comparison lwlib/lwlib-Xaw.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 11054d720c21
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
31 #include <X11/IntrinsicP.h> 31 #include <X11/IntrinsicP.h>
32 #include <X11/CoreP.h> 32 #include <X11/CoreP.h>
33 #include <X11/Shell.h> 33 #include <X11/Shell.h>
34 34
35 #ifdef LWLIB_SCROLLBARS_ATHENA 35 #ifdef LWLIB_SCROLLBARS_ATHENA
36 #include ATHENA_Scrollbar_h_ 36 #include <X11/Xaw/Scrollbar.h>
37 #endif 37 #endif
38 #ifdef LWLIB_DIALOGS_ATHENA 38 #ifdef LWLIB_DIALOGS_ATHENA
39 #include ATHENA_Dialog_h_ 39 #include <X11/Xaw/Dialog.h>
40 #include ATHENA_Form_h_ 40 #include <X11/Xaw/Form.h>
41 #include ATHENA_Command_h_ 41 #include <X11/Xaw/Command.h>
42 #include ATHENA_Label_h_ 42 #include <X11/Xaw/Label.h>
43 #endif 43 #endif
44 #ifdef LWLIB_WIDGETS_ATHENA 44
45 #include ATHENA_Toggle_h_
46 #include "xlwradio.h"
47 #include "xlwcheckbox.h"
48 #include "xlwgauge.h"
49 #ifndef NEED_MOTIF
50 #include ATHENA_AsciiText_h_
51 #endif
52 #endif
53 #include <X11/Xatom.h> 45 #include <X11/Xatom.h>
54 46
55 static void xaw_generic_callback (Widget, XtPointer, XtPointer); 47 static void xaw_generic_callback (Widget, XtPointer, XtPointer);
56 48
57 49
62 #ifdef LWLIB_SCROLLBARS_ATHENA 54 #ifdef LWLIB_SCROLLBARS_ATHENA
63 || XtIsSubclass (widget, scrollbarWidgetClass) 55 || XtIsSubclass (widget, scrollbarWidgetClass)
64 #endif 56 #endif
65 #ifdef LWLIB_DIALOGS_ATHENA 57 #ifdef LWLIB_DIALOGS_ATHENA
66 || XtIsSubclass (widget, dialogWidgetClass) 58 || 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 59 #endif
76 ); 60 );
77 } 61 }
78 62
79 #ifdef LWLIB_SCROLLBARS_ATHENA 63 #ifdef LWLIB_SCROLLBARS_ATHENA
132 else if (XtIsSubclass (widget, scrollbarWidgetClass)) 116 else if (XtIsSubclass (widget, scrollbarWidgetClass))
133 { 117 {
134 xaw_update_scrollbar (instance, widget, val); 118 xaw_update_scrollbar (instance, widget, val);
135 } 119 }
136 #endif 120 #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 121 #ifdef LWLIB_DIALOGS_ATHENA
145 else if (XtIsSubclass (widget, dialogWidgetClass)) 122 else if (XtIsSubclass (widget, dialogWidgetClass))
146 { 123 {
147 Arg al [1]; 124 Arg al [1];
148 XtSetArg (al [0], XtNlabel, val->contents->value); 125 XtSetArg (al [0], XtNlabel, val->contents->value);
149 XtSetValues (widget, al, 1); 126 XtSetValues (widget, al, 1);
150 } 127 }
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)) 128 else if (XtIsSubclass (widget, commandWidgetClass))
162 { 129 {
163 Dimension bw = 0; 130 Dimension bw = 0;
164 Arg al [3]; 131 Arg al [3];
165 XtSetArg (al [0], XtNborderWidth, &bw); 132 XtSetArg (al [0], XtNborderWidth, &bw);
185 XtSetArg (al [2], XtNjustify, XtJustifyCenter); 152 XtSetArg (al [2], XtNjustify, XtJustifyCenter);
186 XtSetValues (widget, al, 3); 153 XtSetValues (widget, al, 3);
187 154
188 XtRemoveAllCallbacks (widget, XtNcallback); 155 XtRemoveAllCallbacks (widget, XtNcallback);
189 XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance); 156 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 } 157 }
199 #endif /* LWLIB_DIALOGS_ATHENA */ 158 #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 } 159 }
204 160
205 void 161 void
206 xaw_update_one_value (widget_instance *instance, Widget widget, 162 xaw_update_one_value (widget_instance *instance, Widget widget,
207 widget_value *val) 163 widget_value *val)
208 { 164 {
209 #ifdef LWLIB_WIDGETS_ATHENA 165 /* This function is not used by the scrollbars and those are the only
210 widget_value *old_wv; 166 Athena widget implemented at the moment so do nothing. */
211 167 return;
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, 1);
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 } 168 }
248 169
249 void 170 void
250 xaw_destroy_instance (widget_instance *instance) 171 xaw_destroy_instance (widget_instance *instance)
251 { 172 {
342 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window} 263 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window}
343 }; 264 };
344 static Boolean actions_initted = False; 265 static Boolean actions_initted = False;
345 266
346 static Widget 267 static Widget
347 make_dialog (const char* name, Widget parent, Boolean pop_up_p, 268 make_dialog (CONST char* name, Widget parent, Boolean pop_up_p,
348 const char* shell_title, const char* icon_name, 269 CONST char* shell_title, CONST char* icon_name,
349 Boolean text_input_slot, 270 Boolean text_input_slot,
350 Boolean radio_box, Boolean list, 271 Boolean radio_box, Boolean list,
351 int left_buttons, int right_buttons) 272 int left_buttons, int right_buttons)
352 { 273 {
353 Arg av [20]; 274 Arg av [20];
451 { 372 {
452 char *name = instance->info->type; 373 char *name = instance->info->type;
453 Widget parent = instance->parent; 374 Widget parent = instance->parent;
454 Widget widget; 375 Widget widget;
455 Boolean pop_up_p = instance->pop_up_p; 376 Boolean pop_up_p = instance->pop_up_p;
456 const char *shell_name = 0; 377 CONST char *shell_name = 0;
457 const char *icon_name = 0; 378 CONST char *icon_name = 0;
458 Boolean text_input_slot = False; 379 Boolean text_input_slot = False;
459 Boolean radio_box = False; 380 Boolean radio_box = False;
460 Boolean list = False; 381 Boolean list = False;
461 int total_buttons; 382 int total_buttons;
462 int left_buttons = 0; 383 int left_buttons = 0;
517 { 438 {
518 widget_instance *instance = (widget_instance *) closure; 439 widget_instance *instance = (widget_instance *) closure;
519 Widget instance_widget; 440 Widget instance_widget;
520 LWLIB_ID id; 441 LWLIB_ID id;
521 XtPointer user_data; 442 XtPointer user_data;
522 #ifdef LWLIB_WIDGETS_ATHENA 443
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); 444 lw_internal_update_other_instances (widget, closure, call_data);
538 445
539 if (! instance) 446 if (! instance)
540 return; 447 return;
541 if (widget->core.being_destroyed) 448 if (widget->core.being_destroyed)
555 XtGetValues (widget, al, 1); 462 XtGetValues (widget, al, 1);
556 } 463 }
557 #else 464 #else
558 /* Damn! Athena doesn't give us a way to hang our own data on the 465 /* 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 466 buttons, so we have to go find it... I guess this assumes that
560 all instances of a button have the same call data. 467 all instances of a button have the same call data. */
561
562 ... Which is a totally bogus assumption --andyp */
563 { 468 {
564 widget_value *val = instance->info->val; 469 widget_value *val = instance->info->val->contents;
565 /* If the widget is a buffer/gutter widget then we already have 470 char *name = XtName (widget);
566 the one we are looking for, so don't try and descend the widget 471 while (val)
567 tree. */
568 if (val->contents)
569 { 472 {
570 char *name = XtName (widget); 473 if (val->name && !strcmp (val->name, name))
571 val = val->contents; 474 break;
572 while (val) 475 val = val->next;
573 {
574 if (val->name && !strcmp (val->name, name))
575 break;
576 val = val->next;
577 }
578 if (! val) abort ();
579 } 476 }
477 if (! val) abort ();
580 user_data = val->call_data; 478 user_data = val->call_data;
581 } 479 }
582 #endif 480 #endif
583 481
584 if (instance->info->selection_cb) 482 if (instance->info->selection_cb)
714 { 612 {
715 return xaw_create_scrollbar (instance, 0); 613 return xaw_create_scrollbar (instance, 0);
716 } 614 }
717 #endif /* LWLIB_SCROLLBARS_ATHENA */ 615 #endif /* LWLIB_SCROLLBARS_ATHENA */
718 616
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 if (ac > 20)
795 abort (); /* #### need assert macro in lwlib */
796 XtSetValues (label, al, ac);
797
798 return label;
799 }
800
801 static Widget
802 xaw_create_progress (widget_instance *instance)
803 {
804 Arg al[20];
805 int ac = 0;
806 Widget scale = 0;
807 widget_value* val = instance->info->val;
808 #if 0 /* This looks too awful, although more correct. */
809 if (!val->call_data)
810 {
811 XtSetArg (al [ac], XtNsensitive, False); ac++;
812 }
813 else
814 {
815 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
816 }
817 #else
818 XtSetArg (al [ac], XtNsensitive, True); ac++;
819 #endif
820
821 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
822 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++;
823 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
824 XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++;
825
826 /* add any args the user supplied for creation time */
827 lw_add_value_args_to_args (val, al, &ac);
828
829 scale = XtCreateManagedWidget (val->name, gaugeWidgetClass,
830 instance->parent, al, ac);
831 /* add the callback */
832 if (val->call_data)
833 XtAddCallback (scale, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
834
835 XtManageChild (scale);
836
837 return scale;
838 }
839
840 #ifndef NEED_MOTIF
841 #define TEXT_BUFFER_SIZE 128
842 static Widget
843 xaw_create_text_field (widget_instance *instance)
844 {
845 Arg al[20];
846 int ac = 0;
847 Widget text = 0;
848 widget_value* val = instance->info->val;
849
850 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
851 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
852 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++;
853 XtSetArg (al [ac], XtNtype, XawAsciiString); ac++;
854 XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++;
855 XtSetArg (al [ac], XtNuseStringInPlace, False); ac++;
856 #if 0
857 XtSetArg (al [ac], XtNlength, TEXT_BUFFER_SIZE); ac++;
858 #endif
859 if (val->value)
860 {
861 XtSetArg (al [ac], XtNstring, val->value); ac++;
862 }
863
864 /* add any args the user supplied for creation time */
865 lw_add_value_args_to_args (val, al, &ac);
866
867 text = XtCreateManagedWidget (val->name, asciiTextWidgetClass,
868 instance->parent, al, ac);
869
870 /* add the callback */
871 if (val->call_data)
872 XtAddCallback (text, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
873
874 XtManageChild (text);
875
876 return text;
877 }
878 #endif
879
880 #endif /* LWLIB_WIDGETS_ATHENA */
881
882 widget_creation_entry 617 widget_creation_entry
883 xaw_creation_table [] = 618 xaw_creation_table [] =
884 { 619 {
885 #ifdef LWLIB_SCROLLBARS_ATHENA 620 #ifdef LWLIB_SCROLLBARS_ATHENA
886 {"vertical-scrollbar", xaw_create_vertical_scrollbar }, 621 {"vertical-scrollbar", xaw_create_vertical_scrollbar},
887 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar }, 622 {"horizontal-scrollbar", xaw_create_horizontal_scrollbar},
888 #endif
889 #ifdef LWLIB_WIDGETS_ATHENA
890 {"button", xaw_create_button },
891 { "label", xaw_create_label_field },
892 #ifndef NEED_MOTIF
893 {"text-field", xaw_create_text_field },
894 #endif
895 {"progress", xaw_create_progress },
896 #endif 623 #endif
897 {NULL, NULL} 624 {NULL, NULL}
898 }; 625 };
899