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