]> code.delx.au - gnu-emacs/blob - lwlib/lwlib-Xlw.c
(xlwmenu_window_p): New function.
[gnu-emacs] / lwlib / lwlib-Xlw.c
1 /* The lwlib interface to "xlwmenu" menus.
2 Copyright (C) 1992 Lucid, Inc.
3
4 This file is part of the Lucid Widget Library.
5
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)
9 any later version.
10
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.
15
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. */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include "lwlib-Xlw.h"
26 #include <X11/StringDefs.h>
27 #include <X11/IntrinsicP.h>
28 #include <X11/ObjectP.h>
29 #include <X11/CompositeP.h>
30 #include <X11/Shell.h>
31 #include "xlwmenu.h"
32
33 #if 0
34
35 #include <stdio.h>
36
37 /* Print the complete X resource name of widget WIDGET to stderr.
38 This is sometimes handy to have available. */
39
40 void
41 x_print_complete_resource_name (widget)
42 Widget widget;
43 {
44 int i;
45 String names[100];
46
47 for (i = 0; i < 100 && widget != NULL; ++i)
48 {
49 names[i] = XtName (widget);
50 widget = XtParent (widget);
51 }
52
53 for (--i; i >= 1; --i)
54 fprintf (stderr, "%s.", names[i]);
55 fprintf (stderr, "%s\n", names[0]);
56 }
57
58 #endif /* 0 */
59
60
61 \f/* Menu callbacks */
62
63 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
64 widget, CLIENT_DATA contains a pointer to the widget_instance
65 for the menu, CALL_DATA contains a pointer to the widget_value
66 structure for the highlighted menu item. The latter may be null
67 if there isn't any highlighted menu item. */
68
69 static void
70 highlight_hook (w, client_data, call_data)
71 Widget w;
72 XtPointer client_data;
73 XtPointer call_data;
74 {
75 widget_instance *instance = (widget_instance *) client_data;
76
77 if (instance->info->highlight_cb
78 && !w->core.being_destroyed)
79 instance->info->highlight_cb (w, instance->info->id, call_data);
80 }
81
82 static void
83 pre_hook (w, client_data, call_data)
84 Widget w;
85 XtPointer client_data;
86 XtPointer call_data;
87 {
88 widget_instance* instance = (widget_instance*)client_data;
89 widget_value* val;
90
91 if (w->core.being_destroyed)
92 return;
93
94 val = lw_get_widget_value_for_widget (instance, w);
95 if (instance->info->pre_activate_cb)
96 instance->info->pre_activate_cb (w, instance->info->id,
97 val ? val->call_data : NULL);
98 }
99
100 static void
101 pick_hook (w, client_data, call_data)
102 Widget w;
103 XtPointer client_data;
104 XtPointer call_data;
105 {
106 widget_instance* instance = (widget_instance*)client_data;
107 widget_value* contents_val = (widget_value*)call_data;
108 widget_value* widget_val;
109 XtPointer widget_arg;
110
111 if (w->core.being_destroyed)
112 return;
113
114 if (instance->info->selection_cb && contents_val && contents_val->enabled
115 && !contents_val->contents)
116 instance->info->selection_cb (w, instance->info->id,
117 contents_val->call_data);
118
119 widget_val = lw_get_widget_value_for_widget (instance, w);
120 widget_arg = widget_val ? widget_val->call_data : NULL;
121 if (instance->info->post_activate_cb)
122 instance->info->post_activate_cb (w, instance->info->id, widget_arg);
123
124 }
125
126 \f/* creation functions */
127
128 static Widget
129 xlw_create_menubar (instance)
130 widget_instance* instance;
131 {
132 Widget widget;
133 Arg al[5];
134 int ac = 0;
135
136 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
137 #ifdef emacs
138 XtSetArg (al[ac], XtNshowGrip, 0); ac++;
139 XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
140 XtSetArg (al[ac], XtNallowResize, 1); ac++;
141 #endif
142
143 /* This used to use XtVaCreateWidget, but an old Xt version
144 has a bug in XtVaCreateWidget that frees instance->info->name. */
145 widget
146 = XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
147 instance->parent, al, ac);
148
149 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
150 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
151 XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
152 (XtPointer)instance);
153 return widget;
154 }
155
156 static Widget
157 xlw_create_popup_menu (instance)
158 widget_instance* instance;
159 {
160 Widget popup_shell
161 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
162 instance->parent, NULL, 0);
163
164 Widget widget;
165 Arg al[2];
166 int ac = 0;
167
168 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
169 XtSetArg (al[ac], XtNhorizontal, False); ac++;
170
171 /* This used to use XtVaManagedCreateWidget, but an old Xt version
172 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
173 widget
174 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
175 popup_shell, al, ac);
176
177 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
178 XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
179 (XtPointer)instance);
180 return popup_shell;
181 }
182
183 widget_creation_entry
184 xlw_creation_table [] =
185 {
186 {"menubar", xlw_create_menubar},
187 {"popup", xlw_create_popup_menu},
188 {NULL, NULL}
189 };
190
191 Boolean
192 lw_lucid_widget_p (widget)
193 Widget widget;
194 {
195 WidgetClass the_class = XtClass (widget);
196
197 if (the_class == xlwMenuWidgetClass)
198 return True;
199 if (the_class == overrideShellWidgetClass)
200 return (XtClass (((CompositeWidget)widget)->composite.children [0])
201 == xlwMenuWidgetClass);
202 return False;
203 }
204
205 void
206 xlw_update_one_widget (instance, widget, val, deep_p)
207 widget_instance* instance;
208 Widget widget;
209 widget_value* val;
210 Boolean deep_p;
211 {
212 XlwMenuWidget mw;
213 Arg al[1];
214
215 if (XtIsShell (widget))
216 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
217 else
218 mw = (XlwMenuWidget)widget;
219
220 /* This used to use XtVaSetValues, but some old Xt versions
221 that have a bug in XtVaCreateWidget might have it here too. */
222 XtSetArg (al[0], XtNmenu, instance->info->val);
223
224 XtSetValues (widget, al, 1);
225 }
226
227 void
228 xlw_update_one_value (instance, widget, val)
229 widget_instance* instance;
230 Widget widget;
231 widget_value* val;
232 {
233 return;
234 }
235
236 void
237 xlw_pop_instance (instance, up)
238 widget_instance* instance;
239 Boolean up;
240 {
241 }
242
243 void
244 xlw_popup_menu (widget, event)
245 Widget widget;
246 XEvent *event;
247 {
248 XButtonPressedEvent dummy;
249 XlwMenuWidget mw;
250
251 if (!XtIsShell (widget))
252 return;
253
254 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
255
256 if (event)
257 pop_up_menu (mw, (XButtonPressedEvent*) event);
258 else
259 {
260 dummy.type = ButtonPress;
261 dummy.serial = 0;
262 dummy.send_event = 0;
263 dummy.display = XtDisplay (widget);
264 dummy.window = XtWindow (XtParent (widget));
265 dummy.time = CurrentTime;
266 dummy.button = 0;
267 XQueryPointer (dummy.display, dummy.window, &dummy.root,
268 &dummy.subwindow, &dummy.x_root, &dummy.y_root,
269 &dummy.x, &dummy.y, &dummy.state);
270
271 pop_up_menu (mw, &dummy);
272 }
273 }
274
275 \f/* Destruction of instances */
276 void
277 xlw_destroy_instance (instance)
278 widget_instance* instance;
279 {
280 if (instance->widget)
281 XtDestroyWidget (instance->widget);
282 }
283