* language/japan-util.el (setup-japanese-environment-internal):
[bpt/emacs.git] / lwlib / lwlib-Xlw.c
CommitLineData
07bf635f
RS
1/* The lwlib interface to "xlwmenu" menus.
2 Copyright (C) 1992 Lucid, Inc.
3
4This file is part of the Lucid Widget Library.
5
6The Lucid Widget Library is free software; you can redistribute it and/or
7modify it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11The Lucid Widget Library is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
07bf635f
RS
20
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"
28
29\f/* Menu callbacks */
30static void
345a94f9
RS
31pre_hook (w, client_data, call_data)
32 Widget w;
33 XtPointer client_data;
34 XtPointer call_data;
07bf635f
RS
35{
36 widget_instance* instance = (widget_instance*)client_data;
37 widget_value* val;
38
39 if (w->core.being_destroyed)
40 return;
41
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);
46}
47
48static void
345a94f9
RS
49pick_hook (w, client_data, call_data)
50 Widget w;
51 XtPointer client_data;
52 XtPointer call_data;
07bf635f
RS
53{
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;
58
59 if (w->core.being_destroyed)
60 return;
61
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);
66
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);
71
72}
73
74\f/* creation functions */
0b96f00b 75
07bf635f 76static Widget
345a94f9
RS
77xlw_create_menubar (instance)
78 widget_instance* instance;
07bf635f 79{
9acc68b1 80 Widget widget;
5acc1a62 81 Arg al[5];
c52de5eb 82 int ac = 0;
9acc68b1 83
c52de5eb 84 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
5acc1a62
PR
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
9acc68b1 90
c52de5eb
RS
91 /* This used to use XtVaCreateWidget, but an old Xt version
92 has a bug in XtVaCreateWidget that frees instance->info->name. */
364e6904 93 widget
c52de5eb
RS
94 = XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
95 instance->parent, al, ac);
19240c20 96
07bf635f
RS
97 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
98 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
99 return widget;
100}
101
102static Widget
345a94f9
RS
103xlw_create_popup_menu (instance)
104 widget_instance* instance;
07bf635f 105{
364e6904
RS
106 Widget popup_shell
107 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
108 instance->parent, NULL, 0);
07bf635f 109
19240c20 110 Widget widget;
c52de5eb
RS
111 Arg al[2];
112 int ac = 0;
19240c20 113
c52de5eb
RS
114 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
115 XtSetArg (al[ac], XtNhorizontal, False); ac++;
19240c20 116
c52de5eb
RS
117 /* This used to use XtVaManagedCreateWidget, but an old Xt version
118 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
364e6904 119 widget
c52de5eb
RS
120 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
121 popup_shell, al, ac);
19240c20 122
07bf635f
RS
123 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
124
125 return popup_shell;
126}
127
128widget_creation_entry
129xlw_creation_table [] =
130{
131 {"menubar", xlw_create_menubar},
132 {"popup", xlw_create_popup_menu},
133 {NULL, NULL}
134};
135
136Boolean
345a94f9
RS
137lw_lucid_widget_p (widget)
138 Widget widget;
07bf635f
RS
139{
140 WidgetClass the_class = XtClass (widget);
364e6904 141
07bf635f
RS
142 if (the_class == xlwMenuWidgetClass)
143 return True;
144 if (the_class == overrideShellWidgetClass)
364e6904
RS
145 return (XtClass (((CompositeWidget)widget)->composite.children [0])
146 == xlwMenuWidgetClass);
07bf635f
RS
147 return False;
148}
149
150void
345a94f9
RS
151xlw_update_one_widget (instance, widget, val, deep_p)
152 widget_instance* instance;
153 Widget widget;
154 widget_value* val;
155 Boolean deep_p;
07bf635f
RS
156{
157 XlwMenuWidget mw;
c52de5eb 158 Arg al[1];
07bf635f
RS
159
160 if (XtIsShell (widget))
161 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
162 else
163 mw = (XlwMenuWidget)widget;
c52de5eb
RS
164
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);
168
169 XtSetValues (widget, al, 1);
07bf635f
RS
170}
171
172void
345a94f9
RS
173xlw_update_one_value (instance, widget, val)
174 widget_instance* instance;
175 Widget widget;
176 widget_value* val;
07bf635f
RS
177{
178 return;
179}
180
181void
345a94f9
RS
182xlw_pop_instance (instance, up)
183 widget_instance* instance;
184 Boolean up;
07bf635f
RS
185{
186}
187
188void
0c7c510c 189xlw_popup_menu (widget, event)
345a94f9 190 Widget widget;
0c7c510c 191 XEvent *event;
07bf635f
RS
192{
193 XButtonPressedEvent dummy;
194 XlwMenuWidget mw;
195
196 if (!XtIsShell (widget))
197 return;
198
199 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
200
0c7c510c
RS
201 if (event)
202 pop_up_menu (mw, event);
203 else
204 {
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);
215
216 pop_up_menu (mw, &dummy);
217 }
07bf635f
RS
218}
219
220\f/* Destruction of instances */
221void
345a94f9
RS
222xlw_destroy_instance (instance)
223 widget_instance* instance;
07bf635f
RS
224{
225 if (instance->widget)
226 XtDestroyWidget (instance->widget);
227}
228