I am trying to wordwrap a longish tooltip under MSW. To do that I though you would insert a newline char like this:
Code: Select all
wxT("Firstline.\nSecondline.")
Is this a Windows problem? What to do?
Code: Select all
wxT("Firstline.\nSecondline.")
I do not know. I definietly see code for handling this in src/msw/tooltip.cpp and seems it fits MS description from http://msdn.microsoft.com/library/defau ... oltips.asp . Dumb question but does replacing '\n' with '\r\n' to be correct with MS description changes this?acsMike wrote:Hi all,
I am trying to wordwrap a longish tooltip under MSW. To do that I though you would insert a newline char like this:But I just get one long line with a "square" where the newline should be.Code: Select all
wxT("Firstline.\nSecondline.")
Is this a Windows problem? What to do?
I think I found it. Your build either does not have correct SDK available or use older comctl32.dll. In such case tooltip.cpp went into replacement new lines with spaces but this was broken because due to optimization in wxStringBase::CopyBeforeWrite() the replacement occured in different text than the one available for tooltip control. It is now fixed in CVS head for me.acsMike wrote:Using "\r\n" gives no linebreak, but instead 2 "squares"! - As if the 2 chars are not recognised!
I do not know what's exactly with your case (could it be own/outdated VC6 headers?). But the change I provided surely fixes something because I was able to duplicate displaying of rectangles with latest DMC compiler. Among all other compilers (DMC, OW,MinGW,Borland,free VC 7.1) only DMC didn't support multiline tooltips.acsMike wrote:A note though; I am trying this on XP so I guess I have a good comctl32.dll. I tried on wx 2.6.1 (i.e file version 1.42 which you now patched.)
That should not be a problem but it definietly needs checking. With current version of widgets sample you can test dynamic changing of tooltip text.acsMike wrote:The tooltip in question is dynamically re-generated; i.e from time to time I replace the tooltip text. Do you think it matters?
Thanks, ABXacsMike wrote:I'll let you know in a few days
Code: Select all
SetToolTip(wxT("New text"));
Code: Select all
SetToolTip((wxToolTip *)NULL);
SetToolTip(wxT("New text"));
Please modify samples/minimal/minimal.cpp sample so it still presents your problem and then make this new minimal.cpp sample somehow available for me. (best with screenshots)acsMike wrote:Hi again, I have now tested version 1.43 - but I still have this problem. I have run on various systems, including Xp, so it's probably not a comctl32.dll problem.
The new code is definietly run because with DMC I got squares before my change and space instead of square after change.acsMike wrote:I don't think the new code is acctually run.
Please use wxWidgets bug tracker (which I should suggest at the very beginning). Assign your entry to me ("abxabx") and I will find it. Thanks!acsMike wrote:Could you please give me your email? Can't seem to be able to post attachments on the board. My email is [email protected]
Code: Select all
void wxToolTip::SetTip(const wxString& tip)
{
m_text = tip;
if ( m_window )
{
// update the tip text shown by the control
wxToolInfo ti(GetHwndOf(m_window));
ti.lpszText = (wxChar *)m_text.c_str();
if ( m_text.Find(_T('\n')) != wxNOT_FOUND )
{//multiline
#ifdef TTM_SETMAXTIPWIDTH
if ( wxApp::GetComCtl32Version() >= 470 )
{
int pos1 = 0,pos2 = m_text.Find(_T('\n')), max = pos2-pos1;
while(pos2 != wxNOT_FOUND)
{
if((pos2-pos1) > max)max = pos2-pos1;
pos1 = pos2; pos2 = m_text.find(_T('\n'),pos2 + 1);
}
pos2 = m_text.Length(); if((pos2-pos1) > max)max = pos2-pos1;
// use TTM_SETMAXTIPWIDTH to make tooltip multiline using the
// extent of its first line as max value
HFONT hfont = (HFONT)SendTooltipMessage(GetToolTipCtrl(),
WM_GETFONT,
0, 0);
if ( !hfont )
{
hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
if ( !hfont )
{
wxLogLastError(wxT("GetStockObject(DEFAULT_GUI_FONT)"));
}
}
MemoryHDC hdc;
if ( !hdc )
{
wxLogLastError(wxT("CreateCompatibleDC(NULL)"));
}
if ( !SelectObject(hdc, hfont) )
{
wxLogLastError(wxT("SelectObject(hfont)"));
}
SIZE sz;
if ( !::GetTextExtentPoint32(hdc, m_text, max, &sz) )
{
wxLogLastError(wxT("GetTextExtentPoint32"));
}
SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH,
0, (void *)sz.cx);
}
#endif // comctl32.dll >= 4.70
// replace the '\n's with spaces because otherwise they appear as
// unprintable characters in the tooltip string
m_text.Replace(_T("\n"), _T(" "));
}
(void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
}
}
I see the change in the code but I do not want to apply it blindly so I would like to ask for some more from you. Could you please write some explanation why do you want once again measure the font in that place? Moreover could you modernize your patch so it could not duplicate code from other place of tooltip.cpp?Vaulter wrote:patch from 1.42 to 1.43 doesn't solve this problem
i suggest this code of wxToolTip::SetTip
that's right! i'll try to explain this decision.ABX wrote: I see the change in the code but I do not want to apply it blindly so I would like to ask for some more from you. Could you please write some explanation why do you want once again measure the font in that place? Moreover could you modernize your patch so it could not duplicate code from other place of tooltip.cpp?
As suggested earlier, feel free to post your improved together with explanation directly into patch tracker and assign it to me (abxabx). Thanks in advance!
ABX
Code: Select all
int pos1 = 0,pos2 = m_text.Find(_T('\n')), max = pos2-pos1;
while(pos2 != wxNOT_FOUND)
{
if((pos2-pos1) > max)max = pos2-pos1;
pos1 = pos2; pos2 = m_text.find(_T('\n'),pos2 + 1);
}
pos2 = m_text.Length(); if((pos2-pos1) > max)max = pos2-pos1;