libyui

/data/gitorious.org/libyui/libyui-master/src/YItem.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                        (C) SuSE GmbH |
00032 \----------------------------------------------------------------------/
00033 
00034   File:         YItem.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 #ifndef YItem_h
00041 #define YItem_h
00042 
00043 #include <string>
00044 #include <vector>
00045 
00046 using std::string;
00047 using std::vector;
00048 
00049 class YItem;
00050 
00051 typedef vector<YItem *>                         YItemCollection;
00052 typedef YItemCollection::iterator               YItemIterator;
00053 typedef YItemCollection::const_iterator         YItemConstIterator;
00054 
00055 
00060 class YItem
00061 {
00062 public:
00066     YItem( const string & label, bool selected = false )
00067         : _label( label )
00068         , _selected( selected )
00069         , _index( -1 )
00070         , _data( 0 )
00071         {}
00072 
00076     YItem( const string & label, const string & iconName, bool selected = false )
00077         : _label( label )
00078         , _iconName( iconName )
00079         , _selected( selected )
00080         , _index( -1 )
00081         , _data( 0 )
00082         {}
00083 
00087     virtual ~YItem() {}
00088 
00093     string label() const { return _label; }
00094 
00098     void setLabel( const string & newLabel ) { _label = newLabel; }
00099 
00103     string iconName() const { return _iconName; }
00104 
00108     bool hasIconName() const { return ! _iconName.empty(); }
00109 
00113     void setIconName( const string & newIconName ) { _iconName = newIconName; }
00114 
00118     bool selected() const { return _selected; }
00119 
00125     void setSelected( bool sel = true ) { _selected = sel; }
00126 
00130     void setIndex( int index ) { _index = index; }
00131 
00135     int index() const { return _index; }
00136 
00145     void setData( void * newData ) { _data = newData; }
00146 
00150     void * data() const { return _data; }
00151 
00152     //
00153     // Children management stubs.
00154     //
00155     // Derived classes that can handle child items should reimplement those
00156     // functions.  
00157     // The following default implementations don't do anything with children;
00158     // they act as if this item didn't have any children.
00159     //
00160 
00164     virtual bool hasChildren() const { return false; }
00165 
00183     virtual YItemIterator       childrenBegin()         { return _noChildren.end(); }
00184     virtual YItemConstIterator  childrenBegin() const   { return _noChildren.end(); }
00185 
00192     virtual YItemIterator       childrenEnd()           { return _noChildren.end(); }
00193     virtual YItemConstIterator  childrenEnd() const     { return _noChildren.end(); }
00194 
00200     virtual YItem * parent() const { return 0; }
00201 
00202 
00203 private:
00204 
00205     string      _label;
00206     string      _iconName;
00207     bool        _selected;
00208     int         _index;
00209     void *      _data;
00210 
00215     static YItemCollection _noChildren;
00216 };
00217 
00218 
00219 
00220 #endif // YItem_h
 All Classes Functions Variables Enumerations Friends