]> git.saurik.com Git - wxWidgets.git/blob - src/msw/richtooltip.cpp
Fix pulsing of bitmaps in focused buttons under Windows 7.
[wxWidgets.git] / src / msw / richtooltip.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/richtooltip.cpp
3 // Purpose: Native MSW implementation of wxRichToolTip.
4 // Author: Vadim Zeitlin
5 // Created: 2011-10-18
6 // RCS-ID: $Id$
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_RICHTOOLTIP
27
28 #ifndef WX_PRECOMP
29 #include "wx/treectrl.h"
30 #endif // WX_PRECOMP
31
32 #include "wx/private/richtooltip.h"
33 #include "wx/generic/private/richtooltip.h"
34 #include "wx/msw/private.h"
35 #include "wx/msw/uxtheme.h"
36
37 // Provide definitions missing from some compilers SDK headers.
38
39 #ifndef TTI_NONE
40 enum
41 {
42 TTI_NONE,
43 TTI_INFO,
44 TTI_WARNING,
45 TTI_ERROR
46 };
47 #endif // !defined(TTI_XXX)
48
49 #ifndef Edit_ShowBalloonTip
50 struct EDITBALLOONTIP
51 {
52 DWORD cbStruct;
53 LPCWSTR pszTitle;
54 LPCWSTR pszText;
55 int ttiIcon;
56 };
57
58 #define Edit_ShowBalloonTip(hwnd, pebt) \
59 (BOOL)::SendMessage((hwnd), 0x1503 /* EM_SHOWBALLOONTIP */, 0, (LPARAM)(pebt))
60
61 #endif // !defined(Edit_ShowBalloonTip)
62
63 // ============================================================================
64 // wxRichToolTipMSWImpl: the real implementation.
65 // ============================================================================
66
67 class wxRichToolTipMSWImpl : public wxRichToolTipGenericImpl
68 {
69 public:
70 wxRichToolTipMSWImpl(const wxString& title, const wxString& message) :
71 wxRichToolTipGenericImpl(title, message)
72 {
73 // So far so good...
74 m_canUseNative = true;
75
76 m_ttiIcon = TTI_NONE;
77 }
78
79 virtual void SetBackgroundColour(const wxColour& col,
80 const wxColour& colEnd)
81 {
82 // Setting background colour is not supported neither.
83 m_canUseNative = false;
84
85 wxRichToolTipGenericImpl::SetBackgroundColour(col, colEnd);
86 }
87
88 virtual void SetCustomIcon(const wxIcon& icon)
89 {
90 // Custom icons are not supported by EM_SHOWBALLOONTIP.
91 m_canUseNative = false;
92
93 wxRichToolTipGenericImpl::SetCustomIcon(icon);
94 }
95
96 virtual void SetStandardIcon(int icon)
97 {
98 wxRichToolTipGenericImpl::SetStandardIcon(icon);
99 if ( !m_canUseNative )
100 return;
101
102 switch ( icon & wxICON_MASK )
103 {
104 case wxICON_WARNING:
105 m_ttiIcon = TTI_WARNING;
106 break;
107
108 case wxICON_ERROR:
109 m_ttiIcon = TTI_ERROR;
110 break;
111
112 case wxICON_INFORMATION:
113 m_ttiIcon = TTI_INFO;
114 break;
115
116 case wxICON_QUESTION:
117 wxFAIL_MSG("Question icon doesn't make sense for a tooltip");
118 break;
119
120 case wxICON_NONE:
121 m_ttiIcon = TTI_NONE;
122 break;
123 }
124 }
125
126 virtual void SetTimeout(unsigned millisecondsTimeout,
127 unsigned millisecondsDelay)
128 {
129 // We don't support changing the timeout or the delay
130 // (maybe TTM_SETDELAYTIME could be used for this?).
131 m_canUseNative = false;
132
133 wxRichToolTipGenericImpl::SetTimeout(millisecondsTimeout,
134 millisecondsDelay);
135 }
136
137 virtual void SetTipKind(wxTipKind tipKind)
138 {
139 // Setting non-default tip is not supported.
140 if ( tipKind != wxTipKind_Auto )
141 m_canUseNative = false;
142
143 wxRichToolTipGenericImpl::SetTipKind(tipKind);
144 }
145
146 virtual void SetTitleFont(const wxFont& font)
147 {
148 // Setting non-default font is not supported.
149 m_canUseNative = false;
150
151 wxRichToolTipGenericImpl::SetTitleFont(font);
152 }
153
154 virtual void ShowFor(wxWindow* win, wxRect* rect)
155 {
156 // TODO: We could use native tooltip control to show native balloon
157 // tooltips for any window but right now we use the simple
158 // EM_SHOWBALLOONTIP API which can only be used with text
159 // controls.
160 if ( m_canUseNative && !rect )
161 {
162 wxTextCtrl* const text = wxDynamicCast(win, wxTextCtrl);
163 if ( text )
164 {
165 EDITBALLOONTIP ebt;
166 ebt.cbStruct = sizeof(EDITBALLOONTIP);
167 ebt.pszTitle = m_title.wc_str();
168 ebt.pszText = m_message.wc_str();
169 ebt.ttiIcon = m_ttiIcon;
170 if ( Edit_ShowBalloonTip(GetHwndOf(text), &ebt) )
171 return;
172 }
173 }
174
175 // Don't set m_canUseNative to false here, we could be able to use the
176 // native tooltips if we're called for a different window the next
177 // time.
178 wxRichToolTipGenericImpl::ShowFor(win, rect);
179 }
180
181 private:
182 // If this is false, we've been requested to do something that the native
183 // version doesn't support and so need to fall back to the generic one.
184 bool m_canUseNative;
185
186 // One of TTI_NONE, TTI_INFO, TTI_WARNING or TTI_ERROR.
187 int m_ttiIcon;
188 };
189
190 /* static */
191 wxRichToolTipImpl*
192 wxRichToolTipImpl::Create(const wxString& title, const wxString& message)
193 {
194 // EM_SHOWBALLOONTIP is only implemented by comctl32.dll v6 so don't even
195 // bother using the native implementation if we're not using themes.
196 if ( wxUxThemeEngine::GetIfActive() )
197 return new wxRichToolTipMSWImpl(title, message);
198
199 return new wxRichToolTipGenericImpl(title, message);
200 }
201
202 #endif // wxUSE_RICHTOOLTIP