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