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

  1. #ifndef _IMENU_
  2.   #define _IMENU_
  3. /******************************************************************************
  4. * FILE NAME: imenu.hpp                                                        *
  5. *                                                                             *
  6. * DESCRIPTION:                                                                *
  7. *    Declaration of the class:                                                *
  8. *      IMenu - This is the base class of menu class                           *
  9. *         hierarchy that provides operations to act on                        *
  10. *         menu items.                                                         *
  11. *                                                                             *
  12. * COPYRIGHT:                                                                  *
  13. *   Licensed Materials - Property of IBM                                      *
  14. *   (c) Copyright IBM Corporation 1992, 1993                                  *
  15. *   US Government Users Restricted Rights - Use duplication                   *
  16. *   or disclosure restricted by GSA ADP Schedule Contract                     *
  17. *   with IBM Corp.                                                            *
  18. *                                                                             *
  19. *******************************************************************************/
  20. #ifndef _IBASE_
  21.  #include <ibase.hpp>
  22. #endif
  23. #ifndef _IWINDOW_
  24.  #include <iwindow.hpp>
  25. #endif
  26.  
  27. /*----------------------------------------------------------------------------*/
  28. /* Align classes on four byte boundary.                                       */
  29. /*----------------------------------------------------------------------------*/
  30. #pragma pack(4)
  31.  
  32. // Forward declarations for other classes
  33. class IMenuItem;
  34. class IColor;
  35. class IResourceId;
  36.  
  37. class IMenu : public IWindow {
  38. typedef IWindow
  39.   Inherited;
  40. /*******************************************************************************
  41. * The IMenu class is an abstract base class for all menu classes.  It          *
  42. * provides functions to add, set, check and disable menu items in the menu.    *
  43. *******************************************************************************/
  44. public:
  45. /*------------------ Constructor/Destructor ------------------------------------
  46. |  The only way to construct an instance of this class is with the default     |
  47. |  constructor.  This is an abstract class.                                    |
  48. ------------------------------------------------------------------------------*/
  49.    IMenu ( );
  50. virtual
  51.   ~IMenu ( ) = 0;
  52.  
  53. /*-------------------------------- Style ---------------------------------------
  54. |  The following styles are valid for this class:                              |
  55. |    classDefaultStyle - This style is a static variable set to noStyle.       |
  56. |    verticalFlip      - This style, if possible, displays the menu above the  |
  57. |                        menu bar; otherwise, the menu is displayed below the  |
  58. |                        menu bar.                                             |
  59. |    noStyle           - This style specifies that no style applies to the     |
  60. |                        menu.                                                 |
  61. |                                                                              |
  62. |  The following functions provide a means of getting and setting the default  |
  63. |  style for this class:                                                       |
  64. |                                                                              |
  65. |    defaultStyle    - Returns the current default style.  This is the same as |
  66. |                      classDefaultStyle unless setDefaultStyle has been       |
  67. |                      called.                                                 |
  68. |    setDefaultStyle - Sets the default style for all subsequent menu items.   |
  69. ------------------------------------------------------------------------------*/
  70. INESTEDBITFLAGCLASSDEF1(Style, IMenu, IWindow);
  71.  
  72. static const Style
  73.   classDefaultStyle,
  74.   verticalFlip,
  75.   noStyle;
  76.  
  77. static Style
  78.   defaultStyle ( );
  79.  
  80. static void
  81.   setDefaultStyle ( const Style &aStyle );
  82.  
  83. /*---------------------- Set and Test Styles -----------------------------------
  84. | The following functions provide a means to set or change the menu style of   |
  85. | instances of this class:                                                     |
  86. |   setVerticalFlip - Displays the menu above the menu bar, if possible.       |
  87. |   isVerticalFlip  - Queries whether the verticalFlip style is set.           |
  88. ------------------------------------------------------------------------------*/
  89. IMenu
  90.   &setVerticalFlip       ( Boolean flip         = true );
  91.  
  92. Boolean
  93.   isVerticalFlip       ( ) const;
  94.  
  95. /*--------------------------- Add Menu Item ------------------------------------
  96. | The following functions provide a means to add menu items to the instances   |
  97. | of this menu class:                                                          |
  98. |   addItem      - Adds a menu item, represented by an instance of IMenuItem,  |
  99. |                  as the last item in a menu or submenu.                      |
  100. |   addText      - Adds a text menu item as the last item in a menu or         |
  101. |                  submenu.                                                    |
  102. |   addBitmap    - Adds a bit-map menu item as the last item in a menu or      |
  103. |                  submenu.                                                    |
  104. |   addSeparator - Adds a separator menu item as the last item in a menu or    |
  105. |                  submenu.                                                    |
  106. |   addSubmenu   - Creats a submenu and adds it to the menu item.              |
  107. ------------------------------------------------------------------------------*/
  108. IMenu
  109.  &addItem      ( IMenuItem&           menuItem,
  110.                  unsigned long        intoSubmenuId = 0),
  111.  
  112.  &addText      ( unsigned long        newItemId,
  113.                  const char*          itemText,
  114.                  unsigned long        intoSubmenuId = 0),
  115.  
  116.  &addText      ( unsigned long        newItemId,
  117.                  const IResourceId&   textResId,
  118.                  unsigned long        intoSubmenuId = 0),
  119.  
  120.  &addBitmap    ( unsigned long        newItemId,
  121.                  const IBitmapHandle& itemBitmap,
  122.                  unsigned long        intoSubmenuId = 0),
  123.  
  124.  &addBitmap    ( unsigned long        newItemId,
  125.                  const IResourceId&   bitmapResId,
  126.                  unsigned long        intoSubmenuId = 0),
  127.  
  128.  &addBitmap    ( unsigned long        newItemId,
  129.                  unsigned long        bitmapResId,
  130.                  unsigned long        intoSubmenuId = 0),
  131.  
  132.  &addSeparator ( unsigned long        newItemId,
  133.                  unsigned long        intoSubmenuId);
  134.  
  135. virtual IMenu
  136.  &addSeparator ( unsigned long        intoSubmenuId = 0 ),
  137.  &addSubmenu   ( unsigned long        itemId ),
  138.  &addSubmenu   ( unsigned long        itemId,
  139.                  const IResourceId&   submenuResId );
  140.  
  141. /*------------------------Replace Menu Item ------------------------------------
  142. | The following functions provide a means to replace menu items of the         |
  143. | instances of this menu class:                                                |
  144. |   setItem               - Replaces a specified menu item's style and         |
  145. |                           representation.                                    |
  146. |   setText               - Replaces a menu item's text.                       |
  147. |   setBitmap             - Causes a menu item to display a bit map.  The bit  |
  148. |                           map is assumed to be in the default resource       |
  149. |                           library.                                           |
  150. |   setSubmenu            - Creates a menu and sets it as the menu item's      |
  151. |                           submenu.                                           |
  152. |   setConditionalCascade - Enables the conditional cascade menu behavior.     |
  153. |                           The item specified by the itemWithSubmenuId        |
  154. |                           argument will have its submenu set as a            |
  155. |                           conditional cascade menu.  The defaultItemId       |
  156. |                           argument specifies the default selection.  You     |
  157. |                           can also use this function to change the default   |
  158. |                           item on a menu that is already a conditional       |
  159. |                           cascade.  An exception will be thrown if:          |
  160. |                             - The items specified for the itemWithSubmenuId  |
  161. |                               or defaultItemId arguments do not exist.       |
  162. |                             - The item specified for the itemWithSubmenuId   |
  163. |                               argument does not have a submenu attached.     |
  164. ------------------------------------------------------------------------------*/
  165. virtual IMenu
  166.  &setItem    ( const IMenuItem&     menuItem ),
  167.  
  168.  &setText    ( unsigned long        menuItemId,
  169.                const char*          newText     ),
  170.  
  171.  &setText    ( unsigned long        menuItemId,
  172.                const IResourceId&   newTextResId ),
  173.  
  174.  &setBitmap  ( unsigned long        menuItemId,
  175.                const IBitmapHandle& bitmapHandle ),
  176.  
  177.  &setBitmap  ( unsigned long        menuItemId,
  178.                const IResourceId&   newBitmapResId ),
  179.  
  180.  &setBitmap  ( unsigned long        menuItemId,
  181.                unsigned long        newBitmapResId ),
  182.  
  183.  &setSubmenu ( unsigned long        itemId,
  184.                const IResourceId&   submenuResId );
  185.  
  186. // setConditionalCascade() and removeConditionalCascade are
  187. // not declared virtual since the were implemented in the first
  188. // CSD. Making them virtual would force existing programs to
  189. // recompile because of VTBL changes.
  190. // Don't see a need for anyone to override these.
  191. IMenu
  192.  &setConditionalCascade
  193.              ( unsigned long        itemWithSubmenuId,
  194.                unsigned long        defaultItemId);
  195.  
  196. /*-----------------------Delete/Remove Menu Item/Submenu------------------------
  197. | The following functions provide a means to delete menu items, submenus, or   |
  198. | cascade behavior.                                                            |
  199. |   deleteItem               - Removes the specified item from the menu.       |
  200. |   removeSubmenu            - Removes the menu item's submenu indicator and   |
  201. |                              destroys the submenu.  This function is         |
  202. |                              typically used to remove a cascading menu.      |
  203. |   removeConditionalCascade - Removes conditional cascade behavior from the   |
  204. |                              menu item specified for the itemWithSubmenuId   |
  205. |                              argument.  An exception will be thrown if the   |
  206. |                              item specified for the itemWithSubmenuId        |
  207. |                              argument does not exist or does not have an     |
  208. |                              associated submenu.                             |
  209. ------------------------------------------------------------------------------*/
  210. virtual IMenu
  211.  &deleteItem    ( unsigned long      itemId ),
  212.  &removeSubmenu ( unsigned long      itemWithSubmenuId  );
  213.  
  214. IMenu
  215.  &removeConditionalCascade
  216.                 ( unsigned long      itemWithSubmenuId  );
  217.  
  218.  
  219. /*---------------------- Check and Disable Menu Item ---------------------------
  220. | The following functions provide a means to check, disable, and select menu   |
  221. | items of the instances of this menu class:                                   |
  222. |   checkItem   - Places a check mark to the left of the specified item.       |
  223. |                 NOTE: The menu bar pull-down cannot be checked.  This is an  |
  224. |                       OS/2 Presentation Manager restriction.                 |
  225. |   uncheckItem - Removes the check mark from a specified menu item.           |
  226. |   enableItem  - Makes a menu item selectable.                                |
  227. |   disableItem - Makes a menu item unselectable.                              |
  228. |   selectItem  - Selects a menu item.                                         |
  229. ------------------------------------------------------------------------------*/
  230. virtual IMenu
  231.   &checkItem    ( unsigned long itemId,
  232.                   Boolean       check  = true ),
  233.   &uncheckItem  ( unsigned long itemId ),
  234.   &enableItem   ( unsigned long itemId,
  235.                   Boolean       enable = true ),
  236.   &disableItem  ( unsigned long itemId ),
  237.   &selectItem   ( unsigned long itemId );
  238.  
  239. /*------------------- Test Checked and Disabled Menu Item ----------------------
  240. | The following functions provide a means to test menu items of the instances  |
  241. | of this menu class:                                                          |
  242. |   isItemDisabled - Returns true if the specified menu item is unselectable.  |
  243. |   isItemChecked  - Returns true if the specified menu item is checked.       |
  244. ------------------------------------------------------------------------------*/
  245. Boolean
  246.   isItemChecked  ( unsigned long itemId ) const,
  247.   isItemDisabled ( unsigned long itemId ) const;
  248.  
  249. /*-------------------------- Accessor ------------------------------------------
  250. | The following functions provide a means to get the menu item of instances    |
  251. | of this class:                                                               |
  252. |   menuItem      - Returns an IMenuItem instance of a menu item.              |
  253. |   numberOfItems - Returns the number of menu items in a menu or submenu.     |
  254. |   itemRect      - Returns the bounding rectangle of a menu item.             |
  255. ------------------------------------------------------------------------------*/
  256. IMenuItem
  257.   menuItem      ( unsigned long itemId ) const;
  258. IRectangle
  259.   itemRect      ( unsigned long itemId ) const;
  260. unsigned long
  261.   numberOfItems ( unsigned long forSubmenuId = 0) const;
  262.  
  263. /*---------------------- ColorArea Enumerator ----------------------------------
  264. | ColorArea - Enumeration that is used to replace and set the color for a      |
  265. |             particular area of the menu.  The valid values are:              |
  266. |               foreground          - Sets the color of the foreground text.   |
  267. |               background          - Sets the color of the background text.   |
  268. |               disabledForeground  - Sets the foreground color for disabled   |
  269. |                                     text.                                    |
  270. |               disabledBackground  - Sets the background color for disabled   |
  271. |                                     text.                                    |
  272. |               highlightForeground - Sets the foreground color for selected   |
  273. |                                     text.                                    |
  274. |               highlightBackground - Sets the background color for selected   |
  275. |                                     text.                                    |
  276. |               border              - Sets the color of the border that        |
  277. |                                     surrounds the menu.                      |
  278. ------------------------------------------------------------------------------*/
  279. enum ColorArea {
  280.   foreground,
  281.   background,
  282.   disabledForeground,
  283.   disabledBackground,
  284.   highlightForeground,
  285.   highlightBackground,
  286.   border };
  287.  
  288. /*-------------------------- Set and Query Color ------------------------------
  289. | The following functions provide  a mean to set and query the menu color:     |
  290. |   setColor - Changes the color of the specific menu area.                    |
  291. |   color    - Returns the color of the specific menu area.                    |
  292. ------------------------------------------------------------------------------*/
  293. IMenu
  294.   &setColor ( ColorArea     value,
  295.               const IColor  &color );
  296. IColor
  297.   color     ( ColorArea     value ) const;
  298.  
  299.  
  300. class Cursor : public IBase {
  301. /*******************************************************************************
  302. * The IMenu::Cursor class creates and manages the cursor for menu items.       *
  303. *******************************************************************************/
  304. public :
  305.   /*------------------ Constructor/Destructor ---------------------------------
  306.   |  The only way to construct an instance of this class is with an instance  |
  307.   |  of an IMenu and submenu ID.  The sub-menu defaults to 0 for the          |
  308.   |  top-level menu items.                                                    |
  309.   ---------------------------------------------------------------------------*/
  310.   Cursor(const IMenu&  menu,
  311.          unsigned long forSubmenuId  = 0 );
  312.  
  313.   /*------------------------ Cursor Movement ------------------------
  314.   | The following functions provide a means to move the cursor      |
  315.   | position:                                                       |
  316.   |                                                                 |
  317.   | setToFirst    - Points to the first menu item.                  |
  318.   | setToNext     - Points to the next menu item.  If there is      |
  319.   |                 none, the cursor is invalidated.                |
  320.   | setToPrevious - Points to the previous menu item.  If there is  |
  321.   |                 none, the cursor is invalidated.                |
  322.   | setToLast     - Points to the last menu item.                   |
  323.   -----------------------------------------------------------------*/
  324.   Boolean
  325.     setToFirst    ( ),
  326.     setToNext     ( ),
  327.     setToPrevious ( ),
  328.     setToLast     ( );
  329.  
  330.   /*--------------- Cursor Validation ------------------------------+
  331.   | The following functions provide a means to validate the cursor: |
  332.   |                                                                 |
  333.   | isValid    - Queries whether this cursor points to a valid menu |
  334.   |              item.                                              |
  335.   | invalidate - Flags the cursor as invalid.                       |
  336.   +----------------------------------------------------------------*/
  337.   Boolean
  338.     isValid    ( ) const;
  339.   void
  340.     invalidate ( );
  341.  
  342.   private :  /*------------------- PRIVATE ------------------------*/
  343.   friend class IMenu;
  344.   long
  345.     lCurrent;
  346.   unsigned long
  347.     ulSubmenu;
  348.   IMenu*
  349.     pMenu;
  350. };
  351.  
  352. /*-------------------- Menu Item Operations with Cursor ------------------------
  353. | The following functions provide a means to manage the menu item of           |
  354. | instances of this class:                                                     |
  355. |                                                                              |
  356. |   elementAt       - Returns the menu item at the cursor position.            |
  357. |   deleteAt        - Deletes the menu item at the cursor position and sets    |
  358. |                     the cursor to the previous menu item.                    |
  359. |   removeSubmenuAt - Removes the menu item at the cursor position submenu     |
  360. |                     indicator and destroys the submenu.  This function is    |
  361. |                     typically used to remove a cascading menu.               |
  362. |   addAt           - Adds the menu item at the cursor's position by pushing   |
  363. |                     everything after the cursor.                             |
  364. |   addNextAt       - Adds the specified menu item as the next item and sets   |
  365. |                     the cursor upon it.                                      |
  366. |   cursor          - Returns an instance of the Cursor nested class and sets  |
  367. |                     the cursor to point to the specified menu item.          |
  368. ------------------------------------------------------------------------------*/
  369. IMenuItem
  370.   elementAt ( const Cursor& cursor ) const;
  371.  
  372. IMenu
  373.   &deleteAt        ( Cursor&            cursor   ),
  374.   &removeSubmenuAt ( Cursor&            cursor   ),
  375.  
  376.   &addAt           ( IMenuItem&         menuItem,
  377.                      Cursor&            cursor   ),
  378.   &addNextAt       ( IMenuItem&         menuItem,
  379.                      Cursor&            cursor   );
  380.  
  381. Cursor
  382.   cursor ( unsigned long itemId,
  383.            unsigned long inSubmenuId = 0 ) const;
  384.  
  385. /*----------------------- Private -----------------------------------*/
  386. private:
  387.   IMenu(const IMenu&);
  388.   IMenu &operator=(const IMenu&);
  389.  
  390. unsigned long
  391.   menuItemId ( const Cursor& cursor ) const;
  392. void
  393.   refCountBitmap(const IBitmapHandle& handle );
  394. static Style
  395.   currentDefaultStyle;
  396. IWindowHandle
  397.   submenuHandle ( unsigned long submenuId ) const;
  398. void*
  399.   pBitmapList;
  400. };
  401.  
  402. INESTEDBITFLAGCLASSFUNCS(Style, IMenu);
  403.  
  404. /*----------------------------------------------------------------------------*/
  405. /* Resume compiler default packing.                                           */
  406. /*----------------------------------------------------------------------------*/
  407. #pragma pack()
  408.  
  409. /*--------------------------------- Inlines ----------------------------------*/
  410. #ifndef I_NO_INLINES
  411.   #include <imenu.inl>
  412. #endif
  413.  
  414. #endif  /* _IMENU_ */
  415.