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;
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 )
191 YItem* newItemSelected = NULL;
194 newItemSelected = item;
202 if ( newItemSelected )
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() );
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 ];
331 const YItem * item = *it;
373 selectedItems.push_back( item );
393 YUI_CHECK_PTR( item );
396 YUI_THROW(
YUIException(
"Item does not belong to this widget" ) );
398 if ( priv->enforceSingleSelection && selected )
402 if ( oldSelectedItem )
435 const YItem * item = *it;
437 if ( item == wantedItem )
492 if ( item->
label() == wantedItemLabel )
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
std::string label() const
Return this item's label.
bool selected() const
Return 'true' if this item is currently selected.
void setIndex(int index)
Set this item's index.
virtual YItemIterator childrenBegin()
Return an iterator that points to the first child item of this item.
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
std::string iconName() const
Return this item's icon name.
virtual bool hasChildren() const
Return 'true' if this item has any child items.
void setSelected(bool sel=true)
Select or unselect this item.
virtual YItem * parent() const
Returns this item's parent item or 0 if it is a toplevel item.
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
virtual YItemIterator childrenEnd()
Return an iterator that points after the last child item of this item.
Base class for UI Exceptions.