libyui  3.4.2
YCheckBoxFrame.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: YCheckBoxFrame.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 "YCheckBoxFrame.h"
31 
32 
34 {
35  YCheckBoxFramePrivate( const std::string & label )
36  : label( label )
37  , autoEnable( true )
38  , invertAutoEnable( false )
39  {}
40 
41  std::string label;
42  bool autoEnable;
43  bool invertAutoEnable;
44 };
45 
46 
47 
48 
50  const std::string & label,
51  bool isChecked )
52  : YSingleChildContainerWidget( parent )
53  , priv( new YCheckBoxFramePrivate( label ) )
54 {
55  YUI_CHECK_NEW( priv );
56 }
57 
58 
60 {
61  // NOP
62 }
63 
64 
65 std::string YCheckBoxFrame::label() const
66 {
67  return priv->label;
68 }
69 
70 void YCheckBoxFrame::setLabel( const std::string & label )
71 {
72  priv->label = label;
73 }
74 
76 {
77  return priv->autoEnable;
78 }
79 
81 {
82  // yuiDebug() << "Auto enable: " << boolalpha << autoEnable << std::endl;
83  priv->autoEnable = autoEnable;
84 }
85 
87 {
88  return priv->invertAutoEnable;
89 }
90 
92 {
93  // yuiDebug() << "Invert auto enable: ", boolalpha << invertAutoEnable << std::endl;
94  priv->invertAutoEnable = invertAutoEnable;
95 }
96 
97 
99 {
100  if ( autoEnable() )
101  {
102  if ( invertAutoEnable() )
103  enabled = ! enabled;
104 
105  yuiDebug() << ( enabled ? "Enabling" : "Disabling" ) << " child widgets of " << this << std::endl;
106  setChildrenEnabled( enabled );
107  }
108 }
109 
110 
111 const YPropertySet &
113 {
114  static YPropertySet propSet;
115 
116  if ( propSet.isEmpty() )
117  {
118  /*
119  * @property boolean Value the on/off state of the CheckBoxFrame's check box
120  * @property std::string Label the text on the frame
121  */
122 
123  propSet.add( YProperty( YUIProperty_Value, YBoolProperty ) );
124  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
125  propSet.add( YWidget::propertySet() );
126  }
127 
128  return propSet;
129 }
130 
131 
132 bool
133 YCheckBoxFrame::setProperty( const std::string & propertyName, const YPropertyValue & val )
134 {
135  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
136 
137  if ( propertyName == YUIProperty_Value ) setValue( val.boolVal() );
138  else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
139  else
140  {
141  return YWidget::setProperty( propertyName, val );
142  }
143 
144  return true; // success -- no special processing necessary
145 }
146 
147 
149 YCheckBoxFrame::getProperty( const std::string & propertyName )
150 {
151  propertySet().check( propertyName ); // throws exceptions if not found
152 
153  if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
154  else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
155  else
156  {
157  return YWidget::getProperty( propertyName );
158  }
159 }
virtual bool value()=0
Get the status of the CheckBoxFrame&#39;s check box.
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.
YCheckBoxFrame(YWidget *parent, const std::string &label, bool checked)
Constructor.
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:430
bool invertAutoEnable() const
Invert the meaning of the CheckBoxFrame&#39;s check box, i.e., disable child widgets when checked...
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual void setAutoEnable(bool autoEnable)
Change autoEnabled flag.
Container widget class that manages one child.
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.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:455
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
void handleChildrenEnablement(bool isChecked)
Handle enabling/disabling of child widgets based on &#39;isChecked&#39; (the current status of the check box)...
Class for widget properties.
Definition: YProperty.h:51
bool autoEnable() const
Handle children enabling/disabling automatically based on the CheckBoxFrame&#39;s check box...
void setChildrenEnabled(bool enabled)
Enable or disable all widgets in this widget tree.
Definition: YWidget.cc:641
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual void setInvertAutoEnable(bool invertAutoEnable)
Change invertAutonEnable flag.
virtual void setLabel(const std::string &label)
Change the label text on the CheckBoxFrame.
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:87
std::string label() const
Return the label text on the CheckBoxFrame.
Abstract base class of all UI widgets.
Definition: YWidget.h:54
virtual ~YCheckBoxFrame()
Destructor.
virtual void setValue(bool isChecked)=0
Check or uncheck the CheckBoxFrame&#39;s check box.
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169