* Rewrote MenuItem.h (we're no longer using Be's header).
* Renamed private SetSysTrigger() to SetAutomaticTrigger(). * Added the '_' prefix to private methods that aren't called by anything outside BMenuItem (ie. no friend classes either). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17005 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,124 +1,107 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
/
|
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
||||||
/ File: MenuItem.h
|
* Distributed under the terms of the MIT License.
|
||||||
/
|
*/
|
||||||
/ Description: BMenuItem represents a single item in a BMenu.
|
|
||||||
/ BSeparatorItem is a cosmetic menu item that demarcates
|
|
||||||
/ groups of other items.
|
|
||||||
/
|
|
||||||
/ Copyright 1994-98, Be Incorporated, All Rights Reserved
|
|
||||||
/
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef _MENU_ITEM_H
|
#ifndef _MENU_ITEM_H
|
||||||
#define _MENU_ITEM_H
|
#define _MENU_ITEM_H
|
||||||
|
|
||||||
#include <BeBuild.h>
|
|
||||||
#include <InterfaceDefs.h>
|
|
||||||
#include <Archivable.h>
|
#include <Archivable.h>
|
||||||
|
#include <InterfaceDefs.h>
|
||||||
#include <Invoker.h>
|
#include <Invoker.h>
|
||||||
#include <Menu.h> /* For convenience */
|
#include <Menu.h>
|
||||||
|
|
||||||
class BMessage;
|
class BMessage;
|
||||||
class BWindow;
|
class BWindow;
|
||||||
|
|
||||||
/*----------------------------------------------------------------*/
|
|
||||||
/*----- BMenuItem class ------------------------------------------*/
|
|
||||||
|
|
||||||
class BMenuItem : public BArchivable, public BInvoker {
|
class BMenuItem : public BArchivable, public BInvoker {
|
||||||
public:
|
public:
|
||||||
BMenuItem( const char *label,
|
BMenuItem(const char* label, BMessage* message,
|
||||||
BMessage *message,
|
char shortcut = 0, uint32 modifiers = 0);
|
||||||
char shortcut = 0,
|
BMenuItem(BMenu* menu, BMessage* message = NULL);
|
||||||
uint32 modifiers = 0);
|
BMenuItem(BMessage* data);
|
||||||
BMenuItem(BMenu *menu, BMessage *message = NULL);
|
virtual ~BMenuItem();
|
||||||
BMenuItem(BMessage *data);
|
|
||||||
virtual ~BMenuItem();
|
|
||||||
static BArchivable *Instantiate(BMessage *data);
|
|
||||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
|
||||||
|
|
||||||
virtual void SetLabel(const char *name);
|
|
||||||
virtual void SetEnabled(bool state);
|
|
||||||
virtual void SetMarked(bool state);
|
|
||||||
virtual void SetTrigger(char ch);
|
|
||||||
virtual void SetShortcut(char ch, uint32 modifiers);
|
|
||||||
|
|
||||||
const char *Label() const;
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
bool IsEnabled() const;
|
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||||
bool IsMarked() const;
|
|
||||||
char Trigger() const;
|
|
||||||
char Shortcut(uint32 *modifiers = NULL) const;
|
|
||||||
|
|
||||||
BMenu *Submenu() const;
|
|
||||||
BMenu *Menu() const;
|
|
||||||
BRect Frame() const;
|
|
||||||
|
|
||||||
protected:
|
virtual void SetLabel(const char* name);
|
||||||
|
virtual void SetEnabled(bool enabled);
|
||||||
|
virtual void SetMarked(bool marked);
|
||||||
|
virtual void SetTrigger(char trigger);
|
||||||
|
virtual void SetShortcut(char shortcut, uint32 modifiers);
|
||||||
|
|
||||||
virtual void GetContentSize(float *width, float *height);
|
const char* Label() const;
|
||||||
virtual void TruncateLabel(float max, char *new_label);
|
bool IsEnabled() const;
|
||||||
virtual void DrawContent();
|
bool IsMarked() const;
|
||||||
virtual void Draw();
|
char Trigger() const;
|
||||||
virtual void Highlight(bool on);
|
char Shortcut(uint32* _modifiers = NULL) const;
|
||||||
bool IsSelected() const;
|
|
||||||
BPoint ContentLocation() const;
|
|
||||||
|
|
||||||
/*----- Private or reserved -----------------------------------------*/
|
BMenu* Submenu() const;
|
||||||
private:
|
BMenu* Menu() const;
|
||||||
friend class BMenu;
|
BRect Frame() const;
|
||||||
friend class BPopUpMenu;
|
|
||||||
friend class BMenuBar;
|
|
||||||
|
|
||||||
virtual void _ReservedMenuItem1();
|
protected:
|
||||||
virtual void _ReservedMenuItem2();
|
virtual void GetContentSize(float* _width, float* _height);
|
||||||
virtual void _ReservedMenuItem3();
|
virtual void TruncateLabel(float maxWidth, char* newLabel);
|
||||||
virtual void _ReservedMenuItem4();
|
virtual void DrawContent();
|
||||||
|
virtual void Draw();
|
||||||
|
virtual void Highlight(bool enabled);
|
||||||
|
bool IsSelected() const;
|
||||||
|
BPoint ContentLocation() const;
|
||||||
|
|
||||||
BMenuItem(const BMenuItem &);
|
private:
|
||||||
BMenuItem &operator=(const BMenuItem &);
|
friend class BMenu;
|
||||||
|
friend class BPopUpMenu;
|
||||||
|
friend class BMenuBar;
|
||||||
|
|
||||||
void InitData();
|
virtual void _ReservedMenuItem1();
|
||||||
void InitMenuData(BMenu *menu);
|
virtual void _ReservedMenuItem2();
|
||||||
void Install(BWindow *window);
|
virtual void _ReservedMenuItem3();
|
||||||
|
virtual void _ReservedMenuItem4();
|
||||||
|
|
||||||
/*----- Protected function -----------------------------------------*/
|
void Install(BWindow* window);
|
||||||
protected:
|
void Uninstall();
|
||||||
virtual status_t Invoke(BMessage *msg = NULL);
|
void SetSuper(BMenu* superMenu);
|
||||||
|
void Select(bool select);
|
||||||
|
void SetAutomaticTrigger(char trigger);
|
||||||
|
|
||||||
/*----- Private or reserved -----------------------------------------*/
|
protected:
|
||||||
private:
|
virtual status_t Invoke(BMessage *msg = NULL);
|
||||||
void Uninstall();
|
|
||||||
void SetSuper(BMenu *super);
|
|
||||||
void Select(bool on);
|
|
||||||
void DrawMarkSymbol(rgb_color bgColor);
|
|
||||||
void DrawShortcutSymbol();
|
|
||||||
void DrawSubmenuSymbol(rgb_color bgColor);
|
|
||||||
void _DrawControlChar(char shortcut, BPoint where);
|
|
||||||
void SetSysTrigger(char ch);
|
|
||||||
|
|
||||||
char *fLabel;
|
private:
|
||||||
BMenu *fSubmenu;
|
BMenuItem(const BMenuItem& other);
|
||||||
BWindow *fWindow;
|
BMenuItem& operator=(const BMenuItem& other);
|
||||||
BMenu *fSuper;
|
|
||||||
BRect fBounds;
|
|
||||||
uint32 fModifiers;
|
|
||||||
float fCachedWidth;
|
|
||||||
int16 fTriggerIndex;
|
|
||||||
char fUserTrigger;
|
|
||||||
char fSysTrigger;
|
|
||||||
char fShortcutChar;
|
|
||||||
bool fMark;
|
|
||||||
bool fEnabled;
|
|
||||||
bool fSelected;
|
|
||||||
|
|
||||||
uint32 _reserved[4];
|
void _InitData();
|
||||||
|
void _InitMenuData(BMenu* menu);
|
||||||
|
|
||||||
|
void _DrawMarkSymbol(rgb_color backgroundColor);
|
||||||
|
void _DrawShortcutSymbol();
|
||||||
|
void _DrawSubmenuSymbol(rgb_color backgroundColor);
|
||||||
|
void _DrawControlChar(char shortcut, BPoint where);
|
||||||
|
|
||||||
|
char* fLabel;
|
||||||
|
BMenu* fSubmenu;
|
||||||
|
BWindow* fWindow;
|
||||||
|
BMenu* fSuper;
|
||||||
|
BRect fBounds;
|
||||||
|
uint32 fModifiers;
|
||||||
|
float fCachedWidth;
|
||||||
|
int16 fTriggerIndex;
|
||||||
|
char fUserTrigger;
|
||||||
|
char fAutomaticTrigger;
|
||||||
|
char fShortcutChar;
|
||||||
|
bool fMark;
|
||||||
|
bool fEnabled;
|
||||||
|
bool fSelected;
|
||||||
|
|
||||||
|
uint32 _reserved[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-------------------------------------------------------------*/
|
// BSeparatorItem now has its own declaration file, but for source
|
||||||
/*-------------------------------------------------------------*/
|
// compatibility we're exporting that class from here too.
|
||||||
|
|
||||||
// We moved BSeparatorItem's declaration to its own file, but for source
|
|
||||||
// compatibility we have to export that class from here too.
|
|
||||||
#include <SeparatorItem.h>
|
#include <SeparatorItem.h>
|
||||||
|
|
||||||
#endif /* _MENU_ITEM_H */
|
#endif /* _MENU_ITEM_H */
|
||||||
|
|||||||
@@ -1805,7 +1805,7 @@ BMenu::CalcTriggers()
|
|||||||
if (item->Trigger() == 0) {
|
if (item->Trigger() == 0) {
|
||||||
const char *newTrigger = ChooseTrigger(item->Label(), &triggersList);
|
const char *newTrigger = ChooseTrigger(item->Label(), &triggersList);
|
||||||
if (newTrigger != NULL) {
|
if (newTrigger != NULL) {
|
||||||
item->SetSysTrigger(*newTrigger);
|
item->SetAutomaticTrigger(*newTrigger);
|
||||||
// TODO: This is crap. I'd prefer to have
|
// TODO: This is crap. I'd prefer to have
|
||||||
// BMenuItem::SetSysTrigger(const char *) update fTriggerIndex.
|
// BMenuItem::SetSysTrigger(const char *) update fTriggerIndex.
|
||||||
// This isn't the case on beos, but it will probably be like that on haiku.
|
// This isn't the case on beos, but it will probably be like that on haiku.
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ const float kLightBGTint = (B_LIGHTEN_1_TINT + B_LIGHTEN_1_TINT + B_NO_TINT) / 3
|
|||||||
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
||||||
uint32 modifiers)
|
uint32 modifiers)
|
||||||
{
|
{
|
||||||
InitData();
|
_InitData();
|
||||||
if (label != NULL)
|
if (label != NULL)
|
||||||
fLabel = strdup(label);
|
fLabel = strdup(label);
|
||||||
|
|
||||||
@@ -106,15 +106,15 @@ BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
|||||||
|
|
||||||
BMenuItem::BMenuItem(BMenu *menu, BMessage *message)
|
BMenuItem::BMenuItem(BMenu *menu, BMessage *message)
|
||||||
{
|
{
|
||||||
InitData();
|
_InitData();
|
||||||
SetMessage(message);
|
SetMessage(message);
|
||||||
InitMenuData(menu);
|
_InitMenuData(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMenuItem::BMenuItem(BMessage *data)
|
BMenuItem::BMenuItem(BMessage *data)
|
||||||
{
|
{
|
||||||
InitData();
|
_InitData();
|
||||||
|
|
||||||
if (data->HasString("_label")) {
|
if (data->HasString("_label")) {
|
||||||
const char *string;
|
const char *string;
|
||||||
@@ -163,7 +163,7 @@ BMenuItem::BMenuItem(BMessage *data)
|
|||||||
BMenu *menu = dynamic_cast<BMenu *>(object);
|
BMenu *menu = dynamic_cast<BMenu *>(object);
|
||||||
|
|
||||||
if (menu != NULL)
|
if (menu != NULL)
|
||||||
InitMenuData(menu);
|
_InitMenuData(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,8 +174,8 @@ BMenuItem::Instantiate(BMessage *data)
|
|||||||
{
|
{
|
||||||
if (validate_instantiation(data, "BMenuItem"))
|
if (validate_instantiation(data, "BMenuItem"))
|
||||||
return new BMenuItem(data);
|
return new BMenuItem(data);
|
||||||
else
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ BMenuItem::SetEnabled(bool state)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fEnabled = state;
|
fEnabled = state;
|
||||||
|
|
||||||
if (fSubmenu != NULL)
|
if (fSubmenu != NULL)
|
||||||
fSubmenu->SetEnabled(state);
|
fSubmenu->SetEnabled(state);
|
||||||
|
|
||||||
@@ -272,14 +272,14 @@ BMenuItem::SetMarked(bool state)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::SetTrigger(char ch)
|
BMenuItem::SetTrigger(char trigger)
|
||||||
{
|
{
|
||||||
fUserTrigger = ch;
|
fUserTrigger = trigger;
|
||||||
|
|
||||||
if (strchr(fLabel, ch) != 0)
|
if (strchr(fLabel, trigger) != 0)
|
||||||
fSysTrigger = ch;
|
fAutomaticTrigger = trigger;
|
||||||
else
|
else
|
||||||
fSysTrigger = -1;
|
fAutomaticTrigger = -1;
|
||||||
|
|
||||||
if (fSuper != NULL)
|
if (fSuper != NULL)
|
||||||
fSuper->InvalidateLayout();
|
fSuper->InvalidateLayout();
|
||||||
@@ -482,13 +482,13 @@ BMenuItem::Draw()
|
|||||||
// draw extra symbols
|
// draw extra symbols
|
||||||
if (fSuper->Layout() == B_ITEMS_IN_COLUMN) {
|
if (fSuper->Layout() == B_ITEMS_IN_COLUMN) {
|
||||||
if (IsMarked())
|
if (IsMarked())
|
||||||
DrawMarkSymbol(bgColor);
|
_DrawMarkSymbol(bgColor);
|
||||||
|
|
||||||
if (fShortcutChar)
|
if (fShortcutChar)
|
||||||
DrawShortcutSymbol();
|
_DrawShortcutSymbol();
|
||||||
|
|
||||||
if (Submenu())
|
if (Submenu())
|
||||||
DrawSubmenuSymbol(bgColor);
|
_DrawSubmenuSymbol(bgColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,7 +534,7 @@ BMenuItem::operator=(const BMenuItem &)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::InitData()
|
BMenuItem::_InitData()
|
||||||
{
|
{
|
||||||
fLabel = NULL;
|
fLabel = NULL;
|
||||||
fSubmenu = NULL;
|
fSubmenu = NULL;
|
||||||
@@ -544,7 +544,7 @@ BMenuItem::InitData()
|
|||||||
fCachedWidth = 0;
|
fCachedWidth = 0;
|
||||||
fTriggerIndex = -1;
|
fTriggerIndex = -1;
|
||||||
fUserTrigger = 0;
|
fUserTrigger = 0;
|
||||||
fSysTrigger = 0;
|
fAutomaticTrigger = 0;
|
||||||
fShortcutChar = 0;
|
fShortcutChar = 0;
|
||||||
fMark = false;
|
fMark = false;
|
||||||
fEnabled = true;
|
fEnabled = true;
|
||||||
@@ -553,7 +553,7 @@ BMenuItem::InitData()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::InitMenuData(BMenu *menu)
|
BMenuItem::_InitMenuData(BMenu *menu)
|
||||||
{
|
{
|
||||||
fSubmenu = menu;
|
fSubmenu = menu;
|
||||||
fSubmenu->fSuperitem = this;
|
fSubmenu->fSuperitem = this;
|
||||||
@@ -665,7 +665,7 @@ BMenuItem::Select(bool selected)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::DrawMarkSymbol(rgb_color bgColor)
|
BMenuItem::_DrawMarkSymbol(rgb_color bgColor)
|
||||||
{
|
{
|
||||||
fSuper->PushState();
|
fSuper->PushState();
|
||||||
|
|
||||||
@@ -700,7 +700,7 @@ BMenuItem::DrawMarkSymbol(rgb_color bgColor)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::DrawShortcutSymbol()
|
BMenuItem::_DrawShortcutSymbol()
|
||||||
{
|
{
|
||||||
// TODO: Review this
|
// TODO: Review this
|
||||||
BPoint where = ContentLocation();
|
BPoint where = ContentLocation();
|
||||||
@@ -760,7 +760,7 @@ BMenuItem::DrawShortcutSymbol()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::DrawSubmenuSymbol(rgb_color bgColor)
|
BMenuItem::_DrawSubmenuSymbol(rgb_color bgColor)
|
||||||
{
|
{
|
||||||
fSuper->PushState();
|
fSuper->PushState();
|
||||||
|
|
||||||
@@ -821,7 +821,7 @@ BMenuItem::_DrawControlChar(char shortcut, BPoint where)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMenuItem::SetSysTrigger(char ch)
|
BMenuItem::SetAutomaticTrigger(char ch)
|
||||||
{
|
{
|
||||||
fSysTrigger = ch;
|
fAutomaticTrigger = ch;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user