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