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