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