clean up wxGTK tooltip code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67298 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2011-03-23 17:36:10 +00:00
parent 2a6545a5a7
commit 558a94bd4a
8 changed files with 34 additions and 94 deletions

View File

@@ -82,11 +82,7 @@ public:
// implementation from now on // implementation from now on
GtkWidget *GetConnectWidget(); virtual GtkWidget *GetConnectWidget();
#if wxUSE_TOOLTIPS
void GTKApplyToolTip( GtkTooltips *tips, const gchar *tip );
#endif // wxUSE_TOOLTIPS
struct _GtkTreeView *m_treeview; struct _GtkTreeView *m_treeview;
struct _GtkListStore *m_liststore; struct _GtkListStore *m_liststore;

View File

@@ -131,7 +131,7 @@ public:
void GtkDisableEvents(); void GtkDisableEvents();
void GtkEnableEvents(); void GtkEnableEvents();
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
void GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ); virtual void GTKApplyToolTip(const char* tip);
#endif // wxUSE_TOOLTIPS #endif // wxUSE_TOOLTIPS
wxRadioBoxButtonsInfoList m_buttonsInfo; wxRadioBoxButtonsInfoList m_buttonsInfo;

View File

@@ -7,10 +7,9 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __GTKTOOLTIPH__ #ifndef _WX_GTKTOOLTIP_H_
#define __GTKTOOLTIPH__ #define _WX_GTKTOOLTIP_H_
#include "wx/defs.h"
#include "wx/string.h" #include "wx/string.h"
#include "wx/object.h" #include "wx/object.h"
@@ -18,7 +17,6 @@
// forward declarations // forward declarations
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxToolTip;
class WXDLLIMPEXP_FWD_CORE wxWindow; class WXDLLIMPEXP_FWD_CORE wxWindow;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -43,15 +41,10 @@ public:
wxString GetTip() const { return m_text; } wxString GetTip() const { return m_text; }
wxWindow *GetWindow() const { return m_window; } wxWindow *GetWindow() const { return m_window; }
bool IsOk() const { return m_window != NULL; }
// Implementation
// this forwards back to wxWindow::GTKApplyToolTip() void GTKSetWindow(wxWindow* win);
void GTKApply( wxWindow *win ); static void GTKApply(GtkWidget* widget, const char* tip);
// this just sets the given tooltip for the specified widget
// tip must be UTF-8 encoded
static void GTKApply(GtkWidget *w, const gchar *tip);
private: private:
wxString m_text; wxString m_text;
@@ -60,4 +53,4 @@ private:
DECLARE_ABSTRACT_CLASS(wxToolTip) DECLARE_ABSTRACT_CLASS(wxToolTip)
}; };
#endif // __GTKTOOLTIPH__ #endif // _WX_GTKTOOLTIP_H_

View File

@@ -218,7 +218,7 @@ public:
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
// applies tooltip to the widget (tip must be UTF-8 encoded) // 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 #endif // wxUSE_TOOLTIPS
// Called when a window should delay showing itself // Called when a window should delay showing itself

View File

@@ -841,23 +841,6 @@ int wxListBox::DoListHitTest(const wxPoint& point) const
// helpers // 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() GtkWidget *wxListBox::GetConnectWidget()
{ {
// the correct widget for listbox events (such as mouse clicks for example) // the correct widget for listbox events (such as mouse clicks for example)

View File

@@ -565,7 +565,7 @@ void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
} }
#if wxUSE_TOOLTIPS #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 // set this tooltip for all radiobuttons which don't have their own tips
unsigned n = 0; unsigned n = 0;

View File

@@ -33,48 +33,38 @@ static GtkTooltips *gs_tooltips = NULL;
IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
wxToolTip::wxToolTip( const wxString &tip ) wxToolTip::wxToolTip( const wxString &tip )
: m_text(tip)
{ {
m_text = tip;
m_window = NULL; m_window = NULL;
} }
void wxToolTip::SetTip( const wxString &tip ) void wxToolTip::SetTip( const wxString &tip )
{ {
m_text = 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) wxASSERT(win);
return;
if ( !gs_tooltips )
gs_tooltips = gtk_tooltips_new();
m_window = win; m_window = win;
m_window->GTKApplyToolTip(wxGTK_CONV_SYS(m_text));
if (m_text.empty())
m_window->GTKApplyToolTip( gs_tooltips, NULL );
else
m_window->GTKApplyToolTip( gs_tooltips, wxGTK_CONV_SYS(m_text) );
} }
/* static */ /* 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)
if (!gtk_check_version(2, 12, 0)) if (!gtk_check_version(2, 12, 0))
{ gtk_widget_set_tooltip_text(widget, tip);
gtk_widget_set_tooltip_text(w, tip);
}
else else
#endif #endif
{ {
if ( !gs_tooltips ) if ( !gs_tooltips )
gs_tooltips = gtk_tooltips_new(); 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)) if (!gtk_check_version(2, 12, 0))
{ {
GtkSettings* settings = gtk_settings_get_default(); GtkSettings* settings = gtk_settings_get_default();
if(!settings) if (settings)
return; gtk_settings_set_long_property(settings, "gtk-enable-tooltips", flag, NULL);
gtk_settings_set_long_property(settings, "gtk-enable-tooltips", flag?TRUE:FALSE, NULL);
} }
else else
#endif #endif
{ {
if (!gs_tooltips) if (!gs_tooltips)
return; gs_tooltips = gtk_tooltips_new();
if (flag) if (flag)
gtk_tooltips_enable( gs_tooltips ); 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 ) void wxToolTip::SetDelay( long msecs )
{ {
#if GTK_CHECK_VERSION(2, 12, 0) #if GTK_CHECK_VERSION(2, 12, 0)
if (!gtk_check_version(2, 12, 0)) if (!gtk_check_version(2, 12, 0))
{ {
GtkSettings* settings = gtk_settings_get_default(); GtkSettings* settings = gtk_settings_get_default();
if(!settings) if (settings)
return; gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", msecs, NULL);
gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", msecs, NULL);
} }
else else
#endif #endif
{ {
if (!gs_tooltips) 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 ); gtk_tooltips_set_delay( gs_tooltips, (int)msecs );
} }
} }

View File

@@ -3778,33 +3778,20 @@ void wxWindowGTK::ClearBackground()
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
void wxWindowGTK::DoSetToolTip( wxToolTip *tip ) void wxWindowGTK::DoSetToolTip( wxToolTip *tip )
{ {
wxWindowBase::DoSetToolTip(tip); if (m_tooltip != tip)
{
wxWindowBase::DoSetToolTip(tip);
if (m_tooltip) if (m_tooltip)
{ m_tooltip->GTKSetWindow(static_cast<wxWindow*>(this));
m_tooltip->GTKApply( (wxWindow *)this ); else
} GTKApplyToolTip(NULL);
else
{
GtkWidget *w = GetConnectWidget();
wxToolTip::GTKApply(w, NULL);
} }
} }
void wxWindowGTK::GTKApplyToolTip( GtkTooltips *tips, const gchar *tip ) void wxWindowGTK::GTKApplyToolTip(const char* tip)
{ {
GtkWidget *w = GetConnectWidget(); wxToolTip::GTKApply(GetConnectWidget(), tip);
#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);
}
} }
#endif // wxUSE_TOOLTIPS #endif // wxUSE_TOOLTIPS