Merge branch 'cde-fixups-1' of ssh://git.code.sf.net/p/cdesktopenv/code into cde...
[oweals/cde.git] / cde / programs / dtmail / dtmail / DmxPrintOptions.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: DmxPrintOptions.C /main/8 1997/04/30 09:44:12 mgreess $ */
24
25 /*
26  *+SNOTICE
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *      
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
36  *      Sun's request.
37  *
38  *      Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42 /*
43  *                   Common Desktop Environment
44  *
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.
52  *                                                                   
53  *
54  *                     RESTRICTED RIGHTS LEGEND                              
55  *
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).
61
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
69  */
70
71
72 #include <stdio.h>
73 #include <stdint.h>
74 #include <X11/Intrinsic.h>
75 #include <Xm/Xm.h>
76 #include <Xm/DialogS.h>
77 #include <Xm/Form.h>
78 #include <Xm/ToggleB.h>
79 #include <Dt/PrintOptionsP.h>
80
81 #include "Dmx.h"
82 #include "DmxPrintOptions.h"
83 #include "DtMail.hh"
84 #include "DtMailError.hh"
85 #include "dtmailopts.h"
86 #include "IndexedOptionMenuUiItem.hh"
87 #include "MailMsg.h"
88 #include "RoamApp.h"
89 #include "TextFieldUiItem.hh"
90
91 #define DMX_ARRAY_SIZE(ary)     (sizeof((ary))/sizeof((ary)[0]))
92
93 static DmxpoPropKey hdrftr_keys[] =
94 {
95     { (int) DTPRINT_OPTION_HEADER_LEFT,
96       DMX_PROPKEY_HEADER_LEFT,
97       DMX_PROPVAL_SUBJECT_HEADER
98     },
99     { (int) DTPRINT_OPTION_HEADER_RIGHT,
100       DMX_PROPKEY_HEADER_RIGHT,
101       DMX_PROPVAL_EMPTY
102     },
103     { (int) DTPRINT_OPTION_FOOTER_LEFT,
104       DMX_PROPKEY_FOOTER_LEFT,
105       DMX_PROPVAL_USER_NAME
106     },
107     { (int) DTPRINT_OPTION_FOOTER_RIGHT,
108       DMX_PROPKEY_FOOTER_RIGHT,
109       DMX_PROPVAL_PAGE_NUMBER
110     }
111 };
112
113 static DmxpoPropKey margin_keys[] =
114 {
115     { (int) DTPRINT_OPTION_MARGIN_TOP,
116       DMX_PROPKEY_MARGIN_TOP,
117       DMX_PROPVAL_DFLT_MARGIN
118     },
119     { (int) DTPRINT_OPTION_MARGIN_LEFT,
120       DMX_PROPKEY_MARGIN_LEFT,
121       DMX_PROPVAL_DFLT_MARGIN
122     },
123     { (int) DTPRINT_OPTION_MARGIN_BOTTOM,
124       DMX_PROPKEY_MARGIN_BOTTOM,
125       DMX_PROPVAL_DFLT_MARGIN
126     },
127     { (int) DTPRINT_OPTION_MARGIN_RIGHT,
128       DMX_PROPKEY_MARGIN_RIGHT,
129       DMX_PROPVAL_DFLT_MARGIN
130     }
131 };
132
133 static DmxpoPropValue hdrftr_values[] =
134 {
135     { (int) DMX_NONE_STRING,
136       DMX_PROPVAL_EMPTY,
137       22, 1, "Empty"
138     },
139     { (int) DMX_CC_HEADER_STRING,
140       DMX_PROPVAL_CC_HEADER,
141       22, 2, "CC Header"
142     },
143     { (int) DMX_DATE_HEADER_STRING,
144       DMX_PROPVAL_DATE_HEADER,
145       22, 3, "Date Header"
146     },
147     { (int) DMX_FROM_HEADER_STRING,
148       DMX_PROPVAL_FROM_HEADER,
149       22, 4, "From Header"
150     },
151     { (int) DMX_SUBJECT_HEADER_STRING,
152       DMX_PROPVAL_SUBJECT_HEADER,
153       22, 5, "Subject Header"
154     },
155     { (int) DMX_TO_HEADER_STRING,
156       DMX_PROPVAL_TO_HEADER,
157       22, 6, "To Header"
158     },
159     { (int) DMX_PAGE_NUMBER_STRING,
160       DMX_PROPVAL_PAGE_NUMBER,
161       22, 7, "Page Number"
162     },
163     { (int) DMX_USER_NAME_STRING,
164       DMX_PROPVAL_USER_NAME,
165       22, 8, "User Name"
166     }
167 };
168                                     
169 static DmxpoPropValue prthdr_values[] =
170 {
171     { (int) DMX_PRINT_HEADERS_NONE,
172       DMX_PROPVAL_NONE,
173       23, 1, "None" },
174     { (int) DMX_PRINT_HEADERS_STANDARD,
175       DMX_PROPVAL_STANDARD,
176       23, 2, "Standard" },
177     { (int) DMX_PRINT_HEADERS_ABBREV,
178       DMX_PROPVAL_ABBREVIATED,
179       23, 3, "Abbreviated" },
180     { (int) DMX_PRINT_HEADERS_ALL,
181       DMX_PROPVAL_ALL,
182       23, 4, "All" }
183 };
184                                     
185 static DmxpoPropValue msgsep_values[] =
186 {
187     { (int) DMX_SEPARATOR_NEW_LINE,
188       DMX_PROPVAL_NEW_LINE,
189       24, 1, "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,
198       24, 4, "New Page" }
199 };
200                                     
201
202
203 DmxPrintOptions::DmxPrintOptions (
204                                 Widget parent
205                                 ) : UIComponent( "PrintOptions" )
206 {
207     IndexedOptionMenu   *iom = (IndexedOptionMenu *) NULL;
208     PropUiItem          *pui = (PropUiItem  *) NULL;
209     Widget              *menu_buttons, w;
210     int                 nitems;
211     char                **strings;
212     void                **data;
213     XmString            xms;
214     int                 i, j, nhdrftrs;
215
216     _iom_array = new DtVirtArray<IndexedOptionMenu *>(10);
217     _propui_array = new DtVirtArray<PropUiItem *>(10);
218     _propui_array_iterator = 0;
219     _parent = parent;
220     _prop_source = NULL;
221     _hdrftr_frame = NULL;
222     _margin_frame = NULL;
223     _msgsep_iom = NULL;
224     _prthdr_iom = NULL;
225
226
227     //
228     //  Create form to hold the printing options
229     //
230     _form = XtVaCreateWidget(
231                                 "PrintingOptionsPane",
232                                 xmFormWidgetClass,
233                                 _parent,
234                                 XmNbottomAttachment, XmATTACH_FORM,
235                                 XmNrightAttachment, XmATTACH_FORM,
236                                 XmNleftAttachment, XmATTACH_FORM,
237                                 XmNtopAttachment, XmATTACH_FORM,
238                                 XmNresizePolicy, XmRESIZE_ANY,
239                                 NULL
240                                 );
241     if (_form == (Widget) NULL) return;
242     _w = _form;
243     installDestroyHandler();
244
245     //
246     //  Create GUI for the Header/Footer options
247     //
248     nitems = DMX_ARRAY_SIZE(hdrftr_values);;
249     strings = (char **) XtMalloc( nitems * sizeof(char*) );
250     data = (void **) XtMalloc( nitems * sizeof(void*) );
251     for (i=0; i<nitems; i++)
252     {
253         data[i] = (void*) hdrftr_values[i].prop_string;
254         strings[i] = GETMSG(
255                         DT_catd, 
256                         hdrftr_values[i].set_id, 
257                         hdrftr_values[i].msg_id,
258                         hdrftr_values[i].dflt_string
259                         );
260     }
261
262     _hdrftr_frame = _DtPrintCreateHdrFtrFrame( _form, nitems, strings, data);
263     XtVaSetValues(
264                 _hdrftr_frame,
265                 XmNtopAttachment, XmATTACH_FORM,
266                 XmNleftAttachment, XmATTACH_FORM,
267                 NULL
268                 );
269     XtManageChild(_hdrftr_frame);
270
271     //
272     //  Create PropUiItem's for the Header/Footer options
273     //
274     menu_buttons = NULL;
275     _DtPrintHdrFtrFrameMenuWidgets( _hdrftr_frame, NULL, NULL, &menu_buttons);
276     for (j=0, nhdrftrs=DMX_ARRAY_SIZE(hdrftr_keys); j<nhdrftrs; j++)
277     {
278         w = _DtPrintHdrFtrFrameEnumToWidget(
279                                 _hdrftr_frame,
280                                 (_DtPrintHdrFtrEnum) hdrftr_keys[j].which
281                                 );
282         iom =
283           new IndexedOptionMenu(w, nitems, (char**)strings, data, menu_buttons);
284         iom->manage();
285         _iom_array->append(iom);
286
287         pui = (PropUiItem *) new IndexedOptionMenuUiItem(
288                                                         iom,
289                                                         _FROM_MAILRC,
290                                                         hdrftr_keys[j].key
291                                                         );
292         _propui_array->append(pui);
293     }
294     XtFree((char*) menu_buttons);
295     XtFree((char*) data);
296     XtFree((char*) strings);
297
298
299     //
300     //  Create GUI for the Margin options
301     //
302     _margin_frame = _DtPrintCreateMarginFrame(_form);
303     XtVaSetValues(
304                 _margin_frame,
305                 XmNtopAttachment, XmATTACH_WIDGET,
306                 XmNtopWidget, _hdrftr_frame,
307                 XmNleftAttachment, XmATTACH_FORM,
308                 NULL
309                 );
310     XtManageChild(_margin_frame);
311
312     //
313     //  Create PropUiItem's for the Margin options
314     //
315     nitems = DMX_ARRAY_SIZE(margin_keys);
316     for (j=0; j<nitems; j++)
317     {
318         w = _DtPrintMarginFrameEnumToWidget(
319                                 _margin_frame,
320                                 (_DtPrintMarginEnum) margin_keys[j].which
321                                 );
322         pui = (PropUiItem *) new TextFieldUiItem(
323                                         w,
324                                         _FROM_MAILRC,
325                                         margin_keys[j].key,
326                                         DmxPrintOptions::isValidMarginSpec,
327                                         (void*) (intptr_t) margin_keys[j].which);
328         _propui_array->append(pui);
329     }
330
331
332     //
333     //  Create GUI for the Printed Headers option
334     //
335     nitems = DMX_ARRAY_SIZE(prthdr_values);;
336     strings = (char **) XtMalloc( nitems * sizeof(char*) );
337     data = (void **) XtMalloc( nitems * sizeof(void*) );
338     for (i=0; i<nitems; i++)
339     {
340         data[i] = (void*) prthdr_values[i].prop_string;
341         strings[i] = GETMSG(
342                         DT_catd, 
343                         prthdr_values[i].set_id, 
344                         prthdr_values[i].msg_id,
345                         prthdr_values[i].dflt_string
346                         );
347     }
348
349     iom = new IndexedOptionMenu(_form, nitems, (char**) strings, data);
350     xms = XmStringCreateLocalized(
351                 GETMSG(DT_catd, 25, 1, "Printed Message Headers:  ")
352                 );
353     XtVaSetValues(
354                 iom->baseWidget(),
355                 XmNlabelString, xms,
356                 XmNtopAttachment, XmATTACH_WIDGET,
357                 XmNtopWidget, _margin_frame,
358                 XmNrightAttachment, XmATTACH_FORM,
359                 XmNleftAttachment, XmATTACH_FORM,
360                 NULL
361                 );
362     iom->manage();
363     _prthdr_iom = iom;
364     _iom_array->append(iom);
365
366     XmStringFree(xms);
367     XtFree((char*) strings);
368     XtFree((char*) data);
369
370     //
371     //  Create PropUiItem for the Printed Headers option
372     //
373     pui = (PropUiItem *) new IndexedOptionMenuUiItem(
374                                                 iom,
375                                                 _FROM_MAILRC,
376                                                 DMX_PROPKEY_PRINT_HEADERS
377                                                 );
378     _propui_array->append(pui);
379
380
381     //
382     //  Create GUI for the Message Separator option
383     //
384     nitems = DMX_ARRAY_SIZE(msgsep_values);;
385     strings = (char **) XtMalloc( nitems * sizeof(char*) );
386     data = (void **) XtMalloc( nitems * sizeof(void*) );
387     for (i=0; i<nitems; i++)
388     {
389         data[i] = (void*) msgsep_values[i].prop_string;
390         strings[i] = GETMSG(
391                         DT_catd, 
392                         msgsep_values[i].set_id, 
393                         msgsep_values[i].msg_id,
394                         msgsep_values[i].dflt_string
395                         );
396     }
397
398     iom = new IndexedOptionMenu(_form, nitems, (char**) strings, data);
399     xms = XmStringCreateLocalized(
400                 GETMSG( DT_catd, 25, 2, "Separate Multiple Messages With:  ")
401                 );
402     XtVaSetValues(
403                 iom->baseWidget(),
404                 XmNlabelString, xms,
405                 XmNtopAttachment, XmATTACH_WIDGET,
406                 XmNtopWidget, _prthdr_iom->baseWidget(),
407                 XmNrightAttachment, XmATTACH_FORM,
408                 XmNleftAttachment, XmATTACH_FORM,
409                 XmNbottomAttachment, XmATTACH_FORM,
410                 NULL
411                 );
412     iom->manage();
413     _iom_array->append(iom);
414     _msgsep_iom = iom;
415
416     XmStringFree(xms);
417     XtFree((char*) strings);
418     XtFree((char*) data);
419
420     //
421     //  Create PropUiItem for the Message Separator option
422     //
423     pui = (PropUiItem *) new IndexedOptionMenuUiItem(
424                                                 iom,
425                                                 _FROM_MAILRC,
426                                                 DMX_PROPKEY_MESSAGE_SEPARATOR);
427     _propui_array->append(pui);
428
429     //XtRealizeWidget(_w);
430     //XtManageChild(_w);
431 }
432
433
434 DmxPrintOptions::~DmxPrintOptions (void)
435 {
436     int i;
437     PropUiItem          *pui;;
438     IndexedOptionMenu   *iom;
439
440     if (_propui_array)
441       for (i=0; i<_propui_array->length(); i++)
442       {
443           pui = (*_propui_array)[i];
444           delete pui;
445       }
446
447     if (_iom_array)
448       for (i=0; i<_iom_array->length(); i++)
449       {
450           iom = (*_iom_array)[i];
451           delete iom;
452       }
453
454     if (_w)
455       XtDestroyWidget(_w);
456 }
457
458 PropUiItem *
459 DmxPrintOptions::getFirstProp(void)
460 {
461     _propui_array_iterator = 0;
462     return getNextProp();
463 }
464
465 PropUiItem *
466 DmxPrintOptions::getNextProp(void)
467 {
468     PropUiItem  *pui = (PropUiItem  *) NULL;
469
470     if (_propui_array_iterator < _propui_array->length())
471     {
472         pui = (*_propui_array)[_propui_array_iterator];
473         _propui_array_iterator++;
474     }
475     return pui;
476 }
477
478 int
479 DmxPrintOptions::getNumProps(void)
480 {
481     return _propui_array->length();
482 }
483
484 const char *
485 DmxPrintOptions::getSeparatorString(void)
486 {
487     DtMail::Session     *d_session = NULL;
488     DtMail::MailRc      *m_rc = NULL;
489     DtMailEnv           error;
490     const char          *string = NULL;
491     char                *dflt = "-";
492
493     d_session = theRoamApp.session()->session();
494     m_rc = d_session->mailRc(error);
495
496     m_rc->getValue(error, DMX_PROPKEY_SEPARATOR_STRING, &string);
497     if (string == NULL || error.isSet())
498       return strdup(dflt);
499
500     return string;
501 }
502
503 DmxStringTypeEnum
504 DmxPrintOptions::getHdrFtrSpec(_DtPrintHdrFtrEnum which)
505 {
506     DtMail::Session     *d_session = NULL;
507     DtMail::MailRc      *m_rc = NULL;
508     DtMailEnv           error;
509     DmxpoPropKey        *key;
510     const char          *string = NULL;
511     DmxpoPropValue      *value = NULL;
512     DmxStringTypeEnum   rtn = DMX_NONE_STRING;
513
514     d_session = theRoamApp.session()->session();
515     m_rc = d_session->mailRc(error);
516
517     key = DmxPrintOptions::enumToPropKey(
518                                 which,
519                                 DMX_ARRAY_SIZE(hdrftr_keys),
520                                 hdrftr_keys
521                                 );
522
523     if (key != NULL)
524     {
525         m_rc->getValue(error, key->key , &string);
526         if (string == NULL || error.isSet())
527           string = strdup(key->dflt_prop_string);
528     }
529     else
530       return rtn;
531
532     value = stringToPropValue(
533                         string,
534                         DMX_ARRAY_SIZE(hdrftr_values),
535                         hdrftr_values);
536     if (value != NULL)
537       rtn = (DmxStringTypeEnum) value->which;
538
539     if (NULL != string)
540       free((void*) string);
541
542     return rtn;
543 }
544
545 const char *
546 DmxPrintOptions::getMarginSpec(_DtPrintMarginEnum which)
547 {
548     DtMail::Session     *d_session = NULL;
549     DtMail::MailRc      *m_rc = NULL;
550     DtMailEnv           error;
551     DmxpoPropKey        *key;
552     const char          *string = NULL;
553
554     d_session = theRoamApp.session()->session();
555     m_rc = d_session->mailRc(error);
556
557     key = DmxPrintOptions::enumToPropKey(
558                                 which,
559                                 DMX_ARRAY_SIZE(margin_keys),
560                                 margin_keys
561                                 );
562
563     if (key == NULL)
564       return DMX_PROPVAL_DFLT_MARGIN;
565
566     m_rc->getValue(error, key->key , &string);
567     if (string == NULL || error.isSet())
568       string = strdup(key->dflt_prop_string);
569
570     return string;
571 }
572
573 DmxMsgSeparatorEnum
574 DmxPrintOptions::getMessageSeparator(void)
575 {
576     DtMail::Session     *d_session = NULL;
577     DtMail::MailRc      *m_rc = NULL;
578     DtMailEnv           error;
579     const char          *string = NULL;
580     DmxpoPropValue      *value = NULL;
581     DmxMsgSeparatorEnum rtn = DMX_SEPARATOR_PAGE_BREAK;
582
583     d_session = theRoamApp.session()->session();
584     m_rc = d_session->mailRc(error);
585
586     m_rc->getValue(error, DMX_PROPKEY_MESSAGE_SEPARATOR , &string);
587     if (string == NULL || error.isSet())
588       return rtn;
589
590     value = stringToPropValue(
591                         string,
592                         DMX_ARRAY_SIZE(msgsep_values),
593                         msgsep_values);
594     if (value != NULL)
595       rtn = (DmxMsgSeparatorEnum) value->which;
596
597     if (NULL != string)
598       free((void*) string);
599
600     return rtn;
601 }
602
603 DmxPrintHeadersEnum
604 DmxPrintOptions::getPrintedHeaders(void)
605 {
606     DtMail::Session     *d_session = NULL;
607     DtMail::MailRc      *m_rc = NULL;
608     DtMailEnv           error;
609     const char          *string = NULL;
610     DmxpoPropValue      *value = NULL;
611     DmxPrintHeadersEnum rtn = DMX_PRINT_HEADERS_STANDARD;
612
613     d_session = theRoamApp.session()->session();
614     m_rc = d_session->mailRc(error);
615
616     m_rc->getValue(error, DMX_PROPKEY_PRINT_HEADERS , &string);
617     if (string == NULL || error.isSet())
618       return rtn;
619
620     value = stringToPropValue(
621                         string,
622                         DMX_ARRAY_SIZE(prthdr_values),
623                         prthdr_values);
624     if (value != NULL)
625       rtn = (DmxPrintHeadersEnum) value->which;
626
627     if (NULL != string)
628       free((void*) string);
629
630     return rtn;
631 }
632
633 DmxpoPropKey *
634 DmxPrintOptions::enumToPropKey(int which, int nkeys, DmxpoPropKey *keys)
635 {
636     for (int i=0; i<nkeys; i++)
637       if (keys[i].which == which)
638         return &(keys[i]);
639     
640     return NULL;
641 }
642
643 PropUiItem *
644 DmxPrintOptions::propKeyToPropItem(char *key)
645 {
646     for (int i=0; i<_propui_array->length(); i++)
647     {
648         PropUiItem      *pui;
649         char            *puikey;
650
651         pui = (*_propui_array)[i];
652         puikey = pui->getKey();
653         if (strcmp(puikey, key) == 0)
654           return pui;
655     }
656     
657     return NULL;
658 }
659
660 DmxpoPropValue *
661 DmxPrintOptions::stringToPropValue(
662                                 const char *string,
663                                 int nvalues,
664                                 DmxpoPropValue *values
665                                 )
666 {
667     for (int i=0; i<nvalues; i++)
668       if (strcmp(values[i].prop_string, string) == 0)
669         return &(values[i]);
670     
671     return NULL;
672 }
673
674 char *
675 DmxPrintOptions::isValidMarginSpec(PropUiItem* pui, void* data)
676 {
677     char        *i18nMsg;
678     char        *errMsg = NULL;
679     char        *marginSpec = NULL;
680     XtEnum      parseError;
681     Widget      text;
682
683     _DtPrintMarginEnum which = (_DtPrintMarginEnum)(long)data;
684
685     text = pui->getWidget();
686     if (text)
687       marginSpec = _DtPrintGetMarginSpec(text);
688
689     parseError = FALSE;
690     if (marginSpec == NULL || strcmp("", marginSpec) == 0)
691       parseError = TRUE;
692     else 
693       (void) XmConvertStringToUnits(
694                                 XtScreenOfObject(text),
695                                 marginSpec,
696                                 XmVERTICAL,
697                                 XmPIXELS,
698                                 &parseError);
699  
700     if (! parseError) return NULL;
701  
702     switch (which)
703     {
704       case DTPRINT_OPTION_MARGIN_TOP:
705         i18nMsg =
706           GETMSG(DT_catd, 26, 1, "Top Margin specifier is invalid:  ");
707         break;
708       case DTPRINT_OPTION_MARGIN_RIGHT:
709         i18nMsg =
710           GETMSG(DT_catd, 26, 2, "Right Margin specifier is invalid:  ");
711         break;
712       case DTPRINT_OPTION_MARGIN_BOTTOM:
713         i18nMsg =
714           GETMSG(DT_catd, 26, 3, "Bottom Margin specifier is invalid:  ");
715         break;
716       case DTPRINT_OPTION_MARGIN_LEFT:
717         i18nMsg =
718           GETMSG(DT_catd, 26, 4, "Left Margin specifier is invalid:  ");
719         break;
720     }
721     errMsg = (char*) XtMalloc(strlen(i18nMsg) + strlen(marginSpec) + 1);
722     sprintf(errMsg, "%s%s", i18nMsg, marginSpec);
723     
724     return errMsg;
725 }