home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IMNITEM.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
21KB
|
379 lines
#ifndef _IMNITEM_
#define _IMNITEM_
/******************************************************************************
* FILE NAME: imnitem.hpp *
* *
* DESCRIPTION: *
* Declaration of the class: *
* IMenuItem - is a data class used to represent a menu item. *
* *
* 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 _IHANDLE_
#include <ihandle.hpp>
#endif
#ifndef _ISTRING_
#include <istring.hpp>
#endif
#ifndef _IBITFLAG_
#include <ibitflag.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
// Forward declarations for other classes
class IResourceId;
class IMenu;
class ISubmenu;
class IMenuItem : public IBase {
typedef IBase
Inherited;
/******************************************************************************
* The IMenuItem class is a data class used to present the menu item *
* structure. This class provides style objects, attribute objects, and *
* functions to set and query the menu item. These functions do not affect *
* the menu unless the IMenu add or set functions are invoked with the *
* instance of the menu item. *
* *
* An IMenuItem can be constructed and added to the menu by using the IMenu or *
* ISubmenu member functions. You can also use the IMenu::menuItem function *
* to query an existing item in a menu, and subsequently change the item's *
* style and attribute, and reset the menu item. *
* *
* NOTE: A menu item ID does not have to be unique. However, if an operation *
* such as IMenu::checked is invoked using the ID, the first menu item *
* that has the ID will be acted upon. *
******************************************************************************/
public:
/*-------------------------------- Styles --------------------------------------
| The following are the valid menu-item styles: |
| |
| classDefaultStyle - This style is a static variable that is set to |
| noStyle. |
| split - The menu item starts in a new row or column. This |
| style cannot be used with splitWithSeparator or |
| buttonSeparator. |
| splitWithSeparator - The menu item starts in a new row or column with a |
| line drawn to separate it. This style cannot be |
| used with split or buttonSeparator. |
| buttonSeparator - A line is drawn to separate the menu item. The |
| user cannot use cursor movement keys to get to it. |
| This style cannot be used with split or |
| splitWithSeparator. |
| postSystemCommand - The menu item generates a system command message |
| that can be handled by |
| ICommandHandler::systemCommand. This style cannot |
| be used with postHelp. |
| postHelp - The menu item generates a help message that is |
| issued to the previous focus window. Therefore, |
| the postHelp style works just like a Help push |
| button. This style cannot be used with |
| postSystemCommand. |
| unavailable - Sets unavailable-state emphasis for a menu item. |
| drawItem - Allows applications to draw the menu item. |
| separator - Specifies that the menu item is a separator |
| noStyle - Specifies that no style applies to the menu item. |
| |
| 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. |
------------------------------------------------------------------------------*/
INESTEDBITFLAGCLASSDEF0(Style, IMenuItem);
static const Style
classDefaultStyle,
split, //mutually exclusive
splitWithSeparator,
buttonSeparator,
postSystemCommand, //mutually exclusive
postHelp,
separator, // mutually exclusive
drawItem,
unavailable,
noStyle;
static Style
defaultStyle ( );
static void
setDefaultStyle ( const Style &aStyle );
/*------------------------------ Attributes ------------------------------------
| The following are the valid menu item attributes. All attributes are set |
| independent of each other. |
| |
| classDefaultAttribute - This attribute is a static variable that is set |
| to noAttribute. |
| noDismiss - If a menu item in a submenu is chosen, the |
| submenu remains displayed. |
| framed - Encloses the menu item in a box. |
| checked - Displays a check mark to the left of the menu |
| item when it is selected. The check mark is |
| removed when the item is de-selected. |
| disabled - Displays the menu item with unavailable-state |
| emphasis, which means it cannot be selected. |
| highlighted - Displays the menu item with selected-state |
| emphasis. |
| noAttribute - Specifies that no attribute applies to the menu |
| item. |
| |
| The following functions provide a means of getting and setting the default |
| attributes for this class: |
| |
| defaultAttribute - Returns the current default attribute. This is |
| the same as classDefaultAttribute unless |
| setDefaultAttribute has been called. |
| setDefaultAttribute - Sets the default attribute for all subsequent menu |
| items. |
------------------------------------------------------------------------------*/
INESTEDBITFLAGCLASSDEF0(Attribute, IMenuItem);
static const Attribute
classDefaultAttribute,
noDismiss,
framed,
checked,
disabled,
highlighted,
noAttribute;
static Attribute
defaultAttribute ( );
static void
setDefaultAttribute ( const Attribute &aAttribute );
/*----------------------- Constructors and Destructor --------------------------
| You can only construct an instance of this class by creating a default |
| menu item. This constructor creates an instance of IMenuItem with the |
| specified styles and attributes. |
| |
| In most cases you will need to perform at least one of the "set" functions |
| on the menu item before it can be added to a menu. For example, if you |
| want a bit-map menu item, you would first construct the IMenuItem and then |
| call one of the setBitmap functions to specify the bit map to be used for |
| display purposes. |
| |
| After construction, IMenuItems that have the separator or drawItem styles |
| can be added to a menu without having to call any of the "set" functions. |
------------------------------------------------------------------------------*/
IMenuItem ( unsigned long itemId,
const Style &style = defaultStyle(),
const Attribute &attribute = defaultAttribute());
~IMenuItem();
/*---------------------------- Enumerations ------------------------------------
| The following enumerations provide a means of setting the style of |
| instances of this class: |
| LayoutType - This enumeration is used to define the placement and layout |
| of the menu item. The valid values are: |
| splitLayout - Starts the menu item in a new |
| row or column. |
| splitWithSeparatorLayout - Starts the menu item in a new |
| row or column with a line |
| drawn to separate it. |
| buttonSeparatorLayout - Separates the menu item and |
| does not allow cursor movement |
| to it. |
| normalLayout - Specifies that no style |
| applies. |
| |
| CommandType - This enumeration is used to define the type of event to |
| generate when the menu item is selected. The valid values |
| are: |
| command - Generates an ICommandHandler::command |
| event. |
| systemCommand - Generates an |
| ICommandHandler::systemCommand event. |
| helpCommand - Generates a help message. |
------------------------------------------------------------------------------*/
enum LayoutType {
normalLayout,
splitLayout,
splitWithSeparatorLayout,
buttonSeparatorLayout
};
enum CommandType {
command,
systemCommand,
helpCommand
};
/*---------------------- Set/Change Style and Attribute ------------------------
| The following functions can be used to set menu item styles: |
| |
| setLayout - Defines the menu item placement and layout. |
| setCommand - Specifies what event to generate when the menu item is |
| selected. |
| setSeparator - Makes the menu item a separator. |
| setSelectable - Enables the menu item for selection. |
| setDrawItem - Generates a draw item event to allow the application to |
| draw the menu item. |
| setNoDismiss - Forces the menu item to remain visible when selected. |
| setFramed - Draws a box to enclose the menu item. |
| setChecked - Displays a check mark to the left of the menu item when |
| it is selected. The check mark is removed when the item |
| is de-selected. |
| setDisabled - Displays the menu item with unavailable-state emphasis, |
| which means it cannot be selected. |
| setHighlighted - Displays the menu item with selected-state emphasis. |
------------------------------------------------------------------------------*/
IMenuItem
&setLayout ( LayoutType aValue ),
&setCommand ( CommandType aValue ),
&setSeparator ( ),
&setSelectable ( Boolean selectable = true ),
&setDrawItem ( Boolean drawItem = true ),
&setNoDismiss ( Boolean noDismiss = true ),
&setFramed ( Boolean framed = true ),
&setChecked ( Boolean checked = true ),
&setDisabled ( Boolean disabled = true ),
&setHighlighted ( Boolean highlighted = true );
/*--------------------Query/Test Style and Attribute ---------------------------
| The following functions can be used to query or test for a specific style |
| or attribute: |
| layoutType - Returns the menu item placement and layout. |
| commandType - Returns the event the menu item will generate when |
| selected. |
| isSelectable - Returns true if the menu item is selectable. |
| isSeparator - Returns true if the separator style is set. |
| isDrawItem - Returns true if the drawItem style is set. |
| isNoDismiss - Returns true if the noDismiss attribute is set. |
| isFramed - Returns true if the framed attribute is set. |
| isChecked - Returns true if the checked attribute is set. |
| isDisabled - Returns true if the disabled attribute is set. |
| isHighlighted - Returns true if the highlighted attribute is set. |
------------------------------------------------------------------------------*/
LayoutType
layoutType ( ) const;
CommandType
commandType ( ) const;
Boolean
isSelectable ( ) const,
isDrawItem ( ) const,
isSeparator ( ) const,
isNoDismiss ( ) const,
isFramed ( ) const,
isChecked ( ) const,
isDisabled ( ) const,
isHighlighted ( ) const;
/*---------------------Set and Change Menu Item ------------------------------
| The following functions can be used to set and change menu item content. |
| setText - Sets the text to be displayed. |
| setBitmap - Sets the bit map to be displayed. The implementation |
| that uses an unsigned long argument is the same as |
| IResourceId. It is provided to resolve ambiguity. |
| setIndex - Sets the menu item ordinal position in its submenu. |
| setSubmenuHandle - Sets the menu item submenu window handle. When |
| selected, the menu item will now display the menu |
| specified by the menuHandle argument as a cascaded |
| submenu. |
----------------------------------------------------------------------------*/
IMenuItem
&setText ( const char* newText ),
&setText ( const IResourceId &textResId ),
&setBitmap ( const IBitmapHandle &menuItem ),
&setBitmap ( const IResourceId &bitmapResId ),
&setBitmap ( unsigned long bitmapResId ),
&setIndex ( long index = atEnd()),
&setSubmenuHandle ( const IWindowHandle &menuHandle );
/*--------------------- Accessor -----------------------------------------------
| The following functions can be used to query the menu item content. |
| id - Returns the ID associated with the menu item. |
| style - Returns an unsigned long representing the menu item's |
| style. |
| attribute - Returns an unsigned long representing the menu item's |
| attributes. |
| index - Returns the ordinal position of the menu item in its |
| submenu. |
| text - Returns an IString that represents the text to be |
| displayed. |
| bitmap - Returns the bit-map handle of the item. |
| submenuHandle - Returns the submenu window handle for the item. |
------------------------------------------------------------------------------*/
unsigned long
id ( ) const,
style ( ) const,
attribute ( ) const;
long
index ( ) const;
IString
text ( ) const;
IBitmapHandle
bitmap ( ) const;
IWindowHandle
submenuHandle ( ) const;
/*-------------------------- Set Style/Attribute ------------------------------
| The following member functions are used to set the menu item's style |
| and attributes: |
| setStyle - Sets the menu item's style from an unsigned long. |
| setAttribute - Sets the menu item's attributes from an unsigned long. |
------------------------------------------------------------------------------*/
IMenuItem
&setStyle ( unsigned long newStyle ),
&setAttribute ( unsigned long newAttribute );
/*----------------------- Private -----------------------------------*/
private:
friend class IMenu;
static Style
currentDefaultStyle;
static Attribute
currentDefaultAttribute;
static long
atEnd ( );
IString
strClItemText;
long
iPosition;
unsigned long
afStyle,
afAttribute,
itemId;
IWindowHandle
hwndSubmenu;
IBitmapHandle
hBitmapHandle;
};
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <imnitem.inl>
#endif
#endif /* _IMNITEM_ */