2009-10-30 01:04:47 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/toplevel/toplevel.cpp
|
|
|
|
// Purpose: Tests for wxTopLevelWindow
|
|
|
|
// Author: Kevin Ollivier
|
|
|
|
// Created: 2008-05-25
|
|
|
|
// Copyright: (c) 2009 Kevin Ollivier <kevino@theolliviers.com>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2018-06-21 20:43:23 -04:00
|
|
|
#include "wx/app.h"
|
2011-05-01 10:58:58 -04:00
|
|
|
#include "wx/dialog.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
#include "wx/textctrl.h"
|
|
|
|
#include "wx/toplevel.h"
|
2009-10-30 01:04:47 -04:00
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2019-01-21 05:45:40 -05:00
|
|
|
#include "testableframe.h"
|
|
|
|
|
2019-02-02 11:31:05 -05:00
|
|
|
class DestroyOnScopeExit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit DestroyOnScopeExit(wxTopLevelWindow* tlw)
|
|
|
|
: m_tlw(tlw)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~DestroyOnScopeExit()
|
|
|
|
{
|
|
|
|
m_tlw->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxTopLevelWindow* const m_tlw;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(DestroyOnScopeExit);
|
|
|
|
};
|
|
|
|
|
2017-11-22 15:13:10 -05:00
|
|
|
static void TopLevelWindowShowTest(wxTopLevelWindow* tlw)
|
2009-10-30 01:04:47 -04:00
|
|
|
{
|
2017-11-07 10:16:08 -05:00
|
|
|
CHECK(!tlw->IsShown());
|
2012-03-03 19:29:14 -05:00
|
|
|
|
2009-10-30 01:04:47 -04:00
|
|
|
wxTextCtrl* textCtrl = new wxTextCtrl(tlw, -1, "test");
|
|
|
|
textCtrl->SetFocus();
|
2012-03-03 19:29:14 -05:00
|
|
|
|
2009-10-30 01:04:47 -04:00
|
|
|
// only run this test on platforms where ShowWithoutActivating is implemented.
|
2011-05-01 10:58:58 -04:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
2018-06-21 20:43:23 -04:00
|
|
|
wxTheApp->GetTopWindow()->SetFocus();
|
2009-10-30 01:04:47 -04:00
|
|
|
tlw->ShowWithoutActivating();
|
2017-11-07 10:16:08 -05:00
|
|
|
CHECK(tlw->IsShown());
|
|
|
|
CHECK(!tlw->IsActive());
|
2012-03-03 19:29:14 -05:00
|
|
|
|
2009-10-30 01:04:47 -04:00
|
|
|
tlw->Hide();
|
2017-11-07 10:16:08 -05:00
|
|
|
CHECK(!tlw->IsShown());
|
|
|
|
CHECK(!tlw->IsActive());
|
2009-10-30 01:04:47 -04:00
|
|
|
#endif
|
2012-03-03 19:29:14 -05:00
|
|
|
|
2019-01-28 18:08:44 -05:00
|
|
|
// Note that at least under MSW, ShowWithoutActivating() still generates
|
|
|
|
// wxActivateEvent, so we must only start counting these events after the
|
|
|
|
// end of the tests above.
|
|
|
|
EventCounter countActivate(tlw, wxEVT_ACTIVATE);
|
|
|
|
|
2009-10-30 01:04:47 -04:00
|
|
|
tlw->Show(true);
|
2019-01-28 18:08:44 -05:00
|
|
|
countActivate.WaitEvent();
|
2017-11-07 10:16:08 -05:00
|
|
|
|
2019-07-17 10:07:06 -04:00
|
|
|
// TLWs never become active when running under Xvfb, presumably because
|
|
|
|
// there is no WM there.
|
|
|
|
if ( !IsRunningUnderXVFB() )
|
|
|
|
CHECK(tlw->IsActive());
|
|
|
|
|
2017-11-07 10:16:08 -05:00
|
|
|
CHECK(tlw->IsShown());
|
2012-03-03 19:29:14 -05:00
|
|
|
|
2009-10-30 01:04:47 -04:00
|
|
|
tlw->Hide();
|
2017-11-07 10:16:08 -05:00
|
|
|
CHECK(!tlw->IsShown());
|
2019-01-28 18:16:52 -05:00
|
|
|
|
|
|
|
countActivate.WaitEvent();
|
2018-06-21 20:43:23 -04:00
|
|
|
CHECK(!tlw->IsActive());
|
2009-10-30 01:04:47 -04:00
|
|
|
}
|
2017-11-22 15:13:10 -05:00
|
|
|
|
|
|
|
TEST_CASE("wxTopLevel::Show", "[tlw][show]")
|
|
|
|
{
|
|
|
|
SECTION("Dialog")
|
|
|
|
{
|
|
|
|
wxDialog* dialog = new wxDialog(NULL, -1, "Dialog Test");
|
2019-02-02 11:31:05 -05:00
|
|
|
DestroyOnScopeExit destroy(dialog);
|
|
|
|
|
2017-11-22 15:13:10 -05:00
|
|
|
TopLevelWindowShowTest(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Frame")
|
|
|
|
{
|
|
|
|
wxFrame* frame = new wxFrame(NULL, -1, "Frame test");
|
2019-02-02 11:31:05 -05:00
|
|
|
DestroyOnScopeExit destroy(frame);
|
|
|
|
|
2017-11-22 15:13:10 -05:00
|
|
|
TopLevelWindowShowTest(frame);
|
|
|
|
}
|
|
|
|
}
|
2019-01-21 05:45:40 -05:00
|
|
|
|
|
|
|
// Check that we receive the expected event when showing the TLW.
|
|
|
|
TEST_CASE("wxTopLevel::ShowEvent", "[tlw][show][event]")
|
|
|
|
{
|
|
|
|
wxFrame* const frame = new wxFrame(NULL, wxID_ANY, "Maximized frame");
|
2019-02-02 11:31:05 -05:00
|
|
|
DestroyOnScopeExit destroy(frame);
|
2019-01-21 05:45:40 -05:00
|
|
|
|
|
|
|
EventCounter countShow(frame, wxEVT_SHOW);
|
|
|
|
|
|
|
|
frame->Maximize();
|
|
|
|
frame->Show();
|
|
|
|
|
2019-01-24 08:04:10 -05:00
|
|
|
CHECK( countShow.WaitEvent() );
|
2019-01-21 05:45:40 -05:00
|
|
|
}
|