home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / FancyBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  26.2 KB  |  907 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/FancyBox.c>                                        */
  21. /* Description:    XfeFancyBox widget source.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <stdio.h>
  28.  
  29. #include <Xfe/FancyBoxP.h>
  30. #include <Xfe/BypassShellP.h>
  31. #include <Xfe/ListUtilP.h>
  32.  
  33. #include <Xm/TextF.h>
  34. #include <Xm/List.h>
  35.  
  36. #include <Xfe/Button.h>
  37. #include <Xfe/Arrow.h>
  38.  
  39. #define MESSAGE1 "Widget is not an XfeFancyBox."
  40. #define MESSAGE2 "XmNtitle is a read-only resource."
  41. #define MESSAGE3 "XmNlist is a read-only resource."
  42. #define MESSAGE4 "XmNshell is a read-only resource."
  43. #define MESSAGE5 "XmNarrow is a read-only resource."
  44. #define MESSAGE6 "XmNfancyBoxType is a creation-only resource."
  45. #define MESSAGE7 "No valid XfeBypassShell found to share for XmNshell."
  46.  
  47. #define LIST_NAME        "FancyList"
  48. #define SHELL_NAME        "FancyShell"
  49. #define TITLE_NAME        "FancyTitle"
  50. #define ARROW_NAME        "FancyArrow"
  51.  
  52. #define CB_OFFSET_BOTTOM(w,cp)    (cp->highlight_thickness+_XfemOffsetBottom(w))
  53. #define CB_OFFSET_LEFT(w,cp)    (cp->highlight_thickness+_XfemOffsetLeft(w))
  54. #define CB_OFFSET_RIGHT(w,cp)    (cp->highlight_thickness+_XfemOffsetRight(w))
  55. #define CB_OFFSET_TOP(w,cp)        (cp->highlight_thickness+_XfemOffsetTop(w))
  56.  
  57. #define CB_RECT_X(w,cp)            (_XfemRectX(w) + cp->highlight_thickness)
  58. #define CB_RECT_Y(w,cp)            (_XfemRectY(w) + cp->highlight_thickness)
  59. #define CB_RECT_WIDTH(w,cp)        (_XfemRectWidth(w)-2*cp->highlight_thickness)
  60. #define CB_RECT_HEIGHT(w,cp)    (_XfemRectHeight(w)-2*cp->highlight_thickness)
  61.  
  62. /*----------------------------------------------------------------------*/
  63. /*                                                                        */
  64. /* Core class methods                                                    */
  65. /*                                                                        */
  66. /*----------------------------------------------------------------------*/
  67. static void     Initialize            (Widget,Widget,ArgList,Cardinal *);
  68. static void     Destroy                (Widget);
  69. static Boolean    SetValues            (Widget,Widget,Widget,ArgList,Cardinal *);
  70. static void        GetValuesHook        (Widget,ArgList,Cardinal *);
  71.  
  72. /*----------------------------------------------------------------------*/
  73. /*                                                                        */
  74. /* XfeManager class methods                                                */
  75. /*                                                                        */
  76. /*----------------------------------------------------------------------*/
  77. static void        PreferredGeometry    (Widget,Dimension *,Dimension *);
  78. static Boolean    AcceptChild            (Widget);
  79. static Boolean    InsertChild            (Widget);
  80. static Boolean    DeleteChild            (Widget);
  81. static void        LayoutComponents    (Widget);
  82.  
  83. /*----------------------------------------------------------------------*/
  84. /*                                                                        */
  85. /* XfeComboBox class methods                                            */
  86. /*                                                                        */
  87. /*----------------------------------------------------------------------*/
  88. static void        LayoutTitle            (Widget);
  89. static void        DrawTitleShadow        (Widget,XEvent *,Region,XRectangle *);
  90.  
  91. /*----------------------------------------------------------------------*/
  92. /*                                                                        */
  93. /* Misc XfeFancyBox functions                                            */
  94. /*                                                                        */
  95. /*----------------------------------------------------------------------*/
  96. static void            DrawHighlight        (Widget,XEvent *,Region,XRectangle *);
  97.  
  98. static Widget        TitleCreate            (Widget);
  99. static void            LayoutTitle            (Widget);
  100. static void            TitleConfigure        (Widget);
  101.  
  102. static Widget        TitleTextCreate        (Widget);
  103. static Widget        TitleLabelCreate    (Widget);
  104.  
  105. static void            IconLayout            (Widget);
  106.  
  107. static Widget        ShellCreate            (Widget);
  108. static void            ShellLayout            (Widget);
  109.  
  110. static Widget        ArrowCreate            (Widget);
  111. static void            ArrowLayout            (Widget);
  112.  
  113.  
  114. static Widget        ListCreate            (Widget);
  115. static void            ListLayout            (Widget);
  116.  
  117. /*----------------------------------------------------------------------*/
  118. /*                                                                        */
  119. /* Screen functions functions                                            */
  120. /*                                                                        */
  121. /*----------------------------------------------------------------------*/
  122. static int            ScreenGetSpaceBelow    (Widget);
  123. static int            ScreenGetSpaceAbove    (Widget);
  124.  
  125.  
  126. /*----------------------------------------------------------------------*/
  127. /*                                                                        */
  128. /* Text callbacks                                                        */
  129. /*                                                                        */
  130. /*----------------------------------------------------------------------*/
  131. static void            TextFocusCB            (Widget,XtPointer,XtPointer);
  132. static void            TextLosingFocusCB    (Widget,XtPointer,XtPointer);
  133.  
  134. /*----------------------------------------------------------------------*/
  135. /*                                                                        */
  136. /* Arrow callbacks                                                        */
  137. /*                                                                        */
  138. /*----------------------------------------------------------------------*/
  139. static void            ArrowArmCB            (Widget,XtPointer,XtPointer);
  140. static void            ArrowDisarmCB        (Widget,XtPointer,XtPointer);
  141. static void            ArrowActivateCB        (Widget,XtPointer,XtPointer);
  142.  
  143. /*----------------------------------------------------------------------*/
  144. /*                                                                        */
  145. /* Synthetic resource Callprocs                                            */
  146. /*                                                                        */
  147. /*----------------------------------------------------------------------*/
  148. static void            SyntheticGetListItems        (Widget,int, XtArgVal *);
  149. static void            SyntheticGetListItemCount    (Widget,int, XtArgVal *);
  150.  
  151. #if 0
  152. /*
  153.  * External definitions of syn_resources for our list widget.
  154.  */
  155. #define SYN_RESOURCE_AA AA((Widget w, int resource_offset, XtArgVal *value))
  156. extern void _DtFancyBoxGetArrowSize        SYN_RESOURCE_AA;
  157. extern void _DtFancyBoxGetLabelString        SYN_RESOURCE_AA;
  158. extern void _DtFancyBoxGetListItemCount        SYN_RESOURCE_AA;
  159. extern void _DtFancyBoxGetListItems        SYN_RESOURCE_AA;
  160. extern void _DtFancyBoxGetListFontList        SYN_RESOURCE_AA;
  161. extern void _DtFancyBoxGetListMarginHeight    SYN_RESOURCE_AA;
  162. extern void _DtFancyBoxGetListMarginWidth    SYN_RESOURCE_AA;
  163. extern void _DtFancyBoxGetListSpacing        SYN_RESOURCE_AA;
  164. extern void _DtFancyBoxGetListTopItemPosition    SYN_RESOURCE_AA;
  165. extern void _DtFancyBoxGetListVisibleItemCount    SYN_RESOURCE_AA;
  166. #endif
  167.  
  168. /*----------------------------------------------------------------------*/
  169. /*                                                                        */
  170. /* XfeFancyBox resources                                                */
  171. /*                                                                        */
  172. /*----------------------------------------------------------------------*/
  173. static XtResource resources[] =     
  174. {                    
  175. #if 0
  176.     /* Title resources */
  177.     {
  178.         XmNtitle,
  179.         XmCReadOnly,
  180.         XmRWidget,
  181.         sizeof(Widget),
  182.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . title),
  183.         XmRImmediate, 
  184.         (XtPointer) NULL
  185.     },
  186.     { 
  187.         XmNcomboBoxType,
  188.         XmCComboBoxType,
  189.         XmRComboBoxType,
  190.         sizeof(unsigned char),
  191.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . combo_box_type),
  192.         XmRImmediate, 
  193.         (XtPointer) XmCOMBO_BOX_READ_ONLY
  194.     },
  195.     { 
  196.         XmNtitleFontList,
  197.         XmCTitleFontList,
  198.         XmRFontList,
  199.         sizeof(XmFontList),
  200.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . title_font_list),
  201.         XmRImmediate, 
  202.         (XtPointer) NULL
  203.     },
  204.     {
  205.         XmNtitleShadowThickness,
  206.         XmCShadowThickness,
  207.         XmRHorizontalDimension,
  208.         sizeof(Dimension),
  209.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . title_shadow_thickness),
  210.         XmRCallProc, 
  211.         (XtPointer) DefaultTitleShadowThickness
  212.     },
  213.     {
  214.         XmNtitleShadowType,
  215.         XmCShadowType,
  216.         XmRShadowType,
  217.         sizeof(unsigned char),
  218.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . title_shadow_type),
  219.         XmRImmediate, 
  220.         (XtPointer) XmSHADOW_IN
  221.     },
  222. #endif
  223.  
  224.     /* Icon resources */
  225.     {
  226.         XmNicon,
  227.         XmCReadOnly,
  228.         XmRWidget,
  229.         sizeof(Widget),
  230.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . icon),
  231.         XmRImmediate, 
  232.         (XtPointer) NULL
  233.     },
  234.  
  235.  
  236. #if 0
  237.     /* List resources */
  238.     {
  239.         XmNlist,
  240.         XmCReadOnly,
  241.         XmRWidget,
  242.         sizeof(Widget),
  243.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . list),
  244.         XmRImmediate, 
  245.         (XtPointer) NULL
  246.     },
  247.     {
  248.         XmNitems,
  249.         XmCItems,
  250.         XmRXmStringTable,
  251.         sizeof(XmStringTable),
  252.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . items),
  253.         XmRImmediate, 
  254.         (XtPointer) NULL
  255.     },
  256.     {
  257.         XmNitemCount,
  258.         XmCItemCount,
  259.         XmRInt,
  260.         sizeof(int),
  261.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . item_count),
  262.         XmRImmediate, 
  263.         (XtPointer) 0
  264.     },
  265.     { 
  266.         XmNlistFontList,
  267.         XmCListFontList,
  268.         XmRFontList,
  269.         sizeof(XmFontList),
  270.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . list_font_list),
  271.         XmRImmediate, 
  272.         (XtPointer) NULL
  273.     },
  274.     { 
  275.         XmNlistMarginHeight,
  276.         XmCListMarginHeight,
  277.         XmRVerticalDimension,
  278.         sizeof(Dimension),
  279.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . list_margin_height),
  280.         XmRImmediate, 
  281.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_MARGIN_HEIGHT
  282.     },
  283.     { 
  284.         XmNlistMarginWidth,
  285.         XmCListMarginWidth,
  286.         XmRHorizontalDimension,
  287.         sizeof(Dimension),
  288.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . list_margin_width),
  289.         XmRImmediate, 
  290.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_MARGIN_WIDTH
  291.     },
  292.     { 
  293.         XmNlistSpacing,
  294.         XmCListSpacing,
  295.         XmRVerticalDimension,
  296.         sizeof(Dimension),
  297.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . list_spacing),
  298.         XmRImmediate, 
  299.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_SPACING
  300.     },
  301.     {
  302.         XmNtopItemPosition,
  303.         XmCTopItemPosition,
  304.         XmRInt,
  305.         sizeof(int),
  306.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . top_item_position),
  307.         XmRImmediate, 
  308.         (XtPointer) 1
  309.     },
  310.     {
  311.         XmNvisibleItemCount,
  312.         XmCVisibleItemCount,
  313.         XmRInt,
  314.         sizeof(int),
  315.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . visible_item_count),
  316.         XmRImmediate, 
  317.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_VISIBLE_ITEM_COUNT
  318.     },
  319.  
  320.     /* Shell resources */
  321.     {
  322.         XmNshell,
  323.         XmCReadOnly,
  324.         XmRWidget,
  325.         sizeof(Widget),
  326.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . shell),
  327.         XmRImmediate, 
  328.         (XtPointer) NULL
  329.     },
  330.     { 
  331.         XmNshareShell,
  332.         XmCShareShell,
  333.         XmRBoolean,
  334.         sizeof(Boolean),
  335.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . share_shell),
  336.         XmRImmediate, 
  337.         (XtPointer) True
  338.     },
  339.     { 
  340.         XmNpoppedUp,
  341.         XmCReadOnly,
  342.         XmRBoolean,
  343.         sizeof(Boolean),
  344.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . popped_up),
  345.         XmRImmediate, 
  346.         (XtPointer) False
  347.     },
  348.  
  349.  
  350.     /* Arrow resources */
  351.     {
  352.         XmNarrow,
  353.         XmCReadOnly,
  354.         XmRWidget,
  355.         sizeof(Widget),
  356.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . arrow),
  357.         XmRImmediate, 
  358.         (XtPointer) NULL
  359.     },
  360.  
  361.     /* Traversal resources */
  362.     {
  363.         XmNhighlightThickness,
  364.         XmCHighlightThickness,
  365.         XmRHorizontalDimension,
  366.         sizeof(Dimension),
  367.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . highlight_thickness),
  368.         XmRImmediate, 
  369.         (XtPointer) 2
  370.     },
  371.     { 
  372.         XmNtraversalOn,
  373.         XmCTraversalOn,
  374.         XmRBoolean,
  375.         sizeof(Boolean),
  376.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . traversal_on),
  377.         XmRImmediate, 
  378.         (XtPointer) True
  379.     },
  380.  
  381.     /* Force the XmNshadowThickness to the default */
  382.     { 
  383.         XmNshadowThickness,
  384.         XmCShadowThickness,
  385.         XmRHorizontalDimension,
  386.         sizeof(Dimension),
  387.         XtOffsetOf(XfeFancyBoxRec , manager . shadow_thickness),
  388.         XmRImmediate, 
  389.         (XtPointer) XfeDEFAULT_SHADOW_THICKNESS
  390.     },
  391.  
  392.     /* Force XmNmarginLeft and XmNmarginRight to 4 */
  393.     { 
  394.         XmNmarginLeft,
  395.         XmCMarginLeft,
  396.         XmRHorizontalDimension,
  397.         sizeof(Dimension),
  398.         XtOffsetOf(XfeFancyBoxRec , xfe_manager . margin_left),
  399.         XmRImmediate, 
  400.         (XtPointer) 4
  401.     },
  402.     { 
  403.         XmNmarginRight,
  404.         XmCMarginRight,
  405.         XmRHorizontalDimension,
  406.         sizeof(Dimension),
  407.         XtOffsetOf(XfeFancyBoxRec , xfe_manager . margin_right),
  408.         XmRImmediate, 
  409.         (XtPointer) 4
  410.     },
  411. #endif
  412.  
  413. };   
  414.  
  415. #if 0
  416. /*----------------------------------------------------------------------*/
  417. /*                                                                        */
  418. /* XfeFancyBox synthetic resources                                        */
  419. /*                                                                        */
  420. /*----------------------------------------------------------------------*/
  421. static XmSyntheticResource synthetic_resources[] =
  422. {
  423.     { 
  424.         XmNitems,
  425.         sizeof(XmStringTable),
  426.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . items),
  427.         SyntheticGetListItems,
  428.         _XfeSyntheticSetResourceForChild 
  429.     },
  430.     { 
  431.         XmNitemCount,
  432.         sizeof(int),
  433.         XtOffsetOf(XfeFancyBoxRec , xfe_fancy_box . item_count),
  434.         SyntheticGetListItemCount,
  435.         _XfeSyntheticSetResourceForChild 
  436.     },
  437. };
  438. #endif
  439.  
  440. /*----------------------------------------------------------------------*/
  441. /*                                                                        */
  442. /* Widget Class Record Initialization                                   */
  443. /*                                                                        */
  444. /*----------------------------------------------------------------------*/
  445. _XFE_WIDGET_CLASS_RECORD(fancybox,FancyBox) =
  446. {
  447.     {
  448.         (WidgetClass) &xfeComboBoxClassRec,        /* superclass            */
  449.         "XfeFancyBox",                            /* class_name            */
  450.         sizeof(XfeFancyBoxRec),                    /* widget_size            */
  451.         NULL,                                    /* class_initialize        */
  452.         NULL,                                    /* class_part_initialize*/
  453.         FALSE,                                    /* class_inited            */
  454.         Initialize,                                /* initialize            */
  455.         NULL,                                    /* initialize_hook        */
  456.         XtInheritRealize,                        /* realize                */
  457.         NULL,                                    /* actions                */
  458.         0,                                        /* num_actions            */
  459.         resources,                              /* resources            */
  460.         XtNumber(resources),                    /* num_resources        */
  461.         NULLQUARK,                              /* xrm_class            */
  462.         TRUE,                                   /* compress_motion        */
  463.         XtExposeCompressMaximal,                /* compress_exposure    */
  464.         TRUE,                                   /* compress_enterleave    */
  465.         FALSE,                                  /* visible_interest        */
  466.         Destroy,                                /* destroy                */
  467.         XtInheritResize,                        /* resize                */
  468.         XtInheritExpose,                        /* expose                */
  469.         SetValues,                              /* set_values            */
  470.         NULL,                                   /* set_values_hook        */
  471.         XtInheritSetValuesAlmost,                /* set_values_almost    */
  472.         GetValuesHook,                            /* get_values_hook        */
  473.         NULL,                                   /* access_focus            */
  474.         XtVersion,                              /* version                */
  475.         NULL,                                   /* callback_private        */
  476.         XtInheritTranslations,                    /* tm_table                */
  477.         XtInheritQueryGeometry,                    /* query_geometry        */
  478.         XtInheritDisplayAccelerator,            /* display accelerator    */
  479.         NULL,                                   /* extension            */
  480.     },
  481.     
  482.     /* Composite Part */
  483.     {
  484.         XtInheritGeometryManager,                /* geometry_manager        */
  485.         XtInheritChangeManaged,                    /* change_managed        */
  486.         XtInheritInsertChild,                    /* insert_child            */
  487.         XtInheritDeleteChild,                    /* delete_child            */
  488.         NULL                                    /* extension            */
  489.     },
  490.  
  491.     /* Constraint Part */
  492.     {
  493.         NULL,                                    /* syn resources        */
  494.         0,                                        /* num syn_resources    */
  495.         sizeof(XfeManagerConstraintRec),        /* constraint size        */
  496.         NULL,                                    /* init proc            */
  497.         NULL,                                    /* destroy proc            */
  498.         NULL,                                    /* set values proc        */
  499.         NULL,                                   /* extension            */
  500.     },
  501.  
  502.     /* XmManager Part */
  503.     {
  504.         XtInheritTranslations,                    /* tm_table                */
  505. #if 0
  506.         synthetic_resources,                    /* syn resources        */
  507.         XtNumber(synthetic_resources),            /* num syn_resources    */
  508. #else
  509.         NULL,                                    /* syn resources        */
  510.         0,                                        /* num syn_resources    */
  511. #endif
  512.         NULL,                                   /* syn_cont_resources      */
  513.         0,                                      /* num_syn_cont_resource*/
  514.         XmInheritParentProcess,                 /* parent_process        */
  515.         NULL,                                   /* extension            */
  516.     },
  517.     
  518.     /* XfeManager Part     */
  519.     {
  520.         XfeInheritBitGravity,                    /* bit_gravity            */
  521.         PreferredGeometry,                        /* preferred_geometry    */
  522.         XfeInheritMinimumGeometry,                /* minimum_geometry        */
  523.         XfeInheritUpdateRect,                    /* update_rect            */
  524.         AcceptChild,                            /* accept_child            */
  525.         InsertChild,                            /* insert_child            */
  526.         DeleteChild,                            /* delete_child            */
  527.         NULL,                                    /* change_managed        */
  528.         NULL,                                    /* prepare_components    */
  529.         LayoutComponents,                        /* layout_components    */
  530.         NULL,                                    /* layout_children        */
  531.         NULL,                                    /* draw_background        */
  532.         XfeInheritDrawShadow,                    /* draw_shadow            */
  533.         XfeInheritDrawComponents,                /* draw_components        */
  534.         NULL,                                    /* extension            */
  535.     },
  536.  
  537.     /* XfeComboBox Part */
  538.     {
  539.         LayoutTitle,                            /* layout_title            */
  540.         XfeInheritLayoutArrow,                    /* layout_arrow            */
  541.         XfeInheritDrawHighlight,                /* draw_highlight        */
  542.         DrawTitleShadow,                        /* draw_title_shadow    */
  543.         NULL,                                    /* extension            */
  544.     },
  545.  
  546.     /* XfeFancyBox Part */
  547.     {
  548.         NULL,                                    /* extension            */
  549.     },
  550. };
  551.  
  552. /*----------------------------------------------------------------------*/
  553. /*                                                                        */
  554. /* xfeFancyBoxWidgetClass declaration.                                    */
  555. /*                                                                        */
  556. /*----------------------------------------------------------------------*/
  557. _XFE_WIDGET_CLASS(fancybox,FancyBox);
  558.  
  559. /*----------------------------------------------------------------------*/
  560. /*                                                                        */
  561. /* Synthetic resource Callprocs                                            */
  562. /*                                                                        */
  563. /*----------------------------------------------------------------------*/
  564. static void
  565. SyntheticGetListItems(Widget w,int offset, XtArgVal * value)
  566. {
  567. }
  568. /*----------------------------------------------------------------------*/
  569. static void
  570. SyntheticGetListItemCount(Widget w,int offset, XtArgVal * value)
  571. {
  572. }
  573. /*----------------------------------------------------------------------*/
  574.  
  575. /*----------------------------------------------------------------------*/
  576. /*                                                                        */
  577. /* Core Class methods                                                    */
  578. /*                                                                        */
  579. /*----------------------------------------------------------------------*/
  580. static void
  581. Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  582. {
  583.     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(nw);
  584.  
  585. #if 0
  586.     /* Make sure rep types are ok */
  587.     XfeRepTypeCheck(nw,XmRShadowType,&fp->title_shadow_type,
  588.                     XmSHADOW_IN);
  589.  
  590.     XfeRepTypeCheck(nw,XmRComboBoxType,&fp->combo_box_type,
  591.                     XmCOMBO_BOX_READ_ONLY);
  592.  
  593.     /* Make sure read-only resources aren't set */
  594.     if (fp->title)
  595.     {
  596.         _XmWarning(nw,MESSAGE2);
  597.  
  598.         fp->title = NULL;
  599.     }
  600.  
  601.     if (fp->list)
  602.     {
  603.         _XmWarning(nw,MESSAGE3);
  604.  
  605.         fp->list = NULL;
  606.     }
  607.  
  608.     if (fp->shell)
  609.     {
  610.         _XmWarning(nw,MESSAGE4);
  611.  
  612.         fp->shell = NULL;
  613.     }
  614.  
  615.     if (fp->arrow)
  616.     {
  617.         _XmWarning(nw,MESSAGE5);
  618.  
  619.         fp->arrow = NULL;
  620.     }
  621.     
  622.     /* Create components */
  623.     fp->arrow        = ArrowCreate(nw);
  624.     fp->title        = TitleCreate(nw);
  625.     fp->shell        = ShellCreate(nw);
  626.     fp->list        = ListCreate(nw);
  627.  
  628.     /* Configure the title */
  629.     TitleConfigure(nw);
  630.  
  631.     /* Initialize private members */
  632.     fp->highlighted = False;
  633.  
  634.  
  635.     /* Manage the children */
  636.     XtManageChild(fp->title);
  637.     XtManageChild(fp->list);
  638.     XtManageChild(fp->arrow);
  639.  
  640. /*      XfeOverrideTranslations(nw,_XfeFancyBoxExtraTranslations); */
  641. #endif
  642.  
  643.     /* Finish of initialization */
  644.     _XfeManagerChainInitialize(rw,nw,xfeFancyBoxWidgetClass);
  645. }
  646. /*----------------------------------------------------------------------*/
  647. static void
  648. Destroy(Widget w)
  649. {
  650. /*     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(w); */
  651. }
  652. /*----------------------------------------------------------------------*/
  653. static Boolean
  654. SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  655. {
  656.     XfeFancyBoxPart *        np = _XfeFancyBoxPart(nw);
  657.     XfeFancyBoxPart *        op = _XfeFancyBoxPart(ow);
  658.  
  659.  
  660.     return _XfeManagerChainSetValues(ow,rw,nw,xfeFancyBoxWidgetClass);
  661. }
  662. /*----------------------------------------------------------------------*/
  663. static void
  664. GetValuesHook(Widget w,ArgList args,Cardinal* nargs)
  665. {
  666. /*     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(w); */
  667.     Cardinal                i;
  668.     
  669.     for (i = 0; i < *nargs; i++)
  670.     {
  671. #if 0
  672.         /* label_string */
  673.         if (strcmp(args[i].name,XmNlabelString) == 0)
  674.         {
  675.             *((XtArgVal *) args[i].value) = 
  676.                 (XtArgVal) XmStringCopy(lp->label_string);
  677.         }
  678.         /* font_list */
  679.         else if (strcmp(args[i].name,XmNfontList) == 0)
  680.         {
  681.             *((XtArgVal *) args[i].value) = 
  682.                 (XtArgVal) XmFontListCopy(lp->font_list);
  683.         }      
  684. #endif
  685.     }
  686. }
  687. /*----------------------------------------------------------------------*/
  688.  
  689. /*----------------------------------------------------------------------*/
  690. /*                                                                        */
  691. /* XfeManager class methods                                                */
  692. /*                                                                        */
  693. /*----------------------------------------------------------------------*/
  694. static void
  695. PreferredGeometry(Widget w,Dimension * width,Dimension * height)
  696. {
  697.     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(w);
  698.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  699.  
  700.     /* Invoke the super class' preferred_geometry method */
  701.     (*xfeComboBoxClassRec.xfe_manager_class.preferred_geometry)(w,
  702.                                                                 width,
  703.                                                                 height);
  704.  
  705.     /* Add the icon widht if needed */
  706.     if (_XfeChildIsShown(fp->icon))
  707.     {
  708.         *width  += (cp->spacing + _XfeWidth(fp->icon));
  709.     }
  710. }
  711. /*----------------------------------------------------------------------*/
  712. static Boolean
  713. AcceptChild(Widget child)
  714. {
  715.     Widget                    w = _XfeParent(child);
  716.     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(w);
  717.  
  718.     return (!_XfeIsAlive(fp->icon) && XfeIsButton(child));
  719. }
  720. /*----------------------------------------------------------------------*/
  721. static Boolean
  722. InsertChild(Widget child)
  723. {
  724.     Widget                    w = _XfeParent(child);
  725.     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(w);
  726.  
  727.     fp->icon = child;
  728.  
  729.     return True;
  730. }
  731. /*----------------------------------------------------------------------*/
  732. static Boolean
  733. DeleteChild(Widget child)
  734. {
  735.     Widget                    w = _XfeParent(child);
  736.     XfeFancyBoxPart *        fp = _XfeFancyBoxPart(w);
  737.  
  738.     fp->icon = NULL;
  739.  
  740.     return True;
  741. }
  742. /*----------------------------------------------------------------------*/
  743. static void
  744. LayoutComponents(Widget w)
  745. {
  746.     /* Layout the arrow */
  747.     _XfeComboBoxLayoutArrow(w);
  748.  
  749.     /* Layout the title */
  750.     _XfeComboBoxLayoutTitle(w);
  751.  
  752.     /* Layout the icon if needed */
  753.     IconLayout(w);
  754. }
  755. /*----------------------------------------------------------------------*/
  756.  
  757. /*----------------------------------------------------------------------*/
  758. /*                                                                        */
  759. /* Misc XfeFancyBox functions                                            */
  760. /*                                                                        */
  761. /*----------------------------------------------------------------------*/
  762. static void
  763. DrawTitleShadow(Widget w,XEvent * event,Region region,XRectangle * clip_rect)
  764. {
  765.     XfeFancyBoxPart *    fp = _XfeFancyBoxPart(w);
  766.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  767.  
  768.     /* Make sure the shadow is needed */
  769.     if (!cp->title_shadow_thickness)
  770.     {
  771.         return;
  772.     }
  773.  
  774.     if (_XfeIsAlive(fp->icon))
  775.     {
  776.         Dimension icon_x1 = _XfeX(fp->icon) - cp->spacing;
  777.         Dimension title_x2 = _XfeX(cp->title) + _XfeWidth(cp->title);
  778.  
  779.         /* Draw the shadow around the icon and text */
  780.         _XmDrawShadows(XtDisplay(w),
  781.                        _XfeWindow(w),
  782.                        _XfemTopShadowGC(w),_XfemBottomShadowGC(w),
  783.                        
  784.                        CB_OFFSET_LEFT(w,cp),
  785.                        
  786.                        _XfeY(cp->title) - 
  787.                        cp->title_shadow_thickness,
  788.  
  789.                        (title_x2 - icon_x1) + 
  790.                        2 * cp->title_shadow_thickness,
  791.                        
  792.                        _XfeHeight(cp->title) + 
  793.                        2 * cp->title_shadow_thickness,
  794.                        
  795.                        cp->title_shadow_thickness,
  796.                        cp->title_shadow_type);
  797.     }
  798.     else
  799.     {
  800.         /* Draw the shadow around the text only */
  801.         XfeDrawShadowsAroundWidget(w,
  802.                                    cp->title,
  803.                                    _XfemTopShadowGC(w),
  804.                                    _XfemBottomShadowGC(w),
  805.                                    0,
  806.                                    cp->title_shadow_thickness,
  807.                                    cp->title_shadow_type);
  808.     }
  809. }
  810. /*----------------------------------------------------------------------*/
  811. static void
  812. LayoutTitle(Widget w)
  813. {
  814.     XfeFancyBoxPart *    fp = _XfeFancyBoxPart(w);
  815.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  816.     int                    x;
  817.     int                    total_icon_width = 0;
  818.  
  819.     if (_XfeIsAlive(fp->icon))
  820.     {
  821.         x = _XfeX(fp->icon) + _XfeWidth(fp->icon);
  822.  
  823.         total_icon_width = _XfeWidth(fp->icon) + cp->spacing;
  824.     }
  825.     else
  826.     {
  827.         x = CB_OFFSET_LEFT(w,cp) + cp->title_shadow_thickness;
  828.     }
  829.  
  830.     _XfeConfigureWidget(cp->title,
  831.  
  832.                         x,
  833.  
  834.                         (_XfeHeight(w) - _XfeHeight(cp->title)) / 2,
  835.                         
  836.                         CB_RECT_WIDTH(w,cp) - 
  837.                         cp->spacing -
  838.                         _XfeWidth(cp->arrow) -
  839.                         total_icon_width -
  840.                         2 * cp->title_shadow_thickness,
  841.                         
  842.                         CB_RECT_HEIGHT(w,cp) - 
  843.                         2 * cp->title_shadow_thickness);
  844. }
  845. /*----------------------------------------------------------------------*/
  846. static void
  847. IconLayout(Widget w)
  848. {
  849.     XfeFancyBoxPart *    fp = _XfeFancyBoxPart(w);
  850.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  851.  
  852.     if (!_XfeIsAlive(fp->icon))
  853.     {
  854.         return;
  855.     }
  856.  
  857.     _XfeConfigureWidget(fp->icon,
  858.  
  859.                         CB_OFFSET_LEFT(w,cp) + 
  860.                         cp->title_shadow_thickness +
  861.                         cp->spacing,
  862.  
  863.                         (_XfeHeight(w) - _XfeHeight(fp->icon)) / 2,
  864.  
  865.                         _XfeWidth(fp->icon),
  866.  
  867.                         _XfeHeight(fp->icon));
  868. }
  869. /*----------------------------------------------------------------------*/
  870.  
  871. /*----------------------------------------------------------------------*/
  872. /*                                                                        */
  873. /* Misc Arrow functions                                                    */
  874. /*                                                                        */
  875. /*----------------------------------------------------------------------*/
  876.  
  877. /*----------------------------------------------------------------------*/
  878. /*                                                                        */
  879. /* Screen functions functions                                            */
  880. /*                                                                        */
  881. /*----------------------------------------------------------------------*/
  882. static int
  883. ScreenGetSpaceBelow(Widget w)
  884. {
  885.     return (int) XfeScreenHeight(w) - (int) (XfeRootY(w) + _XfeHeight(w));
  886. }
  887. /*----------------------------------------------------------------------*/
  888. static int
  889. ScreenGetSpaceAbove(Widget w)
  890. {
  891.     return (int) XfeRootY(w);
  892. }
  893. /*----------------------------------------------------------------------*/
  894.  
  895.  
  896. /*----------------------------------------------------------------------*/
  897. /*                                                                        */
  898. /* XfeFancyBox Public Methods                                            */
  899. /*                                                                        */
  900. /*----------------------------------------------------------------------*/
  901. /* extern */ Widget
  902. XfeCreateFancyBox(Widget pw,char * name,Arg * av,Cardinal ac)
  903. {
  904.     return XtCreateWidget(name,xfeFancyBoxWidgetClass,pw,av,ac);
  905. }
  906. /*----------------------------------------------------------------------*/
  907.