1 /* The lwlib interface to "xlwmenu" menus.
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. */
21 #include "lwlib-Xlw.h"
22 #include <X11/StringDefs.h>
23 #include <X11/IntrinsicP.h>
24 #include <X11/ObjectP.h>
25 #include <X11/CompositeP.h>
26 #include <X11/Shell.h>
29 \f/* Menu callbacks */
31 pre_hook (w
, client_data
, call_data
)
33 XtPointer client_data
;
36 widget_instance
* instance
= (widget_instance
*)client_data
;
39 if (w
->core
.being_destroyed
)
42 val
= lw_get_widget_value_for_widget (instance
, w
);
43 if (instance
->info
->pre_activate_cb
)
44 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
45 val
? val
->call_data
: NULL
);
49 pick_hook (w
, client_data
, call_data
)
51 XtPointer client_data
;
54 widget_instance
* instance
= (widget_instance
*)client_data
;
55 widget_value
* contents_val
= (widget_value
*)call_data
;
56 widget_value
* widget_val
;
59 if (w
->core
.being_destroyed
)
62 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
63 && !contents_val
->contents
)
64 instance
->info
->selection_cb (w
, instance
->info
->id
,
65 contents_val
->call_data
);
67 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
68 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
69 if (instance
->info
->post_activate_cb
)
70 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
74 \f/* creation functions */
77 xlw_create_menubar (instance
)
78 widget_instance
* instance
;
84 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
86 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
87 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
88 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
91 /* This used to use XtVaCreateWidget, but an old Xt version
92 has a bug in XtVaCreateWidget that frees instance->info->name. */
94 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
95 instance
->parent
, al
, ac
);
97 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
98 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
103 xlw_create_popup_menu (instance
)
104 widget_instance
* instance
;
107 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
108 instance
->parent
, NULL
, 0);
114 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
115 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
117 /* This used to use XtVaManagedCreateWidget, but an old Xt version
118 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
120 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
121 popup_shell
, al
, ac
);
123 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
128 widget_creation_entry
129 xlw_creation_table
[] =
131 {"menubar", xlw_create_menubar
},
132 {"popup", xlw_create_popup_menu
},
137 lw_lucid_widget_p (widget
)
140 WidgetClass the_class
= XtClass (widget
);
142 if (the_class
== xlwMenuWidgetClass
)
144 if (the_class
== overrideShellWidgetClass
)
145 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
146 == xlwMenuWidgetClass
);
151 xlw_update_one_widget (instance
, widget
, val
, deep_p
)
152 widget_instance
* instance
;
160 if (XtIsShell (widget
))
161 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
163 mw
= (XlwMenuWidget
)widget
;
165 /* This used to use XtVaSetValues, but some old Xt versions
166 that have a bug in XtVaCreateWidget might have it here too. */
167 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
169 XtSetValues (widget
, al
, 1);
173 xlw_update_one_value (instance
, widget
, val
)
174 widget_instance
* instance
;
182 xlw_pop_instance (instance
, up
)
183 widget_instance
* instance
;
189 xlw_popup_menu (widget
, event
)
193 XButtonPressedEvent dummy
;
196 if (!XtIsShell (widget
))
199 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
202 pop_up_menu (mw
, event
);
205 dummy
.type
= ButtonPress
;
207 dummy
.send_event
= 0;
208 dummy
.display
= XtDisplay (widget
);
209 dummy
.window
= XtWindow (XtParent (widget
));
210 dummy
.time
= CurrentTime
;
212 XQueryPointer (dummy
.display
, dummy
.window
, &dummy
.root
,
213 &dummy
.subwindow
, &dummy
.x_root
, &dummy
.y_root
,
214 &dummy
.x
, &dummy
.y
, &dummy
.state
);
216 pop_up_menu (mw
, &dummy
);
220 \f/* Destruction of instances */
222 xlw_destroy_instance (instance
)
223 widget_instance
* instance
;
225 if (instance
->widget
)
226 XtDestroyWidget (instance
->widget
);