1 /* The lwlib interface to Motif widgets.
2 Copyright (C) 1992 Lucid, Inc.
4 This file is part of the Lucid Widget Library.
6 The Lucid Widget Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 The Lucid Widget Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 #include <X11/StringDefs.h>
29 #include <X11/IntrinsicP.h>
30 #include <X11/ObjectP.h>
31 #include <X11/CoreP.h>
32 #include <X11/CompositeP.h>
35 #include "lwlib-utils.h"
37 #include <Xm/BulletinB.h>
38 #include <Xm/CascadeB.h>
39 #include <Xm/CascadeBG.h>
40 #include <Xm/DrawingA.h>
41 #include <Xm/FileSB.h>
45 #include <Xm/MenuShell.h>
46 #include <Xm/MessageB.h>
47 #include <Xm/PanedW.h>
49 #include <Xm/PushBG.h>
50 #include <Xm/ArrowB.h>
51 #include <Xm/SelectioB.h>
54 #include <Xm/ToggleB.h>
55 #include <Xm/ToggleBG.h>
56 #include <Xm/RowColumn.h>
57 #include <Xm/ScrolledW.h>
58 #include <Xm/Separator.h>
59 #include <Xm/DialogS.h>
68 enum do_call_type
{ pre_activate
, selection
, no_selection
, post_activate
};
71 \f/* Structures to keep destroyed instances */
72 typedef struct _destroyed_instance
79 struct _destroyed_instance
* next
;
82 static destroyed_instance
*make_destroyed_instance
P_ ((char *, char *,
85 static void free_destroyed_instance
P_ ((destroyed_instance
*));
86 Widget first_child
P_ ((Widget
));
87 Boolean lw_motif_widget_p
P_ ((Widget
));
88 static XmString resource_motif_string
P_ ((Widget
, char *));
89 static void destroy_all_children
P_ ((Widget
, int));
90 static void xm_update_label
P_ ((widget_instance
*, Widget
, widget_value
*));
91 static void xm_update_list
P_ ((widget_instance
*, Widget
, widget_value
*));
92 static void xm_update_pushbutton
P_ ((widget_instance
*, Widget
,
94 static void xm_update_cascadebutton
P_ ((widget_instance
*, Widget
,
96 static void xm_update_toggle
P_ ((widget_instance
*, Widget
, widget_value
*));
97 static void xm_update_radiobox
P_ ((widget_instance
*, Widget
, widget_value
*));
98 static void make_menu_in_widget
P_ ((widget_instance
*, Widget
,
99 widget_value
*, int));
100 static void update_one_menu_entry
P_ ((widget_instance
*, Widget
,
101 widget_value
*, Boolean
));
102 static void xm_update_menu
P_ ((widget_instance
*, Widget
, widget_value
*,
104 static void xm_update_text
P_ ((widget_instance
*, Widget
, widget_value
*));
105 static void xm_update_text_field
P_ ((widget_instance
*, Widget
,
107 void xm_update_one_value
P_ ((widget_instance
*, Widget
, widget_value
*));
108 static void activate_button
P_ ((Widget
, XtPointer
, XtPointer
));
109 static Widget make_dialog
P_ ((char *, Widget
, Boolean
, char *, char *,
110 Boolean
, Boolean
, Boolean
, int, int));
111 static destroyed_instance
* find_matching_instance
P_ ((widget_instance
*));
112 static void mark_dead_instance_destroyed
P_ ((Widget
, XtPointer
, XtPointer
));
113 static void recenter_widget
P_ ((Widget
));
114 static Widget recycle_instance
P_ ((destroyed_instance
*));
115 Widget xm_create_dialog
P_ ((widget_instance
*));
116 static Widget make_menubar
P_ ((widget_instance
*));
117 static void remove_grabs
P_ ((Widget
, XtPointer
, XtPointer
));
118 static Widget make_popup_menu
P_ ((widget_instance
*));
119 static Widget make_main
P_ ((widget_instance
*));
120 void xm_destroy_instance
P_ ((widget_instance
*));
121 void xm_popup_menu
P_ ((Widget
, XEvent
*));
122 static void set_min_dialog_size
P_ ((Widget
));
123 static void do_call
P_ ((Widget
, XtPointer
, enum do_call_type
));
124 static void xm_generic_callback
P_ ((Widget
, XtPointer
, XtPointer
));
125 static void xm_nosel_callback
P_ ((Widget
, XtPointer
, XtPointer
));
126 static void xm_pull_down_callback
P_ ((Widget
, XtPointer
, XtPointer
));
127 static void xm_pop_down_callback
P_ ((Widget
, XtPointer
, XtPointer
));
128 static void xm_unmap_callback
P_ ((Widget
, XtPointer
, XtPointer
));
129 void xm_set_keyboard_focus
P_ ((Widget
, Widget
));
130 void xm_set_main_areas
P_ ((Widget
, Widget
, Widget
));
131 static void xm_internal_update_other_instances
P_ ((Widget
, XtPointer
,
133 static void xm_arm_callback
P_ ((Widget
, XtPointer
, XtPointer
));
136 void xm_update_one_widget
P_ ((widget_instance
*, Widget
, widget_value
*,
138 void xm_pop_instance
P_ ((widget_instance
*, Boolean
));
139 void xm_manage_resizing
P_ ((Widget
, Boolean
));
143 static destroyed_instance
*all_destroyed_instances
= NULL
;
145 static destroyed_instance
*
146 make_destroyed_instance (name
, type
, widget
, parent
, pop_up_p
)
153 destroyed_instance
* instance
=
154 (destroyed_instance
*)malloc (sizeof (destroyed_instance
));
155 instance
->name
= safe_strdup (name
);
156 instance
->type
= safe_strdup (type
);
157 instance
->widget
= widget
;
158 instance
->parent
= parent
;
159 instance
->pop_up_p
= pop_up_p
;
160 instance
->next
= NULL
;
165 free_destroyed_instance (instance
)
166 destroyed_instance
* instance
;
168 free (instance
->name
);
169 free (instance
->type
);
173 \f/* motif utility functions */
178 return ((CompositeWidget
)widget
)->composite
.children
[0];
182 lw_motif_widget_p (widget
)
186 XtClass (widget
) == xmDialogShellWidgetClass
187 || XmIsPrimitive (widget
) || XmIsManager (widget
) || XmIsGadget (widget
);
191 resource_motif_string (widget
, name
)
198 resource
.resource_name
= name
;
199 resource
.resource_class
= XmCXmString
;
200 resource
.resource_type
= XmRXmString
;
201 resource
.resource_size
= sizeof (XmString
);
202 resource
.resource_offset
= 0;
203 resource
.default_type
= XtRImmediate
;
204 resource
.default_addr
= 0;
206 XtGetSubresources (widget
, (XtPointer
)&result
, "dialogString",
207 "DialogString", &resource
, 1, NULL
, 0);
211 /* Destroy all of the children of WIDGET
212 starting with number FIRST_CHILD_TO_DESTROY. */
215 destroy_all_children (widget
, first_child_to_destroy
)
217 int first_child_to_destroy
;
223 children
= XtCompositeChildren (widget
, &number
);
226 XtUnmanageChildren (children
+ first_child_to_destroy
,
227 number
- first_child_to_destroy
);
229 /* Unmanage all children and destroy them. They will only be
230 really destroyed when we get out of DispatchEvent. */
231 for (i
= first_child_to_destroy
; i
< number
; i
++)
235 /* Cascade buttons have submenus,and these submenus
236 need to be freed. But they are not included in
237 XtCompositeChildren. So get it out of the cascade button
238 and free it. If this child is not a cascade button,
239 then submenu should remain unchanged. */
240 XtSetArg (al
[0], XmNsubMenuId
, &submenu
);
241 XtGetValues (children
[i
], al
, 1);
243 XtDestroyWidget (submenu
);
244 XtDestroyWidget (children
[i
]);
247 XtFree ((char *) children
);
253 /* Callback XmNarmCallback and XmNdisarmCallback for buttons in a
254 menu. CLIENT_DATA contains a pointer to the widget_value
255 corresponding to widget W. CALL_DATA contains a
256 XmPushButtonCallbackStruct containing the reason why the callback
260 xm_arm_callback (w
, client_data
, call_data
)
262 XtPointer client_data
, call_data
;
264 XmPushButtonCallbackStruct
*cbs
= (XmPushButtonCallbackStruct
*) call_data
;
265 widget_value
*wv
= (widget_value
*) client_data
;
266 widget_instance
*instance
;
268 /* Get the id of the menu bar or popup menu this widget is in. */
271 if (XmIsRowColumn (w
))
273 unsigned char type
= 0xff;
275 XtVaGetValues (w
, XmNrowColumnType
, &type
, NULL
);
276 if (type
== XmMENU_BAR
|| type
== XmMENU_POPUP
)
283 instance
= lw_get_widget_instance (w
);
284 if (instance
&& instance
->info
->highlight_cb
)
286 call_data
= cbs
->reason
== XmCR_DISARM
? NULL
: wv
;
287 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
293 /* Update the label of widget WIDGET. WIDGET must be a Label widget
294 or a subclass of Label. WIDGET_INSTANCE is unused. VAL contains
299 Emacs fills VAL->name with the text to display in the menu, and
300 sets VAL->value to null. Function make_menu_in_widget creates
301 widgets with VAL->name as resource name. This works because the
302 Label widget uses its resource name for display if no
303 XmNlabelString is set.
307 VAL->name is again set to the resource name, but VAL->value is
308 not null, and contains the label string to display. */
311 xm_update_label (instance
, widget
, val
)
312 widget_instance
* instance
;
316 XmString res_string
= 0;
317 XmString built_string
= 0;
318 XmString key_string
= 0;
326 /* A label string is specified, i.e. we are in a dialog. First
327 see if it is overridden by something from the resource file. */
328 res_string
= resource_motif_string (widget
, val
->value
);
332 XtSetArg (al
[ac
], XmNlabelString
, res_string
); ac
++;
337 XmStringCreateLtoR (val
->value
, XmSTRING_DEFAULT_CHARSET
);
338 XtSetArg (al
[ac
], XmNlabelString
, built_string
); ac
++;
341 XtSetArg (al
[ac
], XmNlabelType
, XmSTRING
); ac
++;
346 key_string
= XmStringCreateLtoR (val
->key
, XmSTRING_DEFAULT_CHARSET
);
347 XtSetArg (al
[ac
], XmNacceleratorText
, key_string
); ac
++;
351 XtSetValues (widget
, al
, ac
);
354 XmStringFree (built_string
);
357 XmStringFree (key_string
);
360 \f/* update of list */
362 xm_update_list (instance
, widget
, val
)
363 widget_instance
* instance
;
369 XtRemoveAllCallbacks (widget
, XmNsingleSelectionCallback
);
370 XtAddCallback (widget
, XmNsingleSelectionCallback
, xm_generic_callback
,
372 for (cur
= val
->contents
, i
= 0; cur
; cur
= cur
->next
)
375 XmString xmstr
= XmStringCreate (cur
->value
, XmSTRING_DEFAULT_CHARSET
);
377 XmListAddItem (widget
, xmstr
, 0);
379 XmListSelectPos (widget
, i
, False
);
380 XmStringFree (xmstr
);
384 \f/* update of buttons */
386 xm_update_pushbutton (instance
, widget
, val
)
387 widget_instance
* instance
;
391 XtVaSetValues (widget
, XmNalignment
, XmALIGNMENT_CENTER
, 0);
392 XtRemoveAllCallbacks (widget
, XmNactivateCallback
);
393 XtAddCallback (widget
, XmNactivateCallback
, xm_generic_callback
, instance
);
397 xm_update_cascadebutton (instance
, widget
, val
)
398 widget_instance
* instance
;
402 /* Should also rebuild the menu by calling ...update_menu... */
403 XtRemoveAllCallbacks (widget
, XmNcascadingCallback
);
404 XtAddCallback (widget
, XmNcascadingCallback
, xm_pull_down_callback
,
408 \f/* update toggle and radiobox */
410 xm_update_toggle (instance
, widget
, val
)
411 widget_instance
* instance
;
415 XtRemoveAllCallbacks (widget
, XmNvalueChangedCallback
);
416 XtAddCallback (widget
, XmNvalueChangedCallback
,
417 xm_generic_callback
, instance
);
418 XtVaSetValues (widget
, XmNset
, val
->selected
,
419 XmNalignment
, XmALIGNMENT_BEGINNING
, 0);
423 xm_update_radiobox (instance
, widget
, val
)
424 widget_instance
* instance
;
432 /* update the callback */
433 XtRemoveAllCallbacks (widget
, XmNentryCallback
);
434 XtAddCallback (widget
, XmNentryCallback
, xm_generic_callback
, instance
);
436 /* first update all the toggles */
437 /* Energize kernel interface is currently bad. It sets the selected widget
438 with the selected flag but returns it by its name. So we currently
439 have to support both setting the selection with the selected slot
440 of val contents and setting it with the "value" slot of val. The latter
441 has a higher priority. This to be removed when the kernel is fixed. */
442 for (cur
= val
->contents
; cur
; cur
= cur
->next
)
444 toggle
= XtNameToWidget (widget
, cur
->value
);
447 XtVaSetValues (toggle
, XmNsensitive
, cur
->enabled
, 0);
448 if (!val
->value
&& cur
->selected
)
449 XtVaSetValues (toggle
, XmNset
, cur
->selected
, 0);
450 if (val
->value
&& strcmp (val
->value
, cur
->value
))
451 XtVaSetValues (toggle
, XmNset
, False
, 0);
455 /* The selected was specified by the value slot */
458 toggle
= XtNameToWidget (widget
, val
->value
);
460 XtVaSetValues (toggle
, XmNset
, True
, 0);
465 /* update a popup menu, pulldown menu or a menubar */
467 /* KEEP_FIRST_CHILDREN gives the number of initial children to keep. */
470 make_menu_in_widget (instance
, widget
, val
, keep_first_children
)
471 widget_instance
* instance
;
474 int keep_first_children
;
476 Widget
* children
= 0;
488 Widget
* old_children
;
489 unsigned int old_num_children
;
491 old_children
= XtCompositeChildren (widget
, &old_num_children
);
493 /* Allocate the children array */
494 for (num_children
= 0, cur
= val
; cur
; num_children
++, cur
= cur
->next
);
495 children
= (Widget
*)XtMalloc (num_children
* sizeof (Widget
));
497 /* WIDGET should be a RowColumn. */
498 if (!XmIsRowColumn (widget
))
501 /* Determine whether WIDGET is a menu bar. */
503 XtSetArg (al
[0], XmNrowColumnType
, &type
);
504 XtGetValues (widget
, al
, 1);
505 if (type
!= XmMENU_BAR
&& type
!= XmMENU_PULLDOWN
&& type
!= XmMENU_POPUP
)
507 menubar_p
= type
== XmMENU_BAR
;
509 #if 0 /* This can't be used in LessTif as of 2000-01-24 because it's
510 impossible to decide from this plus the cascading callback if a
511 popup is still posted or not. When selecting cascade button A,
512 then B, then clicking on the frame, the sequence of callbacks is
513 `cascading A', cascading B', `popdown for all cascade buttons in
515 /* Add a callback to popups and pulldowns that is called when
516 it is made invisible again. */
518 XtAddCallback (XtParent (widget
), XmNpopdownCallback
,
519 xm_pop_down_callback
, (XtPointer
)instance
);
522 /* Preserve the first KEEP_FIRST_CHILDREN old children. */
523 for (child_index
= 0, cur
= val
; child_index
< keep_first_children
;
524 child_index
++, cur
= cur
->next
)
525 children
[child_index
] = old_children
[child_index
];
527 /* Check that those are all we have
528 (the caller should have deleted the rest). */
529 if (old_num_children
!= keep_first_children
)
532 /* Create the rest. */
533 for (child_index
= keep_first_children
; cur
; child_index
++, cur
= cur
->next
)
535 enum menu_separator separator
;
538 XtSetArg (al
[ac
], XmNsensitive
, cur
->enabled
); ac
++;
539 XtSetArg (al
[ac
], XmNalignment
, XmALIGNMENT_BEGINNING
); ac
++;
540 XtSetArg (al
[ac
], XmNuserData
, cur
->call_data
); ac
++;
542 if (instance
->pop_up_p
&& !cur
->contents
&& !cur
->call_data
543 && !lw_separator_p (cur
->name
, &separator
, 1))
546 XtSetArg (al
[ac
], XmNalignment
, XmALIGNMENT_CENTER
); ac
++;
547 title
= button
= XmCreateLabel (widget
, cur
->name
, al
, ac
);
549 else if (lw_separator_p (cur
->name
, &separator
, 1))
552 XtSetArg (al
[ac
], XmNseparatorType
, separator
); ++ac
;
553 button
= XmCreateSeparator (widget
, cur
->name
, al
, ac
);
555 else if (!cur
->contents
)
558 button
= XmCreateCascadeButton (widget
, cur
->name
, al
, ac
);
559 else if (!cur
->call_data
)
560 button
= XmCreateLabel (widget
, cur
->name
, al
, ac
);
561 else if (cur
->button_type
== BUTTON_TYPE_TOGGLE
562 || cur
->button_type
== BUTTON_TYPE_RADIO
)
564 XtSetArg (al
[ac
], XmNset
, cur
->selected
); ++ac
;
565 XtSetArg (al
[ac
], XmNvisibleWhenOff
, True
); ++ac
;
566 XtSetArg (al
[ac
], XmNindicatorType
,
567 (cur
->button_type
== BUTTON_TYPE_TOGGLE
568 ? XmN_OF_MANY
: XmONE_OF_MANY
));
570 button
= XmCreateToggleButton (widget
, cur
->name
, al
, ac
);
571 XtAddCallback (button
, XmNarmCallback
, xm_arm_callback
, cur
);
572 XtAddCallback (button
, XmNdisarmCallback
, xm_arm_callback
, cur
);
576 button
= XmCreatePushButton (widget
, cur
->name
, al
, ac
);
577 XtAddCallback (button
, XmNarmCallback
, xm_arm_callback
, cur
);
578 XtAddCallback (button
, XmNdisarmCallback
, xm_arm_callback
, cur
);
581 xm_update_label (instance
, button
, cur
);
583 /* Add a callback that is called when the button is
584 selected. Toggle buttons don't support
585 XmNactivateCallback, we use XmNvalueChangedCallback in
586 that case. Don't add a callback to a simple label. */
587 if (cur
->button_type
)
588 xm_update_toggle (instance
, button
, cur
);
589 else if (cur
->call_data
)
590 XtAddCallback (button
, XmNactivateCallback
, xm_generic_callback
,
591 (XtPointer
)instance
);
595 menu
= XmCreatePulldownMenu (widget
, cur
->name
, NULL
, 0);
597 /* XmNpopdownCallback is working strangely under LessTif.
598 Using XmNunmapCallback is the only way to go there. */
600 XtAddCallback (menu
, XmNunmapCallback
, xm_unmap_callback
,
601 (XtPointer
) instance
);
603 make_menu_in_widget (instance
, menu
, cur
->contents
, 0);
604 XtSetArg (al
[ac
], XmNsubMenuId
, menu
); ac
++;
605 button
= XmCreateCascadeButton (widget
, cur
->name
, al
, ac
);
607 xm_update_label (instance
, button
, cur
);
609 XtAddCallback (button
, XmNcascadingCallback
, xm_pull_down_callback
,
610 (XtPointer
)instance
);
613 children
[child_index
] = button
;
616 /* Last entry is the help button. The original comment read "Has to
617 be done after managing the buttons otherwise the menubar is only
618 4 pixels high." This is no longer true, and to make
619 XmNmenuHelpWidget work, we need to set it before managing the
620 children.. --gerd. */
622 XtVaSetValues (widget
, XmNmenuHelpWidget
, button
, 0);
624 /* LessTif apparently doesn't recompute centered text when more
625 widgets are added. So, do it after all widgets have been
628 XtVaSetValues (title
, XmNalignment
, XmALIGNMENT_CENTER
, 0);
631 XtManageChildren (children
, num_children
);
633 XtFree ((char *) children
);
635 XtFree ((char *) old_children
);
639 update_one_menu_entry (instance
, widget
, val
, deep_p
)
640 widget_instance
* instance
;
648 widget_value
* contents
;
650 if (val
->this_one_change
== NO_CHANGE
)
653 /* update the sensitivity and userdata */
654 /* Common to all widget types */
655 XtVaSetValues (widget
,
656 XmNsensitive
, val
->enabled
,
657 XmNuserData
, val
->call_data
,
660 /* update the menu button as a label. */
661 if (val
->this_one_change
>= VISIBLE_CHANGE
)
663 xm_update_label (instance
, widget
, val
);
664 if (val
->button_type
)
665 xm_update_toggle (instance
, widget
, val
);
668 /* update the pulldown/pullaside as needed */
671 XtSetArg (al
[ac
], XmNsubMenuId
, &menu
); ac
++;
672 XtGetValues (widget
, al
, ac
);
674 contents
= val
->contents
;
680 unsigned int old_num_children
, i
;
684 parent
= XtParent (widget
);
685 widget_list
= XtCompositeChildren (parent
, &old_num_children
);
687 /* Find the widget position within the parent's widget list. */
688 for (i
= 0; i
< old_num_children
; i
++)
689 if (strcmp (XtName (widget_list
[i
]), XtName (widget
)) == 0)
691 if (i
== old_num_children
)
693 if (XmIsCascadeButton (widget_list
[i
]))
695 menu
= XmCreatePulldownMenu (parent
, XtName(widget
), NULL
, 0);
696 make_menu_in_widget (instance
, menu
, contents
, 0);
698 XtSetArg (al
[ac
], XmNsubMenuId
, menu
); ac
++;
699 XtSetValues (widget
, al
, ac
);
705 /* The current menuitem is a XmPushButtonGadget, it
706 needs to be replaced by a CascadeButtonGadget */
707 XtDestroyWidget (widget_list
[i
]);
708 menu
= XmCreatePulldownMenu (parent
, val
->name
, NULL
, 0);
709 make_menu_in_widget (instance
, menu
, contents
, 0);
711 XtSetArg (al
[ac
], XmNsubMenuId
, menu
); ac
++;
712 /* Non-zero values don't work reliably in
713 conjunction with Emacs' event loop */
714 XtSetArg (al
[ac
], XmNmappingDelay
, 0); ac
++;
715 #ifdef XmNpositionIndex /* This is undefined on SCO ODT 2.0. */
716 /* Tell Motif to put it in the right place */
717 XtSetArg (al
[ac
], XmNpositionIndex
, i
); ac
++;
719 button
= XmCreateCascadeButton (parent
, val
->name
, al
, ac
);
720 xm_update_label (instance
, button
, val
);
722 XtAddCallback (button
, XmNcascadingCallback
, xm_pull_down_callback
,
723 (XtPointer
)instance
);
724 XtManageChild (button
);
731 XtSetArg (al
[ac
], XmNsubMenuId
, NULL
); ac
++;
732 XtSetValues (widget
, al
, ac
);
733 XtDestroyWidget (menu
);
735 else if (deep_p
&& contents
->change
!= NO_CHANGE
)
736 xm_update_menu (instance
, menu
, val
, 1);
740 xm_update_menu (instance
, widget
, val
, deep_p
)
741 widget_instance
* instance
;
747 unsigned int num_children
;
748 int num_children_to_keep
= 0;
752 children
= XtCompositeChildren (widget
, &num_children
);
754 /* Widget is a RowColumn widget whose contents have to be updated
755 * to reflect the list of items in val->contents */
757 /* See how many buttons we can keep, and how many we
758 must completely replace. */
759 if (val
->contents
== 0)
760 num_children_to_keep
= 0;
761 else if (val
->contents
->change
== STRUCTURAL_CHANGE
)
765 for (i
= 0, cur
= val
->contents
;
767 && cur
); /* how else to ditch unwanted children ?? - mgd */
768 i
++, cur
= cur
->next
)
770 if (cur
->this_one_change
== STRUCTURAL_CHANGE
)
774 num_children_to_keep
= i
;
778 num_children_to_keep
= num_children
;
780 /* Update all the buttons of the RowColumn, in order,
781 except for those we are going to replace entirely. */
784 for (i
= 0, cur
= val
->contents
; i
< num_children_to_keep
; i
++)
788 num_children_to_keep
= i
;
791 if (children
[i
]->core
.being_destroyed
792 || strcmp (XtName (children
[i
]), cur
->name
))
794 update_one_menu_entry (instance
, children
[i
], cur
, deep_p
);
799 /* Now replace from scratch all the buttons after the last
800 place that the top-level structure changed. */
801 if (val
->contents
->change
== STRUCTURAL_CHANGE
)
803 destroy_all_children (widget
, num_children_to_keep
);
804 make_menu_in_widget (instance
, widget
, val
->contents
,
805 num_children_to_keep
);
808 XtFree ((char *) children
);
812 /* update text widgets */
815 xm_update_text (instance
, widget
, val
)
816 widget_instance
* instance
;
820 XmTextSetString (widget
, val
->value
? val
->value
: "");
821 XtRemoveAllCallbacks (widget
, XmNactivateCallback
);
822 XtAddCallback (widget
, XmNactivateCallback
, xm_generic_callback
, instance
);
823 XtRemoveAllCallbacks (widget
, XmNvalueChangedCallback
);
824 XtAddCallback (widget
, XmNvalueChangedCallback
,
825 xm_internal_update_other_instances
, instance
);
829 xm_update_text_field (instance
, widget
, val
)
830 widget_instance
* instance
;
834 XmTextFieldSetString (widget
, val
->value
? val
->value
: "");
835 XtRemoveAllCallbacks (widget
, XmNactivateCallback
);
836 XtAddCallback (widget
, XmNactivateCallback
, xm_generic_callback
, instance
);
837 XtRemoveAllCallbacks (widget
, XmNvalueChangedCallback
);
838 XtAddCallback (widget
, XmNvalueChangedCallback
,
839 xm_internal_update_other_instances
, instance
);
843 /* update a motif widget */
846 xm_update_one_widget (instance
, widget
, val
, deep_p
)
847 widget_instance
* instance
;
854 /* Mark as not edited */
857 /* Common to all widget types */
858 XtVaSetValues (widget
,
859 XmNsensitive
, val
->enabled
,
860 XmNuserData
, val
->call_data
,
863 /* Common to all label like widgets */
864 if (XtIsSubclass (widget
, xmLabelWidgetClass
))
865 xm_update_label (instance
, widget
, val
);
867 class = XtClass (widget
);
868 /* Class specific things */
869 if (class == xmPushButtonWidgetClass
||
870 class == xmArrowButtonWidgetClass
)
872 xm_update_pushbutton (instance
, widget
, val
);
874 else if (class == xmCascadeButtonWidgetClass
)
876 xm_update_cascadebutton (instance
, widget
, val
);
878 else if (class == xmToggleButtonWidgetClass
879 || class == xmToggleButtonGadgetClass
)
881 xm_update_toggle (instance
, widget
, val
);
883 else if (class == xmRowColumnWidgetClass
)
885 Boolean radiobox
= 0;
889 XtSetArg (al
[ac
], XmNradioBehavior
, &radiobox
); ac
++;
890 XtGetValues (widget
, al
, ac
);
893 xm_update_radiobox (instance
, widget
, val
);
895 xm_update_menu (instance
, widget
, val
, deep_p
);
897 else if (class == xmTextWidgetClass
)
899 xm_update_text (instance
, widget
, val
);
901 else if (class == xmTextFieldWidgetClass
)
903 xm_update_text_field (instance
, widget
, val
);
905 else if (class == xmListWidgetClass
)
907 xm_update_list (instance
, widget
, val
);
911 \f/* getting the value back */
913 xm_update_one_value (instance
, widget
, val
)
914 widget_instance
* instance
;
918 WidgetClass
class = XtClass (widget
);
919 widget_value
*old_wv
;
921 /* copy the call_data slot into the "return" widget_value */
922 for (old_wv
= instance
->info
->val
->contents
; old_wv
; old_wv
= old_wv
->next
)
923 if (!strcmp (val
->name
, old_wv
->name
))
925 val
->call_data
= old_wv
->call_data
;
929 if (class == xmToggleButtonWidgetClass
|| class == xmToggleButtonGadgetClass
)
931 XtVaGetValues (widget
, XmNset
, &val
->selected
, 0);
934 else if (class == xmTextWidgetClass
)
938 val
->value
= XmTextGetString (widget
);
941 else if (class == xmTextFieldWidgetClass
)
945 val
->value
= XmTextFieldGetString (widget
);
948 else if (class == xmRowColumnWidgetClass
)
950 Boolean radiobox
= 0;
954 XtSetArg (al
[ac
], XmNradioBehavior
, &radiobox
); ac
++;
955 XtGetValues (widget
, al
, ac
);
959 CompositeWidget radio
= (CompositeWidget
)widget
;
961 for (i
= 0; i
< radio
->composite
.num_children
; i
++)
964 Widget toggle
= radio
->composite
.children
[i
];
966 XtVaGetValues (toggle
, XmNset
, &set
, 0);
971 val
->value
= safe_strdup (XtName (toggle
));
977 else if (class == xmListWidgetClass
)
981 if (XmListGetSelectedPos (widget
, &pos_list
, &pos_cnt
))
985 for (cur
= val
->contents
, i
= 0; cur
; cur
= cur
->next
)
989 cur
->selected
= False
;
991 for (j
= 0; j
< pos_cnt
; j
++)
992 if (pos_list
[j
] == i
)
994 cur
->selected
= True
;
995 val
->value
= safe_strdup (cur
->name
);
999 XtFree ((char *) pos_list
);
1005 /* This function is for activating a button from a program. It's wrong because
1006 we pass a NULL argument in the call_data which is not Motif compatible.
1007 This is used from the XmNdefaultAction callback of the List widgets to
1008 have a double-click put down a dialog box like the button would do.
1009 I could not find a way to do that with accelerators.
1012 activate_button (widget
, closure
, call_data
)
1015 XtPointer call_data
;
1017 Widget button
= (Widget
)closure
;
1018 XtCallCallbacks (button
, XmNactivateCallback
, NULL
);
1021 /* creation functions */
1025 make_dialog (name
, parent
, pop_up_p
, shell_title
, icon_name
, text_input_slot
,
1026 radio_box
, list
, left_buttons
, right_buttons
)
1032 Boolean text_input_slot
;
1042 Widget icon_separator
;
1047 Widget children
[16]; /* for the final XtManageChildren */
1049 Arg al
[64]; /* Arg List */
1050 int ac
; /* Arg Count */
1056 XtSetArg(al
[ac
], XmNtitle
, shell_title
); ac
++;
1057 XtSetArg(al
[ac
], XtNallowShellResize
, True
); ac
++;
1058 XtSetArg(al
[ac
], XmNdeleteResponse
, XmUNMAP
); ac
++;
1059 result
= XmCreateDialogShell (parent
, "dialog", al
, ac
);
1061 XtSetArg(al
[ac
], XmNautoUnmanage
, FALSE
); ac
++;
1062 /* XtSetArg(al[ac], XmNautoUnmanage, TRUE); ac++; */ /* ####is this ok? */
1063 XtSetArg(al
[ac
], XmNnavigationType
, XmTAB_GROUP
); ac
++;
1064 form
= XmCreateForm (result
, shell_title
, al
, ac
);
1069 XtSetArg(al
[ac
], XmNautoUnmanage
, FALSE
); ac
++;
1070 XtSetArg(al
[ac
], XmNnavigationType
, XmTAB_GROUP
); ac
++;
1071 form
= XmCreateForm (parent
, shell_title
, al
, ac
);
1075 n_children
= left_buttons
+ right_buttons
+ 1;
1077 XtSetArg(al
[ac
], XmNpacking
, n_children
== 3?
1078 XmPACK_COLUMN
: XmPACK_TIGHT
); ac
++;
1079 XtSetArg(al
[ac
], XmNorientation
, n_children
== 3?
1080 XmVERTICAL
: XmHORIZONTAL
); ac
++;
1081 XtSetArg(al
[ac
], XmNnumColumns
, left_buttons
+ right_buttons
+ 1); ac
++;
1082 XtSetArg(al
[ac
], XmNmarginWidth
, 0); ac
++;
1083 XtSetArg(al
[ac
], XmNmarginHeight
, 0); ac
++;
1084 XtSetArg(al
[ac
], XmNspacing
, 13); ac
++;
1085 XtSetArg(al
[ac
], XmNadjustLast
, False
); ac
++;
1086 XtSetArg(al
[ac
], XmNalignment
, XmALIGNMENT_CENTER
); ac
++;
1087 XtSetArg(al
[ac
], XmNisAligned
, True
); ac
++;
1088 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_NONE
); ac
++;
1089 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_FORM
); ac
++;
1090 XtSetArg(al
[ac
], XmNbottomOffset
, 13); ac
++;
1091 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_FORM
); ac
++;
1092 XtSetArg(al
[ac
], XmNleftOffset
, 13); ac
++;
1093 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_FORM
); ac
++;
1094 XtSetArg(al
[ac
], XmNrightOffset
, 13); ac
++;
1095 row
= XmCreateRowColumn (form
, "row", al
, ac
);
1098 for (i
= 0; i
< left_buttons
; i
++)
1100 char button_name
[16];
1101 sprintf (button_name
, "button%d", i
+ 1);
1105 XtSetArg(al
[ac
], XmNhighlightThickness
, 1); ac
++;
1106 XtSetArg(al
[ac
], XmNshowAsDefault
, TRUE
); ac
++;
1108 XtSetArg(al
[ac
], XmNmarginWidth
, 10); ac
++;
1109 XtSetArg(al
[ac
], XmNnavigationType
, XmTAB_GROUP
); ac
++;
1110 children
[n_children
] = XmCreatePushButton (row
, button_name
, al
, ac
);
1114 button
= children
[n_children
];
1116 XtSetArg(al
[ac
], XmNdefaultButton
, button
); ac
++;
1117 XtSetValues (row
, al
, ac
);
1123 /* invisible separator button */
1125 XtSetArg (al
[ac
], XmNmappedWhenManaged
, FALSE
); ac
++;
1126 children
[n_children
] = XmCreateLabel (row
, "separator_button", al
, ac
);
1129 for (i
= 0; i
< right_buttons
; i
++)
1131 char button_name
[16];
1132 sprintf (button_name
, "button%d", left_buttons
+ i
+ 1);
1134 XtSetArg(al
[ac
], XmNmarginWidth
, 10); ac
++;
1135 XtSetArg(al
[ac
], XmNnavigationType
, XmTAB_GROUP
); ac
++;
1136 children
[n_children
] = XmCreatePushButton (row
, button_name
, al
, ac
);
1137 if (! button
) button
= children
[n_children
];
1141 XtManageChildren (children
, n_children
);
1144 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_NONE
); ac
++;
1145 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
1146 XtSetArg(al
[ac
], XmNbottomOffset
, 13); ac
++;
1147 XtSetArg(al
[ac
], XmNbottomWidget
, row
); ac
++;
1148 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_FORM
); ac
++;
1149 XtSetArg(al
[ac
], XmNleftOffset
, 0); ac
++;
1150 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_FORM
); ac
++;
1151 XtSetArg(al
[ac
], XmNrightOffset
, 0); ac
++;
1152 separator
= XmCreateSeparator (form
, "", al
, ac
);
1155 XtSetArg(al
[ac
], XmNlabelType
, XmPIXMAP
); ac
++;
1156 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_FORM
); ac
++;
1157 XtSetArg(al
[ac
], XmNtopOffset
, 13); ac
++;
1158 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_NONE
); ac
++;
1159 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_FORM
); ac
++;
1160 XtSetArg(al
[ac
], XmNleftOffset
, 13); ac
++;
1161 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_NONE
); ac
++;
1162 icon
= XmCreateLabel (form
, icon_name
, al
, ac
);
1165 XtSetArg(al
[ac
], XmNmappedWhenManaged
, FALSE
); ac
++;
1166 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_WIDGET
); ac
++;
1167 XtSetArg(al
[ac
], XmNtopOffset
, 6); ac
++;
1168 XtSetArg(al
[ac
], XmNtopWidget
, icon
); ac
++;
1169 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
1170 XtSetArg(al
[ac
], XmNbottomOffset
, 6); ac
++;
1171 XtSetArg(al
[ac
], XmNbottomWidget
, separator
); ac
++;
1172 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_NONE
); ac
++;
1173 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_NONE
); ac
++;
1174 icon_separator
= XmCreateLabel (form
, "", al
, ac
);
1176 if (text_input_slot
)
1179 XtSetArg(al
[ac
], XmNcolumns
, 50); ac
++;
1180 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_NONE
); ac
++;
1181 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
1182 XtSetArg(al
[ac
], XmNbottomOffset
, 13); ac
++;
1183 XtSetArg(al
[ac
], XmNbottomWidget
, separator
); ac
++;
1184 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_WIDGET
); ac
++;
1185 XtSetArg(al
[ac
], XmNleftOffset
, 13); ac
++;
1186 XtSetArg(al
[ac
], XmNleftWidget
, icon
); ac
++;
1187 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_FORM
); ac
++;
1188 XtSetArg(al
[ac
], XmNrightOffset
, 13); ac
++;
1189 value
= XmCreateTextField (form
, "value", al
, ac
);
1195 XtSetArg(al
[ac
], XmNmarginWidth
, 0); ac
++;
1196 XtSetArg(al
[ac
], XmNmarginHeight
, 0); ac
++;
1197 XtSetArg(al
[ac
], XmNspacing
, 13); ac
++;
1198 XtSetArg(al
[ac
], XmNalignment
, XmALIGNMENT_CENTER
); ac
++;
1199 XtSetArg(al
[ac
], XmNorientation
, XmHORIZONTAL
); ac
++;
1200 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
1201 XtSetArg(al
[ac
], XmNbottomOffset
, 13); ac
++;
1202 XtSetArg(al
[ac
], XmNbottomWidget
, separator
); ac
++;
1203 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_WIDGET
); ac
++;
1204 XtSetArg(al
[ac
], XmNleftOffset
, 13); ac
++;
1205 XtSetArg(al
[ac
], XmNleftWidget
, icon
); ac
++;
1206 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_FORM
); ac
++;
1207 XtSetArg(al
[ac
], XmNrightOffset
, 13); ac
++;
1208 value
= XmCreateRadioBox (form
, "radiobutton1", al
, ac
);
1211 radio_butt
= XmCreateToggleButtonGadget (value
, "radio1", al
, ac
);
1212 children
[i
++] = radio_butt
;
1213 radio_butt
= XmCreateToggleButtonGadget (value
, "radio2", al
, ac
);
1214 children
[i
++] = radio_butt
;
1215 radio_butt
= XmCreateToggleButtonGadget (value
, "radio3", al
, ac
);
1216 children
[i
++] = radio_butt
;
1217 XtManageChildren (children
, i
);
1222 XtSetArg(al
[ac
], XmNvisibleItemCount
, 5); ac
++;
1223 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_NONE
); ac
++;
1224 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
1225 XtSetArg(al
[ac
], XmNbottomOffset
, 13); ac
++;
1226 XtSetArg(al
[ac
], XmNbottomWidget
, separator
); ac
++;
1227 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_WIDGET
); ac
++;
1228 XtSetArg(al
[ac
], XmNleftOffset
, 13); ac
++;
1229 XtSetArg(al
[ac
], XmNleftWidget
, icon
); ac
++;
1230 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_FORM
); ac
++;
1231 XtSetArg(al
[ac
], XmNrightOffset
, 13); ac
++;
1232 value
= XmCreateScrolledList (form
, "list", al
, ac
);
1234 /* this is the easiest way I found to have the dble click in the
1235 list activate the default button */
1236 XtAddCallback (value
, XmNdefaultActionCallback
, activate_button
, button
);
1240 XtSetArg(al
[ac
], XmNalignment
, XmALIGNMENT_BEGINNING
); ac
++;
1241 XtSetArg(al
[ac
], XmNtopAttachment
, XmATTACH_FORM
); ac
++;
1242 XtSetArg(al
[ac
], XmNtopOffset
, 13); ac
++;
1243 XtSetArg(al
[ac
], XmNbottomAttachment
, XmATTACH_WIDGET
); ac
++;
1244 XtSetArg(al
[ac
], XmNbottomOffset
, 13); ac
++;
1245 XtSetArg(al
[ac
], XmNbottomWidget
,
1246 text_input_slot
|| radio_box
|| list
? value
: separator
); ac
++;
1247 XtSetArg(al
[ac
], XmNleftAttachment
, XmATTACH_WIDGET
); ac
++;
1248 XtSetArg(al
[ac
], XmNleftOffset
, 13); ac
++;
1249 XtSetArg(al
[ac
], XmNleftWidget
, icon
); ac
++;
1250 XtSetArg(al
[ac
], XmNrightAttachment
, XmATTACH_FORM
); ac
++;
1251 XtSetArg(al
[ac
], XmNrightOffset
, 13); ac
++;
1252 message
= XmCreateLabel (form
, "message", al
, ac
);
1255 XtManageChild (value
);
1258 children
[i
] = row
; i
++;
1259 children
[i
] = separator
; i
++;
1260 if (text_input_slot
|| radio_box
)
1262 children
[i
] = value
; i
++;
1264 children
[i
] = message
; i
++;
1265 children
[i
] = icon
; i
++;
1266 children
[i
] = icon_separator
; i
++;
1267 XtManageChildren (children
, i
);
1269 if (text_input_slot
|| list
)
1271 XtInstallAccelerators (value
, button
);
1272 XtSetKeyboardFocus (result
, value
);
1276 XtInstallAccelerators (form
, button
);
1277 XtSetKeyboardFocus (result
, button
);
1283 static destroyed_instance
*
1284 find_matching_instance (instance
)
1285 widget_instance
* instance
;
1287 destroyed_instance
* cur
;
1288 destroyed_instance
* prev
;
1289 char* type
= instance
->info
->type
;
1290 char* name
= instance
->info
->name
;
1292 for (prev
= NULL
, cur
= all_destroyed_instances
;
1294 prev
= cur
, cur
= cur
->next
)
1296 if (!strcmp (cur
->name
, name
)
1297 && !strcmp (cur
->type
, type
)
1298 && cur
->parent
== instance
->parent
1299 && cur
->pop_up_p
== instance
->pop_up_p
)
1302 prev
->next
= cur
->next
;
1304 all_destroyed_instances
= cur
->next
;
1307 /* do some cleanup */
1308 else if (!cur
->widget
)
1311 prev
->next
= cur
->next
;
1313 all_destroyed_instances
= cur
->next
;
1314 free_destroyed_instance (cur
);
1315 cur
= prev
? prev
: all_destroyed_instances
;
1322 mark_dead_instance_destroyed (widget
, closure
, call_data
)
1325 XtPointer call_data
;
1327 destroyed_instance
* instance
= (destroyed_instance
*)closure
;
1328 instance
->widget
= NULL
;
1332 recenter_widget (widget
)
1335 Widget parent
= XtParent (widget
);
1336 Screen
* screen
= XtScreen (widget
);
1337 Dimension screen_width
= WidthOfScreen (screen
);
1338 Dimension screen_height
= HeightOfScreen (screen
);
1339 Dimension parent_width
= 0;
1340 Dimension parent_height
= 0;
1341 Dimension child_width
= 0;
1342 Dimension child_height
= 0;
1346 XtVaGetValues (widget
, XtNwidth
, &child_width
, XtNheight
, &child_height
, 0);
1347 XtVaGetValues (parent
, XtNwidth
, &parent_width
, XtNheight
, &parent_height
,
1350 x
= (((Position
)parent_width
) - ((Position
)child_width
)) / 2;
1351 y
= (((Position
)parent_height
) - ((Position
)child_height
)) / 2;
1353 XtTranslateCoords (parent
, x
, y
, &x
, &y
);
1355 if (x
+ child_width
> screen_width
)
1356 x
= screen_width
- child_width
;
1360 if (y
+ child_height
> screen_height
)
1361 y
= screen_height
- child_height
;
1365 XtVaSetValues (widget
, XtNx
, x
, XtNy
, y
, 0);
1369 recycle_instance (instance
)
1370 destroyed_instance
* instance
;
1372 Widget widget
= instance
->widget
;
1374 /* widget is NULL if the parent was destroyed. */
1380 /* Remove the destroy callback as the instance is not in the list
1382 XtRemoveCallback (instance
->parent
, XtNdestroyCallback
,
1383 mark_dead_instance_destroyed
,
1384 (XtPointer
)instance
);
1386 /* Give the focus to the initial item */
1387 focus
= XtNameToWidget (widget
, "*value");
1389 focus
= XtNameToWidget (widget
, "*button1");
1391 XtSetKeyboardFocus (widget
, focus
);
1393 /* shrink the separator label back to their original size */
1394 separator
= XtNameToWidget (widget
, "*separator_button");
1396 XtVaSetValues (separator
, XtNwidth
, 5, XtNheight
, 5, 0);
1398 /* Center the dialog in its parent */
1399 recenter_widget (widget
);
1401 free_destroyed_instance (instance
);
1406 xm_create_dialog (instance
)
1407 widget_instance
* instance
;
1409 char* name
= instance
->info
->type
;
1410 Widget parent
= instance
->parent
;
1412 Boolean pop_up_p
= instance
->pop_up_p
;
1413 char* shell_name
= 0;
1415 Boolean text_input_slot
= False
;
1416 Boolean radio_box
= False
;
1417 Boolean list
= False
;
1419 int left_buttons
= 0;
1420 int right_buttons
= 1;
1421 destroyed_instance
* dead_one
;
1423 /* try to find a widget to recycle */
1424 dead_one
= find_matching_instance (instance
);
1427 Widget recycled_widget
= recycle_instance (dead_one
);
1428 if (recycled_widget
)
1429 return recycled_widget
;
1434 icon_name
= "dbox-error";
1435 shell_name
= "Error";
1439 icon_name
= "dbox-info";
1440 shell_name
= "Information";
1445 icon_name
= "dbox-question";
1446 shell_name
= "Prompt";
1450 text_input_slot
= True
;
1451 icon_name
= "dbox-question";
1452 shell_name
= "Prompt";
1456 icon_name
= "dbox-question";
1457 shell_name
= "Question";
1461 total_buttons
= name
[1] - '0';
1463 if (name
[3] == 'T' || name
[3] == 't')
1465 text_input_slot
= False
;
1469 right_buttons
= name
[4] - '0';
1471 left_buttons
= total_buttons
- right_buttons
;
1473 widget
= make_dialog (name
, parent
, pop_up_p
,
1474 shell_name
, icon_name
, text_input_slot
, radio_box
,
1475 list
, left_buttons
, right_buttons
);
1477 XtAddCallback (widget
, XmNpopdownCallback
, xm_nosel_callback
,
1478 (XtPointer
) instance
);
1482 /* Create a menu bar. We turn off the f10 key
1483 because we have not yet managed to make it work right in Motif. */
1486 make_menubar (instance
)
1487 widget_instance
* instance
;
1493 XtSetArg(al
[ac
], XmNmenuAccelerator
, 0); ++ac
;
1496 /* As of 2000-01-17, the LessTif menu bar resizes to height 0 when
1497 all its children are removed, causing an annoying flickering
1498 behavior. Prevent that by not allowing resizing. */
1499 XtSetArg(al
[ac
], XmNresizeHeight
, False
); ++ac
;
1500 XtSetArg(al
[ac
], XmNresizeWidth
, False
); ++ac
;
1503 return XmCreateMenuBar (instance
->parent
, instance
->info
->name
, al
, ac
);
1507 remove_grabs (shell
, closure
, call_data
)
1510 XtPointer call_data
;
1512 Widget menu
= (Widget
) closure
;
1513 XmRemoveFromPostFromList (menu
, XtParent (XtParent (menu
)));
1517 make_popup_menu (instance
)
1518 widget_instance
* instance
;
1520 Widget parent
= instance
->parent
;
1521 Window parent_window
= parent
->core
.window
;
1524 /* sets the parent window to 0 to fool Motif into not generating a grab */
1525 parent
->core
.window
= 0;
1526 result
= XmCreatePopupMenu (parent
, instance
->info
->name
, NULL
, 0);
1527 XtAddCallback (XtParent (result
), XmNpopdownCallback
, remove_grabs
,
1529 parent
->core
.window
= parent_window
;
1534 make_main (instance
)
1535 widget_instance
* instance
;
1537 Widget parent
= instance
->parent
;
1543 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
1544 XtSetArg (al
[ac
], XmNspacing
, 0); ac
++;
1545 result
= XmCreateMainWindow (parent
, instance
->info
->name
, al
, ac
);
1549 \f/* Table of functions to create widgets */
1553 /* interface with the XDesigner generated functions */
1554 typedef Widget (*widget_maker
) (Widget
);
1555 extern Widget
create_project_p_sheet (Widget parent
);
1556 extern Widget
create_debugger_p_sheet (Widget parent
);
1557 extern Widget
create_breaklist_p_sheet (Widget parent
);
1558 extern Widget
create_le_browser_p_sheet (Widget parent
);
1559 extern Widget
create_class_browser_p_sheet (Widget parent
);
1560 extern Widget
create_call_browser_p_sheet (Widget parent
);
1561 extern Widget
create_build_dialog (Widget parent
);
1562 extern Widget
create_editmode_dialog (Widget parent
);
1563 extern Widget
create_search_dialog (Widget parent
);
1564 extern Widget
create_project_display_dialog (Widget parent
);
1567 make_one (widget_instance
* instance
, widget_maker fn
)
1573 if (instance
->pop_up_p
)
1575 XtSetArg (al
[ac
], XmNallowShellResize
, TRUE
); ac
++;
1576 result
= XmCreateDialogShell (instance
->parent
, "dialog", NULL
, 0);
1577 XtAddCallback (result
, XmNpopdownCallback
, &xm_nosel_callback
,
1578 (XtPointer
) instance
);
1583 result
= (*fn
) (instance
->parent
);
1584 XtRealizeWidget (result
);
1590 make_project_p_sheet (widget_instance
* instance
)
1592 return make_one (instance
, create_project_p_sheet
);
1596 make_debugger_p_sheet (widget_instance
* instance
)
1598 return make_one (instance
, create_debugger_p_sheet
);
1602 make_breaklist_p_sheet (widget_instance
* instance
)
1604 return make_one (instance
, create_breaklist_p_sheet
);
1608 make_le_browser_p_sheet (widget_instance
* instance
)
1610 return make_one (instance
, create_le_browser_p_sheet
);
1614 make_class_browser_p_sheet (widget_instance
* instance
)
1616 return make_one (instance
, create_class_browser_p_sheet
);
1620 make_call_browser_p_sheet (widget_instance
* instance
)
1622 return make_one (instance
, create_call_browser_p_sheet
);
1626 make_build_dialog (widget_instance
* instance
)
1628 return make_one (instance
, create_build_dialog
);
1632 make_editmode_dialog (widget_instance
* instance
)
1634 return make_one (instance
, create_editmode_dialog
);
1638 make_search_dialog (widget_instance
* instance
)
1640 return make_one (instance
, create_search_dialog
);
1644 make_project_display_dialog (widget_instance
* instance
)
1646 return make_one (instance
, create_project_display_dialog
);
1649 #endif /* ENERGIZE */
1651 widget_creation_entry
1652 xm_creation_table
[] =
1654 {"menubar", make_menubar
},
1655 {"popup", make_popup_menu
},
1656 {"main", make_main
},
1658 {"project_p_sheet", make_project_p_sheet
},
1659 {"debugger_p_sheet", make_debugger_p_sheet
},
1660 {"breaklist_psheet", make_breaklist_p_sheet
},
1661 {"leb_psheet", make_le_browser_p_sheet
},
1662 {"class_browser_psheet", make_class_browser_p_sheet
},
1663 {"ctree_browser_psheet", make_call_browser_p_sheet
},
1664 {"build", make_build_dialog
},
1665 {"editmode", make_editmode_dialog
},
1666 {"search", make_search_dialog
},
1667 {"project_display", make_project_display_dialog
},
1668 #endif /* ENERGIZE */
1672 \f/* Destruction of instances */
1674 xm_destroy_instance (instance
)
1675 widget_instance
* instance
;
1677 Widget widget
= instance
->widget
;
1678 /* recycle the dialog boxes */
1679 /* Disable the recycling until we can find a way to have the dialog box
1680 get reasonable layout after we modify its contents. */
1682 && XtClass (widget
) == xmDialogShellWidgetClass
)
1684 destroyed_instance
* dead_instance
=
1685 make_destroyed_instance (instance
->info
->name
,
1686 instance
->info
->type
,
1689 instance
->pop_up_p
);
1690 dead_instance
->next
= all_destroyed_instances
;
1691 all_destroyed_instances
= dead_instance
;
1692 XtUnmanageChild (first_child (instance
->widget
));
1693 XFlush (XtDisplay (instance
->widget
));
1694 XtAddCallback (instance
->parent
, XtNdestroyCallback
,
1695 mark_dead_instance_destroyed
, (XtPointer
)dead_instance
);
1699 /* This might not be necessary now that the nosel is attached to
1700 popdown instead of destroy, but it can't hurt. */
1701 XtRemoveCallback (instance
->widget
, XtNdestroyCallback
,
1702 xm_nosel_callback
, (XtPointer
)instance
);
1703 XtDestroyWidget (instance
->widget
);
1707 \f/* popup utility */
1709 xm_popup_menu (widget
, event
)
1713 XButtonPressedEvent dummy
;
1717 dummy
.type
= ButtonPress
;
1719 dummy
.send_event
= 0;
1720 dummy
.display
= XtDisplay (widget
);
1721 dummy
.window
= XtWindow (XtParent (widget
));
1724 XQueryPointer (dummy
.display
, dummy
.window
, &dummy
.root
,
1725 &dummy
.subwindow
, &dummy
.x_root
, &dummy
.y_root
,
1726 &dummy
.x
, &dummy
.y
, &dummy
.state
);
1727 event
= (XEvent
*) &dummy
;
1730 if (event
->type
== ButtonPress
|| event
->type
== ButtonRelease
)
1732 /* This is so totally ridiculous: there's NO WAY to tell Motif
1733 that *any* button can select a menu item. Only one button
1734 can have that honor.
1737 if (event
->xbutton
.state
& Button5Mask
) trans
= "<Btn5Down>";
1738 else if (event
->xbutton
.state
& Button4Mask
) trans
= "<Btn4Down>";
1739 else if (event
->xbutton
.state
& Button3Mask
) trans
= "<Btn3Down>";
1740 else if (event
->xbutton
.state
& Button2Mask
) trans
= "<Btn2Down>";
1741 else if (event
->xbutton
.state
& Button1Mask
) trans
= "<Btn1Down>";
1742 if (trans
) XtVaSetValues (widget
, XmNmenuPost
, trans
, 0);
1743 XmMenuPosition (widget
, (XButtonPressedEvent
*) event
);
1745 XtManageChild (widget
);
1749 set_min_dialog_size (w
)
1754 XtVaGetValues (w
, XmNwidth
, &width
, XmNheight
, &height
, 0);
1755 XtVaSetValues (w
, XmNminWidth
, width
, XmNminHeight
, height
, 0);
1759 xm_pop_instance (instance
, up
)
1760 widget_instance
* instance
;
1763 Widget widget
= instance
->widget
;
1765 if (XtClass (widget
) == xmDialogShellWidgetClass
)
1767 Widget widget_to_manage
= first_child (widget
);
1770 XtManageChild (widget_to_manage
);
1771 set_min_dialog_size (widget
);
1772 XtSetKeyboardFocus (instance
->parent
, widget
);
1775 XtUnmanageChild (widget_to_manage
);
1780 XtManageChild (widget
);
1782 XtUnmanageChild (widget
);
1787 /* motif callback */
1790 do_call (widget
, closure
, type
)
1793 enum do_call_type type
;
1797 XtPointer user_data
;
1798 widget_instance
* instance
= (widget_instance
*)closure
;
1799 Widget instance_widget
;
1804 if (widget
->core
.being_destroyed
)
1807 instance_widget
= instance
->widget
;
1808 if (!instance_widget
)
1811 id
= instance
->info
->id
;
1814 XtSetArg (al
[ac
], XmNuserData
, &user_data
); ac
++;
1815 XtGetValues (widget
, al
, ac
);
1819 if (instance
->info
->pre_activate_cb
)
1820 instance
->info
->pre_activate_cb (widget
, id
, user_data
);
1823 if (instance
->info
->selection_cb
)
1824 instance
->info
->selection_cb (widget
, id
, user_data
);
1827 if (instance
->info
->selection_cb
)
1828 instance
->info
->selection_cb (widget
, id
, (XtPointer
) -1);
1831 if (instance
->info
->post_activate_cb
)
1832 instance
->info
->post_activate_cb (widget
, id
, user_data
);
1839 /* Like lw_internal_update_other_instances except that it does not do
1840 anything if its shell parent is not managed. This is to protect
1841 lw_internal_update_other_instances to dereference freed memory
1842 if the widget was ``destroyed'' by caching it in the all_destroyed_instances
1845 xm_internal_update_other_instances (widget
, closure
, call_data
)
1848 XtPointer call_data
;
1851 for (parent
= widget
; parent
; parent
= XtParent (parent
))
1852 if (XtIsShell (parent
))
1854 else if (!XtIsManaged (parent
))
1856 lw_internal_update_other_instances (widget
, closure
, call_data
);
1860 xm_generic_callback (widget
, closure
, call_data
)
1863 XtPointer call_data
;
1865 lw_internal_update_other_instances (widget
, closure
, call_data
);
1866 do_call (widget
, closure
, selection
);
1870 xm_nosel_callback (widget
, closure
, call_data
)
1873 XtPointer call_data
;
1875 /* This callback is only called when a dialog box is dismissed with the wm's
1876 destroy button (WM_DELETE_WINDOW.) We want the dialog box to be destroyed
1877 in that case, not just unmapped, so that it releases its keyboard grabs.
1878 But there are problems with running our callbacks while the widget is in
1879 the process of being destroyed, so we set XmNdeleteResponse to XmUNMAP
1880 instead of XmDESTROY and then destroy it ourself after having run the
1883 do_call (widget
, closure
, no_selection
);
1884 XtDestroyWidget (widget
);
1888 xm_pull_down_callback (widget
, closure
, call_data
)
1891 XtPointer call_data
;
1893 Widget parent
= XtParent (widget
);
1895 if (XmIsRowColumn (parent
))
1897 unsigned char type
= 0xff;
1898 XtVaGetValues (parent
, XmNrowColumnType
, &type
, NULL
);
1899 if (type
== XmMENU_BAR
)
1900 do_call (widget
, closure
, pre_activate
);
1905 /* XmNpopdownCallback for MenuShell widgets. WIDGET is the MenuShell,
1906 CLOSURE is a pointer to the widget_instance of the shell, CALL_DATA
1907 is always null under LessTif.
1909 2000-01-23: This callback is called for each cascade button in
1910 a menu, whether or not its submenu is visible. */
1913 xm_pop_down_callback (widget
, closure
, call_data
)
1916 XtPointer call_data
;
1918 widget_instance
*instance
= (widget_instance
*) closure
;
1920 if ((!instance
->pop_up_p
&& (XtParent (widget
) == instance
->widget
))
1921 || (XtParent (widget
) == instance
->parent
))
1922 do_call (widget
, closure
, post_activate
);
1926 xm_unmap_callback (widget
, closure
, call_data
)
1929 XtPointer call_data
;
1931 widget_instance
*instance
= (widget_instance
*) closure
;
1932 if (!instance
->pop_up_p
)
1933 do_call (widget
, closure
, post_activate
);
1937 /* set the keyboard focus */
1939 xm_set_keyboard_focus (parent
, w
)
1943 XmProcessTraversal (w
, 0);
1944 XtSetKeyboardFocus (parent
, w
);
1947 /* Motif hack to set the main window areas. */
1949 xm_set_main_areas (parent
, menubar
, work_area
)
1954 XmMainWindowSetAreas (parent
,
1955 menubar
, /* menubar (maybe 0) */
1956 0, /* command area (psheets) */
1957 0, /* horizontal scroll */
1958 0, /* vertical scroll */
1959 work_area
); /* work area */
1962 /* Motif hack to control resizing on the menubar. */
1964 xm_manage_resizing (w
, flag
)
1968 XtVaSetValues (w
, XtNallowShellResize
, flag
, NULL
);