1 /* $XConsortium: printSetup.c /main/14 1996/10/25 13:37:55 mgreess $ */
2 /**********************************<+>*************************************
3 ***************************************************************************
7 ** Project: HP DT dtpad, a memo maker type editor based on the
10 ** Description: Routines which manipulate the print setup dialog
12 **************************************************************************
13 **********************************<+>*************************************/
15 * Common Desktop Environment
17 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
18 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
19 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
20 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
21 * (c) Copyright 1995 Digital Equipment Corp.
22 * (c) Copyright 1995 Fujitsu Limited
23 * (c) Copyright 1995 Hitachi, Ltd.
26 * RESTRICTED RIGHTS LEGEND
28 *Use, duplication, or disclosure by the U.S. Government is subject to
29 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
30 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
31 *for non-DOD U.S. Government Departments and Agencies are as set forth in
32 *FAR 52.227-19(c)(1,2).
34 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
35 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
36 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
37 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
38 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
39 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
40 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
43 #define REUSE_PRINT_SETUP_DIALOGS
46 #include <sys/param.h>
48 #include <X11/Intrinsic.h>
49 #include <Xm/DialogS.h>
51 #include <Xm/MwmUtil.h>
52 #include <Xm/ToggleB.h>
53 #include <Dt/DtPStrings.h>
54 #include <Dt/HelpDialog.h>
56 #include <Dt/Session.h>
60 static char *_psGetResourceFileName(
62 static void _psSetupToSource(
64 static void _psSourceToSetup(
67 static void _psSetupToUi(
69 static void _psUiToSetup(
71 static Boolean _psUiSpecsAreValid(
73 static void _psAttachPrintSetupDialog(
76 static Widget _psCreatePrintSetupDialog(
79 static void _psPrintSetupCancelCB(
81 XtPointer client_data,
83 static void _psPrintSetupDestroyCB(
85 XtPointer client_data,
87 static void _psPrintSetupPrintCB(
89 XtPointer client_data,
91 static void _psReleasePrintSetupDialog(
94 #define PS_ARRAY_SIZE(ary) (sizeof((ary))/sizeof((ary)[0]))
96 #define PS_HOME_ENV_VARIABLE "HOME"
97 #define PS_DEFAULT_RESOURCE_FILE "dtpadrc"
99 #define PS_RESOURCE_HDRFTR_FORMAT_STRING "Dtpad.%s: %d\n"
100 #define PS_RESOURCE_MARGIN_FORMAT_STRING "Dtpad.%s: %s\n"
102 #define PS_RESOURCE_NAME_HEADER_LEFT "headerLeftEnum"
103 #define PS_RESOURCE_NAME_HEADER_RIGHT "headerRightEnum"
104 #define PS_RESOURCE_NAME_FOOTER_LEFT "footerLeftEnum"
105 #define PS_RESOURCE_NAME_FOOTER_RIGHT "footerRightEnum"
107 #define PS_RESOURCE_NAME_MARGIN_TOP "marginTopSpec"
108 #define PS_RESOURCE_NAME_MARGIN_RIGHT "marginRightSpec"
109 #define PS_RESOURCE_NAME_MARGIN_BOTTOM "marginBottomSpec"
110 #define PS_RESOURCE_NAME_MARGIN_LEFT "marginLeftSpec"
112 #define PS_RESOURCE_VALUE_NONE "Empty"
113 #define PS_RESOURCE_VALUE_DATE "Date"
114 #define PS_RESOURCE_VALUE_DOCNAME "DocName"
115 #define PS_RESOURCE_VALUE_PAGE_NUMBER "PageNumber"
116 #define PS_RESOURCE_VALUE_USER_NAME "UserName"
118 #define PS_RESOURCE_VALUE_DFLT_MARGIN "1.0 in"
120 typedef struct resource_value
122 PrintStringTypeEnum which;
123 char *resource_string;
129 static ResourceValue _psHdrFtrValues[] =
131 { PRINT_NONE_STRING_TYPE_ENUM,
132 PS_RESOURCE_VALUE_NONE,
135 { PRINT_DATE_STRING_TYPE_ENUM,
136 PS_RESOURCE_VALUE_DATE,
139 { PRINT_DOCNAME_STRING_TYPE_ENUM,
140 PS_RESOURCE_VALUE_DOCNAME,
141 15, 3, "Document Name"
143 { PRINT_PAGE_NUMBER_STRING_TYPE_ENUM,
144 PS_RESOURCE_VALUE_PAGE_NUMBER,
147 { PRINT_USER_NAME_STRING_TYPE_ENUM,
148 PS_RESOURCE_VALUE_USER_NAME,
154 static Widget _psDefaultPrintSetupDialog = (Widget) NULL;
155 static char *_psDefaultMargin = PS_RESOURCE_VALUE_DFLT_MARGIN;
157 static XtResource _psResources[] = {
158 {PS_RESOURCE_NAME_FOOTER_LEFT, "FooterLeftEnum", XmRInt, sizeof(int),
159 XtOffset(PrintOptions*, footerLeft),
160 XmRImmediate, (XtPointer) PRINT_NONE_STRING_TYPE_ENUM,
162 {PS_RESOURCE_NAME_FOOTER_RIGHT, "FooterRightEnum", XmRInt, sizeof(int),
163 XtOffset(PrintOptions*, footerRight),
164 XmRImmediate, (XtPointer) PRINT_PAGE_NUMBER_STRING_TYPE_ENUM,
166 {PS_RESOURCE_NAME_HEADER_LEFT, "HeaderLeftEnum", XmRInt, sizeof(int),
167 XtOffset(PrintOptions*, headerLeft),
168 XmRImmediate, (XtPointer) PRINT_NONE_STRING_TYPE_ENUM,
170 {PS_RESOURCE_NAME_HEADER_RIGHT, "HeaderRightEnum", XmRInt, sizeof(int),
171 XtOffset(PrintOptions*, headerRight),
172 XmRImmediate, (XtPointer) PRINT_DOCNAME_STRING_TYPE_ENUM,
174 {PS_RESOURCE_NAME_MARGIN_BOTTOM, "MarginBottomSpec", XmRString, sizeof(String),
175 XtOffset(PrintOptions*, marginBottom),
176 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
178 {PS_RESOURCE_NAME_MARGIN_LEFT, "MarginLeftSpec", XmRString, sizeof(String),
179 XtOffset(PrintOptions*, marginLeft),
180 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
182 {PS_RESOURCE_NAME_MARGIN_RIGHT, "MarginRightSpec", XmRString, sizeof(String),
183 XtOffset(PrintOptions*, marginRight),
184 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
186 {PS_RESOURCE_NAME_MARGIN_TOP, "MarginTopSpec", XmRString, sizeof(String),
187 XtOffset(PrintOptions*, marginTop),
188 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
193 /************************************************************************
196 * Adds dtpad specific items to the passed print setup box.
197 * The document file name is presented in the bottom work area.
198 ************************************************************************/
205 XtCallbackProc cancelCB, XtPointer cancelClosure,
206 XtCallbackProc closeDisplayCB, XtPointer closeDisplayClosure,
207 XtCallbackProc printCB, XtPointer printClosure,
208 XtCallbackProc setupCB, XtPointer setupClosure
213 unsigned char is_set;
215 Widget *menu_buttons;
221 pSetup = (PrintSetup *) XtMalloc( sizeof(PrintSetup) );
222 pSetup->parent = parent;
223 pSetup->docName = strdup(docName);
224 pSetup->cancelCB = cancelCB;
225 pSetup->closeDisplayCB = closeDisplayCB;
226 pSetup->printCB = printCB;
227 pSetup->setupCB = setupCB;
228 pSetup->cancelClosure = cancelClosure;
229 pSetup->closeDisplayClosure = closeDisplayClosure;
230 pSetup->printClosure = printClosure;
231 pSetup->setupClosure = setupClosure;
234 pSetup->dtprintSetup = (Widget) NULL;
235 pSetup->widgets = (psWidgets *) NULL;
238 * Get the current default values for the app-specific printing options.
240 _psSourceToSetup(pSetup, wordWrap);
243 * Get a print setup dialog.
245 _psAttachPrintSetupDialog(pSetup, pPad);
250 /************************************************************************
253 ************************************************************************/
255 PrintSetupDestroy(PrintSetup *pSetup)
257 if (pSetup == NULL) return;
260 free(pSetup->docName);
261 if (pSetup->dtprintSetup);
262 _psReleasePrintSetupDialog(pSetup);
263 XtFree((char*) pSetup);
266 /************************************************************************
268 * Displays the specified print setup GUI.
269 ************************************************************************/
271 PrintSetupDisplay(PrintSetup *pSetup)
273 if (pSetup == NULL) return;
276 * Initialize the print setup Ui.
278 _psSetupToUi(pSetup);
280 XtManageChild(pSetup->dtprintSetup);
281 XtMapWidget(pSetup->dtprintSetup);
284 /************************************************************************
286 * Hides the specified print setup GUI.
287 ************************************************************************/
289 PrintSetupHide(PrintSetup *pSetup)
291 if (pSetup == NULL) return;
292 if (pSetup->dtprintSetup == NULL) return;
293 XtUnmanageChild(pSetup->dtprintSetup);
294 XtUnmapWidget(pSetup->dtprintSetup);
298 /************************************************************************
299 * PrintSetupGetHdrFtrSpec
300 * Returns the current value of the specified header/footer print option.
301 ************************************************************************/
303 PrintSetupGetHdrFtrSpec(PrintSetup *pSetup, _DtPrintHdrFtrEnum which)
305 PrintStringTypeEnum rtn;
307 if (pSetup == NULL) return PRINT_NONE_STRING_TYPE_ENUM;
310 case DTPRINT_OPTION_HEADER_LEFT:
311 rtn = pSetup->options.headerLeft;
313 case DTPRINT_OPTION_HEADER_RIGHT:
314 rtn = pSetup->options.headerRight;
316 case DTPRINT_OPTION_FOOTER_LEFT:
317 rtn = pSetup->options.footerLeft;
319 case DTPRINT_OPTION_FOOTER_RIGHT:
321 rtn = pSetup->options.footerRight;
327 /************************************************************************
328 * PrintSetupGetMarginSpec
329 * Returns the current value of the specified margin print option.
330 ************************************************************************/
332 PrintSetupGetMarginSpec(PrintSetup *pSetup, _DtPrintMarginEnum which)
336 if (pSetup == NULL) return _psDefaultMargin;
339 case DTPRINT_OPTION_MARGIN_TOP:
340 rtn = pSetup->options.marginTop;
342 case DTPRINT_OPTION_MARGIN_RIGHT:
343 rtn = pSetup->options.marginRight;
345 case DTPRINT_OPTION_MARGIN_BOTTOM:
346 rtn = pSetup->options.marginBottom;
348 case DTPRINT_OPTION_MARGIN_LEFT:
350 rtn = pSetup->options.marginLeft;
356 /************************************************************************
357 * PrintSetupGetDefaultPrintData
358 * Returns the current value of the print data in the pData variable.
359 ************************************************************************/
361 PrintSetupGetDefaultPrintData(PrintSetup *pSetup, DtPrintSetupData *pData)
363 if (pSetup == NULL || pData == NULL) return FALSE;
364 return (DtPRINT_SUCCESS == DtPrintFillSetupData(
365 pSetup->dtprintSetup,
369 /************************************************************************
370 * PrintSetupUseWordWrap
371 * Returns the current value of word wrap print option.
372 ************************************************************************/
374 PrintSetupUseWordWrap(PrintSetup *pSetup)
376 if (pSetup == NULL) return TRUE;
377 return pSetup->options.wordWrap;
382 /*******************************************************************************
383 *******************************************************************************
387 *******************************************************************************
388 ******************************************************************************/
390 /************************************************************************
391 * _psGetResourceFileName
392 ************************************************************************/
394 _psGetResourceFileName(PrintSetup *pSetup)
396 #define BUFFER_SIZE 256
397 extern Widget topLevelWithWmCommand;
398 static char buffer[BUFFER_SIZE];
399 static char *dtpadrc = NULL;
400 char *savePath, *saveFile;
403 return XtNewString("/tmp/dtpadrc");
405 if (dtpadrc != NULL) return XtNewString(dtpadrc);
408 saveFile = PS_DEFAULT_RESOURCE_FILE;
409 if (! DtSessionSavePath(topLevelWithWmCommand, &savePath, &saveFile))
413 getenv(PS_HOME_ENV_VARIABLE),
414 DtPERSONAL_TMP_DIRECTORY,
415 PS_DEFAULT_RESOURCE_FILE);
418 dtpadrc = XtNewString(savePath);
420 return XtNewString(dtpadrc);
424 /************************************************************************
426 ************************************************************************/
428 _psSourceToSetup(PrintSetup *pSetup, Boolean wordWrap)
430 XrmDatabase database;
432 PrintOptions pOption;
434 if (pSetup == NULL) return;
436 dtpadrc = _psGetResourceFileName(pSetup);
437 database = XtDatabase(XtDisplay(pSetup->parent));
438 XrmCombineFileDatabase(dtpadrc, &database, TRUE);
441 /* Get the application resources */
442 XtGetApplicationResources(
443 pSetup->parent, &pOption,
444 _psResources, XtNumber(_psResources),
447 pSetup->options.footerLeft = pOption.footerLeft;
448 pSetup->options.footerRight = pOption.footerRight;
449 pSetup->options.headerLeft = pOption.headerLeft;
450 pSetup->options.headerRight = pOption.headerRight;
451 pSetup->options.marginBottom = XtNewString(pOption.marginBottom);
452 pSetup->options.marginLeft = XtNewString(pOption.marginLeft);
453 pSetup->options.marginRight = XtNewString(pOption.marginRight);
454 pSetup->options.marginTop = XtNewString(pOption.marginTop);
455 pSetup->options.wordWrap = wordWrap;
458 /************************************************************************
460 ************************************************************************/
462 _psSetupToSource(PrintSetup *pSetup)
464 PrintOptions *pOption;
468 if (pSetup == NULL) return;
469 pOption = &pSetup->options;
471 dtpadrc = _psGetResourceFileName(pSetup);
472 fp = fopen(dtpadrc, "wb");
475 /* TBD: Error message. */
478 "_psSetupToSource: Cannot open resource file '%s'\n",
486 PS_RESOURCE_HDRFTR_FORMAT_STRING,
487 PS_RESOURCE_NAME_HEADER_LEFT,
493 PS_RESOURCE_HDRFTR_FORMAT_STRING,
494 PS_RESOURCE_NAME_HEADER_RIGHT,
500 PS_RESOURCE_HDRFTR_FORMAT_STRING,
501 PS_RESOURCE_NAME_FOOTER_LEFT,
507 PS_RESOURCE_HDRFTR_FORMAT_STRING,
508 PS_RESOURCE_NAME_FOOTER_RIGHT,
514 PS_RESOURCE_MARGIN_FORMAT_STRING,
515 PS_RESOURCE_NAME_MARGIN_TOP,
521 PS_RESOURCE_MARGIN_FORMAT_STRING,
522 PS_RESOURCE_NAME_MARGIN_RIGHT,
528 PS_RESOURCE_MARGIN_FORMAT_STRING,
529 PS_RESOURCE_NAME_MARGIN_BOTTOM,
530 pOption->marginBottom
535 PS_RESOURCE_MARGIN_FORMAT_STRING,
536 PS_RESOURCE_NAME_MARGIN_LEFT,
543 /************************************************************************
545 ************************************************************************/
547 _psSetupToUi(PrintSetup *pSetup)
551 PrintOptions *pOption;
553 if (pSetup == NULL ||
554 pSetup->dtprintSetup == NULL ||
555 pSetup->widgets == NULL)
557 pOption = &pSetup->options;
559 isSet = (pOption->wordWrap) ? XmSET : XmUNSET;
560 XtVaSetValues(pSetup->widgets->wordWrapTB, XmNset, isSet, NULL);
562 frame = pSetup->widgets->hdrftrFrame;
563 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_LEFT);
564 _DtPrintSetHdrFtrByData(w, (void*) pOption->headerLeft);
566 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_RIGHT);
567 _DtPrintSetHdrFtrByData(w, (void*) pOption->headerRight);
569 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_LEFT);
570 _DtPrintSetHdrFtrByData(w, (void*) pOption->footerLeft);
572 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_RIGHT);
573 _DtPrintSetHdrFtrByData(w, (void*) pOption->footerRight);
575 frame = pSetup->widgets->marginFrame;
576 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
577 _DtPrintSetMarginSpec(w, pOption->marginTop);
579 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
580 _DtPrintSetMarginSpec(w, pOption->marginRight);
582 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
583 _DtPrintSetMarginSpec(w, pOption->marginBottom);
585 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
586 _DtPrintSetMarginSpec(w, pOption->marginLeft);
589 /************************************************************************
591 ************************************************************************/
593 _psUiToSetup(PrintSetup *pSetup)
597 PrintOptions *pOption;
599 Boolean error = FALSE;
601 if (pSetup == NULL ||
602 pSetup->dtprintSetup == NULL ||
603 pSetup->widgets == NULL)
605 pOption = &pSetup->options;
607 XtVaGetValues(pSetup->widgets->wordWrapTB, XmNset, &isSet, NULL);
608 pOption->wordWrap = (isSet == XmUNSET) ? FALSE : TRUE;
610 frame = pSetup->widgets->hdrftrFrame;
612 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_LEFT);
613 pOption->headerLeft = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
615 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_RIGHT);
616 pOption->headerRight = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
618 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_LEFT);
619 pOption->footerLeft = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
621 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_RIGHT);
622 pOption->footerRight = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
624 frame = pSetup->widgets->marginFrame;
626 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
627 marginSpec = _DtPrintGetMarginSpec(w);
628 if (pOption->marginTop != NULL)
629 XtFree(pOption->marginTop);
630 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
631 pOption->marginTop = XtNewString(_psDefaultMargin);
633 pOption->marginTop = marginSpec;
635 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
636 marginSpec = _DtPrintGetMarginSpec(w);
637 if (pOption->marginRight != NULL)
638 XtFree(pOption->marginRight);
639 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
640 pOption->marginRight = XtNewString(_psDefaultMargin);
642 pOption->marginRight = marginSpec;
644 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
645 marginSpec = _DtPrintGetMarginSpec(w);
646 if (pOption->marginBottom != NULL)
647 XtFree(pOption->marginBottom);
648 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
649 pOption->marginBottom = XtNewString(_psDefaultMargin);
651 pOption->marginBottom = marginSpec;
653 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
654 marginSpec = _DtPrintGetMarginSpec(w);
655 if (pOption->marginLeft != NULL)
656 XtFree(pOption->marginLeft);
657 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
658 pOption->marginLeft = XtNewString(_psDefaultMargin);
660 pOption->marginLeft = marginSpec;
663 /************************************************************************
665 ************************************************************************/
667 _psUiSpecsAreValid(PrintSetup *pSetup)
671 PrintOptions *pOption;
674 if (pSetup == NULL ||
675 pSetup->dtprintSetup == NULL ||
676 pSetup->widgets == NULL)
678 pOption = &pSetup->options;
680 frame = pSetup->widgets->marginFrame;
682 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
683 marginSpec = _DtPrintGetMarginSpec(w);
684 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
686 XtEnum parseError = FALSE;
688 (void) XmConvertStringToUnits(
689 XtScreenOfObject(pSetup->parent),
700 i18nMsg = GETMESSAGE(15, 6, "Top Margin specifier is invalid: ");
701 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
702 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
703 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
709 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
710 marginSpec = _DtPrintGetMarginSpec(w);
711 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
713 XtEnum parseError = FALSE;
715 (void) XmConvertStringToUnits(
716 XtScreenOfObject(pSetup->parent),
728 GETMESSAGE(15, 7, "Right Margin specifier is invalid: ");
729 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
730 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
731 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
737 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
738 marginSpec = _DtPrintGetMarginSpec(w);
739 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
741 XtEnum parseError = FALSE;
743 (void) XmConvertStringToUnits(
744 XtScreenOfObject(pSetup->parent),
756 GETMESSAGE(15, 8, "Bottom Margin specifier is invalid: ");
757 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
758 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
759 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
765 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
766 marginSpec = _DtPrintGetMarginSpec(w);
767 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
769 XtEnum parseError = FALSE;
771 (void) XmConvertStringToUnits(
772 XtScreenOfObject(pSetup->parent),
783 i18nMsg = GETMESSAGE(15, 9, "Left Margin specifier is invalid: ");
784 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
785 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
786 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
797 * _psAttachPrintSetupDialog
798 * Creates the widgets for the Setup Dialog.
801 _psAttachPrintSetupDialog(PrintSetup *pSetup, Editor *pPad)
803 char *title, *titlePrefix, *titleParent;
806 unsigned char is_set;
808 #ifdef REUSE_PRINT_SETUP_DIALOGS
809 if (_psDefaultPrintSetupDialog != NULL)
812 * Attempt to reuse the last print setup and print display connection.
814 pSetup->dtprintSetup = _psDefaultPrintSetupDialog;
815 _psDefaultPrintSetupDialog = NULL;
822 pSetup->dtprintSetup = _psCreatePrintSetupDialog(pSetup->parent, pPad);
823 dirname = getenv("HOME");
826 char path[MAXPATHLEN+1];
829 filename = strrchr(pSetup->docName, '/');
830 if (NULL == filename)
831 filename = pSetup->docName;
834 sprintf(path, "%s/%s.ps", dirname, filename);
835 XtVaSetValues(pSetup->dtprintSetup, DtNfileName, path, NULL);
840 * Copy the information about the widgets into the setup.
842 XtVaGetValues(pSetup->dtprintSetup, XmNuserData, &pSetup->widgets, NULL);
845 * Add the setup-specific callbacks.
848 pSetup->dtprintSetup,
850 _psPrintSetupCancelCB,
853 pSetup->dtprintSetup,
854 DtNclosePrintDisplayCallback,
855 pSetup->closeDisplayCB,
856 (XtPointer) pSetup->closeDisplayClosure);
858 pSetup->dtprintSetup,
860 _psPrintSetupPrintCB,
863 pSetup->dtprintSetup,
866 (XtPointer) pSetup->setupClosure);
868 xms = XmStringCreateLocalized(pSetup->docName);
869 XtVaSetValues(pSetup->widgets->docNameLabel, XmNlabelString, xms, NULL);
872 dialog = XtParent(pSetup->widgets->dtprintSetup);
873 if (NULL != dialog && XtIsShell(dialog))
875 titleParent = (char*) GETMESSAGE(7, 2, "Text Editor - ");
876 titlePrefix = (char*) GETMESSAGE(14, 23, "Print Setup - ");
878 (char*) XtMalloc(strlen(titleParent) + strlen(titlePrefix) + strlen(pSetup->docName) + 1);
879 sprintf(title, "%s%s%s", titleParent, titlePrefix, pSetup->docName);
880 XtVaSetValues(dialog, XmNtitle, title, NULL);
885 fprintf(stderr, "Print Setup box is not parented to a shell\n");
888 is_set = (pSetup->options.wordWrap) ? XmSET : XmUNSET;
889 XtVaSetValues(pSetup->widgets->wordWrapTB, XmNset, is_set, NULL);
894 * _psCreatePrintSetupDialog
895 * Creates the widgets for the Setup Dialog.
898 _psCreatePrintSetupDialog(Widget parent, Editor *pPad)
905 unsigned char is_set;
912 * Create the widgets for the Setup Dialog.
914 widgets = (psWidgets *) XtMalloc(sizeof(psWidgets));
917 * Create the DtPrintSetupDialog and specify that the application
918 * specific area be located below the generic area.
921 XtSetArg(args[nargs], XmNautoUnmanage, FALSE); nargs++;
922 widgets->dtprintSetup =
923 DtCreatePrintSetupDialog(parent, "DtPrintSetup", args, nargs);
926 widgets->dtprintSetup,
927 DtNworkAreaLocation, DtWORK_AREA_BOTTOM,
928 XmNuserData, widgets,
932 widgets->dtprintSetup,
934 HelpPrintSetupDialogCB,
938 widgets->dtprintSetup,
940 _psPrintSetupDestroyCB,
941 (XtPointer) widgets);
943 * Create the dtpad-specific setup dialog in the bottom work area
945 widgets->form = XtVaCreateManagedWidget(
948 widgets->dtprintSetup,
954 HelpPrintSetupAppSpecificCB,
958 * Create the document name title label
960 xms = XmStringCreateLocalized( GETMESSAGE(14, 12, "Document Name: ") );
961 widgets->docLabel = XtVaCreateManagedWidget(
965 XmNleftAttachment, XmATTACH_FORM,
966 XmNtopAttachment, XmATTACH_FORM,
972 * Create the document name label
974 widgets->docNameLabel = XtVaCreateManagedWidget(
978 XmNleftAttachment, XmATTACH_WIDGET,
979 XmNleftWidget, widgets->docLabel,
981 XmNrightAttachment, XmATTACH_FORM,
983 XmNtopAttachment, XmATTACH_FORM,
986 xms = XmStringCreateLocalized(GETMESSAGE(14, 13, "Wrap To Fit"));
987 widgets->wordWrapTB = XtVaCreateManagedWidget(
989 xmToggleButtonWidgetClass,
991 XmNalignment, XmALIGNMENT_BEGINNING,
993 XmNleftAttachment, XmATTACH_FORM,
994 XmNrightAttachment, XmATTACH_FORM,
995 XmNtopAttachment, XmATTACH_WIDGET,
996 XmNtopWidget, widgets->docLabel,
1001 * Create GUI for the Header/Footer options
1003 nitems = PS_ARRAY_SIZE(_psHdrFtrValues);
1004 strings = (char **) XtMalloc( nitems * sizeof(char*) );
1005 data = (void **) XtMalloc( nitems * sizeof(void*) );
1006 for (i=0; i<nitems; i++)
1008 data[i] = (void*) _psHdrFtrValues[i].which;
1009 strings[i] = GETMESSAGE(
1010 _psHdrFtrValues[i].set_id,
1011 _psHdrFtrValues[i].msg_id,
1012 _psHdrFtrValues[i].dflt_string
1018 * Create GUI for the Header/Footer options
1020 widgets->hdrftrFrame =
1021 _DtPrintCreateHdrFtrFrame(widgets->form, nitems, strings, data);
1023 widgets->hdrftrFrame,
1024 XmNtopAttachment, XmATTACH_WIDGET,
1025 XmNtopWidget, widgets->wordWrapTB,
1026 XmNleftAttachment, XmATTACH_FORM,
1028 XtManageChild(widgets->hdrftrFrame);
1031 * Create GUI for the Margin options
1033 widgets->marginFrame = _DtPrintCreateMarginFrame(widgets->form);
1035 widgets->marginFrame,
1036 XmNtopAttachment, XmATTACH_WIDGET,
1037 XmNtopWidget, widgets->hdrftrFrame,
1038 XmNleftAttachment, XmATTACH_FORM,
1040 XtManageChild(widgets->marginFrame);
1043 * Create GUI for the Margin options
1045 widgets->marginFrame = _DtPrintCreateMarginFrame(widgets->form);
1047 widgets->marginFrame,
1048 XmNtopAttachment, XmATTACH_WIDGET,
1049 XmNtopWidget, widgets->wordWrapTB,
1050 XmNleftAttachment, XmATTACH_FORM,
1052 XtManageChild(widgets->marginFrame);
1055 * Create GUI for the Header/Footer options
1057 widgets->hdrftrFrame =
1058 _DtPrintCreateHdrFtrFrame(widgets->form, nitems, strings, data);
1060 widgets->hdrftrFrame,
1061 XmNtopAttachment, XmATTACH_WIDGET,
1062 XmNtopWidget, widgets->wordWrapTB,
1063 XmNtopWidget, widgets->marginFrame,
1064 XmNleftAttachment, XmATTACH_FORM,
1066 XtManageChild(widgets->hdrftrFrame);
1070 widgets->hdrftrFrame,
1072 HelpPrintSetupPageHeadersFootersCB,
1076 widgets->marginFrame,
1078 HelpPrintSetupPageMargins,
1081 XtRealizeWidget(widgets->dtprintSetup);
1082 return widgets->dtprintSetup;
1087 * _psReleasePrintSetupDialog
1088 * Removes setup-specific callbacks.
1091 _psReleasePrintSetupDialog(PrintSetup *pSetup)
1094 * Remove the setup-specific callbacks.
1097 pSetup->dtprintSetup,
1099 _psPrintSetupCancelCB,
1100 (XtPointer) pSetup);
1102 pSetup->dtprintSetup,
1103 DtNclosePrintDisplayCallback,
1104 pSetup->closeDisplayCB,
1105 (XtPointer) pSetup->closeDisplayClosure);
1107 pSetup->dtprintSetup,
1109 _psPrintSetupPrintCB,
1110 (XtPointer) pSetup);
1112 pSetup->dtprintSetup,
1115 (XtPointer) pSetup->setupClosure);
1117 #ifdef REUSE_PRINT_SETUP_DIALOGS
1118 if (_psDefaultPrintSetupDialog != NULL)
1121 * Attempt to reuse the last print setup and print display connection.
1123 XtDestroyWidget(_psDefaultPrintSetupDialog);
1124 _psDefaultPrintSetupDialog = NULL;
1126 _psDefaultPrintSetupDialog = pSetup->dtprintSetup;
1128 XtDestroyWidget(pSetup->dtprintSetup);
1134 * _psPrintSetupCancelCB
1137 _psPrintSetupCancelCB(
1138 Widget dtprintSetup,
1139 XtPointer client_data,
1140 XtPointer call_data)
1142 PrintSetup *pSetup = (PrintSetup*) client_data;
1144 PrintSetupHide(pSetup);
1145 pSetup->cancelCB(dtprintSetup, pSetup->cancelClosure, call_data);
1150 * _psPrintSetupDestroyCB
1153 _psPrintSetupDestroyCB(
1154 Widget dtprintSetup,
1155 XtPointer client_data,
1156 XtPointer call_data)
1160 XtVaGetValues(dtprintSetup, XmNuserData, &widgets, NULL);
1161 XtFree((XtPointer) widgets);
1166 * _psPrintSetupPrintCB
1169 _psPrintSetupPrintCB(
1170 Widget dtprintSetup,
1171 XtPointer client_data,
1172 XtPointer call_data)
1174 PrintSetup *pSetup = (PrintSetup*) client_data;
1175 Boolean error = FALSE;
1177 if (! _psUiSpecsAreValid(pSetup)) return;
1179 PrintSetupHide(pSetup);
1180 _psUiToSetup(pSetup);
1181 _psSetupToSource(pSetup);
1182 pSetup->printCB(dtprintSetup, pSetup->printClosure, call_data);