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