comparison lwlib/lwlib-Xaw.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 697ef44129c6
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
39 #include <X11/Xaw/Dialog.h> 39 #include <X11/Xaw/Dialog.h>
40 #include <X11/Xaw/Form.h> 40 #include <X11/Xaw/Form.h>
41 #include <X11/Xaw/Command.h> 41 #include <X11/Xaw/Command.h>
42 #include <X11/Xaw/Label.h> 42 #include <X11/Xaw/Label.h>
43 #endif 43 #endif
44 44 #ifdef LWLIB_WIDGETS_ATHENA
45 #include <X11/Xaw/Toggle.h>
46 #include "xlwradio.h"
47 #include "xlwcheckbox.h"
48 #include "xlwgauge.h"
49 #ifndef NEED_MOTIF
50 #include <X11/Xaw/AsciiText.h>
51 #endif
52 #endif
45 #include <X11/Xatom.h> 53 #include <X11/Xatom.h>
46 54
47 static void xaw_generic_callback (Widget, XtPointer, XtPointer); 55 static void xaw_generic_callback (Widget, XtPointer, XtPointer);
48 56
49 57
54 #ifdef LWLIB_SCROLLBARS_ATHENA 62 #ifdef LWLIB_SCROLLBARS_ATHENA
55 || XtIsSubclass (widget, scrollbarWidgetClass) 63 || XtIsSubclass (widget, scrollbarWidgetClass)
56 #endif 64 #endif
57 #ifdef LWLIB_DIALOGS_ATHENA 65 #ifdef LWLIB_DIALOGS_ATHENA
58 || XtIsSubclass (widget, dialogWidgetClass) 66 || XtIsSubclass (widget, dialogWidgetClass)
67 #endif
68 #ifdef LWLIB_WIDGETS_ATHENA
69 || XtIsSubclass (widget, labelWidgetClass)
70 || XtIsSubclass (widget, toggleWidgetClass)
71 || XtIsSubclass (widget, gaugeWidgetClass)
72 #if 0
73 || XtIsSubclass (widget, textWidgetClass)
74 #endif
59 #endif 75 #endif
60 ); 76 );
61 } 77 }
62 78
63 #ifdef LWLIB_SCROLLBARS_ATHENA 79 #ifdef LWLIB_SCROLLBARS_ATHENA
108 124
109 void 125 void
110 xaw_update_one_widget (widget_instance *instance, Widget widget, 126 xaw_update_one_widget (widget_instance *instance, Widget widget,
111 widget_value *val, Boolean deep_p) 127 widget_value *val, Boolean deep_p)
112 { 128 {
129 if (val->nargs)
130 XtSetValues (widget, val->args, val->nargs);
131
113 if (0) 132 if (0)
114 ; 133 ;
115 #ifdef LWLIB_SCROLLBARS_ATHENA 134 #ifdef LWLIB_SCROLLBARS_ATHENA
116 else if (XtIsSubclass (widget, scrollbarWidgetClass)) 135 else if (XtIsSubclass (widget, scrollbarWidgetClass))
117 { 136 {
123 { 142 {
124 Arg al [1]; 143 Arg al [1];
125 XtSetArg (al [0], XtNlabel, val->contents->value); 144 XtSetArg (al [0], XtNlabel, val->contents->value);
126 XtSetValues (widget, al, 1); 145 XtSetValues (widget, al, 1);
127 } 146 }
147 #endif /* LWLIB_DIALOGS_ATHENA */
148 #ifdef LWLIB_WIDGETS_ATHENA
149 else if (XtClass (widget) == labelWidgetClass)
150 {
151 Arg al [1];
152 XtSetArg (al [0], XtNlabel, val->value);
153 XtSetValues (widget, al, 1);
154 }
155 #endif /* LWLIB_WIDGETS_ATHENA */
156 #if defined (LWLIB_DIALOGS_ATHENA) || defined (LWLIB_WIDGETS_ATHENA)
128 else if (XtIsSubclass (widget, commandWidgetClass)) 157 else if (XtIsSubclass (widget, commandWidgetClass))
129 { 158 {
130 Dimension bw = 0; 159 Dimension bw = 0;
131 Arg al [3]; 160 Arg al [3];
132 XtSetArg (al [0], XtNborderWidth, &bw); 161 XtSetArg (al [0], XtNborderWidth, &bw);
152 XtSetArg (al [2], XtNjustify, XtJustifyCenter); 181 XtSetArg (al [2], XtNjustify, XtJustifyCenter);
153 XtSetValues (widget, al, 3); 182 XtSetValues (widget, al, 3);
154 183
155 XtRemoveAllCallbacks (widget, XtNcallback); 184 XtRemoveAllCallbacks (widget, XtNcallback);
156 XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance); 185 XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance);
186 #ifdef LWLIB_WIDGETS_ATHENA
187 /* set the selected state */
188 if (XtIsSubclass (widget, toggleWidgetClass))
189 {
190 XtSetArg (al [0], XtNstate, val->selected);
191 XtSetValues (widget, al, 1);
192 }
193 #endif /* LWLIB_WIDGETS_ATHENA */
157 } 194 }
158 #endif /* LWLIB_DIALOGS_ATHENA */ 195 #endif /* LWLIB_DIALOGS_ATHENA */
159 } 196 }
160 197
161 void 198 void
162 xaw_update_one_value (widget_instance *instance, Widget widget, 199 xaw_update_one_value (widget_instance *instance, Widget widget,
163 widget_value *val) 200 widget_value *val)
164 { 201 {
165 /* This function is not used by the scrollbars and those are the only 202 #ifdef LWLIB_WIDGETS_ATHENA
166 Athena widget implemented at the moment so do nothing. */ 203 widget_value *old_wv;
167 return; 204
205 /* copy the call_data slot into the "return" widget_value */
206 for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next)
207 if (!strcmp (val->name, old_wv->name))
208 {
209 val->call_data = old_wv->call_data;
210 break;
211 }
212
213 if (XtIsSubclass (widget, toggleWidgetClass))
214 {
215 Arg al [1];
216 XtSetArg (al [0], XtNstate, &val->selected);
217 XtGetValues (widget, al, 1);
218 val->edited = True;
219 }
220 #ifndef NEED_MOTIF
221 else if (XtIsSubclass (widget, asciiTextWidgetClass))
222 {
223 Arg al [1];
224 if (val->value)
225 free (val->value);
226 XtSetArg (al [0], XtNstring, &val->value);
227 XtGetValues (widget, al, 1);
228 val->edited = True;
229 }
230 #endif
231 #endif /* LWLIB_WIDGETS_ATHENA */
168 } 232 }
169 233
170 void 234 void
171 xaw_destroy_instance (widget_instance *instance) 235 xaw_destroy_instance (widget_instance *instance)
172 { 236 {
438 { 502 {
439 widget_instance *instance = (widget_instance *) closure; 503 widget_instance *instance = (widget_instance *) closure;
440 Widget instance_widget; 504 Widget instance_widget;
441 LWLIB_ID id; 505 LWLIB_ID id;
442 XtPointer user_data; 506 XtPointer user_data;
443 507 #ifdef LWLIB_WIDGETS_ATHENA
508 /* We want the selected status to change only when we decide it
509 should change. Yuck but correct. */
510 if (XtIsSubclass (widget, toggleWidgetClass))
511 {
512 Boolean check;
513 Arg al [1];
514
515 XtSetArg (al [0], XtNstate, &check);
516 XtGetValues (widget, al, 1);
517
518 XtSetArg (al [0], XtNstate, !check);
519 XtSetValues (widget, al, 1);
520 }
521 #endif /* LWLIB_WIDGETS_ATHENA */
444 lw_internal_update_other_instances (widget, closure, call_data); 522 lw_internal_update_other_instances (widget, closure, call_data);
445 523
446 if (! instance) 524 if (! instance)
447 return; 525 return;
448 if (widget->core.being_destroyed) 526 if (widget->core.being_destroyed)
462 XtGetValues (widget, al, 1); 540 XtGetValues (widget, al, 1);
463 } 541 }
464 #else 542 #else
465 /* Damn! Athena doesn't give us a way to hang our own data on the 543 /* Damn! Athena doesn't give us a way to hang our own data on the
466 buttons, so we have to go find it... I guess this assumes that 544 buttons, so we have to go find it... I guess this assumes that
467 all instances of a button have the same call data. */ 545 all instances of a button have the same call data.
546
547 ... Which is a totally bogus assumption --andyp */
468 { 548 {
469 widget_value *val = instance->info->val->contents; 549 widget_value *val = instance->info->val;
470 char *name = XtName (widget); 550 /* If the widget is a buffer/gutter widget then we already have
471 while (val) 551 the one we are looking for, so don't try and descend the widget
552 tree. */
553 if (val->contents)
472 { 554 {
473 if (val->name && !strcmp (val->name, name)) 555 char *name = XtName (widget);
474 break; 556 val = val->contents;
475 val = val->next; 557 while (val)
558 {
559 if (val->name && !strcmp (val->name, name))
560 break;
561 val = val->next;
562 }
563 if (! val) abort ();
476 } 564 }
477 if (! val) abort ();
478 user_data = val->call_data; 565 user_data = val->call_data;
479 } 566 }
480 #endif 567 #endif
481 568
482 if (instance->info->selection_cb) 569 if (instance->info->selection_cb)
612 { 699 {
613 return xaw_create_scrollbar (instance, 0); 700 return xaw_create_scrollbar (instance, 0);
614 } 701 }
615 #endif /* LWLIB_SCROLLBARS_ATHENA */ 702 #endif /* LWLIB_SCROLLBARS_ATHENA */
616 703
704 #ifdef LWLIB_WIDGETS_ATHENA
705 /* glyph widgets */
706 static Widget
707 xaw_create_button (widget_instance *instance)
708 {
709 Arg al[20];
710 int ac = 0;
711 Widget button = 0;
712 widget_value* val = instance->info->val;
713
714 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
715 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
716 XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++;
717 /* The highlight doesn't appear to be dynamically set which makes it
718 look ugly. I think this may be a LessTif bug but for now we just
719 get rid of it. */
720 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
721
722 /* add any args the user supplied for creation time */
723 lw_add_value_args_to_args (val, al, &ac);
724
725 if (!val->call_data)
726 button = XtCreateManagedWidget (val->name, labelWidgetClass,
727 instance->parent, al, ac);
728
729 else
730 {
731 if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE)
732 {
733 XtSetArg (al [ac], XtNstate, val->selected); ac++;
734 button = XtCreateManagedWidget
735 (val->name,
736 val->type == TOGGLE_TYPE ? checkboxWidgetClass : radioWidgetClass,
737 instance->parent, al, ac);
738 }
739 else
740 {
741 button = XtCreateManagedWidget (val->name, commandWidgetClass,
742 instance->parent, al, ac);
743 }
744 XtRemoveAllCallbacks (button, XtNcallback);
745 XtAddCallback (button, XtNcallback, xaw_generic_callback, (XtPointer)instance);
746 }
747
748 XtManageChild (button);
749
750 return button;
751 }
752
753 static Widget
754 xaw_create_label_field (widget_instance *instance)
755 {
756 return xaw_create_label (instance->parent, instance->info->val);
757 }
758
759 Widget
760 xaw_create_label (Widget parent, widget_value* val)
761 {
762 Arg al[20];
763 int ac = 0;
764 Widget label = 0;
765
766 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
767 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
768 XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++;
769
770 /* add any args the user supplied for creation time */
771 lw_add_value_args_to_args (val, al, &ac);
772
773 label = XtCreateManagedWidget (val->name, labelWidgetClass,
774 parent, al, ac);
775
776 /* Do it again for arguments that have no effect until the widget is realized. */
777 ac = 0;
778 lw_add_value_args_to_args (val, al, &ac);
779 XtSetValues (label, al, ac);
780
781 return label;
782 }
783
784 static Widget
785 xaw_create_progress (widget_instance *instance)
786 {
787 Arg al[20];
788 int ac = 0;
789 Widget scale = 0;
790 widget_value* val = instance->info->val;
791
792 if (!val->call_data)
793 {
794 XtSetArg (al [ac], XtNsensitive, False); ac++;
795 }
796 else
797 {
798 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
799 }
800 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
801 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++;
802 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
803 XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++;
804
805 /* add any args the user supplied for creation time */
806 lw_add_value_args_to_args (val, al, &ac);
807
808 scale = XtCreateManagedWidget (val->name, gaugeWidgetClass,
809 instance->parent, al, ac);
810 /* add the callback */
811 if (val->call_data)
812 XtAddCallback (scale, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
813
814 XtManageChild (scale);
815
816 return scale;
817 }
818
819 #ifndef NEED_MOTIF
820 static Widget
821 xaw_create_text_field (widget_instance *instance)
822 {
823 Arg al[20];
824 int ac = 0;
825 Widget text = 0;
826 widget_value* val = instance->info->val;
827
828 XtSetArg (al [ac], XtNsensitive, val->enabled && val->call_data); ac++;
829 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
830 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++;
831 XtSetArg (al [ac], XtNtype, XawAsciiString); ac++;
832 XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++;
833
834 /* add any args the user supplied for creation time */
835 lw_add_value_args_to_args (val, al, &ac);
836
837 text = XtCreateManagedWidget (val->name, asciiTextWidgetClass,
838 instance->parent, al, ac);
839 XtManageChild (text);
840
841 return text;
842 }
843 #endif
844 #endif /* LWLIB_WIDGETS_ATHENA */
845
617 widget_creation_entry 846 widget_creation_entry
618 xaw_creation_table [] = 847 xaw_creation_table [] =
619 { 848 {
620 #ifdef LWLIB_SCROLLBARS_ATHENA 849 #ifdef LWLIB_SCROLLBARS_ATHENA
621 {"vertical-scrollbar", xaw_create_vertical_scrollbar}, 850 {"vertical-scrollbar", xaw_create_vertical_scrollbar },
622 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar}, 851 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar },
852 #endif
853 #ifdef LWLIB_WIDGETS_ATHENA
854 {"button", xaw_create_button },
855 { "label", xaw_create_label_field },
856 #ifndef NEED_MOTIF
857 {"text-field", xaw_create_text_field },
858 #endif
859 {"progress", xaw_create_progress },
623 #endif 860 #endif
624 {NULL, NULL} 861 {NULL, NULL}
625 }; 862 };
863