home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IMENU.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
21KB
|
415 lines
#ifndef _IMENU_
#define _IMENU_
/******************************************************************************
* FILE NAME: imenu.hpp *
* *
* DESCRIPTION: *
* Declaration of the class: *
* IMenu - This is the base class of menu class *
* hierarchy that provides operations to act on *
* menu items. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (c) Copyright IBM Corporation 1992, 1993 *
* US Government Users Restricted Rights - Use duplication *
* or disclosure restricted by GSA ADP Schedule Contract *
* with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IBASE_
#include <ibase.hpp>
#endif
#ifndef _IWINDOW_
#include <iwindow.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
// Forward declarations for other classes
class IMenuItem;
class IColor;
class IResourceId;
class IMenu : public IWindow {
typedef IWindow
Inherited;
/*******************************************************************************
* The IMenu class is an abstract base class for all menu classes. It *
* provides functions to add, set, check and disable menu items in the menu. *
*******************************************************************************/
public:
/*------------------ Constructor/Destructor ------------------------------------
| The only way to construct an instance of this class is with the default |
| constructor. This is an abstract class. |
------------------------------------------------------------------------------*/
IMenu ( );
virtual
~IMenu ( ) = 0;
/*-------------------------------- Style ---------------------------------------
| The following styles are valid for this class: |
| classDefaultStyle - This style is a static variable set to noStyle. |
| verticalFlip - This style, if possible, displays the menu above the |
| menu bar; otherwise, the menu is displayed below the |
| menu bar. |
| noStyle - This style specifies that no style applies to the |
| menu. |
| |
| The following functions provide a means of getting and setting the default |
| style for this class: |
| |
| defaultStyle - Returns the current default style. This is the same as |
| classDefaultStyle unless setDefaultStyle has been |
| called. |
| setDefaultStyle - Sets the default style for all subsequent menu items. |
------------------------------------------------------------------------------*/
INESTEDBITFLAGCLASSDEF1(Style, IMenu, IWindow);
static const Style
classDefaultStyle,
verticalFlip,
noStyle;
static Style
defaultStyle ( );
static void
setDefaultStyle ( const Style &aStyle );
/*---------------------- Set and Test Styles -----------------------------------
| The following functions provide a means to set or change the menu style of |
| instances of this class: |
| setVerticalFlip - Displays the menu above the menu bar, if possible. |
| isVerticalFlip - Queries whether the verticalFlip style is set. |
------------------------------------------------------------------------------*/
IMenu
&setVerticalFlip ( Boolean flip = true );
Boolean
isVerticalFlip ( ) const;
/*--------------------------- Add Menu Item ------------------------------------
| The following functions provide a means to add menu items to the instances |
| of this menu class: |
| addItem - Adds a menu item, represented by an instance of IMenuItem, |
| as the last item in a menu or submenu. |
| addText - Adds a text menu item as the last item in a menu or |
| submenu. |
| addBitmap - Adds a bit-map menu item as the last item in a menu or |
| submenu. |
| addSeparator - Adds a separator menu item as the last item in a menu or |
| submenu. |
| addSubmenu - Creats a submenu and adds it to the menu item. |
------------------------------------------------------------------------------*/
IMenu
&addItem ( IMenuItem& menuItem,
unsigned long intoSubmenuId = 0),
&addText ( unsigned long newItemId,
const char* itemText,
unsigned long intoSubmenuId = 0),
&addText ( unsigned long newItemId,
const IResourceId& textResId,
unsigned long intoSubmenuId = 0),
&addBitmap ( unsigned long newItemId,
const IBitmapHandle& itemBitmap,
unsigned long intoSubmenuId = 0),
&addBitmap ( unsigned long newItemId,
const IResourceId& bitmapResId,
unsigned long intoSubmenuId = 0),
&addBitmap ( unsigned long newItemId,
unsigned long bitmapResId,
unsigned long intoSubmenuId = 0),
&addSeparator ( unsigned long newItemId,
unsigned long intoSubmenuId);
virtual IMenu
&addSeparator ( unsigned long intoSubmenuId = 0 ),
&addSubmenu ( unsigned long itemId ),
&addSubmenu ( unsigned long itemId,
const IResourceId& submenuResId );
/*------------------------Replace Menu Item ------------------------------------
| The following functions provide a means to replace menu items of the |
| instances of this menu class: |
| setItem - Replaces a specified menu item's style and |
| representation. |
| setText - Replaces a menu item's text. |
| setBitmap - Causes a menu item to display a bit map. The bit |
| map is assumed to be in the default resource |
| library. |
| setSubmenu - Creates a menu and sets it as the menu item's |
| submenu. |
| setConditionalCascade - Enables the conditional cascade menu behavior. |
| The item specified by the itemWithSubmenuId |
| argument will have its submenu set as a |
| conditional cascade menu. The defaultItemId |
| argument specifies the default selection. You |
| can also use this function to change the default |
| item on a menu that is already a conditional |
| cascade. An exception will be thrown if: |
| - The items specified for the itemWithSubmenuId |
| or defaultItemId arguments do not exist. |
| - The item specified for the itemWithSubmenuId |
| argument does not have a submenu attached. |
------------------------------------------------------------------------------*/
virtual IMenu
&setItem ( const IMenuItem& menuItem ),
&setText ( unsigned long menuItemId,
const char* newText ),
&setText ( unsigned long menuItemId,
const IResourceId& newTextResId ),
&setBitmap ( unsigned long menuItemId,
const IBitmapHandle& bitmapHandle ),
&setBitmap ( unsigned long menuItemId,
const IResourceId& newBitmapResId ),
&setBitmap ( unsigned long menuItemId,
unsigned long newBitmapResId ),
&setSubmenu ( unsigned long itemId,
const IResourceId& submenuResId );
// setConditionalCascade() and removeConditionalCascade are
// not declared virtual since the were implemented in the first
// CSD. Making them virtual would force existing programs to
// recompile because of VTBL changes.
// Don't see a need for anyone to override these.
IMenu
&setConditionalCascade
( unsigned long itemWithSubmenuId,
unsigned long defaultItemId);
/*-----------------------Delete/Remove Menu Item/Submenu------------------------
| The following functions provide a means to delete menu items, submenus, or |
| cascade behavior. |
| deleteItem - Removes the specified item from the menu. |
| removeSubmenu - Removes the menu item's submenu indicator and |
| destroys the submenu. This function is |
| typically used to remove a cascading menu. |
| removeConditionalCascade - Removes conditional cascade behavior from the |
| menu item specified for the itemWithSubmenuId |
| argument. An exception will be thrown if the |
| item specified for the itemWithSubmenuId |
| argument does not exist or does not have an |
| associated submenu. |
------------------------------------------------------------------------------*/
virtual IMenu
&deleteItem ( unsigned long itemId ),
&removeSubmenu ( unsigned long itemWithSubmenuId );
IMenu
&removeConditionalCascade
( unsigned long itemWithSubmenuId );
/*---------------------- Check and Disable Menu Item ---------------------------
| The following functions provide a means to check, disable, and select menu |
| items of the instances of this menu class: |
| checkItem - Places a check mark to the left of the specified item. |
| NOTE: The menu bar pull-down cannot be checked. This is an |
| OS/2 Presentation Manager restriction. |
| uncheckItem - Removes the check mark from a specified menu item. |
| enableItem - Makes a menu item selectable. |
| disableItem - Makes a menu item unselectable. |
| selectItem - Selects a menu item. |
------------------------------------------------------------------------------*/
virtual IMenu
&checkItem ( unsigned long itemId,
Boolean check = true ),
&uncheckItem ( unsigned long itemId ),
&enableItem ( unsigned long itemId,
Boolean enable = true ),
&disableItem ( unsigned long itemId ),
&selectItem ( unsigned long itemId );
/*------------------- Test Checked and Disabled Menu Item ----------------------
| The following functions provide a means to test menu items of the instances |
| of this menu class: |
| isItemDisabled - Returns true if the specified menu item is unselectable. |
| isItemChecked - Returns true if the specified menu item is checked. |
------------------------------------------------------------------------------*/
Boolean
isItemChecked ( unsigned long itemId ) const,
isItemDisabled ( unsigned long itemId ) const;
/*-------------------------- Accessor ------------------------------------------
| The following functions provide a means to get the menu item of instances |
| of this class: |
| menuItem - Returns an IMenuItem instance of a menu item. |
| numberOfItems - Returns the number of menu items in a menu or submenu. |
| itemRect - Returns the bounding rectangle of a menu item. |
------------------------------------------------------------------------------*/
IMenuItem
menuItem ( unsigned long itemId ) const;
IRectangle
itemRect ( unsigned long itemId ) const;
unsigned long
numberOfItems ( unsigned long forSubmenuId = 0) const;
/*---------------------- ColorArea Enumerator ----------------------------------
| ColorArea - Enumeration that is used to replace and set the color for a |
| particular area of the menu. The valid values are: |
| foreground - Sets the color of the foreground text. |
| background - Sets the color of the background text. |
| disabledForeground - Sets the foreground color for disabled |
| text. |
| disabledBackground - Sets the background color for disabled |
| text. |
| highlightForeground - Sets the foreground color for selected |
| text. |
| highlightBackground - Sets the background color for selected |
| text. |
| border - Sets the color of the border that |
| surrounds the menu. |
------------------------------------------------------------------------------*/
enum ColorArea {
foreground,
background,
disabledForeground,
disabledBackground,
highlightForeground,
highlightBackground,
border };
/*-------------------------- Set and Query Color ------------------------------
| The following functions provide a mean to set and query the menu color: |
| setColor - Changes the color of the specific menu area. |
| color - Returns the color of the specific menu area. |
------------------------------------------------------------------------------*/
IMenu
&setColor ( ColorArea value,
const IColor &color );
IColor
color ( ColorArea value ) const;
class Cursor : public IBase {
/*******************************************************************************
* The IMenu::Cursor class creates and manages the cursor for menu items. *
*******************************************************************************/
public :
/*------------------ Constructor/Destructor ---------------------------------
| The only way to construct an instance of this class is with an instance |
| of an IMenu and submenu ID. The sub-menu defaults to 0 for the |
| top-level menu items. |
---------------------------------------------------------------------------*/
Cursor(const IMenu& menu,
unsigned long forSubmenuId = 0 );
/*------------------------ Cursor Movement ------------------------
| The following functions provide a means to move the cursor |
| position: |
| |
| setToFirst - Points to the first menu item. |
| setToNext - Points to the next menu item. If there is |
| none, the cursor is invalidated. |
| setToPrevious - Points to the previous menu item. If there is |
| none, the cursor is invalidated. |
| setToLast - Points to the last menu item. |
-----------------------------------------------------------------*/
Boolean
setToFirst ( ),
setToNext ( ),
setToPrevious ( ),
setToLast ( );
/*--------------- Cursor Validation ------------------------------+
| The following functions provide a means to validate the cursor: |
| |
| isValid - Queries whether this cursor points to a valid menu |
| item. |
| invalidate - Flags the cursor as invalid. |
+----------------------------------------------------------------*/
Boolean
isValid ( ) const;
void
invalidate ( );
private : /*------------------- PRIVATE ------------------------*/
friend class IMenu;
long
lCurrent;
unsigned long
ulSubmenu;
IMenu*
pMenu;
};
/*-------------------- Menu Item Operations with Cursor ------------------------
| The following functions provide a means to manage the menu item of |
| instances of this class: |
| |
| elementAt - Returns the menu item at the cursor position. |
| deleteAt - Deletes the menu item at the cursor position and sets |
| the cursor to the previous menu item. |
| removeSubmenuAt - Removes the menu item at the cursor position submenu |
| indicator and destroys the submenu. This function is |
| typically used to remove a cascading menu. |
| addAt - Adds the menu item at the cursor's position by pushing |
| everything after the cursor. |
| addNextAt - Adds the specified menu item as the next item and sets |
| the cursor upon it. |
| cursor - Returns an instance of the Cursor nested class and sets |
| the cursor to point to the specified menu item. |
------------------------------------------------------------------------------*/
IMenuItem
elementAt ( const Cursor& cursor ) const;
IMenu
&deleteAt ( Cursor& cursor ),
&removeSubmenuAt ( Cursor& cursor ),
&addAt ( IMenuItem& menuItem,
Cursor& cursor ),
&addNextAt ( IMenuItem& menuItem,
Cursor& cursor );
Cursor
cursor ( unsigned long itemId,
unsigned long inSubmenuId = 0 ) const;
/*----------------------- Private -----------------------------------*/
private:
IMenu(const IMenu&);
IMenu &operator=(const IMenu&);
unsigned long
menuItemId ( const Cursor& cursor ) const;
void
refCountBitmap(const IBitmapHandle& handle );
static Style
currentDefaultStyle;
IWindowHandle
submenuHandle ( unsigned long submenuId ) const;
void*
pBitmapList;
};
INESTEDBITFLAGCLASSFUNCS(Style, IMenu);
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
/*--------------------------------- Inlines ----------------------------------*/
#ifndef I_NO_INLINES
#include <imenu.inl>
#endif
#endif /* _IMENU_ */