0
|
1 /* The lwlib interface to Athena widgets.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, 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 1, 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 <stdio.h>
|
|
23
|
163
|
24 #ifdef STDC_HEADERS
|
|
25 #include <stdlib.h>
|
|
26 #endif
|
|
27
|
0
|
28 #include "lwlib-Xaw.h"
|
|
29
|
|
30 #include <X11/StringDefs.h>
|
|
31 #include <X11/IntrinsicP.h>
|
|
32 #include <X11/CoreP.h>
|
|
33 #include <X11/Shell.h>
|
|
34
|
|
35 #ifdef SCROLLBARS_ATHENA
|
|
36 #include <X11/Xaw/Scrollbar.h>
|
|
37 #endif
|
|
38 #ifdef DIALOGS_ATHENA
|
|
39 #include <X11/Xaw/Dialog.h>
|
|
40 #include <X11/Xaw/Form.h>
|
|
41 #include <X11/Xaw/Command.h>
|
|
42 #include <X11/Xaw/Label.h>
|
|
43 #endif
|
|
44
|
|
45 #include <X11/Xatom.h>
|
|
46
|
|
47 static void xaw_generic_callback (Widget, XtPointer, XtPointer);
|
|
48
|
|
49
|
|
50 Boolean
|
|
51 lw_xaw_widget_p (Widget widget)
|
|
52 {
|
|
53 return (0
|
|
54 #ifdef SCROLLBARS_ATHENA
|
|
55 || XtIsSubclass (widget, scrollbarWidgetClass)
|
|
56 #endif
|
|
57 #ifdef DIALOGS_ATHENA
|
|
58 || XtIsSubclass (widget, dialogWidgetClass)
|
|
59 #endif
|
|
60 );
|
|
61 }
|
|
62
|
|
63 #ifdef SCROLLBARS_ATHENA
|
|
64 static void
|
|
65 xaw_update_scrollbar (widget_instance *instance, Widget widget,
|
|
66 widget_value *val)
|
|
67 {
|
|
68 if (val->scrollbar_data)
|
|
69 {
|
|
70 scrollbar_values *data = val->scrollbar_data;
|
|
71 float widget_shown, widget_topOfThumb;
|
|
72 float new_shown, new_topOfThumb;
|
165
|
73 Arg al [10];
|
0
|
74
|
165
|
75 /* First size and position the scrollbar widget. */
|
|
76 XtSetArg (al [0], XtNx, data->scrollbar_x);
|
|
77 XtSetArg (al [1], XtNy, data->scrollbar_y);
|
|
78 XtSetArg (al [2], XtNwidth, data->scrollbar_width);
|
|
79 XtSetArg (al [3], XtNheight, data->scrollbar_height);
|
|
80 XtSetValues (widget, al, 4);
|
0
|
81
|
165
|
82 /* Now size the scrollbar's slider. */
|
|
83 XtSetArg (al [0], XtNtopOfThumb, &widget_topOfThumb);
|
|
84 XtSetArg (al [1], XtNshown, &widget_shown);
|
|
85 XtGetValues (widget, al, 2);
|
0
|
86
|
|
87 new_shown = (double) data->slider_size /
|
|
88 (double) (data->maximum - data->minimum);
|
|
89
|
|
90 new_topOfThumb = (double) (data->slider_position - data->minimum) /
|
|
91 (double) (data->maximum - data->minimum);
|
|
92
|
|
93 if (new_shown > 1.0)
|
|
94 new_shown = 1.0;
|
165
|
95 else if (new_shown < 0)
|
0
|
96 new_shown = 0;
|
|
97
|
|
98 if (new_topOfThumb > 1.0)
|
|
99 new_topOfThumb = 1.0;
|
165
|
100 else if (new_topOfThumb < 0)
|
0
|
101 new_topOfThumb = 0;
|
|
102
|
|
103 if (new_shown != widget_shown || new_topOfThumb != widget_topOfThumb)
|
|
104 XawScrollbarSetThumb (widget, new_topOfThumb, new_shown);
|
|
105 }
|
|
106 }
|
|
107 #endif /* SCROLLBARS_ATHENA */
|
|
108
|
|
109 void
|
|
110 xaw_update_one_widget (widget_instance *instance, Widget widget,
|
|
111 widget_value *val, Boolean deep_p)
|
|
112 {
|
|
113 if (0)
|
|
114 ;
|
|
115 #ifdef SCROLLBARS_ATHENA
|
|
116 else if (XtIsSubclass (widget, scrollbarWidgetClass))
|
|
117 {
|
|
118 xaw_update_scrollbar (instance, widget, val);
|
|
119 }
|
|
120 #endif
|
|
121 #ifdef DIALOGS_ATHENA
|
|
122 else if (XtIsSubclass (widget, dialogWidgetClass))
|
|
123 {
|
165
|
124 Arg al [1];
|
|
125 XtSetArg (al [0], XtNlabel, val->contents->value);
|
|
126 XtSetValues (widget, al, 1);
|
0
|
127 }
|
|
128 else if (XtIsSubclass (widget, commandWidgetClass))
|
|
129 {
|
|
130 Dimension bw = 0;
|
165
|
131 Arg al [3];
|
|
132 XtSetArg (al [0], XtNborderWidth, &bw);
|
|
133 XtGetValues (widget, al, 1);
|
82
|
134
|
|
135 #ifndef LWLIB_DIALOGS_ATHENA3D
|
0
|
136 if (bw == 0)
|
|
137 /* Don't let buttons end up with 0 borderwidth, that's ugly...
|
|
138 Yeah, all this should really be done through app-defaults files
|
|
139 or fallback resources, but that's a whole different can of worms
|
|
140 that I don't feel like opening right now. Making Athena widgets
|
|
141 not look like shit is just entirely too much work.
|
|
142 */
|
165
|
143 {
|
|
144 XtSetArg (al [0], XtNborderWidth, 1);
|
|
145 XtSetValues (widget, al, 1);
|
|
146 }
|
82
|
147 #endif
|
0
|
148
|
165
|
149 XtSetArg (al [0], XtNlabel, val->value);
|
|
150 XtSetArg (al [1], XtNsensitive, val->enabled);
|
|
151 /* Force centered button text. See above. */
|
|
152 XtSetArg (al [2], XtNjustify, XtJustifyCenter);
|
|
153 XtSetValues (widget, al, 3);
|
0
|
154
|
|
155 XtRemoveAllCallbacks (widget, XtNcallback);
|
|
156 XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance);
|
|
157 }
|
|
158 #endif
|
|
159 }
|
|
160
|
|
161 void
|
|
162 xaw_update_one_value (widget_instance *instance, Widget widget,
|
|
163 widget_value *val)
|
|
164 {
|
|
165 /* This function is not used by the scrollbars and those are the only
|
|
166 Athena widget implemented at the moment so do nothing. */
|
|
167 return;
|
|
168 }
|
|
169
|
|
170 void
|
|
171 xaw_destroy_instance (widget_instance *instance)
|
|
172 {
|
|
173 #ifdef DIALOGS_ATHENA
|
|
174 if (XtIsSubclass (instance->widget, dialogWidgetClass))
|
|
175 /* Need to destroy the Shell too. */
|
|
176 XtDestroyWidget (XtParent (instance->widget));
|
|
177 else
|
|
178 #endif
|
|
179 XtDestroyWidget (instance->widget);
|
|
180 }
|
|
181
|
|
182 void
|
|
183 xaw_popup_menu (Widget widget, XEvent *event)
|
|
184 {
|
|
185 /* An Athena menubar has not been implemented. */
|
|
186 return;
|
|
187 }
|
|
188
|
|
189 void
|
|
190 xaw_pop_instance (widget_instance *instance, Boolean up)
|
|
191 {
|
|
192 Widget widget = instance->widget;
|
|
193
|
|
194 if (up)
|
|
195 {
|
|
196 #ifdef DIALOGS_ATHENA
|
|
197 if (XtIsSubclass (widget, dialogWidgetClass))
|
|
198 {
|
|
199 /* For dialogs, we need to call XtPopup on the parent instead
|
|
200 of calling XtManageChild on the widget.
|
|
201 Also we need to hack the shell's WM_PROTOCOLS to get it to
|
|
202 understand what the close box is supposed to do!!
|
|
203 */
|
|
204 Display *dpy = XtDisplay (widget);
|
|
205 Widget shell = XtParent (widget);
|
|
206 Atom props [2];
|
|
207 int i = 0;
|
|
208 props [i++] = XInternAtom (dpy, "WM_DELETE_WINDOW", False);
|
|
209 XChangeProperty (dpy, XtWindow (shell),
|
|
210 XInternAtom (dpy, "WM_PROTOCOLS", False),
|
|
211 XA_ATOM, 32, PropModeAppend,
|
|
212 (unsigned char *) props, i);
|
|
213
|
|
214 /* Center the widget in its parent. Why isn't this kind of crap
|
|
215 done automatically? I thought toolkits were supposed to make
|
|
216 life easier?
|
|
217 */
|
|
218 {
|
|
219 unsigned int x, y, w, h;
|
|
220 Widget topmost = instance->parent;
|
|
221 w = shell->core.width;
|
|
222 h = shell->core.height;
|
|
223 while (topmost->core.parent && XtIsRealized (topmost->core.parent))
|
|
224 topmost = topmost->core.parent;
|
|
225 if (topmost->core.width < w) x = topmost->core.x;
|
|
226 else x = topmost->core.x + ((topmost->core.width - w) / 2);
|
|
227 if (topmost->core.height < h) y = topmost->core.y;
|
|
228 else y = topmost->core.y + ((topmost->core.height - h) / 2);
|
|
229 XtMoveWidget (shell, x, y);
|
|
230 }
|
|
231
|
|
232 /* Finally, pop it up. */
|
|
233 XtPopup (shell, XtGrabNonexclusive);
|
|
234 }
|
|
235 else
|
|
236 #endif /* DIALOGS_ATHENA */
|
|
237 XtManageChild (widget);
|
|
238 }
|
|
239 else
|
|
240 {
|
|
241 #ifdef DIALOGS_ATHENA
|
|
242 if (XtIsSubclass (widget, dialogWidgetClass))
|
|
243 XtUnmanageChild (XtParent (widget));
|
|
244 else
|
|
245 #endif
|
|
246 XtUnmanageChild (widget);
|
|
247 }
|
|
248 }
|
|
249
|
|
250
|
|
251 #ifdef DIALOGS_ATHENA
|
|
252 /* Dialog boxes */
|
|
253
|
|
254 static char overrideTrans[] =
|
|
255 "<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
|
|
256 static XtActionProc wm_delete_window (Widget shell, XtPointer closure,
|
|
257 XtPointer call_data);
|
|
258 static XtActionsRec xaw_actions [] = {
|
|
259 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window}
|
|
260 };
|
|
261 static Boolean actions_initted = False;
|
|
262
|
|
263 static Widget
|
|
264 make_dialog (CONST char* name, Widget parent, Boolean pop_up_p,
|
|
265 CONST char* shell_title, CONST char* icon_name,
|
|
266 Boolean text_input_slot,
|
|
267 Boolean radio_box, Boolean list,
|
|
268 int left_buttons, int right_buttons)
|
|
269 {
|
|
270 Arg av [20];
|
|
271 int ac = 0;
|
|
272 int i, bc;
|
|
273 char button_name [255];
|
|
274 Widget shell;
|
|
275 Widget dialog;
|
|
276 Widget button;
|
|
277 XtTranslations override;
|
|
278
|
|
279 if (! pop_up_p) abort (); /* not implemented */
|
|
280 if (text_input_slot) abort (); /* not implemented */
|
|
281 if (radio_box) abort (); /* not implemented */
|
|
282 if (list) abort (); /* not implemented */
|
|
283
|
|
284 if (! actions_initted)
|
|
285 {
|
|
286 XtAppContext app = XtWidgetToApplicationContext (parent);
|
|
287 XtAppAddActions (app, xaw_actions,
|
|
288 sizeof (xaw_actions) / sizeof (xaw_actions[0]));
|
|
289 actions_initted = True;
|
|
290 }
|
|
291
|
|
292 override = XtParseTranslationTable (overrideTrans);
|
|
293
|
|
294 ac = 0;
|
80
|
295 XtSetArg (av[ac], XtNtitle, shell_title); ac++;
|
0
|
296 XtSetArg (av[ac], XtNallowShellResize, True); ac++;
|
80
|
297 XtSetArg (av[ac], XtNtransientFor, parent); ac++;
|
0
|
298 shell = XtCreatePopupShell ("dialog", transientShellWidgetClass,
|
|
299 parent, av, ac);
|
|
300 XtOverrideTranslations (shell, override);
|
|
301
|
|
302 ac = 0;
|
|
303 dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac);
|
|
304
|
|
305 bc = 0;
|
|
306 button = 0;
|
|
307 for (i = 0; i < left_buttons; i++)
|
|
308 {
|
|
309 ac = 0;
|
80
|
310 XtSetArg (av [ac], XtNfromHoriz, button); ac++;
|
|
311 XtSetArg (av [ac], XtNleft, XtChainLeft); ac++;
|
|
312 XtSetArg (av [ac], XtNright, XtChainLeft); ac++;
|
|
313 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
|
0
|
314 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
|
80
|
315 XtSetArg (av [ac], XtNresizable, True); ac++;
|
0
|
316 sprintf (button_name, "button%d", ++bc);
|
|
317 button = XtCreateManagedWidget (button_name, commandWidgetClass,
|
|
318 dialog, av, ac);
|
|
319 }
|
|
320 if (right_buttons)
|
|
321 {
|
|
322 /* Create a separator
|
|
323
|
|
324 I want the separator to take up the slack between the buttons on
|
|
325 the right and the buttons on the left (that is I want the buttons
|
|
326 after the separator to be packed against the right edge of the
|
|
327 window) but I can't seem to make it do it.
|
|
328 */
|
|
329 ac = 0;
|
80
|
330 XtSetArg (av [ac], XtNfromHoriz, button); ac++;
|
0
|
331 /* XtSetArg (av [ac], XtNfromVert, XtNameToWidget (dialog, "label")); ac++; */
|
80
|
332 XtSetArg (av [ac], XtNleft, XtChainLeft); ac++;
|
|
333 XtSetArg (av [ac], XtNright, XtChainRight); ac++;
|
|
334 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
|
0
|
335 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
|
|
336 XtSetArg (av [ac], XtNlabel, ""); ac++;
|
|
337 XtSetArg (av [ac], XtNwidth, 30); ac++; /* #### aaack!! */
|
|
338 XtSetArg (av [ac], XtNborderWidth, 0); ac++;
|
|
339 XtSetArg (av [ac], XtNshapeStyle, XmuShapeRectangle); ac++;
|
|
340 XtSetArg (av [ac], XtNresizable, False); ac++;
|
|
341 XtSetArg (av [ac], XtNsensitive, False); ac++;
|
|
342 button = XtCreateManagedWidget ("separator",
|
|
343 /* labelWidgetClass, */
|
|
344 /* This has to be Command to fake out
|
|
345 the Dialog widget... */
|
|
346 commandWidgetClass,
|
|
347 dialog, av, ac);
|
|
348 }
|
|
349 for (i = 0; i < right_buttons; i++)
|
|
350 {
|
|
351 ac = 0;
|
80
|
352 XtSetArg (av [ac], XtNfromHoriz, button); ac++;
|
|
353 XtSetArg (av [ac], XtNleft, XtChainRight); ac++;
|
|
354 XtSetArg (av [ac], XtNright, XtChainRight); ac++;
|
|
355 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
|
0
|
356 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
|
80
|
357 XtSetArg (av [ac], XtNresizable, True); ac++;
|
0
|
358 sprintf (button_name, "button%d", ++bc);
|
|
359 button = XtCreateManagedWidget (button_name, commandWidgetClass,
|
|
360 dialog, av, ac);
|
|
361 }
|
|
362
|
|
363 return dialog;
|
|
364 }
|
|
365
|
|
366 Widget
|
|
367 xaw_create_dialog (widget_instance* instance)
|
|
368 {
|
|
369 char *name = instance->info->type;
|
|
370 Widget parent = instance->parent;
|
|
371 Widget widget;
|
|
372 Boolean pop_up_p = instance->pop_up_p;
|
|
373 CONST char *shell_name = 0;
|
|
374 CONST char *icon_name = 0;
|
|
375 Boolean text_input_slot = False;
|
|
376 Boolean radio_box = False;
|
|
377 Boolean list = False;
|
|
378 int total_buttons;
|
|
379 int left_buttons = 0;
|
|
380 int right_buttons = 1;
|
|
381
|
|
382 switch (name [0]) {
|
|
383 case 'E': case 'e':
|
|
384 icon_name = "dbox-error";
|
|
385 shell_name = "Error";
|
|
386 break;
|
|
387
|
|
388 case 'I': case 'i':
|
|
389 icon_name = "dbox-info";
|
|
390 shell_name = "Information";
|
|
391 break;
|
|
392
|
|
393 case 'L': case 'l':
|
|
394 list = True;
|
|
395 icon_name = "dbox-question";
|
|
396 shell_name = "Prompt";
|
|
397 break;
|
|
398
|
|
399 case 'P': case 'p':
|
|
400 text_input_slot = True;
|
|
401 icon_name = "dbox-question";
|
|
402 shell_name = "Prompt";
|
|
403 break;
|
|
404
|
|
405 case 'Q': case 'q':
|
|
406 icon_name = "dbox-question";
|
|
407 shell_name = "Question";
|
|
408 break;
|
|
409 }
|
|
410
|
|
411 total_buttons = name [1] - '0';
|
|
412
|
|
413 if (name [3] == 'T' || name [3] == 't')
|
|
414 {
|
|
415 text_input_slot = False;
|
|
416 radio_box = True;
|
|
417 }
|
|
418 else if (name [3])
|
|
419 right_buttons = name [4] - '0';
|
|
420
|
|
421 left_buttons = total_buttons - right_buttons;
|
|
422
|
|
423 widget = make_dialog (name, parent, pop_up_p,
|
|
424 shell_name, icon_name, text_input_slot, radio_box,
|
|
425 list, left_buttons, right_buttons);
|
|
426
|
|
427 return widget;
|
|
428 }
|
|
429 #endif /* DIALOGS_ATHENA */
|
|
430
|
|
431
|
|
432 static void
|
|
433 xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
434 {
|
|
435 widget_instance *instance = (widget_instance *) closure;
|
|
436 Widget instance_widget;
|
|
437 LWLIB_ID id;
|
|
438 XtPointer user_data;
|
|
439
|
|
440 lw_internal_update_other_instances (widget, closure, call_data);
|
|
441
|
|
442 if (! instance)
|
|
443 return;
|
|
444 if (widget->core.being_destroyed)
|
|
445 return;
|
|
446
|
|
447 instance_widget = instance->widget;
|
|
448 if (!instance_widget)
|
|
449 return;
|
|
450
|
|
451 id = instance->info->id;
|
|
452
|
|
453 #if 0
|
|
454 user_data = NULL;
|
165
|
455 {
|
|
456 Arg al [1];
|
|
457 XtSetArg (al [0], XtNuserData, &user_data);
|
|
458 XtGetValues (widget, al, 1);
|
|
459 }
|
0
|
460 #else
|
|
461 /* Damn! Athena doesn't give us a way to hang our own data on the
|
|
462 buttons, so we have to go find it... I guess this assumes that
|
|
463 all instances of a button have the same call data. */
|
|
464 {
|
|
465 widget_value *val = instance->info->val->contents;
|
|
466 char *name = XtName (widget);
|
|
467 while (val)
|
|
468 {
|
|
469 if (val->name && !strcmp (val->name, name))
|
|
470 break;
|
|
471 val = val->next;
|
|
472 }
|
|
473 if (! val) abort ();
|
|
474 user_data = val->call_data;
|
|
475 }
|
|
476 #endif
|
|
477
|
|
478 if (instance->info->selection_cb)
|
|
479 instance->info->selection_cb (widget, id, user_data);
|
|
480 }
|
|
481
|
|
482 #ifdef DIALOGS_ATHENA
|
|
483
|
|
484 static XtActionProc
|
|
485 wm_delete_window (Widget shell, XtPointer closure, XtPointer call_data)
|
|
486 {
|
|
487 LWLIB_ID id;
|
|
488 Widget *kids = 0;
|
|
489 Widget widget;
|
165
|
490 Arg al [1];
|
0
|
491 if (! XtIsSubclass (shell, shellWidgetClass))
|
|
492 abort ();
|
165
|
493 XtSetArg (al [0], XtNchildren, &kids);
|
|
494 XtGetValues (shell, al, 1);
|
0
|
495 if (!kids || !*kids)
|
|
496 abort ();
|
|
497 widget = kids [0];
|
|
498 if (! XtIsSubclass (widget, dialogWidgetClass))
|
|
499 abort ();
|
|
500 id = lw_get_widget_id (widget);
|
|
501 if (! id) abort ();
|
|
502
|
|
503 {
|
|
504 widget_info *info = lw_get_widget_info (id);
|
|
505 if (! info) abort ();
|
|
506 if (info->selection_cb)
|
|
507 info->selection_cb (widget, id, (XtPointer) -1);
|
|
508 }
|
|
509
|
|
510 lw_destroy_all_widgets (id);
|
|
511 return NULL;
|
|
512 }
|
|
513
|
|
514 #endif /* DIALOGS_ATHENA */
|
|
515
|
|
516
|
|
517 /* Scrollbars */
|
|
518
|
|
519 #ifdef SCROLLBARS_ATHENA
|
|
520 static void
|
|
521 xaw_scrollbar_scroll (Widget widget, XtPointer closure, XtPointer call_data)
|
|
522 {
|
|
523 widget_instance *instance = (widget_instance *) closure;
|
|
524 LWLIB_ID id;
|
|
525 scroll_event event_data;
|
|
526
|
|
527 if (!instance || widget->core.being_destroyed)
|
|
528 return;
|
|
529
|
|
530 id = instance->info->id;
|
|
531 event_data.slider_value = (int) call_data;
|
|
532 event_data.time = 0;
|
|
533
|
|
534 if ((int) call_data > 0)
|
82
|
535 /* event_data.action = SCROLLBAR_PAGE_DOWN;*/
|
|
536 event_data.action = SCROLLBAR_LINE_DOWN;
|
0
|
537 else
|
82
|
538 /* event_data.action = SCROLLBAR_PAGE_UP;*/
|
|
539 event_data.action = SCROLLBAR_LINE_UP;
|
0
|
540
|
|
541 if (instance->info->pre_activate_cb)
|
|
542 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
543 }
|
|
544
|
|
545 static void
|
|
546 xaw_scrollbar_jump (Widget widget, XtPointer closure, XtPointer call_data)
|
|
547 {
|
|
548 widget_instance *instance = (widget_instance *) closure;
|
|
549 LWLIB_ID id;
|
|
550 scroll_event event_data;
|
|
551 scrollbar_values *val =
|
|
552 (scrollbar_values *) instance->info->val->scrollbar_data;
|
|
553 float percent;
|
|
554
|
|
555 if (!instance || widget->core.being_destroyed)
|
|
556 return;
|
|
557
|
|
558 id = instance->info->id;
|
|
559
|
|
560 percent = * (float *) call_data;
|
|
561 event_data.slider_value =
|
|
562 (int) (percent * (float) (val->maximum - val->minimum)) + val->minimum;
|
|
563
|
|
564 event_data.time = 0;
|
|
565 event_data.action = SCROLLBAR_DRAG;
|
|
566
|
|
567 if (instance->info->pre_activate_cb)
|
|
568 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
569 }
|
|
570
|
|
571 static Widget
|
|
572 xaw_create_scrollbar (widget_instance *instance, int vertical)
|
|
573 {
|
78
|
574 Arg av[10];
|
0
|
575 int ac = 0;
|
80
|
576
|
78
|
577 static XtCallbackRec jumpCallbacks[2] =
|
|
578 { {xaw_scrollbar_jump, NULL}, {NULL, NULL} };
|
|
579
|
|
580 static XtCallbackRec scrollCallbacks[2] =
|
|
581 { {xaw_scrollbar_scroll, NULL}, {NULL, NULL} };
|
|
582
|
|
583 jumpCallbacks[0].closure = scrollCallbacks[0].closure = (XtPointer) instance;
|
0
|
584
|
|
585 /* #### This is tacked onto the with and height and completely
|
|
586 screws our geometry management. We should probably make the
|
|
587 top-level aware of this so that people could have a border but so
|
|
588 few people use the Athena scrollbar now that it really isn't
|
|
589 worth the effort, at least not at the moment. */
|
|
590 XtSetArg (av [ac], XtNborderWidth, 0); ac++;
|
80
|
591 XtSetArg (av [ac], XtNorientation,
|
|
592 vertical ? XtorientVertical : XtorientHorizontal); ac++;
|
|
593 XtSetArg (av [ac], "jumpProc", jumpCallbacks); ac++;
|
|
594 XtSetArg (av [ac], "scrollProc", scrollCallbacks); ac++;
|
0
|
595
|
80
|
596 return XtCreateWidget (instance->info->name, scrollbarWidgetClass,
|
|
597 instance->parent, av, ac);
|
0
|
598 }
|
|
599
|
|
600 static Widget
|
|
601 xaw_create_vertical_scrollbar (widget_instance *instance)
|
|
602 {
|
|
603 return xaw_create_scrollbar (instance, 1);
|
|
604 }
|
|
605
|
|
606 static Widget
|
|
607 xaw_create_horizontal_scrollbar (widget_instance *instance)
|
|
608 {
|
|
609 return xaw_create_scrollbar (instance, 0);
|
|
610 }
|
|
611 #endif /* SCROLLBARS_ATHENA */
|
|
612
|
|
613 widget_creation_entry
|
|
614 xaw_creation_table [] =
|
|
615 {
|
|
616 #ifdef SCROLLBARS_ATHENA
|
|
617 {"vertical-scrollbar", xaw_create_vertical_scrollbar},
|
|
618 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar},
|
|
619 #endif
|
|
620 {NULL, NULL}
|
|
621 };
|