home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / ICOMBOBX.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  27KB  |  506 lines

  1. #ifndef _ICOMBOBX_
  2.   #define _ICOMBOBX_
  3. /*******************************************************************************
  4. * FILE NAME: icombobx.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IComboBox - This class creates and manages the combo-box control window. *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _IENTRYFD_
  19.   #include <ientryfd.hpp>
  20. #endif
  21.  
  22. // Forward declarations for other classes:
  23. class IListBox;
  24. #ifndef _IRECT_
  25.   #include <irect.hpp>
  26. #endif
  27.  
  28. /*----------------------------------------------------------------------------*/
  29. /* Align classes on four byte boundary.                                       */
  30. /*----------------------------------------------------------------------------*/
  31. #pragma pack(4)
  32.  
  33. /*----------------------------------------------------------------------------*/
  34. /* Turn off warning for compiler generated copy/assignment                    */
  35. /*----------------------------------------------------------------------------*/
  36. #pragma info(nocpy)
  37.  
  38. class IComboBox : public IEntryField {                      // $JJB!c
  39. typedef IEntryField Inherited;
  40. /*******************************************************************************
  41. * The IComboBox class creates and manages the combination box control window.  *
  42. * The IComboBox class combines an entry field and a list box to form one       *
  43. * control that contains the features of both.                                  *
  44. *                                                                              *
  45. * Specific keystroke processing, such as creating a numeric-only input field,  *
  46. * can be implemented by subclassing the IKeyboardHandler class and adding the  *
  47. * handler to the combination box object.                                       *
  48. *                                                                              *
  49. * EXAMPLE:                                                                     *
  50. *   cb_test = new IComboBox (this, ID_COMBOBOX, IRectangle(x1, y1, x2, y2));   *
  51. *                                                                              *
  52. * The example below shows how to add a item to the listbox part of the combobox.*
  53. *   cb_test.addAscending("First line");                                        *
  54. *******************************************************************************/
  55.  
  56. public:
  57. /*---------------------- Style --------------------------------------------
  58.   The following functions provide a means to set and query combination box
  59.   styles:
  60.  
  61.     Style - Nested class that provides static members that define the set of
  62.             valid combination box styles.  These styles can be used in
  63.             conjunction with the styles defined by the nested classes
  64.             IWindow::Style and IControl::Style.  For example, you could
  65.             define an instance of the IComboBox::Style class and initialize
  66.             it like:
  67.               IComboBox::Style
  68.                 style = IComboBox::dropDownType | IControl::tabStop;
  69.             An object of this type is provided when the combination box is
  70.             created.  A customizable default is used if no styles are
  71.             specified.  Once the object is constructed, IComboBox, IWindow,
  72.             and IControl member functions can be used to set or query the
  73.             object's style.
  74.  
  75.             The declaration of the IComboBox::Style nested class is
  76.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  77.  
  78.   The valid combination box styles are:
  79.     classDefaultStyle - Original default style for this class, which is
  80.                         simpleType | IEntryField::alignLeft | anyData | IWindow::visible.
  81.     simpleType        - Specifies both the entry field control and the list
  82.                         box control are visible.  When the selection changes
  83.                         in the list box control, the text of the selected
  84.                         item in the list box control is placed in the entry
  85.                         field.  An item can also be selected from the list
  86.                         box control by typing a portion of the item into the
  87.                         entry field.  The entry will be completed with the
  88.                         closest match from the list box.
  89.                         NOTE: The parent of a simpleType IComboBox should not
  90.                               set the IWindow::clipChildren style.  Using
  91.                               this style prevents OS/2 from painting a small
  92.                               region below the list box part of the IComboBox
  93.                               object.
  94.     dropDownType      - Specifies the drop-down variation of the combination
  95.                         box, which is the same as simpleType, except that the
  96.                         list box control is hidden until the user requests
  97.                         that it should be displayed.
  98.     dropDownListType  - Specifies the drop-down list variation of the
  99.                         combination box.  The drop-down list only displays
  100.                         one item in the entry field, until the user causes
  101.                         the display of the list box control in order to make
  102.                         alternative selections in the list box.  The drop-
  103.                         down list does not allow a user to type information
  104.                         into the entry field.  The entry field control is
  105.                         replaced by a static control that displays the
  106.                         current selection from the list box.
  107.     anyData           - Sets the combination box entry field to accept text
  108.                         that is a mixture of SBCS and DBCS characters.
  109.  
  110.                         Note: If the text contains both single-byte and
  111.                         double-byte characters and will be converted from an
  112.                         ASCII code page into an EBCDIC code page, this style
  113.                         causes an entry field to ignore accounting for
  114.                         shift-in and shift-out characters that would be
  115.                         introduced into its text.  The opposite of mixedData.
  116.     sbcsData          - Sets the combination box entry field to accept
  117.                         single-byte text only.
  118.     dbcsData          - Sets the combination box entry field to accept
  119.                         double-byte text only.
  120.     mixedData         - Sets the combination box entry field to accept text
  121.                         that is a mixture of SBCS and DBCS characters.
  122.                         Conversion from an ASCII DBCS code page to an EBCDIC
  123.                         DBCS code page can result in a possible increase in
  124.                         the length of the data because of the addition of
  125.                         SI/SO characters, but will not exceed the text limit
  126.                         of the entry field.
  127.     horizontalScroll  - Provides horizontal scrolling for the list box
  128.                         control.
  129.  
  130.   The following functions provide a means of getting and setting the default
  131.   style for this class:
  132.     defaultStyle    - Returns the current default style.  This is the same as
  133.                       classDefaultStyle unless setDefaultStyle has been
  134.                       called.
  135.     setDefaultStyle - Sets the default style for all subsequent combination
  136.                       boxes.
  137. -------------------------------------------------------------------------*/
  138. INESTEDBITFLAGCLASSDEF2(Style, IComboBox, IWindow, IControl);
  139.  
  140. static const Style
  141.   classDefaultStyle,
  142.   simpleType,
  143.   dropDownType,
  144.   dropDownListType,
  145.   anyData,
  146.   sbcsData,
  147.   dbcsData,
  148.   mixedData,
  149.   horizontalScroll;
  150.  
  151. static Style
  152.   defaultStyle();
  153. static void
  154.   setDefaultStyle(Style style);
  155.  
  156. /*------------------------ Constructors ----------------------------------------
  157. | You can create instances of this class in the following ways:                |
  158. |    - From a control ID, parent and owner windows, rectangle, and style.      |
  159. |      This creates the specified combination box control and an object        |
  160. |      for it.                                                                 |
  161. |    - From the ID of a combination box control on a dialog window.            |
  162. |      This creates the object for the specified combination box control.      |
  163. |    - From the window handle of an existing combination box control.          |
  164. |      This creates the object for the specified combination box control.      |
  165. ------------------------------------------------------------------------------*/
  166.   IComboBox(unsigned long id,
  167.             IWindow* parent,
  168.             IWindow* owner,
  169.             const IRectangle& initial= IRectangle(),
  170.             const Style& style = defaultStyle() );
  171.  
  172.   IComboBox(unsigned long id,
  173.             IWindow* parent);
  174.  
  175.   IComboBox(const IWindowHandle& handle);
  176.  
  177.   virtual ~IComboBox();
  178.  
  179. /*------------------------ Scrolling Style Operations --------------------------
  180. |   isHorizontalScroll      - Returns true if the horizontalScroll style is    |
  181. |                             set.                                             |
  182. ------------------------------------------------------------------------------*/
  183. Boolean
  184.   isHorizontalScroll();
  185.  
  186. /*-------------------------------- Type Operations -----------------------------
  187. | The following functions are used to set or return the type of combination    |
  188. | box:                                                                         |
  189. |   ControlType    - Enumeration that defines the types of combination boxes   |
  190. |                    (simple, dropDown, and dropDownList).                     |
  191. |   type           - Returns the currently set combination box type.           |
  192. ------------------------------------------------------------------------------*/
  193. enum ControlType { simple, dropDown, dropDownList };
  194. ControlType
  195.   type() const;
  196.  
  197. /*-------------------------------- List Box Operations -------------------------
  198. | The following functions are used to query, show, or hide the list box part   |
  199. | of the combination box:                                                      |
  200. |   isListShowing - Returns true if the list box control is showing.           |
  201. |   showList      - Shows or hides the list box control.  This is only valid   |
  202. |                   for the dropDown and dropDownList types.                   |
  203. |   hideList      - Hides the list box control.                                |
  204. ------------------------------------------------------------------------------*/
  205. Boolean
  206.   isListShowing() const;
  207. IComboBox&
  208.   showList(Boolean show=true);                // $JJB!c
  209. IComboBox&
  210.   hideList();
  211.  
  212. /*------------------------ Add Item Operations ---------------------------------
  213. | The following functions are used to add a line of text to the list box       |
  214. | part of the combination box:                                                 |
  215. |   add          - Inserts the line in the list box in no specified order or   |
  216. |                  location.                                                   |
  217. |   addAsFirst   - Inserts the line at the front of the list box.              |
  218. |   addAsLast    - Inserts the line at the end of the list box.                |
  219. |   addAscending - Inserts the line in ascending sort order.                   |
  220. |   addDescending- Inserts the line in descending sort order.                  |
  221. ------------------------------------------------------------------------------*/
  222. unsigned long
  223.   add(unsigned long  index, const char* text),
  224.   addAsFirst(const char* text),
  225.   addAsLast(const char* text),
  226.   addAscending(const char* text),
  227.   addDescending(const char* text),
  228.   add(unsigned long  index, const IResourceId& resid),
  229.   addAsFirst(const IResourceId& resid),
  230.   addAsLast(const IResourceId& resid),
  231.   addAscending(const IResourceId& resid),
  232.   addDescending(const IResourceId& resid);
  233.  
  234. /*------------------------ Get/Change Item Operations --------------------------
  235. | The following functions get or change the text in the entryfield part of the |
  236. | combination box.                                                             |
  237. |   itemText    - Returns the text of an item in the list box portion of the   |
  238. |                 combination box.                                             |
  239. |   setItemText - Changes the text of an item in the list box portion of the   |
  240. |                 combination box.                                             |
  241. ------------------------------------------------------------------------------*/
  242. IString
  243.   itemText(unsigned long index) const;
  244. IComboBox&
  245.   setItemText(unsigned long index, const char* string);
  246.  
  247. /*------------------------ Remove Item Operations ------------------------------
  248. | The following functions remove all items or one item from the list box part  |
  249. | of the combination box:                                                      |
  250. |   removeAll - Removes all items from the list box.                           |
  251. |   remove    - Removes one item from the list box and returns the count of    |
  252. |               the number of items that remain.                               |
  253. ------------------------------------------------------------------------------*/
  254. IComboBox&
  255.   removeAll();
  256. long
  257.   remove(unsigned long index );
  258.  
  259. /*------------------------ Selection-State Operations --------------------------
  260. | The following functions set or return the selection-state operations:        |
  261. |   select             - Sets the selection state of an item based on the      |
  262. |                        Boolean value that is passed in.  If true is passed   |
  263. |                        in, the item is selected and any item that was        |
  264. |                        previously selected is deselected.  If false is       |
  265. |                        passed in, the item is deselected.                    |
  266. |   deselect           - Removes the selection state from an item.             |
  267. |   isSelected         - Returns the selection state of an item.               |
  268. |   deselectAll        - Removes the selection state from all items in the     |
  269. |                        list box.                                             |
  270. |   numberOfSelections - Returns 0 if no item is selected or 1 if an item is   |
  271. |                        selected.  The current selection does not change.     |
  272. |   selection          - Returns the 0-based index of the selected item.  If   |
  273. |                        no item is selected, -1 is returned.                  |
  274. ------------------------------------------------------------------------------*/
  275. IComboBox
  276.   &select(unsigned long index, Boolean select = true ),
  277.   &deselect(unsigned long index ),
  278.   &deselectAll();
  279. Boolean
  280.   isSelected(unsigned long index );
  281. unsigned long
  282.   numberOfSelections() const;
  283. long
  284.   selection();
  285.  
  286. /*------------------------ Scrolling Operations --------------------------------
  287. | The following functions scroll an item to the top of the list box or returns |
  288. | the item at the top of the list box:                                         |
  289. |   setTop - Scrolls the requested item to the top of the list box.            |
  290. |   top    - Returns the item number of the item currently at the top of the   |
  291. |            list box.  If there are no items in the list box, an exception    |
  292. |            is thrown.                                                        |
  293. | ------------------------------------------------------------------------------*/
  294. IComboBox&
  295.   setTop(unsigned long index);
  296. unsigned long
  297.   top() const;
  298.  
  299. /*------------------------ Handle Operations -----------------------------------
  300. | The following functions set or retrieve a handle of a list box item:         |
  301. |   setItemHandle - Sets a handle of a list box item.                          |
  302. |   itemHandle    - Returns a handle of a list box item.  An item without a    |
  303. |                   handle returns 0.                                          |
  304. ------------------------------------------------------------------------------*/
  305. IComboBox&
  306.   setItemHandle(unsigned long index, unsigned long handle );
  307. unsigned long
  308.   itemHandle(unsigned long index ) const;
  309.  
  310. /*---------------------------- Enumerations ------------------------------------
  311. | The following enumerations are defined:                                      |
  312. |   SearchType - Used for determining the type of search to perform.  Values   |
  313. |               are:                                                           |
  314. |               prefix      - Matching occurs if the leading characters        |
  315. |                             of the item contain the specified characters.    |
  316. |               substring   - Matching occurs if the item contains a substring |
  317. |                             of the specified characters.                     |
  318. |               exactMatch  - Matching occurs if the item is an exact match for|
  319. |                             the specified characters.                        |
  320. ------------------------------------------------------------------------------*/
  321. enum SearchType {
  322.   prefix,
  323.   substring,
  324.   exactMatch
  325. };
  326.  
  327. /*------------------------ Query Text Operation --------------------------------
  328. | The following function is used to find a text string in the list box:        |
  329. |   locateText - Returns the item number of the list box item that matches the |
  330. |                search string. Starts the search after the index.  If no      |
  331. |                match is found, it returns notFound.  If there is an error,   |
  332. |                an exception occurs.                                          |
  333. ------------------------------------------------------------------------------*/
  334. static const unsigned long notFound ;
  335. static const long first ;
  336. unsigned long
  337.   locateText(const char* searchString,
  338.              Boolean caseSensitive = true,
  339.              SearchType search = exactMatch,
  340.              long  index = first) const;
  341.  
  342. /*------------------------ Miscellaneous Operations ----------------------------
  343. | The following functions provide miscellaneous operations:                    |
  344. |   count     - Returns the count of the number of items in the list box.      |
  345. ------------------------------------------------------------------------------*/
  346. unsigned long
  347.   count() const;
  348.  
  349. class Cursor : public IVBase {
  350. /*******************************************************************************
  351. * The IComboBox::Cursor nested class is used to iterate the items in the       *
  352. * combination box.                                                             *
  353. *                                                                              *
  354. * EXAMPLE:                                                                     *
  355. *  This code shows creating a combo-box, adding an item to it and returning the*
  356. *  index of the item pointed to by the cursor.                                 *
  357. *                                                                              *
  358. *  #include <icombobx.hpp>                                                     *
  359. *  cb_test = new IComboBox(ID_COMBOBOX,this, this, IRectangle(x1, y1, x2, y2));*
  360. *  cb_test->addAscending("This is first item");                                *
  361. *  cb_cursor = new IComboBox::Cursor(*cb_test);                                *
  362. *  cb_cursor->setToFirst();                                                    *
  363. *  CurrentItem = cb_cursor->asIndex();                                         *
  364. *******************************************************************************/
  365.   public :
  366.   /*------------------------ Filters -------------------------------+
  367.   | The following functions allow you to specify how list box items |
  368.   | will be filtered:                                               |
  369.   |   Filter        - Enumeration that defines which items are to be|
  370.   |                   filtered in (selectedItems or allItems).      |
  371.   +----------------------------------------------------------------*/
  372.   enum Filter { selectedItems, allItems };
  373.   /*------------------------ Constructors ---------------------------
  374.   | You can create instances of this class from a combination box   |
  375.   | control and a filter type, thereby creating the specified       |
  376.   | combination box cursor object.                                  |
  377.   -----------------------------------------------------------------*/
  378.   Cursor(const IComboBox& rlb,
  379.          Filter type = selectedItems);
  380.  
  381.   virtual ~Cursor();
  382.  
  383.   /*------------------------ Cursor Movement -----------------------+
  384.   | The following functions control cursor movement in the list box |
  385.   | part of a combination box:                                      |
  386.   |   setToFirst    - Points to the first list box item and         |
  387.   |                   validates the cursor.                         |
  388.   |   setToNext     - Points to the next list box item.  If no more |
  389.   |                   items exist, this will invalidate the cursor. |
  390.   |   setToPrevious - Points to the previous list box item.  If no  |
  391.   |                   previous items exist, this will invalidate    |
  392.   |                   the cursor.                                   |
  393.   |   setToLast     - Points to the last list box item and          |
  394.   |                   validates the cursor.                         |
  395.   |   setToIndex    - Points to the item with the given 0-based     |
  396.   |                   index and validates the cursor.               |
  397.   +----------------------------------------------------------------*/
  398.   Boolean
  399.     setToFirst(),
  400.     setToNext(),
  401.     setToPrevious(),
  402.     setToLast(),
  403.     setToIndex(unsigned long index);
  404.  
  405.   /*--------------- Cursor Validation/Conversion -------------------+
  406.   | The following functions query or return information about the   |
  407.   | item to which the cursor is pointing:                           |
  408.   |   isValid    - Queries whether the cursor is pointing to a      |
  409.   |                valid item.                                      |
  410.   |   invalidate - Flags the cursor as invalid.                     |
  411.   |   asIndex    - Returns the 0-based index of the item pointed to |
  412.   |                by the cursor.                                   |
  413.   +----------------------------------------------------------------*/
  414.   Boolean
  415.     isValid() const;
  416.   void
  417.     invalidate();
  418.   unsigned long
  419.     asIndex() const;
  420.  
  421.   private :
  422.   const IComboBox&
  423.     rlbCl;
  424.   unsigned long
  425.     lClCurrent;
  426.   Filter
  427.     cursorTypeCl;
  428.   unsigned long
  429.     sameValidation;
  430. };
  431. /*------------------------ Cursor Operations ---------------------+
  432. | The following functions use the cursor to operate on list box   |
  433. | items:                                                          |
  434. |   elementAt  - Returns the item's string at the cursor position.|
  435. |   removeAt   - Removes the item at the cursor position.         |
  436. |   replaceAt  - Replaces the item's string at the cursor         |
  437. |                position.                                        |
  438. |   add        - Inserts an item after the cursor position.       |
  439. |   addAsFirst - Inserts an item as the first item and puts the   |
  440. |                cursor on that item.                             |
  441. |   addAsLast  - Inserts an item as the last item and puts the    |
  442. |                cursor on that item.                             |
  443. |   addAsNext  - Inserts an item as the next item and places the  |
  444. |                cursor on that item.                             |
  445. +----------------------------------------------------------------*/
  446. IString
  447.   elementAt(const Cursor& cursor) const;
  448. IComboBox
  449.   &add(const char* strItem, Cursor& cursor),
  450.   &add(const IResourceId& resid  , Cursor& cursor),
  451.   &removeAt(Cursor& cursor),
  452.   &replaceAt(const char* strNew,const Cursor& cursor),
  453.   &addAsFirst(const char* strItem, Cursor& cursor),
  454.   &addAsLast(const char* strItem, Cursor& cursor),
  455.   &addAsNext(const char* strItem, Cursor& cursor),
  456.   &addAsFirst(const IResourceId& resid, Cursor& cursor),
  457.   &addAsLast( const IResourceId& resid, Cursor& cursor),
  458.   &addAsNext( const IResourceId& resid, Cursor& cursor),
  459.   &replaceAt( const IResourceId& resid, const Cursor& cursor);
  460.  
  461. /*---------------------- Contents Operation ----------------------+
  462. | The following function queries the contents of the list box part|
  463. | of the combination box:                                         |
  464. |   isEmpty - Returns true if the list box is empty.              |
  465. +----------------------------------------------------------------*/
  466. Boolean
  467.   isEmpty() const;
  468.  
  469. protected:
  470. /*----------------------------- Layout Size ------------------------------------
  471. | calcMinimumSize - Returns the recommended minimum size of this combination   |
  472. |                   box.  The size is based on the text limit times the        |
  473. |                   average character width by three times the maximum         |
  474. |                   character height.                                          |
  475. ------------------------------------------------------------------------------*/
  476. virtual ISize
  477.   calcMinimumSize() const;
  478.  
  479. private:
  480. /*--------------------------------- Private ----------------------------------*/
  481.   IComboBox(const IComboBox&);
  482.   IComboBox& operator=(const IComboBox&);
  483.  
  484. static Style
  485.   currentDefaultStyle;
  486. unsigned long
  487.   needValidation;
  488. IEntryField::Alignment
  489.   alignment() const;
  490. IComboBox
  491.   &setAlignment(IEntryField::Alignment alignment);
  492. friend class IComboBox::Cursor;
  493. };  /* IComboBox */
  494.  
  495. //Global Style Functions
  496. INESTEDBITFLAGCLASSFUNCS(Style, IComboBox);
  497.                                   // global style functions
  498.  
  499. /*----------------------------------------------------------------------------*/
  500. /* Resume compiler default packing and warning messages.                      */
  501. /*----------------------------------------------------------------------------*/
  502. #pragma pack()
  503. #pragma info(restore)
  504.  
  505. #endif  /* _ICOMBOBX_ */
  506.