]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/valtext.h
remove ancient defines left over from GTK1
[wxWidgets.git] / interface / wx / valtext.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: valtext.h
e54c96f1 3// Purpose: interface of wxTextValidator
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
40ae9600
FM
8
9/**
10 Styles used by wxTextValidator.
58fa61db
FM
11
12 Note that when you specify more styles in wxTextValidator the validation checks
13 are performed in the order in which the styles of this enumeration are defined.
40ae9600
FM
14*/
15enum wxTextValidatorStyle
16{
17 /// No filtering takes place.
18 wxFILTER_NONE,
19
58fa61db
FM
20 /// Empty strings are filtered out.
21 /// If this style is not specified then empty strings are accepted
22 /// only if they pass the other checks (if you use more than one wxTextValidatorStyle).
23 wxFILTER_EMPTY,
24
1406dc01 25 /// Non-ASCII characters are filtered out. See wxString::IsAscii.
40ae9600
FM
26 wxFILTER_ASCII,
27
28 /// Non-alpha characters are filtered out.
1406dc01
FM
29 /// Uses the wxWidgets wrapper for the standard CRT function @c isalpha
30 /// (which is locale-dependent) on all characters of the string.
40ae9600
FM
31 wxFILTER_ALPHA,
32
33 /// Non-alphanumeric characters are filtered out.
1406dc01
FM
34 /// Uses the wxWidgets wrapper for the standard CRT function @c isalnum
35 /// (which is locale-dependent) on all characters of the string.
40ae9600
FM
36 wxFILTER_ALPHANUMERIC,
37
38 /// Non-numeric characters are filtered out.
1406dc01
FM
39 /// Uses the wxWidgets wrapper for the standard CRT function @c isdigit
40 /// (which is locale-dependent) on all characters of the string.
58fa61db 41 wxFILTER_DIGITS,
1406dc01
FM
42
43 /// Non-numeric characters are filtered out.
f73785b1 44 /// Works like @c wxFILTER_DIGITS but allows also decimal points,
1406dc01
FM
45 /// minus/plus signs and the 'e' or 'E' character to input exponents.
46 /// Note that this is not the same behaviour of wxString::IsNumber().
40ae9600
FM
47 wxFILTER_NUMERIC,
48
49 /// Use an include list. The validator checks if the user input is on
50 /// the list, complaining if not. See wxTextValidator::SetIncludes().
51 wxFILTER_INCLUDE_LIST,
52
40ae9600
FM
53 /// Use an include list. The validator checks if each input character is
54 /// in the list (one character per list element), complaining if not.
fcd209b6 55 /// See wxTextValidator::SetCharIncludes().
40ae9600
FM
56 wxFILTER_INCLUDE_CHAR_LIST,
57
58fa61db
FM
58 /// Use an exclude list. The validator checks if the user input is on
59 /// the list, complaining if it is. See wxTextValidator::SetExcludes().
60 wxFILTER_EXCLUDE_LIST,
61
fcd209b6 62 /// Use an exclude list. The validator checks if each input character is
40ae9600 63 /// in the list (one character per list element), complaining if it is.
fcd209b6 64 /// See wxTextValidator::SetCharExcludes().
40ae9600
FM
65 wxFILTER_EXCLUDE_CHAR_LIST
66};
67
23324ae1
FM
68/**
69 @class wxTextValidator
7c913512 70
23324ae1
FM
71 wxTextValidator validates text controls, providing a variety of filtering
72 behaviours.
7c913512 73
fbec75d0
BP
74 For more information, please see @ref overview_validator.
75
23324ae1
FM
76 @library{wxcore}
77 @category{validator}
7c913512 78
a54cf371
VZ
79 @see @ref overview_validator, wxValidator, wxGenericValidator,
80 wxIntegerValidator, wxFloatingPointValidator
23324ae1
FM
81*/
82class wxTextValidator : public wxValidator
83{
84public:
23324ae1 85 /**
fbec75d0
BP
86 Default constructor.
87 */
88 wxTextValidator(const wxTextValidator& validator);
40ae9600 89
fbec75d0
BP
90 /**
91 Constructor taking a style and optional pointer to a wxString variable.
3c4f71cc 92
7c913512 93 @param style
58fa61db 94 One or more of the ::wxTextValidatorStyle styles. See SetStyle().
7c913512 95 @param valPtr
fbec75d0
BP
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
99 the window).
23324ae1 100 */
58fa61db 101 wxTextValidator(long style = wxFILTER_NONE, wxString* valPtr = NULL);
23324ae1
FM
102
103 /**
104 Clones the text validator using the copy constructor.
105 */
43c48e1e 106 virtual wxObject* Clone() const;
23324ae1
FM
107
108 /**
109 Returns a reference to the exclude list (the list of invalid values).
110 */
adaaa686 111 wxArrayString& GetExcludes();
23324ae1
FM
112
113 /**
114 Returns a reference to the include list (the list of valid values).
115 */
adaaa686 116 wxArrayString& GetIncludes();
23324ae1
FM
117
118 /**
119 Returns the validator style.
c78d8a70
FM
120
121 @see HasFlag()
23324ae1 122 */
58fa61db 123 long GetStyle() const;
23324ae1 124
c78d8a70
FM
125 /**
126 Returns @true if the given @a style bit is set in the current style.
127 */
128 bool HasFlag(wxTextValidatorStyle style) const;
129
23324ae1 130 /**
fbec75d0
BP
131 Receives character input from the window and filters it according to
132 the current validator style.
23324ae1
FM
133 */
134 void OnChar(wxKeyEvent& event);
135
136 /**
137 Sets the exclude list (invalid values for the user input).
138 */
139 void SetExcludes(const wxArrayString& stringList);
140
fcd209b6
FM
141 /**
142 Breaks the given @a chars strings in single characters and sets the
143 internal wxArrayString used to store the "excluded" characters
144 (see SetExcludes()).
145
146 This function is mostly useful when @c wxFILTER_EXCLUDE_CHAR_LIST was used.
147 */
148 void SetCharExcludes(const wxString& chars);
149
23324ae1
FM
150 /**
151 Sets the include list (valid values for the user input).
152 */
153 void SetIncludes(const wxArrayString& stringList);
154
fcd209b6
FM
155 /**
156 Breaks the given @a chars strings in single characters and sets the
157 internal wxArrayString used to store the "included" characters
158 (see SetIncludes()).
159
160 This function is mostly useful when @c wxFILTER_INCLUDE_CHAR_LIST was used.
161 */
162 void SetCharIncludes(const wxString& chars);
163
23324ae1 164 /**
58fa61db
FM
165 Sets the validator style which must be a combination of one or more
166 of the ::wxTextValidatorStyle values.
167
168 Note that not all possible combinations make sense!
c78d8a70
FM
169 Also note that the order in which the checks are performed is important,
170 in case you specify more than a single style.
171 wxTextValidator will perform the checks in the same definition order
172 used in the ::wxTextValidatorStyle enumeration.
23324ae1 173 */
58fa61db 174 void SetStyle(long style);
23324ae1
FM
175
176 /**
177 Transfers the value in the text control to the string.
178 */
179 virtual bool TransferFromWindow();
180
181 /**
182 Transfers the string value to the text control.
183 */
184 virtual bool TransferToWindow();
185
186 /**
fbec75d0
BP
187 Validates the window contents against the include or exclude lists,
188 depending on the validator style.
23324ae1
FM
189 */
190 virtual bool Validate(wxWindow* parent);
c78d8a70
FM
191
192protected:
193
194 /**
195 Returns @true if all the characters of the given @a val string
196 are present in the include list (set by SetIncludes() or SetCharIncludes()).
197 */
198 bool ContainsOnlyIncludedCharacters(const wxString& val) const;
199
200 /**
201 Returns true if at least one character of the given @a val string
202 is present in the exclude list (set by SetExcludes() or SetCharExcludes()).
203 */
204 bool ContainsExcludedCharacters(const wxString& val) const;
205
206 /**
207 Returns the error message if the contents of @a val are invalid
208 or the empty string if @a val is valid.
209 */
210 virtual wxString IsValid(const wxString& val) const;
23324ae1 211};
e54c96f1 212