Skip to content

Commit abec851

Browse files
committed
Ensure sendMeasureItemEvent is only called for OS.TTN_SHOW or custom
tooltips Prior to PR #2241, sendMeasureItemEvent was only invoked when the tooltip was not a CustomTooltip. However, after that change, sendMeasureItemEvent is now called for all tooltips. This results in an unintended side effect: sendMeasureItemEvent compares the item's width(obtained from TableItem.getBounds()) to the width of column (via OS.LVM_GETCOLUMNWIDTH) it is present in and sometimes concludes incorrectly that the item doesn't fit. This causes an unnecessary scrollbar to appear, even though the item is fully contained within the column. While the root cause lies in how column item width is calculated (which should be addressed separately), this change acts as a temporary fix to prevent scrollbars from appearing erroneously particularly in the MultipleHyperlinkPresenter. This workaround aligns with the original behavior prior to PR #2241 as sendMeasureItemEvent would not be called for non customToolTip and restores expected UI behavior for now.
1 parent ac52a23 commit abec851

File tree

1 file changed

+35
-32
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+35
-32
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7188,39 +7188,42 @@ private LRESULT positionTooltip(NMHDR hdr, long lParam) {
71887188
if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
71897189
long hFont = item.fontHandle (pinfo.iSubItem);
71907190
if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
7191-
Event event = sendMeasureItemEvent (item, pinfo.iItem, pinfo.iSubItem, hDC);
7192-
if (!isDisposed () && !item.isDisposed ()) {
7193-
RECT itemRect = new RECT ();
7194-
Rectangle boundsInPixels = Win32DPIUtils.pointToPixel(event.getBounds(), getZoom());
7195-
OS.SetRect (itemRect, boundsInPixels.x, boundsInPixels.y, boundsInPixels.x + boundsInPixels.width, boundsInPixels.y + boundsInPixels.height);
7196-
if (hdr.code == OS.TTN_SHOW) {
7197-
RECT toolRect = isCustomToolTip() ? toolTipRect (itemRect) : itemRect;
7198-
OS.MapWindowPoints (handle, 0, toolRect, 2);
7199-
long hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
7200-
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
7201-
Rectangle adjustedTooltipBounds = getDisplay().fitRectangleBoundsIntoMonitorWithCursor(toolRect);
7202-
OS.SetWindowPos(hwndToolTip, 0, adjustedTooltipBounds.x, adjustedTooltipBounds.y,
7203-
adjustedTooltipBounds.width, adjustedTooltipBounds.height, flags);
7204-
result = LRESULT.ONE;
7205-
} else if (isCustomToolTip()) {
7206-
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO ();
7207-
OS.MoveMemory (lpnmtdi, lParam, NMTTDISPINFO.sizeof);
7208-
if (lpnmtdi.lpszText != 0) {
7209-
OS.MoveMemory (lpnmtdi.lpszText, new char [1], 2);
7210-
OS.MoveMemory (lParam, lpnmtdi, NMTTDISPINFO.sizeof);
7211-
}
7212-
RECT cellRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, true, true, true, true, hDC);
7213-
RECT clientRect = new RECT ();
7214-
OS.GetClientRect (handle, clientRect);
7215-
if (itemRect.right > cellRect.right || itemRect.right > clientRect.right) {
7216-
//TEMPORARY CODE
7217-
String string = " ";
7218-
Shell shell = getShell ();
7219-
char [] chars = new char [string.length () + 1];
7220-
string.getChars (0, string.length (), chars, 0);
7221-
shell.setToolTipText (lpnmtdi, chars);
7222-
OS.MoveMemory (lParam, lpnmtdi, NMTTDISPINFO.sizeof);
7191+
if (!isDisposed() && !item.isDisposed()) {
7192+
if (isCustomToolTip() || hdr.code == OS.TTN_SHOW) {
7193+
Event event = sendMeasureItemEvent(item, pinfo.iItem, pinfo.iSubItem, hDC);
7194+
RECT itemRect = new RECT();
7195+
Rectangle boundsInPixels = Win32DPIUtils.pointToPixel(event.getBounds(), getZoom());
7196+
OS.SetRect(itemRect, boundsInPixels.x, boundsInPixels.y, boundsInPixels.x + boundsInPixels.width,
7197+
boundsInPixels.y + boundsInPixels.height);
7198+
if (hdr.code == OS.TTN_SHOW) {
7199+
RECT toolRect = isCustomToolTip() ? toolTipRect(itemRect) : itemRect;
7200+
OS.MapWindowPoints(handle, 0, toolRect, 2);
7201+
long hwndToolTip = OS.SendMessage(handle, OS.LVM_GETTOOLTIPS, 0, 0);
7202+
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
7203+
Rectangle adjustedTooltipBounds = getDisplay().fitRectangleBoundsIntoMonitorWithCursor(toolRect);
7204+
OS.SetWindowPos(hwndToolTip, 0, adjustedTooltipBounds.x, adjustedTooltipBounds.y,
7205+
adjustedTooltipBounds.width, adjustedTooltipBounds.height, flags);
72237206
result = LRESULT.ONE;
7207+
} else {
7208+
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO();
7209+
OS.MoveMemory(lpnmtdi, lParam, NMTTDISPINFO.sizeof);
7210+
if (lpnmtdi.lpszText != 0) {
7211+
OS.MoveMemory(lpnmtdi.lpszText, new char[1], 2);
7212+
OS.MoveMemory(lParam, lpnmtdi, NMTTDISPINFO.sizeof);
7213+
}
7214+
RECT cellRect = item.getBounds(pinfo.iItem, pinfo.iSubItem, true, true, true, true, hDC);
7215+
RECT clientRect = new RECT();
7216+
OS.GetClientRect(handle, clientRect);
7217+
if (itemRect.right > cellRect.right || itemRect.right > clientRect.right) {
7218+
// TEMPORARY CODE
7219+
String string = " ";
7220+
Shell shell = getShell();
7221+
char[] chars = new char[string.length() + 1];
7222+
string.getChars(0, string.length(), chars, 0);
7223+
shell.setToolTipText(lpnmtdi, chars);
7224+
OS.MoveMemory(lParam, lpnmtdi, NMTTDISPINFO.sizeof);
7225+
result = LRESULT.ONE;
7226+
}
72247227
}
72257228
}
72267229
}

0 commit comments

Comments
 (0)