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_textp.c /main/7 1996/10/29 15:21:02 mustafa $
27 * @(#)pal_textp.c 1.31 14 Feb 1994 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_textp.c - Implements Palette TextPane object functionality
49 #include <ab_private/util.h>
50 #include <ab_private/ab.h>
51 #include <ab_private/pal.h>
52 #include <ab_private/prop.h>
53 #include <ab_private/abobj.h>
54 #include <ab_private/abobj_set.h>
55 #include <ab_private/ui_util.h>
58 const int textp_init_height = 80;
59 const int textp_init_width = 80;
61 typedef struct PROP_TEXTP_SETTINGS
64 PropFieldSettingRec name;
65 PropRadioSettingRec scrolling;
66 PropGeometrySettingRec pos;
67 PropGeometrySettingRec size;
68 PropOptionsSettingRec size_metric;
69 PropCheckboxSettingRec wrap;
70 PropRadioSettingRec op;
71 PropFieldSettingRec init_value;
72 PropCheckboxSettingRec init_state;
73 PropOptionsSettingRec frame;
74 PropColorSettingRec bg_color;
75 PropColorSettingRec fg_color;
76 PropMenunameSettingRec menuname;
77 PropFieldSettingRec menu_title;
79 } PropTextpSettingsRec, *PropTextpSettings;
81 /*************************************************************************
83 ** Private Function Declarations **
85 **************************************************************************/
89 static int textp_initialize(
92 static Widget textp_prop_init(
96 static int textp_prop_activate(
100 static int textp_prop_clear(
103 static int textp_prop_load(
106 unsigned long loadkey
108 static int textp_prop_apply(
111 static BOOL textp_prop_pending(
115 static BOOL verify_props(
118 static void turnoff_changebars(
123 /*************************************************************************
127 **************************************************************************/
128 PalItemInfo textp_palitem_rec = {
130 /* type */ AB_TYPE_TEXT_PANE,
131 /* name */ "Text Pane",
132 /* animation pixmaps*/ NULL,
133 /* number of pixmaps*/ 0,
134 /* rev_prop_frame */ NULL,
135 /* fix_prop_dialog */ NULL,
136 /* initialize */ textp_initialize,
137 /* is_a_test */ obj_is_text_pane,
138 /* prop_initialize */ textp_prop_init,
139 /* prop_activate */ textp_prop_activate,
140 /* prop_clear */ textp_prop_clear,
141 /* prop_load */ textp_prop_load,
142 /* prop_apply */ textp_prop_apply,
143 /* prop_pending */ textp_prop_pending
147 PalItemInfo *ab_textp_palitem = &textp_palitem_rec;
148 PropTextpSettingsRec prop_textp_settings_rec[AB_PROP_TYPE_NUM_VALUES];
151 /*************************************************************************
153 ** Function Definitions **
155 **************************************************************************/
162 ABObj parent = obj_get_root(obj_get_parent(obj));
164 obj_set_unique_name(obj, "textpane");
166 if (obj_is_layers(parent)) /* Size already defined in pixels */
168 obj_set_num_rows(obj, -1);
169 obj_set_num_columns(obj, -1);
171 else /* Default Size should be in chars */
173 obj_set_num_rows(obj, 4);
174 obj_set_num_columns(obj, 8);
176 obj_set_textpane_width(obj, 400);
177 obj_set_textpane_height(obj, 400);
179 obj_set_vscrollbar_policy(obj, AB_SCROLLBAR_ALWAYS);
180 obj_set_word_wrap(obj, True);
181 obj_set_hscrollbar_policy(obj, AB_SCROLLBAR_NEVER);
183 abobj_init_pane_position(obj);
195 DtbTextpPropDialogInfoRec rev_textp_prop_dialog; /* Revolving Props */
196 DtbTextpPropDialogInfo cgen = &dtb_textp_prop_dialog; /* Codegen structure */
197 DtbRevolvPropDialogInfo rpd = &(dtb_revolv_prop_dialog);
198 PropTextpSettingsRec *pts = &(prop_textp_settings_rec[type]);
203 if (type == AB_PROP_REVOLVING)
206 * Only the Attributes ControlPanel needs to be created within
207 * the existing Revolving Prop dialog, so fill out all other
208 * fields with the Revolving Prop dialog equivelents, so the
209 * dtb initialize proc will skip those non-NULL fields...
211 dtbTextpPropDialogInfo_clear(&rev_textp_prop_dialog);
213 cgen = &(rev_textp_prop_dialog);
214 cgen->prop_dialog = rpd->prop_dialog;
215 cgen->prop_dialog_shellform = rpd->prop_dialog_shellform;
216 cgen->prop_dialog_panedwin = rpd->prop_dialog_panedwin;
217 cgen->prop_dialog_form = rpd->prop_dialog_form;
218 cgen->objlist_panel = rpd->objlist_panel;
219 cgen->objlist_label = rpd->objlist_label2;
220 cgen->objlist_scrolledwin = rpd->objlist_scrolledwin;
221 cgen->objlist = rpd->objlist;
222 cgen->attrs_ctrlpanel_frame = rpd->attrs_ctrlpanel_frame;
223 cgen->activate_panel = rpd->activate_panel;
224 cgen->apply_button = rpd->apply_button;
225 cgen->ok_button = rpd->ok_button;
226 cgen->cancel_button = rpd->cancel_button;
227 cgen->reset_button = rpd->reset_button;
228 cgen->help_button = rpd->help_button;
231 else /* AB_PROP_FIXED */
232 cgen = &dtb_textp_prop_dialog;
234 if (dtb_textp_prop_dialog_initialize(cgen, parent) == 0)
236 pts->prop_sheet = cgen->attrs_ctrlpanel;
237 pts->current_obj = NULL;
239 if (type == AB_PROP_REVOLVING)
240 XtVaSetValues(parent,
241 XmNuserData, pts->current_obj,
244 /* Dialog/Object List */
245 if (type == AB_PROP_FIXED)
247 prop_fixed_dialog_init(ab_textp_palitem,
248 cgen->prop_dialog_shellform, cgen->objlist);
249 prop_activate_panel_init(type, ab_textp_palitem,
250 cgen->ok_button, cgen->apply_button,
251 cgen->reset_button, cgen->cancel_button,
255 /* Alternate Editor Buttons */
256 prop_editors_panel_init(type, ab_textp_palitem,
257 cgen->attach_button, cgen->conn_button, cgen->helptxt_button);
260 * Prop Sheet Settings....
264 prop_field_init(&(pts->name), cgen->name_field_label,
265 cgen->name_field, cgen->name_cb);
269 item[n] = cgen->scroll_rbox_items.Never_item;
270 item_val[n] = AB_SCROLLBAR_NEVER; n++;
271 item[n] = cgen->scroll_rbox_items.Always_item;
272 item_val[n] = AB_SCROLLBAR_ALWAYS; n++;
273 prop_radiobox_init(&(pts->scrolling), cgen->scroll_rbox_label,
274 cgen->scroll_rbox, n, item, (XtPointer*)item_val,
279 item[n] = cgen->bframe_opmenu_items.None_item;
280 item_val[n] = AB_LINE_NONE; n++;
281 item[n] = cgen->bframe_opmenu_items.Shadow_Out_item;
282 item_val[n] = AB_LINE_SHADOW_OUT; n++;
283 item[n] = cgen->bframe_opmenu_items.Shadow_In_item;
284 item_val[n] = AB_LINE_SHADOW_IN; n++;
285 item[n] = cgen->bframe_opmenu_items.Etched_Out_item;
286 item_val[n] = AB_LINE_ETCHED_OUT; n++;
287 item[n] = cgen->bframe_opmenu_items.Etched_In_item;
288 item_val[n] = AB_LINE_ETCHED_IN; n++;
289 prop_options_init(&(pts->frame), cgen->bframe_opmenu_label,
290 cgen->bframe_opmenu, cgen->bframe_opmenu_menu,
291 n, item, (XtPointer*)item_val,
296 item[n] = cgen->op_rbox_items.Editable_item;
297 item_val[n] = False; n++;
298 item[n] = cgen->op_rbox_items.Read_Only_item;
299 item_val[n] = True; n++;
300 prop_radiobox_init(&(pts->op), cgen->op_rbox_label,
301 cgen->op_rbox, n, item, (XtPointer*)item_val,
306 item[n] = cgen->wordwrap_ckbox_items.nolabel_item;
307 item_val[n] = True; n++;
308 prop_checkbox_init(&(pts->wrap), cgen->wordwrap_ckbox_label,
309 cgen->wordwrap_ckbox, n, item, item_val,
313 prop_field_init(&(pts->menu_title), cgen->menutitle_field_label,
314 cgen->menutitle_field, cgen->menutitle_cb);
317 prop_menuname_init(&(pts->menuname), type, cgen->menu_label,
318 cgen->menu_mbutton, cgen->menu_field,
319 cgen->name_field, cgen->menu_cb,
321 &(pts->current_obj), True);
324 prop_field_init(&(pts->init_value), cgen->ivalue_label,
325 cgen->ivalue_textpane, cgen->ivalue_cb);
328 prop_geomfield_init(&(pts->pos), cgen->pos_label,
329 cgen->x_field_label, cgen->x_field,
330 cgen->y_field_label, cgen->y_field,
331 NULL, NULL, NULL, NULL,
335 prop_geomfield_init(&(pts->size), cgen->size_opmenu_label,
336 NULL, NULL, NULL, NULL,
337 cgen->width_field_label, cgen->width_field,
338 cgen->height_field_label, cgen->height_field,
342 item[n] = cgen->size_opmenu_items.Characters_item;
343 item_val[n] = SIZE_IN_CHARS_KEY; n++;
344 item[n] = cgen->size_opmenu_items.Pixels_item;
345 item_val[n] = SIZE_IN_PIXELS_KEY; n++;
346 prop_options_init(&(pts->size_metric), cgen->size_opmenu_label,
348 cgen->size_opmenu_menu,
349 n, item, (XtPointer*)item_val,
354 item[n] = cgen->istate_ckbox_items.Visible_item;
355 item_val[n] = AB_STATE_VISIBLE; n++;
356 item[n] = cgen->istate_ckbox_items.Active_item;
357 item_val[n] = AB_STATE_ACTIVE; n++;
358 prop_checkbox_init(&(pts->init_state), cgen->istate_ckbox_label,
359 cgen->istate_ckbox, n, item, item_val,
363 prop_colorfield_init(&(pts->bg_color), cgen->bg_mbutton,
364 cgen->bg_mbutton_bg_mbutton_menu_items.None_item,
365 cgen->bg_mbutton_bg_mbutton_menu_items.Color_Chooser_item,
366 cgen->bg_swatch, cgen->bg_field, cgen->bg_cb);
368 prop_colorfield_init(&(pts->fg_color), cgen->fg_mbutton,
369 cgen->fg_mbutton_fg_mbutton_menu_items.None_item,
370 cgen->fg_mbutton_fg_mbutton_menu_items.Color_Chooser_item,
371 cgen->fg_swatch, cgen->fg_field, cgen->fg_cb);
373 prop_changebars_cleared(pts->prop_sheet);
375 return (cgen->prop_dialog_shellform);
387 ui_set_active(prop_textp_settings_rec[type].prop_sheet, active);
397 PropTextpSettingsRec *pts = &(prop_textp_settings_rec[type]);
399 if (pts->current_obj == NULL)
403 prop_field_set_value(&(pts->name), "", False);
405 /* Clear Scrolling */
406 prop_radiobox_set_value(&(pts->scrolling),
407 (XtPointer)AB_SCROLLBAR_NEVER, False);
409 /* Clear Border Frame */
410 prop_options_set_value(&(pts->frame), (XtPointer)AB_LINE_NONE, False);
412 /* Clear Operation */
413 prop_radiobox_set_value(&(pts->op), (XtPointer)False, False);
416 prop_checkbox_set_value(&(pts->wrap), True, True, False);
418 /* Clear Menu Name/Title */
419 prop_menuname_set_value(&(pts->menuname), "", False);
420 prop_field_set_value(&(pts->menu_title), "", False);
422 /* Clear Initial Value*/
423 prop_field_set_value(&(pts->init_value), "", False);
426 prop_geomfield_clear(&(pts->pos), GEOM_X);
427 prop_geomfield_clear(&(pts->pos), GEOM_Y);
430 prop_geomfield_clear(&(pts->size), GEOM_WIDTH);
431 prop_geomfield_clear(&(pts->size), GEOM_HEIGHT);
433 /* Clear Initial State */
434 prop_checkbox_set_value(&(pts->init_state), AB_STATE_VISIBLE, True, False);
435 prop_checkbox_set_value(&(pts->init_state), AB_STATE_ACTIVE, True, False);
438 prop_colorfield_set_value(&(pts->bg_color), "", False);
439 prop_colorfield_set_value(&(pts->fg_color), "", False);
441 pts->current_obj = NULL;
443 turnoff_changebars(type);
453 unsigned long loadkey
456 PropTextpSettingsRec *pts = &(prop_textp_settings_rec[type]);
458 BOOL load_all = (loadkey & LoadAll);
462 if (pts->current_obj != NULL)
463 obj = pts->current_obj;
467 else if (!obj_is_text_pane(obj))
470 pts->current_obj = obj;
473 if (load_all || loadkey & LoadName)
474 prop_field_set_value(&(pts->name), obj_get_name(obj), False);
479 prop_radiobox_set_value(&(pts->scrolling),
480 (XtPointer)obj_get_vscrollbar_policy(obj), False);
482 /* Load Border Frame */
483 prop_options_set_value(&(pts->frame), (XtPointer)obj_get_border_frame(obj), False);
486 prop_checkbox_set_value(&(pts->wrap), True,
487 obj->info.text.word_wrap, False);
490 prop_radiobox_set_value(&(pts->op),
491 (XtPointer)obj_get_read_only(obj), False);
493 /* Load Menu Name/Title */
494 prop_menuname_set_value(&(pts->menuname), obj_get_menu_name(obj), False);
495 prop_field_set_value(&(pts->menu_title), obj_get_menu_title(obj), False);
497 /* Load Initial Value */
498 prop_field_set_value(&(pts->init_value), obj_get_initial_value_string(obj), False);
500 /* Load Initial State */
501 prop_checkbox_set_value(&(pts->init_state), AB_STATE_VISIBLE,
502 obj_is_initially_visible(obj), False);
503 prop_checkbox_set_value(&(pts->init_state), AB_STATE_ACTIVE,
504 obj_is_initially_active(obj), False);
507 prop_colorfield_set_value(&(pts->bg_color), obj_get_bg_color(obj), False);
508 prop_colorfield_set_value(&(pts->fg_color), obj_get_fg_color(obj), False);
510 turnoff_changebars(type);
514 if (load_all || loadkey & LoadPosition)
515 prop_load_obj_position(obj, &(pts->pos));
518 if (load_all || loadkey & LoadSize)
520 if (obj_get_num_columns(obj) == -1) /* Size in Pixels */
522 prop_options_set_value(&(pts->size_metric), (XtPointer)SIZE_IN_PIXELS_KEY, False);
523 width = abobj_get_comp_width(obj);
524 height = abobj_get_comp_height(obj);
526 else /* Size in Chars */
528 prop_options_set_value(&(pts->size_metric), (XtPointer)SIZE_IN_CHARS_KEY, False);
529 width = obj_get_num_columns(obj);
530 height = obj_get_num_rows(obj);
532 prop_geomfield_set_value(&(pts->size), GEOM_WIDTH, width, False);
533 prop_geomfield_set_value(&(pts->size), GEOM_HEIGHT,height, False);
544 PropTextpSettingsRec *pts = &(prop_textp_settings_rec[type]);
545 ABObj chg_root = pts->current_obj;
548 int border, metric, new_w, new_h;
549 BOOL size_chg = False;
550 BOOL reset_bg = False;
551 BOOL reset_fg = False;
553 if (!verify_props(type))
556 if (prop_changed(pts->name.changebar))
558 value = prop_field_get_value(&(pts->name));
559 abobj_set_name(pts->current_obj, value);
562 if (prop_changed(pts->scrolling.changebar))
564 abobj_set_scrollbar_state(pts->current_obj,
565 (AB_SCROLLBAR_POLICY)prop_radiobox_get_value(&(pts->scrolling)));
570 pobj = obj_get_root(obj_get_parent(pts->current_obj));
572 if (prop_changed(pts->pos.changebar))
574 if (obj_is_layers(pobj))
577 if (abobj_is_movable(pts->current_obj))
578 abobj_set_xy(chg_root,
579 prop_geomfield_get_value(&(pts->pos), GEOM_X),
580 prop_geomfield_get_value(&(pts->pos), GEOM_Y));
582 if (prop_changed(pts->size.changebar))
584 metric = (int)prop_options_get_value(&(pts->size_metric));
585 new_w = prop_geomfield_get_value(&(pts->size), GEOM_WIDTH);
586 new_h = prop_geomfield_get_value(&(pts->size), GEOM_HEIGHT);
588 border = /* assumption! */
589 ((prop_options_get_value(&(pts->frame)) != (XtPointer)AB_LINE_NONE)? 4 : 0);
591 if (obj_is_layers(pobj))
593 if (metric == SIZE_IN_PIXELS_KEY)
594 abobj_layer_set_size(pobj, new_w, new_h);
599 abobj_set_num_rows(pts->current_obj,
600 metric == SIZE_IN_CHARS_KEY? new_h : -1);
601 abobj_set_num_columns(pts->current_obj,
602 metric == SIZE_IN_CHARS_KEY? new_w : -1);
604 abobj_set_pixel_width(pts->current_obj,
605 metric == SIZE_IN_PIXELS_KEY? new_w : -1, border);
606 abobj_set_pixel_height(pts->current_obj,
607 metric == SIZE_IN_PIXELS_KEY? new_h : -1, border);
611 if (prop_changed(pts->wrap.changebar))
613 abobj_set_word_wrap(pts->current_obj,
614 prop_checkbox_get_value(&(pts->wrap),True));
616 if (prop_changed(pts->op.changebar))
618 abobj_set_read_only(pts->current_obj,
619 prop_radiobox_get_value(&(pts->op)));
622 if (prop_changed(pts->init_value.changebar))
624 value = prop_field_get_value(&(pts->init_value));
625 abobj_set_initial_value(pts->current_obj, value, 0);
628 if (prop_changed(pts->init_state.changebar))
630 abobj_set_visible(pts->current_obj,
631 prop_checkbox_get_value(&(pts->init_state), AB_STATE_VISIBLE));
632 abobj_set_active(pts->current_obj,
633 prop_checkbox_get_value(&(pts->init_state), AB_STATE_ACTIVE));
635 if (prop_changed(pts->frame.changebar))
637 abobj_set_border_frame(pts->current_obj,
638 (AB_LINE_TYPE)prop_options_get_value(&(pts->frame)));
640 if (prop_changed(pts->fg_color.changebar))
642 value = prop_colorfield_get_value(&(pts->fg_color));
643 abobj_set_foreground_color(pts->current_obj, value);
644 if (util_strempty(value))
647 prop_colorfield_set_value(&(pts->fg_color),
648 obj_get_fg_color(pts->current_obj), False);
650 if (prop_changed(pts->bg_color.changebar))
652 value = prop_colorfield_get_value(&(pts->bg_color));
653 abobj_set_background_color(pts->current_obj, value);
654 if (util_strempty(value))
657 prop_colorfield_set_value(&(pts->bg_color),
658 obj_get_bg_color(pts->current_obj), False);
660 if (prop_changed(pts->menuname.changebar))
662 value = prop_menuname_get_value(&(pts->menuname));
663 abobj_set_menu_name(pts->current_obj, value);
665 prop_menuname_set_value(&(pts->menuname),
666 obj_get_menu_name(pts->current_obj), False);
668 if (prop_changed(pts->menu_title.changebar))
670 value = prop_field_get_value(&(pts->menu_title));
671 abobj_set_menu_title(pts->current_obj, value);
674 abobj_instantiate_changes(pts->current_obj);
675 if (chg_root != pts->current_obj)
676 abobj_tree_instantiate_changes(chg_root);
678 if (reset_bg || reset_fg) /* Set back to No Color */
679 abobj_reset_colors(pts->current_obj, reset_bg, reset_fg);
681 abobj_force_dang_form_resize(pts->current_obj);
683 turnoff_changebars(type);
694 return(prop_changebars_pending(prop_textp_settings_rec[type].prop_sheet));
702 PropTextpSettingsRec *pts = &(prop_textp_settings_rec[type]);
704 if (prop_changed(pts->name.changebar) &&
705 !prop_name_ok(pts->current_obj, pts->name.field))
708 if (prop_changed(pts->pos.changebar) &&
709 (!prop_number_ok(pts->pos.x_field,(STRING)XFieldStr, -SHRT_MAX, SHRT_MAX) ||
710 !prop_number_ok(pts->pos.y_field,(STRING)YFieldStr, -SHRT_MAX, SHRT_MAX)))
713 if (prop_changed(pts->size.changebar) &&
714 (!prop_number_ok(pts->size.w_field, (STRING)WFieldStr, 1, SHRT_MAX) ||
715 !prop_number_ok(pts->size.h_field, (STRING)HFieldStr, 1, SHRT_MAX)))
718 if (prop_changed(pts->fg_color.changebar) && !prop_color_ok(pts->fg_color.field))
721 if (prop_changed(pts->bg_color.changebar) && !prop_color_ok(pts->bg_color.field))
724 if (prop_changed(pts->menuname.changebar) && !prop_obj_name_ok(pts->menuname.field,
725 obj_get_module(pts->current_obj), AB_TYPE_MENU, "Menu"))
736 PropTextpSettingsRec *pts = &(prop_textp_settings_rec[type]);
738 prop_set_changebar(pts->name.changebar, PROP_CB_OFF);
739 prop_set_changebar(pts->scrolling.changebar, PROP_CB_OFF);
740 prop_set_changebar(pts->pos.changebar, PROP_CB_OFF);
741 prop_set_changebar(pts->size.changebar, PROP_CB_OFF);
742 prop_set_changebar(pts->wrap.changebar, PROP_CB_OFF);
743 prop_set_changebar(pts->op.changebar, PROP_CB_OFF);
744 prop_set_changebar(pts->init_value.changebar, PROP_CB_OFF);
745 prop_set_changebar(pts->init_state.changebar, PROP_CB_OFF);
746 prop_set_changebar(pts->frame.changebar, PROP_CB_OFF);
747 prop_set_changebar(pts->bg_color.changebar, PROP_CB_OFF);
748 prop_set_changebar(pts->fg_color.changebar, PROP_CB_OFF);
749 prop_set_changebar(pts->menuname.changebar, PROP_CB_OFF);
750 prop_set_changebar(pts->menu_title.changebar, PROP_CB_OFF);
752 prop_changebars_cleared(pts->prop_sheet);