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: YIntField.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YIntField_h 00026 #define YIntField_h 00027 00028 #include "YWidget.h" 00029 00030 class YIntFieldPrivate; 00031 00032 00033 00034 /** 00035 * IntField: Input field for integer values. Enforces input range between a 00036 * specified minimum and maximum value. 00037 **/ 00038 class YIntField : public YWidget 00039 { 00040 protected: 00041 /** 00042 * Constructor. 00043 * 00044 * Create an IntField with 'label' as the caption, and the specified minimum 00045 * and maximum values. 00046 * 00047 * Note that YWidgetFactory::createIntField() also has an 'initialValue' 00048 * parameter that is not used here (because the current value is not stored 00049 * in this base class, but in the derived class). 00050 **/ 00051 YIntField( YWidget * parent, 00052 const std::string & label, 00053 int minValue, 00054 int maxValue ); 00055 00056 public: 00057 /** 00058 * Destructor. 00059 **/ 00060 virtual ~YIntField(); 00061 00062 /** 00063 * Return a descriptive name of this widget class for logging, 00064 * debugging etc. 00065 **/ 00066 virtual const char * widgetClass() const { return "YIntField"; } 00067 00068 /** 00069 * Get the current value (the number entered by the user or set from the 00070 * outside) of this IntField. 00071 * 00072 * Derived classes are required to implement this. 00073 **/ 00074 virtual int value() = 0; 00075 00076 /** 00077 * Set the current value (the number entered by the user or set from the 00078 * outside) of this IntField. This method enforces 'val to be between 00079 * minValue and maxValue. 00080 **/ 00081 void setValue( int val ) { setValueInternal( enforceRange( val ) ); } 00082 00083 protected: 00084 00085 /** 00086 * Set the current value (the number entered by the user or set from the 00087 * outside) of this IntField. 'val' is guaranteed to be between minValue 00088 * and maxValue; no further checks are required. 00089 * 00090 * Derived classes are required to implement this method. 00091 **/ 00092 virtual void setValueInternal( int val ) = 0; 00093 00094 /** 00095 * Enforce 'val' to be between minValue and maxValue. 00096 * Return a value that is in range. This does not change the internally 00097 * stored value of this IntField in any way. 00098 **/ 00099 int enforceRange( int val ) const; 00100 00101 public: 00102 00103 /** 00104 * Return the minimum value. 00105 **/ 00106 int minValue() const; 00107 00108 /** 00109 * Set a new minimum value. If the current value is less than that, it will 00110 * be set to the new minimum. 00111 **/ 00112 void setMinValue( int val ); 00113 00114 /** 00115 * Return the maximum value. 00116 **/ 00117 int maxValue() const; 00118 00119 /** 00120 * Set a new maximum value. If the current value is greater than that, it 00121 * will be set to the new maximum. 00122 **/ 00123 void setMaxValue( int val ); 00124 00125 /** 00126 * Get the label (the caption above the input field). 00127 **/ 00128 std::string label() const; 00129 00130 /** 00131 * Set the label (the caption above the input field). 00132 * 00133 * Derived classes are free to reimplement this, but they should call this 00134 * base class method at the end of the overloaded function. 00135 **/ 00136 virtual void setLabel( const std::string & label ); 00137 00138 /** 00139 * Set a property. 00140 * Reimplemented from YWidget. 00141 * 00142 * This function may throw YUIPropertyExceptions. 00143 * 00144 * This function returns 'true' if the value was successfully set and 00145 * 'false' if that value requires special handling (not in error cases: 00146 * those are covered by exceptions). 00147 **/ 00148 virtual bool setProperty( const std::string & propertyName, 00149 const YPropertyValue & val ); 00150 00151 /** 00152 * Get a property. 00153 * Reimplemented from YWidget. 00154 * 00155 * This method may throw YUIPropertyExceptions. 00156 **/ 00157 virtual YPropertyValue getProperty( const std::string & propertyName ); 00158 00159 /** 00160 * Return this class's property set. 00161 * This also initializes the property upon the first call. 00162 * 00163 * Reimplemented from YWidget. 00164 **/ 00165 virtual const YPropertySet & propertySet(); 00166 00167 /** 00168 * Get the string of this widget that holds the keyboard shortcut. 00169 * 00170 * Reimplemented from YWidget. 00171 **/ 00172 virtual std::string shortcutString() const { return label(); } 00173 00174 /** 00175 * Set the string of this widget that holds the keyboard shortcut. 00176 * 00177 * Reimplemented from YWidget. 00178 **/ 00179 virtual void setShortcutString( const std::string & str ) 00180 { setLabel( str ); } 00181 00182 /** 00183 * The name of the widget property that will return user input. 00184 * Inherited from YWidget. 00185 **/ 00186 const char * userInputProperty() { return YUIProperty_Value; } 00187 00188 00189 private: 00190 00191 ImplPtr<YIntFieldPrivate> priv; 00192 }; 00193 00194 00195 #endif // YIntField_h