1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: printSetup.c /main/14 1996/10/25 13:37:55 mgreess $ */
- /**********************************<+>*************************************
- ***************************************************************************
- **
- ** File: printSetup.c
- **
- ** Project: HP DT dtpad, a memo maker type editor based on the
- ** Dt Editor widget.
- **
- ** Description: Routines which manipulate the print setup dialog
- **
- **************************************************************************
- **********************************<+>*************************************/
- /*
- * Common Desktop Environment
- *
- * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
- * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
- * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
- * (c) Copyright 1993, 1994, 1995 Novell, Inc.
- * (c) Copyright 1995 Digital Equipment Corp.
- * (c) Copyright 1995 Fujitsu Limited
- * (c) Copyright 1995 Hitachi, Ltd.
- *
- *
- * RESTRICTED RIGHTS LEGEND
- *
- *Use, duplication, or disclosure by the U.S. Government is subject to
- *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
- *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
- *for non-DOD U.S. Government Departments and Agencies are as set forth in
- *FAR 52.227-19(c)(1,2).
- *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
- *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
- *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
- *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
- *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
- *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
- *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
- */
- #define REUSE_PRINT_SETUP_DIALOGS
- #include <stdio.h>
- #include <sys/param.h>
- #include <X11/Intrinsic.h>
- #include <Xm/DialogS.h>
- #include <Xm/Form.h>
- #include <Xm/MwmUtil.h>
- #include <Xm/ToggleB.h>
- #include <Dt/DtPStrings.h>
- #include <Dt/HelpDialog.h>
- #include <Dt/Print.h>
- #include <Dt/Session.h>
- #include "dtpad.h"
- static char *_psGetResourceFileName(
- PrintSetup *pSetup);
- static void _psSetupToSource(
- PrintSetup *pSetup);
- static void _psSourceToSetup(
- PrintSetup *pSetup,
- Boolean wordWrap);
- static void _psSetupToUi(
- PrintSetup *pSetup);
- static void _psUiToSetup(
- PrintSetup *pSetup);
- static Boolean _psUiSpecsAreValid(
- PrintSetup *pSetup);
- static void _psAttachPrintSetupDialog(
- PrintSetup *pSetup,
- Editor *pPad);
- static Widget _psCreatePrintSetupDialog(
- Widget parent,
- Editor *pPad);
- static void _psPrintSetupCancelCB(
- Widget dtprintSetup,
- XtPointer client_data,
- XtPointer call_data);
- static void _psPrintSetupDestroyCB(
- Widget dtprintSetup,
- XtPointer client_data,
- XtPointer call_data);
- static void _psPrintSetupPrintCB(
- Widget dtprintSetup,
- XtPointer client_data,
- XtPointer call_data);
- static void _psReleasePrintSetupDialog(
- PrintSetup *pSetup);
- #define PS_ARRAY_SIZE(ary) (sizeof((ary))/sizeof((ary)[0]))
- #define PS_HOME_ENV_VARIABLE "HOME"
- #define PS_DEFAULT_RESOURCE_FILE "dtpadrc"
- #define PS_RESOURCE_HDRFTR_FORMAT_STRING "Dtpad.%s: %d\n"
- #define PS_RESOURCE_MARGIN_FORMAT_STRING "Dtpad.%s: %s\n"
- #define PS_RESOURCE_NAME_HEADER_LEFT "headerLeftEnum"
- #define PS_RESOURCE_NAME_HEADER_RIGHT "headerRightEnum"
- #define PS_RESOURCE_NAME_FOOTER_LEFT "footerLeftEnum"
- #define PS_RESOURCE_NAME_FOOTER_RIGHT "footerRightEnum"
- #define PS_RESOURCE_NAME_MARGIN_TOP "marginTopSpec"
- #define PS_RESOURCE_NAME_MARGIN_RIGHT "marginRightSpec"
- #define PS_RESOURCE_NAME_MARGIN_BOTTOM "marginBottomSpec"
- #define PS_RESOURCE_NAME_MARGIN_LEFT "marginLeftSpec"
- #define PS_RESOURCE_VALUE_NONE "Empty"
- #define PS_RESOURCE_VALUE_DATE "Date"
- #define PS_RESOURCE_VALUE_DOCNAME "DocName"
- #define PS_RESOURCE_VALUE_PAGE_NUMBER "PageNumber"
- #define PS_RESOURCE_VALUE_USER_NAME "UserName"
- #define PS_RESOURCE_VALUE_DFLT_MARGIN "1.0 in"
- typedef struct resource_value
- {
- PrintStringTypeEnum which;
- char *resource_string;
- int set_id;
- int msg_id;
- char *dflt_string;
- } ResourceValue;
- static ResourceValue _psHdrFtrValues[] =
- {
- { PRINT_NONE_STRING_TYPE_ENUM,
- PS_RESOURCE_VALUE_NONE,
- 15, 1, "None"
- },
- { PRINT_DATE_STRING_TYPE_ENUM,
- PS_RESOURCE_VALUE_DATE,
- 15, 2, "Date"
- },
- { PRINT_DOCNAME_STRING_TYPE_ENUM,
- PS_RESOURCE_VALUE_DOCNAME,
- 15, 3, "Document Name"
- },
- { PRINT_PAGE_NUMBER_STRING_TYPE_ENUM,
- PS_RESOURCE_VALUE_PAGE_NUMBER,
- 15, 4, "Page Number"
- },
- { PRINT_USER_NAME_STRING_TYPE_ENUM,
- PS_RESOURCE_VALUE_USER_NAME,
- 15, 5, "User Name"
- }
- };
-
- static Widget _psDefaultPrintSetupDialog = (Widget) NULL;
- static char *_psDefaultMargin = PS_RESOURCE_VALUE_DFLT_MARGIN;
- static XtResource _psResources[] = {
- {PS_RESOURCE_NAME_FOOTER_LEFT, "FooterLeftEnum", XmRInt, sizeof(int),
- XtOffset(PrintOptions*, footerLeft),
- XmRImmediate, (XtPointer) PRINT_NONE_STRING_TYPE_ENUM,
- },
- {PS_RESOURCE_NAME_FOOTER_RIGHT, "FooterRightEnum", XmRInt, sizeof(int),
- XtOffset(PrintOptions*, footerRight),
- XmRImmediate, (XtPointer) PRINT_PAGE_NUMBER_STRING_TYPE_ENUM,
- },
- {PS_RESOURCE_NAME_HEADER_LEFT, "HeaderLeftEnum", XmRInt, sizeof(int),
- XtOffset(PrintOptions*, headerLeft),
- XmRImmediate, (XtPointer) PRINT_NONE_STRING_TYPE_ENUM,
- },
- {PS_RESOURCE_NAME_HEADER_RIGHT, "HeaderRightEnum", XmRInt, sizeof(int),
- XtOffset(PrintOptions*, headerRight),
- XmRImmediate, (XtPointer) PRINT_DOCNAME_STRING_TYPE_ENUM,
- },
- {PS_RESOURCE_NAME_MARGIN_BOTTOM, "MarginBottomSpec", XmRString, sizeof(String),
- XtOffset(PrintOptions*, marginBottom),
- XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
- },
- {PS_RESOURCE_NAME_MARGIN_LEFT, "MarginLeftSpec", XmRString, sizeof(String),
- XtOffset(PrintOptions*, marginLeft),
- XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
- },
- {PS_RESOURCE_NAME_MARGIN_RIGHT, "MarginRightSpec", XmRString, sizeof(String),
- XtOffset(PrintOptions*, marginRight),
- XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
- },
- {PS_RESOURCE_NAME_MARGIN_TOP, "MarginTopSpec", XmRString, sizeof(String),
- XtOffset(PrintOptions*, marginTop),
- XmRString, (XtPointer) PS_RESOURCE_VALUE_DFLT_MARGIN,
- }
- };
- /************************************************************************
- * PrintSetupCreate
- * Class constructor.
- * Adds dtpad specific items to the passed print setup box.
- * The document file name is presented in the bottom work area.
- ************************************************************************/
- PrintSetup *
- PrintSetupCreate(
- Widget parent,
- char *docName,
- Boolean wordWrap,
- Editor *pPad,
- XtCallbackProc cancelCB, XtPointer cancelClosure,
- XtCallbackProc closeDisplayCB, XtPointer closeDisplayClosure,
- XtCallbackProc printCB, XtPointer printClosure,
- XtCallbackProc setupCB, XtPointer setupClosure
- )
- {
- Widget w;
- XmString xms;
- unsigned char is_set;
- PrintSetup *pSetup;
- Widget *menu_buttons;
- int nitems;
- char **strings;
- void **data;
- int i;
- pSetup = (PrintSetup *) XtMalloc( sizeof(PrintSetup) );
- pSetup->parent = parent;
- pSetup->docName = strdup(docName);
- pSetup->cancelCB = cancelCB;
- pSetup->closeDisplayCB = closeDisplayCB;
- pSetup->printCB = printCB;
- pSetup->setupCB = setupCB;
- pSetup->cancelClosure = cancelClosure;
- pSetup->closeDisplayClosure = closeDisplayClosure;
- pSetup->printClosure = printClosure;
- pSetup->setupClosure = setupClosure;
- pSetup->pPad = pPad;
- pSetup->dtprintSetup = (Widget) NULL;
- pSetup->widgets = (psWidgets *) NULL;
- /*
- * Get the current default values for the app-specific printing options.
- */
- _psSourceToSetup(pSetup, wordWrap);
- /*
- * Get a print setup dialog.
- */
- _psAttachPrintSetupDialog(pSetup, pPad);
- return pSetup;
- }
- /************************************************************************
- * PrintSetupDestroy
- * Class destructor.
- ************************************************************************/
- void
- PrintSetupDestroy(PrintSetup *pSetup)
- {
- if (pSetup == NULL) return;
- if (pSetup->docName)
- free(pSetup->docName);
- if (pSetup->dtprintSetup)
- _psReleasePrintSetupDialog(pSetup);
- XtFree((char*) pSetup);
- }
- /************************************************************************
- * PrintSetupDisplay
- * Displays the specified print setup GUI.
- ************************************************************************/
- void
- PrintSetupDisplay(PrintSetup *pSetup)
- {
- if (pSetup == NULL) return;
- /*
- * Initialize the print setup Ui.
- */
- _psSetupToUi(pSetup);
- XtManageChild(pSetup->dtprintSetup);
- XtMapWidget(pSetup->dtprintSetup);
- }
- /************************************************************************
- * PrintSetupHide
- * Hides the specified print setup GUI.
- ************************************************************************/
- void
- PrintSetupHide(PrintSetup *pSetup)
- {
- if (pSetup == NULL) return;
- if (pSetup->dtprintSetup == NULL) return;
- XtUnmanageChild(pSetup->dtprintSetup);
- XtUnmapWidget(pSetup->dtprintSetup);
- }
- /************************************************************************
- * PrintSetupGetHdrFtrSpec
- * Returns the current value of the specified header/footer print option.
- ************************************************************************/
- PrintStringTypeEnum
- PrintSetupGetHdrFtrSpec(PrintSetup *pSetup, _DtPrintHdrFtrEnum which)
- {
- PrintStringTypeEnum rtn;
- if (pSetup == NULL) return PRINT_NONE_STRING_TYPE_ENUM;
- switch (which)
- {
- case DTPRINT_OPTION_HEADER_LEFT:
- rtn = pSetup->options.headerLeft;
- break;
- case DTPRINT_OPTION_HEADER_RIGHT:
- rtn = pSetup->options.headerRight;
- break;
- case DTPRINT_OPTION_FOOTER_LEFT:
- rtn = pSetup->options.footerLeft;
- break;
- case DTPRINT_OPTION_FOOTER_RIGHT:
- default:
- rtn = pSetup->options.footerRight;
- break;
- }
- return rtn;
- }
- /************************************************************************
- * PrintSetupGetMarginSpec
- * Returns the current value of the specified margin print option.
- ************************************************************************/
- char *
- PrintSetupGetMarginSpec(PrintSetup *pSetup, _DtPrintMarginEnum which)
- {
- char *rtn;
- if (pSetup == NULL) return _psDefaultMargin;
- switch (which)
- {
- case DTPRINT_OPTION_MARGIN_TOP:
- rtn = pSetup->options.marginTop;
- break;
- case DTPRINT_OPTION_MARGIN_RIGHT:
- rtn = pSetup->options.marginRight;
- break;
- case DTPRINT_OPTION_MARGIN_BOTTOM:
- rtn = pSetup->options.marginBottom;
- break;
- case DTPRINT_OPTION_MARGIN_LEFT:
- default:
- rtn = pSetup->options.marginLeft;
- break;
- }
- return rtn;
- }
- /************************************************************************
- * PrintSetupGetDefaultPrintData
- * Returns the current value of the print data in the pData variable.
- ************************************************************************/
- Boolean
- PrintSetupGetDefaultPrintData(PrintSetup *pSetup, DtPrintSetupData *pData)
- {
- if (pSetup == NULL || pData == NULL) return FALSE;
- return (DtPRINT_SUCCESS == DtPrintFillSetupData(
- pSetup->dtprintSetup,
- pData));
- }
- /************************************************************************
- * PrintSetupUseWordWrap
- * Returns the current value of word wrap print option.
- ************************************************************************/
- Boolean
- PrintSetupUseWordWrap(PrintSetup *pSetup)
- {
- if (pSetup == NULL) return TRUE;
- return pSetup->options.wordWrap;
- }
- /*******************************************************************************
- *******************************************************************************
- *
- * Static Functions
- *
- *******************************************************************************
- ******************************************************************************/
- /************************************************************************
- * _psGetResourceFileName
- ************************************************************************/
- static char*
- _psGetResourceFileName(PrintSetup *pSetup)
- {
- #define BUFFER_SIZE 256
- extern Widget topLevelWithWmCommand;
- static char buffer[BUFFER_SIZE];
- static char *dtpadrc = NULL;
- char *savePath, *saveFile;
- if (dtpadrc != NULL) return XtNewString(dtpadrc);
- savePath = NULL;
- saveFile = PS_DEFAULT_RESOURCE_FILE;
- if (! DtSessionSavePath(topLevelWithWmCommand, &savePath, &saveFile))
- {
- snprintf(
- buffer, sizeof(buffer), "%s/%s/%s",
- getenv(PS_HOME_ENV_VARIABLE),
- DtPERSONAL_TMP_DIRECTORY,
- PS_DEFAULT_RESOURCE_FILE);
- savePath = buffer;
- }
- dtpadrc = XtNewString(savePath);
- return XtNewString(dtpadrc);
- }
- /************************************************************************
- * _psSourceToSetup
- ************************************************************************/
- static void
- _psSourceToSetup(PrintSetup *pSetup, Boolean wordWrap)
- {
- XrmDatabase database;
- char *dtpadrc;
- PrintOptions pOption;
- if (pSetup == NULL) return;
- dtpadrc = _psGetResourceFileName(pSetup);
- database = XtDatabase(XtDisplay(pSetup->parent));
- XrmCombineFileDatabase(dtpadrc, &database, TRUE);
- XtFree(dtpadrc);
- /* Get the application resources */
- XtGetApplicationResources(
- pSetup->parent, &pOption,
- _psResources, XtNumber(_psResources),
- NULL, 0);
- pSetup->options.footerLeft = pOption.footerLeft;
- pSetup->options.footerRight = pOption.footerRight;
- pSetup->options.headerLeft = pOption.headerLeft;
- pSetup->options.headerRight = pOption.headerRight;
- pSetup->options.marginBottom = XtNewString(pOption.marginBottom);
- pSetup->options.marginLeft = XtNewString(pOption.marginLeft);
- pSetup->options.marginRight = XtNewString(pOption.marginRight);
- pSetup->options.marginTop = XtNewString(pOption.marginTop);
- pSetup->options.wordWrap = wordWrap;
- }
- /************************************************************************
- * _psSetupToSource
- ************************************************************************/
- static void
- _psSetupToSource(PrintSetup *pSetup)
- {
- PrintOptions *pOption;
- FILE *fp;
- char *dtpadrc;
- if (pSetup == NULL) return;
- pOption = &pSetup->options;
- dtpadrc = _psGetResourceFileName(pSetup);
- fp = fopen(dtpadrc, "wb");
- if (fp == NULL)
- {
- /* TBD: Error message. */
- fprintf(
- stderr,
- "_psSetupToSource: Cannot open resource file '%s'\n",
- dtpadrc);
- return;
- }
- XtFree(dtpadrc);
- fprintf(
- fp,
- PS_RESOURCE_HDRFTR_FORMAT_STRING,
- PS_RESOURCE_NAME_HEADER_LEFT,
- pOption->headerLeft
- );
- fprintf(
- fp,
- PS_RESOURCE_HDRFTR_FORMAT_STRING,
- PS_RESOURCE_NAME_HEADER_RIGHT,
- pOption->headerRight
- );
- fprintf(
- fp,
- PS_RESOURCE_HDRFTR_FORMAT_STRING,
- PS_RESOURCE_NAME_FOOTER_LEFT,
- pOption->footerLeft
- );
- fprintf(
- fp,
- PS_RESOURCE_HDRFTR_FORMAT_STRING,
- PS_RESOURCE_NAME_FOOTER_RIGHT,
- pOption->footerRight
- );
- fprintf(
- fp,
- PS_RESOURCE_MARGIN_FORMAT_STRING,
- PS_RESOURCE_NAME_MARGIN_TOP,
- pOption->marginTop
- );
- fprintf(
- fp,
- PS_RESOURCE_MARGIN_FORMAT_STRING,
- PS_RESOURCE_NAME_MARGIN_RIGHT,
- pOption->marginRight
- );
- fprintf(
- fp,
- PS_RESOURCE_MARGIN_FORMAT_STRING,
- PS_RESOURCE_NAME_MARGIN_BOTTOM,
- pOption->marginBottom
- );
- fprintf(
- fp,
- PS_RESOURCE_MARGIN_FORMAT_STRING,
- PS_RESOURCE_NAME_MARGIN_LEFT,
- pOption->marginLeft
- );
-
- fclose(fp);
- }
- /************************************************************************
- * _psSetupToUi
- ************************************************************************/
- static void
- _psSetupToUi(PrintSetup *pSetup)
- {
- unsigned char isSet;
- Widget frame, w;
- PrintOptions *pOption;
- if (pSetup == NULL ||
- pSetup->dtprintSetup == NULL ||
- pSetup->widgets == NULL)
- return;
- pOption = &pSetup->options;
- isSet = (pOption->wordWrap) ? XmSET : XmUNSET;
- XtVaSetValues(pSetup->widgets->wordWrapTB, XmNset, isSet, NULL);
- frame = pSetup->widgets->hdrftrFrame;
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_LEFT);
- _DtPrintSetHdrFtrByData(w, (void*) pOption->headerLeft);
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_RIGHT);
- _DtPrintSetHdrFtrByData(w, (void*) pOption->headerRight);
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_LEFT);
- _DtPrintSetHdrFtrByData(w, (void*) pOption->footerLeft);
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_RIGHT);
- _DtPrintSetHdrFtrByData(w, (void*) pOption->footerRight);
- frame = pSetup->widgets->marginFrame;
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
- _DtPrintSetMarginSpec(w, pOption->marginTop);
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
- _DtPrintSetMarginSpec(w, pOption->marginRight);
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
- _DtPrintSetMarginSpec(w, pOption->marginBottom);
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
- _DtPrintSetMarginSpec(w, pOption->marginLeft);
- }
- /************************************************************************
- * _psUiToSetup
- ************************************************************************/
- static void
- _psUiToSetup(PrintSetup *pSetup)
- {
- XtArgVal isSet;
- Widget frame, w;
- PrintOptions *pOption;
- char *marginSpec;
- Boolean error = FALSE;
- if (pSetup == NULL ||
- pSetup->dtprintSetup == NULL ||
- pSetup->widgets == NULL)
- return;
- pOption = &pSetup->options;
- XtVaGetValues(pSetup->widgets->wordWrapTB, XmNset, &isSet, NULL);
- pOption->wordWrap = (isSet == XmUNSET) ? FALSE : TRUE;
- frame = pSetup->widgets->hdrftrFrame;
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_LEFT);
- pOption->headerLeft = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_HEADER_RIGHT);
- pOption->headerRight = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_LEFT);
- pOption->footerLeft = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
- w = _DtPrintHdrFtrFrameEnumToWidget(frame, DTPRINT_OPTION_FOOTER_RIGHT);
- pOption->footerRight = (PrintStringTypeEnum) _DtPrintGetHdrFtrData(w);
- frame = pSetup->widgets->marginFrame;
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (pOption->marginTop != NULL)
- XtFree(pOption->marginTop);
- if (marginSpec == NULL || strcmp("", marginSpec) == 0)
- pOption->marginTop = XtNewString(_psDefaultMargin);
- else
- pOption->marginTop = marginSpec;
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (pOption->marginRight != NULL)
- XtFree(pOption->marginRight);
- if (marginSpec == NULL || strcmp("", marginSpec) == 0)
- pOption->marginRight = XtNewString(_psDefaultMargin);
- else
- pOption->marginRight = marginSpec;
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (pOption->marginBottom != NULL)
- XtFree(pOption->marginBottom);
- if (marginSpec == NULL || strcmp("", marginSpec) == 0)
- pOption->marginBottom = XtNewString(_psDefaultMargin);
- else
- pOption->marginBottom = marginSpec;
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (pOption->marginLeft != NULL)
- XtFree(pOption->marginLeft);
- if (marginSpec == NULL || strcmp("", marginSpec) == 0)
- pOption->marginLeft = XtNewString(_psDefaultMargin);
- else
- pOption->marginLeft = marginSpec;
- }
- /************************************************************************
- * _psUiSpecsAreValid
- ************************************************************************/
- static Boolean
- _psUiSpecsAreValid(PrintSetup *pSetup)
- {
- unsigned char isSet;
- Widget frame, w;
- PrintOptions *pOption;
- char *marginSpec;
- if (pSetup == NULL ||
- pSetup->dtprintSetup == NULL ||
- pSetup->widgets == NULL)
- return 0;
- pOption = &pSetup->options;
- frame = pSetup->widgets->marginFrame;
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_TOP);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (marginSpec != NULL && strcmp("", marginSpec) != 0)
- {
- XtEnum parseError = FALSE;
- (void) XmConvertStringToUnits(
- XtScreenOfObject(pSetup->parent),
- marginSpec,
- XmVERTICAL,
- XmPIXELS,
- &parseError);
- if (parseError)
- {
- char *i18nMsg;
- char *errMsg;
-
- i18nMsg = GETMESSAGE(15, 6, "Top Margin specifier is invalid: ");
- errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
- sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
- Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
- XtFree(errMsg);
- return FALSE;
- }
- }
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_RIGHT);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (marginSpec != NULL && strcmp("", marginSpec) != 0)
- {
- XtEnum parseError = FALSE;
- (void) XmConvertStringToUnits(
- XtScreenOfObject(pSetup->parent),
- marginSpec,
- XmHORIZONTAL,
- XmPIXELS,
- &parseError);
- if (parseError)
- {
- char *i18nMsg;
- char *errMsg;
-
- i18nMsg =
- GETMESSAGE(15, 7, "Right Margin specifier is invalid: ");
- errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
- sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
- Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
- XtFree(errMsg);
- return FALSE;
- }
- }
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_BOTTOM);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (marginSpec != NULL && strcmp("", marginSpec) != 0)
- {
- XtEnum parseError = FALSE;
- (void) XmConvertStringToUnits(
- XtScreenOfObject(pSetup->parent),
- marginSpec,
- XmVERTICAL,
- XmPIXELS,
- &parseError);
- if (parseError)
- {
- char *i18nMsg;
- char *errMsg;
-
- i18nMsg =
- GETMESSAGE(15, 8, "Bottom Margin specifier is invalid: ");
- errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
- sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
- Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
- XtFree(errMsg);
- return FALSE;
- }
- }
- w = _DtPrintMarginFrameEnumToWidget(frame, DTPRINT_OPTION_MARGIN_LEFT);
- marginSpec = _DtPrintGetMarginSpec(w);
- if (marginSpec != NULL && strcmp("", marginSpec) != 0)
- {
- XtEnum parseError = FALSE;
- (void) XmConvertStringToUnits(
- XtScreenOfObject(pSetup->parent),
- marginSpec,
- XmHORIZONTAL,
- XmPIXELS,
- &parseError);
- if (parseError)
- {
- char *i18nMsg;
- char *errMsg;
-
- i18nMsg = GETMESSAGE(15, 9, "Left Margin specifier is invalid: ");
- errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
- sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
- Warning(pSetup->pPad, (char *) errMsg, XmDIALOG_WARNING);
- XtFree(errMsg);
- return FALSE;
- }
- }
- return TRUE;
- }
- /*
- * _psAttachPrintSetupDialog
- * Creates the widgets for the Setup Dialog.
- */
- static void
- _psAttachPrintSetupDialog(PrintSetup *pSetup, Editor *pPad)
- {
- char *title, *titlePrefix, *titleParent;
- XmString xms;
- Widget dialog;
- unsigned char is_set;
- #ifdef REUSE_PRINT_SETUP_DIALOGS
- if (_psDefaultPrintSetupDialog != NULL)
- {
- /*
- * Attempt to reuse the last print setup and print display connection.
- */
- pSetup->dtprintSetup = _psDefaultPrintSetupDialog;
- _psDefaultPrintSetupDialog = NULL;
- }
- else
- #endif
- {
- char *dirname;
- pSetup->dtprintSetup = _psCreatePrintSetupDialog(pSetup->parent, pPad);
- dirname = getenv("HOME");
- if (dirname)
- {
- char path[MAXPATHLEN+1];
- char *filename;
- filename = strrchr(pSetup->docName, '/');
- if (NULL == filename)
- filename = pSetup->docName;
- else
- filename++;
- snprintf(path, sizeof(path), "%s/%s.ps", dirname, filename);
- XtVaSetValues(pSetup->dtprintSetup, DtNfileName, path, NULL);
- }
- }
- /*
- * Copy the information about the widgets into the setup.
- */
- XtVaGetValues(pSetup->dtprintSetup, XmNuserData, &pSetup->widgets, NULL);
- /*
- * Add the setup-specific callbacks.
- */
- XtAddCallback(
- pSetup->dtprintSetup,
- DtNcancelCallback,
- _psPrintSetupCancelCB,
- (XtPointer) pSetup);
- XtAddCallback(
- pSetup->dtprintSetup,
- DtNclosePrintDisplayCallback,
- pSetup->closeDisplayCB,
- (XtPointer) pSetup->closeDisplayClosure);
- XtAddCallback(
- pSetup->dtprintSetup,
- DtNprintCallback,
- _psPrintSetupPrintCB,
- (XtPointer) pSetup);
- XtAddCallback(
- pSetup->dtprintSetup,
- DtNsetupCallback,
- pSetup->setupCB,
- (XtPointer) pSetup->setupClosure);
- xms = XmStringCreateLocalized(pSetup->docName);
- XtVaSetValues(pSetup->widgets->docNameLabel, XmNlabelString, xms, NULL);
- XmStringFree(xms);
- dialog = XtParent(pSetup->widgets->dtprintSetup);
- if (NULL != dialog && XtIsShell(dialog))
- {
- titleParent = (char*) GETMESSAGE(7, 2, "Text Editor - ");
- titlePrefix = (char*) GETMESSAGE(14, 23, "Print Setup - ");
- title =
- (char*) XtMalloc(strlen(titleParent) + strlen(titlePrefix) + strlen(pSetup->docName) + 1);
- sprintf(title, "%s%s%s", titleParent, titlePrefix, pSetup->docName);
- XtVaSetValues(dialog, XmNtitle, title, NULL);
- XtFree(title);
- }
- else
- {
- fprintf(stderr, "Print Setup box is not parented to a shell\n");
- }
- is_set = (pSetup->options.wordWrap) ? XmSET : XmUNSET;
- XtVaSetValues(pSetup->widgets->wordWrapTB, XmNset, is_set, NULL);
- }
- /*
- * _psCreatePrintSetupDialog
- * Creates the widgets for the Setup Dialog.
- */
- static Widget
- _psCreatePrintSetupDialog(Widget parent, Editor *pPad)
- {
- Arg args[2];
- int nargs;
- psWidgets *widgets;
- Widget w;
- XmString xms;
- unsigned char is_set;
- int nitems;
- char **strings;
- void **data;
- int i;
- /*
- * Create the widgets for the Setup Dialog.
- */
- widgets = (psWidgets *) XtMalloc(sizeof(psWidgets));
- /*
- * Create the DtPrintSetupDialog and specify that the application
- * specific area be located below the generic area.
- */
- nargs=0;
- XtSetArg(args[nargs], XmNautoUnmanage, FALSE); nargs++;
- widgets->dtprintSetup =
- DtCreatePrintSetupDialog(parent, "DtPrintSetup", args, nargs);
- XtVaSetValues(
- widgets->dtprintSetup,
- DtNworkAreaLocation, DtWORK_AREA_BOTTOM,
- XmNuserData, widgets,
- NULL);
- XtAddCallback(
- widgets->dtprintSetup,
- XmNhelpCallback,
- HelpPrintSetupDialogCB,
- (XtPointer) pPad);
- XtAddCallback(
- widgets->dtprintSetup,
- XmNdestroyCallback,
- _psPrintSetupDestroyCB,
- (XtPointer) widgets);
- /*
- * Create the dtpad-specific setup dialog in the bottom work area
- */
- widgets->form = XtVaCreateManagedWidget(
- "SetupForm",
- xmFormWidgetClass,
- widgets->dtprintSetup,
- NULL);
-
- XtAddCallback(
- widgets->form,
- XmNhelpCallback,
- HelpPrintSetupAppSpecificCB,
- (XtPointer) pPad);
- /*
- * Create the document name title label
- */
- xms = XmStringCreateLocalized( GETMESSAGE(14, 12, "Document Name: ") );
- widgets->docLabel = XtVaCreateManagedWidget(
- "DocumentLable",
- xmLabelGadgetClass,
- widgets->form,
- XmNleftAttachment, XmATTACH_FORM,
- XmNtopAttachment, XmATTACH_FORM,
- XmNlabelString, xms,
- NULL);
- XmStringFree(xms);
- /*
- * Create the document name label
- */
- widgets->docNameLabel = XtVaCreateManagedWidget(
- "DocumentName",
- xmLabelGadgetClass,
- widgets->form,
- XmNleftAttachment, XmATTACH_WIDGET,
- XmNleftWidget, widgets->docLabel,
- #if 0
- XmNrightAttachment, XmATTACH_FORM,
- #endif
- XmNtopAttachment, XmATTACH_FORM,
- NULL);
- xms = XmStringCreateLocalized(GETMESSAGE(14, 13, "Wrap To Fit"));
- widgets->wordWrapTB = XtVaCreateManagedWidget(
- "WrapToFit",
- xmToggleButtonWidgetClass,
- widgets->form,
- XmNalignment, XmALIGNMENT_BEGINNING,
- XmNlabelString, xms,
- XmNleftAttachment, XmATTACH_FORM,
- XmNrightAttachment, XmATTACH_FORM,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, widgets->docLabel,
- NULL);
- XmStringFree(xms);
- /*
- * Create GUI for the Header/Footer options
- */
- nitems = PS_ARRAY_SIZE(_psHdrFtrValues);
- strings = (char **) XtMalloc( nitems * sizeof(char*) );
- data = (void **) XtMalloc( nitems * sizeof(void*) );
- for (i=0; i<nitems; i++)
- {
- data[i] = (void*) _psHdrFtrValues[i].which;
- strings[i] = GETMESSAGE(
- _psHdrFtrValues[i].set_id,
- _psHdrFtrValues[i].msg_id,
- _psHdrFtrValues[i].dflt_string
- );
- }
- #if 0
- /*
- * Create GUI for the Header/Footer options
- */
- widgets->hdrftrFrame =
- _DtPrintCreateHdrFtrFrame(widgets->form, nitems, strings, data);
- XtVaSetValues(
- widgets->hdrftrFrame,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, widgets->wordWrapTB,
- XmNleftAttachment, XmATTACH_FORM,
- NULL);
- XtManageChild(widgets->hdrftrFrame);
- /*
- * Create GUI for the Margin options
- */
- widgets->marginFrame = _DtPrintCreateMarginFrame(widgets->form);
- XtVaSetValues(
- widgets->marginFrame,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, widgets->hdrftrFrame,
- XmNleftAttachment, XmATTACH_FORM,
- NULL);
- XtManageChild(widgets->marginFrame);
- #else
- /*
- * Create GUI for the Margin options
- */
- widgets->marginFrame = _DtPrintCreateMarginFrame(widgets->form);
- XtVaSetValues(
- widgets->marginFrame,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, widgets->wordWrapTB,
- XmNleftAttachment, XmATTACH_FORM,
- NULL);
- XtManageChild(widgets->marginFrame);
- /*
- * Create GUI for the Header/Footer options
- */
- widgets->hdrftrFrame =
- _DtPrintCreateHdrFtrFrame(widgets->form, nitems, strings, data);
- XtVaSetValues(
- widgets->hdrftrFrame,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, widgets->wordWrapTB,
- XmNtopWidget, widgets->marginFrame,
- XmNleftAttachment, XmATTACH_FORM,
- NULL);
- XtManageChild(widgets->hdrftrFrame);
- #endif
- XtAddCallback(
- widgets->hdrftrFrame,
- XmNhelpCallback,
- HelpPrintSetupPageHeadersFootersCB,
- (XtPointer) pPad);
- XtAddCallback(
- widgets->marginFrame,
- XmNhelpCallback,
- HelpPrintSetupPageMargins,
- (XtPointer) pPad);
- XtRealizeWidget(widgets->dtprintSetup);
- return widgets->dtprintSetup;
- }
- /*
- * _psReleasePrintSetupDialog
- * Removes setup-specific callbacks.
- */
- static void
- _psReleasePrintSetupDialog(PrintSetup *pSetup)
- {
- /*
- * Remove the setup-specific callbacks.
- */
- XtRemoveCallback(
- pSetup->dtprintSetup,
- DtNcancelCallback,
- _psPrintSetupCancelCB,
- (XtPointer) pSetup);
- XtRemoveCallback(
- pSetup->dtprintSetup,
- DtNclosePrintDisplayCallback,
- pSetup->closeDisplayCB,
- (XtPointer) pSetup->closeDisplayClosure);
- XtRemoveCallback(
- pSetup->dtprintSetup,
- DtNprintCallback,
- _psPrintSetupPrintCB,
- (XtPointer) pSetup);
- XtRemoveCallback(
- pSetup->dtprintSetup,
- DtNsetupCallback,
- pSetup->setupCB,
- (XtPointer) pSetup->setupClosure);
- #ifdef REUSE_PRINT_SETUP_DIALOGS
- if (_psDefaultPrintSetupDialog != NULL)
- {
- /*
- * Attempt to reuse the last print setup and print display connection.
- */
- XtDestroyWidget(_psDefaultPrintSetupDialog);
- _psDefaultPrintSetupDialog = NULL;
- }
- _psDefaultPrintSetupDialog = pSetup->dtprintSetup;
- #else
- XtDestroyWidget(pSetup->dtprintSetup);
- #endif
- }
- /*
- * _psPrintSetupCancelCB
- */
- static void
- _psPrintSetupCancelCB(
- Widget dtprintSetup,
- XtPointer client_data,
- XtPointer call_data)
- {
- PrintSetup *pSetup = (PrintSetup*) client_data;
- PrintSetupHide(pSetup);
- pSetup->cancelCB(dtprintSetup, pSetup->cancelClosure, call_data);
- }
- /*
- * _psPrintSetupDestroyCB
- */
- static void
- _psPrintSetupDestroyCB(
- Widget dtprintSetup,
- XtPointer client_data,
- XtPointer call_data)
- {
- psWidgets *widgets;
- XtVaGetValues(dtprintSetup, XmNuserData, &widgets, NULL);
- XtFree((XtPointer) widgets);
- }
- /*
- * _psPrintSetupPrintCB
- */
- static void
- _psPrintSetupPrintCB(
- Widget dtprintSetup,
- XtPointer client_data,
- XtPointer call_data)
- {
- PrintSetup *pSetup = (PrintSetup*) client_data;
- Boolean error = FALSE;
- if (! _psUiSpecsAreValid(pSetup)) return;
- PrintSetupHide(pSetup);
- _psUiToSetup(pSetup);
- _psSetupToSource(pSetup);
- pSetup->printCB(dtprintSetup, pSetup->printClosure, call_data);
- }
|