Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / libABobjXm / objxm_args.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
24 /*
25  *    $XConsortium: objxm_args.c /main/5 1996/10/02 15:33:46 drk $
26  *
27  *      @(#)objxm_args.c        1.99 28 Apr 1995        
28  *
29  *     RESTRICTED CONFIDENTIAL INFORMATION:
30  *    
31  *    The information in this document is subject to special
32  *    restrictions in a confidential disclosure agreement between
33  *    HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *    document outside HP, IBM, Sun, USL, SCO, or Univel without
35  *    Sun's specific written approval.  This document and all copies
36  *    and derivative works thereof must be returned or destroyed at
37  *    Sun's request.
38  *
39  *    Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  */
42
43
44 /*
45  ***********************************************************************
46  * objxm_args.c - routines to manage Motif Resource ArgLists
47  *
48  ***********************************************************************
49  */
50
51 #include <stdio.h>
52 #include <assert.h>
53 #include <X11/Intrinsic.h>
54 #include <Xm/ToggleB.h>
55 #include <Xm/Form.h>
56 #include <Xm/MessageB.h>
57 #include <Dt/SpinBox.h>
58 #include <Dt/ComboBox.h>
59 #include <ab_private/trav.h>
60 #include "objxmP.h"
61
62 /*************************************************************************
63 **                                                                      **
64 **       Private Function Declarations                                  **
65 **                                                                      **
66 *************************************************************************/
67
68 int             objxmP_set_attachment_arg(
69                     ABObj            obj,
70                     OBJXM_CONFIG_TYPE   ctype,
71                     ABObj            parent_obj,
72                     AB_COMPASS_POINT dir
73                 );
74
75 /*************************************************************************
76 **                                                                      **
77 **       Public Function Definitions                                    **
78 **                                                                      **
79 *************************************************************************/ 
80
81 /*
82  * Create Resource arglists for all objects in a tree
83  * starting at root
84  */
85 int
86 objxm_tree_set_ui_args(
87     ABObj root, 
88     OBJXM_CONFIG_TYPE ctype, 
89     BOOL replace
90 )
91 {
92     AB_TRAVERSAL    trav;
93     ABObj        obj;
94
95     /*
96      * We only need to call set_args on salient objects,
97      * so we're going to skip the others to improve speed
98      */
99     for (trav_open(&trav, root, AB_TRAV_SALIENT);
100         (obj= trav_next(&trav)) != NULL; )
101     {
102         if (!obj_has_flag(obj, CreateAttrsFlag))
103             objxm_comp_set_ui_args(obj, ctype, replace);
104     }
105     trav_close(&trav);
106     return 0;
107 }
108
109 /*
110  * Remove Resource arglists for all objects in a tree
111  * starting at root
112  */
113 int
114 objxm_tree_remove_ui_args(
115     ABObj root, 
116     OBJXM_CONFIG_TYPE ctype
117 )
118 {
119     AB_TRAVERSAL    trav;
120     ABObj        obj;
121
122     /*
123      * We only need to call set_args on salient objects,
124      * so we're going to skip the others to improve speed
125      */
126     for (trav_open(&trav, root, AB_TRAV_SALIENT);
127         (obj= trav_next(&trav)) != NULL; )
128     {
129         objxm_obj_remove_all_ui_args(obj, ctype);
130         obj_clear_flag(obj, CreateAttrsFlag);
131     }
132     trav_close(&trav);
133     return 0;
134 }
135
136 /*
137  * Create Resource arglists for a Composite Object hierarchy
138  *
139  * Assumes: obj is a composite root
140  */
141 int
142 objxm_comp_set_ui_args(
143     ABObj       obj, 
144     OBJXM_CONFIG_TYPE ctype,
145     BOOL        replace
146 )
147 {
148     ABObj       xy_obj = NULL, /* position object */
149                 s_obj = NULL; /* size object */
150     assert(obj_is_root(obj));
151
152     /* projects, modules and composite-subobjs not allowed */
153     if ((!obj_is_ui(obj)) || obj_is_project(obj) || obj_is_module(obj) ||
154           obj_is_message(obj) || obj_is_sub(obj))
155         return 0;
156
157     util_dprintf(3,
158         "Building Resource List for %s\n", util_strsafe(obj_get_name(obj)));
159
160     xy_obj = objxm_comp_get_subobj(obj, AB_CFG_POSITION_OBJ);
161     s_obj  = objxm_comp_get_subobj(obj, AB_CFG_SIZE_OBJ);
162
163     /* Set resources common to all object types 
164      */
165     if (obj->x >= 0)
166         objxm_obj_set_ui_arg(xy_obj, AB_ARG_INT, XmNx, obj->x);
167
168     if (obj->y >= 0)
169         objxm_obj_set_ui_arg(xy_obj, AB_ARG_INT, XmNy, obj->y); 
170
171     if (obj->width >= 0 && s_obj != NULL)
172         objxm_obj_set_ui_arg(s_obj, AB_ARG_INT, XmNwidth, (Dimension)obj->width);
173
174     if (obj->height >= 0)
175         objxm_obj_set_ui_arg(s_obj, AB_ARG_INT, XmNheight, (Dimension)obj->height); 
176
177     /* If widget is already instantiated, set colors now, else wait until
178      * the post-instantiate phase so that the correct widget-id gets associated
179      * with the allocated colors in the Xt resource cache.
180      */
181     if (objxm_get_widget(obj) != NULL)
182         objxm_comp_set_color_args(obj, ctype, ObjxmBackground | ObjxmForeground);
183
184     /* Only Set XmNsensitive if it is False */
185     /*
186      * CMVC#6399 - XmNsensitive is getting set on the menu, rather than
187      * on the insensitive item. The position config obj for the item is
188      * considered to be the parent of the item, which does not work in
189      * this case. In general, I think the position config obj should not 
190      * be the parent, but the item, itself.      -dunn 3/3/95
191      */
192     if (ctype == OBJXM_CONFIG_CODEGEN)
193     {
194         if (!obj_is_initially_active(obj))
195         {
196             objxm_obj_set_ui_arg(obj, AB_ARG_BOOLEAN, XmNsensitive, False);
197         }
198     }
199
200     /* Call method which sets resources specific to the object-type 
201      */
202     objxmP_comp_set_type_args(obj, ctype);
203
204     /* Code Generation also requires that Attachment Args and
205      * Post-instantiation arg  are generated on the first pass
206      */
207     if (ctype == OBJXM_CONFIG_CODEGEN)
208     {
209         objxm_comp_set_attachment_args(obj, ctype);
210         objxmP_comp_type_post_instantiate(obj, ctype);
211         obj_comp_clear_flag(obj, XmCfgForBuildFlag);
212         obj_comp_set_flag(obj, XmCfgForCodeFlag);
213     }
214     else
215     {
216         obj_comp_clear_flag(obj, XmCfgForCodeFlag);
217         obj_comp_set_flag(obj, XmCfgForBuildFlag);
218     }
219     obj_comp_set_flag(obj, CreateAttrsFlag);
220
221     return 0;
222 }
223
224 int
225 objxm_tree_set_post_inst_args(
226     ABObj       root,
227     OBJXM_CONFIG_TYPE ctype
228 )
229 {
230     AB_TRAVERSAL    trav;
231     ABObj        obj;
232
233     for (trav_open(&trav, root, AB_TRAV_UI);
234         (obj= trav_next(&trav)) != NULL; )
235     {
236         objxm_obj_set_post_inst_args(obj, ctype);
237     }
238     trav_close(&trav);
239     return 0;
240 }
241
242 int
243 objxm_obj_set_post_inst_args(
244     ABObj               obj,
245     OBJXM_CONFIG_TYPE   ctype
246 )
247 {
248     if (obj_is_salient(obj))
249     {
250         objxmP_comp_type_post_instantiate(obj, ctype);
251
252         /* Want to ensure allocated color is associated with correct widget-id
253          * in Xt string-to-pixel converter cache, so need to set color resources
254          * AFTER widget is instantiated.
255          */
256         objxm_comp_set_color_args(obj, ctype, ObjxmBackground | ObjxmForeground);
257     }
258  
259     if (obj->attachments != NULL)
260         objxm_obj_set_attachment_args(obj, ctype);
261
262     return 0;
263 }
264
265 Arg*
266 objxm_get_arg(
267     ArgList     arglist,
268     char        *name
269 )
270 {
271     register int        num_args;
272     register int        i;
273     Arg                 *argptr = NULL;
274
275     num_args = objxm_get_num_args(arglist);
276
277     for (i = 0; i < num_args; i++)
278     {
279         if (strcmp(arglist[i].name, name) == 0)
280         {
281             argptr = &(arglist[i]);
282             break;
283         }
284     }    
285     return argptr;
286
287 }
288
289 int
290 objxm_set_literal_arg(
291     OBJXM_CONFIG_TYPE ctype,
292     ArgList           *p_arglist,
293     String            name,
294     unsigned char     literal 
295 )
296 {
297     XtArgVal    enum_value;
298
299     enum_value = (ctype == OBJXM_CONFIG_CODEGEN?
300                   (XtArgVal)objxm_get_enum_strdef(name, literal) :
301                   (XtArgVal)literal);
302
303     objxm_set_arg(p_arglist, AB_ARG_LITERAL, name, enum_value);
304
305     return 0;
306 }
307
308 int
309 objxm_set_widget_arg(
310     OBJXM_CONFIG_TYPE ctype,
311     ArgList           *p_arglist,
312     String            name,
313     ABObj             w_obj
314 )
315 {
316     XtArgVal    w_value;
317
318     /*
319      * REMIND: free this ISTRING when the arg is destroyed!
320      */
321     w_value = (ctype == OBJXM_CONFIG_CODEGEN?
322                   (XtArgVal)(istr_create(w_obj? obj_get_name(w_obj) : "NULL")):
323                   (XtArgVal)(w_obj? w_obj->ui_handle : NULL));
324
325     objxm_set_arg(p_arglist, AB_ARG_WIDGET, name, w_value);
326
327     return 0;
328 }
329
330
331 int
332 objxm_set_arg(
333     ArgList     *p_arglist,
334     AB_ARG_TYPE argtype,
335     String      name,
336     XtArgVal    value
337 )
338 {
339     Arg             *oldarg;
340     Arg             newarg;
341
342     if (argtype == -1)
343         argtype = objxm_get_res_type(name);
344
345     XtSetArg(newarg, name, (XtArgVal)value);
346
347     if ((oldarg = objxm_get_arg(*p_arglist, name)) != NULL)
348     {
349         /* replace existing arg */
350         *oldarg = newarg;
351         return 0;
352     }
353     objxmP_merge_arg(p_arglist, &newarg);
354
355     return 0;
356
357 }
358
359
360 /*
361  *  sets the argument only if it doesn't already exist in the arglist
362  *  returns 0 if the arg is set, negative if not
363  */
364 int
365 objxm_set_arg_if_new(
366     ArgList     *p_arglist,
367     AB_ARG_TYPE type,
368     STRING      name, 
369     XtArgVal    value
370 )
371 {
372     Arg  *old_arg; 
373
374     old_arg = objxm_get_arg(*p_arglist, name);
375
376     if (old_arg != NULL)
377     {
378         return 1;
379     }
380     return objxm_set_arg(p_arglist, type, name, value);
381 }
382
383 void
384 objxm_remove_all_args(
385     ArgList             *p_arglist,
386     OBJXM_CONFIG_TYPE   ctype
387 )
388 {
389     int         num_args;
390     ArgList     args;
391     AB_ARG_TYPE type;
392     ISTRING     istr;
393     int i;
394
395     /* Free any allocated XmStrings... */
396     if (*p_arglist != NULL)
397     {
398         args     = *p_arglist;
399         num_args = objxm_get_num_args(args);
400         for (i = 0; i < num_args; i++)
401         {
402             type = objxm_get_res_type(args[i].name);
403             if (type == AB_ARG_XMSTRING && args[i].value)
404             {
405                 util_dprintf(3, "%s: Freeing XmString\n", args[i].name);
406                 if (ctype == OBJXM_CONFIG_BUILD)
407                     XmStringFree((XmString)args[i].value);
408                 else /* CONFIG_CODEGEN */
409                 {
410                     istr = (ISTRING)args[i].value;
411                     istr_destroy(istr);
412                 }
413             }
414         }
415         XtFree((char *)*p_arglist);
416         *p_arglist = NULL;
417     }
418 }
419
420 int
421 objxm_get_num_args(
422    ArgList arglist 
423 )
424 {
425     register ArgList args = arglist;
426     register int     n = 0;
427
428     for ( ; (args != (ArgList)NULL) && (args->name != NULL);
429              args++, n++)
430         ;
431
432     return n;
433 }
434
435 /*
436  * Remove the specified arg from the args and re-arrange 
437  */
438 int
439 objxm_remove_arg(
440     ArgList *p_arglist,
441     STRING  name
442 )
443 {
444     register int       i;
445     register ArgList   args;
446     register int       nargs;
447
448     if (*p_arglist == NULL)
449     {
450         return 0;
451     }
452     nargs = objxm_get_num_args(*p_arglist);    
453     if (nargs > 0)
454     {
455         args = *p_arglist;
456         *p_arglist = (ArgList)NULL;
457         for (i = 0; i < nargs ; i++)
458         {
459             if (args[i].name && (strcmp(args[i].name, name) == 0))
460                 continue;
461             objxmP_merge_arg(p_arglist, &args[i]);
462
463         }
464 /** LOA (void)free((STRING )args); **/
465     }
466     return 0;
467 }
468
469
470
471  /******************************************************************
472  * Functions that set Resource args on an entire Composite Obj
473  ******************************************************************/
474
475 /*
476  * Set attachment Resources for a Composite Object hierarchy
477  */
478 objxm_comp_set_attachment_args(
479     ABObj       obj,
480     OBJXM_CONFIG_TYPE ctype
481 )
482 {
483     AB_TRAVERSAL        trav;
484     static ABObj        comp_root = NULL;
485     ABObj               comp_sub = NULL;
486  
487     objxm_obj_set_attachment_args(obj, ctype);
488  
489     if (obj->part_of == NULL) /* No SubObjs */
490         return 0;
491  
492     if (comp_root == NULL) /* Set Root */
493         comp_root = obj;
494     
495     for (trav_open(&trav, obj, AB_TRAV_CHILDREN);
496         (comp_sub= trav_next(&trav)) != NULL; )
497     {
498         if (comp_sub->part_of == comp_root)
499             objxm_comp_set_attachment_args(comp_sub, ctype);
500     }
501     trav_close(&trav);
502  
503     if (obj == comp_root)
504         comp_root = NULL; /* Reset */
505  
506     return 0;
507
508 }
509
510 int
511 objxm_comp_set_color_args(
512     ABObj             obj,
513     OBJXM_CONFIG_TYPE ctype,
514     unsigned int      flag
515 )
516 {
517     static ABObj        rootObj = NULL;
518     static XtArgVal     fgvalue;
519     static XtArgVal     bgvalue;
520     static BOOL         cgen_args;
521     AB_TRAVERSAL        trav;
522     Widget              widget;
523     Pixel               pixel;
524     ABObj               subObj;
525     int                 status;
526     char                name[256];
527     int                 iRet = 0;
528
529     if (rootObj == NULL) /* First time */
530     {
531         rootObj = obj;
532         cgen_args = (ctype == OBJXM_CONFIG_CODEGEN? TRUE : FALSE);
533         if (!cgen_args)
534             widget = (objxm_get_widget(obj)? objxm_get_widget(obj) : ObjxmP_toplevel); 
535
536         if (flag & ObjxmBackground) 
537         {
538             if (util_strempty(obj_get_bg_color(rootObj)))
539                 flag &= ~ObjxmBackground;
540             else
541             {
542                 if (!cgen_args) 
543                 {
544                     status = objxm_name_to_pixel(widget, obj_get_bg_color(rootObj), &pixel);
545
546                     if (status == ERR) /* Color couldn't be allocated! */
547                     {
548                         obj_get_safe_name(rootObj, name, 256);
549                         util_printf_err(catgets(OBJXM_MESSAGE_CATD,
550                                 OBJXM_MESSAGE_SET, 21,
551                                 "WARNING: Object '%s'\nCould not allocate Background color \"%s\".\n\
552 Object's Background will default to white."),
553                                 name, obj_get_bg_color(rootObj));
554                         pixel = WhitePixelOfScreen(XtScreen(ObjxmP_toplevel));
555                     }
556                     bgvalue = (XtArgVal)pixel;
557                 }
558                 else /* Generating Code */
559                      bgvalue= (XtArgVal)istr_create(obj_get_bg_color(rootObj));
560             }
561         }
562         if (flag & ObjxmForeground)
563         {
564             if (util_strempty(obj_get_fg_color(obj)))
565                 flag &= ~ObjxmForeground;
566             else
567             {
568                 if (!cgen_args)
569                 {
570                     status = objxm_name_to_pixel(widget, obj_get_fg_color(rootObj), &pixel);
571
572                     if (status == ERR) /* Color couldn't be allocated! */
573                     {
574                         obj_get_safe_name(rootObj, name, 256);
575                         util_printf_err(catgets(OBJXM_MESSAGE_CATD,
576                                 OBJXM_MESSAGE_SET, 22,
577                                 "WARNING: Object '%s'\nCould not allocate Foreground color \"%s\".\n\
578 Object's Foreground will default to black."),
579                                 name, obj_get_fg_color(rootObj));
580                         pixel = BlackPixelOfScreen(XtScreen(ObjxmP_toplevel));
581                     }
582                     fgvalue = (XtArgVal)pixel;
583                 }
584                 else /* Generating Code */
585                     fgvalue = (XtArgVal)istr_create(obj_get_fg_color(rootObj));
586             }
587         }
588         if (flag == ObjxmNone) /* No Colors to Set */
589         {
590             rootObj = NULL;
591             return iRet;
592         }
593     }
594
595     /* If in Build-mode, set value to Pixel, else (CodeGen-mode)
596      * set the value to the color-name
597      */
598     if (flag & ObjxmBackground && 
599         /* Don't set background on Window Footer SubObjs */
600         !obj_has_flag(obj, NoCodeGenFlag) &&
601         !util_streq(obj_get_class_name(obj), _xmScrolledWindow))
602     {
603         objxm_obj_set_ui_arg(obj, AB_ARG_PIXEL, XmNbackground, bgvalue);
604         obj_set_flag(obj, AttrChangedFlag);
605     }
606
607     if (flag & ObjxmForeground &&
608         /* Don't set foreground on Window Select SubObj */
609         !(obj_is_label(obj) && obj_is_window(obj_get_root(obj)) && 
610           obj == objxm_comp_get_subobj(obj, AB_CFG_SELECT_OBJ)) &&
611         !(util_streq(obj_get_class_name(obj), _xmScrolledWindow)))
612     {
613         objxm_obj_set_ui_arg(obj, AB_ARG_PIXEL, XmNforeground, fgvalue);
614         obj_set_flag(obj, AttrChangedFlag);
615     }
616     /*
617      * set args recursively for any "sub-objs" of this obj
618      */
619     for (trav_open(&trav, obj, AB_TRAV_CHILDREN);
620          (subObj = trav_next(&trav)) != NULL; )
621     {
622         if (subObj->part_of == rootObj)  
623             objxm_comp_set_color_args(subObj, ctype, flag);
624     }
625     trav_close(&trav);
626
627     /* If we've recursed back up to the root obj, then we're done.
628      */
629     if (obj == rootObj)
630         rootObj = NULL;
631
632     return iRet;
633 }
634
635 int
636 objxm_comp_set_default_button_args(
637     ABObj       obj,
638     OBJXM_CONFIG_TYPE   ctype
639 )
640 {
641     AB_TRAVERSAL        trav;
642     ABObj               bbobj, defaultb, child, button;
643     ABObj               button_panel;
644     int                 thickness = 1;
645
646     defaultb = obj_get_default_act_button(obj);
647
648     if (defaultb == NULL) /* No Default Button specified */
649     {
650         thickness = 0;
651         if (ctype == OBJXM_CONFIG_CODEGEN)
652             return 0; /* don't bother setting it */
653     }
654     bbobj = objxm_comp_get_subobj(obj, AB_CFG_WINDOW_BB_OBJ);
655  
656     objxm_obj_set_widget_ui_arg(bbobj, ctype, XmNdefaultButton, defaultb);
657     obj_set_flag(bbobj, AttrChangedFlag);
658
659     button_panel = objxm_comp_custdlg_get_area(obj, AB_CONT_BUTTON_PANEL);
660
661     /* If Dialog has a Button Panel, set all it's button DefaultShadowThickness */
662     if (button_panel != NULL)
663     {
664         for (trav_open(&trav, button_panel, AB_TRAV_SALIENT_UI);
665                 (child= trav_next(&trav)) != NULL; )
666         {
667             if (obj_is_button(child))
668             {
669                 button = objxm_comp_get_subobj(child, AB_CFG_OBJECT_OBJ);
670                 objxm_obj_set_ui_arg(button, AB_ARG_INT,
671                         XmNdefaultButtonShadowThickness, thickness);
672                 obj_set_flag(button, AttrChangedFlag);
673             }
674         }
675         trav_close(&trav);
676     }
677     return 0;
678 }
679
680 int
681 objxm_comp_set_label_args(
682     ABObj       obj,
683     OBJXM_CONFIG_TYPE ctype
684 )
685 {
686     ABObj       subObj = objxm_comp_get_subobj(obj, AB_CFG_LABEL_OBJ);
687     Pixmap      label_pm;
688     STRING      label;
689     int         status = OK;
690     BOOL        cgen_args;
691
692     if (subObj == NULL)
693         return 0;
694
695     cgen_args = (ctype == OBJXM_CONFIG_CODEGEN? TRUE : FALSE);
696     label = obj_get_label(obj);
697
698     switch (obj->label_type)
699     {
700         case AB_LABEL_STRING:
701             if (obj_is_window(obj))
702                 objxm_obj_set_ui_arg(subObj, AB_ARG_STRING, XmNtitle, label);
703             else
704             {
705                 XtArgVal        valstr;
706
707                 objxm_obj_set_literal_ui_arg(subObj, ctype, XmNlabelType, XmSTRING);
708
709                 /* If in Build-mode, convert label to XmString, else (CodeGen-mode)
710                  * set value to label
711                  */
712                 if (cgen_args)
713                     valstr = (XtArgVal)istr_create(label);
714                 else
715                 {
716                     /* NOTE:This XmString is freed in objxm_remove_all_args() */
717                     util_dprintf(3, "%s : allocating XmString\n", XmNlabelString);
718                     valstr = (XtArgVal)objxm_str_to_xmstr(ObjxmP_toplevel, label);
719                 }
720                 objxm_obj_set_ui_arg(subObj, AB_ARG_XMSTRING, XmNlabelString, valstr);
721             }
722             break;
723         case AB_LABEL_GLYPH:
724             if (!util_strempty(label))
725             {
726                 if (!cgen_args)
727                 {
728                     status = objxm_filebase_to_pixmap(ObjxmP_toplevel, label, &label_pm);
729                     if (status != OK)
730                         util_printf_err(objxm_pixmap_conversion_error_msg(obj, label, status));
731                 }
732                 if (status == OK)
733                 {
734                     objxm_obj_set_literal_ui_arg(subObj, ctype, XmNlabelType, XmPIXMAP);
735                     objxm_obj_set_ui_arg(subObj, AB_ARG_PIXMAP, XmNlabelPixmap,
736                                 cgen_args? (XtArgVal)istr_create(obj_get_label(obj)):
737                                 (XtArgVal)label_pm);
738                 }
739             }
740             break;
741         case AB_LABEL_ARROW_DOWN:
742             obj_set_class_name(subObj, _xmArrowButton);
743             objxm_obj_set_literal_ui_arg(subObj, ctype, XmNarrowDirection, XmARROW_DOWN);
744             break;
745         case AB_LABEL_ARROW_UP:
746             obj_set_class_name(subObj, _xmArrowButton);
747             objxm_obj_set_literal_ui_arg(subObj, ctype, XmNarrowDirection, XmARROW_UP);
748             break;
749         case AB_LABEL_ARROW_RIGHT:
750             obj_set_class_name(subObj, _xmArrowButton);
751             objxm_obj_set_literal_ui_arg(subObj, ctype, XmNarrowDirection, XmARROW_RIGHT);
752             break;
753         case AB_LABEL_ARROW_LEFT:
754             obj_set_class_name(subObj, _xmArrowButton);
755             objxm_obj_set_literal_ui_arg(subObj, ctype, XmNarrowDirection,XmARROW_LEFT);
756             break;
757         case AB_LABEL_SEPARATOR:
758             obj_set_class_name(subObj, _xmSeparator);
759             objxm_obj_set_line_style_arg(subObj, ctype);
760             break;
761
762     }
763     obj_set_flag(subObj, AttrChangedFlag);
764     return 0;
765 }
766
767 int
768 objxm_comp_set_lbl_align_args(
769     ABObj       obj,
770     OBJXM_CONFIG_TYPE ctype
771 )
772 {
773     ABObj               subObj = objxm_comp_get_subobj(obj, AB_CFG_LABEL_OBJ);
774     unsigned char       value;
775
776     switch(obj_get_label_alignment(obj))
777     {
778         case AB_ALIGN_RIGHT:
779             value = XmALIGNMENT_END;
780             break;
781         case AB_ALIGN_LEFT:
782             value = XmALIGNMENT_BEGINNING;
783             break;
784         case AB_ALIGN_CENTER:
785             value = XmALIGNMENT_CENTER;
786             break;
787         default:
788             return -1;
789     }
790     objxm_obj_set_literal_ui_arg(subObj, ctype, XmNalignment, value);
791     obj_set_flag(subObj, AttrChangedFlag);
792
793     return 0;
794 }
795
796 int
797 objxm_comp_set_lbl_pos_args(
798     ABObj       obj,
799     OBJXM_CONFIG_TYPE ctype
800 )
801 {
802     ABObj            subObj = objxm_comp_get_subobj(obj, AB_CFG_POSITION_OBJ);
803
804     if (!obj_has_label(obj))
805         return 0;
806
807     switch (obj_get_label_position(obj)) 
808     { 
809         case AB_CP_WEST: 
810             objxm_obj_set_literal_ui_arg(subObj, ctype, 
811                         XmNorientation, XmHORIZONTAL);
812             objxm_obj_set_literal_ui_arg(subObj, ctype, 
813                         XmNentryAlignment, XmALIGNMENT_END);
814             break; 
815         case AB_CP_NORTH: 
816             objxm_obj_set_literal_ui_arg(subObj, ctype, 
817                         XmNorientation, XmVERTICAL);
818             objxm_obj_set_literal_ui_arg(subObj, ctype, 
819                         XmNentryAlignment, XmALIGNMENT_BEGINNING);
820             break; 
821         default:
822             return -1;
823     }
824     objxm_obj_set_ui_arg(subObj, AB_ARG_INT, XmNmarginHeight, 0); 
825     objxm_obj_set_ui_arg(subObj, AB_ARG_INT, XmNmarginWidth, 0); 
826     objxm_obj_set_ui_arg(subObj, AB_ARG_INT, XmNspacing, 0);
827     objxm_obj_set_ui_arg(subObj, AB_ARG_BOOLEAN, XmNadjustLast, True);
828     obj_set_flag(subObj, AttrChangedFlag);
829
830     return 0;
831 }
832
833 int
834 objxm_comp_set_icon_args(
835     ABObj       obj,
836     OBJXM_CONFIG_TYPE ctype
837 )
838 {
839     ABObj       shobj; /* Shell SubObj */
840     STRING      icon, mask, icon_label;
841     Pixmap      icon_pm, mask_pm;
842     int         status = OK;
843
844     if (!obj_is_base_win(obj))
845         return -1;
846
847     shobj = objxm_comp_get_subobj(obj, AB_CFG_OBJECT_OBJ);
848
849     if (ctype == OBJXM_CONFIG_CODEGEN)
850         objxm_obj_set_literal_ui_arg(shobj, ctype, XmNinitialState,
851                 obj_is_initially_iconic(obj)? IconicState : NormalState);
852
853     /* Setup Icon Pixmap */
854     if ((icon = obj_get_icon(obj)) != NULL)
855     {
856         if (ctype != OBJXM_CONFIG_CODEGEN)
857         {
858             status = objxm_filebase_to_pixmap(ObjxmP_toplevel, icon, &icon_pm);
859             if (status != OK)
860                 util_printf_err(objxm_pixmap_conversion_error_msg(obj, icon, status));
861         }
862         if (status == OK)
863             objxm_obj_set_ui_arg(shobj, AB_ARG_PIXMAP, XmNiconPixmap,
864                 ctype == OBJXM_CONFIG_CODEGEN? (XtArgVal)istr_create(icon) : icon_pm);
865     }
866     else if (ctype == OBJXM_CONFIG_BUILD)
867         objxm_obj_set_ui_arg(shobj, AB_ARG_PIXMAP, XmNiconPixmap, NULL);
868
869     if ((mask = obj_get_icon_mask(obj)) != NULL)
870     {
871         if (ctype != OBJXM_CONFIG_CODEGEN)
872         {
873             status = objxm_filebase_to_pixmap(ObjxmP_toplevel, mask, &mask_pm);
874             if (status != OK)
875                 util_printf_err(objxm_pixmap_conversion_error_msg(obj, mask, status));
876         }
877         if (status == OK)
878             objxm_obj_set_ui_arg(shobj, AB_ARG_PIXMAP, XmNiconMask,
879                 ctype == OBJXM_CONFIG_CODEGEN? (XtArgVal)istr_create(mask) : mask_pm);
880     }
881     else if (ctype == OBJXM_CONFIG_BUILD) 
882         objxm_obj_set_ui_arg(shobj, AB_ARG_PIXMAP, XmNiconMask, NULL); 
883
884     /* Setup Icon Label */
885     if ((icon_label = obj_get_icon_label(obj)) != NULL)
886         objxm_obj_set_ui_arg(shobj, AB_ARG_STRING, XmNiconName, icon_label);
887
888     obj_set_flag(shobj, AttrChangedFlag);
889
890     return 0;
891 }
892
893 int
894 objxm_comp_set_read_only_args(
895     ABObj       obj,
896     OBJXM_CONFIG_TYPE ctype
897 )
898 {
899     ABObj       subObj;
900     BOOL        read_only;
901
902     read_only = obj_get_read_only(obj);
903     subObj = objxm_comp_get_subobj(obj, AB_CFG_OBJECT_OBJ);
904
905     switch(obj->type)
906     {
907         case AB_TYPE_COMBO_BOX:
908             objxm_obj_set_literal_ui_arg(subObj, ctype, DtNcomboBoxType,
909                 read_only? DtDROP_DOWN_LIST : DtDROP_DOWN_COMBO_BOX);
910             break;
911         case AB_TYPE_SCALE:
912             objxm_obj_set_ui_arg(subObj, AB_ARG_INT, "slidingMode", 
913                 read_only? 1 : 0);
914             break;
915         case AB_TYPE_TEXT_PANE:
916         case AB_TYPE_TEXT_FIELD:
917             objxm_obj_set_ui_arg(subObj, AB_ARG_BOOLEAN, XmNeditable,
918                 read_only? False : True);
919             objxm_obj_set_ui_arg(subObj, AB_ARG_BOOLEAN, XmNcursorPositionVisible,
920                 read_only? False : True);
921             break;
922
923         default:
924             return -1;
925     }
926     obj_set_flag(subObj, AttrChangedFlag);
927
928     return 0;
929 }
930
931 int
932 objxm_comp_set_border_args(
933     ABObj       obj,
934     OBJXM_CONFIG_TYPE ctype
935 )
936 {
937     ABObj          b_obj;
938     int            bstyle;
939
940     if ((b_obj = objxm_comp_get_subobj(obj, AB_CFG_BORDER_OBJ)) == NULL)
941         return OK;
942
943     switch(obj_get_border_frame(obj))
944     {
945         case AB_LINE_SHADOW_IN:
946             bstyle = XmSHADOW_IN;
947             break;
948         case AB_LINE_SHADOW_OUT:
949             bstyle = XmSHADOW_OUT;
950             break;
951         case AB_LINE_ETCHED_IN:
952             bstyle = XmSHADOW_ETCHED_IN;
953             break;
954         case AB_LINE_ETCHED_OUT:
955             bstyle = XmSHADOW_ETCHED_OUT; 
956             break; 
957         case AB_LINE_NONE:
958         default:
959             return -1;
960     }
961
962     objxm_obj_set_literal_ui_arg(b_obj, ctype, XmNshadowType, bstyle);
963     obj_set_flag(b_obj, AttrChangedFlag);
964
965     return 0;
966
967 }
968
969 int
970 objxm_comp_set_msgbox_button_arg(
971     ABObj               obj,
972     OBJXM_CONFIG_TYPE   ctype,
973     unsigned char       which_btn
974 )
975 {
976     ABObj       msgbox_obj = objxm_comp_get_subobj(obj, AB_CFG_OBJECT_OBJ);
977     BOOL        cgen_args;
978     Widget      msgbox, button;
979     BOOL        (*func)(ABObj obj)= NULL;
980
981     msgbox = objxm_get_widget(msgbox_obj);
982     switch(which_btn)
983     {
984         case XmDIALOG_OK_BUTTON:
985             func = obj_has_action1_button; 
986             break;
987         case XmDIALOG_CANCEL_BUTTON:
988             func = obj_has_cancel_button; 
989             break;
990         case XmDIALOG_HELP_BUTTON:
991             func = obj_has_help_button; 
992             break;
993     }
994     button = XmMessageBoxGetChild(msgbox, which_btn);
995     cgen_args = (ctype == OBJXM_CONFIG_CODEGEN? TRUE : FALSE);
996
997     if (func(obj))
998     {
999         if (!XtIsManaged(button))
1000         {
1001             XtManageChild(button);
1002         }
1003     }
1004     else
1005     {
1006         /* Unmanage the button */
1007         XtUnmanageChild(button);
1008     }
1009     obj_set_flag(msgbox_obj, AttrChangedFlag);
1010
1011     return OK;
1012 }
1013
1014
1015  /***********************************************************
1016  * Functions that set Resource args on a SINGLE SubObj
1017  ***********************************************************/
1018
1019 int
1020 objxm_obj_set_arrow_style_arg(
1021     ABObj               subObj,
1022     OBJXM_CONFIG_TYPE   ctype
1023 )
1024 {
1025     unsigned char       value;
1026
1027     switch(obj_get_arrow_style(obj_get_root(subObj)))
1028     {
1029         case AB_ARROW_FLAT_BEGIN:
1030             value = DtARROWS_FLAT_BEGINNING;
1031             break;
1032         case AB_ARROW_FLAT_END:
1033             value = DtARROWS_FLAT_END;
1034             break;
1035         case AB_ARROW_BEGIN:
1036             value = DtARROWS_BEGINNING;
1037             break;
1038         case AB_ARROW_END:
1039             value = DtARROWS_END;
1040             break;
1041         case AB_ARROW_SPLIT:
1042             value = DtARROWS_SPLIT;
1043             break;
1044         default:
1045             return -1;
1046     }
1047     objxm_obj_set_literal_ui_arg(subObj, ctype, DtNarrowLayout, value);
1048     obj_set_flag(subObj, AttrChangedFlag);
1049
1050     return 0;
1051 }
1052
1053 int
1054 objxm_obj_set_attachment_args(
1055     ABObj       obj,
1056     OBJXM_CONFIG_TYPE ctype
1057 )
1058 {
1059     ABObj         parent_obj;
1060
1061     if (obj == NULL)
1062         return -1;
1063
1064     if (obj->attachments != NULL)
1065     {
1066         parent_obj = obj_get_parent(obj);
1067
1068         objxmP_set_attachment_arg(obj, ctype, parent_obj, AB_CP_NORTH);
1069         objxmP_set_attachment_arg(obj, ctype, parent_obj, AB_CP_WEST);
1070         objxmP_set_attachment_arg(obj, ctype, parent_obj, AB_CP_EAST);
1071         objxmP_set_attachment_arg(obj, ctype, parent_obj, AB_CP_SOUTH);
1072     }
1073
1074     return 0;
1075
1076 }
1077
1078 int
1079 objxm_obj_set_direction_arg(
1080     ABObj               subObj,
1081     OBJXM_CONFIG_TYPE   ctype
1082 )
1083 {
1084     unsigned char       value;
1085  
1086     switch(obj_get_direction(obj_get_root(subObj)))
1087     {
1088         case AB_DIR_LEFT_TO_RIGHT:
1089             value = XmMAX_ON_RIGHT;
1090             break;
1091         case AB_DIR_RIGHT_TO_LEFT:
1092             value = XmMAX_ON_LEFT;
1093             break;
1094         case AB_DIR_TOP_TO_BOTTOM:
1095             value = XmMAX_ON_BOTTOM;
1096             break;
1097         case AB_DIR_BOTTOM_TO_TOP:
1098             value = XmMAX_ON_TOP;
1099             break;
1100         default:
1101             return -1;
1102     }
1103     objxm_obj_set_literal_ui_arg(subObj, ctype, XmNprocessingDirection, value);
1104     obj_set_flag(subObj, AttrChangedFlag);
1105  
1106     return 0;
1107 }
1108
1109 int
1110 objxm_obj_set_line_style_arg(
1111     ABObj       subObj,
1112     OBJXM_CONFIG_TYPE ctype
1113 )
1114 {
1115     unsigned char   value;
1116
1117     value = objxm_linestyle_to_enum(obj_get_line_style(obj_get_root(subObj)));
1118
1119     objxm_obj_set_literal_ui_arg(subObj, ctype, XmNseparatorType, value);
1120     obj_set_flag(subObj, AttrChangedFlag);
1121
1122     return 0;
1123 }
1124
1125 int
1126 objxm_obj_set_orientation_arg(
1127     ABObj               subObj,
1128     OBJXM_CONFIG_TYPE   ctype
1129 )
1130 {
1131     unsigned char       value;
1132
1133     switch (obj_get_orientation(obj_get_root(subObj)))
1134     {
1135         case AB_ORIENT_HORIZONTAL:
1136             value = XmHORIZONTAL;
1137             break;
1138         case AB_ORIENT_VERTICAL:
1139             value = XmVERTICAL;
1140             break;
1141         default:
1142             return -1;
1143     }
1144     objxm_obj_set_literal_ui_arg(subObj, ctype, XmNorientation, value);
1145     obj_set_flag(subObj, AttrChangedFlag);
1146
1147     return 0;
1148 }
1149
1150 int
1151 objxm_obj_set_selection_arg(
1152     ABObj               subObj,
1153     OBJXM_CONFIG_TYPE   ctype
1154 )
1155 {
1156     unsigned char       value;
1157
1158     switch (obj_get_selection_mode(obj_get_root(subObj)))
1159     {
1160         case AB_SELECT_BROWSE:
1161             value = XmBROWSE_SELECT;
1162             break;
1163         case AB_SELECT_MULTIPLE:
1164             value = XmMULTIPLE_SELECT;
1165             break;
1166         case AB_SELECT_BROWSE_MULTIPLE:
1167             value = XmEXTENDED_SELECT;
1168             break;
1169         case AB_SELECT_SINGLE:
1170             value = XmSINGLE_SELECT;
1171             break;
1172     default:
1173         return -1;
1174     }
1175     objxm_obj_set_literal_ui_arg(subObj, ctype, XmNselectionPolicy, value);
1176     obj_set_flag(subObj, AttrChangedFlag);
1177
1178     return 0;
1179 }
1180
1181 STRING
1182 objxm_obj_get_default_motif_class(
1183     ABObj obj
1184 )
1185 {
1186     STRING    cn= NULL;
1187     AB_BUTTON_TYPE btype;
1188
1189     switch (obj->type)
1190     {
1191         case AB_TYPE_BASE_WINDOW:
1192             cn= _applicationShell;
1193             break;
1194         case AB_TYPE_BUTTON:
1195             btype = (AB_BUTTON_TYPE)obj_get_subtype(obj); 
1196             if (btype == AB_BUT_PUSH)
1197                 cn= _xmPushButton;
1198             else if (btype == AB_BUT_DRAWN)
1199                 cn= _xmDrawnButton;
1200             else /* AB_BUT_MENU */
1201                 cn= _dtMenuButton;
1202         break;
1203         case AB_TYPE_DRAWING_AREA:
1204             cn= _xmDrawingArea;
1205             break;
1206         case AB_TYPE_CONTAINER:
1207             if (obj_get_container_type(obj) == AB_CONT_PANED)
1208                 cn = _xmPanedWindow;
1209             else
1210                 cn= _xmBulletinBoard;
1211             break;
1212         case AB_TYPE_COMBO_BOX:
1213             cn= _dtComboBox;
1214             break;
1215         case AB_TYPE_FILE_CHOOSER:
1216             cn= _xmFileSelectionBox;
1217             break;
1218         case AB_TYPE_MESSAGE:
1219             cn= _xmMessageBox;
1220             break;
1221         case AB_TYPE_MENU:
1222             if (obj_get_subtype(obj) == AB_MENU_PULLDOWN)
1223                 cn = _xmPulldownMenu; /* Psuedo-class */
1224             else
1225                 cn = _xmPopupMenu;    /* Psuedo-class */
1226             break;
1227         case AB_TYPE_ITEM:
1228             switch (obj->info.item.type)
1229             {
1230             case AB_ITEM_FOR_MENU:
1231                 if (obj_get_label(obj) == NULL)
1232                 {
1233                     cn= _xmSeparator;
1234                 }
1235                 else
1236                 {
1237                     cn= _xmCascadeButton;
1238                 }
1239             break;
1240
1241             case AB_ITEM_FOR_CHOICE:
1242                 cn= _xmToggleButton;
1243             break;
1244
1245             case AB_ITEM_FOR_MENUBAR:
1246                 cn= _xmCascadeButton;
1247             break;
1248
1249             case AB_ITEM_FOR_LIST:
1250                 /* no class for list items (strings) */
1251             break;
1252             }
1253             break;
1254         case AB_TYPE_LABEL:
1255             cn= _xmLabel;
1256             break;
1257         case AB_TYPE_DIALOG:
1258             cn= _xmDialogShell;
1259             break;
1260         case AB_TYPE_LIST:
1261             cn= _xmScrolledList; /* Psuedo-class */
1262             break;
1263         case AB_TYPE_CHOICE:
1264             cn= _xmRowColumn;
1265             break;
1266         case AB_TYPE_SEPARATOR:
1267             cn= _xmSeparator;
1268             break;
1269         case AB_TYPE_SCALE:
1270             cn= _xmScale;
1271             break;
1272         case AB_TYPE_SPIN_BOX:
1273             cn= _dtSpinBox;
1274             break;
1275         case AB_TYPE_LAYERS:
1276             cn= NULL;
1277             break;
1278         case AB_TYPE_TERM_PANE:
1279             cn= _dtTerm;
1280             break;
1281         case AB_TYPE_TEXT_FIELD:
1282             cn= _xmTextField;
1283             if (obj_get_num_rows(obj) > 1)
1284             {
1285                 cn= _xmText;
1286             }
1287             break;
1288         case AB_TYPE_TEXT_PANE:
1289             cn= _xmText;
1290             break;
1291         default:
1292             break;
1293     }
1294     return cn;
1295 }
1296
1297 /*************************************************************************
1298  * Utility Functions to dump out Resource Arg Values                     *
1299  *************************************************************************/
1300 int
1301 objxm_dump_arglist(
1302     ABObj       obj,
1303     ArgList     args,
1304     int         num_args
1305 )
1306 {
1307     char        name[256];
1308     util_dprintf(0,"Resources for: %s\n", obj_get_safe_name(obj, name, 256));
1309     objxm_dump_arglist_indented(obj, args, num_args, 4);
1310
1311     util_dprintf(0,"\n");
1312     return 0;
1313 }
1314
1315
1316 int
1317 objxm_dump_arglist_indented(
1318     ABObj       obj,
1319     ArgList     args,
1320     int         num_args,
1321     int         spaces
1322 )
1323 {
1324     int         space_count= 0;
1325     int         i= 0;
1326     String      valstr= NULL;
1327     AB_ARG_TYPE arg_type= AB_ARG_UNDEF;
1328     Arg         *arg= NULL;
1329     BOOL        cgen_args = FALSE;
1330
1331     if (obj_has_flag(obj, XmCfgForCodeFlag))
1332         cgen_args = TRUE;
1333
1334     for (i = 0; i < num_args; i++)
1335     {
1336         arg= &(args[i]);
1337         for (space_count= 0; space_count < spaces; ++space_count)
1338         {
1339             util_dprintf(0, " ");
1340         }
1341
1342         util_dprintf(0,"XmN%s = ", args[i].name);
1343         arg_type = objxm_get_res_type(args[i].name);
1344         switch(arg_type)
1345         {
1346             case AB_ARG_INT:
1347                 util_dprintf(0,"%d ", (int)args[i].value);
1348                 break;
1349             case AB_ARG_STRING:
1350                 util_dprintf(0,"%s ", (char*)args[i].value);
1351                 break;
1352             case AB_ARG_PIXEL:
1353                 if (cgen_args)
1354                 {
1355                     util_dprintf(0,"%s ", 
1356                         istr_string((ISTRING)(args[i].value)));
1357                 }
1358                 else
1359                 {
1360                     util_dprintf(0,"(Pixel)%ld ", (long)args[i].value);
1361                 }
1362                 break;
1363             case AB_ARG_XMSTRING:
1364                 if (cgen_args)
1365                     valstr = (String)istr_string((ISTRING)(args[i].value));
1366                 else
1367                     valstr = arg->value?
1368                         (String)objxm_xmstr_to_str((XmString)arg->value): "NULL";
1369                 util_dprintf(0,"%s ", util_strsafe(valstr));
1370                 break;
1371             case AB_ARG_BOOLEAN:
1372                 util_dprintf(0,"%s ", args[i].value? "TRUE" :"FALSE");
1373                 break;
1374             case AB_ARG_LITERAL:
1375                 if (cgen_args)
1376                     valstr = (String)istr_string((ISTRING)(args[i].value));
1377                 else
1378                     valstr = istr_string(objxm_get_enum_strdef(args[i].name,
1379                                         (unsigned char)args[i].value));
1380                 util_dprintf(0,"%s ", util_strsafe(valstr));
1381                 break;
1382             case AB_ARG_WIDGET:
1383                 if (cgen_args)
1384                 {
1385                     util_dprintf(0,"%s ", args[i].value != NULL?
1386                         istr_string((ISTRING)(args[i].value)) : "NULL");
1387                 }
1388                 else
1389                 {
1390                     util_dprintf(0,"%lx = %s ", 
1391                         (Widget)args[i].value,
1392                                 args[i].value ? XtName((Widget)args[i].value) : "NULL");
1393                 }
1394                 break;
1395             case AB_ARG_PIXMAP:
1396                 if (cgen_args)
1397                 {
1398                     util_dprintf(0,"(Pixmap File)%s ",
1399                         istr_string((ISTRING)(args[i].value)));
1400                 }
1401                 else
1402                 {
1403                     util_dprintf(0,"(Pixmap)%ld ", (long)args[i].value);
1404                 }
1405                 break;
1406             default:
1407                 util_dprintf(0,"%d ", args[i].value);
1408                 break;
1409         } /* switch arg_type */
1410
1411         util_dprintf(0,"%s\n",
1412             objxm_res_value_is_default(args[i].name, 
1413                 objxm_get_class_ptr(obj_get_class_name(obj)), args[i].value)? "(Default)":"");
1414     }
1415
1416     return 0;
1417 }
1418
1419 #define A_TOP    0
1420 #define A_BOTTOM 1
1421 #define A_LEFT   2
1422 #define A_RIGHT  3
1423
1424 int
1425 objxm_dump_widget_geometry(
1426     Widget      w
1427 )
1428 {
1429     Position    x,y;
1430     Dimension   width, height;
1431     unsigned char attach[4];
1432     Widget      widget[4];
1433     int         position[4];
1434     int         offset[4];
1435     int         i;
1436     BOOL        parent_is_form = FALSE;
1437     char        *attach_str[] = {"XmNtopAttachment   ", "XmNbottomAttachment",
1438                                  "XmNleftAttachment  ", "XmNrightAttachment "};
1439     char        *widget_str[] = {"XmNtopWidget",        "XmNbottomWidget",
1440                                  "XmNleftWidget",       "XmNrightWidget"};
1441     char        *pos_str[]    = {"XmNtopPosition",      "XmNbottomPosition",
1442                                  "XmNleftPosition",     "XmNrightPosition"};
1443     char        *offset_str[] = {"XmNtopOffset",        "XmNbottomOffset",
1444                                  "XmNleftOffset",       "XmNrightOffset"};
1445
1446     if (w == NULL)
1447         return -1;
1448
1449     parent_is_form = XtIsSubclass(XtParent(w), xmFormWidgetClass);
1450
1451     if (parent_is_form)
1452     {
1453         XtVaGetValues(w,
1454                 XmNx,                   &x,
1455                 XmNy,                   &y,
1456                 XmNwidth,               &width,
1457                 XmNheight,              &height,
1458                 XmNtopAttachment,       &(attach[A_TOP]),
1459                 XmNbottomAttachment,    &(attach[A_BOTTOM]),
1460                 XmNleftAttachment,      &(attach[A_LEFT]),
1461                 XmNrightAttachment,     &(attach[A_RIGHT]),
1462                 XmNtopWidget,           &(widget[A_TOP]),
1463                 XmNbottomWidget,        &(widget[A_BOTTOM]),
1464                 XmNleftWidget,          &(widget[A_LEFT]),
1465                 XmNrightWidget,         &(widget[A_RIGHT]),
1466                 XmNtopPosition,         &(position[A_TOP]),
1467                 XmNbottomPosition,      &(position[A_BOTTOM]),
1468                 XmNleftPosition,        &(position[A_LEFT]),
1469                 XmNrightPosition,       &(position[A_RIGHT]),
1470                 XmNtopOffset,           &(offset[A_TOP]),
1471                 XmNbottomOffset,        &(offset[A_BOTTOM]),
1472                 XmNleftOffset,          &(offset[A_LEFT]),
1473                 XmNrightOffset,         &(offset[A_RIGHT]),
1474                 NULL);
1475
1476     }
1477     else
1478     {
1479         XtVaGetValues(w,
1480                 XmNx,                   &x,
1481                 XmNy,                   &y,
1482                 XmNwidth,               &width,
1483                 XmNheight,              &height,
1484                 NULL);
1485     }
1486
1487     util_dprintf(0,"Widget %s is %s\n", 
1488                 XtName(w),
1489                 XtIsRealized(w) ? "realized" : "not realized");
1490     util_dprintf(0,"Widget %s is %s\n", 
1491                 XtName(w),
1492                 XtIsManaged(w) ? "managed" : "not managed");
1493     util_dprintf(0,"Geometry for %s -->\n", XtName(w));
1494     util_dprintf(0,"    x,y                 = %d,%d\n", x, y);
1495     util_dprintf(0,"    Width x Height      = %d x %d\n", width, height);
1496
1497     if (parent_is_form)
1498     {
1499         for(i=0; i < 4; i++)
1500         {
1501             util_dprintf(0,"    %s = ", attach_str[i]);
1502             switch(attach[i])
1503             {
1504                 case XmATTACH_NONE:
1505                     util_dprintf(0,"XmATTACH_NONE\n");
1506                     break;
1507                 case XmATTACH_FORM:
1508                     util_dprintf(0,"XmATTACH_FORM, Form=%s, %s=%d\n", 
1509                         XtName(XtParent(w)), offset_str[i], offset[i]);
1510                     break;
1511                 case XmATTACH_WIDGET:
1512                     util_dprintf(0,"XmATTACH_WIDGET, %s=%s, %s=%d\n", 
1513                         widget_str[i], XtName(widget[i]), 
1514                         offset_str[i], offset[i]);
1515                     break;
1516                 case XmATTACH_POSITION:
1517                     util_dprintf(0,"XmATTACH_POSITION, %s=%d, %s=%d\n", 
1518                         pos_str[i], position[i], 
1519                         offset_str[i], offset[i]);
1520                     break;
1521             }
1522         }
1523     }
1524     return 0;
1525
1526 }
1527 #undef  A_TOP
1528 #undef  A_BOTTOM
1529 #undef  A_LEFT
1530 #undef  A_RIGHT
1531
1532 /*************************************************************************
1533 **                                                                      **
1534 **       Private Function Definitions                                   **
1535 **                                                                      **
1536 *************************************************************************/ 
1537 /* 
1538  * To this routine just pass in 'Arg *' and the arglist in the ABObj,
1539  * it will merge with existing args for obj and stick it back in the arglist 
1540  *
1541  */
1542 int
1543 objxmP_merge_arg(
1544     ArgList *p_arglist,
1545     Arg     *arg
1546 )
1547 {
1548     ArgList result;
1549     int     nargs= 0;
1550
1551     if ((nargs = objxm_get_num_args(*p_arglist)) == 0)
1552     {            /* first time ever */
1553         result  = objxmP_merge_arglists(arg, 1, (ArgList)NULL, 0);
1554         *p_arglist = result;
1555     }
1556     else
1557     {   /* merge with existing args */
1558         result = objxmP_merge_arglists(arg, 1, *p_arglist, nargs);
1559         XtFree((char *)*p_arglist);
1560         *p_arglist = result;
1561     }
1562     return 0;
1563 }
1564
1565
1566 ArgList
1567 objxmP_merge_arglists(
1568     ArgList args1, 
1569     int num_args1, 
1570     ArgList args2, 
1571     int num_args2
1572 )
1573 {
1574         ArgList result, args;
1575         Arg     nullarg = {NULL, 0};
1576
1577         result = (ArgList)XtMalloc((unsigned) (num_args1 + num_args2 + 1) *
1578                                 sizeof(Arg));
1579         for (args = result; num_args1 != 0; num_args1--)
1580                 *args++ = *args1++;
1581         for ( ; num_args2 != 0; num_args2--)
1582                 *args++ = *args2++;
1583
1584         /* ensure last arg is NULL */
1585         *args = nullarg;
1586         return result;
1587 }
1588
1589 int
1590 objxmP_set_attachment_arg(
1591     ABObj            obj,
1592     OBJXM_CONFIG_TYPE   ctype,
1593     ABObj            parent_obj,
1594     AB_COMPASS_POINT dir
1595 )
1596 {
1597     String         att_side_resource;
1598     String         att_widget_resource;
1599     String         att_offset_resource;
1600     String         att_pos_resource;
1601     AB_ATTACH_TYPE type;
1602     void           *value;
1603     int            offset;
1604     ABObj          att_obj;
1605
1606     switch(dir)
1607     {
1608         case AB_CP_NORTH:
1609             att_side_resource   = XmNtopAttachment;
1610             att_widget_resource = XmNtopWidget;
1611             att_offset_resource = XmNtopOffset;
1612             att_pos_resource    = XmNtopPosition;
1613             break;
1614         case AB_CP_WEST:
1615             att_side_resource   = XmNleftAttachment;
1616             att_widget_resource = XmNleftWidget;
1617             att_offset_resource = XmNleftOffset;
1618             att_pos_resource    = XmNleftPosition;
1619             break;
1620         case AB_CP_EAST:
1621             att_side_resource   = XmNrightAttachment;
1622             att_widget_resource = XmNrightWidget;
1623             att_offset_resource = XmNrightOffset;
1624             att_pos_resource    = XmNrightPosition;
1625             break;
1626         case AB_CP_SOUTH:
1627             att_side_resource   = XmNbottomAttachment;
1628             att_widget_resource = XmNbottomWidget;
1629             att_offset_resource = XmNbottomOffset;
1630             att_pos_resource    = XmNbottomPosition;
1631             break;
1632     }
1633     type   = obj_get_attach_type(obj, dir);
1634     value  = obj_get_attach_value(obj, dir);
1635     offset = obj_get_attach_offset(obj, dir);
1636     switch(type)
1637     {
1638         case AB_ATTACH_POINT:
1639             objxm_obj_set_literal_ui_arg(obj, ctype, att_side_resource, XmATTACH_FORM);
1640             objxm_obj_set_ui_arg(obj, AB_ARG_INT,     att_offset_resource, offset);
1641             break;
1642         case AB_ATTACH_OBJ:
1643         case AB_ATTACH_ALIGN_OBJ_EDGE:
1644             att_obj    = (ABObj)value;
1645             if (att_obj)
1646             {
1647                 /* If has an attachment to a widget which isn't generated in
1648                  * code(window status area), then move the attachment to its parent
1649                  */
1650                 if (ctype == OBJXM_CONFIG_CODEGEN && obj_has_flag(att_obj, NoCodeGenFlag))
1651                     att_obj = parent_obj;
1652
1653                 if (att_obj == parent_obj)
1654                     objxm_obj_set_literal_ui_arg(obj, ctype, att_side_resource, 
1655                         (type==AB_ATTACH_OBJ? XmATTACH_FORM : XmATTACH_OPPOSITE_FORM));
1656                 else
1657                 {
1658                     objxm_obj_set_literal_ui_arg(obj, ctype, att_side_resource, 
1659                         (type==AB_ATTACH_OBJ? XmATTACH_WIDGET : XmATTACH_OPPOSITE_WIDGET));
1660                     objxm_obj_set_widget_ui_arg(obj, ctype, att_widget_resource, att_obj);
1661                 }
1662                 objxm_obj_set_ui_arg(obj, AB_ARG_INT, att_offset_resource, offset);
1663             }
1664             else if (util_get_verbosity() > 0)
1665             {
1666                 char    name[256];
1667                 obj_get_safe_name(obj, name, 256);
1668                 util_printf_err(catgets(OBJXM_MESSAGE_CATD, OBJXM_MESSAGE_SET, 3,
1669                       "ERROR: %s: NULL Object attachment\n"), name);
1670             }
1671             break;
1672
1673         case AB_ATTACH_GRIDLINE: 
1674         case AB_ATTACH_CENTER_GRIDLINE: 
1675             objxm_obj_set_literal_ui_arg(obj, ctype, att_side_resource, XmATTACH_POSITION); 
1676             objxm_obj_set_ui_arg(obj, AB_ARG_INT,     att_pos_resource, value); 
1677             objxm_obj_set_ui_arg(obj, AB_ARG_INT,     att_offset_resource, offset);
1678             break; 
1679
1680         case AB_ATTACH_NONE:
1681         default:
1682             objxm_obj_set_literal_ui_arg(obj, ctype, att_side_resource, XmATTACH_NONE);
1683             break;
1684     }
1685     obj_set_flag(obj, AttrChangedFlag);
1686     return OK;
1687 }