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: YInputField.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YInputField_h 00026 #define YInputField_h 00027 00028 #include <string> 00029 #include "YWidget.h" 00030 00031 class YInputFieldPrivate; 00032 00033 00034 00035 /** 00036 * InputField: General purpose one line input field for entering text and other 00037 * data. Can be used for entering passwords with a "*" echoed for every 00038 * character typed. 00039 * 00040 * Like most widgets, the InputField has a label (a caption) above the input 00041 * field itself. The label can and should get a keyboard shortcut (specified 00042 * with '&') that will make the input field receive the keyboard focus with a 00043 * special key combination ("&Name" -> Alt-N or Ctrl-N will make the keyboard 00044 * focus jump to the corresponding input field). 00045 **/ 00046 class YInputField : public YWidget 00047 { 00048 protected: 00049 /** 00050 * Constructor. 00051 * 00052 * Create an input field with 'label' as the caption. 00053 * If 'passwordMode' is set, the input will be not be echoed as clear text. 00054 **/ 00055 YInputField( YWidget * parent, 00056 const std::string & label, 00057 bool passwordMode = false ); 00058 00059 public: 00060 /** 00061 * Destructor. 00062 **/ 00063 virtual ~YInputField(); 00064 00065 /** 00066 * Return a descriptive name of this widget class for logging, 00067 * debugging etc. 00068 **/ 00069 virtual const char * widgetClass() const; 00070 00071 /** 00072 * Get the current value (the text entered by the user or set from the 00073 * outside) of this input field. 00074 * 00075 * Derived classes are required to implement this. 00076 **/ 00077 virtual std::string value() = 0; 00078 00079 /** 00080 * Set the current value (the text entered by the user or set from the 00081 * outside) of this input field. 00082 * 00083 * Derived classes are required to implement this. 00084 **/ 00085 virtual void setValue( const std::string & text ) = 0; 00086 00087 /** 00088 * Get the label (the caption above the input field). 00089 **/ 00090 std::string label() const; 00091 00092 /** 00093 * Set the label (the caption above the input field). 00094 * 00095 * Derived classes are free to reimplement this, but they should call this 00096 * base class method at the end of the overloaded function. 00097 **/ 00098 virtual void setLabel( const std::string & label ); 00099 00100 /** 00101 * Returns 'true' if this input field is in password mode, i.e. if there 00102 * should be no on-screen echo or only a '*' for each character typed. 00103 * 00104 * Notice that this can only be set in the constructor. 00105 **/ 00106 bool passwordMode() const; 00107 00108 /** 00109 * Get the valid input characters. No input validation is performed (i.e., 00110 * the user can enter anything) if this is empty. 00111 **/ 00112 std::string validChars(); 00113 00114 /** 00115 * Set the valid input characters. No input validation is performed (i.e., 00116 * the user can enter anything) if this is empty. 00117 * 00118 * Derived classes are free to reimplement this, but they should call this 00119 * base class method at the end of the overloaded function. 00120 **/ 00121 virtual void setValidChars( const std::string & validChars ); 00122 00123 /** 00124 * The maximum input length, i.e., the maximum number of characters the 00125 * user can enter. -1 means no limit. 00126 **/ 00127 int inputMaxLength() const; 00128 00129 /** 00130 * Set the maximum input length, i.e., the maximum number of characters the 00131 * user can enter. -1 means no limit. 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 setInputMaxLength( int numberOfChars ); 00137 00138 /** 00139 * Return 'true' if this InputField should be very small. 00140 **/ 00141 bool shrinkable() const; 00142 00143 /** 00144 * Make this InputField very small. This will take effect only upon the 00145 * next geometry management run. 00146 * 00147 * Derived classes can overwrite this, but should call this base class 00148 * function in the new function. 00149 **/ 00150 virtual void setShrinkable( bool shrinkable = true ); 00151 00152 /** 00153 * Set a property. 00154 * Reimplemented from YWidget. 00155 * 00156 * This function may throw YUIPropertyExceptions. 00157 * 00158 * This function returns 'true' if the value was successfully set and 00159 * 'false' if that value requires special handling (not in error cases: 00160 * those are covered by exceptions). 00161 **/ 00162 virtual bool setProperty( const std::string & propertyName, 00163 const YPropertyValue & val ); 00164 00165 /** 00166 * Get a property. 00167 * Reimplemented from YWidget. 00168 * 00169 * This method may throw YUIPropertyExceptions. 00170 **/ 00171 virtual YPropertyValue getProperty( const std::string & propertyName ); 00172 00173 /** 00174 * Return this class's property set. 00175 * This also initializes the property upon the first call. 00176 * 00177 * Reimplemented from YWidget. 00178 **/ 00179 virtual const YPropertySet & propertySet(); 00180 00181 /** 00182 * Get the string of this widget that holds the keyboard shortcut. 00183 * 00184 * Reimplemented from YWidget. 00185 **/ 00186 virtual std::string shortcutString() const { return label(); } 00187 00188 /** 00189 * Set the string of this widget that holds the keyboard shortcut. 00190 * 00191 * Reimplemented from YWidget. 00192 **/ 00193 virtual void setShortcutString( const std::string & str ) 00194 { setLabel( str ); } 00195 00196 /** 00197 * The name of the widget property that will return user input. 00198 * Inherited from YWidget. 00199 **/ 00200 const char * userInputProperty() { return YUIProperty_Value; } 00201 00202 /** 00203 * Save the widget's user input to a macro recorder. 00204 * 00205 * Reimplemented from YWidget to avoid recording passwords. 00206 **/ 00207 virtual void saveUserInput( YMacroRecorder *macroRecorder ); 00208 00209 private: 00210 00211 ImplPtr<YInputFieldPrivate> priv; 00212 }; 00213 00214 00215 #endif // YInputField_h