home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lstbx3.zip / xlistbox.hpp < prev    next >
Text File  |  1994-08-16  |  13KB  |  254 lines

  1. #ifndef _XLISTBOX_
  2. #define _XLISTBOX_
  3. /*******************************************************************************
  4. * FILE NAME: xlistbox.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *   ListBox32 - 32-Bit list box control.                                       *
  9. *                                                                              *
  10. *******************************************************************************/
  11. #ifndef _ILISTBOX_
  12.   #include <ilistbox.hpp>
  13. #endif
  14.  
  15.  
  16. /*----------------------------------------------------------------------------*/
  17. /* Align classes on four byte boundary.                                       */
  18. /*----------------------------------------------------------------------------*/
  19. #pragma pack(4)
  20.  
  21. class ListBox32 : public IListBox {
  22. typedef IListBox
  23.   Inherited;
  24. /*******************************************************************************
  25. *                                                                              *
  26. *******************************************************************************/
  27. public:
  28. /*------------------------------ Extended Style -------------------------------
  29.   The following functions provide a means to set and query the 32-Bit
  30.   replacement list box extended styles:
  31.  
  32.     ExtendedStyle - Nested class that provides static members that define
  33.                     the set of valid 32-Bit list box extended styles.
  34.                     For example, you could define an instance of the
  35.                     ListBox32::ExtendedStyle class and initialize it like:
  36.                         ListBox32::ExtendedStyle extendedStyle =
  37.                                                          ListBox32::checkBox;
  38.                     An object of this type is provided when the 32-Bit list
  39.                     box is created.  A customizable default is used if no
  40.                     styles are specified.  Once the object is constructed,
  41.                     ListBox32 member functions can be used to set or query
  42.                     the object's extended style.
  43.  
  44.                     The declaration of the ListBox32::ExtendedStyle nested
  45.                     class is generated by the INESTEDBITFLAGCLASSDEF0 macro.
  46.  
  47.   The valid list box styles are:
  48.     classDefaultExtendedStyle - This specifies the original default style
  49.                                 for this class, which is nothing.
  50.     checkBox                  - This style prefixes the list item with a
  51.                                 check box.
  52.  
  53.   The following functions provide a means of getting and setting the default
  54.   extended style for this class:
  55.     defaultExtendedStyle    - Returns the current default extended style.
  56.                               This is the same as classDefaultExtendedStyle
  57.                               unless setDefaultExtendedStyle has been called.
  58.     setDefaultExtendedStyle - Sets the default extended style for all
  59.                               subsequent 32-Bit list boxes.
  60.  
  61.  
  62. *******************************************************************************
  63. *****************************  I M P O R T A N T  *****************************
  64. *******************************************************************************
  65.   The base list box styles (i.e. IListBox::horizontalScroll) are
  66.   controlled by the Style nested class which is defined in ILISTBOX.HPP.
  67. -----------------------------------------------------------------------------*/
  68. INESTEDBITFLAGCLASSDEF0(ExtendedStyle, ListBox32);
  69.  
  70. static const ExtendedStyle
  71.   classDefaultExtendedStyle,
  72.   checkBox;
  73.  
  74. static ExtendedStyle
  75.   defaultExtendedStyle     ( );
  76.  
  77. static void
  78.   setDefaultExtendedStyle  ( ExtendedStyle extendedStyle );
  79.  
  80.  
  81. /*-------------------------- Constructors/Destructor ---------------------------
  82. | You can construct generic objects of this class by providing one of the      |
  83. | following items:                                                             |
  84. |    o From a control ID, parent and owner windows, rectangle, style, and      |
  85. |      extended style.  This creates the specified 32-Bit list box control     |
  86. |      and an object for it.                                                   |
  87. |    o From the ID of a 32-Bit list box on a dialog window.  This creates      |
  88. |      the object for the 32-Bit list box.                                     |
  89. |    o From the window handle of an existing 32-Bit list box control.  This    |
  90. |      creates the object for the specified 32-Bit list box control.           |
  91. ------------------------------------------------------------------------------*/
  92.   ListBox32   ( unsigned long       id,
  93.                 IWindow             *parent,
  94.                 IWindow             *owner,
  95.                 const IRectangle    &initial= IRectangle(),
  96.                 const Style         &style = defaultStyle(),
  97.                 const ExtendedStyle &extendedStyle = defaultExtendedStyle() );
  98.  
  99.   ListBox32   ( unsigned long       id,
  100.                 IWindow             *parentDialog );
  101.  
  102.   ListBox32   ( const IWindowHandle &handle );
  103.  
  104. virtual
  105.   ~ListBox32  ( );
  106.  
  107. /*----------------------------- Implementation ---------------------------------
  108. | createListBox - Static function that creates the 32-Bit list box.            |
  109. | validate      - Static function that validates the following:                |
  110. |                    1) The window handle is valid.                            |
  111. |                    2) The window's class is "ListBoxWindow".                 |
  112. ------------------------------------------------------------------------------*/
  113. static IWindowHandle
  114.   createListBox  ( unsigned long       id,
  115.                    IWindow             *parent,
  116.                    IWindow             *owner,
  117.                    const IRectangle    &initial,
  118.                    const Style         &style,
  119.                    const ExtendedStyle &extendedStyle ),
  120.   validate       ( const IWindowHandle &handle );
  121.  
  122. /*---------------------------- Check-state Operations --------------------------
  123. | Set or return the check state operations.                                    |
  124. |   check         - Sets the check state of an item based on the               |
  125. |                   Boolean value that is passed in.  If true is passed        |
  126. |                   in and the list box is a single-selection list box,        |
  127. |                   the item is checked and any item that was                  |
  128. |                   previously checked is unchecked.  If true is               |
  129. |                   passed in and the list box is a multiple-selection         |
  130. |                   or extended-selection list box, the item is checked.       |
  131. |                   In all cases, if false is passed in, the item is           |
  132. |                   unchecked.                                                 |
  133. |   unCheck       - Removes the check state from an item.                      |
  134. |   checkAll      - Sets the check state for all items in the list box.        |
  135. |   unCheckAll    - Removes the check state from all items in the list box.    |
  136. |   isChecked     - Returns the check state of an item.                        |
  137. |   numberChecked - Returns 0 if no item in a single-selection list box        |
  138. |                   is checked or 1 if an item is checked.  Returns            |
  139. |                   the number of checked items in a multiple-selection        |
  140. |                   or extended-selection list box.                            |
  141. |   checkedItem   - Returns the 0-based index of the checked item in a         |
  142. |                   single-selection list box, or the 0-based index of         |
  143. |                   the first checked item in a multiple-selection or          |
  144. |                   extended-selection list box.  In all cases, if no          |
  145. |                   item is checked, -1 is returned.                           |
  146. ------------------------------------------------------------------------------*/
  147. virtual ListBox32
  148.  &check          ( unsigned long index, Boolean check = true ),
  149.  &unCheck        ( unsigned long index ),
  150.  &checkAll       ( ),
  151.  &unCheckAll     ( );
  152.  
  153. virtual Boolean
  154.   isChecked      ( unsigned long index ) const;
  155.  
  156. virtual unsigned long
  157.   numberChecked  ( ) const;
  158.  
  159. virtual long
  160.   checkedItem    ( ) const;
  161.  
  162. /*---------------------------- Enumerations ------------------------------------
  163. | The following enumerations are defined:                                      |
  164. |   ClickEvent - Used to indicate which mouse click event to query or set:     |
  165. |                singleClick - mouse button 1 single click.                    |
  166. |                doubleClick - mouse button 2 double click.                    |
  167. ------------------------------------------------------------------------------*/
  168. enum ClickEvent {
  169.   singleClick,
  170.   doubleClick
  171. };
  172.  
  173. /*------------------------------- Sound Support --------------------------------
  174. | These functions provide a means of getting and setting the sound support     |
  175. | attributes of instances of this class:                                       |
  176. | isSound       - Returns true if the sound is supported on this system.       |
  177. | soundEvent    - Returns a wave file name for the event if it is set.         |
  178. | setSoundEvent - Sets a wave file name for the event.                         |
  179. ------------------------------------------------------------------------------*/
  180. virtual Boolean
  181.   isSound        ( ) const;
  182.  
  183. virtual IString
  184.   soundEvent     ( ClickEvent value ) const;
  185.  
  186. virtual ListBox32
  187.  &setSoundEvent  ( ClickEvent value, const char *waveFile );
  188.  
  189. /*------------------------- Extended Style Functions ---------------------------
  190. | These functions provide a means of getting and setting the default extended  |
  191. | style attributes of instances of this class:                                 |
  192. | isCheckBox      - Returns true if the checkBox extended style is set.        |
  193. | enableCheckBox  - Enables or disables the extended check box style.          |
  194. | disableCheckBox - Disables the extended check box style.                     |
  195. ------------------------------------------------------------------------------*/
  196. virtual Boolean
  197.   isCheckBox       ( ) const;
  198.  
  199. virtual ListBox32
  200.  &enableCheckBox   ( Boolean enable = true ),
  201.  &disableCheckBox  ( );
  202.  
  203.  
  204. protected:
  205. /*----------------------------- Layout Size ------------------------------------
  206. | calcMinimumSize - Returns the recommended minimum size of the 32-Bit list    |
  207. |                   box control.  The size is based on the text string length  |
  208. |                   of the longest string (if not using                        |
  209. |                   IListBox::horizontalScroll style) and the current font.    |
  210. ------------------------------------------------------------------------------*/
  211. virtual ISize
  212.   calcMinimumSize  ( ) const;
  213.  
  214. /*----------------------------- Implementation ---------------------------------
  215. | initialize - Perform initialization tasks that are common across the ctors.  |
  216. ------------------------------------------------------------------------------*/
  217. void
  218.   initialize  ( );
  219.  
  220. /*------------------------------- Extended Styles ------------------------------
  221. | extendedStyle    - Returns the extended style for the list box.              |
  222. | setExtendedStyle - Sets the extended style for the list box.                 |
  223. ------------------------------------------------------------------------------*/
  224. virtual unsigned long
  225.   extendedStyle  ( ) const;
  226.  
  227. virtual ListBox32
  228.  &setExtendedStyle  ( const unsigned long extStyle );
  229.  
  230.  
  231. private:
  232. /*--------------------------------- PRIVATE ----------------------------------*/
  233.  
  234.   ListBox32  ( const ListBox32 & );  //copy ctor
  235.   operator = ( const ListBox32 & );  //assignment ctor
  236.  
  237. static ExtendedStyle
  238.   currentDefaultExtendedStyle;
  239.  
  240. unsigned long
  241.   ulExtendedStyle;
  242.  
  243. Boolean
  244.   bSoundSupported;
  245.  
  246. };  // class ListBox32
  247.  
  248. /*----------------------------------------------------------------------------*/
  249. /* Resume compiler default packing.                                           */
  250. /*----------------------------------------------------------------------------*/
  251. #pragma pack()
  252.  
  253. #endif  //_XLISTBOX_
  254.