From d3feb55c4990a28bbf3c43c239865a958dd6de62 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Nov 2012 14:18:17 +0000 Subject: [PATCH] Add "rect" paramerer to wxRichToolTip::ShowFor(). Allow to show the tooltip at the exact specified position instead of placing it automatically. Closes #14862. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73050 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/generic/private/richtooltip.h | 2 +- include/wx/private/richtooltip.h | 2 +- include/wx/richtooltip.h | 4 ++-- interface/wx/richtooltip.h | 15 ++++++++++----- src/common/richtooltipcmn.cpp | 4 ++-- src/generic/richtooltipg.cpp | 13 +++++++++---- src/msw/richtooltip.cpp | 6 +++--- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f3b0434f2a..48bf721253 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -594,6 +594,7 @@ All (GUI): - 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). +- Add "rect" paramerer to wxRichToolTip::ShowFor() (John Roberts). wxGTK: diff --git a/include/wx/generic/private/richtooltip.h b/include/wx/generic/private/richtooltip.h index 8cd1b0e0dd..c296b0c5ef 100644 --- a/include/wx/generic/private/richtooltip.h +++ b/include/wx/generic/private/richtooltip.h @@ -42,7 +42,7 @@ public: virtual void SetTipKind(wxTipKind tipKind); virtual void SetTitleFont(const wxFont& font); - virtual void ShowFor(wxWindow* win); + virtual void ShowFor(wxWindow* win, wxRect* rect = NULL); protected: wxString m_title, diff --git a/include/wx/private/richtooltip.h b/include/wx/private/richtooltip.h index ad655c7d15..c55b6d8dd4 100644 --- a/include/wx/private/richtooltip.h +++ b/include/wx/private/richtooltip.h @@ -34,7 +34,7 @@ public: virtual void SetTipKind(wxTipKind tipKind) = 0; virtual void SetTitleFont(const wxFont& font) = 0; - virtual void ShowFor(wxWindow* win) = 0; + virtual void ShowFor(wxWindow* win, wxRect* rect = NULL) = 0; virtual ~wxRichToolTipImpl() { } diff --git a/include/wx/richtooltip.h b/include/wx/richtooltip.h index c642b04c2b..4052a5d00c 100644 --- a/include/wx/richtooltip.h +++ b/include/wx/richtooltip.h @@ -87,8 +87,8 @@ public: // or colour appropriate for the current platform. void SetTitleFont(const wxFont& font); - // Show the tooltip for the given window. - void ShowFor(wxWindow* win); + // Show the tooltip for the given window and optionally a specified area. + void ShowFor(wxWindow* win, wxRect* rect = NULL); // Non-virtual dtor as this class is not supposed to be derived from. ~wxRichToolTip(); diff --git a/interface/wx/richtooltip.h b/interface/wx/richtooltip.h index 6e0a014411..6c4615d442 100644 --- a/interface/wx/richtooltip.h +++ b/interface/wx/richtooltip.h @@ -175,15 +175,20 @@ public: void SetTitleFont(const wxFont& font); /** - Show the tooltip for the given window. + Show the tooltip for the given window and optionally specify where to + show the tooltip. - The tooltip tip points to the (middle of the) specified window which - must be non-@NULL. + By default the tooltip tip points to the (middle of the) specified + window which must be non-@NULL or, if @a rect is non-@NULL, the middle + of the specified wxRect. Currently the native MSW implementation is used only if @a win is a - wxTextCtrl. This limitation may be removed in the future. + wxTextCtrl and @a rect is @NULL. This limitation may be removed in the + future. + + Parameter @a rect is new since wxWidgets 2.9.5. */ - void ShowFor(wxWindow* win); + void ShowFor(wxWindow* win, wxRect* rect = NULL); /** Destructor. diff --git a/src/common/richtooltipcmn.cpp b/src/common/richtooltipcmn.cpp index b319bd29fe..c4671f63f1 100644 --- a/src/common/richtooltipcmn.cpp +++ b/src/common/richtooltipcmn.cpp @@ -73,11 +73,11 @@ void wxRichToolTip::SetTitleFont(const wxFont& font) m_impl->SetTitleFont(font); } -void wxRichToolTip::ShowFor(wxWindow* win) +void wxRichToolTip::ShowFor(wxWindow* win, wxRect* rect = NULL); { wxCHECK_RET( win, wxS("Must have a valid window") ); - m_impl->ShowFor(win); + m_impl->ShowFor(win, rect); } wxRichToolTip::~wxRichToolTip() diff --git a/src/generic/richtooltipg.cpp b/src/generic/richtooltipg.cpp index b37410fd57..282f27e7a9 100644 --- a/src/generic/richtooltipg.cpp +++ b/src/generic/richtooltipg.cpp @@ -232,9 +232,14 @@ public: } } - void SetPosition() + void SetPosition(wxRect* rect) { - wxPoint pos = GetTipPoint(); + wxPoint pos; + + if ( !rect || rect->IsEmpty() ) + pos = GetTipPoint(); + else + pos = 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. @@ -668,7 +673,7 @@ void wxRichToolTipGenericImpl::SetTitleFont(const wxFont& font) m_titleFont = font; } -void wxRichToolTipGenericImpl::ShowFor(wxWindow* win) +void wxRichToolTipGenericImpl::ShowFor(wxWindow* win, wxRect* rect = NULL); { // Set the focus to the window the tooltip refers to to make it look active. win->SetFocus(); @@ -685,7 +690,7 @@ void wxRichToolTipGenericImpl::ShowFor(wxWindow* win) popup->SetBackgroundColours(m_colStart, m_colEnd); - popup->SetPosition(); + popup->SetPosition(rect); // show or start the timer to delay showing the popup popup->SetTimeoutAndShow( m_timeout, m_delay ); } diff --git a/src/msw/richtooltip.cpp b/src/msw/richtooltip.cpp index 3cc679abff..4fd5c0206b 100644 --- a/src/msw/richtooltip.cpp +++ b/src/msw/richtooltip.cpp @@ -151,13 +151,13 @@ public: wxRichToolTipGenericImpl::SetTitleFont(font); } - virtual void ShowFor(wxWindow* win) + virtual void ShowFor(wxWindow* win, wxRect* rect = NULL); { // TODO: We could use native tooltip control to show native balloon // tooltips for any window but right now we use the simple // EM_SHOWBALLOONTIP API which can only be used with text // controls. - if ( m_canUseNative ) + if ( m_canUseNative && !rect ) { wxTextCtrl* const text = wxDynamicCast(win, wxTextCtrl); if ( text ) @@ -175,7 +175,7 @@ public: // Don't set m_canUseNative to false here, we could be able to use the // native tooltips if we're called for a different window the next // time. - wxRichToolTipGenericImpl::ShowFor(win); + wxRichToolTipGenericImpl::ShowFor(win, rect); } private: -- 2.45.2