2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: valtext.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxTextValidator
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-09 07:43:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Styles used by wxTextValidator.
|
2009-02-03 16:21:47 -05:00
|
|
|
|
|
|
|
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.
|
2009-01-09 07:43:20 -05:00
|
|
|
*/
|
|
|
|
enum wxTextValidatorStyle
|
|
|
|
{
|
|
|
|
/// No filtering takes place.
|
|
|
|
wxFILTER_NONE,
|
|
|
|
|
2009-02-03 16:21:47 -05:00
|
|
|
/// 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,
|
|
|
|
|
2009-01-31 16:27:27 -05:00
|
|
|
/// Non-ASCII characters are filtered out. See wxString::IsAscii.
|
2009-01-09 07:43:20 -05:00
|
|
|
wxFILTER_ASCII,
|
|
|
|
|
|
|
|
/// Non-alpha characters are filtered out.
|
2009-01-31 16:27:27 -05:00
|
|
|
/// Uses the wxWidgets wrapper for the standard CRT function @c isalpha
|
|
|
|
/// (which is locale-dependent) on all characters of the string.
|
2009-01-09 07:43:20 -05:00
|
|
|
wxFILTER_ALPHA,
|
|
|
|
|
|
|
|
/// Non-alphanumeric characters are filtered out.
|
2009-01-31 16:27:27 -05:00
|
|
|
/// Uses the wxWidgets wrapper for the standard CRT function @c isalnum
|
|
|
|
/// (which is locale-dependent) on all characters of the string.
|
2009-01-09 07:43:20 -05:00
|
|
|
wxFILTER_ALPHANUMERIC,
|
|
|
|
|
|
|
|
/// Non-numeric characters are filtered out.
|
2009-01-31 16:27:27 -05:00
|
|
|
/// Uses the wxWidgets wrapper for the standard CRT function @c isdigit
|
|
|
|
/// (which is locale-dependent) on all characters of the string.
|
2009-02-03 16:21:47 -05:00
|
|
|
wxFILTER_DIGITS,
|
2009-01-31 16:27:27 -05:00
|
|
|
|
|
|
|
/// Non-numeric characters are filtered out.
|
|
|
|
/// Works like @c wxFILTER_SIMPLE_NUMBER 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().
|
2009-01-09 07:43:20 -05:00
|
|
|
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.
|
2009-01-31 17:41:51 -05:00
|
|
|
/// See wxTextValidator::SetCharIncludes().
|
2009-01-09 07:43:20 -05:00
|
|
|
wxFILTER_INCLUDE_CHAR_LIST,
|
|
|
|
|
2009-02-03 16:21:47 -05:00
|
|
|
/// 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,
|
|
|
|
|
2009-01-31 17:41:51 -05:00
|
|
|
/// Use an exclude list. The validator checks if each input character is
|
2009-01-09 07:43:20 -05:00
|
|
|
/// in the list (one character per list element), complaining if it is.
|
2009-01-31 17:41:51 -05:00
|
|
|
/// See wxTextValidator::SetCharExcludes().
|
2009-01-09 07:43:20 -05:00
|
|
|
wxFILTER_EXCLUDE_CHAR_LIST
|
|
|
|
};
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxTextValidator
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxTextValidator validates text controls, providing a variety of filtering
|
|
|
|
behaviours.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
For more information, please see @ref overview_validator.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{validator}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
@see @ref overview_validator, wxValidator, wxGenericValidator
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxTextValidator : public wxValidator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxTextValidator(const wxTextValidator& validator);
|
2009-01-09 07:43:20 -05:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
/**
|
|
|
|
Constructor taking a style and optional pointer to a wxString variable.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param style
|
2009-02-03 16:21:47 -05:00
|
|
|
One or more of the ::wxTextValidatorStyle styles. See SetStyle().
|
2008-03-08 09:43:31 -05:00
|
|
|
@param valPtr
|
2008-04-22 02:01:48 -04:00
|
|
|
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).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-02-03 16:21:47 -05:00
|
|
|
wxTextValidator(long style = wxFILTER_NONE, wxString* valPtr = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Clones the text validator using the copy constructor.
|
|
|
|
*/
|
2008-10-28 11:36:26 -04:00
|
|
|
virtual wxObject* Clone() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a reference to the exclude list (the list of invalid values).
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
wxArrayString& GetExcludes();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a reference to the include list (the list of valid values).
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
wxArrayString& GetIncludes();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the validator style.
|
2009-02-05 13:50:43 -05:00
|
|
|
|
|
|
|
@see HasFlag()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-02-03 16:21:47 -05:00
|
|
|
long GetStyle() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-02-05 13:50:43 -05:00
|
|
|
/**
|
|
|
|
Returns @true if the given @a style bit is set in the current style.
|
|
|
|
*/
|
|
|
|
bool HasFlag(wxTextValidatorStyle style) const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
Receives character input from the window and filters it according to
|
|
|
|
the current validator style.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void OnChar(wxKeyEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the exclude list (invalid values for the user input).
|
|
|
|
*/
|
|
|
|
void SetExcludes(const wxArrayString& stringList);
|
|
|
|
|
2009-01-31 17:41:51 -05:00
|
|
|
/**
|
|
|
|
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);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Sets the include list (valid values for the user input).
|
|
|
|
*/
|
|
|
|
void SetIncludes(const wxArrayString& stringList);
|
|
|
|
|
2009-01-31 17:41:51 -05:00
|
|
|
/**
|
|
|
|
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);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2009-02-03 16:21:47 -05:00
|
|
|
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!
|
2009-02-05 13:50:43 -05:00
|
|
|
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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-02-03 16:21:47 -05:00
|
|
|
void SetStyle(long style);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Transfers the value in the text control to the string.
|
|
|
|
*/
|
|
|
|
virtual bool TransferFromWindow();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Transfers the string value to the text control.
|
|
|
|
*/
|
|
|
|
virtual bool TransferToWindow();
|
|
|
|
|
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
Validates the window contents against the include or exclude lists,
|
|
|
|
depending on the validator style.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
virtual bool Validate(wxWindow* parent);
|
2009-02-05 13:50:43 -05:00
|
|
|
|
|
|
|
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;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|