0
|
1 /* The lwlib interface to "xlwmenu" menus.
|
|
2 Copyright (C) 1992, 1994 Lucid, Inc.
|
|
3
|
|
4 This file is part of the Lucid Widget Library.
|
|
5
|
|
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 2, or (at your option)
|
|
9 any later version.
|
|
10
|
|
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.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
80
|
17 along with XEmacs; see the file COPYING. If not, write to
|
78
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
0
|
20
|
157
|
21 #include <config.h>
|
0
|
22 #include <stdlib.h> /* for abort () */
|
157
|
23 #ifdef HAVE_LIMITS_H
|
0
|
24 #include <limits.h>
|
157
|
25 #endif
|
0
|
26
|
|
27 #include "lwlib-Xlw.h"
|
|
28 #include <X11/StringDefs.h>
|
|
29 #include <X11/IntrinsicP.h>
|
|
30 #include <X11/ObjectP.h>
|
|
31 #include <X11/CompositeP.h>
|
|
32 #include <X11/Shell.h>
|
|
33 #ifdef MENUBARS_LUCID
|
|
34 #include "xlwmenu.h"
|
|
35 #endif
|
|
36 #ifdef SCROLLBARS_LUCID
|
|
37 #include "xlwscrollbar.h"
|
|
38 #endif
|
|
39
|
|
40
|
|
41
|
|
42 #ifdef MENUBARS_LUCID
|
|
43
|
|
44 /* Menu callbacks */
|
|
45
|
|
46 static void
|
|
47 pre_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
|
48 {
|
|
49 widget_instance* instance = (widget_instance*)client_data;
|
|
50 widget_value* val;
|
|
51
|
|
52 if (w->core.being_destroyed)
|
|
53 return;
|
|
54
|
|
55 val = lw_get_widget_value_for_widget (instance, w);
|
|
56 #if 0
|
|
57 /* #### - this code used to (for some random back_asswards reason) pass
|
|
58 the expression below in the call_data slot. For incremental menu
|
|
59 construction, this needs to go. I can't even figure out why it was done
|
78
|
60 this way in the first place...it's just a historical weirdism. --Stig */
|
0
|
61 call_data = (val ? val->call_data : NULL);
|
|
62 #endif
|
|
63 if (val && val->call_data)
|
|
64 abort(); /* #### - the call_data for the top_level
|
|
65 "menubar" widget_value used to be passed
|
|
66 back to the pre_hook. */
|
|
67
|
|
68 if (instance->info->pre_activate_cb)
|
|
69 instance->info->pre_activate_cb (w, instance->info->id, call_data);
|
|
70 }
|
|
71
|
|
72 static void
|
|
73 pick_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
|
74 {
|
|
75 widget_instance* instance = (widget_instance*)client_data;
|
|
76 widget_value* contents_val = (widget_value*)call_data;
|
|
77 widget_value* widget_val;
|
|
78 XtPointer widget_arg;
|
|
79 LWLIB_ID id;
|
|
80 lw_callback post_activate_cb;
|
|
81
|
|
82 if (w->core.being_destroyed)
|
|
83 return;
|
|
84
|
|
85 /* Grab these values before running any functions, in case running
|
|
86 the selection_cb causes the widget to be destroyed. */
|
|
87 id = instance->info->id;
|
|
88 post_activate_cb = instance->info->post_activate_cb;
|
|
89
|
|
90 widget_val = lw_get_widget_value_for_widget (instance, w);
|
|
91 widget_arg = widget_val ? widget_val->call_data : NULL;
|
|
92
|
|
93 if (instance->info->selection_cb &&
|
|
94 contents_val &&
|
|
95 contents_val->enabled &&
|
|
96 !contents_val->contents)
|
|
97 instance->info->selection_cb (w, id, contents_val->call_data);
|
|
98
|
|
99 if (post_activate_cb)
|
|
100 post_activate_cb (w, id, widget_arg);
|
|
101 }
|
|
102
|
|
103
|
|
104
|
|
105 /* creation functions */
|
|
106 static Widget
|
|
107 xlw_create_menubar (widget_instance* instance)
|
|
108 {
|
165
|
109 Arg al [1];
|
|
110 Widget widget;
|
|
111
|
|
112 XtSetArg (al [0], XtNmenu, instance->info->val);
|
|
113 widget = XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
|
|
114 instance->parent, al, 1);
|
80
|
115 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
|
0
|
116 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
|
|
117 return widget;
|
|
118 }
|
|
119
|
|
120 static Widget
|
|
121 xlw_create_popup_menu (widget_instance* instance)
|
|
122 {
|
165
|
123 Arg al [2];
|
|
124 Widget popup_shell, widget;
|
0
|
125
|
165
|
126 popup_shell = XtCreatePopupShell (instance->info->name,
|
|
127 overrideShellWidgetClass,
|
|
128 instance->parent, NULL, 0);
|
|
129 XtSetArg (al [0], XtNmenu, instance->info->val);
|
|
130 XtSetArg (al [1], XtNhorizontal, False);
|
|
131 widget = XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
|
|
132 popup_shell, al, 2);
|
0
|
133 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
|
|
134
|
|
135 return popup_shell;
|
|
136 }
|
|
137 #endif /* MENUBARS_LUCID */
|
|
138
|
|
139 #ifdef SCROLLBARS_LUCID
|
|
140 static void
|
|
141 xlw_scrollbar_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
142 {
|
|
143 widget_instance *instance = (widget_instance *) closure;
|
|
144 LWLIB_ID id;
|
|
145 XlwScrollBarCallbackStruct *data =
|
|
146 (XlwScrollBarCallbackStruct *) call_data;
|
|
147 scroll_event event_data;
|
|
148 scrollbar_values *val =
|
|
149 (scrollbar_values *) instance->info->val->scrollbar_data;
|
|
150 double percent;
|
|
151
|
|
152 if (!instance || widget->core.being_destroyed)
|
|
153 return;
|
|
154
|
|
155 id = instance->info->id;
|
|
156
|
|
157 percent = (double) (data->value - 1) / (double) (INT_MAX - 1);
|
|
158 event_data.slider_value =
|
|
159 (int) (percent * (double) (val->maximum - val->minimum)) + val->minimum;
|
|
160
|
80
|
161 if (event_data.slider_value > val->maximum - val->slider_size)
|
|
162 event_data.slider_value = val->maximum - val->slider_size;
|
0
|
163 else if (event_data.slider_value < val->minimum)
|
80
|
164 event_data.slider_value = val->minimum;
|
0
|
165
|
|
166 if (data->event)
|
|
167 {
|
78
|
168 switch (data->event->type)
|
0
|
169 {
|
|
170 case KeyPress:
|
|
171 case KeyRelease:
|
|
172 event_data.time = data->event->xkey.time;
|
|
173 break;
|
|
174 case ButtonPress:
|
|
175 case ButtonRelease:
|
|
176 event_data.time = data->event->xbutton.time;
|
|
177 break;
|
|
178 case MotionNotify:
|
|
179 event_data.time = data->event->xmotion.time;
|
|
180 break;
|
|
181 case EnterNotify:
|
|
182 case LeaveNotify:
|
|
183 event_data.time = data->event->xcrossing.time;
|
|
184 break;
|
|
185 default:
|
|
186 event_data.time = 0;
|
|
187 break;
|
|
188 }
|
|
189 }
|
|
190 else
|
|
191 event_data.time = 0;
|
|
192
|
|
193 switch (data->reason)
|
|
194 {
|
80
|
195 case XmCR_DECREMENT: event_data.action = SCROLLBAR_LINE_UP; break;
|
|
196 case XmCR_INCREMENT: event_data.action = SCROLLBAR_LINE_DOWN; break;
|
|
197 case XmCR_PAGE_DECREMENT: event_data.action = SCROLLBAR_PAGE_UP; break;
|
|
198 case XmCR_PAGE_INCREMENT: event_data.action = SCROLLBAR_PAGE_DOWN; break;
|
|
199 case XmCR_TO_TOP: event_data.action = SCROLLBAR_TOP; break;
|
|
200 case XmCR_TO_BOTTOM: event_data.action = SCROLLBAR_BOTTOM; break;
|
|
201 case XmCR_DRAG: event_data.action = SCROLLBAR_DRAG; break;
|
|
202 case XmCR_VALUE_CHANGED: event_data.action = SCROLLBAR_CHANGE; break;
|
|
203 default: event_data.action = SCROLLBAR_CHANGE; break;
|
0
|
204 }
|
|
205
|
|
206 if (instance->info->pre_activate_cb)
|
|
207 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
208 }
|
|
209
|
78
|
210 #define add_scrollbar_callback(resource) \
|
|
211 XtAddCallback (scrollbar, resource, xlw_scrollbar_callback, (XtPointer) instance)
|
|
212
|
0
|
213 /* #### Does not yet support horizontal scrollbars. */
|
|
214 static Widget
|
|
215 xlw_create_scrollbar (widget_instance *instance, int vertical)
|
|
216 {
|
|
217 Arg al[20];
|
|
218 int ac = 0;
|
78
|
219 static XtCallbackRec callbacks[2] =
|
|
220 { {xlw_scrollbar_callback, NULL}, {NULL, NULL} };
|
|
221
|
|
222 callbacks[0].closure = (XtPointer) instance;
|
0
|
223
|
78
|
224 XtSetArg (al[ac], XmNminimum, 1); ac++;
|
|
225 XtSetArg (al[ac], XmNmaximum, INT_MAX); ac++;
|
|
226 XtSetArg (al[ac], XmNincrement, 1); ac++;
|
|
227 XtSetArg (al[ac], XmNpageIncrement, 1); ac++;
|
|
228 XtSetArg (al[ac], XmNorientation, (vertical ? XmVERTICAL : XmHORIZONTAL)); ac++;
|
0
|
229
|
78
|
230 XtSetArg (al[ac], XmNdecrementCallback, callbacks); ac++;
|
|
231 XtSetArg (al[ac], XmNdragCallback, callbacks); ac++;
|
|
232 XtSetArg (al[ac], XmNincrementCallback, callbacks); ac++;
|
|
233 XtSetArg (al[ac], XmNpageDecrementCallback, callbacks); ac++;
|
|
234 XtSetArg (al[ac], XmNpageIncrementCallback, callbacks); ac++;
|
|
235 XtSetArg (al[ac], XmNtoBottomCallback, callbacks); ac++;
|
|
236 XtSetArg (al[ac], XmNtoTopCallback, callbacks); ac++;
|
|
237 XtSetArg (al[ac], XmNvalueChangedCallback, callbacks); ac++;
|
0
|
238
|
78
|
239 return XtCreateWidget (instance->info->name, xlwScrollBarWidgetClass,
|
|
240 instance->parent, al, ac);
|
0
|
241 }
|
|
242
|
|
243 static Widget
|
|
244 xlw_create_vertical_scrollbar (widget_instance *instance)
|
|
245 {
|
|
246 return xlw_create_scrollbar (instance, 1);
|
|
247 }
|
|
248
|
|
249 static Widget
|
|
250 xlw_create_horizontal_scrollbar (widget_instance *instance)
|
|
251 {
|
|
252 return xlw_create_scrollbar (instance, 0);
|
|
253 }
|
|
254
|
|
255 static void
|
|
256 xlw_update_scrollbar (widget_instance *instance, Widget widget,
|
|
257 widget_value *val)
|
|
258 {
|
|
259 if (val->scrollbar_data)
|
|
260 {
|
|
261 scrollbar_values *data = val->scrollbar_data;
|
|
262 int widget_sliderSize, widget_val;
|
|
263 int new_sliderSize, new_value;
|
|
264 double percent;
|
165
|
265 Arg al [4];
|
0
|
266
|
78
|
267 /* First size and position the scrollbar widget. */
|
165
|
268 XtSetArg (al [0], XtNx, data->scrollbar_x);
|
|
269 XtSetArg (al [1], XtNy, data->scrollbar_y);
|
|
270 XtSetArg (al [2], XtNwidth, data->scrollbar_width);
|
|
271 XtSetArg (al [3], XtNheight, data->scrollbar_height);
|
|
272 XtSetValues (widget, al, 4);
|
0
|
273
|
80
|
274 /* Now size the scrollbar's slider. */
|
165
|
275 XtSetArg (al [0], XmNsliderSize, &widget_sliderSize);
|
|
276 XtSetArg (al [1], XmNvalue, &widget_val);
|
|
277 XtGetValues (widget, al, 2);
|
0
|
278
|
|
279 percent = (double) data->slider_size /
|
|
280 (double) (data->maximum - data->minimum);
|
|
281 percent = (percent > 1.0 ? 1.0 : percent);
|
|
282 new_sliderSize = (int) ((double) (INT_MAX - 1) * percent);
|
|
283
|
|
284 percent = (double) (data->slider_position - data->minimum) /
|
|
285 (double) (data->maximum - data->minimum);
|
|
286 percent = (percent > 1.0 ? 1.0 : percent);
|
|
287 new_value = (int) ((double) (INT_MAX - 1) * percent);
|
|
288
|
80
|
289 if (new_sliderSize > INT_MAX - 1)
|
165
|
290 new_sliderSize = INT_MAX - 1;
|
|
291 else if (new_sliderSize < 1)
|
|
292 new_sliderSize = 1;
|
0
|
293
|
|
294 if (new_value > (INT_MAX - new_sliderSize))
|
165
|
295 new_value = INT_MAX - new_sliderSize;
|
0
|
296 else if (new_value < 1)
|
165
|
297 new_value = 1;
|
0
|
298
|
|
299 if (new_sliderSize != widget_sliderSize || new_value != widget_val)
|
|
300 XlwScrollBarSetValues (widget, new_value, new_sliderSize, 1, 1, False);
|
|
301 }
|
|
302 }
|
|
303
|
|
304 #endif /* SCROLLBARS_LUCID */
|
|
305
|
|
306 widget_creation_entry
|
|
307 xlw_creation_table [] =
|
|
308 {
|
|
309 #ifdef MENUBARS_LUCID
|
|
310 {"menubar", xlw_create_menubar},
|
|
311 {"popup", xlw_create_popup_menu},
|
|
312 #endif
|
|
313 #ifdef SCROLLBARS_LUCID
|
|
314 {"vertical-scrollbar", xlw_create_vertical_scrollbar},
|
|
315 {"horizontal-scrollbar", xlw_create_horizontal_scrollbar},
|
|
316 #endif
|
|
317 {NULL, NULL}
|
|
318 };
|
|
319
|
|
320 Boolean
|
|
321 lw_lucid_widget_p (Widget widget)
|
|
322 {
|
|
323 WidgetClass the_class = XtClass (widget);
|
|
324 #ifdef MENUBARS_LUCID
|
|
325 if (the_class == xlwMenuWidgetClass)
|
|
326 return True;
|
|
327 #endif
|
|
328 #ifdef SCROLLBARS_LUCID
|
|
329 if (the_class == xlwScrollBarWidgetClass)
|
|
330 return True;
|
|
331 #endif
|
|
332 #ifdef MENUBARS_LUCID
|
|
333 if (the_class == overrideShellWidgetClass)
|
|
334 return
|
|
335 XtClass (((CompositeWidget)widget)->composite.children [0])
|
|
336 == xlwMenuWidgetClass;
|
|
337 #endif
|
|
338 return False;
|
|
339 }
|
|
340
|
|
341 void
|
|
342 xlw_update_one_widget (widget_instance* instance, Widget widget,
|
|
343 widget_value* val, Boolean deep_p)
|
|
344 {
|
|
345 WidgetClass class;
|
|
346
|
|
347 class = XtClass (widget);
|
|
348
|
|
349 if (0)
|
|
350 ;
|
|
351 #ifdef MENUBARS_LUCID
|
|
352 else if (class == xlwMenuWidgetClass)
|
|
353 {
|
|
354 XlwMenuWidget mw;
|
165
|
355 Arg al [1];
|
0
|
356 if (XtIsShell (widget))
|
|
357 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
|
|
358 else
|
|
359 mw = (XlwMenuWidget)widget;
|
165
|
360 XtSetArg (al [0], XtNmenu, val);
|
|
361 XtSetValues (widget, al, 1);
|
0
|
362 }
|
|
363 #endif
|
|
364 #ifdef SCROLLBARS_LUCID
|
|
365 else if (class == xlwScrollBarWidgetClass)
|
|
366 {
|
|
367 xlw_update_scrollbar (instance, widget, val);
|
|
368 }
|
|
369 #endif
|
|
370 }
|
|
371
|
|
372 void
|
|
373 xlw_update_one_value (widget_instance* instance, Widget widget,
|
|
374 widget_value* val)
|
|
375 {
|
|
376 return;
|
|
377 }
|
|
378
|
|
379 void
|
|
380 xlw_pop_instance (widget_instance* instance, Boolean up)
|
|
381 {
|
|
382 }
|
|
383
|
|
384 #ifdef MENUBARS_LUCID
|
|
385 void
|
|
386 xlw_popup_menu (Widget widget, XEvent *event)
|
|
387 {
|
|
388 XlwMenuWidget mw;
|
|
389
|
|
390 if (!XtIsShell (widget))
|
|
391 return;
|
|
392
|
|
393 if (event->type == ButtonPress || event->type == ButtonRelease)
|
|
394 {
|
|
395 mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
|
|
396 xlw_pop_up_menu (mw, (XButtonPressedEvent *)event);
|
|
397 }
|
|
398 else
|
|
399 abort ();
|
|
400 }
|
|
401 #endif
|
|
402
|
|
403 /* Destruction of instances */
|
|
404 void
|
|
405 xlw_destroy_instance (widget_instance* instance)
|
|
406 {
|
|
407 if (instance->widget)
|
|
408 XtDestroyWidget (instance->widget);
|
|
409 }
|