2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: DmxPrintOptions.C /main/8 1997/04/30 09:44:12 mgreess $ */
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
43 * Common Desktop Environment
45 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
46 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
47 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
48 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
49 * (c) Copyright 1995 Digital Equipment Corp.
50 * (c) Copyright 1995 Fujitsu Limited
51 * (c) Copyright 1995 Hitachi, Ltd.
54 * RESTRICTED RIGHTS LEGEND
56 *Use, duplication, or disclosure by the U.S. Government is subject to
57 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
58 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
59 *for non-DOD U.S. Government Departments and Agencies are as set forth in
60 *FAR 52.227-19(c)(1,2).
62 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
63 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
64 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
65 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
66 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
67 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
68 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
73 #include <X11/Intrinsic.h>
75 #include <Xm/DialogS.h>
77 #include <Xm/ToggleB.h>
78 #include <Dt/PrintOptionsP.h>
81 #include "DmxPrintOptions.h"
83 #include "DtMailError.hh"
84 #include "dtmailopts.h"
85 #include "IndexedOptionMenuUiItem.hh"
88 #include "TextFieldUiItem.hh"
90 #define DMX_ARRAY_SIZE(ary) (sizeof((ary))/sizeof((ary)[0]))
92 static DmxpoPropKey hdrftr_keys[] =
94 { (int) DTPRINT_OPTION_HEADER_LEFT,
95 DMX_PROPKEY_HEADER_LEFT,
96 DMX_PROPVAL_SUBJECT_HEADER
98 { (int) DTPRINT_OPTION_HEADER_RIGHT,
99 DMX_PROPKEY_HEADER_RIGHT,
102 { (int) DTPRINT_OPTION_FOOTER_LEFT,
103 DMX_PROPKEY_FOOTER_LEFT,
104 DMX_PROPVAL_USER_NAME
106 { (int) DTPRINT_OPTION_FOOTER_RIGHT,
107 DMX_PROPKEY_FOOTER_RIGHT,
108 DMX_PROPVAL_PAGE_NUMBER
112 static DmxpoPropKey margin_keys[] =
114 { (int) DTPRINT_OPTION_MARGIN_TOP,
115 DMX_PROPKEY_MARGIN_TOP,
116 DMX_PROPVAL_DFLT_MARGIN
118 { (int) DTPRINT_OPTION_MARGIN_LEFT,
119 DMX_PROPKEY_MARGIN_LEFT,
120 DMX_PROPVAL_DFLT_MARGIN
122 { (int) DTPRINT_OPTION_MARGIN_BOTTOM,
123 DMX_PROPKEY_MARGIN_BOTTOM,
124 DMX_PROPVAL_DFLT_MARGIN
126 { (int) DTPRINT_OPTION_MARGIN_RIGHT,
127 DMX_PROPKEY_MARGIN_RIGHT,
128 DMX_PROPVAL_DFLT_MARGIN
132 static DmxpoPropValue hdrftr_values[] =
134 { (int) DMX_NONE_STRING,
138 { (int) DMX_CC_HEADER_STRING,
139 DMX_PROPVAL_CC_HEADER,
142 { (int) DMX_DATE_HEADER_STRING,
143 DMX_PROPVAL_DATE_HEADER,
146 { (int) DMX_FROM_HEADER_STRING,
147 DMX_PROPVAL_FROM_HEADER,
150 { (int) DMX_SUBJECT_HEADER_STRING,
151 DMX_PROPVAL_SUBJECT_HEADER,
152 22, 5, "Subject Header"
154 { (int) DMX_TO_HEADER_STRING,
155 DMX_PROPVAL_TO_HEADER,
158 { (int) DMX_PAGE_NUMBER_STRING,
159 DMX_PROPVAL_PAGE_NUMBER,
162 { (int) DMX_USER_NAME_STRING,
163 DMX_PROPVAL_USER_NAME,
168 static DmxpoPropValue prthdr_values[] =
170 { (int) DMX_PRINT_HEADERS_NONE,
173 { (int) DMX_PRINT_HEADERS_STANDARD,
174 DMX_PROPVAL_STANDARD,
176 { (int) DMX_PRINT_HEADERS_ABBREV,
177 DMX_PROPVAL_ABBREVIATED,
178 23, 3, "Abbreviated" },
179 { (int) DMX_PRINT_HEADERS_ALL,
184 static DmxpoPropValue msgsep_values[] =
186 { (int) DMX_SEPARATOR_NEW_LINE,
187 DMX_PROPVAL_NEW_LINE,
189 { (int) DMX_SEPARATOR_BLANK_LINE,
190 DMX_PROPVAL_BLANK_LINE,
191 24, 2, "Blank Line" },
192 { (int) DMX_SEPARATOR_CHARACTER_LINE,
193 DMX_PROPVAL_CHARACTER_LINE,
194 24, 3, "Character Line" },
195 { (int) DMX_SEPARATOR_PAGE_BREAK,
196 DMX_PROPVAL_PAGE_BREAK,
202 DmxPrintOptions::DmxPrintOptions (
204 ) : UIComponent( "PrintOptions" )
206 IndexedOptionMenu *iom = (IndexedOptionMenu *) NULL;
207 PropUiItem *pui = (PropUiItem *) NULL;
208 Widget *menu_buttons, w;
215 _iom_array = new DtVirtArray<IndexedOptionMenu *>(10);
216 _propui_array = new DtVirtArray<PropUiItem *>(10);
217 _propui_array_iterator = 0;
221 // Create form to hold the printing options
223 _form = XtVaCreateWidget(
224 "PrintingOptionsPane",
227 XmNbottomAttachment, XmATTACH_FORM,
228 XmNrightAttachment, XmATTACH_FORM,
229 XmNleftAttachment, XmATTACH_FORM,
230 XmNtopAttachment, XmATTACH_FORM,
231 XmNresizePolicy, XmRESIZE_ANY,
234 if (_form == (Widget) NULL) return;
236 installDestroyHandler();
239 // Create GUI for the Header/Footer options
241 nitems = DMX_ARRAY_SIZE(hdrftr_values);;
242 strings = (char **) XtMalloc( nitems * sizeof(char*) );
243 data = (void **) XtMalloc( nitems * sizeof(void*) );
244 for (i=0; i<nitems; i++)
246 data[i] = (void*) hdrftr_values[i].prop_string;
249 hdrftr_values[i].set_id,
250 hdrftr_values[i].msg_id,
251 hdrftr_values[i].dflt_string
255 _hdrftr_frame = _DtPrintCreateHdrFtrFrame( _form, nitems, strings, data);
258 XmNtopAttachment, XmATTACH_FORM,
259 XmNleftAttachment, XmATTACH_FORM,
262 XtManageChild(_hdrftr_frame);
265 // Create PropUiItem's for the Header/Footer options
268 _DtPrintHdrFtrFrameMenuWidgets( _hdrftr_frame, NULL, NULL, &menu_buttons);
269 for (j=0, nhdrftrs=DMX_ARRAY_SIZE(hdrftr_keys); j<nhdrftrs; j++)
271 w = _DtPrintHdrFtrFrameEnumToWidget(
273 (_DtPrintHdrFtrEnum) hdrftr_keys[j].which
276 new IndexedOptionMenu(w, nitems, (char**)strings, data, menu_buttons);
278 _iom_array->append(iom);
280 pui = (PropUiItem *) new IndexedOptionMenuUiItem(
285 _propui_array->append(pui);
287 XtFree((char*) menu_buttons);
288 XtFree((char*) data);
289 XtFree((char*) strings);
293 // Create GUI for the Margin options
295 _margin_frame = _DtPrintCreateMarginFrame(_form);
298 XmNtopAttachment, XmATTACH_WIDGET,
299 XmNtopWidget, _hdrftr_frame,
300 XmNleftAttachment, XmATTACH_FORM,
303 XtManageChild(_margin_frame);
306 // Create PropUiItem's for the Margin options
308 nitems = DMX_ARRAY_SIZE(margin_keys);
309 for (j=0; j<nitems; j++)
311 w = _DtPrintMarginFrameEnumToWidget(
313 (_DtPrintMarginEnum) margin_keys[j].which
315 pui = (PropUiItem *) new TextFieldUiItem(
319 DmxPrintOptions::isValidMarginSpec,
320 (void*) (intptr_t) margin_keys[j].which);
321 _propui_array->append(pui);
326 // Create GUI for the Printed Headers option
328 nitems = DMX_ARRAY_SIZE(prthdr_values);;
329 strings = (char **) XtMalloc( nitems * sizeof(char*) );
330 data = (void **) XtMalloc( nitems * sizeof(void*) );
331 for (i=0; i<nitems; i++)
333 data[i] = (void*) prthdr_values[i].prop_string;
336 prthdr_values[i].set_id,
337 prthdr_values[i].msg_id,
338 prthdr_values[i].dflt_string
342 iom = new IndexedOptionMenu(_form, nitems, (char**) strings, data);
343 xms = XmStringCreateLocalized(
344 GETMSG(DT_catd, 25, 1, "Printed Message Headers: ")
349 XmNtopAttachment, XmATTACH_WIDGET,
350 XmNtopWidget, _margin_frame,
351 XmNrightAttachment, XmATTACH_FORM,
352 XmNleftAttachment, XmATTACH_FORM,
357 _iom_array->append(iom);
360 XtFree((char*) strings);
361 XtFree((char*) data);
364 // Create PropUiItem for the Printed Headers option
366 pui = (PropUiItem *) new IndexedOptionMenuUiItem(
369 DMX_PROPKEY_PRINT_HEADERS
371 _propui_array->append(pui);
375 // Create GUI for the Message Separator option
377 nitems = DMX_ARRAY_SIZE(msgsep_values);;
378 strings = (char **) XtMalloc( nitems * sizeof(char*) );
379 data = (void **) XtMalloc( nitems * sizeof(void*) );
380 for (i=0; i<nitems; i++)
382 data[i] = (void*) msgsep_values[i].prop_string;
385 msgsep_values[i].set_id,
386 msgsep_values[i].msg_id,
387 msgsep_values[i].dflt_string
391 iom = new IndexedOptionMenu(_form, nitems, (char**) strings, data);
392 xms = XmStringCreateLocalized(
393 GETMSG( DT_catd, 25, 2, "Separate Multiple Messages With: ")
398 XmNtopAttachment, XmATTACH_WIDGET,
399 XmNtopWidget, _prthdr_iom->baseWidget(),
400 XmNrightAttachment, XmATTACH_FORM,
401 XmNleftAttachment, XmATTACH_FORM,
402 XmNbottomAttachment, XmATTACH_FORM,
406 _iom_array->append(iom);
410 XtFree((char*) strings);
411 XtFree((char*) data);
414 // Create PropUiItem for the Message Separator option
416 pui = (PropUiItem *) new IndexedOptionMenuUiItem(
419 DMX_PROPKEY_MESSAGE_SEPARATOR);
420 _propui_array->append(pui);
422 //XtRealizeWidget(_w);
427 DmxPrintOptions::~DmxPrintOptions (void)
431 IndexedOptionMenu *iom;
434 for (i=0; i<_propui_array->length(); i++)
436 pui = (*_propui_array)[i];
441 for (i=0; i<_iom_array->length(); i++)
443 iom = (*_iom_array)[i];
452 DmxPrintOptions::getFirstProp(void)
454 _propui_array_iterator = 0;
455 return getNextProp();
459 DmxPrintOptions::getNextProp(void)
461 PropUiItem *pui = (PropUiItem *) NULL;
463 if (_propui_array_iterator < _propui_array->length())
465 pui = (*_propui_array)[_propui_array_iterator];
466 _propui_array_iterator++;
472 DmxPrintOptions::getNumProps(void)
474 return _propui_array->length();
478 DmxPrintOptions::getSeparatorString(void)
480 DtMail::Session *d_session = NULL;
481 DtMail::MailRc *m_rc = NULL;
483 const char *string = NULL;
486 d_session = theRoamApp.session()->session();
487 m_rc = d_session->mailRc(error);
489 m_rc->getValue(error, DMX_PROPKEY_SEPARATOR_STRING, &string);
490 if (string == NULL || error.isSet())
497 DmxPrintOptions::getHdrFtrSpec(_DtPrintHdrFtrEnum which)
499 DtMail::Session *d_session = NULL;
500 DtMail::MailRc *m_rc = NULL;
503 const char *string = NULL;
504 DmxpoPropValue *value = NULL;
505 DmxStringTypeEnum rtn = DMX_NONE_STRING;
507 d_session = theRoamApp.session()->session();
508 m_rc = d_session->mailRc(error);
510 key = DmxPrintOptions::enumToPropKey(
512 DMX_ARRAY_SIZE(hdrftr_keys),
518 m_rc->getValue(error, key->key , &string);
519 if (string == NULL || error.isSet())
520 string = strdup(key->dflt_prop_string);
525 value = stringToPropValue(
527 DMX_ARRAY_SIZE(hdrftr_values),
530 rtn = (DmxStringTypeEnum) value->which;
533 free((void*) string);
539 DmxPrintOptions::getMarginSpec(_DtPrintMarginEnum which)
541 DtMail::Session *d_session = NULL;
542 DtMail::MailRc *m_rc = NULL;
545 const char *string = NULL;
547 d_session = theRoamApp.session()->session();
548 m_rc = d_session->mailRc(error);
550 key = DmxPrintOptions::enumToPropKey(
552 DMX_ARRAY_SIZE(margin_keys),
557 return DMX_PROPVAL_DFLT_MARGIN;
559 m_rc->getValue(error, key->key , &string);
560 if (string == NULL || error.isSet())
561 string = strdup(key->dflt_prop_string);
567 DmxPrintOptions::getMessageSeparator(void)
569 DtMail::Session *d_session = NULL;
570 DtMail::MailRc *m_rc = NULL;
572 const char *string = NULL;
573 DmxpoPropValue *value = NULL;
574 DmxMsgSeparatorEnum rtn = DMX_SEPARATOR_PAGE_BREAK;
576 d_session = theRoamApp.session()->session();
577 m_rc = d_session->mailRc(error);
579 m_rc->getValue(error, DMX_PROPKEY_MESSAGE_SEPARATOR , &string);
580 if (string == NULL || error.isSet())
583 value = stringToPropValue(
585 DMX_ARRAY_SIZE(msgsep_values),
588 rtn = (DmxMsgSeparatorEnum) value->which;
591 free((void*) string);
597 DmxPrintOptions::getPrintedHeaders(void)
599 DtMail::Session *d_session = NULL;
600 DtMail::MailRc *m_rc = NULL;
602 const char *string = NULL;
603 DmxpoPropValue *value = NULL;
604 DmxPrintHeadersEnum rtn = DMX_PRINT_HEADERS_STANDARD;
606 d_session = theRoamApp.session()->session();
607 m_rc = d_session->mailRc(error);
609 m_rc->getValue(error, DMX_PROPKEY_PRINT_HEADERS , &string);
610 if (string == NULL || error.isSet())
613 value = stringToPropValue(
615 DMX_ARRAY_SIZE(prthdr_values),
618 rtn = (DmxPrintHeadersEnum) value->which;
621 free((void*) string);
627 DmxPrintOptions::enumToPropKey(int which, int nkeys, DmxpoPropKey *keys)
629 for (int i=0; i<nkeys; i++)
630 if (keys[i].which == which)
637 DmxPrintOptions::propKeyToPropItem(char *key)
639 for (int i=0; i<_propui_array->length(); i++)
644 pui = (*_propui_array)[i];
645 puikey = pui->getKey();
646 if (strcmp(puikey, key) == 0)
654 DmxPrintOptions::stringToPropValue(
657 DmxpoPropValue *values
660 for (int i=0; i<nvalues; i++)
661 if (strcmp(values[i].prop_string, string) == 0)
668 DmxPrintOptions::isValidMarginSpec(PropUiItem* pui, void* data)
672 char *marginSpec = NULL;
676 _DtPrintMarginEnum which = (_DtPrintMarginEnum)(long)data;
678 text = pui->getWidget();
680 marginSpec = _DtPrintGetMarginSpec(text);
683 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
686 (void) XmConvertStringToUnits(
687 XtScreenOfObject(text),
693 if (! parseError) return NULL;
697 case DTPRINT_OPTION_MARGIN_TOP:
699 GETMSG(DT_catd, 26, 1, "Top Margin specifier is invalid: ");
701 case DTPRINT_OPTION_MARGIN_RIGHT:
703 GETMSG(DT_catd, 26, 2, "Right Margin specifier is invalid: ");
705 case DTPRINT_OPTION_MARGIN_BOTTOM:
707 GETMSG(DT_catd, 26, 3, "Bottom Margin specifier is invalid: ");
709 case DTPRINT_OPTION_MARGIN_LEFT:
711 GETMSG(DT_catd, 26, 4, "Left Margin specifier is invalid: ");
714 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
715 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);