428
|
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
|
|
17 along with XEmacs; 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. */
|
|
20
|
|
21 #include <config.h>
|
|
22 #include <stdio.h>
|
|
23
|
|
24 #ifdef STDC_HEADERS
|
|
25 #include <stdlib.h>
|
|
26 #endif
|
|
27
|
|
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 LWLIB_SCROLLBARS_ATHENA
|
442
|
36 #include ATHENA_Scrollbar_h_
|
428
|
37 #endif
|
|
38 #ifdef LWLIB_DIALOGS_ATHENA
|
442
|
39 #include ATHENA_Dialog_h_
|
|
40 #include ATHENA_Form_h_
|
|
41 #include ATHENA_Command_h_
|
|
42 #include ATHENA_Label_h_
|
428
|
43 #endif
|
|
44 #ifdef LWLIB_WIDGETS_ATHENA
|
442
|
45 #include ATHENA_Toggle_h_
|
428
|
46 #include "xlwradio.h"
|
|
47 #include "xlwcheckbox.h"
|
|
48 #include "xlwgauge.h"
|
442
|
49 #include ATHENA_AsciiText_h_
|
428
|
50 #endif
|
|
51 #include <X11/Xatom.h>
|
|
52
|
|
53 static void xaw_generic_callback (Widget, XtPointer, XtPointer);
|
|
54
|
|
55
|
|
56 Boolean
|
|
57 lw_xaw_widget_p (Widget widget)
|
|
58 {
|
|
59 return (0
|
|
60 #ifdef LWLIB_SCROLLBARS_ATHENA
|
|
61 || XtIsSubclass (widget, scrollbarWidgetClass)
|
|
62 #endif
|
|
63 #ifdef LWLIB_DIALOGS_ATHENA
|
|
64 || XtIsSubclass (widget, dialogWidgetClass)
|
|
65 #endif
|
|
66 #ifdef LWLIB_WIDGETS_ATHENA
|
|
67 || XtIsSubclass (widget, labelWidgetClass)
|
|
68 || XtIsSubclass (widget, toggleWidgetClass)
|
|
69 || XtIsSubclass (widget, gaugeWidgetClass)
|
442
|
70 #ifndef NEED_MOTIF
|
|
71 || XtIsSubclass (widget, asciiTextWidgetClass)
|
428
|
72 #endif
|
|
73 #endif
|
|
74 );
|
|
75 }
|
|
76
|
|
77 #ifdef LWLIB_SCROLLBARS_ATHENA
|
|
78 static void
|
|
79 xaw_update_scrollbar (widget_instance *instance, Widget widget,
|
|
80 widget_value *val)
|
|
81 {
|
|
82 if (val->scrollbar_data)
|
|
83 {
|
|
84 scrollbar_values *data = val->scrollbar_data;
|
|
85 float widget_shown, widget_topOfThumb;
|
|
86 float new_shown, new_topOfThumb;
|
|
87 Arg al [10];
|
|
88
|
|
89 /* First size and position the scrollbar widget. */
|
|
90 XtSetArg (al [0], XtNx, data->scrollbar_x);
|
|
91 XtSetArg (al [1], XtNy, data->scrollbar_y);
|
|
92 XtSetArg (al [2], XtNwidth, data->scrollbar_width);
|
|
93 XtSetArg (al [3], XtNheight, data->scrollbar_height);
|
|
94 XtSetValues (widget, al, 4);
|
|
95
|
|
96 /* Now size the scrollbar's slider. */
|
|
97 XtSetArg (al [0], XtNtopOfThumb, &widget_topOfThumb);
|
|
98 XtSetArg (al [1], XtNshown, &widget_shown);
|
|
99 XtGetValues (widget, al, 2);
|
|
100
|
|
101 new_shown = (double) data->slider_size /
|
|
102 (double) (data->maximum - data->minimum);
|
|
103
|
|
104 new_topOfThumb = (double) (data->slider_position - data->minimum) /
|
|
105 (double) (data->maximum - data->minimum);
|
|
106
|
|
107 if (new_shown > 1.0)
|
|
108 new_shown = 1.0;
|
|
109 else if (new_shown < 0)
|
|
110 new_shown = 0;
|
|
111
|
|
112 if (new_topOfThumb > 1.0)
|
|
113 new_topOfThumb = 1.0;
|
|
114 else if (new_topOfThumb < 0)
|
|
115 new_topOfThumb = 0;
|
|
116
|
|
117 if (new_shown != widget_shown || new_topOfThumb != widget_topOfThumb)
|
|
118 XawScrollbarSetThumb (widget, new_topOfThumb, new_shown);
|
|
119 }
|
|
120 }
|
|
121 #endif /* LWLIB_SCROLLBARS_ATHENA */
|
|
122
|
|
123 void
|
|
124 xaw_update_one_widget (widget_instance *instance, Widget widget,
|
2286
|
125 widget_value *val, Boolean UNUSED (deep_p))
|
428
|
126 {
|
|
127 if (0)
|
|
128 ;
|
|
129 #ifdef LWLIB_SCROLLBARS_ATHENA
|
|
130 else if (XtIsSubclass (widget, scrollbarWidgetClass))
|
|
131 {
|
|
132 xaw_update_scrollbar (instance, widget, val);
|
|
133 }
|
|
134 #endif
|
442
|
135 #ifdef LWLIB_WIDGETS_ATHENA
|
|
136 #ifndef NEED_MOTIF
|
|
137 else if (XtIsSubclass (widget, asciiTextWidgetClass))
|
|
138 {
|
|
139 }
|
|
140 #endif
|
|
141 #endif
|
428
|
142 #ifdef LWLIB_DIALOGS_ATHENA
|
|
143 else if (XtIsSubclass (widget, dialogWidgetClass))
|
|
144 {
|
|
145 Arg al [1];
|
|
146 XtSetArg (al [0], XtNlabel, val->contents->value);
|
|
147 XtSetValues (widget, al, 1);
|
|
148 }
|
|
149 #endif /* LWLIB_DIALOGS_ATHENA */
|
|
150 #ifdef LWLIB_WIDGETS_ATHENA
|
438
|
151 else if (XtClass (widget) == labelWidgetClass)
|
428
|
152 {
|
|
153 Arg al [1];
|
|
154 XtSetArg (al [0], XtNlabel, val->value);
|
|
155 XtSetValues (widget, al, 1);
|
|
156 }
|
|
157 #endif /* LWLIB_WIDGETS_ATHENA */
|
|
158 #if defined (LWLIB_DIALOGS_ATHENA) || defined (LWLIB_WIDGETS_ATHENA)
|
|
159 else if (XtIsSubclass (widget, commandWidgetClass))
|
|
160 {
|
|
161 Dimension bw = 0;
|
|
162 Arg al [3];
|
|
163 XtSetArg (al [0], XtNborderWidth, &bw);
|
|
164 XtGetValues (widget, al, 1);
|
|
165
|
|
166 #ifndef LWLIB_DIALOGS_ATHENA3D
|
|
167 if (bw == 0)
|
|
168 /* Don't let buttons end up with 0 borderwidth, that's ugly...
|
|
169 Yeah, all this should really be done through app-defaults files
|
|
170 or fallback resources, but that's a whole different can of worms
|
|
171 that I don't feel like opening right now. Making Athena widgets
|
|
172 not look like shit is just entirely too much work.
|
|
173 */
|
|
174 {
|
|
175 XtSetArg (al [0], XtNborderWidth, 1);
|
|
176 XtSetValues (widget, al, 1);
|
|
177 }
|
|
178 #endif /* ! LWLIB_DIALOGS_ATHENA3D */
|
|
179
|
442
|
180 lw_remove_accelerator_spec (val->value);
|
428
|
181 XtSetArg (al [0], XtNlabel, val->value);
|
|
182 XtSetArg (al [1], XtNsensitive, val->enabled);
|
|
183 /* Force centered button text. See above. */
|
|
184 XtSetArg (al [2], XtNjustify, XtJustifyCenter);
|
|
185 XtSetValues (widget, al, 3);
|
|
186
|
|
187 XtRemoveAllCallbacks (widget, XtNcallback);
|
|
188 XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance);
|
|
189 #ifdef LWLIB_WIDGETS_ATHENA
|
|
190 /* set the selected state */
|
|
191 if (XtIsSubclass (widget, toggleWidgetClass))
|
|
192 {
|
|
193 XtSetArg (al [0], XtNstate, val->selected);
|
|
194 XtSetValues (widget, al, 1);
|
|
195 }
|
|
196 #endif /* LWLIB_WIDGETS_ATHENA */
|
|
197 }
|
|
198 #endif /* LWLIB_DIALOGS_ATHENA */
|
442
|
199 /* Lastly update our global arg values. */
|
|
200 if (val->args && val->args->nargs)
|
|
201 XtSetValues (widget, val->args->args, val->args->nargs);
|
428
|
202 }
|
|
203
|
|
204 void
|
|
205 xaw_update_one_value (widget_instance *instance, Widget widget,
|
|
206 widget_value *val)
|
|
207 {
|
|
208 #ifdef LWLIB_WIDGETS_ATHENA
|
|
209 widget_value *old_wv;
|
|
210
|
|
211 /* copy the call_data slot into the "return" widget_value */
|
|
212 for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next)
|
|
213 if (!strcmp (val->name, old_wv->name))
|
|
214 {
|
|
215 val->call_data = old_wv->call_data;
|
|
216 break;
|
|
217 }
|
|
218
|
|
219 if (XtIsSubclass (widget, toggleWidgetClass))
|
|
220 {
|
|
221 Arg al [1];
|
|
222 XtSetArg (al [0], XtNstate, &val->selected);
|
|
223 XtGetValues (widget, al, 1);
|
|
224 val->edited = True;
|
|
225 }
|
|
226 #ifndef NEED_MOTIF
|
|
227 else if (XtIsSubclass (widget, asciiTextWidgetClass))
|
|
228 {
|
442
|
229 Arg al [2];
|
|
230 String buf = 0;
|
|
231 XtSetArg (al [0], XtNstring, &buf);
|
|
232 XtGetValues (widget, al, 1);
|
|
233
|
428
|
234 if (val->value)
|
442
|
235 {
|
|
236 free (val->value);
|
|
237 val->value = 0;
|
|
238 }
|
|
239 /* I don't think this causes a leak. */
|
|
240 if (buf)
|
|
241 val->value = strdup (buf);
|
428
|
242 val->edited = True;
|
|
243 }
|
|
244 #endif
|
|
245 #endif /* LWLIB_WIDGETS_ATHENA */
|
|
246 }
|
|
247
|
|
248 void
|
|
249 xaw_destroy_instance (widget_instance *instance)
|
|
250 {
|
|
251 #ifdef LWLIB_DIALOGS_ATHENA
|
|
252 if (XtIsSubclass (instance->widget, dialogWidgetClass))
|
|
253 /* Need to destroy the Shell too. */
|
|
254 XtDestroyWidget (XtParent (instance->widget));
|
|
255 else
|
|
256 #endif
|
|
257 XtDestroyWidget (instance->widget);
|
|
258 }
|
|
259
|
|
260 void
|
2286
|
261 xaw_popup_menu (Widget UNUSED (widget), XEvent *UNUSED (event))
|
428
|
262 {
|
|
263 /* An Athena menubar has not been implemented. */
|
|
264 return;
|
|
265 }
|
|
266
|
|
267 void
|
|
268 xaw_pop_instance (widget_instance *instance, Boolean up)
|
|
269 {
|
|
270 Widget widget = instance->widget;
|
|
271
|
|
272 if (up)
|
|
273 {
|
|
274 #ifdef LWLIB_DIALOGS_ATHENA
|
|
275 if (XtIsSubclass (widget, dialogWidgetClass))
|
|
276 {
|
|
277 /* For dialogs, we need to call XtPopup on the parent instead
|
|
278 of calling XtManageChild on the widget.
|
|
279 Also we need to hack the shell's WM_PROTOCOLS to get it to
|
|
280 understand what the close box is supposed to do!!
|
|
281 */
|
|
282 Display *dpy = XtDisplay (widget);
|
|
283 Widget shell = XtParent (widget);
|
|
284 Atom props [2];
|
|
285 int i = 0;
|
|
286 props [i++] = XInternAtom (dpy, "WM_DELETE_WINDOW", False);
|
|
287 XChangeProperty (dpy, XtWindow (shell),
|
|
288 XInternAtom (dpy, "WM_PROTOCOLS", False),
|
|
289 XA_ATOM, 32, PropModeAppend,
|
|
290 (unsigned char *) props, i);
|
|
291
|
|
292 /* Center the widget in its parent. Why isn't this kind of crap
|
|
293 done automatically? I thought toolkits were supposed to make
|
|
294 life easier?
|
|
295 */
|
|
296 {
|
|
297 unsigned int x, y, w, h;
|
|
298 Widget topmost = instance->parent;
|
|
299 w = shell->core.width;
|
|
300 h = shell->core.height;
|
|
301 while (topmost->core.parent &&
|
|
302 XtIsRealized (topmost->core.parent) &&
|
|
303 /* HAVE_SESSION adds an unmapped parent widget that
|
|
304 we should ignore here. */
|
|
305 topmost->core.parent->core.mapped_when_managed)
|
|
306 topmost = topmost->core.parent;
|
|
307 if (topmost->core.width < w) x = topmost->core.x;
|
|
308 else x = topmost->core.x + ((topmost->core.width - w) / 2);
|
|
309 if (topmost->core.height < h) y = topmost->core.y;
|
|
310 else y = topmost->core.y + ((topmost->core.height - h) / 2);
|
|
311 XtMoveWidget (shell, x, y);
|
|
312 }
|
|
313
|
|
314 /* Finally, pop it up. */
|
|
315 XtPopup (shell, XtGrabNonexclusive);
|
|
316 }
|
|
317 else
|
|
318 #endif /* LWLIB_DIALOGS_ATHENA */
|
|
319 XtManageChild (widget);
|
|
320 }
|
|
321 else
|
|
322 {
|
|
323 #ifdef LWLIB_DIALOGS_ATHENA
|
|
324 if (XtIsSubclass (widget, dialogWidgetClass))
|
|
325 XtUnmanageChild (XtParent (widget));
|
|
326 else
|
|
327 #endif
|
|
328 XtUnmanageChild (widget);
|
|
329 }
|
|
330 }
|
|
331
|
|
332
|
|
333 #ifdef LWLIB_DIALOGS_ATHENA
|
|
334 /* Dialog boxes */
|
|
335
|
|
336 static char overrideTrans[] =
|
|
337 "<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
|
|
338 static XtActionProc wm_delete_window (Widget shell, XtPointer closure,
|
|
339 XtPointer call_data);
|
|
340 static XtActionsRec xaw_actions [] = {
|
|
341 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window}
|
|
342 };
|
|
343 static Boolean actions_initted = False;
|
|
344
|
|
345 static Widget
|
442
|
346 make_dialog (const char* name, Widget parent, Boolean pop_up_p,
|
2286
|
347 const char* shell_title, const char* UNUSED (icon_name),
|
428
|
348 Boolean text_input_slot,
|
|
349 Boolean radio_box, Boolean list,
|
|
350 int left_buttons, int right_buttons)
|
|
351 {
|
|
352 Arg av [20];
|
|
353 int ac = 0;
|
|
354 int i, bc;
|
|
355 char button_name [255];
|
|
356 Widget shell;
|
|
357 Widget dialog;
|
|
358 Widget button;
|
|
359 XtTranslations override;
|
|
360
|
|
361 if (! pop_up_p) abort (); /* not implemented */
|
|
362 if (text_input_slot) abort (); /* not implemented */
|
|
363 if (radio_box) abort (); /* not implemented */
|
|
364 if (list) abort (); /* not implemented */
|
|
365
|
|
366 if (! actions_initted)
|
|
367 {
|
|
368 XtAppContext app = XtWidgetToApplicationContext (parent);
|
|
369 XtAppAddActions (app, xaw_actions,
|
|
370 sizeof (xaw_actions) / sizeof (xaw_actions[0]));
|
|
371 actions_initted = True;
|
|
372 }
|
|
373
|
|
374 override = XtParseTranslationTable (overrideTrans);
|
|
375
|
|
376 ac = 0;
|
|
377 XtSetArg (av[ac], XtNtitle, shell_title); ac++;
|
|
378 XtSetArg (av[ac], XtNallowShellResize, True); ac++;
|
|
379 XtSetArg (av[ac], XtNtransientFor, parent); ac++;
|
|
380 shell = XtCreatePopupShell ("dialog", transientShellWidgetClass,
|
|
381 parent, av, ac);
|
|
382 XtOverrideTranslations (shell, override);
|
|
383
|
|
384 ac = 0;
|
|
385 dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac);
|
|
386
|
|
387 bc = 0;
|
|
388 button = 0;
|
|
389 for (i = 0; i < left_buttons; i++)
|
|
390 {
|
|
391 ac = 0;
|
|
392 XtSetArg (av [ac], XtNfromHoriz, button); ac++;
|
|
393 XtSetArg (av [ac], XtNleft, XtChainLeft); ac++;
|
|
394 XtSetArg (av [ac], XtNright, XtChainLeft); ac++;
|
|
395 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
|
|
396 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
|
|
397 XtSetArg (av [ac], XtNresizable, True); ac++;
|
|
398 sprintf (button_name, "button%d", ++bc);
|
|
399 button = XtCreateManagedWidget (button_name, commandWidgetClass,
|
|
400 dialog, av, ac);
|
|
401 }
|
|
402 if (right_buttons)
|
|
403 {
|
|
404 /* Create a separator
|
|
405
|
|
406 I want the separator to take up the slack between the buttons on
|
|
407 the right and the buttons on the left (that is I want the buttons
|
|
408 after the separator to be packed against the right edge of the
|
|
409 window) but I can't seem to make it do it.
|
|
410 */
|
|
411 ac = 0;
|
|
412 XtSetArg (av [ac], XtNfromHoriz, button); ac++;
|
|
413 /* XtSetArg (av [ac], XtNfromVert, XtNameToWidget (dialog, "label")); ac++; */
|
|
414 XtSetArg (av [ac], XtNleft, XtChainLeft); ac++;
|
|
415 XtSetArg (av [ac], XtNright, XtChainRight); ac++;
|
|
416 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
|
|
417 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
|
|
418 XtSetArg (av [ac], XtNlabel, ""); ac++;
|
|
419 XtSetArg (av [ac], XtNwidth, 30); ac++; /* #### aaack!! */
|
|
420 XtSetArg (av [ac], XtNborderWidth, 0); ac++;
|
|
421 XtSetArg (av [ac], XtNshapeStyle, XmuShapeRectangle); ac++;
|
|
422 XtSetArg (av [ac], XtNresizable, False); ac++;
|
|
423 XtSetArg (av [ac], XtNsensitive, False); ac++;
|
|
424 button = XtCreateManagedWidget ("separator",
|
|
425 /* labelWidgetClass, */
|
|
426 /* This has to be Command to fake out
|
|
427 the Dialog widget... */
|
|
428 commandWidgetClass,
|
|
429 dialog, av, ac);
|
|
430 }
|
|
431 for (i = 0; i < right_buttons; i++)
|
|
432 {
|
|
433 ac = 0;
|
|
434 XtSetArg (av [ac], XtNfromHoriz, button); ac++;
|
|
435 XtSetArg (av [ac], XtNleft, XtChainRight); ac++;
|
|
436 XtSetArg (av [ac], XtNright, XtChainRight); ac++;
|
|
437 XtSetArg (av [ac], XtNtop, XtChainBottom); ac++;
|
|
438 XtSetArg (av [ac], XtNbottom, XtChainBottom); ac++;
|
|
439 XtSetArg (av [ac], XtNresizable, True); ac++;
|
|
440 sprintf (button_name, "button%d", ++bc);
|
|
441 button = XtCreateManagedWidget (button_name, commandWidgetClass,
|
|
442 dialog, av, ac);
|
|
443 }
|
|
444
|
|
445 return dialog;
|
|
446 }
|
|
447
|
|
448 Widget
|
|
449 xaw_create_dialog (widget_instance* instance)
|
|
450 {
|
|
451 char *name = instance->info->type;
|
|
452 Widget parent = instance->parent;
|
|
453 Widget widget;
|
|
454 Boolean pop_up_p = instance->pop_up_p;
|
442
|
455 const char *shell_name = 0;
|
|
456 const char *icon_name = 0;
|
428
|
457 Boolean text_input_slot = False;
|
|
458 Boolean radio_box = False;
|
|
459 Boolean list = False;
|
|
460 int total_buttons;
|
|
461 int left_buttons = 0;
|
|
462 int right_buttons = 1;
|
|
463
|
|
464 switch (name [0]) {
|
|
465 case 'E': case 'e':
|
|
466 icon_name = "dbox-error";
|
|
467 shell_name = "Error";
|
|
468 break;
|
|
469
|
|
470 case 'I': case 'i':
|
|
471 icon_name = "dbox-info";
|
|
472 shell_name = "Information";
|
|
473 break;
|
|
474
|
|
475 case 'L': case 'l':
|
|
476 list = True;
|
|
477 icon_name = "dbox-question";
|
|
478 shell_name = "Prompt";
|
|
479 break;
|
|
480
|
|
481 case 'P': case 'p':
|
|
482 text_input_slot = True;
|
|
483 icon_name = "dbox-question";
|
|
484 shell_name = "Prompt";
|
|
485 break;
|
|
486
|
|
487 case 'Q': case 'q':
|
|
488 icon_name = "dbox-question";
|
|
489 shell_name = "Question";
|
|
490 break;
|
|
491 }
|
|
492
|
|
493 total_buttons = name [1] - '0';
|
|
494
|
|
495 if (name [3] == 'T' || name [3] == 't')
|
|
496 {
|
|
497 text_input_slot = False;
|
|
498 radio_box = True;
|
|
499 }
|
|
500 else if (name [3])
|
|
501 right_buttons = name [4] - '0';
|
|
502
|
|
503 left_buttons = total_buttons - right_buttons;
|
|
504
|
|
505 widget = make_dialog (name, parent, pop_up_p,
|
|
506 shell_name, icon_name, text_input_slot, radio_box,
|
|
507 list, left_buttons, right_buttons);
|
|
508
|
|
509 return widget;
|
|
510 }
|
|
511 #endif /* LWLIB_DIALOGS_ATHENA */
|
|
512
|
|
513
|
|
514 static void
|
|
515 xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
|
|
516 {
|
|
517 widget_instance *instance = (widget_instance *) closure;
|
|
518 Widget instance_widget;
|
|
519 LWLIB_ID id;
|
|
520 XtPointer user_data;
|
|
521 #ifdef LWLIB_WIDGETS_ATHENA
|
|
522 /* We want the selected status to change only when we decide it
|
|
523 should change. Yuck but correct. */
|
|
524 if (XtIsSubclass (widget, toggleWidgetClass))
|
|
525 {
|
|
526 Boolean check;
|
|
527 Arg al [1];
|
|
528
|
|
529 XtSetArg (al [0], XtNstate, &check);
|
|
530 XtGetValues (widget, al, 1);
|
|
531
|
|
532 XtSetArg (al [0], XtNstate, !check);
|
|
533 XtSetValues (widget, al, 1);
|
|
534 }
|
|
535 #endif /* LWLIB_WIDGETS_ATHENA */
|
|
536 lw_internal_update_other_instances (widget, closure, call_data);
|
|
537
|
|
538 if (! instance)
|
|
539 return;
|
|
540 if (widget->core.being_destroyed)
|
|
541 return;
|
|
542
|
|
543 instance_widget = instance->widget;
|
|
544 if (!instance_widget)
|
|
545 return;
|
|
546
|
|
547 id = instance->info->id;
|
|
548
|
|
549 #if 0
|
|
550 user_data = NULL;
|
|
551 {
|
|
552 Arg al [1];
|
|
553 XtSetArg (al [0], XtNuserData, &user_data);
|
|
554 XtGetValues (widget, al, 1);
|
|
555 }
|
|
556 #else
|
|
557 /* Damn! Athena doesn't give us a way to hang our own data on the
|
|
558 buttons, so we have to go find it... I guess this assumes that
|
|
559 all instances of a button have the same call data.
|
|
560
|
|
561 ... Which is a totally bogus assumption --andyp */
|
|
562 {
|
|
563 widget_value *val = instance->info->val;
|
|
564 /* If the widget is a buffer/gutter widget then we already have
|
|
565 the one we are looking for, so don't try and descend the widget
|
|
566 tree. */
|
|
567 if (val->contents)
|
|
568 {
|
|
569 char *name = XtName (widget);
|
|
570 val = val->contents;
|
|
571 while (val)
|
|
572 {
|
|
573 if (val->name && !strcmp (val->name, name))
|
|
574 break;
|
|
575 val = val->next;
|
|
576 }
|
|
577 if (! val) abort ();
|
|
578 }
|
|
579 user_data = val->call_data;
|
|
580 }
|
|
581 #endif
|
|
582
|
|
583 if (instance->info->selection_cb)
|
|
584 instance->info->selection_cb (widget, id, user_data);
|
|
585 }
|
|
586
|
|
587 #ifdef LWLIB_DIALOGS_ATHENA
|
|
588
|
|
589 static XtActionProc
|
2286
|
590 wm_delete_window (Widget shell, XtPointer UNUSED (closure),
|
|
591 XtPointer UNUSED (call_data))
|
428
|
592 {
|
|
593 LWLIB_ID id;
|
|
594 Widget *kids = 0;
|
|
595 Widget widget;
|
|
596 Arg al [1];
|
|
597 if (! XtIsSubclass (shell, shellWidgetClass))
|
|
598 abort ();
|
|
599 XtSetArg (al [0], XtNchildren, &kids);
|
|
600 XtGetValues (shell, al, 1);
|
|
601 if (!kids || !*kids)
|
|
602 abort ();
|
|
603 widget = kids [0];
|
|
604 if (! XtIsSubclass (widget, dialogWidgetClass))
|
|
605 abort ();
|
|
606 id = lw_get_widget_id (widget);
|
|
607 if (! id) abort ();
|
|
608
|
|
609 {
|
|
610 widget_info *info = lw_get_widget_info (id);
|
|
611 if (! info) abort ();
|
|
612 if (info->selection_cb)
|
|
613 info->selection_cb (widget, id, (XtPointer) -1);
|
|
614 }
|
|
615
|
|
616 lw_destroy_all_widgets (id);
|
|
617 return NULL;
|
|
618 }
|
|
619
|
|
620 #endif /* LWLIB_DIALOGS_ATHENA */
|
|
621
|
|
622
|
|
623 /* Scrollbars */
|
|
624
|
|
625 #ifdef LWLIB_SCROLLBARS_ATHENA
|
|
626 static void
|
|
627 xaw_scrollbar_scroll (Widget widget, XtPointer closure, XtPointer call_data)
|
|
628 {
|
|
629 widget_instance *instance = (widget_instance *) closure;
|
|
630 LWLIB_ID id;
|
|
631 scroll_event event_data;
|
|
632
|
|
633 if (!instance || widget->core.being_destroyed)
|
|
634 return;
|
|
635
|
|
636 id = instance->info->id;
|
|
637 event_data.slider_value = (int) call_data;
|
|
638 event_data.time = 0;
|
|
639
|
|
640 if ((int) call_data > 0)
|
|
641 /* event_data.action = SCROLLBAR_PAGE_DOWN;*/
|
|
642 event_data.action = SCROLLBAR_LINE_DOWN;
|
|
643 else
|
|
644 /* event_data.action = SCROLLBAR_PAGE_UP;*/
|
|
645 event_data.action = SCROLLBAR_LINE_UP;
|
|
646
|
|
647 if (instance->info->pre_activate_cb)
|
|
648 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
649 }
|
|
650
|
|
651 static void
|
|
652 xaw_scrollbar_jump (Widget widget, XtPointer closure, XtPointer call_data)
|
|
653 {
|
|
654 widget_instance *instance = (widget_instance *) closure;
|
|
655 LWLIB_ID id;
|
|
656 scroll_event event_data;
|
|
657 scrollbar_values *val =
|
|
658 (scrollbar_values *) instance->info->val->scrollbar_data;
|
|
659 float percent;
|
|
660
|
|
661 if (!instance || widget->core.being_destroyed)
|
|
662 return;
|
|
663
|
|
664 id = instance->info->id;
|
|
665
|
|
666 percent = * (float *) call_data;
|
|
667 event_data.slider_value =
|
|
668 (int) (percent * (float) (val->maximum - val->minimum)) + val->minimum;
|
|
669
|
|
670 event_data.time = 0;
|
|
671 event_data.action = SCROLLBAR_DRAG;
|
|
672
|
|
673 if (instance->info->pre_activate_cb)
|
|
674 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
|
|
675 }
|
|
676
|
|
677 static Widget
|
|
678 xaw_create_scrollbar (widget_instance *instance, int vertical)
|
|
679 {
|
|
680 Arg av[10];
|
|
681 int ac = 0;
|
|
682
|
|
683 static XtCallbackRec jumpCallbacks[2] =
|
|
684 { {xaw_scrollbar_jump, NULL}, {NULL, NULL} };
|
|
685
|
|
686 static XtCallbackRec scrollCallbacks[2] =
|
|
687 { {xaw_scrollbar_scroll, NULL}, {NULL, NULL} };
|
|
688
|
|
689 jumpCallbacks[0].closure = scrollCallbacks[0].closure = (XtPointer) instance;
|
|
690
|
|
691 /* #### This is tacked onto the with and height and completely
|
|
692 screws our geometry management. We should probably make the
|
|
693 top-level aware of this so that people could have a border but so
|
|
694 few people use the Athena scrollbar now that it really isn't
|
|
695 worth the effort, at least not at the moment. */
|
|
696 XtSetArg (av [ac], XtNborderWidth, 0); ac++;
|
|
697 XtSetArg (av [ac], XtNorientation,
|
|
698 vertical ? XtorientVertical : XtorientHorizontal); ac++;
|
|
699 XtSetArg (av [ac], "jumpProc", jumpCallbacks); ac++;
|
|
700 XtSetArg (av [ac], "scrollProc", scrollCallbacks); ac++;
|
|
701
|
|
702 return XtCreateWidget (instance->info->name, scrollbarWidgetClass,
|
|
703 instance->parent, av, ac);
|
|
704 }
|
|
705
|
|
706 static Widget
|
|
707 xaw_create_vertical_scrollbar (widget_instance *instance)
|
|
708 {
|
|
709 return xaw_create_scrollbar (instance, 1);
|
|
710 }
|
|
711
|
|
712 static Widget
|
|
713 xaw_create_horizontal_scrollbar (widget_instance *instance)
|
|
714 {
|
|
715 return xaw_create_scrollbar (instance, 0);
|
|
716 }
|
|
717 #endif /* LWLIB_SCROLLBARS_ATHENA */
|
|
718
|
|
719 #ifdef LWLIB_WIDGETS_ATHENA
|
|
720 /* glyph widgets */
|
|
721 static Widget
|
|
722 xaw_create_button (widget_instance *instance)
|
|
723 {
|
|
724 Arg al[20];
|
|
725 int ac = 0;
|
|
726 Widget button = 0;
|
|
727 widget_value* val = instance->info->val;
|
|
728
|
|
729 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
|
|
730 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
|
|
731 XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++;
|
|
732 /* The highlight doesn't appear to be dynamically set which makes it
|
|
733 look ugly. I think this may be a LessTif bug but for now we just
|
|
734 get rid of it. */
|
|
735 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
|
|
736
|
|
737 /* add any args the user supplied for creation time */
|
|
738 lw_add_value_args_to_args (val, al, &ac);
|
|
739
|
|
740 if (!val->call_data)
|
|
741 button = XtCreateManagedWidget (val->name, labelWidgetClass,
|
|
742 instance->parent, al, ac);
|
|
743
|
|
744 else
|
|
745 {
|
|
746 if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE)
|
|
747 {
|
|
748 XtSetArg (al [ac], XtNstate, val->selected); ac++;
|
|
749 button = XtCreateManagedWidget
|
|
750 (val->name,
|
|
751 val->type == TOGGLE_TYPE ? checkboxWidgetClass : radioWidgetClass,
|
|
752 instance->parent, al, ac);
|
|
753 }
|
|
754 else
|
|
755 {
|
|
756 button = XtCreateManagedWidget (val->name, commandWidgetClass,
|
|
757 instance->parent, al, ac);
|
|
758 }
|
|
759 XtRemoveAllCallbacks (button, XtNcallback);
|
|
760 XtAddCallback (button, XtNcallback, xaw_generic_callback, (XtPointer)instance);
|
|
761 }
|
|
762
|
|
763 XtManageChild (button);
|
|
764
|
|
765 return button;
|
|
766 }
|
|
767
|
|
768 static Widget
|
|
769 xaw_create_label_field (widget_instance *instance)
|
|
770 {
|
|
771 return xaw_create_label (instance->parent, instance->info->val);
|
|
772 }
|
|
773
|
|
774 Widget
|
|
775 xaw_create_label (Widget parent, widget_value* val)
|
|
776 {
|
|
777 Arg al[20];
|
|
778 int ac = 0;
|
|
779 Widget label = 0;
|
|
780
|
|
781 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
|
|
782 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
|
|
783 XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++;
|
|
784
|
|
785 /* add any args the user supplied for creation time */
|
|
786 lw_add_value_args_to_args (val, al, &ac);
|
|
787
|
|
788 label = XtCreateManagedWidget (val->name, labelWidgetClass,
|
|
789 parent, al, ac);
|
|
790
|
|
791 /* Do it again for arguments that have no effect until the widget is realized. */
|
|
792 ac = 0;
|
|
793 lw_add_value_args_to_args (val, al, &ac);
|
442
|
794 if (ac > 20)
|
|
795 abort (); /* #### need assert macro in lwlib */
|
428
|
796 XtSetValues (label, al, ac);
|
|
797
|
|
798 return label;
|
|
799 }
|
|
800
|
|
801 static Widget
|
|
802 xaw_create_progress (widget_instance *instance)
|
|
803 {
|
|
804 Arg al[20];
|
|
805 int ac = 0;
|
|
806 Widget scale = 0;
|
|
807 widget_value* val = instance->info->val;
|
442
|
808 #if 0 /* This looks too awful, although more correct. */
|
428
|
809 if (!val->call_data)
|
|
810 {
|
|
811 XtSetArg (al [ac], XtNsensitive, False); ac++;
|
|
812 }
|
|
813 else
|
|
814 {
|
|
815 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
|
|
816 }
|
442
|
817 #else
|
|
818 XtSetArg (al [ac], XtNsensitive, True); ac++;
|
|
819 #endif
|
|
820
|
428
|
821 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
|
|
822 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++;
|
|
823 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
|
|
824 XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++;
|
|
825
|
|
826 /* add any args the user supplied for creation time */
|
|
827 lw_add_value_args_to_args (val, al, &ac);
|
|
828
|
|
829 scale = XtCreateManagedWidget (val->name, gaugeWidgetClass,
|
|
830 instance->parent, al, ac);
|
|
831 /* add the callback */
|
|
832 if (val->call_data)
|
|
833 XtAddCallback (scale, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
|
|
834
|
|
835 XtManageChild (scale);
|
|
836
|
|
837 return scale;
|
|
838 }
|
|
839
|
460
|
840 #if defined(LWLIB_WIDGETS_ATHENA)
|
442
|
841 #define TEXT_BUFFER_SIZE 128
|
428
|
842 static Widget
|
|
843 xaw_create_text_field (widget_instance *instance)
|
|
844 {
|
|
845 Arg al[20];
|
|
846 int ac = 0;
|
|
847 Widget text = 0;
|
|
848 widget_value* val = instance->info->val;
|
|
849
|
442
|
850 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
|
428
|
851 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
|
|
852 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++;
|
|
853 XtSetArg (al [ac], XtNtype, XawAsciiString); ac++;
|
|
854 XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++;
|
442
|
855 XtSetArg (al [ac], XtNuseStringInPlace, False); ac++;
|
|
856 #if 0
|
|
857 XtSetArg (al [ac], XtNlength, TEXT_BUFFER_SIZE); ac++;
|
|
858 #endif
|
|
859 if (val->value)
|
|
860 {
|
|
861 XtSetArg (al [ac], XtNstring, val->value); ac++;
|
|
862 }
|
428
|
863
|
|
864 /* add any args the user supplied for creation time */
|
|
865 lw_add_value_args_to_args (val, al, &ac);
|
|
866
|
|
867 text = XtCreateManagedWidget (val->name, asciiTextWidgetClass,
|
|
868 instance->parent, al, ac);
|
442
|
869
|
|
870 /* add the callback */
|
|
871 if (val->call_data)
|
|
872 XtAddCallback (text, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
|
|
873
|
428
|
874 XtManageChild (text);
|
|
875
|
|
876 return text;
|
|
877 }
|
|
878 #endif
|
442
|
879
|
428
|
880 #endif /* LWLIB_WIDGETS_ATHENA */
|
|
881
|
450
|
882 const widget_creation_entry
|
428
|
883 xaw_creation_table [] =
|
|
884 {
|
|
885 #ifdef LWLIB_SCROLLBARS_ATHENA
|
|
886 {"vertical-scrollbar", xaw_create_vertical_scrollbar },
|
|
887 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar },
|
|
888 #endif
|
|
889 #ifdef LWLIB_WIDGETS_ATHENA
|
|
890 {"button", xaw_create_button },
|
|
891 { "label", xaw_create_label_field },
|
|
892 {"text-field", xaw_create_text_field },
|
|
893 {"progress", xaw_create_progress },
|
|
894 #endif
|
|
895 {NULL, NULL}
|
|
896 };
|
|
897
|