xref: /haiku/headers/os/interface/MenuItem.h (revision aff60bb217827097c13d643275fdf1f1c66e7f17)
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 class BMenu;
69 friend class BPopUpMenu;
70 friend class 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 /*-------------------------------------------------------------*/
119 
120 // We moved BSeparatorItem's declaration to its own file, but for source
121 // compatibility we have to export that class from here too.
122 #include <SeparatorItem.h>
123 
124 #endif /* _MENU_ITEM_H */
125