1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTextValidator
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 Styles used by wxTextValidator.
13 enum wxTextValidatorStyle
15 /// No filtering takes place.
18 /// Non-ASCII characters are filtered out. See wxString::IsAscii.
21 /// Non-alpha characters are filtered out.
22 /// Uses the wxWidgets wrapper for the standard CRT function @c isalpha
23 /// (which is locale-dependent) on all characters of the string.
26 /// Non-alphanumeric characters are filtered out.
27 /// Uses the wxWidgets wrapper for the standard CRT function @c isalnum
28 /// (which is locale-dependent) on all characters of the string.
29 wxFILTER_ALPHANUMERIC
,
31 /// Non-numeric characters are filtered out.
32 /// Uses the wxWidgets wrapper for the standard CRT function @c isdigit
33 /// (which is locale-dependent) on all characters of the string.
34 wxFILTER_SIMPLE_NUMBER
,
36 /// Non-numeric characters are filtered out.
37 /// Works like @c wxFILTER_SIMPLE_NUMBER but allows also decimal points,
38 /// minus/plus signs and the 'e' or 'E' character to input exponents.
39 /// Note that this is not the same behaviour of wxString::IsNumber().
42 /// Use an include list. The validator checks if the user input is on
43 /// the list, complaining if not. See wxTextValidator::SetIncludes().
44 wxFILTER_INCLUDE_LIST
,
46 /// Use an exclude list. The validator checks if the user input is on
47 /// the list, complaining if it is. See wxTextValidator::SetExcludes().
48 wxFILTER_EXCLUDE_LIST
,
50 /// Use an include list. The validator checks if each input character is
51 /// in the list (one character per list element), complaining if not.
52 /// See wxTextValidator::SetCharIncludes().
53 wxFILTER_INCLUDE_CHAR_LIST
,
55 /// Use an exclude list. The validator checks if each input character is
56 /// in the list (one character per list element), complaining if it is.
57 /// See wxTextValidator::SetCharExcludes().
58 wxFILTER_EXCLUDE_CHAR_LIST
62 @class wxTextValidator
64 wxTextValidator validates text controls, providing a variety of filtering
67 For more information, please see @ref overview_validator.
72 @see @ref overview_validator, wxValidator, wxGenericValidator
74 class wxTextValidator
: public wxValidator
80 wxTextValidator(const wxTextValidator
& validator
);
83 Constructor taking a style and optional pointer to a wxString variable.
86 One of the ::wxTextValidatorStyle styles.
88 A pointer to a wxString variable that contains the value. This
89 variable should have a lifetime equal to or longer than the
90 validator lifetime (which is usually determined by the lifetime of
93 wxTextValidator(wxTextValidatorStyle style
= wxFILTER_NONE
, wxString
* valPtr
= NULL
);
96 Clones the text validator using the copy constructor.
98 virtual wxObject
* Clone() const;
101 Returns a reference to the exclude list (the list of invalid values).
103 wxArrayString
& GetExcludes();
106 Returns a reference to the include list (the list of valid values).
108 wxArrayString
& GetIncludes();
111 Returns the validator style.
113 wxTextValidatorStyle
GetStyle() const;
116 Receives character input from the window and filters it according to
117 the current validator style.
119 void OnChar(wxKeyEvent
& event
);
122 Sets the exclude list (invalid values for the user input).
124 void SetExcludes(const wxArrayString
& stringList
);
127 Breaks the given @a chars strings in single characters and sets the
128 internal wxArrayString used to store the "excluded" characters
131 This function is mostly useful when @c wxFILTER_EXCLUDE_CHAR_LIST was used.
133 void SetCharExcludes(const wxString
& chars
);
136 Sets the include list (valid values for the user input).
138 void SetIncludes(const wxArrayString
& stringList
);
141 Breaks the given @a chars strings in single characters and sets the
142 internal wxArrayString used to store the "included" characters
145 This function is mostly useful when @c wxFILTER_INCLUDE_CHAR_LIST was used.
147 void SetCharIncludes(const wxString
& chars
);
150 Sets the validator style.
152 void SetStyle(wxTextValidatorStyle style
);
155 Transfers the value in the text control to the string.
157 virtual bool TransferFromWindow();
160 Transfers the string value to the text control.
162 virtual bool TransferToWindow();
165 Validates the window contents against the include or exclude lists,
166 depending on the validator style.
168 virtual bool Validate(wxWindow
* parent
);