libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YRadioButton.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YRadioButton.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YRadioButton_h
00026 #define YRadioButton_h
00027 
00028 #include "YWidget.h"
00029 
00030 class YRadioButtonGroup;
00031 class YRadioButtonPrivate;
00032 
00033 
00034 /**
00035  * RadioButton: Widget for one-out-of-many selection.
00036  *
00037  * Only one RadioButton in a RadioBox (in a RadioButtonGroup) can be set to
00038  * "on" at the same time. Setting any RadioButton of a RadioButtonGroup to "on"
00039  * automatically sets all others in the same RadioButtonGroup to "off".
00040  *
00041  * RadioButtons customarily have a distinct visual appearance from CheckBoxes:
00042  *
00043  *     ( ) RadioButton 1
00044  *     (*) RadioButton 2
00045  *     ( ) RadioButton 3
00046  *
00047  *     [ ] CheckBox 1
00048  *     [*] CheckBox 2
00049  *     [*] CheckBox 3
00050  **/
00051 class YRadioButton : public YWidget
00052 {
00053 protected:
00054     /**
00055      * Constructor.
00056      *
00057      * Creates a new RadioButton with user-visible text 'label'.
00058      * 'label' can and should contain a keyboard shortcut (designated with
00059      * '&').
00060      *
00061      * The caller has to take care to add this RadioButton to its
00062      * RadioButtonGroup:
00063      *
00064      * if ( radioButton->buttonGroup() )
00065      *     radioButton->buttonGroup()->addRadioButton( radioButton );
00066      *
00067      * This can't be done in the constructor because it would involve calling a
00068      * virtual function, which doesn't work yet within the constructor.
00069      **/
00070     YRadioButton( YWidget * parent, const std::string & label );
00071 
00072 public:
00073     /**
00074      * Destructor: Removes the button from the radio button group.
00075      **/
00076     virtual ~YRadioButton();
00077 
00078     /**
00079      * Returns a descriptive name of this widget class for logging,
00080      * debugging etc.
00081      *
00082      * Reimplemented from YWidget.
00083      **/
00084     virtual const char * widgetClass() const { return "YRadioButton"; }
00085 
00086     /**
00087      * Get the current on/off value:
00088      * 'true' if checked, 'false' if unchecked.
00089      *
00090      * Derived classes are required to implement this.
00091      **/
00092     virtual bool value() = 0;
00093 
00094     /**
00095      * Set the radio button value (on/off).
00096      *
00097      * Derived classes are required to implement this.
00098      **/
00099     virtual void setValue( bool checked ) = 0;
00100 
00101     /**
00102      * Get the label (the text on the RadioButton).
00103      **/
00104     std::string label() const;
00105 
00106     /**
00107      * Set the label (the text on the RadioButton).
00108      *
00109      * Derived classes are free to reimplement this, but they should call this
00110      * base class method at the end of the overloaded function.
00111      **/
00112     virtual void setLabel( const std::string & label );
00113 
00114     /**
00115      * Returns 'true' if a bold font should be used.
00116      **/
00117     bool useBoldFont() const;
00118 
00119     /**
00120      * Indicate whether or not a bold font should be used.
00121      *
00122      * Derived classes are free to reimplement this, but they should call this
00123      * base class method at the end of the overloaded function.
00124      **/
00125     virtual void setUseBoldFont( bool bold = true );
00126 
00127     /**
00128      * Get a pointer to the radio button group this button belongs to.
00129      **/
00130     YRadioButtonGroup * buttonGroup();
00131 
00132     /**
00133      * Set a property.
00134      * Reimplemented from YWidget.
00135      *
00136      * This method may throw exceptions, for example
00137      *   - if there is no property with that name
00138      *   - if the expected type and the type mismatch
00139      *   - if the value is out of range
00140      *
00141      * This function returns 'true' if the value was successfully set and
00142      * 'false' if that value requires special handling (not in error cases:
00143      * those are covered by exceptions).
00144      **/
00145     virtual bool setProperty( const std::string & propertyName,
00146                               const YPropertyValue & val );
00147 
00148     /**
00149      * Get a property.
00150      * Reimplemented from YWidget.
00151      *
00152      * This method may throw exceptions, for example
00153      *   - if there is no property with that name
00154      **/
00155     virtual YPropertyValue getProperty( const std::string & propertyName );
00156 
00157     /**
00158      * Return this class's property set.
00159      * This also initializes the property set upon the first call.
00160      *
00161      * Reimplemented from YWidget.
00162      **/
00163     virtual const YPropertySet & propertySet();
00164 
00165     /**
00166      * Get the string of this widget that holds the keyboard shortcut.
00167      *
00168      * Reimplemented from YWidget.
00169      **/
00170     virtual std::string shortcutString() const { return label(); }
00171 
00172     /**
00173      * Set the string of this widget that holds the keyboard shortcut.
00174      *
00175      * Reimplemented from YWidget.
00176      **/
00177     virtual void setShortcutString( const std::string & str )
00178         { setLabel( str ); }
00179 
00180     /**
00181      * The name of the widget property that will return user input.
00182      * Inherited from YWidget.
00183      **/
00184     const char * userInputProperty() { return YUIProperty_Value; }
00185 
00186 protected:
00187     /**
00188      * Traverse the widget hierarchy upwards to find the corresponding
00189      * YRadioButtonGroup, i.e. the class that controls the radio box behaviour
00190      * (i.e. that makes sure that no more than one RadioButton is set to "on"
00191      * at the same time).
00192      **/
00193     YRadioButtonGroup * findRadioButtonGroup() const;
00194 
00195     /**
00196      * Save the widget's user input to a macro recorder.
00197      *
00198      * Reimplemented from YWidget because only radio buttons that are on (no
00199      * more than one per radio box) are recorded.
00200      **/
00201     virtual void saveUserInput( YMacroRecorder *macroRecorder );
00202 
00203 private:
00204 
00205     ImplPtr<YRadioButtonPrivate> priv;
00206 };
00207 
00208 
00209 #endif // YRadioButton_h
 All Classes Functions Variables Enumerations Friends