libyui  3.3.2
YInputField.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: YInputField.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YInputField_h
26 #define YInputField_h
27 
28 #include <string>
29 #include "YWidget.h"
30 
31 class YInputFieldPrivate;
32 
33 
34 
35 /**
36  * InputField: General purpose one line input field for entering text and other
37  * data. Can be used for entering passwords with a "*" echoed for every
38  * character typed.
39  *
40  * Like most widgets, the InputField has a label (a caption) above the input
41  * field itself. The label can and should get a keyboard shortcut (specified
42  * with '&') that will make the input field receive the keyboard focus with a
43  * special key combination ("&Name" -> Alt-N or Ctrl-N will make the keyboard
44  * focus jump to the corresponding input field).
45  **/
46 class YInputField : public YWidget
47 {
48 protected:
49  /**
50  * Constructor.
51  *
52  * Create an input field with 'label' as the caption.
53  * If 'passwordMode' is set, the input will be not be echoed as clear text.
54  **/
56  const std::string & label,
57  bool passwordMode = false );
58 
59 public:
60  /**
61  * Destructor.
62  **/
63  virtual ~YInputField();
64 
65  /**
66  * Return a descriptive name of this widget class for logging,
67  * debugging etc.
68  **/
69  virtual const char * widgetClass() const;
70 
71  /**
72  * Get the current value (the text entered by the user or set from the
73  * outside) of this input field.
74  *
75  * Derived classes are required to implement this.
76  **/
77  virtual std::string value() = 0;
78 
79  /**
80  * Set the current value (the text entered by the user or set from the
81  * outside) of this input field.
82  *
83  * Derived classes are required to implement this.
84  **/
85  virtual void setValue( const std::string & text ) = 0;
86 
87  /**
88  * Get the label (the caption above the input field).
89  **/
90  std::string label() const;
91 
92  /**
93  * Set the label (the caption above the input field).
94  *
95  * Derived classes are free to reimplement this, but they should call this
96  * base class method at the end of the overloaded function.
97  **/
98  virtual void setLabel( const std::string & label );
99 
100  /**
101  * Returns 'true' if this input field is in password mode, i.e. if there
102  * should be no on-screen echo or only a '*' for each character typed.
103  *
104  * Notice that this can only be set in the constructor.
105  **/
106  bool passwordMode() const;
107 
108  /**
109  * Get the valid input characters. No input validation is performed (i.e.,
110  * the user can enter anything) if this is empty.
111  **/
112  std::string validChars();
113 
114  /**
115  * Set the valid input characters. No input validation is performed (i.e.,
116  * the user can enter anything) if this is empty.
117  *
118  * Derived classes are free to reimplement this, but they should call this
119  * base class method at the end of the overloaded function.
120  **/
121  virtual void setValidChars( const std::string & validChars );
122 
123  /**
124  * The maximum input length, i.e., the maximum number of characters the
125  * user can enter. -1 means no limit.
126  **/
127  int inputMaxLength() const;
128 
129  /**
130  * Set the maximum input length, i.e., the maximum number of characters the
131  * user can enter. -1 means no limit.
132  *
133  * Derived classes are free to reimplement this, but they should call this
134  * base class method at the end of the overloaded function.
135  **/
136  virtual void setInputMaxLength( int numberOfChars );
137 
138  /**
139  * Return 'true' if this InputField should be very small.
140  **/
141  bool shrinkable() const;
142 
143  /**
144  * Make this InputField very small. This will take effect only upon the
145  * next geometry management run.
146  *
147  * Derived classes can overwrite this, but should call this base class
148  * function in the new function.
149  **/
150  virtual void setShrinkable( bool shrinkable = true );
151 
152  /**
153  * Set a property.
154  * Reimplemented from YWidget.
155  *
156  * This function may throw YUIPropertyExceptions.
157  *
158  * This function returns 'true' if the value was successfully set and
159  * 'false' if that value requires special handling (not in error cases:
160  * those are covered by exceptions).
161  **/
162  virtual bool setProperty( const std::string & propertyName,
163  const YPropertyValue & val );
164 
165  /**
166  * Get a property.
167  * Reimplemented from YWidget.
168  *
169  * This method may throw YUIPropertyExceptions.
170  **/
171  virtual YPropertyValue getProperty( const std::string & propertyName );
172 
173  /**
174  * Return this class's property set.
175  * This also initializes the property upon the first call.
176  *
177  * Reimplemented from YWidget.
178  **/
179  virtual const YPropertySet & propertySet();
180 
181  /**
182  * Get the string of this widget that holds the keyboard shortcut.
183  *
184  * Reimplemented from YWidget.
185  **/
186  virtual std::string shortcutString() const { return label(); }
187 
188  /**
189  * Set the string of this widget that holds the keyboard shortcut.
190  *
191  * Reimplemented from YWidget.
192  **/
193  virtual void setShortcutString( const std::string & str )
194  { setLabel( str ); }
195 
196  /**
197  * The name of the widget property that will return user input.
198  * Inherited from YWidget.
199  **/
200  const char * userInputProperty() { return YUIProperty_Value; }
201 
202  /**
203  * Save the widget's user input to a macro recorder.
204  *
205  * Reimplemented from YWidget to avoid recording passwords.
206  **/
207  virtual void saveUserInput( YMacroRecorder *macroRecorder );
208 
209 private:
210 
212 };
213 
214 
215 #endif // YInputField_h
Abstract base class for macro recorders.
virtual void setInputMaxLength(int numberOfChars)
Set the maximum input length, i.e., the maximum number of characters the user can enter...
Definition: YInputField.cc:119
virtual const char * widgetClass() const
Return a descriptive name of this widget class for logging, debugging etc.
Definition: YInputField.cc:194
bool passwordMode() const
Returns &#39;true&#39; if this input field is in password mode, i.e.
Definition: YInputField.cc:82
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YInputField.h:193
Transport class for the value of simple properties.
Definition: YProperty.h:104
std::string label() const
Get the label (the caption above the input field).
Definition: YInputField.cc:70
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YInputField.cc:150
const char * userInputProperty()
The name of the widget property that will return user input.
Definition: YInputField.h:200
virtual void setShrinkable(bool shrinkable=true)
Make this InputField very small.
Definition: YInputField.cc:94
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YInputField.cc:126
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
Definition: YInputField.cc:76
virtual std::string value()=0
Get the current value (the text entered by the user or set from the outside) of this input field...
int inputMaxLength() const
The maximum input length, i.e., the maximum number of characters the user can enter.
Definition: YInputField.cc:113
virtual void setValue(const std::string &text)=0
Set the current value (the text entered by the user or set from the outside) of this input field...
virtual void setValidChars(const std::string &validChars)
Set the valid input characters.
Definition: YInputField.cc:107
virtual void saveUserInput(YMacroRecorder *macroRecorder)
Save the widget&#39;s user input to a macro recorder.
Definition: YInputField.cc:184
YInputField(YWidget *parent, const std::string &label, bool passwordMode=false)
Constructor.
Definition: YInputField.cc:53
virtual ~YInputField()
Destructor.
Definition: YInputField.cc:64
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YInputField.cc:168
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YInputField.h:186
InputField: General purpose one line input field for entering text and other data.
Definition: YInputField.h:46
bool shrinkable() const
Return &#39;true&#39; if this InputField should be very small.
Definition: YInputField.cc:88
std::string validChars()
Get the valid input characters.
Definition: YInputField.cc:101
Abstract base class of all UI widgets.
Definition: YWidget.h:54