libyui  3.4.2
YRichText.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YRichText.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YRichText.h"
31 
32 
34 {
35  /**
36  * Constructor.
37  **/
38  YRichTextPrivate( const std::string & text, bool plainTextMode )
39  : text( text )
40  , plainTextMode( plainTextMode )
41  , autoScrollDown ( false )
42  , shrinkable( false )
43  {}
44 
45  std::string text;
46  bool plainTextMode;
47  bool autoScrollDown;
48  bool shrinkable;
49 };
50 
51 
52 
53 
54 YRichText::YRichText( YWidget * parent, const std::string & text, bool plainTextMode )
55  : YWidget( parent )
56  , priv( new YRichTextPrivate( text, plainTextMode ) )
57 {
58  YUI_CHECK_NEW( priv );
59 
60  setDefaultStretchable( YD_HORIZ, true );
61  setDefaultStretchable( YD_VERT, true );
62 }
63 
64 
66 {
67  // NOP
68 }
69 
70 
71 void YRichText::setValue( const std::string & newValue )
72 {
73  priv->text = newValue;
74 }
75 
76 
77 std::string YRichText::value() const
78 {
79  return priv->text;
80 }
81 
82 
84 {
85  return priv->plainTextMode;
86 }
87 
88 
90 {
91  priv->plainTextMode = plainTextMode;
92 }
93 
94 
96 {
97  return priv->autoScrollDown;
98 }
99 
100 
102 {
103  priv->autoScrollDown = autoScrollDown;
104 }
105 
106 
108 {
109  return priv->shrinkable;
110 }
111 
112 
114 {
115  priv->shrinkable = shrinkable;
116 }
117 
118 
119 const YPropertySet &
121 {
122  static YPropertySet propSet;
123 
124  if ( propSet.isEmpty() )
125  {
126  /*
127  * @property std::string Value the text content
128  * @property std::string Text the text content
129  */
130  propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
131  propSet.add( YProperty( YUIProperty_Text, YStringProperty ) );
132  propSet.add( YWidget::propertySet() );
133  }
134 
135  return propSet;
136 }
137 
138 
139 bool
140 YRichText::setProperty( const std::string & propertyName, const YPropertyValue & val )
141 {
142  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
143 
144  if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() );
145  else if ( propertyName == YUIProperty_Text ) setValue( val.stringVal() );
146  else
147  {
148  return YWidget::setProperty( propertyName, val );
149  }
150 
151  return true; // success -- no special processing necessary
152 }
153 
154 
156 YRichText::getProperty( const std::string & propertyName )
157 {
158  propertySet().check( propertyName ); // throws exceptions if not found
159 
160  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
161  else if ( propertyName == YUIProperty_Text ) return YPropertyValue( value() );
162  else
163  {
164  return YWidget::getProperty( propertyName );
165  }
166 }
bool shrinkable() const
Returns &#39;true&#39; if this widget is "shrinkable", i.e.
Definition: YRichText.cc:107
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
Transport class for the value of simple properties.
Definition: YProperty.h:104
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:430
bool autoScrollDown() const
Return &#39;true&#39; if this RichText widget should automatically scroll down when the text content is chang...
Definition: YRichText.cc:95
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual void setValue(const std::string &newValue)
Change the text content of the RichText widget.
Definition: YRichText.cc:71
virtual ~YRichText()
Destructor.
Definition: YRichText.cc:65
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YRichText.cc:120
YRichText(YWidget *parent, const std::string &text, bool plainTextMode=false)
Constructor.
Definition: YRichText.cc:54
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YRichText.cc:156
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:393
YRichTextPrivate(const std::string &text, bool plainTextMode)
Constructor.
Definition: YRichText.cc:38
std::string value() const
Return the text content of the RichText widget.
Definition: YRichText.cc:77
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:455
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:564
Class for widget properties.
Definition: YProperty.h:51
virtual void setAutoScrollDown(bool on=true)
Set this RichText widget&#39;s "auto scroll down" mode on or off.
Definition: YRichText.cc:101
bool plainTextMode() const
Return &#39;true&#39; if this RichText widget is in "plain text" mode, i.e.
Definition: YRichText.cc:83
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:87
Abstract base class of all UI widgets.
Definition: YWidget.h:54
void setShrinkable(bool shrinkable=true)
Make this widget shrinkable, i.e.
Definition: YRichText.cc:113
virtual void setPlainTextMode(bool on=true)
Set this RichText widget&#39;s "plain text" mode on or off.
Definition: YRichText.cc:89
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YRichText.cc:140