comparison lwlib/lwlib-Xlw.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 697ef44129c6
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */ 19 Boston, MA 02111-1307, USA. */
20 20
21 #include <config.h> 21 #include <config.h>
22 #include <stdlib.h> /* for abort () */ 22 #include <stdlib.h> /* for abort () */
23 #include <stdio.h> /* for abort () */
23 #include <limits.h> 24 #include <limits.h>
24 25
25 #include "lwlib-Xlw.h" 26 #include "lwlib-Xlw.h"
27 #include "lwlib-utils.h"
26 #include <X11/StringDefs.h> 28 #include <X11/StringDefs.h>
27 #include <X11/IntrinsicP.h> 29 #include <X11/IntrinsicP.h>
28 #include <X11/ObjectP.h> 30 #include <X11/ObjectP.h>
29 #include <X11/CompositeP.h> 31 #include <X11/CompositeP.h>
30 #include <X11/Shell.h> 32 #include <X11/Shell.h>
33 #ifdef HAVE_WIDGETS
34 #include "../src/EmacsManager.h"
35 #endif
31 #ifdef LWLIB_MENUBARS_LUCID 36 #ifdef LWLIB_MENUBARS_LUCID
32 #include "xlwmenu.h" 37 #include "xlwmenu.h"
33 #endif 38 #endif
34 #ifdef LWLIB_SCROLLBARS_LUCID 39 #ifdef LWLIB_SCROLLBARS_LUCID
35 #include "xlwscrollbar.h" 40 #include "xlwscrollbar.h"
41 #endif
42 #ifdef LWLIB_TABS_LUCID
43 #ifdef NEED_MOTIF
44 #include "lwlib-Xm.h"
45 #endif
46 #ifdef NEED_ATHENA
47 #include "lwlib-Xaw.h"
48 #endif
49 #include "../src/xmu.h"
50 #include "xlwtabs.h"
36 #endif 51 #endif
37 52
38 53
39 54
40 #ifdef LWLIB_MENUBARS_LUCID 55 #ifdef LWLIB_MENUBARS_LUCID
299 } 314 }
300 } 315 }
301 316
302 #endif /* LWLIB_SCROLLBARS_LUCID */ 317 #endif /* LWLIB_SCROLLBARS_LUCID */
303 318
319 #ifdef LWLIB_TABS_LUCID
320 /* tab control
321
322 lwlib is such an incredible hairy crock. I just cannot believe
323 it! There are random dependencies between functions, there is a
324 total lack of genericity, even though it initially appears to be
325 generic. It should all be junked and begun again. Building tabs are
326 an example - in theory we should be able to reuse a lot of the
327 general stuff because we want to put labels of whatever toolkit we
328 are using in the tab. Instead we have to hack it by hand. */
329 static void
330 xlw_tab_control_callback (Widget w, XtPointer client_data, XtPointer call_data)
331 {
332 /* call data is the topmost widget */
333 widget_instance* instance = (widget_instance*)client_data;
334 Widget top = (Widget)call_data;
335 char *name = XtName (top);
336 widget_value* widget_val;
337 XtPointer widget_arg;
338 LWLIB_ID id;
339 lw_callback post_activate_cb;
340
341 if (w->core.being_destroyed)
342 return;
343
344 /* Grab these values before running any functions, in case running
345 the selection_cb causes the widget to be destroyed. */
346 id = instance->info->id;
347 post_activate_cb = instance->info->post_activate_cb;
348
349 /* search for the widget_val for the selected tab */
350 for (widget_val = instance->info->val->contents; widget_val;
351 widget_val = widget_val->next)
352 {
353 if (!strcmp (widget_val->name, name))
354 break;
355 }
356
357 widget_arg = widget_val ? widget_val->call_data : NULL;
358
359 if (instance->info->selection_cb &&
360 widget_val &&
361 widget_val->enabled &&
362 !widget_val->contents)
363 instance->info->selection_cb (w, id, widget_arg);
364
365 if (post_activate_cb)
366 post_activate_cb (w, id, widget_arg);
367 }
368
369 static Widget
370 xlw_create_tab_control (widget_instance *instance)
371 {
372 Arg al[20];
373 int ac = 0;
374 Widget tab = 0;
375 widget_value* val = instance->info->val;
376
377 XtSetArg (al [ac], XtNsensitive, val->enabled); ac++;
378 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
379 XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++;
380 XtSetArg (al [ac], XtNresizable, False); ac++;
381
382 /* add any args the user supplied for creation time */
383 lw_add_value_args_to_args (val, al, &ac);
384
385 tab = XtCreateManagedWidget (val->name, tabsWidgetClass,
386 instance->parent, al, ac);
387 XtRemoveAllCallbacks (tab, XtNcallback);
388 XtAddCallback (tab, XtNcallback, xlw_tab_control_callback, (XtPointer)instance);
389
390 XtManageChild (tab);
391
392 return tab;
393 }
394
395 static void build_tabs_in_widget (widget_instance* instance, Widget widget,
396 widget_value* val)
397 {
398 widget_value* cur = val;
399 for (cur = val; cur; cur = cur->next)
400 {
401 if (cur->value)
402 {
403 #ifdef LWLIB_WIDGETS_MOTIF
404 xm_create_label (widget, cur);
405 #else
406 xaw_create_label (widget, cur);
407 #endif
408 }
409 cur->change = NO_CHANGE;
410 }
411 }
412
413 static void
414 xlw_update_tab_control (widget_instance* instance, Widget widget, widget_value* val)
415 {
416 Widget* children;
417 unsigned int num_children;
418 int i;
419 widget_value *cur = 0;
420
421 XtRemoveAllCallbacks (widget, XtNcallback);
422 XtAddCallback (widget, XtNcallback, xlw_tab_control_callback, (XtPointer)instance);
423
424 if (val->change == STRUCTURAL_CHANGE
425 ||
426 (val->contents && val->contents->change == STRUCTURAL_CHANGE))
427 {
428 destroy_all_children (widget);
429 build_tabs_in_widget (instance, widget, val->contents);
430 }
431
432 children = XtCompositeChildren (widget, &num_children);
433 if (children)
434 {
435 for (i = 0, cur = val->contents; i < num_children; i++)
436 {
437 if (!cur)
438 abort ();
439 if (children [i]->core.being_destroyed
440 || strcmp (XtName (children [i]), cur->name))
441 continue;
442 #ifdef NEED_MOTIF
443 if (lw_motif_widget_p (children [i]))
444 xm_update_one_widget (instance, children [i], cur, False);
445 #endif
446 #ifdef NEED_ATHENA
447 if (lw_xaw_widget_p (children [i]))
448 xaw_update_one_widget (instance, children [i], cur, False);
449 #endif
450 cur = cur->next;
451 }
452 XtFree ((char *) children);
453 }
454 if (cur)
455 abort ();
456 }
457 #endif /* LWLIB_TABS_LUCID */
458
459 #ifdef HAVE_WIDGETS
460 static Widget
461 xlw_create_clip_window (widget_instance *instance)
462 {
463 Arg al[20];
464 int ac = 0;
465 Widget clip = 0;
466 widget_value* val = instance->info->val;
467
468 XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++;
469 XtSetArg (al [ac], XtNsensitive, TRUE); ac++;
470 /* add any args the user supplied for creation time */
471 lw_add_value_args_to_args (val, al, &ac);
472
473 /* Create a clip window to contain the subwidget. Incredibly the
474 XEmacs manager seems to be the most appropriate widget for
475 this. Nothing else is simple enough and yet does what is
476 required. */
477 clip = XtCreateManagedWidget (val->name,
478 emacsManagerWidgetClass,
479 instance->parent, al, ac);
480
481 return clip;
482 }
483 #endif
484
304 widget_creation_entry 485 widget_creation_entry
305 xlw_creation_table [] = 486 xlw_creation_table [] =
306 { 487 {
307 #ifdef LWLIB_MENUBARS_LUCID 488 #ifdef LWLIB_MENUBARS_LUCID
308 {"menubar", xlw_create_menubar}, 489 {"menubar", xlw_create_menubar},
309 {"popup", xlw_create_popup_menu}, 490 {"popup", xlw_create_popup_menu},
310 #endif 491 #endif
311 #ifdef LWLIB_SCROLLBARS_LUCID 492 #ifdef LWLIB_SCROLLBARS_LUCID
312 {"vertical-scrollbar", xlw_create_vertical_scrollbar}, 493 {"vertical-scrollbar", xlw_create_vertical_scrollbar},
313 {"horizontal-scrollbar", xlw_create_horizontal_scrollbar}, 494 {"horizontal-scrollbar", xlw_create_horizontal_scrollbar},
495 #endif
496 #ifdef LWLIB_TABS_LUCID
497 {"tab-control", xlw_create_tab_control},
498 #endif
499 #ifdef HAVE_WIDGETS
500 {"clip-window", xlw_create_clip_window},
314 #endif 501 #endif
315 {NULL, NULL} 502 {NULL, NULL}
316 }; 503 };
317 504
318 Boolean 505 Boolean
323 if (the_class == xlwMenuWidgetClass) 510 if (the_class == xlwMenuWidgetClass)
324 return True; 511 return True;
325 #endif 512 #endif
326 #ifdef LWLIB_SCROLLBARS_LUCID 513 #ifdef LWLIB_SCROLLBARS_LUCID
327 if (the_class == xlwScrollBarWidgetClass) 514 if (the_class == xlwScrollBarWidgetClass)
515 return True;
516 #endif
517 #ifdef LWLIB_TABS_LUCID
518 if (the_class == tabsWidgetClass)
328 return True; 519 return True;
329 #endif 520 #endif
330 #ifdef LWLIB_MENUBARS_LUCID 521 #ifdef LWLIB_MENUBARS_LUCID
331 if (the_class == overrideShellWidgetClass) 522 if (the_class == overrideShellWidgetClass)
332 return 523 return
338 529
339 void 530 void
340 xlw_update_one_widget (widget_instance* instance, Widget widget, 531 xlw_update_one_widget (widget_instance* instance, Widget widget,
341 widget_value* val, Boolean deep_p) 532 widget_value* val, Boolean deep_p)
342 { 533 {
343 WidgetClass class; 534 WidgetClass class = XtClass (widget);
344
345 class = XtClass (widget);
346 535
347 if (0) 536 if (0)
348 ; 537 ;
349 #ifdef LWLIB_MENUBARS_LUCID 538 #ifdef LWLIB_MENUBARS_LUCID
350 else if (class == xlwMenuWidgetClass) 539 else if (class == xlwMenuWidgetClass)
363 else if (class == xlwScrollBarWidgetClass) 552 else if (class == xlwScrollBarWidgetClass)
364 { 553 {
365 xlw_update_scrollbar (instance, widget, val); 554 xlw_update_scrollbar (instance, widget, val);
366 } 555 }
367 #endif 556 #endif
557 #ifdef LWLIB_TABS_LUCID
558 else if (class == tabsWidgetClass)
559 {
560 xlw_update_tab_control (instance, widget, val);
561 }
562 #endif
368 } 563 }
369 564
370 void 565 void
371 xlw_update_one_value (widget_instance* instance, Widget widget, 566 xlw_update_one_value (widget_instance* instance, Widget widget,
372 widget_value* val) 567 widget_value* val)