]> git.saurik.com Git - wxWidgets.git/blame - src/msw/richtooltip.cpp
Add wxFontDialog ctor not taking wxFontData to wxOSX.
[wxWidgets.git] / src / msw / richtooltip.cpp
CommitLineData
e520c3f7
VZ
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: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $
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
26d863e2 29 #include "wx/treectrl.h"
e520c3f7
VZ
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
26d863e2
VZ
37// Provide definitions missing from some compilers SDK headers.
38
39#ifndef TTI_NONE
40enum
41{
42 TTI_NONE,
43 TTI_INFO,
44 TTI_WARNING,
45 TTI_ERROR
46};
47#endif // !defined(TTI_XXX)
48
49#ifndef Edit_ShowBalloonTip
50struct 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
e520c3f7
VZ
63// ============================================================================
64// wxRichToolTipMSWImpl: the real implementation.
65// ============================================================================
66
67class wxRichToolTipMSWImpl : public wxRichToolTipGenericImpl
68{
69public:
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 milliseconds)
127 {
128 // We don't support changing the timeout (maybe TTM_SETDELAYTIME could
129 // be used for this?).
130 m_canUseNative = false;
131
132 wxRichToolTipGenericImpl::SetTimeout(milliseconds);
133 }
134
135 virtual void SetTipKind(wxTipKind tipKind)
136 {
137 // Setting non-default tip is not supported.
138 if ( tipKind != wxTipKind_Auto )
139 m_canUseNative = false;
140
141 wxRichToolTipGenericImpl::SetTipKind(tipKind);
142 }
143
144 virtual void SetTitleFont(const wxFont& font)
145 {
146 // Setting non-default font is not supported.
147 m_canUseNative = false;
148
149 wxRichToolTipGenericImpl::SetTitleFont(font);
150 }
151
152 virtual void ShowFor(wxWindow* win)
153 {
154 // TODO: We could use native tooltip control to show native balloon
155 // tooltips for any window but right now we use the simple
156 // EM_SHOWBALLOONTIP API which can only be used with text
157 // controls.
158 if ( m_canUseNative )
159 {
160 wxTextCtrl* const text = wxDynamicCast(win, wxTextCtrl);
161 if ( text )
162 {
163 EDITBALLOONTIP ebt;
164 ebt.cbStruct = sizeof(EDITBALLOONTIP);
165 ebt.pszTitle = m_title.wc_str();
166 ebt.pszText = m_message.wc_str();
167 ebt.ttiIcon = m_ttiIcon;
168 if ( Edit_ShowBalloonTip(GetHwndOf(text), &ebt) )
169 return;
170 }
171 }
172
173 // Don't set m_canUseNative to false here, we could be able to use the
174 // native tooltips if we're called for a different window the next
175 // time.
176 wxRichToolTipGenericImpl::ShowFor(win);
177 }
178
179private:
180 // If this is false, we've been requested to do something that the native
181 // version doesn't support and so need to fall back to the generic one.
182 bool m_canUseNative;
183
184 // One of TTI_NONE, TTI_INFO, TTI_WARNING or TTI_ERROR.
185 int m_ttiIcon;
186};
187
188/* static */
189wxRichToolTipImpl*
190wxRichToolTipImpl::Create(const wxString& title, const wxString& message)
191{
192 // EM_SHOWBALLOONTIP is only implemented by comctl32.dll v6 so don't even
193 // bother using the native implementation if we're not using themes.
194 if ( wxUxThemeEngine::GetIfActive() )
195 return new wxRichToolTipMSWImpl(title, message);
196
197 return new wxRichToolTipGenericImpl(title, message);
198}
199
200#endif // wxUSE_RICHTOOLTIP