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