(rmail-reply): Don't forget to narrow header in
[emacs.git] / lwlib / lwlib-Xlw.c
blob7a56559577469f6d2f32ae754039e480033d8e6c
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)
9 any later version.
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 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
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"
33 #if 0
35 #include <stdio.h>
37 /* Print the complete X resource name of widget WIDGET to stderr.
38 This is sometimes handy to have available. */
40 void
41 x_print_complete_resource_name (widget)
42 Widget widget;
44 int i;
45 String names[100];
47 for (i = 0; i < 100 && widget != NULL; ++i)
49 names[i] = XtName (widget);
50 widget = XtParent (widget);
53 for (--i; i >= 1; --i)
54 fprintf (stderr, "%s.", names[i]);
55 fprintf (stderr, "%s\n", names[0]);
58 #endif /* 0 */
61 \f/* Menu callbacks */
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. */
69 static void
70 highlight_hook (w, client_data, call_data)
71 Widget w;
72 XtPointer client_data;
73 XtPointer call_data;
75 widget_instance *instance = (widget_instance *) client_data;
77 if (instance->info->highlight_cb
78 && !w->core.being_destroyed)
79 instance->info->highlight_cb (w, instance->info->id, call_data);
82 static void
83 pre_hook (w, client_data, call_data)
84 Widget w;
85 XtPointer client_data;
86 XtPointer call_data;
88 widget_instance* instance = (widget_instance*)client_data;
89 widget_value* val;
91 if (w->core.being_destroyed)
92 return;
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);
100 static void
101 pick_hook (w, client_data, call_data)
102 Widget w;
103 XtPointer client_data;
104 XtPointer call_data;
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;
111 if (w->core.being_destroyed)
112 return;
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);
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);
126 \f/* creation functions */
128 static Widget
129 xlw_create_menubar (instance)
130 widget_instance* instance;
132 Widget widget;
133 Arg al[5];
134 int ac = 0;
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
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);
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;
156 static Widget
157 xlw_create_popup_menu (instance)
158 widget_instance* instance;
160 Widget popup_shell
161 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
162 instance->parent, NULL, 0);
164 Widget widget;
165 Arg al[2];
166 int ac = 0;
168 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
169 XtSetArg (al[ac], XtNhorizontal, False); ac++;
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);
177 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
178 XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
179 (XtPointer)instance);
180 return popup_shell;
183 widget_creation_entry
184 xlw_creation_table [] =
186 {"menubar", xlw_create_menubar},
187 {"popup", xlw_create_popup_menu},
188 {NULL, NULL}
191 Boolean
192 lw_lucid_widget_p (widget)
193 Widget widget;
195 WidgetClass the_class = XtClass (widget);
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;
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;
212 XlwMenuWidget mw;
213 Arg al[1];
215 if (XtIsShell (widget))
216 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
217 else
218 mw = (XlwMenuWidget)widget;
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);
224 XtSetValues (widget, al, 1);
227 void
228 xlw_update_one_value (instance, widget, val)
229 widget_instance* instance;
230 Widget widget;
231 widget_value* val;
233 return;
236 void
237 xlw_pop_instance (instance, up)
238 widget_instance* instance;
239 Boolean up;
243 void
244 xlw_popup_menu (widget, event)
245 Widget widget;
246 XEvent *event;
248 XButtonPressedEvent dummy;
249 XlwMenuWidget mw;
251 if (!XtIsShell (widget))
252 return;
254 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
256 if (event)
257 pop_up_menu (mw, (XButtonPressedEvent*) event);
258 else
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);
271 pop_up_menu (mw, &dummy);
275 \f/* Destruction of instances */
276 void
277 xlw_destroy_instance (instance)
278 widget_instance* instance;
280 if (instance->widget)
281 XtDestroyWidget (instance->widget);