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