Make UEFI boot-platform build again
[haiku.git] / src / libs / icon / shape / PathContainer.cpp
blobb9b9fcfa7cfa1b4a5ddd99f1caa507eff7295641
1 /*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "PathContainer.h"
11 #include <stdio.h>
12 #include <string.h>
14 #include <OS.h>
16 #include "VectorPath.h"
18 #ifdef ICON_O_MATIC
19 PathContainerListener::PathContainerListener() {}
20 PathContainerListener::~PathContainerListener() {}
21 #endif
24 // constructor
25 PathContainer::PathContainer(bool ownsPaths)
26 : fPaths(16),
27 fOwnsPaths(ownsPaths)
28 #ifdef ICON_O_MATIC
29 , fListeners(2)
30 #endif
34 // destructor
35 PathContainer::~PathContainer()
37 #ifdef ICON_O_MATIC
38 int32 count = fListeners.CountItems();
39 if (count > 0) {
40 debugger("~PathContainer() - there are still"
41 "listeners attached\n");
43 #endif // ICON_O_MATIC
44 _MakeEmpty();
47 // #pragma mark -
49 // AddPath
50 bool
51 PathContainer::AddPath(VectorPath* path)
53 return AddPath(path, CountPaths());
56 // AddPath
57 bool
58 PathContainer::AddPath(VectorPath* path, int32 index)
60 if (!path)
61 return false;
63 // prevent adding the same path twice
64 if (HasPath(path))
65 return false;
67 if (fPaths.AddItem((void*)path, index)) {
68 #ifdef ICON_O_MATIC
69 _NotifyPathAdded(path, index);
70 #endif
71 return true;
74 fprintf(stderr, "PathContainer::AddPath() - out of memory!\n");
75 return false;
78 // RemovePath
79 bool
80 PathContainer::RemovePath(VectorPath* path)
82 if (fPaths.RemoveItem((void*)path)) {
83 #ifdef ICON_O_MATIC
84 _NotifyPathRemoved(path);
85 #endif
86 return true;
89 return false;
92 // RemovePath
93 VectorPath*
94 PathContainer::RemovePath(int32 index)
96 VectorPath* path = (VectorPath*)fPaths.RemoveItem(index);
97 #ifdef ICON_O_MATIC
98 if (path) {
99 _NotifyPathRemoved(path);
101 #endif
103 return path;
106 // MakeEmpty
107 void
108 PathContainer::MakeEmpty()
110 _MakeEmpty();
113 // #pragma mark -
115 // CountPaths
116 int32
117 PathContainer::CountPaths() const
119 return fPaths.CountItems();
122 // HasPath
123 bool
124 PathContainer::HasPath(VectorPath* path) const
126 return fPaths.HasItem((void*)path);
129 // IndexOf
130 int32
131 PathContainer::IndexOf(VectorPath* path) const
133 return fPaths.IndexOf((void*)path);
136 // PathAt
137 VectorPath*
138 PathContainer::PathAt(int32 index) const
140 return (VectorPath*)fPaths.ItemAt(index);
143 // PathAtFast
144 VectorPath*
145 PathContainer::PathAtFast(int32 index) const
147 return (VectorPath*)fPaths.ItemAtFast(index);
150 // #pragma mark -
152 #ifdef ICON_O_MATIC
153 // AddListener
154 bool
155 PathContainer::AddListener(PathContainerListener* listener)
157 if (listener && !fListeners.HasItem((void*)listener))
158 return fListeners.AddItem(listener);
159 return false;
162 // RemoveListener
163 bool
164 PathContainer::RemoveListener(PathContainerListener* listener)
166 return fListeners.RemoveItem(listener);
168 #endif // ICON_O_MATIC
170 // #pragma mark -
172 // _MakeEmpty
173 void
174 PathContainer::_MakeEmpty()
176 int32 count = CountPaths();
177 for (int32 i = 0; i < count; i++) {
178 VectorPath* path = PathAtFast(i);
179 #ifdef ICON_O_MATIC
180 _NotifyPathRemoved(path);
181 if (fOwnsPaths)
182 path->ReleaseReference();
183 #else
184 if (fOwnsPaths)
185 delete path;
186 #endif
188 fPaths.MakeEmpty();
191 // #pragma mark -
193 #ifdef ICON_O_MATIC
194 // _NotifyPathAdded
195 void
196 PathContainer::_NotifyPathAdded(VectorPath* path, int32 index) const
198 BList listeners(fListeners);
199 int32 count = listeners.CountItems();
200 for (int32 i = 0; i < count; i++) {
201 PathContainerListener* listener
202 = (PathContainerListener*)listeners.ItemAtFast(i);
203 listener->PathAdded(path, index);
207 // _NotifyPathRemoved
208 void
209 PathContainer::_NotifyPathRemoved(VectorPath* path) const
211 BList listeners(fListeners);
212 int32 count = listeners.CountItems();
213 for (int32 i = 0; i < count; i++) {
214 PathContainerListener* listener
215 = (PathContainerListener*)listeners.ItemAtFast(i);
216 listener->PathRemoved(path);
219 #endif // ICON_O_MATIC