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