diff --git a/include/wx/valnum.h b/include/wx/valnum.h index f4436cb027..42f7675a76 100644 --- a/include/wx/valnum.h +++ b/include/wx/valnum.h @@ -50,6 +50,10 @@ public: // we don't need this as we do our validation on the fly here. virtual bool Validate(wxWindow * WXUNUSED(parent)) wxOVERRIDE { return true; } + // Override base class method to check that the window is a text control or + // combobox. + virtual void SetWindow(wxWindow *win) wxOVERRIDE; + protected: wxNumValidatorBase(int style) { diff --git a/src/common/valnum.cpp b/src/common/valnum.cpp index bb483502a6..4f11072b1c 100644 --- a/src/common/valnum.cpp +++ b/src/common/valnum.cpp @@ -52,6 +52,23 @@ int wxNumValidatorBase::GetFormatFlags() const return flags; } +void wxNumValidatorBase::SetWindow(wxWindow *win) +{ + wxValidator::SetWindow(win); + +#if wxUSE_TEXTCTRL + if ( wxDynamicCast(m_validatorWindow, wxTextCtrl) ) + return; +#endif // wxUSE_TEXTCTRL + +#if wxUSE_COMBOBOX + if ( wxDynamicCast(m_validatorWindow, wxComboBox) ) + return; +#endif // wxUSE_COMBOBOX + + wxFAIL_MSG("Can only be used with wxTextCtrl or wxComboBox"); +} + wxTextEntry *wxNumValidatorBase::GetTextEntry() const { #if wxUSE_TEXTCTRL @@ -64,8 +81,6 @@ wxTextEntry *wxNumValidatorBase::GetTextEntry() const return combo; #endif // wxUSE_COMBOBOX - wxFAIL_MSG("Can only be used with wxTextCtrl or wxComboBox"); - return NULL; }