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: YSimpleInputField.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 "YSimpleInputField.h" 00031 00032 00033 struct YSimpleInputFieldPrivate 00034 { 00035 YSimpleInputFieldPrivate( const std::string & label ) 00036 : label( label ) 00037 {} 00038 00039 std::string label; 00040 }; 00041 00042 00043 00044 00045 YSimpleInputField::YSimpleInputField( YWidget * parent, const std::string & label ) 00046 : YWidget( parent ) 00047 , priv( new YSimpleInputFieldPrivate( label ) ) 00048 { 00049 YUI_CHECK_NEW( priv ); 00050 00051 setDefaultStretchable( YD_HORIZ, false ); 00052 setDefaultStretchable( YD_VERT, false ); 00053 } 00054 00055 00056 YSimpleInputField::~YSimpleInputField() 00057 { 00058 // NOP 00059 } 00060 00061 00062 std::string YSimpleInputField::label() const 00063 { 00064 return priv->label; 00065 } 00066 00067 00068 void YSimpleInputField::setLabel( const std::string & label ) 00069 { 00070 priv->label = label; 00071 } 00072 00073 00074 00075 const YPropertySet & 00076 YSimpleInputField::propertySet() 00077 { 00078 static YPropertySet propSet; 00079 00080 if ( propSet.isEmpty() ) 00081 { 00082 /* 00083 * @property std::string Value the text the user entered 00084 * @property std::string Label caption above the input field 00085 */ 00086 propSet.add( YProperty( YUIProperty_Value, YStringProperty ) ); 00087 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00088 propSet.add( YWidget::propertySet() ); 00089 } 00090 00091 return propSet; 00092 } 00093 00094 00095 bool 00096 YSimpleInputField::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00097 { 00098 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00099 00100 if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() ); 00101 else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); 00102 else 00103 { 00104 return YWidget::setProperty( propertyName, val ); 00105 } 00106 00107 return true; // success -- no special processing necessary 00108 } 00109 00110 00111 YPropertyValue 00112 YSimpleInputField::getProperty( const std::string & propertyName ) 00113 { 00114 propertySet().check( propertyName ); // throws exceptions if not found 00115 00116 if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() ); 00117 else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); 00118 else 00119 { 00120 return YWidget::getProperty( propertyName ); 00121 } 00122 }