fix showing toolbar tooltips (we were using a pointer to a temporary object so it mostly _appeared_ to work but really didn't)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25974 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3200,7 +3200,8 @@ bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
|
|||||||
// we need to handle it as well, otherwise no tooltips will be shown in
|
// we need to handle it as well, otherwise no tooltips will be shown in
|
||||||
// this case
|
// this case
|
||||||
#ifndef __WXWINCE__
|
#ifndef __WXWINCE__
|
||||||
if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) || ttip.empty() )
|
if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW)
|
||||||
|
|| ttip.empty() )
|
||||||
{
|
{
|
||||||
// not a tooltip message or no tooltip to show anyhow
|
// not a tooltip message or no tooltip to show anyhow
|
||||||
return false;
|
return false;
|
||||||
@@ -3209,41 +3210,58 @@ bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
|
|||||||
|
|
||||||
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
|
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
|
||||||
|
|
||||||
|
// We don't want to use the szText buffer because it has a limit of 80
|
||||||
|
// bytes and this is not enough, especially for Unicode build where it
|
||||||
|
// limits the tooltip string length to only 40 characters
|
||||||
|
//
|
||||||
|
// The best would be, of course, to not impose any length limitations at
|
||||||
|
// all but then the buffer would have to be dynamic and someone would have
|
||||||
|
// to free it and we don't have the tooltip owner object here any more, so
|
||||||
|
// for now use our own static buffer with a higher fixed max length.
|
||||||
|
//
|
||||||
|
// Note that using a static buffer should not be a problem as only a single
|
||||||
|
// tooltip can be shown at the same time anyhow.
|
||||||
#if !wxUSE_UNICODE
|
#if !wxUSE_UNICODE
|
||||||
if ( code == (WXUINT) TTN_NEEDTEXTA )
|
if ( code == (WXUINT) TTN_NEEDTEXTW )
|
||||||
{
|
{
|
||||||
// we pass just the pointer as we store the string internally anyhow
|
// We need to convert tooltip from multi byte to Unicode on the fly.
|
||||||
ttText->lpszText = (char *)ttip.c_str();
|
static wchar_t buf[513];
|
||||||
}
|
|
||||||
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
|
|
||||||
// Convert tooltip from multi byte to Unicode.
|
|
||||||
|
|
||||||
// We don't want to use the szText buffer because it has a limit of 80
|
// Truncate tooltip length if needed as otherwise we might not have
|
||||||
// bytes, for now use our own static buffer with a higher fixed max
|
// enough space for it in the buffer and MultiByteToWideChar() would
|
||||||
// length.
|
// return an error
|
||||||
// Preferably a dynamic buffer should be used, but who frees the buffer?
|
size_t tipLength = wxMin(ttip.Len(), WXSIZEOF(buf) - 1);
|
||||||
|
|
||||||
static const int MAX_LENGTH = 512;
|
|
||||||
static wchar_t buf[MAX_LENGTH+1];
|
|
||||||
|
|
||||||
ttText->lpszText = (LPSTR) buf;
|
|
||||||
|
|
||||||
// Truncate tooltip length if needed
|
|
||||||
size_t tipLength = wxMin(ttip.Len(), MAX_LENGTH);
|
|
||||||
|
|
||||||
// Convert to WideChar without adding the NULL character. The NULL
|
// Convert to WideChar without adding the NULL character. The NULL
|
||||||
// character is added afterwards (this is more efficient).
|
// character is added afterwards (this is more efficient).
|
||||||
::MultiByteToWideChar(CP_ACP, 0, ttip, tipLength, buf, MAX_LENGTH);
|
int len = ::MultiByteToWideChar
|
||||||
|
(
|
||||||
|
CP_ACP,
|
||||||
|
0, // no flags
|
||||||
|
ttip,
|
||||||
|
tipLength,
|
||||||
|
buf,
|
||||||
|
WXSIZEOF(buf) - 1
|
||||||
|
);
|
||||||
|
|
||||||
buf[tipLength] = '\0';
|
if ( !len )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("MultiByteToWideChar()"));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // Unicode/!Unicode
|
buf[len] = L'\0';
|
||||||
|
ttText->lpszText = (LPSTR) buf;
|
||||||
|
}
|
||||||
|
else // TTN_NEEDTEXTA
|
||||||
|
#endif // !wxUSE_UNICODE
|
||||||
|
{
|
||||||
|
// we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
|
||||||
|
// if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
|
||||||
|
// to copy the string we have into the buffer
|
||||||
|
static wxChar buf[513];
|
||||||
|
wxStrncpy(buf, ttip.c_str(), WXSIZEOF(buf) - 1);
|
||||||
|
buf[WXSIZEOF(buf) - 1] = _T('\0');
|
||||||
|
ttText->lpszText = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user