Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / ab / pal_mainwin.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  *      $XConsortium: pal_mainwin.c /main/5 1996/08/08 18:02:22 mustafa $
25  *
26  * @(#)pal_mainwin.c    1.67 11 Aug 1995      cde_app_builder/src/ab
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *
30  *      The information in this document is subject to special
31  *      restrictions in a confidential disclosure agreement between
32  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
33  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
34  *      Sun's specific written approval.  This document and all copies
35  *      and derivative works thereof must be returned or destroyed at
36  *      Sun's request.
37  *
38  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  *
40  */
41
42
43 /*
44  * pal_mainwin.c - Implements Palette Main Window object functionality
45  */
46 #include <stdio.h>
47 #include <Xm/Xm.h>
48 #include <ab_private/ab.h>
49 #include <ab_private/pal.h>
50 #include <ab_private/prop.h>
51 #include <ab_private/abobj.h>
52 #include <ab_private/abobj_set.h>
53 #include <ab_private/ui_util.h>
54 #include "mainwin_ui.h"
55
56 const int    mainwin_init_height = 175;
57 const int    mainwin_init_width  = 400;
58
59 typedef struct  PROP_MAINWIN_SETTINGS
60 {
61     Widget                      prop_sheet;
62     PropFieldSettingRec         name;
63     PropFieldSettingRec         title;
64     PropRadioSettingRec         size_policy;
65     PropGeometrySettingRec      geometry;
66     PropRadioSettingRec         resize_mode;
67     PropFieldSettingRec         icon;
68     PropFieldSettingRec         icon_mask;
69     PropFieldSettingRec         icon_label;
70     PropCheckboxSettingRec      areas;
71     PropCheckboxSettingRec      init_state;
72     PropColorSettingRec         bg_color;
73     PropColorSettingRec         fg_color;
74     ABObj                       current_obj;
75 } PropMainwinSettingsRec, *PropMainwinSettings;
76
77 /*************************************************************************
78 **                                                                      **
79 **       Private Function Declarations                                  **
80 **                                                                      **
81 **************************************************************************/
82 /*
83  * Methods
84  */
85 static int      mainwin_initialize(
86                     ABObj   obj
87                 );
88 static Widget   mainwin_prop_init(
89                     Widget  parent,
90                     AB_PROP_TYPE type
91                 );
92 static int      mainwin_prop_activate(
93                     AB_PROP_TYPE type,
94                     BOOL         active
95                 );
96 static int      mainwin_prop_clear(
97                     AB_PROP_TYPE type
98                 );
99 static int      mainwin_prop_load(
100                     ABObj        obj,
101                     AB_PROP_TYPE type,
102                     unsigned long loadkey
103                 );
104 static int      mainwin_prop_apply(
105                     AB_PROP_TYPE type
106                 );
107
108 static BOOL     mainwin_prop_pending(
109                     AB_PROP_TYPE type
110                 );
111
112 static BOOL     verify_props(
113                     AB_PROP_TYPE type
114                 );
115 static void     turnoff_changebars(
116                     AB_PROP_TYPE type
117                 );
118
119 static void     mainwin_create_area(
120                     ABObj               obj,
121                     AB_CONTAINER_TYPE   area_type
122                 );
123
124 static void     mainwin_remove_area(
125                     ABObj               obj,
126                     ABObj               area
127                 );
128
129
130 /*************************************************************************
131 **                                                                      **
132 **       Data                                                           **
133 **                                                                      **
134 **************************************************************************/
135
136 PalItemInfo mainwin_palitem_rec = {
137
138     /* type             */  AB_TYPE_BASE_WINDOW,
139     /* name             */  "Main Window",
140     /* animation pixmaps*/  NULL,
141     /* number of pixmaps*/  0,
142     /* rev_prop_frame   */  NULL,
143     /* fix_prop_dialog  */  NULL,
144     /* initialize       */  mainwin_initialize,
145     /* is_a_test        */  obj_is_base_win,
146     /* prop_initialize  */  mainwin_prop_init,
147     /* prop_active      */  mainwin_prop_activate,
148     /* prop_clear       */  mainwin_prop_clear,
149     /* prop_load        */  mainwin_prop_load,
150     /* prop_apply       */  mainwin_prop_apply,
151     /* prop_pending     */  mainwin_prop_pending
152
153 };
154
155 PalItemInfo *ab_mainwin_palitem = &mainwin_palitem_rec;
156 PropMainwinSettingsRec prop_mainwin_settings_rec[AB_PROP_TYPE_NUM_VALUES];
157
158 /*************************************************************************
159 **                                                                      **
160 **       Function Definitions                                           **
161 **                                                                      **
162 **************************************************************************/
163 static int
164 mainwin_initialize(
165     ABObj     obj
166 )
167 {
168     ABObj       project = proj_get_project();
169
170     obj_set_unique_name(obj, "mainwindow");
171
172     obj_set_label(obj, catgets(Dtb_project_catd, 100, 258, "Main Window"));
173     obj_set_bg_color(obj, "white");
174     obj_set_is_initially_visible(obj, True);
175     obj_set_is_initially_iconic(obj, False);
176     obj_set_is_initially_active(obj, True);
177     obj->width          = mainwin_init_width;
178     obj->height         = mainwin_init_height;
179
180     /* If no Main Windows are currently designated as the
181      * "Primary" MainWindow (root window), then set this
182      * one to be it
183      */
184     if (obj_get_root_window(project) == NULL)
185         obj_set_root_window(project, obj);
186
187     return OK;
188 }
189
190 static Widget
191 mainwin_prop_init(
192     Widget       parent,
193     AB_PROP_TYPE type
194 )
195 {
196     DtbMainwinPropDialogInfoRec rev_mainwin_prop_dialog; /* Revolving Props */
197     DtbMainwinPropDialogInfo    cgen;
198     DtbRevolvPropDialogInfo     rpd = &(dtb_revolv_prop_dialog);
199     PropMainwinSettingsRec      *pms = &(prop_mainwin_settings_rec[type]);
200     Widget                      item[6];
201     int                         item_val[6];
202     int                         i, n;
203
204     if (type == AB_PROP_REVOLVING)
205     {
206         /* Cloning Trick:
207          * Only the Attributes ControlPanel needs to be created within
208          * the existing Revolving Prop dialog, so fill out all other
209          * fields with the Revolving Prop dialog equivelents, so the
210          * dtb initialize proc will skip those non-NULL fields...
211          */
212         dtbMainwinPropDialogInfo_clear(&rev_mainwin_prop_dialog);
213
214         cgen = &(rev_mainwin_prop_dialog);
215         cgen->prop_dialog = rpd->prop_dialog;
216         cgen->prop_dialog_shellform = rpd->prop_dialog_shellform;
217         cgen->prop_dialog_panedwin = rpd->prop_dialog_panedwin;
218         cgen->prop_dialog_form = rpd->prop_dialog_form;
219         cgen->objlist_panel = rpd->objlist_panel;
220         cgen->objlist_label = rpd->objlist_label2;
221         cgen->objlist_scrolledwin = rpd->objlist_scrolledwin;
222         cgen->objlist = rpd->objlist;
223         cgen->attrs_ctrlpanel_frame = rpd->attrs_ctrlpanel_frame;
224         cgen->activate_panel = rpd->activate_panel;
225         cgen->ok_button = rpd->ok_button;
226         cgen->cancel_button = rpd->cancel_button;
227         cgen->apply_button = rpd->apply_button;
228         cgen->reset_button = rpd->reset_button;
229         cgen->help_button = rpd->help_button;
230
231     }
232     else /* AB_PROP_FIXED */
233         cgen = &dtb_mainwin_prop_dialog;
234
235     if (dtb_mainwin_prop_dialog_initialize(cgen, parent) == 0)
236     {
237         pms->prop_sheet = cgen->attrs_ctrlpanel;
238         pms->current_obj = NULL;
239
240         if (type == AB_PROP_REVOLVING)
241                 XtVaSetValues(parent,
242                         XmNuserData, pms->current_obj,
243                         NULL);
244
245         /* Dialog/Object List */
246         if (type == AB_PROP_FIXED)
247         {
248             prop_fixed_dialog_init(ab_mainwin_palitem,
249                         cgen->prop_dialog_shellform, cgen->objlist);
250             prop_activate_panel_init(type, ab_mainwin_palitem,
251                         cgen->ok_button, cgen->apply_button,
252                         cgen->reset_button, cgen->cancel_button,
253                         cgen->help_button);
254         }
255         /* Alternate Editor Buttons */
256         prop_editors_panel_init(type, ab_mainwin_palitem,
257             NULL, cgen->conn_button, cgen->helptxt_button);
258
259         /*
260           * Prop Sheet Settings....
261          */
262
263         /* Name */
264         prop_field_init(&(pms->name), cgen->name_field_label,
265                 cgen->name_field, cgen->name_cb);
266
267         /* Title */
268         prop_field_init(&(pms->title), cgen->title_field_label,
269                 cgen->title_field,
270                 cgen->title_cb);
271
272         /* Resize Mode */
273         n = 0;
274         item[n] = cgen->resizemode_rbox_items.Adjustable_item;
275         item_val[n] = True; n++;
276         item[n] = cgen->resizemode_rbox_items.Fixed_item;
277         item_val[n] = False; n++;
278         prop_radiobox_init(&(pms->resize_mode), cgen->resizemode_rbox_label,
279                 cgen->resizemode_rbox, n, item, (XtPointer*)item_val,
280                 cgen->resizemode_cb);
281
282         /* Icon Filename */
283         prop_field_init(&(pms->icon), cgen->icon_field_label,
284                 cgen->icon_field, cgen->icon_cb);
285
286         /* Icon Mask Filename */
287         prop_field_init(&(pms->icon_mask), cgen->iconmask_field_label,
288                 cgen->iconmask_field, cgen->iconmask_cb);
289
290         /* Icon Label */
291         prop_field_init(&(pms->icon_label), cgen->iconlabel_field_label,
292                 cgen->iconlabel_field, cgen->iconlabel_cb);
293
294         /* Window Areas */
295         n = 0;
296         item[n] = cgen->areas_ckbox_items.Menubar_item;
297         item_val[n] = AB_CONT_MENU_BAR; n++;
298         item[n] = cgen->areas_ckbox_items.Toolbar_item;
299         item_val[n] = AB_CONT_TOOL_BAR; n++;
300         item[n] = cgen->areas_ckbox_items.Footer_item;
301         item_val[n] = AB_CONT_FOOTER; n++;
302         prop_checkbox_init(&(pms->areas), cgen->areas_ckbox_label,
303                 cgen->areas_ckbox, n, item, item_val,
304                 cgen->areas_cb);
305
306         /* Size Policy */
307         n = 0;
308         item[n] = cgen->size_policy_rbox_items.Fit_Contents_item;
309         item_val[n] = SIZE_OF_CONTENTS_KEY; n++;
310         item[n] = cgen->size_policy_rbox_items.Fixed_item;
311         item_val[n] = SIZE_FIXED_KEY; n++;
312         prop_radiobox_init(&(pms->size_policy), cgen->size_policy_rbox_label,
313                 cgen->size_policy_rbox, n, item, (XtPointer*)item_val,
314                 cgen->size_policy_cb);
315
316         for(i=0; i < n; i++)
317             XtAddCallback(item[i], XmNvalueChangedCallback,
318                   prop_size_policyCB, (XtPointer)&(pms->geometry));
319
320         /* Geometry */
321         prop_geomfield_init(&(pms->geometry), cgen->geom_label,
322                 NULL, NULL, NULL, NULL,
323                 cgen->width_field_label, cgen->width_field,
324                 cgen->height_field_label, cgen->height_field,
325                 cgen->geom_cb);
326
327         /* Initial State */
328         n = 0;
329         item[n] = cgen->istate_ckbox_items.Visible_item;
330         item_val[n] = AB_STATE_VISIBLE; n++;
331         item[n] = cgen->istate_ckbox_items.Iconic_item;
332         item_val[n] = AB_STATE_ICONIC; n++;
333         prop_checkbox_init(&(pms->init_state), cgen->istate_ckbox_label,
334                 cgen->istate_ckbox, n, item, item_val,
335                 cgen->istate_cb);
336
337         /* Background Setting */
338         prop_colorfield_init(&(pms->bg_color), cgen->bg_mbutton,
339                 cgen->bg_mbutton_bg_mbutton_menu_items.None_item,
340                 cgen->bg_mbutton_bg_mbutton_menu_items.Color_Chooser_item,
341                 cgen->bg_swatch, cgen->bg_field, cgen->bg_cb);
342
343         /* Foreground Setting */
344         prop_colorfield_init(&(pms->fg_color), cgen->fg_mbutton,
345                 cgen->fg_mbutton_fg_mbutton_menu_items.None_item,
346                 cgen->fg_mbutton_fg_mbutton_menu_items.Color_Chooser_item,
347                 cgen->fg_swatch, cgen->fg_field, cgen->fg_cb);
348
349         prop_changebars_cleared(pms->prop_sheet);
350
351         return (cgen->prop_dialog_shellform);
352     }
353     else
354         return NULL;
355
356 }
357
358 static int
359 mainwin_prop_activate(
360     AB_PROP_TYPE type,
361     BOOL         active
362 )
363 {
364      ui_set_active(prop_mainwin_settings_rec[type].prop_sheet, active);
365      return OK;
366 }
367
368 static int
369 mainwin_prop_clear(
370     AB_PROP_TYPE type
371 )
372 {
373     PropMainwinSettingsRec      *pms = &(prop_mainwin_settings_rec[type]);
374
375     if (pms->current_obj == NULL)
376         return OK;
377
378     /* Clear Name */
379     prop_field_set_value(&(pms->name), "", False);
380
381     /* Clear Title */
382     prop_field_set_value(&(pms->title), "", False);
383
384     /* Clear Resize Mode */
385     prop_radiobox_set_value(&(pms->resize_mode), (XtPointer)True, False);
386
387     /* Clear Icon Filename */
388     prop_field_set_value(&(pms->icon), "", False);
389
390     /* Clear Icon Mask Filename */
391     prop_field_set_value(&(pms->icon_mask), "", False);
392
393     /* Clear Icon Label */
394     prop_field_set_value(&(pms->icon_label), "", False);
395
396     /* Clear Areas */
397     prop_checkbox_set_value(&(pms->areas), AB_CONT_MENU_BAR, False, False);
398     prop_checkbox_set_value(&(pms->areas), AB_CONT_TOOL_BAR, False, False);
399     prop_checkbox_set_value(&(pms->areas), AB_CONT_FOOTER, False, False);
400
401     /* Clear Size Policy */
402     prop_radiobox_set_value(&(pms->size_policy),
403                             (XtPointer)SIZE_FIXED_KEY, False);
404
405     /* Clear Size */
406     prop_geomfield_clear(&(pms->geometry), GEOM_WIDTH);
407     prop_geomfield_clear(&(pms->geometry), GEOM_HEIGHT);
408
409     /* Clear Initial State */
410     prop_checkbox_set_value(&(pms->init_state), AB_STATE_VISIBLE, True, False);
411     prop_checkbox_set_value(&(pms->init_state), AB_STATE_ICONIC, False, False);
412
413     /* Clear Color */
414     prop_colorfield_set_value(&(pms->bg_color), "", False);
415     prop_colorfield_set_value(&(pms->fg_color), "", False);
416
417     pms->current_obj = NULL;
418
419     turnoff_changebars(type);
420
421     return OK;
422 }
423
424 static int
425 mainwin_prop_load(
426     ABObj        obj,
427     AB_PROP_TYPE type,
428     unsigned long loadkey
429 )
430 {
431     PropMainwinSettingsRec      *pms = &(prop_mainwin_settings_rec[type]);
432     ABObj                       area;
433     BOOL                        load_all = (loadkey & LoadAll);
434
435     if (obj == NULL)
436     {
437         if (pms->current_obj != NULL)
438             obj = pms->current_obj;
439         else
440             return ERROR;
441     }
442     else if (!obj_is_base_win(obj))
443         return ERROR;
444     else
445         pms->current_obj = obj;
446
447     /* Load Name */
448     if (load_all || loadkey & LoadName)
449         prop_field_set_value(&(pms->name), obj_get_name(obj), False);
450
451     if (load_all)
452     {
453         /* Load Title */
454         prop_field_set_value(&(pms->title), obj_get_label(obj), False);
455
456         /* Load Resize Mode */
457         prop_radiobox_set_value(&(pms->resize_mode),
458                                 (XtPointer)obj_get_resizable(obj), False);
459
460         /* Load Icon Filename */
461         prop_field_set_value(&(pms->icon), obj_get_icon(obj), False);
462
463         /* Load Icon Mask Filename */
464         prop_field_set_value(&(pms->icon_mask), obj_get_icon_mask(obj), False);
465
466         /* Load Icon Label */
467         prop_field_set_value(&(pms->icon_label), obj_get_icon_label(obj), False);
468
469         /* Load Window Areas */
470         area = objxm_comp_mainwin_get_area(obj, AB_CONT_MENU_BAR);
471         prop_checkbox_set_value(&(pms->areas), AB_CONT_MENU_BAR,
472         area != NULL, False);
473
474         area = objxm_comp_mainwin_get_area(obj, AB_CONT_TOOL_BAR);
475         prop_checkbox_set_value(&(pms->areas), AB_CONT_TOOL_BAR,
476                 area != NULL, False);
477
478         area = objxm_comp_mainwin_get_area(obj, AB_CONT_FOOTER);
479         prop_checkbox_set_value(&(pms->areas), AB_CONT_FOOTER,
480                 area != NULL, False);
481
482         /* Load Size Policy */
483         prop_radiobox_set_value(&(pms->size_policy),
484                                 abobj_width_resizable(obj)?
485                                 (XtPointer)SIZE_FIXED_KEY :
486                                 (XtPointer)SIZE_OF_CONTENTS_KEY, False);
487
488         /* Load Initial State */
489         prop_checkbox_set_value(&(pms->init_state), AB_STATE_VISIBLE,
490                 obj_is_initially_visible(obj), False);
491         prop_checkbox_set_value(&(pms->init_state), AB_STATE_ICONIC,
492                 obj_is_initially_iconic(obj), False);
493
494         /* Load Color */
495         prop_colorfield_set_value(&(pms->bg_color), obj_get_bg_color(obj), False);
496         prop_colorfield_set_value(&(pms->fg_color), obj_get_fg_color(obj), False);
497
498         turnoff_changebars(type);
499     }
500
501     /* Load Size */
502     if (load_all || loadkey & LoadSize)
503         prop_load_obj_size(obj, &(pms->geometry));
504
505     return OK;
506 }
507
508 int
509 mainwin_prop_apply(
510     AB_PROP_TYPE   type
511 )
512 {
513     PropMainwinSettingsRec      *pms = &(prop_mainwin_settings_rec[type]);
514     ABObj                       module;
515     ABObj                       area;
516     BOOL                        area_set;
517     STRING                      value, icon, icon_mask, icon_label;
518     BOOL                        reset_bg = False;
519     BOOL                        reset_fg = False;
520     BOOL                        size_chg = False;
521     int                         new_w, new_h;
522
523     if (!verify_props(type))
524         return ERROR;
525
526     if (prop_changed(pms->name.changebar))
527     {
528         value = prop_field_get_value(&(pms->name));
529         abobj_set_name(pms->current_obj, value);
530         util_free(value);
531     }
532     if (prop_changed(pms->title.changebar))
533     {
534         value = prop_field_get_value(&(pms->title));
535         abobj_set_label(pms->current_obj, pms->current_obj->label_type, value);
536         util_free(value);
537     }
538     if (prop_changed(pms->resize_mode.changebar))
539     {
540         abobj_set_resize_mode(pms->current_obj,
541                 (BOOL)prop_radiobox_get_value(&(pms->resize_mode)));
542     }
543     if (prop_changed(pms->icon.changebar) ||
544         prop_changed(pms->icon_mask.changebar) ||
545         prop_changed(pms->icon_label.changebar))
546     {
547         icon = prop_field_get_value(&(pms->icon));
548         icon_mask = prop_field_get_value(&(pms->icon_mask));
549         icon_label = prop_field_get_value(&(pms->icon_label));
550         abobj_set_icon(pms->current_obj, icon, icon_mask, icon_label);
551         util_free(icon);
552         util_free(icon_mask);
553         util_free(icon_label);
554     }
555     if (prop_changed(pms->areas.changebar))
556     {
557         module = obj_get_module(pms->current_obj);
558
559         /* Menubar */
560         area = objxm_comp_mainwin_get_area(pms->current_obj, AB_CONT_MENU_BAR);
561         area_set = prop_checkbox_get_value(&(pms->areas), AB_CONT_MENU_BAR);
562
563         if (area != NULL && !area_set) /* Remove Menubar */
564             mainwin_remove_area(pms->current_obj, area);
565
566         else if (area == NULL && area_set) /* Add Menubar */
567             mainwin_create_area(pms->current_obj, AB_CONT_MENU_BAR);
568
569         /* Toolbar */
570         area = objxm_comp_mainwin_get_area(pms->current_obj, AB_CONT_TOOL_BAR);
571         area_set = prop_checkbox_get_value(&(pms->areas), AB_CONT_TOOL_BAR);
572
573         if (area != NULL && !area_set) /* Remove Toolbar */
574             mainwin_remove_area(pms->current_obj, area);
575
576         else if (area == NULL && area_set) /* Add Toolbar */
577             mainwin_create_area(pms->current_obj, AB_CONT_TOOL_BAR);
578
579         /* Footer */
580         area = objxm_comp_mainwin_get_area(pms->current_obj, AB_CONT_FOOTER);
581         area_set = prop_checkbox_get_value(&(pms->areas), AB_CONT_FOOTER);
582
583         if (area != NULL && !area_set) /* Remove Footer */
584             mainwin_remove_area(pms->current_obj, area);
585
586         else if (area == NULL && area_set) /* Add Footer */
587             mainwin_create_area(pms->current_obj, AB_CONT_FOOTER);
588     }
589     if (prop_changed(pms->size_policy.changebar))
590     {
591         abobj_set_size_policy(pms->current_obj,
592                 prop_radiobox_get_value(&(pms->size_policy)) == SIZE_FIXED_KEY);
593
594         size_chg = True;
595     }
596     if (prop_changed(pms->geometry.changebar))
597     {
598         if (abobj_width_resizable(pms->current_obj))
599         {
600             new_w = prop_geomfield_get_value(&(pms->geometry), GEOM_WIDTH);
601             abobj_set_pixel_width(pms->current_obj, new_w, 0);
602         }
603         if (abobj_height_resizable(pms->current_obj))
604         {
605             new_h = prop_geomfield_get_value(&(pms->geometry), GEOM_HEIGHT);
606             abobj_set_pixel_height(pms->current_obj, new_h, 0);
607         }
608     }
609     if (prop_changed(pms->init_state.changebar))
610     {
611         abobj_set_visible(pms->current_obj,
612                 prop_checkbox_get_value(&(pms->init_state), AB_STATE_VISIBLE));
613         abobj_set_iconic(pms->current_obj,
614                 prop_checkbox_get_value(&(pms->init_state), AB_STATE_ICONIC));
615     }
616     if (prop_changed(pms->fg_color.changebar))
617     {
618         value = prop_colorfield_get_value(&(pms->fg_color));
619         abobj_set_foreground_color(pms->current_obj, value);
620         if (util_strempty(value))
621             reset_fg = True;
622         util_free(value);
623         prop_colorfield_set_value(&(pms->fg_color),
624                 obj_get_fg_color(pms->current_obj), False);
625     }
626     if (prop_changed(pms->bg_color.changebar))
627     {
628         value = prop_colorfield_get_value(&(pms->bg_color));
629         abobj_set_background_color(pms->current_obj, value);
630         if (util_strempty(value))
631             reset_bg = True;
632         util_free(value);
633         prop_colorfield_set_value(&(pms->bg_color),
634                 obj_get_bg_color(pms->current_obj), False);
635     }
636     abobj_instantiate_changes(pms->current_obj);
637
638     if (reset_bg || reset_fg) /* Set back to No Color */
639         abobj_reset_colors(pms->current_obj, reset_bg, reset_fg);
640
641     turnoff_changebars(type);
642
643     return OK;
644
645 }
646
647 static BOOL
648 mainwin_prop_pending(
649     AB_PROP_TYPE type
650 )
651 {
652     return(prop_changebars_pending(prop_mainwin_settings_rec[type].prop_sheet));
653 }
654
655 static BOOL
656 verify_props(
657     AB_PROP_TYPE type
658 )
659 {
660     PropMainwinSettingsRec *pms = &(prop_mainwin_settings_rec[type]);
661     ABObj                  area;
662     BOOL                   area_set;
663
664     if (prop_changed(pms->name.changebar) && !prop_name_ok(pms->current_obj, pms->name.field))
665         return False;
666
667     if (prop_changed(pms->areas.changebar))
668     {
669         DTB_MODAL_ANSWER        answer;
670         ABObj                   pobj;
671
672         area = objxm_comp_mainwin_get_area(pms->current_obj, AB_CONT_MENU_BAR);
673         area_set = prop_checkbox_get_value(&(pms->areas), AB_CONT_MENU_BAR);
674         if (area != NULL && !area_set) /* Remove Menubar */
675         {
676             pobj = objxm_comp_get_subobj(area, AB_CFG_PARENT_OBJ);
677
678             if (obj_get_num_children(pobj) > 0)
679             {
680                 /* Popup Modal Message and wait for answer */
681                 dtb_mainwin_remove_mbar_msg_initialize(
682                         &dtb_mainwin_remove_mbar_msg);
683                 answer = dtb_show_modal_message(pms->areas.checkbox,
684                                 &dtb_mainwin_remove_mbar_msg,
685                                 NULL, NULL, NULL);
686                 if (answer == DTB_ANSWER_CANCEL)
687                     return False;
688             }
689         }
690
691         area = objxm_comp_mainwin_get_area(pms->current_obj, AB_CONT_TOOL_BAR);
692         area_set = prop_checkbox_get_value(&(pms->areas), AB_CONT_TOOL_BAR);
693         if (area != NULL && !area_set) /* Remove Toolbar */
694         {
695             pobj = objxm_comp_get_subobj(area, AB_CFG_PARENT_OBJ);
696
697             if (obj_get_num_children(pobj) > 0)
698             {
699                 /* Popup Modal Message and wait for answer */
700                 dtb_mainwin_remove_tbar_msg_initialize(
701                         &dtb_mainwin_remove_tbar_msg);
702                 answer = dtb_show_modal_message(pms->areas.checkbox,
703                                 &dtb_mainwin_remove_tbar_msg,
704                                 NULL, NULL, NULL);
705                 if (answer == DTB_ANSWER_CANCEL)
706                     return False;
707             }
708         }
709
710         area = objxm_comp_mainwin_get_area(pms->current_obj, AB_CONT_FOOTER);
711         area_set = prop_checkbox_get_value(&(pms->areas), AB_CONT_FOOTER);
712         if (area != NULL && !area_set) /* Remove Footer */
713         {
714             pobj = objxm_comp_get_subobj(area, AB_CFG_PARENT_OBJ);
715
716             if (obj_get_num_children(pobj) > 0)
717             {
718                 /* Popup Modal Message and wait for answer */
719                 dtb_mainwin_remove_footer_msg_initialize(
720                         &dtb_mainwin_remove_footer_msg);
721                 answer = dtb_show_modal_message(pms->areas.checkbox,
722                                 &dtb_mainwin_remove_footer_msg,
723                                 NULL, NULL, NULL);
724                 if (answer == DTB_ANSWER_CANCEL)
725                     return False;
726             }
727         }
728     }
729     if (prop_changed(pms->icon.changebar) &&
730         !prop_graphic_filename_ok(pms->icon.field, True))
731         return False;
732
733     if (prop_changed(pms->icon_mask.changebar) &&
734         !prop_graphic_filename_ok(pms->icon_mask.field, True))
735         return False;
736
737     if (prop_changed(pms->geometry.changebar) &&
738          (!prop_number_ok(pms->geometry.w_field, (STRING)WFieldStr, 1, SHRT_MAX) ||
739          !prop_number_ok(pms->geometry.h_field, (STRING)HFieldStr, 1, SHRT_MAX)))
740         return False;
741
742     if (prop_changed(pms->fg_color.changebar) && !prop_color_ok(pms->fg_color.field))
743         return False;
744
745     if (prop_changed(pms->bg_color.changebar) && !prop_color_ok(pms->bg_color.field))
746         return False;
747
748     return True;
749 }
750
751 static void
752 turnoff_changebars(
753     AB_PROP_TYPE type
754 )
755 {
756     PropMainwinSettingsRec *pms = &(prop_mainwin_settings_rec[type]);
757
758     prop_set_changebar(pms->name.changebar,             PROP_CB_OFF);
759     prop_set_changebar(pms->title.changebar,            PROP_CB_OFF);
760     prop_set_changebar(pms->resize_mode.changebar,      PROP_CB_OFF);
761     prop_set_changebar(pms->icon.changebar,             PROP_CB_OFF);
762     prop_set_changebar(pms->icon_mask.changebar,        PROP_CB_OFF);
763     prop_set_changebar(pms->icon_label.changebar,       PROP_CB_OFF);
764     prop_set_changebar(pms->areas.changebar,            PROP_CB_OFF);
765     prop_set_changebar(pms->size_policy.changebar,      PROP_CB_OFF);
766     prop_set_changebar(pms->geometry.changebar,         PROP_CB_OFF);
767     prop_set_changebar(pms->init_state.changebar,       PROP_CB_OFF);
768     prop_set_changebar(pms->bg_color.changebar,         PROP_CB_OFF);
769     prop_set_changebar(pms->fg_color.changebar,         PROP_CB_OFF);
770
771     prop_changebars_cleared(pms->prop_sheet);
772
773 }
774
775 static void
776 mainwin_create_area(
777     ABObj       obj,
778     AB_CONTAINER_TYPE   area_type
779 )
780 {
781     ABObj       mwobj;
782     ABObj       label, area;
783     ABObj       workobj;
784     Dimension   height;
785
786     mwobj = objxm_comp_get_subobj(obj, AB_CFG_WINDOW_MW_OBJ);
787     workobj = objxm_comp_get_subobj(obj, AB_CFG_PARENT_OBJ);
788
789     area = obj_create(AB_TYPE_CONTAINER, mwobj);
790     obj_set_subtype(area, area_type);
791     pal_initialize_obj(area);
792
793     if (area_type == AB_CONT_FOOTER)
794     {
795         label = obj_create(AB_TYPE_LABEL, area);
796         obj_set_x(label, 1);
797         obj_set_y(label, 1);
798         pal_initialize_obj(label);
799         obj_set_label(label, catgets(Dtb_project_catd, 100, 264, "footer message"));
800         obj_set_label_alignment(label, AB_ALIGN_LEFT);
801         obj_set_unique_name(label,
802                 ab_ident_from_name_and_label(obj_get_name(obj), "label"));
803
804         /*
805          * Workaround part1: MainWindow bug that causes MainWindow to shrink
806          * when a MessageWindow area is added
807          */
808         XtVaGetValues(objxm_get_widget(workobj),
809                 XmNheight,      &height,
810                 NULL);
811     }
812     abobj_show_tree(area, True);
813
814     /* Workaround part2 */
815     if (area_type == AB_CONT_FOOTER)
816         XtVaSetValues(objxm_get_widget(workobj),
817                 XmNheight,      height,
818                 NULL);
819
820     abobj_set_save_needed(obj_get_module(obj), True);
821
822 }
823
824 static void
825 mainwin_remove_area(
826     ABObj       obj,
827     ABObj       area
828 )
829 {
830 /*
831     XtUnmanageChild(objxm_get_widget(area));
832 */
833     objxm_tree_destroy(area);
834
835     abobj_set_save_needed(obj_get_module(obj), True);
836 }