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