2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
25 * $XConsortium: pal_label.c /main/5 1996/08/08 18:01:43 mustafa $
27 * @(#)pal_label.c 1.74 11 Aug 1995 cde_app_builder/src/ab
29 * RESTRICTED CONFIDENTIAL INFORMATION:
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
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
45 * pal_label.c - Implements Palette Label object functionality
49 #include <ab_private/ab.h>
50 #include <ab_private/abobj.h>
51 #include <ab_private/abobj_set.h>
52 #include <ab_private/pal.h>
53 #include <ab_private/prop.h>
54 #include <ab_private/ui_util.h>
58 typedef struct PROP_LABEL_SETTINGS
61 PropFieldSettingRec name;
62 PropOptionsSettingRec label_type;
63 PropFieldSettingRec label;
64 PropOptionsSettingRec label_align;
65 PropRadioSettingRec size_policy;
66 PropGeometrySettingRec geometry;
67 PropCheckboxSettingRec init_state;
68 PropColorSettingRec bg_color;
69 PropColorSettingRec fg_color;
71 } PropLabelSettingsRec, *PropLabelSettings;
73 /*************************************************************************
75 ** Private Function Declarations **
77 **************************************************************************/
81 static int label_initialize(
84 static Widget label_prop_init(
88 static int label_prop_activate(
92 static int label_prop_clear(
95 static int label_prop_load(
100 static int label_prop_apply(
103 static BOOL label_prop_pending(
107 static BOOL verify_props(
110 static void turnoff_changebars(
117 static void size_policyCB(
119 XtPointer clientdata,
120 XmToggleButtonCallbackStruct *state
124 /*************************************************************************
128 **************************************************************************/
129 PalItemInfo label_palitem_rec = {
131 /* type */ AB_TYPE_LABEL,
133 /* animation pixmaps*/ NULL,
134 /* number of pixmaps*/ 0,
135 /* rev_prop_frame */ NULL,
136 /* fix_prop_dialog */ NULL,
137 /* initialize */ label_initialize,
138 /* is_a_test */ obj_is_label,
139 /* prop_initialize */ label_prop_init,
140 /* prop_activate */ label_prop_activate,
141 /* prop_clear */ label_prop_clear,
142 /* prop_load */ label_prop_load,
143 /* prop_apply */ label_prop_apply,
144 /* prop_pending */ label_prop_pending
148 PalItemInfo *ab_label_palitem = &label_palitem_rec;
149 PropLabelSettingsRec prop_label_settings_rec[AB_PROP_TYPE_NUM_VALUES];
152 /*************************************************************************
154 ** Function Definitions **
156 **************************************************************************/
162 obj_set_unique_name(obj, "label");
164 obj_set_label(obj, catgets(Dtb_project_catd, 6, 69, "Label"));
165 obj_set_is_initially_visible(obj, True);
166 obj_set_is_initially_active(obj, True);
168 obj_set_attachment(obj, AB_CP_NORTH, AB_ATTACH_POINT, NULL, obj->y);
169 obj_set_attachment(obj, AB_CP_WEST, AB_ATTACH_POINT, NULL, obj->x);
181 DtbLabelPropDialogInfoRec rev_label_prop_dialog; /* Revolving Props */
182 DtbLabelPropDialogInfo cgen = &dtb_label_prop_dialog; /* Codegen structure */
183 DtbRevolvPropDialogInfo rpd = &(dtb_revolv_prop_dialog);
184 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
190 if (type == AB_PROP_REVOLVING)
193 * Only the Attributes ControlPanel needs to be created within
194 * the existing Revolving Prop dialog, so fill out all other
195 * fields with the Revolving Prop dialog equivelents, so the
196 * dtb initialize proc will skip those non-NULL fields...
198 dtbLabelPropDialogInfo_clear(&rev_label_prop_dialog);
200 cgen = &(rev_label_prop_dialog);
201 cgen->prop_dialog = rpd->prop_dialog;
202 cgen->prop_dialog_shellform = rpd->prop_dialog_shellform;
203 cgen->prop_dialog_panedwin = rpd->prop_dialog_panedwin;
204 cgen->prop_dialog_form = rpd->prop_dialog_form;
205 cgen->objlist_panel = rpd->objlist_panel;
206 cgen->objlist_label = rpd->objlist_label2;
207 cgen->objlist_scrolledwin = rpd->objlist_scrolledwin;
208 cgen->objlist = rpd->objlist;
209 cgen->attrs_ctrlpanel_frame = rpd->attrs_ctrlpanel_frame;
210 cgen->activate_panel = rpd->activate_panel;
211 cgen->apply_button = rpd->apply_button;
212 cgen->ok_button = rpd->ok_button;
213 cgen->cancel_button = rpd->cancel_button;
214 cgen->reset_button = rpd->reset_button;
215 cgen->help_button = rpd->help_button;
218 else /* AB_PROP_FIXED - create entire dialog */
219 cgen = &dtb_label_prop_dialog;
222 if (dtb_label_prop_dialog_initialize(cgen, parent) == 0)
224 pls->prop_sheet = cgen->attrs_ctrlpanel;
225 pls->current_obj = NULL;
227 if (type == AB_PROP_REVOLVING)
228 XtVaSetValues(parent,
229 XmNuserData, pls->current_obj,
232 /* Dialog/Object List */
233 if (type == AB_PROP_FIXED)
235 prop_fixed_dialog_init(ab_label_palitem,
236 cgen->prop_dialog_shellform, cgen->objlist);
237 prop_activate_panel_init(type, ab_label_palitem,
238 cgen->ok_button, cgen->apply_button,
239 cgen->reset_button, cgen->cancel_button,
243 /* Alternate Editor Buttons */
244 prop_editors_panel_init(type, ab_label_palitem,
245 cgen->attach_button, cgen->conn_button, cgen->helptxt_button);
248 * Prop Sheet Settings....
252 prop_field_init(&(pls->name), cgen->name_field_label,
253 cgen->name_field, cgen->name_cb);
257 item[n] = cgen->labeltype_rbox_items.String_item;
258 item_val[n] = AB_LABEL_STRING; n++;
259 item[n] = cgen->labeltype_rbox_items.Graphic_item;
260 item_val[n] = AB_LABEL_GLYPH; n++;
261 prop_options_init(&(pls->label_type), cgen->labeltype_rbox_label,
262 cgen->labeltype_rbox, cgen->labeltype_rbox_menu,
263 n, item, (XtPointer*)item_val,
267 prop_field_init(&(pls->label), cgen->label_label, cgen->label_textpane,
270 prop_label_field_init(&(pls->label), cgen->graphic_hint, item, n);
274 item[n] = cgen->labelalign_opmenu_items.Left_item;
275 item_val[n] = AB_ALIGN_LEFT; n++;
276 item[n] = cgen->labelalign_opmenu_items.Centered_item;
277 item_val[n] = AB_ALIGN_CENTER; n++;
278 item[n] = cgen->labelalign_opmenu_items.Right_item;
279 item_val[n] = AB_ALIGN_RIGHT; n++;
280 prop_options_init(&(pls->label_align), cgen->labelalign_opmenu_label,
281 cgen->labelalign_opmenu, cgen->labelalign_opmenu_menu,
282 n, item, (XtPointer*)item_val,
283 cgen->labelalign_cb);
287 item[n] = cgen->szpolicy_rbox_items.Size_of_Label_item;
288 item_val[n] = SIZE_OF_CONTENTS_KEY; n++;
289 item[n] = cgen->szpolicy_rbox_items.Fixed_item;
290 item_val[n] = SIZE_FIXED_KEY; n++;
291 prop_radiobox_init(&(pls->size_policy), cgen->szpolicy_rbox_label,
292 cgen->szpolicy_rbox, n, item, (XtPointer*)item_val,
296 XtAddCallback(item[i], XmNvalueChangedCallback,
297 (XtCallbackProc)prop_size_policyCB, (XtPointer)&(pls->geometry));
301 prop_geomfield_init(&(pls->geometry), cgen->geom_label,
302 cgen->x_field_label, cgen->x_field,
303 cgen->y_field_label, cgen->y_field,
304 cgen->width_field_label, cgen->width_field,
305 cgen->height_field_label, cgen->height_field,
310 item[n] = cgen->istate_ckbox_items.Visible_item;
311 item_val[n] = AB_STATE_VISIBLE; n++;
312 item[n] = cgen->istate_ckbox_items.Active_item;
313 item_val[n] = AB_STATE_ACTIVE; n++;
314 prop_checkbox_init(&(pls->init_state), cgen->istate_ckbox_label,
315 cgen->istate_ckbox, n, item, item_val,
319 prop_colorfield_init(&(pls->bg_color), cgen->bg_mbutton,
320 cgen->bg_mbutton_bg_mbutton_menu_items.None_item,
321 cgen->bg_mbutton_bg_mbutton_menu_items.Color_Chooser_item,
322 cgen->bg_swatch, cgen->bg_field, cgen->bg_cb);
325 prop_colorfield_init(&(pls->fg_color), cgen->fg_mbutton,
326 cgen->fg_mbutton_fg_mbutton_menu_items.None_item,
327 cgen->fg_mbutton_fg_mbutton_menu_items.Color_Chooser_item,
328 cgen->fg_swatch, cgen->fg_field, cgen->fg_cb);
330 prop_changebars_cleared(pls->prop_sheet);
332 return (cgen->prop_dialog_shellform);
345 ui_set_active(prop_label_settings_rec[type].prop_sheet, active);
356 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
358 if (pls->current_obj == NULL)
362 prop_field_set_value(&(pls->name), "", False);
364 /* Clear LabelType */
365 prop_options_set_value(&(pls->label_type), (XtPointer)AB_LABEL_STRING, False);
366 ui_set_active(pls->label.field, True);
367 ui_set_active(pls->label.label, True);
370 ui_set_label_string(pls->label.label, (STRING)LabelForString);
371 prop_field_set_value(&(pls->label), "", False);
373 /* Clear Label Alignment */
374 prop_options_set_value(&(pls->label_align), (XtPointer)AB_ALIGN_CENTER, False);
377 prop_geomfield_clear(&(pls->geometry), GEOM_X);
378 prop_geomfield_clear(&(pls->geometry), GEOM_Y);
379 prop_geomfield_clear(&(pls->geometry), GEOM_WIDTH);
380 prop_geomfield_clear(&(pls->geometry), GEOM_HEIGHT);
382 /* Clear Size Policy */
383 prop_radiobox_set_value(&(pls->size_policy),
384 (XtPointer)SIZE_OF_CONTENTS_KEY, False);
386 /* Clear Initial State */
387 prop_checkbox_set_value(&(pls->init_state), AB_STATE_VISIBLE, True, False);
388 prop_checkbox_set_value(&(pls->init_state), AB_STATE_ACTIVE, True, False);
390 /* Clear Background Color */
391 prop_colorfield_set_value(&(pls->bg_color), "", False);
393 /* Clear Foreground Color */
394 prop_colorfield_set_value(&(pls->fg_color), "", False);
396 pls->current_obj = NULL;
398 turnoff_changebars(type);
408 unsigned long loadkey
411 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
412 BOOL load_all = (loadkey & LoadAll);
416 if (pls->current_obj != NULL)
417 obj = pls->current_obj;
421 else if (!obj_is_label(obj))
424 pls->current_obj = obj;
427 if (load_all || loadkey & LoadName)
428 prop_field_set_value(&(pls->name), obj_get_name(obj), False);
433 prop_options_set_value(&(pls->label_type), (XtPointer)obj->label_type, False);
434 prop_setup_label_field(&(pls->label), NULL,
435 obj->label_type, obj_get_label(obj), AB_LINE_UNDEF);
437 /* Load Label Alignment */
438 prop_options_set_value(&(pls->label_align), (XtPointer)obj_get_label_alignment(obj), False);
440 /* Load Size Policy */
441 prop_radiobox_set_value(&(pls->size_policy),
442 abobj_width_resizable(obj)?
443 (XtPointer)SIZE_FIXED_KEY :
444 (XtPointer)SIZE_OF_CONTENTS_KEY, False);
446 /* Load Initial State */
447 prop_checkbox_set_value(&(pls->init_state), AB_STATE_VISIBLE,
448 obj_is_initially_visible(obj), False);
449 prop_checkbox_set_value(&(pls->init_state), AB_STATE_ACTIVE,
450 obj_is_initially_active(obj), False);
453 prop_colorfield_set_value(&(pls->bg_color), obj_get_bg_color(obj), False);
454 prop_colorfield_set_value(&(pls->fg_color), obj_get_fg_color(obj), False);
456 turnoff_changebars(type);
460 if (load_all || loadkey & LoadPosition)
461 prop_load_obj_position(obj, &(pls->geometry));
463 if (load_all || loadkey & LoadSize)
464 prop_load_obj_size(obj, &(pls->geometry));
474 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
476 BOOL size_chg = False;
477 BOOL reset_bg = False;
478 BOOL reset_fg = False;
481 if (!verify_props(type))
484 if (prop_changed(pls->name.changebar))
486 value = prop_field_get_value(&(pls->name));
487 abobj_set_name(pls->current_obj, value);
490 if (prop_changed(pls->label.changebar) || prop_changed(pls->label_type.changebar))
492 value = prop_field_get_value(&(pls->label));
493 abobj_set_label(pls->current_obj,
494 (AB_LABEL_TYPE)prop_options_get_value(&(pls->label_type)),
499 if (prop_changed(pls->size_policy.changebar))
501 BOOL fixed_size = prop_radiobox_get_value(
502 &(pls->size_policy)) == SIZE_FIXED_KEY;
503 /* If the label or label type hasn't changed and the
504 * label's size was set to "Fixed" and now is being
505 * changed to "Size of Label", then we have to re-
506 * instantiate the label along with setting the
507 * XmNrecomputeSize resource back to True, so that the
508 * label will resize itself correctly. Otherwise, the
509 * resize won't take place.
511 if (!prop_changed(pls->label.changebar) &&
512 !prop_changed(pls->label_type.changebar) &&
513 (obj_get_width(pls->current_obj) != -1) && !fixed_size)
515 obj_clear_flag(pls->current_obj, InstantiatedFlag);
518 abobj_set_size_policy(pls->current_obj, fixed_size);
521 if (prop_changed(pls->geometry.changebar))
523 if (abobj_width_resizable(pls->current_obj))
525 new_w = prop_geomfield_get_value(&(pls->geometry), GEOM_WIDTH);
526 abobj_set_pixel_width(pls->current_obj, new_w, 0);
528 if (abobj_height_resizable(pls->current_obj))
530 new_h = prop_geomfield_get_value(&(pls->geometry), GEOM_HEIGHT);
531 abobj_set_pixel_height(pls->current_obj, new_h, 0);
533 if (abobj_is_movable(pls->current_obj))
534 abobj_set_xy(pls->current_obj,
535 prop_geomfield_get_value(&(pls->geometry), GEOM_X),
536 prop_geomfield_get_value(&(pls->geometry), GEOM_Y));
540 if (prop_changed(pls->init_state.changebar))
542 abobj_set_visible(pls->current_obj,
543 prop_checkbox_get_value(&(pls->init_state), AB_STATE_VISIBLE));
544 abobj_set_active(pls->current_obj,
545 prop_checkbox_get_value(&(pls->init_state), AB_STATE_ACTIVE));
547 if (prop_changed(pls->label_align.changebar))
549 abobj_set_label_alignment(pls->current_obj,
550 (AB_ALIGNMENT)prop_options_get_value(&(pls->label_align)));
553 if (prop_changed(pls->fg_color.changebar))
555 value = prop_colorfield_get_value(&(pls->fg_color));
556 abobj_set_foreground_color(pls->current_obj, value);
557 if (util_strempty(value))
560 prop_colorfield_set_value(&(pls->fg_color), obj_get_fg_color(pls->current_obj), False);
562 if (prop_changed(pls->bg_color.changebar))
564 value = prop_colorfield_get_value(&(pls->bg_color));
565 abobj_set_background_color(pls->current_obj, value);
566 if (util_strempty(value))
569 prop_colorfield_set_value(&(pls->bg_color), obj_get_bg_color(pls->current_obj), False);
572 abobj_instantiate_changes(pls->current_obj);
574 if (reset_bg || reset_fg) /* Set back to No Color */
575 abobj_reset_colors(pls->current_obj, reset_bg, reset_fg);
577 abobj_force_dang_form_resize(pls->current_obj);
579 /* Label may have changed Size as a result...*/
580 prop_geomfield_set_value(&(pls->geometry), GEOM_WIDTH,
581 abobj_get_comp_width(pls->current_obj), False);
582 prop_geomfield_set_value(&(pls->geometry), GEOM_HEIGHT,
583 abobj_get_comp_height(pls->current_obj), False);
585 turnoff_changebars(type);
596 return(prop_changebars_pending(prop_label_settings_rec[type].prop_sheet));
604 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
606 if (prop_changed(pls->name.changebar) && !prop_name_ok(pls->current_obj, pls->name.field))
609 if ((prop_changed(pls->label_type.changebar) || prop_changed(pls->label.changebar)) &&
610 prop_options_get_value(&(pls->label_type)) == (XtPointer)AB_LABEL_GLYPH &&
611 !prop_graphic_filename_ok(pls->label.field, False))
614 if (prop_changed(pls->geometry.changebar) &&
615 (!prop_number_ok(pls->geometry.x_field, (STRING)XFieldStr,-SHRT_MAX, SHRT_MAX) ||
616 !prop_number_ok(pls->geometry.y_field, (STRING)YFieldStr,-SHRT_MAX, SHRT_MAX) ||
617 !prop_number_ok(pls->geometry.w_field, (STRING)WFieldStr, 1, SHRT_MAX) ||
618 !prop_number_ok(pls->geometry.h_field, (STRING)HFieldStr, 1, SHRT_MAX)))
621 if (prop_changed(pls->fg_color.changebar) && !prop_color_ok(pls->fg_color.field))
624 if (prop_changed(pls->bg_color.changebar) && !prop_color_ok(pls->bg_color.field))
635 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
637 prop_set_changebar(pls->name.changebar, PROP_CB_OFF);
638 prop_set_changebar(pls->label_type.changebar,PROP_CB_OFF);
639 prop_set_changebar(pls->label.changebar, PROP_CB_OFF);
640 prop_set_changebar(pls->label_align.changebar,PROP_CB_OFF);
641 prop_set_changebar(pls->geometry.changebar, PROP_CB_OFF);
642 prop_set_changebar(pls->size_policy.changebar, PROP_CB_OFF);
643 prop_set_changebar(pls->init_state.changebar,PROP_CB_OFF);
644 prop_set_changebar(pls->bg_color.changebar, PROP_CB_OFF);
645 prop_set_changebar(pls->fg_color.changebar, PROP_CB_OFF);
647 prop_changebars_cleared(pls->prop_sheet);
654 XtPointer clientdata,
655 XmToggleButtonCallbackStruct *state
658 AB_PROP_TYPE type = (AB_PROP_TYPE)clientdata;
659 PropLabelSettingsRec *pls = &(prop_label_settings_rec[type]);
662 /* Width/Height fields should ONLY be editable if Size Policy
667 XtVaGetValues(w, XmNuserData, &value, NULL);
668 ui_field_set_editable(pls->geometry.w_field, value == SIZE_FIXED_KEY);
669 ui_field_set_editable(pls->geometry.h_field, value == SIZE_FIXED_KEY);