From 3c3b6f606364ae8bd86eeeb3e129636c5294ea85 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Nov 2012 14:32:15 +0000 Subject: [PATCH] Add possibility to delay showing wxRichToolTip. Optionally show the tooltip after a delay instead of doing it immediately when Show() is called. Closes #14846. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72997 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/generic/private/richtooltip.h | 9 ++-- include/wx/private/richtooltip.h | 5 +- include/wx/richtooltip.h | 5 +- interface/wx/richtooltip.h | 16 ++++--- samples/dialogs/dialogs.cpp | 14 ++++-- src/common/richtooltipcmn.cpp | 7 +-- src/generic/richtooltipg.cpp | 60 ++++++++++++++++++------ src/msw/richtooltip.cpp | 12 +++-- 9 files changed, 91 insertions(+), 38 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index ed1b5ad72b..f364429e5d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -593,6 +593,7 @@ All (GUI): - Added wxControl::GetSizeFromTextSize() (Manuel Martin). - Optionally allow showing tooltips for disabled ribbon buttons (wxBen). - Add wxTL_NO_HEADER style to wxTreeListCtrl (robboto). +- Add possibility to delay showing wxRichToolTip (John Roberts). wxGTK: diff --git a/include/wx/generic/private/richtooltip.h b/include/wx/generic/private/richtooltip.h index ad8283fe8a..8cd1b0e0dd 100644 --- a/include/wx/generic/private/richtooltip.h +++ b/include/wx/generic/private/richtooltip.h @@ -3,7 +3,7 @@ // Purpose: wxRichToolTipGenericImpl declaration. // Author: Vadim Zeitlin // Created: 2011-10-18 -// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $ +// RCS-ID: $Id$ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -30,13 +30,15 @@ public: // This is pretty arbitrary, we could follow MSW and use some multiple // of double-click time here. m_timeout = 5000; + m_delay = 0; } virtual void SetBackgroundColour(const wxColour& col, const wxColour& colEnd); virtual void SetCustomIcon(const wxIcon& icon); virtual void SetStandardIcon(int icon); - virtual void SetTimeout(unsigned milliseconds); + virtual void SetTimeout(unsigned milliseconds, + unsigned millisecondsDelay = 0); virtual void SetTipKind(wxTipKind tipKind); virtual void SetTitleFont(const wxFont& font); @@ -52,7 +54,8 @@ private: wxColour m_colStart, m_colEnd; - unsigned m_timeout; + unsigned m_timeout, + m_delay; wxTipKind m_tipKind; diff --git a/include/wx/private/richtooltip.h b/include/wx/private/richtooltip.h index 75d30a9d1f..ad655c7d15 100644 --- a/include/wx/private/richtooltip.h +++ b/include/wx/private/richtooltip.h @@ -3,7 +3,7 @@ // Purpose: wxRichToolTipImpl declaration. // Author: Vadim Zeitlin // Created: 2011-10-18 -// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $ +// RCS-ID: $Id$ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -29,7 +29,8 @@ public: const wxColour& colEnd) = 0; virtual void SetCustomIcon(const wxIcon& icon) = 0; virtual void SetStandardIcon(int icon) = 0; - virtual void SetTimeout(unsigned milliseconds) = 0; + virtual void SetTimeout(unsigned milliseconds, + unsigned millisecondsShowdelay = 0) = 0; virtual void SetTipKind(wxTipKind tipKind) = 0; virtual void SetTitleFont(const wxFont& font) = 0; diff --git a/include/wx/richtooltip.h b/include/wx/richtooltip.h index 7c72ed6528..c642b04c2b 100644 --- a/include/wx/richtooltip.h +++ b/include/wx/richtooltip.h @@ -3,7 +3,7 @@ // Purpose: Declaration of wxRichToolTip class. // Author: Vadim Zeitlin // Created: 2011-10-07 -// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $ +// RCS-ID: $Id$ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -76,7 +76,8 @@ public: // elapses but this method can be used to change this or also disable // hiding the tooltip automatically entirely by passing 0 in this parameter // (but doing this can result in native version not being used). - void SetTimeout(unsigned milliseconds); + // Optionally specify a show delay. + void SetTimeout(unsigned milliseconds, unsigned millisecondsShowdelay = 0); // Choose the tip kind, possibly none. By default the tip is positioned // automatically, as if wxTipKind_Auto was used. diff --git a/interface/wx/richtooltip.h b/interface/wx/richtooltip.h index e8c6a99694..6e0a014411 100644 --- a/interface/wx/richtooltip.h +++ b/interface/wx/richtooltip.h @@ -133,17 +133,21 @@ public: //@} /** - Set timeout after which the tooltip should disappear, in milliseconds. + Set timeout after which the tooltip should disappear and + optionally set a delay before the tooltip is shown, in milliseconds. - By default the tooltip is hidden after system-dependent interval of - time elapses but this method can be used to change this or also disable - hiding the tooltip automatically entirely by passing 0 in this parameter - (but doing this will prevent the native MSW version from being used). + By default the tooltip is shown immediately and hidden after a + system-dependent interval of time elapses. This method can be used to + change this or also disable hiding the tooltip automatically entirely + by passing 0 in this parameter (but doing this will prevent the native + MSW version from being used). Notice that the tooltip will always be hidden if the user presses a key or clicks a mouse button. + + Parameter @a millisecondsDelay is new since wxWidgets 2.9.5. */ - void SetTimeout(unsigned milliseconds); + void SetTimeout(unsigned millisecondsTimeout, unsigned millisecondsDelay = 0); /** Choose the tip kind, possibly none. diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index bc8d2601bb..0adb60f99f 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -1854,13 +1854,14 @@ public: WXSIZEOF(bgStyles), bgStyles, 1, wxRA_SPECIFY_ROWS); - const wxString timeouts[] = { "&None", "&Default", "&3 seconds" }; + const wxString timeouts[] = { "&None", "&Default (no delay)", "&3 seconds" }; wxCOMPILE_TIME_ASSERT( WXSIZEOF(timeouts) == Timeout_Max, TmMismatch ); m_timeouts = new wxRadioBox(this, wxID_ANY, "Timeout:", wxDefaultPosition, wxDefaultSize, WXSIZEOF(timeouts), timeouts, 1, wxRA_SPECIFY_ROWS); m_timeouts->SetSelection(Timeout_Default); + m_timeDelay = new wxCheckBox(this, wxID_ANY, "Delay show" ); // Lay them out. m_textBody->SetMinSize(wxSize(300, 200)); @@ -1872,6 +1873,7 @@ public: sizer->Add(m_tipKinds, wxSizerFlags().Centre().Border()); sizer->Add(m_bgStyles, wxSizerFlags().Centre().Border()); sizer->Add(m_timeouts, wxSizerFlags().Centre().Border()); + sizer->Add(m_timeDelay, wxSizerFlags().Centre().Border()); wxBoxSizer* const sizerBtns = new wxBoxSizer(wxHORIZONTAL); sizerBtns->Add(btnShowText, wxSizerFlags().Border(wxRIGHT)); sizerBtns->Add(btnShowBtn, wxSizerFlags().Border(wxLEFT)); @@ -1972,17 +1974,22 @@ private: break; } + int delay = m_timeDelay->IsChecked() ? 500 : 0; + switch ( m_timeouts->GetSelection() ) { case Timeout_None: - tip.SetTimeout(0); + // Don't call SetTimeout unnecessarily + // or msw will show generic impl + if ( delay ) + tip.SetTimeout(0, delay); break; case Timeout_Default: break; case Timeout_3sec: - tip.SetTimeout(3000); + tip.SetTimeout(3000, delay); break; } @@ -1997,6 +2004,7 @@ private: wxRadioBox* m_tipKinds; wxRadioBox* m_bgStyles; wxRadioBox* m_timeouts; + wxCheckBox* m_timeDelay; }; void MyFrame::OnRichTipDialog(wxCommandEvent& WXUNUSED(event)) diff --git a/src/common/richtooltipcmn.cpp b/src/common/richtooltipcmn.cpp index 5914af4ad2..b319bd29fe 100644 --- a/src/common/richtooltipcmn.cpp +++ b/src/common/richtooltipcmn.cpp @@ -3,7 +3,7 @@ // Purpose: wxRichToolTip implementation common to all platforms. // Author: Vadim Zeitlin // Created: 2011-10-18 -// RCS-ID: $Id: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $ +// RCS-ID: $Id$ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -57,9 +57,10 @@ void wxRichToolTip::SetIcon(const wxIcon& icon) m_impl->SetCustomIcon(icon); } -void wxRichToolTip::SetTimeout(unsigned milliseconds) +void wxRichToolTip::SetTimeout(unsigned milliseconds, + unsigned millisecondsDelay) { - m_impl->SetTimeout(milliseconds); + m_impl->SetTimeout(milliseconds, millisecondsDelay); } void wxRichToolTip::SetTipKind(wxTipKind tipKind) diff --git a/src/generic/richtooltipg.cpp b/src/generic/richtooltipg.cpp index b3e4709ac9..b37410fd57 100644 --- a/src/generic/richtooltipg.cpp +++ b/src/generic/richtooltipg.cpp @@ -3,7 +3,7 @@ // Purpose: Implementation of wxRichToolTip. // Author: Vadim Zeitlin // Created: 2011-10-07 -// RCS-ID: $Id: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $ +// RCS-ID: $Id$ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -232,7 +232,7 @@ public: } } - void DoShow() + void SetPosition() { wxPoint pos = GetTipPoint(); @@ -241,18 +241,30 @@ public: pos -= m_anchorPos; Move(pos, wxSIZE_NO_ADJUSTMENTS); + } + void DoShow() + { Popup(); } - void SetTimeout(unsigned timeout) + void SetTimeoutAndShow(unsigned timeout, unsigned delay) { - if ( !timeout ) + if ( !timeout && !delay ) + { + DoShow(); return; + } Connect(wxEVT_TIMER, wxTimerEventHandler(wxRichToolTipPopup::OnTimer)); - m_timer.Start(timeout, true /* one shot */); + m_timeout = timeout; // set for use in OnTimer if we have a delay + m_delayShow = delay != 0; + + if ( !m_delayShow ) + DoShow(); + + m_timer.Start((delay ? delay : timeout), true /* one shot */); } protected: @@ -560,10 +572,22 @@ private: // Timer event handler hides the tooltip when the timeout expires. void OnTimer(wxTimerEvent& WXUNUSED(event)) { - // Doing "Notify" here ensures that our OnDismiss() is called and so we - // also Destroy() ourselves. We could use Dismiss() and call Destroy() - // explicitly from here as well. - DismissAndNotify(); + if ( !m_delayShow ) + { + // Doing "Notify" here ensures that our OnDismiss() is called and so we + // also Destroy() ourselves. We could use Dismiss() and call Destroy() + // explicitly from here as well. + DismissAndNotify(); + + return; + } + + m_delayShow = false; + + if ( m_timeout ) + m_timer.Start(m_timeout, true); + + DoShow(); } @@ -574,6 +598,12 @@ private: // The timer counting down the time until we're hidden. wxTimer m_timer; + // We will need to accesss the timeout period when delaying showing tooltip. + int m_timeout; + + // If true, delay showing the tooltip. + bool m_delayShow; + wxDECLARE_NO_COPY_CLASS(wxRichToolTipPopup); }; @@ -621,9 +651,11 @@ void wxRichToolTipGenericImpl::SetStandardIcon(int icon) } } -void wxRichToolTipGenericImpl::SetTimeout(unsigned milliseconds) +void wxRichToolTipGenericImpl::SetTimeout(unsigned millisecondsTimeout, + unsigned millisecondsDelay) { - m_timeout = milliseconds; + m_delay = millisecondsDelay; + m_timeout = millisecondsTimeout; } void wxRichToolTipGenericImpl::SetTipKind(wxTipKind tipKind) @@ -653,9 +685,9 @@ void wxRichToolTipGenericImpl::ShowFor(wxWindow* win) popup->SetBackgroundColours(m_colStart, m_colEnd); - popup->DoShow(); - - popup->SetTimeout(m_timeout); + popup->SetPosition(); + // show or start the timer to delay showing the popup + popup->SetTimeoutAndShow( m_timeout, m_delay ); } // Currently only wxMSW provides a native implementation. diff --git a/src/msw/richtooltip.cpp b/src/msw/richtooltip.cpp index 5751118153..3cc679abff 100644 --- a/src/msw/richtooltip.cpp +++ b/src/msw/richtooltip.cpp @@ -3,7 +3,7 @@ // Purpose: Native MSW implementation of wxRichToolTip. // Author: Vadim Zeitlin // Created: 2011-10-18 -// RCS-ID: $Id: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $ +// RCS-ID: $Id$ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -123,13 +123,15 @@ public: } } - virtual void SetTimeout(unsigned milliseconds) + virtual void SetTimeout(unsigned millisecondsTimeout, + unsigned millisecondsDelay) { - // We don't support changing the timeout (maybe TTM_SETDELAYTIME could - // be used for this?). + // We don't support changing the timeout or the delay + // (maybe TTM_SETDELAYTIME could be used for this?). m_canUseNative = false; - wxRichToolTipGenericImpl::SetTimeout(milliseconds); + wxRichToolTipGenericImpl::SetTimeout(millisecondsTimeout, + millisecondsDelay); } virtual void SetTipKind(wxTipKind tipKind) -- 2.45.2