From 558a94bd4aa3ebb90e95978bc3501a6496014396 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 23 Mar 2011 17:36:10 +0000 Subject: [PATCH] clean up wxGTK tooltip code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67298 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/listbox.h | 6 +----- include/wx/gtk/radiobox.h | 2 +- include/wx/gtk/tooltip.h | 19 ++++++------------ include/wx/gtk/window.h | 2 +- src/gtk/listbox.cpp | 17 ---------------- src/gtk/radiobox.cpp | 2 +- src/gtk/tooltip.cpp | 49 +++++++++++++++-------------------------------- src/gtk/window.cpp | 31 +++++++++--------------------- 8 files changed, 34 insertions(+), 94 deletions(-) diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 791766f..038a534 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -82,11 +82,7 @@ public: // implementation from now on - GtkWidget *GetConnectWidget(); - -#if wxUSE_TOOLTIPS - void GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ); -#endif // wxUSE_TOOLTIPS + virtual GtkWidget *GetConnectWidget(); struct _GtkTreeView *m_treeview; struct _GtkListStore *m_liststore; diff --git a/include/wx/gtk/radiobox.h b/include/wx/gtk/radiobox.h index 901a09d..2fe3566 100644 --- a/include/wx/gtk/radiobox.h +++ b/include/wx/gtk/radiobox.h @@ -131,7 +131,7 @@ public: void GtkDisableEvents(); void GtkEnableEvents(); #if wxUSE_TOOLTIPS - void GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ); + virtual void GTKApplyToolTip(const char* tip); #endif // wxUSE_TOOLTIPS wxRadioBoxButtonsInfoList m_buttonsInfo; diff --git a/include/wx/gtk/tooltip.h b/include/wx/gtk/tooltip.h index 0135be8..6a01dd6 100644 --- a/include/wx/gtk/tooltip.h +++ b/include/wx/gtk/tooltip.h @@ -7,10 +7,9 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef __GTKTOOLTIPH__ -#define __GTKTOOLTIPH__ +#ifndef _WX_GTKTOOLTIP_H_ +#define _WX_GTKTOOLTIP_H_ -#include "wx/defs.h" #include "wx/string.h" #include "wx/object.h" @@ -18,7 +17,6 @@ // forward declarations //----------------------------------------------------------------------------- -class WXDLLIMPEXP_FWD_CORE wxToolTip; class WXDLLIMPEXP_FWD_CORE wxWindow; //----------------------------------------------------------------------------- @@ -43,15 +41,10 @@ public: wxString GetTip() const { return m_text; } wxWindow *GetWindow() const { return m_window; } - bool IsOk() const { return m_window != NULL; } - - // this forwards back to wxWindow::GTKApplyToolTip() - void GTKApply( wxWindow *win ); - - // this just sets the given tooltip for the specified widget - // tip must be UTF-8 encoded - static void GTKApply(GtkWidget *w, const gchar *tip); + // Implementation + void GTKSetWindow(wxWindow* win); + static void GTKApply(GtkWidget* widget, const char* tip); private: wxString m_text; @@ -60,4 +53,4 @@ private: DECLARE_ABSTRACT_CLASS(wxToolTip) }; -#endif // __GTKTOOLTIPH__ +#endif // _WX_GTKTOOLTIP_H_ diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index d794b8c..df2e41d 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -218,7 +218,7 @@ public: #if wxUSE_TOOLTIPS // applies tooltip to the widget (tip must be UTF-8 encoded) - virtual void GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ); + virtual void GTKApplyToolTip(const char* tip); #endif // wxUSE_TOOLTIPS // Called when a window should delay showing itself diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index d62d0bf..5c2da5c 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -841,23 +841,6 @@ int wxListBox::DoListHitTest(const wxPoint& point) const // helpers // ---------------------------------------------------------------------------- -#if wxUSE_TOOLTIPS -void wxListBox::GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ) -{ -#if GTK_CHECK_VERSION(2, 12, 0) - if (!gtk_check_version(2, 12, 0)) - { - gtk_widget_set_tooltip_text(GTK_WIDGET( m_treeview ), tip); - } - else -#endif - { - // RN: Is this needed anymore? - gtk_tooltips_set_tip( tips, GTK_WIDGET( m_treeview ), tip, NULL ); - } -} -#endif // wxUSE_TOOLTIPS - GtkWidget *wxListBox::GetConnectWidget() { // the correct widget for listbox events (such as mouse clicks for example) diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 0f0c535..887d1a3 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -565,7 +565,7 @@ void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w) } #if wxUSE_TOOLTIPS -void wxRadioBox::GTKApplyToolTip(GtkTooltips * WXUNUSED(tips), const gchar *tip) +void wxRadioBox::GTKApplyToolTip(const char* tip) { // set this tooltip for all radiobuttons which don't have their own tips unsigned n = 0; diff --git a/src/gtk/tooltip.cpp b/src/gtk/tooltip.cpp index 53707ef..ffcb59d 100644 --- a/src/gtk/tooltip.cpp +++ b/src/gtk/tooltip.cpp @@ -33,48 +33,38 @@ static GtkTooltips *gs_tooltips = NULL; IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject) wxToolTip::wxToolTip( const wxString &tip ) + : m_text(tip) { - m_text = tip; m_window = NULL; } void wxToolTip::SetTip( const wxString &tip ) { m_text = tip; - GTKApply( m_window ); + if (m_window) + m_window->GTKApplyToolTip(wxGTK_CONV_SYS(m_text)); } -void wxToolTip::GTKApply( wxWindow *win ) +void wxToolTip::GTKSetWindow(wxWindow* win) { - if (!win) - return; - - if ( !gs_tooltips ) - gs_tooltips = gtk_tooltips_new(); - + wxASSERT(win); m_window = win; - - if (m_text.empty()) - m_window->GTKApplyToolTip( gs_tooltips, NULL ); - else - m_window->GTKApplyToolTip( gs_tooltips, wxGTK_CONV_SYS(m_text) ); + m_window->GTKApplyToolTip(wxGTK_CONV_SYS(m_text)); } /* static */ -void wxToolTip::GTKApply(GtkWidget *w, const gchar *tip) +void wxToolTip::GTKApply(GtkWidget* widget, const char* tip) { #if GTK_CHECK_VERSION(2, 12, 0) if (!gtk_check_version(2, 12, 0)) - { - gtk_widget_set_tooltip_text(w, tip); - } + gtk_widget_set_tooltip_text(widget, tip); else #endif { if ( !gs_tooltips ) gs_tooltips = gtk_tooltips_new(); - gtk_tooltips_set_tip(gs_tooltips, w, tip, NULL); + gtk_tooltips_set_tip(gs_tooltips, widget, tip, NULL); } } @@ -84,15 +74,14 @@ void wxToolTip::Enable( bool flag ) if (!gtk_check_version(2, 12, 0)) { GtkSettings* settings = gtk_settings_get_default(); - if(!settings) - return; - gtk_settings_set_long_property(settings, "gtk-enable-tooltips", flag?TRUE:FALSE, NULL); + if (settings) + gtk_settings_set_long_property(settings, "gtk-enable-tooltips", flag, NULL); } else #endif { if (!gs_tooltips) - return; + gs_tooltips = gtk_tooltips_new(); if (flag) gtk_tooltips_enable( gs_tooltips ); @@ -101,29 +90,21 @@ void wxToolTip::Enable( bool flag ) } } -G_BEGIN_DECLS -void gtk_tooltips_set_delay (GtkTooltips *tooltips, - guint delay); -G_END_DECLS - void wxToolTip::SetDelay( long msecs ) { #if GTK_CHECK_VERSION(2, 12, 0) if (!gtk_check_version(2, 12, 0)) { GtkSettings* settings = gtk_settings_get_default(); - if(!settings) - return; - gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", msecs, NULL); + if (settings) + gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", msecs, NULL); } else #endif { if (!gs_tooltips) - return; + gs_tooltips = gtk_tooltips_new(); - // FIXME: This is a deprecated function and might not even have an effect. - // Try to not use it, after which remove the prototype above. gtk_tooltips_set_delay( gs_tooltips, (int)msecs ); } } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 8638aa0..d09edd5 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -3778,33 +3778,20 @@ void wxWindowGTK::ClearBackground() #if wxUSE_TOOLTIPS void wxWindowGTK::DoSetToolTip( wxToolTip *tip ) { - wxWindowBase::DoSetToolTip(tip); - - if (m_tooltip) - { - m_tooltip->GTKApply( (wxWindow *)this ); - } - else + if (m_tooltip != tip) { - GtkWidget *w = GetConnectWidget(); - wxToolTip::GTKApply(w, NULL); + wxWindowBase::DoSetToolTip(tip); + + if (m_tooltip) + m_tooltip->GTKSetWindow(static_cast(this)); + else + GTKApplyToolTip(NULL); } } -void wxWindowGTK::GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ) +void wxWindowGTK::GTKApplyToolTip(const char* tip) { - GtkWidget *w = GetConnectWidget(); - -#if GTK_CHECK_VERSION(2, 12, 0) - if (!gtk_check_version(2, 12, 0)) - { - gtk_widget_set_tooltip_text (w, tip); - } - else -#endif - { - gtk_tooltips_set_tip(tips, w, tip, NULL); - } + wxToolTip::GTKApply(GetConnectWidget(), tip); } #endif // wxUSE_TOOLTIPS -- 2.7.4