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