2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: DmxPrintSetup.C /main/17 1997/09/03 17:34:59 mgreess $ */
30 * RESTRICTED CONFIDENTIAL INFORMATION:
32 * The information in this document is subject to special
33 * restrictions in a confidential disclosure agreement between
34 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
35 * document outside HP, IBM, Sun, USL, SCO, or Univel without
36 * Sun's specific written approval. This document and all copies
37 * and derivative works thereof must be returned or destroyed at
40 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
46 * Common Desktop Environment
48 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
49 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
50 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
51 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
52 * (c) Copyright 1995 Digital Equipment Corp.
53 * (c) Copyright 1995 Fujitsu Limited
54 * (c) Copyright 1995 Hitachi, Ltd.
57 * RESTRICTED RIGHTS LEGEND
59 *Use, duplication, or disclosure by the U.S. Government is subject to
60 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
61 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
62 *for non-DOD U.S. Government Departments and Agencies are as set forth in
63 *FAR 52.227-19(c)(1,2).
65 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
66 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
67 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
68 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
69 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
70 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
71 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
74 #include <sys/param.h>
79 #include <Xm/ToggleB.h>
80 #include <Xm/ToggleBG.h>
83 #include "DmxPrintOptions.h"
84 #include "DmxPrintSetup.h"
85 #include "DtMailHelp.hh"
89 #include "RoamMenuWindow.h"
91 static DtMailBoolean DmxPrintSetup_print_separately = DTM_FALSE;
92 static DtMailBoolean DmxPrintSetup_use_word_wrap = DTM_TRUE;
93 static DtMailBoolean DmxPrintSetup_print_to_file = DTM_FALSE;
94 static char *DmxPrintSetup_printer_name = NULL;
95 #ifdef REUSE_PRINT_SETUP_DIALOGS
96 static Widget DmxPrintSetup_default_dtprint_setup = NULL;
99 DmxPrintSetup::DmxPrintSetup (
101 XtCallbackProc printCB, XtPointer printClosure,
102 XtCallbackProc cancelCB, XtPointer cancelClosure,
103 XtCallbackProc closeDisplayCB, XtPointer closeDisplayClosure,
104 XtCallbackProc pdmSetupCB, XtPointer pdmSetupClosure)
107 _dtprint_setup = (Widget) NULL;
108 _widgets = (PrintSetupWidgets *) NULL;
109 _use_word_wrap = DmxPrintSetup_use_word_wrap;
110 _print_separately = DmxPrintSetup_print_separately;
111 _print_to_file = DmxPrintSetup_print_to_file;
112 if (NULL != DmxPrintSetup_printer_name)
113 _printer_name = strdup(DmxPrintSetup_printer_name);
115 _printer_name = NULL;
117 _filename = (char*) malloc(MAXPATHLEN+1);
118 if (NULL != _filename)
119 sprintf(_filename, "%s/dtmail_messages.ps", getenv("HOME"));
122 _cancelCB = cancelCB;
123 _closeDisplayCB = closeDisplayCB;
124 _pdmSetupCB = pdmSetupCB;
126 _printClosure = printClosure;
127 _cancelClosure = cancelClosure;
128 _closeDisplayClosure = closeDisplayClosure;
129 _pdmSetupClosure = pdmSetupClosure;
131 attachPrintSetupDialog();
132 XtRealizeWidget(_dtprint_setup);
135 DmxPrintSetup::~DmxPrintSetup (void)
137 if (NULL != _printer_name)
140 if (NULL != _filename)
143 detachPrintSetupDialog();
147 DmxPrintSetup::setPrintToFileName (char *filename)
149 if (NULL != _filename)
152 _filename = strdup(filename);
154 if (NULL != _filename)
155 XtVaSetValues(_dtprint_setup, DtNfileName, _filename, NULL);
159 DmxPrintSetup::display (void)
161 if (_dtprint_setup == NULL) return;
163 #ifdef REUSE_PRINT_SETUP_DIALOGS
164 Position x1, y1, x2, y2;
165 Dimension w1, h1, w2, h2;
167 XtParent(_dtprint_setup),
168 XmNx, &x1, XmNy, &y1,
169 XmNwidth, &w1, XmNheight, &h1,
173 XmNx, &x2, XmNy, &y2,
174 XmNwidth, &w2, XmNheight, &h2,
177 XtParent(_dtprint_setup),
178 XmNx, x2 + (w2 - w1) / 2, XmNy, y2 + (h2 - h1) / 2,
182 XtManageChild(_dtprint_setup);
184 if (NULL != _printer_name)
185 XtVaSetValues(_widgets->printer_name_tf, XmNvalue, _printer_name, NULL);
189 DmxPrintSetup::getDefaultPrintData (DtPrintSetupData *print_data)
191 if (_dtprint_setup == NULL || print_data == NULL) return DTM_FALSE;
192 if (DtPRINT_SUCCESS == DtPrintFillSetupData(_dtprint_setup, print_data))
199 DmxPrintSetup::printSeparately (void)
201 if (DTM_TRUE != _print_to_file)
202 return _print_separately;
208 DmxPrintSetup::useWordWrap (void)
210 return _use_word_wrap;
214 DmxPrintSetup::attachPrintSetupDialog (void)
216 unsigned char is_set;
219 #ifdef REUSE_PRINT_SETUP_DIALOGS
220 if (DmxPrintSetup_default_dtprint_setup != NULL)
223 // Attempt to reuse the last print setup and print display connection.
225 _dtprint_setup = DmxPrintSetup_default_dtprint_setup;
226 DmxPrintSetup_default_dtprint_setup = NULL;
229 _dtprint_setup = createPrintSetupDialog(theRoamApp.baseWidget());
231 _dtprint_setup = createPrintSetupDialog(_parent);
235 // Copy the information about the widgets into the setup.
237 XtVaGetValues(_dtprint_setup, XmNuserData, &_widgets, NULL);
240 // Add the setup-specific callbacks
245 DmxPrintSetup::printCB,
251 (XtPointer) _cancelClosure);
254 DtNclosePrintDisplayCallback,
256 (XtPointer) _closeDisplayClosure);
261 (XtPointer) _pdmSetupClosure);
263 is_set = (_print_separately) ? XmSET : XmUNSET;
264 XtVaSetValues(_widgets->print_separately_tb, XmNset, is_set, NULL);
266 is_set = (_use_word_wrap) ? XmSET : XmUNSET;
267 XtVaSetValues(_widgets->use_word_wrap_tb, XmNset, is_set, NULL);
269 if (DTM_TRUE == _print_to_file)
272 DtNprintDestination, DtPRINT_TO_FILE,
277 DtNprintDestination, DtPRINT_TO_PRINTER,
280 if (NULL != _printer_name)
281 XtVaSetValues(_dtprint_setup, DtNprinterName, _printer_name, NULL);
283 if (NULL != _filename)
284 XtVaSetValues(_dtprint_setup, DtNfileName, _filename, NULL);
286 dialog = XtParent(_dtprint_setup);
287 if (NULL != dialog && XtIsShell(dialog))
289 char *title = (char*) GETMSG(DT_catd, 21, 21, "Mailer - Print Setup");
290 XtVaSetValues(dialog, XmNtitle, title, NULL);
294 fprintf(stderr, "Print Setup box is not parented to a shell\n");
300 DmxPrintSetup::createPrintSetupDialog (Widget parent)
302 PrintSetupWidgets *widgets;
306 // Create the app-specific widgets for the Setup Dialog.
307 widgets = (PrintSetupWidgets *) XtMalloc(sizeof(PrintSetupWidgets));
310 // Create the DtPrintSetupDialog and specify that the application
311 // specific area be located below the generic area.
312 // Save the PrintSetupWidgets record as UserData so it can be
315 widgets->dtprint_setup =
316 DtCreatePrintSetupDialog(parent, "Setup", NULL, 0);
319 widgets->dtprint_setup,
320 DtNworkAreaLocation, DtWORK_AREA_BOTTOM,
321 XmNuserData, widgets,
325 widgets->dtprint_setup,
328 (void *)DTMAILPRINTSETUPDIALOG);
331 widgets->dtprint_setup,
333 &DmxPrintSetup::destroyPrintSetupDialogCB,
334 (XtPointer) widgets);
336 widgets->form = XtVaCreateWidget(
339 widgets->dtprint_setup,
342 xms = XmStringCreateLocalized(GETMSG(DT_catd, 21, 12, "Print Separately"));
343 widgets->print_separately_tb = XtVaCreateManagedWidget(
345 xmToggleButtonWidgetClass,
347 XmNalignment, XmALIGNMENT_BEGINNING,
349 XmNleftAttachment, XmATTACH_FORM,
350 XmNtopAttachment, XmATTACH_FORM,
354 xms = XmStringCreateLocalized(GETMSG(DT_catd, 21, 13, "Use Word Wrap"));
355 widgets->use_word_wrap_tb = XtVaCreateManagedWidget(
357 xmToggleButtonWidgetClass,
359 XmNalignment, XmALIGNMENT_BEGINNING,
361 XmNleftAttachment, XmATTACH_FORM,
362 XmNrightAttachment, XmATTACH_FORM,
363 XmNtopAttachment, XmATTACH_WIDGET,
364 XmNtopWidget, widgets->print_separately_tb,
368 xms = XmStringCreateLocalized(GETMSG(DT_catd, 21, 20, "More ..."));
369 widgets->more_options_pb = XtVaCreateManagedWidget(
371 xmPushButtonWidgetClass,
373 XmNalignment, XmALIGNMENT_BEGINNING,
375 XmNleftAttachment, XmATTACH_NONE,
376 XmNrightAttachment, XmATTACH_FORM,
377 XmNtopAttachment, XmATTACH_WIDGET,
378 XmNtopWidget, widgets->use_word_wrap_tb,
383 widgets->more_options_pb,
385 &DmxPrintSetup::moreOptionsCB,
388 widgets->checkbox_tb =
389 XtNameToWidget(widgets->dtprint_setup, "DestRadioBox.button_1");
390 widgets->printer_name_tf = XtNameToWidget(widgets->dtprint_setup, "Name");
392 if (NULL != widgets->checkbox_tb)
394 widgets->checkbox_tb,
395 XmNvalueChangedCallback,
396 &DmxPrintSetup::destinationChangedCB,
397 (XtPointer) widgets);
399 XtManageChild(widgets->form);
400 return(widgets->dtprint_setup);
405 DmxPrintSetup::detachPrintSetupDialog (void)
410 DmxPrintSetup::printCB,
416 (XtPointer) _cancelClosure);
419 DtNclosePrintDisplayCallback,
421 (XtPointer) _closeDisplayClosure);
426 (XtPointer) _pdmSetupClosure);
429 // Leave the Print Setup Dialog for the next print job.
431 #ifdef REUSE_PRINT_SETUP_DIALOGS
432 if (DmxPrintSetup_default_dtprint_setup != NULL)
434 XtDestroyWidget(DmxPrintSetup_default_dtprint_setup);
435 DmxPrintSetup_default_dtprint_setup = NULL;
437 DmxPrintSetup_default_dtprint_setup = _dtprint_setup;
439 XtDestroyWidget(_dtprint_setup);
445 DmxPrintSetup::savePrintSetupOptions(DtPrintSetupData *print_data)
447 unsigned char is_set;
449 XtVaGetValues(_widgets->print_separately_tb, XmNset, &is_set, NULL);
450 _print_separately = (is_set == XmSET) ? DTM_TRUE : DTM_FALSE;
451 DmxPrintSetup_print_separately = _print_separately;
453 XtVaGetValues(_widgets->use_word_wrap_tb, XmNset, &is_set, NULL);
454 _use_word_wrap = (is_set == XmSET) ? DTM_TRUE : DTM_FALSE;
455 DmxPrintSetup_use_word_wrap = _use_word_wrap;
458 (DtPRINT_TO_FILE == print_data->destination) ? DTM_TRUE : DTM_FALSE;
459 DmxPrintSetup_print_to_file = _print_to_file;
461 if (NULL != _printer_name)
463 _printer_name = strdup(print_data->printer_name);
465 if (NULL != DmxPrintSetup_printer_name)
466 free(DmxPrintSetup_printer_name);
467 DmxPrintSetup_printer_name = strdup(_printer_name);
469 if (NULL != _filename)
471 _filename = strdup(print_data->dest_info);
476 DmxPrintSetup::destinationChangedCB(
478 XtPointer client_data,
481 PrintSetupWidgets *widgets = (PrintSetupWidgets*) client_data;
484 if (NULL == checkbox_tb) return;
486 XtVaGetValues(checkbox_tb, XmNset, &toggleFlag, NULL);
489 widgets->print_separately_tb,
494 XtVaSetValues(widgets->print_separately_tb, XmNsensitive, True, NULL);
499 DmxPrintSetup::destroyPrintSetupDialogCB(Widget, XtPointer widgets, XtPointer)
501 XtFree((char *) widgets);
506 DmxPrintSetup::moreOptionsCB(Widget, XtPointer, XtPointer)
508 OptCmd *optCmd = (OptCmd *) theRoamApp.mailOptions();
510 optCmd->displayPrintingOptionsPane();
514 DmxPrintSetup::printCB(Widget w, XtPointer client_data, XtPointer call_data)
516 DmxPrintSetup *thisSetup = (DmxPrintSetup*) client_data;
517 DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*) call_data;
519 thisSetup->_printCB(w, thisSetup->_printClosure, call_data);
520 thisSetup->savePrintSetupOptions(pbs->print_data);