(A-IWDSU+271C4): New abstract node.
[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 #include ATHENA_AsciiText_h_
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)
70 #ifndef NEED_MOTIF
71           || XtIsSubclass (widget, asciiTextWidgetClass)
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,
125                        widget_value *val, Boolean deep_p)
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
135 #ifdef LWLIB_WIDGETS_ATHENA
136 #ifndef NEED_MOTIF
137   else if (XtIsSubclass (widget, asciiTextWidgetClass))
138       {
139       }
140 #endif
141 #endif
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
151   else if (XtClass (widget) == labelWidgetClass)
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
180       lw_remove_accelerator_spec (val->value);
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 */
199   /* Lastly update our global arg values. */
200   if (val->args && val->args->nargs)
201     XtSetValues (widget, val->args->args, val->args->nargs);
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     {
229       Arg al [2];
230       String buf = 0;
231       XtSetArg (al [0], XtNstring, &buf);
232       XtGetValues (widget, al, 1);
233
234       if (val->value)
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);
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
261 xaw_popup_menu (Widget widget, XEvent *event)
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 \f
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
346 make_dialog (const char* name, Widget parent, Boolean pop_up_p,
347              const char* shell_title, const char* icon_name,
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;
455   const char *shell_name = 0;
456   const char *icon_name = 0;
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
590 wm_delete_window (Widget shell, XtPointer closure, XtPointer call_data)
591 {
592   LWLIB_ID id;
593   Widget *kids = 0;
594   Widget widget;
595   Arg al [1];
596   if (! XtIsSubclass (shell, shellWidgetClass))
597     abort ();
598   XtSetArg (al [0], XtNchildren, &kids);
599   XtGetValues (shell, al, 1);
600   if (!kids || !*kids) abort ();
601
602   for (widget = *kids;
603        widget && ! XtIsSubclass (widget, dialogWidgetClass);
604        widget = *++kids)
605     ;
606   if (!widget) abort ();
607
608   id = lw_get_widget_id (widget);
609   if (! id) abort ();
610
611   {
612     widget_info *info = lw_get_widget_info (id);
613     if (! info) abort ();
614     if (info->selection_cb)
615       info->selection_cb (widget, id, (XtPointer) -1);
616   }
617
618   lw_destroy_all_widgets (id);
619   return NULL;
620 }
621
622 #endif /* LWLIB_DIALOGS_ATHENA */
623
624 \f
625 /* Scrollbars */
626
627 #ifdef LWLIB_SCROLLBARS_ATHENA
628 static void
629 xaw_scrollbar_scroll (Widget widget, XtPointer closure, XtPointer call_data)
630 {
631   widget_instance *instance = (widget_instance *) closure;
632   LWLIB_ID id;
633   scroll_event event_data;
634
635   if (!instance || widget->core.being_destroyed)
636     return;
637
638   id = instance->info->id;
639   event_data.slider_value = (int) call_data;
640   event_data.time = 0;
641
642   if ((int) call_data > 0)
643     /* event_data.action = SCROLLBAR_PAGE_DOWN;*/
644     event_data.action = SCROLLBAR_LINE_DOWN;
645   else
646     /* event_data.action = SCROLLBAR_PAGE_UP;*/
647     event_data.action = SCROLLBAR_LINE_UP;
648
649   if (instance->info->pre_activate_cb)
650     instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
651 }
652
653 static void
654 xaw_scrollbar_jump (Widget widget, XtPointer closure, XtPointer call_data)
655 {
656   widget_instance *instance = (widget_instance *) closure;
657   LWLIB_ID id;
658   scroll_event event_data;
659   scrollbar_values *val =
660     (scrollbar_values *) instance->info->val->scrollbar_data;
661   float percent;
662
663   if (!instance || widget->core.being_destroyed)
664     return;
665
666   id = instance->info->id;
667
668   percent = * (float *) call_data;
669   event_data.slider_value =
670     (int) (percent * (float) (val->maximum - val->minimum)) + val->minimum;
671
672   event_data.time = 0;
673   event_data.action = SCROLLBAR_DRAG;
674
675   if (instance->info->pre_activate_cb)
676     instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
677 }
678
679 static Widget
680 xaw_create_scrollbar (widget_instance *instance, int vertical)
681 {
682   Arg av[10];
683   int ac = 0;
684   
685   static XtCallbackRec jumpCallbacks[2] =
686   { {xaw_scrollbar_jump, NULL}, {NULL, NULL} };
687   
688   static XtCallbackRec scrollCallbacks[2] =
689   { {xaw_scrollbar_scroll, NULL}, {NULL, NULL} };
690
691   jumpCallbacks[0].closure = scrollCallbacks[0].closure = (XtPointer) instance;
692
693   /* #### This is tacked onto the with and height and completely
694      screws our geometry management.  We should probably make the
695      top-level aware of this so that people could have a border but so
696      few people use the Athena scrollbar now that it really isn't
697      worth the effort, at least not at the moment. */
698   XtSetArg (av [ac], XtNborderWidth, 0); ac++;
699   XtSetArg (av [ac], XtNorientation,
700             vertical ? XtorientVertical : XtorientHorizontal); ac++;
701   XtSetArg (av [ac], "jumpProc",   jumpCallbacks);   ac++;
702   XtSetArg (av [ac], "scrollProc", scrollCallbacks); ac++;
703
704   return XtCreateWidget (instance->info->name, scrollbarWidgetClass,
705                          instance->parent, av, ac);
706 }
707
708 static Widget
709 xaw_create_vertical_scrollbar (widget_instance *instance)
710 {
711   return xaw_create_scrollbar (instance, 1);
712 }
713
714 static Widget
715 xaw_create_horizontal_scrollbar (widget_instance *instance)
716 {
717   return xaw_create_scrollbar (instance, 0);
718 }
719 #endif /* LWLIB_SCROLLBARS_ATHENA */
720
721 #ifdef LWLIB_WIDGETS_ATHENA
722 /* glyph widgets */
723 static Widget
724 xaw_create_button (widget_instance *instance)
725 {
726   Arg al[20];
727   int ac = 0;
728   Widget button = 0;
729   widget_value* val = instance->info->val;
730
731   XtSetArg (al [ac], XtNsensitive, val->enabled);               ac++;
732   XtSetArg (al [ac], XtNmappedWhenManaged, FALSE);      ac++;
733   XtSetArg (al [ac], XtNjustify, XtJustifyCenter);              ac++;
734   /* The highlight doesn't appear to be dynamically set which makes it
735      look ugly.  I think this may be a LessTif bug but for now we just
736      get rid of it. */
737   XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
738
739   /* add any args the user supplied for creation time */
740   lw_add_value_args_to_args (val, al, &ac);
741
742   if (!val->call_data)
743     button = XtCreateManagedWidget (val->name, labelWidgetClass, 
744                                     instance->parent, al, ac);
745
746   else 
747     {
748       if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE)
749         {
750           XtSetArg (al [ac], XtNstate, val->selected);  ac++;
751           button = XtCreateManagedWidget 
752             (val->name, 
753              val->type == TOGGLE_TYPE ? checkboxWidgetClass : radioWidgetClass,
754              instance->parent, al, ac);
755         }
756       else 
757         {
758           button = XtCreateManagedWidget (val->name, commandWidgetClass,
759                                           instance->parent, al, ac);
760         }
761       XtRemoveAllCallbacks (button, XtNcallback);
762       XtAddCallback (button, XtNcallback, xaw_generic_callback, (XtPointer)instance);
763     }
764
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
793   /* Do it again for arguments that have no effect until the widget is realized. */
794   ac = 0;
795   lw_add_value_args_to_args (val, al, &ac);
796   if (ac > 20)
797     abort (); /* #### need assert macro in lwlib */
798   XtSetValues (label, al, ac);
799
800   return label;
801 }
802
803 static Widget
804 xaw_create_progress (widget_instance *instance)
805 {
806   Arg al[20];
807   int ac = 0;
808   Widget scale = 0;
809   widget_value* val = instance->info->val;
810 #if 0           /* This looks too awful, although more correct. */
811   if (!val->call_data)
812     {
813       XtSetArg (al [ac], XtNsensitive, False);          ac++;
814     }
815   else
816     {
817       XtSetArg (al [ac], XtNsensitive, val->enabled);           ac++;
818     }
819 #else
820   XtSetArg (al [ac], XtNsensitive, True);               ac++;
821 #endif
822
823   XtSetArg (al [ac], XtNmappedWhenManaged, FALSE);      ac++;
824   XtSetArg (al [ac], XtNorientation, XtorientHorizontal);       ac++;
825   XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
826   XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++;
827
828   /* add any args the user supplied for creation time */
829   lw_add_value_args_to_args (val, al, &ac);
830
831   scale = XtCreateManagedWidget (val->name, gaugeWidgetClass,
832                                  instance->parent, al, ac);
833   /* add the callback */
834   if (val->call_data)
835     XtAddCallback (scale, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
836
837   XtManageChild (scale);
838
839   return scale;
840 }
841
842 #if defined(LWLIB_WIDGETS_ATHENA)
843 #define TEXT_BUFFER_SIZE 128
844 static Widget
845 xaw_create_text_field (widget_instance *instance)
846 {
847   Arg al[20];
848   int ac = 0;
849   Widget text = 0;
850   widget_value* val = instance->info->val;
851
852   XtSetArg (al [ac], XtNsensitive, val->enabled);               ac++;
853   XtSetArg (al [ac], XtNmappedWhenManaged, FALSE);      ac++;
854   XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);      ac++;
855   XtSetArg (al [ac], XtNtype, XawAsciiString);          ac++;
856   XtSetArg (al [ac], XtNeditType, XawtextEdit);         ac++;
857   XtSetArg (al [ac], XtNuseStringInPlace, False);               ac++;
858 #if 0
859   XtSetArg (al [ac], XtNlength, TEXT_BUFFER_SIZE);      ac++;
860 #endif
861   if (val->value)
862     {
863       XtSetArg (al [ac], XtNstring, val->value);                ac++;
864     }
865
866   /* add any args the user supplied for creation time */
867   lw_add_value_args_to_args (val, al, &ac);
868
869   text = XtCreateManagedWidget (val->name, asciiTextWidgetClass,
870                                       instance->parent, al, ac);
871
872   /* add the callback */
873   if (val->call_data)
874     XtAddCallback (text, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
875
876   XtManageChild (text);
877
878   return text;
879 }
880 #endif
881
882 #endif /* LWLIB_WIDGETS_ATHENA */
883
884 const widget_creation_entry
885 xaw_creation_table [] =
886 {
887 #ifdef LWLIB_SCROLLBARS_ATHENA
888   {"vertical-scrollbar",        xaw_create_vertical_scrollbar   },
889   {"horizontal-scrollbar",      xaw_create_horizontal_scrollbar },
890 #endif
891 #ifdef LWLIB_WIDGETS_ATHENA
892   {"button",            xaw_create_button               },
893   { "label",            xaw_create_label_field          },
894   {"text-field",                xaw_create_text_field           },
895   {"progress",          xaw_create_progress             },
896 #endif
897   {NULL, NULL}
898 };
899