From cb7ef329e79d7d5ece580924fde20b347124e421 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 Mar 2011 11:10:38 +0000 Subject: [PATCH] Fix setting tooltips for generic wxSpinCtrl. Forward the tooltip set for the control to its subcontrols. Closes #9817. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67199 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/generic/spinctlg.h | 3 +++ src/generic/spinctlg.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 407b501d3b..6d61b9b16f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -489,6 +489,7 @@ All (GUI): - Added wxFont::Underlined() and MakeUnderlined() methods. - Added wxFont::SetSymbolicSize() and related methods. - Fix SVG files generation in locales using decimal comma (snowleopard). +- Fix setting tooltips for generic wxSpinCtrl (Catalin Raceanu). GTK: diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index aa44dc989a..56eda17f9f 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -82,6 +82,9 @@ public: virtual bool Enable(bool enable = true); virtual bool Show(bool show = true); virtual bool Reparent(wxWindowBase *newParent); +#if wxUSE_TOOLTIPS + virtual void DoSetToolTip(wxToolTip *tip); +#endif // wxUSE_TOOLTIPS // get the subcontrols wxTextCtrl *GetText() const { return m_textCtrl; } diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index 796f89efb5..ca2a1bb465 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -29,6 +29,7 @@ #endif //WX_PRECOMP #include "wx/spinctrl.h" +#include "wx/tooltip.h" #if wxUSE_SPINCTRL @@ -192,6 +193,10 @@ bool wxSpinCtrlGenericBase::Create(wxWindow *parent, m_textCtrl = new wxSpinCtrlTextGeneric(this, value, style); m_spinButton = new wxSpinCtrlButtonGeneric(this, style); +#if wxUSE_TOOLTIPS + m_textCtrl->SetToolTip(GetToolTipText()); + m_spinButton->SetToolTip(GetToolTipText()); +#endif // wxUSE_TOOLTIPS m_spin_value = m_spinButton->GetValue(); @@ -321,6 +326,33 @@ bool wxSpinCtrlGenericBase::Reparent(wxWindowBase *newParent) 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 + // ---------------------------------------------------------------------------- // Handle sub controls events // ----------------------------------------------------------------------------