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