From 35434eea52d24f1ad964bc5e0697747ec0cd82da Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 2 Jun 2014 01:15:39 +0000 Subject: [PATCH] Hide tooltip when its associated window is hidden in wxMSW. Don't leave the tooltip shown on screen if the window it was shown for was hidden or iconized (without moving the mouse, as that would have dismissed the tooltip as well). Closes #16265. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/tooltip.h | 4 ++++ src/msw/tooltip.cpp | 34 ++++++++++++++++++++++++++++++++++ src/msw/toplevel.cpp | 3 +++ 3 files changed, 41 insertions(+) diff --git a/include/wx/msw/tooltip.h b/include/wx/msw/tooltip.h index 68ea492031..fd3fe908f0 100644 --- a/include/wx/msw/tooltip.h +++ b/include/wx/msw/tooltip.h @@ -69,6 +69,10 @@ public: // makes sense to use it for tooltips associated with a single window only. void SetRect(const wxRect& rc); + // Called when TLW shown state is changed and hides the tooltip itself if + // the window it's associated with is hidden. + static void UpdateVisibility(); + private: // Adds a window other than our main m_window to this tooltip. void DoAddHWND(WXHWND hWnd); diff --git a/src/msw/tooltip.cpp b/src/msw/tooltip.cpp index 053080aaeb..1ff9a95eb2 100644 --- a/src/msw/tooltip.cpp +++ b/src/msw/tooltip.cpp @@ -298,6 +298,40 @@ WXHWND wxToolTip::GetToolTipCtrl() return ms_hwndTT; } +/* static */ +void wxToolTip::UpdateVisibility() +{ + wxToolInfo ti(NULL, 0, wxRect()); + ti.uFlags = 0; + + if ( !SendTooltipMessage(ms_hwndTT, TTM_GETCURRENTTOOL, &ti) ) + return; + + wxWindow* const associatedWindow = wxFindWinFromHandle(ti.hwnd); + if ( !associatedWindow ) + return; + + bool hideTT = false; + if ( !associatedWindow->IsShownOnScreen() ) + { + // If the associated window or its parent is hidden, the tooltip + // shouldn't remain shown. + hideTT = true; + } + else + { + // Even if it's not hidden, it could also be iconized. + wxTopLevelWindow* const + frame = wxDynamicCast(wxGetTopLevelParent(associatedWindow), wxTopLevelWindow); + + if ( frame && frame->IsIconized() ) + hideTT = true; + } + + if ( hideTT ) + ::ShowWindow(ms_hwndTT, SW_HIDE); +} + /* static */ void wxToolTip::RelayEvent(WXMSG *msg) { diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index d4da7ed7b5..54e3d09bf1 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -717,6 +717,9 @@ void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) // makes it not iconized and only minimizing it does make it iconized. m_iconized = nShowCmd == SW_MINIMIZE; } + + // Don't leave a tooltip hanging around if TLW is hidden now. + wxToolTip::UpdateVisibility(); } void wxTopLevelWindowMSW::ShowWithoutActivating()