From a2b0b8dbaa42cb3edebdec7166b91d42b1322b61 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2014 22:19:10 +0000 Subject: [PATCH] Handle updating tooltip text in wxCompositeWindow correctly. While calling SetToolTip(wxToolTip*) overload already worked correctly for wxCompositeWindow, using SetToolTip(wxString) did not if a tooltip already existed, as it didn't use the virtual DoSetToolTip() in this case, resulting in e.g. impossibility to update wxSpinCtrlDouble tooltip using this method. Fix this by introducing DoSetToolTipText() virtual which is used by that overload now and overriding it in wxCompositeWindow. Also don't override DoSetToolTip() in wxSpinCtrlGenericBase any more, it is not necessary as it's already done by its base class wxCompositeWindow. Closes #16595. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78245 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/compositewin.h | 10 ++++++++++ include/wx/generic/spinctlg.h | 3 --- include/wx/window.h | 3 ++- src/common/wincmn.cpp | 2 +- src/generic/spinctlg.cpp | 26 -------------------------- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index a9f6d35cbd..d905100266 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -123,6 +123,7 @@ wxMSW: - Drastically improve efficiency of selecting all items in wxDataViewCtrl. - Fix wxMenuEvent::GetMenu() for wxEVT_MENU_{OPEN,CLOSE} in MDI frames. - Added support for reading multi string values to wxRegKey (Carl Godkin). +- Fix updating wxSpinCtrlDouble tooltip text (Laurent Poujoulat). wxOSX/Cocoa: diff --git a/include/wx/compositewin.h b/include/wx/compositewin.h index a58d2e7e6c..0a9bbdff81 100644 --- a/include/wx/compositewin.h +++ b/include/wx/compositewin.h @@ -113,6 +113,16 @@ public: } #if wxUSE_TOOLTIPS + virtual void DoSetToolTipText(const wxString &tip) + { + BaseWindowClass::DoSetToolTipText(tip); + + // Use a variable to disambiguate between SetToolTip() overloads. + void (wxWindowBase::*func)(const wxString&) = &wxWindowBase::SetToolTip; + + SetForAllParts(func, tip); + } + virtual void DoSetToolTip(wxToolTip *tip) { BaseWindowClass::DoSetToolTip(tip); diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index a35cc8a4a4..3a914ef64d 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -83,9 +83,6 @@ public: // forward these functions to all subcontrols virtual bool Enable(bool enable = true); virtual bool Show(bool show = true); -#if wxUSE_TOOLTIPS - virtual void DoSetToolTip(wxToolTip *tip); -#endif // wxUSE_TOOLTIPS virtual bool SetBackgroundColour(const wxColour& colour); diff --git a/include/wx/window.h b/include/wx/window.h index 128d35de0e..b1f52a6325 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1312,7 +1312,7 @@ public: #if wxUSE_TOOLTIPS // the easiest way to set a tooltip for a window is to use this method - void SetToolTip( const wxString &tip ); + void SetToolTip( const wxString &tip ) { DoSetToolTipText(tip); } // attach a tooltip to the window, pointer can be NULL to remove // existing tooltip void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); } @@ -1787,6 +1787,7 @@ protected: virtual void DoCentre(int dir); #if wxUSE_TOOLTIPS + virtual void DoSetToolTipText( const wxString &tip ); virtual void DoSetToolTip( wxToolTip *tip ); #endif // wxUSE_TOOLTIPS diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 9b9da9a023..5640c43103 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2282,7 +2282,7 @@ wxString wxWindowBase::GetToolTipText() const return m_tooltip ? m_tooltip->GetTip() : wxString(); } -void wxWindowBase::SetToolTip( const wxString &tip ) +void wxWindowBase::DoSetToolTipText( const wxString &tip ) { // don't create the new tooltip if we already have one if ( m_tooltip ) diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index e14aa5b4b1..1a577dcde7 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -350,32 +350,6 @@ bool wxSpinCtrlGenericBase::Show(bool show) return true; } -#if wxUSE_TOOLTIPS -void wxSpinCtrlGenericBase::DoSetToolTip(wxToolTip *tip) -{ - // Notice that we must check for the subcontrols not being NULL (as they - // could be if we were created with the default ctor and this is called - // before Create() for some reason) and that we can't call SetToolTip(tip) - // because this would take ownership of the wxToolTip object (twice). - if ( m_textCtrl ) - { - if ( tip ) - m_textCtrl->SetToolTip(tip->GetTip()); - else - m_textCtrl->SetToolTip(NULL); - } - - if ( m_spinButton ) - { - if( tip ) - m_spinButton->SetToolTip(tip->GetTip()); - else - m_spinButton->SetToolTip(NULL); - } - - wxWindowBase::DoSetToolTip(tip); -} -#endif // wxUSE_TOOLTIPS bool wxSpinCtrlGenericBase::SetBackgroundColour(const wxColour& colour) {