[Classes] [Prev] [Next] [Methods]

CMenuButton

Methods Index

Heritage
Description
Usage
Environment
Protected Data Members
Public Methods
Constructor, Destructor, and Initializer methods
Methods Overridden from CButton
Methods Specific to CMenuButton
Protected Methods

CMenuButton


Heritage

Superclass: CButton


Description

A CMenuButton object is a specialized type of CButton that you can use to provide button accelerators for a menu items. Typically, you place CMenuButton objects in a CToolBar object, but you can place them in any CSubview.

When clicked, a CMenuButton sends itsMenuCommand via the DoMenuCommand mechanism. Like a CButton, a CMenuButton can also send commands (via the DoCommand mechanism) when the cursor enters or leaves the button, and when the mouse button is pressed down or released over the button.

A CMenuButton sets its title to the text of its corresponding menu item. In addition, if the menu item is checkable, the CMenuButton is togglable, and it reflects the state of the menu item.

See Also: For more information on CButton's commands, see CButton.


Usage

When the menu is changed, instances of CMenuButtons do not automatically update themselves. Your application is responsible for calling the CMenuButton::SyncWithMenu method or the CToolBar::UpdateMenuButton(s) methods when the menu changes.

XVT suggests that you use the following code for updating other CMenuButtons:

CMenuBar*  aMenuBar = GetMenuBar();
aMenuBar->SetEnabled(M_EDIT_COPY, TRUE);
itsCopyMenuButton->SyncWithMenu();
XVT suggests that you use the following code for updating a CMenuButton in a CToolBar:

CMenuBar*  aMenuBar = GetMenuBar();
aMenuBar->SetEnabled(M_EDIT_COPY, TRUE);
aMenuBar->SetEnabled(M_EDIT_CUT, TRUE);
itsToolBar->UpdateMenuButton(M_EDIT_CUT);
itsToolBar->UpdateMenuButton(M_EDIT_COPY);
When using CMenuButtons (or CButtons) in a CToolBar, you can have the status bar indicate what feature the button represents as the cursor moves over the buttons. You can implement this feature like this:

// keep a pointer to the CToolBar and CStatusBar 
// in your window
class CShellWin : public CShellWin
{
...
protected:
CToolBar *itsToolBar;
CStatusBar *itsStatusBar;
};

// defint INcmd and OUTcmd for buttons
#define INcmd ..
#define OUTcmd ..

#define OUTPUT_FILEScmd ..
#define STATUS_FIELD ..

CShellWin::CShellWin(..)
{
// Window must have a tool bar (itsToolBar)
// Window must have a status bar (itsStatusBar)
itsToolBar = new CToolBar(this);
itsStatusBar = new CStatusBar(this);
itsStatusBar->AppendField(STATUS_FIELD,
"Initial Status");
// append more status fields as desired

// After constructing buttons for toolbar, set
// their in/out commands
// Titles will automatically be set to the text
// in the menu
CMenuButton *aMenuButton = new CMenuButton(
itsToolBar, M_FILE_NEW,
CImage("filenew.bmp"));
aMenuButton->SetCommands(NULLcmd, NULLcmd,
INcmd, OUTcmd);
aMenuButton = new CMenuButton(
itsToolBar, M_FILE_OPEN,
CImage("fileopen.bmp"));
aMenuButton->SetCommands(NULLcmd, NULLcmd,
INcmd, OUTcmd);

// CButton may also have active status help,
// but their titles must be set explicitly
CButton *aButton = new CButton(
itsToolBar, CPoint(0, 0),
CImage("outfiles.bmp"));
aButton->SetTitle(
"Output selected files to disk");
aMenuButton->SetCommands(OUTPUT_FILEScmd,
NULLcmd, INcmd, OUTcmd);

...etc...
}

CShellWin::DoCommand(long theCommand, void *theData)
{
switch(theCommand)
{
...
case INcmd:
// When INcmd is received, set the
// STATUS_FIELD to the title of the view.
{
CView *aView = (CView *)theData;
itsStatusBar->SetFieldStatus(
STATUS_FIELD, aView->GetTitle());
}
break;
case OUTcmd:
// When OUTcmd is received, clear STATUS_FIELD
itsStatusBar->SetFieldStatus(STATUS_FIELD,
NULLString);
break;
case OUTPUT_FILEScmd:
// do appropriate action, "output files"
// button was clicked
break;
...
}
}

CShellWin::DoMenuCommand(MENU_TAG theCommand,
BOOLEAN s, BOOLEAN c)
{
// No extra work is required to handle
// CMenuButtons. The DoMenuCommand is called the
// when the menu item is selected from the menu,
// or when a CMenuButton is clicked upon.
switch(theCommand)
{
...
case M_FILE_NEW:
// create new file
break;
case M_FILE_OPEN:
// open file
break;
...
}
}

CShellWin::UpdateMenus(CMenuBar *theMenuBar)
{
CWindow::UpdateMenus(theMenuBar);
// If you are using CMenuButtons, update
// their state here.
itsToolBar->UpdateMenuButtons();
}

Environment

CMenuButton objects do not react to changes in their CEnvironment object. You can specify the colors used to render the button in the IButton initializer method. However, the subviews enclosed by a CMenuButton still react to changes in their CEnvironment object.


Protected Data Members

MENU_TAG itsMenuTag; The MENU_TAG that corresponds to button
BOOLEAN itsMenuIsEnabled; Indicates if itsMenuTag is enabled


Public Methods

Constructor, Destructor, and Initializer methods

All of the constructors for the CMenuButton class take a menu item (MENU_TAG) to which the CMenuButton corresponds. Initially, the state of the CMenuButton corresponds to itsmenu item. If the menu item is checkable, the button is togglable. If the menu item is checked, the button is in the down state (i.e., CButton::TS_DOWN). If the menu item is enabled, the button is enabled.

A CMenuButton also sets its title to the text of the corresponding menu item. If the menu item is not on the window's menu, the button is enabled and non-togglable.

CMenuButton(CSubview *theEnclosure, 
const CRect &theSize,
MENU_TAG theMenuTag);
CMenuButton(CSubview *theEnclosure,
const CPoint & theTopLeft, // autosized to theText
MENU_TAG theMenuTag,
const CStringRW &theText);
CMenuButton(CSubview *theEnclosure,
const CPoint &theTopLeft, // autosized to theImage
MENU_TAG theMenuTag,
const CImage &theImage);
CMenuButton(CSubview *theEnclosure,
MENU_TAG theMenuTag,
const CImage &theImage);
CMenuButton(
CSubview *theEnclosure,
MENU_TAG theMenuTag,
const CStringRW &theText);
CMenuButton(const CMenuButton &theButton);
CMenuButton & operator= (const CMenuButton &theButton);
virtual ~CMenuButton();

Methods Overridden from CButton

virtual void SetTogglable(BOOLEAN isTogglable);

Methods Specific to CMenuButton

void SetMenuTag(MENU_TAG theMenuTag);
MENU_TAG GetMenuTag(void) const;
void SyncWithMenu(void);
virtual void Enable(void);

Protected Methods

virtual void DoUpAction(void);
void InitMenuButton(void);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.