Skip to content

Commit c21286a

Browse files
HeikoKlareakoch-yatta
authored andcommitted
[Win32] Revert treating Tree.INSET as point value
Windows seems to use pixel-based insets, such that treating the defined values as point values and scaling them led to wrong image placements in trees and eventually cut off checkboxes or overlapped the text.
1 parent d4ddd4c commit c21286a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ LRESULT CDDS_ITEMPOSTPAINT (NMTVCUSTOMDRAW nmcd, long wParam, long lParam) {
748748
}
749749
}
750750
}
751-
rect.left += DPIUtil.pointToPixel(INSET - 1, zoom) ;
751+
rect.left += INSET - 1;
752752
if (drawImage) {
753753
Image image = null;
754754
if (index == 0) {
@@ -757,8 +757,8 @@ LRESULT CDDS_ITEMPOSTPAINT (NMTVCUSTOMDRAW nmcd, long wParam, long lParam) {
757757
Image [] images = item.images;
758758
if (images != null) image = images [index];
759759
}
760-
int inset = i != 0 ? DPIUtil.pointToPixel(INSET, zoom) : 0;
761-
int offset = i != 0 ? DPIUtil.pointToPixel(INSET, zoom) : DPIUtil.pointToPixel(INSET + 2, zoom);
760+
int inset = i != 0 ? INSET : 0;
761+
int offset = i != 0 ? INSET : INSET + 2;
762762
if (image != null) {
763763
Rectangle bounds = image.getBounds (); // Points
764764
if (size == null) size = Win32DPIUtils.pixelToPointAsSize (getImageSize (), zoom); // To Points
@@ -5488,7 +5488,7 @@ public void showColumn (TreeColumn column) {
54885488
SCROLLINFO info = new SCROLLINFO();
54895489
info.cbSize = SCROLLINFO.sizeof;
54905490
info.fMask = OS.SIF_POS;
5491-
info.nPos = Math.max(0, headerRect.left - DPIUtil.pointToPixel(INSET / 2, getZoom()));
5491+
info.nPos = Math.max(0, headerRect.left - Tree.INSET / 2);
54925492
OS.SetScrollInfo(hwndParent, OS.SB_HORZ, info, true);
54935493
setScrollWidth();
54945494
} else if (scrollBecauseRight) {
@@ -5502,8 +5502,8 @@ public void showColumn (TreeColumn column) {
55025502
// info.nPos + wideRect = headerRect.left + wideHeader
55035503
// info.nPos = headerRect.left + wideHeader - wideRect
55045504
info.nPos = Math.max(0, wideHeader + headerRect.left - wideRect
5505-
- DPIUtil.pointToPixel(INSET / 2, getZoom()) );
5506-
info.nPos = Math.min(rect.right - DPIUtil.pointToPixel(INSET / 2, getZoom()), info.nPos);
5505+
- Tree.INSET / 2);
5506+
info.nPos = Math.min(rect.right - Tree.INSET / 2, info.nPos);
55075507

55085508
OS.SetScrollInfo(hwndParent, OS.SB_HORZ, info, true);
55095509
setScrollWidth();
@@ -7930,7 +7930,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
79307930
}
79317931
}
79327932

7933-
int x = rects[i].left + DPIUtil.pointToPixel(INSET + 2, getZoom());
7933+
int x = rects[i].left + INSET + 2;
79347934
if (columns[i].image != null) {
79357935
GCData data = new GCData();
79367936
data.device = display;
@@ -8248,7 +8248,7 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
82488248
data.background = OS.GetBkColor (nmcd.hdc);
82498249
data.font = Font.win32_new (display, hFont);
82508250
GC gc = createNewGC(nmcd.hdc, data);
8251-
int x = cellRect [0].left + DPIUtil.pointToPixel(INSET, getZoom());
8251+
int x = cellRect [0].left + INSET;
82528252
if (index [0] != 0) x -= gridWidth;
82538253
Image image = item [0].getImage (index [0]);
82548254
if (image != null || index [0] == 0) {
@@ -8259,11 +8259,11 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
82598259
Rectangle rect = image.getBounds (); // Points
82608260
int zoom = getZoom();
82618261
gc.drawImage (image, rect.x, rect.y, rect.width, rect.height, DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(imageRect.top, zoom), DPIUtil.pixelToPoint(size.x, zoom), DPIUtil.pixelToPoint(size.y, zoom));
8262-
x += DPIUtil.pointToPixel(INSET, getZoom()) + (index [0] == 0 ? 1 : 0);
8262+
x += INSET + (index [0] == 0 ? 1 : 0);
82638263
}
82648264
x += size.x;
82658265
} else {
8266-
x += DPIUtil.pointToPixel(INSET, getZoom());
8266+
x += INSET;
82678267
}
82688268
String string = item [0].getText (index [0]);
82698269
if (string != null) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ RECT getBounds (int index, boolean getText, boolean getImage, boolean fullText,
492492
}
493493
if (getText) {
494494
if (fullText && clip) {
495-
rect.left = rect.right + DPIUtil.pointToPixel(Tree.INSET, getZoom());
495+
rect.left = rect.right + Tree.INSET;
496496
rect.right = headerRect.right;
497497
} else {
498498
String string = index == 0 ? text : strings != null ? strings [index] : null;
@@ -513,10 +513,10 @@ RECT getBounds (int index, boolean getText, boolean getImage, boolean fullText,
513513
OS.ReleaseDC (hwnd, hNewDC);
514514
}
515515
if (getImage) {
516-
rect.right += textRect.right - textRect.left + DPIUtil.pointToPixel(Tree.INSET * 3, getZoom());
516+
rect.right += textRect.right - textRect.left + Tree.INSET * 3;
517517
} else {
518-
rect.left = rect.right + DPIUtil.pointToPixel(Tree.INSET, getZoom());
519-
rect.right = rect.left + (textRect.right - textRect.left) + DPIUtil.pointToPixel(Tree.INSET, getZoom());
518+
rect.left = rect.right + Tree.INSET;
519+
rect.right = rect.left + (textRect.right - textRect.left) + Tree.INSET;
520520
}
521521
}
522522
}
@@ -914,8 +914,9 @@ public Rectangle getTextBounds (int index) {
914914
Rectangle getTextBoundsInPixels (int index) {
915915
if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
916916
RECT rect = getBounds (index, true, false, true);
917+
if (index == 0) rect.left += Tree.INSET - 1;
917918
rect.left = Math.min (rect.left, rect.right);
918-
rect.right = rect.right + DPIUtil.pointToPixel(Tree.INSET, getZoom()); // Add INSET margin to avoid truncation of text seen with "Segoe UI" font
919+
rect.right = rect.right - Tree.INSET + 1; // Add 1 px margin to avoid truncation of text seen with "Segoe UI" font
919920
int width = Math.max (0, rect.right - rect.left);
920921
int height = Math.max (0, rect.bottom - rect.top);
921922
return new Rectangle (rect.left, rect.top, width, height);

0 commit comments

Comments
 (0)