Add GNU LGPL headers to all .c .C and .h files
[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 librararies 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     Widget              widget = NULL;
401
402     if (frame == NULL) return;
403
404     XtVaGetValues(frame, XmNuserData, &info, NULL);
405     if (info == NULL) return;
406
407     if (menu != NULL)
408       *menu = info->menu;
409
410     if (nmenu_buttons != NULL)
411       *nmenu_buttons = info->nspecs;
412
413     if (menu_buttons != NULL)
414     {
415         if (*menu_buttons == NULL)
416           *menu_buttons = (Widget *) XtMalloc( info->nspecs * sizeof(Widget) );
417     
418         for (i=0; i<info->nspecs; i++)
419           (*menu_buttons)[i] = info->specs[i].button;
420     }
421 }
422
423 /*
424  * Function:  _DtPrintGetHdrFtrIndex
425  *
426  *      option -        specifies the HdrFtr option menu
427  *
428  * Returns the index of the active menu option of the specified
429  * option menu. 
430  */
431 int
432 _DtPrintGetHdrFtrIndex(
433         Widget                  option
434         )
435 {
436     int         index = -1;
437     Widget      selected;
438
439     if (! option) return index;
440
441     XtVaGetValues(option, XmNmenuHistory, &selected, NULL);
442     XtVaGetValues(selected, XmNuserData, &index, NULL);
443     return index;
444 }
445
446 /*
447  * Function:  _DtPrintGetHdrFtrData
448  *
449  *      option -        specifies the HdrFtr option menu
450  *
451  * Returns the data associated with the active menu option of the specified
452  * option menu. 
453  */
454 void *
455 _DtPrintGetHdrFtrData(
456         Widget                  option
457         )
458 {
459     int                 index = 0;
460     DtpoHdrFtrFrame     *info = NULL;
461
462     if (! option) return (void*) NULL;
463     XtVaGetValues(option, XmNuserData, &info, NULL);
464     if (info == NULL) return;
465
466     index = _DtPrintGetHdrFtrIndex(option);
467     return info->specs[index].data;
468 }
469
470 /*
471  * Function:  _DtPrintGetHdrFtrString
472  *
473  *      option -        specifies the HdrFtr option menu
474  *
475  * Returns the string associated with the active menu option of the specified
476  * option menu. 
477  */
478 char *
479 _DtPrintGetHdrFtrString(
480         Widget                  option
481         )
482 {
483     int                 index = 0;
484     DtpoHdrFtrFrame     *info = NULL;
485
486     if (! option) return (void*) NULL;
487     XtVaGetValues(option, XmNuserData, &info, NULL);
488     if (info == NULL) return;
489
490     index = _DtPrintGetHdrFtrIndex(option);
491     return info->specs[index].string;
492 }
493
494 /*
495  * Function:  _DtPrintSetHdrFtrByData
496  *
497  * Displays the specified menu item as the currently active option.
498  *
499  *      option -        specifies the HdrFtr option menu
500  *      data -          data associated with the option to be displayed.
501  */
502 void
503 _DtPrintSetHdrFtrByData(
504         Widget                  option,
505         void                    *data
506         )
507 {
508     int                 i;
509     DtpoHdrFtrFrame     *info;
510
511     if (option == NULL) return;
512     XtVaGetValues(option, XmNuserData, &info, NULL);
513     if (info == NULL) return;
514
515     for (i=0; i<info->nspecs; i++)
516       if (info->specs[i].data == data)
517       {
518           XtVaSetValues(option, XmNmenuHistory, info->specs[i].button, NULL);
519           return;
520       }
521 }
522
523 /*
524  * Function:  _DtPrintSetHdrFtrByIndex
525  *
526  * Displays the specified menu item as the currently active option.
527  *
528  *      option -        specifies the HdrFtr option menu
529  *      index -         specifies the option to be displayed.
530  */
531 void
532 _DtPrintSetHdrFtrByIndex(
533         Widget                  option,
534         int                     index
535         )
536 {
537     DtpoHdrFtrFrame     *info;
538
539     if (option == NULL) return;
540     XtVaGetValues(option, XmNuserData, &info, NULL);
541     if (info == NULL) return;
542
543     XtVaSetValues(option, XmNmenuHistory, info->specs[index].button, NULL);
544 }
545
546 /*
547  * Function:  _DtPrintSetHdrFtrByString
548  *
549  * Displays the specified menu item as the currently active option.
550  *
551  *      option -        specifies the HdrFtr option menu
552  *      string -        string associated with the option to be displayed.
553  */
554 void
555 _DtPrintSetHdrFtrByString(
556         Widget                  option,
557         char                    *string
558         )
559 {
560     int                 i;
561     DtpoHdrFtrFrame     *info;
562
563     if (option == NULL) return;
564     XtVaGetValues(option, XmNuserData, &info, NULL);
565     if (info == NULL) return;
566
567     for (i=0; i<info->nspecs; i++)
568       if (strcmp(info->specs[i].string,string) == 0)
569       {
570           XtVaSetValues(option, XmNmenuHistory, info->specs[i].button, NULL);
571           return;
572       }
573 }
574
575
576
577 /******************************************************************************
578  *
579  * _DtPrint Margin API
580  *
581  ******************************************************************************/
582 typedef struct dtpo_margin_frame
583 {
584     Widget      frame,
585                 label,
586                 form,
587
588                 top,
589                 right,
590                 bottom,
591                 left,
592
593                 top_label,
594                 right_label,
595                 bottom_label,
596                 left_label;
597 } DtpoMarginFrame;
598
599 static void
600 _DtPrintDestroyMarginFrameCB(
601         Widget          frame,
602         XtPointer       client_data,
603         XtPointer       call_data
604         )
605 {
606     DtpoHdrFtrFrame     *info = (DtpoHdrFtrFrame *) client_data;
607     Widget              widget;
608
609     if (info == NULL) return;
610     XtFree((char*) info);
611 }
612
613 /*
614  * Function:  _DtPrintCreateMarginFrame
615  *
616  * Creates a frame for specifying margins.  The frame contains four text
617  * fields, one for each _DtPrintMarginEnum.
618  *
619  *      parent -        specifies the parent of the frame.
620  *
621  * Returns the widget id of the frame.
622  */
623 Widget
624 _DtPrintCreateMarginFrame(
625         Widget                  parent
626         )
627 {
628     DtpoMarginFrame
629                 *info;
630     Arg         args[16];
631     int         n;
632     XmString    xms;
633     int         i;
634
635     info = (DtpoMarginFrame *) XtMalloc( sizeof(DtpoMarginFrame) );
636
637     n = 0;
638     XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
639     XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
640     XtSetArg(args[n], XmNuserData, info); n++;
641     info->frame = XmCreateFrame(parent, "MarginFrame", args, n);
642     XtAddCallback(
643                 info->frame,
644                 XmNdestroyCallback,
645                 _DtPrintDestroyMarginFrameCB,
646                 (XtPointer) info
647                 );
648
649     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_LABEL);
650     n = 0;
651     XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
652     XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
653     XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
654     XtSetArg(args[n], XmNlabelString, xms); n++;
655     info->label = XmCreateLabel(info->frame, "MarginLabel", args, n);
656     XtManageChild(info->label);
657     XmStringFree(xms);
658
659     n = 0;
660     XtSetArg(args[n], XmNallowOverlap, False); n++;
661     XtSetArg(args[n], XmNfractionBase, 2); n++;
662     info->form = XmCreateForm(info->frame, "MarginForm", args, n);
663
664     n = 0;
665     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
666     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
667     XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
668     XtSetArg(args[n], XmNrightPosition, 1); n++;
669     XtSetArg(args[n], XmNrightOffset, 5); n++;
670     info->top = XmCreateTextField(info->form, "MarginTopText", args, n);
671     XtManageChild(info->top);
672
673     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_TOP_MARGIN_LABEL);
674
675     n = 0;
676     XtSetArg(args[n], XmNlabelString, xms); n++;
677     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
678     XtSetArg(args[n], XmNtopWidget, info->top); n++;
679     XtSetArg(args[n], XmNtopOffset, 0); n++;
680     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
681     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
682     XtSetArg(args[n], XmNrightWidget, info->top); n++;
683     XtSetArg(args[n], XmNrightOffset, 3); n++;
684     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
685     XtSetArg(args[n], XmNbottomWidget, info->top); n++;
686     XtSetArg(args[n], XmNbottomOffset, 0); n++;
687     info->top_label =
688       XmCreateLabelGadget(info->form, "MarginTopLabel", args, n);
689     XmStringFree(xms);
690     XtManageChild(info->top_label);
691
692     n = 0;
693     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
694     XtSetArg(args[n], XmNtopWidget, info->top); n++;
695     XtSetArg(args[n], XmNtopOffset, 0); n++;
696     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
697     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
698     info->right = XmCreateTextField(info->form, "MarginRightText", args, n);
699     XtManageChild(info->right);
700
701     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_RIGHT_MARGIN_LABEL);
702     n = 0;
703     XtSetArg(args[n], XmNlabelString, xms); n++;
704     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
705     XtSetArg(args[n], XmNtopWidget, info->right); n++;
706     XtSetArg(args[n], XmNtopOffset, 0); n++;
707     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
708     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
709     XtSetArg(args[n], XmNrightWidget, info->right); n++;
710     XtSetArg(args[n], XmNrightOffset, 3); n++;
711     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
712     XtSetArg(args[n], XmNbottomWidget, info->right); n++;
713     XtSetArg(args[n], XmNbottomOffset, 0); n++;
714     info->right_label =
715       XmCreateLabelGadget(info->form, "MarginRightLabel", args, n);
716     XmStringFree(xms);
717     XtManageChild(info->right_label);
718
719     n = 0;
720     XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
721     XtSetArg(args[n], XmNtopWidget, info->top); n++;
722     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
723     XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
724     XtSetArg(args[n], XmNrightWidget, info->top); n++;
725     XtSetArg(args[n], XmNrightOffset, 0); n++;
726     info->bottom = XmCreateTextField(info->form, "MarginBottomText", args, n);
727     XtManageChild(info->bottom);
728
729     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_BOTTOM_MARGIN_LABEL);
730     n = 0;
731     XtSetArg(args[n], XmNlabelString, xms); n++;
732     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
733     XtSetArg(args[n], XmNtopWidget, info->bottom); n++;
734     XtSetArg(args[n], XmNtopOffset, 0); n++;
735     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
736     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
737     XtSetArg(args[n], XmNrightWidget, info->bottom); n++;
738     XtSetArg(args[n], XmNrightOffset, 3); n++;
739     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
740     XtSetArg(args[n], XmNbottomWidget, info->bottom); n++;
741     XtSetArg(args[n], XmNbottomOffset, 0); n++;
742     info->bottom_label =
743       XmCreateLabelGadget(info->form, "MarginBottomLabel", args, n);
744     XmStringFree(xms);
745     XtManageChild(info->bottom_label);
746
747     n = 0;
748     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
749     XtSetArg(args[n], XmNtopWidget, info->bottom); n++;
750     XtSetArg(args[n], XmNtopOffset, 0); n++;
751     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
752     XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
753     XtSetArg(args[n], XmNrightWidget, info->right); n++;
754     XtSetArg(args[n], XmNrightOffset, 0); n++;
755     info->left = XmCreateTextField(info->form, "MarginLeftText", args, n);
756     XtManageChild(info->left);
757
758     xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_LEFT_MARGIN_LABEL);
759     n = 0;
760     XtSetArg(args[n], XmNlabelString, xms); n++;
761     XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
762     XtSetArg(args[n], XmNtopWidget, info->left); n++;
763     XtSetArg(args[n], XmNtopOffset, 0); n++;
764     XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
765     XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
766     XtSetArg(args[n], XmNrightWidget, info->left); n++;
767     XtSetArg(args[n], XmNrightOffset, 3); n++;
768     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
769     XtSetArg(args[n], XmNbottomWidget, info->left); n++;
770     XtSetArg(args[n], XmNbottomOffset, 0); n++;
771     info->left_label =
772       XmCreateLabelGadget(info->form, "MarginLeftLabel", args, n);
773     XmStringFree(xms);
774     XtManageChild(info->left_label);
775
776     XtManageChild(info->form);
777     return info->frame;
778 }
779
780 /*
781  * Function:  _DtPrintMarginFrameEnumToWidget
782  *
783  *      frame - specifies the HdrFtr frame
784  *      which - specifies the particular margin in "frame".
785  *
786  * Returns the widget id of the textfield for "which"
787  */
788 Widget
789 _DtPrintMarginFrameEnumToWidget(
790         Widget                  frame,
791         _DtPrintMarginEnum      which
792         )
793 {
794     DtpoMarginFrame     *info;
795     Widget              widget = NULL;
796
797     XtVaGetValues(frame, XmNuserData, &info, NULL);
798     if (info == NULL)
799       return widget;
800
801     switch (which)
802     {
803         case DTPRINT_OPTION_MARGIN_TOP:
804           widget = info->top; break;
805         case DTPRINT_OPTION_MARGIN_RIGHT:
806           widget = info->right; break;
807         case DTPRINT_OPTION_MARGIN_BOTTOM:
808           widget = info->bottom; break;
809         case DTPRINT_OPTION_MARGIN_LEFT:
810           widget = info->left; break;
811         default:
812           break;
813     }
814
815     return widget;
816 }
817
818 /*
819  * Function:  _DtPrintGetMarginSpec
820  *
821  *      margin -        specifies the margin widget.
822  *
823  * Returns a copy of the contents of the specified margin.
824  * The calling function should free this string when done with it.
825  */
826 char*
827 _DtPrintGetMarginSpec(
828         Widget                  margin
829         )
830 {
831     char                *spec = NULL;
832
833     if (margin)
834         spec = XmTextFieldGetString(margin);
835
836     return spec;
837 }
838
839 /*
840  * Function:  _DtPrintSetMarginSpec
841  *
842  *      margin -specifies the margin widget.
843  *      spec  - specifies the string to be displayed in the GUI.
844  *
845  */
846 void
847 _DtPrintSetMarginSpec(
848         Widget                  margin,
849         char                    *spec
850         )
851 {
852     if (margin)
853       XmTextFieldSetString(margin, spec);
854 }