libyui  3.10.0
YCheckBox.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: YCheckBox.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 "YCheckBox.h"
31 
32 using std::string;
33 
34 
36 {
37  YCheckBoxPrivate( const string & label )
38  : label( label )
39  , useBoldFont( false )
40  {}
41 
42  string label;
43  bool useBoldFont;
44 };
45 
46 
47 YCheckBox::YCheckBox( YWidget * parent, const string & label )
48  : YWidget( parent )
49  , priv( new YCheckBoxPrivate( label ) )
50 {
51  YUI_CHECK_NEW( priv );
52 }
53 
54 
56 {
57  // NOP
58 }
59 
60 
61 void YCheckBox::setLabel( const string & newLabel )
62 {
63  priv->label = newLabel;
64 }
65 
66 
67 string YCheckBox::label() const
68 {
69  return priv->label;
70 }
71 
72 
74 {
75  return priv->useBoldFont;
76 }
77 
78 
79 void YCheckBox::setUseBoldFont( bool bold )
80 {
81  priv->useBoldFont = bold;
82 }
83 
84 
85 const YPropertySet &
87 {
88  static YPropertySet propSet;
89 
90  if ( propSet.isEmpty() )
91  {
92  /*
93  * @property boolean Value the on/off state; nil for "don't care" (tristate)
94  * @property string Label the text on the CheckBox
95  */
96 
97  propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
98  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
99  propSet.add( YWidget::propertySet() );
100  }
101 
102  return propSet;
103 }
104 
105 
106 bool
107 YCheckBox::setProperty( const string & propertyName, const YPropertyValue & val )
108 {
109  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
110 
111  if ( propertyName == YUIProperty_Value ) return false; // need special processing
112  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
113  else
114  {
115  return YWidget::setProperty( propertyName, val );
116  }
117 
118  return true; // success -- no special processing necessary
119 }
120 
121 
123 YCheckBox::getProperty( const string & propertyName )
124 {
125  propertySet().check( propertyName ); // throws exceptions if not found
126 
127  if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
128  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
129  else
130  {
131  return YWidget::getProperty( propertyName );
132  }
133 }
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
YCheckBox::~YCheckBox
virtual ~YCheckBox()
Destructor.
Definition: YCheckBox.cc:55
YCheckBox::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YCheckBox.cc:86
YCheckBoxPrivate
Definition: YCheckBox.cc:36
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
YPropertyValue::stringVal
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
YCheckBox::setUseBoldFont
virtual void setUseBoldFont(bool bold=true)
Indicate whether or not a bold font should be used.
Definition: YCheckBox.cc:79
YPropertyValue::type
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
YCheckBox::setLabel
virtual void setLabel(const std::string &label)
Set the label (the text on the CheckBox).
Definition: YCheckBox.cc:61
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
YCheckBox::YCheckBox
YCheckBox(YWidget *parent, const std::string &label)
Constructor.
Definition: YCheckBox.cc:47
YCheckBox::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YCheckBox.cc:107
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:105
YCheckBox::label
std::string label() const
Get the label (the text on the CheckBox).
Definition: YCheckBox.cc:67
YCheckBox::useBoldFont
bool useBoldFont() const
Returns 'true' if a bold font should be used.
Definition: YCheckBox.cc:73
YWidget::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:432
YCheckBox::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YCheckBox.cc:123
YWidget::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:395