Opened 9 years ago

Closed 5 years ago

#11685 closed defect (fixed)

Fix calculate max width for tooltips

Reported by: _Cool- Owned by:
Priority: normal Milestone:
Component: wxMSW Version: stable-latest
Keywords: wxTooltip SetTip width Cc:
Blocked By: Blocking:
Patch: no


In file msw/tooltip.cpp
void wxToolTip::Add(WXHWND hWnd)

  • if ( ms_maxWidth != -1 && maxWidth > ms_maxWidth )

I think that should be as follows:
+ if ( ms_maxWidth != -1 && maxWidth < ms_maxWidth )

Attachments (1)

tooltip.cpp download (1.9 KB) - added by _Cool- 9 years ago.
Tooltip usage example

Download all attachments as: .zip

Change History (10)

comment:1 Changed 9 years ago by vadz

  • Resolution set to invalid
  • Status changed from new to closed

Sorry, why? The width of the tooltip should be not greater than maximal width, not "not less".

Do you have some problem which disappears after making this change? If so, which one? Please describe it in details and reopen the ticket in this case.

comment:2 Changed 9 years ago by _Cool-

  • Resolution invalid deleted
  • Status changed from closed to reopened

The idea is to set the max size of tooltip maximum. Otherwise, we obtain
SetToolTip ( "123");
SetToolTip ( "12345");

-123 -
-45 -

So you can either just put the maximum size when creating or re-install it each time you change the text of tooltip.

comment:3 Changed 9 years ago by vadz

  • Status changed from reopened to infoneeded_new

Sorry, I still don't understand. The default max width is at least 400 pixels so I don't see why should "12345" be wrapped like this unless its length is greater than 400... Could you please explain?

comment:4 Changed 9 years ago by _Cool-

  • Status changed from infoneeded_new to new

Call SendTooltipMessage with TTM_SETMAXTIPWIDTH param happens only once, the first call SetToolTip("123"), when we create the tooltip and call wxToolTip::Add.
Then the second SetToolTip("12345") call only
wxToolTip::SetTip(const wxString & tip) => SendTooltipMessage TTM_UPDATETIPTEXT
Consequently maxtipwidth remains for the string "123" and "45" will wrap.

comment:5 Changed 9 years ago by vadz

Ah, ok, I finally see the problem, I didn't realize you were updating the same tooltip. The proposed change is still incorrect though AFAICS because it will break the display of different tooltips. We might need to send TTM_SETMAXTIPWIDTH after TTM_UPDATETIPTEXT though or something like this.

In any case, a patch reproducing this problem in a sample would be welcome as it'd allow us to test that it's really fixed.


Changed 9 years ago by _Cool-

Tooltip usage example

comment:6 Changed 9 years ago by _Cool-

vadz, yes, send TTM_SETMAXTIPWIDTH after TTM_UPDATETIPTEXT is the most correct, but only the question - why do we do the work that makes winapi? Can properly remove all that is connected with the calculation maxwidth, and TTM_SETMAXTIPWIDTH send from wxToolTip::SetMaxWidth(int width)?

comment:7 Changed 9 years ago by vadz

I am pretty sure we had to do this for the old versions of Windows to wrap over long tooltips. It probably should be ok to avoid this on XP+ systems. Someone would need to be tested that it works first though...

comment:8 Changed 5 years ago by awi

  • Keywords wxTooltip SetTip width added; tooltip.cpp removed

Fixed by r75758
Ref. #4685

comment:9 Changed 5 years ago by vadz

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.