From aaae8296646096f4f4e0cd6dc6ad77e1fed4c4c2 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 14 Apr 2002 11:05:18 +0000 Subject: [PATCH] Applied custom character filter patch for text validator Corrected typo in spinbutt.tex git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/spinbutt.tex | 2 +- docs/latex/wx/valtext.tex | 4 ++++ include/wx/valtext.h | 5 +++++ src/common/valtext.cpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9aa739d0e0..cd36fc121b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -158,6 +158,7 @@ All (GUI): - added (platform-dependent) scan code to wxKeyEvent (Bryce Denney) - added wxTextCtrl::EmulateKeyPress() - Added wxMouseCaptureChangedEvent +- Added custom character filtering to wxTextValidator wxMSW: diff --git a/docs/latex/wx/spinbutt.tex b/docs/latex/wx/spinbutt.tex index 623d20c8d2..3be1a60ec3 100644 --- a/docs/latex/wx/spinbutt.tex +++ b/docs/latex/wx/spinbutt.tex @@ -44,7 +44,7 @@ direct input to member functions that take a \twocolwidtha{7cm} \begin{twocollist} -\twocolitem{{\bf EVT\_SPIN(id, func)}}{Generated whenever an arros is pressed.} +\twocolitem{{\bf EVT\_SPIN(id, func)}}{Generated whenever an arrow is pressed.} \twocolitem{{\bf EVT\_SPIN\_UP(id, func)}}{Generated when left/up arrow is pressed.} \twocolitem{{\bf EVT\_SPIN\_DOWN(id, func)}}{Generated when right/down arrow is pressed.} \end{twocollist}% diff --git a/docs/latex/wx/valtext.tex b/docs/latex/wx/valtext.tex index 704235fc03..c3c286ecc5 100644 --- a/docs/latex/wx/valtext.tex +++ b/docs/latex/wx/valtext.tex @@ -46,6 +46,10 @@ Constructor, taking a style and optional pointer to a wxString variable. checks if the user input is on the list, complaining if not.} \twocolitem{{\bf wxFILTER\_EXCLUDE\_LIST}}{Use an exclude list. The validator checks if the user input is on the list, complaining if it is.} +\twocolitem{{\bf 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.} +\twocolitem{{\bf 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 it is.} \end{twocollist} } diff --git a/include/wx/valtext.h b/include/wx/valtext.h index 01e0e6d911..0d986f0270 100644 --- a/include/wx/valtext.h +++ b/include/wx/valtext.h @@ -29,6 +29,8 @@ #define wxFILTER_NUMERIC 0x0008 #define wxFILTER_INCLUDE_LIST 0x0010 #define wxFILTER_EXCLUDE_LIST 0x0020 +#define wxFILTER_INCLUDE_CHAR_LIST 0x0040 +#define wxFILTER_EXCLUDE_CHAR_LIST 0x0080 class WXDLLEXPORT wxTextValidator: public wxValidator { @@ -70,6 +72,9 @@ public: // Filter keystrokes void OnChar(wxKeyEvent& event); + bool IsInCharIncludeList(const wxString& val); + bool IsNotInCharExcludeList(const wxString& val); + DECLARE_EVENT_TABLE() protected: diff --git a/src/common/valtext.cpp b/src/common/valtext.cpp index 483b71d075..4c8a474868 100644 --- a/src/common/valtext.cpp +++ b/src/common/valtext.cpp @@ -170,6 +170,18 @@ bool wxTextValidator::Validate(wxWindow *parent) errormsg = _("'%s' should be numeric."); } + else if ( (m_validatorStyle & wxFILTER_INCLUDE_CHAR_LIST) && !IsInCharIncludeList(val)) + { + //it's only ok to have the members of the list + errormsg = _("'%s' is invalid"); + ok = FALSE; + } + else if ( (m_validatorStyle & wxFILTER_EXCLUDE_CHAR_LIST) && !IsNotInCharExcludeList(val)) + { + // it's only ok to have non-members of the list + errormsg = _("'%s' is invalid"); + ok = FALSE; + } if ( !ok ) { @@ -262,6 +274,8 @@ void wxTextValidator::OnChar(wxKeyEvent& event) if ( !(keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode > WXK_START) && ( + ((m_validatorStyle & wxFILTER_INCLUDE_CHAR_LIST) && !IsInCharIncludeList(wxString((char) keyCode, 1))) || + ((m_validatorStyle & wxFILTER_EXCLUDE_CHAR_LIST) && !IsNotInCharExcludeList(wxString((char) keyCode, 1))) || ((m_validatorStyle & wxFILTER_ASCII) && !isascii(keyCode)) || ((m_validatorStyle & wxFILTER_ALPHA) && !wxIsalpha(keyCode)) || ((m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsalnum(keyCode)) || @@ -295,5 +309,27 @@ static bool wxIsNumeric(const wxString& val) return TRUE; } +bool wxTextValidator::IsInCharIncludeList(const wxString& val) +{ + size_t i; + for ( i = 0; i < val.Length(); i++) + { + if (!m_includeList.Member((wxString) val[i])) + return FALSE; + } + return TRUE; +} + +bool wxTextValidator::IsNotInCharExcludeList(const wxString& val) +{ + size_t i; + for ( i = 0; i < val.Length(); i++) + { + if (m_excludeList.Member((wxString) val[i])) + return FALSE; + } + return TRUE; +} + #endif // wxUSE_VALIDATORS -- 2.47.2