diff --git a/headers/os/interface/MenuItem.h b/headers/os/interface/MenuItem.h index 777ff3284c..6ccd24cfbf 100644 --- a/headers/os/interface/MenuItem.h +++ b/headers/os/interface/MenuItem.h @@ -1,124 +1,107 @@ -/******************************************************************************* -/ -/ File: MenuItem.h -/ -/ 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 -/ -*******************************************************************************/ - +/* + * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _MENU_ITEM_H #define _MENU_ITEM_H -#include -#include + #include +#include #include -#include /* For convenience */ +#include class BMessage; class BWindow; -/*----------------------------------------------------------------*/ -/*----- BMenuItem class ------------------------------------------*/ class BMenuItem : public BArchivable, public BInvoker { -public: - BMenuItem( const char *label, - BMessage *message, - char shortcut = 0, - uint32 modifiers = 0); - BMenuItem(BMenu *menu, BMessage *message = NULL); - 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); + public: + BMenuItem(const char* label, BMessage* message, + char shortcut = 0, uint32 modifiers = 0); + BMenuItem(BMenu* menu, BMessage* message = NULL); + BMenuItem(BMessage* data); + virtual ~BMenuItem(); - const char *Label() const; - bool IsEnabled() const; - bool IsMarked() const; - char Trigger() const; - char Shortcut(uint32 *modifiers = NULL) const; - - BMenu *Submenu() const; - BMenu *Menu() const; - BRect Frame() const; + static BArchivable* Instantiate(BMessage* archive); + virtual status_t Archive(BMessage* archive, bool deep = true) 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); -virtual void TruncateLabel(float max, char *new_label); -virtual void DrawContent(); -virtual void Draw(); -virtual void Highlight(bool on); - bool IsSelected() const; - BPoint ContentLocation() const; + const char* Label() const; + bool IsEnabled() const; + bool IsMarked() const; + char Trigger() const; + char Shortcut(uint32* _modifiers = NULL) const; -/*----- Private or reserved -----------------------------------------*/ -private: -friend class BMenu; -friend class BPopUpMenu; -friend class BMenuBar; + BMenu* Submenu() const; + BMenu* Menu() const; + BRect Frame() const; -virtual void _ReservedMenuItem1(); -virtual void _ReservedMenuItem2(); -virtual void _ReservedMenuItem3(); -virtual void _ReservedMenuItem4(); + protected: + virtual void GetContentSize(float* _width, float* _height); + virtual void TruncateLabel(float maxWidth, char* newLabel); + virtual void DrawContent(); + virtual void Draw(); + virtual void Highlight(bool enabled); + bool IsSelected() const; + BPoint ContentLocation() const; - BMenuItem(const BMenuItem &); - BMenuItem &operator=(const BMenuItem &); + private: + friend class BMenu; + friend class BPopUpMenu; + friend class BMenuBar; - void InitData(); - void InitMenuData(BMenu *menu); - void Install(BWindow *window); + virtual void _ReservedMenuItem1(); + virtual void _ReservedMenuItem2(); + virtual void _ReservedMenuItem3(); + virtual void _ReservedMenuItem4(); -/*----- Protected function -----------------------------------------*/ -protected: -virtual status_t Invoke(BMessage *msg = NULL); + void Install(BWindow* window); + void Uninstall(); + void SetSuper(BMenu* superMenu); + void Select(bool select); + void SetAutomaticTrigger(char trigger); -/*----- Private or reserved -----------------------------------------*/ -private: - 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); + protected: + virtual status_t Invoke(BMessage *msg = NULL); - char *fLabel; - BMenu *fSubmenu; - BWindow *fWindow; - BMenu *fSuper; - BRect fBounds; - uint32 fModifiers; - float fCachedWidth; - int16 fTriggerIndex; - char fUserTrigger; - char fSysTrigger; - char fShortcutChar; - bool fMark; - bool fEnabled; - bool fSelected; + private: + BMenuItem(const BMenuItem& other); + BMenuItem& operator=(const BMenuItem& other); - 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]; }; -/*-------------------------------------------------------------*/ -/*-------------------------------------------------------------*/ - -// We moved BSeparatorItem's declaration to its own file, but for source -// compatibility we have to export that class from here too. +// BSeparatorItem now has its own declaration file, but for source +// compatibility we're exporting that class from here too. #include #endif /* _MENU_ITEM_H */ diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 68601fce2f..7f87d05e91 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1805,7 +1805,7 @@ BMenu::CalcTriggers() if (item->Trigger() == 0) { const char *newTrigger = ChooseTrigger(item->Label(), &triggersList); if (newTrigger != NULL) { - item->SetSysTrigger(*newTrigger); + item->SetAutomaticTrigger(*newTrigger); // TODO: This is crap. I'd prefer to have // BMenuItem::SetSysTrigger(const char *) update fTriggerIndex. // This isn't the case on beos, but it will probably be like that on haiku. diff --git a/src/kits/interface/MenuItem.cpp b/src/kits/interface/MenuItem.cpp index 7a8db2ed0a..6f53e46b72 100644 --- a/src/kits/interface/MenuItem.cpp +++ b/src/kits/interface/MenuItem.cpp @@ -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, uint32 modifiers) { - InitData(); + _InitData(); if (label != NULL) fLabel = strdup(label); @@ -106,15 +106,15 @@ BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut, BMenuItem::BMenuItem(BMenu *menu, BMessage *message) { - InitData(); + _InitData(); SetMessage(message); - InitMenuData(menu); + _InitMenuData(menu); } BMenuItem::BMenuItem(BMessage *data) { - InitData(); + _InitData(); if (data->HasString("_label")) { const char *string; @@ -163,7 +163,7 @@ BMenuItem::BMenuItem(BMessage *data) BMenu *menu = dynamic_cast(object); if (menu != NULL) - InitMenuData(menu); + _InitMenuData(menu); } } } @@ -174,8 +174,8 @@ BMenuItem::Instantiate(BMessage *data) { if (validate_instantiation(data, "BMenuItem")) return new BMenuItem(data); - else - return NULL; + + return NULL; } @@ -249,7 +249,7 @@ BMenuItem::SetEnabled(bool state) return; fEnabled = state; - + if (fSubmenu != NULL) fSubmenu->SetEnabled(state); @@ -272,14 +272,14 @@ BMenuItem::SetMarked(bool state) void -BMenuItem::SetTrigger(char ch) +BMenuItem::SetTrigger(char trigger) { - fUserTrigger = ch; + fUserTrigger = trigger; - if (strchr(fLabel, ch) != 0) - fSysTrigger = ch; + if (strchr(fLabel, trigger) != 0) + fAutomaticTrigger = trigger; else - fSysTrigger = -1; + fAutomaticTrigger = -1; if (fSuper != NULL) fSuper->InvalidateLayout(); @@ -482,13 +482,13 @@ BMenuItem::Draw() // draw extra symbols if (fSuper->Layout() == B_ITEMS_IN_COLUMN) { if (IsMarked()) - DrawMarkSymbol(bgColor); + _DrawMarkSymbol(bgColor); if (fShortcutChar) - DrawShortcutSymbol(); + _DrawShortcutSymbol(); if (Submenu()) - DrawSubmenuSymbol(bgColor); + _DrawSubmenuSymbol(bgColor); } } @@ -534,7 +534,7 @@ BMenuItem::operator=(const BMenuItem &) void -BMenuItem::InitData() +BMenuItem::_InitData() { fLabel = NULL; fSubmenu = NULL; @@ -544,7 +544,7 @@ BMenuItem::InitData() fCachedWidth = 0; fTriggerIndex = -1; fUserTrigger = 0; - fSysTrigger = 0; + fAutomaticTrigger = 0; fShortcutChar = 0; fMark = false; fEnabled = true; @@ -553,7 +553,7 @@ BMenuItem::InitData() void -BMenuItem::InitMenuData(BMenu *menu) +BMenuItem::_InitMenuData(BMenu *menu) { fSubmenu = menu; fSubmenu->fSuperitem = this; @@ -665,7 +665,7 @@ BMenuItem::Select(bool selected) void -BMenuItem::DrawMarkSymbol(rgb_color bgColor) +BMenuItem::_DrawMarkSymbol(rgb_color bgColor) { fSuper->PushState(); @@ -700,7 +700,7 @@ BMenuItem::DrawMarkSymbol(rgb_color bgColor) void -BMenuItem::DrawShortcutSymbol() +BMenuItem::_DrawShortcutSymbol() { // TODO: Review this BPoint where = ContentLocation(); @@ -760,7 +760,7 @@ BMenuItem::DrawShortcutSymbol() void -BMenuItem::DrawSubmenuSymbol(rgb_color bgColor) +BMenuItem::_DrawSubmenuSymbol(rgb_color bgColor) { fSuper->PushState(); @@ -821,7 +821,7 @@ BMenuItem::_DrawControlChar(char shortcut, BPoint where) void -BMenuItem::SetSysTrigger(char ch) +BMenuItem::SetAutomaticTrigger(char ch) { - fSysTrigger = ch; + fAutomaticTrigger = ch; }