comparison lwlib/lwlib.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents e121b013d1f0
children f220cc83d72e
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
2 Copyright (C) 1992, 1993, 1994 Lucid, Inc. 2 Copyright (C) 1992, 1993, 1994 Lucid, Inc.
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp. 3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
4 4
5 This file is part of the Lucid Widget Library. 5 This file is part of the Lucid Widget Library.
6 6
7 The Lucid Widget Library is free software; you can redistribute it and/or 7 The Lucid Widget Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as published by 8 modify it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option) 9 the Free Software Foundation; either version 2, or (at your option)
10 any later version. 10 any later version.
11 11
12 The Lucid Widget Library is distributed in the hope that it will be useful, 12 The Lucid Widget Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to 18 along with XEmacs; see the file COPYING. If not, write to
112 } 112 }
113 return wv; 113 return wv;
114 } 114 }
115 115
116 /* this is analogous to free(). It frees only what was allocated 116 /* this is analogous to free(). It frees only what was allocated
117 by malloc_widget_value(), and no substructures. 117 by malloc_widget_value(), and no substructures.
118 */ 118 */
119 void 119 void
120 free_widget_value (widget_value *wv) 120 free_widget_value (widget_value *wv)
121 { 121 {
122 if (wv->free_list) 122 if (wv->free_list)
128 static void free_widget_value_tree (widget_value *wv); 128 static void free_widget_value_tree (widget_value *wv);
129 129
130 static void 130 static void
131 free_widget_value_contents (widget_value *wv) 131 free_widget_value_contents (widget_value *wv)
132 { 132 {
133 if (wv->name) free (wv->name); 133 if (wv->name) free (wv->name);
134 if (wv->value) free (wv->value); 134 if (wv->value) free (wv->value);
135 if (wv->key) free (wv->key); 135 if (wv->key) free (wv->key);
136 136
137 /* #### - all of this 0xDEADBEEF stuff should be unnecessary 137 /* #### - all of this 0xDEADBEEF stuff should be unnecessary
138 in production code... it should be conditionalized. */ 138 in production code... it should be conditionalized. */
139 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF; 139 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF;
140 140
141 if (wv->toolkit_data && wv->free_toolkit_data) 141 if (wv->toolkit_data && wv->free_toolkit_data)
142 { 142 {
143 XtFree (wv->toolkit_data); 143 XtFree ((char *) wv->toolkit_data);
144 wv->toolkit_data = (void *) 0xDEADBEEF; 144 wv->toolkit_data = (void *) 0xDEADBEEF;
145 } 145 }
146 #ifdef NEED_SCROLLBARS 146 #ifdef NEED_SCROLLBARS
147 if (wv->scrollbar_data) 147 if (wv->scrollbar_data)
148 { 148 {
236 236
237 static widget_value * 237 static widget_value *
238 copy_widget_value_tree (widget_value *val, change_type change) 238 copy_widget_value_tree (widget_value *val, change_type change)
239 { 239 {
240 widget_value *copy; 240 widget_value *copy;
241 241
242 if (!val) 242 if (!val)
243 return NULL; 243 return NULL;
244 if (val == (widget_value *) 1) 244 if (val == (widget_value *) 1)
245 return val; 245 return val;
246 246
513 if (!val2) 513 if (!val2)
514 { 514 {
515 free_widget_value_tree (val1); 515 free_widget_value_tree (val1);
516 return NULL; 516 return NULL;
517 } 517 }
518 518
519 change = NO_CHANGE; 519 change = NO_CHANGE;
520 520
521 if (val1->type != val2->type) 521 if (val1->type != val2->type)
522 { 522 {
523 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "type change", 523 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "type change",
587 587
588 if (level > 0) 588 if (level > 0)
589 { 589 {
590 merged_contents = 590 merged_contents =
591 merge_widget_value (val1->contents, val2->contents, level - 1); 591 merge_widget_value (val1->contents, val2->contents, level - 1);
592 592
593 if (val1->contents && !merged_contents) 593 if (val1->contents && !merged_contents)
594 { 594 {
595 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents gone)", 595 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents gone)",
596 0, 0); 596 0, 0);
597 change = max (change, INVISIBLE_CHANGE); 597 change = max (change, INVISIBLE_CHANGE);
600 { 600 {
601 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents change)", 601 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents change)",
602 0, 0); 602 0, 0);
603 change = max (change, INVISIBLE_CHANGE); 603 change = max (change, INVISIBLE_CHANGE);
604 } 604 }
605 605
606 val1->contents = merged_contents; 606 val1->contents = merged_contents;
607 } 607 }
608 608
609 merged_next = merge_widget_value (val1->next, val2->next, level); 609 merged_next = merge_widget_value (val1->next, val2->next, level);
610 610
625 } 625 }
626 626
627 val1->next = merged_next; 627 val1->next = merged_next;
628 628
629 val1->change = change; 629 val1->change = change;
630 630
631 if (change > NO_CHANGE && val1->toolkit_data) 631 if (change > NO_CHANGE && val1->toolkit_data)
632 { 632 {
633 if (val1->free_toolkit_data) 633 if (val1->free_toolkit_data)
634 XtFree (val1->toolkit_data); 634 XtFree ((char *) val1->toolkit_data);
635 val1->toolkit_data = NULL; 635 val1->toolkit_data = NULL;
636 } 636 }
637 637
638 return val1; 638 return val1;
639 } 639 }
654 { 654 {
655 int length = strlen (name) + 2; 655 int length = strlen (name) + 2;
656 char *real_name = (char *) alloca (length); 656 char *real_name = (char *) alloca (length);
657 real_name [0] = '*'; 657 real_name [0] = '*';
658 strcpy (real_name + 1, name); 658 strcpy (real_name + 1, name);
659 659
660 widget = XtNameToWidget (instance->widget, real_name); 660 widget = XtNameToWidget (instance->widget, real_name);
661 } 661 }
662 return widget; 662 return widget;
663 } 663 }
664 664
665 static void 665 static void
666 set_one_value (widget_instance *instance, widget_value *val, Boolean deep_p) 666 set_one_value (widget_instance *instance, widget_value *val, Boolean deep_p)
667 { 667 {
668 Widget widget = name_to_widget (instance, val->name); 668 Widget widget = name_to_widget (instance, val->name);
669 669
670 if (widget) 670 if (widget)
671 { 671 {
672 #ifdef NEED_LUCID 672 #ifdef NEED_LUCID
673 if (lw_lucid_widget_p (instance->widget)) 673 if (lw_lucid_widget_p (instance->widget))
674 xlw_update_one_widget (instance, widget, val, deep_p); 674 xlw_update_one_widget (instance, widget, val, deep_p);
788 } 788 }
789 789
790 static Boolean 790 static Boolean
791 dialog_spec_p (CONST char *name) 791 dialog_spec_p (CONST char *name)
792 { 792 {
793 /* return True if name matches [EILPQeilpq][1-9][Bb] or 793 /* return True if name matches [EILPQeilpq][1-9][Bb] or
794 [EILPQeilpq][1-9][Bb][Rr][1-9] */ 794 [EILPQeilpq][1-9][Bb][Rr][1-9] */
795 if (!name) 795 if (!name)
796 return False; 796 return False;
797 797
798 switch (name [0]) 798 switch (name [0])
799 { 799 {
800 case 'E': case 'I': case 'L': case 'P': case 'Q': 800 case 'E': case 'I': case 'L': case 'P': case 'Q':
801 case 'e': case 'i': case 'l': case 'p': case 'q': 801 case 'e': case 'i': case 'l': case 'p': case 'q':
802 if (name [1] >= '0' && name [1] <= '9') 802 if (name [1] >= '0' && name [1] <= '9')
812 return True; 812 return True;
813 return False; 813 return False;
814 } 814 }
815 else 815 else
816 return False; 816 return False;
817 817
818 default: 818 default:
819 return False; 819 return False;
820 } 820 }
821 } 821 }
822 822
853 #ifdef DIALOGS_LUCID 853 #ifdef DIALOGS_LUCID
854 /* not yet (not ever?) */ 854 /* not yet (not ever?) */
855 #endif 855 #endif
856 } 856 }
857 } 857 }
858 858
859 if (!function) 859 if (!function)
860 { 860 {
861 fprintf (stderr, "No creation function for widget type %s\n", 861 fprintf (stderr, "No creation function for widget type %s\n",
862 instance->info->type); 862 instance->info->type);
863 abort (); 863 abort ();
869 abort (); 869 abort ();
870 870
871 /* XtRealizeWidget (instance->widget);*/ 871 /* XtRealizeWidget (instance->widget);*/
872 } 872 }
873 873
874 void 874 void
875 lw_register_widget (CONST char *type, CONST char *name, 875 lw_register_widget (CONST char *type, CONST char *name,
876 LWLIB_ID id, widget_value *val, 876 LWLIB_ID id, widget_value *val,
877 lw_callback pre_activate_cb, lw_callback selection_cb, 877 lw_callback pre_activate_cb, lw_callback selection_cb,
878 lw_callback post_activate_cb) 878 lw_callback post_activate_cb)
879 { 879 {
884 884
885 Widget 885 Widget
886 lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p) 886 lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
887 { 887 {
888 widget_instance *instance; 888 widget_instance *instance;
889 889
890 instance = find_instance (id, parent, pop_up_p); 890 instance = find_instance (id, parent, pop_up_p);
891 return instance ? instance->widget : NULL; 891 return instance ? instance->widget : NULL;
892 } 892 }
893 893
894 Widget 894 Widget
895 lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p) 895 lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
896 { 896 {
897 widget_instance *instance; 897 widget_instance *instance;
898 widget_info *info; 898 widget_info *info;
899 899
900 instance = find_instance (id, parent, pop_up_p); 900 instance = find_instance (id, parent, pop_up_p);
901 if (!instance) 901 if (!instance)
902 { 902 {
903 info = get_widget_info (id, False); 903 info = get_widget_info (id, False);
904 if (!info) 904 if (!info)
919 { 919 {
920 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb, 920 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb,
921 post_activate_cb); 921 post_activate_cb);
922 return lw_make_widget (id, parent, pop_up_p); 922 return lw_make_widget (id, parent, pop_up_p);
923 } 923 }
924 924
925 925
926 /* destroying the widgets */ 926 /* destroying the widgets */
927 static void 927 static void
928 destroy_one_instance (widget_instance *instance) 928 destroy_one_instance (widget_instance *instance)
929 { 929 {
970 970
971 void 971 void
972 lw_destroy_widget (Widget w) 972 lw_destroy_widget (Widget w)
973 { 973 {
974 widget_instance *instance = get_widget_instance (w, True); 974 widget_instance *instance = get_widget_instance (w, True);
975 975
976 if (instance) 976 if (instance)
977 { 977 {
978 widget_info *info = instance->info; 978 widget_info *info = instance->info;
979 /* instance has already been removed from the list; free it */ 979 /* instance has already been removed from the list; free it */
980 destroy_one_instance (instance); 980 destroy_one_instance (instance);
1126 /* get the values back */ 1126 /* get the values back */
1127 static Boolean 1127 static Boolean
1128 get_one_value (widget_instance *instance, widget_value *val) 1128 get_one_value (widget_instance *instance, widget_value *val)
1129 { 1129 {
1130 Widget widget = name_to_widget (instance, val->name); 1130 Widget widget = name_to_widget (instance, val->name);
1131 1131
1132 if (widget) 1132 if (widget)
1133 { 1133 {
1134 #ifdef NEED_LUCID 1134 #ifdef NEED_LUCID
1135 if (lw_lucid_widget_p (instance->widget)) 1135 if (lw_lucid_widget_p (instance->widget))
1136 xlw_update_one_value (instance, widget, val); 1136 xlw_update_one_value (instance, widget, val);
1195 return NULL; 1195 return NULL;
1196 } 1196 }
1197 1197
1198 1198
1199 /* update other instances value when one thing changed */ 1199 /* update other instances value when one thing changed */
1200 /* This function can be used as a an XtCallback for the widgets that get 1200 /* This function can be used as a an XtCallback for the widgets that get
1201 modified to update other instances of the widgets. Closure should be the 1201 modified to update other instances of the widgets. Closure should be the
1202 widget_instance. */ 1202 widget_instance. */
1203 void 1203 void
1204 lw_internal_update_other_instances (Widget widget, XtPointer closure, 1204 lw_internal_update_other_instances (Widget widget, XtPointer closure,
1205 XtPointer call_data) 1205 XtPointer call_data)
1206 { 1206 {
1207 /* To forbid recursive calls */ 1207 /* To forbid recursive calls */
1208 static Boolean updating; 1208 static Boolean updating;
1209 1209
1210 widget_instance *instance = (widget_instance*)closure; 1210 widget_instance *instance = (widget_instance*)closure;
1211 char *name = XtName (widget); 1211 char *name = XtName (widget);
1212 widget_info *info; 1212 widget_info *info;
1213 widget_instance *cur; 1213 widget_instance *cur;
1214 widget_value *val; 1214 widget_value *val;
1270 { 1270 {
1271 Pixel foreground = 0; 1271 Pixel foreground = 0;
1272 Pixel background = 1; 1272 Pixel background = 1;
1273 Widget widget_to_invert = XtNameToWidget (w, "*sheet"); 1273 Widget widget_to_invert = XtNameToWidget (w, "*sheet");
1274 Arg al [2]; 1274 Arg al [2];
1275 1275
1276 if (!widget_to_invert) 1276 if (!widget_to_invert)
1277 widget_to_invert = w; 1277 widget_to_invert = w;
1278 1278
1279 XtSetArg (al [0], XtNforeground, &foreground); 1279 XtSetArg (al [0], XtNforeground, &foreground);
1280 XtSetArg (al [1], XtNbackground, &background); 1280 XtSetArg (al [1], XtNbackground, &background);