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