* 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:
Axel Dörfler
2006-04-04 13:02:52 +00:00
parent 40b478baec
commit 0f11085c6c
3 changed files with 105 additions and 122 deletions
+65 -82
View File
@@ -1,111 +1,97 @@
/******************************************************************************* /*
/ * 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); static BArchivable* Instantiate(BMessage* archive);
virtual void SetEnabled(bool state); virtual status_t Archive(BMessage* archive, bool deep = true) const;
virtual void SetMarked(bool state);
virtual void SetTrigger(char ch);
virtual void SetShortcut(char ch, uint32 modifiers);
const char *Label() const; 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);
const char* Label() const;
bool IsEnabled() const; bool IsEnabled() const;
bool IsMarked() const; bool IsMarked() const;
char Trigger() const; char Trigger() const;
char Shortcut(uint32 *modifiers = NULL) const; char Shortcut(uint32* _modifiers = NULL) const;
BMenu *Submenu() const; BMenu* Submenu() const;
BMenu *Menu() const; BMenu* Menu() const;
BRect Frame() const; BRect Frame() const;
protected: protected:
virtual void GetContentSize(float* _width, float* _height);
virtual void GetContentSize(float *width, float *height); virtual void TruncateLabel(float maxWidth, char* newLabel);
virtual void TruncateLabel(float max, char *new_label); virtual void DrawContent();
virtual void DrawContent(); virtual void Draw();
virtual void Draw(); virtual void Highlight(bool enabled);
virtual void Highlight(bool on);
bool IsSelected() const; bool IsSelected() const;
BPoint ContentLocation() const; BPoint ContentLocation() const;
/*----- Private or reserved -----------------------------------------*/ private:
private: friend class BMenu;
friend class BMenu; friend class BPopUpMenu;
friend class BPopUpMenu; friend class BMenuBar;
friend class BMenuBar;
virtual void _ReservedMenuItem1(); virtual void _ReservedMenuItem1();
virtual void _ReservedMenuItem2(); virtual void _ReservedMenuItem2();
virtual void _ReservedMenuItem3(); virtual void _ReservedMenuItem3();
virtual void _ReservedMenuItem4(); virtual void _ReservedMenuItem4();
BMenuItem(const BMenuItem &); void Install(BWindow* window);
BMenuItem &operator=(const BMenuItem &);
void InitData();
void InitMenuData(BMenu *menu);
void Install(BWindow *window);
/*----- Protected function -----------------------------------------*/
protected:
virtual status_t Invoke(BMessage *msg = NULL);
/*----- Private or reserved -----------------------------------------*/
private:
void Uninstall(); void Uninstall();
void SetSuper(BMenu *super); void SetSuper(BMenu* superMenu);
void Select(bool on); void Select(bool select);
void DrawMarkSymbol(rgb_color bgColor); void SetAutomaticTrigger(char trigger);
void DrawShortcutSymbol();
void DrawSubmenuSymbol(rgb_color bgColor);
void _DrawControlChar(char shortcut, BPoint where);
void SetSysTrigger(char ch);
char *fLabel; protected:
BMenu *fSubmenu; virtual status_t Invoke(BMessage *msg = NULL);
BWindow *fWindow;
BMenu *fSuper; private:
BMenuItem(const BMenuItem& other);
BMenuItem& operator=(const BMenuItem& other);
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; BRect fBounds;
uint32 fModifiers; uint32 fModifiers;
float fCachedWidth; float fCachedWidth;
int16 fTriggerIndex; int16 fTriggerIndex;
char fUserTrigger; char fUserTrigger;
char fSysTrigger; char fAutomaticTrigger;
char fShortcutChar; char fShortcutChar;
bool fMark; bool fMark;
bool fEnabled; bool fEnabled;
@@ -114,11 +100,8 @@ private:
uint32 _reserved[4]; 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 */
+1 -1
View File
@@ -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.
+22 -22
View File
@@ -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,7 +174,7 @@ 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;
} }
@@ -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;
} }