26 #define YUILogComponent "ui"
30 #include "YSelectionWidget.h"
31 #include "YUIException.h"
32 #include "YApplication.h"
38 bool enforceSingleSelection,
39 bool recursiveSelection )
41 , enforceSingleSelection( enforceSingleSelection )
42 , recursiveSelection ( recursiveSelection )
46 bool enforceSingleSelection;
47 bool recursiveSelection;
48 std::string iconBasePath;
49 YItemCollection itemCollection;
56 const std::string & label,
57 bool enforceSingleSelection ,
58 bool recursiveSelection )
62 YUI_CHECK_NEW( priv );
64 if ( enforceSingleSelection && recursiveSelection )
65 YUI_THROW(
YUIException(
"recursiveSelection is only available for multiSelection Widgets."));
91 priv->itemCollection.clear();
103 priv->label = newLabel;
109 return priv->enforceSingleSelection;
114 return priv->recursiveSelection;
127 priv->iconBasePath = basePath;
133 return priv->iconBasePath;
139 std::string fullPath;
141 if ( ! iconName.empty() )
143 if ( iconName[0] ==
'/' )
146 if ( priv->iconBasePath.empty() ||
147 priv->iconBasePath[0] !=
'/' )
149 return YUI::yApp()->iconLoader()->findIcon( iconName );
152 fullPath += priv->iconBasePath +
"/" + iconName;
170 YUI_CHECK_PTR( item );
174 YUI_THROW(
YUIException(
"Item already owned by parent item -"
175 " call addItem() only for toplevel items!" ) );
180 priv->itemCollection.push_back( item );
181 item->
setIndex( priv->itemCollection.size() - 1 );
189 if ( priv->enforceSingleSelection )
206 if ( oldSelectedItem && oldSelectedItem != item )
219 if ( priv->itemCollection.size() == 1 )
226 const std::string & iconName,
229 YItem * item =
new YItem( itemLabel, iconName, selected );
230 YUI_CHECK_NEW( item );
237 addItem( itemLabel,
"", selected );
244 priv->itemCollection.reserve( priv->itemCollection.size() + itemCollection.size() );
246 for ( YItemConstIterator it = itemCollection.begin();
247 it != itemCollection.end();
262 return priv->itemCollection.begin();
268 return priv->itemCollection.begin();
275 return priv->itemCollection.end();
282 return priv->itemCollection.end();
288 return ! priv->itemCollection.empty();
294 return priv->itemCollection.size();
301 if ( priv->itemCollection.empty() )
304 return priv->itemCollection.front();
311 if ( index < 0 || index >= (
int) priv->itemCollection.size() )
314 return priv->itemCollection[ index ];
327 YItemConstIterator end )
329 for ( YItemConstIterator it = begin; it != end; ++it )
331 const YItem * item = *it;
364 YItemConstIterator begin,
365 YItemConstIterator end )
367 for ( YItemConstIterator it = begin; it != end; ++it )
372 selectedItems.push_back( item );
392 YUI_CHECK_PTR( item );
395 YUI_THROW(
YUIException(
"Item does not belong to this widget" ) );
397 if ( priv->enforceSingleSelection && selected )
401 if ( oldSelectedItem )
429 YItemConstIterator begin,
430 YItemConstIterator end )
const
432 for ( YItemConstIterator it = begin; it != end; ++it )
434 const YItem * item = *it;
436 if ( item == wantedItem )
463 for ( YItemConstIterator it = begin; it != end; ++it )
484 YItemConstIterator begin,
485 YItemConstIterator end )
const
487 for ( YItemConstIterator it = begin; it != end; ++it )
491 if ( item->
label() == wantedItemLabel )