libyui  3.10.0
YMultiLineEdit.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: YMultiLineEdit.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 "YMultiLineEdit.h"
31 
32 
33 #define DEFAULT_VISIBLE_LINES 3
34 
35 using std::string;
36 
37 
39 {
40  YMultiLineEditPrivate( const string & label )
41  : label( label )
42  , inputMaxLength( -1 )
43  , defaultVisibleLines( DEFAULT_VISIBLE_LINES )
44  {}
45 
46  string label;
47  int inputMaxLength;
48  int defaultVisibleLines;
49 };
50 
51 
52 
53 
54 YMultiLineEdit::YMultiLineEdit( YWidget * parent, const string & label )
55  : YWidget( parent )
56  , priv( new YMultiLineEditPrivate( label ) )
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 string YMultiLineEdit::label() const
72 {
73  return priv->label;
74 }
75 
76 
77 void YMultiLineEdit::setLabel( const string & label )
78 {
79  priv->label = label;
80 }
81 
82 
84 {
85  return priv->inputMaxLength;
86 }
87 
88 
90 {
91  priv->inputMaxLength = len;
92 }
93 
94 
96 {
97  return priv->defaultVisibleLines;
98 }
99 
100 
101 void YMultiLineEdit::setDefaultVisibleLines( int newVisibleLines )
102 {
103  priv->defaultVisibleLines = newVisibleLines;
104 }
105 
106 
107 const YPropertySet &
109 {
110  static YPropertySet propSet;
111 
112  if ( propSet.isEmpty() )
113  {
114  /*
115  * @property string Value the MultiLineEdit text contents (with newlines)
116  * @property string Label caption above the MultiLineEdit
117  * @property integer InputMaxLength maximum number of input characters
118  */
119  propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
120  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
121  propSet.add( YProperty( YUIProperty_InputMaxLength, YIntegerProperty ) );
122  propSet.add( YWidget::propertySet() );
123  }
124 
125  return propSet;
126 }
127 
128 
129 bool
130 YMultiLineEdit::setProperty( const string & propertyName, const YPropertyValue & val )
131 {
132  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
133 
134  if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() );
135  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
136  else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() );
137  else
138  {
139  return YWidget::setProperty( propertyName, val );
140  }
141 
142  return true; // success -- no special processing necessary
143 }
144 
145 
147 YMultiLineEdit::getProperty( const string & propertyName )
148 {
149  propertySet().check( propertyName ); // throws exceptions if not found
150 
151  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
152  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
153  else if ( propertyName == YUIProperty_InputMaxLength ) return YPropertyValue( inputMaxLength() );
154  else
155  {
156  return YWidget::getProperty( propertyName );
157  }
158 }
YMultiLineEdit::~YMultiLineEdit
virtual ~YMultiLineEdit()
Destructor.
Definition: YMultiLineEdit.cc:65
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
YMultiLineEditPrivate
Definition: YMultiLineEdit.cc:39
YMultiLineEdit::label
std::string label() const
Get the label (the caption above the MultiLineEdit).
Definition: YMultiLineEdit.cc:71
YMultiLineEdit::setInputMaxLength
virtual void setInputMaxLength(int numberOfChars)
Set the maximum input length, i.e., the maximum number of characters the user can enter.
Definition: YMultiLineEdit.cc:89
YPropertySet
A set of properties to check names and types against.
Definition: YProperty.h:198
YPropertySet::isEmpty
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
YMultiLineEdit::setDefaultVisibleLines
virtual void setDefaultVisibleLines(int newVisibleLines)
Set the number of input lines that are visible by default.
Definition: YMultiLineEdit.cc:101
YPropertyValue::stringVal
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
YMultiLineEdit::defaultVisibleLines
int defaultVisibleLines() const
Return the number of input lines that are visible by default.
Definition: YMultiLineEdit.cc:95
YPropertyValue::type
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
YWidget::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:457
YProperty
Class for widget properties.
Definition: YProperty.h:52
YMultiLineEdit::setLabel
virtual void setLabel(const std::string &label)
Set the label (the caption above the MultiLineEdit).
Definition: YMultiLineEdit.cc:77
YMultiLineEdit::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YMultiLineEdit.cc:147
YMultiLineEdit::value
virtual std::string value()=0
Get the current value (the text entered by the user or set from the outside) of this MultiLineEdit.
YPropertySet::check
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
Definition: YProperty.cc:88
YMultiLineEdit::setValue
virtual void setValue(const std::string &text)=0
Set the current value (the text entered by the user or set from the outside) of this MultiLineEdit.
YMultiLineEdit::inputMaxLength
int inputMaxLength() const
The maximum input length, i.e., the maximum number of characters the user can enter.
Definition: YMultiLineEdit.cc:83
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
YMultiLineEdit::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YMultiLineEdit.cc:108
YMultiLineEdit::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YMultiLineEdit.cc:130
YMultiLineEdit::YMultiLineEdit
YMultiLineEdit(YWidget *parent, const std::string &label)
Constructor.
Definition: YMultiLineEdit.cc:54
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