- if ( !m_validatorWindow )
- return FALSE;
- if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
- return FALSE;
- if ( !m_stringValue )
- return FALSE;
-
- wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
-
- // If window is disabled, don't validate
- if ( !control->Enabled() )
- return FALSE;
-
- wxString val(control->GetValue());
-
- if ( m_validatorStyle & wxFILTER_INCLUDE_LIST )
- {
- if ( !m_includeList.Member(val) )
- {
- m_validatorWindow->SetFocus();
- char buf[512];
- sprintf(buf, _("%s is invalid."), (const char *)val);
- wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
- return FALSE;
- }
- }
- if ( m_validatorStyle & wxFILTER_EXCLUDE_LIST )
- {
- if ( m_excludeList.Member(val) )
- {
- m_validatorWindow->SetFocus();
- char buf[512];
- sprintf(buf, _("%s is invalid."), (const char *)val);
- wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
- return FALSE;
- }
- }
- if ( (m_validatorStyle & wxFILTER_ASCII) && !val.IsAscii() )
- {
- m_validatorWindow->SetFocus();
- char buf[512];
- sprintf(buf, _("%s should only contain ASCII characters."), (const char *)val);
- wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
- return FALSE;
- }
- if ( (m_validatorStyle & wxFILTER_ALPHA) && !wxIsAlpha(val) )
- {
- m_validatorWindow->SetFocus();
- char buf[512];
- sprintf(buf, _("%s should only contain alphabetic characters."), (const char *)val);
- wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
- return FALSE;
- }
- if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsAlphaNumeric(val))
- {
- m_validatorWindow->SetFocus();
- char buf[512];
- sprintf(buf, _("%s should only contain alphabetic or numeric characters."), (const char *)val);
- wxMessageBox(buf,_("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
- return FALSE;
- }
- if ( (m_validatorStyle & wxFILTER_NUMERIC) && !wxIsNumeric(val))
-
- {
- m_validatorWindow->SetFocus();
- char buf[512];
- sprintf(buf, _("%s should be numeric."), (const char *)val);
- wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
- return FALSE;
- }
-
- return TRUE ;
+ // If window is disabled, simply return
+ if ( !m_validatorWindow->IsEnabled() )
+ return true;
+
+ wxTextEntry * const text = GetTextEntry();
+ if ( !text )
+ return false;
+
+ wxString val(text->GetValue());
+
+ // NB: this format string should always contain exactly one '%s'
+ wxString errormsg;
+
+ switch (m_validatorStyle)
+ {
+ case wxFILTER_NONE:
+ // nothing to do...
+ break;
+
+ case wxFILTER_INCLUDE_LIST:
+ if ( m_includes.Index(val) == wxNOT_FOUND )
+ errormsg = _("'%s' is invalid");
+ break;
+
+ case wxFILTER_EXCLUDE_LIST:
+ if ( m_excludes.Index(val) != wxNOT_FOUND )
+ errormsg = _("'%s' is invalid");
+ break;
+
+ case wxFILTER_ASCII:
+ if ( !val.IsAscii() )
+ errormsg = _("'%s' should only contain ASCII characters.");
+ break;
+
+ case wxFILTER_ALPHA:
+ if ( !wxIsAlpha(val) )
+ errormsg = _("'%s' should only contain alphabetic characters.");
+ break;
+
+ case wxFILTER_ALPHANUMERIC:
+ if ( !wxIsAlphaNumeric(val) )
+ errormsg = _("'%s' should only contain alphabetic or numeric characters.");
+ break;
+
+ case wxFILTER_NUMERIC:
+ if ( !wxIsNumeric(val) )
+ errormsg = _("'%s' should be numeric.");
+ break;
+
+ case wxFILTER_INCLUDE_CHAR_LIST:
+ if ( !IsInCharIncludes(val) )
+ errormsg = _("'%s' is invalid");
+ break;
+
+ case wxFILTER_EXCLUDE_CHAR_LIST:
+ if ( !IsNotInCharExcludes(val) )
+ errormsg = _("'%s' is invalid");
+ break;
+
+ default:
+ wxFAIL_MSG("invalid text validator style");
+ }
+
+ if ( !errormsg.empty() )
+ {
+ m_validatorWindow->SetFocus();
+
+ wxString buf;
+ buf.Printf(errormsg, val.c_str());
+
+ wxMessageBox(buf, _("Validation conflict"),
+ wxOK | wxICON_EXCLAMATION, parent);
+
+ return false;
+ }
+
+ return true;