comparison lwlib/lwlib-Xaw.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 84b14dcb0985
children 98528da0b7fc
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
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_INCLUDE(Scrollbar.h) 36 #include ATHENA_Scrollbar_h_
37 #endif 37 #endif
38 #ifdef LWLIB_DIALOGS_ATHENA 38 #ifdef LWLIB_DIALOGS_ATHENA
39 #include ATHENA_INCLUDE(Dialog.h) 39 #include ATHENA_Dialog_h_
40 #include ATHENA_INCLUDE(Form.h) 40 #include ATHENA_Form_h_
41 #include ATHENA_INCLUDE(Command.h) 41 #include ATHENA_Command_h_
42 #include ATHENA_INCLUDE(Label.h) 42 #include ATHENA_Label_h_
43 #endif 43 #endif
44 #ifdef LWLIB_WIDGETS_ATHENA 44 #ifdef LWLIB_WIDGETS_ATHENA
45 #include ATHENA_INCLUDE(Toggle.h) 45 #include ATHENA_Toggle_h_
46 #include "xlwradio.h" 46 #include "xlwradio.h"
47 #include "xlwcheckbox.h" 47 #include "xlwcheckbox.h"
48 #include "xlwgauge.h" 48 #include "xlwgauge.h"
49 #ifndef NEED_MOTIF 49 #ifndef NEED_MOTIF
50 #include ATHENA_INCLUDE(AsciiText.h) 50 #include ATHENA_AsciiText_h_
51 #endif 51 #endif
52 #endif 52 #endif
53 #include <X11/Xatom.h> 53 #include <X11/Xatom.h>
54 54
55 static void xaw_generic_callback (Widget, XtPointer, XtPointer); 55 static void xaw_generic_callback (Widget, XtPointer, XtPointer);
67 #endif 67 #endif
68 #ifdef LWLIB_WIDGETS_ATHENA 68 #ifdef LWLIB_WIDGETS_ATHENA
69 || XtIsSubclass (widget, labelWidgetClass) 69 || XtIsSubclass (widget, labelWidgetClass)
70 || XtIsSubclass (widget, toggleWidgetClass) 70 || XtIsSubclass (widget, toggleWidgetClass)
71 || XtIsSubclass (widget, gaugeWidgetClass) 71 || XtIsSubclass (widget, gaugeWidgetClass)
72 #if 0 72 #ifndef NEED_MOTIF
73 || XtIsSubclass (widget, textWidgetClass) 73 || XtIsSubclass (widget, asciiTextWidgetClass)
74 #endif 74 #endif
75 #endif 75 #endif
76 ); 76 );
77 } 77 }
78 78
124 124
125 void 125 void
126 xaw_update_one_widget (widget_instance *instance, Widget widget, 126 xaw_update_one_widget (widget_instance *instance, Widget widget,
127 widget_value *val, Boolean deep_p) 127 widget_value *val, Boolean deep_p)
128 { 128 {
129 if (val->args && val->args->nargs)
130 XtSetValues (widget, val->args->args, val->args->nargs);
131
132 if (0) 129 if (0)
133 ; 130 ;
134 #ifdef LWLIB_SCROLLBARS_ATHENA 131 #ifdef LWLIB_SCROLLBARS_ATHENA
135 else if (XtIsSubclass (widget, scrollbarWidgetClass)) 132 else if (XtIsSubclass (widget, scrollbarWidgetClass))
136 { 133 {
137 xaw_update_scrollbar (instance, widget, val); 134 xaw_update_scrollbar (instance, widget, val);
138 } 135 }
136 #endif
137 #ifdef LWLIB_WIDGETS_ATHENA
138 #ifndef NEED_MOTIF
139 else if (XtIsSubclass (widget, asciiTextWidgetClass))
140 {
141 }
142 #endif
139 #endif 143 #endif
140 #ifdef LWLIB_DIALOGS_ATHENA 144 #ifdef LWLIB_DIALOGS_ATHENA
141 else if (XtIsSubclass (widget, dialogWidgetClass)) 145 else if (XtIsSubclass (widget, dialogWidgetClass))
142 { 146 {
143 Arg al [1]; 147 Arg al [1];
173 XtSetArg (al [0], XtNborderWidth, 1); 177 XtSetArg (al [0], XtNborderWidth, 1);
174 XtSetValues (widget, al, 1); 178 XtSetValues (widget, al, 1);
175 } 179 }
176 #endif /* ! LWLIB_DIALOGS_ATHENA3D */ 180 #endif /* ! LWLIB_DIALOGS_ATHENA3D */
177 181
182 lw_remove_accelerator_spec (val->value);
178 XtSetArg (al [0], XtNlabel, val->value); 183 XtSetArg (al [0], XtNlabel, val->value);
179 XtSetArg (al [1], XtNsensitive, val->enabled); 184 XtSetArg (al [1], XtNsensitive, val->enabled);
180 /* Force centered button text. See above. */ 185 /* Force centered button text. See above. */
181 XtSetArg (al [2], XtNjustify, XtJustifyCenter); 186 XtSetArg (al [2], XtNjustify, XtJustifyCenter);
182 XtSetValues (widget, al, 3); 187 XtSetValues (widget, al, 3);
191 XtSetValues (widget, al, 1); 196 XtSetValues (widget, al, 1);
192 } 197 }
193 #endif /* LWLIB_WIDGETS_ATHENA */ 198 #endif /* LWLIB_WIDGETS_ATHENA */
194 } 199 }
195 #endif /* LWLIB_DIALOGS_ATHENA */ 200 #endif /* LWLIB_DIALOGS_ATHENA */
201 /* Lastly update our global arg values. */
202 if (val->args && val->args->nargs)
203 XtSetValues (widget, val->args->args, val->args->nargs);
196 } 204 }
197 205
198 void 206 void
199 xaw_update_one_value (widget_instance *instance, Widget widget, 207 xaw_update_one_value (widget_instance *instance, Widget widget,
200 widget_value *val) 208 widget_value *val)
218 val->edited = True; 226 val->edited = True;
219 } 227 }
220 #ifndef NEED_MOTIF 228 #ifndef NEED_MOTIF
221 else if (XtIsSubclass (widget, asciiTextWidgetClass)) 229 else if (XtIsSubclass (widget, asciiTextWidgetClass))
222 { 230 {
223 Arg al [1]; 231 Arg al [2];
232 String buf = 0;
233 XtSetArg (al [0], XtNstring, &buf);
234 XtGetValues (widget, al, 1);
235
224 if (val->value) 236 if (val->value)
225 free (val->value); 237 {
226 XtSetArg (al [0], XtNstring, &val->value); 238 free (val->value);
227 XtGetValues (widget, al, 1); 239 val->value = 0;
240 }
241 /* I don't think this causes a leak. */
242 if (buf)
243 val->value = strdup (buf);
228 val->edited = True; 244 val->edited = True;
229 } 245 }
230 #endif 246 #endif
231 #endif /* LWLIB_WIDGETS_ATHENA */ 247 #endif /* LWLIB_WIDGETS_ATHENA */
232 } 248 }
327 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window} 343 {"lwlib_delete_dialog", (XtActionProc) wm_delete_window}
328 }; 344 };
329 static Boolean actions_initted = False; 345 static Boolean actions_initted = False;
330 346
331 static Widget 347 static Widget
332 make_dialog (CONST char* name, Widget parent, Boolean pop_up_p, 348 make_dialog (const char* name, Widget parent, Boolean pop_up_p,
333 CONST char* shell_title, CONST char* icon_name, 349 const char* shell_title, const char* icon_name,
334 Boolean text_input_slot, 350 Boolean text_input_slot,
335 Boolean radio_box, Boolean list, 351 Boolean radio_box, Boolean list,
336 int left_buttons, int right_buttons) 352 int left_buttons, int right_buttons)
337 { 353 {
338 Arg av [20]; 354 Arg av [20];
436 { 452 {
437 char *name = instance->info->type; 453 char *name = instance->info->type;
438 Widget parent = instance->parent; 454 Widget parent = instance->parent;
439 Widget widget; 455 Widget widget;
440 Boolean pop_up_p = instance->pop_up_p; 456 Boolean pop_up_p = instance->pop_up_p;
441 CONST char *shell_name = 0; 457 const char *shell_name = 0;
442 CONST char *icon_name = 0; 458 const char *icon_name = 0;
443 Boolean text_input_slot = False; 459 Boolean text_input_slot = False;
444 Boolean radio_box = False; 460 Boolean radio_box = False;
445 Boolean list = False; 461 Boolean list = False;
446 int total_buttons; 462 int total_buttons;
447 int left_buttons = 0; 463 int left_buttons = 0;
774 parent, al, ac); 790 parent, al, ac);
775 791
776 /* Do it again for arguments that have no effect until the widget is realized. */ 792 /* Do it again for arguments that have no effect until the widget is realized. */
777 ac = 0; 793 ac = 0;
778 lw_add_value_args_to_args (val, al, &ac); 794 lw_add_value_args_to_args (val, al, &ac);
795 if (ac > 20)
796 abort (); /* #### need assert macro in lwlib */
779 XtSetValues (label, al, ac); 797 XtSetValues (label, al, ac);
780 798
781 return label; 799 return label;
782 } 800 }
783 801
786 { 804 {
787 Arg al[20]; 805 Arg al[20];
788 int ac = 0; 806 int ac = 0;
789 Widget scale = 0; 807 Widget scale = 0;
790 widget_value* val = instance->info->val; 808 widget_value* val = instance->info->val;
791 809 #if 0 /* This looks too awful, although more correct. */
792 if (!val->call_data) 810 if (!val->call_data)
793 { 811 {
794 XtSetArg (al [ac], XtNsensitive, False); ac++; 812 XtSetArg (al [ac], XtNsensitive, False); ac++;
795 } 813 }
796 else 814 else
797 { 815 {
798 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; 816 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
799 } 817 }
818 #else
819 XtSetArg (al [ac], XtNsensitive, True); ac++;
820 #endif
821
800 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; 822 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
801 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++; 823 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++;
802 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++; 824 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++;
803 XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++; 825 XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++;
804 826
815 837
816 return scale; 838 return scale;
817 } 839 }
818 840
819 #ifndef NEED_MOTIF 841 #ifndef NEED_MOTIF
842 #define TEXT_BUFFER_SIZE 128
820 static Widget 843 static Widget
821 xaw_create_text_field (widget_instance *instance) 844 xaw_create_text_field (widget_instance *instance)
822 { 845 {
823 Arg al[20]; 846 Arg al[20];
824 int ac = 0; 847 int ac = 0;
825 Widget text = 0; 848 Widget text = 0;
826 widget_value* val = instance->info->val; 849 widget_value* val = instance->info->val;
827 850
828 XtSetArg (al [ac], XtNsensitive, val->enabled && val->call_data); ac++; 851 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
829 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; 852 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
830 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++; 853 XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++;
831 XtSetArg (al [ac], XtNtype, XawAsciiString); ac++; 854 XtSetArg (al [ac], XtNtype, XawAsciiString); ac++;
832 XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++; 855 XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++;
856 XtSetArg (al [ac], XtNuseStringInPlace, False); ac++;
857 #if 0
858 XtSetArg (al [ac], XtNlength, TEXT_BUFFER_SIZE); ac++;
859 #endif
860 if (val->value)
861 {
862 XtSetArg (al [ac], XtNstring, val->value); ac++;
863 }
833 864
834 /* add any args the user supplied for creation time */ 865 /* add any args the user supplied for creation time */
835 lw_add_value_args_to_args (val, al, &ac); 866 lw_add_value_args_to_args (val, al, &ac);
836 867
837 text = XtCreateManagedWidget (val->name, asciiTextWidgetClass, 868 text = XtCreateManagedWidget (val->name, asciiTextWidgetClass,
838 instance->parent, al, ac); 869 instance->parent, al, ac);
870
871 /* add the callback */
872 if (val->call_data)
873 XtAddCallback (text, XtNgetValue, xaw_generic_callback, (XtPointer)instance);
874
839 XtManageChild (text); 875 XtManageChild (text);
840 876
841 return text; 877 return text;
842 } 878 }
843 #endif 879 #endif
880
844 #endif /* LWLIB_WIDGETS_ATHENA */ 881 #endif /* LWLIB_WIDGETS_ATHENA */
845 882
846 widget_creation_entry 883 widget_creation_entry
847 xaw_creation_table [] = 884 xaw_creation_table [] =
848 { 885 {