2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "PathContainer.h"
16 #include "VectorPath.h"
19 PathContainerListener::PathContainerListener() {}
20 PathContainerListener::~PathContainerListener() {}
25 PathContainer::PathContainer(bool ownsPaths
)
35 PathContainer::~PathContainer()
38 int32 count
= fListeners
.CountItems();
40 debugger("~PathContainer() - there are still"
41 "listeners attached\n");
43 #endif // ICON_O_MATIC
51 PathContainer::AddPath(VectorPath
* path
)
53 return AddPath(path
, CountPaths());
58 PathContainer::AddPath(VectorPath
* path
, int32 index
)
63 // prevent adding the same path twice
67 if (fPaths
.AddItem((void*)path
, index
)) {
69 _NotifyPathAdded(path
, index
);
74 fprintf(stderr
, "PathContainer::AddPath() - out of memory!\n");
80 PathContainer::RemovePath(VectorPath
* path
)
82 if (fPaths
.RemoveItem((void*)path
)) {
84 _NotifyPathRemoved(path
);
94 PathContainer::RemovePath(int32 index
)
96 VectorPath
* path
= (VectorPath
*)fPaths
.RemoveItem(index
);
99 _NotifyPathRemoved(path
);
108 PathContainer::MakeEmpty()
117 PathContainer::CountPaths() const
119 return fPaths
.CountItems();
124 PathContainer::HasPath(VectorPath
* path
) const
126 return fPaths
.HasItem((void*)path
);
131 PathContainer::IndexOf(VectorPath
* path
) const
133 return fPaths
.IndexOf((void*)path
);
138 PathContainer::PathAt(int32 index
) const
140 return (VectorPath
*)fPaths
.ItemAt(index
);
145 PathContainer::PathAtFast(int32 index
) const
147 return (VectorPath
*)fPaths
.ItemAtFast(index
);
155 PathContainer::AddListener(PathContainerListener
* listener
)
157 if (listener
&& !fListeners
.HasItem((void*)listener
))
158 return fListeners
.AddItem(listener
);
164 PathContainer::RemoveListener(PathContainerListener
* listener
)
166 return fListeners
.RemoveItem(listener
);
168 #endif // ICON_O_MATIC
174 PathContainer::_MakeEmpty()
176 int32 count
= CountPaths();
177 for (int32 i
= 0; i
< count
; i
++) {
178 VectorPath
* path
= PathAtFast(i
);
180 _NotifyPathRemoved(path
);
182 path
->ReleaseReference();
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
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