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