]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/tooltip.cpp
Fix/hack 1.
[wxWidgets.git] / src / gtk / tooltip.cpp
CommitLineData
90b1b133
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: tooltip.cpp
ff8bfdbb 3// Purpose: wxToolTip implementation
90b1b133
RR
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
ff8bfdbb 7// Licence: wxWindows licence
90b1b133
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
ff8bfdbb 11 #pragma implementation "tooltip.h"
90b1b133
RR
12#endif
13
a9d6a93c 14#include "wx/setup.h"
cad880f5
RR
15
16#if wxUSE_TOOLTIPS
f7f1f70f 17
ff8bfdbb 18#include "wx/window.h"
90b1b133
RR
19#include "wx/tooltip.h"
20
21#include "gtk/gtk.h"
22#include "gdk/gdk.h"
23
f6bcfd97
BP
24extern GdkFont *GtkGetDefaultGuiFont();
25
301cd871
RR
26//-----------------------------------------------------------------------------
27// global data
28//-----------------------------------------------------------------------------
29
30static GtkTooltips *ss_tooltips = (GtkTooltips*) NULL;
31static GdkColor ss_bg;
32static GdkColor ss_fg;
ff8bfdbb 33
90b1b133 34//-----------------------------------------------------------------------------
b1170810 35// wxToolTip
90b1b133
RR
36//-----------------------------------------------------------------------------
37
b1170810
RR
38wxToolTip::wxToolTip( const wxString &tip )
39{
40 m_text = tip;
301cd871 41 m_window = (wxWindow*) NULL;
b1170810 42}
90b1b133 43
301cd871 44void wxToolTip::SetTip( const wxString &tip )
b1170810 45{
301cd871
RR
46 m_text = tip;
47 Apply( m_window );
48}
49
50void wxToolTip::Apply( wxWindow *win )
51{
52 if (!win) return;
53
54 if (!ss_tooltips)
90b1b133 55 {
301cd871 56 ss_tooltips = gtk_tooltips_new();
ff8bfdbb
VZ
57
58 ss_fg.red = 0;
301cd871
RR
59 ss_fg.green = 0;
60 ss_fg.blue = 0;
61 gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_fg );
ff8bfdbb 62
301cd871
RR
63 ss_bg.red = 65535;
64 ss_bg.green = 65535;
65 ss_bg.blue = 50000;
66 gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_bg );
ff8bfdbb 67
02e8b87f
RR
68#if (GTK_MINOR_VERSION > 0)
69 gtk_tooltips_force_window( ss_tooltips );
70
71 GtkStyle *g_style =
72 gtk_style_copy(
73 gtk_widget_get_style( ss_tooltips->tip_window ) );
74
75 g_style->fg[GTK_STATE_NORMAL] = ss_fg;
76 g_style->bg[GTK_STATE_NORMAL] = ss_bg;
f6bcfd97
BP
77 gdk_font_unref( g_style->font );
78 g_style->font = gdk_font_ref( GtkGetDefaultGuiFont() );
79
02e8b87f
RR
80 gtk_widget_set_style( ss_tooltips->tip_window, g_style );
81#else
ff8bfdbb 82 gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg );
02e8b87f 83#endif
90b1b133 84 }
ff8bfdbb 85
301cd871 86 m_window = win;
ff8bfdbb 87
301cd871 88 if (m_text.IsEmpty())
05939a81 89 m_window->ApplyToolTip( ss_tooltips, (wxChar*) NULL );
301cd871
RR
90 else
91 m_window->ApplyToolTip( ss_tooltips, m_text );
90b1b133
RR
92}
93
94void wxToolTip::Enable( bool flag )
95{
301cd871 96 if (!ss_tooltips) return;
ff8bfdbb 97
90b1b133 98 if (flag)
301cd871 99 gtk_tooltips_enable( ss_tooltips );
90b1b133 100 else
301cd871 101 gtk_tooltips_disable( ss_tooltips );
90b1b133
RR
102}
103
104void wxToolTip::SetDelay( long msecs )
105{
b02da6b1
VZ
106 if (!ss_tooltips)
107 return;
ff8bfdbb 108
b02da6b1 109 gtk_tooltips_set_delay( ss_tooltips, (int)msecs );
90b1b133 110}
dcf924a3 111
f7f1f70f 112#endif
90b1b133 113