comparison lwlib/lwlib-Xlw.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 5a2589c672dc
children 11054d720c21
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
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 () */
24 #include <limits.h> 23 #include <limits.h>
25 24
26 #include "lwlib-Xlw.h" 25 #include "lwlib-Xlw.h"
27 #include "lwlib-utils.h"
28 #include <X11/StringDefs.h> 26 #include <X11/StringDefs.h>
29 #include <X11/IntrinsicP.h> 27 #include <X11/IntrinsicP.h>
30 #include <X11/ObjectP.h> 28 #include <X11/ObjectP.h>
31 #include <X11/CompositeP.h> 29 #include <X11/CompositeP.h>
32 #include <X11/Shell.h> 30 #include <X11/Shell.h>
33 #ifdef HAVE_WIDGETS
34 #include "../src/EmacsManager.h"
35 #endif
36 #ifdef LWLIB_MENUBARS_LUCID 31 #ifdef LWLIB_MENUBARS_LUCID
37 #include "xlwmenu.h" 32 #include "xlwmenu.h"
38 #endif 33 #endif
39 #ifdef LWLIB_SCROLLBARS_LUCID 34 #ifdef LWLIB_SCROLLBARS_LUCID
40 #include "xlwscrollbar.h" 35 #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"
51 #endif 36 #endif
52 37
53 38
54 39
55 #ifdef LWLIB_MENUBARS_LUCID 40 #ifdef LWLIB_MENUBARS_LUCID
314 } 299 }
315 } 300 }
316 301
317 #endif /* LWLIB_SCROLLBARS_LUCID */ 302 #endif /* LWLIB_SCROLLBARS_LUCID */
318 303
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
485 widget_creation_entry 304 widget_creation_entry
486 xlw_creation_table [] = 305 xlw_creation_table [] =
487 { 306 {
488 #ifdef LWLIB_MENUBARS_LUCID 307 #ifdef LWLIB_MENUBARS_LUCID
489 {"menubar", xlw_create_menubar}, 308 {"menubar", xlw_create_menubar},
491 #endif 310 #endif
492 #ifdef LWLIB_SCROLLBARS_LUCID 311 #ifdef LWLIB_SCROLLBARS_LUCID
493 {"vertical-scrollbar", xlw_create_vertical_scrollbar}, 312 {"vertical-scrollbar", xlw_create_vertical_scrollbar},
494 {"horizontal-scrollbar", xlw_create_horizontal_scrollbar}, 313 {"horizontal-scrollbar", xlw_create_horizontal_scrollbar},
495 #endif 314 #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},
501 #endif
502 {NULL, NULL} 315 {NULL, NULL}
503 }; 316 };
504 317
505 Boolean 318 Boolean
506 lw_lucid_widget_p (Widget widget) 319 lw_lucid_widget_p (Widget widget)
510 if (the_class == xlwMenuWidgetClass) 323 if (the_class == xlwMenuWidgetClass)
511 return True; 324 return True;
512 #endif 325 #endif
513 #ifdef LWLIB_SCROLLBARS_LUCID 326 #ifdef LWLIB_SCROLLBARS_LUCID
514 if (the_class == xlwScrollBarWidgetClass) 327 if (the_class == xlwScrollBarWidgetClass)
515 return True;
516 #endif
517 #ifdef LWLIB_TABS_LUCID
518 if (the_class == tabsWidgetClass)
519 return True; 328 return True;
520 #endif 329 #endif
521 #ifdef LWLIB_MENUBARS_LUCID 330 #ifdef LWLIB_MENUBARS_LUCID
522 if (the_class == overrideShellWidgetClass) 331 if (the_class == overrideShellWidgetClass)
523 return 332 return
524 XtClass (((CompositeWidget)widget)->composite.children [0]) 333 XtClass (((CompositeWidget)widget)->composite.children [0])
525 == xlwMenuWidgetClass; 334 == xlwMenuWidgetClass;
526 #endif 335 #endif
527 #ifdef HAVE_WIDGETS
528 if (the_class == emacsManagerWidgetClass)
529 return True;
530 #endif
531 return False; 336 return False;
532 } 337 }
533 338
534 void 339 void
535 xlw_update_one_widget (widget_instance* instance, Widget widget, 340 xlw_update_one_widget (widget_instance* instance, Widget widget,
536 widget_value* val, Boolean deep_p) 341 widget_value* val, Boolean deep_p)
537 { 342 {
538 WidgetClass class = XtClass (widget); 343 WidgetClass class;
344
345 class = XtClass (widget);
539 346
540 if (0) 347 if (0)
541 ; 348 ;
542 #ifdef LWLIB_MENUBARS_LUCID 349 #ifdef LWLIB_MENUBARS_LUCID
543 else if (class == xlwMenuWidgetClass) 350 else if (class == xlwMenuWidgetClass)
556 else if (class == xlwScrollBarWidgetClass) 363 else if (class == xlwScrollBarWidgetClass)
557 { 364 {
558 xlw_update_scrollbar (instance, widget, val); 365 xlw_update_scrollbar (instance, widget, val);
559 } 366 }
560 #endif 367 #endif
561 #ifdef LWLIB_TABS_LUCID
562 else if (class == tabsWidgetClass)
563 {
564 xlw_update_tab_control (instance, widget, val);
565 }
566 #endif
567 /* Lastly update our global arg values. */
568 if (val->args && val->args->nargs)
569 XtSetValues (widget, val->args->args, val->args->nargs);
570 } 368 }
571 369
572 void 370 void
573 xlw_update_one_value (widget_instance* instance, Widget widget, 371 xlw_update_one_value (widget_instance* instance, Widget widget,
574 widget_value* val) 372 widget_value* val)