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;
152 priv->iconBasePath = basePath;
158 return priv->iconBasePath;
166 if ( ! iconName.empty() )
168 if ( iconName[0] ==
'/' )
171 if ( priv->iconBasePath.empty() ||
172 priv->iconBasePath[0] !=
'/' )
174 return YUI::yApp()->
iconLoader()->findIcon( iconName );
177 fullPath += priv->iconBasePath +
"/" + iconName;
195 YUI_CHECK_PTR( item );
199 YUI_THROW(
YUIException(
"Item already owned by parent item -"
200 " call addItem() only for toplevel items!" ) );
205 priv->itemCollection.push_back( item );
206 item->
setIndex( priv->itemCollection.size() - 1 );
214 if ( priv->enforceSingleSelection )
216 YItem * newItemSelected = 0;
220 newItemSelected = item;
228 if ( newItemSelected )
241 if ( priv->enforceInitialSelection )
248 if ( priv->itemCollection.size() == 1 )
256 const string & iconName,
259 YItem * item =
new YItem( itemLabel, iconName, selected );
260 YUI_CHECK_NEW( item );
267 addItem( itemLabel,
"", selected );
274 priv->itemCollection.reserve( priv->itemCollection.size() + itemCollection.size() );
277 it != itemCollection.end();
292 return priv->itemCollection.begin();
298 return priv->itemCollection.begin();
305 return priv->itemCollection.end();
312 return priv->itemCollection.end();
318 return ! priv->itemCollection.empty();
324 return priv->itemCollection.size();
331 if ( priv->itemCollection.empty() )
334 return priv->itemCollection.front();
341 if ( index < 0 || index >= (
int) priv->itemCollection.size() )
344 return priv->itemCollection[ index ];
361 const YItem * item = *it;
423 YUI_CHECK_PTR( item );
426 YUI_THROW(
YUIException(
"Item does not belong to this widget" ) );
428 if ( priv->enforceSingleSelection && selected )
432 if ( oldSelectedItem )
471 const YItem * item = *it;
473 if ( item == wantedItem )
528 if ( item->
label() == wantedItemLabel )
547 yuiMilestone() <<
"Items:" << endl;
553 switch ( (*it)->status() )
555 case 0: status =
"[ ]";
break;
556 case 1: status =
"[x]";
break;
560 sprintf( buffer,
"[%d]", (*it)->status() );
565 yuiMilestone() <<
" " << status <<
" "
570 yuiMilestone() <<
"---" << endl;
std::string label() const
Return this item's label.
void setIndex(int index)
Set this item's index.
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
virtual YItemIterator childrenBegin()
Return an iterator that points to the first child item of this item.
bool selected() const
Return 'true' if this item is currently selected.
std::string iconName() const
Return this item's icon name.
YIconLoader * iconLoader()
Return the icon loader.
virtual YItem * parent() const
Return 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.
Helper class that calls startMultipleChanges() in its constructor and cares about the necessary call ...
virtual YItemIterator childrenEnd()
Return an iterator that points after the last child item of this item.
Base class for UI Exceptions.
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.