Skip to content

Commit 943caec

Browse files
committed
Ensure sendMeasureItemEvent is only called for OS.TTN_SHOW or custom
tooltips Prior to PR eclipse-platform#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 eclipse-platform#2241 as sendMeasureItemEvent would not be called for non customToolTip and restores expected UI behavior for now.
1 parent ac52a23 commit 943caec

File tree

1 file changed

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

1 file changed

+36
-32
lines changed

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

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7175,6 +7175,7 @@ private LRESULT positionTooltip(NMHDR hdr, long lParam) {
71757175
OS.ScreenToClient (handle, pt);
71767176
pinfo.x = pt.x;
71777177
pinfo.y = pt.y;
7178+
System.out.println(hdr.code);
71787179
/*
71797180
* Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
71807181
* a point that is above the table, instead of returning -1 to
@@ -7188,39 +7189,42 @@ private LRESULT positionTooltip(NMHDR hdr, long lParam) {
71887189
if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
71897190
long hFont = item.fontHandle (pinfo.iSubItem);
71907191
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);
7192+
if (!isDisposed() && !item.isDisposed()) {
7193+
if (isCustomToolTip() || hdr.code == OS.TTN_SHOW) {
7194+
Event event = sendMeasureItemEvent(item, pinfo.iItem, pinfo.iSubItem, hDC);
7195+
RECT itemRect = new RECT();
7196+
Rectangle boundsInPixels = Win32DPIUtils.pointToPixel(event.getBounds(), getZoom());
7197+
OS.SetRect(itemRect, boundsInPixels.x, boundsInPixels.y, boundsInPixels.x + boundsInPixels.width,
7198+
boundsInPixels.y + boundsInPixels.height);
7199+
if (hdr.code == OS.TTN_SHOW) {
7200+
RECT toolRect = isCustomToolTip() ? toolTipRect(itemRect) : itemRect;
7201+
OS.MapWindowPoints(handle, 0, toolRect, 2);
7202+
long hwndToolTip = OS.SendMessage(handle, OS.LVM_GETTOOLTIPS, 0, 0);
7203+
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
7204+
Rectangle adjustedTooltipBounds = getDisplay().fitRectangleBoundsIntoMonitorWithCursor(toolRect);
7205+
OS.SetWindowPos(hwndToolTip, 0, adjustedTooltipBounds.x, adjustedTooltipBounds.y,
7206+
adjustedTooltipBounds.width, adjustedTooltipBounds.height, flags);
72237207
result = LRESULT.ONE;
7208+
} else {
7209+
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO();
7210+
OS.MoveMemory(lpnmtdi, lParam, NMTTDISPINFO.sizeof);
7211+
if (lpnmtdi.lpszText != 0) {
7212+
OS.MoveMemory(lpnmtdi.lpszText, new char[1], 2);
7213+
OS.MoveMemory(lParam, lpnmtdi, NMTTDISPINFO.sizeof);
7214+
}
7215+
RECT cellRect = item.getBounds(pinfo.iItem, pinfo.iSubItem, true, true, true, true, hDC);
7216+
RECT clientRect = new RECT();
7217+
OS.GetClientRect(handle, clientRect);
7218+
if (itemRect.right > cellRect.right || itemRect.right > clientRect.right) {
7219+
// TEMPORARY CODE
7220+
String string = " ";
7221+
Shell shell = getShell();
7222+
char[] chars = new char[string.length() + 1];
7223+
string.getChars(0, string.length(), chars, 0);
7224+
shell.setToolTipText(lpnmtdi, chars);
7225+
OS.MoveMemory(lParam, lpnmtdi, NMTTDISPINFO.sizeof);
7226+
result = LRESULT.ONE;
7227+
}
72247228
}
72257229
}
72267230
}

0 commit comments

Comments
 (0)