xref: /haiku/headers/os/interface/MenuItem.h (revision 4afae676ad98b8f1e219f704dfc9c8507bce106e)
1 /*******************************************************************************
2 /
3 /	File:			MenuItem.h
4 /
5 /   Description:    BMenuItem represents a single item in a BMenu.
6 /                   BSeparatorItem is a cosmetic menu item that demarcates
7 /                   groups of other items.
8 /
9 /	Copyright 1994-98, Be Incorporated, All Rights Reserved
10 /
11 *******************************************************************************/
12 
13 #ifndef _MENU_ITEM_H
14 #define _MENU_ITEM_H
15 
16 #include <BeBuild.h>
17 #include <InterfaceDefs.h>
18 #include <Archivable.h>
19 #include <Invoker.h>
20 #include <Menu.h>			/* For convenience */
21 
22 class BMessage;
23 class BWindow;
24 
25 /*----------------------------------------------------------------*/
26 /*----- BMenuItem class ------------------------------------------*/
27 
28 class BMenuItem : public BArchivable, public BInvoker {
29 public:
30 						BMenuItem(	const char *label,
31 									BMessage *message,
32 									char shortcut = 0,
33 									uint32 modifiers = 0);
34 						BMenuItem(BMenu *menu, BMessage *message = NULL);
35 						BMenuItem(BMessage *data);
36 virtual					~BMenuItem();
37 static	BArchivable		*Instantiate(BMessage *data);
38 virtual	status_t		Archive(BMessage *data, bool deep = true) const;
39 
40 virtual	void			SetLabel(const char *name);
41 virtual	void			SetEnabled(bool state);
42 virtual	void			SetMarked(bool state);
43 virtual void			SetTrigger(char ch);
44 virtual void			SetShortcut(char ch, uint32 modifiers);
45 
46 		const char		*Label() const;
47 		bool			IsEnabled() const;
48 		bool			IsMarked() const;
49 		char			Trigger() const;
50 		char			Shortcut(uint32 *modifiers = NULL) const;
51 
52 		BMenu			*Submenu() const;
53 		BMenu			*Menu() const;
54 		BRect			Frame() const;
55 
56 protected:
57 
58 virtual	void			GetContentSize(float *width, float *height);
59 virtual	void			TruncateLabel(float max, char *new_label);
60 virtual	void			DrawContent();
61 virtual	void			Draw();
62 virtual	void			Highlight(bool on);
63 		bool			IsSelected() const;
64 		BPoint			ContentLocation() const;
65 
66 /*----- Private or reserved -----------------------------------------*/
67 private:
68 friend	BMenu;
69 friend	BPopUpMenu;
70 friend	BMenuBar;
71 
72 virtual	void		_ReservedMenuItem1();
73 virtual	void		_ReservedMenuItem2();
74 virtual	void		_ReservedMenuItem3();
75 virtual	void		_ReservedMenuItem4();
76 
77 					BMenuItem(const BMenuItem &);
78 		BMenuItem	&operator=(const BMenuItem &);
79 
80 		void		InitData();
81 		void		InitMenuData(BMenu *menu);
82 		void		Install(BWindow *window);
83 
84 /*----- Protected function -----------------------------------------*/
85 protected:
86 virtual	status_t	Invoke(BMessage *msg = NULL);
87 
88 /*----- Private or reserved -----------------------------------------*/
89 private:
90 		void		Uninstall();
91 		void		SetSuper(BMenu *super);
92 		void		Select(bool on);
93 		void		DrawMarkSymbol();
94 		void		DrawShortcutSymbol();
95 		void		DrawSubmenuSymbol();
96 		void		DrawControlChar(const char *control);
97 		void		SetSysTrigger(char ch);
98 
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		fSysTrigger;
109 		char		fShortcutChar;
110 		bool		fMark;
111 		bool		fEnabled;
112 		bool		fSelected;
113 
114 		uint32		_reserved[4];
115 };
116 
117 /*----------------------------------------------------------------*/
118 /*----- BSeparatorItem class -------------------------------------*/
119 
120 class BSeparatorItem : public BMenuItem
121 {
122 public:
123 						BSeparatorItem();
124 						BSeparatorItem(BMessage *data);
125 virtual					~BSeparatorItem();
126 virtual	status_t		Archive(BMessage *data, bool deep = true) const;
127 static	BArchivable		*Instantiate(BMessage *data);
128 virtual	void			SetEnabled(bool state);
129 
130 protected:
131 
132 virtual	void			GetContentSize(float *width, float *height);
133 virtual	void			Draw();
134 
135 /*----- Private or reserved -----------------------------------------*/
136 private:
137 virtual	void		_ReservedSeparatorItem1();
138 virtual	void		_ReservedSeparatorItem2();
139 
140 		BSeparatorItem	&operator=(const BSeparatorItem &);
141 
142 		uint32		_reserved[1];
143 };
144 
145 /*-------------------------------------------------------------*/
146 /*-------------------------------------------------------------*/
147 
148 #endif /* _MENU_ITEM_H */
149