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 /* $XConsortium: printSetup.c /main/14 1996/10/25 13:37:55 mgreess $ */
24 /**********************************<+>*************************************
25 ***************************************************************************
29 ** Project: HP DT dtpad, a memo maker type editor based on the
32 ** Description: Routines which manipulate the print setup dialog
34 **************************************************************************
35 **********************************<+>*************************************/
37 * Common Desktop Environment
39 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
40 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
41 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
42 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
43 * (c) Copyright 1995 Digital Equipment Corp.
44 * (c) Copyright 1995 Fujitsu Limited
45 * (c) Copyright 1995 Hitachi, Ltd.
48 * RESTRICTED RIGHTS LEGEND
50 *Use, duplication, or disclosure by the U.S. Government is subject to
51 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
52 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
53 *for non-DOD U.S. Government Departments and Agencies are as set forth in
54 *FAR 52.227-19(c)(1,2).
56 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
57 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
58 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
59 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
60 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
61 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
62 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
65 #define REUSE_PRINT_SETUP_DIALOGS
68 #include <sys/param.h>
70 #include <X11/Intrinsic.h>
71 #include <Xm/DialogS.h>
73 #include <Xm/MwmUtil.h>
74 #include <Xm/ToggleB.h>
75 #include <Dt/DtPStrings.h>
76 #include <Dt/HelpDialog.h>
78 #include <Dt/Session.h>
82 static char *_psGetResourceFileName(
84 static void _psSetupToSource(
86 static void _psSourceToSetup(
89 static void _psSetupToUi(
91 static void _psUiToSetup(
93 static Boolean _psUiSpecsAreValid(
95 static void _psAttachPrintSetupDialog(
98 static Widget _psCreatePrintSetupDialog(
101 static void _psPrintSetupCancelCB(
103 XtPointer client_data,
104 XtPointer call_data);
105 static void _psPrintSetupDestroyCB(
107 XtPointer client_data,
108 XtPointer call_data);
109 static void _psPrintSetupPrintCB(
111 XtPointer client_data,
112 XtPointer call_data);
113 static void _psReleasePrintSetupDialog(
116 #define PS_ARRAY_SIZE(ary) (sizeof((ary))/sizeof((ary)[0]))
118 #define PS_HOME_ENV_VARIABLE "HOME"
119 #define PS_DEFAULT_RESOURCE_FILE "dtpadrc"
121 #define PS_RESOURCE_HDRFTR_FORMAT_STRING "Dtpad.%s: %d\n"
122 #define PS_RESOURCE_MARGIN_FORMAT_STRING "Dtpad.%s: %s\n"
124 #define PS_RESOURCE_NAME_HEADER_LEFT "headerLeftEnum"
125 #define PS_RESOURCE_NAME_HEADER_RIGHT "headerRightEnum"
126 #define PS_RESOURCE_NAME_FOOTER_LEFT "footerLeftEnum"
127 #define PS_RESOURCE_NAME_FOOTER_RIGHT "footerRightEnum"
129 #define PS_RESOURCE_NAME_MARGIN_TOP "marginTopSpec"
130 #define PS_RESOURCE_NAME_MARGIN_RIGHT "marginRightSpec"
131 #define PS_RESOURCE_NAME_MARGIN_BOTTOM "marginBottomSpec"
132 #define PS_RESOURCE_NAME_MARGIN_LEFT "marginLeftSpec"
134 #define PS_RESOURCE_VALUE_NONE "Empty"
135 #define PS_RESOURCE_VALUE_DATE "Date"
136 #define PS_RESOURCE_VALUE_DOCNAME "DocName"
137 #define PS_RESOURCE_VALUE_PAGE_NUMBER "PageNumber"
138 #define PS_RESOURCE_VALUE_USER_NAME "UserName"
140 #define PS_RESOURCE_VALUE_DFLT_MARGIN "1.0 in"
142 typedef struct resource_value
144 PrintStringTypeEnum which;
145 char *resource_string;
151 static ResourceValue _psHdrFtrValues[] =
153 { PRINT_NONE_STRING_TYPE_ENUM,
154 PS_RESOURCE_VALUE_NONE,
157 { PRINT_DATE_STRING_TYPE_ENUM,
158 PS_RESOURCE_VALUE_DATE,
161 { PRINT_DOCNAME_STRING_TYPE_ENUM,
162 PS_RESOURCE_VALUE_DOCNAME,
163 15, 3, "Document Name"
165 { PRINT_PAGE_NUMBER_STRING_TYPE_ENUM,
166 PS_RESOURCE_VALUE_PAGE_NUMBER,
169 { PRINT_USER_NAME_STRING_TYPE_ENUM,
170 PS_RESOURCE_VALUE_USER_NAME,
176 static Widget _psDefaultPrintSetupDialog = (Widget) NULL;
177 static char *_psDefaultMargin = PS_RESOURCE_VALUE_DFLT_MARGIN;
179 static XtResource _psResources[] = {
180 {PS_RESOURCE_NAME_FOOTER_LEFT, "FooterLeftEnum", XmRInt, sizeof(int),
181 XtOffset(PrintOptions*, footerLeft),
182 XmRImmediate, (XtPointer) PRINT_NONE_STRING_TYPE_ENUM,
184 {PS_RESOURCE_NAME_FOOTER_RIGHT, "FooterRightEnum", XmRInt, sizeof(int),
185 XtOffset(PrintOptions*, footerRight),
186 XmRImmediate, (XtPointer) PRINT_PAGE_NUMBER_STRING_TYPE_ENUM,
188 {PS_RESOURCE_NAME_HEADER_LEFT, "HeaderLeftEnum", XmRInt, sizeof(int),
189 XtOffset(PrintOptions*, headerLeft),
190 XmRImmediate, (XtPointer) PRINT_NONE_STRING_TYPE_ENUM,
192 {PS_RESOURCE_NAME_HEADER_RIGHT, "HeaderRightEnum", XmRInt, sizeof(int),
193 XtOffset(PrintOptions*, headerRight),
194 XmRImmediate, (XtPointer) PRINT_DOCNAME_STRING_TYPE_ENUM,
196 {PS_RESOURCE_NAME_MARGIN_BOTTOM, "MarginBottomSpec", XmRString, sizeof(String),
197 XtOffset(PrintOptions*, marginBottom),
198 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
200 {PS_RESOURCE_NAME_MARGIN_LEFT, "MarginLeftSpec", XmRString, sizeof(String),
201 XtOffset(PrintOptions*, marginLeft),
202 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
204 {PS_RESOURCE_NAME_MARGIN_RIGHT, "MarginRightSpec", XmRString, sizeof(String),
205 XtOffset(PrintOptions*, marginRight),
206 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
208 {PS_RESOURCE_NAME_MARGIN_TOP, "MarginTopSpec", XmRString, sizeof(String),
209 XtOffset(PrintOptions*, marginTop),
210 XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
215 /************************************************************************
218 * Adds dtpad specific items to the passed print setup box.
219 * The document file name is presented in the bottom work area.
220 ************************************************************************/
227 XtCallbackProc cancelCB, XtPointer cancelClosure,
228 XtCallbackProc closeDisplayCB, XtPointer closeDisplayClosure,
229 XtCallbackProc printCB, XtPointer printClosure,
230 XtCallbackProc setupCB, XtPointer setupClosure
235 unsigned char is_set;
237 Widget *menu_buttons;
243 pSetup = (PrintSetup *) XtMalloc( sizeof(PrintSetup) );
244 pSetup->parent = parent;
245 pSetup->docName = strdup(docName);
246 pSetup->cancelCB = cancelCB;
247 pSetup->closeDisplayCB = closeDisplayCB;
248 pSetup->printCB = printCB;
249 pSetup->setupCB = setupCB;
250 pSetup->cancelClosure = cancelClosure;
251 pSetup->closeDisplayClosure = closeDisplayClosure;
252 pSetup->printClosure = printClosure;
253 pSetup->setupClosure = setupClosure;
256 pSetup->dtprintSetup = (Widget) NULL;
257 pSetup->widgets = (psWidgets *) NULL;
260 * Get the current default values for the app-specific printing options.
262 _psSourceToSetup(pSetup, wordWrap);
265 * Get a print setup dialog.
267 _psAttachPrintSetupDialog(pSetup, pPad);
272 /************************************************************************
275 ************************************************************************/
277 PrintSetupDestroy(PrintSetup *pSetup)
279 if (pSetup == NULL) return;
282 free(pSetup->docName);
283 if (pSetup->dtprintSetup);
284 _psReleasePrintSetupDialog(pSetup);
285 XtFree((char*) pSetup);
288 /************************************************************************
290 * Displays the specified print setup GUI.
291 ************************************************************************/
293 PrintSetupDisplay(PrintSetup *pSetup)
295 if (pSetup == NULL) return;
298 * Initialize the print setup Ui.
300 _psSetupToUi(pSetup);
302 XtManageChild(pSetup->dtprintSetup);
303 XtMapWidget(pSetup->dtprintSetup);
306 /************************************************************************
308 * Hides the specified print setup GUI.
309 ************************************************************************/
311 PrintSetupHide(PrintSetup *pSetup)
313 if (pSetup == NULL) return;
314 if (pSetup->dtprintSetup == NULL) return;
315 XtUnmanageChild(pSetup->dtprintSetup);
316 XtUnmapWidget(pSetup->dtprintSetup);
320 /************************************************************************
321 * PrintSetupGetHdrFtrSpec
322 * Returns the current value of the specified header/footer print option.
323 ************************************************************************/
325 PrintSetupGetHdrFtrSpec(PrintSetup *pSetup, _DtPrintHdrFtrEnum which)
327 PrintStringTypeEnum rtn;
329 if (pSetup == NULL) return PRINT_NONE_STRING_TYPE_ENUM;
332 case DTPRINT_OPTION_HEADER_LEFT:
333 rtn = pSetup->options.headerLeft;
335 case DTPRINT_OPTION_HEADER_RIGHT:
336 rtn = pSetup->options.headerRight;
338 case DTPRINT_OPTION_FOOTER_LEFT:
339 rtn = pSetup->options.footerLeft;
341 case DTPRINT_OPTION_FOOTER_RIGHT:
343 rtn = pSetup->options.footerRight;
349 /************************************************************************
350 * PrintSetupGetMarginSpec
351 * Returns the current value of the specified margin print option.
352 ************************************************************************/
354 PrintSetupGetMarginSpec(PrintSetup *pSetup, _DtPrintMarginEnum which)
358 if (pSetup == NULL) return _psDefaultMargin;
361 case DTPRINT_OPTION_MARGIN_TOP:
362 rtn = pSetup->options.marginTop;
364 case DTPRINT_OPTION_MARGIN_RIGHT:
365 rtn = pSetup->options.marginRight;
367 case DTPRINT_OPTION_MARGIN_BOTTOM:
368 rtn = pSetup->options.marginBottom;
370 case DTPRINT_OPTION_MARGIN_LEFT:
372 rtn = pSetup->options.marginLeft;
378 /************************************************************************
379 * PrintSetupGetDefaultPrintData
380 * Returns the current value of the print data in the pData variable.
381 ************************************************************************/
383 PrintSetupGetDefaultPrintData(PrintSetup *pSetup, DtPrintSetupData *pData)
385 if (pSetup == NULL || pData == NULL) return FALSE;
386 return (DtPRINT_SUCCESS == DtPrintFillSetupData(
387 pSetup->dtprintSetup,
391 /************************************************************************
392 * PrintSetupUseWordWrap
393 * Returns the current value of word wrap print option.
394 ************************************************************************/
396 PrintSetupUseWordWrap(PrintSetup *pSetup)
398 if (pSetup == NULL) return TRUE;
399 return pSetup->options.wordWrap;
404 /*******************************************************************************
405 *******************************************************************************
409 *******************************************************************************
410 ******************************************************************************/
412 /************************************************************************
413 * _psGetResourceFileName
414 ************************************************************************/
416 _psGetResourceFileName(PrintSetup *pSetup)
418 #define BUFFER_SIZE 256
419 extern Widget topLevelWithWmCommand;
420 static char buffer[BUFFER_SIZE];
421 static char *dtpadrc = NULL;
422 char *savePath, *saveFile;
425 return XtNewString("/tmp/dtpadrc");
427 if (dtpadrc != NULL) return XtNewString(dtpadrc);
430 saveFile = PS_DEFAULT_RESOURCE_FILE;
431 if (! DtSessionSavePath(topLevelWithWmCommand, &savePath, &saveFile))
435 getenv(PS_HOME_ENV_VARIABLE),
436 DtPERSONAL_TMP_DIRECTORY,
437 PS_DEFAULT_RESOURCE_FILE);
440 dtpadrc = XtNewString(savePath);
442 return XtNewString(dtpadrc);
446 /************************************************************************
448 ************************************************************************/
450 _psSourceToSetup(PrintSetup *pSetup, Boolean wordWrap)
452 XrmDatabase database;
454 PrintOptions pOption;
456 if (pSetup == NULL) return;
458 dtpadrc = _psGetResourceFileName(pSetup);
459 database = XtDatabase(XtDisplay(pSetup->parent));
460 XrmCombineFileDatabase(dtpadrc, &database, TRUE);
463 /* Get the application resources */
464 XtGetApplicationResources(
465 pSetup->parent, &pOption,
466 _psResources, XtNumber(_psResources),
469 pSetup->options.footerLeft = pOption.footerLeft;
470 pSetup->options.footerRight = pOption.footerRight;
471 pSetup->options.headerLeft = pOption.headerLeft;
472 pSetup->options.headerRight = pOption.headerRight;
473 pSetup->options.marginBottom = XtNewString(pOption.marginBottom);
474 pSetup->options.marginLeft = XtNewString(pOption.marginLeft);
475 pSetup->options.marginRight = XtNewString(pOption.marginRight);
476 pSetup->options.marginTop = XtNewString(pOption.marginTop);
477 pSetup->options.wordWrap = wordWrap;
480 /************************************************************************
482 ************************************************************************/
484 _psSetupToSource(PrintSetup *pSetup)
486 PrintOptions *pOption;
490 if (pSetup == NULL) return;
491 pOption = &pSetup->options;
493 dtpadrc = _psGetResourceFileName(pSetup);
494 fp = fopen(dtpadrc, "wb");
497 /* TBD: Error message. */
500 "_psSetupToSource: Cannot open resource file '%s'\n",
508 PS_RESOURCE_HDRFTR_FORMAT_STRING,
509 PS_RESOURCE_NAME_HEADER_LEFT,
515 PS_RESOURCE_HDRFTR_FORMAT_STRING,
516 PS_RESOURCE_NAME_HEADER_RIGHT,
522 PS_RESOURCE_HDRFTR_FORMAT_STRING,
523 PS_RESOURCE_NAME_FOOTER_LEFT,
529 PS_RESOURCE_HDRFTR_FORMAT_STRING,
530 PS_RESOURCE_NAME_FOOTER_RIGHT,
536 PS_RESOURCE_MARGIN_FORMAT_STRING,
537 PS_RESOURCE_NAME_MARGIN_TOP,
543 PS_RESOURCE_MARGIN_FORMAT_STRING,
544 PS_RESOURCE_NAME_MARGIN_RIGHT,
550 PS_RESOURCE_MARGIN_FORMAT_STRING,
551 PS_RESOURCE_NAME_MARGIN_BOTTOM,
552 pOption->marginBottom
557 PS_RESOURCE_MARGIN_FORMAT_STRING,
558 PS_RESOURCE_NAME_MARGIN_LEFT,
565 /************************************************************************
567 ************************************************************************/
569 _psSetupToUi(PrintSetup *pSetup)
573 PrintOptions *pOption;
575 if (pSetup == NULL ||
576 pSetup->dtprintSetup == NULL ||
577 pSetup->widgets == NULL)
579 pOption = &pSetup->options;
581 isSet = (pOption->wordWrap) ? XmSET : XmUNSET;
582 XtVaSetValues(pSetup->widgets->wordWrapTB, XmNset, isSet, NULL);
584 frame = pSetup->widgets->hdrftrFrame;
585 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_LEFT);
586 _DtPrintSetHdrFtrByData(w, (void*) pOption->headerLeft);
588 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_RIGHT);
589 _DtPrintSetHdrFtrByData(w, (void*) pOption->headerRight);
591 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_LEFT);
592 _DtPrintSetHdrFtrByData(w, (void*) pOption->footerLeft);
594 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_RIGHT);
595 _DtPrintSetHdrFtrByData(w, (void*) pOption->footerRight);
597 frame = pSetup->widgets->marginFrame;
598 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
599 _DtPrintSetMarginSpec(w, pOption->marginTop);
601 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
602 _DtPrintSetMarginSpec(w, pOption->marginRight);
604 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
605 _DtPrintSetMarginSpec(w, pOption->marginBottom);
607 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
608 _DtPrintSetMarginSpec(w, pOption->marginLeft);
611 /************************************************************************
613 ************************************************************************/
615 _psUiToSetup(PrintSetup *pSetup)
619 PrintOptions *pOption;
621 Boolean error = FALSE;
623 if (pSetup == NULL ||
624 pSetup->dtprintSetup == NULL ||
625 pSetup->widgets == NULL)
627 pOption = &pSetup->options;
629 XtVaGetValues(pSetup->widgets->wordWrapTB, XmNset, &isSet, NULL);
630 pOption->wordWrap = (isSet == XmUNSET) ? FALSE : TRUE;
632 frame = pSetup->widgets->hdrftrFrame;
634 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_LEFT);
635 pOption->headerLeft = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
637 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_RIGHT);
638 pOption->headerRight = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
640 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_LEFT);
641 pOption->footerLeft = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
643 w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_RIGHT);
644 pOption->footerRight = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
646 frame = pSetup->widgets->marginFrame;
648 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
649 marginSpec = _DtPrintGetMarginSpec(w);
650 if (pOption->marginTop != NULL)
651 XtFree(pOption->marginTop);
652 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
653 pOption->marginTop = XtNewString(_psDefaultMargin);
655 pOption->marginTop = marginSpec;
657 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
658 marginSpec = _DtPrintGetMarginSpec(w);
659 if (pOption->marginRight != NULL)
660 XtFree(pOption->marginRight);
661 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
662 pOption->marginRight = XtNewString(_psDefaultMargin);
664 pOption->marginRight = marginSpec;
666 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
667 marginSpec = _DtPrintGetMarginSpec(w);
668 if (pOption->marginBottom != NULL)
669 XtFree(pOption->marginBottom);
670 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
671 pOption->marginBottom = XtNewString(_psDefaultMargin);
673 pOption->marginBottom = marginSpec;
675 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
676 marginSpec = _DtPrintGetMarginSpec(w);
677 if (pOption->marginLeft != NULL)
678 XtFree(pOption->marginLeft);
679 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
680 pOption->marginLeft = XtNewString(_psDefaultMargin);
682 pOption->marginLeft = marginSpec;
685 /************************************************************************
687 ************************************************************************/
689 _psUiSpecsAreValid(PrintSetup *pSetup)
693 PrintOptions *pOption;
696 if (pSetup == NULL ||
697 pSetup->dtprintSetup == NULL ||
698 pSetup->widgets == NULL)
700 pOption = &pSetup->options;
702 frame = pSetup->widgets->marginFrame;
704 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
705 marginSpec = _DtPrintGetMarginSpec(w);
706 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
708 XtEnum parseError = FALSE;
710 (void) XmConvertStringToUnits(
711 XtScreenOfObject(pSetup->parent),
722 i18nMsg = GETMESSAGE(15, 6, "Top Margin specifier is invalid: ");
723 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
724 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
725 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
731 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
732 marginSpec = _DtPrintGetMarginSpec(w);
733 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
735 XtEnum parseError = FALSE;
737 (void) XmConvertStringToUnits(
738 XtScreenOfObject(pSetup->parent),
750 GETMESSAGE(15, 7, "Right Margin specifier is invalid: ");
751 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
752 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
753 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
759 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
760 marginSpec = _DtPrintGetMarginSpec(w);
761 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
763 XtEnum parseError = FALSE;
765 (void) XmConvertStringToUnits(
766 XtScreenOfObject(pSetup->parent),
778 GETMESSAGE(15, 8, "Bottom Margin specifier is invalid: ");
779 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
780 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
781 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
787 w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
788 marginSpec = _DtPrintGetMarginSpec(w);
789 if (marginSpec != NULL && strcmp("", marginSpec) != 0)
791 XtEnum parseError = FALSE;
793 (void) XmConvertStringToUnits(
794 XtScreenOfObject(pSetup->parent),
805 i18nMsg = GETMESSAGE(15, 9, "Left Margin specifier is invalid: ");
806 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
807 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
808 Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
819 * _psAttachPrintSetupDialog
820 * Creates the widgets for the Setup Dialog.
823 _psAttachPrintSetupDialog(PrintSetup *pSetup, Editor *pPad)
825 char *title, *titlePrefix, *titleParent;
828 unsigned char is_set;
830 #ifdef REUSE_PRINT_SETUP_DIALOGS
831 if (_psDefaultPrintSetupDialog != NULL)
834 * Attempt to reuse the last print setup and print display connection.
836 pSetup->dtprintSetup = _psDefaultPrintSetupDialog;
837 _psDefaultPrintSetupDialog = NULL;
844 pSetup->dtprintSetup = _psCreatePrintSetupDialog(pSetup->parent, pPad);
845 dirname = getenv("HOME");
848 char path[MAXPATHLEN+1];
851 filename = strrchr(pSetup->docName, '/');
852 if (NULL == filename)
853 filename = pSetup->docName;
856 sprintf(path, "%s/%s.ps", dirname, filename);
857 XtVaSetValues(pSetup->dtprintSetup, DtNfileName, path, NULL);
862 * Copy the information about the widgets into the setup.
864 XtVaGetValues(pSetup->dtprintSetup, XmNuserData, &pSetup->widgets, NULL);
867 * Add the setup-specific callbacks.
870 pSetup->dtprintSetup,
872 _psPrintSetupCancelCB,
875 pSetup->dtprintSetup,
876 DtNclosePrintDisplayCallback,
877 pSetup->closeDisplayCB,
878 (XtPointer) pSetup->closeDisplayClosure);
880 pSetup->dtprintSetup,
882 _psPrintSetupPrintCB,
885 pSetup->dtprintSetup,
888 (XtPointer) pSetup->setupClosure);
890 xms = XmStringCreateLocalized(pSetup->docName);
891 XtVaSetValues(pSetup->widgets->docNameLabel, XmNlabelString, xms, NULL);
894 dialog = XtParent(pSetup->widgets->dtprintSetup);
895 if (NULL != dialog && XtIsShell(dialog))
897 titleParent = (char*) GETMESSAGE(7, 2, "Text Editor - ");
898 titlePrefix = (char*) GETMESSAGE(14, 23, "Print Setup - ");
900 (char*) XtMalloc(strlen(titleParent) + strlen(titlePrefix) + strlen(pSetup->docName) + 1);
901 sprintf(title, "%s%s%s", titleParent, titlePrefix, pSetup->docName);
902 XtVaSetValues(dialog, XmNtitle, title, NULL);
907 fprintf(stderr, "Print Setup box is not parented to a shell\n");
910 is_set = (pSetup->options.wordWrap) ? XmSET : XmUNSET;
911 XtVaSetValues(pSetup->widgets->wordWrapTB, XmNset, is_set, NULL);
916 * _psCreatePrintSetupDialog
917 * Creates the widgets for the Setup Dialog.
920 _psCreatePrintSetupDialog(Widget parent, Editor *pPad)
927 unsigned char is_set;
934 * Create the widgets for the Setup Dialog.
936 widgets = (psWidgets *) XtMalloc(sizeof(psWidgets));
939 * Create the DtPrintSetupDialog and specify that the application
940 * specific area be located below the generic area.
943 XtSetArg(args[nargs], XmNautoUnmanage, FALSE); nargs++;
944 widgets->dtprintSetup =
945 DtCreatePrintSetupDialog(parent, "DtPrintSetup", args, nargs);
948 widgets->dtprintSetup,
949 DtNworkAreaLocation, DtWORK_AREA_BOTTOM,
950 XmNuserData, widgets,
954 widgets->dtprintSetup,
956 HelpPrintSetupDialogCB,
960 widgets->dtprintSetup,
962 _psPrintSetupDestroyCB,
963 (XtPointer) widgets);
965 * Create the dtpad-specific setup dialog in the bottom work area
967 widgets->form = XtVaCreateManagedWidget(
970 widgets->dtprintSetup,
976 HelpPrintSetupAppSpecificCB,
980 * Create the document name title label
982 xms = XmStringCreateLocalized( GETMESSAGE(14, 12, "Document Name: ") );
983 widgets->docLabel = XtVaCreateManagedWidget(
987 XmNleftAttachment, XmATTACH_FORM,
988 XmNtopAttachment, XmATTACH_FORM,
994 * Create the document name label
996 widgets->docNameLabel = XtVaCreateManagedWidget(
1000 XmNleftAttachment, XmATTACH_WIDGET,
1001 XmNleftWidget, widgets->docLabel,
1003 XmNrightAttachment, XmATTACH_FORM,
1005 XmNtopAttachment, XmATTACH_FORM,
1008 xms = XmStringCreateLocalized(GETMESSAGE(14, 13, "Wrap To Fit"));
1009 widgets->wordWrapTB = XtVaCreateManagedWidget(
1011 xmToggleButtonWidgetClass,
1013 XmNalignment, XmALIGNMENT_BEGINNING,
1014 XmNlabelString, xms,
1015 XmNleftAttachment, XmATTACH_FORM,
1016 XmNrightAttachment, XmATTACH_FORM,
1017 XmNtopAttachment, XmATTACH_WIDGET,
1018 XmNtopWidget, widgets->docLabel,
1023 * Create GUI for the Header/Footer options
1025 nitems = PS_ARRAY_SIZE(_psHdrFtrValues);
1026 strings = (char **) XtMalloc( nitems * sizeof(char*) );
1027 data = (void **) XtMalloc( nitems * sizeof(void*) );
1028 for (i=0; i<nitems; i++)
1030 data[i] = (void*) _psHdrFtrValues[i].which;
1031 strings[i] = GETMESSAGE(
1032 _psHdrFtrValues[i].set_id,
1033 _psHdrFtrValues[i].msg_id,
1034 _psHdrFtrValues[i].dflt_string
1040 * Create GUI for the Header/Footer options
1042 widgets->hdrftrFrame =
1043 _DtPrintCreateHdrFtrFrame(widgets->form, nitems, strings, data);
1045 widgets->hdrftrFrame,
1046 XmNtopAttachment, XmATTACH_WIDGET,
1047 XmNtopWidget, widgets->wordWrapTB,
1048 XmNleftAttachment, XmATTACH_FORM,
1050 XtManageChild(widgets->hdrftrFrame);
1053 * Create GUI for the Margin options
1055 widgets->marginFrame = _DtPrintCreateMarginFrame(widgets->form);
1057 widgets->marginFrame,
1058 XmNtopAttachment, XmATTACH_WIDGET,
1059 XmNtopWidget, widgets->hdrftrFrame,
1060 XmNleftAttachment, XmATTACH_FORM,
1062 XtManageChild(widgets->marginFrame);
1065 * Create GUI for the Margin options
1067 widgets->marginFrame = _DtPrintCreateMarginFrame(widgets->form);
1069 widgets->marginFrame,
1070 XmNtopAttachment, XmATTACH_WIDGET,
1071 XmNtopWidget, widgets->wordWrapTB,
1072 XmNleftAttachment, XmATTACH_FORM,
1074 XtManageChild(widgets->marginFrame);
1077 * Create GUI for the Header/Footer options
1079 widgets->hdrftrFrame =
1080 _DtPrintCreateHdrFtrFrame(widgets->form, nitems, strings, data);
1082 widgets->hdrftrFrame,
1083 XmNtopAttachment, XmATTACH_WIDGET,
1084 XmNtopWidget, widgets->wordWrapTB,
1085 XmNtopWidget, widgets->marginFrame,
1086 XmNleftAttachment, XmATTACH_FORM,
1088 XtManageChild(widgets->hdrftrFrame);
1092 widgets->hdrftrFrame,
1094 HelpPrintSetupPageHeadersFootersCB,
1098 widgets->marginFrame,
1100 HelpPrintSetupPageMargins,
1103 XtRealizeWidget(widgets->dtprintSetup);
1104 return widgets->dtprintSetup;
1109 * _psReleasePrintSetupDialog
1110 * Removes setup-specific callbacks.
1113 _psReleasePrintSetupDialog(PrintSetup *pSetup)
1116 * Remove the setup-specific callbacks.
1119 pSetup->dtprintSetup,
1121 _psPrintSetupCancelCB,
1122 (XtPointer) pSetup);
1124 pSetup->dtprintSetup,
1125 DtNclosePrintDisplayCallback,
1126 pSetup->closeDisplayCB,
1127 (XtPointer) pSetup->closeDisplayClosure);
1129 pSetup->dtprintSetup,
1131 _psPrintSetupPrintCB,
1132 (XtPointer) pSetup);
1134 pSetup->dtprintSetup,
1137 (XtPointer) pSetup->setupClosure);
1139 #ifdef REUSE_PRINT_SETUP_DIALOGS
1140 if (_psDefaultPrintSetupDialog != NULL)
1143 * Attempt to reuse the last print setup and print display connection.
1145 XtDestroyWidget(_psDefaultPrintSetupDialog);
1146 _psDefaultPrintSetupDialog = NULL;
1148 _psDefaultPrintSetupDialog = pSetup->dtprintSetup;
1150 XtDestroyWidget(pSetup->dtprintSetup);
1156 * _psPrintSetupCancelCB
1159 _psPrintSetupCancelCB(
1160 Widget dtprintSetup,
1161 XtPointer client_data,
1162 XtPointer call_data)
1164 PrintSetup *pSetup = (PrintSetup*) client_data;
1166 PrintSetupHide(pSetup);
1167 pSetup->cancelCB(dtprintSetup, pSetup->cancelClosure, call_data);
1172 * _psPrintSetupDestroyCB
1175 _psPrintSetupDestroyCB(
1176 Widget dtprintSetup,
1177 XtPointer client_data,
1178 XtPointer call_data)
1182 XtVaGetValues(dtprintSetup, XmNuserData, &widgets, NULL);
1183 XtFree((XtPointer) widgets);
1188 * _psPrintSetupPrintCB
1191 _psPrintSetupPrintCB(
1192 Widget dtprintSetup,
1193 XtPointer client_data,
1194 XtPointer call_data)
1196 PrintSetup *pSetup = (PrintSetup*) client_data;
1197 Boolean error = FALSE;
1199 if (! _psUiSpecsAreValid(pSetup)) return;
1201 PrintSetupHide(pSetup);
1202 _psUiToSetup(pSetup);
1203 _psSetupToSource(pSetup);
1204 pSetup->printCB(dtprintSetup, pSetup->printClosure, call_data);