pal_combobox.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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 libraries 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_combobox.c /main/5 1996/08/08 17:52:08 mustafa $
  25. *
  26. * @(#)pal_combobox.c 1.1 23 Feb 1994
  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. * pal_combobox.c - Implements Palette ComboBox object functionality
  43. */
  44. #include <stdint.h>
  45. #include <stdio.h>
  46. #include <Xm/Xm.h>
  47. #include "dtb_utils.h"
  48. #include <ab_private/obj_notify.h>
  49. #include <ab_private/ab.h>
  50. #include <ab_private/pal.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>
  55. #include "combobox_ui.h"
  56. const int combo_box_init_width = 100;
  57. static const int input_rows = 3;
  58. typedef struct PROP_COMBOBOX_SETTINGS
  59. {
  60. Widget prop_sheet;
  61. PropFieldSettingRec name;
  62. PropRadioSettingRec combobox_type;
  63. PropGeometrySettingRec pos;
  64. PropRadioSettingRec wth_policy;
  65. PropGeometrySettingRec wth;
  66. PropOptionsSettingRec label_type;
  67. PropFieldSettingRec label;
  68. PropOptionsSettingRec label_pos;
  69. PropCheckboxSettingRec init_state;
  70. PropColorSettingRec bg_color;
  71. PropColorSettingRec fg_color;
  72. PropFieldSettingRec item_label;
  73. PropCheckboxSettingRec item_state;
  74. PropItemsSettingRec items;
  75. ABObj current_obj;
  76. } PropComboboxSettingsRec, *PropComboboxSettings;
  77. /*************************************************************************
  78. ** **
  79. ** Private Function Declarations **
  80. ** **
  81. **************************************************************************/
  82. /*
  83. * Methods
  84. */
  85. static int combo_box_initialize(
  86. ABObj obj
  87. );
  88. static Widget combo_box_prop_init(
  89. Widget parent,
  90. AB_PROP_TYPE type
  91. );
  92. static int combo_box_prop_activate(
  93. AB_PROP_TYPE type,
  94. BOOL active
  95. );
  96. static int combo_box_prop_clear(
  97. AB_PROP_TYPE type
  98. );
  99. static int combo_box_prop_load(
  100. ABObj obj,
  101. AB_PROP_TYPE type,
  102. unsigned long loadkey
  103. );
  104. static int combo_box_prop_apply(
  105. AB_PROP_TYPE type
  106. );
  107. static BOOL combo_box_prop_pending(
  108. AB_PROP_TYPE type
  109. );
  110. static BOOL verify_props(
  111. AB_PROP_TYPE type
  112. );
  113. static void turnoff_changebars(
  114. AB_PROP_TYPE type
  115. );
  116. /*
  117. * ABObj Callbacks
  118. */
  119. static int combobox_install_obj_destroy_CB(void);
  120. static int combobox_obj_destroy_CB(
  121. ObjEvDestroyInfo destroyInfo
  122. );
  123. /*
  124. * Xt Callbacks
  125. */
  126. static void wth_policyCB(
  127. Widget widget,
  128. XtPointer clientdata,
  129. XmToggleButtonCallbackStruct *state
  130. );
  131. /*************************************************************************
  132. ** **
  133. ** Data **
  134. ** **
  135. **************************************************************************/
  136. PalItemInfo combo_box_palitem_rec = {
  137. /* type */ AB_TYPE_COMBO_BOX,
  138. /* name */ "Combo Box",
  139. /* animation pixmaps*/ NULL,
  140. /* number of pixmaps*/ 0,
  141. /* rev_prop_frame */ NULL,
  142. /* fix_prop_dialog */ NULL,
  143. /* initialize */ combo_box_initialize,
  144. /* is_a_test */ obj_is_combo_box,
  145. /* prop_initialize */ combo_box_prop_init,
  146. /* prop_activate */ combo_box_prop_activate,
  147. /* prop_clear */ combo_box_prop_clear,
  148. /* prop_load */ combo_box_prop_load,
  149. /* prop_apply */ combo_box_prop_apply,
  150. /* prop_pending */ combo_box_prop_pending
  151. };
  152. PalItemInfo *ab_combo_box_palitem = &combo_box_palitem_rec;
  153. PropComboboxSettingsRec prop_combobox_settings_rec[AB_PROP_TYPE_NUM_VALUES];
  154. /*************************************************************************
  155. ** **
  156. ** Function Definitions **
  157. ** **
  158. **************************************************************************/
  159. static int
  160. combo_box_initialize(
  161. ABObj obj
  162. )
  163. {
  164. ABObj iobj;
  165. String items[2];
  166. int i;
  167. obj_set_unique_name(obj, "combobox");
  168. obj_set_label(obj, CATGETS(Dtb_project_catd, 100, 255, "ComboBox:"));
  169. obj_set_label_position(obj, AB_CP_WEST);
  170. obj_set_height(obj, -1);
  171. /* Add initial items to list */
  172. items[0] = CATGETS(Dtb_project_catd, 6, 70, "itemA");
  173. items[1] = CATGETS(Dtb_project_catd, 6, 71, "itemB");
  174. for (i=0; i < XtNumber(items); i++)
  175. {
  176. iobj = obj_create(AB_TYPE_ITEM, NULL);
  177. obj_set_subtype(iobj, AB_ITEM_FOR_COMBO_BOX);
  178. obj_append_child(obj, iobj);
  179. abobj_set_item_name(iobj, obj_get_module(obj), obj_get_name(obj), items[i]);
  180. obj_set_label(iobj, items[i]);
  181. obj_set_is_initially_selected(iobj, i==0? True : False);
  182. }
  183. obj_set_attachment(obj, AB_CP_NORTH, AB_ATTACH_POINT, NULL, obj->y);
  184. obj_set_attachment(obj, AB_CP_WEST, AB_ATTACH_POINT, NULL, obj->x);
  185. return OK;
  186. }
  187. static Widget
  188. combo_box_prop_init(
  189. Widget parent,
  190. AB_PROP_TYPE type
  191. )
  192. {
  193. DtbComboboxPropDialogInfoRec rev_combobox_prop_dialog; /* Revolving Props */
  194. DtbComboboxPropDialogInfo cgen = &dtb_combobox_prop_dialog; /* Codegen structure */
  195. DtbRevolvPropDialogInfo rpd = &(dtb_revolv_prop_dialog);
  196. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  197. Widget item[6];
  198. XtArgVal item_val[6];
  199. XtPointer item_ptr[6];
  200. Widget item2[6];
  201. XtArgVal item2_val[6];
  202. int i, n, j;
  203. if (type == AB_PROP_REVOLVING)
  204. {
  205. /* Cloning Trick:
  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...
  210. */
  211. dtbComboboxPropDialogInfo_clear(&rev_combobox_prop_dialog);
  212. cgen = &(rev_combobox_prop_dialog);
  213. cgen->prop_dialog = rpd->prop_dialog;
  214. cgen->prop_dialog_shellform = rpd->prop_dialog_shellform;
  215. cgen->prop_dialog_panedwin = rpd->prop_dialog_panedwin;
  216. cgen->prop_dialog_form = rpd->prop_dialog_form;
  217. cgen->objlist_panel = rpd->objlist_panel;
  218. cgen->objlist_label = rpd->objlist_label2;
  219. cgen->objlist_scrolledwin = rpd->objlist_scrolledwin;
  220. cgen->objlist = rpd->objlist;
  221. cgen->attrs_ctrlpanel_frame = rpd->attrs_ctrlpanel_frame;
  222. cgen->activate_panel = rpd->activate_panel;
  223. cgen->ok_button = rpd->ok_button;
  224. cgen->cancel_button = rpd->cancel_button;
  225. cgen->apply_button = rpd->apply_button;
  226. cgen->reset_button = rpd->reset_button;
  227. cgen->help_button = rpd->help_button;
  228. /*
  229. * Get notification of object destruction!
  230. */
  231. combobox_install_obj_destroy_CB();
  232. }
  233. else /* AB_PROP_FIXED */
  234. cgen = &dtb_combobox_prop_dialog;
  235. if (dtb_combobox_prop_dialog_initialize(cgen, parent) == 0)
  236. {
  237. pcs->prop_sheet = cgen->attrs_ctrlpanel;
  238. pcs->current_obj = NULL;
  239. if (type == AB_PROP_REVOLVING)
  240. XtVaSetValues(parent,
  241. XmNuserData, pcs->current_obj,
  242. NULL);
  243. /* Dialog/Object List */
  244. if (type == AB_PROP_FIXED)
  245. {
  246. prop_fixed_dialog_init(ab_combo_box_palitem,
  247. cgen->prop_dialog_shellform, cgen->objlist);
  248. prop_activate_panel_init(type, ab_combo_box_palitem,
  249. cgen->ok_button, cgen->apply_button,
  250. cgen->reset_button, cgen->cancel_button,
  251. cgen->help_button);
  252. }
  253. /* Alternate Editor Buttons */
  254. prop_editors_panel_init(type, ab_combo_box_palitem,
  255. cgen->attach_button, cgen->conn_button, cgen->helptxt_button);
  256. /*
  257. * Prop Sheet Settings....
  258. */
  259. /* Name */
  260. prop_field_init(&(pcs->name), cgen->name_field_label,
  261. cgen->name_field, cgen->name_cb);
  262. /* Label, Type, Position */
  263. n = 0;
  264. item[n] = cgen->labeltype_rbox_items.String_item;
  265. item_ptr[n] = (void *) AB_LABEL_STRING; n++;
  266. item[n] = cgen->labeltype_rbox_items.Graphic_item;
  267. item_ptr[n] = (void *) AB_LABEL_GLYPH; n++;
  268. prop_options_init(&(pcs->label_type), cgen->labeltype_rbox_label,
  269. cgen->labeltype_rbox, cgen->labeltype_rbox_menu,
  270. n, item, item_ptr,
  271. cgen->labeltype_cb);
  272. prop_field_init(&(pcs->label), cgen->label_field_label,
  273. cgen->label_field, cgen->label_cb);
  274. prop_label_field_init(&(pcs->label), cgen->graphic_hint, item, n);
  275. n = 0;
  276. item[n] = cgen->labelpos_rbox_items.Above_item;
  277. item_ptr[n] = (void *) AB_CP_NORTH; n++;
  278. item[n] = cgen->labelpos_rbox_items.Left_item;
  279. item_ptr[n] = (void *) AB_CP_WEST; n++;
  280. prop_options_init(&(pcs->label_pos), cgen->labelpos_rbox_label,
  281. cgen->labelpos_rbox, cgen->labelpos_rbox_menu,
  282. n, item, item_ptr,
  283. cgen->labeltype_cb);
  284. /* Read Only */
  285. n = 0;
  286. item[n] = cgen->comboboxtype_rbox_items.Static_item;
  287. item_ptr[n] = (void *) True; n++;
  288. item[n] = cgen->comboboxtype_rbox_items.Editable_item;
  289. item_ptr[n] = (void *) False; n++;
  290. prop_radiobox_init(&(pcs->combobox_type), cgen->comboboxtype_rbox_label,
  291. cgen->comboboxtype_rbox, n, item, item_ptr,
  292. cgen->comboboxtype_cb);
  293. /* Position */
  294. prop_geomfield_init(&(pcs->pos), cgen->pos_label,
  295. cgen->x_field_label, cgen->x_field,
  296. cgen->y_field_label, cgen->y_field,
  297. NULL, NULL,
  298. NULL, NULL,
  299. cgen->pos_cb);
  300. /* Width */
  301. n = 0;
  302. item[n] = cgen->wpolicy_rbox_items.Longest_Item_item;
  303. item_ptr[n] = (void *) SIZE_OF_CONTENTS_KEY; n++;
  304. item[n] = cgen->wpolicy_rbox_items.Fixed_item;
  305. item_ptr[n] = (void *) SIZE_FIXED_KEY; n++;
  306. prop_radiobox_init(&(pcs->wth_policy), cgen->wpolicy_rbox_label,
  307. cgen->wpolicy_rbox, n, item, item_ptr,
  308. cgen->wpolicy_cb);
  309. for(i=0; i < n; i++)
  310. XtAddCallback(item[i], XmNvalueChangedCallback,
  311. (XtCallbackProc)prop_size_policyCB, (XtPointer)&(pcs->wth));
  312. prop_geomfield_init(&(pcs->wth), cgen->wpolicy_rbox_label,
  313. NULL, NULL, NULL, NULL,
  314. cgen->w_field_label, cgen->w_field,
  315. NULL, NULL,
  316. cgen->wpolicy_cb);
  317. /* Initial State */
  318. n = 0;
  319. item[n] = cgen->istate_ckbox_items.Visible_item;
  320. item_val[n] = AB_STATE_VISIBLE; n++;
  321. item[n] = cgen->istate_ckbox_items.Active_item;
  322. item_val[n] = AB_STATE_ACTIVE; n++;
  323. prop_checkbox_init(&(pcs->init_state), cgen->istate_ckbox_label,
  324. cgen->istate_ckbox, n, item, item_val,
  325. cgen->istate_cb);
  326. /* Color */
  327. prop_colorfield_init(&(pcs->bg_color), cgen->bg_mbutton,
  328. cgen->bg_mbutton_bg_mbutton_menu_items.None_item,
  329. cgen->bg_mbutton_bg_mbutton_menu_items.Color_Chooser_item,
  330. cgen->bg_swatch, cgen->bg_field, cgen->bg_cb);
  331. prop_colorfield_init(&(pcs->fg_color), cgen->fg_mbutton,
  332. cgen->fg_mbutton_fg_mbutton_menu_items.None_item,
  333. cgen->fg_mbutton_fg_mbutton_menu_items.Color_Chooser_item,
  334. cgen->fg_swatch, cgen->fg_field, cgen->fg_cb);
  335. /* Item Editor....*/
  336. /* Item Label */
  337. prop_field_init(&(pcs->item_label), cgen->itemlabel_label,
  338. cgen->itemlabel_field, cgen->itemlist_cb);
  339. /* Item State */
  340. n = 0;
  341. item[n] = cgen->item_state_ckbox_items.Selected_item;
  342. item_val[n] = AB_STATE_SELECTED; n++;
  343. prop_checkbox_init(&(pcs->item_state), NULL,
  344. cgen->item_state_ckbox, n, item, item_val,
  345. cgen->itemlist_cb);
  346. /* Store Items->Add menu items in array */
  347. n = 0;
  348. item[n] = cgen->item_edit_mbutton_editmenu_items.Add_Before_item;
  349. item_val[n] = INSERT_BEFORE; n++;
  350. item[n] = cgen->item_edit_mbutton_editmenu_items.Add_After_item;
  351. item_val[n] = INSERT_AFTER; n++;
  352. /* Store Items->Edit menu items in array */
  353. j = 0;
  354. item2[j] = cgen->item_edit_mbutton_editmenu_items.Cut_item;
  355. item2_val[j] = AB_EDIT_CUT; j++;
  356. item2[j] = cgen->item_edit_mbutton_editmenu_items.Copy_item;
  357. item2_val[j] = AB_EDIT_COPY; j++;
  358. item2[j] = cgen->item_edit_mbutton_editmenu_items.Paste_item;
  359. item2_val[j] = AB_EDIT_PASTE; j++;
  360. item2[j] = cgen->item_edit_mbutton_editmenu_items.Delete_item;
  361. item2_val[j] = AB_EDIT_DELETE; j++;
  362. item2[j] = cgen->item_edit_mbutton_editmenu_items.Change_item;
  363. item2_val[j] = EDIT_CHANGE; j++;
  364. prop_item_editor_init(&(pcs->items), AB_ITEM_FOR_COMBO_BOX,
  365. cgen->itemlist, cgen->itemlist_cb,
  366. cgen->item_add_button,
  367. n, item, item_val,
  368. j, item2, item2_val,
  369. &(pcs->item_label), NULL/*label_type*/, NULL/*graphic_hint*/,
  370. NULL/*mnemonic*/, NULL/*accel*/, NULL/*line_style*/,
  371. &(pcs->item_state), NULL,
  372. &(pcs->current_obj));
  373. prop_changebars_cleared(pcs->prop_sheet);
  374. return (cgen->prop_dialog_shellform);
  375. }
  376. else
  377. return NULL;
  378. }
  379. static int
  380. combo_box_prop_activate(
  381. AB_PROP_TYPE type,
  382. BOOL active
  383. )
  384. {
  385. ui_set_active(prop_combobox_settings_rec[type].prop_sheet, active);
  386. return OK;
  387. }
  388. static int
  389. combo_box_prop_clear(
  390. AB_PROP_TYPE type
  391. )
  392. {
  393. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  394. if (pcs->current_obj == NULL)
  395. return OK;
  396. /* Clear Name */
  397. prop_field_set_value(&(pcs->name), "", False);
  398. /* Clear Label Type/Position */
  399. prop_options_set_value(&(pcs->label_type), (XtPointer)AB_LABEL_STRING, False);
  400. prop_options_set_value(&(pcs->label_pos), (XtPointer)AB_CP_WEST, False);
  401. /* Clear Label */
  402. ui_set_label_string(pcs->label.label, "Label:");
  403. prop_field_set_value(&(pcs->label), "", False);
  404. /* Clear Read Only */
  405. prop_radiobox_set_value(&(pcs->combobox_type), (XtPointer)True, False);
  406. /* Clear Position */
  407. prop_geomfield_clear(&(pcs->pos), GEOM_X);
  408. prop_geomfield_clear(&(pcs->pos), GEOM_Y);
  409. /* Clear Width */
  410. prop_radiobox_set_value(&(pcs->wth_policy), (XtPointer)SIZE_OF_CONTENTS_KEY, False);
  411. prop_geomfield_clear(&(pcs->wth), GEOM_WIDTH);
  412. /* Clear Initial State */
  413. prop_checkbox_set_value(&(pcs->init_state), AB_STATE_VISIBLE, True, False);
  414. prop_checkbox_set_value(&(pcs->init_state), AB_STATE_ACTIVE, True, False);
  415. /* Clear Color */
  416. prop_colorfield_set_value(&(pcs->bg_color), "", False);
  417. prop_colorfield_set_value(&(pcs->fg_color), "", False);
  418. /* Clear Items */
  419. prop_item_editor_clear(&(pcs->items));
  420. pcs->current_obj = NULL;
  421. turnoff_changebars(type);
  422. return OK;
  423. }
  424. static int
  425. combo_box_prop_load(
  426. ABObjPtr obj,
  427. AB_PROP_TYPE type,
  428. unsigned long loadkey
  429. )
  430. {
  431. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  432. BOOL editable;
  433. BOOL load_all = (loadkey & LoadAll);
  434. if (obj == NULL)
  435. {
  436. if (pcs->current_obj != NULL)
  437. obj = pcs->current_obj;
  438. else
  439. return ERROR;
  440. }
  441. else if (!obj_is_combo_box(obj))
  442. return ERROR;
  443. else
  444. pcs->current_obj = obj;
  445. /* Load Name */
  446. if (load_all || loadkey & LoadName)
  447. prop_field_set_value(&(pcs->name), obj_get_name(obj), False);
  448. if (load_all)
  449. {
  450. /* Load Label Type/Position */
  451. prop_options_set_value(&(pcs->label_type), (XtPointer)obj->label_type, False);
  452. prop_options_set_value(&(pcs->label_pos), (XtPointer)obj_get_label_position(obj), False);
  453. /* Load Label */
  454. prop_setup_label_field(&(pcs->label), NULL,
  455. obj->label_type, obj_get_label(obj), AB_LINE_UNDEF);
  456. /* Load Read Only */
  457. prop_radiobox_set_value(&(pcs->combobox_type),
  458. (XtPointer)(intptr_t) obj_get_read_only(obj), False);
  459. /* Load Initial State */
  460. prop_checkbox_set_value(&(pcs->init_state), AB_STATE_VISIBLE,
  461. obj_is_initially_visible(obj), False);
  462. prop_checkbox_set_value(&(pcs->init_state), AB_STATE_ACTIVE,
  463. obj_is_initially_active(obj), False);
  464. /* Load Color */
  465. prop_colorfield_set_value(&(pcs->bg_color), obj_get_bg_color(obj), False);
  466. prop_colorfield_set_value(&(pcs->fg_color), obj_get_fg_color(obj), False);
  467. /* Load Items */
  468. prop_item_editor_load(&(pcs->items), obj);
  469. turnoff_changebars(type);
  470. }
  471. /* Load Position */
  472. if (load_all || loadkey & LoadPosition)
  473. prop_load_obj_position(obj, &(pcs->pos));
  474. /* Load Width */
  475. if (load_all || loadkey & LoadSize)
  476. {
  477. editable = abobj_width_resizable(obj);
  478. prop_radiobox_set_value(&(pcs->wth_policy),
  479. editable? (XtPointer)SIZE_FIXED_KEY :
  480. (XtPointer)SIZE_OF_CONTENTS_KEY, False);
  481. ui_set_active(pcs->wth.w_field, editable);
  482. ui_set_active(pcs->wth.w_label, editable);
  483. prop_geomfield_set_value(&(pcs->wth), GEOM_WIDTH,
  484. abobj_get_comp_width(obj), False);
  485. }
  486. return OK;
  487. }
  488. int
  489. combo_box_prop_apply(
  490. AB_PROP_TYPE type
  491. )
  492. {
  493. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  494. STRING value;
  495. int width_policy, new_w;
  496. BOOL size_chg = False;
  497. BOOL reset_bg = False;
  498. BOOL reset_fg = False;
  499. if (!verify_props(type))
  500. return ERROR;
  501. if (prop_changed(pcs->name.changebar))
  502. {
  503. value = prop_field_get_value(&(pcs->name));
  504. abobj_set_name(pcs->current_obj, value);
  505. util_free(value);
  506. }
  507. if (prop_changed(pcs->label.changebar) ||
  508. prop_changed(pcs->label_type.changebar))
  509. {
  510. value = prop_field_get_value(&(pcs->label));
  511. abobj_set_label(pcs->current_obj,
  512. (AB_LABEL_TYPE)prop_options_get_value(&(pcs->label_type)),
  513. value);
  514. util_free(value);
  515. abobj_set_label_position(pcs->current_obj,
  516. (AB_COMPASS_POINT)prop_options_get_value(&(pcs->label_pos)));
  517. size_chg = True;
  518. }
  519. if (prop_changed(pcs->combobox_type.changebar))
  520. {
  521. abobj_set_read_only(pcs->current_obj,
  522. (BOOL)prop_radiobox_get_value(&(pcs->combobox_type)));
  523. }
  524. if (prop_changed(pcs->pos.changebar))
  525. {
  526. if (abobj_is_movable(pcs->current_obj))
  527. abobj_set_xy(pcs->current_obj,
  528. prop_geomfield_get_value(&(pcs->pos), GEOM_X),
  529. prop_geomfield_get_value(&(pcs->pos), GEOM_Y));
  530. }
  531. if (prop_changed(pcs->wth_policy.changebar))
  532. {
  533. width_policy = prop_radiobox_get_value(&(pcs->wth_policy));
  534. abobj_set_size_policy(pcs->current_obj, width_policy == SIZE_FIXED_KEY);
  535. if (width_policy == SIZE_FIXED_KEY)
  536. {
  537. new_w = prop_geomfield_get_value(&(pcs->wth), GEOM_WIDTH);
  538. abobj_set_pixel_width(pcs->current_obj, new_w, 0);
  539. }
  540. size_chg = True;
  541. }
  542. if (prop_changed(pcs->init_state.changebar))
  543. {
  544. abobj_set_visible(pcs->current_obj,
  545. prop_checkbox_get_value(&(pcs->init_state), AB_STATE_VISIBLE));
  546. abobj_set_active(pcs->current_obj,
  547. prop_checkbox_get_value(&(pcs->init_state), AB_STATE_ACTIVE));
  548. }
  549. if (prop_changed(pcs->fg_color.changebar))
  550. {
  551. value = prop_colorfield_get_value(&(pcs->fg_color));
  552. abobj_set_foreground_color(pcs->current_obj, value);
  553. if (util_strempty(value))
  554. reset_fg = True;
  555. util_free(value);
  556. prop_colorfield_set_value(&(pcs->fg_color), obj_get_fg_color(pcs->current_obj),
  557. False);
  558. }
  559. if (prop_changed(pcs->bg_color.changebar))
  560. {
  561. value = prop_colorfield_get_value(&(pcs->bg_color));
  562. abobj_set_background_color(pcs->current_obj, value);
  563. if (util_strempty(value))
  564. reset_bg = True;
  565. util_free(value);
  566. prop_colorfield_set_value(&(pcs->bg_color), obj_get_bg_color(pcs->current_obj),
  567. False);
  568. }
  569. if (prop_changed(pcs->items.changebar))
  570. {
  571. prop_item_change(&(pcs->items), False);
  572. prop_item_editor_apply(&(pcs->items));
  573. size_chg = True;
  574. }
  575. abobj_tree_instantiate_changes(pcs->current_obj);
  576. if (reset_bg || reset_fg) /* Set back to No Color */
  577. abobj_reset_colors(pcs->current_obj, reset_bg, reset_fg);
  578. if (size_chg)
  579. abobj_force_dang_form_resize(pcs->current_obj);
  580. turnoff_changebars(type);
  581. return OK;
  582. }
  583. static BOOL
  584. combo_box_prop_pending(
  585. AB_PROP_TYPE type
  586. )
  587. {
  588. return(prop_changebars_pending(prop_combobox_settings_rec[type].prop_sheet));
  589. }
  590. static BOOL
  591. verify_props(
  592. AB_PROP_TYPE type
  593. )
  594. {
  595. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  596. if (prop_changed(pcs->name.changebar) && !prop_name_ok(pcs->current_obj,
  597. pcs->name.field))
  598. return False;
  599. if ((prop_changed(pcs->label_type.changebar) || prop_changed(pcs->label.changebar)) &&
  600. prop_options_get_value(&(pcs->label_type)) == (XtPointer)AB_LABEL_GLYPH &&
  601. !prop_graphic_filename_ok(pcs->label.field, False))
  602. return False;
  603. if (prop_changed(pcs->pos.changebar) &&
  604. (!prop_number_ok(pcs->pos.x_field, (STRING)XFieldStr, -SHRT_MAX, SHRT_MAX) ||
  605. !prop_number_ok(pcs->pos.y_field, (STRING)YFieldStr, -SHRT_MAX, SHRT_MAX)))
  606. return False;
  607. if (prop_changed(pcs->wth.changebar) &&
  608. !prop_number_ok(pcs->wth.w_field, (STRING)WFieldStr, 1, SHRT_MAX))
  609. return False;
  610. if (prop_changed(pcs->fg_color.changebar) && !prop_color_ok(pcs->fg_color.field))
  611. return False;
  612. if (prop_changed(pcs->bg_color.changebar) && !prop_color_ok(pcs->bg_color.field))
  613. return False;
  614. return True;
  615. }
  616. static void
  617. turnoff_changebars(
  618. AB_PROP_TYPE type
  619. )
  620. {
  621. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  622. prop_set_changebar(pcs->name.changebar, PROP_CB_OFF);
  623. prop_set_changebar(pcs->combobox_type.changebar, PROP_CB_OFF);
  624. prop_set_changebar(pcs->pos.changebar, PROP_CB_OFF);
  625. prop_set_changebar(pcs->wth_policy.changebar, PROP_CB_OFF);
  626. prop_set_changebar(pcs->label_type.changebar, PROP_CB_OFF);
  627. prop_set_changebar(pcs->label.changebar, PROP_CB_OFF);
  628. prop_set_changebar(pcs->init_state.changebar, PROP_CB_OFF);
  629. prop_set_changebar(pcs->bg_color.changebar, PROP_CB_OFF);
  630. prop_set_changebar(pcs->fg_color.changebar, PROP_CB_OFF);
  631. prop_set_changebar(pcs->items.changebar, PROP_CB_OFF);
  632. prop_changebars_cleared(pcs->prop_sheet);
  633. }
  634. static int
  635. combobox_install_obj_destroy_CB(void)
  636. {
  637. static BOOL callback_installed = False;
  638. if (callback_installed)
  639. return 0;
  640. obj_add_destroy_callback(combobox_obj_destroy_CB, "ComboBox Props");
  641. return 0;
  642. }
  643. static int
  644. combobox_obj_destroy_CB(ObjEvDestroyInfo destroyInfo)
  645. {
  646. int i;
  647. ABObj doomedObj = destroyInfo->obj;
  648. PropComboboxSettingsRec *pcs;
  649. if (!obj_is_combo_box_item(doomedObj))
  650. return 0;
  651. for (i = 0; i < AB_PROP_TYPE_NUM_VALUES; ++i)
  652. {
  653. pcs = &(prop_combobox_settings_rec[i]);
  654. if (pcs->current_obj == doomedObj)
  655. pcs->current_obj = NULL;
  656. if (pcs->items.current_item == doomedObj)
  657. pcs->items.current_item = NULL;
  658. if (pcs->items.clipboard_item == doomedObj)
  659. pcs->items.clipboard_item = NULL;
  660. }
  661. return 0;
  662. }
  663. static void
  664. wth_policyCB(
  665. Widget w,
  666. XtPointer clientdata,
  667. XmToggleButtonCallbackStruct *state
  668. )
  669. {
  670. AB_PROP_TYPE type = (AB_PROP_TYPE)clientdata;
  671. PropComboboxSettingsRec *pcs = &(prop_combobox_settings_rec[type]);
  672. XtArgVal value;
  673. /* Width field should ONLY be editable if Size Policy
  674. * is "Fixed"
  675. */
  676. if (state->set)
  677. {
  678. XtVaGetValues(w, XmNuserData, &value, NULL);
  679. ui_field_set_editable(pcs->wth.w_field, value == SIZE_FIXED_KEY);
  680. }
  681. }