+#if wxUSE_TOOLTIPS
+
+bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
+ WXLPARAM lParam,
+ const wxString& ttip)
+{
+ // I don't know why it happens, but the versions of comctl32.dll starting
+ // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
+ // this message is supposed to be sent to Unicode programs only) -- hence
+ // we need to handle it as well, otherwise no tooltips will be shown in
+ // this case
+
+ if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) || ttip.empty() )
+ {
+ // not a tooltip message or no tooltip to show anyhow
+ return FALSE;
+ }
+
+ LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
+
+#if !wxUSE_UNICODE
+ if ( code == (WXUINT) TTN_NEEDTEXTA )
+ {
+ // we pass just the pointer as we store the string internally anyhow
+ ttText->lpszText = (char *)ttip.c_str();
+ }
+ else // TTN_NEEDTEXTW
+#endif // !Unicode
+ {
+#if wxUSE_UNICODE
+ // in Unicode mode this is just what we need
+ ttText->lpszText = (wxChar *)ttip.c_str();
+#else // !Unicode
+ // in ANSI mode we have to convert the string and put it into the
+ // provided buffer: be careful not to overrun it
+ const size_t lenAnsi = ttip.length();
+
+ // some compilers (MetroWerks and Cygwin) don't like calling mbstowcs
+ // with NULL argument
+ #if defined( __MWERKS__ ) || defined( __CYGWIN__ )
+ size_t lenUnicode = 2*lenAnsi;
+ #else
+ size_t lenUnicode = mbstowcs(NULL, ttip, lenAnsi);
+ #endif
+
+ // using the pointer of right type avoids us doing all sorts of
+ // pointer arithmetics ourselves
+ wchar_t *dst = (wchar_t *)ttText->szText,
+ *pwz = new wchar_t[lenUnicode + 1];
+ mbstowcs(pwz, ttip, lenAnsi + 1);
+
+ // stay inside the buffer (-1 because it must be NUL-terminated)
+ if ( lenUnicode > WXSIZEOF(ttText->szText) - 1 )
+ {
+ lenUnicode = WXSIZEOF(ttText->szText) - 1;
+ }
+
+ memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
+
+ // put the terminating wide NUL
+ dst[lenUnicode] = L'\0';
+
+ delete [] pwz;
+#endif // Unicode/!Unicode
+ }
+
+ return TRUE;
+}
+
+#endif // wxUSE_TOOLTIPS
+