libyui  3.3.2
YCheckBox.h
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.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YCheckBox_h
26 #define YCheckBox_h
27 
28 #include <string>
29 
30 #include "YWidget.h"
31 #include "ImplPtr.h"
32 
33 class YCheckBoxPrivate;
34 
35 enum YCheckBoxState
36 {
37  YCheckBox_dont_care = -1, // tristate
38  YCheckBox_off = 0,
39  YCheckBox_on = 1
40 };
41 
42 /**
43  * A tri-state check box. It can be toggled between ON and OFF by the user
44  * and additionally set to a DONT-CARE value programatically.
45  **/
46 class YCheckBox : public YWidget
47 {
48 protected:
49  /**
50  * Constructor.
51  **/
52  YCheckBox( YWidget * parent, const std::string & label );
53 
54 public:
55  /**
56  * Destructor.
57  **/
58  virtual ~YCheckBox();
59 
60  /**
61  * Returns a descriptive name of this widget class for logging,
62  * debugging etc.
63  **/
64  virtual const char * widgetClass() const { return "YCheckBox"; }
65 
66 
67  /**
68  * Get the current value:
69  *
70  * YCheckBox_on CheckBox is checked
71  * YCheckBox_off CheckBox is unchecked
72  *
73  * YCheckBox_dont_care tri-state: CheckBox is greyed out,
74  * neither checked nor unchecked
75  *
76  * The user cannot set YCheckBox_dont_care directly. This status is always
77  * only set from the outside, usually because a setting cannot be clearly
78  * determined. For example, a checkbox
79  *
80  * [ ] Read only
81  *
82  * would be set to "don't care" (by the application, not directly by the
83  * user) when it is to display the read-only state of a group of files
84  * where some are read-only and some are writeable.
85  *
86  * Derived classes are required to implement this function.
87  * (Intentionally not const)
88  **/
89  virtual YCheckBoxState value() = 0;
90 
91  /**
92  * Set the CheckBox value (on/off/don't care).
93  *
94  * Derived classes are required to implement this.
95  **/
96  virtual void setValue( YCheckBoxState state ) = 0;
97 
98  /**
99  * Simplified access to value(): Return 'true' if the CheckBox is checked.
100  **/
101  bool isChecked() { return value() == YCheckBox_on; }
102 
103  /**
104  * Simplified access to setValue(): Check of uncheck the CheckBox.
105  **/
106  void setChecked( bool checked = true )
107  { setValue( checked ? YCheckBox_on : YCheckBox_off ); }
108 
109  /**
110  * Simplified access to tri-state ("don't care").
111  **/
112  bool dontCare() { return value() == YCheckBox_dont_care; }
113 
114  /**
115  * Simplified access to setting tri-state ("don't care").
116  **/
117  void setDontCare() { setValue( YCheckBox_dont_care ); }
118 
119  /**
120  * Get the label (the text on the CheckBox).
121  **/
122  std::string label() const;
123 
124  /**
125  * Set the label (the text on the CheckBox).
126  *
127  * Derived classes are free to reimplement this, but they should call this
128  * base class method at the end of the overloaded function.
129  **/
130  virtual void setLabel( const std::string & label );
131 
132  /**
133  * Returns 'true' if a bold font should be used.
134  **/
135  bool useBoldFont() const;
136 
137  /**
138  * Indicate whether or not a bold font should be used.
139  *
140  * Derived classes are free to reimplement this, but they should call this
141  * base class method at the end of the overloaded function.
142  **/
143  virtual void setUseBoldFont( bool bold = true );
144 
145  /**
146  * Set a property.
147  * Reimplemented from YWidget.
148  *
149  * This method may throw exceptions, for example
150  * - if there is no property with that name
151  * - if the expected type and the type mismatch
152  * - if the value is out of range
153  *
154  * This function returns 'true' if the value was successfully set and
155  * 'false' if that value requires special handling (not in error cases:
156  * those are covered by exceptions).
157  **/
158  virtual bool setProperty( const std::string & propertyName,
159  const YPropertyValue & val );
160 
161  /**
162  * Get a property.
163  * Reimplemented from YWidget.
164  *
165  * This method may throw exceptions, for example
166  * - if there is no property with that name
167  **/
168  virtual YPropertyValue getProperty( const std::string & propertyName );
169 
170  /**
171  * Return this class's property set.
172  * This also initializes the property set upon the first call.
173  *
174  * Reimplemented from YWidget.
175  **/
176  virtual const YPropertySet & propertySet();
177 
178  /**
179  * Get the string of this widget that holds the keyboard shortcut.
180  *
181  * Reimplemented from YWidget.
182  **/
183  virtual std::string shortcutString() const { return label(); }
184 
185  /**
186  * Set the string of this widget that holds the keyboard shortcut.
187  *
188  * Reimplemented from YWidget.
189  **/
190  virtual void setShortcutString( const std::string & str )
191  { setLabel( str ); }
192 
193  /**
194  * The name of the widget property that will return user input.
195  * Inherited from YWidget.
196  **/
197  const char * userInputProperty() { return YUIProperty_Value; }
198 
199 
200 private:
201 
203 };
204 
205 
206 #endif // YCheckBox_h
const char * userInputProperty()
The name of the widget property that will return user input.
Definition: YCheckBox.h:197
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
A set of properties to check names and types against.
Definition: YProperty.h:197
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
bool isChecked()
Simplified access to value(): Return &#39;true&#39; if the CheckBox is checked.
Definition: YCheckBox.h:101
YCheckBox(YWidget *parent, const std::string &label)
Constructor.
Definition: YCheckBox.cc:45
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YCheckBox.h:64
std::string label() const
Get the label (the text on the CheckBox).
Definition: YCheckBox.cc:65
virtual void setLabel(const std::string &label)
Set the label (the text on the CheckBox).
Definition: YCheckBox.cc:59
bool dontCare()
Simplified access to tri-state ("don&#39;t care").
Definition: YCheckBox.h:112
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YCheckBox.cc:105
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YCheckBox.h:183
virtual void setValue(YCheckBoxState state)=0
Set the CheckBox value (on/off/don&#39;t care).
void setDontCare()
Simplified access to setting tri-state ("don&#39;t care").
Definition: YCheckBox.h:117
virtual void setUseBoldFont(bool bold=true)
Indicate whether or not a bold font should be used.
Definition: YCheckBox.cc:77
void setChecked(bool checked=true)
Simplified access to setValue(): Check of uncheck the CheckBox.
Definition: YCheckBox.h:106
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YCheckBox.h:190
bool useBoldFont() const
Returns &#39;true&#39; if a bold font should be used.
Definition: YCheckBox.cc:71
A tri-state check box.
Definition: YCheckBox.h:46
Abstract base class of all UI widgets.
Definition: YWidget.h:54
virtual ~YCheckBox()
Destructor.
Definition: YCheckBox.cc:53
virtual YCheckBoxState value()=0
Get the current value:
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YCheckBox.cc:121