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: YRichText.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 "YRichText.h" 00031 00032 00033 struct YRichTextPrivate 00034 { 00035 /** 00036 * Constructor. 00037 **/ 00038 YRichTextPrivate( const std::string & text, bool plainTextMode ) 00039 : text( text ) 00040 , plainTextMode( plainTextMode ) 00041 , autoScrollDown ( false ) 00042 , shrinkable( false ) 00043 {} 00044 00045 std::string text; 00046 bool plainTextMode; 00047 bool autoScrollDown; 00048 bool shrinkable; 00049 }; 00050 00051 00052 00053 00054 YRichText::YRichText( YWidget * parent, const std::string & text, bool plainTextMode ) 00055 : YWidget( parent ) 00056 , priv( new YRichTextPrivate( text, plainTextMode ) ) 00057 { 00058 YUI_CHECK_NEW( priv ); 00059 00060 setDefaultStretchable( YD_HORIZ, true ); 00061 setDefaultStretchable( YD_VERT, true ); 00062 } 00063 00064 00065 YRichText::~YRichText() 00066 { 00067 // NOP 00068 } 00069 00070 00071 void YRichText::setValue( const std::string & newValue ) 00072 { 00073 priv->text = newValue; 00074 } 00075 00076 00077 std::string YRichText::value() const 00078 { 00079 return priv->text; 00080 } 00081 00082 00083 bool YRichText::plainTextMode() const 00084 { 00085 return priv->plainTextMode; 00086 } 00087 00088 00089 void YRichText::setPlainTextMode( bool plainTextMode ) 00090 { 00091 priv->plainTextMode = plainTextMode; 00092 } 00093 00094 00095 bool YRichText::autoScrollDown() const 00096 { 00097 return priv->autoScrollDown; 00098 } 00099 00100 00101 void YRichText::setAutoScrollDown( bool autoScrollDown ) 00102 { 00103 priv->autoScrollDown = autoScrollDown; 00104 } 00105 00106 00107 bool YRichText::shrinkable() const 00108 { 00109 return priv->shrinkable; 00110 } 00111 00112 00113 void YRichText::setShrinkable( bool shrinkable ) 00114 { 00115 priv->shrinkable = shrinkable; 00116 } 00117 00118 00119 const YPropertySet & 00120 YRichText::propertySet() 00121 { 00122 static YPropertySet propSet; 00123 00124 if ( propSet.isEmpty() ) 00125 { 00126 /* 00127 * @property std::string Value the text content 00128 * @property std::string Text the text content 00129 */ 00130 propSet.add( YProperty( YUIProperty_Value, YStringProperty ) ); 00131 propSet.add( YProperty( YUIProperty_Text, YStringProperty ) ); 00132 propSet.add( YWidget::propertySet() ); 00133 } 00134 00135 return propSet; 00136 } 00137 00138 00139 bool 00140 YRichText::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00141 { 00142 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00143 00144 if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() ); 00145 else if ( propertyName == YUIProperty_Text ) setValue( val.stringVal() ); 00146 else 00147 { 00148 return YWidget::setProperty( propertyName, val ); 00149 } 00150 00151 return true; // success -- no special processing necessary 00152 } 00153 00154 00155 YPropertyValue 00156 YRichText::getProperty( const std::string & propertyName ) 00157 { 00158 propertySet().check( propertyName ); // throws exceptions if not found 00159 00160 if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() ); 00161 else if ( propertyName == YUIProperty_Text ) return YPropertyValue( value() ); 00162 else 00163 { 00164 return YWidget::getProperty( propertyName ); 00165 } 00166 }