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