Page 1 of 2

Newlines in tooltips

Posted: Tue Jun 14, 2005 12:04 pm
by acsMike
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:

Code: Select all

wxT("Firstline.\nSecondline.")
But I just get one long line with a "square" where the newline should be.
Is this a Windows problem? What to do? :?

Re: Newlines in tooltips

Posted: Tue Jun 14, 2005 12:32 pm
by ABX
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:

Code: Select all

wxT("Firstline.\nSecondline.")
But I just get one long line with a "square" where the newline should be.
Is this a Windows problem? What to do? :?
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?

ABX

Posted: Tue Jun 14, 2005 1:01 pm
by acsMike
Using "\r\n" gives no linebreak, but instead 2 "squares"! - As if the 2 chars are not recognised!

Thanks though!

Posted: Tue Jun 14, 2005 5:55 pm
by ABX
acsMike wrote:Using "\r\n" gives no linebreak, but instead 2 "squares"! - As if the 2 chars are not recognised!
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.

Here is change required in tooltip.cpp:
http://cvs.wxwidgets.org/viewcvs.cgi/wx ... 42&r2=1.43

Following change in widgets sample allows testing it:
http://cvs.wxwidgets.org/viewcvs.cgi/wx ... 33&r2=1.34

ABX

Posted: Tue Jun 14, 2005 8:35 pm
by acsMike
Wow, thanks.
I will try it out when I get back in a few days.
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.)

The tooltip in question is dynamically re-generated; i.e from time to time I replace the tooltip text. Do you think it matters? I'll let you know in a few days :-)

Posted: Wed Jun 15, 2005 6:43 am
by ABX
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.)
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:The tooltip in question is dynamically re-generated; i.e from time to time I replace the tooltip text. Do you think it matters?
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:I'll let you know in a few days :-)
Thanks, ABX

Posted: Mon Jun 20, 2005 2:51 pm
by acsMike
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.

I still get squares instead of newlines or spaces so I don't think the new code is acctually run.

I am at a loss right now... :? Hmmm

Posted: Mon Jun 20, 2005 3:05 pm
by acsMike
Found a workaround; and possibly a hint to the nature of the problem:

Instead of dynamically changing the tooltip like this:

Code: Select all

SetToolTip(wxT("New text"));
I do the following:

Code: Select all

SetToolTip((wxToolTip *)NULL);
SetToolTip(wxT("New text"));
I assume, if the very first tooltip did not contain a newline char, an updated tooltip which does contain newlines will not update properly.

Posted: Mon Jun 20, 2005 3:05 pm
by ABX
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.
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:I don't think the new code is acctually run.
The new code is definietly run because with DMC I got squares before my change and space instead of square after change.

ABX

Posted: Mon Jun 20, 2005 3:27 pm
by acsMike
Could you please give me your email? Can't seem to be able to post attachments on the board. My email is [email protected]

Posted: Mon Jun 20, 2005 3:38 pm
by ABX
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]
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!

ABX

Posted: Tue Aug 23, 2005 9:41 pm
by tiwag
has any investigation be done about this ?
in wx-cvs there is no change in /src/msw/tooltip.cpp , it's still version 1.43
// RCS-ID: $Id: tooltip.cpp,v 1.43 2005/06/14 17:43:45 ABX Exp $

i have similar problems as described by ascMike,
from XRC resources loaded tooltips, which are shown perfectly as multiline tooltips in an ANSI build of the wxApp,
shows a small rectangle instead of the newline when building a unicode version.

btw. i'm running Windows XP , wxApp::GetComCtl32Version() results 600

Posted: Fri Sep 09, 2005 1:41 pm
by Vaulter
patch from 1.42 to 1.43 doesn't solve this problem
i suggest this code of wxToolTip::SetTip

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);
    }
}

Posted: Fri Sep 09, 2005 1:56 pm
by ABX
Vaulter wrote:patch from 1.42 to 1.43 doesn't solve this problem
i suggest this code of wxToolTip::SetTip
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

Posted: Mon Sep 12, 2005 6:40 am
by Vaulter
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
that's right! i'll try to explain this decision.
1. i have wxTreeCtrl, and i was needed multiline tootip (screenshot). But, when wxTreeCtrl constructed, it call wxToolTip.Add() with "" text, so, SETMAXTIPWIDTH do not sended to tooltip,
2. for each item i need different tooltips, with different maxwidths, so i think that in SetTip it would be naturally to send SETMAXTIPWIDTH.
3. and max width better to make by string with max length:

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;
4. duplicate code is solve with carrying-out code with SETMAXTIPWIDTH (SetTipWidthFor(wxString ToolTip)) to single function and it could be called from Add and SetTip functions both.

ps: excuse me, i dont found bug tracker. :(