libyui  3.3.1
YSimpleInputField.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: YSimpleInputField.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 "YSimpleInputField.h"
31 
32 
34 {
35  YSimpleInputFieldPrivate( const std::string & label )
36  : label( label )
37  {}
38 
39  std::string label;
40 };
41 
42 
43 
44 
45 YSimpleInputField::YSimpleInputField( YWidget * parent, const std::string & label )
46  : YWidget( parent )
47  , priv( new YSimpleInputFieldPrivate( label ) )
48 {
49  YUI_CHECK_NEW( priv );
50 
51  setDefaultStretchable( YD_HORIZ, false );
52  setDefaultStretchable( YD_VERT, false );
53 }
54 
55 
57 {
58  // NOP
59 }
60 
61 
62 std::string YSimpleInputField::label() const
63 {
64  return priv->label;
65 }
66 
67 
68 void YSimpleInputField::setLabel( const std::string & label )
69 {
70  priv->label = label;
71 }
72 
73 
74 
75 const YPropertySet &
77 {
78  static YPropertySet propSet;
79 
80  if ( propSet.isEmpty() )
81  {
82  /*
83  * @property std::string Value the text the user entered
84  * @property std::string Label caption above the input field
85  */
86  propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
87  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
88  propSet.add( YWidget::propertySet() );
89  }
90 
91  return propSet;
92 }
93 
94 
95 bool
96 YSimpleInputField::setProperty( const std::string & propertyName, const YPropertyValue & val )
97 {
98  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
99 
100  if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() );
101  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
102  else
103  {
104  return YWidget::setProperty( propertyName, val );
105  }
106 
107  return true; // success -- no special processing necessary
108 }
109 
110 
112 YSimpleInputField::getProperty( const std::string & propertyName )
113 {
114  propertySet().check( propertyName ); // throws exceptions if not found
115 
116  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
117  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
118  else
119  {
120  return YWidget::getProperty( propertyName );
121  }
122 }
virtual ~YSimpleInputField()
Destructor.
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
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:428
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual std::string value()=0
Get the current value (the text entered by the user or set from the outside) of this input field...
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
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
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 input field...
Class for widget properties.
Definition: YProperty.h:51
std::string label() const
Get the label (the caption above the input field).
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
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
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
YSimpleInputField(YWidget *parent, const std::string &label)
Constructor.