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