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: YLabel.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #define MAX_DEBUG_LABEL_LEN 32 00026 00027 00028 #define YUILogComponent "ui" 00029 #include "YUILog.h" 00030 00031 #include "YUISymbols.h" 00032 #include "YLabel.h" 00033 00034 00035 struct YLabelPrivate 00036 { 00037 /** 00038 * Constructor 00039 **/ 00040 YLabelPrivate( const std::string & text, 00041 bool isHeading, 00042 bool isOutputField ) 00043 : text( text ) 00044 , isHeading( isHeading ) 00045 , isOutputField( isOutputField ) 00046 , useBoldFont( false ) 00047 {} 00048 00049 std::string text; 00050 bool isHeading; 00051 bool isOutputField; 00052 bool useBoldFont; 00053 }; 00054 00055 00056 YLabel::YLabel( YWidget * parent, 00057 const std::string & text, 00058 bool isHeading, 00059 bool isOutputField ) 00060 : YWidget( parent ) 00061 , priv( new YLabelPrivate( text, isHeading, isOutputField ) ) 00062 { 00063 YUI_CHECK_NEW( priv ); 00064 } 00065 00066 00067 YLabel::~YLabel() 00068 { 00069 // NOP 00070 } 00071 00072 00073 std::string YLabel::text() const 00074 { 00075 return priv->text; 00076 } 00077 00078 00079 void YLabel::setText( const std::string & newText ) 00080 { 00081 priv->text = newText; 00082 } 00083 00084 00085 bool YLabel::isHeading() const 00086 { 00087 return priv->isHeading; 00088 } 00089 00090 00091 bool YLabel::isOutputField() const 00092 { 00093 return priv->isOutputField; 00094 } 00095 00096 00097 bool YLabel::useBoldFont() const 00098 { 00099 return priv->useBoldFont; 00100 } 00101 00102 00103 void YLabel::setUseBoldFont( bool bold ) 00104 { 00105 priv->useBoldFont = bold; 00106 } 00107 00108 00109 const YPropertySet & 00110 YLabel::propertySet() 00111 { 00112 static YPropertySet propSet; 00113 00114 if ( propSet.isEmpty() ) 00115 { 00116 /* 00117 * @property std::string Label the label text 00118 * @property std::string Value the label text (alias for Label) 00119 * @property std::string Text the label text (alias for Label) 00120 */ 00121 00122 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00123 propSet.add( YProperty( YUIProperty_Value, YStringProperty ) ); 00124 propSet.add( YProperty( YUIProperty_Text, YStringProperty ) ); 00125 propSet.add( YWidget::propertySet() ); 00126 } 00127 00128 return propSet; 00129 } 00130 00131 00132 bool 00133 YLabel::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00134 { 00135 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00136 00137 if ( propertyName == YUIProperty_Label ) setText( val.stringVal() ); 00138 else if ( propertyName == YUIProperty_Value ) setText( val.stringVal() ); 00139 else if ( propertyName == YUIProperty_Text ) setText( val.stringVal() ); 00140 else 00141 { 00142 return YWidget::setProperty( propertyName, val ); 00143 } 00144 00145 return true; // success -- no special processing necessary 00146 } 00147 00148 00149 YPropertyValue 00150 YLabel::getProperty( const std::string & propertyName ) 00151 { 00152 propertySet().check( propertyName ); // throws exceptions if not found 00153 00154 if ( propertyName == YUIProperty_Label ) return YPropertyValue( text() ); 00155 else if ( propertyName == YUIProperty_Value ) return YPropertyValue( text() ); 00156 else if ( propertyName == YUIProperty_Text ) return YPropertyValue( text() ); 00157 else 00158 { 00159 return YWidget::getProperty( propertyName ); 00160 } 00161 } 00162 00163 00164 std::string YLabel::debugLabel() const 00165 { 00166 std::string label = text(); 00167 00168 if ( label.size() > MAX_DEBUG_LABEL_LEN ) 00169 { 00170 label.resize( MAX_DEBUG_LABEL_LEN ); 00171 label.append( "..." ); 00172 } 00173 00174 for ( std::string::size_type i=0; i < label.size(); i++ ) 00175 { 00176 if ( label[i] == '\n' ) label[i] = ' '; 00177 if ( label[i] == '\"' ) label[i] = ' '; 00178 } 00179 00180 return label; 00181 } 00182 00183 00184 00185 const char * 00186 YLabel::widgetClass() const 00187 { 00188 if ( priv->isHeading ) return "YLabel_Heading"; 00189 else if ( priv->isOutputField ) return "YLabel_OutputField"; 00190 else return "YLabel"; 00191 }