From 8d6a2b39214438fd42322b8f4083aed8bdccc3d1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 4 Sep 2015 16:23:13 +0200 Subject: [PATCH] Don't send wxActivateEvent for minimized windows in wxMSW Unexpectedly, minimizing the window by clicking on its taskbar icon resulted in a wxActivateEvent. This broke the focus handling in wxTLW and resulted in debug messages about ::SetFocus() failure whenever the window was minimized in this way. It also seems that other existing code doesn't take into account the possibility of getting an "active" activation event when the window is minimized and this doesn't happen in the other ports, so don't send this event in wxMSW neither. Closes #17128. --- docs/changes.txt | 1 + interface/wx/event.h | 5 +++++ src/msw/window.cpp | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index cafb0c207c..58906a5396 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -167,6 +167,7 @@ wxMSW: - Avoid bogus assert after calling wxDatePickerCtrl::SetRange(). - Add solution file for building with MSVS 2014 (Peter Tissen). - Correct wxGetOsDescription() for Windows 10 (Tobias Taschner). +- Don't send wxActivateEvent for minimized windows (bzcdr). wxOSX/Cocoa: diff --git a/interface/wx/event.h b/interface/wx/event.h index 413c293ba9..3148c50966 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -3005,6 +3005,11 @@ public: a @c wxEVT_ACTIVATE or @c wxEVT_ACTIVATE_APP event. @endEventTable + @note Until wxWidgets 3.1.0 activation events could be sent by wxMSW when + the window was minimized. This reflected the native MSW behaviour but was + often surprising and unexpected, so starting from 3.1.0 such events are not + sent any more when the window is in the minimized state. + @library{wxcore} @category{events} diff --git a/src/msw/window.cpp b/src/msw/window.cpp index bfa3efd17c..34707fad7c 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4044,9 +4044,19 @@ bool wxWindowMSW::HandleDestroy() // --------------------------------------------------------------------------- bool wxWindowMSW::HandleActivate(int state, - bool WXUNUSED(minimized), - WXHWND WXUNUSED(activate)) + bool minimized, + WXHWND WXUNUSED(activate)) { + if ( minimized ) + { + // Getting activation event when the window is minimized, as happens + // e.g. when the window task bar icon is clicked, is unexpected and + // managed to even break the logic in wx itself (see #17128), so just + // don't do it as there doesn't seem to be any need to be notified + // about the activation of the window icon in the task bar in practice. + return false; + } + wxActivateEvent event(wxEVT_ACTIVATE, (state == WA_ACTIVE) || (state == WA_CLICKACTIVE), m_windowId,