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