1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/tooltip.cpp
3 // Purpose: wxToolTip implementation
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
11
12 #if wxUSE_TOOLTIPS
13
14 #include "wx/tooltip.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/window.h"
18 #endif
19
20 #include "wx/gtk/private.h"
21
22 //-----------------------------------------------------------------------------
23 // global data
24 //-----------------------------------------------------------------------------
25
26 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
27 static GtkTooltips *gs_tooltips = NULL;
28 #endif
29
30 //-----------------------------------------------------------------------------
31 // wxToolTip
32 //-----------------------------------------------------------------------------
33
34 wxIMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject);
35
wxToolTip(const wxString & tip)36 wxToolTip::wxToolTip( const wxString &tip )
37 : m_text(tip)
38 {
39 m_window = NULL;
40 }
41
SetTip(const wxString & tip)42 void wxToolTip::SetTip( const wxString &tip )
43 {
44 m_text = tip;
45 if (m_window)
46 m_window->GTKApplyToolTip(wxGTK_CONV_SYS(m_text));
47 }
48
GTKSetWindow(wxWindow * win)49 void wxToolTip::GTKSetWindow(wxWindow* win)
50 {
51 wxASSERT(win);
52 m_window = win;
53 m_window->GTKApplyToolTip(wxGTK_CONV_SYS(m_text));
54 }
55
56 /* static */
GTKApply(GtkWidget * widget,const char * tip)57 void wxToolTip::GTKApply(GtkWidget* widget, const char* tip)
58 {
59 #if GTK_CHECK_VERSION(2, 12, 0)
60 if (wx_is_at_least_gtk2(12))
61 gtk_widget_set_tooltip_text(widget, tip);
62 else
63 #endif
64 {
65 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
66 if ( !gs_tooltips )
67 gs_tooltips = gtk_tooltips_new();
68
69 gtk_tooltips_set_tip(gs_tooltips, widget, tip, NULL);
70 #endif
71 }
72 }
73
Enable(bool flag)74 void wxToolTip::Enable( bool flag )
75 {
76 #ifdef __WXGTK4__
77 wxUnusedVar(flag);
78 #else
79 #if GTK_CHECK_VERSION(2, 12, 0)
80 if (wx_is_at_least_gtk2(12))
81 {
82 GtkSettings* settings = gtk_settings_get_default();
83 wxGCC_WARNING_SUPPRESS(deprecated-declarations)
84 if (settings)
85 gtk_settings_set_long_property(settings, "gtk-enable-tooltips", flag, NULL);
86 wxGCC_WARNING_RESTORE()
87 }
88 else
89 #endif
90 {
91 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
92 if (!gs_tooltips)
93 gs_tooltips = gtk_tooltips_new();
94
95 if (flag)
96 gtk_tooltips_enable( gs_tooltips );
97 else
98 gtk_tooltips_disable( gs_tooltips );
99 #endif
100 }
101 #endif // !__WXGTK4__
102 }
103
SetDelay(long msecs)104 void wxToolTip::SetDelay( long msecs )
105 {
106 #ifdef __WXGTK4__
107 wxUnusedVar(msecs);
108 #else
109 #if GTK_CHECK_VERSION(2, 12, 0)
110 if (wx_is_at_least_gtk2(12))
111 {
112 GtkSettings* settings = gtk_settings_get_default();
113 wxGCC_WARNING_SUPPRESS(deprecated-declarations)
114 if (settings)
115 gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", msecs, NULL);
116 wxGCC_WARNING_RESTORE()
117 }
118 else
119 #endif
120 {
121 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
122 if (!gs_tooltips)
123 gs_tooltips = gtk_tooltips_new();
124
125 gtk_tooltips_set_delay( gs_tooltips, (int)msecs );
126 #endif
127 }
128 #endif // !__WXGTK4__
129 }
130
SetAutoPop(long WXUNUSED (msecs))131 void wxToolTip::SetAutoPop( long WXUNUSED(msecs) )
132 {
133 }
134
SetReshow(long WXUNUSED (msecs))135 void wxToolTip::SetReshow( long WXUNUSED(msecs) )
136 {
137 }
138
139 #endif // wxUSE_TOOLTIPS
140