(comment-find): New function.
[emacs.git] / lwlib / lwlib-Xlw.c
blobee6596c27ef0be6fe8c589c2acbeedb28867ee49
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 "lwlib-Xlw.h"
26 #include <X11/StringDefs.h>
27 #include <X11/IntrinsicP.h>
28 #include <X11/ObjectP.h>
29 #include <X11/CompositeP.h>
30 #include <X11/Shell.h>
31 #include "xlwmenu.h"
33 \f/* Menu callbacks */
34 static void
35 pre_hook (w, client_data, call_data)
36 Widget w;
37 XtPointer client_data;
38 XtPointer call_data;
40 widget_instance* instance = (widget_instance*)client_data;
41 widget_value* val;
43 if (w->core.being_destroyed)
44 return;
46 val = lw_get_widget_value_for_widget (instance, w);
47 if (instance->info->pre_activate_cb)
48 instance->info->pre_activate_cb (w, instance->info->id,
49 val ? val->call_data : NULL);
52 static void
53 pick_hook (w, client_data, call_data)
54 Widget w;
55 XtPointer client_data;
56 XtPointer call_data;
58 widget_instance* instance = (widget_instance*)client_data;
59 widget_value* contents_val = (widget_value*)call_data;
60 widget_value* widget_val;
61 XtPointer widget_arg;
63 if (w->core.being_destroyed)
64 return;
66 if (instance->info->selection_cb && contents_val && contents_val->enabled
67 && !contents_val->contents)
68 instance->info->selection_cb (w, instance->info->id,
69 contents_val->call_data);
71 widget_val = lw_get_widget_value_for_widget (instance, w);
72 widget_arg = widget_val ? widget_val->call_data : NULL;
73 if (instance->info->post_activate_cb)
74 instance->info->post_activate_cb (w, instance->info->id, widget_arg);
78 \f/* creation functions */
80 static Widget
81 xlw_create_menubar (instance)
82 widget_instance* instance;
84 Widget widget;
85 Arg al[5];
86 int ac = 0;
88 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
89 #ifdef emacs
90 XtSetArg (al[ac], XtNshowGrip, 0); ac++;
91 XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
92 XtSetArg (al[ac], XtNallowResize, 1); ac++;
93 #endif
95 /* This used to use XtVaCreateWidget, but an old Xt version
96 has a bug in XtVaCreateWidget that frees instance->info->name. */
97 widget
98 = XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
99 instance->parent, al, ac);
101 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
102 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
103 return widget;
106 static Widget
107 xlw_create_popup_menu (instance)
108 widget_instance* instance;
110 Widget popup_shell
111 = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
112 instance->parent, NULL, 0);
114 Widget widget;
115 Arg al[2];
116 int ac = 0;
118 XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
119 XtSetArg (al[ac], XtNhorizontal, False); ac++;
121 /* This used to use XtVaManagedCreateWidget, but an old Xt version
122 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
123 widget
124 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
125 popup_shell, al, ac);
127 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
129 return popup_shell;
132 widget_creation_entry
133 xlw_creation_table [] =
135 {"menubar", xlw_create_menubar},
136 {"popup", xlw_create_popup_menu},
137 {NULL, NULL}
140 Boolean
141 lw_lucid_widget_p (widget)
142 Widget widget;
144 WidgetClass the_class = XtClass (widget);
146 if (the_class == xlwMenuWidgetClass)
147 return True;
148 if (the_class == overrideShellWidgetClass)
149 return (XtClass (((CompositeWidget)widget)->composite.children [0])
150 == xlwMenuWidgetClass);
151 return False;
154 void
155 xlw_update_one_widget (instance, widget, val, deep_p)
156 widget_instance* instance;
157 Widget widget;
158 widget_value* val;
159 Boolean deep_p;
161 XlwMenuWidget mw;
162 Arg al[1];
164 if (XtIsShell (widget))
165 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
166 else
167 mw = (XlwMenuWidget)widget;
169 /* This used to use XtVaSetValues, but some old Xt versions
170 that have a bug in XtVaCreateWidget might have it here too. */
171 XtSetArg (al[0], XtNmenu, instance->info->val);
173 XtSetValues (widget, al, 1);
176 void
177 xlw_update_one_value (instance, widget, val)
178 widget_instance* instance;
179 Widget widget;
180 widget_value* val;
182 return;
185 void
186 xlw_pop_instance (instance, up)
187 widget_instance* instance;
188 Boolean up;
192 void
193 xlw_popup_menu (widget, event)
194 Widget widget;
195 XEvent *event;
197 XButtonPressedEvent dummy;
198 XlwMenuWidget mw;
200 if (!XtIsShell (widget))
201 return;
203 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
205 if (event)
206 pop_up_menu (mw, event);
207 else
209 dummy.type = ButtonPress;
210 dummy.serial = 0;
211 dummy.send_event = 0;
212 dummy.display = XtDisplay (widget);
213 dummy.window = XtWindow (XtParent (widget));
214 dummy.time = CurrentTime;
215 dummy.button = 0;
216 XQueryPointer (dummy.display, dummy.window, &dummy.root,
217 &dummy.subwindow, &dummy.x_root, &dummy.y_root,
218 &dummy.x, &dummy.y, &dummy.state);
220 pop_up_menu (mw, &dummy);
224 \f/* Destruction of instances */
225 void
226 xlw_destroy_instance (instance)
227 widget_instance* instance;
229 if (instance->widget)
230 XtDestroyWidget (instance->widget);