home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / ComboBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  45.4 KB  |  1,603 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/ComboBox.c>                                        */
  21. /* Description:    XfeComboBox widget source.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <stdio.h>
  28.  
  29. #include <Xfe/ComboBoxP.h>
  30. #include <Xfe/ListUtilP.h>
  31.  
  32. #include <Xfe/FrameShell.h>
  33. #include <Xfe/BypassShell.h>
  34.  
  35. #include <Xm/TextF.h>
  36. #include <Xm/List.h>
  37.  
  38. #include <Xfe/Button.h>
  39. #include <Xfe/Arrow.h>
  40.  
  41. #define MESSAGE1 "Widget is not an XfeComboBox."
  42. #define MESSAGE2 "XmNtitle is a read-only resource."
  43. #define MESSAGE3 "XmNlist is a read-only resource."
  44. #define MESSAGE4 "XmNshell is a read-only resource."
  45. #define MESSAGE5 "XmNarrow is a read-only resource."
  46. #define MESSAGE6 "XmNcomboBoxType is a creation-only resource."
  47. #define MESSAGE7 "No valid XfeBypassShell found to share for XmNshell."
  48.  
  49. #define LIST_NAME        "ComboList"
  50. #define SHELL_NAME        "ComboShell"
  51. #define TITLE_NAME        "ComboTitle"
  52. #define ARROW_NAME        "ComboArrow"
  53.  
  54. #define CB_OFFSET_BOTTOM(w,cp)    (cp->highlight_thickness+_XfemOffsetBottom(w))
  55. #define CB_OFFSET_LEFT(w,cp)    (cp->highlight_thickness+_XfemOffsetLeft(w))
  56. #define CB_OFFSET_RIGHT(w,cp)    (cp->highlight_thickness+_XfemOffsetRight(w))
  57. #define CB_OFFSET_TOP(w,cp)        (cp->highlight_thickness+_XfemOffsetTop(w))
  58.  
  59. #define CB_RECT_X(w,cp)            (_XfemRectX(w) + cp->highlight_thickness)
  60. #define CB_RECT_Y(w,cp)            (_XfemRectY(w) + cp->highlight_thickness)
  61. #define CB_RECT_WIDTH(w,cp)        (_XfemRectWidth(w)-2*cp->highlight_thickness)
  62. #define CB_RECT_HEIGHT(w,cp)    (_XfemRectHeight(w)-2*cp->highlight_thickness)
  63.  
  64. #define STICK_DELAY 200
  65.  
  66. /*----------------------------------------------------------------------*/
  67. /*                                                                        */
  68. /* Core class methods                                                    */
  69. /*                                                                        */
  70. /*----------------------------------------------------------------------*/
  71. static void        ClassPartInit        (WidgetClass);
  72. static void     Initialize            (Widget,Widget,ArgList,Cardinal *);
  73. static void     Destroy                (Widget);
  74. static Boolean    SetValues            (Widget,Widget,Widget,ArgList,Cardinal *);
  75. static void        GetValuesHook        (Widget,ArgList,Cardinal *);
  76.  
  77. /*----------------------------------------------------------------------*/
  78. /*                                                                        */
  79. /* XfeManager class methods                                                */
  80. /*                                                                        */
  81. /*----------------------------------------------------------------------*/
  82. static void        PreferredGeometry    (Widget,Dimension *,Dimension *);
  83. static Boolean    AcceptChild            (Widget);
  84. static void        LayoutComponents    (Widget);
  85. static void        DrawShadow            (Widget,XEvent *,Region,XRectangle *);
  86. static void        DrawComponents        (Widget,XEvent *,Region,XRectangle *);
  87.  
  88. /*----------------------------------------------------------------------*/
  89. /*                                                                        */
  90. /* XfeComboBox class methods                                            */
  91. /*                                                                        */
  92. /*----------------------------------------------------------------------*/
  93. static void        LayoutTitle            (Widget);
  94. static void        LayoutArrow            (Widget);
  95. static void        DrawHighlight        (Widget,XEvent *,Region,XRectangle *);
  96. static void        DrawTitleShadow        (Widget,XEvent *,Region,XRectangle *);
  97.  
  98. /*----------------------------------------------------------------------*/
  99. /*                                                                        */
  100. /* XfeComboBox action procedures                                        */
  101. /*                                                                        */
  102. /*----------------------------------------------------------------------*/
  103. static void     ActionPopdown        (Widget,XEvent *,char **,Cardinal *);
  104. static void     ActionPopup            (Widget,XEvent *,char **,Cardinal *);
  105. static void     ActionHighlight        (Widget,XEvent *,char **,Cardinal *);
  106.  
  107. /*----------------------------------------------------------------------*/
  108. /*                                                                        */
  109. /* Misc XfeComboBox functions                                            */
  110. /*                                                                        */
  111. /*----------------------------------------------------------------------*/
  112.  
  113. static Widget        TitleCreate            (Widget);
  114. static void            TitleConfigure        (Widget);
  115.  
  116. static Widget        TitleTextCreate        (Widget);
  117. static Widget        TitleLabelCreate    (Widget);
  118.  
  119. static Widget        ArrowCreate            (Widget);
  120.  
  121.  
  122. /*----------------------------------------------------------------------*/
  123. /*                                                                        */
  124. /* List functions                                                        */
  125. /*                                                                        */
  126. /*----------------------------------------------------------------------*/
  127. static Widget        ListCreate            (Widget);
  128. static void            ListLayout            (Widget);
  129. static void            ListManage            (Widget);
  130. static void            ListUnmanage        (Widget);
  131.  
  132. /*----------------------------------------------------------------------*/
  133. /*                                                                        */
  134. /* Stick functions                                                        */
  135. /*                                                                        */
  136. /*----------------------------------------------------------------------*/
  137. static void        StickTimeout        (XtPointer,XtIntervalId *);
  138. static void        StickAddTimeout        (Widget);
  139. static void        StickRemoveTimeout    (Widget);
  140.  
  141. /*----------------------------------------------------------------------*/
  142. /*                                                                        */
  143. /* Shell functions                                                        */
  144. /*                                                                        */
  145. /*----------------------------------------------------------------------*/
  146. static Widget        ShellCreate            (Widget);
  147. static void            ShellLayout            (Widget);
  148. static void            ShellPopup            (Widget);
  149. static void            ShellPopdown        (Widget);
  150.  
  151. /*----------------------------------------------------------------------*/
  152. /*                                                                        */
  153. /* Screen functions functions                                            */
  154. /*                                                                        */
  155. /*----------------------------------------------------------------------*/
  156. static int            ScreenGetSpaceBelow    (Widget);
  157. static int            ScreenGetSpaceAbove    (Widget);
  158.  
  159.  
  160. /*----------------------------------------------------------------------*/
  161. /*                                                                        */
  162. /* Text callbacks                                                        */
  163. /*                                                                        */
  164. /*----------------------------------------------------------------------*/
  165. static void            TextFocusCB            (Widget,XtPointer,XtPointer);
  166. static void            TextLosingFocusCB    (Widget,XtPointer,XtPointer);
  167.  
  168. /*----------------------------------------------------------------------*/
  169. /*                                                                        */
  170. /* Arrow callbacks                                                        */
  171. /*                                                                        */
  172. /*----------------------------------------------------------------------*/
  173. static void            ArrowActivateCB        (Widget,XtPointer,XtPointer);
  174.  
  175. /*----------------------------------------------------------------------*/
  176. /*                                                                        */
  177. /* Resource Callprocs                                                    */
  178. /*                                                                        */
  179. /*----------------------------------------------------------------------*/
  180. static void            DefaultTitleShadowThickness    (Widget,int,XrmValue *);
  181.  
  182. /*----------------------------------------------------------------------*/
  183. /*                                                                        */
  184. /* Synthetic resource Callprocs                                            */
  185. /*                                                                        */
  186. /*----------------------------------------------------------------------*/
  187. static void            SyntheticGetListItems        (Widget,int, XtArgVal *);
  188. static void            SyntheticGetListItemCount    (Widget,int, XtArgVal *);
  189.  
  190. #if 0
  191. /*
  192.  * External definitions of syn_resources for our list widget.
  193.  */
  194. #define SYN_RESOURCE_AA AA((Widget w, int resource_offset, XtArgVal *value))
  195. extern void _DtComboBoxGetArrowSize        SYN_RESOURCE_AA;
  196. extern void _DtComboBoxGetLabelString        SYN_RESOURCE_AA;
  197. extern void _DtComboBoxGetListItemCount        SYN_RESOURCE_AA;
  198. extern void _DtComboBoxGetListItems        SYN_RESOURCE_AA;
  199. extern void _DtComboBoxGetListFontList        SYN_RESOURCE_AA;
  200. extern void _DtComboBoxGetListMarginHeight    SYN_RESOURCE_AA;
  201. extern void _DtComboBoxGetListMarginWidth    SYN_RESOURCE_AA;
  202. extern void _DtComboBoxGetListSpacing        SYN_RESOURCE_AA;
  203. extern void _DtComboBoxGetListTopItemPosition    SYN_RESOURCE_AA;
  204. extern void _DtComboBoxGetListVisibleItemCount    SYN_RESOURCE_AA;
  205. #endif
  206.  
  207. /*----------------------------------------------------------------------*/
  208. /*                                                                        */
  209. /* XfeComboBox resources                                                */
  210. /*                                                                        */
  211. /*----------------------------------------------------------------------*/
  212. static XtResource resources[] =     
  213. {                    
  214.     /* Title resources */
  215.     {
  216.         XmNtitle,
  217.         XmCReadOnly,
  218.         XmRWidget,
  219.         sizeof(Widget),
  220.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . title),
  221.         XmRImmediate, 
  222.         (XtPointer) NULL
  223.     },
  224.     { 
  225.         XmNcomboBoxType,
  226.         XmCComboBoxType,
  227.         XmRComboBoxType,
  228.         sizeof(unsigned char),
  229.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . combo_box_type),
  230.         XmRImmediate, 
  231.         (XtPointer) XmCOMBO_BOX_READ_ONLY
  232.     },
  233.     { 
  234.         XmNspacing,
  235.         XmCSpacing,
  236.         XmRHorizontalDimension,
  237.         sizeof(Dimension),
  238.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . spacing),
  239.         XmRImmediate, 
  240.         (XtPointer) 4
  241.     },
  242.     { 
  243.         XmNtitleFontList,
  244.         XmCTitleFontList,
  245.         XmRFontList,
  246.         sizeof(XmFontList),
  247.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . title_font_list),
  248.         XmRImmediate, 
  249.         (XtPointer) NULL
  250.     },
  251.     {
  252.         XmNtitleShadowThickness,
  253.         XmCShadowThickness,
  254.         XmRHorizontalDimension,
  255.         sizeof(Dimension),
  256.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . title_shadow_thickness),
  257.         XmRCallProc, 
  258.         (XtPointer) DefaultTitleShadowThickness
  259.     },
  260.     {
  261.         XmNtitleShadowType,
  262.         XmCShadowType,
  263.         XmRShadowType,
  264.         sizeof(unsigned char),
  265.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . title_shadow_type),
  266.         XmRImmediate, 
  267.         (XtPointer) XmSHADOW_IN
  268.     },
  269.  
  270.     /* List resources */
  271.     {
  272.         XmNlist,
  273.         XmCReadOnly,
  274.         XmRWidget,
  275.         sizeof(Widget),
  276.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . list),
  277.         XmRImmediate, 
  278.         (XtPointer) NULL
  279.     },
  280.     {
  281.         XmNitems,
  282.         XmCItems,
  283.         XmRXmStringTable,
  284.         sizeof(XmStringTable),
  285.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . items),
  286.         XmRImmediate, 
  287.         (XtPointer) NULL
  288.     },
  289.     {
  290.         XmNitemCount,
  291.         XmCItemCount,
  292.         XmRInt,
  293.         sizeof(int),
  294.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . item_count),
  295.         XmRImmediate, 
  296.         (XtPointer) 0
  297.     },
  298.     { 
  299.         XmNlistFontList,
  300.         XmCListFontList,
  301.         XmRFontList,
  302.         sizeof(XmFontList),
  303.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . list_font_list),
  304.         XmRImmediate, 
  305.         (XtPointer) NULL
  306.     },
  307.     { 
  308.         XmNlistMarginHeight,
  309.         XmCListMarginHeight,
  310.         XmRVerticalDimension,
  311.         sizeof(Dimension),
  312.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . list_margin_height),
  313.         XmRImmediate, 
  314.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_MARGIN_HEIGHT
  315.     },
  316.     { 
  317.         XmNlistMarginWidth,
  318.         XmCListMarginWidth,
  319.         XmRHorizontalDimension,
  320.         sizeof(Dimension),
  321.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . list_margin_width),
  322.         XmRImmediate, 
  323.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_MARGIN_WIDTH
  324.     },
  325.     { 
  326.         XmNlistSpacing,
  327.         XmCListSpacing,
  328.         XmRVerticalDimension,
  329.         sizeof(Dimension),
  330.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . list_spacing),
  331.         XmRImmediate, 
  332.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_SPACING
  333.     },
  334.     {
  335.         XmNtopItemPosition,
  336.         XmCTopItemPosition,
  337.         XmRInt,
  338.         sizeof(int),
  339.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . top_item_position),
  340.         XmRImmediate, 
  341.         (XtPointer) 1
  342.     },
  343.     {
  344.         XmNvisibleItemCount,
  345.         XmCVisibleItemCount,
  346.         XmRInt,
  347.         sizeof(int),
  348.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . visible_item_count),
  349.         XmRImmediate, 
  350.         (XtPointer) XfeDEFAULT_COMBO_BOX_LIST_VISIBLE_ITEM_COUNT
  351.     },
  352.  
  353.     /* Shell resources */
  354.     {
  355.         XmNshell,
  356.         XmCReadOnly,
  357.         XmRWidget,
  358.         sizeof(Widget),
  359.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . shell),
  360.         XmRImmediate, 
  361.         (XtPointer) NULL
  362.     },
  363.     { 
  364.         XmNshareShell,
  365.         XmCShareShell,
  366.         XmRBoolean,
  367.         sizeof(Boolean),
  368.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . share_shell),
  369.         XmRImmediate, 
  370.         (XtPointer) True
  371.     },
  372.     { 
  373.         XmNpoppedUp,
  374.         XmCReadOnly,
  375.         XmRBoolean,
  376.         sizeof(Boolean),
  377.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . popped_up),
  378.         XmRImmediate, 
  379.         (XtPointer) False
  380.     },
  381.  
  382.  
  383.     /* Arrow resources */
  384.     {
  385.         XmNarrow,
  386.         XmCReadOnly,
  387.         XmRWidget,
  388.         sizeof(Widget),
  389.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . arrow),
  390.         XmRImmediate, 
  391.         (XtPointer) NULL
  392.     },
  393.  
  394.     /* Traversal resources */
  395.     {
  396.         XmNhighlightThickness,
  397.         XmCHighlightThickness,
  398.         XmRHorizontalDimension,
  399.         sizeof(Dimension),
  400.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . highlight_thickness),
  401.         XmRImmediate, 
  402.         (XtPointer) 2
  403.     },
  404.     { 
  405.         XmNtraversalOn,
  406.         XmCTraversalOn,
  407.         XmRBoolean,
  408.         sizeof(Boolean),
  409.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . traversal_on),
  410.         XmRImmediate, 
  411.         (XtPointer) True
  412.     },
  413.  
  414.     /* Force the XmNshadowThickness to the default */
  415.     { 
  416.         XmNshadowThickness,
  417.         XmCShadowThickness,
  418.         XmRHorizontalDimension,
  419.         sizeof(Dimension),
  420.         XtOffsetOf(XfeComboBoxRec , manager . shadow_thickness),
  421.         XmRImmediate, 
  422.         (XtPointer) XfeDEFAULT_SHADOW_THICKNESS
  423.     },
  424.  
  425.     /* Force XmNmarginLeft and XmNmarginRight to 4 */
  426.     { 
  427.         XmNmarginLeft,
  428.         XmCMarginLeft,
  429.         XmRHorizontalDimension,
  430.         sizeof(Dimension),
  431.         XtOffsetOf(XfeComboBoxRec , xfe_manager . margin_left),
  432.         XmRImmediate, 
  433.         (XtPointer) 4
  434.     },
  435.     { 
  436.         XmNmarginRight,
  437.         XmCMarginRight,
  438.         XmRHorizontalDimension,
  439.         sizeof(Dimension),
  440.         XtOffsetOf(XfeComboBoxRec , xfe_manager . margin_right),
  441.         XmRImmediate, 
  442.         (XtPointer) 4
  443.     },
  444.  
  445. };   
  446.  
  447. /*----------------------------------------------------------------------*/
  448. /*                                                                        */
  449. /* XfeComboBox synthetic resources                                        */
  450. /*                                                                        */
  451. /*----------------------------------------------------------------------*/
  452. static XmSyntheticResource synthetic_resources[] =
  453. {
  454.     { 
  455.         XmNspacing,
  456.         sizeof(Dimension),
  457.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . spacing),
  458.         _XmFromHorizontalPixels,
  459.         _XmToHorizontalPixels 
  460.     },
  461.     { 
  462.         XmNitems,
  463.         sizeof(XmStringTable),
  464.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . items),
  465.         SyntheticGetListItems,
  466.         _XfeSyntheticSetResourceForChild 
  467.     },
  468.     { 
  469.         XmNitemCount,
  470.         sizeof(int),
  471.         XtOffsetOf(XfeComboBoxRec , xfe_combo_box . item_count),
  472.         SyntheticGetListItemCount,
  473.         _XfeSyntheticSetResourceForChild 
  474.     },
  475. };
  476.  
  477. /*----------------------------------------------------------------------*/
  478. /*                                                                        */
  479. /* XfeComboBox actions                                                    */
  480. /*                                                                        */
  481. /*----------------------------------------------------------------------*/
  482. static XtActionsRec actions[] = 
  483. {
  484.     { "Popup",                        ActionPopup                },
  485.     { "Popdown",                    ActionPopdown            },
  486.     { "Highlight",                    ActionHighlight            },
  487. };
  488.  
  489. /*----------------------------------------------------------------------*/
  490. /*                                                                        */
  491. /* Widget Class Record Initialization                                   */
  492. /*                                                                        */
  493. /*----------------------------------------------------------------------*/
  494. _XFE_WIDGET_CLASS_RECORD(combobox,ComboBox) =
  495. {
  496.     {
  497.         (WidgetClass) &xfeManagerClassRec,        /* superclass            */
  498.         "XfeComboBox",                            /* class_name            */
  499.         sizeof(XfeComboBoxRec),                    /* widget_size            */
  500.         NULL,                                    /* class_initialize        */
  501.         ClassPartInit,                            /* class_part_initialize*/
  502.         FALSE,                                    /* class_inited            */
  503.         Initialize,                                /* initialize            */
  504.         NULL,                                    /* initialize_hook        */
  505.         XtInheritRealize,                        /* realize                */
  506.         actions,                                /* actions                */
  507.         XtNumber(actions),                        /* num_actions            */
  508.         resources,                              /* resources            */
  509.         XtNumber(resources),                    /* num_resources        */
  510.         NULLQUARK,                              /* xrm_class            */
  511.         TRUE,                                   /* compress_motion        */
  512.         XtExposeCompressMaximal,                /* compress_exposure    */
  513.         TRUE,                                   /* compress_enterleave    */
  514.         FALSE,                                  /* visible_interest        */
  515.         Destroy,                                /* destroy                */
  516.         XtInheritResize,                        /* resize                */
  517.         XtInheritExpose,                        /* expose                */
  518.         SetValues,                              /* set_values            */
  519.         NULL,                                   /* set_values_hook        */
  520.         XtInheritSetValuesAlmost,                /* set_values_almost    */
  521.         GetValuesHook,                            /* get_values_hook        */
  522.         NULL,                                   /* access_focus            */
  523.         XtVersion,                              /* version                */
  524.         NULL,                                   /* callback_private        */
  525.         XtInheritTranslations,                    /* tm_table                */
  526.         XtInheritQueryGeometry,                    /* query_geometry        */
  527.         XtInheritDisplayAccelerator,            /* display accelerator    */
  528.         NULL,                                   /* extension            */
  529.     },
  530.     
  531.     /* Composite Part */
  532.     {
  533.         XtInheritGeometryManager,                /* geometry_manager        */
  534.         XtInheritChangeManaged,                    /* change_managed        */
  535.         XtInheritInsertChild,                    /* insert_child            */
  536.         XtInheritDeleteChild,                    /* delete_child            */
  537.         NULL                                    /* extension            */
  538.     },
  539.  
  540.     /* Constraint Part */
  541.     {
  542.         NULL,                                    /* syn resources        */
  543.         0,                                        /* num syn_resources    */
  544.         sizeof(XfeManagerConstraintRec),        /* constraint size        */
  545.         NULL,                                    /* init proc            */
  546.         NULL,                                    /* destroy proc            */
  547.         NULL,                                    /* set values proc        */
  548.         NULL,                                   /* extension            */
  549.     },
  550.  
  551.     /* XmManager Part */
  552.     {
  553.         XtInheritTranslations,                    /* tm_table                */
  554.         synthetic_resources,                    /* syn resources        */
  555.         XtNumber(synthetic_resources),            /* num syn_resources    */
  556.         NULL,                                   /* syn_cont_resources      */
  557.         0,                                      /* num_syn_cont_resource*/
  558.         XmInheritParentProcess,                 /* parent_process        */
  559.         NULL,                                   /* extension            */
  560.     },
  561.     
  562.     /* XfeManager Part     */
  563.     {
  564.         XfeInheritBitGravity,                    /* bit_gravity            */
  565.         PreferredGeometry,                        /* preferred_geometry    */
  566.         XfeInheritMinimumGeometry,                /* minimum_geometry        */
  567.         XfeInheritUpdateRect,                    /* update_rect            */
  568.         AcceptChild,                            /* accept_child            */
  569.         NULL,                                    /* insert_child            */
  570.         NULL,                                    /* delete_child            */
  571.         NULL,                                    /* change_managed        */
  572.         NULL,                                    /* prepare_components    */
  573.         LayoutComponents,                        /* layout_components    */
  574.         NULL,                                    /* layout_children        */
  575.         NULL,                                    /* draw_background        */
  576.         DrawShadow,                                /* draw_shadow            */
  577.         DrawComponents,                            /* draw_components        */
  578.         NULL,                                    /* extension            */
  579.     },
  580.  
  581.     /* XfeComboBox Part */
  582.     {
  583.         LayoutTitle,                            /* layout_title            */
  584.         LayoutArrow,                            /* layout_arrow            */
  585.         DrawHighlight,                            /* draw_highlight        */
  586.         DrawTitleShadow,                        /* draw_title_shadow    */
  587.         NULL,                                    /* extension            */
  588.     },
  589. };
  590.  
  591. /*----------------------------------------------------------------------*/
  592. /*                                                                        */
  593. /* xfeComboBoxWidgetClass declaration.                                    */
  594. /*                                                                        */
  595. /*----------------------------------------------------------------------*/
  596. _XFE_WIDGET_CLASS(combobox,ComboBox);
  597.  
  598. /*----------------------------------------------------------------------*/
  599. /*                                                                        */
  600. /* XfeComboBox resource call procedures                                    */
  601. /*                                                                        */
  602. /*----------------------------------------------------------------------*/
  603. static void
  604. DefaultTitleShadowThickness(Widget w,int offset,XrmValue * value)
  605. {
  606.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  607.     static Dimension        shadow_thickness;
  608.  
  609.     if (cp->combo_box_type == XmCOMBO_BOX_EDITABLE)
  610.     {
  611.         shadow_thickness = _XfemShadowThickness(w);
  612.     }
  613.     else
  614.     {
  615.         shadow_thickness = 0;
  616.     }
  617.  
  618.     value->addr = (XPointer) &shadow_thickness;
  619.     value->size = sizeof(shadow_thickness);
  620. }
  621. /*----------------------------------------------------------------------*/
  622.  
  623. /*----------------------------------------------------------------------*/
  624. /*                                                                        */
  625. /* Synthetic resource Callprocs                                            */
  626. /*                                                                        */
  627. /*----------------------------------------------------------------------*/
  628. static void
  629. SyntheticGetListItems(Widget w,int offset, XtArgVal * value)
  630. {
  631. }
  632. /*----------------------------------------------------------------------*/
  633. static void
  634. SyntheticGetListItemCount(Widget w,int offset, XtArgVal * value)
  635. {
  636. }
  637. /*----------------------------------------------------------------------*/
  638.  
  639. /*----------------------------------------------------------------------*/
  640. /*                                                                        */
  641. /* Core Class methods                                                    */
  642. /*                                                                        */
  643. /*----------------------------------------------------------------------*/
  644. static void
  645. ClassPartInit(WidgetClass wc)
  646. {
  647.     XfeComboBoxWidgetClass cc = (XfeComboBoxWidgetClass) wc;
  648.     XfeComboBoxWidgetClass sc = (XfeComboBoxWidgetClass) wc->core_class.superclass;
  649.  
  650.     _XfeResolve(cc,sc,xfe_combo_box_class,layout_title,
  651.                 XfeInheritLayoutTitle);
  652.  
  653.     _XfeResolve(cc,sc,xfe_combo_box_class,layout_arrow,
  654.                 XfeInheritLayoutArrow);
  655.  
  656.     _XfeResolve(cc,sc,xfe_combo_box_class,draw_highlight,
  657.                 XfeInheritDrawHighlight);
  658.    
  659.     _XfeResolve(cc,sc,xfe_combo_box_class,draw_title_shadow,
  660.                 XfeInheritDrawTitleShadow);
  661. }
  662. /*----------------------------------------------------------------------*/
  663. static void
  664. Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  665. {
  666.     XfeComboBoxPart *        cp = _XfeComboBoxPart(nw);
  667.  
  668.     /* Make sure rep types are ok */
  669.     XfeRepTypeCheck(nw,XmRShadowType,&cp->title_shadow_type,
  670.                     XmSHADOW_IN);
  671.  
  672.     XfeRepTypeCheck(nw,XmRComboBoxType,&cp->combo_box_type,
  673.                     XmCOMBO_BOX_READ_ONLY);
  674.  
  675.     /* Make sure read-only resources aren't set */
  676.     if (cp->title)
  677.     {
  678.         _XmWarning(nw,MESSAGE2);
  679.  
  680.         cp->title = NULL;
  681.     }
  682.  
  683.     if (cp->list)
  684.     {
  685.         _XmWarning(nw,MESSAGE3);
  686.  
  687.         cp->list = NULL;
  688.     }
  689.  
  690.     if (cp->shell)
  691.     {
  692.         _XmWarning(nw,MESSAGE4);
  693.  
  694.         cp->shell = NULL;
  695.     }
  696.  
  697.     if (cp->arrow)
  698.     {
  699.         _XmWarning(nw,MESSAGE5);
  700.  
  701.         cp->arrow = NULL;
  702.     }
  703.     
  704.     /* Create components */
  705.     cp->arrow        = ArrowCreate(nw);
  706.     cp->title        = TitleCreate(nw);
  707.     cp->shell        = ShellCreate(nw);
  708.     cp->list        = ListCreate(nw);
  709.  
  710.     /* Configure the title */
  711.     TitleConfigure(nw);
  712.  
  713.     /* Initialize private members */
  714.     cp->highlighted            = False;
  715.     cp->delay_timer_id        = 0;
  716.  
  717.     /* Manage the children */
  718.     XtManageChild(cp->title);
  719.     XtManageChild(cp->list);
  720.     XtManageChild(cp->arrow);
  721.  
  722.      XfeOverrideTranslations(nw,_XfeComboBoxExtraTranslations);
  723.  
  724.     /* Finish of initialization */
  725.     _XfeManagerChainInitialize(rw,nw,xfeComboBoxWidgetClass);
  726. }
  727. /*----------------------------------------------------------------------*/
  728. static void
  729. Destroy(Widget w)
  730. {
  731. /*     XfeComboBoxPart *        cp = _XfeComboBoxPart(w); */
  732. }
  733. /*----------------------------------------------------------------------*/
  734. static Boolean
  735. SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  736. {
  737.     XfeComboBoxPart *        np = _XfeComboBoxPart(nw);
  738.     XfeComboBoxPart *        op = _XfeComboBoxPart(ow);
  739.  
  740.     /* title */
  741.     if (np->title != op->title)
  742.     {
  743.         _XmWarning(nw,MESSAGE2);
  744.  
  745.         np->title = op->title;
  746.     }
  747.  
  748.     /* list */
  749.     if (np->list != op->list)
  750.     {
  751.         _XmWarning(nw,MESSAGE3);
  752.  
  753.         np->list = op->list;
  754.     }
  755.  
  756.     /* shell */
  757.     if (np->shell != op->shell)
  758.     {
  759.         _XmWarning(nw,MESSAGE4);
  760.  
  761.         np->shell = op->shell;
  762.     }
  763.  
  764.     /* combo_box_type */
  765.     if (np->combo_box_type != op->combo_box_type)
  766.     {
  767.         TitleConfigure(nw);
  768.  
  769.         _XfemConfigFlags(nw) |= XfeConfigExpose;
  770.  
  771. #if 0
  772.         _XmWarning(nw,MESSAGE6);
  773.  
  774.         np->combo_box_type = op->combo_box_type;
  775. #endif
  776.     }
  777.  
  778.     /* title_shadow_thickness */
  779.     if (np->title_shadow_thickness != op->title_shadow_thickness)
  780.     {
  781.         _XfemConfigFlags(nw) |= XfeConfigGLE;
  782.     }
  783.  
  784.     /* title_shadow_type */
  785.     if (np->title_shadow_type != op->title_shadow_type)
  786.     {
  787.         /* Make sure the new shadow type is ok */
  788.         XfeRepTypeCheck(nw,XmRShadowType,&np->title_shadow_type,XmSHADOW_IN);
  789.  
  790.         _XfemConfigFlags(nw) |= XfeConfigExpose;
  791.     }
  792.  
  793.     return _XfeManagerChainSetValues(ow,rw,nw,xfeComboBoxWidgetClass);
  794. }
  795. /*----------------------------------------------------------------------*/
  796. static void
  797. GetValuesHook(Widget w,ArgList args,Cardinal* nargs)
  798. {
  799. /*     XfeComboBoxPart *        cp = _XfeComboBoxPart(w); */
  800.     Cardinal                i;
  801.     
  802.     for (i = 0; i < *nargs; i++)
  803.     {
  804. #if 0
  805.         /* label_string */
  806.         if (strcmp(args[i].name,XmNlabelString) == 0)
  807.         {
  808.             *((XtArgVal *) args[i].value) = 
  809.                 (XtArgVal) XmStringCopy(lp->label_string);
  810.         }
  811.         /* font_list */
  812.         else if (strcmp(args[i].name,XmNfontList) == 0)
  813.         {
  814.             *((XtArgVal *) args[i].value) = 
  815.                 (XtArgVal) XmFontListCopy(lp->font_list);
  816.         }      
  817. #endif
  818.     }
  819. }
  820. /*----------------------------------------------------------------------*/
  821.  
  822. /*----------------------------------------------------------------------*/
  823. /*                                                                        */
  824. /* XfeManager class methods                                                */
  825. /*                                                                        */
  826. /*----------------------------------------------------------------------*/
  827. static void
  828. PreferredGeometry(Widget w,Dimension * width,Dimension * height)
  829. {
  830.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  831.     
  832.     *height = 
  833.         CB_OFFSET_TOP(w,cp)  + CB_OFFSET_BOTTOM(w,cp) +
  834.         XfeMax(_XfeHeight(cp->title),_XfeHeight(cp->arrow)) +
  835.         2 * cp->title_shadow_thickness;
  836.  
  837.     *width  = 
  838.         CB_OFFSET_LEFT(w,cp) + CB_OFFSET_RIGHT(w,cp) + 
  839.         _XfeWidth(cp->title) +
  840.         cp->spacing +
  841.         _XfeWidth(cp->arrow) +
  842.         2 * cp->title_shadow_thickness;
  843. }
  844. /*----------------------------------------------------------------------*/
  845. static Boolean
  846. AcceptChild(Widget child)
  847. {
  848.     return False;
  849. }
  850. /*----------------------------------------------------------------------*/
  851. static void
  852. LayoutComponents(Widget w)
  853. {
  854.     _XfeComboBoxLayoutArrow(w);
  855.  
  856.     _XfeComboBoxLayoutTitle(w);
  857. }
  858. /*----------------------------------------------------------------------*/
  859. static void
  860. DrawShadow(Widget w,XEvent * event,Region region,XRectangle * clip_rect)
  861. {
  862.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  863.  
  864.     if (!_XfemShadowThickness(w))
  865.      {
  866.          return;
  867.      }
  868.  
  869.     /* Draw the shadow */
  870.     _XmDrawShadows(XtDisplay(w),
  871.                    _XfeWindow(w),
  872.                    _XfemTopShadowGC(w),_XfemBottomShadowGC(w),
  873.                    cp->highlight_thickness,
  874.                    cp->highlight_thickness,
  875.                    _XfeWidth(w) - 2 * cp->highlight_thickness,
  876.                    _XfeHeight(w) - 2 * cp->highlight_thickness,
  877.                    _XfemShadowThickness(w),
  878.                    _XfemShadowType(w));
  879. }
  880. /*----------------------------------------------------------------------*/
  881. static void
  882. DrawComponents(Widget w,XEvent * event,Region region,XRectangle * clip_rect)
  883. {
  884.     /* Draw the highlight */
  885.     _XfeComboBoxDrawHighlight(w,event,region,clip_rect);
  886.  
  887.     /* Draw the title shadow */
  888.     _XfeComboBoxDrawTitleShadow(w,event,region,clip_rect);
  889. }
  890. /*----------------------------------------------------------------------*/
  891.  
  892.  
  893. /*----------------------------------------------------------------------*/
  894. /*                                                                        */
  895. /* XfeComboBox action procedures                                        */
  896. /*                                                                        */
  897. /*----------------------------------------------------------------------*/
  898. static void
  899. ActionPopup(Widget item,XEvent * event,char ** params,Cardinal * nparams)
  900. {
  901.     Widget                w = XfeIsComboBox(item) ? item : _XfeParent(item);
  902.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  903.     int                    space_below = ScreenGetSpaceBelow(w);
  904.     int                    space_above = ScreenGetSpaceAbove(w);
  905.  
  906. #if 1
  907.     printf("ActionPopup(%s,above = %d,below = %d)\n",
  908.            XtName(w),
  909.            space_above,
  910.            space_below);
  911. #endif
  912.  
  913.     /* Check if we are already popped up */
  914.     if (cp->popped_up)
  915.     {
  916.         printf("already popped up\n");
  917.  
  918.         StickRemoveTimeout(w);
  919.  
  920.         ListUnmanage(w);
  921.         
  922.         XtVaSetValues(cp->arrow,XmNarmed,False,NULL);
  923.  
  924.         return;
  925.     }
  926.  
  927.     space_below = 200;
  928.  
  929.       _XfeConfigureWidget(cp->shell,
  930.                         XfeRootX(w),
  931.                         XfeRootY(w) + _XfeHeight(w),
  932.                         _XfeWidth(w),
  933.                         space_below);
  934.  
  935. /*       XtVaSetValues(cp->list, */
  936. /*                   XmNlistMarginWidth, 100, */
  937. /*                   NULL); */
  938.  
  939. /*     XtVaSetValues(cp->arrow,XmCArmed,True,NULL); */
  940.  
  941. /*     XtPopup(cp->shell,XtGrabNone); */
  942. /*     XMapRaised(XtDisplay(w),_XfeWindow(cp->shell)); */
  943. /*     XMapRaised(XtDisplay(w),_XfeWindow(cp->shell)); */
  944.  
  945.      cp->remain_popped_up = False;
  946.  
  947. #if 1
  948.     StickAddTimeout(w);
  949. #endif
  950.  
  951.      XtVaSetValues(cp->arrow,XmNarmed,True,NULL);
  952.  
  953.     ListManage(w);
  954. }
  955. /*----------------------------------------------------------------------*/
  956. static void
  957. ActionPopdown(Widget item,XEvent * event,char ** params,Cardinal * nparams)
  958. {
  959.     Widget                w = XfeIsComboBox(item) ? item : _XfeParent(item);
  960.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  961.  
  962. #if 1
  963.     printf("ActionPopdown(%s)\n",XtName(w));
  964. #endif
  965.  
  966.     if (cp->delay_timer_id)
  967.     {
  968.         StickRemoveTimeout(w);
  969.     }
  970.     else
  971.     {
  972.         ListUnmanage(w);
  973.  
  974.     }
  975.     
  976.     XtVaSetValues(cp->arrow,XmNarmed,False,NULL);
  977.  
  978. /*     if (!cp->remain_popped_up) */
  979. /*     { */
  980. /*         XtPopdown(cp->shell); */
  981. /*     } */
  982.     
  983. /*       cp->remain_popped_up = False; */
  984.  
  985. /*      ListUnmanage(w); */
  986.  
  987. /*     XUnmapWindow(XtDisplay(w),_XfeWindow(cp->shell)); */
  988. }
  989. /*----------------------------------------------------------------------*/
  990. static void
  991. ActionHighlight(Widget item,XEvent * event,char ** params,Cardinal * nparams)
  992. {
  993.     Widget w = XfeIsComboBox(item) ? item : _XfeParent(item);
  994.     
  995.     XmProcessTraversal(w,XmTRAVERSE_CURRENT);
  996. }
  997. /*----------------------------------------------------------------------*/
  998.  
  999. /*----------------------------------------------------------------------*/
  1000. /*                                                                        */
  1001. /* Misc XfeComboBox functions                                            */
  1002. /*                                                                        */
  1003. /*----------------------------------------------------------------------*/
  1004. static void
  1005. DrawHighlight(Widget w,XEvent * event,Region region,XRectangle * clip_rect)
  1006. {
  1007.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  1008.  
  1009.     /* Make sure the highlight is needed */
  1010.     if (!cp->highlight_thickness || !_XfeIsRealized(w))
  1011.     {
  1012.         return;
  1013.     }
  1014.  
  1015.     if (cp->highlighted)
  1016.     {
  1017.         _XmDrawSimpleHighlight(XtDisplay(w),
  1018.                                _XfeWindow(w), 
  1019.                                _XfemHighlightGC(w),
  1020.                                0,0, 
  1021.                                _XfeWidth(w),_XfeHeight(w),
  1022.                                cp->highlight_thickness);
  1023.     }
  1024.     else
  1025.     {
  1026.         assert( XmIsManager(_XfeParent(w)) );
  1027.  
  1028.         _XmDrawSimpleHighlight(XtDisplay(w),
  1029.                                _XfeWindow(w), 
  1030.                                _XfemBackgroundGC(_XfeParent(w)),
  1031.                                0,0, 
  1032.                                _XfeWidth(w),_XfeHeight(w),
  1033.                                cp->highlight_thickness);
  1034.     }
  1035. }
  1036. /*----------------------------------------------------------------------*/
  1037. static void
  1038. DrawTitleShadow(Widget w,XEvent * event,Region region,XRectangle * clip_rect)
  1039. {
  1040.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  1041.  
  1042.     /* Make sure the shadow is needed */
  1043.     if (!cp->title_shadow_thickness)
  1044.     {
  1045.         return;
  1046.     }
  1047.  
  1048.     /* Draw the shadow around the text only */
  1049.     XfeDrawShadowsAroundWidget(w,
  1050.                                cp->title,
  1051.                                _XfemTopShadowGC(w),
  1052.                                _XfemBottomShadowGC(w),
  1053.                                0,
  1054.                                cp->title_shadow_thickness,
  1055.                                cp->title_shadow_type);
  1056. }
  1057. /*----------------------------------------------------------------------*/
  1058. static Widget
  1059. TitleCreate(Widget w)
  1060. {
  1061.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1062.     Widget                title = NULL;
  1063.  
  1064.     if (cp->combo_box_type == XmCOMBO_BOX_EDITABLE)
  1065.     {
  1066.         title = TitleTextCreate(w);
  1067.     }
  1068.     else
  1069.     {
  1070.         title = TitleLabelCreate(w);
  1071.     }
  1072.  
  1073.     return title;
  1074. }
  1075. /*----------------------------------------------------------------------*/
  1076. static void
  1077. TitleConfigure(Widget w)
  1078. {
  1079.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1080.     Arg                    av[10];
  1081.     Cardinal            ac = 0;
  1082.  
  1083.     assert( _XfeIsAlive(cp->title) );
  1084.  
  1085.     if (cp->combo_box_type == XmCOMBO_BOX_EDITABLE)
  1086.     {
  1087.         XfeOverrideTranslations(cp->title,
  1088.                                 _XfeComboBoxTextEditableTranslations);
  1089.  
  1090.         XtSetArg(av[ac],XmNeditable,True); ac++;
  1091.         XtSetArg(av[ac],XmNcursorPositionVisible,True); ac++;
  1092.     }
  1093.     else
  1094.     {
  1095.         XfeOverrideTranslations(cp->title,
  1096.                                 _XfeComboBoxTextReadOnlyTranslations);
  1097.  
  1098.         XtSetArg(av[ac],XmNeditable,False); ac++;
  1099.         XtSetArg(av[ac],XmNcursorPositionVisible,False); ac++;
  1100.     }
  1101.  
  1102.     XtSetValues(cp->title,av,ac);
  1103. }
  1104. /*----------------------------------------------------------------------*/
  1105. static Widget
  1106. TitleTextCreate(Widget w)
  1107. {
  1108. /*     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w); */
  1109.     Widget                text = NULL;
  1110.  
  1111.     text = XtVaCreateWidget(TITLE_NAME,
  1112.                             xmTextFieldWidgetClass,
  1113.                             w,
  1114.                             XmNbackground,            _XfeBackgroundPixel(w),
  1115.                             XmNbackgroundPixmap,    _XfeBackgroundPixmap(w),
  1116.                             XmNhighlightThickness,    0,
  1117.                             XmNshadowThickness,        0,
  1118.                             NULL);
  1119.  
  1120.  
  1121.     XtAddCallback(text,XmNfocusCallback,TextFocusCB,w);
  1122.     XtAddCallback(text,XmNlosingFocusCallback,TextLosingFocusCB,w);
  1123.  
  1124.     return text;
  1125. }
  1126. /*----------------------------------------------------------------------*/
  1127. static Widget
  1128. TitleLabelCreate(Widget w)
  1129. {
  1130. /*     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w); */
  1131.     Widget                label = NULL;
  1132.  
  1133.     label = XtVaCreateWidget(TITLE_NAME,
  1134.                              xfeLabelWidgetClass,
  1135.                              w,
  1136.                              XmNbackground,            _XfeBackgroundPixel(w),
  1137.                              XmNbackgroundPixmap,    _XfeBackgroundPixmap(w),
  1138.                              XmNshadowThickness,        0,
  1139.                              XmNlabelAlignment,        XmALIGNMENT_BEGINNING,
  1140.                              NULL);
  1141.  
  1142.     /* Add the extra combo box translations to the label */
  1143. /*     XfeOverrideTranslations(label,_XfeComboBoxExtraTranslations); */
  1144.  
  1145.     return label;
  1146. }
  1147. /*----------------------------------------------------------------------*/
  1148. static void
  1149. LayoutTitle(Widget w)
  1150. {
  1151.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  1152.  
  1153.     _XfeConfigureWidget(cp->title,
  1154.  
  1155.                         CB_OFFSET_LEFT(w,cp) + cp->title_shadow_thickness,
  1156.  
  1157.                         (_XfeHeight(w) - _XfeHeight(cp->title)) / 2,
  1158.                         
  1159.                         CB_RECT_WIDTH(w,cp) - 
  1160.                         cp->spacing -
  1161.                         _XfeWidth(cp->arrow) -
  1162.                         2 * cp->title_shadow_thickness,
  1163.                         
  1164.                         CB_RECT_HEIGHT(w,cp) - 
  1165.                         2 * cp->title_shadow_thickness);
  1166. }
  1167. /*----------------------------------------------------------------------*/
  1168.  
  1169. /*----------------------------------------------------------------------*/
  1170. /*                                                                        */
  1171. /* List functions                                                        */
  1172. /*                                                                        */
  1173. /*----------------------------------------------------------------------*/
  1174. static Widget
  1175. ListCreate(Widget w)
  1176. {
  1177.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1178.     Widget                list = NULL;
  1179.     Arg                    av[10];
  1180.     Cardinal            ac = 0;
  1181.  
  1182.     assert( _XfeIsAlive(cp->shell) );
  1183.  
  1184.     XtSetArg(av[ac],XmNbackground,        _XfeBackgroundPixel(w));    ac++;
  1185.     XtSetArg(av[ac],XmNforeground,        _XfemForeground(w));        ac++;
  1186.     XtSetArg(av[ac],XmNshadowThickness,    _XfemShadowThickness(w));    ac++;
  1187.  
  1188.     list = XmCreateScrolledList(cp->shell,LIST_NAME,av,ac);
  1189.  
  1190.       XtManageChild(list);
  1191.  
  1192.     XtUnmanageChild(_XfeParent(list));
  1193.  
  1194. /*     _XfeResizeWidget(list,400,500); */
  1195. /*     _XfeResizeWidget(cp->shell,400,500); */
  1196.  
  1197.     return list;
  1198. }
  1199. /*----------------------------------------------------------------------*/
  1200. static void
  1201. ListManage(Widget w)
  1202. {
  1203.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1204.  
  1205.     assert( _XfeIsAlive(cp->shell) );
  1206.     assert( _XfeIsAlive(cp->list) );
  1207.  
  1208.     printf("ListManage(%s)\n",XtName(w));
  1209.  
  1210. /*     cp->remain_popped_up = True; */
  1211.  
  1212.     /* popped up */
  1213.      cp->popped_up = True;
  1214.  
  1215.     /* Manage the scrolled window */
  1216.     XtManageChild(_XfeParent(cp->list));
  1217.  
  1218.     ShellPopup(w);
  1219.  
  1220. #if 0
  1221.     XmUpdateDisplay(w);
  1222.     XFlush(XtDisplay(w));
  1223. #endif
  1224.  
  1225. /*     _XmPopupSpringLoaded(w); */
  1226. }
  1227. /*----------------------------------------------------------------------*/
  1228. static void
  1229. ListUnmanage(Widget w)
  1230. {
  1231.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1232.  
  1233.     assert( _XfeIsAlive(cp->shell) );
  1234.     assert( _XfeIsAlive(cp->list) );
  1235.  
  1236.     /* not popped up */
  1237.      cp->popped_up = False;
  1238.  
  1239.     /* Unmanage the scrolled window */
  1240.     XtUnmanageChild(_XfeParent(cp->list));
  1241.  
  1242.     ShellPopdown(w);
  1243. }
  1244. /*----------------------------------------------------------------------*/
  1245.  
  1246. /*----------------------------------------------------------------------*/
  1247. /*                                                                        */
  1248. /* Shell functions                                                        */
  1249. /*                                                                        */
  1250. /*----------------------------------------------------------------------*/
  1251. static Widget
  1252. ShellCreate(Widget w)
  1253. {
  1254.     Widget        shell = NULL;
  1255.     Widget        frame_shell;
  1256.  
  1257.     /* Look for a XfeFrameShell ancestor */
  1258.     frame_shell = XfeAncestorFindByClass(w,
  1259.                                          xfeFrameShellWidgetClass,
  1260.                                          XfeFIND_ANY);
  1261.  
  1262.     /* If found, use it */
  1263.     if (_XfeIsAlive(frame_shell))
  1264.     {
  1265.         shell = XfeFrameShellGetBypassShell(frame_shell);
  1266.     }
  1267.     else
  1268.     {
  1269.         shell = XfeCreateBypassShell(w,SHELL_NAME,NULL,0);
  1270.  
  1271.         XtRealizeWidget(shell);
  1272.     }
  1273.  
  1274.     assert( _XfeIsAlive(shell) );
  1275.  
  1276.  
  1277.     if (!_XfeIsRealized(shell))
  1278.     {
  1279.         XtRealizeWidget(shell);
  1280.     }
  1281.  
  1282.     return shell;
  1283. }
  1284. /*----------------------------------------------------------------------*/
  1285. static void
  1286. ShellPopup(Widget w)
  1287. {
  1288.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1289.  
  1290.     assert( _XfeIsAlive(cp->shell) );
  1291.  
  1292. /*     _XmPopupSpringLoaded(cp->shell); */
  1293.     _XmPopup(cp->shell,XtGrabNone);
  1294. }
  1295. /*----------------------------------------------------------------------*/
  1296. static void
  1297. ShellPopdown(Widget w)
  1298. {
  1299.     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w);
  1300.  
  1301.     assert( _XfeIsAlive(cp->shell) );
  1302.  
  1303.     _XmPopdown(cp->shell);
  1304. }
  1305. /*----------------------------------------------------------------------*/
  1306. static Widget
  1307. ArrowCreate(Widget w)
  1308. {
  1309. /*     XfeComboBoxPart *    cp  = _XfeComboBoxPart(w); */
  1310.     Widget                arrow = NULL;
  1311.  
  1312.     arrow = XtVaCreateWidget(ARROW_NAME,
  1313.                              xfeArrowWidgetClass,
  1314.                              w,
  1315.                              XmNbackground,            _XfeBackgroundPixel(w),
  1316.                              XmNbackgroundPixmap,    _XfeBackgroundPixmap(w),
  1317.                               XmNshadowThickness,        1,
  1318. /*                               XmNemulateMotif,            False, */
  1319.                               XmNraiseBorderThickness,    0,
  1320.                              XmNraiseOnEnter,            False,
  1321.                               XmNfillOnEnter,            False,
  1322.                               XmNshadowThickness,        0,
  1323.  
  1324.                              XmNbuttonType,                XmBUTTON_TOGGLE,
  1325.  
  1326.                              NULL);
  1327.  
  1328.  
  1329.     XfeOverrideTranslations(arrow,_XfeComboBoxArrowTranslations);
  1330.  
  1331. #if 0
  1332.     XtAddCallback(arrow,XmNarmCallback,ArrowArmCB,w);
  1333.     XtAddCallback(arrow,XmNdisarmCallback,ArrowDisarmCB,w);
  1334.     XtAddCallback(arrow,XmNactivateCallback,ArrowActivateCB,w);
  1335. #endif
  1336.  
  1337. /*     XtAddCallback(arrow,XmNactivateCallback,ArrowActivateCB,w); */
  1338.  
  1339.     return arrow;
  1340. }
  1341. /*----------------------------------------------------------------------*/
  1342. static void
  1343. LayoutArrow(Widget w)
  1344. {
  1345.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  1346.  
  1347.     _XfeConfigureWidget(cp->arrow,
  1348.  
  1349.                         _XfeWidth(w) - 
  1350.                         CB_OFFSET_RIGHT(w,cp) - 
  1351.                         _XfeWidth(cp->arrow),
  1352.  
  1353.                         (_XfeHeight(w) - _XfeHeight(cp->arrow)) / 2,
  1354.  
  1355.                         _XfeWidth(cp->arrow),
  1356.  
  1357.                         _XfeHeight(cp->arrow));
  1358. }
  1359. /*----------------------------------------------------------------------*/
  1360.  
  1361. /*----------------------------------------------------------------------*/
  1362. /*                                                                        */
  1363. /* Text callbacks                                                        */
  1364. /*                                                                        */
  1365. /*----------------------------------------------------------------------*/
  1366. static void
  1367. TextFocusCB(Widget text,XtPointer client_data,XtPointer call_data)
  1368. {
  1369.     Widget                    w = (Widget) client_data;
  1370.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  1371.  
  1372.     cp->highlighted = True;
  1373.  
  1374.     DrawHighlight(w,NULL,NULL,&_XfemWidgetRect(w));
  1375. }
  1376. /*----------------------------------------------------------------------*/
  1377. static void
  1378. TextLosingFocusCB(Widget text,XtPointer client_data,XtPointer call_data)
  1379. {
  1380.     Widget                    w = (Widget) client_data;
  1381.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  1382.  
  1383.     cp->highlighted = False;
  1384.  
  1385.     DrawHighlight(w,NULL,NULL,&_XfemWidgetRect(w));
  1386. }
  1387. /*----------------------------------------------------------------------*/
  1388.  
  1389. /*----------------------------------------------------------------------*/
  1390. /*                                                                        */
  1391. /* Arrow callbacks                                                        */
  1392. /*                                                                        */
  1393. /*----------------------------------------------------------------------*/
  1394. static void
  1395. ArrowActivateCB(Widget text,XtPointer client_data,XtPointer call_data)
  1396. {
  1397.     Widget                    w = (Widget) client_data;
  1398.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  1399.  
  1400. #if 0
  1401.     printf("ArrowActivate(%s)\n",XtName(w));
  1402. #endif
  1403.  
  1404. /*     cp->remain_popped_up = True; */
  1405.  
  1406. }
  1407. /*----------------------------------------------------------------------*/
  1408.  
  1409. /*----------------------------------------------------------------------*/
  1410. /*                                                                        */
  1411. /* Misc Arrow functions                                                    */
  1412. /*                                                                        */
  1413. /*----------------------------------------------------------------------*/
  1414.  
  1415. /*----------------------------------------------------------------------*/
  1416. /*                                                                        */
  1417. /* Screen functions functions                                            */
  1418. /*                                                                        */
  1419. /*----------------------------------------------------------------------*/
  1420. static int
  1421. ScreenGetSpaceBelow(Widget w)
  1422. {
  1423.     return (int) XfeScreenHeight(w) - (int) (XfeRootY(w) + _XfeHeight(w));
  1424. }
  1425. /*----------------------------------------------------------------------*/
  1426. static int
  1427. ScreenGetSpaceAbove(Widget w)
  1428. {
  1429.     return (int) XfeRootY(w);
  1430. }
  1431. /*----------------------------------------------------------------------*/
  1432.  
  1433. /*----------------------------------------------------------------------*/
  1434. /*                                                                        */
  1435. /* Stick functions                                                        */
  1436. /*                                                                        */
  1437. /*----------------------------------------------------------------------*/
  1438. static void
  1439. StickTimeout(XtPointer client_data,XtIntervalId * id)
  1440. {
  1441.     Widget                    w = (Widget) client_data;
  1442.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  1443.  
  1444.     cp->delay_timer_id = 0;
  1445.  
  1446.     cp->remain_popped_up = True;
  1447.  
  1448. #if 1
  1449.      printf("StickTimeout(%s)\n",XtName(w));
  1450. #endif
  1451. }
  1452. /*----------------------------------------------------------------------*/
  1453. static void
  1454. StickAddTimeout(Widget w)
  1455. {
  1456.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  1457.  
  1458.     cp->delay_timer_id = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
  1459.                                          STICK_DELAY,
  1460.                                          StickTimeout,
  1461.                                          (XtPointer) w);
  1462. }
  1463. /*----------------------------------------------------------------------*/
  1464. static void
  1465. StickRemoveTimeout(Widget w)
  1466. {
  1467.     XfeComboBoxPart *    cp = _XfeComboBoxPart(w);
  1468.  
  1469.     /* Remove the timer if its still has not triggered */
  1470.     if (cp->delay_timer_id)
  1471.     {
  1472.         XtRemoveTimeOut(cp->delay_timer_id);
  1473.     }
  1474.  
  1475.     /* Reset the timer */
  1476.     cp->delay_timer_id = 0;
  1477. }
  1478. /*----------------------------------------------------------------------*/
  1479.  
  1480. /*----------------------------------------------------------------------*/
  1481. /*                                                                        */
  1482. /* XfeComboBox method invocation functions                                */
  1483. /*                                                                        */
  1484. /*----------------------------------------------------------------------*/
  1485. /* extern */ void
  1486. _XfeComboBoxLayoutTitle(Widget w)
  1487. {
  1488.     XfeComboBoxWidgetClass cc = (XfeComboBoxWidgetClass) XtClass(w);
  1489.     
  1490.     if (cc->xfe_combo_box_class.layout_title)
  1491.     {
  1492.         (*cc->xfe_combo_box_class.layout_title)(w);
  1493.     }
  1494. }
  1495. /*----------------------------------------------------------------------*/
  1496. /* extern */ void
  1497. _XfeComboBoxLayoutArrow(Widget w)
  1498. {
  1499.     XfeComboBoxWidgetClass cc = (XfeComboBoxWidgetClass) XtClass(w);
  1500.     
  1501.     if (cc->xfe_combo_box_class.layout_arrow)
  1502.     {
  1503.         (*cc->xfe_combo_box_class.layout_arrow)(w);
  1504.     }
  1505. }
  1506. /*----------------------------------------------------------------------*/
  1507. /* extern */ void
  1508. _XfeComboBoxDrawHighlight(Widget            w,
  1509.                           XEvent *            event,
  1510.                           Region            region,
  1511.                           XRectangle *        rect)
  1512. {
  1513.     XfeComboBoxWidgetClass cc = (XfeComboBoxWidgetClass) XtClass(w);
  1514.     
  1515.     if (cc->xfe_combo_box_class.draw_highlight)
  1516.     {
  1517.         (*cc->xfe_combo_box_class.draw_highlight)(w,event,region,rect);
  1518.     }
  1519. }
  1520. /*----------------------------------------------------------------------*/
  1521. /* extern */ void
  1522. _XfeComboBoxDrawTitleShadow(Widget            w,
  1523.                             XEvent *        event,
  1524.                             Region            region,
  1525.                             XRectangle *    rect)
  1526. {
  1527.     XfeComboBoxWidgetClass cc = (XfeComboBoxWidgetClass) XtClass(w);
  1528.     
  1529.     if (cc->xfe_combo_box_class.draw_title_shadow)
  1530.     {
  1531.         (*cc->xfe_combo_box_class.draw_title_shadow)(w,event,region,rect);
  1532.     }
  1533. }
  1534. /*----------------------------------------------------------------------*/
  1535.  
  1536. /*----------------------------------------------------------------------*/
  1537. /*                                                                        */
  1538. /* XfeComboBox Public Methods                                            */
  1539. /*                                                                        */
  1540. /*----------------------------------------------------------------------*/
  1541. /* extern */ Widget
  1542. XfeCreateComboBox(Widget pw,char * name,Arg * av,Cardinal ac)
  1543. {
  1544.     return XtCreateWidget(name,xfeComboBoxWidgetClass,pw,av,ac);
  1545. }
  1546. /*----------------------------------------------------------------------*/
  1547. /* extern */ void
  1548. XfeComboBoxAddItem(Widget w,XmString item,int position)
  1549. {
  1550.     XfeComboBoxPart *        cp = _XfeComboBoxPart(w);
  1551. /*     XmListPart *            lp = _XfeXmListPart(w); */
  1552.  
  1553.     assert( _XfeIsAlive(w) );
  1554.     assert( XfeIsComboBox(w) );
  1555.  
  1556.     XmListAddItem(cp->list,item,position);
  1557.  
  1558.  
  1559. #if 0
  1560.     DtComboBoxWidget combo = (DtComboBoxWidget)combo_w;
  1561.     DtComboBoxPart *combo_p = (DtComboBoxPart*)&(combo->combo_box);
  1562.     XmStringTable list_items = ((XmListWidget)combo_p->list)->list.items;
  1563.     int i;
  1564.  
  1565.     if (item && ((XmListWidget)combo_p->list)->list.itemCount) {
  1566.     for (i = 0; i < combo_p->item_count; i++)
  1567.         if (XmStringCompare(item, list_items[i]))
  1568.         break;
  1569.     if ((i < combo_p->item_count) && unique)
  1570.         return;
  1571.     }
  1572.  
  1573.     XmListAddItem(combo_p->list, item, pos);
  1574.     SyncWithList(combo_p);
  1575.  
  1576.     if (combo_p->label) {
  1577.     SetMaximumLabelSize(combo_p);
  1578.     if (combo_p->type == XmDROP_DOWN_LIST_BOX) {
  1579.         ClearShadow(combo, TRUE);
  1580.         if (combo_p->recompute_size)
  1581.         SetComboBoxSize(combo);
  1582.         LayoutChildren(combo);
  1583.         DrawShadow(combo);
  1584.     }
  1585.     }
  1586.     if (combo_p->type == XmDROP_DOWN_COMBO_BOX)
  1587.     SetTextFieldData(combo_p, NULL);
  1588.     else
  1589.     SetLabelData(combo_p, NULL, FALSE);
  1590. #endif
  1591.  
  1592. }
  1593. /*----------------------------------------------------------------------*/
  1594. /* extern */ void
  1595. XfeComboBoxAddItemUnique(Widget w,XmString item,int position)
  1596. {
  1597. /*     XfeComboBoxPart *        cp = _XfeComboBoxPart(w); */
  1598.  
  1599.     assert( _XfeIsAlive(w) );
  1600.     assert( XfeIsComboBox(w) );
  1601. }
  1602. /*----------------------------------------------------------------------*/
  1603.