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

  1. #ifndef _ISUBMENU_
  2.   #define _ISUBMENU_
  3. /******************************************************************************
  4. * FILE NAME: isubmenu.hpp                                                     *
  5. *                                                                             *
  6. * DESCRIPTION:                                                                *
  7. *    Declaration of the class:                                                *
  8. *    ISubmenu - This class is used to create an object to represent           *
  9. *               a submenu from a window handle.                               *
  10. *                                                                             *
  11. * COPYRIGHT:                                                                  *
  12. *   Licensed Materials - Property of IBM                                      *
  13. *   (c) Copyright IBM Corporation 1992, 1993                                  *
  14. *   US Government Users Restricted Rights - Use duplication                   *
  15. *   or disclosure restricted by GSA ADP Schedule Contract                     *
  16. *   with IBM Corp.                                                            *
  17.  
  18. *******************************************************************************/
  19. #ifndef _IMENU_
  20.   #include <imenu.hpp>
  21. #endif
  22.  
  23. /*----------------------------------------------------------------------------*/
  24. /* Align classes on four byte boundary.                                       */
  25. /*----------------------------------------------------------------------------*/
  26. #pragma pack(4)
  27.  
  28. /*----------------------------------------------------------------------------*/
  29. /* Turn off warning for compiler generated copy/assignment                    */
  30. /*----------------------------------------------------------------------------*/
  31. #pragma info(nocpy)
  32.  
  33. class IMenuItem;
  34.  
  35. class ISubmenu : public IMenu {
  36. typedef IMenu
  37.   Inherited;
  38. /*******************************************************************************
  39. * The ISubmenu class is used to create an object to represent a submenu from   *
  40. * a menu handle.  This class overrides IMenu functions to provide undoable     *
  41. * menu item operations.  The menu item operations are intended to act on a     *
  42. * submenu.  Any changes will be undone when the menu terminates.               *
  43. *******************************************************************************/
  44. public:
  45. /*----------------------- Constructor/Destructor -------------------------------
  46. |  The only way to construct instances of this class is with a window handle   |
  47. |  of the submenu window.                                                      |
  48. ------------------------------------------------------------------------------*/
  49.   ISubmenu(const IWindowHandle& submenuHandle);
  50.  
  51. virtual
  52.   ~ISubmenu();
  53.  
  54. /*-------------------------------- Accessors -----------------------------------
  55. | This function provides a means of getting the window handle of instances of  |
  56. | this class:                                                                  |
  57. |   handle - Returns the submenu window handle.                                |
  58. ------------------------------------------------------------------------------*/
  59. virtual IWindowHandle
  60.   handle             ( ) const;
  61.  
  62. /*--------------------------- Add Menu Item ------------------------------------
  63. | The following functions provide a means to add menu items to the instances   |
  64. | of this submenu class.                                                       |
  65. |   addItem      - Adds a menu item represented by an instance of IMenuItem    |
  66. |                  as the last item in a menu or submenu.                      |
  67. |   addText      - Adds a text menu item as the last item in a menu or         |
  68. |                  submenu.                                                    |
  69. |   addBitmap    - Adds a bit-map menu item as the last item in a menu or      |
  70. |                  submenu.                                                    |
  71. |   addSeparator - Adds a separator menu item as the last item in a menu or    |
  72. |                  submenu.                                                    |
  73. ------------------------------------------------------------------------------*/
  74. ISubmenu
  75.  &addItem      ( IMenuItem           &menuItem ),
  76.  
  77.  &addText      ( unsigned long       newItemId,
  78.                  const char*         itemText  ),
  79.  &addText      ( unsigned long       newItemId,
  80.                  const IResourceId   &newItemTextResId ),
  81.  
  82.  &addBitmap    ( unsigned long       newItemId,
  83.                  const IBitmapHandle &itemBitmap ),
  84.  
  85.  &addBitmap    ( unsigned long       newItemId,
  86.                  const IResourceId   &newItemBitmapResId ),
  87.  &addBitmap    ( unsigned long       newItemId,
  88.                  unsigned long       newItemBitmapResId );
  89.  
  90. virtual ISubmenu
  91.  &addSeparator ( unsigned long       newItemId );
  92.  
  93. /*------------------------Replace Menu Item -----------------------------------
  94. | The following functions provide a means to replace menu items of the         |
  95. | instances of this submenu class.                                             |
  96. |   setItem   - Replaces a specified menu item's style and representation.     |
  97. |   setText   - Replaces a specified menu item's text.                         |
  98. |   setBitmap - Replaces a specified menu item bit map.                        |
  99. ------------------------------------------------------------------------------*/
  100. virtual ISubmenu
  101.  &setItem   ( const IMenuItem      &menuItem ),
  102.  
  103.  &setText   ( unsigned long        menuItemId,
  104.               const char*          newText ),
  105.  &setText   ( unsigned long        menuItemId,
  106.               const IResourceId    &newTextResId ),
  107.  
  108.  &setBitmap ( unsigned long        menuItemId,
  109.               const IBitmapHandle  &bitmapHandle ),
  110.  &setBitmap ( unsigned long        menuItemId,
  111.               const IResourceId    &newBitmapResId ),
  112.  &setBitmap ( unsigned long        menuItemId,
  113.               unsigned long        newBitmapResId );
  114.  
  115. /*-----------------------Delete/Remove Menu Item/Submenu-----------------------
  116. | The following functions provide a means to delete menu items and remove a    |
  117. | submenu of the instances of this submenu class.                              |
  118. |   deleteItem    - Removes the specified item from a menu.                    |
  119. |   removeSubmenu - Removes a menu item submenu indicator and destroys the     |
  120. |                   submenu.  This member function is typically used to        |
  121. |                   remove a cascading menu.                                   |
  122. ------------------------------------------------------------------------------*/
  123. virtual ISubmenu
  124.  &deleteItem    ( unsigned long itemId      ),
  125.  &removeSubmenu ( unsigned long itemWithSubmenuId );
  126.  
  127. /*---------------------Change Menu-item State, Add and Delete-------------------
  128. | The ISubmenu class overrides each of the following IMenu member functions.   |
  129. | In each of its overridden versions of these functions, ISubmenu actually     |
  130. | calls each of the IMenu versions of the functions to cause the menu to       |
  131. | change.  Then, it stores information about how the menu was changed so that  |
  132. | it can be undone.                                                            |
  133. |   checkItem   - Places a check mark in front of the menu item.               |
  134. |   uncheckItem - Removes the check mark from the menu item.                   |
  135. |   enableItem  - Makes the menu item selectable.                              |
  136. |   disableItem - Makes the menu item unselectable.                            |
  137. ------------------------------------------------------------------------------*/
  138. virtual ISubmenu
  139.  &checkItem    ( unsigned long  itemId,
  140.                  Boolean        checked  = true ),
  141.  &uncheckItem  ( unsigned long  itemId ),
  142.  &enableItem   ( unsigned long  itemId,
  143.                  Boolean        enabled  = true ),
  144.  &disableItem  ( unsigned long  itemId );
  145.  
  146. /*--------------------- Undo Changes -------------------------------------------
  147. | This function restores the submenu.                                          |
  148. |  undo - Reverses all the changes made to the menu using the ISubmenu member  |
  149. |         functions.  You should not need to call this function since it is    |
  150. |         called automatically by the IMenuHandler.                            |
  151. ------------------------------------------------------------------------------*/
  152. ISubmenu
  153.   &undo();
  154.  
  155. class Cursor : public IBase {
  156. /*******************************************************************************
  157. * The ISubmenu::Cursor class creates and manages the cursor for menu items.    *
  158. *******************************************************************************/
  159. public :
  160.   /*------------------ Constructor/Destructor ---------------------------------
  161.   |  The only way to construct an instance of this class is with an instance  |
  162.   |  of an ISubmenu.                                                          |
  163.   ---------------------------------------------------------------------------*/
  164.   Cursor(const ISubmenu&  menu);
  165.   /*------------------------ Cursor Movement ------------------------
  166.   | The following functions provide a means to move the cursor      |
  167.   | position:                                                       |
  168.   |   setToFirst    - Points to the first menu item.                |
  169.   |   setToNext     - Points to the next menu item.  If there is    |
  170.   |                   none, the cursor is invalidated.              |
  171.   |   setToPrevious - Points to the previous menu item.  If there   |
  172.   |                   is none, the cursor is invalidated.           |
  173.   |   setToLast     - Points to the last menu item.                 |
  174.   -----------------------------------------------------------------*/
  175.   Boolean
  176.     setToFirst    ( ),
  177.     setToNext     ( ),
  178.     setToPrevious ( ),
  179.     setToLast     ( );
  180.  
  181.   /*--------------- Cursor Validation ------------------------------+
  182.   | The following functions provide a means to validate the cursor: |
  183.   |   isValid    - Queries whether this cursor points to a valid    |
  184.   |                menu item.                                       |
  185.   |   invalidate - Flags this cursor as invalid.                    |
  186.   +----------------------------------------------------------------*/
  187.   Boolean
  188.     isValid    ( ) const;
  189.   void
  190.     invalidate ( );
  191.  
  192.   private :  /*------------------- PRIVATE ------------------------*/
  193.   friend class ISubmenu;
  194.   long
  195.     lCurrent;
  196.   ISubmenu*
  197.     pSubmenu;
  198. };
  199.  
  200. /*-------------------- Menu Item Operations with Cursor ------------------------
  201. | The following functions provide a means to manage the menu item of           |
  202. | instances of this class.                                                     |
  203. |   elementAt       - Returns the menu item at the cursor position.            |
  204. |   deleteAt        - Deletes the menu item at the cursor position and sets    |
  205. |                     the cursor to the menu item that precedes the deleted    |
  206. |                     menu item.                                               |
  207. |   removeSubmenuAt - Removes the menu item at the cursor position submenu     |
  208. |                     indicator and destroys the sub-menu.  This member        |
  209. |                     function is typically used to remove cascading menus.    |
  210. |   addAt           - Adds the menu item at the cursor by pushing everything   |
  211. |                     after cursor.                                            |
  212. |   addNextAt       - Adds the menu item as the next item in the submenu and   |
  213. |                     sets the cursor there.                                   |
  214. |   cursor          - Returns an instance of Cursor and sets the cursor to     |
  215. |                     point to the specific menu item.                         |
  216. ------------------------------------------------------------------------------*/
  217. IMenuItem
  218.   elementAt ( const Cursor& cursor ) const;
  219.  
  220. ISubmenu
  221.   &deleteAt        ( Cursor&     cursor   ),
  222.   &removeSubmenuAt ( Cursor&     cursor   ),
  223.   &addAt           ( IMenuItem&  menuItem,
  224.                      Cursor&     cursor   ),
  225.   &addNextAt       ( IMenuItem&  menuItem,
  226.                      Cursor&     cursor   );
  227. Cursor
  228.   cursor ( unsigned long itemId) const;
  229.  
  230. /*----------------------- Private -----------------------------------*/
  231. private:
  232. void
  233.   setUndoAddItem(unsigned long itemId),
  234.   setUndoChangeItem(const IMenuItem& origItem);
  235. unsigned long
  236.   menuItemId ( const Cursor& cursor ) const;
  237. IWindowHandle
  238.   hwndHandle;
  239. void*
  240.   pItemList;
  241.  
  242. /*------------------- Hidden Functions. -----------------------------------
  243. | The following inherited functions are hidden in this class.              |
  244. |-------------------------------------------------------------------------*/
  245.   ISubmenu(const IMenu&);
  246.   ISubmenu &operator=(const IMenu&);
  247.  
  248. };
  249.  
  250. /*----------------------------------------------------------------------------*/
  251. /* Resume compiler default packing and warning messages.                      */
  252. /*----------------------------------------------------------------------------*/
  253. #pragma pack()
  254. #pragma info(restore)
  255.  
  256. /*--------------------------------- Inlines ----------------------------------*/
  257. #ifndef I_NO_INLINES
  258.   #include <isubmenu.inl>
  259. #endif
  260.  
  261. #endif
  262.