2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "StyleContainer.h"
19 StyleContainerListener::StyleContainerListener() {}
20 StyleContainerListener::~StyleContainerListener() {}
24 StyleContainer::StyleContainer()
35 StyleContainer::~StyleContainer()
38 int32 count
= fListeners
.CountItems();
40 debugger("~StyleContainer() - there are still"
41 "listeners attached\n");
43 #endif // ICON_O_MATIC
51 StyleContainer::AddStyle(Style
* style
)
53 return AddStyle(style
, CountStyles());
58 StyleContainer::AddStyle(Style
* style
, int32 index
)
63 // prevent adding the same style twice
67 if (fStyles
.AddItem((void*)style
, index
)) {
69 _NotifyStyleAdded(style
, index
);
74 fprintf(stderr
, "StyleContainer::AddStyle() - out of memory!\n");
80 StyleContainer::RemoveStyle(Style
* style
)
82 if (fStyles
.RemoveItem((void*)style
)) {
84 _NotifyStyleRemoved(style
);
94 StyleContainer::RemoveStyle(int32 index
)
96 Style
* style
= (Style
*)fStyles
.RemoveItem(index
);
99 _NotifyStyleRemoved(style
);
108 StyleContainer::MakeEmpty()
117 StyleContainer::CountStyles() const
119 return fStyles
.CountItems();
124 StyleContainer::HasStyle(Style
* style
) const
126 return fStyles
.HasItem((void*)style
);
131 StyleContainer::IndexOf(Style
* style
) const
133 return fStyles
.IndexOf((void*)style
);
138 StyleContainer::StyleAt(int32 index
) const
140 return (Style
*)fStyles
.ItemAt(index
);
145 StyleContainer::StyleAtFast(int32 index
) const
147 return (Style
*)fStyles
.ItemAtFast(index
);
156 StyleContainer::AddListener(StyleContainerListener
* listener
)
158 if (listener
&& !fListeners
.HasItem((void*)listener
))
159 return fListeners
.AddItem(listener
);
165 StyleContainer::RemoveListener(StyleContainerListener
* listener
)
167 return fListeners
.RemoveItem(listener
);
170 #endif // ICON_O_MATIC
176 StyleContainer::_MakeEmpty()
178 int32 count
= CountStyles();
179 for (int32 i
= 0; i
< count
; i
++) {
180 Style
* style
= StyleAtFast(i
);
182 _NotifyStyleRemoved(style
);
183 style
->ReleaseReference();
197 StyleContainer::_NotifyStyleAdded(Style
* style
, int32 index
) const
199 BList
listeners(fListeners
);
200 int32 count
= listeners
.CountItems();
201 for (int32 i
= 0; i
< count
; i
++) {
202 StyleContainerListener
* listener
203 = (StyleContainerListener
*)listeners
.ItemAtFast(i
);
204 listener
->StyleAdded(style
, index
);
208 // _NotifyStyleRemoved
210 StyleContainer::_NotifyStyleRemoved(Style
* style
) const
212 BList
listeners(fListeners
);
213 int32 count
= listeners
.CountItems();
214 for (int32 i
= 0; i
< count
; i
++) {
215 StyleContainerListener
* listener
216 = (StyleContainerListener
*)listeners
.ItemAtFast(i
);
217 listener
->StyleRemoved(style
);
221 #endif // ICON_O_MATIC