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
24 * $XConsortium: pal_glyph.c /main/3 1995/11/06 17:38:34 rswiston $
26 * @(#)pal_glyph.c 1.3 21 Feb 1994 cde_app_builder/src/ab
28 * RESTRICTED CONFIDENTIAL INFORMATION:
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
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 * pal_glyph.c - Implements Palette Glyph object functionality
51 #include <Xm/RowColumn.h>
53 #include <Xm/ToggleB.h>
54 #include <Xm/Separator.h>
55 #include <ab_private/pal.h>
56 #include <ab_private/prop.h>
57 #include <ab_private/abobj_set.h>
58 #include <ab_private/ui_util.h>
60 const int glyph_init_height = 175;
61 const int glyph_init_width = 400;
63 /*************************************************************************
65 ** Private Function Declarations **
67 **************************************************************************/
71 static int glyph_initialize(
74 static Widget glyph_prop_init(
78 static int glyph_prop_activate(
82 static int glyph_prop_clear(
85 static int glyph_prop_load(
89 static int glyph_prop_apply(
93 static BOOL glyph_prop_pending(
97 static BOOL verify_props(
100 static void turnoff_changebars(
105 /*************************************************************************
109 **************************************************************************/
111 PalItemInfo glyph_palitem_rec = {
113 /* type */ AB_TYPE_GLYPH,
115 /* animation pixmaps*/ NULL,
116 /* number of pixmaps*/ 0,
117 /* rev_prop_frame */ NULL,
118 /* fix_prop_dialog */ NULL,
119 /* initialize */ glyph_initialize,
120 /* is_a_test */ obj_is_glyph,
121 /* prop_initialize */ glyph_prop_init,
122 /* prop_active */ glyph_prop_activate,
123 /* prop_clear */ glyph_prop_clear,
124 /* prop_load */ glyph_prop_load,
125 /* prop_apply */ glyph_prop_apply,
126 /* prop_pending */ glyph_prop_pending
129 PalItemInfo *ab_glyph_palitem = &glyph_palitem_rec;
131 static ABObj current_obj[AB_PROP_TYPE_NUM_VALUES];
133 static Widget prop_form[AB_PROP_TYPE_NUM_VALUES];
135 static Widget name_label[AB_PROP_TYPE_NUM_VALUES],
136 name_field[AB_PROP_TYPE_NUM_VALUES],
137 name_cb[AB_PROP_TYPE_NUM_VALUES],
139 colorf_label[AB_PROP_TYPE_NUM_VALUES],
140 colorf_field[AB_PROP_TYPE_NUM_VALUES],
141 colorf_cb[AB_PROP_TYPE_NUM_VALUES],
143 monof_label[AB_PROP_TYPE_NUM_VALUES],
144 monof_field[AB_PROP_TYPE_NUM_VALUES],
145 monof_cb[AB_PROP_TYPE_NUM_VALUES],
147 fg_label[AB_PROP_TYPE_NUM_VALUES],
148 fg_button[AB_PROP_TYPE_NUM_VALUES],
149 fg_field[AB_PROP_TYPE_NUM_VALUES],
150 fg_cb[AB_PROP_TYPE_NUM_VALUES],
151 fg_glyph[AB_PROP_TYPE_NUM_VALUES],
153 bg_label[AB_PROP_TYPE_NUM_VALUES],
154 bg_button[AB_PROP_TYPE_NUM_VALUES],
155 bg_field[AB_PROP_TYPE_NUM_VALUES],
156 bg_cb[AB_PROP_TYPE_NUM_VALUES],
157 bg_glyph[AB_PROP_TYPE_NUM_VALUES];
160 /*************************************************************************
162 ** Function Definitions **
164 **************************************************************************/
172 name = obj_alloc_unique_name(obj_get_module(obj), "glyph", -1);
173 obj_set_name(obj, name);
195 prop_form[type] = prop_pane = XtVaCreateManagedWidget("glyph_prop_pane",
198 XmNresizePolicy, XmRESIZE_ANY,
201 /* Set record of changebars currently "ON" to 0 */
202 prop_init_change_count(prop_pane);
204 XtVaGetValues(prop_pane,
205 XmNbackground, &parent_bg,
208 /********************************************************************
209 * Create Name Setting *
210 ********************************************************************/
211 name_field[type] = XtVaCreateManagedWidget("namefield",
212 xmTextFieldWidgetClass,
214 XmNshadowThickness, 1,
215 XmNhighlightThickness, 1,
217 XmNleftAttachment, XmATTACH_POSITION,
218 XmNleftPosition, prop_setting_anchor,
219 XmNleftOffset, prop_offset_from_lbl,
220 XmNrightAttachment, XmATTACH_POSITION,
221 XmNrightPosition, prop_setting_end,
222 XmNtopAttachment, XmATTACH_FORM,
223 XmNtopOffset, prop_setting_offset,
225 setting = name_field[type];
227 xmlabel = XmStringCreateLocalized("Object Name:");
228 name_label[type] = label = XtVaCreateManagedWidget("prop_label",
231 XmNlabelString, xmlabel,
232 XmNalignment, XmALIGNMENT_END,
233 XmNrightAttachment, XmATTACH_POSITION,
234 XmNrightPosition, prop_setting_anchor,
235 XmNleftAttachment, XmATTACH_POSITION,
236 XmNleftPosition, prop_label_anchor,
237 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
238 XmNtopWidget, setting,
239 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
240 XmNbottomWidget, setting,
242 XmStringFree(xmlabel);
244 name_cb[type] = XtVaCreateManagedWidget("changebar",
245 xmSeparatorWidgetClass,
247 XmNorientation, XmVERTICAL,
248 XmNseparatorType, XmSINGLE_LINE,
249 XmNwidth, prop_cb_width,
250 XmNbackground, parent_bg,
251 XmNforeground, parent_bg,
252 XmNleftAttachment, XmATTACH_POSITION,
253 XmNleftPosition, prop_cb_anchor,
254 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
255 XmNtopWidget, setting,
256 XmNrightAttachment, XmATTACH_POSITION,
257 XmNrightPosition, prop_label_anchor,
258 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
259 XmNbottomWidget, setting,
260 XmNuserData, PROP_CB_OFF,
262 XtAddCallback(name_field[type], XmNvalueChangedCallback, prop_field_chgCB, name_cb[type]);
263 XtVaSetValues(name_field[type], XmNuserData, PROP_EDIT, NULL);
266 /********************************************************************
267 * Create Color Filename Setting *
268 ********************************************************************/
269 colorf_field[type] = XtVaCreateManagedWidget("field",
270 xmTextFieldWidgetClass,
272 XmNshadowThickness, 1,
273 XmNhighlightThickness, 1,
275 XmNleftAttachment, XmATTACH_POSITION,
276 XmNleftPosition, prop_setting_anchor,
277 XmNleftOffset, prop_offset_from_lbl,
278 XmNtopAttachment, XmATTACH_WIDGET,
279 XmNtopWidget, setting,
280 XmNtopOffset, prop_setting_offset,
281 XmNrightAttachment, XmATTACH_POSITION,
282 XmNrightPosition, prop_setting_end,
285 setting = colorf_field[type];
286 xmlabel = XmStringCreateLocalized("Color Filename:");
287 colorf_label[type] = XtVaCreateManagedWidget("prop_label",
290 XmNlabelString, xmlabel,
291 XmNalignment, XmALIGNMENT_END,
292 XmNrightAttachment, XmATTACH_POSITION,
293 XmNrightPosition, prop_setting_anchor,
294 XmNleftAttachment, XmATTACH_POSITION,
295 XmNleftPosition, prop_label_anchor,
296 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
297 XmNtopWidget, setting,
298 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
299 XmNbottomWidget, setting,
301 XmStringFree(xmlabel);
303 colorf_cb[type] = XtVaCreateManagedWidget("changebar",
304 xmSeparatorWidgetClass,
306 XmNorientation, XmVERTICAL,
307 XmNseparatorType, XmSINGLE_LINE,
308 XmNwidth, prop_cb_width,
309 XmNbackground, parent_bg,
310 XmNforeground, parent_bg,
311 XmNleftAttachment, XmATTACH_POSITION,
312 XmNleftPosition, prop_cb_anchor,
313 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
314 XmNtopWidget, setting,
315 XmNrightAttachment, XmATTACH_POSITION,
316 XmNrightPosition, prop_label_anchor,
317 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
318 XmNbottomWidget, setting,
319 XmNuserData, PROP_CB_OFF,
321 XtAddCallback(colorf_field[type], XmNvalueChangedCallback, prop_field_chgCB, colorf_cb[type]);
322 XtVaSetValues(colorf_field[type], XmNuserData, PROP_EDIT, NULL);
325 /********************************************************************
326 * Create Mono Filename Setting *
327 ********************************************************************/
328 monof_field[type] = XtVaCreateManagedWidget("field",
329 xmTextFieldWidgetClass,
331 XmNshadowThickness, 1,
332 XmNhighlightThickness, 1,
334 XmNleftAttachment, XmATTACH_POSITION,
335 XmNleftPosition, prop_setting_anchor,
336 XmNleftOffset, prop_offset_from_lbl,
337 XmNtopAttachment, XmATTACH_WIDGET,
338 XmNtopWidget, setting,
339 XmNtopOffset, prop_setting_offset,
340 XmNrightAttachment, XmATTACH_POSITION,
341 XmNrightPosition, prop_setting_end,
344 setting = monof_field[type];
345 xmlabel = XmStringCreateLocalized("Color Filename:");
346 monof_label[type] = XtVaCreateManagedWidget("prop_label",
349 XmNlabelString, xmlabel,
350 XmNalignment, XmALIGNMENT_END,
351 XmNrightAttachment, XmATTACH_POSITION,
352 XmNrightPosition, prop_setting_anchor,
353 XmNleftAttachment, XmATTACH_POSITION,
354 XmNleftPosition, prop_label_anchor,
355 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
356 XmNtopWidget, setting,
357 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
358 XmNbottomWidget, setting,
360 XmStringFree(xmlabel);
362 monof_cb[type] = XtVaCreateManagedWidget("changebar",
363 xmSeparatorWidgetClass,
365 XmNorientation, XmVERTICAL,
366 XmNseparatorType, XmSINGLE_LINE,
367 XmNwidth, prop_cb_width,
368 XmNbackground, parent_bg,
369 XmNforeground, parent_bg,
370 XmNleftAttachment, XmATTACH_POSITION,
371 XmNleftPosition, prop_cb_anchor,
372 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
373 XmNtopWidget, setting,
374 XmNrightAttachment, XmATTACH_POSITION,
375 XmNrightPosition, prop_label_anchor,
376 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
377 XmNbottomWidget, setting,
378 XmNuserData, PROP_CB_OFF,
380 XtAddCallback(monof_field[type], XmNvalueChangedCallback, prop_field_chgCB,
382 XtVaSetValues(monof_field[type], XmNuserData, PROP_EDIT, NULL);
386 /********************************************************************
387 * Create Background Color Setting *
388 ********************************************************************/
391 xmlabel = XmStringCreateLocalized("ColorChooser...");
392 bg_button[type] = button = XtVaCreateManagedWidget("color_button",
393 xmPushButtonWidgetClass,
395 XmNlabelString, xmlabel,
396 XmNleftAttachment, XmATTACH_POSITION,
397 XmNleftPosition, prop_setting_anchor,
398 XmNleftOffset, prop_offset_from_lbl,
399 XmNtopAttachment, XmATTACH_WIDGET,
400 XmNtopWidget, setting,
401 XmNtopOffset, prop_setting_offset,
403 XmStringFree(xmlabel);
406 xmlabel = XmStringCreateLocalized(" ");
408 XtVaCreateManagedWidget("color_glyph[type]",
411 XmNlabelString, xmlabel,
413 XmNleftAttachment, XmATTACH_WIDGET,
414 XmNleftWidget, button,
416 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
417 XmNtopWidget, button,
419 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
420 XmNbottomWidget, button,
423 XmStringFree(xmlabel);
426 XtVaCreateManagedWidget("color_field",
427 xmTextFieldWidgetClass,
429 XmNshadowThickness, 1,
430 XmNhighlightThickness, 1,
432 XmNleftAttachment, XmATTACH_WIDGET,
433 XmNleftWidget, bg_glyph[type],
435 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
436 XmNtopWidget, button,
438 XmNrightAttachment, XmATTACH_POSITION,
439 XmNrightPosition, prop_setting_end,
443 xmlabel = XmStringCreateLocalized("Background:");
444 bg_label[type] = label = XtVaCreateManagedWidget("prop_label",
447 XmNlabelString, xmlabel,
448 XmNalignment, XmALIGNMENT_END,
449 XmNrightAttachment, XmATTACH_POSITION,
450 XmNrightPosition, prop_setting_anchor,
451 XmNleftAttachment, XmATTACH_POSITION,
452 XmNleftPosition, prop_label_anchor,
453 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
454 XmNtopWidget, setting,
455 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
456 XmNbottomWidget, setting,
458 XmStringFree(xmlabel);
460 bg_cb[type] = XtVaCreateManagedWidget("changebar",
461 xmSeparatorWidgetClass,
463 XmNorientation, XmVERTICAL,
464 XmNseparatorType, XmSINGLE_LINE,
465 XmNwidth, prop_cb_width,
466 XmNbackground, parent_bg,
467 XmNforeground, parent_bg,
468 XmNleftAttachment, XmATTACH_POSITION,
469 XmNleftPosition, prop_cb_anchor,
470 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
471 XmNtopWidget, setting,
472 XmNrightAttachment, XmATTACH_POSITION,
473 XmNrightPosition, prop_label_anchor,
474 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
475 XmNbottomWidget, setting,
476 XmNuserData, PROP_CB_OFF,
478 XtAddCallback(bg_field[type], XmNvalueChangedCallback, prop_field_chgCB, bg_cb[type]);
479 XtVaSetValues(bg_field[type], XmNuserData, PROP_EDIT, NULL);
481 /* Install color chooser */
482 prop_add_color_chooser(bg_button[type],bg_glyph[type],bg_field[type]);
486 /********************************************************************
487 * Create Foreground Color Setting *
488 ********************************************************************/
491 xmlabel = XmStringCreateLocalized("ColorChooser...");
492 fg_button[type] = button = XtVaCreateManagedWidget("color_button",
493 xmPushButtonWidgetClass,
495 XmNlabelString, xmlabel,
496 XmNleftAttachment, XmATTACH_POSITION,
497 XmNleftPosition, prop_setting_anchor,
498 XmNleftOffset, prop_offset_from_lbl,
499 XmNtopAttachment, XmATTACH_WIDGET,
500 XmNtopWidget, setting,
501 XmNtopOffset, prop_setting_offset,
503 XmStringFree(xmlabel);
506 xmlabel = XmStringCreateLocalized(" ");
508 XtVaCreateManagedWidget("color_glyph",
511 XmNlabelString, xmlabel,
513 XmNleftAttachment, XmATTACH_WIDGET,
514 XmNleftWidget, button,
516 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
517 XmNtopWidget, button,
519 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
520 XmNbottomWidget, button,
523 XmStringFree(xmlabel);
526 XtVaCreateManagedWidget("color_field[type]",
527 xmTextFieldWidgetClass,
529 XmNshadowThickness, 1,
530 XmNhighlightThickness, 1,
532 XmNleftAttachment, XmATTACH_WIDGET,
533 XmNleftWidget, fg_glyph[type],
535 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
536 XmNtopWidget, button,
538 XmNrightAttachment, XmATTACH_POSITION,
539 XmNrightPosition, prop_setting_end,
543 xmlabel = XmStringCreateLocalized("Foreground:");
544 fg_label[type] = label = XtVaCreateManagedWidget("prop_label",
547 XmNlabelString, xmlabel,
548 XmNalignment, XmALIGNMENT_END,
549 XmNrightAttachment, XmATTACH_POSITION,
550 XmNrightPosition, prop_setting_anchor,
551 XmNleftAttachment, XmATTACH_POSITION,
552 XmNleftPosition, prop_label_anchor,
553 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
554 XmNtopWidget, setting,
555 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
556 XmNbottomWidget, setting,
558 XmStringFree(xmlabel);
560 fg_cb[type] = XtVaCreateManagedWidget("changebar",
561 xmSeparatorWidgetClass,
563 XmNorientation, XmVERTICAL,
564 XmNseparatorType, XmSINGLE_LINE,
565 XmNwidth, prop_cb_width,
566 XmNbackground, parent_bg,
567 XmNforeground, parent_bg,
568 XmNleftAttachment, XmATTACH_POSITION,
569 XmNleftPosition, prop_cb_anchor,
570 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
571 XmNtopWidget, setting,
572 XmNrightAttachment, XmATTACH_POSITION,
573 XmNrightPosition, prop_label_anchor,
574 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
575 XmNbottomWidget, setting,
576 XmNuserData, PROP_CB_OFF,
578 XtAddCallback(fg_field[type], XmNvalueChangedCallback, prop_field_chgCB, fg_cb[type]);
579 XtVaSetValues(fg_field[type], XmNuserData, PROP_EDIT, NULL);
581 /* Install color chooser */
582 prop_add_color_chooser(fg_button[type],fg_glyph[type],fg_field[type]);
590 current_obj[type] = NULL;
591 if (type == AB_PROP_REVOLVING)
592 XtVaSetValues(parent,
593 XmNuserData, current_obj[type],
607 * Set sensitivity of each Prop Sheet setting
609 ui_set_active(name_label[type], active);
610 ui_set_active(name_field[type], active);
612 ui_set_active(colorf_label[type], active);
613 ui_set_active(colorf_field[type], active);
615 ui_set_active(monof_label[type], active);
616 ui_set_active(monof_field[type], active);
619 ui_set_active(fg_label[type], active);
620 ui_set_active(fg_button[type], active);
621 ui_set_active(fg_field[type], active);
632 if (current_obj[type] == NULL)
636 prop_set_field(name_field[type], "");
638 /* Clear Color Filename */
639 prop_set_field(colorf_field[type], "");
641 /* Clear Mono Filename */
642 prop_set_field(monof_field[type], "");
644 /* Clear Background Color */
646 prop_set_field(bg_field[type], "");
647 prop_set_color_glyph(bg_glyph[type], NULL);
650 /* Clear Foreground Color */
652 prop_set_field(fg_field[type], "");
653 prop_set_color_glyph(fg_glyph[type], NULL);
655 turnoff_changebars(type);
657 current_obj[type] = NULL;
658 if (type == AB_PROP_REVOLVING)
659 XtVaSetValues(ab_glyph_palitem->rev_prop_frame,
660 XmNuserData, current_obj[type],
677 if (current_obj[type] != NULL)
679 /* Reset props for current object */
680 obj = current_obj[type];
686 else if (!obj_is_base_win(obj))
690 /* Load props for new object */
691 current_obj[type] = obj;
692 if (type == AB_PROP_REVOLVING)
693 XtVaSetValues(ab_glyph_palitem->rev_prop_frame,
694 XmNuserData, current_obj[type],
699 prop_set_field(name_field[type], obj_get_name(obj));
701 /* Load Color Filename */
703 prop_set_field(colorf_field[type], obj_get_color_filename(obj));
706 /* Load Mono Filename */
708 prop_set_field(monof_field[type], obj_get_mono_filename(obj));
711 /* Load Background Color */
713 prop_set_field(bg_field[type], obj_get_bg_color(obj));
714 prop_set_color_glyph(bg_glyph[type], obj_get_bg_color(obj));
717 /* Load Foreground Color */
719 prop_set_field(fg_field[type], obj_get_fg_color(obj));
720 prop_set_color_glyph(fg_glyph[type], obj_get_fg_color(obj));
723 /* Turn off changebars */
724 turnoff_changebars(type);
736 if (current_obj[type] == NULL)
739 if (!verify_props(type))
742 if (prop_changed(name_cb[type]))
744 value = ui_get_field_string(name_field[type]);
745 abobj_set_name(current_obj[type], value);
748 if (prop_changed(colorf_cb[type]))
751 value = ui_get_field_string(label_field[type]);
752 abobj_set_label(current_obj[type], current_obj[type]->label_type, value);
757 if (prop_changed(fg_cb[type]))
759 value = ui_get_field_string(fg_field[type]);
760 abobj_set_foreground_color(current_obj[type], value);
762 prop_set_color_glyph(fg_glyph[type], obj_get_fg_color(current_obj[type]));
764 if (prop_changed(bg_cb[type]))
766 value = ui_get_field_string(bg_field[type]);
767 abobj_set_background_color(current_obj[type], value);
769 prop_set_color_glyph(bg_glyph[type], obj_get_bg_color(current_obj[type]));
773 turnoff_changebars(type);
784 if (prop_get_change_count(prop_form[type]) > 0)
785 return TRUE; /* Changes pending */
787 return FALSE;/* No Changes pending */
796 if (prop_changed(name_cb[type]) && !prop_name_ok(current_obj[type], name_field[type]))
800 if (prop_changed(fg_cb[type]) && !prop_color_ok(fg_field[type]))
803 if (prop_changed(bg_cb[type]) && !prop_color_ok(bg_field[type]))
815 /* Ensure all Changebars are OFF and change_count is 0
817 prop_set_changebar(name_cb[type], PROP_CB_OFF);
818 prop_set_changebar(colorf_cb[type], PROP_CB_OFF);
819 prop_set_changebar(monof_cb[type], PROP_CB_OFF);
821 prop_set_changebar(bg_cb[type], PROP_CB_OFF);
822 prop_set_changebar(fg_cb[type], PROP_CB_OFF);
825 prop_init_change_count(prop_form[type]);