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