Fix misspelling of utf-fragment-on-decoding.
[emacs.git] / lwlib / lwlib-Xlw.c
blobcc1e8f7890f9c788555ba4c00a0eb361ad01dbe5
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 "../src/lisp.h"
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"
35 #if 0
37 #include <stdio.h>
39 /* Print the complete X resource name of widget WIDGET to stderr.
40 This is sometimes handy to have available. */
42 void
43 x_print_complete_resource_name (widget)
44 Widget widget;
46 int i;
47 String names[100];
49 for (i = 0; i < 100 && widget != NULL; ++i)
51 names[i] = XtName (widget);
52 widget = XtParent (widget);
55 for (--i; i >= 1; --i)
56 fprintf (stderr, "%s.", names[i]);
57 fprintf (stderr, "%s\n", names[0]);
60 #endif /* 0 */
63 \f/* Menu callbacks */
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. */
71 static void
72 highlight_hook (w, client_data, call_data)
73 Widget w;
74 XtPointer client_data;
75 XtPointer call_data;
77 widget_instance *instance = (widget_instance *) client_data;
79 if (instance->info->highlight_cb
80 && !w->core.being_destroyed)
81 instance->info->highlight_cb (w, instance->info->id, call_data);
84 static void
85 pre_hook (w, client_data, call_data)
86 Widget w;
87 XtPointer client_data;
88 XtPointer call_data;
90 widget_instance* instance = (widget_instance*)client_data;
91 widget_value* val;
93 if (w->core.being_destroyed)
94 return;
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);
102 static void
103 pick_hook (w, client_data, call_data)
104 Widget w;
105 XtPointer client_data;
106 XtPointer call_data;
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;
113 if (w->core.being_destroyed)
114 return;
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);
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);
128 \f/* creation functions */
130 static Widget
131 xlw_create_menubar (instance)
132 widget_instance* instance;
134 Widget widget;
135 Arg al[5];
136 int ac = 0;
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
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);
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;
158 static Widget
159 xlw_create_popup_menu (instance)
160 widget_instance* instance;
162 Widget popup_shell
163 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
164 instance->parent, NULL, 0);
166 Widget widget;
167 Arg al[2];
168 int ac = 0;
170 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
171 XtSetArg (al[ac], XtNhorizontal, False); ac++;
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);
179 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
180 XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
181 (XtPointer)instance);
182 return popup_shell;
185 widget_creation_entry
186 xlw_creation_table [] =
188 {"menubar", xlw_create_menubar},
189 {"popup", xlw_create_popup_menu},
190 {NULL, NULL}
193 Boolean
194 lw_lucid_widget_p (widget)
195 Widget widget;
197 WidgetClass the_class = XtClass (widget);
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;
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;
214 XlwMenuWidget mw;
215 Arg al[1];
217 if (XtIsShell (widget))
218 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
219 else
220 mw = (XlwMenuWidget)widget;
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);
226 XtSetValues (widget, al, 1);
229 void
230 xlw_update_one_value (instance, widget, val)
231 widget_instance* instance;
232 Widget widget;
233 widget_value* val;
235 return;
238 void
239 xlw_pop_instance (instance, up)
240 widget_instance* instance;
241 Boolean up;
245 void
246 xlw_popup_menu (widget, event)
247 Widget widget;
248 XEvent *event;
250 XButtonPressedEvent dummy;
251 XlwMenuWidget mw;
253 if (!XtIsShell (widget))
254 return;
256 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
258 if (event)
259 pop_up_menu (mw, (XButtonPressedEvent*) event);
260 else
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);
273 pop_up_menu (mw, &dummy);
277 \f/* Destruction of instances */
278 void
279 xlw_destroy_instance (instance)
280 widget_instance* instance;
282 if (instance->widget)
283 XtDestroyWidget (instance->widget);