]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/tooltip.cpp
fixed compilation for wxBase
[wxWidgets.git] / src / gtk / tooltip.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifdef __GNUG__
11 #pragma implementation "tooltip.h"
12 #endif
13
14 #include "wx/setup.h"
15
16 #if wxUSE_TOOLTIPS
17
18 #include "wx/window.h"
19 #include "wx/tooltip.h"
20
21 #include "wx/gtk/private.h"
22
23 extern GdkFont *GtkGetDefaultGuiFont();
24
25 //-----------------------------------------------------------------------------
26 // global data
27 //-----------------------------------------------------------------------------
28
29 static GtkTooltips *ss_tooltips = (GtkTooltips*) NULL;
30 static GdkColor ss_bg;
31 static GdkColor ss_fg;
32
33 //-----------------------------------------------------------------------------
34 // wxToolTip
35 //-----------------------------------------------------------------------------
36
37 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
38
39 wxToolTip::wxToolTip( const wxString &tip )
40 {
41 m_text = tip;
42 m_window = (wxWindow*) NULL;
43 }
44
45 void wxToolTip::SetTip( const wxString &tip )
46 {
47 m_text = tip;
48 Apply( m_window );
49 }
50
51 void wxToolTip::Apply( wxWindow *win )
52 {
53 if (!win) return;
54
55 if (!ss_tooltips)
56 {
57 ss_tooltips = gtk_tooltips_new();
58
59 ss_fg.red = 0;
60 ss_fg.green = 0;
61 ss_fg.blue = 0;
62 gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_fg );
63
64 ss_bg.red = 65535;
65 ss_bg.green = 65535;
66 ss_bg.blue = 50000;
67 gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_bg );
68
69 #if GTK_CHECK_VERSION(1, 2, 0)
70 gtk_tooltips_force_window( ss_tooltips );
71
72 GtkStyle *g_style =
73 gtk_style_copy(
74 gtk_widget_get_style( ss_tooltips->tip_window ) );
75
76 g_style->fg[GTK_STATE_NORMAL] = ss_fg;
77 g_style->bg[GTK_STATE_NORMAL] = ss_bg;
78
79 SET_STYLE_FONT( g_style, GtkGetDefaultGuiFont() );
80
81 gtk_widget_set_style( ss_tooltips->tip_window, g_style );
82 #else // GTK+ 1.0
83 gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg );
84 #endif
85 }
86
87 m_window = win;
88
89 if (m_text.IsEmpty())
90 m_window->ApplyToolTip( ss_tooltips, (wxChar*) NULL );
91 else
92 m_window->ApplyToolTip( ss_tooltips, m_text );
93 }
94
95 void wxToolTip::Enable( bool flag )
96 {
97 if (!ss_tooltips) return;
98
99 if (flag)
100 gtk_tooltips_enable( ss_tooltips );
101 else
102 gtk_tooltips_disable( ss_tooltips );
103 }
104
105 void wxToolTip::SetDelay( long msecs )
106 {
107 if (!ss_tooltips)
108 return;
109
110 gtk_tooltips_set_delay( ss_tooltips, (int)msecs );
111 }
112
113 #endif
114