home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / hpp.z / WCOMBOX.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-25  |  15.3 KB  |  456 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,4);
  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.         // Selected
  157.         //
  158.         //     Get/set the selected item in the list box.  A selected
  159.         //     value of -1 means nothing is selected.  Setting the value
  160.         //     to -1 clears the selected entry and the edit box.
  161.  
  162.         WInt GetSelected() const;
  163.         WBool SetSelected( WInt index );
  164.  
  165.         // Sort
  166.         //
  167.         //     Get/set the sort mode.
  168.  
  169.         WBool GetSort() const;
  170.         WBool SetSort( WBool sort );
  171.  
  172.         // Locale (for type of sort)
  173.         //
  174.         //
  175.         WBool           SetLocale( WLocaleID locID );
  176.         WLocaleID       GetLocale();
  177.  
  178.         // TextLimit
  179.         //
  180.         //     Get/set the maximum # of characters the user can type
  181.         //     into the edit box. 0 or negative means set to maximum.
  182.  
  183.         WLong GetTextLimit() const;
  184.         WBool SetTextLimit( WLong limit );
  185.  
  186.  
  187.         /**************************************************************
  188.          * Methods
  189.          **************************************************************/
  190.  
  191.         // Add
  192.         //
  193.         //     Adds an item.  If itemNumber is set to >= 0, item is
  194.         //     inserted at the given location.  If the list is sorted
  195.         //     and itemNumber is set to -1, inserts in correct spot;
  196.         //     otherwise adds to the end.  Can also set optional
  197.         //     per-item data.
  198.         //     Returns the index of the item, or a negative value in
  199.         //     case of error.
  200.  
  201.         WInt Add( const WChar * string, WInt itemNumber=-1,
  202.                   void * itemUserData=NULL, WBool addInSortedOrder=TRUE );
  203.  
  204.         // Clear
  205.         //
  206.         //     Clear the edit box.
  207.  
  208.         void  Clear();
  209.  
  210.         // Copy
  211.         //
  212.         //     Copy the selected area into the clipboard.
  213.  
  214.         WBool Copy();
  215.  
  216.         // Cut
  217.         //
  218.         //     Copy the selected area into the clipboard then clear it.
  219.  
  220.         void  Cut();
  221.  
  222.         // DataAddLookupItem
  223.         //
  224.         //     Allows the user to manually fill the list with lookup items.
  225.         //     This is an alternative method to setting the DataLookupSource
  226.         //     and DataLookupColumns properties.
  227.  
  228.         WInt DataAddLookupItem( const WDataValue & value,
  229.                                 const WChar * string = NULL,
  230.                                 WInt itemNumber=-1, void * itemUserData=NULL,
  231.                                 WBool addInSortedOrder=TRUE );
  232.  
  233.         // DataFetchLookupItems
  234.         //
  235.         //      Forces the lookup items to be fetched from the database
  236.         //      (according to the DataLookupSource and DataLookupColumns
  237.         //      properties).
  238.         //      This is normally done when either data source is opened...
  239.  
  240.         WBool DataFetchLookupItems();
  241.  
  242.         // Delete
  243.         //
  244.         //     Deletes the specified item.  If an item's data is set,
  245.         //     invokes the WDeleteItemEvent event first.  Returns the count
  246.         //     of items remaining in the list, or negative if error occurs.
  247.  
  248.         WInt Delete( WInt itemNumber );
  249.  
  250.         // DeleteAll
  251.  
  252.         WBool DeleteAll ();
  253.  
  254.         // Find
  255.         //
  256.         //     Finds the first string that matches a given prefix.  The
  257.         //     search starts immediately AFTER the given index (use -1
  258.         //     to search from the beginning) and wraps when the bottom
  259.         //     is reached.  The search is not case-sensitive.  If exact
  260.         //     is specified, the string must match exactly, otherwise
  261.         //     a prefix match is done.  Returns the index of the match
  262.         //     or negative on error.
  263.  
  264.         WInt Find( const WChar *match, WInt startAfter=-1,
  265.                    WBool exact=FALSE ) const;
  266.  
  267.         // Paste
  268.         //
  269.         //     Paste the clipboard text into the current selection.
  270.  
  271.         void Paste();
  272.  
  273.         // Reset
  274.         //
  275.         //     Reset (clear) both the list box and edit box.
  276.  
  277.         void Reset();
  278.  
  279.         // Select
  280.         //
  281.         //     Find and select an item.  Searches for the first item whose
  282.         //     prefix matches (case-insensitive) the given string.  Returns
  283.         //     the index of the new selected item, or negative if an error
  284.         //     occurs.  If startAfter is -1, search starts at first item.
  285.  
  286.         WInt Select( const WChar * match, WInt startAfter=-1 );
  287.  
  288.         // Undo
  289.         //
  290.         //     Undo the last change to the edit box.
  291.  
  292.         WBool Undo();
  293.  
  294.         /**************************************************************
  295.          * Item Properties
  296.          **************************************************************/
  297.  
  298.         // DataLookupValue
  299.         //
  300.         //     Get the lookup value associated with the given list item.
  301.  
  302.         WDataValue GetDataLookupValue( WInt itemNumber ) const;
  303.  
  304.         // Text
  305.         //
  306.         //     Get the text of a specific item in the list.  First two
  307.         //     versions return a WString, which is set to a null string
  308.         //     if an error occurs.  Last version copies it into a buffer
  309.         //     and returns the length, or a negative value.
  310.  
  311.         WString GetText( WInt itemNumber ) const;
  312.  
  313.         // TextLength
  314.         //
  315.         //     Get the length of the text of an item in the list (without
  316.         //     the null character).  A negative value is returned in case
  317.         //     of error.
  318.  
  319.         WInt GetTextLength( WInt itemNumber ) const;
  320.  
  321.         // UserData
  322.         //
  323.         //     Get/set per-item data.  When getting data, a value of
  324.         //     ((void *)-1) for the itemUserData indicates an error.
  325.  
  326.         WBool  SetUserData( WInt itemNumber, void * itemData );
  327.         void * GetUserData( WInt itemNumber ) const;
  328.  
  329.         // Height
  330.         //
  331.         //     Get/set height of listbox items or the edit box.  If
  332.         //     itemNumber is -1, works on edit box, otherwise must be
  333.         //     0 if the WCBSOwnerDrawVariable flag is not set, otherwise
  334.         //     it is the index of the item.  For get, negative value
  335.         //     is returned to indicate error.
  336.  
  337.         WInt GetHeight( WInt itemNumber ) const;
  338.         WBool SetHeight( WInt itemNumber, WInt height );
  339.  
  340.         /**************************************************************
  341.          * Others
  342.          **************************************************************/
  343.  
  344.         virtual size_t GetTextLength() const;
  345.  
  346.         virtual WBool FDXIn();
  347.  
  348.         virtual WBool FDXOut();
  349.     
  350.         virtual WBool FillDragEventData( WDragEventData & event ) const;
  351.  
  352.         WBool DestroyEventHandler( WWindow * window, WEventData * event );
  353.  
  354.         WULong ProcessChildMessage( WWindowHandle hWnd, WULong msg,
  355.                                     WULong wParam, WULong lParam );
  356.  
  357.         virtual WBool ProcessMessage( const WMessage & msg,
  358.                                       WLong & returns );
  359.  
  360.         virtual WBool SetHeight( const WInt & height, WBool update=TRUE );
  361.         virtual WInt GetHeight() const;
  362.  
  363.         virtual WBool SetText( const WString & str );
  364.         virtual WString GetText() const;
  365.  
  366.         virtual WBool SetUserData( void * userData );
  367.         virtual void * GetUserData() const;
  368.  
  369.         virtual WBool ProcessCommand( WUInt id, WNotify code,
  370.                                       WNotifyInfo info, WLong & returns );
  371.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  372.                                    void * data=NULL );
  373.     
  374.         virtual WBool DefaultProcess( const WMessage & msg,
  375.                                       WLong & returns );
  376.     
  377.         virtual WBool      AttachToWindow( WWindowHandle hWnd, WBool destroy,
  378.                                            WBool subclass );
  379.         virtual WWindowHandle DetachFromWindow();
  380.     
  381.         virtual WStyle        GetDefaultStyle() const;
  382.         virtual WStyle        GetDefaultExtendedStyle() const;
  383.         virtual const WChar * InitializeClass();
  384.  
  385.         WBool DeleteItemHandler( WComboBox *, WDeleteItemEventData *ev );
  386.  
  387.         // Event handlers for the DataTarget
  388.  
  389.         WBool DataOpenHandler( WComboBox *, WDataOpenEventData *ev );
  390.         WBool DataCloseHandler( WComboBox *, WDataCloseEventData *ev );
  391.         WBool DataAvailableHandler( WComboBox *, WDataAvailableEventData *ev );
  392.         WBool DataRequestHandler( WComboBox *, WDataRequestEventData *ev );
  393.         WBool DataLookupItemHandler( WComboBox *, WDataLookupItemEventData *ev );
  394.  
  395.         /**************************************************************
  396.          * Internal
  397.          **************************************************************/
  398.  
  399.         virtual WRect GetRectangle( WBool absolute=FALSE ) const;
  400.         virtual WBool Move( const WRect & rectangle, WBool update=TRUE );
  401.         virtual WBool Move( const WRect & rectangle, WDeferMoveHandle & dwp );
  402.         virtual WBool Move( const WPoint & point, WBool update=TRUE );
  403.         virtual WBool Move( const WPoint & point, WDeferMoveHandle & dwp );
  404.  
  405.     protected:
  406.  
  407.         WBool IndirectUserData( WBool indirect );
  408.  
  409.         WBool  SetRealUserData( WInt itemNumber, void * itemData );
  410.         void * GetRealUserData( WInt itemNumber ) const;
  411.  
  412.         WBool AllocLookup();
  413.  
  414.         void RemoveLookupItems();
  415.     
  416.         virtual WBool LoadWindow( WWindow * parent,
  417.                                   const WResourceID & id,
  418.                                   WModuleHandle module=_ApplicationModule );
  419.     
  420.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  421.                                   const WChar *className,
  422.                                   const WChar *title, const WRect & r,
  423.                                   WStyle wstyle, WStyle exStyle,
  424.                                   void * data=NULL );
  425.  
  426.         /**************************************************************
  427.          * Data members
  428.          **************************************************************/
  429.  
  430.     private:
  431.  
  432.         WWindowHandle       _editChild;
  433.         WCallbackProc       _editWndProc;
  434.         WWindowHandle       _listChild;
  435.         WCallbackProc       _listWndProc;
  436.         WLong               _textLimit;
  437.         WBool               _indirectUserData;
  438.         WDataLookup *       _dataLookup;
  439.         WDataTargetCell *   _dataTarget;
  440.         WInt                _initialValue;
  441.         WBool               _wasEnabled;
  442.         WBool               _wasPainting;
  443.         WBool               _ignoreChange;
  444.         WStringArray *      _fdxDataSourceStringArray;
  445.         WInt *              _fdxDataSourceInt;
  446.         WInt                _realHeight;
  447. };
  448.  
  449.  
  450. #ifndef _WNO_PRAGMA_PUSH
  451. #pragma enum pop;
  452. #pragma pack(pop);
  453. #endif
  454.  
  455. #endif // _WCOMBOX_HPP_INCLUDED
  456.