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