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: YMultiLineEdit.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 "YMultiLineEdit.h" 00031 00032 00033 #define DEFAULT_VISIBLE_LINES 3 00034 00035 00036 struct YMultiLineEditPrivate 00037 { 00038 YMultiLineEditPrivate( const std::string & label ) 00039 : label( label ) 00040 , inputMaxLength( -1 ) 00041 , defaultVisibleLines( DEFAULT_VISIBLE_LINES ) 00042 {} 00043 00044 std::string label; 00045 int inputMaxLength; 00046 int defaultVisibleLines; 00047 }; 00048 00049 00050 00051 00052 YMultiLineEdit::YMultiLineEdit( YWidget * parent, const std::string & label ) 00053 : YWidget( parent ) 00054 , priv( new YMultiLineEditPrivate( label ) ) 00055 { 00056 YUI_CHECK_NEW( priv ); 00057 00058 setDefaultStretchable( YD_HORIZ, true ); 00059 setDefaultStretchable( YD_VERT, true ); 00060 } 00061 00062 00063 YMultiLineEdit::~YMultiLineEdit() 00064 { 00065 // NOP 00066 } 00067 00068 00069 std::string YMultiLineEdit::label() const 00070 { 00071 return priv->label; 00072 } 00073 00074 00075 void YMultiLineEdit::setLabel( const std::string & label ) 00076 { 00077 priv->label = label; 00078 } 00079 00080 00081 int YMultiLineEdit::inputMaxLength() const 00082 { 00083 return priv->inputMaxLength; 00084 } 00085 00086 00087 void YMultiLineEdit::setInputMaxLength( int len ) 00088 { 00089 priv->inputMaxLength = len; 00090 } 00091 00092 00093 int YMultiLineEdit::defaultVisibleLines() const 00094 { 00095 return priv->defaultVisibleLines; 00096 } 00097 00098 00099 void YMultiLineEdit::setDefaultVisibleLines( int newVisibleLines ) 00100 { 00101 priv->defaultVisibleLines = newVisibleLines; 00102 } 00103 00104 00105 const YPropertySet & 00106 YMultiLineEdit::propertySet() 00107 { 00108 static YPropertySet propSet; 00109 00110 if ( propSet.isEmpty() ) 00111 { 00112 /* 00113 * @property std::string Value the MultiLineEdit text contents (with newlines) 00114 * @property std::string Label caption above the MultiLineEdit 00115 * @property integer InputMaxLength maximum number of input characters 00116 */ 00117 propSet.add( YProperty( YUIProperty_Value, YStringProperty ) ); 00118 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00119 propSet.add( YProperty( YUIProperty_InputMaxLength, YIntegerProperty ) ); 00120 propSet.add( YWidget::propertySet() ); 00121 } 00122 00123 return propSet; 00124 } 00125 00126 00127 bool 00128 YMultiLineEdit::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00129 { 00130 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00131 00132 if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() ); 00133 else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); 00134 else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() ); 00135 else 00136 { 00137 return YWidget::setProperty( propertyName, val ); 00138 } 00139 00140 return true; // success -- no special processing necessary 00141 } 00142 00143 00144 YPropertyValue 00145 YMultiLineEdit::getProperty( const std::string & propertyName ) 00146 { 00147 propertySet().check( propertyName ); // throws exceptions if not found 00148 00149 if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() ); 00150 else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); 00151 else if ( propertyName == YUIProperty_InputMaxLength ) return YPropertyValue( inputMaxLength() ); 00152 else 00153 { 00154 return YWidget::getProperty( propertyName ); 00155 } 00156 }