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
74 #include <X11/Intrinsic.h>
76 #include <Xm/DialogS.h>
78 #include <Xm/ToggleB.h>
79 #include <Dt/PrintOptionsP.h>
82 #include "DmxPrintOptions.h"
84 #include "DtMailError.hh"
85 #include "dtmailopts.h"
86 #include "IndexedOptionMenuUiItem.hh"
89 #include "TextFieldUiItem.hh"
91 #define DMX_ARRAY_SIZE(ary) (sizeof((ary))/sizeof((ary)[0]))
93 static DmxpoPropKey hdrftr_keys[] =
95 { (int) DTPRINT_OPTION_HEADER_LEFT,
96 DMX_PROPKEY_HEADER_LEFT,
97 DMX_PROPVAL_SUBJECT_HEADER
99 { (int) DTPRINT_OPTION_HEADER_RIGHT,
100 DMX_PROPKEY_HEADER_RIGHT,
103 { (int) DTPRINT_OPTION_FOOTER_LEFT,
104 DMX_PROPKEY_FOOTER_LEFT,
105 DMX_PROPVAL_USER_NAME
107 { (int) DTPRINT_OPTION_FOOTER_RIGHT,
108 DMX_PROPKEY_FOOTER_RIGHT,
109 DMX_PROPVAL_PAGE_NUMBER
113 static DmxpoPropKey margin_keys[] =
115 { (int) DTPRINT_OPTION_MARGIN_TOP,
116 DMX_PROPKEY_MARGIN_TOP,
117 DMX_PROPVAL_DFLT_MARGIN
119 { (int) DTPRINT_OPTION_MARGIN_LEFT,
120 DMX_PROPKEY_MARGIN_LEFT,
121 DMX_PROPVAL_DFLT_MARGIN
123 { (int) DTPRINT_OPTION_MARGIN_BOTTOM,
124 DMX_PROPKEY_MARGIN_BOTTOM,
125 DMX_PROPVAL_DFLT_MARGIN
127 { (int) DTPRINT_OPTION_MARGIN_RIGHT,
128 DMX_PROPKEY_MARGIN_RIGHT,
129 DMX_PROPVAL_DFLT_MARGIN
133 static DmxpoPropValue hdrftr_values[] =
135 { (int) DMX_NONE_STRING,
139 { (int) DMX_CC_HEADER_STRING,
140 DMX_PROPVAL_CC_HEADER,
143 { (int) DMX_DATE_HEADER_STRING,
144 DMX_PROPVAL_DATE_HEADER,
147 { (int) DMX_FROM_HEADER_STRING,
148 DMX_PROPVAL_FROM_HEADER,
151 { (int) DMX_SUBJECT_HEADER_STRING,
152 DMX_PROPVAL_SUBJECT_HEADER,
153 22, 5, "Subject Header"
155 { (int) DMX_TO_HEADER_STRING,
156 DMX_PROPVAL_TO_HEADER,
159 { (int) DMX_PAGE_NUMBER_STRING,
160 DMX_PROPVAL_PAGE_NUMBER,
163 { (int) DMX_USER_NAME_STRING,
164 DMX_PROPVAL_USER_NAME,
169 static DmxpoPropValue prthdr_values[] =
171 { (int) DMX_PRINT_HEADERS_NONE,
174 { (int) DMX_PRINT_HEADERS_STANDARD,
175 DMX_PROPVAL_STANDARD,
177 { (int) DMX_PRINT_HEADERS_ABBREV,
178 DMX_PROPVAL_ABBREVIATED,
179 23, 3, "Abbreviated" },
180 { (int) DMX_PRINT_HEADERS_ALL,
185 static DmxpoPropValue msgsep_values[] =
187 { (int) DMX_SEPARATOR_NEW_LINE,
188 DMX_PROPVAL_NEW_LINE,
190 { (int) DMX_SEPARATOR_BLANK_LINE,
191 DMX_PROPVAL_BLANK_LINE,
192 24, 2, "Blank Line" },
193 { (int) DMX_SEPARATOR_CHARACTER_LINE,
194 DMX_PROPVAL_CHARACTER_LINE,
195 24, 3, "Character Line" },
196 { (int) DMX_SEPARATOR_PAGE_BREAK,
197 DMX_PROPVAL_PAGE_BREAK,
203 DmxPrintOptions::DmxPrintOptions (
205 ) : UIComponent( "PrintOptions" )
207 IndexedOptionMenu *iom = (IndexedOptionMenu *) NULL;
208 PropUiItem *pui = (PropUiItem *) NULL;
209 Widget *menu_buttons, w;
216 _iom_array = new DtVirtArray<IndexedOptionMenu *>(10);
217 _propui_array = new DtVirtArray<PropUiItem *>(10);
218 _propui_array_iterator = 0;
222 // Create form to hold the printing options
224 _form = XtVaCreateWidget(
225 "PrintingOptionsPane",
228 XmNbottomAttachment, XmATTACH_FORM,
229 XmNrightAttachment, XmATTACH_FORM,
230 XmNleftAttachment, XmATTACH_FORM,
231 XmNtopAttachment, XmATTACH_FORM,
232 XmNresizePolicy, XmRESIZE_ANY,
235 if (_form == (Widget) NULL) return;
237 installDestroyHandler();
240 // Create GUI for the Header/Footer options
242 nitems = DMX_ARRAY_SIZE(hdrftr_values);;
243 strings = (char **) XtMalloc( nitems * sizeof(char*) );
244 data = (void **) XtMalloc( nitems * sizeof(void*) );
245 for (i=0; i<nitems; i++)
247 data[i] = (void*) hdrftr_values[i].prop_string;
250 hdrftr_values[i].set_id,
251 hdrftr_values[i].msg_id,
252 hdrftr_values[i].dflt_string
256 _hdrftr_frame = _DtPrintCreateHdrFtrFrame( _form, nitems, strings, data);
259 XmNtopAttachment, XmATTACH_FORM,
260 XmNleftAttachment, XmATTACH_FORM,
263 XtManageChild(_hdrftr_frame);
266 // Create PropUiItem's for the Header/Footer options
269 _DtPrintHdrFtrFrameMenuWidgets( _hdrftr_frame, NULL, NULL, &menu_buttons);
270 for (j=0, nhdrftrs=DMX_ARRAY_SIZE(hdrftr_keys); j<nhdrftrs; j++)
272 w = _DtPrintHdrFtrFrameEnumToWidget(
274 (_DtPrintHdrFtrEnum) hdrftr_keys[j].which
277 new IndexedOptionMenu(w, nitems, (char**)strings, data, menu_buttons);
279 _iom_array->append(iom);
281 pui = (PropUiItem *) new IndexedOptionMenuUiItem(
286 _propui_array->append(pui);
288 XtFree((char*) menu_buttons);
289 XtFree((char*) data);
290 XtFree((char*) strings);
294 // Create GUI for the Margin options
296 _margin_frame = _DtPrintCreateMarginFrame(_form);
299 XmNtopAttachment, XmATTACH_WIDGET,
300 XmNtopWidget, _hdrftr_frame,
301 XmNleftAttachment, XmATTACH_FORM,
304 XtManageChild(_margin_frame);
307 // Create PropUiItem's for the Margin options
309 nitems = DMX_ARRAY_SIZE(margin_keys);
310 for (j=0; j<nitems; j++)
312 w = _DtPrintMarginFrameEnumToWidget(
314 (_DtPrintMarginEnum) margin_keys[j].which
316 pui = (PropUiItem *) new TextFieldUiItem(
320 DmxPrintOptions::isValidMarginSpec,
321 (void*) (intptr_t) margin_keys[j].which);
322 _propui_array->append(pui);
327 // Create GUI for the Printed Headers option
329 nitems = DMX_ARRAY_SIZE(prthdr_values);;
330 strings = (char **) XtMalloc( nitems * sizeof(char*) );
331 data = (void **) XtMalloc( nitems * sizeof(void*) );
332 for (i=0; i<nitems; i++)
334 data[i] = (void*) prthdr_values[i].prop_string;
337 prthdr_values[i].set_id,
338 prthdr_values[i].msg_id,
339 prthdr_values[i].dflt_string
343 iom = new IndexedOptionMenu(_form, nitems, (char**) strings, data);
344 xms = XmStringCreateLocalized(
345 GETMSG(DT_catd, 25, 1, "Printed Message Headers: ")
350 XmNtopAttachment, XmATTACH_WIDGET,
351 XmNtopWidget, _margin_frame,
352 XmNrightAttachment, XmATTACH_FORM,
353 XmNleftAttachment, XmATTACH_FORM,
358 _iom_array->append(iom);
361 XtFree((char*) strings);
362 XtFree((char*) data);
365 // Create PropUiItem for the Printed Headers option
367 pui = (PropUiItem *) new IndexedOptionMenuUiItem(
370 DMX_PROPKEY_PRINT_HEADERS
372 _propui_array->append(pui);
376 // Create GUI for the Message Separator option
378 nitems = DMX_ARRAY_SIZE(msgsep_values);;
379 strings = (char **) XtMalloc( nitems * sizeof(char*) );
380 data = (void **) XtMalloc( nitems * sizeof(void*) );
381 for (i=0; i<nitems; i++)
383 data[i] = (void*) msgsep_values[i].prop_string;
386 msgsep_values[i].set_id,
387 msgsep_values[i].msg_id,
388 msgsep_values[i].dflt_string
392 iom = new IndexedOptionMenu(_form, nitems, (char**) strings, data);
393 xms = XmStringCreateLocalized(
394 GETMSG( DT_catd, 25, 2, "Separate Multiple Messages With: ")
399 XmNtopAttachment, XmATTACH_WIDGET,
400 XmNtopWidget, _prthdr_iom->baseWidget(),
401 XmNrightAttachment, XmATTACH_FORM,
402 XmNleftAttachment, XmATTACH_FORM,
403 XmNbottomAttachment, XmATTACH_FORM,
407 _iom_array->append(iom);
411 XtFree((char*) strings);
412 XtFree((char*) data);
415 // Create PropUiItem for the Message Separator option
417 pui = (PropUiItem *) new IndexedOptionMenuUiItem(
420 DMX_PROPKEY_MESSAGE_SEPARATOR);
421 _propui_array->append(pui);
423 //XtRealizeWidget(_w);
428 DmxPrintOptions::~DmxPrintOptions (void)
432 IndexedOptionMenu *iom;
435 for (i=0; i<_propui_array->length(); i++)
437 pui = (*_propui_array)[i];
442 for (i=0; i<_iom_array->length(); i++)
444 iom = (*_iom_array)[i];
453 DmxPrintOptions::getFirstProp(void)
455 _propui_array_iterator = 0;
456 return getNextProp();
460 DmxPrintOptions::getNextProp(void)
462 PropUiItem *pui = (PropUiItem *) NULL;
464 if (_propui_array_iterator < _propui_array->length())
466 pui = (*_propui_array)[_propui_array_iterator];
467 _propui_array_iterator++;
473 DmxPrintOptions::getNumProps(void)
475 return _propui_array->length();
479 DmxPrintOptions::getSeparatorString(void)
481 DtMail::Session *d_session = NULL;
482 DtMail::MailRc *m_rc = NULL;
484 const char *string = NULL;
487 d_session = theRoamApp.session()->session();
488 m_rc = d_session->mailRc(error);
490 m_rc->getValue(error, DMX_PROPKEY_SEPARATOR_STRING, &string);
491 if (string == NULL || error.isSet())
498 DmxPrintOptions::getHdrFtrSpec(_DtPrintHdrFtrEnum which)
500 DtMail::Session *d_session = NULL;
501 DtMail::MailRc *m_rc = NULL;
504 const char *string = NULL;
505 DmxpoPropValue *value = NULL;
506 DmxStringTypeEnum rtn = DMX_NONE_STRING;
508 d_session = theRoamApp.session()->session();
509 m_rc = d_session->mailRc(error);
511 key = DmxPrintOptions::enumToPropKey(
513 DMX_ARRAY_SIZE(hdrftr_keys),
519 m_rc->getValue(error, key->key , &string);
520 if (string == NULL || error.isSet())
521 string = strdup(key->dflt_prop_string);
526 value = stringToPropValue(
528 DMX_ARRAY_SIZE(hdrftr_values),
531 rtn = (DmxStringTypeEnum) value->which;
534 free((void*) string);
540 DmxPrintOptions::getMarginSpec(_DtPrintMarginEnum which)
542 DtMail::Session *d_session = NULL;
543 DtMail::MailRc *m_rc = NULL;
546 const char *string = NULL;
548 d_session = theRoamApp.session()->session();
549 m_rc = d_session->mailRc(error);
551 key = DmxPrintOptions::enumToPropKey(
553 DMX_ARRAY_SIZE(margin_keys),
558 return DMX_PROPVAL_DFLT_MARGIN;
560 m_rc->getValue(error, key->key , &string);
561 if (string == NULL || error.isSet())
562 string = strdup(key->dflt_prop_string);
568 DmxPrintOptions::getMessageSeparator(void)
570 DtMail::Session *d_session = NULL;
571 DtMail::MailRc *m_rc = NULL;
573 const char *string = NULL;
574 DmxpoPropValue *value = NULL;
575 DmxMsgSeparatorEnum rtn = DMX_SEPARATOR_PAGE_BREAK;
577 d_session = theRoamApp.session()->session();
578 m_rc = d_session->mailRc(error);
580 m_rc->getValue(error, DMX_PROPKEY_MESSAGE_SEPARATOR , &string);
581 if (string == NULL || error.isSet())
584 value = stringToPropValue(
586 DMX_ARRAY_SIZE(msgsep_values),
589 rtn = (DmxMsgSeparatorEnum) value->which;
592 free((void*) string);
598 DmxPrintOptions::getPrintedHeaders(void)
600 DtMail::Session *d_session = NULL;
601 DtMail::MailRc *m_rc = NULL;
603 const char *string = NULL;
604 DmxpoPropValue *value = NULL;
605 DmxPrintHeadersEnum rtn = DMX_PRINT_HEADERS_STANDARD;
607 d_session = theRoamApp.session()->session();
608 m_rc = d_session->mailRc(error);
610 m_rc->getValue(error, DMX_PROPKEY_PRINT_HEADERS , &string);
611 if (string == NULL || error.isSet())
614 value = stringToPropValue(
616 DMX_ARRAY_SIZE(prthdr_values),
619 rtn = (DmxPrintHeadersEnum) value->which;
622 free((void*) string);
628 DmxPrintOptions::enumToPropKey(int which, int nkeys, DmxpoPropKey *keys)
630 for (int i=0; i<nkeys; i++)
631 if (keys[i].which == which)
638 DmxPrintOptions::propKeyToPropItem(char *key)
640 for (int i=0; i<_propui_array->length(); i++)
645 pui = (*_propui_array)[i];
646 puikey = pui->getKey();
647 if (strcmp(puikey, key) == 0)
655 DmxPrintOptions::stringToPropValue(
658 DmxpoPropValue *values
661 for (int i=0; i<nvalues; i++)
662 if (strcmp(values[i].prop_string, string) == 0)
669 DmxPrintOptions::isValidMarginSpec(PropUiItem* pui, void* data)
673 char *marginSpec = NULL;
677 _DtPrintMarginEnum which = (_DtPrintMarginEnum)(long)data;
679 text = pui->getWidget();
681 marginSpec = _DtPrintGetMarginSpec(text);
684 if (marginSpec == NULL || strcmp("", marginSpec) == 0)
687 (void) XmConvertStringToUnits(
688 XtScreenOfObject(text),
694 if (! parseError) return NULL;
698 case DTPRINT_OPTION_MARGIN_TOP:
700 GETMSG(DT_catd, 26, 1, "Top Margin specifier is invalid: ");
702 case DTPRINT_OPTION_MARGIN_RIGHT:
704 GETMSG(DT_catd, 26, 2, "Right Margin specifier is invalid: ");
706 case DTPRINT_OPTION_MARGIN_BOTTOM:
708 GETMSG(DT_catd, 26, 3, "Bottom Margin specifier is invalid: ");
710 case DTPRINT_OPTION_MARGIN_LEFT:
712 GETMSG(DT_catd, 26, 4, "Left Margin specifier is invalid: ");
715 errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
716 sprintf(errMsg, "%s%s", i18nMsg, marginSpec);