2008-05-24 23:08:31 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/window/setsize.cpp
|
|
|
|
// Purpose: Tests for SetSize() and related wxWindow methods
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2008-05-25
|
|
|
|
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
2019-09-21 18:49:11 -04:00
|
|
|
#include "wx/frame.h"
|
2008-05-24 23:08:31 -04:00
|
|
|
#include "wx/window.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
#include "wx/scopedptr.h"
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#include "asserthelper.h"
|
2019-10-17 15:59:06 -04:00
|
|
|
#include "waitforpaint.h"
|
2008-05-24 23:08:31 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2019-09-21 18:43:59 -04:00
|
|
|
// tests helpers
|
2008-05-24 23:08:31 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
namespace
|
2008-05-24 23:08:31 -04:00
|
|
|
{
|
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
// Helper class overriding DoGetBestSize() for testing purposes.
|
|
|
|
class MyWindow : public wxWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyWindow(wxWindow* parent)
|
|
|
|
: wxWindow(parent, wxID_ANY)
|
2012-08-15 19:34:18 -04:00
|
|
|
{
|
2019-09-21 18:43:59 -04:00
|
|
|
}
|
2008-05-24 23:08:31 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
protected:
|
|
|
|
virtual wxSize DoGetBestSize() const wxOVERRIDE { return wxSize(50, 250); }
|
2008-05-24 23:08:31 -04:00
|
|
|
};
|
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
} // anonymous namespace
|
2008-05-24 23:08:31 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2019-09-21 18:43:59 -04:00
|
|
|
// tests themselves
|
2008-05-24 23:08:31 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
TEST_CASE("wxWindow::SetSize", "[window][size]")
|
2008-05-24 23:08:31 -04:00
|
|
|
{
|
2019-09-21 18:43:59 -04:00
|
|
|
wxScopedPtr<wxWindow> w(new MyWindow(wxTheApp->GetTopWindow()));
|
2008-05-24 23:08:31 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
SECTION("Simple")
|
|
|
|
{
|
|
|
|
const wxSize size(127, 35);
|
|
|
|
w->SetSize(size);
|
|
|
|
CHECK( size == w->GetSize() );
|
|
|
|
}
|
2008-05-24 23:08:31 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
SECTION("With min size")
|
|
|
|
{
|
|
|
|
w->SetMinSize(wxSize(100, 100));
|
2008-05-24 23:08:31 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
const wxSize size(200, 50);
|
|
|
|
w->SetSize(size);
|
|
|
|
CHECK( size == w->GetSize() );
|
|
|
|
}
|
2008-05-24 23:08:31 -04:00
|
|
|
}
|
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
TEST_CASE("wxWindow::GetBestSize", "[window][size][best-size]")
|
2008-05-24 23:08:31 -04:00
|
|
|
{
|
2019-09-21 18:43:59 -04:00
|
|
|
wxScopedPtr<wxWindow> w(new MyWindow(wxTheApp->GetTopWindow()));
|
2008-05-24 23:08:31 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
CHECK( wxSize(50, 250) == w->GetBestSize() );
|
2012-08-15 19:34:18 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
w->SetMinSize(wxSize(100, 100));
|
|
|
|
CHECK( wxSize(100, 250) == w->GetBestSize() );
|
2012-08-15 19:34:18 -04:00
|
|
|
|
2019-09-21 18:43:59 -04:00
|
|
|
w->SetMaxSize(wxSize(200, 200));
|
|
|
|
CHECK( wxSize(100, 200) == w->GetBestSize() );
|
2012-08-15 19:34:18 -04:00
|
|
|
}
|
2019-09-21 18:49:11 -04:00
|
|
|
|
|
|
|
TEST_CASE("wxWindow::MovePreservesSize", "[window][size][move]")
|
|
|
|
{
|
|
|
|
wxScopedPtr<wxWindow>
|
|
|
|
w(new wxFrame(wxTheApp->GetTopWindow(), wxID_ANY, "Test child frame"));
|
|
|
|
|
2019-10-17 16:01:36 -04:00
|
|
|
// 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.
|
|
|
|
WaitForPaint waitForPaint(w.get());
|
|
|
|
|
|
|
|
w->Show();
|
|
|
|
|
2021-01-30 18:29:31 -05:00
|
|
|
waitForPaint.YieldUntilPainted();
|
2019-09-21 18:49:11 -04:00
|
|
|
|
|
|
|
const wxRect rectOrig = w->GetRect();
|
|
|
|
|
|
|
|
// Check that moving the window doesn't change its size.
|
|
|
|
w->Move(rectOrig.GetPosition() + wxPoint(100, 100));
|
|
|
|
CHECK( w->GetSize() == rectOrig.GetSize() );
|
|
|
|
}
|