xref: /haiku/src/apps/debuganalyzer/gui/SubWindowManager.cpp (revision 83b1a68c52ba3e0e8796282759f694b7fdddf06d)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "SubWindowManager.h"
7 
8 #include <new>
9 
10 #include <Message.h>
11 
12 #include <AutoLocker.h>
13 
14 
15 SubWindowManager::SubWindowManager(BLooper* parent)
16 	:
17 	fParent(parent),
18 	fSubWindows()
19 {
20 }
21 
22 
23 SubWindowManager::~SubWindowManager()
24 {
25 }
26 
27 
28 status_t
29 SubWindowManager::Init()
30 {
31 	return fSubWindows.Init();
32 }
33 
34 
35 bool
36 SubWindowManager::AddSubWindow(SubWindow* window)
37 {
38 	AutoLocker<SubWindowManager> locker(this);
39 
40 	if (fSubWindows.Lookup(*window->GetSubWindowKey()) != NULL)
41 		return false;
42 
43 	fSubWindows.Insert(window);
44 
45 	return true;
46 }
47 
48 
49 bool
50 SubWindowManager::RemoveSubWindow(SubWindow* window)
51 {
52 	AutoLocker<SubWindowManager> locker(this);
53 
54 	return fSubWindows.Remove(window);
55 }
56 
57 
58 SubWindow*
59 SubWindowManager::LookupSubWindow(const SubWindowKey& key) const
60 {
61 	return fSubWindows.Lookup(key);
62 }
63 
64 
65 void
66 SubWindowManager::Broadcast(uint32 messageCode)
67 {
68 	BMessage message(messageCode);
69 	Broadcast(&message);
70 }
71 
72 
73 void
74 SubWindowManager::Broadcast(BMessage* message)
75 {
76 	AutoLocker<SubWindowManager> locker(this);
77 
78 	SubWindowTable::Iterator it = fSubWindows.GetIterator();
79 	while (SubWindow* window = it.Next())
80 		window->PostMessage(message);
81 }
82