libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YTable.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YTable.cc
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "ui"
00027 #include "YUILog.h"
00028 
00029 #include "YUISymbols.h"
00030 #include "YTable.h"
00031 
00032 
00033 struct YTablePrivate
00034 {
00035     YTablePrivate( YTableHeader * header )
00036         : header( header )
00037         , keepSorting( false )
00038         , immediateMode( false )
00039     {
00040     }
00041 
00042     YTableHeader *      header;
00043     bool                keepSorting;
00044     bool                immediateMode;
00045 };
00046 
00047 
00048 
00049 
00050 YTable::YTable( YWidget * parent, YTableHeader * header, bool multiSelection )
00051     : YSelectionWidget( parent,
00052                         "",     // label
00053                         ! multiSelection ) // enforceSingleSelection
00054     , priv( new YTablePrivate( header ) )
00055 {
00056     YUI_CHECK_PTR( header );
00057     YUI_CHECK_NEW( priv   );
00058 
00059     setDefaultStretchable( YD_HORIZ, true );
00060     setDefaultStretchable( YD_VERT,  true );
00061 }
00062 
00063 
00064 YTable::~YTable()
00065 {
00066     if ( priv->header )
00067         delete priv->header;
00068 }
00069 
00070 
00071 void
00072 YTable::setTableHeader( YTableHeader * newHeader )
00073 {
00074     YUI_CHECK_PTR( newHeader );
00075 
00076     if ( priv->header->columns() != newHeader->columns() )
00077         deleteAllItems();
00078 
00079     delete priv->header;
00080     priv->header = newHeader;
00081 }
00082 
00083 
00084 int
00085 YTable::columns() const
00086 {
00087     return priv->header->columns();
00088 }
00089 
00090 
00091 bool
00092 YTable::hasColumn( int column ) const
00093 {
00094     return priv->header->hasColumn( column );
00095 }
00096 
00097 
00098 std::string
00099 YTable::header( int column ) const
00100 {
00101     return priv->header->header( column );
00102 }
00103 
00104 
00105 YAlignmentType
00106 YTable::alignment( int column ) const
00107 {
00108     return priv->header->alignment( column );
00109 }
00110 
00111 
00112 bool
00113 YTable::immediateMode() const
00114 {
00115     return priv->immediateMode;
00116 }
00117 
00118 
00119 void
00120 YTable::setImmediateMode( bool immediateMode )
00121 {
00122     priv->immediateMode = immediateMode;
00123 
00124     if ( immediateMode )
00125         setNotify( true );
00126 }
00127 
00128 
00129 bool
00130 YTable::keepSorting() const
00131 {
00132     return priv->keepSorting;
00133 }
00134 
00135 
00136 void
00137 YTable::setKeepSorting( bool keepSorting )
00138 {
00139     priv->keepSorting = keepSorting;
00140 }
00141 
00142 
00143 bool
00144 YTable::hasMultiSelection() const
00145 {
00146     return ! YSelectionWidget::enforceSingleSelection();
00147 }
00148 
00149 
00150 const YPropertySet &
00151 YTable::propertySet()
00152 {
00153     static YPropertySet propSet;
00154 
00155     if ( propSet.isEmpty() )
00156     {
00157         /*
00158          * @property itemID             Value           The currently selected item
00159          * @property itemID             CurrentItem     The currently selected item
00160          * @property itemList           Items           All items
00161          * @property itemList           SelectedItems   All currently selected items
00162          * @property std::string        Cell            One cell (one column of one item)
00163          * @property integer            Cell            (ChangeWidget only) One cell as integer
00164          * @property `icon(...)         Cell            Icon for one one cell
00165          * @property std::string        Item            Alias for Cell
00166          * @property std::string        Item            QueryWidget only: Return one complete item
00167          * @property std::string        IconPath        Base path for icons
00168          * @property bool               MultiSelection  Flag: User can select multiple items (read-only)
00169          */
00170         propSet.add( YProperty( YUIProperty_Value,              YOtherProperty   ) );
00171         propSet.add( YProperty( YUIProperty_CurrentItem,        YOtherProperty   ) );
00172         propSet.add( YProperty( YUIProperty_SelectedItems,      YOtherProperty   ) );
00173         propSet.add( YProperty( YUIProperty_Items,              YOtherProperty   ) );
00174         propSet.add( YProperty( YUIProperty_Cell,               YOtherProperty   ) );
00175         propSet.add( YProperty( YUIProperty_Item,               YOtherProperty   ) );
00176         propSet.add( YProperty( YUIProperty_IconPath,           YStringProperty  ) );
00177         propSet.add( YProperty( YUIProperty_MultiSelection,     YBoolProperty,   true ) ); // read-only
00178         propSet.add( YWidget::propertySet() );
00179     }
00180 
00181     return propSet;
00182 }
00183 
00184 
00185 bool
00186 YTable::setProperty( const std::string & propertyName, const YPropertyValue & val )
00187 {
00188     propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
00189 
00190     if      ( propertyName == YUIProperty_Value         )       return false; // Needs special handling
00191     else if ( propertyName == YUIProperty_CurrentItem   )       return false; // Needs special handling
00192     else if ( propertyName == YUIProperty_SelectedItems )       return false; // Needs special handling
00193     else if ( propertyName == YUIProperty_Items         )       return false; // Needs special handling
00194     else if ( propertyName == YUIProperty_Cell          )       return false; // Needs special handling
00195     else if ( propertyName == YUIProperty_Item          )       return false; // Needs special handling
00196     else if ( propertyName == YUIProperty_IconPath      )       setIconBasePath( val.stringVal() );
00197     else
00198     {
00199         return YWidget::setProperty( propertyName, val );
00200     }
00201 
00202     return true; // success -- no special processing necessary
00203 }
00204 
00205 
00206 YPropertyValue
00207 YTable::getProperty( const std::string & propertyName )
00208 {
00209     propertySet().check( propertyName ); // throws exceptions if not found
00210 
00211     if      ( propertyName == YUIProperty_Value         )       return YPropertyValue( YOtherProperty );
00212     else if ( propertyName == YUIProperty_CurrentItem   )       return YPropertyValue( YOtherProperty );
00213     else if ( propertyName == YUIProperty_SelectedItems )       return YPropertyValue( YOtherProperty );
00214     else if ( propertyName == YUIProperty_Items         )       return YPropertyValue( YOtherProperty );
00215     else if ( propertyName == YUIProperty_Cell          )       return YPropertyValue( YOtherProperty );
00216     else if ( propertyName == YUIProperty_Item          )       return YPropertyValue( YOtherProperty );
00217     else if ( propertyName == YUIProperty_IconPath      )       return YPropertyValue( iconBasePath() );
00218     else
00219     {
00220         return YWidget::getProperty( propertyName );
00221     }
00222 }
 All Classes Functions Variables Enumerations Friends