libyui
3.0.10
|
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: YCheckBox.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YCheckBox_h 00026 #define YCheckBox_h 00027 00028 #include <string> 00029 00030 #include "YWidget.h" 00031 #include "ImplPtr.h" 00032 00033 class YCheckBoxPrivate; 00034 00035 enum YCheckBoxState 00036 { 00037 YCheckBox_dont_care = -1, // tristate 00038 YCheckBox_off = 0, 00039 YCheckBox_on = 1 00040 }; 00041 00042 00043 class YCheckBox : public YWidget 00044 { 00045 protected: 00046 /** 00047 * Constructor. 00048 **/ 00049 YCheckBox( YWidget * parent, const std::string & label ); 00050 00051 public: 00052 /** 00053 * Destructor. 00054 **/ 00055 virtual ~YCheckBox(); 00056 00057 /** 00058 * Returns a descriptive name of this widget class for logging, 00059 * debugging etc. 00060 **/ 00061 virtual const char * widgetClass() const { return "YCheckBox"; } 00062 00063 00064 /** 00065 * Get the current value: 00066 * 00067 * YCheckBox_on CheckBox is checked 00068 * YCheckBox_off CheckBox is unchecked 00069 * 00070 * YCheckBox_dont_care tri-state: CheckBox is greyed out, 00071 * neither checked nor unchecked 00072 * 00073 * The user cannot set YCheckBox_dont_care directly. This status is always 00074 * only set from the outside, usually because a setting cannot be clearly 00075 * determined. For example, a checkbox 00076 * 00077 * [ ] Read only 00078 * 00079 * would be set to "don't care" (by the application, not directly by the 00080 * user) when it is to display the read-only state of a group of files 00081 * where some are read-only and some are writeable. 00082 * 00083 * Derived classes are required to implement this function. 00084 * (Intentionally not const) 00085 **/ 00086 virtual YCheckBoxState value() = 0; 00087 00088 /** 00089 * Set the CheckBox value (on/off/don't care). 00090 * 00091 * Derived classes are required to implement this. 00092 **/ 00093 virtual void setValue( YCheckBoxState state ) = 0; 00094 00095 /** 00096 * Simplified access to value(): Return 'true' if the CheckBox is checked. 00097 **/ 00098 bool isChecked() { return value() == YCheckBox_on; } 00099 00100 /** 00101 * Simplified access to setValue(): Check of uncheck the CheckBox. 00102 **/ 00103 void setChecked( bool checked = true ) 00104 { setValue( checked ? YCheckBox_on : YCheckBox_off ); } 00105 00106 /** 00107 * Simplified access to tri-state ("don't care"). 00108 **/ 00109 bool dontCare() { return value() == YCheckBox_dont_care; } 00110 00111 /** 00112 * Simplified access to setting tri-state ("don't care"). 00113 **/ 00114 void setDontCare() { setValue( YCheckBox_dont_care ); } 00115 00116 /** 00117 * Get the label (the text on the CheckBox). 00118 **/ 00119 std::string label() const; 00120 00121 /** 00122 * Set the label (the text on the CheckBox). 00123 * 00124 * Derived classes are free to reimplement this, but they should call this 00125 * base class method at the end of the overloaded function. 00126 **/ 00127 virtual void setLabel( const std::string & label ); 00128 00129 /** 00130 * Returns 'true' if a bold font should be used. 00131 **/ 00132 bool useBoldFont() const; 00133 00134 /** 00135 * Indicate whether or not a bold font should be used. 00136 * 00137 * Derived classes are free to reimplement this, but they should call this 00138 * base class method at the end of the overloaded function. 00139 **/ 00140 virtual void setUseBoldFont( bool bold = true ); 00141 00142 /** 00143 * Set a property. 00144 * Reimplemented from YWidget. 00145 * 00146 * This method may throw exceptions, for example 00147 * - if there is no property with that name 00148 * - if the expected type and the type mismatch 00149 * - if the value is out of range 00150 * 00151 * This function returns 'true' if the value was successfully set and 00152 * 'false' if that value requires special handling (not in error cases: 00153 * those are covered by exceptions). 00154 **/ 00155 virtual bool setProperty( const std::string & propertyName, 00156 const YPropertyValue & val ); 00157 00158 /** 00159 * Get a property. 00160 * Reimplemented from YWidget. 00161 * 00162 * This method may throw exceptions, for example 00163 * - if there is no property with that name 00164 **/ 00165 virtual YPropertyValue getProperty( const std::string & propertyName ); 00166 00167 /** 00168 * Return this class's property set. 00169 * This also initializes the property set upon the first call. 00170 * 00171 * Reimplemented from YWidget. 00172 **/ 00173 virtual const YPropertySet & propertySet(); 00174 00175 /** 00176 * Get the string of this widget that holds the keyboard shortcut. 00177 * 00178 * Reimplemented from YWidget. 00179 **/ 00180 virtual std::string shortcutString() const { return label(); } 00181 00182 /** 00183 * Set the string of this widget that holds the keyboard shortcut. 00184 * 00185 * Reimplemented from YWidget. 00186 **/ 00187 virtual void setShortcutString( const std::string & str ) 00188 { setLabel( str ); } 00189 00190 /** 00191 * The name of the widget property that will return user input. 00192 * Inherited from YWidget. 00193 **/ 00194 const char * userInputProperty() { return YUIProperty_Value; } 00195 00196 00197 private: 00198 00199 ImplPtr<YCheckBoxPrivate> priv; 00200 }; 00201 00202 00203 #endif // YCheckBox_h