]> git.saurik.com Git - wxWidgets.git/commitdiff
clean up wxGTK tooltip code
authorPaul Cornett <paulcor@bullseye.com>
Wed, 23 Mar 2011 17:36:10 +0000 (17:36 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Wed, 23 Mar 2011 17:36:10 +0000 (17:36 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67298 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/listbox.h
include/wx/gtk/radiobox.h
include/wx/gtk/tooltip.h
include/wx/gtk/window.h
src/gtk/listbox.cpp
src/gtk/radiobox.cpp
src/gtk/tooltip.cpp
src/gtk/window.cpp

index 791766f62f74a7e29d88a26fc1060d0cfc5a8371..038a53464b86920e535e933f1a66fabe13f9dd1a 100644 (file)
@@ -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;
index 901a09d845d614f5d8990d8b17c9b3e90d4a03c6..2fe356639626a94ecd33209e7f275ed34dc6b014 100644 (file)
@@ -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;
index 0135be8ee4e962b00c07644260930cba0b2ed8d5..6a01dd6468e08356de8b755bd4929717ce9cce09 100644 (file)
@@ -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_
index d794b8c1c135577c8fed6ed273b03c32735e760e..df2e41dc11559b594037cca9c6dcb5d42caf3ed9 100644 (file)
@@ -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
index d62d0bf3a4920f992d96607928914462b816eaa7..5c2da5cb53620e629a03abeff16627584f30a94e 100644 (file)
@@ -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)
index 0f0c5350c78568d2cac046e30b1bac1411610533..887d1a3d9a1f814c94810c28d6d9157d775d1db1 100644 (file)
@@ -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;
index 53707efbc7e39f87f09db639a397bae4a737ae3a..ffcb59d4c1b9aab0a1647c85729126b1d748b171 100644 (file)
@@ -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 );
     }
 }
index 8638aa03314930f79f3b7c354536c005287013c2..d09edd5c64e5820a169ff8f60a20764295b4b4c1 100644 (file)
@@ -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<wxWindow*>(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