Commit | Line | Data |
---|---|---|
07bf635f | 1 | /* The lwlib interface to "xlwmenu" menus. |
67f02b82 GM |
2 | |
3 | Copyright (C) 1992 Lucid, Inc. | |
acaf905b | 4 | Copyright (C) 1994, 2000-2012 Free Software Foundation, Inc. |
07bf635f RS |
5 | |
6 | This file is part of the Lucid Widget Library. | |
7 | ||
177c0ea7 | 8 | The Lucid Widget Library is free software; you can redistribute it and/or |
07bf635f RS |
9 | modify it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 1, or (at your option) | |
11 | any later version. | |
12 | ||
13 | The Lucid Widget Library is distributed in the hope that it will be useful, | |
177c0ea7 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
07bf635f RS |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU Emacs; see the file COPYING. If not, write to | |
364c38d3 LK |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. */ | |
07bf635f | 22 | |
0f0912e6 PE |
23 | #ifdef HAVE_CONFIG_H |
24 | #include <config.h> | |
25 | #endif | |
26 | ||
d7306fe6 | 27 | #include <setjmp.h> |
67f02b82 | 28 | #include <lisp.h> |
2f96293d | 29 | |
07bf635f RS |
30 | #include "lwlib-Xlw.h" |
31 | #include <X11/StringDefs.h> | |
32 | #include <X11/IntrinsicP.h> | |
33 | #include <X11/ObjectP.h> | |
34 | #include <X11/CompositeP.h> | |
35 | #include <X11/Shell.h> | |
36 | #include "xlwmenu.h" | |
37 | ||
d3a785ff GM |
38 | #if 0 |
39 | ||
40 | #include <stdio.h> | |
41 | ||
42 | /* Print the complete X resource name of widget WIDGET to stderr. | |
43 | This is sometimes handy to have available. */ | |
44 | ||
45 | void | |
c825c0b6 | 46 | x_print_complete_resource_name (Widget widget) |
d3a785ff GM |
47 | { |
48 | int i; | |
49 | String names[100]; | |
50 | ||
51 | for (i = 0; i < 100 && widget != NULL; ++i) | |
52 | { | |
53 | names[i] = XtName (widget); | |
54 | widget = XtParent (widget); | |
55 | } | |
56 | ||
57 | for (--i; i >= 1; --i) | |
58 | fprintf (stderr, "%s.", names[i]); | |
59 | fprintf (stderr, "%s\n", names[0]); | |
60 | } | |
61 | ||
62 | #endif /* 0 */ | |
63 | ||
64 | ||
07bf635f | 65 | \f/* Menu callbacks */ |
fa616ec4 GM |
66 | |
67 | /* Callback XtNhighlightCallback for Lucid menus. W is the menu | |
68 | widget, CLIENT_DATA contains a pointer to the widget_instance | |
69 | for the menu, CALL_DATA contains a pointer to the widget_value | |
70 | structure for the highlighted menu item. The latter may be null | |
71 | if there isn't any highlighted menu item. */ | |
72 | ||
73 | static void | |
c3174d16 | 74 | highlight_hook (Widget w, XtPointer client_data, XtPointer call_data) |
fa616ec4 GM |
75 | { |
76 | widget_instance *instance = (widget_instance *) client_data; | |
77 | ||
78 | if (instance->info->highlight_cb | |
79 | && !w->core.being_destroyed) | |
80 | instance->info->highlight_cb (w, instance->info->id, call_data); | |
81 | } | |
82 | ||
3fcd0186 | 83 | static void |
c3174d16 | 84 | enter_hook (Widget w, XtPointer client_data, XtPointer call_data) |
3fcd0186 JD |
85 | { |
86 | highlight_hook (w, client_data, call_data); | |
87 | } | |
88 | ||
89 | static void | |
c3174d16 | 90 | leave_hook (Widget w, XtPointer client_data, XtPointer call_data) |
3fcd0186 JD |
91 | { |
92 | highlight_hook (w, client_data, NULL); | |
93 | } | |
94 | ||
95 | ||
07bf635f | 96 | static void |
c3174d16 | 97 | pre_hook (Widget w, XtPointer client_data, XtPointer call_data) |
07bf635f RS |
98 | { |
99 | widget_instance* instance = (widget_instance*)client_data; | |
100 | widget_value* val; | |
101 | ||
102 | if (w->core.being_destroyed) | |
103 | return; | |
104 | ||
105 | val = lw_get_widget_value_for_widget (instance, w); | |
106 | if (instance->info->pre_activate_cb) | |
107 | instance->info->pre_activate_cb (w, instance->info->id, | |
108 | val ? val->call_data : NULL); | |
109 | } | |
110 | ||
111 | static void | |
c3174d16 | 112 | pick_hook (Widget w, XtPointer client_data, XtPointer call_data) |
07bf635f RS |
113 | { |
114 | widget_instance* instance = (widget_instance*)client_data; | |
115 | widget_value* contents_val = (widget_value*)call_data; | |
116 | widget_value* widget_val; | |
117 | XtPointer widget_arg; | |
118 | ||
119 | if (w->core.being_destroyed) | |
120 | return; | |
121 | ||
122 | if (instance->info->selection_cb && contents_val && contents_val->enabled | |
123 | && !contents_val->contents) | |
124 | instance->info->selection_cb (w, instance->info->id, | |
125 | contents_val->call_data); | |
126 | ||
127 | widget_val = lw_get_widget_value_for_widget (instance, w); | |
128 | widget_arg = widget_val ? widget_val->call_data : NULL; | |
129 | if (instance->info->post_activate_cb) | |
130 | instance->info->post_activate_cb (w, instance->info->id, widget_arg); | |
131 | ||
132 | } | |
133 | ||
134 | \f/* creation functions */ | |
0b96f00b | 135 | |
07bf635f | 136 | static Widget |
c3174d16 | 137 | xlw_create_menubar (widget_instance *instance) |
07bf635f | 138 | { |
9acc68b1 | 139 | Widget widget; |
5acc1a62 | 140 | Arg al[5]; |
c52de5eb | 141 | int ac = 0; |
9acc68b1 | 142 | |
c52de5eb | 143 | XtSetArg (al[ac], XtNmenu, instance->info->val); ac++; |
5acc1a62 PR |
144 | #ifdef emacs |
145 | XtSetArg (al[ac], XtNshowGrip, 0); ac++; | |
146 | XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++; | |
147 | XtSetArg (al[ac], XtNallowResize, 1); ac++; | |
148 | #endif | |
9acc68b1 | 149 | |
c52de5eb RS |
150 | /* This used to use XtVaCreateWidget, but an old Xt version |
151 | has a bug in XtVaCreateWidget that frees instance->info->name. */ | |
364e6904 | 152 | widget |
c52de5eb RS |
153 | = XtCreateWidget (instance->info->name, xlwMenuWidgetClass, |
154 | instance->parent, al, ac); | |
19240c20 | 155 | |
07bf635f RS |
156 | XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance); |
157 | XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance); | |
3fcd0186 JD |
158 | XtAddCallback (widget, XtNleaveCallback, leave_hook, (XtPointer)instance); |
159 | XtAddCallback (widget, XtNenterCallback, enter_hook, (XtPointer)instance); | |
07bf635f RS |
160 | return widget; |
161 | } | |
162 | ||
163 | static Widget | |
c3174d16 | 164 | xlw_create_popup_menu (widget_instance *instance) |
07bf635f | 165 | { |
364e6904 RS |
166 | Widget popup_shell |
167 | = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass, | |
168 | instance->parent, NULL, 0); | |
177c0ea7 | 169 | |
19240c20 | 170 | Widget widget; |
c52de5eb RS |
171 | Arg al[2]; |
172 | int ac = 0; | |
19240c20 | 173 | |
c52de5eb RS |
174 | XtSetArg (al[ac], XtNmenu, instance->info->val); ac++; |
175 | XtSetArg (al[ac], XtNhorizontal, False); ac++; | |
19240c20 | 176 | |
c52de5eb RS |
177 | /* This used to use XtVaManagedCreateWidget, but an old Xt version |
178 | has a bug in XtVaManagedCreateWidget that frees instance->info->name. */ | |
364e6904 | 179 | widget |
c52de5eb RS |
180 | = XtCreateManagedWidget ("popup", xlwMenuWidgetClass, |
181 | popup_shell, al, ac); | |
19240c20 | 182 | |
07bf635f | 183 | XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance); |
3fcd0186 JD |
184 | XtAddCallback (widget, XtNleaveCallback, leave_hook, (XtPointer)instance); |
185 | XtAddCallback (widget, XtNenterCallback, enter_hook, (XtPointer)instance); | |
244c93fe | 186 | |
07bf635f RS |
187 | return popup_shell; |
188 | } | |
189 | ||
177c0ea7 | 190 | widget_creation_entry |
07bf635f RS |
191 | xlw_creation_table [] = |
192 | { | |
193 | {"menubar", xlw_create_menubar}, | |
194 | {"popup", xlw_create_popup_menu}, | |
195 | {NULL, NULL} | |
196 | }; | |
197 | ||
198 | Boolean | |
c3174d16 | 199 | lw_lucid_widget_p (Widget widget) |
07bf635f RS |
200 | { |
201 | WidgetClass the_class = XtClass (widget); | |
364e6904 | 202 | |
07bf635f RS |
203 | if (the_class == xlwMenuWidgetClass) |
204 | return True; | |
205 | if (the_class == overrideShellWidgetClass) | |
364e6904 RS |
206 | return (XtClass (((CompositeWidget)widget)->composite.children [0]) |
207 | == xlwMenuWidgetClass); | |
07bf635f RS |
208 | return False; |
209 | } | |
210 | ||
211 | void | |
e226063c DL |
212 | xlw_update_one_widget (widget_instance* instance, Widget widget, |
213 | widget_value* val, Boolean deep_p) | |
07bf635f | 214 | { |
c52de5eb | 215 | Arg al[1]; |
07bf635f | 216 | |
c52de5eb RS |
217 | /* This used to use XtVaSetValues, but some old Xt versions |
218 | that have a bug in XtVaCreateWidget might have it here too. */ | |
219 | XtSetArg (al[0], XtNmenu, instance->info->val); | |
220 | ||
221 | XtSetValues (widget, al, 1); | |
07bf635f RS |
222 | } |
223 | ||
224 | void | |
c825c0b6 J |
225 | xlw_update_one_value (widget_instance *instance, |
226 | Widget widget, | |
227 | widget_value *val) | |
07bf635f RS |
228 | { |
229 | return; | |
230 | } | |
231 | ||
232 | void | |
e226063c | 233 | xlw_pop_instance (widget_instance* instance, Boolean up) |
07bf635f RS |
234 | { |
235 | } | |
236 | ||
237 | void | |
c3174d16 | 238 | xlw_popup_menu (Widget widget, XEvent *event) |
07bf635f | 239 | { |
07bf635f RS |
240 | XlwMenuWidget mw; |
241 | ||
242 | if (!XtIsShell (widget)) | |
243 | return; | |
244 | ||
245 | mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0]; | |
246 | ||
0c7c510c | 247 | if (event) |
244c93fe | 248 | XtCallActionProc ((Widget) mw, "start", event, NULL, 0); |
0c7c510c RS |
249 | else |
250 | { | |
244c93fe JD |
251 | XEvent dummy; |
252 | XButtonPressedEvent *bd = &dummy.xbutton; | |
253 | ||
254 | bd->type = ButtonPress; | |
255 | bd->serial = 0; | |
256 | bd->send_event = 0; | |
257 | bd->display = XtDisplay (widget); | |
258 | bd->window = XtWindow (XtParent (widget)); | |
259 | bd->time = CurrentTime; | |
260 | bd->button = 0; | |
261 | XQueryPointer (bd->display, bd->window, &bd->root, | |
262 | &bd->subwindow, &bd->x_root, &bd->y_root, | |
263 | &bd->x, &bd->y, &bd->state); | |
264 | ||
265 | XtCallActionProc ((Widget) mw, "start", &dummy, NULL, 0); | |
0c7c510c | 266 | } |
07bf635f RS |
267 | } |
268 | ||
269 | \f/* Destruction of instances */ | |
270 | void | |
c3174d16 | 271 | xlw_destroy_instance (widget_instance *instance) |
07bf635f RS |
272 | { |
273 | if (instance->widget) | |
274 | XtDestroyWidget (instance->widget); | |
275 | } |