X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/adaaa68635b4c8a4d8c5284add40366ea3eefb07..6a3f8b4f1f1c802df93ce7bc05588536cb7a4dad:/interface/wx/valtext.h diff --git a/interface/wx/valtext.h b/interface/wx/valtext.h index 21527bc796..b96a580090 100644 --- a/interface/wx/valtext.h +++ b/interface/wx/valtext.h @@ -6,6 +6,66 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// + +/** + 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_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(). + 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 @@ -14,33 +74,6 @@ For more information, please see @ref overview_validator. - @beginStyleTable - @style{wxFILTER_NONE} - No filtering takes place. - @style{wxFILTER_ASCII} - Non-ASCII characters are filtered out. - @style{wxFILTER_ALPHA} - Non-alpha characters are filtered out. - @style{wxFILTER_ALPHANUMERIC} - Non-alphanumeric characters are filtered out. - @style{wxFILTER_NUMERIC} - Non-numeric characters are filtered out. - @style{wxFILTER_INCLUDE_LIST} - Use an include list. The validator checks if the user input is on - the list, complaining if not. See SetIncludes(). - @style{wxFILTER_EXCLUDE_LIST} - Use an exclude list. The validator checks if the user input is on - the list, complaining if it is. See SetExcludes(). - @style{wxFILTER_INCLUDE_CHAR_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 SetIncludes(). - @style{wxFILTER_EXCLUDE_CHAR_LIST} - Use an include list. The validator checks if each input character is - in the list (one character per list element), complaining if it is. - See SetExcludes(). - @endStyleTable - @library{wxcore} @category{validator} @@ -53,11 +86,12 @@ public: Default constructor. */ wxTextValidator(const wxTextValidator& validator); + /** Constructor taking a style and optional pointer to a wxString variable. @param style - A bitlist of flags documented in the class description. + 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 @@ -69,7 +103,7 @@ public: /** Clones the text validator using the copy constructor. */ - virtual wxValidator* Clone() const; + virtual wxObject* Clone() const; /** Returns a reference to the exclude list (the list of invalid values). @@ -83,9 +117,16 @@ public: /** 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. @@ -97,13 +138,38 @@ public: */ 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); /** - Sets the validator style. + 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); @@ -122,5 +188,25 @@ public: 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; };