1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTextValidator
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 Styles used by wxTextValidator.
13 Note that when you specify more styles in wxTextValidator the validation checks
14 are performed in the order in which the styles of this enumeration are defined.
16 enum wxTextValidatorStyle
18 /// No filtering takes place.
21 /// Empty strings are filtered out.
22 /// If this style is not specified then empty strings are accepted
23 /// only if they pass the other checks (if you use more than one wxTextValidatorStyle).
26 /// Non-ASCII characters are filtered out. See wxString::IsAscii.
29 /// Non-alpha characters are filtered out.
30 /// Uses the wxWidgets wrapper for the standard CRT function @c isalpha
31 /// (which is locale-dependent) on all characters of the string.
34 /// Non-alphanumeric characters are filtered out.
35 /// Uses the wxWidgets wrapper for the standard CRT function @c isalnum
36 /// (which is locale-dependent) on all characters of the string.
37 wxFILTER_ALPHANUMERIC
,
39 /// Non-numeric characters are filtered out.
40 /// Uses the wxWidgets wrapper for the standard CRT function @c isdigit
41 /// (which is locale-dependent) on all characters of the string.
44 /// Non-numeric characters are filtered out.
45 /// Works like @c wxFILTER_SIMPLE_NUMBER but allows also decimal points,
46 /// minus/plus signs and the 'e' or 'E' character to input exponents.
47 /// Note that this is not the same behaviour of wxString::IsNumber().
50 /// Use an include list. The validator checks if the user input is on
51 /// the list, complaining if not. See wxTextValidator::SetIncludes().
52 wxFILTER_INCLUDE_LIST
,
54 /// Use an include list. The validator checks if each input character is
55 /// in the list (one character per list element), complaining if not.
56 /// See wxTextValidator::SetCharIncludes().
57 wxFILTER_INCLUDE_CHAR_LIST
,
59 /// Use an exclude list. The validator checks if the user input is on
60 /// the list, complaining if it is. See wxTextValidator::SetExcludes().
61 wxFILTER_EXCLUDE_LIST
,
63 /// Use an exclude list. The validator checks if each input character is
64 /// in the list (one character per list element), complaining if it is.
65 /// See wxTextValidator::SetCharExcludes().
66 wxFILTER_EXCLUDE_CHAR_LIST
70 @class wxTextValidator
72 wxTextValidator validates text controls, providing a variety of filtering
75 For more information, please see @ref overview_validator.
80 @see @ref overview_validator, wxValidator, wxGenericValidator
82 class wxTextValidator
: public wxValidator
88 wxTextValidator(const wxTextValidator
& validator
);
91 Constructor taking a style and optional pointer to a wxString variable.
94 One or more of the ::wxTextValidatorStyle styles. See SetStyle().
96 A pointer to a wxString variable that contains the value. This
97 variable should have a lifetime equal to or longer than the
98 validator lifetime (which is usually determined by the lifetime of
101 wxTextValidator(long style
= wxFILTER_NONE
, wxString
* valPtr
= NULL
);
104 Clones the text validator using the copy constructor.
106 virtual wxObject
* Clone() const;
109 Returns a reference to the exclude list (the list of invalid values).
111 wxArrayString
& GetExcludes();
114 Returns a reference to the include list (the list of valid values).
116 wxArrayString
& GetIncludes();
119 Returns the validator style.
121 long GetStyle() const;
124 Receives character input from the window and filters it according to
125 the current validator style.
127 void OnChar(wxKeyEvent
& event
);
130 Sets the exclude list (invalid values for the user input).
132 void SetExcludes(const wxArrayString
& stringList
);
135 Breaks the given @a chars strings in single characters and sets the
136 internal wxArrayString used to store the "excluded" characters
139 This function is mostly useful when @c wxFILTER_EXCLUDE_CHAR_LIST was used.
141 void SetCharExcludes(const wxString
& chars
);
144 Sets the include list (valid values for the user input).
146 void SetIncludes(const wxArrayString
& stringList
);
149 Breaks the given @a chars strings in single characters and sets the
150 internal wxArrayString used to store the "included" characters
153 This function is mostly useful when @c wxFILTER_INCLUDE_CHAR_LIST was used.
155 void SetCharIncludes(const wxString
& chars
);
158 Sets the validator style which must be a combination of one or more
159 of the ::wxTextValidatorStyle values.
161 Note that not all possible combinations make sense!
163 void SetStyle(long style
);
166 Transfers the value in the text control to the string.
168 virtual bool TransferFromWindow();
171 Transfers the string value to the text control.
173 virtual bool TransferToWindow();
176 Validates the window contents against the include or exclude lists,
177 depending on the validator style.
179 virtual bool Validate(wxWindow
* parent
);