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_textf.c /main/5 1996/08/08 18:04:36 mustafa $
27 * @(#)pal_textf.c 1.62 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_textf.c - Implements Palette TextField object functionality
49 #include <ab_private/pal.h>
50 #include <ab_private/ab.h>
51 #include <ab_private/prop.h>
52 #include <ab_private/abobj.h>
53 #include <ab_private/abobj_set.h>
54 #include <ab_private/ui_util.h>
57 typedef struct PROP_TEXTF_SETTINGS
60 PropFieldSettingRec name;
61 PropGeometrySettingRec pos;
62 PropGeometrySettingRec size;
63 PropOptionsSettingRec size_metric;
64 PropOptionsSettingRec label_type;
65 PropFieldSettingRec label;
66 PropOptionsSettingRec label_pos;
67 PropRadioSettingRec op;
68 PropFieldSettingRec max_chars;
69 PropFieldSettingRec init_value;
70 PropCheckboxSettingRec init_state;
71 PropColorSettingRec bg_color;
72 PropColorSettingRec fg_color;
74 PropMenunameSettingRec menuname;
77 } PropTextfSettingsRec, *PropTextfSettings;
79 /*************************************************************************
81 ** Private Function Declarations **
83 **************************************************************************/
87 static int textf_initialize(
90 static Widget textf_prop_init(
94 static int textf_prop_activate(
98 static int textf_prop_clear(
101 static int textf_prop_load(
104 unsigned long loadkey
106 static int textf_prop_apply(
109 static BOOL textf_prop_pending(
113 static BOOL verify_props(
116 static void turnoff_changebars(
124 /*************************************************************************
128 **************************************************************************/
129 PalItemInfo textf_palitem_rec = {
131 /* type */ AB_TYPE_TEXT_FIELD,
132 /* name */ "Text Field",
133 /* animation pixmaps*/ NULL,
134 /* number of pixmaps*/ 0,
135 /* rev_prop_frame */ NULL,
136 /* fix_prop_dialog */ NULL,
137 /* initialize */ textf_initialize,
138 /* is_a_test */ obj_is_text_field,
139 /* prop_initialize */ textf_prop_init,
140 /* prop_activate */ textf_prop_activate,
141 /* prop_clear */ textf_prop_clear,
142 /* prop_load */ textf_prop_load,
143 /* prop_apply */ textf_prop_apply,
144 /* prop_pending */ textf_prop_pending
148 PalItemInfo *ab_textf_palitem = &textf_palitem_rec;
149 PropTextfSettingsRec prop_textf_settings_rec[AB_PROP_TYPE_NUM_VALUES];
151 /*************************************************************************
153 ** Function Definitions **
155 **************************************************************************/
161 AB_TEXT_INFO *info = &(obj->info.text);
163 obj_set_unique_name(obj, "textfield");
165 obj_set_label(obj, catgets(Dtb_project_catd, 100, 263, "TextField:"));
166 obj_set_is_initially_visible(obj, True);
167 obj_set_is_initially_active(obj, True);
168 obj_set_num_columns(obj, 8);
169 obj_set_max_length(obj, 80);
171 obj_set_attachment(obj, AB_CP_NORTH, AB_ATTACH_POINT, NULL, obj->y);
172 obj_set_attachment(obj, AB_CP_WEST, AB_ATTACH_POINT, NULL, obj->x);
184 DtbTextfPropDialogInfoRec rev_textf_prop_dialog; /* Revolving Props */
185 DtbTextfPropDialogInfo cgen = &dtb_textf_prop_dialog; /* Codegen structure */
186 DtbRevolvPropDialogInfo rpd = &(dtb_revolv_prop_dialog);
187 PropTextfSettingsRec *pts = &(prop_textf_settings_rec[type]);
192 if (type == AB_PROP_REVOLVING)
195 * Only the Attributes ControlPanel needs to be created within
196 * the existing Revolving Prop dialog, so fill out all other
197 * fields with the Revolving Prop dialog equivelents, so the
198 * dtb initialize proc will skip those non-NULL fields...
200 dtbTextfPropDialogInfo_clear(&rev_textf_prop_dialog);
202 cgen = &(rev_textf_prop_dialog);
203 cgen->prop_dialog = rpd->prop_dialog;
204 cgen->prop_dialog_shellform = rpd->prop_dialog_shellform;
205 cgen->prop_dialog_panedwin = rpd->prop_dialog_panedwin;
206 cgen->prop_dialog_form = rpd->prop_dialog_form;
207 cgen->objlist_panel = rpd->objlist_panel;
208 cgen->objlist_label = rpd->objlist_label2;
209 cgen->objlist_scrolledwin = rpd->objlist_scrolledwin;
210 cgen->objlist = rpd->objlist;
211 cgen->attrs_ctrlpanel_frame = rpd->attrs_ctrlpanel_frame;
212 cgen->activate_panel = rpd->activate_panel;
213 cgen->apply_button = rpd->apply_button;
214 cgen->ok_button = rpd->ok_button;
215 cgen->cancel_button = rpd->cancel_button;
216 cgen->reset_button = rpd->reset_button;
217 cgen->help_button = rpd->help_button;
220 else /* AB_PROP_FIXED */
221 cgen = &dtb_textf_prop_dialog;
223 if (dtb_textf_prop_dialog_initialize(cgen, parent) == 0)
225 pts->prop_sheet = cgen->attrs_ctrlpanel;
226 pts->current_obj = NULL;
228 if (type == AB_PROP_REVOLVING)
229 XtVaSetValues(parent,
230 XmNuserData, pts->current_obj,
233 /* Dialog/Object List */
234 if (type == AB_PROP_FIXED)
236 prop_fixed_dialog_init(ab_textf_palitem,
237 cgen->prop_dialog_shellform, cgen->objlist);
238 prop_activate_panel_init(type, ab_textf_palitem,
239 cgen->ok_button, cgen->apply_button,
240 cgen->reset_button, cgen->cancel_button,
244 /* Alternate Editor Buttons */
245 prop_editors_panel_init(type, ab_textf_palitem,
246 cgen->attach_button, cgen->conn_button, cgen->helptxt_button);
249 * Prop Sheet Settings....
253 prop_field_init(&(pts->name), cgen->name_field_label,
254 cgen->name_field, cgen->name_cb);
256 /* Label, Type, Position */
258 item[n] = cgen->labeltype_rbox_items.String_item;
259 item_val[n] = AB_LABEL_STRING; n++;
260 item[n] = cgen->labeltype_rbox_items.Graphic_item;
261 item_val[n] = AB_LABEL_GLYPH; n++;
262 prop_options_init(&(pts->label_type), cgen->labeltype_rbox_label,
263 cgen->labeltype_rbox, cgen->labeltype_rbox_menu,
264 n, item, (XtPointer*)item_val,
267 prop_field_init(&(pts->label), cgen->label_field_label,
268 cgen->label_field, cgen->label_cb);
269 prop_label_field_init(&(pts->label), cgen->graphic_hint, item, n);
272 item[n] = cgen->labelpos_rbox_items.Left_item;
273 item_val[n] = AB_CP_WEST; n++;
274 item[n] = cgen->labelpos_rbox_items.Above_item;
275 item_val[n] = AB_CP_NORTH; n++;
276 prop_options_init(&(pts->label_pos), cgen->labelpos_rbox_label,
277 cgen->labelpos_rbox, cgen->labelpos_rbox_menu,
278 n, item, (XtPointer*)item_val,
283 prop_menuname_init(&(pts->menuname), cgen->menu_mbutton, cgen->menu_field,
284 cgen->name_field, cgen->menu_cb,
285 &(pts->current_obj), True);
290 item[n] = cgen->op_rbox_items.Editable_item;
291 item_val[n] = False; n++;
292 item[n] = cgen->op_rbox_items.Read_Only_item;
293 item_val[n] = True; n++;
294 prop_radiobox_init(&(pts->op), cgen->op_rbox_label,
295 cgen->op_rbox, n, item, (XtPointer*)item_val,
299 prop_field_init(&(pts->max_chars), cgen->charsmax_field_label,
300 cgen->charsmax_field, cgen->charsmax_cb);
303 prop_field_init(&(pts->init_value), cgen->ivalue_field_label,
304 cgen->ivalue_field, cgen->ivalue_cb);
307 prop_geomfield_init(&(pts->pos), cgen->pos_label,
308 cgen->x_field_label, cgen->x_field,
309 cgen->y_field_label, cgen->y_field,
310 NULL, NULL, NULL, NULL,
314 prop_geomfield_init(&(pts->size), cgen->width_opmenu_label,
315 NULL, NULL, NULL, NULL,
316 cgen->w_field_label, cgen->w_field,
321 item[n] = cgen->width_opmenu_items.Characters_item;
322 item_val[n] = SIZE_IN_CHARS_KEY; n++;
323 item[n] = cgen->width_opmenu_items.Pixels_item;
324 item_val[n] = SIZE_IN_PIXELS_KEY; n++;
325 prop_options_init(&(pts->size_metric), cgen->width_opmenu_label,
327 cgen->width_opmenu_menu,
328 n, item, (XtPointer*)item_val,
333 item[n] = cgen->istate_ckbox_items.Visible_item;
334 item_val[n] = AB_STATE_VISIBLE; n++;
335 item[n] = cgen->istate_ckbox_items.Active_item;
336 item_val[n] = AB_STATE_ACTIVE; n++;
337 prop_checkbox_init(&(pts->init_state), cgen->istate_ckbox_label,
338 cgen->istate_ckbox, n, item, item_val,
342 prop_colorfield_init(&(pts->bg_color), cgen->bg_mbutton,
343 cgen->bg_mbutton_bg_mbutton_menu_items.None_item,
344 cgen->bg_mbutton_bg_mbutton_menu_items.Color_Chooser_item,
345 cgen->bg_swatch, cgen->bg_field, cgen->bg_cb);
347 prop_colorfield_init(&(pts->fg_color), cgen->fg_mbutton,
348 cgen->fg_mbutton_fg_mbutton_menu_items.None_item,
349 cgen->fg_mbutton_fg_mbutton_menu_items.Color_Chooser_item,
350 cgen->fg_swatch, cgen->fg_field, cgen->fg_cb);
352 prop_changebars_cleared(pts->prop_sheet);
354 return (cgen->prop_dialog_shellform);
367 ui_set_active(prop_textf_settings_rec[type].prop_sheet, active);
378 PropTextfSettingsRec *pts = &(prop_textf_settings_rec[type]);
380 if (pts->current_obj == NULL)
384 prop_field_set_value(&(pts->name), "", False);
386 /* Clear Label Type/Position */
387 prop_options_set_value(&(pts->label_type), (XtPointer)AB_LABEL_STRING, False);
388 prop_options_set_value(&(pts->label_pos), (XtPointer)AB_CP_WEST, False);
391 ui_set_label_string(pts->label.label, "Label:");
392 prop_field_set_value(&(pts->label), "", False);
394 /* Clear Menu Name */
396 prop_menuname_set_value(&(pts->menuname), "", False);
399 /* Clear Operation */
400 prop_radiobox_set_value(&(pts->op), (XtPointer)False, False);
402 /* Clear Maximum Chars */
403 prop_field_set_value(&(pts->max_chars), "", False);
405 /* Clear Initial Value*/
406 prop_field_set_value(&(pts->init_value), "", False);
409 prop_geomfield_clear(&(pts->pos), GEOM_X);
410 prop_geomfield_clear(&(pts->pos), GEOM_Y);
413 prop_geomfield_clear(&(pts->size), GEOM_WIDTH);
415 /* Clear Initial State */
416 prop_checkbox_set_value(&(pts->init_state), AB_STATE_VISIBLE, True, False);
417 prop_checkbox_set_value(&(pts->init_state), AB_STATE_ACTIVE, True, False);
420 prop_colorfield_set_value(&(pts->bg_color), "", False);
421 prop_colorfield_set_value(&(pts->fg_color), "", False);
423 pts->current_obj = NULL;
425 turnoff_changebars(type);
435 unsigned long loadkey
438 PropTextfSettingsRec *pts = &(prop_textf_settings_rec[type]);
440 BOOL load_all = (loadkey & LoadAll);
444 if (pts->current_obj != NULL)
445 obj = pts->current_obj;
449 else if (!obj_is_text_field(obj))
452 pts->current_obj = obj;
455 if (load_all || loadkey & LoadName)
456 prop_field_set_value(&(pts->name), obj_get_name(obj), False);
460 /* Load Label Type/Position */
461 prop_options_set_value(&(pts->label_type), (XtPointer)obj->label_type, False);
462 prop_options_set_value(&(pts->label_pos), (XtPointer)obj_get_label_position(obj), False);
465 prop_setup_label_field(&(pts->label), NULL,
466 obj->label_type, obj_get_label(obj), AB_LINE_UNDEF);
468 prop_radiobox_set_value(&(pts->op),
469 (XtPointer)obj_get_read_only(obj), False);
471 /* Load Maximum Chars */
472 prop_field_set_numeric_value(&(pts->max_chars), obj_get_max_length(obj), False);
474 /* Load Initial Value */
475 prop_field_set_value(&(pts->init_value), obj_get_initial_value_string(obj), False);
477 /* Load Initial State */
478 prop_checkbox_set_value(&(pts->init_state), AB_STATE_VISIBLE,
479 obj_is_initially_visible(obj), False);
480 prop_checkbox_set_value(&(pts->init_state), AB_STATE_ACTIVE,
481 obj_is_initially_active(obj), False);
484 prop_colorfield_set_value(&(pts->bg_color), obj_get_bg_color(obj), False);
485 prop_colorfield_set_value(&(pts->fg_color), obj_get_fg_color(obj), False);
487 turnoff_changebars(type);
491 if (load_all || loadkey & LoadPosition)
492 prop_load_obj_position(obj, &(pts->pos));
495 if (load_all || loadkey & LoadSize)
497 if (obj_get_num_columns(obj) == -1) /* Size in Pixels */
499 prop_options_set_value(&(pts->size_metric), (XtPointer)SIZE_IN_PIXELS_KEY, False);
500 width = abobj_get_comp_width(obj);
502 else /* Size in Chars */
504 prop_options_set_value(&(pts->size_metric), (XtPointer)SIZE_IN_CHARS_KEY, False);
505 width = obj_get_num_columns(obj);
507 prop_geomfield_set_value(&(pts->size), GEOM_WIDTH, width, False);
518 PropTextfSettingsRec *pts = &(prop_textf_settings_rec[type]);
520 int num, metric, new_w;
521 BOOL size_chg = False;
522 BOOL reset_bg = False;
523 BOOL reset_fg = False;
525 if (!verify_props(type))
528 if (prop_changed(pts->name.changebar))
530 value = prop_field_get_value(&(pts->name));
531 abobj_set_name(pts->current_obj, value);
534 if (prop_changed(pts->label.changebar) ||
535 prop_changed(pts->label_type.changebar))
537 value = prop_field_get_value(&(pts->label));
538 abobj_set_label(pts->current_obj,
539 (AB_LABEL_TYPE)prop_options_get_value(&(pts->label_type)),
543 abobj_set_label_position(pts->current_obj,
544 (AB_COMPASS_POINT)prop_options_get_value(&(pts->label_pos)));
548 if (prop_changed(pts->menuname.changebar))
550 value = prop_menuname_get_value(&(pts->menuname));
551 abobj_set_menu_name(pts->current_obj, value);
553 prop_menuname_set_value(&(pts->menuname),
554 obj_get_menu_name(pts->current_obj), False);
557 if (prop_changed(pts->op.changebar))
559 abobj_set_read_only(pts->current_obj,
560 prop_radiobox_get_value(&(pts->op)));
563 if (prop_changed(pts->max_chars.changebar))
565 num = prop_field_get_numeric_value(&(pts->max_chars));
566 abobj_set_max_length(pts->current_obj, num);
568 if (prop_changed(pts->init_value.changebar))
570 value = prop_field_get_value(&(pts->init_value));
571 abobj_set_initial_value(pts->current_obj, value, 0);
574 if (prop_changed(pts->pos.changebar))
576 if (abobj_is_movable(pts->current_obj))
577 abobj_set_xy(pts->current_obj,
578 prop_geomfield_get_value(&(pts->pos), GEOM_X),
579 prop_geomfield_get_value(&(pts->pos), GEOM_Y));
581 if (prop_changed(pts->size.changebar))
583 metric = (int)prop_options_get_value(&(pts->size_metric));
584 new_w = prop_geomfield_get_value(&(pts->size), GEOM_WIDTH);
586 abobj_set_num_columns(pts->current_obj,
587 metric == SIZE_IN_CHARS_KEY? new_w : -1);
588 abobj_set_pixel_width(pts->current_obj,
589 metric == SIZE_IN_PIXELS_KEY? new_w : -1, 0);
593 if (prop_changed(pts->init_state.changebar))
595 abobj_set_visible(pts->current_obj,
596 prop_checkbox_get_value(&(pts->init_state), AB_STATE_VISIBLE));
597 abobj_set_active(pts->current_obj,
598 prop_checkbox_get_value(&(pts->init_state), AB_STATE_ACTIVE));
600 if (prop_changed(pts->fg_color.changebar))
602 value = prop_colorfield_get_value(&(pts->fg_color));
603 abobj_set_foreground_color(pts->current_obj, value);
604 if (util_strempty(value))
607 prop_colorfield_set_value(&(pts->fg_color), obj_get_fg_color(pts->current_obj), False);
609 if (prop_changed(pts->bg_color.changebar))
611 value = prop_colorfield_get_value(&(pts->bg_color));
612 abobj_set_background_color(pts->current_obj, value);
613 if (util_strempty(value))
616 prop_colorfield_set_value(&(pts->bg_color),
617 obj_get_bg_color(pts->current_obj), False);
619 abobj_instantiate_changes(pts->current_obj);
621 if (reset_bg || reset_fg) /* Set back to No Color */
622 abobj_reset_colors(pts->current_obj, reset_bg, reset_fg);
625 abobj_force_dang_form_resize(pts->current_obj);
627 turnoff_changebars(type);
637 return(prop_changebars_pending(prop_textf_settings_rec[type].prop_sheet));
645 PropTextfSettingsRec *pts = &(prop_textf_settings_rec[type]);
647 if (prop_changed(pts->name.changebar) && !prop_name_ok(pts->current_obj, pts->name.field))
650 if ((prop_changed(pts->label_type.changebar) || prop_changed(pts->label.changebar)) &&
651 prop_options_get_value(&(pts->label_type)) == (XtPointer)AB_LABEL_GLYPH &&
652 !prop_graphic_filename_ok(pts->label.field, False))
655 if (prop_changed(pts->pos.changebar) &&
656 (!prop_number_ok(pts->pos.x_field, (STRING)XFieldStr, -SHRT_MAX, SHRT_MAX) ||
657 !prop_number_ok(pts->pos.y_field, (STRING)YFieldStr, -SHRT_MAX, SHRT_MAX)))
660 if (prop_changed(pts->size.changebar) &&
661 !prop_number_ok(pts->size.w_field, (STRING)WFieldStr, 1, SHRT_MAX))
664 if (prop_changed(pts->max_chars.changebar) &&
665 !prop_number_ok(pts->max_chars.field, "Maximum Char Field", 1, 999))
668 if (prop_changed(pts->fg_color.changebar) && !prop_color_ok(pts->fg_color.field))
671 if (prop_changed(pts->bg_color.changebar) && !prop_color_ok(pts->bg_color.field))
675 if (prop_changed(pts->menuname.changebar) && !prop_obj_name_ok(pts->menuname.field,
676 obj_get_module(pts->current_obj), AB_TYPE_MENU, "Menu"))
688 PropTextfSettingsRec *pts = &(prop_textf_settings_rec[type]);
690 prop_set_changebar(pts->name.changebar, PROP_CB_OFF);
691 prop_set_changebar(pts->pos.changebar, PROP_CB_OFF);
692 prop_set_changebar(pts->size.changebar, PROP_CB_OFF);
693 prop_set_changebar(pts->label_type.changebar, PROP_CB_OFF);
694 prop_set_changebar(pts->label.changebar, PROP_CB_OFF);
695 prop_set_changebar(pts->op.changebar, PROP_CB_OFF);
696 prop_set_changebar(pts->max_chars.changebar, PROP_CB_OFF);
697 prop_set_changebar(pts->init_value.changebar, PROP_CB_OFF);
698 prop_set_changebar(pts->init_state.changebar, PROP_CB_OFF);
699 prop_set_changebar(pts->bg_color.changebar, PROP_CB_OFF);
700 prop_set_changebar(pts->fg_color.changebar, PROP_CB_OFF);
702 prop_set_changebar(pts->menuname.changebar, PROP_CB_OFF);
705 prop_changebars_cleared(pts->prop_sheet);