libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YSelectionBox.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:         YSelectionBox.cc
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "ui"
00027 #include "YUILog.h"
00028 
00029 #include "YSelectionBox.h"
00030 #include "YUISymbols.h"
00031 #include "YUIException.h"
00032 
00033 
00034 struct YSelectionBoxPrivate
00035 {
00036     YSelectionBoxPrivate()
00037         : shrinkable( false )
00038         , immediateMode( false )
00039         {}
00040 
00041     bool shrinkable;
00042     bool immediateMode;
00043 };
00044 
00045 
00046 
00047 
00048 YSelectionBox::YSelectionBox( YWidget * parent, const std::string & label )
00049     : YSelectionWidget( parent, label,
00050                         true ) // enforceSingleSelection
00051     , priv( new YSelectionBoxPrivate() )
00052 {
00053     YUI_CHECK_NEW( priv );
00054 
00055     setDefaultStretchable( YD_HORIZ, true );
00056     setDefaultStretchable( YD_VERT,  true );
00057 
00058 }
00059 
00060 
00061 YSelectionBox::~YSelectionBox()
00062 {
00063     // NOP
00064 }
00065 
00066 
00067 bool YSelectionBox::shrinkable() const
00068 {
00069     return priv->shrinkable;
00070 }
00071 
00072 
00073 void YSelectionBox::setShrinkable( bool shrinkable )
00074 {
00075     priv->shrinkable = shrinkable;
00076 }
00077 
00078 
00079 bool YSelectionBox::immediateMode() const
00080 {
00081     return priv->immediateMode;
00082 }
00083 
00084 
00085 void YSelectionBox::setImmediateMode( bool immediateMode )
00086 {
00087     priv->immediateMode = immediateMode;
00088 
00089     if ( immediateMode )
00090         setNotify( true );
00091 }
00092 
00093 
00094 const YPropertySet &
00095 YSelectionBox::propertySet()
00096 {
00097     static YPropertySet propSet;
00098 
00099     if ( propSet.isEmpty() )
00100     {
00101         /*
00102          * @property itemID             Value           The currently selected item
00103          * @property itemID             CurrentItem     The currently selected item
00104          * @property itemList           Items           All items
00105          * @property std::string        Label           Caption above the selection box
00106          * @property std::string        IconPath        Base path for icons
00107          */
00108         propSet.add( YProperty( YUIProperty_Value,              YOtherProperty   ) );
00109         propSet.add( YProperty( YUIProperty_CurrentItem,        YOtherProperty   ) );
00110         propSet.add( YProperty( YUIProperty_Items,              YOtherProperty   ) );
00111         propSet.add( YProperty( YUIProperty_Label,              YStringProperty  ) );
00112         propSet.add( YProperty( YUIProperty_IconPath,           YStringProperty  ) );
00113         propSet.add( YWidget::propertySet() );
00114     }
00115 
00116     return propSet;
00117 }
00118 
00119 
00120 bool
00121 YSelectionBox::setProperty( const std::string & propertyName, const YPropertyValue & val )
00122 {
00123     propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
00124 
00125     if      ( propertyName == YUIProperty_Value         )       return false; // Needs special handling
00126     else if ( propertyName == YUIProperty_CurrentItem   )       return false; // Needs special handling
00127     else if ( propertyName == YUIProperty_Items         )       return false; // Needs special handling
00128     else if ( propertyName == YUIProperty_Label         )       setLabel( val.stringVal() );
00129     else if ( propertyName == YUIProperty_IconPath      )       setIconBasePath( val.stringVal() );
00130     else
00131     {
00132         return YWidget::setProperty( propertyName, val );
00133     }
00134 
00135     return true; // success -- no special processing necessary
00136 }
00137 
00138 
00139 YPropertyValue
00140 YSelectionBox::getProperty( const std::string & propertyName )
00141 {
00142     propertySet().check( propertyName ); // throws exceptions if not found
00143 
00144     if      ( propertyName == YUIProperty_Value         )       return YPropertyValue( YOtherProperty );
00145     else if ( propertyName == YUIProperty_CurrentItem   )       return YPropertyValue( YOtherProperty );
00146     else if ( propertyName == YUIProperty_Items         )       return YPropertyValue( YOtherProperty );
00147     else if ( propertyName == YUIProperty_Label         )       return YPropertyValue( label() );
00148     else if ( propertyName == YUIProperty_IconPath      )       return YPropertyValue( iconBasePath() );
00149     else
00150     {
00151         return YWidget::getProperty( propertyName );
00152     }
00153 }
 All Classes Functions Variables Enumerations Friends