1 /* $TOG: DmxPrintSetup.C /main/17 1997/09/03 17:34:59 mgreess $ */
8 * RESTRICTED CONFIDENTIAL INFORMATION:
10 * The information in this document is subject to special
11 * restrictions in a confidential disclosure agreement between
12 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
13 * document outside HP, IBM, Sun, USL, SCO, or Univel without
14 * Sun's specific written approval. This document and all copies
15 * and derivative works thereof must be returned or destroyed at
18 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
24 * Common Desktop Environment
26 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
27 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
28 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
29 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
30 * (c) Copyright 1995 Digital Equipment Corp.
31 * (c) Copyright 1995 Fujitsu Limited
32 * (c) Copyright 1995 Hitachi, Ltd.
35 * RESTRICTED RIGHTS LEGEND
37 *Use, duplication, or disclosure by the U.S. Government is subject to
38 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
39 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
40 *for non-DOD U.S. Government Departments and Agencies are as set forth in
41 *FAR 52.227-19(c)(1,2).
43 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
44 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
45 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
46 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
47 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
48 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
49 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
52 #include <sys/param.h>
57 #include <Xm/ToggleB.h>
58 #include <Xm/ToggleBG.h>
61 #include "DmxPrintOptions.h"
62 #include "DmxPrintSetup.h"
63 #include "DtMailHelp.hh"
67 #include "RoamMenuWindow.h"
69 static DtMailBoolean DmxPrintSetup_print_separately = DTM_FALSE;
70 static DtMailBoolean DmxPrintSetup_use_word_wrap = DTM_TRUE;
71 static DtMailBoolean DmxPrintSetup_print_to_file = DTM_FALSE;
72 static char *DmxPrintSetup_printer_name = NULL;
73 #ifdef REUSE_PRINT_SETUP_DIALOGS
74 static Widget DmxPrintSetup_default_dtprint_setup = NULL;
77 DmxPrintSetup::DmxPrintSetup (
79 XtCallbackProc printCB, XtPointer printClosure,
80 XtCallbackProc cancelCB, XtPointer cancelClosure,
81 XtCallbackProc closeDisplayCB, XtPointer closeDisplayClosure,
82 XtCallbackProc pdmSetupCB, XtPointer pdmSetupClosure)
85 _dtprint_setup = (Widget) NULL;
86 _widgets = (PrintSetupWidgets *) NULL;
87 _use_word_wrap = DmxPrintSetup_use_word_wrap;
88 _print_separately = DmxPrintSetup_print_separately;
89 _print_to_file = DmxPrintSetup_print_to_file;
90 if (NULL != DmxPrintSetup_printer_name)
91 _printer_name = strdup(DmxPrintSetup_printer_name);
95 _filename = (char*) malloc(MAXPATHLEN+1);
96 if (NULL != _filename)
97 sprintf(_filename, "%s/dtmail_messages.ps", getenv("HOME"));
100 _cancelCB = cancelCB;
101 _closeDisplayCB = closeDisplayCB;
102 _pdmSetupCB = pdmSetupCB;
104 _printClosure = printClosure;
105 _cancelClosure = cancelClosure;
106 _closeDisplayClosure = closeDisplayClosure;
107 _pdmSetupClosure = pdmSetupClosure;
109 attachPrintSetupDialog();
110 XtRealizeWidget(_dtprint_setup);
113 DmxPrintSetup::~DmxPrintSetup (void)
115 if (NULL != _printer_name)
118 if (NULL != _filename)
121 detachPrintSetupDialog();
125 DmxPrintSetup::setPrintToFileName (char *filename)
127 if (NULL != _filename)
130 _filename = strdup(filename);
132 if (NULL != _filename)
133 XtVaSetValues(_dtprint_setup, DtNfileName, _filename, NULL);
137 DmxPrintSetup::display (void)
139 if (_dtprint_setup == NULL) return;
141 #ifdef REUSE_PRINT_SETUP_DIALOGS
142 Position x1, y1, x2, y2;
143 Dimension w1, h1, w2, h2;
145 XtParent(_dtprint_setup),
146 XmNx, &x1, XmNy, &y1,
147 XmNwidth, &w1, XmNheight, &h1,
151 XmNx, &x2, XmNy, &y2,
152 XmNwidth, &w2, XmNheight, &h2,
155 XtParent(_dtprint_setup),
156 XmNx, x2 + (w2 - w1) / 2, XmNy, y2 + (h2 - h1) / 2,
160 XtManageChild(_dtprint_setup);
162 if (NULL != _printer_name)
163 XtVaSetValues(_widgets->printer_name_tf, XmNvalue, _printer_name, NULL);
167 DmxPrintSetup::getDefaultPrintData (DtPrintSetupData *print_data)
169 if (_dtprint_setup == NULL || print_data == NULL) return DTM_FALSE;
170 if (DtPRINT_SUCCESS == DtPrintFillSetupData(_dtprint_setup, print_data))
177 DmxPrintSetup::printSeparately (void)
179 if (DTM_TRUE != _print_to_file)
180 return _print_separately;
186 DmxPrintSetup::useWordWrap (void)
188 return _use_word_wrap;
192 DmxPrintSetup::attachPrintSetupDialog (void)
194 unsigned char is_set;
197 #ifdef REUSE_PRINT_SETUP_DIALOGS
198 if (DmxPrintSetup_default_dtprint_setup != NULL)
201 // Attempt to reuse the last print setup and print display connection.
203 _dtprint_setup = DmxPrintSetup_default_dtprint_setup;
204 DmxPrintSetup_default_dtprint_setup = NULL;
207 _dtprint_setup = createPrintSetupDialog(theRoamApp.baseWidget());
209 _dtprint_setup = createPrintSetupDialog(_parent);
213 // Copy the information about the widgets into the setup.
215 XtVaGetValues(_dtprint_setup, XmNuserData, &_widgets, NULL);
218 // Add the setup-specific callbacks
223 DmxPrintSetup::printCB,
229 (XtPointer) _cancelClosure);
232 DtNclosePrintDisplayCallback,
234 (XtPointer) _closeDisplayClosure);
239 (XtPointer) _pdmSetupClosure);
241 is_set = (_print_separately) ? XmSET : XmUNSET;
242 XtVaSetValues(_widgets->print_separately_tb, XmNset, is_set, NULL);
244 is_set = (_use_word_wrap) ? XmSET : XmUNSET;
245 XtVaSetValues(_widgets->use_word_wrap_tb, XmNset, is_set, NULL);
247 if (DTM_TRUE == _print_to_file)
250 DtNprintDestination, DtPRINT_TO_FILE,
255 DtNprintDestination, DtPRINT_TO_PRINTER,
258 if (NULL != _printer_name)
259 XtVaSetValues(_dtprint_setup, DtNprinterName, _printer_name, NULL);
261 if (NULL != _filename)
262 XtVaSetValues(_dtprint_setup, DtNfileName, _filename, NULL);
264 dialog = XtParent(_dtprint_setup);
265 if (NULL != dialog && XtIsShell(dialog))
267 char *title = (char*) GETMSG(DT_catd, 21, 21, "Mailer - Print Setup");
268 XtVaSetValues(dialog, XmNtitle, title, NULL);
272 fprintf(stderr, "Print Setup box is not parented to a shell\n");
278 DmxPrintSetup::createPrintSetupDialog (Widget parent)
280 PrintSetupWidgets *widgets;
284 // Create the app-specific widgets for the Setup Dialog.
285 widgets = (PrintSetupWidgets *) XtMalloc(sizeof(PrintSetupWidgets));
288 // Create the DtPrintSetupDialog and specify that the application
289 // specific area be located below the generic area.
290 // Save the PrintSetupWidgets record as UserData so it can be
293 widgets->dtprint_setup =
294 DtCreatePrintSetupDialog(parent, "Setup", NULL, 0);
297 widgets->dtprint_setup,
298 DtNworkAreaLocation, DtWORK_AREA_BOTTOM,
299 XmNuserData, widgets,
303 widgets->dtprint_setup,
306 DTMAILPRINTSETUPDIALOG);
309 widgets->dtprint_setup,
311 &DmxPrintSetup::destroyPrintSetupDialogCB,
312 (XtPointer) widgets);
314 widgets->form = XtVaCreateWidget(
317 widgets->dtprint_setup,
320 xms = XmStringCreateLocalized(GETMSG(DT_catd, 21, 12, "Print Separately"));
321 widgets->print_separately_tb = XtVaCreateManagedWidget(
323 xmToggleButtonWidgetClass,
325 XmNalignment, XmALIGNMENT_BEGINNING,
327 XmNleftAttachment, XmATTACH_FORM,
328 XmNtopAttachment, XmATTACH_FORM,
332 xms = XmStringCreateLocalized(GETMSG(DT_catd, 21, 13, "Use Word Wrap"));
333 widgets->use_word_wrap_tb = XtVaCreateManagedWidget(
335 xmToggleButtonWidgetClass,
337 XmNalignment, XmALIGNMENT_BEGINNING,
339 XmNleftAttachment, XmATTACH_FORM,
340 XmNrightAttachment, XmATTACH_FORM,
341 XmNtopAttachment, XmATTACH_WIDGET,
342 XmNtopWidget, widgets->print_separately_tb,
346 xms = XmStringCreateLocalized(GETMSG(DT_catd, 21, 20, "More ..."));
347 widgets->more_options_pb = XtVaCreateManagedWidget(
349 xmPushButtonWidgetClass,
351 XmNalignment, XmALIGNMENT_BEGINNING,
353 XmNleftAttachment, XmATTACH_NONE,
354 XmNrightAttachment, XmATTACH_FORM,
355 XmNtopAttachment, XmATTACH_WIDGET,
356 XmNtopWidget, widgets->use_word_wrap_tb,
361 widgets->more_options_pb,
363 &DmxPrintSetup::moreOptionsCB,
366 widgets->checkbox_tb =
367 XtNameToWidget(widgets->dtprint_setup, "DestRadioBox.button_1");
368 widgets->printer_name_tf = XtNameToWidget(widgets->dtprint_setup, "Name");
370 if (NULL != widgets->checkbox_tb)
372 widgets->checkbox_tb,
373 XmNvalueChangedCallback,
374 &DmxPrintSetup::destinationChangedCB,
375 (XtPointer) widgets);
377 XtManageChild(widgets->form);
378 return(widgets->dtprint_setup);
383 DmxPrintSetup::detachPrintSetupDialog (void)
388 DmxPrintSetup::printCB,
394 (XtPointer) _cancelClosure);
397 DtNclosePrintDisplayCallback,
399 (XtPointer) _closeDisplayClosure);
404 (XtPointer) _pdmSetupClosure);
407 // Leave the Print Setup Dialog for the next print job.
409 #ifdef REUSE_PRINT_SETUP_DIALOGS
410 if (DmxPrintSetup_default_dtprint_setup != NULL)
412 XtDestroyWidget(DmxPrintSetup_default_dtprint_setup);
413 DmxPrintSetup_default_dtprint_setup = NULL;
415 DmxPrintSetup_default_dtprint_setup = _dtprint_setup;
417 XtDestroyWidget(_dtprint_setup);
423 DmxPrintSetup::savePrintSetupOptions(DtPrintSetupData *print_data)
425 unsigned char is_set;
427 XtVaGetValues(_widgets->print_separately_tb, XmNset, &is_set, NULL);
428 _print_separately = (is_set == XmSET) ? DTM_TRUE : DTM_FALSE;
429 DmxPrintSetup_print_separately = _print_separately;
431 XtVaGetValues(_widgets->use_word_wrap_tb, XmNset, &is_set, NULL);
432 _use_word_wrap = (is_set == XmSET) ? DTM_TRUE : DTM_FALSE;
433 DmxPrintSetup_use_word_wrap = _use_word_wrap;
436 (DtPRINT_TO_FILE == print_data->destination) ? DTM_TRUE : DTM_FALSE;
437 DmxPrintSetup_print_to_file = _print_to_file;
439 if (NULL != _printer_name)
441 _printer_name = strdup(print_data->printer_name);
443 if (NULL != DmxPrintSetup_printer_name)
444 free(DmxPrintSetup_printer_name);
445 DmxPrintSetup_printer_name = strdup(_printer_name);
447 if (NULL != _filename)
449 _filename = strdup(print_data->dest_info);
454 DmxPrintSetup::destinationChangedCB(
456 XtPointer client_data,
459 PrintSetupWidgets *widgets = (PrintSetupWidgets*) client_data;
462 if (NULL == checkbox_tb) return;
464 XtVaGetValues(checkbox_tb, XmNset, &toggleFlag, NULL);
467 widgets->print_separately_tb,
472 XtVaSetValues(widgets->print_separately_tb, XmNsensitive, True, NULL);
477 DmxPrintSetup::destroyPrintSetupDialogCB(Widget, XtPointer widgets, XtPointer)
479 XtFree((char *) widgets);
484 DmxPrintSetup::moreOptionsCB(Widget, XtPointer, XtPointer)
486 OptCmd *optCmd = (OptCmd *) theRoamApp.mailOptions();
488 optCmd->displayPrintingOptionsPane();
492 DmxPrintSetup::printCB(Widget w, XtPointer client_data, XtPointer call_data)
494 DmxPrintSetup *thisSetup = (DmxPrintSetup*) client_data;
495 DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*) call_data;
497 thisSetup->_printCB(w, thisSetup->_printClosure, call_data);
498 thisSetup->savePrintSetupOptions(pbs->print_data);