]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/richtooltip.cpp
9a50ab2271b172b3e5932505f7cd5c849f35a1dd
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/richtooltip.cpp
3 // Purpose: Native MSW implementation of wxRichToolTip.
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/treectrl.h"
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"
37 // Provide definitions missing from some compilers SDK headers.
47 #endif // !defined(TTI_XXX)
49 #ifndef Edit_ShowBalloonTip
58 #define Edit_ShowBalloonTip(hwnd, pebt) \
59 (BOOL)::SendMessage((hwnd), 0x1503 /* EM_SHOWBALLOONTIP */, 0, (LPARAM)(pebt))
61 #endif // !defined(Edit_ShowBalloonTip)
63 // ============================================================================
64 // wxRichToolTipMSWImpl: the real implementation.
65 // ============================================================================
67 class wxRichToolTipMSWImpl
: public wxRichToolTipGenericImpl
70 wxRichToolTipMSWImpl(const wxString
& title
, const wxString
& message
) :
71 wxRichToolTipGenericImpl(title
, message
)
74 m_canUseNative
= true;
79 virtual void SetBackgroundColour(const wxColour
& col
,
80 const wxColour
& colEnd
)
82 // Setting background colour is not supported neither.
83 m_canUseNative
= false;
85 wxRichToolTipGenericImpl::SetBackgroundColour(col
, colEnd
);
88 virtual void SetCustomIcon(const wxIcon
& icon
)
90 // Custom icons are not supported by EM_SHOWBALLOONTIP.
91 m_canUseNative
= false;
93 wxRichToolTipGenericImpl::SetCustomIcon(icon
);
96 virtual void SetStandardIcon(int icon
)
98 wxRichToolTipGenericImpl::SetStandardIcon(icon
);
99 if ( !m_canUseNative
)
102 switch ( icon
& wxICON_MASK
)
105 m_ttiIcon
= TTI_WARNING
;
109 m_ttiIcon
= TTI_ERROR
;
112 case wxICON_INFORMATION
:
113 m_ttiIcon
= TTI_INFO
;
116 case wxICON_QUESTION
:
117 wxFAIL_MSG("Question icon doesn't make sense for a tooltip");
121 m_ttiIcon
= TTI_NONE
;
126 virtual void SetTimeout(unsigned millisecondsTimeout
,
127 unsigned millisecondsDelay
)
129 // We don't support changing the timeout or the delay
130 // (maybe TTM_SETDELAYTIME could be used for this?).
131 m_canUseNative
= false;
133 wxRichToolTipGenericImpl::SetTimeout(millisecondsTimeout
,
137 virtual void SetTipKind(wxTipKind tipKind
)
139 // Setting non-default tip is not supported.
140 if ( tipKind
!= wxTipKind_Auto
)
141 m_canUseNative
= false;
143 wxRichToolTipGenericImpl::SetTipKind(tipKind
);
146 virtual void SetTitleFont(const wxFont
& font
)
148 // Setting non-default font is not supported.
149 m_canUseNative
= false;
151 wxRichToolTipGenericImpl::SetTitleFont(font
);
154 virtual void ShowFor(wxWindow
* win
, const wxRect
* rect
)
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
160 if ( m_canUseNative
&& !rect
)
162 wxTextCtrl
* const text
= wxDynamicCast(win
, wxTextCtrl
);
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
) )
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
178 wxRichToolTipGenericImpl::ShowFor(win
, rect
);
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.
186 // One of TTI_NONE, TTI_INFO, TTI_WARNING or TTI_ERROR.
192 wxRichToolTipImpl::Create(const wxString
& title
, const wxString
& message
)
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
);
199 return new wxRichToolTipGenericImpl(title
, message
);
202 #endif // wxUSE_RICHTOOLTIP