home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / Chrome.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  28.9 KB  |  1,202 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/Chrome.c>                                            */
  21. /* Description:    XfeChrome widget source.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/ChromeP.h>
  28.  
  29. /* Possible children classes */
  30. #include <Xfe/Label.h>
  31. #include <Xfe/Button.h>
  32. #include <Xfe/Cascade.h>
  33.  
  34. #include <Xm/Separator.h>
  35. #include <Xm/DrawingA.h>
  36. #include <Xm/MainW.h>
  37. #include <Xm/Form.h>
  38. #include <Xm/Frame.h>
  39.  
  40. #define MESSAGE1 "Widget is not an XfeChrome."
  41. #define MESSAGE2 "The XmNmenuBar widget cannot be changed."
  42. #define MESSAGE3 "The XmNtoolBox widget cannot be changed."
  43. #define MESSAGE4 "The XmNdashBoard widget cannot be changed."
  44.  
  45. #define IS_MENU_BAR(w)        (_XfeIsAlive(w) && XmIsRowColumn(w))
  46. #define IS_TOOL_BOX(w)        (_XfeIsAlive(w) && XfeIsToolBox(w))
  47. #define IS_DASH_BOARD(w)    (_XfeIsAlive(w) && XfeIsDashBoard(w))
  48.  
  49. #define SHOW_BOTTOM_VIEW(cp)    (_XfeChildIsShown((cp)->bottom_view))
  50. #define SHOW_CENTER_VIEW(cp)    (_XfeChildIsShown((cp)->center_view))
  51. #define SHOW_DASH_BOARD(cp)        (_XfeChildIsShown((cp)->dash_board))
  52. #define SHOW_LEFT_VIEW(cp)        (_XfeChildIsShown((cp)->left_view))
  53. #define SHOW_MENU_BAR(cp)        (_XfeChildIsShown((cp)->menu_bar))
  54. #define SHOW_RIGHT_VIEW(cp)        (_XfeChildIsShown((cp)->right_view))
  55. #define SHOW_TOOL_BOX(cp)        (_XfeChildIsShown((cp)->tool_box))
  56. #define SHOW_TOP_VIEW(cp)        (_XfeChildIsShown((cp)->top_view))
  57.  
  58. /*----------------------------------------------------------------------*/
  59. /*                                                                        */
  60. /* Core class methods                                                    */
  61. /*                                                                        */
  62. /*----------------------------------------------------------------------*/
  63. static void     Initialize            (Widget,Widget,ArgList,Cardinal *);
  64. static void     Destroy                (Widget);
  65. static Boolean    SetValues            (Widget,Widget,Widget,ArgList,Cardinal *);
  66.  
  67. /*----------------------------------------------------------------------*/
  68. /*                                                                        */
  69. /* Constraint class methods                                                */
  70. /*                                                                        */
  71. /*----------------------------------------------------------------------*/
  72. static void        ConstraintInitialize(Widget,Widget,ArgList,Cardinal *);
  73. static Boolean    ConstraintSetValues    (Widget,Widget,Widget,ArgList,Cardinal *);
  74.  
  75. /*----------------------------------------------------------------------*/
  76. /*                                                                        */
  77. /* XfeManager class methods                                                */
  78. /*                                                                        */
  79. /*----------------------------------------------------------------------*/
  80. static void        PreferredGeometry    (Widget,Dimension *,Dimension *);
  81. static Boolean    AcceptChild            (Widget);
  82. static Boolean    InsertChild            (Widget);
  83. static Boolean    DeleteChild            (Widget);
  84. static void        LayoutChildren        (Widget);
  85.  
  86. /*----------------------------------------------------------------------*/
  87. /*                                                                        */
  88. /* Misc XfeChrome functions                                                */
  89. /*                                                                        */
  90. /*----------------------------------------------------------------------*/
  91. static void        LayoutBottomView    (Widget);
  92. static void        LayoutCenterView    (Widget);
  93. static void        LayoutDashBoard        (Widget);
  94. static void        LayoutLeftView        (Widget);
  95. static void        LayoutMenuBar        (Widget);
  96. static void        LayoutRightView        (Widget);
  97. static void        LayoutToolBox        (Widget);
  98. static void        LayoutTopView        (Widget);
  99.                                    
  100. /*----------------------------------------------------------------------*/
  101. /*                                                                        */
  102. /* Constraint resource callprocs                                        */
  103. /*                                                                        */
  104. /*----------------------------------------------------------------------*/
  105. static void        DefaultChromeChildType            (Widget,int,XrmValue *);
  106.  
  107. /*----------------------------------------------------------------------*/
  108. /*                                                                        */
  109. /* XfeChrome resources                                                    */
  110. /*                                                                        */
  111. /*----------------------------------------------------------------------*/
  112. static XtResource resources[] =     
  113. {                    
  114.     /* Resources */
  115.     { 
  116.         XmNmenuBar,
  117.         XmCWidget,
  118.         XmRWidget,
  119.         sizeof(Widget),
  120.         XtOffsetOf(XfeChromeRec , xfe_chrome . menu_bar),
  121.         XmRImmediate, 
  122.         (XtPointer) NULL
  123.     },
  124.     { 
  125.         XmNtoolBox,
  126.         XmCWidget,
  127.         XmRWidget,
  128.         sizeof(Widget),
  129.         XtOffsetOf(XfeChromeRec , xfe_chrome . tool_box),
  130.         XmRImmediate, 
  131.         (XtPointer) NULL
  132.     },
  133.     { 
  134.         XmNcenterView,
  135.         XmCWidget,
  136.         XmRWidget,
  137.         sizeof(Widget),
  138.         XtOffsetOf(XfeChromeRec , xfe_chrome . center_view),
  139.         XmRImmediate, 
  140.         (XtPointer) NULL
  141.     },
  142.     { 
  143.         XmNtopView,
  144.         XmCWidget,
  145.         XmCWidget,
  146.         sizeof(Widget),
  147.         XtOffsetOf(XfeChromeRec , xfe_chrome . top_view),
  148.         XmRImmediate, 
  149.         (XtPointer) NULL
  150.     },
  151.     { 
  152.         XmNbottomView,
  153.         XmCWidget,
  154.         XmRWidget,
  155.         sizeof(Widget),
  156.         XtOffsetOf(XfeChromeRec , xfe_chrome . bottom_view),
  157.         XmRImmediate, 
  158.         (XtPointer) NULL
  159.     },
  160.     { 
  161.         XmNleftView,
  162.         XmCWidget,
  163.         XmCWidget,
  164.         sizeof(Widget),
  165.         XtOffsetOf(XfeChromeRec , xfe_chrome . left_view),
  166.         XmRImmediate, 
  167.         (XtPointer) NULL
  168.     },
  169.     { 
  170.         XmNrightView,
  171.         XmCWidget,
  172.         XmRWidget,
  173.         sizeof(Widget),
  174.         XtOffsetOf(XfeChromeRec , xfe_chrome . right_view),
  175.         XmRImmediate, 
  176.         (XtPointer) NULL
  177.     },
  178.     { 
  179.         XmNdashBoard,
  180.         XmCWidget,
  181.         XmRWidget,
  182.         sizeof(Widget),
  183.         XtOffsetOf(XfeChromeRec , xfe_chrome . dash_board),
  184.         XmRImmediate, 
  185.         (XtPointer) NULL
  186.     },
  187.     { 
  188.         XmNspacing,
  189.         XmCSpacing,
  190.         XmRHorizontalDimension,
  191.         sizeof(Dimension),
  192.         XtOffsetOf(XfeChromeRec , xfe_chrome . spacing),
  193.         XmRImmediate, 
  194.         (XtPointer) 1
  195.     },
  196.  
  197.     /* Force all the margins to 0 */
  198.     { 
  199.         XmNmarginBottom,
  200.         XmCMarginBottom,
  201.         XmRVerticalDimension,
  202.         sizeof(Dimension),
  203.         XtOffsetOf(XfeChromeRec , xfe_manager . margin_bottom),
  204.         XmRImmediate, 
  205.         (XtPointer) 0
  206.     },
  207.     { 
  208.         XmNmarginLeft,
  209.         XmCMarginLeft,
  210.         XmRHorizontalDimension,
  211.         sizeof(Dimension),
  212.         XtOffsetOf(XfeChromeRec , xfe_manager . margin_left),
  213.         XmRImmediate, 
  214.         (XtPointer) 0
  215.     },
  216.     { 
  217.         XmNmarginRight,
  218.         XmCMarginRight,
  219.         XmRHorizontalDimension,
  220.         sizeof(Dimension),
  221.         XtOffsetOf(XfeChromeRec , xfe_manager . margin_right),
  222.         XmRImmediate, 
  223.         (XtPointer) 0
  224.     },
  225.     { 
  226.         XmNmarginTop,
  227.         XmCMarginTop,
  228.         XmRVerticalDimension,
  229.         sizeof(Dimension),
  230.         XtOffsetOf(XfeChromeRec , xfe_manager . margin_top),
  231.         XmRImmediate, 
  232.         (XtPointer) 0
  233.     },
  234. };   
  235.  
  236. /*----------------------------------------------------------------------*/
  237. /*                                                                        */
  238. /* XfeChrome synthetic resources                                        */
  239. /*                                                                        */
  240. /*----------------------------------------------------------------------*/
  241. static XmSyntheticResource synthetic_resources[] =
  242. {
  243.    { 
  244.        XmNspacing,
  245.        sizeof(Dimension),
  246.        XtOffsetOf(XfeChromeRec , xfe_chrome . spacing),
  247.        _XmFromHorizontalPixels,
  248.        _XmToHorizontalPixels 
  249.    },
  250. };
  251.  
  252. /*----------------------------------------------------------------------*/
  253. /*                                                                        */
  254. /* XfeChrome constraint resources                                        */
  255. /*                                                                        */
  256. /*----------------------------------------------------------------------*/
  257. static XtResource constraint_resources[] = 
  258. {
  259.     { 
  260.         XmNchromeChildType,
  261.         XmCChromeChildType,
  262.         XmRChromeChildType,
  263.         sizeof(unsigned char),
  264.         XtOffsetOf(XfeChromeConstraintRec , xfe_chrome . chrome_child_type),
  265.         XmRCallProc,
  266.         (XtPointer) DefaultChromeChildType
  267.     },
  268. };   
  269.  
  270. /*----------------------------------------------------------------------*/
  271. /*                                                                        */
  272. /* Widget Class Record Initialization                                   */
  273. /*                                                                        */
  274. /*----------------------------------------------------------------------*/
  275. _XFE_WIDGET_CLASS_RECORD(chrome,Chrome) =
  276. {
  277.     {
  278.         (WidgetClass) &xfeManagerClassRec,        /* superclass            */
  279.         "XfeChrome",                            /* class_name            */
  280.         sizeof(XfeChromeRec),                    /* widget_size            */
  281.         NULL,                                    /* class_initialize        */
  282.         NULL,                                    /* class_part_initialize*/
  283.         FALSE,                                    /* class_inited            */
  284.         Initialize,                                /* initialize            */
  285.         NULL,                                    /* initialize_hook        */
  286.         XtInheritRealize,                        /* realize                */
  287.         NULL,                                    /* actions                */
  288.         0,                                        /* num_actions            */
  289.         resources,                              /* resources            */
  290.         XtNumber(resources),                    /* num_resources        */
  291.         NULLQUARK,                              /* xrm_class            */
  292.         TRUE,                                   /* compress_motion        */
  293.         XtExposeCompressMaximal,                /* compress_exposure    */
  294.         TRUE,                                   /* compress_enterleave    */
  295.         FALSE,                                  /* visible_interest        */
  296.         Destroy,                                /* destroy                */
  297.         XtInheritResize,                        /* resize                */
  298.         XtInheritExpose,                        /* expose                */
  299.         SetValues,                              /* set_values            */
  300.         NULL,                                   /* set_values_hook        */
  301.         XtInheritSetValuesAlmost,                /* set_values_almost    */
  302.         NULL,                                    /* get_values_hook        */
  303.         NULL,                                   /* access_focus            */
  304.         XtVersion,                              /* version                */
  305.         NULL,                                   /* callback_private        */
  306.         XtInheritTranslations,                    /* tm_table                */
  307.         XtInheritQueryGeometry,                    /* query_geometry        */
  308.         XtInheritDisplayAccelerator,            /* display accelerator    */
  309.         NULL,                                   /* extension            */
  310.     },
  311.     
  312.     /* Composite Part */
  313.     {
  314.         XtInheritGeometryManager,                /* geometry_manager        */
  315.         XtInheritChangeManaged,                    /* change_managed        */
  316.         XtInheritInsertChild,                    /* insert_child            */
  317.         XtInheritDeleteChild,                    /* delete_child            */
  318.         NULL                                    /* extension            */
  319.     },
  320.  
  321.     /* Constraint Part */
  322.     {
  323.         constraint_resources,                    /* constraint res        */
  324.         XtNumber(constraint_resources),            /* num constraint res    */
  325.         sizeof(XfeChromeConstraintRec),            /* constraint size        */
  326.         ConstraintInitialize,                    /* init proc            */
  327.         NULL,                                    /* destroy proc            */
  328.         ConstraintSetValues,                    /* set values proc        */
  329.         NULL,                                   /* extension            */
  330.     },
  331.  
  332.     /* XmManager Part */
  333.     {
  334.         XtInheritTranslations,                    /* tm_table                */
  335.         synthetic_resources,                    /* syn resources        */
  336.         XtNumber(synthetic_resources),            /* num syn_resources    */
  337.         NULL,                                    /* syn resources        */
  338.         0,                                        /* num syn_resources    */
  339.         XmInheritParentProcess,                 /* parent_process        */
  340.         NULL,                                   /* extension            */
  341.     },
  342.     
  343.     /* XfeManager Part     */
  344.     {
  345.         XfeInheritBitGravity,                    /* bit_gravity            */
  346.         PreferredGeometry,                        /* preferred_geometry    */
  347.         XfeInheritMinimumGeometry,                /* minimum_geometry        */
  348.         XfeInheritUpdateRect,                    /* update_rect            */
  349.         AcceptChild,                            /* accept_child            */
  350.         InsertChild,                            /* insert_child            */
  351.         DeleteChild,                            /* delete_child            */
  352.         NULL,                                    /* change_managed        */
  353.         NULL,                                    /* prepare_components    */
  354.         NULL,                                    /* layout_components    */
  355.         LayoutChildren,                            /* layout_children        */
  356.         NULL,                                    /* draw_background        */
  357.         XfeInheritDrawShadow,                    /* draw_shadow            */
  358.         NULL,                                    /* draw_components        */
  359.         NULL,                                    /* extension            */
  360.     },
  361.  
  362.     /* XfeChrome Part */
  363.     {
  364.         NULL,                                    /* extension            */
  365.     },
  366. };
  367.  
  368. /*----------------------------------------------------------------------*/
  369. /*                                                                        */
  370. /* xfeChromeWidgetClass declaration.                                    */
  371. /*                                                                        */
  372. /*----------------------------------------------------------------------*/
  373. _XFE_WIDGET_CLASS(chrome,Chrome);
  374.  
  375. /*----------------------------------------------------------------------*/
  376. /*                                                                        */
  377. /* Constraint resource callprocs                                        */
  378. /*                                                                        */
  379. /*----------------------------------------------------------------------*/
  380. static void
  381. DefaultChromeChildType(Widget child,int offset,XrmValue * value)
  382. {
  383.     Widget                    w = _XfeParent(child);
  384.     XfeChromePart *            cp = _XfeChromePart(w);
  385.     static unsigned char    chrome_child_type;
  386.  
  387.     /* menu_bar */
  388.     if (IS_MENU_BAR(child))
  389.     {
  390.         chrome_child_type = XmCHROME_MENU_BAR;
  391.     }
  392.     /* tool_box */
  393.     else if (IS_TOOL_BOX(child))
  394.     {
  395.         chrome_child_type = XmCHROME_TOOL_BOX;
  396.     }
  397.     /* dash_board */
  398.     else if (IS_DASH_BOARD(child))
  399.     {
  400.         chrome_child_type = XmCHROME_DASH_BOARD;
  401.     }
  402.     /* center_view */
  403.     else if (!_XfeIsAlive(cp->center_view))
  404.     {
  405.         chrome_child_type = XmCHROME_CENTER_VIEW;
  406.     }
  407.     /* top_view */
  408.     else if (!_XfeIsAlive(cp->top_view))
  409.     {
  410.         chrome_child_type = XmCHROME_TOP_VIEW;
  411.     }
  412.     /* bottom_view */
  413.     else if (!_XfeIsAlive(cp->bottom_view))
  414.     {
  415.         chrome_child_type = XmCHROME_BOTTOM_VIEW;
  416.     }
  417.     /* left_view */
  418.     else if (!_XfeIsAlive(cp->left_view))
  419.     {
  420.         chrome_child_type = XmCHROME_LEFT_VIEW;
  421.     }
  422.     /* right_view */
  423.     else if (!_XfeIsAlive(cp->right_view))
  424.     {
  425.         chrome_child_type = XmCHROME_RIGHT_VIEW;
  426.     }
  427.  
  428.     value->addr = (XPointer) &chrome_child_type;
  429.     value->size = sizeof(chrome_child_type);
  430. }
  431. /*----------------------------------------------------------------------*/
  432.  
  433. /*----------------------------------------------------------------------*/
  434. /*                                                                        */
  435. /* Core Class methods                                                    */
  436. /*                                                                        */
  437. /*----------------------------------------------------------------------*/
  438. static void
  439. Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  440. {
  441.     XfeChromePart *        cp = _XfeChromePart(nw);
  442.  
  443.     /* Finish of initialization */
  444.     _XfeManagerChainInitialize(rw,nw,xfeChromeWidgetClass);
  445. }
  446. /*----------------------------------------------------------------------*/
  447. static void
  448. Destroy(Widget w)
  449. {
  450.     XfeChromePart *        cp = _XfeChromePart(w);
  451.  
  452. }
  453. /*----------------------------------------------------------------------*/
  454. static Boolean
  455. SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  456. {
  457.     XfeChromePart *        np = _XfeChromePart(nw);
  458.     XfeChromePart *        op = _XfeChromePart(ow);
  459.  
  460.     /* spacing */
  461.     if (np->spacing != op->spacing)
  462.     {
  463.         _XfemConfigFlags(nw) |= XfeConfigLayout;
  464.     }
  465.  
  466.     /* menu_bar */
  467.     if (np->menu_bar != op->menu_bar)
  468.     {
  469.         np->menu_bar = op->menu_bar;
  470.  
  471.         _XfeWarning(nw,MESSAGE2);
  472.     }
  473.  
  474.     /* tool_box */
  475.     if (np->tool_box != op->tool_box)
  476.     {
  477.         np->tool_box = op->tool_box;
  478.  
  479.         _XfeWarning(nw,MESSAGE3);
  480.     }
  481.  
  482.     /* dash_board */
  483.     if (np->dash_board != op->dash_board)
  484.     {
  485.         np->dash_board = op->dash_board;
  486.  
  487.         _XfeWarning(nw,MESSAGE4);
  488.     }
  489.  
  490.     /* center_view */
  491.     if (np->center_view != op->center_view)
  492.     {
  493.         _XfemConfigFlags(nw) |= XfeConfigLayout;
  494.     }
  495.  
  496.     /* top_view */
  497.     if (np->top_view != op->top_view)
  498.     {
  499.         _XfemConfigFlags(nw) |= XfeConfigLayout;
  500.     }
  501.  
  502.     /* bottom_view */
  503.     if (np->bottom_view != op->bottom_view)
  504.     {
  505.         _XfemConfigFlags(nw) |= XfeConfigLayout;
  506.     }
  507.  
  508.     return _XfeManagerChainSetValues(ow,rw,nw,xfeChromeWidgetClass);
  509. }
  510. /*----------------------------------------------------------------------*/
  511.  
  512. /*----------------------------------------------------------------------*/
  513. /*                                                                        */
  514. /* Constraint class methods                                                */
  515. /*                                                                        */
  516. /*----------------------------------------------------------------------*/
  517. static void
  518. ConstraintInitialize(Widget rc,Widget nc,ArgList av,Cardinal * ac)
  519. {
  520.       Widget                        w = _XfeParent(nc);
  521.     XfeChromeConstraintPart *    cp = _XfeChromeConstraintPart(nc);
  522.  
  523.     /* Make sure the chrome child type is ok */
  524.     XfeRepTypeCheck(nc,XmRChromeChildType,&cp->chrome_child_type,
  525.                     XmCHROME_IGNORE);
  526.  
  527.     /* Finish constraint initialization */
  528.     _XfeConstraintChainInitialize(rc,nc,xfeChromeWidgetClass);
  529. }
  530. /*----------------------------------------------------------------------*/
  531. static Boolean
  532. ConstraintSetValues(Widget oc,Widget rc,Widget nc,ArgList av,Cardinal * ac)
  533. {
  534.     Widget                        w = XtParent(nc);
  535.      XfeChromeConstraintPart *    ncp = _XfeChromeConstraintPart(nc);
  536.      XfeChromeConstraintPart *    ocp = _XfeChromeConstraintPart(oc);
  537.  
  538.     /* chrome_child_type */
  539.     if (ncp->chrome_child_type != ocp->chrome_child_type)
  540.     {
  541.         /* Make sure the new chrome child type is ok */
  542.         XfeRepTypeCheck(nc,XmRChromeChildType,&ncp->chrome_child_type,
  543.                         XmCHROME_IGNORE);
  544.     }
  545.  
  546.     /* Finish constraint set values */
  547.     return _XfeConstraintChainSetValues(oc,rc,nc,xfeChromeWidgetClass);
  548. }
  549. /*----------------------------------------------------------------------*/
  550.  
  551. /*----------------------------------------------------------------------*/
  552. /*                                                                        */
  553. /* XfeManager class methods                                                */
  554. /*                                                                        */
  555. /*----------------------------------------------------------------------*/
  556. static void
  557. PreferredGeometry(Widget w,Dimension * width,Dimension * height)
  558. {
  559.     XfeChromePart *        cp = _XfeChromePart(w);
  560.  
  561.     *width  = _XfemOffsetLeft(w) + _XfemOffsetRight(w);
  562.     *height = _XfemOffsetTop(w)  + _XfemOffsetBottom(w);
  563.  
  564. }
  565. /*----------------------------------------------------------------------*/
  566. static Boolean
  567. AcceptChild(Widget child)
  568. {
  569.     Widget                w = XtParent(child);
  570.     XfeChromePart *        cp = _XfeChromePart(w);
  571.     Boolean                accept = True;
  572.  
  573.     /* menu_bar */
  574.     if (IS_MENU_BAR(child))
  575.     {
  576.         accept = !cp->menu_bar;
  577.     }
  578.     /* tool_box */
  579.     else if (IS_TOOL_BOX(child))
  580.     {
  581.         accept = !cp->tool_box;
  582.     }
  583.     /* dash_board */
  584.     else if (IS_DASH_BOARD(child))
  585.     {
  586.         accept = !cp->dash_board;
  587.     }
  588.     /* view / top_view / bottom_view */
  589.     else if (!cp->center_view ||
  590.              !cp->top_view ||
  591.              !cp->bottom_view ||
  592.              !cp->left_view ||
  593.              !cp->right_view)
  594.     {
  595.         accept = True;
  596.     }
  597.  
  598.     return accept;
  599. }
  600. /*----------------------------------------------------------------------*/
  601. static Boolean
  602. InsertChild(Widget child)
  603. {
  604.     Widget                w = XtParent(child);
  605.     XfeChromePart *        cp = _XfeChromePart(w);
  606.     Boolean                layout = False;
  607.  
  608.     /* menu_bar */
  609.     if (IS_MENU_BAR(child))
  610.     {
  611.         cp->menu_bar = child;
  612.  
  613.         layout = True;
  614.     }
  615.     /* tool_box */
  616.     else if (IS_TOOL_BOX(child))
  617.     {
  618.         cp->tool_box = child;
  619.  
  620.         layout = True;
  621.     }
  622.     /* dash_board */
  623.     else if (IS_DASH_BOARD(child))
  624.     {
  625.         cp->dash_board = child;
  626.  
  627.         layout = True;
  628.     }
  629.     /* center_view */
  630.     else if (!cp->center_view)
  631.     {
  632.         cp->center_view = child;
  633.  
  634.         layout = True;
  635.     }
  636.     /* top_view */
  637.     else if (!cp->top_view)
  638.     {
  639.         cp->top_view = child;
  640.  
  641.         layout = True;
  642.     }
  643.     /* bottom_view */
  644.     else if (!cp->bottom_view)
  645.     {
  646.         cp->bottom_view = child;
  647.  
  648.         layout = True;
  649.     }
  650.     /* left_view */
  651.     else if (!cp->left_view)
  652.     {
  653.         cp->left_view = child;
  654.  
  655.         layout = True;
  656.     }
  657.     /* right_view */
  658.     else if (!cp->right_view)
  659.     {
  660.         cp->right_view = child;
  661.  
  662.         layout = True;
  663.     }
  664.  
  665.     return layout;
  666. }
  667. /*----------------------------------------------------------------------*/
  668. static Boolean
  669. DeleteChild(Widget child)
  670. {
  671.     Widget                w = XtParent(child);
  672.     XfeChromePart *        cp = _XfeChromePart(w);
  673.  
  674.     /* menu_bar */
  675.     if (child == cp->menu_bar)
  676.     {
  677.         cp->menu_bar = NULL;
  678.     }
  679.     /* tool_box */
  680.     else if (child == cp->tool_box)
  681.     {
  682.         cp->tool_box = NULL;
  683.     }
  684.     /* dash_board */
  685.     else if (child == cp->dash_board)
  686.     {
  687.         cp->dash_board = NULL;
  688.     }
  689.     /* center_view */
  690.     else if (child == cp->center_view)
  691.     {
  692.         cp->center_view = NULL;
  693.     }
  694.     /* top_view */
  695.     else if (child == cp->top_view)
  696.     {
  697.         cp->top_view = NULL;
  698.     }
  699.     /* bottom_view */
  700.     else if (child == cp->bottom_view)
  701.     {
  702.         cp->bottom_view = NULL;
  703.     }
  704.     /* left_view */
  705.     else if (child == cp->left_view)
  706.     {
  707.         cp->left_view = NULL;
  708.     }
  709.     /* right_view */
  710.     else if (child == cp->right_view)
  711.     {
  712.         cp->right_view = NULL;
  713.     }
  714.     
  715.     return True;
  716. }
  717. /*----------------------------------------------------------------------*/
  718. static void
  719. LayoutChildren(Widget w)
  720. {
  721.     XfeChromePart *    cp = _XfeChromePart(w);
  722.  
  723.     /* menu_bar */
  724.     if (SHOW_MENU_BAR(cp))
  725.     {
  726.         LayoutMenuBar(w);
  727.     }
  728.  
  729.     /* tool_box */
  730.     if (SHOW_TOOL_BOX(cp))
  731.     {
  732.         LayoutToolBox(w);
  733.     }
  734.  
  735.     /* dash_board */
  736.     if (SHOW_DASH_BOARD(cp))
  737.     {
  738.         LayoutDashBoard(w);
  739.     }
  740.  
  741.     /* top_view */
  742.     if (SHOW_TOP_VIEW(cp))
  743.     {
  744.         LayoutTopView(w);
  745.     }
  746.  
  747.     /* left_view */
  748.     if (SHOW_LEFT_VIEW(cp))
  749.     {
  750.         LayoutLeftView(w);
  751.     }
  752.  
  753.     /* bottom_view */
  754.     if (SHOW_BOTTOM_VIEW(cp))
  755.     {
  756.         LayoutBottomView(w);
  757.     }
  758.  
  759.     /* right_view */
  760.     if (SHOW_RIGHT_VIEW(cp))
  761.     {
  762.         LayoutRightView(w);
  763.     }
  764.  
  765.     /* center_view */
  766.     if (SHOW_CENTER_VIEW(cp))
  767.     {
  768.         LayoutCenterView(w);
  769.     }
  770. }
  771. /*----------------------------------------------------------------------*/
  772.  
  773. /*----------------------------------------------------------------------*/
  774. /*                                                                        */
  775. /* Misc XfeChrome functions                                                */
  776. /*                                                                        */
  777. /*----------------------------------------------------------------------*/
  778. static void
  779. LayoutMenuBar(Widget w)
  780. {
  781.     XfeChromePart *    cp = _XfeChromePart(w);
  782.  
  783.     assert( SHOW_MENU_BAR(cp) );
  784.  
  785.     /* Place the menu bar on the very top and occupy the full width */
  786.     _XfeConfigureWidget(cp->menu_bar,
  787.                         _XfemRectX(w),
  788.                         _XfemRectY(w),
  789.                         _XfemRectWidth(w),
  790.                         _XfeHeight(cp->menu_bar));
  791. }
  792. /*----------------------------------------------------------------------*/
  793. static void
  794. LayoutToolBox(Widget w)
  795. {
  796.     XfeChromePart *    cp = _XfeChromePart(w);
  797.  
  798.     assert( SHOW_TOOL_BOX(cp) );
  799.  
  800.     /* Menu bar is shown */
  801.     if (SHOW_MENU_BAR(cp))
  802.     {
  803.         /* Place the tool box right after the menu bar */
  804.         _XfeConfigureWidget(cp->tool_box,
  805.  
  806.                             _XfemRectX(w),
  807.                             
  808.                             _XfeY(cp->menu_bar) +
  809.                             _XfeHeight(cp->menu_bar),
  810.                             
  811.                             _XfemRectWidth(w),
  812.  
  813.                             _XfeHeight(cp->tool_box));
  814.     }
  815.     /* Menu bar is not shown */
  816.     else
  817.     {
  818.         /* Place the tool box on the very top */
  819.         _XfeConfigureWidget(cp->tool_box,
  820.  
  821.                             _XfemRectX(w),
  822.                             
  823.                             _XfemRectY(w),
  824.                             
  825.                             _XfemRectWidth(w),
  826.  
  827.                             _XfeHeight(cp->tool_box));
  828.     }
  829.  
  830. }
  831. /*----------------------------------------------------------------------*/
  832. static void
  833. LayoutDashBoard(Widget w)
  834. {
  835.     XfeChromePart *    cp = _XfeChromePart(w);
  836.  
  837.     assert( SHOW_DASH_BOARD(cp) );
  838.  
  839.     /* Make sure the dash board looks right */
  840.     XtVaSetValues(cp->dash_board,
  841.                   XmNusePreferredWidth,        False,
  842.                   XmNusePreferredHeight,    True,
  843.                   NULL);
  844.  
  845.     /* Place the dash board the very bottom and occupy the full width */
  846.     _XfeConfigureWidget(cp->dash_board,
  847.  
  848.                         _XfemRectX(w),
  849.                         
  850.                         _XfeHeight(w) - 
  851.                         _XfemOffsetBottom(w) -
  852.                         _XfeHeight(cp->dash_board),
  853.  
  854.                         _XfemRectWidth(w),
  855.  
  856.                         _XfeHeight(cp->dash_board));
  857.  
  858. }
  859. /*----------------------------------------------------------------------*/
  860. static void
  861. LayoutTopView(Widget w)
  862. {
  863.     XfeChromePart *    cp = _XfeChromePart(w);
  864.     Widget            top = NULL;
  865.     Widget            bottom = NULL;
  866.     int                y;
  867.     int                x;
  868.     int                width;
  869.     int                height;
  870.  
  871.     assert( SHOW_TOP_VIEW(cp) );
  872.  
  873.     /* tool_box is shown */
  874.     if (SHOW_TOOL_BOX(cp))
  875.     {
  876.         top = cp->tool_box;
  877.     }
  878.     /* menu_bar is shown */
  879.     else if (SHOW_MENU_BAR(cp))
  880.     {
  881.         top = cp->menu_bar;
  882.     }
  883.  
  884.     if (_XfeIsAlive(top))
  885.     {
  886.         y = _XfeY(top) + _XfeHeight(top) + cp->spacing;
  887.     }
  888.     else
  889.     {
  890.         y = _XfemRectY(w);
  891.     }
  892.  
  893.     /* left_view is shown */
  894.     if (SHOW_LEFT_VIEW(cp))
  895.     {
  896.         x = _XfemRectX(w) + _XfeWidth(cp->left_view);
  897.  
  898.         width = _XfemRectWidth(w) - _XfeWidth(cp->left_view);
  899.     }
  900.     else
  901.     {
  902.         x = _XfemRectX(w);
  903.  
  904.         width = _XfemRectWidth(w);
  905.     }
  906.     
  907.     /* right_view is shown */
  908.     if (SHOW_RIGHT_VIEW(cp))
  909.     {
  910.         width -= _XfeWidth(cp->right_view);
  911.     }
  912.  
  913.     height = _XfeHeight(cp->top_view);
  914.     
  915.     /* Place the top_view */
  916.     _XfeConfigureWidget(cp->top_view,x,y,width,height);
  917. }
  918. /*----------------------------------------------------------------------*/
  919. static void
  920. LayoutBottomView(Widget w)
  921. {
  922.     XfeChromePart *    cp = _XfeChromePart(w);
  923.     Widget            top = NULL;
  924.     Widget            bottom = NULL;
  925.     int                y;
  926.     int                x;
  927.     int                width;
  928.     int                height;
  929.  
  930.     assert( SHOW_BOTTOM_VIEW(cp) );
  931.  
  932.     /* dash_board is shown */
  933.     if (SHOW_DASH_BOARD(cp))
  934.     {
  935.         bottom = cp->dash_board;
  936.     }
  937.  
  938.     if (_XfeIsAlive(bottom))
  939.     {
  940.         y = _XfeY(bottom) - cp->spacing;
  941.     }
  942.     else
  943.     {
  944.         y = _XfeHeight(w) - _XfemOffsetBottom(w);
  945.     }
  946.  
  947.     y -= _XfeHeight(cp->bottom_view);
  948.  
  949.     /* left_view is shown */
  950.     if (SHOW_LEFT_VIEW(cp))
  951.     {
  952.         x = _XfemRectX(w) + _XfeWidth(cp->left_view);
  953.  
  954.         width = _XfemRectWidth(w) - _XfeWidth(cp->left_view);
  955.     }
  956.     else
  957.     {
  958.         x = _XfemRectX(w);
  959.  
  960.         width = _XfemRectWidth(w);
  961.     }
  962.     
  963.     /* right_view is shown */
  964.     if (SHOW_RIGHT_VIEW(cp))
  965.     {
  966.         width -= _XfeWidth(cp->right_view);
  967.     }
  968.  
  969.     height = _XfeHeight(cp->bottom_view);
  970.  
  971.     /* Place the bottom_view */
  972.     _XfeConfigureWidget(cp->bottom_view,x,y,width,height);
  973. }
  974. /*----------------------------------------------------------------------*/
  975. static void
  976. LayoutCenterView(Widget w)
  977. {
  978.     XfeChromePart *    cp = _XfeChromePart(w);
  979.     Widget            top = NULL;
  980.     Widget            bottom = NULL;
  981.     int                y;
  982.     int                y2;
  983.     int                x;
  984.     int                width;
  985.     int                height;
  986.  
  987.     assert( SHOW_CENTER_VIEW(cp) );
  988.  
  989.     /* top_view is shown */
  990.     if (SHOW_TOP_VIEW(cp))
  991.     {
  992.         top = cp->top_view;
  993.     }
  994.     /* tool_box is shown */
  995.     else if (SHOW_TOOL_BOX(cp))
  996.     {
  997.         top = cp->tool_box;
  998.     }
  999.     /* menu_bar is shown */
  1000.     else if (SHOW_MENU_BAR(cp))
  1001.     {
  1002.         top = cp->menu_bar;
  1003.     }
  1004.  
  1005.     /* bottom_view is shown */
  1006.     if (SHOW_BOTTOM_VIEW(cp))
  1007.     {
  1008.         bottom = cp->bottom_view;
  1009.     }
  1010.     /* dash_board is shown */
  1011.     else if (SHOW_DASH_BOARD(cp))
  1012.     {
  1013.         bottom = cp->dash_board;
  1014.     }
  1015.  
  1016.     if (_XfeIsAlive(top))
  1017.     {
  1018.         y = _XfeY(top) + _XfeHeight(top) + cp->spacing;
  1019.     }
  1020.     else
  1021.     {
  1022.         y = _XfemRectY(w);
  1023.     }
  1024.  
  1025.     if (_XfeIsAlive(bottom))
  1026.     {
  1027.         y2 = _XfeY(bottom) - cp->spacing;
  1028.     }
  1029.     else
  1030.     {
  1031.         y2 = _XfeHeight(w) - _XfemOffsetBottom(w);
  1032.     }
  1033.  
  1034.     /* left_view is shown */
  1035.     if (SHOW_LEFT_VIEW(cp))
  1036.     {
  1037.         x = _XfemRectX(w) + _XfeWidth(cp->left_view);
  1038.  
  1039.         width = _XfemRectWidth(w) - _XfeWidth(cp->left_view);
  1040.     }
  1041.     else
  1042.     {
  1043.         x = _XfemRectX(w);
  1044.  
  1045.         width = _XfemRectWidth(w);
  1046.     }
  1047.     
  1048.     /* right_view is shown */
  1049.     if (SHOW_RIGHT_VIEW(cp))
  1050.     {
  1051.         width -= _XfeWidth(cp->right_view);
  1052.     }
  1053.  
  1054.     height = y2 - y;
  1055.  
  1056.     /* Place the center_view */
  1057.     _XfeConfigureWidget(cp->center_view,x,y,width,height);
  1058. }
  1059. /*----------------------------------------------------------------------*/
  1060. static void
  1061. LayoutLeftView(Widget w)
  1062. {
  1063.     XfeChromePart *    cp = _XfeChromePart(w);
  1064.     Widget            top = NULL;
  1065.     Widget            bottom = NULL;
  1066.     Position        y1;
  1067.     Position        y2;
  1068.  
  1069.     assert( SHOW_LEFT_VIEW(cp) );
  1070.  
  1071. #if 0
  1072.     /* tool_box is shown */
  1073.     if (SHOW_TOOL_BOX(cp))
  1074.     {
  1075.         top = cp->tool_box;
  1076.     }
  1077.     /* menu_bar is shown */
  1078.     else if (SHOW_MENU_BAR(cp))
  1079.     {
  1080.         top = cp->menu_bar;
  1081.     }
  1082.  
  1083.     if (_XfeIsAlive(top))
  1084.     {
  1085.         y1 = _XfeY(top) + _XfeHeight(top) + cp->spacing;
  1086.     }
  1087.     else
  1088.     {
  1089.         y1 = _XfemRectY(w);
  1090.     }
  1091.  
  1092.     /* Place the top_view */
  1093.     _XfeConfigureWidget(cp->top_view,
  1094.                         
  1095.                         _XfemRectX(w),
  1096.                             
  1097.                         y1,
  1098.                             
  1099.                         _XfemRectWidth(w),
  1100.  
  1101.                         _XfeHeight(cp->top_view));
  1102.  
  1103. #endif
  1104.  
  1105. }
  1106. /*----------------------------------------------------------------------*/
  1107. static void
  1108. LayoutRightView(Widget w)
  1109. {
  1110.     XfeChromePart *    cp = _XfeChromePart(w);
  1111.     Widget            top = NULL;
  1112.     Widget            bottom = NULL;
  1113.     Position        y1;
  1114.     Position        y2;
  1115.  
  1116.     assert( SHOW_RIGHT_VIEW(cp) );
  1117.  
  1118. #if 0
  1119.     /* tool_box is shown */
  1120.     if (SHOW_TOOL_BOX(cp))
  1121.     {
  1122.         top = cp->tool_box;
  1123.     }
  1124.     /* menu_bar is shown */
  1125.     else if (SHOW_MENU_BAR(cp))
  1126.     {
  1127.         top = cp->menu_bar;
  1128.     }
  1129.  
  1130.     if (_XfeIsAlive(top))
  1131.     {
  1132.         y1 = _XfeY(top) + _XfeHeight(top) + cp->spacing;
  1133.     }
  1134.     else
  1135.     {
  1136.         y1 = _XfemRectY(w);
  1137.     }
  1138.  
  1139.     /* Place the top_view */
  1140.     _XfeConfigureWidget(cp->top_view,
  1141.                         
  1142.                         _XfemRectX(w),
  1143.                             
  1144.                         y1,
  1145.                             
  1146.                         _XfemRectWidth(w),
  1147.  
  1148.                         _XfeHeight(cp->top_view));
  1149.  
  1150. #endif
  1151.  
  1152. }
  1153. /*----------------------------------------------------------------------*/
  1154.  
  1155. /*----------------------------------------------------------------------*/
  1156. /*                                                                        */
  1157. /* XfeChrome Public Methods                                                */
  1158. /*                                                                        */
  1159. /*----------------------------------------------------------------------*/
  1160. Widget
  1161. XfeCreateChrome(Widget pw,char * name,Arg * av,Cardinal ac)
  1162. {
  1163.     return XtCreateWidget(name,xfeChromeWidgetClass,pw,av,ac);
  1164. }
  1165. /*----------------------------------------------------------------------*/
  1166. /* extern */ Widget
  1167. XfeChromeGetComponent(Widget chrome,unsigned char component)
  1168. {
  1169.     XfeChromePart *        cp = _XfeChromePart(chrome);
  1170.     Widget                cw = NULL;
  1171.  
  1172.     switch(component)
  1173.     {
  1174.     case XmCHROME_MENU_BAR:
  1175.         cw = cp->menu_bar;
  1176.         break;
  1177.  
  1178.     case XmCHROME_TOOL_BOX:
  1179.         cw = cp->tool_box;
  1180.         break;
  1181.  
  1182.     case XmCHROME_TOP_VIEW:
  1183.         cw = cp->top_view;
  1184.         break;
  1185.  
  1186.     case XmCHROME_CENTER_VIEW:
  1187.         cw = cp->center_view;
  1188.         break;
  1189.  
  1190.     case XmCHROME_BOTTOM_VIEW:
  1191.         cw = cp->bottom_view;
  1192.         break;
  1193.  
  1194.     case XmCHROME_DASH_BOARD:
  1195.         cw = cp->dash_board;
  1196.         break;
  1197.     }
  1198.  
  1199.     return cw;
  1200. }
  1201. /*----------------------------------------------------------------------*/
  1202.