comparison lwlib/lwlib-Xm.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 41dbb7a9d5f2
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
58 #include <Xm/RowColumn.h> 58 #include <Xm/RowColumn.h>
59 #include <Xm/ScrolledW.h> 59 #include <Xm/ScrolledW.h>
60 #include <Xm/Separator.h> 60 #include <Xm/Separator.h>
61 #include <Xm/DialogS.h> 61 #include <Xm/DialogS.h>
62 #include <Xm/Form.h> 62 #include <Xm/Form.h>
63 #ifdef LWLIB_WIDGETS_MOTIF
63 #include <Xm/Scale.h> 64 #include <Xm/Scale.h>
64 #if XmVERSION > 1 65 #if XmVERSION > 1
65 #include <Xm/ComboBox.h> 66 #include <Xm/ComboBoxP.h>
67 #endif
66 #endif 68 #endif
67 69
68 #ifdef LWLIB_MENUBARS_MOTIF 70 #ifdef LWLIB_MENUBARS_MOTIF
69 static void xm_pull_down_callback (Widget, XtPointer, XtPointer); 71 static void xm_pull_down_callback (Widget, XtPointer, XtPointer);
70 #endif 72 #endif
71 static void xm_internal_update_other_instances (Widget, XtPointer, 73 static void xm_internal_update_other_instances (Widget, XtPointer,
72 XtPointer); 74 XtPointer);
73 static void xm_pop_down_callback (Widget, XtPointer, XtPointer); 75 static void xm_pop_down_callback (Widget, XtPointer, XtPointer);
74 static void xm_generic_callback (Widget, XtPointer, XtPointer); 76 static void xm_generic_callback (Widget, XtPointer, XtPointer);
75 #ifdef LWLIB_DIALOGS_MOTIF 77 static void mark_dead_instance_destroyed (Widget widget, XtPointer closure,
78 XtPointer call_data);
79 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
76 static void xm_nosel_callback (Widget, XtPointer, XtPointer); 80 static void xm_nosel_callback (Widget, XtPointer, XtPointer);
77 #endif 81 #endif
78 #ifdef LWLIB_SCROLLBARS_MOTIF 82 #ifdef LWLIB_SCROLLBARS_MOTIF
79 static void xm_scrollbar_callback (Widget, XtPointer, XtPointer); 83 static void xm_scrollbar_callback (Widget, XtPointer, XtPointer);
80 #endif 84 #endif
169 XtGetSubresources (widget, (XtPointer)&result, name, 173 XtGetSubresources (widget, (XtPointer)&result, name,
170 name, &resource, 1, NULL, 0); 174 name, &resource, 1, NULL, 0);
171 return result; 175 return result;
172 } 176 }
173 177
174 #ifdef LWLIB_MENUBARS_MOTIF
175
176 static void
177 destroy_all_children (Widget widget)
178 {
179 Widget* children;
180 unsigned int number;
181 int i;
182
183 children = XtCompositeChildren (widget, &number);
184 if (children)
185 {
186 /* Unmanage all children and destroy them. They will only be
187 * really destroyed when we get out of DispatchEvent. */
188 for (i = 0; i < number; i++)
189 {
190 Widget child = children [i];
191 if (!child->core.being_destroyed)
192 {
193 XtUnmanageChild (child);
194 XtDestroyWidget (child);
195 }
196 }
197 XtFree ((char *) children);
198 }
199 }
200
201 #endif /* LWLIB_MENUBARS_MOTIF */
202
203 178
204 179
205 #ifdef LWLIB_DIALOGS_MOTIF 180 #ifdef LWLIB_DIALOGS_MOTIF
206 181
207 static Boolean 182 static Boolean
219 return False; 194 return False;
220 } 195 }
221 196
222 #endif /* LWLIB_DIALOGS_MOTIF */ 197 #endif /* LWLIB_DIALOGS_MOTIF */
223 198
224 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) 199 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
225 200
226 /* update the label of anything subclass of a label */ 201 /* update the label of anything subclass of a label */
227 static void 202 static void
228 xm_update_label (widget_instance* instance, Widget widget, widget_value* val) 203 xm_update_label (widget_instance* instance, Widget widget, widget_value* val)
229 { 204 {
231 XmString key_string = NULL; 206 XmString key_string = NULL;
232 XmString val_string = NULL; 207 XmString val_string = NULL;
233 XmString name_string = NULL; 208 XmString name_string = NULL;
234 Arg al [20]; 209 Arg al [20];
235 int ac = 0; 210 int ac = 0;
211 int type;
212
213 /* Don't clobber pixmap types. */
214 XtSetArg (al [0], XmNlabelType, &type);
215 XtGetValues (widget, al, 1);
216
217 if (type == XmPIXMAP)
218 return;
236 219
237 if (val->value) 220 if (val->value)
238 { 221 {
239 #ifdef LWLIB_DIALOGS_MOTIF 222 #ifdef LWLIB_DIALOGS_MOTIF
240 /* 223 /*
260 { 243 {
261 char *value_name = NULL; 244 char *value_name = NULL;
262 char *res_name = NULL; 245 char *res_name = NULL;
263 246
264 res_name = resource_string (widget, val->name); 247 res_name = resource_string (widget, val->name);
248 /* Concatenating the value with itself seems just plain daft. */
265 if (!res_name) 249 if (!res_name)
266 res_name = val->name; 250 {
267 251 built_string =
268 name_string = 252 XmStringCreateLtoR (val->value, XmSTRING_DEFAULT_CHARSET);
269 XmStringCreateLtoR (res_name, XmSTRING_DEFAULT_CHARSET); 253 }
270 254 else
271 value_name = XtMalloc (strlen (val->value) + 2); 255 {
272 *value_name = 0; 256 name_string =
273 strcat (value_name, " "); 257 XmStringCreateLtoR (res_name, XmSTRING_DEFAULT_CHARSET);
274 strcat (value_name, val->value); 258
275 259 value_name = XtMalloc (strlen (val->value) + 2);
276 val_string = 260 *value_name = 0;
277 XmStringCreateLtoR (value_name, XmSTRING_DEFAULT_CHARSET); 261 strcat (value_name, " ");
278 262 strcat (value_name, val->value);
279 built_string = 263
280 XmStringConcat (name_string, val_string); 264 val_string =
281 265 XmStringCreateLtoR (value_name, XmSTRING_DEFAULT_CHARSET);
282 XtFree (value_name); 266
267 built_string =
268 XmStringConcat (name_string, val_string);
269
270 XtFree (value_name);
271 }
283 } 272 }
284 273
285 XtSetArg (al [ac], XmNlabelString, built_string); ac++; 274 XtSetArg (al [ac], XmNlabelString, built_string); ac++;
286 XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++; 275 XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++;
287 } 276 }
301 if (key_string) 290 if (key_string)
302 XmStringFree (key_string); 291 XmStringFree (key_string);
303 292
304 if (name_string) 293 if (name_string)
305 XmStringFree (name_string); 294 XmStringFree (name_string);
295
296 if (val_string)
297 XmStringFree (val_string);
306 } 298 }
307 299
308 #endif /* defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) */ 300 #endif /* defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) */
309 301
310 /* update of list */ 302 /* update of list */
378 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback); 370 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
379 XtAddCallback (widget, XmNvalueChangedCallback, xm_generic_callback, 371 XtAddCallback (widget, XmNvalueChangedCallback, xm_generic_callback,
380 instance); 372 instance);
381 XtSetArg (al [0], XmNset, val->selected); 373 XtSetArg (al [0], XmNset, val->selected);
382 XtSetArg (al [1], XmNalignment, XmALIGNMENT_BEGINNING); 374 XtSetArg (al [1], XmNalignment, XmALIGNMENT_BEGINNING);
383 XtSetValues (widget, al, 2); 375 XtSetValues (widget, al, 1);
384 } 376 }
385 377
386 static void 378 static void
387 xm_update_radiobox (widget_instance* instance, Widget widget, 379 xm_update_radiobox (widget_instance* instance, Widget widget,
388 widget_value* val) 380 widget_value* val)
422 XtSetArg (al [0], XmNset, True); 414 XtSetArg (al [0], XmNset, True);
423 XtSetValues (toggle, al, 1); 415 XtSetValues (toggle, al, 1);
424 } 416 }
425 } 417 }
426 } 418 }
419
420 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
421 /* update of combo box */
422 static void
423 xm_update_combo_box (widget_instance* instance, Widget widget, widget_value* val)
424 {
425 widget_value* cur;
426 int i;
427 XtRemoveAllCallbacks (widget, XmNselectionCallback);
428 XtAddCallback (widget, XmNselectionCallback, xm_generic_callback,
429 instance);
430 for (cur = val->contents, i = 0; cur; cur = cur->next)
431 if (cur->value)
432 {
433 XmString xmstr = XmStringCreate (cur->value, XmSTRING_DEFAULT_CHARSET);
434 i += 1;
435 XmListAddItem (CB_List (widget), xmstr, 0);
436 if (cur->selected)
437 XmListSelectPos (CB_List (widget), i, False);
438 XmStringFree (xmstr);
439 }
440 }
441 #endif
427 442
428 #ifdef LWLIB_MENUBARS_MOTIF 443 #ifdef LWLIB_MENUBARS_MOTIF
429 444
430 /* update a popup menu, pulldown menu or a menubar */ 445 /* update a popup menu, pulldown menu or a menubar */
431 static void 446 static void
765 void 780 void
766 xm_update_one_widget (widget_instance* instance, Widget widget, 781 xm_update_one_widget (widget_instance* instance, Widget widget,
767 widget_value* val, Boolean deep_p) 782 widget_value* val, Boolean deep_p)
768 { 783 {
769 WidgetClass class; 784 WidgetClass class;
770 Arg al [2]; 785 Arg al [20];
786 int ac = 0;
771 787
772 /* Mark as not edited */ 788 /* Mark as not edited */
773 val->edited = False; 789 val->edited = False;
774 790
775 /* Common to all widget types */ 791 /* Common to all widget types */
776 XtSetArg (al [0], XmNsensitive, val->enabled); 792 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
777 XtSetArg (al [1], XmNuserData, val->call_data); 793 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
778 XtSetValues (widget, al, 2); 794 lw_add_value_args_to_args (val, al, &ac);
779 795
780 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) 796 XtSetValues (widget, al, ac);
797
798 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
781 /* Common to all label like widgets */ 799 /* Common to all label like widgets */
782 if (XtIsSubclass (widget, xmLabelWidgetClass)) 800 if (XtIsSubclass (widget, xmLabelWidgetClass))
783 xm_update_label (instance, widget, val); 801 xm_update_label (instance, widget, val);
784 #endif /* defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) */ 802 #endif
785
786 class = XtClass (widget); 803 class = XtClass (widget);
787 /* Class specific things */ 804 /* Class specific things */
788 if (class == xmPushButtonWidgetClass || 805 if (class == xmPushButtonWidgetClass ||
789 class == xmArrowButtonWidgetClass) 806 class == xmArrowButtonWidgetClass)
790 { 807 {
825 } 842 }
826 else if (class == xmListWidgetClass) 843 else if (class == xmListWidgetClass)
827 { 844 {
828 xm_update_list (instance, widget, val); 845 xm_update_list (instance, widget, val);
829 } 846 }
847 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
848 else if (class == xmComboBoxWidgetClass)
849 {
850 xm_update_combo_box (instance, widget, val);
851 }
852 #endif
830 #ifdef LWLIB_SCROLLBARS_MOTIF 853 #ifdef LWLIB_SCROLLBARS_MOTIF
831 else if (class == xmScrollBarWidgetClass) 854 else if (class == xmScrollBarWidgetClass)
832 { 855 {
833 xm_update_scrollbar (instance, widget, val); 856 xm_update_scrollbar (instance, widget, val);
834 } 857 }
901 } 924 }
902 } 925 }
903 val->edited = True; 926 val->edited = True;
904 } 927 }
905 } 928 }
906 else if (class == xmListWidgetClass) 929 else if (class == xmListWidgetClass
930 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
931 || class == xmComboBoxWidgetClass
932 #endif
933 )
907 { 934 {
908 int pos_cnt; 935 int pos_cnt;
909 int* pos_list; 936 int* pos_list;
910 if (XmListGetSelectedPos (widget, &pos_list, &pos_cnt)) 937 Widget list = widget;
938 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
939 if (class == xmComboBoxWidgetClass)
940 list = CB_List (widget);
941 #endif
942 if (XmListGetSelectedPos (list, &pos_list, &pos_cnt))
911 { 943 {
912 int i; 944 int i;
913 widget_value* cur; 945 widget_value* cur;
914 for (cur = val->contents, i = 0; cur; cur = cur->next) 946 for (cur = val->contents, i = 0; cur; cur = cur->next)
915 if (cur->value) 947 if (cur->value)
1314 } 1346 }
1315 return NULL; 1347 return NULL;
1316 } 1348 }
1317 1349
1318 static void 1350 static void
1319 mark_dead_instance_destroyed (Widget widget, XtPointer closure,
1320 XtPointer call_data)
1321 {
1322 destroyed_instance* instance = (destroyed_instance*)closure;
1323 instance->widget = NULL;
1324 }
1325
1326 static void
1327 recenter_widget (Widget widget) 1351 recenter_widget (Widget widget)
1328 { 1352 {
1329 Widget parent = XtParent (widget); 1353 Widget parent = XtParent (widget);
1330 Screen* screen = XtScreen (widget); 1354 Screen* screen = XtScreen (widget);
1331 Dimension screen_width = WidthOfScreen (screen); 1355 Dimension screen_width = WidthOfScreen (screen);
1564 return make_scrollbar (instance, 0); 1588 return make_scrollbar (instance, 0);
1565 } 1589 }
1566 1590
1567 #endif /* LWLIB_SCROLLBARS_MOTIF */ 1591 #endif /* LWLIB_SCROLLBARS_MOTIF */
1568 1592
1593 #ifdef LWLIB_WIDGETS_MOTIF
1569 /* glyph widgets */ 1594 /* glyph widgets */
1570 static Widget 1595 static Widget
1571 make_button (widget_instance *instance) 1596 xm_create_button (widget_instance *instance)
1572 { 1597 {
1573 Arg al[20]; 1598 Arg al[20];
1574 int ac = 0; 1599 int ac = 0;
1575 Widget button = 0; 1600 Widget button = 0;
1576 widget_value* val = instance->info->val; 1601 widget_value* val = instance->info->val;
1613 1638
1614 return button; 1639 return button;
1615 } 1640 }
1616 1641
1617 static Widget 1642 static Widget
1618 make_progress (widget_instance *instance) 1643 xm_create_progress (widget_instance *instance)
1619 { 1644 {
1620 Arg al[20]; 1645 Arg al[20];
1621 int ac = 0; 1646 int ac = 0;
1622 Widget scale = 0; 1647 Widget scale = 0;
1623 widget_value* val = instance->info->val; 1648 widget_value* val = instance->info->val;
1624 1649
1625 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++; 1650 if (!val->call_data)
1651 {
1652 XtSetArg (al [ac], XmNsensitive, False); ac++;
1653 }
1654 else
1655 {
1656 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
1657 }
1626 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; 1658 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
1627 XtSetArg (al [ac], XmNuserData, val->call_data); ac++; 1659 XtSetArg (al [ac], XmNuserData, val->call_data); ac++;
1628 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++; 1660 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
1629 XtSetArg (al [ac], XmNorientation, XmHORIZONTAL); ac++; 1661 XtSetArg (al [ac], XmNorientation, XmHORIZONTAL); ac++;
1630 /* The highlight doesn't appear to be dynamically set which makes it 1662 /* The highlight doesn't appear to be dynamically set which makes it
1631 look ugly. I think this may be a LessTif bug but for now we just 1663 look ugly. I think this may be a LessTif bug but for now we just
1632 get rid of it. */ 1664 get rid of it. */
1633 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++; 1665 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
1634 if (!val->call_data)
1635 XtSetArg (al [ac], XmNsensitive, False); ac++;
1636
1637 /* add any args the user supplied for creation time */ 1666 /* add any args the user supplied for creation time */
1638 lw_add_value_args_to_args (val, al, &ac); 1667 lw_add_value_args_to_args (val, al, &ac);
1639 1668
1640 scale = XmCreateScale (instance->parent, val->name, al, ac); 1669 scale = XmCreateScale (instance->parent, val->name, al, ac);
1641 if (val->call_data) 1670 if (val->call_data)
1646 1675
1647 return scale; 1676 return scale;
1648 } 1677 }
1649 1678
1650 static Widget 1679 static Widget
1651 make_text_field (widget_instance *instance) 1680 xm_create_text_field (widget_instance *instance)
1652 { 1681 {
1653 Arg al[20]; 1682 Arg al[20];
1654 int ac = 0; 1683 int ac = 0;
1655 Widget text = 0; 1684 Widget text = 0;
1656 widget_value* val = instance->info->val; 1685 widget_value* val = instance->info->val;
1675 XtManageChild (text); 1704 XtManageChild (text);
1676 1705
1677 return text; 1706 return text;
1678 } 1707 }
1679 1708
1709 static Widget
1710 xm_create_label_field (widget_instance *instance)
1711 {
1712 return xm_create_label (instance->parent, instance->info->val);
1713 }
1714
1715 Widget
1716 xm_create_label (Widget parent, widget_value* val)
1717 {
1718 Arg al[20];
1719 int ac = 0;
1720 Widget label = 0;
1721
1722 XtSetArg (al [ac], XmNsensitive, val->enabled); ac++;
1723 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
1724 XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++;
1725 /* The highlight doesn't appear to be dynamically set which makes it
1726 look ugly. I think this may be a LessTif bug but for now we just
1727 get rid of it. */
1728 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
1729
1730 /* add any args the user supplied for creation time */
1731 lw_add_value_args_to_args (val, al, &ac);
1732
1733 label = XmCreateLabel (parent, val->name, al, ac);
1734
1735 XtManageChild (label);
1736
1737 /* Do it again for arguments that have no effect until the widget is realized. */
1738 ac = 0;
1739 lw_add_value_args_to_args (val, al, &ac);
1740 XtSetValues (label, al, ac);
1741
1742 return label;
1743 }
1744
1680 #if XmVERSION > 1 1745 #if XmVERSION > 1
1681 static Widget 1746 static Widget
1682 make_combo_box (widget_instance *instance) 1747 xm_create_combo_box (widget_instance *instance)
1683 { 1748 {
1684 Arg al[20]; 1749 Arg al[20];
1685 int ac = 0; 1750 int ac = 0;
1686 Widget combo = 0; 1751 Widget combo = 0;
1687 widget_value* val = instance->info->val; 1752 widget_value* val = instance->info->val;
1696 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++; 1761 XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++;
1697 1762
1698 /* add any args the user supplied for creation time */ 1763 /* add any args the user supplied for creation time */
1699 lw_add_value_args_to_args (val, al, &ac); 1764 lw_add_value_args_to_args (val, al, &ac);
1700 1765
1701 combo = XmCreateComboBox (instance->parent, val->name, al, ac); 1766 combo = XmCreateDropDownComboBox (instance->parent, val->name, al, ac);
1702 if (val->call_data) 1767 if (val->call_data)
1703 XtAddCallback (combo, XmNselectionCallback, xm_generic_callback, 1768 XtAddCallback (combo, XmNselectionCallback, xm_generic_callback,
1704 (XtPointer)instance); 1769 (XtPointer)instance);
1705 1770
1706 XtManageChild (combo); 1771 XtManageChild (combo);
1707 1772
1708 return combo; 1773 return combo;
1709 } 1774 }
1710 #endif 1775 #endif
1776 #endif /* LWLIB_WIDGETS_MOTIF */
1711 1777
1712 1778
1713 /* Table of functions to create widgets */ 1779 /* Table of functions to create widgets */
1714 1780
1715 widget_creation_entry 1781 widget_creation_entry
1721 #endif 1787 #endif
1722 #ifdef LWLIB_SCROLLBARS_MOTIF 1788 #ifdef LWLIB_SCROLLBARS_MOTIF
1723 {"vertical-scrollbar", make_vertical_scrollbar}, 1789 {"vertical-scrollbar", make_vertical_scrollbar},
1724 {"horizontal-scrollbar", make_horizontal_scrollbar}, 1790 {"horizontal-scrollbar", make_horizontal_scrollbar},
1725 #endif 1791 #endif
1726 {"button", make_button}, 1792 #ifdef LWLIB_WIDGETS_MOTIF
1727 {"progress", make_progress}, 1793 {"button", xm_create_button},
1728 {"text-field", make_text_field}, 1794 {"progress", xm_create_progress},
1795 {"text-field", xm_create_text_field},
1796 {"label", xm_create_label_field},
1729 #if XmVERSION > 1 1797 #if XmVERSION > 1
1730 {"combo-box", make_combo_box}, 1798 {"combo-box", xm_create_combo_box},
1799 #endif
1731 #endif 1800 #endif
1732 {NULL, NULL} 1801 {NULL, NULL}
1733 }; 1802 };
1734 1803
1735 /* Destruction of instances */ 1804 /* Destruction of instances */
1736 void 1805 void
1737 xm_destroy_instance (widget_instance* instance) 1806 xm_destroy_instance (widget_instance* instance)
1738 { 1807 {
1739 #ifdef LWLIB_DIALOGS_MOTIF 1808 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
1740 /* It appears that this is used only for dialog boxes. */ 1809 /* It appears that this is used only for dialog boxes. */
1741 Widget widget = instance->widget; 1810 Widget widget = instance->widget;
1742 /* recycle the dialog boxes */ 1811 /* recycle the dialog boxes */
1743 /* Disable the recycling until we can find a way to have the dialog box 1812 /* Disable the recycling until we can find a way to have the dialog box
1744 get reasonable layout after we modify its contents. */ 1813 get reasonable layout after we modify its contents. */
1765 XtRemoveCallback (instance->widget, XtNdestroyCallback, 1834 XtRemoveCallback (instance->widget, XtNdestroyCallback,
1766 xm_nosel_callback, (XtPointer)instance); 1835 xm_nosel_callback, (XtPointer)instance);
1767 1836
1768 XtDestroyWidget (instance->widget); 1837 XtDestroyWidget (instance->widget);
1769 } 1838 }
1770 #endif /* LWLIB_DIALOGS_MOTIF */ 1839 #endif /* LWLIB_DIALOGS_MOTIF || LWLIB_WIDGETS_MOTIF */
1771 } 1840 }
1772 1841
1773 /* popup utility */ 1842 /* popup utility */
1774 #ifdef LWLIB_MENUBARS_MOTIF 1843 #ifdef LWLIB_MENUBARS_MOTIF
1775 1844
1918 } 1987 }
1919 1988
1920 static void 1989 static void
1921 xm_generic_callback (Widget widget, XtPointer closure, XtPointer call_data) 1990 xm_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
1922 { 1991 {
1923 #if (defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_DIALOGS_MOTIF)) 1992 #if (defined (LWLIB_MENUBARS_MOTIF) || defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF))
1924 /* We want the selected status to change only when we decide it 1993 /* We want the selected status to change only when we decide it
1925 should change. Yuck but correct. */ 1994 should change. Yuck but correct. */
1926 if (XtClass (widget) == xmToggleButtonWidgetClass 1995 if (XtClass (widget) == xmToggleButtonWidgetClass
1927 || XtClass (widget) == xmToggleButtonGadgetClass) 1996 || XtClass (widget) == xmToggleButtonGadgetClass)
1928 { 1997 {
1943 static void 2012 static void
1944 xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data) 2013 xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
1945 { 2014 {
1946 do_call (widget, closure, post_activate); 2015 do_call (widget, closure, post_activate);
1947 } 2016 }
1948
1949 #ifdef LWLIB_DIALOGS_MOTIF
1950
1951 static void
1952 xm_nosel_callback (Widget widget, XtPointer closure, XtPointer call_data)
1953 {
1954 /* This callback is only called when a dialog box is dismissed with the wm's
1955 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed
1956 in that case, not just unmapped, so that it releases its keyboard grabs.
1957 But there are problems with running our callbacks while the widget is in
1958 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP
1959 instead of XmDESTROY and then destroy it ourself after having run the
1960 callback.
1961 */
1962 do_call (widget, closure, no_selection);
1963 XtDestroyWidget (widget);
1964 }
1965
1966 #endif
1967 2017
1968 #ifdef LWLIB_MENUBARS_MOTIF 2018 #ifdef LWLIB_MENUBARS_MOTIF
1969 2019
1970 static void 2020 static void
1971 xm_pull_down_callback (Widget widget, XtPointer closure, XtPointer call_data) 2021 xm_pull_down_callback (Widget widget, XtPointer closure, XtPointer call_data)
2071 if (instance->info->pre_activate_cb) 2121 if (instance->info->pre_activate_cb)
2072 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data); 2122 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
2073 } 2123 }
2074 #endif /* LWLIB_SCROLLBARS_MOTIF */ 2124 #endif /* LWLIB_SCROLLBARS_MOTIF */
2075 2125
2126 #if defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_WIDGETS_MOTIF)
2127 static void
2128 mark_dead_instance_destroyed (Widget widget, XtPointer closure,
2129 XtPointer call_data)
2130 {
2131 destroyed_instance* instance = (destroyed_instance*)closure;
2132 instance->widget = NULL;
2133 }
2134
2135 static void
2136 xm_nosel_callback (Widget widget, XtPointer closure, XtPointer call_data)
2137 {
2138 /* This callback is only called when a dialog box is dismissed with the wm's
2139 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed
2140 in that case, not just unmapped, so that it releases its keyboard grabs.
2141 But there are problems with running our callbacks while the widget is in
2142 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP
2143 instead of XmDESTROY and then destroy it ourself after having run the
2144 callback.
2145 */
2146 do_call (widget, closure, no_selection);
2147 XtDestroyWidget (widget);
2148 }
2149 #endif
2150
2076 2151
2077 /* set the keyboard focus */ 2152 /* set the keyboard focus */
2078 void 2153 void
2079 xm_set_keyboard_focus (Widget parent, Widget w) 2154 xm_set_keyboard_focus (Widget parent, Widget w)
2080 { 2155 {