xref: /haiku/src/apps/debuganalyzer/gui/SubWindowManager.h (revision 7749d0bb0c358a3279b1b9cc76d8376e900130a5)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef SUB_WINDOW_MANAGER_H
6 #define SUB_WINDOW_MANAGER_H
7 
8 #include <Locker.h>
9 
10 #include <Referenceable.h>
11 
12 #include <util/OpenHashTable.h>
13 
14 #include "SubWindow.h"
15 
16 
17 class SubWindowManager : public BReferenceable, public BLocker {
18 public:
19 								SubWindowManager(BLooper* parent);
20 	virtual						~SubWindowManager();
21 
22 			status_t			Init();
23 
24 			bool				AddSubWindow(SubWindow* window);
25 			bool				RemoveSubWindow(SubWindow* window);
26 			SubWindow*			LookupSubWindow(const SubWindowKey& key) const;
27 
28 			void				Broadcast(uint32 messageCode);
29 			void				Broadcast(BMessage* message);
30 
31 private:
32 			struct HashDefinition {
33 				typedef SubWindowKey	KeyType;
34 				typedef	SubWindow		ValueType;
35 
36 				size_t HashKey(const SubWindowKey& key) const
37 				{
38 					return key.HashCode();
39 				}
40 
41 				size_t Hash(const SubWindow* value) const
42 				{
43 					return value->GetSubWindowKey()->HashCode();
44 				}
45 
46 				bool Compare(const SubWindowKey& key,
47 					const SubWindow* value) const
48 				{
49 					return key.Equals(value->GetSubWindowKey());
50 				}
51 
52 				SubWindow*& GetLink(SubWindow* value) const
53 				{
54 					return value->fNext;
55 				}
56 			};
57 
58 			typedef BOpenHashTable<HashDefinition> SubWindowTable;
59 
60 private:
61 			BLooper*			fParent;
62 			SubWindowTable		fSubWindows;
63 };
64 
65 
66 #endif	// SUB_WINDOW_MANAGER_H
67