Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / ab / pal_custdlg.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: pal_custdlg.c /main/5 1996/08/08 17:59:53 mustafa $
26  *
27  * @(#)pal_custdlg.c    1.40 15 Feb 1994      cde_app_builder/src/ab
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  * pal_custdlg.c - Implements Palette CustomDialog object functionality
46  */
47 #include <stdio.h>
48 #include <Xm/Xm.h>
49 #include <ab_private/util.h>
50 #include <ab_private/ab.h>
51 #include <ab_private/pal.h>
52 #include <ab_private/proj.h>
53 #include <ab_private/prop.h>
54 #include <ab_private/abobj.h>
55 #include <ab_private/abobj_set.h>
56 #include <ab_private/ui_util.h>
57 #include "custdlg_ui.h"
58
59
60 const int    custdlg_init_height = 175;
61 const int    custdlg_init_width  = 380;
62
63 typedef struct  PROP_CUSTDLG_SETTINGS
64 {
65     Widget                      prop_sheet;
66     PropObjOptionsSettingRec    win_parent;
67     PropFieldSettingRec         name;
68     PropFieldSettingRec         title;
69     PropRadioSettingRec         size_policy;
70     PropGeometrySettingRec      geometry;
71     PropRadioSettingRec         resize_mode;
72     PropCheckboxSettingRec      areas;
73     PropObjOptionsSettingRec    default_but;
74     PropObjOptionsSettingRec    help_but;
75     PropCheckboxSettingRec      init_state;
76     PropColorSettingRec         bg_color;
77     PropColorSettingRec         fg_color;
78     ABObj                       current_obj;
79 } PropCustdlgSettingsRec, *PropCustdlgSettings;
80
81 /*************************************************************************
82 **                                                                      **
83 **       Private Function Declarations                                  **
84 **                                                                      **
85 **************************************************************************/
86 /*
87  * Methods
88  */
89 static int      custdlg_initialize(
90                     ABObj   obj
91                 );
92 static Widget   custdlg_prop_init(
93                     Widget  parent,
94                     AB_PROP_TYPE type
95                 );
96 static int      custdlg_prop_activate(
97                     AB_PROP_TYPE type,
98                     BOOL         active
99                 );
100 static int      custdlg_prop_clear(
101                     AB_PROP_TYPE type
102                 );
103 static int      custdlg_prop_load(
104                     ABObj        obj,
105                     AB_PROP_TYPE type,
106                     unsigned long loadkey
107                 );
108 static int      custdlg_prop_apply(
109                     AB_PROP_TYPE type
110                 );
111 static BOOL     custdlg_prop_pending(
112                     AB_PROP_TYPE type
113                 );
114
115 static BOOL     verify_props(
116                     AB_PROP_TYPE type
117                 );
118 static void     turnoff_changebars(
119                     AB_PROP_TYPE type
120                 );
121
122 static void     custdlg_create_area(
123                     ABObj               obj,
124                     AB_CONTAINER_TYPE   area_type
125                 );
126 static void     custdlg_create_buttons(
127                     ABObj               obj,
128                     ABObj               area
129                 );
130 static void     custdlg_remove_area(
131                     ABObj               obj,
132                     ABObj               area
133                 );
134 static BOOL     button_test_func(
135                     ABObj               obj
136                 );
137 static BOOL     winparent_test_func(
138                     ABObj               obj
139                 );
140
141
142
143 /*************************************************************************
144 **                                                                      **
145 **       Data                                                           **
146 **                                                                      **
147 **************************************************************************/
148
149 PalItemInfo custdlg_palitem_rec = {
150
151     /* type             */  AB_TYPE_DIALOG,
152     /* name             */  "Custom Dialog",
153     /* animation pixmaps*/  NULL,
154     /* number of pixmaps*/  0,
155     /* rev_prop_frame   */  NULL,
156     /* fix_prop_dialog  */  NULL,
157     /* initialize       */  custdlg_initialize,
158     /* is_a_test        */  obj_is_popup_win,
159     /* prop_initialize  */  custdlg_prop_init,
160     /* prop_activate    */  custdlg_prop_activate,
161     /* prop_clear       */  custdlg_prop_clear,
162     /* prop_load        */  custdlg_prop_load,
163     /* prop_apply       */  custdlg_prop_apply,
164     /* prop_pending     */  custdlg_prop_pending
165
166 };
167
168 PalItemInfo *ab_custdlg_palitem = &custdlg_palitem_rec;
169 PropCustdlgSettingsRec prop_custdlg_settings_rec[AB_PROP_TYPE_NUM_VALUES];
170
171
172 /*************************************************************************
173 **                                                                      **
174 **       Function Definitions                                           **
175 **                                                                      **
176 **************************************************************************/
177 static int
178 custdlg_initialize(
179     ABObj     obj
180 )
181 {
182     ABObj       module = obj_get_module(obj);
183     ABObj       win;
184     ABObj       apobj;
185     int         num_wins;
186     int         i;
187
188     /* Find MainWindow to be Custom Dialog's Motif parent.
189      * If none exist, window-parent will remain NULL
190      */
191     num_wins = obj_get_num_children(module);
192     for (i = 0; i < num_wins; i++)
193     {
194         win = obj_get_child(module, i);
195         if (obj_is_base_win(win))
196         {
197             obj_set_win_parent(obj, win);
198             break;
199         }
200     }
201     obj_set_unique_name(obj, "dialog");
202
203     obj_set_label(obj, catgets(Dtb_project_catd, 100, 256, "Custom Dialog"));
204     obj_set_bg_color(obj, "white");
205     obj_set_is_initially_visible(obj, False);
206     obj_set_is_initially_active(obj, True);
207     obj_set_width(obj, custdlg_init_width);
208     obj_set_height(obj, custdlg_init_height);
209
210     /* Create Default Button Panel */
211     apobj = obj_create(AB_TYPE_CONTAINER, obj);
212     obj_set_subtype(apobj, AB_CONT_BUTTON_PANEL);
213     pal_initialize_obj(apobj);
214
215     /* Create Default Buttons for Button Panel */
216     custdlg_create_buttons(obj, apobj);
217
218     return OK;
219
220 }
221
222 static Widget
223 custdlg_prop_init(
224     Widget parent,
225     AB_PROP_TYPE type
226 )
227 {
228     DtbCustdlgPropDialogInfoRec rev_custdlg_prop_dialog; /* Revolving Props */
229     DtbCustdlgPropDialogInfo    cgen = &dtb_custdlg_prop_dialog; /* Codegen structure */
230     DtbRevolvPropDialogInfo     rpd = &(dtb_revolv_prop_dialog);
231     PropCustdlgSettingsRec      *pcs = &(prop_custdlg_settings_rec[type]);
232     Widget                      item[6];
233     int                         item_val[6];
234     int                         i, n;
235
236     if (type == AB_PROP_REVOLVING)
237     {
238         /* Cloning Trick:
239          * Only the Attributes ControlPanel needs to be created within
240          * the existing Revolving Prop dialog, so fill out all other
241          * fields with the Revolving Prop dialog equivelents, so the
242          * dtb initialize proc will skip those non-NULL fields...
243          */
244         dtbCustdlgPropDialogInfo_clear(&rev_custdlg_prop_dialog);
245
246         cgen = &(rev_custdlg_prop_dialog);
247         cgen->prop_dialog = rpd->prop_dialog;
248         cgen->prop_dialog_shellform = rpd->prop_dialog_shellform;
249         cgen->prop_dialog_panedwin = rpd->prop_dialog_panedwin;
250         cgen->prop_dialog_form = rpd->prop_dialog_form;
251         cgen->objlist_panel = rpd->objlist_panel;
252         cgen->objlist_label = rpd->objlist_label2;
253         cgen->objlist_scrolledwin = rpd->objlist_scrolledwin;
254         cgen->objlist = rpd->objlist;
255         cgen->attrs_ctrlpanel_frame = rpd->attrs_ctrlpanel_frame;
256         cgen->activate_panel = rpd->activate_panel;
257         cgen->apply_button = rpd->apply_button;
258         cgen->ok_button = rpd->ok_button;
259         cgen->cancel_button = rpd->cancel_button;
260         cgen->reset_button = rpd->reset_button;
261         cgen->help_button = rpd->help_button;
262
263     }
264     else /* AB_PROP_FIXED */
265         cgen = &dtb_custdlg_prop_dialog;
266
267     if (dtb_custdlg_prop_dialog_initialize(cgen, parent) == 0)
268     {
269         pcs->prop_sheet = cgen->attrs_ctrlpanel;
270         pcs->current_obj = NULL;
271
272         if (type == AB_PROP_REVOLVING)
273                 XtVaSetValues(parent,
274                         XmNuserData, pcs->current_obj,
275                         NULL);
276
277         /* Dialog/Object List */
278         if (type == AB_PROP_FIXED)
279         {
280             prop_fixed_dialog_init(ab_custdlg_palitem,
281                         cgen->prop_dialog_shellform, cgen->objlist);
282             prop_activate_panel_init(type, ab_custdlg_palitem,
283                         cgen->ok_button, cgen->apply_button,
284                         cgen->reset_button, cgen->cancel_button,
285                         cgen->help_button);
286         }
287
288         /* Alternate Editor Buttons */
289         prop_editors_panel_init(type, ab_custdlg_palitem,
290             NULL, cgen->conn_button, cgen->helptxt_button);
291
292         /*
293           * Prop Sheet Settings....
294          */
295
296         /* Name */
297         prop_field_init(&(pcs->name), cgen->name_field_label,
298                 cgen->name_field, cgen->name_cb);
299
300         /* Window Parent */
301         n = 0;
302         item[n] = cgen->winparent_opmenu_items.None_item;
303         item_val[n] = NULL; n++;
304         prop_obj_options_init(&(pcs->win_parent), cgen->winparent_opmenu_label,
305                 cgen->winparent_opmenu, cgen->winparent_opmenu_menu,
306                 n, item, (XtPointer*)item_val,
307                 cgen->winparent_cb, True, /* Display module */
308                 &(pcs->current_obj), winparent_test_func);
309
310         /* Title */
311         prop_field_init(&(pcs->title), cgen->title_field_label, cgen->title_field,
312                 cgen->title_cb);
313
314         /* Resize Mode */
315         n = 0;
316         item[n] = cgen->resizemode_rbox_items.Adjustable_item;
317         item_val[n] = True; n++;
318         item[n] = cgen->resizemode_rbox_items.Fixed_item;
319         item_val[n] = False; n++;
320         prop_radiobox_init(&(pcs->resize_mode), cgen->resizemode_rbox_label,
321                 cgen->resizemode_rbox, n, item, (XtPointer*)item_val,
322                 cgen->resizemode_cb);
323
324         /* Window Areas */
325         n = 0;
326         n = 0;
327         item[n] = cgen->areas_ckbox_items.Button_Panel_item;
328         item_val[n] = AB_CONT_BUTTON_PANEL; n++;
329         item[n] = cgen->areas_ckbox_items.Footer_item;
330         item_val[n] = AB_CONT_FOOTER; n++;
331         prop_checkbox_init(&(pcs->areas), cgen->areas_ckbox_label,
332                 cgen->areas_ckbox, n, item, item_val,
333                 cgen->areas_cb);
334
335         /* Default Button */
336         n = 0;
337         item[n] = cgen->defaultb_opmenu_items.None_item;
338         item_val[n] = NULL; n++;
339         prop_obj_options_init(&(pcs->default_but), cgen->defaultb_opmenu_label,
340                 cgen->defaultb_opmenu, cgen->defaultb_opmenu_menu,
341                 n, item, (XtPointer*)item_val,
342                 cgen->default_button_cb, False, /* don't display module */
343                 &(pcs->current_obj), button_test_func);
344
345         /* Help Button */
346         n = 0;
347         item[n] = cgen->helpb_opmenu_items.None_item;
348         item_val[n] = NULL; n++;
349         prop_obj_options_init(&(pcs->help_but), cgen->helpb_opmenu_label,
350                 cgen->helpb_opmenu, cgen->helpb_opmenu_menu,
351                 n, item, (XtPointer*)item_val,
352                 cgen->help_button_cb, False, /* don't display module */
353                 &(pcs->current_obj), button_test_func);
354
355         /* Size Policy */
356         n = 0;
357         item[n] = cgen->size_policy_rbox_items.Fit_Contents_item;
358         item_val[n] = SIZE_OF_CONTENTS_KEY; n++;
359         item[n] = cgen->size_policy_rbox_items.Fixed_item;
360         item_val[n] = SIZE_FIXED_KEY; n++;
361         prop_radiobox_init(&(pcs->size_policy), cgen->size_policy_rbox_label,
362                 cgen->size_policy_rbox, n, item, (XtPointer*)item_val,
363                 cgen->size_policy_cb);
364
365         for(i=0; i < n; i++)
366             XtAddCallback(item[i], XmNvalueChangedCallback,
367                         (XtCallbackProc)prop_size_policyCB, (XtPointer)&(pcs->geometry));
368
369         /* Geometry */
370         prop_geomfield_init(&(pcs->geometry), cgen->geom_label,
371                 NULL, NULL, NULL, NULL,
372                 cgen->width_field_label, cgen->width_field,
373                 cgen->height_field_label, cgen->height_field,
374                 cgen->geom_cb);
375
376         /* Initial State */
377         n = 0;
378         item[n] = cgen->istate_ckbox_items.Visible_item;
379         item_val[n] = AB_STATE_VISIBLE; n++;
380         prop_checkbox_init(&(pcs->init_state), cgen->istate_ckbox_label,
381                 cgen->istate_ckbox, n, item, item_val,
382                 cgen->istate_cb);
383
384         /* Color */
385         prop_colorfield_init(&(pcs->bg_color), cgen->bg_mbutton,
386                 cgen->bg_mbutton_bg_mbutton_menu_items.None_item,
387                 cgen->bg_mbutton_bg_mbutton_menu_items.Color_Chooser_item,
388                 cgen->bg_swatch, cgen->bg_field, cgen->bg_cb);
389
390         prop_colorfield_init(&(pcs->fg_color), cgen->fg_mbutton,
391                 cgen->fg_mbutton_fg_mbutton_menu_items.None_item,
392                 cgen->fg_mbutton_fg_mbutton_menu_items.Color_Chooser_item,
393                 cgen->fg_swatch, cgen->fg_field, cgen->fg_cb);
394
395         prop_changebars_cleared(pcs->prop_sheet);
396
397         return (cgen->prop_dialog_shellform);
398     }
399     else
400         return NULL;
401
402 }
403
404 static int
405 custdlg_prop_activate(
406     AB_PROP_TYPE type,
407     BOOL         active
408 )
409 {
410      ui_set_active(prop_custdlg_settings_rec[type].prop_sheet, active);
411
412     return OK;
413 }
414
415
416 static int
417 custdlg_prop_clear(
418     AB_PROP_TYPE type
419 )
420 {
421     PropCustdlgSettingsRec      *pcs = &(prop_custdlg_settings_rec[type]);
422
423     if (pcs->current_obj == NULL)
424         return OK;
425
426     /* Clear Name */
427     prop_field_set_value(&(pcs->name), "", False);
428
429     /* Clear Window Parent */
430     prop_obj_options_load(&(pcs->win_parent), NULL);
431
432     /* Clear Title */
433     prop_field_set_value(&(pcs->title), "", False);
434
435     /* Clear Resize Mode */
436     prop_radiobox_set_value(&(pcs->resize_mode), (XtPointer)True, False);
437
438     /* Clear Window Areas */
439     prop_checkbox_set_value(&(pcs->areas), AB_CONT_BUTTON_PANEL, False, False);
440     prop_checkbox_set_value(&(pcs->areas), AB_CONT_FOOTER, False, False);
441
442     /* Clear Default Button */
443     prop_obj_options_load(&(pcs->default_but), NULL);
444
445     /* Clear Help Button */
446     prop_obj_options_load(&(pcs->help_but), NULL);
447
448     /* Clear Size Policy */
449     prop_radiobox_set_value(&(pcs->size_policy), (XtPointer)SIZE_FIXED_KEY, False);
450
451     /* Clear Size */
452     prop_geomfield_clear(&(pcs->geometry), GEOM_WIDTH);
453     prop_geomfield_clear(&(pcs->geometry), GEOM_HEIGHT);
454
455     /* Clear Initial State */
456     prop_checkbox_set_value(&(pcs->init_state), AB_STATE_VISIBLE, True, False);
457
458     /* Clear Color */
459     prop_colorfield_set_value(&(pcs->bg_color), "", False);
460     prop_colorfield_set_value(&(pcs->fg_color), "", False);
461
462     pcs->current_obj = NULL;
463
464     turnoff_changebars(type);
465
466     return OK;
467
468 }
469
470 static int
471 custdlg_prop_load(
472     ABObj        obj,
473     AB_PROP_TYPE type,
474     unsigned long loadkey
475 )
476 {
477     ABObj                       area;
478     PropCustdlgSettingsRec      *pcs = &(prop_custdlg_settings_rec[type]);
479     BOOL                        load_all = (loadkey & LoadAll);
480
481     if (obj == NULL)
482     {
483         if (pcs->current_obj != NULL)
484             obj = pcs->current_obj;
485         else
486             return ERROR;
487     }
488     else if (!obj_is_popup_win(obj))
489         return ERROR;
490     else
491         pcs->current_obj = obj;
492
493     /* Load Name */
494     if (load_all || loadkey & LoadName)
495         prop_field_set_value(&(pcs->name), obj_get_name(obj), False);
496
497     if (load_all)
498     {
499         /* Load Window Parent */
500         prop_obj_options_load(&(pcs->win_parent), proj_get_project());
501         prop_obj_options_set_value(&(pcs->win_parent),
502         obj_get_win_parent(obj), False);
503
504         /* Load Title */
505         prop_field_set_value(&(pcs->title), obj_get_label(obj), False);
506
507         /* Load Resize Mode */
508         prop_radiobox_set_value(&(pcs->resize_mode),
509                                 (XtPointer)obj_get_resizable(obj), False);
510
511         /* Load Window Areas */
512         area = objxm_comp_custdlg_get_area(obj, AB_CONT_BUTTON_PANEL);
513         prop_checkbox_set_value(&(pcs->areas), AB_CONT_BUTTON_PANEL,
514         area != NULL, False);
515
516         area = objxm_comp_custdlg_get_area(obj, AB_CONT_FOOTER);
517         prop_checkbox_set_value(&(pcs->areas), AB_CONT_FOOTER,
518                 area != NULL, False);
519
520         /* Load Default Button */
521         prop_obj_options_load(&(pcs->default_but),
522         objxm_comp_custdlg_get_area(obj, AB_CONT_BUTTON_PANEL));
523         prop_obj_options_set_value(&(pcs->default_but),
524         obj_get_default_act_button(obj), False);
525
526         /* Load Help Button */
527         prop_obj_options_load(&(pcs->help_but),
528         objxm_comp_custdlg_get_area(obj, AB_CONT_BUTTON_PANEL));
529         prop_obj_options_set_value(&(pcs->help_but),
530         obj_get_help_act_button(obj), False);
531
532         /* Load Size Policy */
533         prop_radiobox_set_value(&(pcs->size_policy),
534                                 abobj_width_resizable(obj)?
535                                 (XtPointer)SIZE_FIXED_KEY :
536                                 (XtPointer)SIZE_OF_CONTENTS_KEY, False);
537
538         /* Load Initial State */
539         prop_checkbox_set_value(&(pcs->init_state), AB_STATE_VISIBLE,
540                 obj_is_initially_visible(obj), False);
541
542         /* Load Color */
543         prop_colorfield_set_value(&(pcs->bg_color), obj_get_bg_color(obj), False);
544         prop_colorfield_set_value(&(pcs->fg_color), obj_get_fg_color(obj), False);
545
546         turnoff_changebars(type);
547     }
548
549     /* Load Size */
550     if (load_all || loadkey & LoadSize)
551         prop_load_obj_size(obj, &(pcs->geometry));
552
553     return OK;
554 }
555
556 int
557 custdlg_prop_apply(
558     AB_PROP_TYPE   type
559 )
560 {
561     PropCustdlgSettingsRec      *pcs = &(prop_custdlg_settings_rec[type]);
562     ABObj                       module;
563     ABObj                       area;
564     STRING                      value;
565     BOOL                        area_set;
566     BOOL                        reset_bg = False;
567     BOOL                        reset_fg = False;
568     BOOL                        size_chg = False;
569     int                         new_w, new_h;
570
571     if (!verify_props(type))
572         return ERROR;
573
574     if (prop_changed(pcs->name.changebar))
575     {
576         value = prop_field_get_value(&(pcs->name));
577         abobj_set_name(pcs->current_obj, value);
578         util_free(value);
579     }
580     if (prop_changed(pcs->win_parent.options.changebar))
581     {
582         ABObj   win_parent = (ABObj) NULL;
583
584         win_parent = prop_obj_options_get_value(&(pcs->win_parent));
585         abobj_set_win_parent(pcs->current_obj, win_parent);
586     }
587     if (prop_changed(pcs->title.changebar))
588     {
589         value = prop_field_get_value(&(pcs->title));
590         abobj_set_label(pcs->current_obj, pcs->current_obj->label_type, value);
591         util_free(value);
592     }
593     if (prop_changed(pcs->resize_mode.changebar))
594     {
595         abobj_set_resize_mode(pcs->current_obj,
596                 (BOOL)prop_radiobox_get_value(&(pcs->resize_mode)));
597     }
598     if (prop_changed(pcs->areas.changebar))
599     {
600         module = obj_get_module(pcs->current_obj);
601
602         /* Button Panel */
603         area = objxm_comp_custdlg_get_area(pcs->current_obj, AB_CONT_BUTTON_PANEL);
604         area_set = prop_checkbox_get_value(&(pcs->areas), AB_CONT_BUTTON_PANEL);
605
606         if (area != NULL && !area_set) /* Remove Button Panel */
607             custdlg_remove_area(pcs->current_obj, area);
608
609         else if (area == NULL && area_set) /* Add Button Panel */
610             custdlg_create_area(pcs->current_obj, AB_CONT_BUTTON_PANEL);
611
612         /* Footer */
613         area = objxm_comp_custdlg_get_area(pcs->current_obj, AB_CONT_FOOTER);
614         area_set = prop_checkbox_get_value(&(pcs->areas), AB_CONT_FOOTER);
615
616         if (area != NULL && !area_set) /* Remove Footer */
617             custdlg_remove_area(pcs->current_obj, area);
618
619         else if (area == NULL && area_set) /* Add Footer */
620             custdlg_create_area(pcs->current_obj, AB_CONT_FOOTER);
621     }
622     if (prop_changed(pcs->default_but.options.changebar))
623     {
624         abobj_set_default_act_button(pcs->current_obj,
625             prop_obj_options_get_value(&(pcs->default_but)));
626
627     }
628     if (prop_changed(pcs->help_but.options.changebar))
629     {
630         abobj_set_help_act_button(pcs->current_obj,
631             prop_obj_options_get_value(&(pcs->help_but)));
632
633     }
634     if (prop_changed(pcs->size_policy.changebar))
635     {
636         abobj_set_size_policy(pcs->current_obj,
637                 prop_radiobox_get_value(&(pcs->size_policy)) == SIZE_FIXED_KEY);
638
639         size_chg = True;
640     }
641     if (prop_changed(pcs->geometry.changebar))
642     {
643         if (abobj_width_resizable(pcs->current_obj))
644         {
645             new_w = prop_geomfield_get_value(&(pcs->geometry), GEOM_WIDTH);
646             abobj_set_pixel_width(pcs->current_obj, new_w, 0);
647         }
648         if (abobj_height_resizable(pcs->current_obj))
649         {
650             new_h = prop_geomfield_get_value(&(pcs->geometry), GEOM_HEIGHT);
651             abobj_set_pixel_height(pcs->current_obj, new_h, 0);
652         }
653     }
654     if (prop_changed(pcs->init_state.changebar))
655     {
656         abobj_set_visible(pcs->current_obj,
657                 prop_checkbox_get_value(&(pcs->init_state), AB_STATE_VISIBLE));
658     }
659     if (prop_changed(pcs->fg_color.changebar))
660     {
661         value = prop_colorfield_get_value(&(pcs->fg_color));
662         abobj_set_foreground_color(pcs->current_obj, value);
663         if (util_strempty(value))
664             reset_fg = True;
665         util_free(value);
666         prop_colorfield_set_value(&(pcs->fg_color), obj_get_fg_color(pcs->current_obj), False);
667     }
668     if (prop_changed(pcs->bg_color.changebar))
669     {
670         value = prop_colorfield_get_value(&(pcs->bg_color));
671         abobj_set_background_color(pcs->current_obj, value);
672         if (util_strempty(value))
673             reset_bg = True;
674         util_free(value);
675         prop_colorfield_set_value(&(pcs->bg_color), obj_get_bg_color(pcs->current_obj), False);
676     }
677     abobj_tree_instantiate_changes(pcs->current_obj);
678
679     if (reset_bg || reset_fg) /* Set back to No Color */
680         abobj_reset_colors(pcs->current_obj, reset_bg, reset_fg);
681
682     turnoff_changebars(type);
683
684     return OK;
685
686 }
687
688 static BOOL
689 custdlg_prop_pending(
690     AB_PROP_TYPE type
691 )
692 {
693     return(prop_changebars_pending(prop_custdlg_settings_rec[type].prop_sheet));
694 }
695
696 static BOOL
697 verify_props(
698     AB_PROP_TYPE type
699 )
700 {
701     PropCustdlgSettingsRec      *pcs = &(prop_custdlg_settings_rec[type]);
702     ABObj                       area;
703     BOOL                        area_set;
704
705     if (prop_changed(pcs->name.changebar) && !prop_name_ok(pcs->current_obj, pcs->name.field))
706         return False;
707
708     if (prop_changed(pcs->areas.changebar))
709     {
710         DTB_MODAL_ANSWER        answer = DTB_ANSWER_NONE;
711         ABObj                   pobj;
712
713         /* Check Button Panel */
714         area = objxm_comp_custdlg_get_area(pcs->current_obj, AB_CONT_BUTTON_PANEL);
715         area_set = prop_checkbox_get_value(&(pcs->areas), AB_CONT_BUTTON_PANEL);
716         if (area != NULL && !area_set) /* Remove Menubar */
717         {
718             pobj = objxm_comp_get_subobj(area, AB_CFG_PARENT_OBJ);
719
720             if (obj_get_num_children(pobj) > 0)
721             {
722                 /* Popup Modal Message and wait for answer */
723                 dtb_custdlg_remove_bpanel_msg_initialize(
724                         &dtb_custdlg_remove_bpanel_msg);
725                 answer = dtb_show_modal_message(pcs->areas.checkbox,
726                                 &dtb_custdlg_remove_bpanel_msg,
727                                 NULL, NULL, NULL);
728                 if (answer == DTB_ANSWER_CANCEL)
729                     return False;
730             }
731         }
732
733         area = objxm_comp_custdlg_get_area(pcs->current_obj, AB_CONT_FOOTER);
734         area_set = prop_checkbox_get_value(&(pcs->areas), AB_CONT_FOOTER);
735         if (area != NULL && !area_set) /* Remove Footer */
736         {
737             pobj = objxm_comp_get_subobj(area, AB_CFG_PARENT_OBJ);
738
739             if (obj_get_num_children(pobj) > 0)
740             {
741                 /* Popup Modal Message and wait for answer */
742                 dtb_custdlg_remove_footer_msg_initialize(
743                         &dtb_custdlg_remove_footer_msg);
744                 answer = dtb_show_modal_message(pcs->areas.checkbox,
745                                 &dtb_custdlg_remove_footer_msg,
746                                 NULL, NULL, NULL);
747                 if (answer == DTB_ANSWER_CANCEL)
748                     return False;
749             }
750         }
751     }
752
753     if (prop_changed(pcs->geometry.changebar) &&
754          (!prop_number_ok(pcs->geometry.w_field, (STRING)WFieldStr, 1, SHRT_MAX) ||
755          !prop_number_ok(pcs->geometry.h_field, (STRING)HFieldStr, 1, SHRT_MAX)))
756         return False;
757
758     if (prop_changed(pcs->fg_color.changebar) && !prop_color_ok(pcs->fg_color.field))
759         return False;
760
761     if (prop_changed(pcs->bg_color.changebar) && !prop_color_ok(pcs->bg_color.field))
762         return False;
763
764     return True;
765 }
766
767 static void
768 turnoff_changebars(
769     AB_PROP_TYPE type
770 )
771 {
772     PropCustdlgSettingsRec *pcs = &(prop_custdlg_settings_rec[type]);
773
774     prop_set_changebar(pcs->name.changebar,             PROP_CB_OFF);
775     prop_set_changebar(pcs->win_parent.options.changebar,PROP_CB_OFF);
776     prop_set_changebar(pcs->title.changebar,            PROP_CB_OFF);
777     prop_set_changebar(pcs->resize_mode.changebar,      PROP_CB_OFF);
778     prop_set_changebar(pcs->areas.changebar,            PROP_CB_OFF);
779     prop_set_changebar(pcs->default_but.options.changebar,PROP_CB_OFF);
780     prop_set_changebar(pcs->help_but.options.changebar, PROP_CB_OFF);
781     prop_set_changebar(pcs->size_policy.changebar,      PROP_CB_OFF);
782     prop_set_changebar(pcs->geometry.changebar,         PROP_CB_OFF);
783     prop_set_changebar(pcs->init_state.changebar,       PROP_CB_OFF);
784     prop_set_changebar(pcs->bg_color.changebar,         PROP_CB_OFF);
785     prop_set_changebar(pcs->fg_color.changebar,         PROP_CB_OFF);
786
787     prop_changebars_cleared(pcs->prop_sheet);
788
789 }
790
791 static void
792 custdlg_create_area(
793     ABObj               obj,
794     AB_CONTAINER_TYPE   area_type
795 )
796 {
797     ABObj       pwobj;
798     ABObj       label, area;
799     ABObj       workobj;
800     Dimension   height;
801
802     pwobj = objxm_comp_get_subobj(obj, AB_CFG_WINDOW_PW_OBJ);
803     workobj = objxm_comp_get_subobj(obj, AB_CFG_PARENT_OBJ);
804
805     area = obj_create(AB_TYPE_CONTAINER, pwobj);
806     obj_set_subtype(area, area_type);
807     pal_initialize_obj(area);
808
809     if (area_type == AB_CONT_FOOTER)
810     {
811         label = obj_create(AB_TYPE_LABEL, area);
812         obj_set_x(label, 1);
813         obj_set_y(label, 1);
814         pal_initialize_obj(label);
815         obj_set_label(label, catgets(Dtb_project_catd, 100, 264, "footer message"));
816         obj_set_label_alignment(label, AB_ALIGN_LEFT);
817         obj_set_unique_name(label,
818                 ab_ident_from_name_and_label(obj_get_name(obj), "label"));
819
820         /*
821          * Workaround part1: MainWindow bug that causes MainWindow to shrink
822          * when a MessageWindow area is added
823          */
824         XtVaGetValues(objxm_get_widget(workobj),
825                 XmNheight,      &height,
826                 NULL);
827     }
828     else if (area_type == AB_CONT_BUTTON_PANEL)
829         custdlg_create_buttons(obj, area);
830
831     abobj_show_tree(area, True);
832
833     /* Workaround part2 */
834     if (area_type == AB_CONT_FOOTER)
835         XtVaSetValues(objxm_get_widget(workobj),
836                 XmNheight,      height,
837                 NULL);
838
839     abobj_set_save_needed(obj_get_module(obj), True);
840
841 }
842
843 static void
844 custdlg_create_buttons(
845     ABObj       obj,
846     ABObj       area
847 )
848 {
849     ABObj       bobj;
850     char    *button_names[] = {"button1","button2","button3"};
851     char    *button_labels[3];
852     int     startpos, endpos;
853     int         i;
854
855     button_labels[0] = catgets(Dtb_project_catd, 100, 265, "Button1");
856     button_labels[1] = catgets(Dtb_project_catd, 100, 266, "Button2");
857     button_labels[2] = catgets(Dtb_project_catd, 100, 267, "Button3");
858
859     endpos = 0;
860     for(i=0; i < XtNumber(button_names); i++)
861     {
862         bobj = obj_create(AB_TYPE_BUTTON, area);
863         obj_set_subtype(bobj, AB_BUT_PUSH);
864         obj_set_unique_name(bobj,
865             ab_ident_from_name_and_label(obj_get_name(obj),button_names[i]));
866         obj_set_label(bobj, button_labels[i]);
867         obj_set_is_initially_visible(bobj, True);
868         obj_set_is_initially_active(bobj, True);
869         startpos = endpos + 10;
870         obj_set_attachment(bobj, AB_CP_WEST, AB_ATTACH_GRIDLINE, (void*)startpos, 0);
871         endpos = startpos + 20;
872         obj_set_attachment(bobj, AB_CP_EAST, AB_ATTACH_GRIDLINE, (void*)endpos, 0);
873         obj_set_attachment(bobj, AB_CP_NORTH, AB_ATTACH_POINT, (void*)0, 5);
874     }
875
876 }
877
878 static void
879 custdlg_remove_area(
880     ABObj       obj,
881     ABObj       area
882 )
883 {
884     objxm_tree_destroy(area);
885     abobj_set_save_needed(obj_get_module(obj), True);
886 }
887
888 /*
889  * Test whether a Button should be a candidate to be the dialog's
890  * "Default" button or not
891  */
892 static BOOL
893 button_test_func(
894     ABObj       obj
895 )
896 {
897     ABObj       parent = obj_get_root(obj_get_parent(obj));
898
899     if (obj_is_button(obj))
900     {
901         while (obj_is_group(parent))
902             parent = obj_get_root(obj_get_parent(parent));
903
904         if (obj_get_container_type(parent) == AB_CONT_BUTTON_PANEL)
905             return True;
906     }
907     return False;
908 }
909
910 /*
911  * Test whether an object can be the "Window Parent" of the dialog
912  */
913 static BOOL
914 winparent_test_func(
915     ABObj       obj
916 )
917 {
918     return(obj_is_base_win(obj));
919 }