428
+ − 1 /* A general interface to the widgets of different toolkits.
+ − 2 Copyright (C) 1992, 1993, 1994 Lucid, Inc.
+ − 3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
+ − 4
+ − 5 This file is part of the Lucid Widget Library.
+ − 6
+ − 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
+ − 9 the Free Software Foundation; either version 2, or (at your option)
+ − 10 any later version.
+ − 11
+ − 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
+ − 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ − 15 GNU General Public License for more details.
+ − 16
+ − 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
+ − 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 20 Boston, MA 02111-1307, USA. */
+ − 21
+ − 22 #ifdef NeXT
+ − 23 #undef __STRICT_BSD__ /* ick */
+ − 24 #endif
+ − 25
+ − 26 #include <config.h>
+ − 27 #include <stdio.h>
+ − 28 #include <stdlib.h>
+ − 29 #include <string.h>
+ − 30 #include <sys/types.h>
+ − 31 #ifdef HAVE_UNISTD_H
+ − 32 #include <unistd.h>
+ − 33 #endif
+ − 34 #include <X11/StringDefs.h>
+ − 35 #include "lwlib-internal.h"
+ − 36 #include "lwlib-utils.h"
+ − 37
+ − 38 #ifdef NEED_LUCID
+ − 39 #include "lwlib-Xlw.h"
+ − 40 #endif
+ − 41 #ifdef NEED_MOTIF
+ − 42 #include "lwlib-Xm.h"
434
+ − 43 #ifdef LWLIB_WIDGETS_MOTIF
+ − 44 #include <Xm/Xm.h>
+ − 45 #endif
428
+ − 46 #endif
+ − 47 #ifdef NEED_ATHENA
+ − 48 #include "lwlib-Xaw.h"
+ − 49 #endif
+ − 50
+ − 51 /* #### Does a check need to be put back in here to make sure we have
+ − 52 sufficient defines to function properly or are the checks in the
+ − 53 makefile sufficient? */
+ − 54
+ − 55 /* List of all widgets managed by the library. Note that each "widget"
+ − 56 listed here may actually be a tree of widgets; for example, a
+ − 57 single entry here might represent a single menubar or popup menu,
+ − 58 each of which might be implemented with a tree of widgets.
+ − 59 */
+ − 60 static widget_info *all_widget_info = NULL;
+ − 61
+ − 62 /* boolean flag indicating that the menubar is active */
+ − 63 int lw_menu_active = 0;
+ − 64
+ − 65 /* X11 menubar widget */
+ − 66 Widget lw_menubar_widget = NULL;
+ − 67
+ − 68 /* whether the last menu operation was a keyboard accelerator */
+ − 69 int lw_menu_accelerate = False;
+ − 70
+ − 71
+ − 72 /* Forward declarations */
434
+ − 73 static void instantiate_widget_instance (widget_instance *instance);
+ − 74 static void free_widget_value_args (widget_value* wv);
428
+ − 75
+ − 76
+ − 77 /* utility functions for widget_instance and widget_info */
+ − 78 static char *
442
+ − 79 safe_strdup (const char *s)
428
+ − 80 {
+ − 81 char *result;
+ − 82 if (! s) return 0;
+ − 83 result = (char *) malloc (strlen (s) + 1);
+ − 84 if (! result)
+ − 85 return 0;
+ − 86 strcpy (result, s);
+ − 87 return result;
+ − 88 }
+ − 89
+ − 90 static void
+ − 91 safe_free_str (char *s)
+ − 92 {
+ − 93 if (s) free (s);
+ − 94 }
+ − 95
+ − 96 static widget_value *widget_value_free_list = 0;
+ − 97
+ − 98 widget_value *
+ − 99 malloc_widget_value (void)
+ − 100 {
+ − 101 widget_value *wv;
+ − 102 if (widget_value_free_list)
+ − 103 {
+ − 104 wv = widget_value_free_list;
+ − 105 widget_value_free_list = wv->free_list;
+ − 106 wv->free_list = 0;
+ − 107 }
+ − 108 else
+ − 109 {
+ − 110 wv = (widget_value *) malloc (sizeof (widget_value));
+ − 111 }
+ − 112 if (wv)
+ − 113 {
438
+ − 114 memset (wv, '\0', sizeof (widget_value));
428
+ − 115 }
+ − 116 return wv;
+ − 117 }
+ − 118
+ − 119 /* this is analogous to free(). It frees only what was allocated
+ − 120 by malloc_widget_value(), and no substructures.
+ − 121 */
+ − 122 void
+ − 123 free_widget_value (widget_value *wv)
+ − 124 {
+ − 125 if (wv->free_list)
+ − 126 abort ();
+ − 127 wv->free_list = widget_value_free_list;
+ − 128 widget_value_free_list = wv;
+ − 129 }
+ − 130
+ − 131 static void
+ − 132 free_widget_value_contents (widget_value *wv)
+ − 133 {
+ − 134 if (wv->name) free (wv->name);
+ − 135 if (wv->value) free (wv->value);
+ − 136 if (wv->key) free (wv->key);
+ − 137
+ − 138 /* #### - all of this 0xDEADBEEF stuff should be unnecessary
+ − 139 in production code... it should be conditionalized. */
+ − 140 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF;
+ − 141
+ − 142 if (wv->toolkit_data && wv->free_toolkit_data)
+ − 143 {
+ − 144 XtFree ((char *) wv->toolkit_data);
+ − 145 wv->toolkit_data = (void *) 0xDEADBEEF;
+ − 146 }
+ − 147 #ifdef NEED_SCROLLBARS
+ − 148 if (wv->scrollbar_data)
+ − 149 {
+ − 150 free (wv->scrollbar_data);
+ − 151 wv->scrollbar_data = NULL;
+ − 152 }
+ − 153 #endif
+ − 154 if (wv->contents && (wv->contents != (widget_value*)1))
+ − 155 {
+ − 156 free_widget_value_tree (wv->contents);
+ − 157 wv->contents = (widget_value *) 0xDEADBEEF;
+ − 158 }
434
+ − 159
+ − 160 free_widget_value_args (wv);
+ − 161
428
+ − 162 if (wv->next)
+ − 163 {
+ − 164 free_widget_value_tree (wv->next);
+ − 165 wv->next = (widget_value *) 0xDEADBEEF;
+ − 166 }
+ − 167 }
+ − 168
+ − 169 void
+ − 170 free_widget_value_tree (widget_value *wv)
+ − 171 {
+ − 172 if (!wv)
+ − 173 return;
+ − 174
+ − 175 free_widget_value_contents (wv);
+ − 176 free_widget_value (wv);
+ − 177 }
+ − 178
+ − 179 #ifdef NEED_SCROLLBARS
+ − 180
+ − 181 static void
+ − 182 copy_scrollbar_values (widget_value *val, widget_value *copy)
+ − 183 {
+ − 184 if (!copy->scrollbar_data)
+ − 185 copy->scrollbar_data =
+ − 186 (scrollbar_values *) malloc (sizeof (scrollbar_values));
+ − 187
+ − 188 if (val->scrollbar_data)
+ − 189 *copy->scrollbar_data = *val->scrollbar_data;
+ − 190 else
438
+ − 191 memset (copy->scrollbar_data, '\0', sizeof (scrollbar_values));
428
+ − 192 }
+ − 193
+ − 194 /*
+ − 195 * Return true if old->scrollbar_data were not equivalent
3025
+ − 196 * to new_->scrollbar_data.
428
+ − 197 */
+ − 198 static Boolean
1201
+ − 199 merge_scrollbar_values (widget_value *old, widget_value *new_)
428
+ − 200 {
+ − 201 Boolean changed = False;
+ − 202
1201
+ − 203 if (new_->scrollbar_data && !old->scrollbar_data)
428
+ − 204 {
1201
+ − 205 copy_scrollbar_values (new_, old);
428
+ − 206 changed = True;
+ − 207 }
1201
+ − 208 else if (!new_->scrollbar_data && old->scrollbar_data)
428
+ − 209 {
+ − 210 free (old->scrollbar_data);
+ − 211 old->scrollbar_data = NULL;
+ − 212 }
1201
+ − 213 else if (new_->scrollbar_data && old->scrollbar_data)
428
+ − 214 {
+ − 215 scrollbar_values *old_sb = old->scrollbar_data;
1201
+ − 216 scrollbar_values *new_sb = new_->scrollbar_data;
428
+ − 217
+ − 218 if ((old_sb->line_increment != new_sb->line_increment) ||
+ − 219 (old_sb->page_increment != new_sb->page_increment) ||
+ − 220 (old_sb->minimum != new_sb->minimum) ||
+ − 221 (old_sb->maximum != new_sb->maximum) ||
+ − 222 (old_sb->slider_size != new_sb->slider_size) ||
+ − 223 (old_sb->slider_position != new_sb->slider_position) ||
+ − 224 (old_sb->scrollbar_width != new_sb->scrollbar_width) ||
+ − 225 (old_sb->scrollbar_height != new_sb->scrollbar_height) ||
+ − 226 (old_sb->scrollbar_x != new_sb->scrollbar_x) ||
+ − 227 (old_sb->scrollbar_y != new_sb->scrollbar_y))
+ − 228 changed = True;
+ − 229
+ − 230 *old_sb = *new_sb;
+ − 231 }
+ − 232
+ − 233 return changed;
+ − 234 }
+ − 235
+ − 236 #endif /* NEED_SCROLLBARS */
+ − 237
771
+ − 238 #ifdef HAVE_X_WIDGETS
434
+ − 239 /*
+ − 240 * Return true if old->args was not equivalent
3025
+ − 241 * to new_->args.
434
+ − 242 */
+ − 243 static Boolean
3025
+ − 244 merge_widget_value_args (widget_value *old, widget_value *new_)
434
+ − 245 {
+ − 246 Boolean changed = False;
+ − 247
3025
+ − 248 if (new_->args && !old->args)
434
+ − 249 {
3025
+ − 250 lw_copy_widget_value_args (new_, old);
434
+ − 251 changed = True;
+ − 252 }
+ − 253 /* Generally we don't want to lose values that are already in the
+ − 254 widget. */
3025
+ − 255 else if (!new_->args && old->args)
434
+ − 256 {
3025
+ − 257 lw_copy_widget_value_args (old, new_);
434
+ − 258 changed = True;
+ − 259 }
3025
+ − 260 else if (new_->args && old->args && new_->args != old->args)
434
+ − 261 {
+ − 262 /* #### Do something more sensible here than just copying the
+ − 263 new values (like actually merging the values). */
3025
+ − 264 lw_copy_widget_value_args (new_, old);
434
+ − 265 changed = True;
+ − 266 }
3025
+ − 267 else if (new_->args && new_->args == old->args && new_->args->args_changed == True)
450
+ − 268 {
+ − 269 changed = True;
+ − 270 }
434
+ − 271
+ − 272 return changed;
+ − 273 }
771
+ − 274 #endif /* HAVE_X_WIDGETS */
434
+ − 275
428
+ − 276 /* Make a complete copy of a widget_value tree. Store CHANGE into
+ − 277 the widget_value tree's `change' field. */
+ − 278
442
+ − 279 widget_value *
428
+ − 280 copy_widget_value_tree (widget_value *val, change_type change)
+ − 281 {
+ − 282 widget_value *copy;
+ − 283
+ − 284 if (!val)
+ − 285 return NULL;
+ − 286 if (val == (widget_value *) 1)
+ − 287 return val;
+ − 288
+ − 289 copy = malloc_widget_value ();
+ − 290 if (copy)
+ − 291 {
+ − 292 /* #### - don't seg fault *here* if out of memory. Menus will be
+ − 293 truncated inexplicably. */
+ − 294 copy->type = val->type;
+ − 295 copy->name = safe_strdup (val->name);
+ − 296 copy->value = safe_strdup (val->value);
+ − 297 copy->key = safe_strdup (val->key);
+ − 298 copy->accel = val->accel;
+ − 299 copy->enabled = val->enabled;
+ − 300 copy->selected = val->selected;
+ − 301 copy->edited = False;
+ − 302 copy->change = change;
+ − 303 copy->contents = copy_widget_value_tree (val->contents, change);
+ − 304 copy->call_data = val->call_data;
+ − 305 copy->next = copy_widget_value_tree (val->next, change);
+ − 306 copy->toolkit_data = NULL;
+ − 307 copy->free_toolkit_data = False;
434
+ − 308
+ − 309 lw_copy_widget_value_args (val, copy);
428
+ − 310 #ifdef NEED_SCROLLBARS
+ − 311 copy_scrollbar_values (val, copy);
+ − 312 #endif
+ − 313 }
+ − 314 return copy;
+ − 315 }
+ − 316
+ − 317 /* This function is used to implement incremental menu construction. */
+ − 318
+ − 319 widget_value *
+ − 320 replace_widget_value_tree (widget_value *node, widget_value *newtree)
+ − 321 {
+ − 322 widget_value *copy;
+ − 323
+ − 324 if (!node || !newtree)
+ − 325 abort ();
+ − 326
+ − 327 copy = copy_widget_value_tree (newtree, STRUCTURAL_CHANGE);
+ − 328
+ − 329 free_widget_value_contents (node);
+ − 330 *node = *copy;
+ − 331 free_widget_value (copy); /* free the node, but not its contents. */
+ − 332 return node;
+ − 333 }
+ − 334
+ − 335 static widget_info *
442
+ − 336 allocate_widget_info (const char *type, const char *name,
428
+ − 337 LWLIB_ID id, widget_value *val,
+ − 338 lw_callback pre_activate_cb, lw_callback selection_cb,
+ − 339 lw_callback post_activate_cb)
+ − 340 {
+ − 341 widget_info *info = (widget_info *) malloc (sizeof (widget_info));
+ − 342 info->type = safe_strdup (type);
+ − 343 info->name = safe_strdup (name);
+ − 344 info->id = id;
+ − 345 info->val = copy_widget_value_tree (val, STRUCTURAL_CHANGE);
+ − 346 info->busy = False;
+ − 347 info->pre_activate_cb = pre_activate_cb;
+ − 348 info->selection_cb = selection_cb;
+ − 349 info->post_activate_cb = post_activate_cb;
+ − 350 info->instances = NULL;
+ − 351
+ − 352 info->next = all_widget_info;
+ − 353 all_widget_info = info;
+ − 354
+ − 355 return info;
+ − 356 }
+ − 357
+ − 358 static void
+ − 359 free_widget_info (widget_info *info)
+ − 360 {
+ − 361 safe_free_str (info->type);
+ − 362 safe_free_str (info->name);
+ − 363 free_widget_value_tree (info->val);
438
+ − 364 memset (info, '\0', sizeof (widget_info));
428
+ − 365 free (info);
+ − 366 }
+ − 367
+ − 368 static void
2286
+ − 369 mark_widget_destroyed (Widget widget, XtPointer closure,
+ − 370 XtPointer UNUSED (call_data))
428
+ − 371 {
+ − 372 widget_instance *instance = (widget_instance*)closure;
+ − 373
+ − 374 /* be very conservative */
+ − 375 if (instance->widget == widget)
+ − 376 instance->widget = NULL;
+ − 377 }
+ − 378
+ − 379 static widget_instance *
+ − 380 allocate_widget_instance (widget_info *info, Widget parent, Boolean pop_up_p)
+ − 381 {
+ − 382 widget_instance *instance =
+ − 383 (widget_instance *) malloc (sizeof (widget_instance));
+ − 384 instance->parent = parent;
+ − 385 instance->pop_up_p = pop_up_p;
+ − 386 instance->info = info;
+ − 387 instance->next = info->instances;
+ − 388 info->instances = instance;
+ − 389
+ − 390 instantiate_widget_instance (instance);
+ − 391
+ − 392 XtAddCallback (instance->widget, XtNdestroyCallback,
+ − 393 mark_widget_destroyed, (XtPointer)instance);
+ − 394 return instance;
+ − 395 }
+ − 396
+ − 397 static void
+ − 398 free_widget_instance (widget_instance *instance)
+ − 399 {
438
+ − 400 memset (instance, '\0', sizeof (widget_instance));
428
+ − 401 free (instance);
+ − 402 }
+ − 403
+ − 404 static widget_info *
+ − 405 get_widget_info (LWLIB_ID id, Boolean remove_p)
+ − 406 {
+ − 407 widget_info *info;
+ − 408 widget_info *prev;
+ − 409 for (prev = NULL, info = all_widget_info;
+ − 410 info;
+ − 411 prev = info, info = info->next)
+ − 412 if (info->id == id)
+ − 413 {
+ − 414 if (remove_p)
+ − 415 {
+ − 416 if (prev)
+ − 417 prev->next = info->next;
+ − 418 else
+ − 419 all_widget_info = info->next;
+ − 420 }
+ − 421 return info;
+ − 422 }
+ − 423 return NULL;
+ − 424 }
+ − 425
+ − 426 /* Internal function used by the library dependent implementation to get the
+ − 427 widget_value for a given widget in an instance */
+ − 428 widget_info *
+ − 429 lw_get_widget_info (LWLIB_ID id)
+ − 430 {
+ − 431 return get_widget_info (id, 0);
+ − 432 }
+ − 433
+ − 434 static int
+ − 435 map_widget_values (widget_value *value, int (*mapfunc) (widget_value *value,
+ − 436 void *closure),
+ − 437 void *closure)
+ − 438 {
+ − 439 int retval = 0;
+ − 440
+ − 441 if (value->contents)
+ − 442 retval = map_widget_values (value->contents, mapfunc, closure);
+ − 443 if (retval)
+ − 444 return retval;
+ − 445
+ − 446 if (value->next)
+ − 447 retval = map_widget_values (value->next, mapfunc, closure);
+ − 448 if (retval)
+ − 449 return retval;
+ − 450
+ − 451 return (mapfunc) (value, closure);
+ − 452 }
+ − 453
+ − 454 int
+ − 455 lw_map_widget_values (LWLIB_ID id, int (*mapfunc) (widget_value *value,
+ − 456 void *closure),
+ − 457 void *closure)
+ − 458 {
+ − 459 widget_info *info = get_widget_info (id, 0);
+ − 460
+ − 461 if (!info)
+ − 462 abort ();
+ − 463
+ − 464 if (info->val)
+ − 465 return map_widget_values (info->val, mapfunc, closure);
+ − 466 return 0;
+ − 467 }
+ − 468
+ − 469 static widget_instance *
+ − 470 get_widget_instance (Widget widget, Boolean remove_p)
+ − 471 {
+ − 472 widget_info *info;
+ − 473 widget_instance *instance;
+ − 474 widget_instance *prev;
+ − 475 for (info = all_widget_info; info; info = info->next)
+ − 476 for (prev = NULL, instance = info->instances;
+ − 477 instance;
+ − 478 prev = instance, instance = instance->next)
+ − 479 if (instance->widget == widget)
+ − 480 {
+ − 481 if (remove_p)
+ − 482 {
+ − 483 if (prev)
+ − 484 prev->next = instance->next;
+ − 485 else
+ − 486 info->instances = instance->next;
+ − 487 }
+ − 488 return instance;
+ − 489 }
+ − 490 return (widget_instance *) 0;
+ − 491 }
+ − 492
+ − 493 static widget_instance*
+ − 494 find_instance (LWLIB_ID id, Widget parent, Boolean pop_up_p)
+ − 495 {
+ − 496 widget_info *info = get_widget_info (id, False);
+ − 497 widget_instance *instance;
+ − 498
+ − 499 if (info)
+ − 500 for (instance = info->instances; instance; instance = instance->next)
+ − 501 if (instance->parent == parent && instance->pop_up_p == pop_up_p)
+ − 502 return instance;
+ − 503
+ − 504 return NULL;
+ − 505 }
+ − 506
+ − 507
+ − 508 /* utility function for widget_value */
+ − 509 static Boolean
442
+ − 510 safe_strcmp (const char *s1, const char *s2)
428
+ − 511 {
+ − 512 if (!!s1 ^ !!s2) return True;
+ − 513 return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2;
+ − 514 }
+ − 515
+ − 516 #if 0
+ − 517 # define EXPLAIN(name, oc, nc, desc, a1, a2) \
+ − 518 printf ("Change: \"%s\"\tmax(%s=%d,%s=%d)\t%s %d %d\n", \
+ − 519 name, \
+ − 520 (oc == NO_CHANGE ? "none" : \
+ − 521 (oc == INVISIBLE_CHANGE ? "invisible" : \
+ − 522 (oc == VISIBLE_CHANGE ? "visible" : \
+ − 523 (oc == STRUCTURAL_CHANGE ? "structural" : "???")))), \
+ − 524 oc, \
+ − 525 (nc == NO_CHANGE ? "none" : \
+ − 526 (nc == INVISIBLE_CHANGE ? "invisible" : \
+ − 527 (nc == VISIBLE_CHANGE ? "visible" : \
+ − 528 (nc == STRUCTURAL_CHANGE ? "structural" : "???")))), \
+ − 529 nc, desc, a1, a2)
+ − 530 #else
+ − 531 # define EXPLAIN(name, oc, nc, desc, a1, a2)
+ − 532 #endif
+ − 533
+ − 534
+ − 535 static widget_value *
+ − 536 merge_widget_value (widget_value *val1, widget_value *val2, int level)
+ − 537 {
+ − 538 change_type change;
+ − 539 widget_value *merged_next;
+ − 540 widget_value *merged_contents;
+ − 541
+ − 542 if (!val1)
+ − 543 {
+ − 544 if (val2)
+ − 545 return copy_widget_value_tree (val2, STRUCTURAL_CHANGE);
+ − 546 else
+ − 547 return NULL;
+ − 548 }
+ − 549 if (!val2)
+ − 550 {
+ − 551 free_widget_value_tree (val1);
+ − 552 return NULL;
+ − 553 }
+ − 554
+ − 555 change = NO_CHANGE;
+ − 556
+ − 557 if (val1->type != val2->type)
+ − 558 {
+ − 559 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "type change",
+ − 560 val1->type, val2->type);
+ − 561 change = max (change, STRUCTURAL_CHANGE);
+ − 562 val1->type = val2->type;
+ − 563 }
+ − 564 if (safe_strcmp (val1->name, val2->name))
+ − 565 {
+ − 566 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "name change",
+ − 567 val1->name, val2->name);
+ − 568 change = max (change, STRUCTURAL_CHANGE);
+ − 569 safe_free_str (val1->name);
+ − 570 val1->name = safe_strdup (val2->name);
+ − 571 }
+ − 572 if (safe_strcmp (val1->value, val2->value))
+ − 573 {
+ − 574 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "value change",
+ − 575 val1->value, val2->value);
+ − 576 change = max (change, VISIBLE_CHANGE);
+ − 577 safe_free_str (val1->value);
+ − 578 val1->value = safe_strdup (val2->value);
+ − 579 }
+ − 580 if (safe_strcmp (val1->key, val2->key))
+ − 581 {
+ − 582 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "key change",
+ − 583 val1->key, val2->key);
+ − 584 change = max (change, VISIBLE_CHANGE);
+ − 585 safe_free_str (val1->key);
+ − 586 val1->key = safe_strdup (val2->key);
+ − 587 }
+ − 588 if (val1->accel != val2->accel)
+ − 589 {
+ − 590 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "accelerator change",
+ − 591 val1->accel, val2->accel);
+ − 592 change = max (change, VISIBLE_CHANGE);
+ − 593 val1->accel = val2->accel;
+ − 594 }
+ − 595 if (val1->enabled != val2->enabled)
+ − 596 {
+ − 597 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "enablement change",
+ − 598 val1->enabled, val2->enabled);
+ − 599 change = max (change, VISIBLE_CHANGE);
+ − 600 val1->enabled = val2->enabled;
+ − 601 }
+ − 602 if (val1->selected != val2->selected)
+ − 603 {
+ − 604 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "selection change",
+ − 605 val1->selected, val2->selected);
+ − 606 change = max (change, VISIBLE_CHANGE);
+ − 607 val1->selected = val2->selected;
+ − 608 }
+ − 609 if (val1->call_data != val2->call_data)
+ − 610 {
+ − 611 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "call-data change",
+ − 612 val1->call_data, val2->call_data);
+ − 613 change = max (change, INVISIBLE_CHANGE);
+ − 614 val1->call_data = val2->call_data;
+ − 615 }
771
+ − 616 #ifdef HAVE_X_WIDGETS
434
+ − 617 if (merge_widget_value_args (val1, val2))
+ − 618 {
+ − 619 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "widget change", 0, 0);
+ − 620 change = max (change, VISIBLE_CHANGE);
+ − 621 }
+ − 622 #endif
+ − 623
428
+ − 624 #ifdef NEED_SCROLLBARS
+ − 625 if (merge_scrollbar_values (val1, val2))
+ − 626 {
+ − 627 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "scrollbar change", 0, 0);
+ − 628 change = max (change, VISIBLE_CHANGE);
+ − 629 }
+ − 630 #endif
+ − 631
+ − 632 if (level > 0)
+ − 633 {
+ − 634 merged_contents =
+ − 635 merge_widget_value (val1->contents, val2->contents, level - 1);
+ − 636
+ − 637 if (val1->contents && !merged_contents)
+ − 638 {
+ − 639 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents gone)",
+ − 640 0, 0);
+ − 641 change = max (change, INVISIBLE_CHANGE);
+ − 642 }
+ − 643 else if (merged_contents && merged_contents->change != NO_CHANGE)
+ − 644 {
+ − 645 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents change)",
+ − 646 0, 0);
+ − 647 change = max (change, INVISIBLE_CHANGE);
+ − 648 }
+ − 649
+ − 650 val1->contents = merged_contents;
+ − 651 }
+ − 652
+ − 653 merged_next = merge_widget_value (val1->next, val2->next, level);
+ − 654
+ − 655 if (val1->next && !merged_next)
+ − 656 {
+ − 657 EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "(following gone)",
+ − 658 0, 0);
+ − 659 change = max (change, STRUCTURAL_CHANGE);
+ − 660 }
+ − 661 else if (merged_next)
+ − 662 {
+ − 663 if (merged_next->change)
+ − 664 {
+ − 665 EXPLAIN (val1->name, change, merged_next->change, "(following change)",
+ − 666 0, 0);
2286
+ − 667 change = max (change, merged_next->change);
428
+ − 668 }
+ − 669 }
+ − 670
+ − 671 val1->next = merged_next;
+ − 672
+ − 673 val1->change = change;
+ − 674
+ − 675 if (change > NO_CHANGE && val1->toolkit_data)
+ − 676 {
+ − 677 if (val1->free_toolkit_data)
+ − 678 XtFree ((char *) val1->toolkit_data);
+ − 679 val1->toolkit_data = NULL;
+ − 680 }
+ − 681
+ − 682 return val1;
+ − 683 }
+ − 684
+ − 685
+ − 686 /* modifying the widgets */
+ − 687 static Widget
442
+ − 688 name_to_widget (widget_instance *instance, const char *name)
428
+ − 689 {
+ − 690 Widget widget = NULL;
+ − 691
+ − 692 if (!instance->widget)
+ − 693 return NULL;
+ − 694
+ − 695 if (!strcmp (XtName (instance->widget), name))
+ − 696 widget = instance->widget;
+ − 697 else
+ − 698 {
+ − 699 int length = strlen (name) + 2;
+ − 700 char *real_name = (char *) alloca (length);
+ − 701 real_name [0] = '*';
+ − 702 strcpy (real_name + 1, name);
+ − 703
+ − 704 widget = XtNameToWidget (instance->widget, real_name);
+ − 705 }
+ − 706 return widget;
+ − 707 }
+ − 708
+ − 709 static void
+ − 710 set_one_value (widget_instance *instance, widget_value *val, Boolean deep_p)
+ − 711 {
+ − 712 Widget widget = name_to_widget (instance, val->name);
+ − 713
+ − 714 if (widget)
+ − 715 {
+ − 716 #ifdef NEED_LUCID
+ − 717 if (lw_lucid_widget_p (instance->widget))
+ − 718 xlw_update_one_widget (instance, widget, val, deep_p);
+ − 719 #endif
+ − 720 #ifdef NEED_MOTIF
+ − 721 if (lw_motif_widget_p (instance->widget))
+ − 722 xm_update_one_widget (instance, widget, val, deep_p);
+ − 723 #endif
+ − 724 #ifdef NEED_ATHENA
+ − 725 if (lw_xaw_widget_p (instance->widget))
+ − 726 xaw_update_one_widget (instance, widget, val, deep_p);
+ − 727 #endif
+ − 728 }
+ − 729 }
+ − 730
+ − 731 static void
+ − 732 update_one_widget_instance (widget_instance *instance, Boolean deep_p)
+ − 733 {
+ − 734 widget_value *val;
+ − 735
+ − 736 if (!instance->widget)
+ − 737 /* the widget was destroyed */
+ − 738 return;
+ − 739
+ − 740 for (val = instance->info->val; val; val = val->next)
+ − 741 if (val->change != NO_CHANGE)
+ − 742 set_one_value (instance, val, deep_p);
+ − 743 }
+ − 744
+ − 745 static void
+ − 746 update_all_widget_values (widget_info *info, Boolean deep_p)
+ − 747 {
+ − 748 widget_instance *instance;
+ − 749 widget_value *val;
+ − 750
+ − 751 for (instance = info->instances; instance; instance = instance->next)
+ − 752 update_one_widget_instance (instance, deep_p);
+ − 753
+ − 754 for (val = info->val; val; val = val->next)
450
+ − 755 {
+ − 756 val->change = NO_CHANGE;
+ − 757 if (val->args)
+ − 758 val->args->args_changed = False;
+ − 759 }
428
+ − 760 }
+ − 761
+ − 762 void
+ − 763 lw_modify_all_widgets (LWLIB_ID id, widget_value *val, Boolean deep_p)
+ − 764 {
+ − 765 widget_info *info = get_widget_info (id, False);
+ − 766 widget_value *new_val;
+ − 767 widget_value *next_new_val;
+ − 768 widget_value *cur;
+ − 769 widget_value *prev;
+ − 770 widget_value *next;
+ − 771 int found;
+ − 772
+ − 773 if (!info)
+ − 774 return;
+ − 775
+ − 776 for (new_val = val; new_val; new_val = new_val->next)
+ − 777 {
+ − 778 next_new_val = new_val->next;
+ − 779 new_val->next = NULL;
+ − 780 found = False;
+ − 781 for (prev = NULL, cur = info->val; cur; prev = cur, cur = cur->next)
+ − 782 if (!strcmp (cur->name, new_val->name))
+ − 783 {
+ − 784 found = True;
+ − 785 next = cur->next;
+ − 786 cur->next = NULL;
+ − 787 cur = merge_widget_value (cur, new_val, deep_p ? 1000 : 1);
+ − 788 if (prev)
+ − 789 prev->next = cur ? cur : next;
+ − 790 else
+ − 791 info->val = cur ? cur : next;
+ − 792 if (cur)
+ − 793 cur->next = next;
+ − 794 break;
+ − 795 }
+ − 796 if (!found)
+ − 797 {
+ − 798 /* Could not find it, add it */
+ − 799 if (prev)
+ − 800 prev->next = copy_widget_value_tree (new_val, STRUCTURAL_CHANGE);
+ − 801 else
+ − 802 info->val = copy_widget_value_tree (new_val, STRUCTURAL_CHANGE);
+ − 803 }
+ − 804 new_val->next = next_new_val;
+ − 805 }
+ − 806
+ − 807 update_all_widget_values (info, deep_p);
+ − 808 }
+ − 809
+ − 810
+ − 811 /* creating the widgets */
+ − 812
+ − 813 static void
+ − 814 initialize_widget_instance (widget_instance *instance)
+ − 815 {
+ − 816 widget_value *val;
+ − 817
+ − 818 for (val = instance->info->val; val; val = val->next)
+ − 819 val->change = STRUCTURAL_CHANGE;
+ − 820
+ − 821 update_one_widget_instance (instance, True);
+ − 822
+ − 823 for (val = instance->info->val; val; val = val->next)
450
+ − 824 {
+ − 825 val->change = NO_CHANGE;
+ − 826 if (val->args)
+ − 827 val->args->args_changed = False;
+ − 828 }
428
+ − 829 }
+ − 830
1201
+ − 831 #if defined (NEED_LUCID) || defined (NEED_ATHENA) || defined (NEED_MOTIF)
+ − 832
442
+ − 833 /* strcasecmp() is not sufficiently portable or standard,
+ − 834 and it's easier just to write our own. */
+ − 835 static int
+ − 836 ascii_strcasecmp (const char *s1, const char *s2)
+ − 837 {
+ − 838 while (1)
+ − 839 {
+ − 840 char c1 = *s1++;
+ − 841 char c2 = *s2++;
+ − 842 if (c1 >= 'A' && c1 <= 'Z') c1 += 'a' - 'A';
+ − 843 if (c2 >= 'A' && c2 <= 'Z') c2 += 'a' - 'A';
+ − 844 if (c1 != c2) return c1 - c2;
+ − 845 if (c1 == '\0') return 0;
+ − 846 }
+ − 847 }
428
+ − 848
+ − 849 static widget_creation_function
450
+ − 850 find_in_table (const char *type, const widget_creation_entry table[])
428
+ − 851 {
450
+ − 852 const widget_creation_entry *cur;
428
+ − 853 for (cur = table; cur->type; cur++)
442
+ − 854 if (!ascii_strcasecmp (type, cur->type))
428
+ − 855 return cur->function;
+ − 856 return NULL;
+ − 857 }
+ − 858
872
+ − 859 #endif
+ − 860
428
+ − 861 static Boolean
442
+ − 862 dialog_spec_p (const char *name)
428
+ − 863 {
+ − 864 /* return True if name matches [EILPQeilpq][1-9][Bb] or
+ − 865 [EILPQeilpq][1-9][Bb][Rr][1-9] */
+ − 866 if (!name)
+ − 867 return False;
+ − 868
+ − 869 switch (name [0])
+ − 870 {
+ − 871 case 'E': case 'I': case 'L': case 'P': case 'Q':
+ − 872 case 'e': case 'i': case 'l': case 'p': case 'q':
+ − 873 if (name [1] >= '0' && name [1] <= '9')
+ − 874 {
+ − 875 if (name [2] != 'B' && name [2] != 'b')
+ − 876 return False;
+ − 877 if (!name [3])
+ − 878 return True;
+ − 879 if ((name [3] == 'T' || name [3] == 't') && !name [4])
+ − 880 return True;
+ − 881 if ((name [3] == 'R' || name [3] == 'r')
+ − 882 && name [4] >= '0' && name [4] <= '9' && !name [5])
+ − 883 return True;
+ − 884 return False;
+ − 885 }
+ − 886 else
+ − 887 return False;
+ − 888
+ − 889 default:
+ − 890 return False;
+ − 891 }
+ − 892 }
+ − 893
+ − 894 static void
+ − 895 instantiate_widget_instance (widget_instance *instance)
+ − 896 {
+ − 897 widget_creation_function function = NULL;
+ − 898
+ − 899 #ifdef NEED_LUCID
+ − 900 if (!function)
+ − 901 function = find_in_table (instance->info->type, xlw_creation_table);
+ − 902 #endif
+ − 903 #ifdef NEED_MOTIF
+ − 904 if (!function)
+ − 905 function = find_in_table (instance->info->type, xm_creation_table);
+ − 906 #endif
+ − 907 #ifdef NEED_ATHENA
+ − 908 if (!function)
+ − 909 function = find_in_table (instance->info->type, xaw_creation_table);
+ − 910 #endif
+ − 911
+ − 912 if (!function)
+ − 913 {
+ − 914 if (dialog_spec_p (instance->info->type))
+ − 915 {
+ − 916 #ifdef LWLIB_DIALOGS_MOTIF
+ − 917 if (!function)
+ − 918 function = xm_create_dialog;
+ − 919 #endif
+ − 920 #ifdef LWLIB_DIALOGS_ATHENA
+ − 921 if (!function)
+ − 922 function = xaw_create_dialog;
+ − 923 #endif
+ − 924 #ifdef LWLIB_DIALOGS_LUCID
+ − 925 /* not yet (not ever?) */
+ − 926 #endif
+ − 927 }
+ − 928 }
+ − 929
+ − 930 if (!function)
+ − 931 {
+ − 932 fprintf (stderr, "No creation function for widget type %s\n",
+ − 933 instance->info->type);
+ − 934 abort ();
+ − 935 }
+ − 936
+ − 937 instance->widget = (*function) (instance);
+ − 938
+ − 939 if (!instance->widget)
+ − 940 abort ();
+ − 941
+ − 942 /* XtRealizeWidget (instance->widget);*/
+ − 943 }
+ − 944
+ − 945 void
442
+ − 946 lw_register_widget (const char *type, const char *name,
428
+ − 947 LWLIB_ID id, widget_value *val,
+ − 948 lw_callback pre_activate_cb, lw_callback selection_cb,
+ − 949 lw_callback post_activate_cb)
+ − 950 {
+ − 951 if (!get_widget_info (id, False))
+ − 952 allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb,
+ − 953 post_activate_cb);
+ − 954 }
+ − 955
+ − 956 Widget
+ − 957 lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
+ − 958 {
+ − 959 widget_instance *instance = find_instance (id, parent, pop_up_p);
+ − 960 return instance ? instance->widget : NULL;
+ − 961 }
+ − 962
+ − 963 Widget
+ − 964 lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
+ − 965 {
+ − 966 widget_instance *instance = find_instance (id, parent, pop_up_p);
+ − 967
+ − 968 if (!instance)
+ − 969 {
+ − 970 widget_info *info = get_widget_info (id, False);
+ − 971 if (!info)
+ − 972 return NULL;
+ − 973 instance = allocate_widget_instance (info, parent, pop_up_p);
+ − 974 initialize_widget_instance (instance);
+ − 975 }
+ − 976 if (!instance->widget)
+ − 977 abort ();
+ − 978 return instance->widget;
+ − 979 }
+ − 980
+ − 981 Widget
442
+ − 982 lw_create_widget (const char *type, const char *name,
428
+ − 983 LWLIB_ID id, widget_value *val,
+ − 984 Widget parent, Boolean pop_up_p, lw_callback pre_activate_cb,
+ − 985 lw_callback selection_cb, lw_callback post_activate_cb)
+ − 986 {
+ − 987 lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb,
+ − 988 post_activate_cb);
+ − 989 return lw_make_widget (id, parent, pop_up_p);
+ − 990 }
+ − 991
+ − 992
+ − 993 /* destroying the widgets */
+ − 994 static void
+ − 995 destroy_one_instance (widget_instance *instance)
+ − 996 {
+ − 997 /* Remove the destroy callback on the widget; that callback will try to
+ − 998 dereference the instance object (to set its widget slot to 0, since the
+ − 999 widget is dead.) Since the instance is now dead, we don't have to worry
+ − 1000 about the fact that its widget is dead too.
+ − 1001
+ − 1002 This happens in the Phase2Destroy of the widget, so this callback would
+ − 1003 not have been run until arbitrarily long after the instance was freed.
+ − 1004 */
+ − 1005 if (instance->widget)
+ − 1006 XtRemoveCallback (instance->widget, XtNdestroyCallback,
+ − 1007 mark_widget_destroyed, (XtPointer)instance);
+ − 1008
+ − 1009 if (instance->widget)
+ − 1010 {
+ − 1011 /* The else are pretty tricky here, including the empty statement
+ − 1012 at the end because it would be very bad to destroy a widget
+ − 1013 twice. */
+ − 1014 #ifdef NEED_LUCID
+ − 1015 if (lw_lucid_widget_p (instance->widget))
+ − 1016 xlw_destroy_instance (instance);
+ − 1017 else
+ − 1018 #endif
+ − 1019 #ifdef NEED_MOTIF
+ − 1020 if (lw_motif_widget_p (instance->widget))
+ − 1021 xm_destroy_instance (instance);
+ − 1022 else
+ − 1023 #endif
+ − 1024 #ifdef NEED_ATHENA
+ − 1025 if (lw_xaw_widget_p (instance->widget))
+ − 1026 xaw_destroy_instance (instance);
+ − 1027 else
+ − 1028 #endif
+ − 1029 {
+ − 1030 /* do not remove the empty statement */
+ − 1031 ;
+ − 1032 }
+ − 1033 }
+ − 1034
+ − 1035 free_widget_instance (instance);
+ − 1036 }
+ − 1037
+ − 1038 void
+ − 1039 lw_destroy_widget (Widget w)
+ − 1040 {
+ − 1041 widget_instance *instance = get_widget_instance (w, True);
+ − 1042
+ − 1043 if (instance)
+ − 1044 {
+ − 1045 widget_info *info = instance->info;
+ − 1046 /* instance has already been removed from the list; free it */
+ − 1047 destroy_one_instance (instance);
+ − 1048 /* if there are no instances left, free the info too */
+ − 1049 if (!info->instances)
+ − 1050 lw_destroy_all_widgets (info->id);
+ − 1051 }
+ − 1052 }
+ − 1053
+ − 1054 void
+ − 1055 lw_destroy_all_widgets (LWLIB_ID id)
+ − 1056 {
+ − 1057 widget_info *info = get_widget_info (id, True);
+ − 1058 widget_instance *instance;
+ − 1059 widget_instance *next;
+ − 1060
+ − 1061 if (info)
+ − 1062 {
+ − 1063 for (instance = info->instances; instance; )
+ − 1064 {
+ − 1065 next = instance->next;
+ − 1066 destroy_one_instance (instance);
+ − 1067 instance = next;
+ − 1068 }
+ − 1069 free_widget_info (info);
+ − 1070 }
+ − 1071 }
+ − 1072
+ − 1073 void
442
+ − 1074 lw_destroy_everything (void)
428
+ − 1075 {
+ − 1076 while (all_widget_info)
+ − 1077 lw_destroy_all_widgets (all_widget_info->id);
+ − 1078 }
+ − 1079
+ − 1080 void
442
+ − 1081 lw_destroy_all_pop_ups (void)
428
+ − 1082 {
+ − 1083 widget_info *info;
+ − 1084 widget_info *next;
+ − 1085 widget_instance *instance;
+ − 1086
+ − 1087 for (info = all_widget_info; info; info = next)
+ − 1088 {
+ − 1089 next = info->next;
+ − 1090 instance = info->instances;
+ − 1091 if (instance && instance->pop_up_p)
+ − 1092 lw_destroy_all_widgets (info->id);
+ − 1093 }
+ − 1094 }
+ − 1095
+ − 1096 Widget
+ − 1097 lw_raise_all_pop_up_widgets (void)
+ − 1098 {
+ − 1099 widget_info *info;
+ − 1100 widget_instance *instance;
+ − 1101 Widget result = NULL;
+ − 1102
+ − 1103 for (info = all_widget_info; info; info = info->next)
+ − 1104 for (instance = info->instances; instance; instance = instance->next)
+ − 1105 if (instance->pop_up_p)
+ − 1106 {
+ − 1107 Widget widget = instance->widget;
+ − 1108 if (widget)
+ − 1109 {
+ − 1110 if (XtIsManaged (widget)
+ − 1111 #ifdef NEED_MOTIF
+ − 1112 /* What a complete load of crap!!!!
+ − 1113 When a dialogShell is on the screen, it is not managed!
+ − 1114 */
+ − 1115 || (lw_motif_widget_p (instance->widget) &&
+ − 1116 XtIsManaged (first_child (widget)))
+ − 1117 #endif
+ − 1118 )
+ − 1119 {
+ − 1120 if (!result)
+ − 1121 result = widget;
+ − 1122 XMapRaised (XtDisplay (widget), XtWindow (widget));
+ − 1123 }
+ − 1124 }
+ − 1125 }
+ − 1126 return result;
+ − 1127 }
+ − 1128
+ − 1129 static void
+ − 1130 lw_pop_all_widgets (LWLIB_ID id, Boolean up)
+ − 1131 {
+ − 1132 widget_info *info = get_widget_info (id, False);
+ − 1133 widget_instance *instance;
+ − 1134
+ − 1135 if (info)
+ − 1136 for (instance = info->instances; instance; instance = instance->next)
+ − 1137 if (instance->pop_up_p && instance->widget)
+ − 1138 {
+ − 1139 #ifdef NEED_LUCID
+ − 1140 if (lw_lucid_widget_p (instance->widget))
+ − 1141 {
+ − 1142 XtRealizeWidget (instance->widget);
+ − 1143 xlw_pop_instance (instance, up);
+ − 1144 }
+ − 1145 #endif
+ − 1146 #ifdef NEED_MOTIF
+ − 1147 if (lw_motif_widget_p (instance->widget))
+ − 1148 {
+ − 1149 XtRealizeWidget (instance->widget);
+ − 1150 xm_pop_instance (instance, up);
+ − 1151 }
+ − 1152 #endif
+ − 1153 #ifdef NEED_ATHENA
+ − 1154 if (lw_xaw_widget_p (instance->widget))
+ − 1155 {
+ − 1156 XtRealizeWidget (XtParent (instance->widget));
+ − 1157 XtRealizeWidget (instance->widget);
+ − 1158 xaw_pop_instance (instance, up);
+ − 1159 }
+ − 1160 #endif
+ − 1161 }
+ − 1162 }
+ − 1163
+ − 1164 void
+ − 1165 lw_pop_up_all_widgets (LWLIB_ID id)
+ − 1166 {
+ − 1167 lw_pop_all_widgets (id, True);
+ − 1168 }
+ − 1169
+ − 1170 void
+ − 1171 lw_pop_down_all_widgets (LWLIB_ID id)
+ − 1172 {
+ − 1173 lw_pop_all_widgets (id, False);
+ − 1174 }
+ − 1175
+ − 1176 void
+ − 1177 lw_popup_menu (Widget widget, XEvent *event)
+ − 1178 {
+ − 1179 #ifdef LWLIB_MENUBARS_LUCID
+ − 1180 if (lw_lucid_widget_p (widget))
+ − 1181 xlw_popup_menu (widget, event);
+ − 1182 #endif
+ − 1183 #ifdef LWLIB_MENUBARS_MOTIF
+ − 1184 if (lw_motif_widget_p (widget))
+ − 1185 xm_popup_menu (widget, event);
+ − 1186 #endif
+ − 1187 #ifdef LWLIB_MENUBARS_ATHENA
+ − 1188 if (lw_xaw_widget_p (widget))
+ − 1189 xaw_popup_menu (widget, event); /* not implemented */
+ − 1190 #endif
+ − 1191 }
+ − 1192
+ − 1193 /* get the values back */
+ − 1194 static Boolean
+ − 1195 get_one_value (widget_instance *instance, widget_value *val)
+ − 1196 {
+ − 1197 Widget widget = name_to_widget (instance, val->name);
+ − 1198
+ − 1199 if (widget)
+ − 1200 {
+ − 1201 #ifdef NEED_LUCID
+ − 1202 if (lw_lucid_widget_p (instance->widget))
+ − 1203 xlw_update_one_value (instance, widget, val);
+ − 1204 #endif
+ − 1205 #ifdef NEED_MOTIF
+ − 1206 if (lw_motif_widget_p (instance->widget))
+ − 1207 xm_update_one_value (instance, widget, val);
+ − 1208 #endif
+ − 1209 #ifdef NEED_ATHENA
+ − 1210 if (lw_xaw_widget_p (instance->widget))
+ − 1211 xaw_update_one_value (instance, widget, val);
+ − 1212 #endif
+ − 1213 return True;
+ − 1214 }
+ − 1215 else
+ − 1216 return False;
+ − 1217 }
+ − 1218
+ − 1219 Boolean
+ − 1220 lw_get_some_values (LWLIB_ID id, widget_value *val_out)
+ − 1221 {
+ − 1222 widget_info *info = get_widget_info (id, False);
+ − 1223 widget_instance *instance;
+ − 1224 widget_value *val;
+ − 1225 Boolean result = False;
+ − 1226
+ − 1227 if (!info)
+ − 1228 return False;
+ − 1229
+ − 1230 instance = info->instances;
+ − 1231 if (!instance)
+ − 1232 return False;
+ − 1233
+ − 1234 for (val = val_out; val; val = val->next)
+ − 1235 if (get_one_value (instance, val))
+ − 1236 result = True;
+ − 1237
+ − 1238 return result;
+ − 1239 }
+ − 1240
+ − 1241 widget_value*
+ − 1242 lw_get_all_values (LWLIB_ID id)
+ − 1243 {
+ − 1244 widget_info *info = get_widget_info (id, False);
+ − 1245 widget_value *val = info->val;
+ − 1246 if (lw_get_some_values (id, val))
+ − 1247 return val;
+ − 1248 else
+ − 1249 return NULL;
+ − 1250 }
+ − 1251
+ − 1252 /* internal function used by the library dependent implementation to get the
+ − 1253 widget_value for a given widget in an instance */
+ − 1254 widget_value*
+ − 1255 lw_get_widget_value_for_widget (widget_instance *instance, Widget w)
+ − 1256 {
+ − 1257 char *name = XtName (w);
+ − 1258 widget_value *cur;
+ − 1259 for (cur = instance->info->val; cur; cur = cur->next)
+ − 1260 if (!strcmp (cur->name, name))
+ − 1261 return cur;
+ − 1262 return NULL;
+ − 1263 }
+ − 1264
+ − 1265
+ − 1266 /* update other instances value when one thing changed */
+ − 1267 /* This function can be used as a an XtCallback for the widgets that get
+ − 1268 modified to update other instances of the widgets. Closure should be the
+ − 1269 widget_instance. */
+ − 1270 void
+ − 1271 lw_internal_update_other_instances (Widget widget, XtPointer closure,
2286
+ − 1272 XtPointer UNUSED (call_data))
428
+ − 1273 {
+ − 1274 /* To forbid recursive calls */
+ − 1275 static Boolean updating;
+ − 1276
+ − 1277 widget_instance *instance = (widget_instance*)closure;
+ − 1278 char *name = XtName (widget);
+ − 1279 widget_info *info;
+ − 1280 widget_instance *cur;
+ − 1281 widget_value *val;
+ − 1282
+ − 1283 /* never recurse as this could cause infinite recursions. */
+ − 1284 if (updating)
+ − 1285 return;
+ − 1286
+ − 1287 /* protect against the widget being destroyed */
+ − 1288 if (XtWidgetBeingDestroyedP (widget))
+ − 1289 return;
+ − 1290
+ − 1291 /* Return immediately if there are no other instances */
+ − 1292 info = instance->info;
+ − 1293 if (!info->instances->next)
+ − 1294 return;
+ − 1295
+ − 1296 updating = True;
+ − 1297
+ − 1298 for (val = info->val; val && strcmp (val->name, name); val = val->next);
+ − 1299
+ − 1300 if (val && get_one_value (instance, val))
+ − 1301 for (cur = info->instances; cur; cur = cur->next)
+ − 1302 if (cur != instance)
+ − 1303 set_one_value (cur, val, True);
+ − 1304
+ − 1305 updating = False;
+ − 1306 }
+ − 1307
+ − 1308
+ − 1309
+ − 1310 /* get the id */
+ − 1311
+ − 1312 LWLIB_ID
+ − 1313 lw_get_widget_id (Widget w)
+ − 1314 {
+ − 1315 widget_instance *instance = get_widget_instance (w, False);
+ − 1316
+ − 1317 return instance ? instance->info->id : 0;
+ − 1318 }
+ − 1319
+ − 1320
+ − 1321 /* set the keyboard focus */
+ − 1322 void
+ − 1323 lw_set_keyboard_focus (Widget parent, Widget w)
+ − 1324 {
+ − 1325 #if defined(NEED_MOTIF) && !defined(LESSTIF_VERSION)
+ − 1326 /* This loses with Lesstif v0.75a */
+ − 1327 xm_set_keyboard_focus (parent, w);
+ − 1328 #else
+ − 1329 XtSetKeyboardFocus (parent, w);
+ − 1330 #endif
+ − 1331 }
+ − 1332
+ − 1333
+ − 1334 /* Show busy */
+ − 1335 static void
2286
+ − 1336 show_one_widget_busy (Widget w, Boolean UNUSED (flag))
428
+ − 1337 {
+ − 1338 Pixel foreground = 0;
+ − 1339 Pixel background = 1;
+ − 1340 Widget widget_to_invert = XtNameToWidget (w, "*sheet");
+ − 1341 Arg al [2];
+ − 1342
+ − 1343 if (!widget_to_invert)
+ − 1344 widget_to_invert = w;
+ − 1345
+ − 1346 XtSetArg (al [0], XtNforeground, &foreground);
+ − 1347 XtSetArg (al [1], XtNbackground, &background);
+ − 1348 XtGetValues (widget_to_invert, al, 2);
+ − 1349
+ − 1350 XtSetArg (al [0], XtNforeground, background);
+ − 1351 XtSetArg (al [1], XtNbackground, foreground);
+ − 1352 XtSetValues (widget_to_invert, al, 2);
+ − 1353 }
+ − 1354
+ − 1355 void
+ − 1356 lw_show_busy (Widget w, Boolean busy)
+ − 1357 {
+ − 1358 widget_instance *instance = get_widget_instance (w, False);
+ − 1359 widget_info *info;
+ − 1360 widget_instance *next;
+ − 1361
+ − 1362 if (instance)
+ − 1363 {
+ − 1364 info = instance->info;
+ − 1365 if (info->busy != busy)
+ − 1366 {
+ − 1367 for (next = info->instances; next; next = next->next)
+ − 1368 if (next->widget)
+ − 1369 show_one_widget_busy (next->widget, busy);
+ − 1370 info->busy = busy;
+ − 1371 }
+ − 1372 }
+ − 1373 }
+ − 1374
+ − 1375 void lw_add_value_args_to_args (widget_value* wv, ArgList addto, int* offset)
+ − 1376 {
+ − 1377 int i;
434
+ − 1378 if (wv->args && wv->args->nargs)
428
+ − 1379 {
434
+ − 1380 for (i = 0; i<wv->args->nargs; i++)
428
+ − 1381 {
434
+ − 1382 addto[i + *offset] = wv->args->args[i];
428
+ − 1383 }
434
+ − 1384 *offset += wv->args->nargs;
428
+ − 1385 }
+ − 1386 }
+ − 1387
639
+ − 1388 XtArgVal lw_get_value_arg (widget_value* wv, String name)
+ − 1389 {
+ − 1390 int i;
+ − 1391 if (wv->args)
+ − 1392 {
+ − 1393 for (i = 0; i < wv->args->nargs; i++)
+ − 1394 {
+ − 1395 if (!strcmp (wv->args->args[i].name, name))
+ − 1396 {
+ − 1397 return wv->args->args[i].value;
+ − 1398 }
+ − 1399 }
+ − 1400 }
+ − 1401 return (XtArgVal)0;
+ − 1402 }
+ − 1403
434
+ − 1404 void lw_add_widget_value_arg (widget_value* wv, String name, XtArgVal value)
+ − 1405 {
442
+ − 1406 int i = 0;
434
+ − 1407 if (!wv->args)
+ − 1408 {
+ − 1409 wv->args = (widget_args *) malloc (sizeof (widget_args));
438
+ − 1410 memset (wv->args, '\0', sizeof (widget_args));
434
+ − 1411 wv->args->ref_count = 1;
+ − 1412 wv->args->nargs = 0;
+ − 1413 wv->args->args = (ArgList) malloc (sizeof (Arg) * 10);
438
+ − 1414 memset (wv->args->args, '\0', sizeof (Arg) * 10);
434
+ − 1415 }
+ − 1416
+ − 1417 if (wv->args->nargs > 10)
+ − 1418 return;
+ − 1419
450
+ − 1420 /* Register the change. */
+ − 1421 wv->args->args_changed = True;
442
+ − 1422 /* If the arg is already there then we must replace it. */
+ − 1423 for (i = 0; i < wv->args->nargs; i++)
+ − 1424 {
+ − 1425 if (!strcmp (wv->args->args[i].name, name))
+ − 1426 {
+ − 1427 XtSetArg (wv->args->args [i], name, value);
+ − 1428 break;
+ − 1429 }
+ − 1430 }
+ − 1431 if (i >= wv->args->nargs)
+ − 1432 {
+ − 1433 XtSetArg (wv->args->args [wv->args->nargs], name, value); wv->args->nargs++;
+ − 1434 }
434
+ − 1435 }
+ − 1436
+ − 1437 static void free_widget_value_args (widget_value* wv)
+ − 1438 {
+ − 1439 if (wv->args)
+ − 1440 {
+ − 1441 if (--wv->args->ref_count <= 0)
+ − 1442 {
+ − 1443 #ifdef LWLIB_WIDGETS_MOTIF
+ − 1444 int i;
+ − 1445 for (i = 0; i < wv->args->nargs; i++)
+ − 1446 {
+ − 1447 if (!strcmp (wv->args->args[i].name, XmNfontList))
+ − 1448 XmFontListFree ((XmFontList)wv->args->args[i].value);
+ − 1449 }
+ − 1450 #endif
+ − 1451 free (wv->args->args);
+ − 1452 free (wv->args);
442
+ − 1453 wv->args = 0;
434
+ − 1454 }
+ − 1455 }
+ − 1456 }
+ − 1457
+ − 1458 void lw_copy_widget_value_args (widget_value* val, widget_value* copy)
+ − 1459 {
442
+ − 1460 if (val == copy || val->args == copy->args)
+ − 1461 return;
+ − 1462
+ − 1463 if (copy->args)
434
+ − 1464 {
442
+ − 1465 free_widget_value_args (copy);
434
+ − 1466 }
442
+ − 1467
+ − 1468 if (val->args)
434
+ − 1469 {
+ − 1470 copy->args = val->args;
+ − 1471 copy->args->ref_count++;
+ − 1472 }
+ − 1473 }
+ − 1474
442
+ − 1475 /* Remove %_ and convert %% to %. We can do this in-place because we
+ − 1476 are always shortening, never lengthening, the string. */
+ − 1477 void
+ − 1478 lw_remove_accelerator_spec (char *val)
+ − 1479 {
+ − 1480 char *foo = val, *bar = val;
+ − 1481
+ − 1482 while (*bar)
+ − 1483 {
+ − 1484 if (*bar == '%' && *(bar+1) == '_')
+ − 1485 bar += 2;
+ − 1486 else if (*bar == '%' && *(bar+1) == '%')
+ − 1487 {
+ − 1488 *foo++ = *bar++;
+ − 1489 bar++;
+ − 1490 }
+ − 1491 else
+ − 1492 *foo++ = *bar++;
+ − 1493 }
+ − 1494 *foo = '\0';
+ − 1495 }