X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ccc0835d0266869b5295a0923b37cacb71b9e61b..12bb29f5432174ecbd65549bda832d70d34a98ae:/src/generic/richtooltipg.cpp?ds=inline diff --git a/src/generic/richtooltipg.cpp b/src/generic/richtooltipg.cpp index b3e4709ac9..5d08e1261a 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,27 +232,44 @@ public: } } - void DoShow() + void SetPosition(const wxRect* rect) { - wxPoint pos = GetTipPoint(); + wxPoint pos; + + if ( !rect || rect->IsEmpty() ) + pos = GetTipPoint(); + else + pos = GetParent()->ClientToScreen( wxPoint( rect->x + rect->width / 2, rect->y + rect->height / 2 ) ); // We want our anchor point to coincide with this position so offset // the position of the top left corner passed to Move() accordingly. 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 +577,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 +603,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 +656,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) @@ -636,7 +673,7 @@ void wxRichToolTipGenericImpl::SetTitleFont(const wxFont& font) m_titleFont = font; } -void wxRichToolTipGenericImpl::ShowFor(wxWindow* win) +void wxRichToolTipGenericImpl::ShowFor(wxWindow* win, const wxRect* rect) { // Set the focus to the window the tooltip refers to to make it look active. win->SetFocus(); @@ -653,9 +690,9 @@ void wxRichToolTipGenericImpl::ShowFor(wxWindow* win) popup->SetBackgroundColours(m_colStart, m_colEnd); - popup->DoShow(); - - popup->SetTimeout(m_timeout); + popup->SetPosition(rect); + // show or start the timer to delay showing the popup + popup->SetTimeoutAndShow( m_timeout, m_delay ); } // Currently only wxMSW provides a native implementation.