Extract waiting for the first paint event in a reusable function

No real changes, this is just a refactoring to allow reusing the same
loop waiting until we can get the real window geometry in other tests.

This commit is best viewed with --color-moved.
This commit is contained in:
Vadim Zeitlin
2019-09-22 00:55:31 +02:00
parent da8cecbfe5
commit 35de675830

View File

@@ -70,6 +70,34 @@ private:
bool& m_painted;
};
// This function should be used to show the window and wait until we can get
// its real geometry.
void ShowAndWaitForPaint(wxWindow* w)
{
// Unfortunately showing the window is asynchronous, at least when using
// X11, so we have to wait for some time before retrieving its true
// geometry. And it's not clear how long should we wait, so we do it until
// we get the first paint event -- by then the window really should have
// its final size.
bool painted;
WaitForPaint waitForPaint(&painted);
w->Bind(wxEVT_PAINT, waitForPaint);
w->Show();
wxStopWatch sw;
while ( !painted )
{
wxYield();
if ( sw.Time() > 250 )
{
WARN("Didn't get a paint event until timeout expiration");
break;
}
}
}
} // anonymous namespace
// ----------------------------------------------------------------------------
@@ -115,28 +143,7 @@ TEST_CASE("wxWindow::MovePreservesSize", "[window][size][move]")
wxScopedPtr<wxWindow>
w(new wxFrame(wxTheApp->GetTopWindow(), wxID_ANY, "Test child frame"));
// Unfortunately showing the window is asynchronous, at least when using
// X11, so we have to wait for some time before retrieving its true
// geometry. And it's not clear how long should we wait, so we do it until
// we get the first paint event -- by then the window really should have
// its final size.
bool painted;
WaitForPaint waitForPaint(&painted);
w->Bind(wxEVT_PAINT, waitForPaint);
w->Show();
wxStopWatch sw;
while ( !painted )
{
wxYield();
if ( sw.Time() > 250 )
{
WARN("Didn't get a paint event until timeout expiration");
break;
}
}
ShowAndWaitForPaint(w.get());
const wxRect rectOrig = w->GetRect();