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