Mercurial > emacs
annotate lwlib/lwlib.c @ 6063:233fffcfb6c8
(Fget_char_property): New function.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 24 Feb 1994 19:18:32 +0000 |
parents | b135bb2b4bfe |
children | 65beaa9aa1e4 |
rev | line source |
---|---|
5626 | 1 /* A general interface to the widgets of different toolkits. |
2 Copyright (C) 1992, 1993 Lucid, Inc. | |
3 | |
4 This file is part of the Lucid Widget Library. | |
5 | |
6 The Lucid Widget Library is free software; you can redistribute it and/or | |
7 modify it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 The Lucid Widget Library is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 #ifdef NeXT | |
21 #undef __STRICT_BSD__ /* ick */ | |
22 #endif | |
23 | |
24 #include <stdlib.h> | |
25 #include <unistd.h> | |
26 #include <sys/types.h> | |
27 #include <string.h> | |
28 #include <stdio.h> | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
29 #include <ctype.h> |
5627
7ff2d6076466
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5626
diff
changeset
|
30 #include "lwlib-int.h" |
5626 | 31 #include "lwlib-utils.h" |
5706
75570af32e92
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5627
diff
changeset
|
32 #include <X11/StringDefs.h> |
5626 | 33 |
34 #if defined(__GNUC__) && !defined(alloca) | |
35 #define alloca __builtin_alloca | |
36 #endif | |
37 | |
38 #if ((!__GNUC__) && !defined(__hpux)) && !defined(AIXV3) | |
39 #include <alloca.h> | |
40 #endif | |
41 | |
42 #if defined(AIXV3) | |
43 #pragma alloca | |
44 #endif | |
45 | |
46 #if defined (USE_LUCID) | |
47 #include "lwlib-Xlw.h" | |
48 #endif | |
49 #if defined (USE_MOTIF) | |
50 #include "lwlib-Xm.h" | |
51 #endif | |
52 #if defined (USE_OLIT) | |
53 #include "lwlib-Xol.h" | |
54 #endif | |
55 | |
56 #if !defined (USE_LUCID) && !defined (USE_MOTIF) && !defined (USE_OLIT) | |
57 ERROR! At least one of USE_LUCID, USE_MOTIF or USE_OLIT must be defined. | |
58 #endif | |
59 | |
60 #if defined (USE_MOTIF) && defined (USE_OLIT) | |
61 ERROR! no more than one of USE_MOTIF and USE_OLIT may be defined. | |
62 #endif | |
63 | |
64 /* List of all widgets managed by the library. */ | |
65 static widget_info* | |
66 all_widget_info = NULL; | |
67 | |
68 /* Forward declarations */ | |
69 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
70 instanciate_widget_instance (/* widget_instance* instance */); |
5626 | 71 |
72 /* utility functions for widget_instance and widget_info */ | |
73 static char * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
74 safe_strdup (s) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
75 char *s; |
5626 | 76 { |
77 char *result; | |
78 if (! s) return 0; | |
79 result = (char *) malloc (strlen (s) + 1); | |
80 if (! result) | |
81 return 0; | |
82 strcpy (result, s); | |
83 return result; | |
84 } | |
85 | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
86 /* Like strcmp but ignore differences in case. */ |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
87 |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
88 static int |
5853 | 89 my_strcasecmp (s1, s2) |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
90 char *s1, *s2; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
91 { |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
92 while (1) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
93 { |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
94 int c1 = *s1++; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
95 int c2 = *s2++; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
96 if (isupper (c1)) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
97 c1 = tolower (c1); |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
98 if (isupper (c2)) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
99 c2 = tolower (c2); |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
100 if (c1 != c2) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
101 return (c1 > c2 ? 1 : -1); |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
102 if (c1 == 0) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
103 return 0; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
104 } |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
105 } |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
106 |
5626 | 107 static void |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
108 safe_free_str (s) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
109 char *s; |
5626 | 110 { |
111 if (s) free (s); | |
112 } | |
113 | |
114 static widget_value *widget_value_free_list = 0; | |
5993
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
115 static int malloc_cpt = 0; |
5626 | 116 |
117 widget_value * | |
118 malloc_widget_value () | |
119 { | |
120 widget_value *wv; | |
121 if (widget_value_free_list) | |
122 { | |
123 wv = widget_value_free_list; | |
124 widget_value_free_list = wv->free_list; | |
125 wv->free_list = 0; | |
126 } | |
127 else | |
128 { | |
129 wv = (widget_value *) malloc (sizeof (widget_value)); | |
5993
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
130 malloc_cpt++; |
5626 | 131 } |
132 memset (wv, 0, sizeof (widget_value)); | |
133 return wv; | |
134 } | |
135 | |
136 /* this is analagous to free(). It frees only what was allocated | |
137 by malloc_widget_value(), and no substructures. | |
138 */ | |
139 void | |
140 free_widget_value (wv) | |
141 widget_value *wv; | |
142 { | |
143 if (wv->free_list) | |
144 abort (); | |
5993
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
145 |
5999
b135bb2b4bfe
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5993
diff
changeset
|
146 if (malloc_cpt > 25) |
5993
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
147 { |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
148 /* When the number of already allocated cells is too big, |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
149 We free it. */ |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
150 free (wv); |
5999
b135bb2b4bfe
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5993
diff
changeset
|
151 malloc_cpt--; |
5993
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
152 } |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
153 else |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
154 { |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
155 wv->free_list = widget_value_free_list; |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
156 widget_value_free_list = wv; |
5feb28cb62c8
*** empty log message ***
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
5853
diff
changeset
|
157 } |
5626 | 158 } |
159 | |
160 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
161 free_widget_value_tree (wv) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
162 widget_value *wv; |
5626 | 163 { |
164 if (!wv) | |
165 return; | |
166 | |
167 if (wv->name) free (wv->name); | |
168 if (wv->value) free (wv->value); | |
169 if (wv->key) free (wv->key); | |
170 | |
171 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF; | |
172 | |
173 if (wv->toolkit_data && wv->free_toolkit_data) | |
174 { | |
175 free (wv->toolkit_data); | |
176 wv->toolkit_data = (void *) 0xDEADBEEF; | |
177 } | |
178 | |
179 if (wv->contents && (wv->contents != (widget_value*)1)) | |
180 { | |
181 free_widget_value_tree (wv->contents); | |
182 wv->contents = (widget_value *) 0xDEADBEEF; | |
183 } | |
184 if (wv->next) | |
185 { | |
186 free_widget_value_tree (wv->next); | |
187 wv->next = (widget_value *) 0xDEADBEEF; | |
188 } | |
189 free_widget_value (wv); | |
190 } | |
191 | |
192 static widget_value * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
193 copy_widget_value_tree (val, change) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
194 widget_value* val; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
195 change_type change; |
5626 | 196 { |
197 widget_value* copy; | |
198 | |
199 if (!val) | |
200 return NULL; | |
201 if (val == (widget_value *) 1) | |
202 return val; | |
203 | |
204 copy = malloc_widget_value (); | |
205 copy->name = safe_strdup (val->name); | |
206 copy->value = safe_strdup (val->value); | |
207 copy->key = safe_strdup (val->key); | |
208 copy->enabled = val->enabled; | |
209 copy->selected = val->selected; | |
210 copy->edited = False; | |
211 copy->change = change; | |
212 copy->contents = copy_widget_value_tree (val->contents, change); | |
213 copy->call_data = val->call_data; | |
214 copy->next = copy_widget_value_tree (val->next, change); | |
215 copy->toolkit_data = NULL; | |
216 copy->free_toolkit_data = False; | |
217 return copy; | |
218 } | |
219 | |
220 static widget_info * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
221 allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb, post_activate_cb) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
222 char* type; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
223 char* name; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
224 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
225 widget_value* val; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
226 lw_callback pre_activate_cb; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
227 lw_callback selection_cb; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
228 lw_callback post_activate_cb; |
5626 | 229 { |
230 widget_info* info = (widget_info*)malloc (sizeof (widget_info)); | |
231 info->type = safe_strdup (type); | |
232 info->name = safe_strdup (name); | |
233 info->id = id; | |
234 info->val = copy_widget_value_tree (val, STRUCTURAL_CHANGE); | |
235 info->busy = False; | |
236 info->pre_activate_cb = pre_activate_cb; | |
237 info->selection_cb = selection_cb; | |
238 info->post_activate_cb = post_activate_cb; | |
239 info->instances = NULL; | |
240 | |
241 info->next = all_widget_info; | |
242 all_widget_info = info; | |
243 | |
244 return info; | |
245 } | |
246 | |
247 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
248 free_widget_info (info) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
249 widget_info* info; |
5626 | 250 { |
251 safe_free_str (info->type); | |
252 safe_free_str (info->name); | |
253 free_widget_value_tree (info->val); | |
254 memset ((void*)info, 0xDEADBEEF, sizeof (widget_info)); | |
255 free (info); | |
256 } | |
257 | |
258 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
259 mark_widget_destroyed (widget, closure, call_data) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
260 Widget widget; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
261 XtPointer closure; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
262 XtPointer call_data; |
5626 | 263 { |
264 widget_instance* instance = (widget_instance*)closure; | |
265 | |
266 /* be very conservative */ | |
267 if (instance->widget == widget) | |
268 instance->widget = NULL; | |
269 } | |
270 | |
271 static widget_instance * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
272 allocate_widget_instance (info, parent, pop_up_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
273 widget_info* info; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
274 Widget parent; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
275 Boolean pop_up_p; |
5626 | 276 { |
277 widget_instance* instance = | |
278 (widget_instance*)malloc (sizeof (widget_instance)); | |
279 instance->parent = parent; | |
280 instance->pop_up_p = pop_up_p; | |
281 instance->info = info; | |
282 instance->next = info->instances; | |
283 info->instances = instance; | |
284 | |
285 instanciate_widget_instance (instance); | |
286 | |
287 XtAddCallback (instance->widget, XtNdestroyCallback, | |
288 mark_widget_destroyed, (XtPointer)instance); | |
289 return instance; | |
290 } | |
291 | |
292 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
293 free_widget_instance (instance) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
294 widget_instance* instance; |
5626 | 295 { |
296 memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance)); | |
297 free (instance); | |
298 } | |
299 | |
300 static widget_info * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
301 get_widget_info (id, remove_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
302 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
303 Boolean remove_p; |
5626 | 304 { |
305 widget_info* info; | |
306 widget_info* prev; | |
307 for (prev = NULL, info = all_widget_info; | |
308 info; | |
309 prev = info, info = info->next) | |
310 if (info->id == id) | |
311 { | |
312 if (remove_p) | |
313 { | |
314 if (prev) | |
315 prev->next = info->next; | |
316 else | |
317 all_widget_info = info->next; | |
318 } | |
319 return info; | |
320 } | |
321 return NULL; | |
322 } | |
323 | |
324 static widget_instance * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
325 get_widget_instance (widget, remove_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
326 Widget widget; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
327 Boolean remove_p; |
5626 | 328 { |
329 widget_info* info; | |
330 widget_instance* instance; | |
331 widget_instance* prev; | |
332 for (info = all_widget_info; info; info = info->next) | |
333 for (prev = NULL, instance = info->instances; | |
334 instance; | |
335 prev = instance, instance = instance->next) | |
336 if (instance->widget == widget) | |
337 { | |
338 if (remove_p) | |
339 { | |
340 if (prev) | |
341 prev->next = instance->next; | |
342 else | |
343 info->instances = instance->next; | |
344 } | |
345 return instance; | |
346 } | |
347 return (widget_instance *) 0; | |
348 } | |
349 | |
350 static widget_instance* | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
351 find_instance (id, parent, pop_up_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
352 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
353 Widget parent; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
354 Boolean pop_up_p; |
5626 | 355 { |
356 widget_info* info = get_widget_info (id, False); | |
357 widget_instance* instance; | |
358 | |
359 if (info) | |
360 for (instance = info->instances; instance; instance = instance->next) | |
361 if (instance->parent == parent && instance->pop_up_p == pop_up_p) | |
362 return instance; | |
363 | |
364 return NULL; | |
365 } | |
366 | |
367 | |
368 /* utility function for widget_value */ | |
369 static Boolean | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
370 safe_strcmp (s1, s2) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
371 char* s1; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
372 char* s2; |
5626 | 373 { |
374 if (!!s1 ^ !!s2) return True; | |
375 return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2; | |
376 } | |
377 | |
378 static int | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
379 max (i1, i2) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
380 int i1; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
381 int i2; |
5626 | 382 { |
383 return i1 > i2 ? i1 : i2; | |
384 } | |
385 | |
386 | |
387 #if 0 | |
388 # define EXPLAIN(name, oc, nc, desc, a1, a2) \ | |
389 printf ("Change: \"%s\"\tmax(%s=%d,%s=%d)\t%s %d %d\n", \ | |
390 name, \ | |
391 (oc == NO_CHANGE ? "none" : \ | |
392 (oc == INVISIBLE_CHANGE ? "invisible" : \ | |
393 (oc == VISIBLE_CHANGE ? "visible" : \ | |
394 (oc == STRUCTURAL_CHANGE ? "structural" : "???")))), \ | |
395 oc, \ | |
396 (nc == NO_CHANGE ? "none" : \ | |
397 (nc == INVISIBLE_CHANGE ? "invisible" : \ | |
398 (nc == VISIBLE_CHANGE ? "visible" : \ | |
399 (nc == STRUCTURAL_CHANGE ? "structural" : "???")))), \ | |
400 nc, desc, a1, a2) | |
401 #else | |
402 # define EXPLAIN(name, oc, nc, desc, a1, a2) | |
403 #endif | |
404 | |
405 | |
406 static widget_value * | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
407 merge_widget_value (val1, val2, level) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
408 widget_value* val1; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
409 widget_value* val2; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
410 int level; |
5626 | 411 { |
412 change_type change; | |
413 widget_value* merged_next; | |
414 widget_value* merged_contents; | |
415 | |
416 if (!val1) | |
417 { | |
418 if (val2) | |
419 return copy_widget_value_tree (val2, STRUCTURAL_CHANGE); | |
420 else | |
421 return NULL; | |
422 } | |
423 if (!val2) | |
424 { | |
425 free_widget_value_tree (val1); | |
426 return NULL; | |
427 } | |
428 | |
429 change = NO_CHANGE; | |
430 | |
431 if (safe_strcmp (val1->name, val2->name)) | |
432 { | |
433 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "name change", | |
434 val1->name, val2->name); | |
435 change = max (change, STRUCTURAL_CHANGE); | |
436 safe_free_str (val1->name); | |
437 val1->name = safe_strdup (val2->name); | |
438 } | |
439 if (safe_strcmp (val1->value, val2->value)) | |
440 { | |
441 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "value change", | |
442 val1->value, val2->value); | |
443 change = max (change, VISIBLE_CHANGE); | |
444 safe_free_str (val1->value); | |
445 val1->value = safe_strdup (val2->value); | |
446 } | |
447 if (safe_strcmp (val1->key, val2->key)) | |
448 { | |
449 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "key change", | |
450 val1->key, val2->key); | |
451 change = max (change, VISIBLE_CHANGE); | |
452 safe_free_str (val1->key); | |
453 val1->key = safe_strdup (val2->key); | |
454 } | |
455 if (val1->enabled != val2->enabled) | |
456 { | |
457 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "enablement change", | |
458 val1->enabled, val2->enabled); | |
459 change = max (change, VISIBLE_CHANGE); | |
460 val1->enabled = val2->enabled; | |
461 } | |
462 if (val1->selected != val2->selected) | |
463 { | |
464 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "selection change", | |
465 val1->selected, val2->selected); | |
466 change = max (change, VISIBLE_CHANGE); | |
467 val1->selected = val2->selected; | |
468 } | |
469 if (val1->call_data != val2->call_data) | |
470 { | |
471 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "call-data change", | |
472 val1->call_data, val2->call_data); | |
473 change = max (change, INVISIBLE_CHANGE); | |
474 val1->call_data = val2->call_data; | |
475 } | |
476 | |
477 if (level > 0) | |
478 { | |
479 merged_contents = | |
480 merge_widget_value (val1->contents, val2->contents, level - 1); | |
481 | |
482 if (val1->contents && !merged_contents) | |
483 { | |
484 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents gone)", | |
485 0, 0); | |
486 change = max (change, INVISIBLE_CHANGE); | |
487 } | |
488 else if (merged_contents && merged_contents->change != NO_CHANGE) | |
489 { | |
490 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents change)", | |
491 0, 0); | |
492 change = max (change, INVISIBLE_CHANGE); | |
493 } | |
494 | |
495 val1->contents = merged_contents; | |
496 } | |
497 | |
498 merged_next = merge_widget_value (val1->next, val2->next, level); | |
499 | |
500 if (val1->next && !merged_next) | |
501 { | |
502 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "(following gone)", | |
503 0, 0); | |
504 change = max (change, STRUCTURAL_CHANGE); | |
505 } | |
506 else if (merged_next) | |
507 { | |
508 if (merged_next->change) | |
509 EXPLAIN (val1->name, change, merged_next->change, "(following change)", | |
510 0, 0); | |
511 change = max (change, merged_next->change); | |
512 } | |
513 | |
514 val1->next = merged_next; | |
515 | |
516 val1->change = change; | |
517 | |
518 if (change > NO_CHANGE && val1->toolkit_data) | |
519 { | |
520 if (val1->free_toolkit_data) | |
521 free (val1->toolkit_data); | |
522 val1->toolkit_data = NULL; | |
523 } | |
524 | |
525 return val1; | |
526 } | |
527 | |
528 | |
529 /* modifying the widgets */ | |
530 static Widget | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
531 name_to_widget (instance, name) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
532 widget_instance* instance; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
533 char* name; |
5626 | 534 { |
535 Widget widget = NULL; | |
536 | |
537 if (!instance->widget) | |
538 return NULL; | |
539 | |
540 if (!strcmp (XtName (instance->widget), name)) | |
541 widget = instance->widget; | |
542 else | |
543 { | |
544 int length = strlen (name) + 2; | |
545 char* real_name = (char *) alloca (length); | |
546 real_name [0] = '*'; | |
547 strcpy (real_name + 1, name); | |
548 | |
549 widget = XtNameToWidget (instance->widget, real_name); | |
550 } | |
551 return widget; | |
552 } | |
553 | |
554 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
555 set_one_value (instance, val, deep_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
556 widget_instance* instance; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
557 widget_value* val; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
558 Boolean deep_p; |
5626 | 559 { |
560 Widget widget = name_to_widget (instance, val->name); | |
561 | |
562 if (widget) | |
563 { | |
564 #if defined (USE_LUCID) | |
565 if (lw_lucid_widget_p (instance->widget)) | |
566 xlw_update_one_widget (instance, widget, val, deep_p); | |
567 #endif | |
568 #if defined (USE_MOTIF) | |
569 if (lw_motif_widget_p (instance->widget)) | |
570 xm_update_one_widget (instance, widget, val, deep_p); | |
571 #endif | |
572 #if defined (USE_OLIT) | |
573 if (lw_olit_widget_p (instance->widget)) | |
574 xol_update_one_widget (instance, widget, val, deep_p); | |
575 #endif | |
576 } | |
577 } | |
578 | |
579 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
580 update_one_widget_instance (instance, deep_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
581 widget_instance* instance; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
582 Boolean deep_p; |
5626 | 583 { |
584 widget_value *val; | |
585 | |
586 if (!instance->widget) | |
587 /* the widget was destroyed */ | |
588 return; | |
589 | |
590 for (val = instance->info->val; val; val = val->next) | |
591 if (val->change != NO_CHANGE) | |
592 set_one_value (instance, val, deep_p); | |
593 } | |
594 | |
595 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
596 update_all_widget_values (info, deep_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
597 widget_info* info; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
598 Boolean deep_p; |
5626 | 599 { |
600 widget_instance* instance; | |
601 widget_value* val; | |
602 | |
603 for (instance = info->instances; instance; instance = instance->next) | |
604 update_one_widget_instance (instance, deep_p); | |
605 | |
606 for (val = info->val; val; val = val->next) | |
607 val->change = NO_CHANGE; | |
608 } | |
609 | |
610 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
611 lw_modify_all_widgets (id, val, deep_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
612 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
613 widget_value* val; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
614 Boolean deep_p; |
5626 | 615 { |
616 widget_info* info = get_widget_info (id, False); | |
617 widget_value* new_val; | |
618 widget_value* next_new_val; | |
619 widget_value* cur; | |
620 widget_value* prev; | |
621 widget_value* next; | |
622 int found; | |
623 | |
624 if (!info) | |
625 return; | |
626 | |
627 for (new_val = val; new_val; new_val = new_val->next) | |
628 { | |
629 next_new_val = new_val->next; | |
630 new_val->next = NULL; | |
631 found = False; | |
632 for (prev = NULL, cur = info->val; cur; prev = cur, cur = cur->next) | |
633 if (!strcmp (cur->name, new_val->name)) | |
634 { | |
635 found = True; | |
636 next = cur->next; | |
637 cur->next = NULL; | |
638 cur = merge_widget_value (cur, new_val, deep_p ? 1000 : 1); | |
639 if (prev) | |
640 prev->next = cur ? cur : next; | |
641 else | |
642 info->val = cur ? cur : next; | |
643 if (cur) | |
644 cur->next = next; | |
645 break; | |
646 } | |
647 if (!found) | |
648 { | |
649 /* Could not find it, add it */ | |
650 if (prev) | |
651 prev->next = copy_widget_value_tree (new_val, STRUCTURAL_CHANGE); | |
652 else | |
653 info->val = copy_widget_value_tree (new_val, STRUCTURAL_CHANGE); | |
654 } | |
655 new_val->next = next_new_val; | |
656 } | |
657 | |
658 update_all_widget_values (info, deep_p); | |
659 } | |
660 | |
661 | |
662 /* creating the widgets */ | |
663 | |
664 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
665 initialize_widget_instance (instance) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
666 widget_instance* instance; |
5626 | 667 { |
668 widget_value* val; | |
669 | |
670 for (val = instance->info->val; val; val = val->next) | |
671 val->change = STRUCTURAL_CHANGE; | |
672 | |
673 update_one_widget_instance (instance, True); | |
674 | |
675 for (val = instance->info->val; val; val = val->next) | |
676 val->change = NO_CHANGE; | |
677 } | |
678 | |
679 | |
680 static widget_creation_function | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
681 find_in_table (type, table) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
682 char* type; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
683 widget_creation_entry* table; |
5626 | 684 { |
685 widget_creation_entry* cur; | |
686 for (cur = table; cur->type; cur++) | |
5853 | 687 if (!my_strcasecmp (type, cur->type)) |
5626 | 688 return cur->function; |
689 return NULL; | |
690 } | |
691 | |
692 static Boolean | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
693 dialog_spec_p (name) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
694 char* name; |
5626 | 695 { |
696 /* return True if name matches [EILPQeilpq][1-9][Bb] or | |
697 [EILPQeilpq][1-9][Bb][Rr][1-9] */ | |
698 if (!name) | |
699 return False; | |
700 | |
701 switch (name [0]) | |
702 { | |
703 case 'E': case 'I': case 'L': case 'P': case 'Q': | |
704 case 'e': case 'i': case 'l': case 'p': case 'q': | |
705 if (name [1] >= '0' && name [1] <= '9') | |
706 { | |
707 if (name [2] != 'B' && name [2] != 'b') | |
708 return False; | |
709 if (!name [3]) | |
710 return True; | |
711 if ((name [3] == 'T' || name [3] == 't') && !name [4]) | |
712 return True; | |
713 if ((name [3] == 'R' || name [3] == 'r') | |
714 && name [4] >= '0' && name [4] <= '9' && !name [5]) | |
715 return True; | |
716 return False; | |
717 } | |
718 else | |
719 return False; | |
720 | |
721 default: | |
722 return False; | |
723 } | |
724 } | |
725 | |
726 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
727 instanciate_widget_instance (instance) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
728 widget_instance* instance; |
5626 | 729 { |
730 widget_creation_function function = NULL; | |
731 | |
732 #if defined (USE_LUCID) | |
733 if (!function) | |
734 function = find_in_table (instance->info->type, xlw_creation_table); | |
735 #endif | |
736 #if defined(USE_MOTIF) | |
737 if (!function) | |
738 function = find_in_table (instance->info->type, xm_creation_table); | |
739 #endif | |
740 #if defined (USE_OLIT) | |
741 if (!function) | |
742 function = find_in_table (instance->info->type, xol_creation_table); | |
743 #endif | |
744 | |
745 if (!function) | |
746 { | |
747 if (dialog_spec_p (instance->info->type)) | |
748 { | |
749 #if defined (USE_LUCID) | |
750 /* not yet */ | |
751 #endif | |
752 #if defined(USE_MOTIF) | |
753 if (!function) | |
754 function = xm_create_dialog; | |
755 #endif | |
756 #if defined (USE_OLIT) | |
757 /* not yet */ | |
758 #endif | |
759 } | |
760 } | |
761 | |
762 if (!function) | |
763 { | |
764 printf ("No creation function for widget type %s\n", | |
765 instance->info->type); | |
766 abort (); | |
767 } | |
768 | |
769 instance->widget = (*function) (instance); | |
770 | |
771 if (!instance->widget) | |
772 abort (); | |
773 | |
774 /* XtRealizeWidget (instance->widget);*/ | |
775 } | |
776 | |
777 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
778 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb, post_activate_cb) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
779 char* type; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
780 char* name; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
781 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
782 widget_value* val; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
783 lw_callback pre_activate_cb; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
784 lw_callback selection_cb; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
785 lw_callback post_activate_cb; |
5626 | 786 { |
787 if (!get_widget_info (id, False)) | |
788 allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb, | |
789 post_activate_cb); | |
790 } | |
791 | |
792 Widget | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
793 lw_get_widget (id, parent, pop_up_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
794 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
795 Widget parent; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
796 Boolean pop_up_p; |
5626 | 797 { |
798 widget_instance* instance; | |
799 | |
800 instance = find_instance (id, parent, pop_up_p); | |
801 return instance ? instance->widget : NULL; | |
802 } | |
803 | |
804 Widget | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
805 lw_make_widget (id, parent, pop_up_p) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
806 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
807 Widget parent; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
808 Boolean pop_up_p; |
5626 | 809 { |
810 widget_instance* instance; | |
811 widget_info* info; | |
812 | |
813 instance = find_instance (id, parent, pop_up_p); | |
814 if (!instance) | |
815 { | |
816 info = get_widget_info (id, False); | |
817 if (!info) | |
818 return NULL; | |
819 instance = allocate_widget_instance (info, parent, pop_up_p); | |
820 initialize_widget_instance (instance); | |
821 } | |
822 if (!instance->widget) | |
823 abort (); | |
824 return instance->widget; | |
825 } | |
826 | |
827 Widget | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
828 lw_create_widget (type, name, id, val, parent, pop_up_p, pre_activate_cb, selection_cb, post_activate_cb) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
829 char* type; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
830 char* name; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
831 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
832 widget_value* val; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
833 Widget parent; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
834 Boolean pop_up_p; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
835 lw_callback pre_activate_cb; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
836 lw_callback selection_cb; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
837 lw_callback post_activate_cb; |
5626 | 838 { |
839 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb, | |
840 post_activate_cb); | |
841 return lw_make_widget (id, parent, pop_up_p); | |
842 } | |
843 | |
844 | |
845 /* destroying the widgets */ | |
846 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
847 destroy_one_instance (instance) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
848 widget_instance* instance; |
5626 | 849 { |
850 /* Remove the destroy callback on the widget; that callback will try to | |
851 dereference the instance object (to set its widget slot to 0, since the | |
852 widget is dead.) Since the instance is now dead, we don't have to worry | |
853 about the fact that its widget is dead too. | |
854 | |
855 This happens in the Phase2Destroy of the widget, so this callback would | |
856 not have been run until arbitrarily long after the instance was freed. | |
857 */ | |
858 if (instance->widget) | |
859 XtRemoveCallback (instance->widget, XtNdestroyCallback, | |
860 mark_widget_destroyed, (XtPointer)instance); | |
861 | |
862 if (instance->widget) | |
863 { | |
864 /* The else are pretty tricky here, including the empty statement | |
865 at the end because it would be very bad to destroy a widget | |
866 twice. */ | |
867 #if defined (USE_LUCID) | |
868 if (lw_lucid_widget_p (instance->widget)) | |
869 xlw_destroy_instance (instance); | |
870 else | |
871 #endif | |
872 #if defined (USE_MOTIF) | |
873 if (lw_motif_widget_p (instance->widget)) | |
874 xm_destroy_instance (instance); | |
875 else | |
876 #endif | |
877 #if defined (USE_OLIT) | |
878 if (lw_olit_widget_p (instance->widget)) | |
879 xol_destroy_instance (instance); | |
880 else | |
881 #endif | |
882 /* do not remove the empty statement */ | |
883 ; | |
884 } | |
885 | |
886 free_widget_instance (instance); | |
887 } | |
888 | |
889 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
890 lw_destroy_widget (w) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
891 Widget w; |
5626 | 892 { |
893 widget_instance* instance = get_widget_instance (w, True); | |
894 | |
895 if (instance) | |
896 { | |
897 widget_info *info = instance->info; | |
898 /* instance has already been removed from the list; free it */ | |
899 destroy_one_instance (instance); | |
900 /* if there are no instances left, free the info too */ | |
901 if (!info->instances) | |
902 lw_destroy_all_widgets (info->id); | |
903 } | |
904 } | |
905 | |
906 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
907 lw_destroy_all_widgets (id) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
908 LWLIB_ID id; |
5626 | 909 { |
910 widget_info* info = get_widget_info (id, True); | |
911 widget_instance* instance; | |
912 widget_instance* next; | |
913 | |
914 if (info) | |
915 { | |
916 for (instance = info->instances; instance; ) | |
917 { | |
918 next = instance->next; | |
919 destroy_one_instance (instance); | |
920 instance = next; | |
921 } | |
922 free_widget_info (info); | |
923 } | |
924 } | |
925 | |
926 void | |
927 lw_destroy_everything () | |
928 { | |
929 while (all_widget_info) | |
930 lw_destroy_all_widgets (all_widget_info->id); | |
931 } | |
932 | |
933 void | |
934 lw_destroy_all_pop_ups () | |
935 { | |
936 widget_info* info; | |
937 widget_info* next; | |
938 widget_instance* instance; | |
939 | |
940 for (info = all_widget_info; info; info = next) | |
941 { | |
942 next = info->next; | |
943 instance = info->instances; | |
944 if (instance && instance->pop_up_p) | |
945 lw_destroy_all_widgets (info->id); | |
946 } | |
947 } | |
948 | |
949 #ifdef USE_MOTIF | |
950 extern Widget first_child (Widget); /* garbage */ | |
951 #endif | |
952 | |
953 Widget | |
954 lw_raise_all_pop_up_widgets () | |
955 { | |
956 widget_info* info; | |
957 widget_instance* instance; | |
958 Widget result = NULL; | |
959 | |
960 for (info = all_widget_info; info; info = info->next) | |
961 for (instance = info->instances; instance; instance = instance->next) | |
962 if (instance->pop_up_p) | |
963 { | |
964 Widget widget = instance->widget; | |
965 if (widget) | |
966 { | |
967 if (XtIsManaged (widget) | |
968 #ifdef USE_MOTIF | |
969 /* What a complete load of crap!!!! | |
970 When a dialogShell is on the screen, it is not managed! | |
971 */ | |
972 || (lw_motif_widget_p (instance->widget) && | |
973 XtIsManaged (first_child (widget))) | |
974 #endif | |
975 ) | |
976 { | |
977 if (!result) | |
978 result = widget; | |
979 XMapRaised (XtDisplay (widget), XtWindow (widget)); | |
980 } | |
981 } | |
982 } | |
983 return result; | |
984 } | |
985 | |
986 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
987 lw_pop_all_widgets (id, up) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
988 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
989 Boolean up; |
5626 | 990 { |
991 widget_info* info = get_widget_info (id, False); | |
992 widget_instance* instance; | |
993 | |
994 if (info) | |
995 for (instance = info->instances; instance; instance = instance->next) | |
996 if (instance->pop_up_p && instance->widget) | |
997 { | |
998 if (!XtIsRealized (instance->widget)) | |
999 XtRealizeWidget (instance->widget); | |
1000 #if defined (USE_LUCID) | |
1001 if (lw_lucid_widget_p (instance->widget)) | |
1002 xlw_pop_instance (instance, up); | |
1003 #endif | |
1004 #if defined (USE_MOTIF) | |
1005 if (lw_motif_widget_p (instance->widget)) | |
1006 xm_pop_instance (instance, up); | |
1007 #endif | |
1008 #if defined (USE_OLIT) | |
1009 if (lw_olit_widget_p (instance->widget)) | |
1010 xol_pop_instance (instance, up); | |
1011 #endif | |
1012 } | |
1013 } | |
1014 | |
1015 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1016 lw_pop_up_all_widgets (id) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1017 LWLIB_ID id; |
5626 | 1018 { |
1019 lw_pop_all_widgets (id, True); | |
1020 } | |
1021 | |
1022 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1023 lw_pop_down_all_widgets (id) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1024 LWLIB_ID id; |
5626 | 1025 { |
1026 lw_pop_all_widgets (id, False); | |
1027 } | |
1028 | |
1029 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1030 lw_popup_menu (widget) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1031 Widget widget; |
5626 | 1032 { |
1033 #if defined (USE_LUCID) | |
1034 if (lw_lucid_widget_p (widget)) | |
1035 xlw_popup_menu (widget); | |
1036 #endif | |
1037 #if defined (USE_MOTIF) | |
1038 if (lw_motif_widget_p (widget)) | |
1039 xm_popup_menu (widget); | |
1040 #endif | |
1041 #if defined (USE_OLIT) | |
1042 if (lw_olit_widget_p (widget)) | |
1043 xol_popup_menu (widget); | |
1044 #endif | |
1045 } | |
1046 | |
1047 /* get the values back */ | |
1048 static Boolean | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1049 get_one_value (instance, val) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1050 widget_instance* instance; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1051 widget_value* val; |
5626 | 1052 { |
1053 Widget widget = name_to_widget (instance, val->name); | |
1054 | |
1055 if (widget) | |
1056 { | |
1057 #if defined (USE_LUCID) | |
1058 if (lw_lucid_widget_p (instance->widget)) | |
1059 xlw_update_one_value (instance, widget, val); | |
1060 #endif | |
1061 #if defined (USE_MOTIF) | |
1062 if (lw_motif_widget_p (instance->widget)) | |
1063 xm_update_one_value (instance, widget, val); | |
1064 #endif | |
1065 #if defined (USE_OLIT) | |
1066 if (lw_olit_widget_p (instance->widget)) | |
1067 xol_update_one_value (instance, widget, val); | |
1068 #endif | |
1069 return True; | |
1070 } | |
1071 else | |
1072 return False; | |
1073 } | |
1074 | |
1075 Boolean | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1076 lw_get_some_values (id, val_out) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1077 LWLIB_ID id; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1078 widget_value* val_out; |
5626 | 1079 { |
1080 widget_info* info = get_widget_info (id, False); | |
1081 widget_instance* instance; | |
1082 widget_value* val; | |
1083 Boolean result = False; | |
1084 | |
1085 if (!info) | |
1086 return False; | |
1087 | |
1088 instance = info->instances; | |
1089 if (!instance) | |
1090 return False; | |
1091 | |
1092 for (val = val_out; val; val = val->next) | |
1093 if (get_one_value (instance, val)) | |
1094 result = True; | |
1095 | |
1096 return result; | |
1097 } | |
1098 | |
1099 widget_value* | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1100 lw_get_all_values (id) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1101 LWLIB_ID id; |
5626 | 1102 { |
1103 widget_info* info = get_widget_info (id, False); | |
1104 widget_value* val = info->val; | |
1105 if (lw_get_some_values (id, val)) | |
1106 return val; | |
1107 else | |
1108 return NULL; | |
1109 } | |
1110 | |
1111 /* internal function used by the library dependent implementation to get the | |
1112 widget_value for a given widget in an instance */ | |
1113 widget_value* | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1114 lw_get_widget_value_for_widget (instance, w) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1115 widget_instance* instance; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1116 Widget w; |
5626 | 1117 { |
1118 char* name = XtName (w); | |
1119 widget_value* cur; | |
1120 for (cur = instance->info->val; cur; cur = cur->next) | |
1121 if (!strcmp (cur->name, name)) | |
1122 return cur; | |
1123 return NULL; | |
1124 } | |
1125 | |
1126 /* update other instances value when one thing changed */ | |
1127 /* This function can be used as a an XtCallback for the widgets that get | |
1128 modified to update other instances of the widgets. Closure should be the | |
1129 widget_instance. */ | |
1130 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1131 lw_internal_update_other_instances (widget, closure, call_data) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1132 Widget widget; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1133 XtPointer closure; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1134 XtPointer call_data; |
5626 | 1135 { |
1136 /* To forbid recursive calls */ | |
1137 static Boolean updating; | |
1138 | |
1139 widget_instance* instance = (widget_instance*)closure; | |
1140 char* name = XtName (widget); | |
1141 widget_info* info; | |
1142 widget_instance* cur; | |
1143 widget_value* val; | |
1144 | |
1145 /* never recurse as this could cause infinite recursions. */ | |
1146 if (updating) | |
1147 return; | |
1148 | |
1149 /* protect against the widget being destroyed */ | |
1150 if (XtWidgetBeingDestroyedP (widget)) | |
1151 return; | |
1152 | |
1153 /* Return immediately if there are no other instances */ | |
1154 info = instance->info; | |
1155 if (!info->instances->next) | |
1156 return; | |
1157 | |
1158 updating = True; | |
1159 | |
1160 for (val = info->val; val && strcmp (val->name, name); val = val->next); | |
1161 | |
1162 if (val && get_one_value (instance, val)) | |
1163 for (cur = info->instances; cur; cur = cur->next) | |
1164 if (cur != instance) | |
1165 set_one_value (cur, val, True); | |
1166 | |
1167 updating = False; | |
1168 } | |
1169 | |
1170 | |
1171 /* get the id */ | |
1172 | |
1173 LWLIB_ID | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1174 lw_get_widget_id (w) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1175 Widget w; |
5626 | 1176 { |
1177 widget_instance* instance = get_widget_instance (w, False); | |
1178 | |
1179 return instance ? instance->info->id : 0; | |
1180 } | |
1181 | |
1182 /* set the keyboard focus */ | |
1183 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1184 lw_set_keyboard_focus (parent, w) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1185 Widget parent; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1186 Widget w; |
5626 | 1187 { |
1188 #if defined (USE_MOTIF) | |
1189 xm_set_keyboard_focus (parent, w); | |
1190 #else | |
1191 XtSetKeyboardFocus (parent, w); | |
1192 #endif | |
1193 } | |
1194 | |
1195 /* Show busy */ | |
1196 static void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1197 show_one_widget_busy (w, flag) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1198 Widget w; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1199 Boolean flag; |
5626 | 1200 { |
1201 Pixel foreground = 0; | |
1202 Pixel background = 1; | |
1203 Widget widget_to_invert = XtNameToWidget (w, "*sheet"); | |
1204 if (!widget_to_invert) | |
1205 widget_to_invert = w; | |
1206 | |
1207 XtVaGetValues (widget_to_invert, | |
1208 XtNforeground, &foreground, | |
1209 XtNbackground, &background, | |
1210 0); | |
1211 XtVaSetValues (widget_to_invert, | |
1212 XtNforeground, background, | |
1213 XtNbackground, foreground, | |
1214 0); | |
1215 } | |
1216 | |
1217 void | |
5724
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1218 lw_show_busy (w, busy) |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1219 Widget w; |
02a4aeb69cae
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5706
diff
changeset
|
1220 Boolean busy; |
5626 | 1221 { |
1222 widget_instance* instance = get_widget_instance (w, False); | |
1223 widget_info* info; | |
1224 widget_instance* next; | |
1225 | |
1226 if (instance) | |
1227 { | |
1228 info = instance->info; | |
1229 if (info->busy != busy) | |
1230 { | |
1231 for (next = info->instances; next; next = next->next) | |
1232 if (next->widget) | |
1233 show_one_widget_busy (next->widget, busy); | |
1234 info->busy = busy; | |
1235 } | |
1236 } | |
1237 } |