home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WCOMBOX.HPP < prev    next >
C/C++ Source or Header  |  1996-12-03  |  16KB  |  473 lines

  1. /*************************************************************************
  2.  *
  3.  * WComboBox -- Wrapper for the combobox control.
  4.  *
  5.  *   Events:
  6.  *
  7.  *       BeginOwnerDraw -- Called before the first DrawItem.
  8.  *
  9.  *       Change -- Occurs whenever the edit box changes.
  10.  *
  11.  *       DataAvailable --
  12.  *
  13.  *       DataClose --
  14.  *
  15.  *       DataOpen --
  16.  *
  17.  *       DataRequest --
  18.  *
  19.  *       DoubleClick -- When an item in the list box is double-clicked.
  20.  *
  21.  *       DrawItem -- Called for owner-draw.
  22.  *
  23.  *       DropDown -- The list box is about to drop down.
  24.  *
  25.  *       DropDownSelect --
  26.  *
  27.  *       EndOwnerDraw -- Called after last DrawItem.
  28.  *
  29.  *       Select -- When an item in the list box has been selected.
  30.  *
  31.  *************************************************************************/
  32.  
  33. #ifndef _WCOMBOX_HPP_INCLUDED
  34. #define _WCOMBOX_HPP_INCLUDED
  35.  
  36. #ifndef _WNO_PRAGMA_PUSH
  37. #pragma pack(push,8);
  38. #pragma enum int;
  39. #endif
  40.  
  41. #ifndef _WCONTROL_HPP_INCLUDED
  42. #  include "wcontrol.hpp"
  43. #endif
  44.  
  45. #ifndef _WLOCALE_HPP_INCLUDED
  46. #  include "wlocale.hpp"
  47. #endif
  48.  
  49. #ifndef _WDRAWITM_HPP_INCLUDED
  50. #  include "wdrawitm.hpp"
  51. #endif
  52.  
  53. #ifndef _WDATATRG_HPP_INCLUDED
  54. #  include "wdatatrg.hpp"
  55. #endif
  56.  
  57. //
  58. // ComboBox styles
  59. //
  60.  
  61. #define WCBSDefault           ((WStyle)0x50200201L) // WS_VISIBLE|CBS_HASSTRINGS|CBS_SIMPLE|WS_CHILD|WS_VSCROLL
  62. #define WCBSSimple            ((WStyle)0x00000001L) // CBS_SIMPLE
  63. #define WCBSDropDown          ((WStyle)0x00000002L) // CBS_DROPDOWN
  64. #define WCBSDropDownList      ((WStyle)0x00000003L) // CBS_DROPDOWNLIST
  65. #define WCBSOwnerDrawFixed    ((WStyle)0x00000010L) // CBS_OWNERDRAWFIXED
  66. #define WCBSOwnerDrawVariable ((WStyle)0x00000020L) // CBS_OWNERDRAWVARIABLE
  67. #define WCBSAutoHScroll       ((WStyle)0x00000040L) // CBS_AUTOHSCROLL
  68. #define WCBSOEMConvert        ((WStyle)0x00000080L) // CBS_OEMCONVERT
  69. #define WCBSSort              ((WStyle)0x00000100L) // CBS_SORT
  70. #define WCBSHasStrings        ((WStyle)0x00000200L) // CBS_HASSTRINGS
  71. #define WCBSNoIntegralHeight  ((WStyle)0x00000400L) // CBS_NOINTEGRALHEIGHT
  72. #define WCBSDisableNoScroll   ((WStyle)0x00000800L) // CBS_DISABLENOSCROLL
  73. #define WCBSUpperCase         ((WStyle)0x00002000L) // CBS_UPPERCASE
  74. #define WCBSLowerCase         ((WStyle)0x00004000L) // CBS_LOWERCASE
  75.  
  76. struct WComboBoxFDXData {
  77.     WStringArray                items;
  78.     WInt                        selected;
  79. };
  80.  
  81. class WCMCLASS WComboBox : public WControl {
  82.     WDeclareSubclass( WComboBox, WControl );
  83.     
  84.     public:
  85.  
  86.         /**************************************************************
  87.          * Constructors and Destructors
  88.          **************************************************************/
  89.  
  90.         WComboBox();
  91.     
  92.         ~WComboBox();
  93.  
  94.         /**************************************************************
  95.          * Properties
  96.          **************************************************************/
  97.  
  98.         // Count
  99.         //
  100.         //     Returns the number of items in the list box, or negative
  101.         //     if an error occurs.
  102.  
  103.         WInt GetCount() const;
  104.  
  105.         // DataColumns
  106.         //
  107.         //     DataTarget property
  108.  
  109.         WString GetDataColumns() const;
  110.         WBool   SetDataColumns( const WString & cols );
  111.  
  112.         // DataLookupColumns
  113.         //
  114.         //     DataTarget property
  115.  
  116.         WString GetDataLookupColumns() const;
  117.         WBool   SetDataLookupColumns( const WString & cols );
  118.  
  119.         // DataLookupSource
  120.         //
  121.         //     DataTarget property
  122.  
  123.         WDataSource *GetDataLookupSource() const;
  124.         WBool        SetDataLookupSource( WDataSource *source );
  125.  
  126.         // DataSource
  127.         //
  128.         //     DataTarget property
  129.  
  130.         WDataSource *GetDataSource() const;
  131.         WBool        SetDataSource( WDataSource *source );
  132.  
  133.         // FDXDataSource
  134.  
  135.         WBool SetFDXDataSource( WStringArray * fdxDataSource );
  136.         WBool SetFDXDataSource( WInt * fdxDataSource );
  137.  
  138.         // DroppedDown
  139.         //
  140.         //     Get/set the drop down state.  TRUE = dropped, FALSE = not.
  141.  
  142.         WBool GetDroppedDown() const;
  143.         WBool SetDroppedDown( WBool show );
  144.  
  145.         // EditSelection
  146.         //
  147.         //     The current selection in the edit control.  The
  148.         //     selection points start at 0 and occur between the characters.
  149.         //     Note that no value can be greater than 65534.  When setting,
  150.         //     set start=-1 to deselect everything, or set end=-1 to
  151.         //     select from start to end of text.
  152.  
  153.         WRange GetEditSelection() const;
  154.         WBool SetEditSelection( const WRange & editSelection );
  155.  
  156.         // ExtendedUI
  157.         //
  158.         //     Controls whether or not the combobox uses the extended UI.
  159.         //     If TRUE, the F4 key does nothing and the down arrow key
  160.         //     opens the drop-down list.  Otherwise the F4 key opens
  161.         //     the drop-down list and the down arrow key moves the
  162.         //     current selection.
  163.  
  164.         WBool GetExtendedUI() const;
  165.         WBool SetExtendedUI( WBool on );
  166.  
  167.         // Selected
  168.         //
  169.         //     Get/set the selected item in the list box.  A selected
  170.         //     value of -1 means nothing is selected.  Setting the value
  171.         //     to -1 clears the selected entry and the edit box.
  172.  
  173.         WInt GetSelected() const;
  174.         WBool SetSelected( WInt index );
  175.  
  176.         // Sort
  177.         //
  178.         //     Get/set the sort mode.
  179.  
  180.         WBool GetSort() const;
  181.         WBool SetSort( WBool sort );
  182.  
  183.         // Locale (for type of sort)
  184.         //
  185.         //
  186.         WBool           SetLocale( WLocaleID locID );
  187.         WLocaleID       GetLocale();
  188.  
  189.         // TextLimit
  190.         //
  191.         //     Get/set the maximum # of characters the user can type
  192.         //     into the edit box. 0 or negative means set to maximum.
  193.  
  194.         WLong GetTextLimit() const;
  195.         WBool SetTextLimit( WLong limit );
  196.  
  197.  
  198.         /**************************************************************
  199.          * Methods
  200.          **************************************************************/
  201.  
  202.         // Add
  203.         //
  204.         //     Adds an item.  If itemNumber is set to >= 0, item is
  205.         //     inserted at the given location.  If the list is sorted
  206.         //     and itemNumber is set to -1, inserts in correct spot;
  207.         //     otherwise adds to the end.  Can also set optional
  208.         //     per-item data.
  209.         //     Returns the index of the item, or a negative value in
  210.         //     case of error.
  211.  
  212.         WInt Add( const WChar * string, WInt itemNumber=-1,
  213.                   void * itemUserData=NULL, WBool addInSortedOrder=TRUE );
  214.  
  215.         // Clear
  216.         //
  217.         //     Clear the edit box.
  218.  
  219.         void  Clear();
  220.  
  221.         // Copy
  222.         //
  223.         //     Copy the selected area into the clipboard.
  224.  
  225.         WBool Copy();
  226.  
  227.         // Cut
  228.         //
  229.         //     Copy the selected area into the clipboard then clear it.
  230.  
  231.         void  Cut();
  232.  
  233.         // DataAddLookupItem
  234.         //
  235.         //     Allows the user to manually fill the list with lookup items.
  236.         //     This is an alternative method to setting the DataLookupSource
  237.         //     and DataLookupColumns properties.
  238.  
  239.         WInt DataAddLookupItem( const WDataValue & value,
  240.                                 const WChar * string = NULL,
  241.                                 WInt itemNumber=-1, void * itemUserData=NULL,
  242.                                 WBool addInSortedOrder=TRUE );
  243.  
  244.         // DataFetchLookupItems
  245.         //
  246.         //      Forces the lookup items to be fetched from the database
  247.         //      (according to the DataLookupSource and DataLookupColumns
  248.         //      properties).
  249.         //      This is normally done when either data source is opened...
  250.  
  251.         WBool DataFetchLookupItems();
  252.  
  253.         // Delete
  254.         //
  255.         //     Deletes the specified item.  If an item's data is set,
  256.         //     invokes the WDeleteItemEvent event first.  Returns the count
  257.         //     of items remaining in the list, or negative if error occurs.
  258.  
  259.         WInt Delete( WInt itemNumber );
  260.  
  261.         // DeleteAll
  262.  
  263.         WBool DeleteAll ();
  264.  
  265.         // Find
  266.         //
  267.         //     Finds the first string that matches a given prefix.  The
  268.         //     search starts immediately AFTER the given index (use -1
  269.         //     to search from the beginning) and wraps when the bottom
  270.         //     is reached.  The search is not case-sensitive.  If exact
  271.         //     is specified, the string must match exactly, otherwise
  272.         //     a prefix match is done.  Returns the index of the match
  273.         //     or negative on error.
  274.  
  275.         WInt Find( const WChar *match, WInt startAfter=-1,
  276.                    WBool exact=FALSE ) const;
  277.  
  278.         // Paste
  279.         //
  280.         //     Paste the clipboard text into the current selection.
  281.  
  282.         void Paste();
  283.  
  284.         // Reset
  285.         //
  286.         //     Reset (clear) both the list box and edit box.
  287.  
  288.         void Reset();
  289.  
  290.         // Select
  291.         //
  292.         //     Find and select an item.  Searches for the first item whose
  293.         //     prefix matches (case-insensitive) the given string.  Returns
  294.         //     the index of the new selected item, or negative if an error
  295.         //     occurs.  If startAfter is -1, search starts at first item.
  296.  
  297.         WInt Select( const WChar * match, WInt startAfter=-1 );
  298.  
  299.         // Undo
  300.         //
  301.         //     Undo the last change to the edit box.
  302.  
  303.         WBool Undo();
  304.  
  305.         /**************************************************************
  306.          * Item Properties
  307.          **************************************************************/
  308.  
  309.         // DataLookupValue
  310.         //
  311.         //     Get the lookup value associated with the given list item.
  312.  
  313.         WDataValue GetDataLookupValue( WInt itemNumber ) const;
  314.  
  315.         // Text
  316.         //
  317.         //     Get the text of a specific item in the list.  First two
  318.         //     versions return a WString, which is set to a null string
  319.         //     if an error occurs.  Last version copies it into a buffer
  320.         //     and returns the length, or a negative value.
  321.  
  322.         WString GetText( WInt itemNumber ) const;
  323.  
  324.         // TextLength
  325.         //
  326.         //     Get the length of the text of an item in the list (without
  327.         //     the null character).  A negative value is returned in case
  328.         //     of error.
  329.  
  330.         WInt GetTextLength( WInt itemNumber ) const;
  331.  
  332.         // UserData
  333.         //
  334.         //     Get/set per-item data.  When getting data, a value of
  335.         //     ((void *)-1) for the itemUserData indicates an error.
  336.  
  337.         WBool  SetUserData( WInt itemNumber, void * itemData );
  338.         void * GetUserData( WInt itemNumber ) const;
  339.  
  340.         // Height
  341.         //
  342.         //     Get/set height of listbox items or the edit box.  If
  343.         //     itemNumber is -1, works on edit box, otherwise must be
  344.         //     0 if the WCBSOwnerDrawVariable flag is not set, otherwise
  345.         //     it is the index of the item.  For get, negative value
  346.         //     is returned to indicate error.
  347.  
  348.         WInt GetHeight( WInt itemNumber ) const;
  349.         WBool SetHeight( WInt itemNumber, WInt height );
  350.  
  351.         /**************************************************************
  352.          * Others
  353.          **************************************************************/
  354.  
  355.         virtual size_t GetTextLength() const;
  356.  
  357.         virtual WBool FDXIn();
  358.  
  359.         virtual WBool FDXOut();
  360.     
  361.         virtual WBool FillDragEventData( WDragEventData & event ) const;
  362.  
  363.         WBool DestroyEventHandler( WWindow * window, WEventData * event );
  364.  
  365.         WLong ProcessChildMessage( WWindowHandle hWnd, WUInt msg,
  366.                                    WUInt wParam, WLong lParam );
  367.  
  368.         virtual WBool ProcessMessage( const WMessage & msg,
  369.                                       WLong & returns );
  370.  
  371.         virtual WBool SetHeight( const WInt & height, WBool update=TRUE );
  372.         virtual WInt GetHeight() const;
  373.  
  374.         virtual WBool SetText( const WString & str );
  375.         virtual WString GetText() const;
  376.  
  377.         virtual WBool SetUserData( void * userData );
  378.         virtual void * GetUserData() const;
  379.  
  380.         virtual WBool ProcessCommand( WUInt id, WNotify code,
  381.                                       WNotifyInfo info, WLong & returns );
  382.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  383.                                    void * data=NULL );
  384.     
  385.         virtual WBool DefaultProcess( const WMessage & msg,
  386.                                       WLong & returns );
  387.     
  388.         virtual WBool      AttachToWindow( WWindowHandle hWnd, WBool destroy,
  389.                                            WBool subclass );
  390.         virtual WWindowHandle DetachFromWindow();
  391.     
  392.         virtual WStyle        GetDefaultStyle() const;
  393.         virtual WStyle        GetDefaultExtendedStyle() const;
  394.         virtual const WChar * InitializeClass();
  395.  
  396.         WBool DeleteItemHandler( WComboBox *, WDeleteItemEventData *ev );
  397.  
  398.         // Event handlers for the DataTarget
  399.  
  400.         WBool DataOpenHandler( WComboBox *, WDataOpenEventData *ev );
  401.         WBool DataCloseHandler( WComboBox *, WDataCloseEventData *ev );
  402.         WBool DataAvailableHandler( WComboBox *, WDataAvailableEventData *ev );
  403.         WBool DataRequestHandler( WComboBox *, WDataRequestEventData *ev );
  404.         WBool DataLookupItemHandler( WComboBox *, WDataLookupItemEventData *ev );
  405.  
  406.         /**************************************************************
  407.          * Overrides
  408.          **************************************************************/
  409.  
  410.         virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
  411.         virtual WBool SetFont( const WFont & font, WBool preserveSize=TRUE );
  412.         virtual WRect GetRectangle( WBool absolute=FALSE ) const;
  413.         virtual WBool Move( const WRect & rectangle, WBool update=TRUE );
  414.         virtual WBool Move( const WRect & rectangle, WDeferMoveHandle & dwp );
  415.         virtual WBool Move( const WPoint & point, WBool update=TRUE );
  416.         virtual WBool Move( const WPoint & point, WDeferMoveHandle & dwp );
  417.  
  418.         /**************************************************************
  419.          * Internal
  420.          **************************************************************/
  421.  
  422.     protected:
  423.  
  424.         WBool IndirectUserData( WBool indirect );
  425.  
  426.         WBool  SetRealUserData( WInt itemNumber, void * itemData );
  427.         void * GetRealUserData( WInt itemNumber ) const;
  428.  
  429.         WBool AllocLookup();
  430.  
  431.         void RemoveLookupItems();
  432.     
  433.         virtual WBool LoadWindow( WWindow * parent,
  434.                                   const WResourceID & id,
  435.                                   WModuleHandle module=_ApplicationModule );
  436.     
  437.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  438.                                   const WChar *className,
  439.                                   const WChar *title, const WRect & r,
  440.                                   WStyle wstyle, WStyle exStyle,
  441.                                   void * data=NULL );
  442.  
  443.         /**************************************************************
  444.          * Data members
  445.          **************************************************************/
  446.  
  447.     private:
  448.  
  449.         WWindowHandle       _editChild;
  450.         WCallbackProc       _editWndProc;
  451.         WWindowHandle       _listChild;
  452.         WCallbackProc       _listWndProc;
  453.         WLong               _textLimit;
  454.         WBool               _indirectUserData;
  455.         WDataLookup *       _dataLookup;
  456.         WDataTargetCell *   _dataTarget;
  457.         WInt                _initialValue;
  458.         WBool               _wasEnabled;
  459.         WBool               _wasPainting;
  460.         WBool               _ignoreChange;
  461.         WStringArray *      _fdxDataSourceStringArray;
  462.         WInt *              _fdxDataSourceInt;
  463.         WInt                _realHeight;
  464. };
  465.  
  466.  
  467. #ifndef _WNO_PRAGMA_PUSH
  468. #pragma enum pop;
  469. #pragma pack(pop);
  470. #endif
  471.  
  472. #endif // _WCOMBOX_HPP_INCLUDED
  473.