- 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) )
- {
- 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) )
- {
- 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() )
- {
- 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) )
- {
- 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))
- {
- 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))
-
- {
- 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( !CheckValidator() )
+ return FALSE;
+
+ wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
+
+ // If window is disabled, simply return
+ if ( !control->IsEnabled() )
+ return TRUE;
+
+ wxString val(control->GetValue());
+
+ bool ok = TRUE;
+
+ // NB: this format string should contian exactly one '%s'
+ wxString errormsg;
+
+ bool includeList = (m_validatorStyle & wxFILTER_INCLUDE_LIST) != 0;
+ if ( includeList || (m_validatorStyle & wxFILTER_EXCLUDE_LIST) )
+ {
+ // if includeList, it's only ok to have the members of the list,
+ // otherwise it's only ok to have non-members
+ ok = includeList == m_includeList.Member(val);
+ if ( !ok )
+ {
+ errormsg = _("'%s' is invalid");
+ }
+ }
+ else if ( (m_validatorStyle & wxFILTER_ASCII) && !val.IsAscii() )
+ {
+ ok = FALSE;
+
+ errormsg = _("'%s' should only contain ASCII characters.");
+ }
+ else if ( (m_validatorStyle & wxFILTER_ALPHA) && !wxIsAlpha(val) )
+ {
+ ok = FALSE;
+
+ errormsg = _("'%s' should only contain alphabetic characters.");
+ }
+ else if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsAlphaNumeric(val))
+ {
+ ok = FALSE;
+
+ errormsg = _("'%s' should only contain alphabetic or numeric characters.");
+ }
+ else if ( (m_validatorStyle & wxFILTER_NUMERIC) && !wxIsNumeric(val))
+ {
+ ok = FALSE;
+
+ errormsg = _("'%s' should be numeric.");
+ }
+
+ if ( !ok )
+ {
+ wxASSERT_MSG( !errormsg.empty(), _T("you forgot to set errormsg") );
+
+ m_validatorWindow->SetFocus();
+
+ wxString buf;
+ buf.Printf(errormsg, val.c_str());
+
+ wxMessageBox(buf, _("Validation conflict"),
+ wxOK | wxICON_EXCLAMATION, parent);
+ }
+
+ return ok;