Fix prototypes.
[emacs.git] / lwlib / lwlib-Xlw.c
bloba088b299b8bdd322e825dc5ccb192ba6a1434446
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.
6 This file is part of the Lucid Widget Library.
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.
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.
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. */
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <setjmp.h>
28 #include "lisp.h"
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"
38 #if 0
40 #include <stdio.h>
42 /* Print the complete X resource name of widget WIDGET to stderr.
43 This is sometimes handy to have available. */
45 void
46 x_print_complete_resource_name (widget)
47 Widget widget;
49 int i;
50 String names[100];
52 for (i = 0; i < 100 && widget != NULL; ++i)
54 names[i] = XtName (widget);
55 widget = XtParent (widget);
58 for (--i; i >= 1; --i)
59 fprintf (stderr, "%s.", names[i]);
60 fprintf (stderr, "%s\n", names[0]);
63 #endif /* 0 */
66 \f/* Menu callbacks */
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. */
74 static void
75 highlight_hook (Widget w, XtPointer client_data, 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 enter_hook (Widget w, XtPointer client_data, XtPointer call_data)
87 highlight_hook (w, client_data, call_data);
90 static void
91 leave_hook (Widget w, XtPointer client_data, XtPointer call_data)
93 highlight_hook (w, client_data, NULL);
97 static void
98 pre_hook (Widget w, XtPointer client_data, XtPointer call_data)
100 widget_instance* instance = (widget_instance*)client_data;
101 widget_value* val;
103 if (w->core.being_destroyed)
104 return;
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);
112 static void
113 pick_hook (Widget w, XtPointer client_data, XtPointer call_data)
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;
120 if (w->core.being_destroyed)
121 return;
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);
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);
135 \f/* creation functions */
137 static Widget
138 xlw_create_menubar (widget_instance *instance)
140 Widget widget;
141 Arg al[5];
142 int ac = 0;
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
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);
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;
164 static Widget
165 xlw_create_popup_menu (widget_instance *instance)
167 Widget popup_shell
168 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
169 instance->parent, NULL, 0);
171 Widget widget;
172 Arg al[2];
173 int ac = 0;
175 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
176 XtSetArg (al[ac], XtNhorizontal, False); ac++;
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);
184 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
185 XtAddCallback (widget, XtNleaveCallback, leave_hook, (XtPointer)instance);
186 XtAddCallback (widget, XtNenterCallback, enter_hook, (XtPointer)instance);
188 return popup_shell;
191 widget_creation_entry
192 xlw_creation_table [] =
194 {"menubar", xlw_create_menubar},
195 {"popup", xlw_create_popup_menu},
196 {NULL, NULL}
199 Boolean
200 lw_lucid_widget_p (Widget widget)
202 WidgetClass the_class = XtClass (widget);
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;
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
224 Arg al[1];
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);
230 XtSetValues (widget, al, 1);
233 void
234 xlw_update_one_value (widget_instance *instance, Widget widget, widget_value *val)
236 return;
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
250 void
251 xlw_popup_menu (Widget widget, XEvent *event)
253 XlwMenuWidget mw;
255 if (!XtIsShell (widget))
256 return;
258 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
260 if (event)
261 XtCallActionProc ((Widget) mw, "start", event, NULL, 0);
262 else
264 XEvent dummy;
265 XButtonPressedEvent *bd = &dummy.xbutton;
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);
278 XtCallActionProc ((Widget) mw, "start", &dummy, NULL, 0);
282 \f/* Destruction of instances */
283 void
284 xlw_destroy_instance (widget_instance *instance)
286 if (instance->widget)
287 XtDestroyWidget (instance->widget);
290 /* arch-tag: 541e3912-477d-406e-9bf2-dbf2b7ff8c3b
291 (do not change this comment) */