xref: /haiku/src/kits/tracker/GroupedMenu.h (revision 25a7b01d15612846f332751841da3579db313082)
1 #ifndef GROUPED_MENU_H
2 #define GROUPED_MENU_H
3 
4 
5 #include <Menu.h>
6 #include <MenuItem.h>
7 #include <List.h>
8 
9 
10 namespace BPrivate {
11 
12 class TGroupedMenu;
13 
14 class TMenuItemGroup {
15 	public:
16 		TMenuItemGroup(const char* name);
17 		~TMenuItemGroup();
18 
19 		bool AddItem(BMenuItem* item);
20 		bool AddItem(BMenuItem* item, int32 atIndex);
21 		bool AddItem(BMenu* menu);
22 		bool AddItem(BMenu* menu, int32 atIndex);
23 
24 		bool RemoveItem(BMenuItem* item);
25 		bool RemoveItem(BMenu* menu);
26 		BMenuItem* RemoveItem(int32 index);
27 
28 		BMenuItem* ItemAt(int32 index);
29 		int32 CountItems();
30 
31 	private:
32 		friend class TGroupedMenu;
33 		void Separated(bool separated);
34 		bool HasSeparator();
35 
36 	private:
37 		const char*		fName;
38 		BList			fList;
39 		TGroupedMenu*	fMenu;
40 		int32			fFirstItemIndex;
41 		int32			fItemsTotal;
42 		bool			fHasSeparator;
43 };
44 
45 
46 class TGroupedMenu : public BMenu {
47 	public:
48 		TGroupedMenu(const char* name);
49 		~TGroupedMenu();
50 
51 		bool AddGroup(TMenuItemGroup* group);
52 		bool AddGroup(TMenuItemGroup* group, int32 atIndex);
53 
54 		bool RemoveGroup(TMenuItemGroup* group);
55 
56 		TMenuItemGroup* GroupAt(int32 index);
57 		int32 CountGroups();
58 
59 	private:
60 		friend class TMenuItemGroup;
61 		void AddGroupItem(TMenuItemGroup* group, BMenuItem* item,
62 			int32 atIndex);
63 		void RemoveGroupItem(TMenuItemGroup* group, BMenuItem* item);
64 
65 	private:
66 		BList	fGroups;
67 };
68 
69 }	// namespace BPrivate
70 
71 #endif	// GROUPED_MENU_H
72