aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann1999-07-21 21:43:52 +0000
committerGerd Moellmann1999-07-21 21:43:52 +0000
commit968aa0ada461d3267b2f278a829abed21ed031c9 (patch)
tree53c4fb775a4f0ffc5c113603b00c7dc9ae85c8a8
parentda88f5921810efc44d46f972f8808920f6ed84e5 (diff)
downloademacs-968aa0ada461d3267b2f278a829abed21ed031c9.tar.gz
emacs-968aa0ada461d3267b2f278a829abed21ed031c9.zip
Add function prototypes.
(xm_update_label): Use val->name to look up a label string from resources. (all_dashes_p): Removed. (make_menu_in_widget): Use lw_separator_p. Set Motif separator type. (make_menu_in_widget): Set alignment of menu title after all widgets have been created. (xm_update_toggle): Add callback xm_generic_callback instead of xm_internal_update_other_instances. (make_menu_in_widget): Do help button before managing children to get it to the right place. (make_menu_in_widget): Create toggle buttons. (update_one_menu_entry): Update toggle buttons. (make_menu_in_widget): Test for menubar widgets using XmNrowColumnType.
-rw-r--r--lwlib/lwlib-Xm.c212
1 files changed, 159 insertions, 53 deletions
diff --git a/lwlib/lwlib-Xm.c b/lwlib/lwlib-Xm.c
index 7bfa1f04ccb..6b1e3bfee85 100644
--- a/lwlib/lwlib-Xm.c
+++ b/lwlib/lwlib-Xm.c
@@ -57,15 +57,13 @@ Boston, MA 02111-1307, USA. */
57#include <Xm/DialogS.h> 57#include <Xm/DialogS.h>
58#include <Xm/Form.h> 58#include <Xm/Form.h>
59 59
60static void xm_pull_down_callback (/* Widget, XtPointer, XtPointer */); 60#ifdef __STDC__
61static void xm_internal_update_other_instances (/* Widget, XtPointer, 61#define P_(X) X
62 XtPointer */); 62#else
63static void xm_generic_callback (/* Widget, XtPointer, XtPointer */); 63#define P_(X) ()
64static void xm_nosel_callback (/* Widget, XtPointer, XtPointer */); 64#endif
65static void xm_pop_down_callback (/* Widget, XtPointer, XtPointer */);
66 65
67static void xm_update_menu (/* widget_instance*, Widget, widget_value*, 66enum do_call_type { pre_activate, selection, no_selection, post_activate };
68 Boolean) */);
69 67
70 68
71 /* Structures to keep destroyed instances */ 69 /* Structures to keep destroyed instances */
@@ -79,6 +77,65 @@ typedef struct _destroyed_instance
79 struct _destroyed_instance* next; 77 struct _destroyed_instance* next;
80} destroyed_instance; 78} destroyed_instance;
81 79
80static destroyed_instance *make_destroyed_instance P_ ((char *, char *,
81 Widget, Widget,
82 Boolean));
83static void free_destroyed_instance P_ ((destroyed_instance*));
84Widget first_child P_ ((Widget));
85Boolean lw_motif_widget_p P_ ((Widget));
86static XmString resource_motif_string P_ ((Widget, char *));
87static void destroy_all_children P_ ((Widget, int));
88static void xm_update_label P_ ((widget_instance *, Widget, widget_value *));
89static void xm_update_list P_ ((widget_instance *, Widget, widget_value *));
90static void xm_update_pushbutton P_ ((widget_instance *, Widget,
91 widget_value *));
92static void xm_update_cascadebutton P_ ((widget_instance *, Widget,
93 widget_value *));
94static void xm_update_toggle P_ ((widget_instance *, Widget, widget_value *));
95static void xm_update_radiobox P_ ((widget_instance *, Widget, widget_value *));
96static void make_menu_in_widget P_ ((widget_instance *, Widget,
97 widget_value *, int));
98static void update_one_menu_entry P_ ((widget_instance *, Widget,
99 widget_value *, Boolean));
100static void xm_update_menu P_ ((widget_instance *, Widget, widget_value *,
101 Boolean));
102static void xm_update_text P_ ((widget_instance *, Widget, widget_value *));
103static void xm_update_text_field P_ ((widget_instance *, Widget,
104 widget_value *));
105void xm_update_one_value P_ ((widget_instance *, Widget, widget_value *));
106static void activate_button P_ ((Widget, XtPointer, XtPointer));
107static Widget make_dialog P_ ((char *, Widget, Boolean, char *, char *,
108 Boolean, Boolean, Boolean, int, int));
109static destroyed_instance* find_matching_instance P_ ((widget_instance*));
110static void mark_dead_instance_destroyed P_ ((Widget, XtPointer, XtPointer));
111static void recenter_widget P_ ((Widget));
112static Widget recycle_instance P_ ((destroyed_instance*));
113Widget xm_create_dialog P_ ((widget_instance*));
114static Widget make_menubar P_ ((widget_instance*));
115static void remove_grabs P_ ((Widget, XtPointer, XtPointer));
116static Widget make_popup_menu P_ ((widget_instance*));
117static Widget make_main P_ ((widget_instance*));
118void xm_destroy_instance P_ ((widget_instance*));
119void xm_popup_menu P_ ((Widget, XEvent *));
120static void set_min_dialog_size P_ ((Widget));
121static void do_call P_ ((Widget, XtPointer, enum do_call_type));
122static void xm_generic_callback P_ ((Widget, XtPointer, XtPointer));
123static void xm_nosel_callback P_ ((Widget, XtPointer, XtPointer));
124static void xm_pull_down_callback P_ ((Widget, XtPointer, XtPointer));
125static void xm_pop_down_callback P_ ((Widget, XtPointer, XtPointer));
126void xm_set_keyboard_focus P_ ((Widget, Widget));
127void xm_set_main_areas P_ ((Widget, Widget, Widget));
128static void xm_internal_update_other_instances P_ ((Widget, XtPointer,
129 XtPointer));
130
131#if 0
132void xm_update_one_widget P_ ((widget_instance *, Widget, widget_value *,
133 Boolean));
134void xm_pop_instance P_ ((widget_instance*, Boolean));
135void xm_manage_resizing P_ ((Widget, Boolean));
136#endif
137
138
82static destroyed_instance* 139static destroyed_instance*
83all_destroyed_instances = NULL; 140all_destroyed_instances = NULL;
84 141
@@ -188,7 +245,24 @@ destroy_all_children (widget, first_child_to_destroy)
188 } 245 }
189} 246}
190 247
191 /* update the label of anything subclass of a label */ 248
249/* Update the label of widget WIDGET. WIDGET must be a Label widget
250 or a subclass of Label. WIDGET_INSTANCE is unused. VAL contains
251 the value to update.
252
253 Menus:
254
255 Emacs fills VAL->name with the text to display in the menu, and
256 sets VAL->value to null. Function make_menu_in_widget creates
257 widgets with VAL->name as resource name. This works because the
258 Label widget uses its resource name for display if no
259 XmNlabelString is set.
260
261 Dialogs:
262
263 VAL->name is again set to the resource name, but VAL->value is
264 not null, and contains the label string to display. */
265
192static void 266static void
193xm_update_label (instance, widget, val) 267xm_update_label (instance, widget, val)
194 widget_instance* instance; 268 widget_instance* instance;
@@ -200,11 +274,13 @@ xm_update_label (instance, widget, val)
200 XmString key_string = 0; 274 XmString key_string = 0;
201 Arg al [256]; 275 Arg al [256];
202 int ac; 276 int ac;
203 277
204 ac = 0; 278 ac = 0;
205 279
206 if (val->value) 280 if (val->value)
207 { 281 {
282 /* A label string is specified, i.e. we are in a dialog. First
283 see if it is overridden by something from the resource file. */
208 res_string = resource_motif_string (widget, val->value); 284 res_string = resource_motif_string (widget, val->value);
209 285
210 if (res_string) 286 if (res_string)
@@ -217,6 +293,7 @@ xm_update_label (instance, widget, val)
217 XmStringCreateLtoR (val->value, XmSTRING_DEFAULT_CHARSET); 293 XmStringCreateLtoR (val->value, XmSTRING_DEFAULT_CHARSET);
218 XtSetArg (al [ac], XmNlabelString, built_string); ac++; 294 XtSetArg (al [ac], XmNlabelString, built_string); ac++;
219 } 295 }
296
220 XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++; 297 XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++;
221 } 298 }
222 299
@@ -293,7 +370,7 @@ xm_update_toggle (instance, widget, val)
293{ 370{
294 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback); 371 XtRemoveAllCallbacks (widget, XmNvalueChangedCallback);
295 XtAddCallback (widget, XmNvalueChangedCallback, 372 XtAddCallback (widget, XmNvalueChangedCallback,
296 xm_internal_update_other_instances, instance); 373 xm_generic_callback, instance);
297 XtVaSetValues (widget, XmNset, val->selected, 374 XtVaSetValues (widget, XmNset, val->selected,
298 XmNalignment, XmALIGNMENT_BEGINNING, 0); 375 XmNalignment, XmALIGNMENT_BEGINNING, 0);
299} 376}
@@ -340,17 +417,8 @@ xm_update_radiobox (instance, widget, val)
340 } 417 }
341} 418}
342 419
343 /* update a popup menu, pulldown menu or a menubar */ 420
344static Boolean 421/* update a popup menu, pulldown menu or a menubar */
345all_dashes_p (s)
346 char* s;
347{
348 char* t;
349 for (t = s; *t; t++)
350 if (*t != '-')
351 return False;
352 return True;
353}
354 422
355/* KEEP_FIRST_CHILDREN gives the number of initial children to keep. */ 423/* KEEP_FIRST_CHILDREN gives the number of initial children to keep. */
356 424
@@ -366,10 +434,12 @@ make_menu_in_widget (instance, widget, val, keep_first_children)
366 int child_index; 434 int child_index;
367 widget_value* cur; 435 widget_value* cur;
368 Widget button = 0; 436 Widget button = 0;
437 Widget title = 0;
369 Widget menu; 438 Widget menu;
370 Arg al [256]; 439 Arg al [256];
371 int ac; 440 int ac;
372 Boolean menubar_p; 441 Boolean menubar_p;
442 unsigned char type;
373 443
374 Widget* old_children; 444 Widget* old_children;
375 unsigned int old_num_children; 445 unsigned int old_num_children;
@@ -380,13 +450,20 @@ make_menu_in_widget (instance, widget, val, keep_first_children)
380 for (num_children = 0, cur = val; cur; num_children++, cur = cur->next); 450 for (num_children = 0, cur = val; cur; num_children++, cur = cur->next);
381 children = (Widget*)XtMalloc (num_children * sizeof (Widget)); 451 children = (Widget*)XtMalloc (num_children * sizeof (Widget));
382 452
383 /* tricky way to know if this RowColumn is a menubar or a pulldown... */ 453 /* WIDGET should be a RowColumn. */
384 menubar_p = False; 454 if (!XmIsRowColumn (widget))
385 XtSetArg (al[0], XmNisHomogeneous, &menubar_p); 455 abort ();
456
457 /* Determine whether WIDGET is a menu bar. */
458 type = -1;
459 XtSetArg (al[0], XmNrowColumnType, &type);
386 XtGetValues (widget, al, 1); 460 XtGetValues (widget, al, 1);
461 if (type != XmMENU_BAR && type != XmMENU_PULLDOWN && type != XmMENU_POPUP)
462 abort ();
463 menubar_p = type == XmMENU_BAR;
387 464
388 /* add the unmap callback for popups and pulldowns */ 465 /* Add a callback to popups and pulldowns that is called when
389 /*** this sounds bogus ***/ 466 it is made invisible again. */
390 if (!menubar_p) 467 if (!menubar_p)
391 XtAddCallback (XtParent (widget), XmNpopdownCallback, 468 XtAddCallback (XtParent (widget), XmNpopdownCallback,
392 xm_pop_down_callback, (XtPointer)instance); 469 xm_pop_down_callback, (XtPointer)instance);
@@ -403,22 +480,26 @@ make_menu_in_widget (instance, widget, val, keep_first_children)
403 480
404 /* Create the rest. */ 481 /* Create the rest. */
405 for (child_index = keep_first_children; cur; child_index++, cur = cur->next) 482 for (child_index = keep_first_children; cur; child_index++, cur = cur->next)
406 { 483 {
484 enum menu_separator separator;
485
407 ac = 0; 486 ac = 0;
408 XtSetArg (al [ac], XmNsensitive, cur->enabled); ac++; 487 XtSetArg (al[ac], XmNsensitive, cur->enabled); ac++;
409 XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; 488 XtSetArg (al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
410 XtSetArg (al [ac], XmNuserData, cur->call_data); ac++; 489 XtSetArg (al[ac], XmNuserData, cur->call_data); ac++;
411 490
412 if (instance->pop_up_p && !cur->contents && !cur->call_data 491 if (instance->pop_up_p && !cur->contents && !cur->call_data
413 && !all_dashes_p (cur->name)) 492 && !lw_separator_p (cur->name, &separator, 1))
414 { 493 {
415 ac = 0; 494 ac = 0;
416 XtSetArg (al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++; 495 XtSetArg (al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
417 button = XmCreateLabel (widget, cur->name, al, ac); 496 title = button = XmCreateLabel (widget, cur->name, al, ac);
418 } 497 }
419 else if (all_dashes_p (cur->name)) 498 else if (lw_separator_p (cur->name, &separator, 1))
420 { 499 {
421 button = XmCreateSeparator (widget, cur->name, NULL, 0); 500 ac = 0;
501 XtSetArg (al[ac], XmNseparatorType, separator); ++ac;
502 button = XmCreateSeparator (widget, cur->name, al, ac);
422 } 503 }
423 else if (!cur->contents) 504 else if (!cur->contents)
424 { 505 {
@@ -426,13 +507,29 @@ make_menu_in_widget (instance, widget, val, keep_first_children)
426 button = XmCreateCascadeButton (widget, cur->name, al, ac); 507 button = XmCreateCascadeButton (widget, cur->name, al, ac);
427 else if (!cur->call_data) 508 else if (!cur->call_data)
428 button = XmCreateLabel (widget, cur->name, al, ac); 509 button = XmCreateLabel (widget, cur->name, al, ac);
510 else if (cur->button_type == BUTTON_TYPE_TOGGLE
511 || cur->button_type == BUTTON_TYPE_RADIO)
512 {
513 XtSetArg (al[ac], XmNset, cur->selected); ++ac;
514 XtSetArg (al[ac], XmNvisibleWhenOff, True); ++ac;
515 XtSetArg (al[ac], XmNindicatorType,
516 (cur->button_type == BUTTON_TYPE_TOGGLE
517 ? XmN_OF_MANY : XmONE_OF_MANY));
518 ++ac;
519 button = XmCreateToggleButtonGadget (widget, cur->name, al, ac);
520 }
429 else 521 else
430 button = XmCreatePushButtonGadget (widget, cur->name, al, ac); 522 button = XmCreatePushButtonGadget (widget, cur->name, al, ac);
431 523
432 xm_update_label (instance, button, cur); 524 xm_update_label (instance, button, cur);
433 525
434 /* don't add a callback to a simple label */ 526 /* Add a callback that is called when the button is
435 if (cur->call_data) 527 selected. Toggle buttons don't support
528 XmNactivateCallback, we use XmNvalueChangedCallback in
529 that case. Don't add a callback to a simple label. */
530 if (cur->button_type)
531 xm_update_toggle (instance, button, cur);
532 else if (cur->call_data)
436 XtAddCallback (button, XmNactivateCallback, xm_generic_callback, 533 XtAddCallback (button, XmNactivateCallback, xm_generic_callback,
437 (XtPointer)instance); 534 (XtPointer)instance);
438 } 535 }
@@ -441,8 +538,8 @@ make_menu_in_widget (instance, widget, val, keep_first_children)
441 menu = XmCreatePulldownMenu (widget, cur->name, NULL, 0); 538 menu = XmCreatePulldownMenu (widget, cur->name, NULL, 0);
442 make_menu_in_widget (instance, menu, cur->contents, 0); 539 make_menu_in_widget (instance, menu, cur->contents, 0);
443 XtSetArg (al [ac], XmNsubMenuId, menu); ac++; 540 XtSetArg (al [ac], XmNsubMenuId, menu); ac++;
444 /* non-zero values don't work reliably in 541 /* Non-zero values don't work reliably in conjunction with
445 conjunction with Emacs' event loop */ 542 Emacs' event loop */
446 XtSetArg (al [ac], XmNmappingDelay, 0); ac++; 543 XtSetArg (al [ac], XmNmappingDelay, 0); ac++;
447 button = XmCreateCascadeButtonGadget (widget, cur->name, al, ac); 544 button = XmCreateCascadeButtonGadget (widget, cur->name, al, ac);
448 545
@@ -452,19 +549,25 @@ make_menu_in_widget (instance, widget, val, keep_first_children)
452 (XtPointer)instance); 549 (XtPointer)instance);
453 } 550 }
454 551
455 children [child_index] = button; 552 children[child_index] = button;
456 } 553 }
457 554
458 XtManageChildren (children, num_children); 555 /* Last entry is the help button. The original comment read "Has to
459 556 be done after managing the buttons otherwise the menubar is only
460 /* Last entry is the help button. Has to be done after managing 557 4 pixels high." This is no longer true, and to make
461 * the buttons otherwise the menubar is only 4 pixels high... */ 558 XmNmenuHelpWidget work, we need to set it before managing the
559 children.. --gerd. */
462 if (button) 560 if (button)
463 { 561 XtVaSetValues (widget, XmNmenuHelpWidget, button, 0);
464 ac = 0; 562
465 XtSetArg (al [ac], XmNmenuHelpWidget, button); ac++; 563 /* LessTif apparently doesn't recompute centered text when more
466 XtSetValues (widget, al, ac); 564 widgets are added. So, do it after all widgets have been
467 } 565 created. */
566 if (title)
567 XtVaSetValues (title, XmNalignment, XmALIGNMENT_CENTER, 0);
568
569 if (num_children)
570 XtManageChildren (children, num_children);
468 571
469 XtFree ((char *) children); 572 XtFree ((char *) children);
470 if (old_children) 573 if (old_children)
@@ -495,7 +598,11 @@ update_one_menu_entry (instance, widget, val, deep_p)
495 598
496 /* update the menu button as a label. */ 599 /* update the menu button as a label. */
497 if (val->this_one_change >= VISIBLE_CHANGE) 600 if (val->this_one_change >= VISIBLE_CHANGE)
498 xm_update_label (instance, widget, val); 601 {
602 xm_update_label (instance, widget, val);
603 if (val->button_type)
604 xm_update_toggle (instance, widget, val);
605 }
499 606
500 /* update the pulldown/pullaside as needed */ 607 /* update the pulldown/pullaside as needed */
501 ac = 0; 608 ac = 0;
@@ -1352,6 +1459,7 @@ make_popup_menu (instance)
1352 parent->core.window = parent_window; 1459 parent->core.window = parent_window;
1353 return result; 1460 return result;
1354} 1461}
1462
1355static Widget 1463static Widget
1356make_main (instance) 1464make_main (instance)
1357 widget_instance* instance; 1465 widget_instance* instance;
@@ -1608,8 +1716,6 @@ xm_pop_instance (instance, up)
1608 1716
1609/* motif callback */ 1717/* motif callback */
1610 1718
1611enum do_call_type { pre_activate, selection, no_selection, post_activate };
1612
1613static void 1719static void
1614do_call (widget, closure, type) 1720do_call (widget, closure, type)
1615 Widget widget; 1721 Widget widget;