X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/903f689bf7c3c379cba45881373aa9bdd15d6e70..3bef6c4cf30e426d9aeb11535d39bbb562b2b730:/src/common/valtext.cpp diff --git a/src/common/valtext.cpp b/src/common/valtext.cpp index 3973230d80..7da74055f5 100644 --- a/src/common/valtext.cpp +++ b/src/common/valtext.cpp @@ -42,6 +42,8 @@ BEGIN_EVENT_TABLE(wxTextValidator, wxValidator) END_EVENT_TABLE() #endif +static bool wxIsNumeric(const wxString& val); + wxTextValidator::wxTextValidator(long style, wxString *val) { m_validatorStyle = style ; @@ -132,6 +134,7 @@ bool wxTextValidator::Validate(wxWindow *parent) { 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); @@ -142,6 +145,7 @@ bool wxTextValidator::Validate(wxWindow *parent) { 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); @@ -150,6 +154,7 @@ bool wxTextValidator::Validate(wxWindow *parent) } 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); @@ -157,6 +162,7 @@ bool wxTextValidator::Validate(wxWindow *parent) } 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); @@ -164,13 +170,16 @@ bool wxTextValidator::Validate(wxWindow *parent) } 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) && !val.IsNumber()) + 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); @@ -291,4 +300,14 @@ void wxTextValidator::OnChar(wxKeyEvent& event) textCtrl->wxTextCtrl::OnChar(event); } +static bool wxIsNumeric(const wxString& val) +{ + int i; + for ( i = 0; i < (int)val.Length(); i++) + { + if ((!isdigit(val[i])) && (val[i] != '.')) + return FALSE; + } + return TRUE; +}