]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/valtext.cpp
generate key events for Space/Enter in addition to the activate events, as wxMSW...
[wxWidgets.git] / src / common / valtext.cpp
index 483b71d07520cfb0345983c33fe624906a902431..fc7bc3e4c752f86a5a57244ce0a5c6f1f408c7ca 100644 (file)
@@ -61,6 +61,7 @@ wxTextValidator::wxTextValidator(long style, wxString *val)
 }
 
 wxTextValidator::wxTextValidator(const wxTextValidator& val)
+    : wxValidator()
 {
     Copy(val);
 }
@@ -170,6 +171,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 +275,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 +310,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