]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/tooltip.cpp
Corrected assertion
[wxWidgets.git] / src / gtk1 / 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
9e691f46 21#include "wx/gtk/private.h"
90b1b133 22
f6bcfd97
BP
23extern GdkFont *GtkGetDefaultGuiFont();
24
301cd871
RR
25//-----------------------------------------------------------------------------
26// global data
27//-----------------------------------------------------------------------------
28
29static GtkTooltips *ss_tooltips = (GtkTooltips*) NULL;
30static GdkColor ss_bg;
31static GdkColor ss_fg;
ff8bfdbb 32
90b1b133 33//-----------------------------------------------------------------------------
b1170810 34// wxToolTip
90b1b133
RR
35//-----------------------------------------------------------------------------
36
b342f8f0
RD
37IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
38
b1170810
RR
39wxToolTip::wxToolTip( const wxString &tip )
40{
41 m_text = tip;
301cd871 42 m_window = (wxWindow*) NULL;
b1170810 43}
90b1b133 44
301cd871 45void wxToolTip::SetTip( const wxString &tip )
b1170810 46{
301cd871
RR
47 m_text = tip;
48 Apply( m_window );
49}
50
51void wxToolTip::Apply( wxWindow *win )
52{
53 if (!win) return;
54
55 if (!ss_tooltips)
90b1b133 56 {
301cd871 57 ss_tooltips = gtk_tooltips_new();
ff8bfdbb
VZ
58
59 ss_fg.red = 0;
301cd871
RR
60 ss_fg.green = 0;
61 ss_fg.blue = 0;
62 gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_fg );
ff8bfdbb 63
301cd871
RR
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 );
ff8bfdbb 68
9e691f46 69#if GTK_CHECK_VERSION(1, 2, 0)
02e8b87f 70 gtk_tooltips_force_window( ss_tooltips );
b342f8f0
RD
71
72 GtkStyle *g_style =
02e8b87f
RR
73 gtk_style_copy(
74 gtk_widget_get_style( ss_tooltips->tip_window ) );
b342f8f0 75
02e8b87f
RR
76 g_style->fg[GTK_STATE_NORMAL] = ss_fg;
77 g_style->bg[GTK_STATE_NORMAL] = ss_bg;
9e691f46
VZ
78
79 SET_STYLE_FONT( g_style, GtkGetDefaultGuiFont() );
b342f8f0 80
02e8b87f 81 gtk_widget_set_style( ss_tooltips->tip_window, g_style );
9e691f46 82#else // GTK+ 1.0
ff8bfdbb 83 gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg );
02e8b87f 84#endif
90b1b133 85 }
ff8bfdbb 86
301cd871 87 m_window = win;
ff8bfdbb 88
301cd871 89 if (m_text.IsEmpty())
05939a81 90 m_window->ApplyToolTip( ss_tooltips, (wxChar*) NULL );
301cd871
RR
91 else
92 m_window->ApplyToolTip( ss_tooltips, m_text );
90b1b133
RR
93}
94
95void wxToolTip::Enable( bool flag )
96{
301cd871 97 if (!ss_tooltips) return;
ff8bfdbb 98
90b1b133 99 if (flag)
301cd871 100 gtk_tooltips_enable( ss_tooltips );
90b1b133 101 else
301cd871 102 gtk_tooltips_disable( ss_tooltips );
90b1b133
RR
103}
104
105void wxToolTip::SetDelay( long msecs )
106{
b02da6b1
VZ
107 if (!ss_tooltips)
108 return;
ff8bfdbb 109
b02da6b1 110 gtk_tooltips_set_delay( ss_tooltips, (int)msecs );
90b1b133 111}
dcf924a3 112
f7f1f70f 113#endif
90b1b133 114