libyui  3.3.2
YRadioButton.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: YRadioButton.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YRadioButton_h
26 #define YRadioButton_h
27 
28 #include "YWidget.h"
29 
30 class YRadioButtonGroup;
32 
33 
34 /**
35  * RadioButton: Widget for one-out-of-many selection.
36  *
37  * Only one RadioButton in a RadioBox (in a RadioButtonGroup) can be set to
38  * "on" at the same time. Setting any RadioButton of a RadioButtonGroup to "on"
39  * automatically sets all others in the same RadioButtonGroup to "off".
40  *
41  * RadioButtons customarily have a distinct visual appearance from CheckBoxes:
42  *
43  * ( ) RadioButton 1
44  * (*) RadioButton 2
45  * ( ) RadioButton 3
46  *
47  * [ ] CheckBox 1
48  * [*] CheckBox 2
49  * [*] CheckBox 3
50  **/
51 class YRadioButton : public YWidget
52 {
53 protected:
54  /**
55  * Constructor.
56  *
57  * Creates a new RadioButton with user-visible text 'label'.
58  * 'label' can and should contain a keyboard shortcut (designated with
59  * '&').
60  *
61  * The caller has to take care to add this RadioButton to its
62  * RadioButtonGroup:
63  *
64  * if ( radioButton->buttonGroup() )
65  * radioButton->buttonGroup()->addRadioButton( radioButton );
66  *
67  * This can't be done in the constructor because it would involve calling a
68  * virtual function, which doesn't work yet within the constructor.
69  **/
70  YRadioButton( YWidget * parent, const std::string & label );
71 
72 public:
73  /**
74  * Destructor: Removes the button from the radio button group.
75  **/
76  virtual ~YRadioButton();
77 
78  /**
79  * Returns a descriptive name of this widget class for logging,
80  * debugging etc.
81  *
82  * Reimplemented from YWidget.
83  **/
84  virtual const char * widgetClass() const { return "YRadioButton"; }
85 
86  /**
87  * Get the current on/off value:
88  * 'true' if checked, 'false' if unchecked.
89  *
90  * Derived classes are required to implement this.
91  **/
92  virtual bool value() = 0;
93 
94  /**
95  * Set the radio button value (on/off).
96  *
97  * Derived classes are required to implement this.
98  **/
99  virtual void setValue( bool checked ) = 0;
100 
101  /**
102  * Get the label (the text on the RadioButton).
103  **/
104  std::string label() const;
105 
106  /**
107  * Set the label (the text on the RadioButton).
108  *
109  * Derived classes are free to reimplement this, but they should call this
110  * base class method at the end of the overloaded function.
111  **/
112  virtual void setLabel( const std::string & label );
113 
114  /**
115  * Returns 'true' if a bold font should be used.
116  **/
117  bool useBoldFont() const;
118 
119  /**
120  * Indicate whether or not a bold font should be used.
121  *
122  * Derived classes are free to reimplement this, but they should call this
123  * base class method at the end of the overloaded function.
124  **/
125  virtual void setUseBoldFont( bool bold = true );
126 
127  /**
128  * Get a pointer to the radio button group this button belongs to.
129  **/
131 
132  /**
133  * Set a property.
134  * Reimplemented from YWidget.
135  *
136  * This method may throw exceptions, for example
137  * - if there is no property with that name
138  * - if the expected type and the type mismatch
139  * - if the value is out of range
140  *
141  * This function returns 'true' if the value was successfully set and
142  * 'false' if that value requires special handling (not in error cases:
143  * those are covered by exceptions).
144  **/
145  virtual bool setProperty( const std::string & propertyName,
146  const YPropertyValue & val );
147 
148  /**
149  * Get a property.
150  * Reimplemented from YWidget.
151  *
152  * This method may throw exceptions, for example
153  * - if there is no property with that name
154  **/
155  virtual YPropertyValue getProperty( const std::string & propertyName );
156 
157  /**
158  * Return this class's property set.
159  * This also initializes the property set upon the first call.
160  *
161  * Reimplemented from YWidget.
162  **/
163  virtual const YPropertySet & propertySet();
164 
165  /**
166  * Get the string of this widget that holds the keyboard shortcut.
167  *
168  * Reimplemented from YWidget.
169  **/
170  virtual std::string shortcutString() const { return label(); }
171 
172  /**
173  * Set the string of this widget that holds the keyboard shortcut.
174  *
175  * Reimplemented from YWidget.
176  **/
177  virtual void setShortcutString( const std::string & str )
178  { setLabel( str ); }
179 
180  /**
181  * The name of the widget property that will return user input.
182  * Inherited from YWidget.
183  **/
184  const char * userInputProperty() { return YUIProperty_Value; }
185 
186 protected:
187  /**
188  * Traverse the widget hierarchy upwards to find the corresponding
189  * YRadioButtonGroup, i.e. the class that controls the radio box behaviour
190  * (i.e. that makes sure that no more than one RadioButton is set to "on"
191  * at the same time).
192  **/
194 
195  /**
196  * Save the widget's user input to a macro recorder.
197  *
198  * Reimplemented from YWidget because only radio buttons that are on (no
199  * more than one per radio box) are recorded.
200  **/
201  virtual void saveUserInput( YMacroRecorder *macroRecorder );
202 
203 private:
204 
206 };
207 
208 
209 #endif // YRadioButton_h
RadioButton: Widget for one-out-of-many selection.
Definition: YRadioButton.h:51
Abstract base class for macro recorders.
virtual void setLabel(const std::string &label)
Set the label (the text on the RadioButton).
Definition: YRadioButton.cc:87
virtual ~YRadioButton()
Destructor: Removes the button from the radio button group.
Definition: YRadioButton.cc:77
Transport class for the value of simple properties.
Definition: YProperty.h:104
virtual void setUseBoldFont(bool bold=true)
Indicate whether or not a bold font should be used.
A group of YRadioButton widgets.
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 useBoldFont() const
Returns &#39;true&#39; if a bold font should be used.
Definition: YRadioButton.cc:99
YRadioButtonGroup * buttonGroup()
Get a pointer to the radio button group this button belongs to.
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YRadioButton.h:170
virtual bool value()=0
Get the current on/off value: &#39;true&#39; if checked, &#39;false&#39; if unchecked.
YRadioButton(YWidget *parent, const std::string &label)
Constructor.
Definition: YRadioButton.cc:60
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YRadioButton.h:177
YRadioButtonGroup * findRadioButtonGroup() const
Traverse the widget hierarchy upwards to find the corresponding YRadioButtonGroup, i.e.
std::string label() const
Get the label (the text on the RadioButton).
Definition: YRadioButton.cc:93
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
virtual void setValue(bool checked)=0
Set the radio button value (on/off).
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YRadioButton.h:84
virtual void saveUserInput(YMacroRecorder *macroRecorder)
Save the widget&#39;s user input to a macro recorder.
const char * userInputProperty()
The name of the widget property that will return user input.
Definition: YRadioButton.h:184
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Abstract base class of all UI widgets.
Definition: YWidget.h:54