| Methods Index |
CButton
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();XVT suggests that you use the following code for updating a
aMenuBar->SetEnabled(M_EDIT_COPY, TRUE);
itsCopyMenuButton->SyncWithMenu();
CMenuButton in a CToolBar:
CMenuBar* aMenuBar = GetMenuBar();When using
aMenuBar->SetEnabled(M_EDIT_COPY, TRUE);
aMenuBar->SetEnabled(M_EDIT_CUT, TRUE);
itsToolBar->UpdateMenuButton(M_EDIT_CUT);
itsToolBar->UpdateMenuButton(M_EDIT_COPY);
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();
}
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.
|
|
|
MENU_TAG itsMenuTag;
|
The MENU_TAG that corresponds to button
|
BOOLEAN itsMenuIsEnabled;
|
Indicates if itsMenuTag is enabled
|
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 of the size indicated by theSize with the enclosure specified by theEnclosure. The created button corresponds to theMenuTag menu item. This constructor is generally followed by creation of other CView objects that have the created CMenuButton as their enclosure.You should, however, use this constructor only when constructing a
CMenuButton that contains views other than CText or CPicture. XVT supplies convenience constructors for these common construction cases.
CMenuButton(CSubview *theEnclosure,
const CPoint & theTopLeft, // autosized to theText
MENU_TAG theMenuTag,
const CStringRW &theText);
CMenuButton that contains text. This constructor creates a CText object, places it in the new CMenuButton, and sizes the button to the text.
CMenuButton(CSubview *theEnclosure,
const CPoint &theTopLeft, // autosized to theImage
MENU_TAG theMenuTag,
const CImage &theImage);
CMenuButton that contains a portable image. This constructor creates a CPicture object, places it in the new CMenuButton, and sizes the button to the image.
CMenuButton(CSubview *theEnclosure,
MENU_TAG theMenuTag,
const CImage &theImage);
CMenuButton that contains a portable image to be placed in a CToolBar. This constructor differs from the previous one in that it does not require a CPoint location. This argument is not necessary for creating CMenuButtons that exist in a CToolBar, because the CToolBar handles positioning of the button.
CMenuButton(
CSubview *theEnclosure,
MENU_TAG theMenuTag,
const CStringRW &theText);
theEnclosure. The button will generate a DoMenuCommand event associated with theMenuTag. It displays theText as its title. This constructor does not take any point or region for the button, allowing those attributes to be determined later. This constructor is commonly used by containers which rearrange their views after they are constructed (e.g. CToolBar).
CMenuButton(const CMenuButton &theButton);
theButton's attributes. The inherited CButton copy constructor copies the menu item that corresponds to theButton as well as the button's attributes.
CMenuButton & operator= (const CMenuButton &theButton);
CMenuButton to another. The inherited CButton assignment operator copies the menu item that corresponds to theButton as well as the button's attributes.
virtual ~CMenuButton();
CMenuButton class, which deletes the button and all of its nested views.
virtual void SetTogglable(BOOLEAN isTogglable);
CMenuButton object is togglable only if its corresponding MENU_TAG is togglable, this method is disabled for CMenuButton.
void SetMenuTag(MENU_TAG theMenuTag);
CMenuButton.
MENU_TAG GetMenuTag(void) const;
CMenuButton.
void SyncWithMenu(void);
CMenuButton with its corresponding menu item. If the menu item is checked, the created button is in the down state (CButton::TS_DOWN). If the menu item is enabled, the button is enabled. If the menu item is not on the window's menu, the button is enabled.
virtual void Enable(void);
CView.
virtual void DoUpAction(void);
DoMenuCommand upon a DoUp event. This method is overridden from CButton.
void InitMenuButton(void);
CMenuButton to correspond with its menu item.