Skip to content

Commit ca8bfa0

Browse files
arunjose696amartya4256
authored andcommitted
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 ca8bfa0

File tree

1 file changed

+17
-10
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7188,23 +7188,21 @@ 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);
7191+
if (!isDisposed() && !item.isDisposed()) {
71967192
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);
7193+
RECT itemRect = getItemBounds(pinfo, item, hDC);
7194+
RECT toolRect = isCustomToolTip() ? toolTipRect(itemRect) : itemRect;
7195+
OS.MapWindowPoints(handle, 0, toolRect, 2);
7196+
long hwndToolTip = OS.SendMessage(handle, OS.LVM_GETTOOLTIPS, 0, 0);
72007197
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
72017198
Rectangle adjustedTooltipBounds = getDisplay().fitRectangleBoundsIntoMonitorWithCursor(toolRect);
72027199
OS.SetWindowPos(hwndToolTip, 0, adjustedTooltipBounds.x, adjustedTooltipBounds.y,
72037200
adjustedTooltipBounds.width, adjustedTooltipBounds.height, flags);
72047201
result = LRESULT.ONE;
72057202
} else if (isCustomToolTip()) {
7206-
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO ();
7207-
OS.MoveMemory (lpnmtdi, lParam, NMTTDISPINFO.sizeof);
7203+
RECT itemRect = getItemBounds(pinfo, item, hDC);
7204+
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO();
7205+
OS.MoveMemory(lpnmtdi, lParam, NMTTDISPINFO.sizeof);
72087206
if (lpnmtdi.lpszText != 0) {
72097207
OS.MoveMemory (lpnmtdi.lpszText, new char [1], 2);
72107208
OS.MoveMemory (lParam, lpnmtdi, NMTTDISPINFO.sizeof);
@@ -7231,6 +7229,15 @@ private LRESULT positionTooltip(NMHDR hdr, long lParam) {
72317229
return result;
72327230
}
72337231

7232+
private RECT getItemBounds(LVHITTESTINFO pinfo, TableItem item, long hDC) {
7233+
Event event = sendMeasureItemEvent(item, pinfo.iItem, pinfo.iSubItem, hDC);
7234+
RECT itemRect = new RECT();
7235+
Rectangle boundsInPixels = Win32DPIUtils.pointToPixel(event.getBounds(), getZoom());
7236+
OS.SetRect(itemRect, boundsInPixels.x, boundsInPixels.y, boundsInPixels.x + boundsInPixels.width,
7237+
boundsInPixels.y + boundsInPixels.height);
7238+
return itemRect;
7239+
}
7240+
72347241
LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
72357242
switch (nmcd.dwDrawStage) {
72367243
case OS.CDDS_PREPAINT: {

0 commit comments

Comments
 (0)