Changes which are not mine:
[emacs.git] / lwlib / lwlib-Xlw.c
bloba927d40bf25fd82ed60fffbf00a772b44d77a8c2
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 #include "lwlib-Xlw.h"
22 #include <X11/StringDefs.h>
23 #include <X11/IntrinsicP.h>
24 #include <X11/ObjectP.h>
25 #include <X11/CompositeP.h>
26 #include <X11/Shell.h>
27 #include "xlwmenu.h"
29 \f/* Menu callbacks */
30 static void
31 pre_hook (w, client_data, call_data)
32 Widget w;
33 XtPointer client_data;
34 XtPointer call_data;
36 widget_instance* instance = (widget_instance*)client_data;
37 widget_value* val;
39 if (w->core.being_destroyed)
40 return;
42 val = lw_get_widget_value_for_widget (instance, w);
43 if (instance->info->pre_activate_cb)
44 instance->info->pre_activate_cb (w, instance->info->id,
45 val ? val->call_data : NULL);
48 static void
49 pick_hook (w, client_data, call_data)
50 Widget w;
51 XtPointer client_data;
52 XtPointer call_data;
54 widget_instance* instance = (widget_instance*)client_data;
55 widget_value* contents_val = (widget_value*)call_data;
56 widget_value* widget_val;
57 XtPointer widget_arg;
59 if (w->core.being_destroyed)
60 return;
62 if (instance->info->selection_cb && contents_val && contents_val->enabled
63 && !contents_val->contents)
64 instance->info->selection_cb (w, instance->info->id,
65 contents_val->call_data);
67 widget_val = lw_get_widget_value_for_widget (instance, w);
68 widget_arg = widget_val ? widget_val->call_data : NULL;
69 if (instance->info->post_activate_cb)
70 instance->info->post_activate_cb (w, instance->info->id, widget_arg);
74 \f/* creation functions */
76 static Widget
77 xlw_create_menubar (instance)
78 widget_instance* instance;
80 Widget widget;
81 Arg al[5];
82 int ac = 0;
84 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
85 #ifdef emacs
86 XtSetArg (al[ac], XtNshowGrip, 0); ac++;
87 XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
88 XtSetArg (al[ac], XtNallowResize, 1); ac++;
89 #endif
91 /* This used to use XtVaCreateWidget, but an old Xt version
92 has a bug in XtVaCreateWidget that frees instance->info->name. */
93 widget
94 = XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
95 instance->parent, al, ac);
97 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
98 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
99 return widget;
102 static Widget
103 xlw_create_popup_menu (instance)
104 widget_instance* instance;
106 Widget popup_shell
107 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
108 instance->parent, NULL, 0);
110 Widget widget;
111 Arg al[2];
112 int ac = 0;
114 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
115 XtSetArg (al[ac], XtNhorizontal, False); ac++;
117 /* This used to use XtVaManagedCreateWidget, but an old Xt version
118 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
119 widget
120 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
121 popup_shell, al, ac);
123 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
125 return popup_shell;
128 widget_creation_entry
129 xlw_creation_table [] =
131 {"menubar", xlw_create_menubar},
132 {"popup", xlw_create_popup_menu},
133 {NULL, NULL}
136 Boolean
137 lw_lucid_widget_p (widget)
138 Widget widget;
140 WidgetClass the_class = XtClass (widget);
142 if (the_class == xlwMenuWidgetClass)
143 return True;
144 if (the_class == overrideShellWidgetClass)
145 return (XtClass (((CompositeWidget)widget)->composite.children [0])
146 == xlwMenuWidgetClass);
147 return False;
150 void
151 xlw_update_one_widget (instance, widget, val, deep_p)
152 widget_instance* instance;
153 Widget widget;
154 widget_value* val;
155 Boolean deep_p;
157 XlwMenuWidget mw;
158 Arg al[1];
160 if (XtIsShell (widget))
161 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
162 else
163 mw = (XlwMenuWidget)widget;
165 /* This used to use XtVaSetValues, but some old Xt versions
166 that have a bug in XtVaCreateWidget might have it here too. */
167 XtSetArg (al[0], XtNmenu, instance->info->val);
169 XtSetValues (widget, al, 1);
172 void
173 xlw_update_one_value (instance, widget, val)
174 widget_instance* instance;
175 Widget widget;
176 widget_value* val;
178 return;
181 void
182 xlw_pop_instance (instance, up)
183 widget_instance* instance;
184 Boolean up;
188 void
189 xlw_popup_menu (widget, event)
190 Widget widget;
191 XEvent *event;
193 XButtonPressedEvent dummy;
194 XlwMenuWidget mw;
196 if (!XtIsShell (widget))
197 return;
199 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
201 if (event)
202 pop_up_menu (mw, event);
203 else
205 dummy.type = ButtonPress;
206 dummy.serial = 0;
207 dummy.send_event = 0;
208 dummy.display = XtDisplay (widget);
209 dummy.window = XtWindow (XtParent (widget));
210 dummy.time = CurrentTime;
211 dummy.button = 0;
212 XQueryPointer (dummy.display, dummy.window, &dummy.root,
213 &dummy.subwindow, &dummy.x_root, &dummy.y_root,
214 &dummy.x, &dummy.y, &dummy.state);
216 pop_up_menu (mw, &dummy);
220 \f/* Destruction of instances */
221 void
222 xlw_destroy_instance (instance)
223 widget_instance* instance;
225 if (instance->widget)
226 XtDestroyWidget (instance->widget);