]>
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 // 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 ///////////////////////////////////////////////////////////////////////////////
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 milliseconds
)
128 // We don't support changing the timeout (maybe TTM_SETDELAYTIME could
129 // be used for this?).
130 m_canUseNative
= false;
132 wxRichToolTipGenericImpl::SetTimeout(milliseconds
);
135 virtual void SetTipKind(wxTipKind tipKind
)
137 // Setting non-default tip is not supported.
138 if ( tipKind
!= wxTipKind_Auto
)
139 m_canUseNative
= false;
141 wxRichToolTipGenericImpl::SetTipKind(tipKind
);
144 virtual void SetTitleFont(const wxFont
& font
)
146 // Setting non-default font is not supported.
147 m_canUseNative
= false;
149 wxRichToolTipGenericImpl::SetTitleFont(font
);
152 virtual void ShowFor(wxWindow
* win
)
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
158 if ( m_canUseNative
)
160 wxTextCtrl
* const text
= wxDynamicCast(win
, wxTextCtrl
);
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
) )
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
176 wxRichToolTipGenericImpl::ShowFor(win
);
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.
184 // One of TTI_NONE, TTI_INFO, TTI_WARNING or TTI_ERROR.
190 wxRichToolTipImpl::Create(const wxString
& title
, const wxString
& message
)
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
);
197 return new wxRichToolTipGenericImpl(title
, message
);
200 #endif // wxUSE_RICHTOOLTIP