libyui

/data/gitorious.org/libyui/libyui-master/src/YTableItem.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:         YTableItem.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 #ifndef YTableItem_h
00041 #define YTableItem_h
00042 
00043 #include "YItem.h"
00044 
00045 using std::string;
00046 using std::vector;
00047 
00048 class YTableCell;
00049 
00050 typedef vector<YTableCell *>                    YTableCellCollection;
00051 typedef YTableCellCollection::iterator          YTableCellIterator;
00052 typedef YTableCellCollection::const_iterator    YTableCellConstIterator;
00053 
00054 
00069 class YTableItem: public YItem
00070 {
00071 public:
00072 
00076     YTableItem();
00077 
00094     YTableItem( const string & label_0,
00095                 const string & label_1 = string(),
00096                 const string & label_2 = string(),
00097                 const string & label_3 = string(),
00098                 const string & label_4 = string(),
00099                 const string & label_5 = string(),
00100                 const string & label_6 = string(),
00101                 const string & label_7 = string(),
00102                 const string & label_8 = string(),
00103                 const string & label_9 = string() );
00104 
00110     virtual ~YTableItem();
00111 
00121     void addCell( YTableCell * cell_disown );
00122 
00127     void addCell( const string & label, const string & iconName = string() );
00128 
00132     void deleteCells();
00133 
00137     YTableCellIterator          cellsBegin()            { return _cells.begin(); }
00138     YTableCellConstIterator     cellsBegin() const      { return _cells.begin(); }
00139 
00143     YTableCellIterator          cellsEnd()              { return _cells.end(); }
00144     YTableCellConstIterator     cellsEnd() const        { return _cells.end(); }
00145 
00150     const YTableCell * cell( int index ) const;
00151     YTableCell * cell( int index );
00152 
00156     int cellCount() const { return _cells.size(); }
00157 
00162     bool hasCell( int index ) const;
00163 
00168     string label( int index ) const;
00169 
00174     string iconName( int index ) const;
00175 
00180     bool hasIconName( int index ) const;
00181 
00185     string label() const { return label(0); }
00186     
00187 private:
00188 
00189     // Disable unwanted base class methods. They don't make sense in this
00190     // context since there is not just one single label or icon name, but one
00191     // for each cell.
00192 
00193     string      iconName()      const                           { return ""; }
00194     bool        hasIconName()   const                           { return false; }
00195     void        setLabel        ( const string & )              {}
00196     void        setIconName     ( const string & )              {}
00197 
00198 
00199     //
00200     // Data members
00201     //
00202 
00203     YTableCellCollection _cells;
00204 };
00205 
00206 
00207 
00229 class YTableCell
00230 {
00231 public:
00237     YTableCell( const string & label, const string & iconName = "" )
00238         : _label( label )
00239         , _iconName( iconName )
00240         , _parent( 0 )
00241         , _column ( -1 )
00242         {}
00243 
00248     YTableCell( YTableItem *    parent,
00249                 int             column,
00250                 const string &  label,
00251                 const string &  iconName = "" )
00252         : _label( label )
00253         , _iconName( iconName )
00254         , _parent( parent )
00255         , _column ( column )
00256         {}
00257 
00264     virtual ~YTableCell() {}
00265 
00270     string label() const { return _label; }
00271 
00279     void setLabel( const string & newLabel ) { _label = newLabel; }
00280 
00284     string iconName() const { return _iconName; }
00285 
00289     bool hasIconName() const { return ! _iconName.empty(); }
00290 
00298     void setIconName( const string & newIconName ) { _iconName = newIconName; }
00299 
00303     YTableItem * parent() const { return _parent; }
00304 
00309     int column() const { return _column; }
00310 
00315     int itemIndex() const { return _parent ? _parent->index() : -1; }
00316 
00323     void reparent( YTableItem * parent, int column );
00324 
00325 
00326 private:
00327 
00328     string              _label;
00329     string              _iconName;
00330     YTableItem *        _parent;
00331     int                 _column;
00332 };
00333 
00334 
00335 
00336  #endif // YTableItem_h
 All Classes Functions Variables Enumerations Friends