]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/richtooltip.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/richtooltip.cpp
3 // Purpose: Native MSW implementation of wxRichToolTip.
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
28 #include "wx/treectrl.h"
31 #include "wx/private/richtooltip.h"
32 #include "wx/generic/private/richtooltip.h"
33 #include "wx/msw/private.h"
34 #include "wx/msw/uxtheme.h"
36 // Provide definitions missing from some compilers SDK headers.
46 #endif // !defined(TTI_XXX)
48 #ifndef Edit_ShowBalloonTip
57 #define Edit_ShowBalloonTip(hwnd, pebt) \
58 (BOOL)::SendMessage((hwnd), 0x1503 /* EM_SHOWBALLOONTIP */, 0, (LPARAM)(pebt))
60 #endif // !defined(Edit_ShowBalloonTip)
62 // ============================================================================
63 // wxRichToolTipMSWImpl: the real implementation.
64 // ============================================================================
66 class wxRichToolTipMSWImpl
: public wxRichToolTipGenericImpl
69 wxRichToolTipMSWImpl(const wxString
& title
, const wxString
& message
) :
70 wxRichToolTipGenericImpl(title
, message
)
73 m_canUseNative
= true;
78 virtual void SetBackgroundColour(const wxColour
& col
,
79 const wxColour
& colEnd
)
81 // Setting background colour is not supported neither.
82 m_canUseNative
= false;
84 wxRichToolTipGenericImpl::SetBackgroundColour(col
, colEnd
);
87 virtual void SetCustomIcon(const wxIcon
& icon
)
89 // Custom icons are not supported by EM_SHOWBALLOONTIP.
90 m_canUseNative
= false;
92 wxRichToolTipGenericImpl::SetCustomIcon(icon
);
95 virtual void SetStandardIcon(int icon
)
97 wxRichToolTipGenericImpl::SetStandardIcon(icon
);
98 if ( !m_canUseNative
)
101 switch ( icon
& wxICON_MASK
)
104 m_ttiIcon
= TTI_WARNING
;
108 m_ttiIcon
= TTI_ERROR
;
111 case wxICON_INFORMATION
:
112 m_ttiIcon
= TTI_INFO
;
115 case wxICON_QUESTION
:
116 wxFAIL_MSG("Question icon doesn't make sense for a tooltip");
120 m_ttiIcon
= TTI_NONE
;
125 virtual void SetTimeout(unsigned millisecondsTimeout
,
126 unsigned millisecondsDelay
)
128 // We don't support changing the timeout or the delay
129 // (maybe TTM_SETDELAYTIME could be used for this?).
130 m_canUseNative
= false;
132 wxRichToolTipGenericImpl::SetTimeout(millisecondsTimeout
,
136 virtual void SetTipKind(wxTipKind tipKind
)
138 // Setting non-default tip is not supported.
139 if ( tipKind
!= wxTipKind_Auto
)
140 m_canUseNative
= false;
142 wxRichToolTipGenericImpl::SetTipKind(tipKind
);
145 virtual void SetTitleFont(const wxFont
& font
)
147 // Setting non-default font is not supported.
148 m_canUseNative
= false;
150 wxRichToolTipGenericImpl::SetTitleFont(font
);
153 virtual void ShowFor(wxWindow
* win
, const wxRect
* rect
)
155 // TODO: We could use native tooltip control to show native balloon
156 // tooltips for any window but right now we use the simple
157 // EM_SHOWBALLOONTIP API which can only be used with text
159 if ( m_canUseNative
&& !rect
)
161 wxTextCtrl
* const text
= wxDynamicCast(win
, wxTextCtrl
);
165 ebt
.cbStruct
= sizeof(EDITBALLOONTIP
);
166 ebt
.pszTitle
= m_title
.wc_str();
167 ebt
.pszText
= m_message
.wc_str();
168 ebt
.ttiIcon
= m_ttiIcon
;
169 if ( Edit_ShowBalloonTip(GetHwndOf(text
), &ebt
) )
174 // Don't set m_canUseNative to false here, we could be able to use the
175 // native tooltips if we're called for a different window the next
177 wxRichToolTipGenericImpl::ShowFor(win
, rect
);
181 // If this is false, we've been requested to do something that the native
182 // version doesn't support and so need to fall back to the generic one.
185 // One of TTI_NONE, TTI_INFO, TTI_WARNING or TTI_ERROR.
191 wxRichToolTipImpl::Create(const wxString
& title
, const wxString
& message
)
193 // EM_SHOWBALLOONTIP is only implemented by comctl32.dll v6 so don't even
194 // bother using the native implementation if we're not using themes.
195 if ( wxUxThemeEngine::GetIfActive() )
196 return new wxRichToolTipMSWImpl(title
, message
);
198 return new wxRichToolTipGenericImpl(title
, message
);
201 #endif // wxUSE_RICHTOOLTIP