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