aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-02-01 18:21:00 +0000
committerRichard M. Stallman1994-02-01 18:21:00 +0000
commit5f61736f6513125d647cd4ac2bdac331778a97f1 (patch)
tree2c9761fd267e24dc3021fde545a17f40fc2b5925
parentda4ce263a3d1a185f0c004260c90f55960ff9d32 (diff)
downloademacs-5f61736f6513125d647cd4ac2bdac331778a97f1.tar.gz
emacs-5f61736f6513125d647cd4ac2bdac331778a97f1.zip
*** empty log message ***
-rw-r--r--lwlib/lwlib.c217
1 files changed, 165 insertions, 52 deletions
diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c
index 21ca8987f7b..2f1e93ec343 100644
--- a/lwlib/lwlib.c
+++ b/lwlib/lwlib.c
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26#include <sys/types.h> 26#include <sys/types.h>
27#include <string.h> 27#include <string.h>
28#include <stdio.h> 28#include <stdio.h>
29#include <ctype.h>
29#include "lwlib-int.h" 30#include "lwlib-int.h"
30#include "lwlib-utils.h" 31#include "lwlib-utils.h"
31#include <X11/StringDefs.h> 32#include <X11/StringDefs.h>
@@ -66,11 +67,12 @@ all_widget_info = NULL;
66 67
67 /* Forward declarations */ 68 /* Forward declarations */
68static void 69static void
69instanciate_widget_instance (widget_instance* instance); 70instanciate_widget_instance (/* widget_instance* instance */);
70 71
71 /* utility functions for widget_instance and widget_info */ 72 /* utility functions for widget_instance and widget_info */
72static char * 73static char *
73safe_strdup (char* s) 74safe_strdup (s)
75 char *s;
74{ 76{
75 char *result; 77 char *result;
76 if (! s) return 0; 78 if (! s) return 0;
@@ -81,8 +83,30 @@ safe_strdup (char* s)
81 return result; 83 return result;
82} 84}
83 85
86/* Like strcmp but ignore differences in case. */
87
88static int
89strcasecmp (s1, s2)
90 char *s1, *s2;
91{
92 while (1)
93 {
94 int c1 = *s1++;
95 int c2 = *s2++;
96 if (isupper (c1))
97 c1 = tolower (c1);
98 if (isupper (c2))
99 c2 = tolower (c2);
100 if (c1 != c2)
101 return (c1 > c2 ? 1 : -1);
102 if (c1 == 0)
103 return 0;
104 }
105}
106
84static void 107static void
85safe_free_str (char* s) 108safe_free_str (s)
109 char *s;
86{ 110{
87 if (s) free (s); 111 if (s) free (s);
88} 112}
@@ -121,7 +145,8 @@ free_widget_value (wv)
121} 145}
122 146
123static void 147static void
124free_widget_value_tree (widget_value* wv) 148free_widget_value_tree (wv)
149 widget_value *wv;
125{ 150{
126 if (!wv) 151 if (!wv)
127 return; 152 return;
@@ -152,7 +177,9 @@ free_widget_value_tree (widget_value* wv)
152} 177}
153 178
154static widget_value * 179static widget_value *
155copy_widget_value_tree (widget_value* val, change_type change) 180copy_widget_value_tree (val, change)
181 widget_value* val;
182 change_type change;
156{ 183{
157 widget_value* copy; 184 widget_value* copy;
158 185
@@ -178,9 +205,14 @@ copy_widget_value_tree (widget_value* val, change_type change)
178} 205}
179 206
180static widget_info * 207static widget_info *
181allocate_widget_info (char* type, char* name, LWLIB_ID id, widget_value* val, 208allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb, post_activate_cb)
182 lw_callback pre_activate_cb, lw_callback selection_cb, 209 char* type;
183 lw_callback post_activate_cb) 210 char* name;
211 LWLIB_ID id;
212 widget_value* val;
213 lw_callback pre_activate_cb;
214 lw_callback selection_cb;
215 lw_callback post_activate_cb;
184{ 216{
185 widget_info* info = (widget_info*)malloc (sizeof (widget_info)); 217 widget_info* info = (widget_info*)malloc (sizeof (widget_info));
186 info->type = safe_strdup (type); 218 info->type = safe_strdup (type);
@@ -200,7 +232,8 @@ allocate_widget_info (char* type, char* name, LWLIB_ID id, widget_value* val,
200} 232}
201 233
202static void 234static void
203free_widget_info (widget_info* info) 235free_widget_info (info)
236 widget_info* info;
204{ 237{
205 safe_free_str (info->type); 238 safe_free_str (info->type);
206 safe_free_str (info->name); 239 safe_free_str (info->name);
@@ -210,7 +243,10 @@ free_widget_info (widget_info* info)
210} 243}
211 244
212static void 245static void
213mark_widget_destroyed (Widget widget, XtPointer closure, XtPointer call_data) 246mark_widget_destroyed (widget, closure, call_data)
247 Widget widget;
248 XtPointer closure;
249 XtPointer call_data;
214{ 250{
215 widget_instance* instance = (widget_instance*)closure; 251 widget_instance* instance = (widget_instance*)closure;
216 252
@@ -220,7 +256,10 @@ mark_widget_destroyed (Widget widget, XtPointer closure, XtPointer call_data)
220} 256}
221 257
222static widget_instance * 258static widget_instance *
223allocate_widget_instance (widget_info* info, Widget parent, Boolean pop_up_p) 259allocate_widget_instance (info, parent, pop_up_p)
260 widget_info* info;
261 Widget parent;
262 Boolean pop_up_p;
224{ 263{
225 widget_instance* instance = 264 widget_instance* instance =
226 (widget_instance*)malloc (sizeof (widget_instance)); 265 (widget_instance*)malloc (sizeof (widget_instance));
@@ -238,14 +277,17 @@ allocate_widget_instance (widget_info* info, Widget parent, Boolean pop_up_p)
238} 277}
239 278
240static void 279static void
241free_widget_instance (widget_instance* instance) 280free_widget_instance (instance)
281 widget_instance* instance;
242{ 282{
243 memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance)); 283 memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance));
244 free (instance); 284 free (instance);
245} 285}
246 286
247static widget_info * 287static widget_info *
248get_widget_info (LWLIB_ID id, Boolean remove_p) 288get_widget_info (id, remove_p)
289 LWLIB_ID id;
290 Boolean remove_p;
249{ 291{
250 widget_info* info; 292 widget_info* info;
251 widget_info* prev; 293 widget_info* prev;
@@ -267,7 +309,9 @@ get_widget_info (LWLIB_ID id, Boolean remove_p)
267} 309}
268 310
269static widget_instance * 311static widget_instance *
270get_widget_instance (Widget widget, Boolean remove_p) 312get_widget_instance (widget, remove_p)
313 Widget widget;
314 Boolean remove_p;
271{ 315{
272 widget_info* info; 316 widget_info* info;
273 widget_instance* instance; 317 widget_instance* instance;
@@ -291,7 +335,10 @@ get_widget_instance (Widget widget, Boolean remove_p)
291} 335}
292 336
293static widget_instance* 337static widget_instance*
294find_instance (LWLIB_ID id, Widget parent, Boolean pop_up_p) 338find_instance (id, parent, pop_up_p)
339 LWLIB_ID id;
340 Widget parent;
341 Boolean pop_up_p;
295{ 342{
296 widget_info* info = get_widget_info (id, False); 343 widget_info* info = get_widget_info (id, False);
297 widget_instance* instance; 344 widget_instance* instance;
@@ -307,14 +354,18 @@ find_instance (LWLIB_ID id, Widget parent, Boolean pop_up_p)
307 354
308/* utility function for widget_value */ 355/* utility function for widget_value */
309static Boolean 356static Boolean
310safe_strcmp (char* s1, char* s2) 357safe_strcmp (s1, s2)
358 char* s1;
359 char* s2;
311{ 360{
312 if (!!s1 ^ !!s2) return True; 361 if (!!s1 ^ !!s2) return True;
313 return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2; 362 return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2;
314} 363}
315 364
316static int 365static int
317max (int i1, int i2) 366max (i1, i2)
367 int i1;
368 int i2;
318{ 369{
319 return i1 > i2 ? i1 : i2; 370 return i1 > i2 ? i1 : i2;
320} 371}
@@ -340,7 +391,10 @@ max (int i1, int i2)
340 391
341 392
342static widget_value * 393static widget_value *
343merge_widget_value (widget_value* val1, widget_value* val2, int level) 394merge_widget_value (val1, val2, level)
395 widget_value* val1;
396 widget_value* val2;
397 int level;
344{ 398{
345 change_type change; 399 change_type change;
346 widget_value* merged_next; 400 widget_value* merged_next;
@@ -461,7 +515,9 @@ merge_widget_value (widget_value* val1, widget_value* val2, int level)
461 515
462/* modifying the widgets */ 516/* modifying the widgets */
463static Widget 517static Widget
464name_to_widget (widget_instance* instance, char* name) 518name_to_widget (instance, name)
519 widget_instance* instance;
520 char* name;
465{ 521{
466 Widget widget = NULL; 522 Widget widget = NULL;
467 523
@@ -483,7 +539,10 @@ name_to_widget (widget_instance* instance, char* name)
483} 539}
484 540
485static void 541static void
486set_one_value (widget_instance* instance, widget_value* val, Boolean deep_p) 542set_one_value (instance, val, deep_p)
543 widget_instance* instance;
544 widget_value* val;
545 Boolean deep_p;
487{ 546{
488 Widget widget = name_to_widget (instance, val->name); 547 Widget widget = name_to_widget (instance, val->name);
489 548
@@ -505,7 +564,9 @@ set_one_value (widget_instance* instance, widget_value* val, Boolean deep_p)
505} 564}
506 565
507static void 566static void
508update_one_widget_instance (widget_instance* instance, Boolean deep_p) 567update_one_widget_instance (instance, deep_p)
568 widget_instance* instance;
569 Boolean deep_p;
509{ 570{
510 widget_value *val; 571 widget_value *val;
511 572
@@ -519,7 +580,9 @@ update_one_widget_instance (widget_instance* instance, Boolean deep_p)
519} 580}
520 581
521static void 582static void
522update_all_widget_values (widget_info* info, Boolean deep_p) 583update_all_widget_values (info, deep_p)
584 widget_info* info;
585 Boolean deep_p;
523{ 586{
524 widget_instance* instance; 587 widget_instance* instance;
525 widget_value* val; 588 widget_value* val;
@@ -532,7 +595,10 @@ update_all_widget_values (widget_info* info, Boolean deep_p)
532} 595}
533 596
534void 597void
535lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p) 598lw_modify_all_widgets (id, val, deep_p)
599 LWLIB_ID id;
600 widget_value* val;
601 Boolean deep_p;
536{ 602{
537 widget_info* info = get_widget_info (id, False); 603 widget_info* info = get_widget_info (id, False);
538 widget_value* new_val; 604 widget_value* new_val;
@@ -583,7 +649,8 @@ lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p)
583/* creating the widgets */ 649/* creating the widgets */
584 650
585static void 651static void
586initialize_widget_instance (widget_instance* instance) 652initialize_widget_instance (instance)
653 widget_instance* instance;
587{ 654{
588 widget_value* val; 655 widget_value* val;
589 656
@@ -598,7 +665,9 @@ initialize_widget_instance (widget_instance* instance)
598 665
599 666
600static widget_creation_function 667static widget_creation_function
601find_in_table (char* type, widget_creation_entry* table) 668find_in_table (type, table)
669 char* type;
670 widget_creation_entry* table;
602{ 671{
603 widget_creation_entry* cur; 672 widget_creation_entry* cur;
604 for (cur = table; cur->type; cur++) 673 for (cur = table; cur->type; cur++)
@@ -608,7 +677,8 @@ find_in_table (char* type, widget_creation_entry* table)
608} 677}
609 678
610static Boolean 679static Boolean
611dialog_spec_p (char* name) 680dialog_spec_p (name)
681 char* name;
612{ 682{
613 /* return True if name matches [EILPQeilpq][1-9][Bb] or 683 /* return True if name matches [EILPQeilpq][1-9][Bb] or
614 [EILPQeilpq][1-9][Bb][Rr][1-9] */ 684 [EILPQeilpq][1-9][Bb][Rr][1-9] */
@@ -641,7 +711,8 @@ dialog_spec_p (char* name)
641} 711}
642 712
643static void 713static void
644instanciate_widget_instance (widget_instance* instance) 714instanciate_widget_instance (instance)
715 widget_instance* instance;
645{ 716{
646 widget_creation_function function = NULL; 717 widget_creation_function function = NULL;
647 718
@@ -691,9 +762,14 @@ instanciate_widget_instance (widget_instance* instance)
691} 762}
692 763
693void 764void
694lw_register_widget (char* type, char* name, LWLIB_ID id, widget_value* val, 765lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb, post_activate_cb)
695 lw_callback pre_activate_cb, lw_callback selection_cb, 766 char* type;
696 lw_callback post_activate_cb) 767 char* name;
768 LWLIB_ID id;
769 widget_value* val;
770 lw_callback pre_activate_cb;
771 lw_callback selection_cb;
772 lw_callback post_activate_cb;
697{ 773{
698 if (!get_widget_info (id, False)) 774 if (!get_widget_info (id, False))
699 allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb, 775 allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb,
@@ -701,7 +777,10 @@ lw_register_widget (char* type, char* name, LWLIB_ID id, widget_value* val,
701} 777}
702 778
703Widget 779Widget
704lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p) 780lw_get_widget (id, parent, pop_up_p)
781 LWLIB_ID id;
782 Widget parent;
783 Boolean pop_up_p;
705{ 784{
706 widget_instance* instance; 785 widget_instance* instance;
707 786
@@ -710,7 +789,10 @@ lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
710} 789}
711 790
712Widget 791Widget
713lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p) 792lw_make_widget (id, parent, pop_up_p)
793 LWLIB_ID id;
794 Widget parent;
795 Boolean pop_up_p;
714{ 796{
715 widget_instance* instance; 797 widget_instance* instance;
716 widget_info* info; 798 widget_info* info;
@@ -730,9 +812,16 @@ lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
730} 812}
731 813
732Widget 814Widget
733lw_create_widget (char* type, char* name, LWLIB_ID id, widget_value* val, 815lw_create_widget (type, name, id, val, parent, pop_up_p, pre_activate_cb, selection_cb, post_activate_cb)
734 Widget parent, Boolean pop_up_p, lw_callback pre_activate_cb, 816 char* type;
735 lw_callback selection_cb, lw_callback post_activate_cb) 817 char* name;
818 LWLIB_ID id;
819 widget_value* val;
820 Widget parent;
821 Boolean pop_up_p;
822 lw_callback pre_activate_cb;
823 lw_callback selection_cb;
824 lw_callback post_activate_cb;
736{ 825{
737 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb, 826 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb,
738 post_activate_cb); 827 post_activate_cb);
@@ -742,7 +831,8 @@ lw_create_widget (char* type, char* name, LWLIB_ID id, widget_value* val,
742 831
743/* destroying the widgets */ 832/* destroying the widgets */
744static void 833static void
745destroy_one_instance (widget_instance* instance) 834destroy_one_instance (instance)
835 widget_instance* instance;
746{ 836{
747 /* Remove the destroy callback on the widget; that callback will try to 837 /* Remove the destroy callback on the widget; that callback will try to
748 dereference the instance object (to set its widget slot to 0, since the 838 dereference the instance object (to set its widget slot to 0, since the
@@ -784,7 +874,8 @@ destroy_one_instance (widget_instance* instance)
784} 874}
785 875
786void 876void
787lw_destroy_widget (Widget w) 877lw_destroy_widget (w)
878 Widget w;
788{ 879{
789 widget_instance* instance = get_widget_instance (w, True); 880 widget_instance* instance = get_widget_instance (w, True);
790 881
@@ -800,7 +891,8 @@ lw_destroy_widget (Widget w)
800} 891}
801 892
802void 893void
803lw_destroy_all_widgets (LWLIB_ID id) 894lw_destroy_all_widgets (id)
895 LWLIB_ID id;
804{ 896{
805 widget_info* info = get_widget_info (id, True); 897 widget_info* info = get_widget_info (id, True);
806 widget_instance* instance; 898 widget_instance* instance;
@@ -879,7 +971,9 @@ lw_raise_all_pop_up_widgets ()
879} 971}
880 972
881static void 973static void
882lw_pop_all_widgets (LWLIB_ID id, Boolean up) 974lw_pop_all_widgets (id, up)
975 LWLIB_ID id;
976 Boolean up;
883{ 977{
884 widget_info* info = get_widget_info (id, False); 978 widget_info* info = get_widget_info (id, False);
885 widget_instance* instance; 979 widget_instance* instance;
@@ -906,19 +1000,22 @@ lw_pop_all_widgets (LWLIB_ID id, Boolean up)
906} 1000}
907 1001
908void 1002void
909lw_pop_up_all_widgets (LWLIB_ID id) 1003lw_pop_up_all_widgets (id)
1004 LWLIB_ID id;
910{ 1005{
911 lw_pop_all_widgets (id, True); 1006 lw_pop_all_widgets (id, True);
912} 1007}
913 1008
914void 1009void
915lw_pop_down_all_widgets (LWLIB_ID id) 1010lw_pop_down_all_widgets (id)
1011 LWLIB_ID id;
916{ 1012{
917 lw_pop_all_widgets (id, False); 1013 lw_pop_all_widgets (id, False);
918} 1014}
919 1015
920void 1016void
921lw_popup_menu (Widget widget) 1017lw_popup_menu (widget)
1018 Widget widget;
922{ 1019{
923#if defined (USE_LUCID) 1020#if defined (USE_LUCID)
924 if (lw_lucid_widget_p (widget)) 1021 if (lw_lucid_widget_p (widget))
@@ -936,7 +1033,9 @@ lw_popup_menu (Widget widget)
936 1033
937 /* get the values back */ 1034 /* get the values back */
938static Boolean 1035static Boolean
939get_one_value (widget_instance* instance, widget_value* val) 1036get_one_value (instance, val)
1037 widget_instance* instance;
1038 widget_value* val;
940{ 1039{
941 Widget widget = name_to_widget (instance, val->name); 1040 Widget widget = name_to_widget (instance, val->name);
942 1041
@@ -961,7 +1060,9 @@ get_one_value (widget_instance* instance, widget_value* val)
961} 1060}
962 1061
963Boolean 1062Boolean
964lw_get_some_values (LWLIB_ID id, widget_value* val_out) 1063lw_get_some_values (id, val_out)
1064 LWLIB_ID id;
1065 widget_value* val_out;
965{ 1066{
966 widget_info* info = get_widget_info (id, False); 1067 widget_info* info = get_widget_info (id, False);
967 widget_instance* instance; 1068 widget_instance* instance;
@@ -983,7 +1084,8 @@ lw_get_some_values (LWLIB_ID id, widget_value* val_out)
983} 1084}
984 1085
985widget_value* 1086widget_value*
986lw_get_all_values (LWLIB_ID id) 1087lw_get_all_values (id)
1088 LWLIB_ID id;
987{ 1089{
988 widget_info* info = get_widget_info (id, False); 1090 widget_info* info = get_widget_info (id, False);
989 widget_value* val = info->val; 1091 widget_value* val = info->val;
@@ -996,7 +1098,9 @@ lw_get_all_values (LWLIB_ID id)
996/* internal function used by the library dependent implementation to get the 1098/* internal function used by the library dependent implementation to get the
997 widget_value for a given widget in an instance */ 1099 widget_value for a given widget in an instance */
998widget_value* 1100widget_value*
999lw_get_widget_value_for_widget (widget_instance* instance, Widget w) 1101lw_get_widget_value_for_widget (instance, w)
1102 widget_instance* instance;
1103 Widget w;
1000{ 1104{
1001 char* name = XtName (w); 1105 char* name = XtName (w);
1002 widget_value* cur; 1106 widget_value* cur;
@@ -1011,8 +1115,10 @@ lw_get_widget_value_for_widget (widget_instance* instance, Widget w)
1011 modified to update other instances of the widgets. Closure should be the 1115 modified to update other instances of the widgets. Closure should be the
1012 widget_instance. */ 1116 widget_instance. */
1013void 1117void
1014lw_internal_update_other_instances (Widget widget, XtPointer closure, 1118lw_internal_update_other_instances (widget, closure, call_data)
1015 XtPointer call_data) 1119 Widget widget;
1120 XtPointer closure;
1121 XtPointer call_data;
1016{ 1122{
1017 /* To forbid recursive calls */ 1123 /* To forbid recursive calls */
1018 static Boolean updating; 1124 static Boolean updating;
@@ -1052,7 +1158,8 @@ lw_internal_update_other_instances (Widget widget, XtPointer closure,
1052 /* get the id */ 1158 /* get the id */
1053 1159
1054LWLIB_ID 1160LWLIB_ID
1055lw_get_widget_id (Widget w) 1161lw_get_widget_id (w)
1162 Widget w;
1056{ 1163{
1057 widget_instance* instance = get_widget_instance (w, False); 1164 widget_instance* instance = get_widget_instance (w, False);
1058 1165
@@ -1061,7 +1168,9 @@ lw_get_widget_id (Widget w)
1061 1168
1062 /* set the keyboard focus */ 1169 /* set the keyboard focus */
1063void 1170void
1064lw_set_keyboard_focus (Widget parent, Widget w) 1171lw_set_keyboard_focus (parent, w)
1172 Widget parent;
1173 Widget w;
1065{ 1174{
1066#if defined (USE_MOTIF) 1175#if defined (USE_MOTIF)
1067 xm_set_keyboard_focus (parent, w); 1176 xm_set_keyboard_focus (parent, w);
@@ -1072,7 +1181,9 @@ lw_set_keyboard_focus (Widget parent, Widget w)
1072 1181
1073 /* Show busy */ 1182 /* Show busy */
1074static void 1183static void
1075show_one_widget_busy (Widget w, Boolean flag) 1184show_one_widget_busy (w, flag)
1185 Widget w;
1186 Boolean flag;
1076{ 1187{
1077 Pixel foreground = 0; 1188 Pixel foreground = 0;
1078 Pixel background = 1; 1189 Pixel background = 1;
@@ -1091,7 +1202,9 @@ show_one_widget_busy (Widget w, Boolean flag)
1091} 1202}
1092 1203
1093void 1204void
1094lw_show_busy (Widget w, Boolean busy) 1205lw_show_busy (w, busy)
1206 Widget w;
1207 Boolean busy;
1095{ 1208{
1096 widget_instance* instance = get_widget_instance (w, False); 1209 widget_instance* instance = get_widget_instance (w, False);
1097 widget_info* info; 1210 widget_info* info;