X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/58fa61dbad0ea1158f6c6e96d611c26057e069ba..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/common/valtext.cpp diff --git a/src/common/valtext.cpp b/src/common/valtext.cpp index 78135abcc0..dced8ecb83 100644 --- a/src/common/valtext.cpp +++ b/src/common/valtext.cpp @@ -33,6 +33,8 @@ #include #include +#include "wx/combo.h" + // ---------------------------------------------------------------------------- // global helpers // ---------------------------------------------------------------------------- @@ -76,7 +78,7 @@ void wxTextValidator::SetStyle(long style) { m_validatorStyle = style; -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL int check; check = (int)HasFlag(wxFILTER_ALPHA) + (int)HasFlag(wxFILTER_ALPHANUMERIC) + (int)HasFlag(wxFILTER_DIGITS) + (int)HasFlag(wxFILTER_NUMERIC); @@ -93,7 +95,7 @@ void wxTextValidator::SetStyle(long style) (int)HasFlag(wxFILTER_EXCLUDE_LIST) + (int)HasFlag(wxFILTER_EXCLUDE_CHAR_LIST); wxASSERT_MSG(check <= 1, "Using both an include/exclude list may lead to unexpected results"); -#endif +#endif // wxDEBUG_LEVEL } bool wxTextValidator::Copy(const wxTextValidator& val) @@ -112,21 +114,29 @@ bool wxTextValidator::Copy(const wxTextValidator& val) wxTextEntry *wxTextValidator::GetTextEntry() { #if wxUSE_TEXTCTRL - if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + if (wxDynamicCast(m_validatorWindow, wxTextCtrl)) { return (wxTextCtrl*)m_validatorWindow; } #endif #if wxUSE_COMBOBOX - if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox))) + if (wxDynamicCast(m_validatorWindow, wxComboBox)) { return (wxComboBox*)m_validatorWindow; } #endif +#if wxUSE_COMBOCTRL + if (wxDynamicCast(m_validatorWindow, wxComboCtrl)) + { + return (wxComboCtrl*)m_validatorWindow; + } +#endif + wxFAIL_MSG( - _T("wxTextValidator can only be used with wxTextCtrl or wxComboBox") + "wxTextValidator can only be used with wxTextCtrl, wxComboBox, " + "or wxComboCtrl" ); return NULL; @@ -149,7 +159,7 @@ bool wxTextValidator::Validate(wxWindow *parent) wxString errormsg; if ( HasFlag(wxFILTER_EMPTY) && val.empty() ) { - errormsg = _("The empty string is not allowed."); + errormsg = _("Required information entry is empty."); } else if ( !(errormsg = IsValid(val)).empty() ) { @@ -201,17 +211,38 @@ bool wxTextValidator::TransferFromWindow() return true; } +// IRIX mipsPro refuses to compile wxStringCheck() if func is inline so +// let's work around this by using this non-template function instead of +// wxStringCheck(). And while this might be fractionally less efficient because +// the function call won't be inlined like this, we don't care enough about +// this to add extra #ifs for non-IRIX case. +namespace +{ + +bool CheckString(bool (*func)(const wxUniChar&), const wxString& str) +{ + for ( wxString::const_iterator i = str.begin(); i != str.end(); ++i ) + { + if ( !func(*i) ) + return false; + } + + return true; +} + +} // anonymous namespace + wxString wxTextValidator::IsValid(const wxString& val) const { // wxFILTER_EMPTY is checked for in wxTextValidator::Validate if ( HasFlag(wxFILTER_ASCII) && !val.IsAscii() ) return _("'%s' should only contain ASCII characters."); - if ( HasFlag(wxFILTER_ALPHA) && !wxStringCheck(val) ) + if ( HasFlag(wxFILTER_ALPHA) && !CheckString(wxIsalpha, val) ) return _("'%s' should only contain alphabetic characters."); - if ( HasFlag(wxFILTER_ALPHANUMERIC) && !wxStringCheck(val) ) + if ( HasFlag(wxFILTER_ALPHANUMERIC) && !CheckString(wxIsalnum, val) ) return _("'%s' should only contain alphabetic or numeric characters."); - if ( HasFlag(wxFILTER_DIGITS) && !wxStringCheck(val) ) + if ( HasFlag(wxFILTER_DIGITS) && !CheckString(wxIsdigit, val) ) return _("'%s' should only contain digits."); if ( HasFlag(wxFILTER_NUMERIC) && !wxIsNumeric(val) ) return _("'%s' should be numeric.");