X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/00405b6c68db3713740835e47912aba00ea8a1f8..404b319a85dadd7decf7a5a5331020520031a41c:/src/generic/richtooltipg.cpp?ds=sidebyside diff --git a/src/generic/richtooltipg.cpp b/src/generic/richtooltipg.cpp index 2cbce1e6fd..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 /////////////////////////////////////////////////////////////////////////////// @@ -170,7 +170,7 @@ public: Layout(); } - void SetBackground(wxColour colStart, wxColour colEnd) + void SetBackgroundColours(wxColour colStart, wxColour colEnd) { if ( !colStart.IsOk() ) { @@ -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(); @@ -651,11 +688,11 @@ void wxRichToolTipGenericImpl::ShowFor(wxWindow* win) m_titleFont ); - popup->SetBackground(m_colStart, m_colEnd); - - popup->DoShow(); + popup->SetBackgroundColours(m_colStart, m_colEnd); - 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.