home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / ToolBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  43.9 KB  |  1,646 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/ToolBar.c>                                            */
  21. /* Description:    XfeToolBar widget source.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <stdio.h>
  28.  
  29. #include <Xfe/ToolBarP.h>
  30.  
  31. /* Possible children classes */
  32. #include <Xfe/Label.h>
  33. #include <Xfe/Button.h>
  34. #include <Xfe/Cascade.h>
  35.  
  36. #include <Xm/Separator.h>
  37. #include <Xm/SeparatoG.h>
  38.  
  39. #define MESSAGE1 "Widget is not an XfeToolBar."
  40. #define MESSAGE2 "XfeToolbar can only have XfeButton & XmSeparator children."
  41. #define MESSAGE3 "XmNmaxChildHeight is a read-only resource."
  42. #define MESSAGE4 "XmNmaxChildWidth is a read-only resource."
  43.  
  44. #define DEFAULT_MAX_CHILD_HEIGHT    0
  45. #define DEFAULT_MAX_CHILD_WIDTH        0
  46.  
  47. /*----------------------------------------------------------------------*/
  48. /*                                                                        */
  49. /* Core class methods                                                    */
  50. /*                                                                        */
  51. /*----------------------------------------------------------------------*/
  52. static void     Initialize        (Widget,Widget,ArgList,Cardinal *);
  53. static void     Destroy            (Widget);
  54. static Boolean    SetValues        (Widget,Widget,Widget,ArgList,Cardinal *);
  55.  
  56. /*----------------------------------------------------------------------*/
  57. /*                                                                        */
  58. /* Composite Class Methods                                                */
  59. /*                                                                        */
  60. /*----------------------------------------------------------------------*/
  61. static XtGeometryResult GeometryManager    (Widget,XtWidgetGeometry *,
  62.                                          XtWidgetGeometry *);
  63.  
  64. /*----------------------------------------------------------------------*/
  65. /*                                                                        */
  66. /* XfeManager class methods                                                */
  67. /*                                                                        */
  68. /*----------------------------------------------------------------------*/
  69. static void        PreferredGeometry    (Widget,Dimension *,Dimension *);
  70. static void        DrawComponents        (Widget,XEvent *,Region,XRectangle *);
  71. static void        LayoutChildren        (Widget);
  72. static Boolean    AcceptChild            (Widget);
  73. static Boolean    InsertChild            (Widget);
  74. static void        ChangeManaged        (Widget);
  75. static void        PrepareComponents    (Widget,int);
  76.  
  77. /*----------------------------------------------------------------------*/
  78. /*                                                                        */
  79. /* XfeCascade action procedures                                            */
  80. /*                                                                        */
  81. /*----------------------------------------------------------------------*/
  82. static void     Btn3Down            (Widget,XEvent *,char **,Cardinal *);
  83. static void     Btn3Up                (Widget,XEvent *,char **,Cardinal *);
  84.  
  85. /*----------------------------------------------------------------------*/
  86. /*                                                                        */
  87. /* Misc XfeToolBar functions                                            */
  88. /*                                                                        */
  89. /*----------------------------------------------------------------------*/
  90. static void            PreferredVertical        (Widget,Dimension *,Dimension *);
  91. static void            PreferredHorizontal        (Widget,Dimension *,Dimension *);
  92. static void            LayoutVertical            (Widget);
  93. static void            LayoutHorizontal        (Widget);
  94. static Boolean        IsValidChild            (Widget);
  95. static Boolean        IsButtonChild            (Widget);
  96. static Boolean        IsSeparatorChild        (Widget);
  97. static Boolean        IsLayableChild            (Widget);
  98. static void            InvokeCallbacks            (Widget,XtCallbackList,Widget,
  99.                                              int,XEvent *);
  100.  
  101. /*----------------------------------------------------------------------*/
  102. /*                                                                        */
  103. /* XfeToolBar children apply client procedures                            */
  104. /*                                                                        */
  105. /*----------------------------------------------------------------------*/
  106. static void        ApplyButtonLayout        (Widget,Widget,XtPointer);
  107. static void        ApplyChildUsePrefWidth    (Widget,Widget,XtPointer);
  108. static void        ApplyChildUsePrefHeight    (Widget,Widget,XtPointer);
  109. static void        ApplySelectionModifiers    (Widget,Widget,XtPointer);
  110. static void        ApplyActiveEnabled        (Widget,Widget,XtPointer);
  111. static void        ApplySelectedEnabled    (Widget,Widget,XtPointer);
  112.  
  113. /*----------------------------------------------------------------------*/
  114. /*                                                                        */
  115. /* Button functions                                                        */
  116. /*                                                                        */
  117. /*----------------------------------------------------------------------*/
  118. static void        ButtonSetActiveEnabled        (Widget,Widget,Boolean);
  119. static void        ButtonSetSelectedEnabled    (Widget,Widget,Boolean);
  120. static void        ButtonSetActiveWidget        (Widget,Widget,Boolean,XEvent *);
  121. static void        ButtonSetSelectedWidget        (Widget,Widget,Boolean,XEvent *);
  122.  
  123. /*----------------------------------------------------------------------*/
  124. /*                                                                        */
  125. /* Button callbacks                                                        */
  126. /*                                                                        */
  127. /*----------------------------------------------------------------------*/
  128. static void        ButtonActiveCB        (Widget,XtPointer,XtPointer);
  129. static void        ButtonSelectedCB    (Widget,XtPointer,XtPointer);
  130.  
  131. /*----------------------------------------------------------------------*/
  132. /*                                                                        */
  133. /* XfeToolBar Resources                                                 */
  134. /*                                                                        */
  135. /*----------------------------------------------------------------------*/
  136. static XtResource resources[] =     
  137. {                    
  138.     /* Callback resources */         
  139.     { 
  140.         XmNbutton3DownCallback,
  141.         XmCCallback,
  142.         XmRCallback,
  143.         sizeof(XtCallbackList),
  144.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . button_3_down_callback),
  145.         XmRImmediate, 
  146.         (XtPointer) NULL
  147.     },
  148.     { 
  149.         XmNbutton3UpCallback,
  150.         XmCCallback,
  151.         XmRCallback,
  152.         sizeof(XtCallbackList),
  153.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . button_3_up_callback),
  154.         XmRImmediate, 
  155.         (XtPointer) NULL
  156.     },
  157.     { 
  158.         XmNselectionChangedCallback,
  159.         XmCCallback,
  160.         XmRCallback,
  161.         sizeof(XtCallbackList),
  162.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . selection_changed_callback),
  163.         XmRImmediate, 
  164.         (XtPointer) NULL
  165.     },
  166.     { 
  167.         XmNvalueChangedCallback,
  168.         XmCCallback,
  169.         XmRCallback,
  170.         sizeof(XtCallbackList),
  171.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . value_changed_callback),
  172.         XmRImmediate, 
  173.         (XtPointer) NULL
  174.     },
  175.  
  176.     /* Button resources */
  177.     { 
  178.         XmNbuttonLayout,
  179.         XmCButtonLayout,
  180.         XmRButtonLayout,
  181.         sizeof(unsigned char),
  182.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . button_layout),
  183.         XmRImmediate, 
  184.         (XtPointer) XmBUTTON_LABEL_ONLY
  185.     },
  186.  
  187.     /* Separator resources */
  188.     { 
  189.         XmNseparatorThickness,
  190.         XmCSeparatorThickness,
  191.         XmRInt,
  192.         sizeof(int),
  193.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . separator_thickness),
  194.         XmRImmediate, 
  195.         (XtPointer) 50
  196.     },
  197.  
  198.     /* Raised resources */
  199.     { 
  200.         XmNraised,
  201.         XmCRaised,
  202.         XmRBoolean,
  203.         sizeof(Boolean),
  204.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . raised),
  205.         XmRImmediate, 
  206.         (XtPointer) False
  207.     },
  208.     { 
  209.         XmNraiseBorderThickness,
  210.         XmCRaiseBorderThickness,
  211.         XmRHorizontalDimension,
  212.         sizeof(Dimension),
  213.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . raise_border_thickness),
  214.         XmRImmediate, 
  215.         (XtPointer) 0
  216.     },
  217.     {
  218.         XmNchildUsePreferredHeight,
  219.         XmCChildUsePreferredHeight,
  220.         XmRBoolean,
  221.         sizeof(Boolean),
  222.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . child_use_pref_height),
  223.         XmRImmediate, 
  224.         (XtPointer) False
  225.     },
  226.     {
  227.         XmNchildUsePreferredWidth,
  228.         XmCChildUsePreferredWidth,
  229.         XmRBoolean,
  230.         sizeof(Boolean),
  231.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . child_use_pref_width),
  232.         XmRImmediate, 
  233.         (XtPointer) False
  234.     },
  235.     { 
  236.         XmNchildForceHeight,
  237.         XmCChildForceHeight,
  238.         XmRBoolean,
  239.         sizeof(Boolean),
  240.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . child_force_height),
  241.         XmRImmediate, 
  242.         (XtPointer) True
  243.     },
  244.     { 
  245.         XmNchildForceWidth,
  246.         XmCChildForceWidth,
  247.         XmRBoolean,
  248.         sizeof(Boolean),
  249.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . child_force_width),
  250.         XmRImmediate, 
  251.         (XtPointer) True
  252.     },
  253.  
  254.     /* Radio resources */
  255.     { 
  256.         XmNradioBehavior,
  257.         XmCRadioBehavior,
  258.         XmRBoolean,
  259.         sizeof(Boolean),
  260.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . radio_behavior),
  261.         XmRImmediate, 
  262.         (XtPointer) False
  263.     },
  264.     { 
  265.         XmNactiveButton,
  266.         XmCActiveButton,
  267.         XmRWidget,
  268.         sizeof(Widget),
  269.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . active_button),
  270.         XmRImmediate, 
  271.         (XtPointer) NULL
  272.     },
  273.  
  274.     /* Selection resources */
  275.     { 
  276.         XmNselectedButton,
  277.         XmCSelectedButton,
  278.         XmRWidget,
  279.         sizeof(Widget),
  280.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . selected_button),
  281.         XmRImmediate, 
  282.         (XtPointer) NULL
  283.     },
  284.     { 
  285.         XmNselectionModifiers,
  286.         XmCSelectionModifiers,
  287.         XmRModifiers,
  288.         sizeof(Modifiers),
  289.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . selection_modifiers),
  290.         XmRImmediate, 
  291.         (XtPointer) None
  292.     },
  293.     { 
  294.         XmNselectionPolicy,
  295.         XmCSelectionPolicy,
  296.         XmRToolBarSelectionPolicy,
  297.         sizeof(unsigned char),
  298.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . selection_policy),
  299.         XmRImmediate, 
  300.         (XtPointer) XmTOOL_BAR_SELECT_NONE
  301.     },
  302.  
  303.     /* Wrapping resources */
  304.     { 
  305.         XmNallowWrap,
  306.         XmCBoolean,
  307.         XmRBoolean,
  308.         sizeof(Boolean),
  309.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . allow_wrap),
  310.         XmRImmediate, 
  311.         (XtPointer) False
  312.     },
  313.     { 
  314.         XmNmaxNumColumns,
  315.         XmCMaxNumColumns,
  316.         XmRCardinal,
  317.         sizeof(Cardinal),
  318.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . max_num_columns),
  319.         XmRImmediate, 
  320.         (XtPointer) 10
  321.     },
  322.     { 
  323.         XmNmaxNumRows,
  324.         XmCMaxNumRows,
  325.         XmRCardinal,
  326.         sizeof(Cardinal),
  327.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . max_num_rows),
  328.         XmRImmediate, 
  329.         (XtPointer) 10
  330.     },
  331.  
  332.     { 
  333.         XmNmaxChildHeight,
  334.         XmCReadOnly,
  335.         XmRVerticalDimension,
  336.         sizeof(Dimension),
  337.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . max_child_height),
  338.         XmRImmediate, 
  339.         (XtPointer) DEFAULT_MAX_CHILD_HEIGHT
  340.     },
  341.     { 
  342.         XmNmaxChildWidth,
  343.         XmCReadOnly,
  344.         XmRVerticalDimension,
  345.         sizeof(Dimension),
  346.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . max_child_width),
  347.         XmRImmediate, 
  348.         (XtPointer) DEFAULT_MAX_CHILD_WIDTH
  349.     },
  350.  
  351. };   
  352.  
  353. /*----------------------------------------------------------------------*/
  354. /*                                                                        */
  355. /* XfeToolBar Synthetic Resources                                        */
  356. /*                                                                        */
  357. /*----------------------------------------------------------------------*/
  358. static XmSyntheticResource syn_resources[] =
  359. {
  360.     { 
  361.         XmNraiseBorderThickness,
  362.         sizeof(Dimension),
  363.         XtOffsetOf(XfeToolBarRec , xfe_tool_bar . raise_border_thickness),
  364.         _XmFromHorizontalPixels,
  365.         _XmToHorizontalPixels 
  366.     },
  367. };
  368.  
  369.  
  370. /*----------------------------------------------------------------------*/
  371. /*                                                                        */
  372. /* XfeToolBar actions                                                    */
  373. /*                                                                        */
  374. /*----------------------------------------------------------------------*/
  375. static XtActionsRec actions[] = 
  376. {
  377.     { "Btn3Down",    Btn3Down        },
  378.     { "Btn3Up",        Btn3Up            },
  379. };
  380.  
  381.  
  382. /*----------------------------------------------------------------------*/
  383. /*                                                                        */
  384. /* Widget Class Record Initialization                                   */
  385. /*                                                                        */
  386. /*----------------------------------------------------------------------*/
  387. _XFE_WIDGET_CLASS_RECORD(toolbar,ToolBar) =
  388. {
  389.     {
  390.         (WidgetClass) &xfeOrientedClassRec,        /* superclass            */
  391.         "XfeToolBar",                            /* class_name            */
  392.         sizeof(XfeToolBarRec),                    /* widget_size            */
  393.         NULL,                                    /* class_initialize        */
  394.         NULL,                                    /* class_part_initialize*/
  395.         FALSE,                                    /* class_inited            */
  396.         Initialize,                                /* initialize            */
  397.         NULL,                                    /* initialize_hook        */
  398.         XtInheritRealize,                        /* realize                */
  399.         actions,                                /* actions                */
  400.         XtNumber(actions),                        /* num_actions            */
  401.         resources,                              /* resources            */
  402.         XtNumber(resources),                    /* num_resources        */
  403.         NULLQUARK,                              /* xrm_class            */
  404.         TRUE,                                   /* compress_motion        */
  405.         XtExposeCompressMaximal,                /* compress_exposure    */
  406.         TRUE,                                   /* compress_enterleave    */
  407.         FALSE,                                  /* visible_interest        */
  408.         Destroy,                                /* destroy                */
  409.         XtInheritResize,                        /* resize                */
  410.         XtInheritExpose,                        /* expose                */
  411.         SetValues,                              /* set_values            */
  412.         NULL,                                   /* set_values_hook        */
  413.         XtInheritSetValuesAlmost,                /* set_values_almost    */
  414.         NULL,                                    /* get_values_hook        */
  415.         NULL,                                   /* access_focus            */
  416.         XtVersion,                              /* version                */
  417.         NULL,                                   /* callback_private        */
  418.         XtInheritTranslations,                    /* tm_table                */
  419.         XtInheritQueryGeometry,                    /* query_geometry        */
  420.         XtInheritDisplayAccelerator,            /* display accelerator    */
  421.         NULL,                                   /* extension            */
  422.     },
  423.     
  424.     /* Composite Part */
  425.     {
  426. /* When XfeManager bugs in GeometryManager() are fixed, I can use it to! */
  427. #if 0
  428.         XtInheritGeometryManager,                /* geometry_manager        */
  429. #else
  430.         GeometryManager,                        /* geometry_manager        */
  431. #endif
  432.         XtInheritChangeManaged,                    /* change_managed        */
  433.         XtInheritInsertChild,                    /* insert_child            */
  434.         XtInheritDeleteChild,                    /* delete_child            */
  435.         NULL                                    /* extension            */
  436.     },
  437.  
  438.     /* Constraint Part */
  439.     {
  440.         NULL,                                    /* resource list        */
  441.         0,                                        /* num resources        */
  442.         sizeof(XfeToolBarConstraintRec),        /* constraint size        */
  443.         NULL,                                    /* init proc            */
  444.         NULL,                                   /* destroy proc            */
  445.         NULL,                                    /* set values proc        */
  446.         NULL,                                   /* extension            */
  447.     },
  448.  
  449.     /* XmManager Part */
  450.     {
  451.         XtInheritTranslations,                    /* tm_table                */
  452.         syn_resources,                            /* syn resources        */
  453.         XtNumber(syn_resources),                /* num syn_resources    */
  454.         NULL,                                   /* syn_cont_resources    */
  455.         0,                                      /* num_syn_cont_resource*/
  456.         XmInheritParentProcess,                 /* parent_process        */
  457.         NULL,                                   /* extension            */
  458.     },
  459.     
  460.     /* XfeManager Part     */
  461.     {
  462.         XfeInheritBitGravity,                    /* bit_gravity            */
  463.         PreferredGeometry,                        /* preferred_geometry    */
  464.         XfeInheritMinimumGeometry,                /* minimum_geometry        */
  465.         XfeInheritUpdateRect,                    /* update_rect            */
  466.         AcceptChild,                            /* accept_child            */
  467.         InsertChild,                            /* insert_child            */
  468.         XfeInheritDeleteChild,                    /* delete_child            */
  469.         ChangeManaged,                            /* change_managed        */
  470.         PrepareComponents,                        /* prepare_components    */
  471.         NULL,                                    /* layout_components    */
  472.         LayoutChildren,                            /* layout_children        */
  473.         NULL,                                    /* draw_background        */
  474.         XfeInheritDrawShadow,                    /* draw_shadow            */
  475.         DrawComponents,                            /* draw_components        */
  476.         NULL,                                    /* extension            */
  477.     },
  478.  
  479.     /* XfeOriented Part */
  480.     {
  481.         NULL,                                    /* enter                */
  482.         NULL,                                    /* leave                */
  483.         NULL,                                    /* motion                */
  484.         NULL,                                    /* drag_start            */
  485.         NULL,                                    /* drag_end                */
  486.         NULL,                                    /* drag_motion            */
  487.         NULL,                                    /* des_enter            */
  488.         NULL,                                    /* des_leave            */
  489.         NULL,                                    /* des_motion            */
  490.         NULL,                                    /* des_drag_start        */
  491.         NULL,                                    /* des_drag_end            */
  492.         NULL,                                    /* des_drag_motion        */
  493.         NULL,                                    /* extension              */
  494.     },
  495.  
  496.  
  497.     /* XfeToolBar Part */
  498.     {
  499.         NULL,                                    /* extension            */
  500.     },
  501. };
  502.  
  503. /*----------------------------------------------------------------------*/
  504. /*                                                                        */
  505. /* xfeToolBarWidgetClass declaration.                                    */
  506. /*                                                                        */
  507. /*----------------------------------------------------------------------*/
  508. _XFE_WIDGET_CLASS(toolbar,ToolBar);
  509.  
  510. /*----------------------------------------------------------------------*/
  511. /*                                                                        */
  512. /* Core Class methods                                                    */
  513. /*                                                                        */
  514. /*----------------------------------------------------------------------*/
  515. static void
  516. Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  517. {
  518.     XfeToolBarPart *        tp = _XfeToolBarPart(nw);
  519.  
  520.     /* max_child_height */
  521.     if (tp->max_child_height > DEFAULT_MAX_CHILD_HEIGHT)
  522.     {
  523.         tp->max_child_height = DEFAULT_MAX_CHILD_HEIGHT;
  524.       
  525.         _XfeWarning(nw,MESSAGE3);
  526.     }
  527.  
  528.     /* max_child_width */
  529.     if (tp->max_child_width > DEFAULT_MAX_CHILD_WIDTH)
  530.     {
  531.         tp->max_child_width = DEFAULT_MAX_CHILD_WIDTH;
  532.       
  533.         _XfeWarning(nw,MESSAGE4);
  534.     }
  535.  
  536.     /* Add Button3 translations */
  537.     XfeOverrideTranslations(nw,_XfeToolBarExtraTranslations);
  538.  
  539.     /* Initialize private members */
  540.     tp->num_managed                = 0;
  541.     tp->num_components            = 0;
  542.     tp->total_children_width    = 0;
  543.     tp->total_children_height    = 0;
  544.  
  545.     /* Finish of initialization */
  546.     _XfeManagerChainInitialize(rw,nw,xfeToolBarWidgetClass);
  547. }
  548. /*----------------------------------------------------------------------*/
  549. static void
  550. Destroy(Widget w)
  551. {
  552. }
  553. /*----------------------------------------------------------------------*/
  554. static Boolean
  555. SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  556. {
  557.     XfeToolBarPart *        np = _XfeToolBarPart(nw);
  558.     XfeToolBarPart *        op = _XfeToolBarPart(ow);
  559.  
  560.     /* max_child_height */
  561.     if (np->max_child_height != op->max_child_height)
  562.     {
  563.         np->max_child_height = op->max_child_height;
  564.       
  565.         _XfeWarning(nw,MESSAGE3);
  566.     }
  567.  
  568.     /* max_child_width */
  569.     if (np->max_child_width != op->max_child_width)
  570.     {
  571.         np->max_child_width = op->max_child_width;
  572.       
  573.         _XfeWarning(nw,MESSAGE4);
  574.     }
  575.     
  576.     /* button_layout */
  577.     if (np->button_layout != op->button_layout)
  578.     {
  579.         XfeManagerApply(nw,ApplyButtonLayout,(XtPointer) nw,False);
  580.  
  581.         _XfemConfigFlags(nw) |= XfeConfigGLE;
  582.  
  583.         _XfemPrepareFlags(nw) |= _XFE_PREPARE_MAX_CHILD_DIMENSIONS;
  584.     }
  585.  
  586.     /* child_use_pref_width */
  587.     if (np->child_use_pref_width != op->child_use_pref_width)
  588.     {
  589.         XfeManagerApply(nw,ApplyChildUsePrefWidth,(XtPointer) nw,False);
  590.  
  591.         _XfemConfigFlags(nw) |= XfeConfigGLE;
  592.  
  593.         _XfemPrepareFlags(nw) |= _XFE_PREPARE_MAX_CHILD_DIMENSIONS;
  594.     }
  595.  
  596.     /* child_use_pref_height */
  597.     if (np->child_use_pref_height != op->child_use_pref_height)
  598.     {
  599.         XfeManagerApply(nw,ApplyChildUsePrefHeight,(XtPointer) nw,False);
  600.  
  601.         _XfemConfigFlags(nw) |= XfeConfigGLE;
  602.  
  603.         _XfemPrepareFlags(nw) |= _XFE_PREPARE_MAX_CHILD_DIMENSIONS;
  604.     }
  605.  
  606.     /* separator_thickness */
  607.     if (np->separator_thickness != op->separator_thickness)
  608.     {
  609.         _XfemConfigFlags(nw) |= XfeConfigLED;
  610.     }
  611.  
  612.     /* raise_border_thickness */
  613.     if (np->raise_border_thickness != op->raise_border_thickness)
  614.     {
  615.         _XfemConfigFlags(nw) |= XfeConfigGLED;
  616.     }
  617.  
  618.     /* raised */
  619.     if (np->raised != op->raised)
  620.     {
  621.         _XfemConfigFlags(nw) |= XfeConfigED;
  622.     }
  623.  
  624.     /* active_button */
  625.     if (np->active_button != op->active_button)
  626.     {
  627.         ButtonSetActiveWidget(nw,np->active_button,False,NULL);
  628.     }
  629.  
  630.     /* radio_behavior */
  631.     if (np->radio_behavior != op->radio_behavior)
  632.     {
  633.         if (np->radio_behavior)
  634.         {
  635.             ButtonSetActiveWidget(nw,np->active_button,False,NULL);
  636.         }
  637.         else
  638.         {
  639.             ButtonSetActiveWidget(nw,NULL,False,NULL);
  640.         }
  641.  
  642.         XfeManagerApply(nw,ApplyActiveEnabled,(XtPointer) nw,False);
  643.     }
  644.  
  645.     /* selected_button */
  646.     if (np->selected_button != op->selected_button)
  647.     {
  648.         ButtonSetSelectedWidget(nw,np->selected_button,False,NULL);
  649.     }
  650.  
  651.     /* selection_policy */
  652.     if (np->selection_policy != op->selection_policy)
  653.     {
  654.         if (np->selection_policy == XmTOOL_BAR_SELECT_SINGLE)
  655.         {
  656.             ButtonSetSelectedWidget(nw,np->selected_button,False,NULL);
  657.         }
  658.         else if (np->selection_policy == XmTOOL_BAR_SELECT_NONE)
  659.         {
  660.             ButtonSetSelectedWidget(nw,NULL,False,NULL);
  661.         }
  662.  
  663.         XfeManagerApply(nw,ApplySelectedEnabled,(XtPointer) nw,False);
  664.     }
  665.  
  666.     /* selection_modifiers */
  667.     if (np->selection_modifiers != op->selection_modifiers)
  668.     {
  669.         XfeManagerApply(nw,ApplySelectionModifiers,(XtPointer) nw,False);
  670.     }
  671.  
  672.     return _XfeManagerChainSetValues(ow,rw,nw,xfeToolBarWidgetClass);
  673. }
  674. /*----------------------------------------------------------------------*/
  675.  
  676. /*----------------------------------------------------------------------*/
  677. /*                                                                        */
  678. /* Composite Class Methods                                                */
  679. /*                                                                        */
  680. /*----------------------------------------------------------------------*/
  681. static XtGeometryResult
  682. GeometryManager(Widget child,XtWidgetGeometry *request,XtWidgetGeometry *reply)
  683. {
  684.     Widget                w = XtParent(child);
  685.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  686.     XtGeometryMask        mask = request->request_mode;
  687.     XtGeometryResult    our_result = XtGeometryNo;
  688.  
  689. /*     printf("GeometryManager(%s) - child = %s\n",XtName(w),XtName(child)); */
  690.     
  691.     /* Ignore x changes */
  692.     if (mask & CWX)
  693.     {
  694.         mask |= ~CWX;
  695.  
  696.         /*_XfeWarning(w,MESSAGE11);*/
  697.     }
  698.  
  699.     /* Ignore y changes */
  700.     if (mask & CWY)
  701.     {
  702.         mask |= ~CWY;
  703.         
  704.         /*_XfeWarning(w,MESSAGE12);*/
  705.     }
  706.  
  707.     /* Ignore border_width changes */
  708.     if (mask & CWBorderWidth)
  709.     {
  710.         mask |= ~CWBorderWidth;
  711.  
  712.         /*_XfeWarning(w,MESSAGE13);*/
  713.     }
  714.  
  715.     /* Check for something else being requested */
  716.     if ((mask & CWWidth) || (mask & CWHeight))
  717.     {
  718.         Boolean                change_width = False;
  719.         Boolean                change_height = False;
  720.         Dimension            old_width;
  721.         Dimension            old_height;
  722.         Dimension            old_max_child_width;
  723.         Dimension            old_max_child_height;
  724.         Dimension            pref_width;
  725.         Dimension            pref_height;
  726.  
  727.         /* Remember the child's old dimensions */
  728.         old_width = _XfeWidth(child);
  729.         old_height = _XfeHeight(child);
  730.  
  731.         /* Adjust the child's dimensions _TEMPORARLY_ */
  732.         if (mask & CWWidth)
  733.         {
  734.             _XfeWidth(child) = request->width;
  735.         }
  736.  
  737.         if (mask & CWHeight)
  738.         {
  739.             _XfeHeight(child) = request->height;
  740.         }
  741.  
  742.         /* Remember our max child dimensions */
  743.         old_max_child_width = tp->max_child_width;
  744.         old_max_child_height = tp->max_child_height;
  745.  
  746.         if (_XfeWidth(child) > tp->max_child_width)
  747.         {
  748.             tp->max_child_width = _XfeWidth(child);
  749.         }
  750.  
  751.         if (_XfeHeight(child) > tp->max_child_height)
  752.         {
  753.             tp->max_child_height = _XfeHeight(child);
  754.         }
  755.  
  756.         /* Obtain the preferred geometry to support the new child */
  757.         _XfeManagerPreferredGeometry(w,&pref_width,&pref_height);
  758.  
  759.         /* Restore the child's dimensions */
  760.         _XfeWidth(child) = old_width;
  761.         _XfeHeight(child) = old_height;
  762.             
  763.         /* Restore our max children dimensions */
  764.         tp->max_child_width = old_max_child_width;
  765.         tp->max_child_height = old_max_child_height;
  766.  
  767.         /* Check for changes in preferred width if needed */
  768.         if (_XfemUsePreferredWidth(w) && (_XfeWidth(w) != pref_width))
  769.         {
  770.             change_width = True;
  771.         }
  772.  
  773.         /* Check for changes in preferred height if needed */
  774.         if (_XfemUsePreferredHeight(w) && (_XfeHeight(w) != pref_height))
  775.         {
  776.             change_height = True;
  777.         }
  778.  
  779.         /* Check for geometry changes to ourselves */
  780.         if (change_width || change_height)
  781.         {
  782.             XtGeometryResult    parent_result;
  783.             XtWidgetGeometry    parent_request;
  784.                 
  785.             parent_request.request_mode = 0;
  786.                 
  787.             /* Request a width change */
  788.             if (change_width)
  789.             {
  790.                 parent_request.width = pref_width;
  791.                 parent_request.request_mode |= CWWidth;
  792.             }
  793.                 
  794.             /* Request a width height */
  795.             if (change_height)
  796.             {
  797.                 parent_request.height = pref_height;
  798.                 parent_request.request_mode |= CWHeight;
  799.             }
  800.  
  801.             /* Make the request */
  802.             parent_result = _XmMakeGeometryRequest(w,&parent_request);
  803.  
  804.             /* Adjust geometry accordingly */
  805.             if (parent_result == XtGeometryYes)
  806.             {
  807.                 /* Goody */
  808.                 if (mask & CWWidth)
  809.                 {
  810.                     _XfeWidth(child) = request->width;
  811.  
  812.                     if (_XfeWidth(child) > tp->max_child_width)
  813.                     {
  814.                         tp->max_child_width = _XfeWidth(child);
  815.                     }
  816.  
  817.                     _XfemPreferredWidth(w) = pref_width;
  818.                 }
  819.  
  820.                 if (mask & CWHeight)
  821.                 {
  822.                     _XfeHeight(child) = request->height;
  823.  
  824.                     if (_XfeHeight(child) > tp->max_child_height)
  825.                     {
  826.                         tp->max_child_height = _XfeHeight(child);
  827.                     }
  828.                         
  829.                     _XfemPreferredHeight(w) = pref_height;
  830.                 }
  831.  
  832.                 XfeResize(w);
  833.  
  834.                 our_result = XtGeometryYes;
  835.  
  836.             }
  837.             else if(parent_result == XtGeometryNo)
  838.             {
  839.                 /* Too bad */
  840.             }
  841.         }
  842.     }
  843.  
  844.     return our_result;
  845. }
  846. /*----------------------------------------------------------------------*/
  847.  
  848. /*----------------------------------------------------------------------*/
  849. /*                                                                        */
  850. /* XfeManager class methods                                                */
  851. /*                                                                        */
  852. /*----------------------------------------------------------------------*/
  853. static Boolean
  854. AcceptChild(Widget child)
  855. {
  856.     return IsValidChild(child);
  857. }
  858. /*----------------------------------------------------------------------*/
  859. static Boolean
  860. InsertChild(Widget child)
  861. {
  862.     Widget                    w = XtParent(child);
  863.     XfeToolBarPart *        tp = _XfeToolBarPart(w);
  864.  
  865.  
  866.     /* Configure children that are not private components */
  867.     if (!_XfeManagerPrivateComponent(child))
  868.     {
  869.         /* Buttons */
  870.         if (IsButtonChild(child))
  871.         {
  872.             Arg            xargs[10];
  873.             Cardinal    n = 0;
  874.  
  875.             XtSetArg(xargs[n],XmNbuttonLayout,tp->button_layout); n++;
  876.             XtSetArg(xargs[n],XmNusePreferredWidth,tp->child_use_pref_width); n++;
  877.             XtSetArg(xargs[n],XmNusePreferredHeight,tp->child_use_pref_height); n++;
  878.  
  879.             if (tp->radio_behavior)
  880.             {
  881.                 XtSetArg(xargs[n],XmNbuttonType,XmBUTTON_TOGGLE); n++;
  882.             }
  883.  
  884.             if (tp->selection_policy != XmTOOL_BAR_SELECT_NONE)
  885.             {
  886.                 XtSetArg(xargs[n],XmNselectionModifiers,tp->selection_modifiers); n++;
  887.             }
  888.             
  889.             XtSetValues(child,xargs,n);
  890.  
  891.             if (tp->radio_behavior)
  892.             {
  893.                 ButtonSetActiveEnabled(w,child,True);
  894.             }
  895.  
  896.             if (tp->selection_policy != XmTOOL_BAR_SELECT_NONE)
  897.             {
  898.                 ButtonSetSelectedEnabled(w,child,True);
  899.             }
  900.         }
  901.     }
  902.  
  903.     return True;
  904. }
  905. /*----------------------------------------------------------------------*/
  906. static void
  907. ChangeManaged(Widget w)
  908. {
  909. /*     XfeToolBarPart *    tp = _XfeToolBarPart(w); */
  910.  
  911.     PrepareComponents(w,_XFE_PREPARE_MAX_CHILD_DIMENSIONS);
  912. }
  913. /*----------------------------------------------------------------------*/
  914. static void
  915. PrepareComponents(Widget w,int flags)
  916. {
  917.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  918.  
  919. /*     flags = _XFE_PREPARE_MAX_CHILD_DIMENSIONS; */
  920.  
  921.     if (flags & _XFE_PREPARE_MAX_CHILD_DIMENSIONS)
  922.     {
  923.         _XfeManagerChildrenInfo(w,
  924.                                 &tp->max_child_width,
  925.                                 &tp->max_child_height,
  926.                                 &tp->total_children_width,
  927.                                 &tp->total_children_height,
  928.                                 &tp->num_managed,
  929.                                 &tp->num_components);
  930.     }
  931. }
  932. /*----------------------------------------------------------------------*/
  933. static void
  934. DrawComponents(Widget w,XEvent * event,Region region,XRectangle * clip_rect)
  935. {
  936.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  937.  
  938.     /* Make sure there is a highlight to draw */
  939.     if (!tp->raise_border_thickness || !tp->raised)
  940.     {
  941.         return;
  942.     }
  943.  
  944.     /* The shadow thickness can be used to tweak the raised effect */
  945.     switch(tp->raise_border_thickness)
  946.     {
  947.     case 2:
  948.     case 4:
  949.  
  950.         XfeDrawRectangle(XtDisplay(w),
  951.                          _XfeWindow(w),
  952.                          _XfemHighlightGC(w),
  953.                          0,
  954.                          0,
  955.                          _XfeWidth(w),
  956.                          _XfeHeight(w),
  957.                          tp->raise_border_thickness / 2);
  958.  
  959.         _XmDrawShadows(XtDisplay(w),
  960.                        _XfeWindow(w),
  961.                        _XfemTopShadowGC(w),
  962.                        _XfemBottomShadowGC(w),
  963.                        tp->raise_border_thickness / 2,
  964.                        tp->raise_border_thickness / 2,
  965.                        _XfeWidth(w) - 2 * (tp->raise_border_thickness / 2),
  966.                        _XfeHeight(w) - 2 * (tp->raise_border_thickness / 2),
  967.                        tp->raise_border_thickness / 2,
  968.                        XmSHADOW_OUT);
  969.  
  970.         break;
  971.  
  972.     default:
  973.  
  974.         XfeDrawRectangle(XtDisplay(w),
  975.                          _XfeWindow(w),
  976.                          _XfemHighlightGC(w),
  977.                          0,
  978.                          0,
  979.                          _XfeWidth(w),
  980.                          _XfeHeight(w),
  981.                          tp->raise_border_thickness);
  982.         break;
  983.     }
  984. }
  985. /*----------------------------------------------------------------------*/
  986. static void
  987. PreferredGeometry(Widget w,Dimension * width,Dimension * height)
  988. {
  989.     switch(_XfeOrientedOrientation(w))
  990.     {
  991.     case XmHORIZONTAL:
  992.         PreferredHorizontal(w,width,height);
  993.         break;
  994.  
  995.     case XmVERTICAL:
  996.         PreferredVertical(w,width,height);
  997.         break;
  998.     }
  999. }
  1000. /*----------------------------------------------------------------------*/
  1001. static void
  1002. LayoutChildren(Widget w)
  1003. {
  1004.     switch(_XfeOrientedOrientation(w))
  1005.     {
  1006.     case XmHORIZONTAL:
  1007.         
  1008.         LayoutHorizontal(w);
  1009.         
  1010.         break;
  1011.         
  1012.     case XmVERTICAL:
  1013.         
  1014.         LayoutVertical(w);
  1015.         
  1016.         break;
  1017.     }
  1018. }
  1019. /*----------------------------------------------------------------------*/
  1020.  
  1021. /*----------------------------------------------------------------------*/
  1022. /*                                                                        */
  1023. /* XfeCascade action procedures                                            */
  1024. /*                                                                        */
  1025. /*----------------------------------------------------------------------*/
  1026. static void
  1027. Btn3Down(Widget w,XEvent * event,char ** params,Cardinal * nparams)
  1028. {
  1029.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1030.  
  1031.     printf("Btn3Down(%s)\n",XtName(w));
  1032.  
  1033.     _XfeInvokeCallbacks(w,tp->button_3_down_callback,
  1034.                         XmCR_BUTTON_3_DOWN,event,False);
  1035. }
  1036. /*----------------------------------------------------------------------*/
  1037. static void
  1038. Btn3Up(Widget w,XEvent * event,char ** params,Cardinal * nparams)
  1039. {
  1040.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1041.  
  1042.     printf("Btn3Up(%s)\n",XtName(w));
  1043.  
  1044.     _XfeInvokeCallbacks(w,tp->button_3_up_callback,
  1045.                         XmCR_BUTTON_3_UP,event,False);
  1046. }
  1047. /*----------------------------------------------------------------------*/
  1048.  
  1049. /*----------------------------------------------------------------------*/
  1050. /*                                                                        */
  1051. /* Misc XfeToolBar functions                                            */
  1052. /*                                                                        */
  1053. /*----------------------------------------------------------------------*/
  1054. static void
  1055. PreferredVertical(Widget w,Dimension * width,Dimension * height)
  1056. {
  1057.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1058.     Cardinal            i;
  1059.     
  1060.     *height = 
  1061.         _XfemOffsetTop(w)  + _XfemOffsetBottom(w) +
  1062.         2 * tp->raise_border_thickness;
  1063.  
  1064.     *width  = 
  1065.         _XfemOffsetLeft(w) + _XfemOffsetRight(w) + 
  1066.         2 * tp->raise_border_thickness;
  1067.  
  1068.     for (i = 0; i < _XfemNumChildren(w); i++)
  1069.     {
  1070.         Widget child = _XfemChildren(w)[i];
  1071.         
  1072.         if (IsLayableChild(child))
  1073.         {
  1074.             if (IsButtonChild(child))
  1075.             {
  1076.                 if (tp->child_force_height)
  1077.                 {
  1078.                     *height += tp->max_child_height;
  1079.                 }
  1080.                 else
  1081.                 {
  1082.                     *height += _XfeHeight(child);
  1083.                 }
  1084.  
  1085.                 *height += _XfeOrientedSpacing(w);
  1086.             }
  1087.             else if (IsSeparatorChild(child) && _XfeHeight(child))
  1088.             {
  1089.                 *height += (_XfeHeight(child) + _XfeOrientedSpacing(w));
  1090.             }
  1091.             else
  1092.             {
  1093.                 assert( 0 );
  1094.             }
  1095.         } /* IsLayableChild */
  1096.     } /* for */
  1097.  
  1098.  
  1099.     *width += tp->max_child_width;
  1100. }
  1101. /*----------------------------------------------------------------------*/
  1102. static void
  1103. PreferredHorizontal(Widget w,Dimension * width,Dimension * height)
  1104. {
  1105.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1106.     Cardinal            i;
  1107.     
  1108.     *height = 
  1109.         _XfemOffsetTop(w)  + _XfemOffsetBottom(w) + 
  1110.         2 * tp->raise_border_thickness;
  1111.  
  1112.     *width  = 
  1113.         _XfemOffsetLeft(w) + _XfemOffsetRight(w) + 
  1114.         2 * tp->raise_border_thickness;
  1115.  
  1116.     for (i = 0; i < _XfemNumChildren(w); i++)
  1117.     {
  1118.         Widget child = _XfemChildren(w)[i];
  1119.         
  1120.         if (IsLayableChild(child))
  1121.         {
  1122.             if (IsButtonChild(child))
  1123.             {
  1124.                 if (tp->child_force_width)
  1125.                 {
  1126.                     *width += tp->max_child_width;
  1127.                 }
  1128.                 else
  1129.                 {
  1130.                     *width += _XfeWidth(child);
  1131.                 }
  1132.  
  1133.                 *width += _XfeOrientedSpacing(w);
  1134.             }
  1135.             else if (IsSeparatorChild(child) && _XfeWidth(child))
  1136.             {
  1137.                 *width += (_XfeWidth(child) + _XfeOrientedSpacing(w));
  1138.             }
  1139.             else
  1140.             {
  1141.                 assert( 0 );
  1142.             }
  1143.         } /* IsLayableChild */
  1144.     } /* for */
  1145.  
  1146.  
  1147.     *height += tp->max_child_height;
  1148.  
  1149. }
  1150. /*----------------------------------------------------------------------*/
  1151. static void
  1152. LayoutVertical(Widget w)
  1153. {
  1154.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1155.     Cardinal            i;
  1156.     Position            x;
  1157.     Position            y;
  1158.     Dimension            width;
  1159.     Dimension            height;
  1160.     
  1161.     y = _XfemOffsetTop(w) + tp->raise_border_thickness;
  1162.  
  1163.     for (i = 0; i < _XfemNumChildren(w); i++)
  1164.     {
  1165.         Widget child = _XfemChildren(w)[i];
  1166.  
  1167.         if (IsLayableChild(child))
  1168.         {
  1169.             if (IsButtonChild(child))
  1170.             {
  1171.                 /* The button's width */
  1172.                 width = 
  1173.                     tp->child_force_width ? 
  1174.                     (_XfemRectWidth(w) - 2 * tp->raise_border_thickness) : 
  1175.                     _XfeWidth(child);
  1176.  
  1177.                 /* The button's height */
  1178.                 height = 
  1179.                     tp->child_force_height ? 
  1180.                     tp->max_child_height : 
  1181.                     _XfeHeight(child);
  1182.  
  1183.  
  1184.                 x = (_XfeWidth(w) - width) / 2;
  1185.                 
  1186.                 _XfeConfigureWidget(child,x,y,width,height);
  1187.  
  1188.                 y += (_XfeHeight(child) + _XfeOrientedSpacing(w));
  1189.             }
  1190.             else if (IsSeparatorChild(child))
  1191.             {
  1192.                 if (_XfeChildIsShown(child) && 
  1193.                     _XfeWidth(child) && 
  1194.                     _XfeHeight(child))
  1195.                 {
  1196.                     width = (_XfeWidth(w) * tp->separator_thickness) / 100;
  1197.                     height = _XfeHeight(child);
  1198.  
  1199.                     x = (_XfeWidth(w) - width) / 2;
  1200.  
  1201.                     _XfeConfigureWidget(child,x,y,width,height);
  1202.                     
  1203.                     y += (height + _XfeOrientedSpacing(w));
  1204.                 }
  1205.             }
  1206.             else
  1207.             {
  1208.                 assert( 0 );
  1209.             }
  1210.         } /* IsLayableChild */
  1211.     } /* for */
  1212. }
  1213. /*----------------------------------------------------------------------*/
  1214. static void
  1215. LayoutHorizontal(Widget w)
  1216. {
  1217.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1218.     Cardinal            i;
  1219.     Position            x;
  1220.     Position            y;
  1221.     Dimension            width;
  1222.     Dimension            height;
  1223.  
  1224.     x = _XfemOffsetLeft(w) + tp->raise_border_thickness;
  1225.  
  1226.     for (i = 0; i < _XfemNumChildren(w); i++)
  1227.     {
  1228.         Widget child = _XfemChildren(w)[i];
  1229.  
  1230.         if (IsLayableChild(child))
  1231.         {
  1232.             if (IsButtonChild(child))
  1233.             {
  1234.                 /* The button's width */
  1235.                 width = 
  1236.                     tp->child_force_width ? 
  1237.                     tp->max_child_width : 
  1238.                     _XfeWidth(child);
  1239.                 
  1240.                 /* The button's height */
  1241.                 height = 
  1242.                     tp->child_force_height ? 
  1243.                     (_XfemRectHeight(w) - 2 * tp->raise_border_thickness) : 
  1244.                     _XfeHeight(child);
  1245.  
  1246.                 y = (_XfeHeight(w) - height) / 2;
  1247.                 
  1248.                 _XfeConfigureWidget(child,x,y,width,height);
  1249.  
  1250.                 x += (_XfeWidth(child) + _XfeOrientedSpacing(w));
  1251.             }
  1252.             else if (IsSeparatorChild(child))
  1253.             {
  1254.                 if (_XfeChildIsShown(child) && 
  1255.                     _XfeWidth(child) && 
  1256.                     _XfeHeight(child))
  1257.                 {
  1258.                     width = _XfeWidth(child);
  1259.                     height = (_XfeHeight(w) * tp->separator_thickness) / 100;
  1260.  
  1261.                     y = (_XfeHeight(w) - height) / 2;
  1262.  
  1263.                     _XfeConfigureWidget(child,x,y,width,height);
  1264.                     
  1265.                     x += (width + _XfeOrientedSpacing(w));
  1266.                 }
  1267.             }
  1268.             else
  1269.             {
  1270.                 assert( 0 );
  1271.             }
  1272.         } /* IsLayableChild */
  1273.     } /* for */
  1274. }
  1275. /*----------------------------------------------------------------------*/
  1276. static Boolean
  1277. IsValidChild(Widget child)
  1278. {
  1279.     return (IsButtonChild(child) || IsSeparatorChild(child));
  1280. }
  1281. /*----------------------------------------------------------------------*/
  1282. static Boolean
  1283. IsButtonChild(Widget child)
  1284. {
  1285.     return (XfeIsButton(child) || XfeIsCascade(child));
  1286. }
  1287. /*----------------------------------------------------------------------*/
  1288. static Boolean
  1289. IsSeparatorChild(Widget child)
  1290. {
  1291.     return (XmIsSeparator(child) || 
  1292.             XmIsSeparatorGadget(child) ||
  1293.             XmIsLabel(child) || 
  1294.             XmIsLabelGadget(child) ||
  1295.             XfeIsLabel(child));
  1296. }
  1297. /*----------------------------------------------------------------------*/
  1298. static Boolean
  1299. IsLayableChild(Widget child)
  1300. {
  1301.     return (_XfeIsAlive(child) && 
  1302.             XtIsManaged(child) && 
  1303.             !_XfeManagerPrivateComponent(child));
  1304. }
  1305. /*----------------------------------------------------------------------*/
  1306. static void
  1307. InvokeCallbacks(Widget            w,
  1308.                 XtCallbackList    list,
  1309.                 Widget            button,
  1310.                 int                reason,
  1311.                 XEvent *        event)
  1312. {
  1313. /*     XfeToolBarPart *    tp = _XfeToolBarPart(w); */
  1314.  
  1315.     /* Invoke the callbacks only if needed */
  1316.     if (list)
  1317.     {
  1318.         XfeToolBarCallbackStruct cbs;
  1319.     
  1320.         cbs.event        = event;
  1321.         cbs.reason        = reason;
  1322.  
  1323.         cbs.armed        = False;
  1324.         cbs.selected    = False;
  1325.  
  1326.         if (_XfeIsAlive(button))
  1327.         {
  1328.             XtVaSetValues(button,
  1329.                           XmNarmed,        &cbs.armed,
  1330.                           XmNselected,    &cbs.selected,
  1331.                           NULL);
  1332.         }
  1333.  
  1334.         /* Flush the display */
  1335.         XFlush(XtDisplay(w));
  1336.     
  1337.         /* Invoke the Callback List */
  1338.         XtCallCallbackList(w,list,&cbs);
  1339.     }
  1340. }
  1341. /*----------------------------------------------------------------------*/
  1342.  
  1343. /*----------------------------------------------------------------------*/
  1344. /*                                                                        */
  1345. /* Button functions                                                        */
  1346. /*                                                                        */
  1347. /*----------------------------------------------------------------------*/
  1348. static void
  1349. ButtonSetActiveEnabled(Widget w,Widget button,Boolean state)
  1350. {
  1351.     assert( XfeIsToolBar(w) );
  1352.  
  1353.     XtRemoveCallback(button,XmNactivateCallback,ButtonActiveCB,w);
  1354.  
  1355.     if (state)
  1356.     {
  1357.         XtAddCallback(button,XmNactivateCallback,ButtonActiveCB,w);
  1358.     }
  1359. }
  1360. /*----------------------------------------------------------------------*/
  1361. static void
  1362. ButtonSetSelectedEnabled(Widget w,Widget button,Boolean state)
  1363. {
  1364.     assert( XfeIsToolBar(w) );
  1365.  
  1366.     XtRemoveCallback(button,XmNselectionChangedCallback,ButtonSelectedCB,w);
  1367.  
  1368.     if (state)
  1369.     {
  1370.         XtAddCallback(button,XmNselectionChangedCallback,ButtonSelectedCB,w);
  1371.     }
  1372. }
  1373. /*----------------------------------------------------------------------*/
  1374. static void
  1375. ButtonSetActiveWidget(Widget    w,
  1376.                       Widget    button,
  1377.                       Boolean    invoke_callbacks,
  1378.                       XEvent *    event)
  1379. {
  1380.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1381.     Cardinal            i;
  1382.     Widget                new_active_button = NULL;
  1383.  
  1384.     for (i = 0; i < _XfemNumChildren(w); i++)
  1385.     {
  1386.         Widget child = _XfemChildren(w)[i];
  1387.         
  1388.         if (IsButtonChild(child) && _XfeIsAlive(child))
  1389.         {
  1390.             if (child == button)
  1391.             {
  1392.                 XtVaSetValues(child,XmNarmed,True,NULL);
  1393.  
  1394.                 new_active_button = child;
  1395.             }
  1396.             else
  1397.             {
  1398.                 XtVaSetValues(child,XmNarmed,False,NULL);
  1399.             }
  1400.         }
  1401.     }
  1402.  
  1403.     if (new_active_button != tp->active_button)
  1404.     {
  1405.         tp->active_button = new_active_button;
  1406.  
  1407.         if (invoke_callbacks)
  1408.         {
  1409.             InvokeCallbacks(w,
  1410.                             tp->value_changed_callback,
  1411.                             tp->active_button,
  1412.                             XmCR_TOOL_BAR_VALUE_CHANGED,
  1413.                             event);
  1414.         }
  1415.     }
  1416. }
  1417. /*----------------------------------------------------------------------*/
  1418. static void
  1419. ButtonSetSelectedWidget(Widget        w,
  1420.                         Widget        button,
  1421.                         Boolean        invoke_callbacks,
  1422.                         XEvent *    event)
  1423. {
  1424.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1425.     Cardinal            i;
  1426.     Widget                new_selected_button = NULL;
  1427.  
  1428.     for (i = 0; i < _XfemNumChildren(w); i++)
  1429.     {
  1430.         Widget child = _XfemChildren(w)[i];
  1431.         
  1432.         if (IsButtonChild(child) && _XfeIsAlive(child))
  1433.         {
  1434.             if (child == button)
  1435.             {
  1436.                 XtVaSetValues(child,XmNselected,True,NULL);
  1437.  
  1438.                 new_selected_button = child;
  1439.             }
  1440.             else
  1441.             {
  1442.                 XtVaSetValues(child,XmNselected,False,NULL);
  1443.             }
  1444.         }
  1445.     }
  1446.  
  1447.     if (new_selected_button != tp->selected_button)
  1448.     {
  1449.         tp->selected_button = new_selected_button;
  1450.  
  1451.         if (invoke_callbacks)
  1452.         {
  1453.             InvokeCallbacks(w,
  1454.                             tp->value_changed_callback,
  1455.                             tp->selected_button,
  1456.                             XmCR_TOOL_BAR_VALUE_CHANGED,
  1457.                             event);
  1458.         }
  1459.     }
  1460. }
  1461. /*----------------------------------------------------------------------*/
  1462.  
  1463. /*----------------------------------------------------------------------*/
  1464. /*                                                                        */
  1465. /* Button callbacks                                                        */
  1466. /*                                                                        */
  1467. /*----------------------------------------------------------------------*/
  1468. static void
  1469. ButtonActiveCB(Widget button,XtPointer client_data,XtPointer call_data)
  1470. {
  1471.     Widget                        w = (Widget) client_data;
  1472.     XfeButtonCallbackStruct *    data = (XfeButtonCallbackStruct *) call_data;
  1473.  
  1474.     ButtonSetActiveWidget(w,button,True,data->event);
  1475. }
  1476. /*----------------------------------------------------------------------*/
  1477. static void
  1478. ButtonSelectedCB(Widget button,XtPointer client_data,XtPointer call_data)
  1479. {
  1480.     Widget                                        w = (Widget) client_data;
  1481.     XfeLabelSelectionChangedCallbackStruct *    data = 
  1482.         (XfeLabelSelectionChangedCallbackStruct *) call_data;
  1483.  
  1484.     ButtonSetSelectedWidget(w,button,True,data->event);
  1485. }
  1486. /*----------------------------------------------------------------------*/
  1487.  
  1488. /*----------------------------------------------------------------------*/
  1489. /*                                                                        */
  1490. /* XfeToolBar children apply client procedures                            */
  1491. /*                                                                        */
  1492. /*----------------------------------------------------------------------*/
  1493. static void
  1494. ApplyButtonLayout(Widget w,Widget child,XtPointer client_data)
  1495. {
  1496.     XfeToolBarPart *    tp = _XfeToolBarPart((Widget) client_data);
  1497.  
  1498.     if (IsButtonChild(child))
  1499.     {
  1500.         Arg            xargs[3];
  1501.         Cardinal    n = 0;
  1502.         
  1503.         XtSetArg(xargs[n],XmNbuttonLayout,tp->button_layout); n++;
  1504.  
  1505.         XtSetValues(child,xargs,n);
  1506.     }
  1507. }
  1508. /*----------------------------------------------------------------------*/
  1509. static void
  1510. ApplyChildUsePrefWidth(Widget w,Widget child,XtPointer client_data)
  1511. {
  1512.     XfeToolBarPart *    tp = _XfeToolBarPart((Widget) client_data);
  1513.     Arg                    xargs[1];
  1514.  
  1515.     XtSetArg(xargs[0],XmNusePreferredWidth,tp->child_use_pref_width);
  1516.  
  1517.     if (XfeIsPrimitive(child))
  1518.     {
  1519.         XtSetValues(child,xargs,1);
  1520.     }
  1521. }
  1522. /*----------------------------------------------------------------------*/
  1523. static void
  1524. ApplyChildUsePrefHeight(Widget w,Widget child,XtPointer client_data)
  1525. {
  1526.     XfeToolBarPart *    tp = _XfeToolBarPart((Widget) client_data);
  1527.     Arg                    xargs[1];
  1528.  
  1529.     XtSetArg(xargs[0],XmNusePreferredHeight,tp->child_use_pref_height);
  1530.  
  1531.     if (XfeIsPrimitive(child))
  1532.     {
  1533.         XtSetValues(child,xargs,1);
  1534.     }
  1535. }
  1536. /*----------------------------------------------------------------------*/
  1537. static void
  1538. ApplySelectionModifiers(Widget w,Widget child,XtPointer client_data)
  1539. {
  1540.     XfeToolBarPart *    tp = _XfeToolBarPart((Widget) client_data);
  1541.  
  1542.     if (IsButtonChild(child))
  1543.     {
  1544.         Arg xargs[1];
  1545.         
  1546.         XtSetArg(xargs[0],XmNselectionModifiers,tp->selection_modifiers);
  1547.  
  1548.         XtSetValues(child,xargs,1);
  1549.     }
  1550. }
  1551. /*----------------------------------------------------------------------*/
  1552. static void
  1553. ApplyActiveEnabled(Widget w,Widget child,XtPointer client_data)
  1554. {
  1555.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1556.  
  1557.     if (IsButtonChild(child))
  1558.     {
  1559.         ButtonSetActiveEnabled(w,child,tp->radio_behavior);
  1560.     }
  1561. }
  1562. /*----------------------------------------------------------------------*/
  1563. static void
  1564. ApplySelectedEnabled(Widget w,Widget child,XtPointer client_data)
  1565. {
  1566.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1567.  
  1568.     if (IsButtonChild(child))
  1569.     {
  1570.         ButtonSetSelectedEnabled(w,child,tp->selection_policy != XmTOOL_BAR_SELECT_NONE);
  1571.     }
  1572. }
  1573. /*----------------------------------------------------------------------*/
  1574.  
  1575. /*----------------------------------------------------------------------*/
  1576. /*                                                                        */
  1577. /* XfeToolBar Public Methods                                            */
  1578. /*                                                                        */
  1579. /*----------------------------------------------------------------------*/
  1580. /* extern */ Widget
  1581. XfeCreateToolBar(Widget pw,char * name,Arg * av,Cardinal ac)
  1582. {
  1583.    return XtCreateWidget(name,xfeToolBarWidgetClass,pw,av,ac);
  1584. }
  1585. /*----------------------------------------------------------------------*/
  1586. /* extern */ Boolean
  1587. XfeToolBarSetActiveButton(Widget w,Widget button)
  1588. {
  1589.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1590.  
  1591.     assert( XfeIsToolBar(w) );
  1592.     assert( _XfeIsAlive(w) );
  1593.     assert( _XfeIsAlive(button) );
  1594.     assert( _XfeParent(button) == w );
  1595.  
  1596.     /* Make sure they are alive */
  1597.     if (!_XfeIsAlive(w) || !_XfeIsAlive(button))
  1598.     {
  1599.         return False;
  1600.     }
  1601.  
  1602.     /* Make sure the active button has changed */
  1603.     if (button == tp->active_button)
  1604.     {
  1605.         return False;
  1606.     }
  1607.  
  1608.     ButtonSetActiveWidget(w,button,False,NULL);
  1609.  
  1610.     return True;
  1611. }
  1612. /*----------------------------------------------------------------------*/
  1613. /* extern */ Boolean
  1614. XfeToolBarSetSelectedButton(Widget w,Widget button)
  1615. {
  1616.     XfeToolBarPart *    tp = _XfeToolBarPart(w);
  1617.  
  1618.     assert( XfeIsToolBar(w) );
  1619.     assert( _XfeIsAlive(w) );
  1620.     assert( _XfeIsAlive(button) );
  1621.     assert( _XfeParent(button) == w );
  1622.  
  1623.     /* Make sure they are alive */
  1624.     if (!_XfeIsAlive(w) || !_XfeIsAlive(button))
  1625.     {
  1626.         return False;
  1627.     }
  1628.  
  1629.     /* Make sure the selection policy is ok */
  1630.     if (tp->selection_policy == XmTOOL_BAR_SELECT_NONE)
  1631.     {
  1632.         return False;
  1633.     }
  1634.  
  1635.     /* Make sure the selected button has changed */
  1636.     if (button == tp->selected_button)
  1637.     {
  1638.         return False;
  1639.     }
  1640.  
  1641.     ButtonSetSelectedWidget(w,button,False,NULL);
  1642.  
  1643.     return True;
  1644. }
  1645. /*----------------------------------------------------------------------*/
  1646.