lib/DtPrint: remove register keyword
[oweals/cde.git] / cde / lib / DtPrint / PrintOptions.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 /* $XConsortium: PrintOptions.c /main/4 1996/04/29 17:12:37 rswiston $ */
24
25 /*
26  *+SNOTICE
27  *
28  *      $:$
29  *
30  *      RESTRICTED CONFIDENTIAL INFORMATION:
31  *      
32  *      The information in this document is subject to special
33  *      restrictions in a confidential disclosure agreement between
34  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
35  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
36  *      Sun's specific written approval.  This document and all copies
37  *      and derivative works thereof must be returned or destroyed at
38  *      Sun's request.
39  *
40  *      Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
41  *
42  *+ENOTICE
43  */
44 /* 
45  *                   Common Desktop Environment
46  *
47  * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
48  * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
49  * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
50  * (c) Copyright 1993, 1994, 1995 Novell, Inc.
51  * (c) Copyright 1995 Digital Equipment Corp.
52  * (c) Copyright 1995 Fujitsu Limited
53  * (c) Copyright 1995 Hitachi, Ltd.
54  *                                                                 
55  *
56  *                   RESTRICTED RIGHTS LEGEND                              
57  *
58  * Use, duplication, or disclosure by the U.S. Government is subject to
59  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
60  * Technical Data and Computer Software clause in DFARS 252.227-7013.  Rights
61  * for non-DOD U.S. Government Departments and Agencies are as set forth in
62  * FAR 52.227-19(c)(1,2).
63  *
64  * Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
65  * International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A. 
66  * Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
67  * Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
68  * Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
69  * Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
70  * Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
71  */
72                                                                    
73 #include <Xm/XmAll.h>
74 #include "Dt/Print.h"
75 #include "PrintMsgsP.h"
76 #include "PrintOptionsP.h"
77
78
79 /******************************************************************************
80  *
81  * Static functions
82  *
83  ******************************************************************************/
84
85 static void
86 _DtPrintDestroyHdrFtrFrameCB(
87         Widget          frame,
88         XtPointer       client_data,
89         XtPointer       call_data
90         );
91 static void
92 _DtPrintDestroyMarginFrameCB(
93         Widget          frame,
94         XtPointer       client_data,
95         XtPointer       call_data
96         );
97
98 /******************************************************************************
99  *
100  * _DtPrint Header/Footer API
101  *
102  ******************************************************************************/
103 typedef struct dtpo_header_footer_spec
104 {
105         Widget          button;
106         void            *data;
107         char            *string;
108 } DtpoHdrFtrSpec;
109
110 typedef struct dtpo_header_footer_frame
111 {
112     Widget              frame,
113                         label,
114                         form,
115                         menu,
116                         top_left,
117                         top_right,
118                         bottom_left,
119                         bottom_right;
120     
121     int                 nspecs;
122     DtpoHdrFtrSpec      *specs;
123 } DtpoHdrFtrFrame;
124
125 static void
126 _DtPrintDestroyHdrFtrFrameCB(
127         Widget          frame,
128         XtPointer       client_data,
129         XtPointer       call_data
130         )
131 {
132     DtpoHdrFtrFrame     *info = (DtpoHdrFtrFrame *) client_data;
133
134     if (info == NULL) return;
135     if (info->specs != NULL)
136       XtFree((char*) info->specs);
137     XtFree((char*) info);
138 }
139
140
141 /*
142  * Function:  _DtPrintCreateHdrFtrFrame
143  *
144  * Creates a frame for specifying the contents of page headers and footers.
145  * The frame contains four option menus, one for each _DtPrintHdrFtrEnum.
146  * The pulldown menus for the option menu are constructed from the .string
147  * field in the array of _DtPrintHdrFtrSpec in "specs".
148  * 
149  * _DtPrintCreateHdrFtrFrame copies the pointer to the array of
150  * _DtPrintHdrFtrSpec.  IT DOES NOT COPY THE ELEMENTS OF THE ARRAY.
151  *
152  *      parent -        specifies the parent of the frame.
153  *      nspecs -        specifies the number of entries in the specs array.
154  *      specs -         array of header/footer specifiers.  The .string
155  *                      field is used to construct labels in the GUI.
156  *                      The .data field is returned in calls to
157  *                      _DtPrintGetHdrFtrSpec.
158  *
159  * Returns the widget id for the frame.
160  */
161 Widget
162 _DtPrintCreateHdrFtrFrame(
163         Widget          parent,
164         int             nspecs,
165         char            **spec_strings,
166         void            **spec_data
167         )
168 {
169     DtpoHdrFtrFrame     *info;
170     Arg         args[16];
171     int         n;
172     int         i;
173     XmString    xms;
174
175     info = (DtpoHdrFtrFrame *) XtMalloc( sizeof(DtpoHdrFtrFrame) );
176     info->nspecs = nspecs;
177     info->specs = (DtpoHdrFtrSpec *) XtMalloc(nspecs*sizeof(DtpoHdrFtrSpec));
178     for (i=0; i<nspecs; i++)
179     {
180         info->specs[i].string = spec_strings[i];
181         if (spec_data != (void*) NULL)
182           info->specs[i].data = spec_data[i];
183         else
184           info->specs[i].data = (void*) NULL;
185         info->specs[i].button = (Widget) NULL;
186     }
187
188
189     /*
190      * Create the frame and attach add a destroyCallback to clean up
191      * memory allocated for this object.
192      */
193     n = 0;
194     XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
195     XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
196     XtSetArg(args[n], XmNuserData, info); n++;
197     info->frame = XmCreateFrame(parent, "HdrFtrFrame", args, n);
198     XtAddCallback(
199                 info->frame,
200                 XmNdestroyCallback,
201                 _DtPrintDestroyHdrFtrFrameCB,
202                 (XtPointer) info
203                 );
204
205     /*
206      * Create a label child for the frame
207      */
208     xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_LABEL);
209     n = 0;
210     XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
211     XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
212     XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
213     XtSetArg(args[n], XmNlabelString, xms); n++;
214     info->label = XmCreateLabel(info->frame, "HdrFtrLabel", args, n);
215     XtManageChild(info->label);
216     XmStringFree(xms);
217
218     /*
219      * Create a form work area child which will be populated by the
220      * OptionMenu's.
221      */
222     n = 0;
223     XtSetArg(args[n], XmNallowOverlap, False); n++;
224     XtSetArg(args[n], XmNfractionBase, 2); n++;
225     info->form = XmCreateForm(info->frame, "HdrFtrForm", args, n);
226
227     /*
228      * Create the pulldown menu for the option menus.
229      * Store the button index in the userData resource of each button.
230      */
231     info->menu = XmCreatePulldownMenu(parent, "HdrFtrMenu", NULL, 0);
232     for (i=0; i<info->nspecs; i++)
233     {
234         static char     button_label[32];
235
236         sprintf(button_label, "Button%d", i);
237         xms = XmStringCreateLocalized(info->specs[i].string);
238         n = 0;
239         XtSetArg(args[n], XmNlabelString, xms); n++;
240         XtSetArg(args[n], XmNuserData, i); n++;
241         info->specs[i].button =
242             XmCreatePushButtonGadget(info->menu, button_label, args, n);
243         XmStringFree(xms);
244         XtManageChild(info->specs[i].button);
245     }
246
247
248     /*
249      * Create the option menus using the menu created above.
250      */
251     xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_TOP_LEFT_LABEL);
252
253     n=0;
254     XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
255     XtSetArg(args[n], XmNlabelString, xms); n++;
256     XtSetArg(args[n], XmNuserData, info); n++;
257     XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
258     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
259     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
260     XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
261     XtSetArg(args[n], XmNrightPosition, 1); n++;
262     XtSetArg(args[n], XmNrightOffset, 5); n++;
263
264     info->top_left = XmCreateOptionMenu(
265                                 info->form,
266                                 "PageHeaderLeftOM",
267                                 args, n
268                                 );
269     XmStringFree(xms);
270     XtManageChild(info->top_left);
271
272     xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_TOP_RIGHT_LABEL);
273
274     n=0;
275     XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
276     XtSetArg(args[n], XmNlabelString, xms); n++;
277     XtSetArg(args[n], XmNuserData, info); n++;
278     XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
279     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
280     XtSetArg(args[n], XmNtopWidget, info->top_left); n++;
281     XtSetArg(args[n], XmNtopOffset, 0); n++;
282     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
283     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
284
285     info->top_right = XmCreateOptionMenu(
286                                 info->form,
287                                 "PageHeaderRightOM",
288                                 args, n
289                                 );
290     XmStringFree(xms);
291     XtManageChild(info->top_right);
292
293     xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_BOTTOM_LEFT_LABEL);
294
295     n=0;
296     XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
297     XtSetArg(args[n], XmNlabelString, xms); n++;
298     XtSetArg(args[n], XmNuserData, info); n++;
299     XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
300     XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
301     XtSetArg(args[n], XmNtopWidget, info->top_left); n++;
302     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
303     XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
304     XtSetArg(args[n], XmNrightWidget, info->top_left); n++;
305     XtSetArg(args[n], XmNrightOffset, 0); n++;
306
307     info->bottom_left = XmCreateOptionMenu(
308                                 info->form,
309                                 "PageFooterLeftOM",
310                                 args, n
311                                 );
312     XmStringFree(xms);
313     XtManageChild(info->bottom_left);
314
315     xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_BOTTOM_RIGHT_LABEL);
316
317     n=0;
318     XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
319     XtSetArg(args[n], XmNlabelString, xms); n++;
320     XtSetArg(args[n], XmNuserData, info); n++;
321     XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
322     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
323     XtSetArg(args[n], XmNtopWidget, info->bottom_left); n++;
324     XtSetArg(args[n], XmNtopOffset, 0); n++;
325     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
326     XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
327     XtSetArg(args[n], XmNrightWidget, info->top_right); n++;
328     XtSetArg(args[n], XmNrightOffset, 0); n++;
329
330     info->bottom_right = XmCreateOptionMenu(
331                                 info->form,
332                                 "PageFooterRightOM",
333                                 args, n
334                                 );
335     XmStringFree(xms);
336     XtManageChild(info->bottom_right);
337
338     XtManageChild(info->form);
339     return info->frame;
340 }
341
342 /*
343  * Function:  _DtPrintHdrFtrFrameEnumToWidget
344  *
345  * Returns the widget id of the option menu corresponding the specified
346  * header or footer.
347  *
348  *      frame - specifies the HdrFtr frame
349  *      which - specifies the particular header or footer in "frame".
350  *
351  * Returns the widget id of the option menu for "which"
352  */
353 Widget
354 _DtPrintHdrFtrFrameEnumToWidget(
355         Widget                  frame,
356         _DtPrintHdrFtrEnum      which
357         )
358 {
359     DtpoHdrFtrFrame     *info;
360     Widget              widget = NULL;
361
362     XtVaGetValues(frame, XmNuserData, &info, NULL);
363     if (info == NULL)
364       return widget;
365
366     switch (which)
367     {
368         case DTPRINT_OPTION_HEADER_LEFT:
369           widget = info->top_left; break;
370         case DTPRINT_OPTION_HEADER_RIGHT:
371           widget = info->top_right; break;
372         case DTPRINT_OPTION_FOOTER_LEFT:
373           widget = info->bottom_left; break;
374         case DTPRINT_OPTION_FOOTER_RIGHT:
375           widget = info->bottom_right; break;
376         default:
377           widget = NULL;
378     }
379
380     return widget;
381 }
382
383 /*
384  * Function:  _DtPrintHdrFtrFrameMenuWidgets
385  *
386  *      widget -specifies the option menu
387  *
388  * Returns the widgets which make up the pulldown menu.
389  */
390 void
391 _DtPrintHdrFtrFrameMenuWidgets(
392         Widget                  frame,
393         Widget                  *menu,
394         int                     *nmenu_buttons,
395         Widget                  **menu_buttons
396         )
397 {
398     int                 i;
399     DtpoHdrFtrFrame     *info;
400
401     if (frame == NULL) return;
402
403     XtVaGetValues(frame, XmNuserData, &info, NULL);
404     if (info == NULL) return;
405
406     if (menu != NULL)
407       *menu = info->menu;
408
409     if (nmenu_buttons != NULL)
410       *nmenu_buttons = info->nspecs;
411
412     if (menu_buttons != NULL)
413     {
414         if (*menu_buttons == NULL)
415           *menu_buttons = (Widget *) XtMalloc( info->nspecs * sizeof(Widget) );
416     
417         for (i=0; i<info->nspecs; i++)
418           (*menu_buttons)[i] = info->specs[i].button;
419     }
420 }
421
422 /*
423  * Function:  _DtPrintGetHdrFtrIndex
424  *
425  *      option -        specifies the HdrFtr option menu
426  *
427  * Returns the index of the active menu option of the specified
428  * option menu. 
429  */
430 int
431 _DtPrintGetHdrFtrIndex(
432         Widget                  option
433         )
434 {
435     int         index = -1;
436     Widget      selected;
437
438     if (! option) return index;
439
440     XtVaGetValues(option, XmNmenuHistory, &selected, NULL);
441     XtVaGetValues(selected, XmNuserData, &index, NULL);
442     return index;
443 }
444
445 /*
446  * Function:  _DtPrintGetHdrFtrData
447  *
448  *      option -        specifies the HdrFtr option menu
449  *
450  * Returns the data associated with the active menu option of the specified
451  * option menu. 
452  */
453 void *
454 _DtPrintGetHdrFtrData(
455         Widget                  option
456         )
457 {
458     int                 index = 0;
459     DtpoHdrFtrFrame     *info = NULL;
460
461     if (! option) return (void*) NULL;
462     XtVaGetValues(option, XmNuserData, &info, NULL);
463     if (info == NULL) return 0;
464
465     index = _DtPrintGetHdrFtrIndex(option);
466     return info->specs[index].data;
467 }
468
469 /*
470  * Function:  _DtPrintGetHdrFtrString
471  *
472  *      option -        specifies the HdrFtr option menu
473  *
474  * Returns the string associated with the active menu option of the specified
475  * option menu. 
476  */
477 char *
478 _DtPrintGetHdrFtrString(
479         Widget                  option
480         )
481 {
482     int                 index = 0;
483     DtpoHdrFtrFrame     *info = NULL;
484
485     if (! option) return (void*) NULL;
486     XtVaGetValues(option, XmNuserData, &info, NULL);
487     if (info == NULL) return 0;
488
489     index = _DtPrintGetHdrFtrIndex(option);
490     return info->specs[index].string;
491 }
492
493 /*
494  * Function:  _DtPrintSetHdrFtrByData
495  *
496  * Displays the specified menu item as the currently active option.
497  *
498  *      option -        specifies the HdrFtr option menu
499  *      data -          data associated with the option to be displayed.
500  */
501 void
502 _DtPrintSetHdrFtrByData(
503         Widget                  option,
504         void                    *data
505         )
506 {
507     int                 i;
508     DtpoHdrFtrFrame     *info;
509
510     if (option == NULL) return;
511     XtVaGetValues(option, XmNuserData, &info, NULL);
512     if (info == NULL) return;
513
514     for (i=0; i<info->nspecs; i++)
515       if (info->specs[i].data == data)
516       {
517           XtVaSetValues(option, XmNmenuHistory, info->specs[i].button, NULL);
518           return;
519       }
520 }
521
522 /*
523  * Function:  _DtPrintSetHdrFtrByIndex
524  *
525  * Displays the specified menu item as the currently active option.
526  *
527  *      option -        specifies the HdrFtr option menu
528  *      index -         specifies the option to be displayed.
529  */
530 void
531 _DtPrintSetHdrFtrByIndex(
532         Widget                  option,
533         int                     index
534         )
535 {
536     DtpoHdrFtrFrame     *info;
537
538     if (option == NULL) return;
539     XtVaGetValues(option, XmNuserData, &info, NULL);
540     if (info == NULL) return;
541
542     XtVaSetValues(option, XmNmenuHistory, info->specs[index].button, NULL);
543 }
544
545 /*
546  * Function:  _DtPrintSetHdrFtrByString
547  *
548  * Displays the specified menu item as the currently active option.
549  *
550  *      option -        specifies the HdrFtr option menu
551  *      string -        string associated with the option to be displayed.
552  */
553 void
554 _DtPrintSetHdrFtrByString(
555         Widget                  option,
556         char                    *string
557         )
558 {
559     int                 i;
560     DtpoHdrFtrFrame     *info;
561
562     if (option == NULL) return;
563     XtVaGetValues(option, XmNuserData, &info, NULL);
564     if (info == NULL) return;
565
566     for (i=0; i<info->nspecs; i++)
567       if (strcmp(info->specs[i].string,string) == 0)
568       {
569           XtVaSetValues(option, XmNmenuHistory, info->specs[i].button, NULL);
570           return;
571       }
572 }
573
574
575
576 /******************************************************************************
577  *
578  * _DtPrint Margin API
579  *
580  ******************************************************************************/
581 typedef struct dtpo_margin_frame
582 {
583     Widget      frame,
584                 label,
585                 form,
586
587                 top,
588                 right,
589                 bottom,
590                 left,
591
592                 top_label,
593                 right_label,
594                 bottom_label,
595                 left_label;
596 } DtpoMarginFrame;
597
598 static void
599 _DtPrintDestroyMarginFrameCB(
600         Widget          frame,
601         XtPointer       client_data,
602         XtPointer       call_data
603         )
604 {
605     DtpoHdrFtrFrame     *info = (DtpoHdrFtrFrame *) client_data;
606
607     if (info == NULL) return;
608     XtFree((char*) info);
609 }
610
611 /*
612  * Function:  _DtPrintCreateMarginFrame
613  *
614  * Creates a frame for specifying margins.  The frame contains four text
615  * fields, one for each _DtPrintMarginEnum.
616  *
617  *      parent -        specifies the parent of the frame.
618  *
619  * Returns the widget id of the frame.
620  */
621 Widget
622 _DtPrintCreateMarginFrame(
623         Widget                  parent
624         )
625 {
626     DtpoMarginFrame
627                 *info;
628     Arg         args[16];
629     int         n;
630     XmString    xms;
631
632     info = (DtpoMarginFrame *) XtMalloc( sizeof(DtpoMarginFrame) );
633
634     n = 0;
635     XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
636     XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
637     XtSetArg(args[n], XmNuserData, info); n++;
638     info->frame = XmCreateFrame(parent, "MarginFrame", args, n);
639     XtAddCallback(
640                 info->frame,
641                 XmNdestroyCallback,
642                 _DtPrintDestroyMarginFrameCB,
643                 (XtPointer) info
644                 );
645
646     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_LABEL);
647     n = 0;
648     XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
649     XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
650     XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
651     XtSetArg(args[n], XmNlabelString, xms); n++;
652     info->label = XmCreateLabel(info->frame, "MarginLabel", args, n);
653     XtManageChild(info->label);
654     XmStringFree(xms);
655
656     n = 0;
657     XtSetArg(args[n], XmNallowOverlap, False); n++;
658     XtSetArg(args[n], XmNfractionBase, 2); n++;
659     info->form = XmCreateForm(info->frame, "MarginForm", args, n);
660
661     n = 0;
662     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
663     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
664     XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
665     XtSetArg(args[n], XmNrightPosition, 1); n++;
666     XtSetArg(args[n], XmNrightOffset, 5); n++;
667     info->top = XmCreateTextField(info->form, "MarginTopText", args, n);
668     XtManageChild(info->top);
669
670     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_TOP_MARGIN_LABEL);
671
672     n = 0;
673     XtSetArg(args[n], XmNlabelString, xms); n++;
674     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
675     XtSetArg(args[n], XmNtopWidget, info->top); n++;
676     XtSetArg(args[n], XmNtopOffset, 0); n++;
677     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
678     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
679     XtSetArg(args[n], XmNrightWidget, info->top); n++;
680     XtSetArg(args[n], XmNrightOffset, 3); n++;
681     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
682     XtSetArg(args[n], XmNbottomWidget, info->top); n++;
683     XtSetArg(args[n], XmNbottomOffset, 0); n++;
684     info->top_label =
685       XmCreateLabelGadget(info->form, "MarginTopLabel", args, n);
686     XmStringFree(xms);
687     XtManageChild(info->top_label);
688
689     n = 0;
690     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
691     XtSetArg(args[n], XmNtopWidget, info->top); n++;
692     XtSetArg(args[n], XmNtopOffset, 0); n++;
693     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
694     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
695     info->right = XmCreateTextField(info->form, "MarginRightText", args, n);
696     XtManageChild(info->right);
697
698     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_RIGHT_MARGIN_LABEL);
699     n = 0;
700     XtSetArg(args[n], XmNlabelString, xms); n++;
701     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
702     XtSetArg(args[n], XmNtopWidget, info->right); n++;
703     XtSetArg(args[n], XmNtopOffset, 0); n++;
704     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
705     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
706     XtSetArg(args[n], XmNrightWidget, info->right); n++;
707     XtSetArg(args[n], XmNrightOffset, 3); n++;
708     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
709     XtSetArg(args[n], XmNbottomWidget, info->right); n++;
710     XtSetArg(args[n], XmNbottomOffset, 0); n++;
711     info->right_label =
712       XmCreateLabelGadget(info->form, "MarginRightLabel", args, n);
713     XmStringFree(xms);
714     XtManageChild(info->right_label);
715
716     n = 0;
717     XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
718     XtSetArg(args[n], XmNtopWidget, info->top); n++;
719     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
720     XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
721     XtSetArg(args[n], XmNrightWidget, info->top); n++;
722     XtSetArg(args[n], XmNrightOffset, 0); n++;
723     info->bottom = XmCreateTextField(info->form, "MarginBottomText", args, n);
724     XtManageChild(info->bottom);
725
726     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_BOTTOM_MARGIN_LABEL);
727     n = 0;
728     XtSetArg(args[n], XmNlabelString, xms); n++;
729     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
730     XtSetArg(args[n], XmNtopWidget, info->bottom); n++;
731     XtSetArg(args[n], XmNtopOffset, 0); n++;
732     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
733     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
734     XtSetArg(args[n], XmNrightWidget, info->bottom); n++;
735     XtSetArg(args[n], XmNrightOffset, 3); n++;
736     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
737     XtSetArg(args[n], XmNbottomWidget, info->bottom); n++;
738     XtSetArg(args[n], XmNbottomOffset, 0); n++;
739     info->bottom_label =
740       XmCreateLabelGadget(info->form, "MarginBottomLabel", args, n);
741     XmStringFree(xms);
742     XtManageChild(info->bottom_label);
743
744     n = 0;
745     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
746     XtSetArg(args[n], XmNtopWidget, info->bottom); n++;
747     XtSetArg(args[n], XmNtopOffset, 0); n++;
748     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
749     XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
750     XtSetArg(args[n], XmNrightWidget, info->right); n++;
751     XtSetArg(args[n], XmNrightOffset, 0); n++;
752     info->left = XmCreateTextField(info->form, "MarginLeftText", args, n);
753     XtManageChild(info->left);
754
755     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_LEFT_MARGIN_LABEL);
756     n = 0;
757     XtSetArg(args[n], XmNlabelString, xms); n++;
758     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
759     XtSetArg(args[n], XmNtopWidget, info->left); n++;
760     XtSetArg(args[n], XmNtopOffset, 0); n++;
761     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
762     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
763     XtSetArg(args[n], XmNrightWidget, info->left); n++;
764     XtSetArg(args[n], XmNrightOffset, 3); n++;
765     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
766     XtSetArg(args[n], XmNbottomWidget, info->left); n++;
767     XtSetArg(args[n], XmNbottomOffset, 0); n++;
768     info->left_label =
769       XmCreateLabelGadget(info->form, "MarginLeftLabel", args, n);
770     XmStringFree(xms);
771     XtManageChild(info->left_label);
772
773     XtManageChild(info->form);
774     return info->frame;
775 }
776
777 /*
778  * Function:  _DtPrintMarginFrameEnumToWidget
779  *
780  *      frame - specifies the HdrFtr frame
781  *      which - specifies the particular margin in "frame".
782  *
783  * Returns the widget id of the textfield for "which"
784  */
785 Widget
786 _DtPrintMarginFrameEnumToWidget(
787         Widget                  frame,
788         _DtPrintMarginEnum      which
789         )
790 {
791     DtpoMarginFrame     *info;
792     Widget              widget = NULL;
793
794     XtVaGetValues(frame, XmNuserData, &info, NULL);
795     if (info == NULL)
796       return widget;
797
798     switch (which)
799     {
800         case DTPRINT_OPTION_MARGIN_TOP:
801           widget = info->top; break;
802         case DTPRINT_OPTION_MARGIN_RIGHT:
803           widget = info->right; break;
804         case DTPRINT_OPTION_MARGIN_BOTTOM:
805           widget = info->bottom; break;
806         case DTPRINT_OPTION_MARGIN_LEFT:
807           widget = info->left; break;
808         default:
809           break;
810     }
811
812     return widget;
813 }
814
815 /*
816  * Function:  _DtPrintGetMarginSpec
817  *
818  *      margin -        specifies the margin widget.
819  *
820  * Returns a copy of the contents of the specified margin.
821  * The calling function should free this string when done with it.
822  */
823 char*
824 _DtPrintGetMarginSpec(
825         Widget                  margin
826         )
827 {
828     char                *spec = NULL;
829
830     if (margin)
831         spec = XmTextFieldGetString(margin);
832
833     return spec;
834 }
835
836 /*
837  * Function:  _DtPrintSetMarginSpec
838  *
839  *      margin -specifies the margin widget.
840  *      spec  - specifies the string to be displayed in the GUI.
841  *
842  */
843 void
844 _DtPrintSetMarginSpec(
845         Widget                  margin,
846         char                    *spec
847         )
848 {
849     if (margin)
850       XmTextFieldSetString(margin, spec);
851 }