From dfec7aa0c08617ed61fc1ee04551aea19dc6abd0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Dec 2018 01:01:49 +0100 Subject: [PATCH] Make disabling the window before creating it actually work Disabling a window before actually creating it ought to work, similarly to hiding a window before creating it which can be used to avoid showing the window on screen at all, even briefly. However it didn't under MSW where the window was disabled from wxWidgets point of view, but not at the MSW level. Fix this by accounting for the enabled state in MSWGetStyle(). Closes #16385. --- docs/changes.txt | 8 ++++++++ src/msw/window.cpp | 3 +++ tests/controls/buttontest.cpp | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index ea37991c44..5ce2c6c4c2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -102,6 +102,14 @@ Changes in behaviour which may result in build errors removing its name. +3.1.?: (released 2012-??-??) +---------------------------- + +All (GUI): + +- Make disabling the window before creating it actually work. + + 3.1.2: (released 2018-12-10) ---------------------------- diff --git a/src/msw/window.cpp b/src/msw/window.cpp index e17b851b59..609f6e8c19 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1518,6 +1518,9 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle() WXDWORD style = WS_CHILD; + if ( !IsThisEnabled() ) + style |= WS_DISABLED; + // using this flag results in very significant reduction in flicker, // especially with controls inside the static boxes (as the interior of the // box is not redrawn twice), but sometimes results in redraw problems, so diff --git a/tests/controls/buttontest.cpp b/tests/controls/buttontest.cpp index 764de5b28e..4f84523828 100644 --- a/tests/controls/buttontest.cpp +++ b/tests/controls/buttontest.cpp @@ -102,8 +102,21 @@ void ButtonTestCase::Disabled() wxUIActionSimulator sim; - //In this test we disable the button and check events are not sent - m_button->Disable(); + // In this test we disable the button and check events are not sent and we + // do it once by disabling the previously enabled button and once by + // creating the button in the disabled state. + SECTION("Disable after creation") + { + m_button->Disable(); + } + + SECTION("Create disabled") + { + delete m_button; + m_button = new wxButton(); + m_button->Disable(); + m_button->Create(wxTheApp->GetTopWindow(), wxID_ANY, "wxButton"); + } sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10)); wxYield();