diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 2bfb862f74..cad8c190bf 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2031,19 +2031,20 @@ public: // Traverse all the direct children calling OnDo() on them and also all // grandchildren, calling OnRecurse() for them. - bool DoForAllChildren() + bool DoForSelfAndChildren() { + wxValidator* const validator = m_win->GetValidator(); + if ( validator && !OnDo(validator) ) + { + return false; + } + wxWindowList& children = m_win->GetChildren(); for ( wxWindowList::iterator i = children.begin(); i != children.end(); ++i ) { wxWindow* const child = static_cast(*i); - wxValidator* const validator = child->GetValidator(); - if ( validator && !OnDo(validator) ) - { - return false; - } // Notice that validation should never recurse into top level // children, e.g. some other dialog which might happen to be @@ -2102,7 +2103,7 @@ bool wxWindowBase::Validate() } }; - return ValidateTraverser(this).DoForAllChildren(); + return ValidateTraverser(this).DoForSelfAndChildren(); #else // !wxUSE_VALIDATORS return true; #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS @@ -2140,7 +2141,7 @@ bool wxWindowBase::TransferDataToWindow() } }; - return DataToWindowTraverser(this).DoForAllChildren(); + return DataToWindowTraverser(this).DoForSelfAndChildren(); #else // !wxUSE_VALIDATORS return true; #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS @@ -2168,7 +2169,7 @@ bool wxWindowBase::TransferDataFromWindow() } }; - return DataFromWindowTraverser(this).DoForAllChildren(); + return DataFromWindowTraverser(this).DoForSelfAndChildren(); #else // !wxUSE_VALIDATORS return true; #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS diff --git a/tests/validators/valtext.cpp b/tests/validators/valtext.cpp index fcd2d8adaf..893577ea05 100644 --- a/tests/validators/valtext.cpp +++ b/tests/validators/valtext.cpp @@ -184,4 +184,30 @@ TEXT_VALIDATOR_TEST_CASE("wxTextValidator::IsValid", "[wxTextValidator][filters] } } +TEXT_VALIDATOR_TEST_CASE("wxTextValidator::TransferToWindow", "[wxTextValidator][transferdata]") +{ + wxString value = "wxwidgets"; + wxTextValidator val(wxFILTER_ALPHA, &value); + m_text->SetValidator(val); + + CHECK( m_text->IsEmpty() ); + + REQUIRE( m_text->TransferDataToWindow() ); + + CHECK( m_text->GetValue() == "wxwidgets" ); +} + +TEXT_VALIDATOR_TEST_CASE("wxTextValidator::TransferFromWindow", "[wxTextValidator][transferdata]") +{ + wxString value; + wxTextValidator val(wxFILTER_ALPHA, &value); + m_text->SetValidator(val); + + m_text->ChangeValue("wxwidgets"); + + REQUIRE( m_text->TransferDataFromWindow() ); + + CHECK( value == "wxwidgets" ); +} + #endif // wxUSE_VALIDATORS && wxUSE_UIACTIONSIMULATOR