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