Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / abmf / ui_c_file.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: ui_c_file.c /main/3 1995/11/06 18:15:01 rswiston $
26  * 
27  *      @(#)ui_c_file.c 3.115 21 Mar 1995
28  * 
29  * RESTRICTED CONFIDENTIAL INFORMATION:
30  * 
31  * The information in this document is subject to special restrictions in a
32  * confidential disclosure agreement between HP, IBM, Sun, USL, SCO and
33  * Univel.  Do not distribute this document outside HP, IBM, Sun, USL, SCO,
34  * or Univel without Sun's specific written approval.  This document and all
35  * copies and derivative works thereof must be returned or destroyed at Sun's
36  * request.
37  * 
38  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  * 
40  */
41
42
43 /*
44  * Write a file containing object initialization functions (module_ui.c).
45  * These functions will be compiled and linked with the application.
46  * 
47  * 
48  */
49
50 #include <string.h>
51 #include <stdio.h>
52 #include <ab_private/AB.h>
53 #include <ab/util_types.h>
54 #include <ab_private/abio.h>
55 #include <ab_private/objxm.h>
56 #include <ab_private/strlist.h>
57 #include "abmfP.h"
58 #include "argsP.h"
59 #include "utilsP.h"
60 #include "instancesP.h"
61 #include "cdefsP.h"
62 #include "create_declsP.h"
63 #include "write_cP.h"
64 #include "obj_namesP.h"
65 #include "ui_header_fileP.h"    /* write_widget_specific_includes */
66 #include "ui_c_fileP.h"
67 #include "lib_func_stringsP.h"
68 #include "msg_cvt.h"
69
70 static int      write_all_obj_clear_procs(
71                         GenCodeInfo genCodeInfo, ABObj rootObj);
72 static int      write_all_obj_create_procs(GenCodeInfo genCodeInfo, ABObj rootObj);
73 static int      write_call_create_proc(
74                                 GenCodeInfo genCodeInfo, 
75                                 ABObj obj);
76 static int      write_manage_widgets(
77                         GenCodeInfo     genCodeInfo, 
78                         ABObj           obj
79                 );
80 static int      write_manage_one_tree(
81                         GenCodeInfo     genCodeInfo, 
82                         ABObj           obj
83                 );
84 static int      write_manage_descendants(
85                         GenCodeInfo     genCodeInfo, 
86                         ABObj           obj
87                 );
88 static int write_out_mainwin_set_areas(GenCodeInfo genCodeInfo, ABObj obj);
89 static int write_out_dialog_set_pane_height(GenCodeInfo genCodeInfo, ABObj obj);
90 static int write_add_widget_ref_resources(GenCodeInfo genCodeInfo, ABObj root);
91 static BOOL     obj_should_be_managed_when_initialized(ABObj obj);
92 static BOOL     abmfP_obj_has_unmanaged_child(ABObj obj);
93 static int      write_action_target_includes(
94                         GenCodeInfo     genCodeInfo, 
95                         ABObj           module
96                 );
97
98 static int      write_call_all_user_post_create_procs(
99                         GenCodeInfo     genCodeInfo, 
100                         ABObj           obj
101                 );
102 static int      write_call_user_post_create_procs(
103                         GenCodeInfo genCodeInfo, 
104                         ABObj obj
105                 );
106 static int      write_msg_init_proc(
107                     GenCodeInfo genCodeInfo, 
108                     ABObj       parent
109                 );
110 static int      write_msg_clear_proc(
111                     GenCodeInfo genCodeInfo,
112                     ABObj       module
113                 );
114
115 static int      abmfP_obj_get_num_conns_by_when(
116                     ABObj       obj,
117                     AB_WHEN     when
118                 );
119
120 static ABObj    abmfP_obj_get_conn_by_when(
121                     ABObj       obj,
122                     AB_WHEN     when,
123                     int         which_conn
124                 );
125
126 static StringList abmfP_get_msg_action_list(
127                     ABObj   msg_obj
128                 );
129
130
131 static STRING
132 strip_spaces_and_dots(char *mname)
133 {
134     static char         new_name[MAXPATHLEN];
135     char               *p;
136
137     strcpy(new_name, mname);
138     p = (char *) strrchr(new_name, '.');
139     if (p)
140         p = (char *) strrchr(p, '.');
141     if (p)
142         p = (char *) strrchr(p, '.');
143     if (p)
144         p = (char *) strrchr(p, ' ');
145     return new_name;
146 }
147
148
149 /*
150  * Traverse object list and write out Widget decls.
151  */
152 static int
153 write_all_shared_var_decls(GenCodeInfo genCodeInfo, ABObj module)
154 {
155     File                codeFile = genCodeInfo->code_file;
156     AB_TRAVERSAL        trav;
157     ABObj               ui_obj = NULL;
158
159     /*
160      * Define the widgets in this module
161      */
162     for (trav_open(&trav, module, AB_TRAV_UI);
163          (ui_obj = trav_next(&trav)) != NULL;)
164     {
165         if (obj_is_window(ui_obj))
166         {
167             abio_printf(codeFile, "\n%s\t%s = \n",
168                     abmfP_get_c_struct_type_name(ui_obj),
169                     abmfP_get_c_struct_global_name(ui_obj));
170             abio_printf(codeFile, "{\n    False\t /* initialized */\n};\n");
171         }
172         else if (obj_is_message(ui_obj))
173         {
174             abio_printf(codeFile, "%s\t%s;\n",
175                     "DtbMessageDataRec",
176                     abmfP_get_c_struct_global_name(ui_obj));
177         }
178     }
179     trav_close(&trav);
180
181     return 0;
182 }
183
184
185 static int
186 write_call_create_proc(GenCodeInfo genCodeInfo, ABObj obj)
187 {
188     File codeFile= genCodeInfo->code_file;
189     char        createProc[1024];
190     ABObj       structObj = NULL;
191     ABObj       item = NULL;
192
193     strcpy(createProc, abmfP_get_create_proc_name(obj));
194
195     abio_printf(codeFile, "%s(", createProc);
196     structObj = abmfP_obj_get_struct_obj(obj);
197     if ((structObj != NULL) && (structObj == abmfP_ip_obj(genCodeInfo)))
198     {
199         abio_printf(codeFile, "instance");
200     }
201     else
202     {
203         abio_printf(codeFile, "&(%s)", abmfP_get_c_name(genCodeInfo, obj));
204     }
205
206     abio_indent(codeFile);
207
208     if (abmfP_obj_create_proc_has_parent_param(obj))
209     {
210         STRING  parentName = NULL;
211
212         /*
213         if (   (obj == abmfP_ip_obj(genCodeInfo))
214             && (abmfP_parent_param(genCodeInfo) != NULL))
215         {
216             parentName = istr_string(abmfP_parent_param(genCodeInfo));
217         }
218         else
219         */
220         {
221             parentName = abmfP_get_widget_parent_name(genCodeInfo, obj);
222         }
223         abio_puts(codeFile, ",\n");
224         abio_printf(codeFile, "%s", parentName);
225     }
226
227     /*
228      * Write out submenu parameters
229      */
230     {
231         int     num_submenus = abmfP_get_num_cp_submenu_params(obj);
232         int     submenu_num = 0;
233         ABObj   submenuObj = NULL;
234
235         for (submenu_num = 0; submenu_num < num_submenus; ++submenu_num)
236         {
237             submenuObj = abmfP_get_cp_submenu_param_obj(obj, submenu_num);
238             if (submenuObj == NULL)
239             {
240                 break;
241             }
242             abio_puts(codeFile, ",\n");
243             abio_printf(codeFile, "%s", 
244                 abmfP_get_c_name(genCodeInfo, submenuObj));
245         }
246     }
247
248     abio_puts(codeFile, ");\n");
249     abio_outdent(codeFile);
250
251     obj_set_was_written(obj, TRUE);
252
253     return 0;
254 }
255
256
257 static int
258 write_all_call_create_procs(GenCodeInfo genCodeInfo, ABObj root)
259 {
260     AB_TRAVERSAL        trav;
261     ABObj               obj;
262     int         inst= 0;
263
264     for (trav_open(&trav, root, AB_TRAV_UI | AB_TRAV_MOD_PARENTS_FIRST);
265         (obj= trav_next(&trav)) != NULL; )
266     {
267         if (abmfP_obj_has_create_proc(obj))
268         {
269             write_call_create_proc(genCodeInfo, obj);
270             ++inst;
271         }
272         else if (obj_is_menu_ref(obj))
273         {
274             write_call_create_proc(genCodeInfo, obj);
275             ++inst;
276         }
277     }
278     trav_close(&trav);
279     return inst;
280 }
281
282
283 static int
284 write_add_widget_ref_resources(GenCodeInfo genCodeInfo, ABObj root)
285 {
286     File                codeFile= genCodeInfo->code_file;
287     AB_TRAVERSAL        trav;
288     ABObj               obj;
289     STRING              c_name= NULL;
290     ABObj               menu = NULL;
291
292     abio_printf(codeFile, "\n");
293     abmfP_write_c_comment(genCodeInfo, FALSE, 
294         "Add widget-reference resources.");
295     for (trav_open(&trav, root, AB_TRAV_UI | AB_TRAV_MOD_PARENTS_FIRST);
296         (obj= trav_next(&trav)) != NULL; )
297     {
298         menu = obj_get_menu(obj);
299         if (obj_is_item(obj) && (menu != NULL))
300         {
301             c_name= abmfP_get_c_name(genCodeInfo, obj);
302             abio_printf(codeFile, "XtVaSetValues(%s,\n", c_name);
303             abio_indent(codeFile);
304             abio_printf(codeFile, "XmNsubMenuId, %s,\n",
305                 abmfP_get_c_name(genCodeInfo, menu));
306             abio_puts(codeFile, "NULL);\n");
307             abio_outdent(codeFile);
308         }
309
310         /*
311          * Register popup menus
312          */
313         if ((menu != NULL) && (obj_is_root(obj)) && (obj_is_popup(menu)))
314         {
315             ABObj menuParent = 
316                         objxm_comp_get_subobj(obj, AB_CFG_MENU_PARENT_OBJ);
317             abio_printf(codeFile, "%s(%s,\n",
318                 abmfP_lib_popup_menu_register->name,
319                 abmfP_get_c_name(genCodeInfo, menu));
320                 
321             abio_indent(codeFile);
322             abio_printf(codeFile, "%s);\n",
323                 abmfP_get_c_name(genCodeInfo, menuParent));
324             abio_outdent(codeFile);
325         }
326
327         if (abmfP_get_num_args_of_classes(obj, ABMF_ARGCLASS_WIDGET_REF) < 1)
328         {
329             continue;
330         }
331
332         c_name= abmfP_get_c_name(genCodeInfo, obj);
333         abio_printf(codeFile, "\n");
334         abmfP_xt_va_list_open_setvalues(genCodeInfo, obj);
335         abmfP_obj_spew_args(genCodeInfo, 
336                 obj, ABMF_ARGCLASS_WIDGET_REF, ABMF_ARGFMT_VA_LIST);
337         abmfP_xt_va_list_close(genCodeInfo);
338     }
339     trav_close(&trav);
340
341     return 0;
342 }
343
344
345 static int
346 write_manage_widgets(
347                         GenCodeInfo     genCodeInfo, 
348                         ABObj           tree
349 )
350 {
351     AB_TRAVERSAL        trav;
352     ABObj               obj = NULL;
353
354     /*
355      * Manage the windows
356      */
357     for (trav_open(&trav, tree, AB_TRAV_WINDOWS);
358         (obj = trav_next(&trav)) != NULL; )
359     {
360         write_manage_one_tree(genCodeInfo, obj);
361     }
362     trav_close(&trav);
363
364     return 0;
365 }
366
367
368 static int
369 write_manage_one_tree(
370                         GenCodeInfo     genCodeInfo, 
371                         ABObj           tree
372 )
373 {
374     write_manage_descendants(genCodeInfo, tree);
375     if (obj_should_be_managed_when_initialized(tree))
376     {
377         abio_printf(genCodeInfo->code_file, "XtManageChild(%s);\n",
378             abmfP_get_c_name(genCodeInfo, tree));
379     }
380
381     return 0;
382 }
383
384
385 /*
386  * 
387  */
388 static int
389 write_manage_descendants(
390                         GenCodeInfo genCodeInfo, 
391                         ABObj obj
392 )
393 {
394     AB_TRAVERSAL        childTrav;
395     ABObj               child = NULL;
396
397     for (trav_open(&childTrav, obj, AB_TRAV_CHILDREN);
398         (child = trav_next(&childTrav)) != NULL; )
399     {
400         if (obj_is_ui(child))
401         {
402             write_manage_descendants(genCodeInfo, child);
403         }
404     }
405     trav_close(&childTrav);
406
407     /* Manage the children
408      * Manage them, if it is a composite and has children.
409      * Managing the child of a dialog shell will cause the shell to become
410      * visible, so don't manage the children of shells that aren't visible
411      */
412     if (   (!(   ObjWClassIsDialogShell(obj) 
413               && (!obj_is_initially_visible(obj))))
414         && (ObjWClassIsCompositeSubclass(obj))
415         && (abmfP_obj_has_field(obj))
416         && (obj_has_child(obj))
417        )
418     {
419         if (   abmfP_obj_has_unmanaged_child(obj)
420             || ObjWClassIsCommand(obj)
421             || ObjWClassIsFileSelectionBox(obj)
422             || ObjWClassIsMainWindow(obj)
423             || ObjWClassIsPanedWindow(obj)
424             || ObjWClassIsScrolledWindow(obj)
425            )
426         {
427             /* This object has one or more unmanaged children.
428              * Manage each child individually.
429              *
430              * Or, the widget class has a complex private structure (e.g.,
431              * ScrolledWindow), and we can't rely on XmNchildren.
432              */
433             AB_TRAVERSAL        unmanagedTrav;
434             ABObj               child = NULL;
435             for (trav_open(&unmanagedTrav, obj, AB_TRAV_CHILDREN);
436                 (child = trav_next(&unmanagedTrav)) != NULL; )
437             {
438                 if (obj_should_be_managed_when_initialized(child))
439                 {
440                     abio_printf(genCodeInfo->code_file,
441                         "XtManageChild(%s);\n",
442                             abmfP_get_c_name(genCodeInfo, child));
443                 }
444             }
445             trav_close(&unmanagedTrav);
446         }
447         else
448         {
449             /* All children managed - just manage 'em all 
450              */
451             abio_printf(genCodeInfo->code_file, "XtVaGetValues(%s,\n",
452                 abmfP_get_c_name(genCodeInfo, obj));
453             abio_indent(genCodeInfo->code_file);
454             abio_puts(genCodeInfo->code_file, 
455               "XmNchildren, &children, XmNnumChildren, &numChildren, NULL);\n");
456             abio_outdent(genCodeInfo->code_file);
457             abio_printf(genCodeInfo->code_file,
458                 "XtManageChildren(children, numChildren);\n");
459         }
460     }
461     return 0;
462 }
463
464 static int
465 write_out_mainwin_set_areas(GenCodeInfo genCodeInfo, ABObj obj)
466 {
467     ABObj       mainwin, menubar, toolbar, workarea, footer;
468
469     if (!obj_is_base_win(obj))
470         return 0;
471
472     mainwin = objxm_comp_get_subobj(obj, AB_CFG_WINDOW_MW_OBJ);
473     menubar = objxm_comp_mainwin_get_area(obj, AB_CONT_MENU_BAR);
474     toolbar = objxm_comp_mainwin_get_area(obj, AB_CONT_TOOL_BAR);
475     footer  = objxm_comp_mainwin_get_area(obj, AB_CONT_FOOTER);
476     workarea = objxm_comp_get_subobj(obj, AB_CFG_PARENT_OBJ);
477
478     if (menubar || toolbar)
479     {
480         abio_printf(genCodeInfo->code_file,
481             "XmMainWindowSetAreas(%s,\n", abmfP_get_c_name(genCodeInfo,mainwin));
482
483         abio_indent(genCodeInfo->code_file);
484
485         abio_printf(genCodeInfo->code_file, "%s,\n",
486             menubar? abmfP_get_c_name(genCodeInfo, menubar) : "NULL");
487
488         abio_printf(genCodeInfo->code_file, "%s,\n",
489             toolbar? abmfP_get_c_name(genCodeInfo, toolbar) : "NULL");
490
491         abio_printf(genCodeInfo->code_file, "NULL,\n");
492         abio_printf(genCodeInfo->code_file, "NULL,\n");
493
494         abio_printf(genCodeInfo->code_file, "%s);\n",
495             workarea? abmfP_get_c_name(genCodeInfo, workarea) : "NULL");
496
497         abio_outdent(genCodeInfo->code_file);
498     }
499     if (footer)
500     {
501         abio_printf(genCodeInfo->code_file,
502             "XtVaSetValues(%s,\n", abmfP_get_c_name(genCodeInfo, mainwin));
503
504         abio_indent(genCodeInfo->code_file);
505
506         abio_printf(genCodeInfo->code_file,
507             "XmNmessageWindow, %s,\n",
508                 abmfP_get_c_name(genCodeInfo, footer));
509         abio_printf(genCodeInfo->code_file, "NULL);\n");
510
511         abio_outdent(genCodeInfo->code_file);
512     }
513     return 0;
514 }
515
516 static int
517 write_set_fixed_pane(GenCodeInfo genCodeInfo, ABObj pane)
518 {
519
520     abio_printf(genCodeInfo->code_file, 
521         "XtVaGetValues(%s,\n",
522         abmfP_get_c_name(genCodeInfo, pane));
523     abio_indent(genCodeInfo->code_file);
524     abio_printf(genCodeInfo->code_file, "XmNheight, &pane_height,\n");
525     abio_printf(genCodeInfo->code_file, "NULL);\n");
526     abio_outdent(genCodeInfo->code_file); 
527  
528     abio_printf(genCodeInfo->code_file,  
529         "XtVaSetValues(%s,\n", 
530         abmfP_get_c_name(genCodeInfo, pane)); 
531  
532     abio_indent(genCodeInfo->code_file);   
533  
534     abio_printf(genCodeInfo->code_file, 
535         "XmNpaneMinimum,   pane_height,\n");
536     abio_printf(genCodeInfo->code_file,
537         "XmNpaneMaximum,   pane_height,\n");
538     abio_printf(genCodeInfo->code_file, "NULL);\n\n"); 
539  
540     abio_outdent(genCodeInfo->code_file); 
541
542     return 0;
543 }
544
545 static int
546 write_out_dialog_set_pane_height(GenCodeInfo genCodeInfo, ABObj obj)
547 {
548     ABObj       dialog, panedwin, button_panel, footer;
549  
550     if (!obj_is_popup_win(obj))
551         return 0;
552
553     panedwin = objxm_comp_get_subobj(obj, AB_CFG_WINDOW_PW_OBJ);
554     button_panel = objxm_comp_custdlg_get_area(obj, AB_CONT_BUTTON_PANEL);
555     footer  = objxm_comp_custdlg_get_area(obj, AB_CONT_FOOTER);
556
557     if (button_panel || footer)
558     {
559         abmfP_write_c_comment(genCodeInfo, FALSE,
560                 "Make Dialog Button-Panel & Footer a fixed height");
561
562         abio_printf(genCodeInfo->code_file, "{\n");
563         abio_indent(genCodeInfo->code_file); 
564
565         abio_printf(genCodeInfo->code_file,"Dimension   pane_height;\n\n");
566
567         if (button_panel)
568             write_set_fixed_pane(genCodeInfo, button_panel);
569
570         if (footer)
571             write_set_fixed_pane(genCodeInfo, footer);
572
573         abio_outdent(genCodeInfo->code_file);
574         abio_printf(genCodeInfo->code_file, "}\n");
575     }
576     return 0;
577 }
578
579
580 /*
581  * Don't manage popup windows or menus
582  *
583  * Where all the children of a widget are to be managed, use 
584  * XtManageChildren(). That's supposed to be more efficient than
585  * managing each child, individually.
586  */
587 static BOOL
588 obj_should_be_managed_when_initialized(ABObj obj)
589 {
590     ABObj       wholeObj = obj_get_root(obj);
591     ABObj       itemParentObj = NULL;
592
593     if (!abmfP_obj_has_field(obj))
594     {
595         return FALSE;
596     }
597
598     /*
599      * Menus are not managed until needed
600      */
601     if (obj_is_menu(obj))
602     {
603         return FALSE;
604     }
605
606     /*
607      * Shells are not managed (Xt error!)
608      * The top composite in a dialog is not managed, so that the dialog
609      *     will not become visible until needed.
610      */
611     if (    ObjWClassIsShellSubclass(obj)
612         || (   (abmfP_parent(obj) != NULL) 
613             && (((abmfP_parent(obj))->type == AB_TYPE_DIALOG)
614                 || ((abmfP_parent(obj))->type == AB_TYPE_FILE_CHOOSER))
615             && (ObjWClassIsDialogShell(abmfP_parent(obj)))) )
616     {
617         return FALSE;
618     }
619
620     /*
621      * The item parent for an option menu is really a menu pane
622      */
623     if (wholeObj != NULL)
624     {
625         itemParentObj = objxm_comp_get_subobj(wholeObj, AB_CFG_PARENT_OBJ);
626     }
627     if (   obj_is_menu(obj)
628         || (obj_is_option_menu(wholeObj) && (obj == itemParentObj)) )
629     {
630         return FALSE;
631     }
632
633     if (!obj_is_initially_visible(obj))
634         return FALSE;
635
636     return TRUE;
637 }
638
639
640 static BOOL
641 abmfP_obj_has_unmanaged_child(ABObj obj)
642 {
643     AB_TRAVERSAL        trav;
644     ABObj               child = NULL;
645     BOOL                doesIt = FALSE;
646
647     for (trav_open(&trav, obj, AB_TRAV_CHILDREN);
648         (child = trav_next(&trav)) != NULL; )
649     {
650         /* menus don't show up in XmNchildren list, so we need to ignore them
651          */
652         if (   abmfP_obj_has_field(child)
653             && (!obj_is_menu(child))
654             && (!ObjWClassIsMenuShell(child))
655             && (!ObjWClassIsPulldownMenu(child))
656             && (!ObjWClassIsPopupMenu(child))
657             && (!obj_should_be_managed_when_initialized(child)) )
658         {
659             /* this is an unmanaged child */
660             doesIt = TRUE;
661             break;
662         }
663     }
664     trav_close(&trav);
665
666     return doesIt;
667 }
668
669
670 /* 
671  * Write out one object clear proc
672  */
673 static int
674 write_obj_clear_proc(GenCodeInfo genCodeInfo, ABObj obj)
675 {
676     File        file= genCodeInfo->code_file;
677     abmfP_write_clear_proc_begin(genCodeInfo, obj);
678     abio_printf(file,
679         "memset((void *)(%s), 0, sizeof(*%s));\n",
680         abmfP_instance_ptr_var_name,
681         abmfP_instance_ptr_var_name
682         );
683     abmfP_write_c_func_end(genCodeInfo, "0");
684     return 0;
685 }
686
687
688 /*
689  * Write out one object initialization proc
690  */
691 static int
692 write_obj_init_proc(GenCodeInfo genCodeInfo, ABObj parent)
693 {
694     int                 return_value= 0;
695     File                codeFile = genCodeInfo->code_file;
696     ABObj               obj;
697     ABObj               whole_obj = NULL;
698     int                 inst = FALSE;
699     AB_TRAVERSAL        trav;
700
701     abmfP_gencode_enter_func(genCodeInfo);
702     genCodeInfo->cur_func.ip_obj= abmfP_obj_get_struct_obj(parent);
703     genCodeInfo->cur_func.create_obj= abmfP_obj_get_struct_obj(parent);
704     abmfP_parent_param(genCodeInfo) = istr_const(abmfP_parent_param_name);
705     abmfP_parent_param_has_value(genCodeInfo) = TRUE;
706
707     abmfP_write_init_proc_begin(genCodeInfo, parent);
708
709     abio_printf(codeFile, "WidgetList\tchildren = NULL;\n");
710     abio_printf(codeFile, "int\t\tnumChildren = 0;\n");
711     abio_printf(codeFile, "if (%s->initialized)\n", 
712         abmfP_instance_ptr_var_name);
713     abmfP_write_c_block_begin(genCodeInfo);
714     abio_puts(codeFile, "return 0;\n");
715     abmfP_write_c_block_end(genCodeInfo);
716     abio_printf(codeFile, "%s->initialized = True;\n\n",
717         abmfP_instance_ptr_var_name);
718
719     inst= write_all_call_create_procs(genCodeInfo, parent);
720     write_add_widget_ref_resources(genCodeInfo, parent);
721
722     /*
723      * Write out code to layout groups
724      */
725     abio_printf(codeFile, "\n");
726     abmfP_write_c_comment(genCodeInfo, FALSE, 
727         "Call utility functions to do group layout");
728     for (trav_open(&trav, parent, AB_TRAV_GROUPS);
729          (obj = trav_next(&trav)) != NULL;)
730     {
731         if (abmfP_obj_needs_align_handler(obj))
732         {
733             ABObj       oobj = objxm_comp_get_subobj(obj, AB_CFG_OBJECT_OBJ);
734
735             abio_printf(codeFile, "\n");
736
737             abio_printf(genCodeInfo->code_file, 
738                 "%s(%s,\n\t\t%s,\n\t\t%s,\n\t\t%s,\n\t\t%d, %d, %d, %d, %d);\n",
739                 abmfP_lib_children_align->name,
740                 abmfP_get_c_name(genCodeInfo, oobj),
741                 abmfP_obj_get_group_type(obj),
742                 abmfP_obj_get_row_align_type(obj),
743                 abmfP_obj_get_col_align_type(obj),
744                 0,
745                 obj_get_num_rows(obj),
746                 obj_get_num_columns(obj),
747                 obj_get_hoffset(obj),
748                 obj_get_voffset(obj));
749         }
750     }
751     trav_close(&trav);
752
753     abio_printf(codeFile, "\n");
754     if (obj_is_base_win(parent))
755         write_out_mainwin_set_areas(genCodeInfo, parent);
756     else if (obj_is_popup_win(parent))
757         write_out_dialog_set_pane_height(genCodeInfo, parent);
758
759     abio_puts(codeFile, nlstr);
760     abmfP_write_c_comment(genCodeInfo, FALSE, 
761         "Manage the tree, from the bottom up.");
762     write_manage_widgets(genCodeInfo, parent);
763     if (obj_is_popup_win(parent))
764     {
765         ABObj   pwObj = objxm_comp_get_subobj(parent, AB_CFG_WINDOW_PW_OBJ);
766         
767         if (pwObj)
768         {
769             abmfP_write_c_comment(genCodeInfo, FALSE,
770                 "Turn off traversal for invisible sash in dialog's PanedWindow");
771             abio_printf(codeFile, "%s(%s);\n",
772                 abmfP_lib_remove_sash_focus->name,      
773                 abmfP_get_c_name(genCodeInfo, pwObj));
774         }
775     }
776
777     /*
778      * Add Callbacks
779      */
780     abio_printf(codeFile, "\n");
781     abmfP_write_c_comment(genCodeInfo, FALSE, 
782         "Add User and Connection callbacks");
783     for (trav_open(&trav, parent, AB_TRAV_UI);
784          (obj = trav_next(&trav)) != NULL;)
785     {
786         if ( ((abmfP_get_window_parent(obj) == parent) || (obj == parent))
787             && (abmfP_write_add_callbacks_and_actions(genCodeInfo, obj) < 0)
788            )
789         {
790             return_code(-1);
791         }
792     }
793     trav_close(&trav);
794
795     abmfP_write_c_func_end(genCodeInfo, "0");
796
797 epilogue:
798     abmfP_gencode_exit_func(genCodeInfo);
799     return return_value;
800 }
801
802
803 static int
804 write_all_obj_init_procs(GenCodeInfo genCodeInfo, ABObj module)
805 {
806     ABObj               obj;
807     AB_TRAVERSAL        trav;
808     BOOL                MsgClearWritten = FALSE;
809
810     abmfP_tree_set_written(module, FALSE);
811     for (trav_open(&trav, module, AB_TRAV_SALIENT_UI);
812          (obj = trav_next(&trav)) != NULL;)
813     {
814 /*
815         if (obj_is_message(obj) && !MsgClearWritten)
816         {
817             write_msg_clear_proc(genCodeInfo, module); 
818             MsgClearWritten = TRUE;
819         }
820         else if (obj_is_window(obj))
821         {
822             write_obj_clear_proc(genCodeInfo, obj);
823         }
824 */
825
826         if (obj_is_window(obj))
827         {
828             write_obj_clear_proc(genCodeInfo, obj);
829             write_obj_init_proc(genCodeInfo, obj);
830         }
831         else if (obj_is_message(obj))
832         {
833             write_msg_init_proc(genCodeInfo, obj);
834         }
835     }
836     trav_close(&trav);
837     abmfP_tree_set_written(module, FALSE);
838     return 0;
839 }
840
841 static int
842 write_create_proc_decls(GenCodeInfo genCodeInfo, ABObj module)
843 {
844     File                codeFile = genCodeInfo->code_file;
845     AB_TRAVERSAL        trav;
846     ABObj               obj;
847     char               *parent = NULL;
848
849     abmfP_tree_set_written(module, FALSE);
850     abio_puts(codeFile, "\n");
851     abmfP_write_c_comment(genCodeInfo, FALSE,
852         "Widget create procedure decls");
853
854     for (trav_open(&trav, module, AB_TRAV_UI);
855          (obj = trav_next(&trav)) != NULL;)
856     {
857         if (!abmfP_obj_has_create_proc(obj))
858         {
859             continue;
860         }
861         abmfP_write_create_proc_decl(genCodeInfo, obj);
862     }
863     trav_close(&trav);
864     abio_puts(codeFile, "\n");
865     return 0;
866 }
867
868
869 static void
870 set_parent_for_submenu(ABObj obj)
871 {
872     ABObj               child = NULL;
873
874     if (obj_has_child(obj))
875     {
876         child = obj_get_child(obj, 0);
877         if (!obj_has_parent(child))
878         {
879             obj_append_child(obj, child);
880         }
881     }
882 }
883
884
885 static int
886 item_has_children(ABObj obj)
887 {
888     return (obj_is_menu_item(obj) && obj_has_child(obj));
889 }
890
891
892 static void
893 check_for_submenus(ABObj obj)
894 {
895     AB_TRAVERSAL        trav;
896     ABObj               child;
897
898     for (trav_open(&trav, obj, AB_TRAV_CHILDREN);
899          (child = trav_next(&trav)) != NULL;)
900     {
901         if (item_has_children(child))
902         {
903             set_parent_for_submenu(child);
904             check_for_submenus(child);
905         }
906     }
907     trav_close(&trav);
908 }
909
910
911 static void
912 assign_parent_to_submenus(ABObj project)
913 {
914     AB_TRAVERSAL        trav;
915     ABObj               obj;
916
917     for (trav_open(&trav, project, AB_TRAV_UI);
918          (obj = trav_next(&trav)) != NULL;)
919     {
920         if (obj_is_menu(obj))
921             check_for_submenus(obj);
922     }
923 }
924
925
926 int
927 write_obj_create_proc(GenCodeInfo genCodeInfo, ABObj obj)
928 {
929     File                codeFile = genCodeInfo->code_file;
930     ABObj               top_obj = NULL;
931     ABObj               ip_obj = abmfP_obj_get_struct_obj(obj);
932     ABObj               help_obj = NULL;
933     int                 num_post_create_procs = 0;
934     STRING              help_volume, help_location, help_text;
935
936     abmfP_gencode_enter_func(genCodeInfo);
937     abmfP_create_obj(genCodeInfo) = obj;
938     abmfP_ip_obj(genCodeInfo) = ip_obj;
939
940     if (abmfP_obj_create_proc_has_parent_param(obj))
941     {
942         abmfP_parent_param(genCodeInfo) = istr_const(abmfP_parent_param_name);
943         abmfP_parent_param_has_value(genCodeInfo) = TRUE;
944     }
945
946     abmfP_write_create_proc_begin(genCodeInfo, obj);
947     abmfP_write_create_proc_decls(genCodeInfo);
948     abmfP_write_create_widgets_for_comp_obj(genCodeInfo, obj);
949     write_call_all_user_post_create_procs(genCodeInfo, obj);
950
951     if (abmfP_obj_needs_centering_handler(obj))
952     {
953         abio_printf(genCodeInfo->code_file, "\t%s(%s, %s);\n",
954                 abmfP_lib_center->name,
955                 abmfP_get_c_name(genCodeInfo, obj),
956                 abmfP_obj_get_centering_type(obj));
957     }
958
959     abmfP_write_c_func_end(genCodeInfo, "0");
960
961     obj_set_was_written(obj, TRUE);
962     abmfP_obj_set_subobjs_written(obj, TRUE);
963     abmfP_obj_set_items_written(obj, TRUE);
964
965 epilogue:
966     abmfP_gencode_exit_func(genCodeInfo);
967     return (OK);
968 }
969
970
971 static int
972 write_call_all_user_post_create_procs(
973                         GenCodeInfo genCodeInfo, 
974                         ABObj           obj
975 )
976 {
977     int                 return_value = 0;
978     int                 total_post_create_procs = 0;
979     ABObj               item = NULL;
980     AB_TRAVERSAL        itemTrav;
981
982     total_post_create_procs += 
983             abmfP_obj_get_num_conns_by_when(obj, AB_WHEN_AFTER_CREATED);
984     for (trav_open(&itemTrav, obj, AB_TRAV_ITEMS_FOR_OBJ);
985         (item = trav_next(&itemTrav)) != NULL; )
986     {
987         total_post_create_procs += 
988             abmfP_obj_get_num_conns_by_when(item, AB_WHEN_AFTER_CREATED);
989     }
990     /* don't close trav, yet */
991
992     if (total_post_create_procs > 0)
993     {
994         abio_puts(genCodeInfo->code_file, "\n");
995         abmfP_write_c_comment(genCodeInfo, FALSE,
996                 "Call user (Post-)Create procs");
997         for (trav_reset(&itemTrav);
998             (item = trav_next(&itemTrav)) != NULL; )
999         {
1000             write_call_user_post_create_procs(genCodeInfo, item);
1001         }
1002
1003         /*
1004          * Call object's last, after all the subobjecs completely inited
1005          */
1006         write_call_user_post_create_procs(genCodeInfo, obj);
1007     }
1008     trav_close(&itemTrav);      /* close it, now */
1009
1010     return return_value;
1011 }
1012
1013
1014 static int
1015 write_call_user_post_create_procs(GenCodeInfo genCodeInfo, ABObj subObj)
1016 {
1017     int         return_value = 0;
1018     int         num_post_create_procs = 0;
1019     ABObj       action = NULL;
1020     ABObj       compObj = obj_get_root(subObj);
1021     ABObj       sourceObj = objxm_comp_get_source_for_when(
1022                                 compObj, AB_WHEN_AFTER_CREATED);
1023     ABObj       targetObj = NULL;
1024     char        targetStructPtrName[MAX_NAME_SIZE];
1025     char        sourceName[MAX_NAME_SIZE];
1026     *targetStructPtrName = 0;
1027     *sourceName = 0;
1028
1029         num_post_create_procs = 
1030             abmfP_obj_get_num_conns_by_when(compObj, AB_WHEN_AFTER_CREATED);
1031         if (num_post_create_procs > 0)
1032         {
1033             int         i = 0;
1034     
1035             for (i = 0; i < num_post_create_procs; ++i)
1036             {
1037                 action = abmfP_obj_get_conn_by_when(
1038                                 compObj, AB_WHEN_AFTER_CREATED, i);
1039                 targetObj = obj_get_to(action);
1040
1041                 /*
1042                  * source widget
1043                  */
1044                 util_strncpy(sourceName, abmfP_get_c_name(
1045                                 genCodeInfo, sourceObj), MAX_NAME_SIZE);
1046
1047                 if (targetObj == NULL)
1048                 {
1049                     strcpy(targetStructPtrName, abmfP_str_null);
1050                 }
1051                 else
1052                 {
1053                     util_strncpy(targetStructPtrName,
1054                         abmfP_get_c_struct_ptr_name(genCodeInfo, targetObj),
1055                         MAX_NAME_SIZE);
1056                 }
1057
1058                 abio_printf(genCodeInfo->code_file,
1059                   "%s(%s, (XtPointer)%s, (XtPointer)%s);\n",
1060                     abmfP_get_action_name(action),
1061                     sourceName,
1062                     targetStructPtrName,
1063                     abmfP_get_c_struct_ptr_name(genCodeInfo, sourceObj));
1064             }
1065         }
1066     return return_value;
1067 }
1068
1069
1070 /*
1071  * Writes out parents before children
1072  */
1073 static int
1074 write_all_obj_create_procs(GenCodeInfo genCodeInfo, ABObj rootObj)
1075 {
1076     int                 return_value = 0;
1077     int                 rc = 0;         /* return code */
1078     AB_TRAVERSAL        trav;
1079     ABObj               obj = NULL;
1080
1081     for (trav_open(&trav, rootObj, AB_TRAV_UI | AB_TRAV_MOD_PARENTS_FIRST);
1082          (obj = trav_next(&trav)) != NULL;)
1083     {
1084         if (!abmfP_obj_has_create_proc(obj))
1085         {
1086             continue;
1087         }
1088         abio_printf(genCodeInfo->code_file, "\n\n");
1089         if ((rc = write_obj_create_proc(genCodeInfo, obj)) < 0)
1090         {
1091             return_value = rc;
1092             break;
1093         }
1094     }
1095     trav_close(&trav);
1096
1097     return return_value;
1098 }
1099
1100
1101 /*
1102  * 
1103  */
1104 static int
1105 write_includes(GenCodeInfo genCodeInfo, ABObj module)
1106 {
1107     File        codeFile = genCodeInfo->code_file;
1108     int         num_written = 0;
1109     AB_TRAVERSAL        trav;
1110     ABObj               obj = NULL;
1111     BOOL                includeGlyphFiles = FALSE;
1112     STRING              glyphFile = NULL;
1113     StringListRec       glyphIncludesRec;
1114     StringList          glyphIncludes= &(glyphIncludesRec);
1115     strlist_construct(glyphIncludes);
1116
1117     strlist_set_is_unique(glyphIncludes, TRUE);
1118     ++num_written;
1119     abmfP_tree_write_widget_specific_includes(codeFile, module);
1120     abmfP_write_c_local_include(genCodeInfo, 
1121         abmfP_get_utils_header_file_name(module));
1122     abmfP_write_c_local_include(genCodeInfo, 
1123         abmfP_get_project_header_file_name(module));
1124
1125     write_action_target_includes(genCodeInfo, module);
1126
1127     abmfP_write_c_local_include(genCodeInfo,
1128         abmfP_get_ui_header_file_name(module));
1129
1130     if (includeGlyphFiles)
1131     {
1132         for (trav_open(&trav, module, AB_TRAV_SALIENT_UI); 
1133                 (obj = trav_next(&trav)) != NULL; )
1134         {
1135             ++num_written;
1136             if (abmfP_obj_has_glyph_label(obj))
1137             {
1138                 glyphFile = obj_get_label(obj);
1139                 if (!strlist_str_exists(glyphIncludes, glyphFile))
1140                 {
1141                     strlist_add_str(glyphIncludes, glyphFile, NULL);
1142                     abmfP_write_c_local_include(genCodeInfo, glyphFile);
1143                 }
1144             }
1145         }
1146         trav_close(&trav);      /* finally close it */
1147     }
1148
1149     strlist_destruct(glyphIncludes);
1150     return num_written;
1151 }
1152
1153
1154 static int
1155 write_action_target_includes(GenCodeInfo genCodeInfo, ABObj module)
1156 {
1157     int         numIncludes = 0;
1158     ABObj       project = obj_get_project(module);
1159     ABObj       action = NULL;
1160     AB_TRAVERSAL        trav;
1161     ABObj       fromObj = NULL;
1162     ABObj       fromModule = NULL;
1163     ABObj       toObj = NULL;
1164     ABObj       toModule = NULL;
1165     STRING      headerFile = NULL;
1166     StringListRec       targetIncludes;
1167     strlist_construct(&targetIncludes);
1168
1169     /*
1170      * REMIND: this should be AB_TRAV_ACTIONS_FOR_OBJ.
1171      *          Currently, there's a bug that puts cross-module
1172      *          connection under the module, rather than the project
1173      */
1174     for (trav_open(&trav, project, AB_TRAV_ACTIONS);
1175         (action = trav_next(&trav)) != NULL; )
1176     {
1177         fromObj = obj_get_from(action);
1178         fromModule = NULL;
1179         if (fromObj != NULL)
1180         {
1181             fromModule = obj_get_module(fromObj);
1182         }
1183         toObj = obj_get_to(action);
1184         toModule = NULL;
1185         if (toObj != NULL)
1186         {
1187             toModule= obj_get_module(toObj);
1188         }
1189
1190         if ((fromModule != NULL) && (fromModule == module)
1191             && (toModule != NULL) && (toModule != module))
1192         {
1193             /* cross-module connection from this module */
1194             headerFile = abmfP_get_ui_header_file_name(toModule);
1195             if (!strlist_str_exists(&targetIncludes, headerFile))
1196             {    
1197                 strlist_add_str(&targetIncludes, headerFile, NULL);
1198                 abmfP_write_c_local_include(genCodeInfo, headerFile);
1199             }
1200
1201         }
1202     }
1203     trav_close(&trav);
1204
1205     strlist_destruct(&targetIncludes);
1206     return numIncludes;
1207 }
1208
1209
1210
1211 /*
1212  * Write the object initialization function file.
1213  */
1214 int
1215 abmfP_write_ui_c_file(
1216                       GenCodeInfo genCodeInfo,
1217                       STRING codeFileName,
1218                       ABObj module
1219 )
1220 {
1221     File                codeFile = genCodeInfo->code_file;
1222     char                moduleName[1024];
1223     ABObj               obj = NULL;
1224     char               *errmsg = NULL;
1225     *moduleName = 0;
1226
1227     /*
1228      * Write file header.
1229      */
1230     sprintf(moduleName, "module %s", util_strsafe(obj_get_name(module)));
1231     abmfP_write_file_header(
1232                 genCodeInfo, 
1233                 codeFileName,
1234                 FALSE,
1235                 moduleName,
1236                 util_get_program_name(), 
1237                 ABMF_MODIFY_NOT,
1238         " * Contains: user module object initialize and create functions"
1239                 );
1240
1241
1242     /*
1243      * Write includes.
1244      */
1245     write_includes(genCodeInfo, module);
1246
1247     /*
1248      * REMIND: include header files from other modules
1249      */
1250     abio_puts(codeFile, "\n");
1251
1252     assign_parent_to_submenus(module);
1253
1254     /*
1255      * Write the file!
1256      */
1257     write_all_shared_var_decls(genCodeInfo, module);
1258     write_create_proc_decls(genCodeInfo, module);
1259     write_all_obj_init_procs(genCodeInfo, module);
1260     write_all_obj_create_procs(genCodeInfo, module);
1261
1262     return OK;
1263 }
1264
1265
1266 static ABObj    connFromObj = NULL;
1267 static AB_WHEN  connWhen = AB_WHEN_UNDEF;
1268
1269 static BOOL
1270 action_from_pred(ABObj obj)
1271 {
1272    return (   (obj_get_from(obj) == connFromObj) 
1273            && (obj_get_when(obj) == connWhen) );
1274 }
1275
1276
1277 static int 
1278 abmfP_obj_get_num_conns_by_when(
1279                 ABObj   obj,
1280                 AB_WHEN when
1281 )
1282 {
1283     ABObj       project = obj_get_project(obj);
1284     int         numConns = 0;
1285     if (project == NULL)
1286     {
1287         return -1;
1288     }
1289
1290     connFromObj = obj_get_actual_obj(obj); connWhen = when;
1291     numConns = trav_count_cond(project, AB_TRAV_ACTIONS, action_from_pred);
1292     connFromObj = NULL; connWhen = AB_WHEN_UNDEF;
1293     return numConns;
1294 }
1295
1296
1297 static ABObj    
1298 abmfP_obj_get_conn_by_when(
1299                     ABObj       obj,
1300                     AB_WHEN     when,
1301                     int         which_conn
1302 )
1303 {
1304     ABObj               project = obj_get_project(obj);
1305     AB_TRAVERSAL        trav;
1306     ABObj               action = NULL;
1307     if (project == NULL)
1308     {
1309         return NULL;
1310     }
1311
1312     connFromObj = obj_get_actual_obj(obj); connWhen = when;
1313     trav_open_cond(&trav, project, AB_TRAV_ACTIONS, action_from_pred);
1314     trav_goto(&trav, which_conn);
1315     action = trav_obj(&trav);
1316     trav_close(&trav);
1317     connFromObj = NULL; connWhen = AB_WHEN_UNDEF;
1318
1319     return action;
1320 }
1321
1322 static StringList
1323 abmfP_get_msg_action_list(
1324     ABObj   msg_obj
1325 )
1326 {
1327     ABObj       module = NULL;
1328     ABObj       action = NULL;
1329     ABObj       fromObj = NULL; 
1330     AB_TRAVERSAL        trav;
1331     StringList  callback_funcs = strlist_create();
1332
1333     if (!obj_is_message(msg_obj))
1334         return NULL;
1335
1336     module = obj_get_module(msg_obj);
1337     for (trav_open(&trav, module, AB_TRAV_ACTIONS);
1338         (action = trav_next(&trav)) != NULL; )
1339     { 
1340         fromObj = obj_get_from(action);
1341         if (fromObj == msg_obj)
1342         {
1343             strlist_add_str(callback_funcs,
1344                 abmfP_get_action_name(action),
1345                 (void *) obj_get_when(action));
1346         }
1347     }
1348
1349     if (strlist_get_num_strs(callback_funcs) == 0)
1350     {
1351         strlist_destroy(callback_funcs);
1352         callback_funcs = NULL;
1353     }
1354
1355     return (callback_funcs);
1356 }
1357
1358 /*
1359  * Write out one message object initialization proc
1360  */
1361 static int
1362 write_msg_init_proc(GenCodeInfo genCodeInfo, ABObj parent)
1363 {
1364     int                 return_value = 0;
1365     File                codeFile = genCodeInfo->code_file;
1366     STRING              i18n_str = (STRING) NULL;
1367     STRING              dialogType = (STRING) NULL;
1368     STRING              default_btn = (STRING) NULL;
1369     STRING              str = (STRING) NULL;
1370     StringList          callback_funcs = (StringList) NULL;
1371     STRING              callback_func = (STRING) NULL;
1372     STRING              okCB = (STRING) NULL, 
1373                         action2CB = (STRING) NULL, 
1374                         action3CB = (STRING) NULL, 
1375                         cancelCB = (STRING) NULL;
1376     AB_WHEN             when = AB_WHEN_UNDEF;
1377     int                 i = 0;
1378     STRING              help_text = (STRING) NULL,
1379                         help_volume = (STRING) NULL,
1380                         help_location = (STRING) NULL;
1381
1382     abmfP_gencode_enter_func(genCodeInfo);
1383     genCodeInfo->cur_func.ip_obj = abmfP_obj_get_struct_obj(parent);
1384     genCodeInfo->cur_func.create_obj = abmfP_obj_get_struct_obj(parent);
1385     abmfP_parent_param(genCodeInfo) = (ISTRING) NULL;
1386     abmfP_parent_param_has_value(genCodeInfo) = FALSE;
1387
1388     abmfP_write_init_proc_begin(genCodeInfo, parent);
1389
1390     /* Write out one local variable for help I18N */
1391     if ( obj_has_help_data(parent) && 
1392         (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API))
1393     {
1394         abio_puts(codeFile, "char       *tmp_txt;\n");
1395     }
1396
1397     abio_printf(codeFile, "if (%s->initialized)\n", 
1398         abmfP_instance_ptr_var_name);
1399     abmfP_write_c_block_begin(genCodeInfo);
1400     abio_puts(codeFile, "return 0;\n");
1401     abmfP_write_c_block_end(genCodeInfo);
1402     abio_printf(codeFile, "%s->initialized = True;\n\n",
1403         abmfP_instance_ptr_var_name);
1404
1405     /* Set the Message Dialog Type */
1406     switch (obj_get_msg_type(parent))
1407     {
1408         case AB_MSG_ERROR:
1409             dialogType = "XmDIALOG_ERROR";
1410             break;
1411         case AB_MSG_INFORMATION:
1412             dialogType = "XmDIALOG_INFORMATION";
1413             break;
1414         case AB_MSG_QUESTION:
1415             dialogType = "XmDIALOG_QUESTION";
1416             break;
1417         case AB_MSG_WARNING:
1418             dialogType = "XmDIALOG_WARNING";
1419             break;
1420         case AB_MSG_WORKING:
1421             dialogType = "XmDIALOG_WORKING";
1422             break;
1423         default:
1424             break;
1425     }
1426     abio_printf(codeFile, "%s->type = ", abmfP_instance_ptr_var_name);
1427     abio_printf(codeFile, "%s;\n", dialogType);
1428
1429     /* Set Message Dialog Title */
1430     abio_printf(codeFile, "%s->title = ", abmfP_instance_ptr_var_name);
1431     str = obj_get_label(parent);
1432     if (!util_strempty(str))
1433     {
1434         if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) 
1435         {
1436             i18n_str = abmfP_catgets_prefix_str(genCodeInfo, parent, str);
1437             abio_printf(codeFile, "XmStringCreateLocalized(%s", i18n_str);
1438             abio_put_string(codeFile, str);
1439             abio_puts(codeFile, "));\n");
1440         }
1441         else
1442         {
1443             abio_puts(codeFile, "XmStringCreateLocalized(");
1444             abio_put_string(codeFile, str);
1445             abio_puts(codeFile, ");\n");
1446         }
1447     }
1448     else
1449     {
1450         abio_puts(codeFile, "(XmString) NULL;\n");
1451     }
1452
1453     /* Set Message Dialog message string */
1454     abio_printf(codeFile, "%s->message = ", abmfP_instance_ptr_var_name);
1455     str = obj_get_msg_string(parent);
1456     if (!util_strempty(str))
1457     {
1458         if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) 
1459         {
1460             i18n_str = abmfP_catgets_prefix_str(genCodeInfo, parent, str);
1461             abio_printf(codeFile, "XmStringCreateLocalized(%s", i18n_str);
1462             abio_put_string(codeFile, str);
1463             abio_puts(codeFile, "));\n");  
1464         }
1465         else
1466         {
1467             abio_puts(codeFile, "XmStringCreateLocalized("); 
1468             abio_put_string(codeFile, str); 
1469             abio_puts(codeFile, ");\n"); 
1470         }
1471     }
1472     else
1473     {
1474         abio_puts(codeFile, "(XmString) NULL;\n");
1475     }
1476
1477     /* Get callback function names */
1478     callback_funcs = abmfP_get_msg_action_list(parent);
1479     if (callback_funcs != NULL)
1480     {
1481         for (i = 0; i < strlist_get_num_strs(callback_funcs); i++)
1482         {
1483             callback_func = strlist_get_str(callback_funcs, i, (void**)&when);
1484             switch (when)
1485             {
1486                 case AB_WHEN_ACTION1:
1487                     okCB = callback_func;
1488                     break;
1489                 case AB_WHEN_ACTION2:
1490                     action2CB = callback_func;
1491                     break;
1492                 case AB_WHEN_ACTION3:
1493                     action3CB = callback_func;
1494                     break;
1495                 case AB_WHEN_CANCEL:
1496                     cancelCB = callback_func;
1497                     break;
1498             }
1499         }
1500     }
1501
1502
1503     /* Set the Action1 button (Ok button) label */
1504     abio_printf(codeFile, "%s->action1_label = ", abmfP_instance_ptr_var_name);
1505     str = obj_get_action1_label(parent);
1506     if (!util_strempty(str))
1507     {
1508         if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) 
1509         {
1510             i18n_str = abmfP_catgets_prefix_str(genCodeInfo, parent, str);
1511             abio_printf(codeFile, "XmStringCreateLocalized(%s", i18n_str);
1512             abio_put_string(codeFile, str);
1513             abio_puts(codeFile, "));\n");   
1514         }
1515         else
1516         {
1517             abio_puts(codeFile, "XmStringCreateLocalized(");
1518             abio_put_string(codeFile, str);
1519             abio_puts(codeFile, ");\n");
1520         }
1521     }
1522     else
1523     {
1524         abio_puts(codeFile, "(XmString) NULL;\n");
1525     }
1526     
1527     /* Set the Action1 button callback (Ok callback) */
1528     abio_printf(codeFile, "%s->action1_callback = ", abmfP_instance_ptr_var_name);
1529     abio_printf(codeFile, "%s;\n", okCB? okCB : "(XtCallbackProc) NULL");
1530
1531     /* Set the Action2 button label (Extra button) */
1532     abio_printf(codeFile, "%s->action2_label = ", abmfP_instance_ptr_var_name);
1533     str = obj_get_action2_label(parent);
1534     if (!util_strempty(str))
1535     {
1536         if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API)
1537         {
1538             i18n_str = abmfP_catgets_prefix_str(genCodeInfo, parent, str);
1539             abio_printf(codeFile, "XmStringCreateLocalized(%s", i18n_str);
1540             abio_put_string(codeFile, str);
1541             abio_puts(codeFile, "));\n");
1542         }
1543         else
1544         {
1545             abio_puts(codeFile, "XmStringCreateLocalized("); 
1546             abio_put_string(codeFile, str); 
1547             abio_puts(codeFile, ");\n"); 
1548         }
1549     }
1550     else
1551     {
1552         abio_puts(codeFile, "(XmString) NULL;\n");
1553     }
1554
1555     /* Set the Action2 button callback (Extra button) */
1556     abio_printf(codeFile,"%s->action2_callback = ",abmfP_instance_ptr_var_name);
1557     abio_printf(codeFile, "%s;\n", 
1558                 action2CB? action2CB : "(XtCallbackProc) NULL");
1559
1560     /* Set the Action3 button label (Extra button) */
1561     abio_printf(codeFile, "%s->action3_label = ", abmfP_instance_ptr_var_name);
1562     str = obj_get_action3_label(parent);
1563     if (!util_strempty(str))
1564     {
1565         if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API)
1566         {
1567             i18n_str = abmfP_catgets_prefix_str(genCodeInfo, parent, str);
1568             abio_printf(codeFile, "XmStringCreateLocalized(%s", i18n_str);
1569             abio_put_string(codeFile, str);
1570             abio_puts(codeFile, "));\n");
1571         }
1572         else
1573         {
1574             abio_puts(codeFile, "XmStringCreateLocalized(");
1575             abio_put_string(codeFile, str);
1576             abio_puts(codeFile, ");\n");
1577         }
1578     }   
1579     else
1580     {  
1581         abio_puts(codeFile, "(XmString) NULL;\n");
1582     }   
1583  
1584     /* Set the Action3 button callback (Extra button) */
1585     abio_printf(codeFile,"%s->action3_callback = ",abmfP_instance_ptr_var_name);
1586     abio_printf(codeFile, "%s;\n",
1587                 action3CB? action3CB : "(XtCallbackProc) NULL");
1588  
1589     /* Set the Cancel button boolean */
1590     abio_printf(codeFile, "%s->cancel_button = ", abmfP_instance_ptr_var_name);
1591     abio_printf(codeFile, "%s;\n",
1592                 obj_has_cancel_button(parent)? "True":"False");
1593
1594     /* Set the Cancel button callback */
1595     abio_printf(codeFile, "%s->cancel_callback = ", abmfP_instance_ptr_var_name);
1596     abio_printf(codeFile, "%s;\n", cancelCB? cancelCB:"(XtCallbackProc) NULL");
1597
1598     /* Set the Help button boolean */
1599     abio_printf(codeFile, "%s->help_button = ", abmfP_instance_ptr_var_name);
1600     abio_printf(codeFile, "%s;\n",
1601                 obj_has_help_button(parent)? "True":"False");
1602
1603     /* Set Object Help Data */
1604     if (obj_has_help_data(parent))
1605     {
1606         obj_get_help_data(parent, &help_volume, &help_location, &help_text);
1607
1608         /* Set the help text field */
1609         if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API) 
1610         {
1611             i18n_str = abmfP_catgets_prefix_str(genCodeInfo,parent,help_text);
1612             abio_printf(codeFile,"tmp_txt = %s", i18n_str);
1613             abio_put_string(codeFile, help_text);
1614             abio_puts(codeFile, ");\n");
1615             abio_printf(codeFile,
1616                 "%s->help_data.help_text = XtMalloc(strlen(tmp_txt)+1);\n",
1617                 abmfP_instance_ptr_var_name);
1618             abio_printf(codeFile,
1619                 "strcpy(%s->help_data.help_text, tmp_txt);\n",
1620                 abmfP_instance_ptr_var_name);
1621             abio_puts(codeFile,"\n");
1622         }
1623         else
1624         {
1625             abio_printf(codeFile, "%s->help_data.help_text = ",
1626                 abmfP_instance_ptr_var_name);
1627             abio_put_string(codeFile, help_text);
1628             abio_puts(codeFile, ";\n");
1629         }
1630
1631         /* Set the help volume field */
1632         if (!util_strempty(obj_get_help_volume(parent)))
1633         {
1634             abio_printf(codeFile, "%s->help_data.help_volume = ",
1635                 abmfP_instance_ptr_var_name);
1636             abio_put_string(codeFile, help_volume);
1637             abio_puts(codeFile, ";\n");
1638         }
1639         else
1640         {
1641             abio_printf(codeFile,
1642                 "%s->help_data.help_volume = \"\";\n",
1643                 abmfP_instance_ptr_var_name);
1644         }
1645
1646         /* Set the help location field */
1647         if (!util_strempty(obj_get_help_location(parent))) 
1648         { 
1649             abio_printf(codeFile, "%s->help_data.help_locationID = ",
1650                 abmfP_instance_ptr_var_name); 
1651             abio_put_string(codeFile, help_location); 
1652             abio_puts(codeFile, ";\n"); 
1653         }
1654         else
1655         {
1656             abio_printf(codeFile,
1657                 "%s->help_data.help_locationID = \"\";\n",
1658                 abmfP_instance_ptr_var_name);
1659         }
1660     }
1661     else
1662     {
1663         abio_printf(codeFile, 
1664                 "%s->help_data.help_text = (char *) NULL;\n",
1665                 abmfP_instance_ptr_var_name);
1666         abio_printf(codeFile, 
1667                 "%s->help_data.help_volume = \"\";\n",
1668                 abmfP_instance_ptr_var_name);
1669         abio_printf(codeFile, 
1670                 "%s->help_data.help_locationID = \"\";\n",
1671                 abmfP_instance_ptr_var_name);
1672     }
1673
1674     /* Set the default button */
1675     switch(obj_get_default_btn(parent))
1676     {
1677         case AB_DEFAULT_BTN_ACTION1:
1678             default_btn = "DTB_ACTION1_BUTTON";
1679             break;
1680         case AB_DEFAULT_BTN_ACTION2:
1681             default_btn = "DTB_ACTION2_BUTTON";
1682             break;
1683         case AB_DEFAULT_BTN_ACTION3:
1684             default_btn = "DTB_ACTION3_BUTTON";
1685             break;
1686         case AB_DEFAULT_BTN_CANCEL:
1687             default_btn = "DTB_CANCEL_BUTTON";
1688             break;
1689         case AB_DEFAULT_BTN_NONE:
1690             default_btn = "DTB_NONE";
1691             break;
1692         default:
1693             break;
1694     }
1695     abio_printf(codeFile, "%s->default_button = ", abmfP_instance_ptr_var_name);
1696     abio_printf(codeFile, "%s;\n", default_btn);
1697     
1698     abmfP_write_c_func_end(genCodeInfo, "0");
1699
1700 epilogue:
1701     abmfP_gencode_exit_func(genCodeInfo);
1702     return return_value;
1703 }
1704
1705 /* 
1706  * Write out the generic message clear proc 
1707  */
1708 static int
1709 write_msg_clear_proc(
1710     GenCodeInfo genCodeInfo, 
1711     ABObj       module
1712 )
1713 {
1714     File        file = genCodeInfo->code_file;
1715     int         iRet = 0;
1716
1717     iRet = abmfP_write_c_func_begin(
1718             genCodeInfo,
1719             FALSE,                                 /* Is static */
1720             abmfP_str_int,                         /* return type */
1721             abmfP_get_msg_clear_proc_name(module), /* function name */
1722             "DtbMessageData",                     /* Argument type */
1723             abmfP_instance_ptr_var_name,           /* Argument name */
1724             NULL);
1725
1726     abio_printf(file,
1727         "memset((void *)(%s), 0, sizeof(*%s));\n",
1728         abmfP_instance_ptr_var_name,
1729         abmfP_instance_ptr_var_name);
1730
1731     abmfP_write_c_func_end(genCodeInfo, "0");
1732
1733     return iRet;
1734 }