Merge branch 'win-val-self' of https://github.com/AliKet/wxWidgets
Make wxWindow::TransferData{To,From}Window and Validate work on the window itself too. See https://github.com/wxWidgets/wxWidgets/pull/2235
This commit is contained in:
@@ -2031,19 +2031,20 @@ public:
|
|||||||
|
|
||||||
// Traverse all the direct children calling OnDo() on them and also all
|
// Traverse all the direct children calling OnDo() on them and also all
|
||||||
// grandchildren, calling OnRecurse() for them.
|
// 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();
|
wxWindowList& children = m_win->GetChildren();
|
||||||
for ( wxWindowList::iterator i = children.begin();
|
for ( wxWindowList::iterator i = children.begin();
|
||||||
i != children.end();
|
i != children.end();
|
||||||
++i )
|
++i )
|
||||||
{
|
{
|
||||||
wxWindow* const child = static_cast<wxWindow*>(*i);
|
wxWindow* const child = static_cast<wxWindow*>(*i);
|
||||||
wxValidator* const validator = child->GetValidator();
|
|
||||||
if ( validator && !OnDo(validator) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notice that validation should never recurse into top level
|
// Notice that validation should never recurse into top level
|
||||||
// children, e.g. some other dialog which might happen to be
|
// 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
|
#else // !wxUSE_VALIDATORS
|
||||||
return true;
|
return true;
|
||||||
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
||||||
@@ -2140,7 +2141,7 @@ bool wxWindowBase::TransferDataToWindow()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return DataToWindowTraverser(this).DoForAllChildren();
|
return DataToWindowTraverser(this).DoForSelfAndChildren();
|
||||||
#else // !wxUSE_VALIDATORS
|
#else // !wxUSE_VALIDATORS
|
||||||
return true;
|
return true;
|
||||||
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
||||||
@@ -2168,7 +2169,7 @@ bool wxWindowBase::TransferDataFromWindow()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return DataFromWindowTraverser(this).DoForAllChildren();
|
return DataFromWindowTraverser(this).DoForSelfAndChildren();
|
||||||
#else // !wxUSE_VALIDATORS
|
#else // !wxUSE_VALIDATORS
|
||||||
return true;
|
return true;
|
||||||
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
||||||
|
@@ -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
|
#endif // wxUSE_VALIDATORS && wxUSE_UIACTIONSIMULATOR
|
||||||
|
Reference in New Issue
Block a user