26 #define YUILogComponent "ui"
30 #include "YSelectionWidget.h"
31 #include "YUIException.h"
32 #include "YApplication.h"
40 bool enforceSingleSelection,
41 bool recursiveSelection )
43 , enforceSingleSelection( enforceSingleSelection )
44 , enforceInitialSelection(
true )
45 , recursiveSelection ( recursiveSelection )
49 bool enforceSingleSelection;
50 bool enforceInitialSelection;
51 bool recursiveSelection;
61 bool enforceSingleSelection ,
62 bool recursiveSelection )
66 YUI_CHECK_NEW( priv );
69 YUI_THROW(
YUIException(
"recursiveSelection is only available for multiSelection Widgets."));
95 priv->itemCollection.clear();
107 priv->label = newLabel;
113 return priv->enforceSingleSelection;
119 if ( priv->enforceSingleSelection )
120 priv->enforceInitialSelection = newVal;
126 return priv->enforceInitialSelection && priv->enforceSingleSelection;
132 return priv->recursiveSelection;
145 priv->iconBasePath = basePath;
151 return priv->iconBasePath;
159 if ( ! iconName.empty() )
161 if ( iconName[0] ==
'/' )
164 if ( priv->iconBasePath.empty() ||
165 priv->iconBasePath[0] !=
'/' )
167 return YUI::yApp()->iconLoader()->findIcon( iconName );
170 fullPath += priv->iconBasePath +
"/" + iconName;
188 YUI_CHECK_PTR( item );
192 YUI_THROW(
YUIException(
"Item already owned by parent item -"
193 " call addItem() only for toplevel items!" ) );
198 priv->itemCollection.push_back( item );
199 item->
setIndex( priv->itemCollection.size() - 1 );
207 if ( priv->enforceSingleSelection )
209 YItem * newItemSelected = 0;
213 newItemSelected = item;
221 if ( newItemSelected )
234 if ( priv->enforceInitialSelection )
241 if ( priv->itemCollection.size() == 1 )
249 const string & iconName,
252 YItem * item =
new YItem( itemLabel, iconName, selected );
253 YUI_CHECK_NEW( item );
260 addItem( itemLabel,
"", selected );
267 priv->itemCollection.reserve( priv->itemCollection.size() + itemCollection.size() );
270 it != itemCollection.end();
285 return priv->itemCollection.begin();
291 return priv->itemCollection.begin();
298 return priv->itemCollection.end();
305 return priv->itemCollection.end();
311 return ! priv->itemCollection.empty();
317 return priv->itemCollection.size();
324 if ( priv->itemCollection.empty() )
327 return priv->itemCollection.front();
334 if ( index < 0 || index >= (
int) priv->itemCollection.size() )
337 return priv->itemCollection[ index ];
354 const YItem * item = *it;
416 YUI_CHECK_PTR( item );
419 YUI_THROW(
YUIException(
"Item does not belong to this widget" ) );
421 if ( priv->enforceSingleSelection && selected )
425 if ( oldSelectedItem )
464 const YItem * item = *it;
466 if ( item == wantedItem )
521 if ( item->
label() == wantedItemLabel )
540 yuiMilestone() <<
"Items:" << endl;
546 switch ( (*it)->status() )
548 case 0: status =
"[ ]";
break;
549 case 1: status =
"[x]";
break;
553 sprintf( buffer,
"[%d]", (*it)->status() );
558 yuiMilestone() <<
" " << status <<
" "
563 yuiMilestone() <<
"---" << endl;
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
Helper class that calls startMultipleChanges() in its constructor and cares about the necessary call ...
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
std::string label() const
Return this item's label.
bool selected() const
Return 'true' if this item is currently selected.
virtual YItemIterator childrenBegin()
Return an iterator that points to the first child item of this item.
virtual YItem * parent() const
Returns this item's parent item or 0 if it is a toplevel item.
virtual bool hasChildren() const
Return 'true' if this item has any child items.
void setSelected(bool sel=true)
Select or unselect this item.
void setIndex(int index)
Set this item's index.
virtual YItemIterator childrenEnd()
Return an iterator that points after the last child item of this item.
std::string iconName() const
Return this item's icon name.
Base class for UI Exceptions.