1 /* 2 * Copyright 2006-2007, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _MENU_ITEM_H 6 #define _MENU_ITEM_H 7 8 9 #include <Archivable.h> 10 #include <InterfaceDefs.h> 11 #include <Invoker.h> 12 #include <Menu.h> 13 14 class BMessage; 15 class BWindow; 16 17 18 class BMenuItem : public BArchivable, public BInvoker { 19 public: 20 BMenuItem(const char* label, BMessage* message, 21 char shortcut = 0, uint32 modifiers = 0); 22 BMenuItem(BMenu* menu, 23 BMessage* message = NULL); 24 BMenuItem(BMessage* data); 25 virtual ~BMenuItem(); 26 27 static BArchivable* Instantiate(BMessage* archive); 28 virtual status_t Archive(BMessage* archive, 29 bool deep = true) const; 30 31 virtual void SetLabel(const char* name); 32 virtual void SetEnabled(bool enable); 33 virtual void SetMarked(bool mark); 34 virtual void SetTrigger(char trigger); 35 virtual void SetShortcut(char shortcut, uint32 modifiers); 36 37 const char* Label() const; 38 bool IsEnabled() const; 39 bool IsMarked() const; 40 char Trigger() const; 41 char Shortcut(uint32* _modifiers = NULL) const; 42 43 BMenu* Submenu() const; 44 BMenu* Menu() const; 45 BRect Frame() const; 46 47 protected: 48 virtual void GetContentSize(float* _width, float* _height); 49 virtual void TruncateLabel(float maxWidth, char* newLabel); 50 virtual void DrawContent(); 51 virtual void Draw(); 52 virtual void Highlight(bool highlight); 53 bool IsSelected() const; 54 BPoint ContentLocation() const; 55 56 private: 57 friend class BMenu; 58 friend class BPopUpMenu; 59 friend class BMenuBar; 60 61 virtual void _ReservedMenuItem1(); 62 virtual void _ReservedMenuItem2(); 63 virtual void _ReservedMenuItem3(); 64 virtual void _ReservedMenuItem4(); 65 66 void Install(BWindow* window); 67 void Uninstall(); 68 void SetSuper(BMenu* superMenu); 69 void Select(bool select); 70 void SetAutomaticTrigger(int32 index, 71 uint32 trigger); 72 73 protected: 74 virtual status_t Invoke(BMessage* message = NULL); 75 76 private: 77 BMenuItem(const BMenuItem& other); 78 BMenuItem& operator=(const BMenuItem& other); 79 80 void _InitData(); 81 void _InitMenuData(BMenu* menu); 82 83 void _DrawMarkSymbol(); 84 void _DrawShortcutSymbol(); 85 void _DrawSubmenuSymbol(); 86 void _DrawControlChar(char shortcut, BPoint where); 87 88 private: 89 char* fLabel; 90 BMenu* fSubmenu; 91 BWindow* fWindow; 92 BMenu* fSuper; 93 BRect fBounds; 94 uint32 fModifiers; 95 float fCachedWidth; 96 int16 fTriggerIndex; 97 char fUserTrigger; 98 char fShortcutChar; 99 bool fMark; 100 bool fEnabled; 101 bool fSelected; 102 uint32 fTrigger; 103 104 uint32 _reserved[3]; 105 }; 106 107 // BSeparatorItem now has its own declaration file, but for source 108 // compatibility we're exporting that class from here too. 109 #include <SeparatorItem.h> 110 111 #endif // _MENU_ITEM_H 112