From 25b32ef8091c278928027b3326a83033874f134b Mon Sep 17 00:00:00 2001 From: "shahzaib.ibrahim" Date: Tue, 14 May 2024 14:26:13 +0200 Subject: [PATCH] Adapt GetSystemMetrics calls to be DPI dependent Writing GetSystemMetrics method in Widget class so that the child controls can use it to get System Metrics to be DPI dependent Contributes to: https://github.com/eclipse-platform/eclipse.platform.swt/issues/62 & https://github.com/eclipse-platform/eclipse.platform.swt/issues/127 --- .../win32/org/eclipse/swt/widgets/Button.java | 38 +++++++++---------- .../win32/org/eclipse/swt/widgets/Combo.java | 8 ++-- .../org/eclipse/swt/widgets/Composite.java | 2 +- .../org/eclipse/swt/widgets/Control.java | 18 ++++----- .../org/eclipse/swt/widgets/DateTime.java | 2 +- .../org/eclipse/swt/widgets/Decorations.java | 14 +++---- .../win32/org/eclipse/swt/widgets/Label.java | 4 +- .../win32/org/eclipse/swt/widgets/List.java | 4 +- .../win32/org/eclipse/swt/widgets/Menu.java | 2 +- .../org/eclipse/swt/widgets/ProgressBar.java | 8 ++-- .../win32/org/eclipse/swt/widgets/Scale.java | 8 ++-- .../org/eclipse/swt/widgets/ScrollBar.java | 12 +++--- .../org/eclipse/swt/widgets/Scrollable.java | 4 +- .../win32/org/eclipse/swt/widgets/Shell.java | 20 +++++----- .../win32/org/eclipse/swt/widgets/Slider.java | 8 ++-- .../org/eclipse/swt/widgets/Spinner.java | 8 ++-- .../win32/org/eclipse/swt/widgets/Table.java | 4 +- .../win32/org/eclipse/swt/widgets/Text.java | 17 ++------- .../win32/org/eclipse/swt/widgets/Tree.java | 8 ++-- .../org/eclipse/swt/widgets/TreeColumn.java | 2 +- .../win32/org/eclipse/swt/widgets/Widget.java | 14 ++++++- 21 files changed, 104 insertions(+), 101 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java index 503bec630e4..821c66a078d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java @@ -54,24 +54,13 @@ public class Button extends Control { ImageList imageList; boolean ignoreMouse, grayed, useDarkModeExplorerTheme; static final int MARGIN = 4; - static final int CHECK_WIDTH, CHECK_HEIGHT; + private final int checkWidth, checkHeight; static final int ICON_WIDTH = 128, ICON_HEIGHT = 128; static /*final*/ boolean COMMAND_LINK = false; static final char[] STRING_WITH_ZERO_CHAR = new char[] {'0'}; static final long ButtonProc; static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true); static { - long hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES); - if (hBitmap == 0) { - CHECK_WIDTH = OS.GetSystemMetrics (OS.SM_CXVSCROLL); - CHECK_HEIGHT = OS.GetSystemMetrics (OS.SM_CYVSCROLL); - } else { - BITMAP bitmap = new BITMAP (); - OS.GetObject (hBitmap, BITMAP.sizeof, bitmap); - OS.DeleteObject (hBitmap); - CHECK_WIDTH = bitmap.bmWidth / 4; - CHECK_HEIGHT = bitmap.bmHeight / 3; - } WNDCLASS lpWndClass = new WNDCLASS (); OS.GetClassInfo (0, ButtonClass, lpWndClass); ButtonProc = lpWndClass.lpfnWndProc; @@ -119,6 +108,17 @@ public class Button extends Control { */ public Button (Composite parent, int style) { super (parent, checkStyle (style)); + long hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES); + if (hBitmap == 0) { + checkWidth = getSystemMetrics(OS.SM_CXVSCROLL); + checkHeight = getSystemMetrics (OS.SM_CYVSCROLL); + } else { + BITMAP bitmap = new BITMAP (); + OS.GetObject (hBitmap, BITMAP.sizeof, bitmap); + OS.DeleteObject (hBitmap); + checkWidth = bitmap.bmWidth / 4; + checkHeight = bitmap.bmHeight / 3; + } } void _setImage (Image image) { @@ -315,11 +315,11 @@ else if ((style & SWT.RIGHT) != 0) { int width = 0, height = 0, border = getBorderWidthInPixels (); if ((style & SWT.ARROW) != 0) { if ((style & (SWT.UP | SWT.DOWN)) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); - height += OS.GetSystemMetrics (OS.SM_CYVSCROLL); + width += getSystemMetrics (OS.SM_CXVSCROLL); + height += getSystemMetrics (OS.SM_CYVSCROLL); } else { - width += OS.GetSystemMetrics (OS.SM_CXHSCROLL); - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + width += getSystemMetrics (OS.SM_CXHSCROLL); + height += getSystemMetrics (OS.SM_CYHSCROLL); } } else { if ((style & SWT.COMMAND) != 0) { @@ -373,7 +373,7 @@ else if ((style & SWT.RIGHT) != 0) { flags = OS.DT_CALCRECT | OS.DT_WORDBREAK; rect.right = wHint - width - 2 * border; if (isRadioOrCheck()) { - rect.right -= CHECK_WIDTH + 3; + rect.right -= checkWidth + 3; } else { rect.right -= 6; } @@ -392,8 +392,8 @@ else if ((style & SWT.RIGHT) != 0) { OS.ReleaseDC (handle, hDC); } if (isRadioOrCheck()) { - width += CHECK_WIDTH + extra; - height = Math.max (height, CHECK_HEIGHT + 3); + width += checkWidth + extra; + height = Math.max (height, checkHeight + 3); } if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { width += 12; height += 10; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java index e6b9bc77218..b02c7ece78f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java @@ -655,8 +655,8 @@ public void clearSelection () { width += pcbi.itemLeft + (pcbi.buttonRight - pcbi.buttonLeft); height = (pcbi.buttonBottom - pcbi.buttonTop) + pcbi.buttonTop * 2; } else { - int border = OS.GetSystemMetrics (OS.SM_CXEDGE); - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL) + border * 2; + int border = getSystemMetrics (OS.SM_CXEDGE); + width += getSystemMetrics (OS.SM_CXVSCROLL) + border * 2; int textHeight = (int)OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0); if ((style & SWT.DROP_DOWN) != 0) { height = textHeight + 6; @@ -665,7 +665,7 @@ public void clearSelection () { } } if ((style & SWT.SIMPLE) != 0 && (style & SWT.H_SCROLL) != 0) { - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + height += getSystemMetrics (OS.SM_CYHSCROLL); } return new Point (width, height); } @@ -2188,7 +2188,7 @@ void setScrollWidth (int scrollWidth) { OS.SendMessage (handle, OS.CB_SETDROPPEDWIDTH, 0, 0); OS.SendMessage (handle, OS.CB_SETHORIZONTALEXTENT, scrollWidth, 0); } else { - scrollWidth += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + scrollWidth += getSystemMetrics (OS.SM_CYHSCROLL); OS.SendMessage (handle, OS.CB_SETDROPPEDWIDTH, scrollWidth, 0); OS.SendMessage (handle, OS.CB_SETHORIZONTALEXTENT, 0, 0); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java index cbebbb252f3..dbe54d0f504 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java @@ -1854,7 +1854,7 @@ LRESULT wmNCPaint (long hwnd, long wParam, long lParam) { rect.right -= rect.left; rect.bottom -= rect.top; rect.left = rect.top = 0; - int border = OS.GetSystemMetrics (OS.SM_CXEDGE); + int border = getSystemMetrics (OS.SM_CXEDGE); OS.ExcludeClipRect (hDC, border, border, rect.right - border, rect.bottom - border); OS.DrawThemeBackground (display.hEditTheme (), hDC, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null); OS.ReleaseDC (hwnd, hDC); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index f4ee1afd1fc..94d8a370db0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -680,7 +680,7 @@ void createHandle () { } void checkGesture () { - int value = OS.GetSystemMetrics (OS.SM_DIGITIZER); + int value =getSystemMetrics (OS.SM_DIGITIZER); if ((value & (OS.NID_READY | OS.NID_MULTI_INPUT)) != 0) { /* * Feature in Windows 7: All gestures are enabled by default except GID_ROTATE. @@ -1161,8 +1161,8 @@ public int getBorderWidth () { int getBorderWidthInPixels () { long borderHandle = borderHandle (); int bits1 = OS.GetWindowLong (borderHandle, OS.GWL_EXSTYLE); - if ((bits1 & OS.WS_EX_CLIENTEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXEDGE); - if ((bits1 & OS.WS_EX_STATICEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXBORDER); + if ((bits1 & OS.WS_EX_CLIENTEDGE) != 0) return getSystemMetrics (OS.SM_CXEDGE); + if ((bits1 & OS.WS_EX_STATICEDGE) != 0) return getSystemMetrics (OS.SM_CXBORDER); int bits2 = OS.GetWindowLong (borderHandle, OS.GWL_STYLE); if ((bits2 & OS.WS_BORDER) != 0) { @@ -1172,9 +1172,9 @@ int getBorderWidthInPixels () { * saves screen space, but could break some layouts. */ if (isUseWsBorder ()) - return OS.GetSystemMetrics (OS.SM_CXEDGE); + return getSystemMetrics (OS.SM_CXEDGE); - return OS.GetSystemMetrics (OS.SM_CXBORDER); + return getSystemMetrics (OS.SM_CXBORDER); } return 0; @@ -2284,10 +2284,10 @@ void printWidget (long hwnd, long hdc, GC gc) { hwndInsertAfter = OS.HWND_TOP; } if (fixPrintWindow) { - int x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN); - int y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN); - int width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN); - int height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN); + int x =getSystemMetrics (OS.SM_XVIRTUALSCREEN); + int y =getSystemMetrics (OS.SM_YVIRTUALSCREEN); + int width =getSystemMetrics (OS.SM_CXVIRTUALSCREEN); + int height =getSystemMetrics (OS.SM_CYVIRTUALSCREEN); int flags = OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE | OS.SWP_DRAWFRAME; if ((bits1 & OS.WS_VISIBLE) != 0) { OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 0, 0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java index f3fb972b4a0..2a247320d95 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java @@ -238,7 +238,7 @@ protected void checkSubclass () { width = size.cx; height = size.cy; // TODO: Can maybe use DTM_GETDATETIMEPICKERINFO for this - int upDownHeight = OS.GetSystemMetrics (OS.SM_CYVSCROLL) + 7; + int upDownHeight = getSystemMetrics (OS.SM_CYVSCROLL) + 7; height = Math.max (height, upDownHeight); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java index 5a0e267aa38..7e86d45ebe3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java @@ -316,8 +316,8 @@ Control computeTabRoot () { OS.AdjustWindowRectEx (rect, bits1, hasMenu, bits2); /* Get the size of the scroll bars */ - if (horizontalBar != null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL); - if (verticalBar != null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL); + if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL); + if (verticalBar != null) rect.right += getSystemMetrics (OS.SM_CXVSCROLL); /* Compute the height of the menu bar */ if (hasMenu) { @@ -326,7 +326,7 @@ Control computeTabRoot () { OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, testRect); while ((testRect.bottom - testRect.top) < height) { if (testRect.bottom - testRect.top == 0) break; - rect.top -= OS.GetSystemMetrics (OS.SM_CYMENU) - OS.GetSystemMetrics (OS.SM_CYBORDER); + rect.top -= getSystemMetrics (OS.SM_CYMENU) - getSystemMetrics (OS.SM_CYBORDER); OS.SetRect (testRect, 0, 0, rect.right - rect.left, rect.bottom - rect.top); OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, testRect); } @@ -466,8 +466,8 @@ void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) * the window restored. There is no fix for this problem at * this time. */ - if (horizontalBar != null) width -= OS.GetSystemMetrics (OS.SM_CYHSCROLL); - if (verticalBar != null) height -= OS.GetSystemMetrics (OS.SM_CXVSCROLL); + if (horizontalBar != null) width -= getSystemMetrics (OS.SM_CYHSCROLL); + if (verticalBar != null) height -= getSystemMetrics (OS.SM_CXVSCROLL); RECT rect = new RECT (); int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); @@ -902,11 +902,11 @@ void setImages (Image image, Image [] images) { datas [i] = images [i].getImageData (getZoom()); } images = bestImages; - sort (images, datas, OS.GetSystemMetrics (OS.SM_CXSMICON), OS.GetSystemMetrics (OS.SM_CYSMICON), depth); + sort (images, datas, getSystemMetrics (OS.SM_CXSMICON), getSystemMetrics (OS.SM_CYSMICON), depth); } smallIcon = images [0]; if (images.length > 1) { - sort (images, datas, OS.GetSystemMetrics (OS.SM_CXICON), OS.GetSystemMetrics (OS.SM_CYICON), depth); + sort (images, datas, getSystemMetrics (OS.SM_CXICON), getSystemMetrics (OS.SM_CYICON), depth); } largeIcon = images [0]; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java index c7b1e4e58ec..00141b4f172 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java @@ -135,7 +135,7 @@ static int checkStyle (int style) { checkWidget (); int width = 0, height = 0, border = getBorderWidthInPixels (); if ((style & SWT.SEPARATOR) != 0) { - int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER); + int lineWidth = getSystemMetrics (OS.SM_CXBORDER); if ((style & SWT.HORIZONTAL) != 0) { width = DEFAULT_WIDTH; height = lineWidth * 2; } else { @@ -535,7 +535,7 @@ void wmDrawChildSeparator(DRAWITEMSTRUCT struct) { if ((style & SWT.SHADOW_NONE) != 0) return; RECT rect = new RECT (); - int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER); + int lineWidth = getSystemMetrics (OS.SM_CXBORDER); int flags = (style & SWT.SHADOW_IN) != 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED; if ((style & SWT.HORIZONTAL) != 0) { int bottom = struct.top + Math.max (lineWidth * 2, (struct.bottom - struct.top) / 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java index 67f2971a163..b72a967359f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java @@ -260,10 +260,10 @@ static int checkStyle (int style) { width += border * 2 + INSET; height += border * 2; if ((style & SWT.V_SCROLL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); + width += getSystemMetrics (OS.SM_CXVSCROLL); } if ((style & SWT.H_SCROLL) != 0) { - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + height += getSystemMetrics (OS.SM_CYHSCROLL); } return new Point (width, height); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java index cdd69e3b268..af057fb5bce 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java @@ -1354,7 +1354,7 @@ LRESULT wmTimer (long wParam, long lParam) { if (!success) return null; if (OS.PtInRect (rect, pt)) { // Mouse cursor is within the bounds of menu item - selectedMenuItem.showTooltip (pt.x, pt.y + OS.GetSystemMetrics(OS.SM_CYCURSOR) / 2 + 5); + selectedMenuItem.showTooltip (pt.x, pt.y + getSystemMetrics(OS.SM_CYCURSOR) / 2 + 5); } else { /* * Mouse cursor is outside the bounds of the menu item: diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java index 88124e9178b..a720997c004 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java @@ -123,11 +123,11 @@ static int checkStyle (int style) { int border = getBorderWidthInPixels (); int width = border * 2, height = border * 2; if ((style & SWT.HORIZONTAL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10; - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + width += getSystemMetrics (OS.SM_CXHSCROLL) * 10; + height += getSystemMetrics (OS.SM_CYHSCROLL); } else { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); - height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10; + width += getSystemMetrics (OS.SM_CXVSCROLL); + height += getSystemMetrics (OS.SM_CYVSCROLL) * 10; } if (wHint != SWT.DEFAULT) width = wHint + (border * 2); if (hHint != SWT.DEFAULT) height = hHint + (border * 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java index 0f343716f1c..d1557658cfe 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java @@ -150,13 +150,13 @@ static int checkStyle (int style) { RECT rect = new RECT (); OS.SendMessage (handle, OS.TBM_GETTHUMBRECT, 0, rect); if ((style & SWT.HORIZONTAL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10; - int scrollY = OS.GetSystemMetrics (OS.SM_CYHSCROLL); + width += getSystemMetrics (OS.SM_CXHSCROLL) * 10; + int scrollY = getSystemMetrics (OS.SM_CYHSCROLL); height += (rect.top * 2) + scrollY + (scrollY / 3); } else { - int scrollX = OS.GetSystemMetrics (OS.SM_CXVSCROLL); + int scrollX = getSystemMetrics (OS.SM_CXVSCROLL); width += (rect.left * 2) + scrollX + (scrollX / 3); - height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10; + height += getSystemMetrics (OS.SM_CYVSCROLL) * 10; } if (wHint != SWT.DEFAULT) width = wHint + (border * 2); if (hHint != SWT.DEFAULT) height = hHint + (border * 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java index 50a9c06e5bb..1fb4dd98afa 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java @@ -199,10 +199,10 @@ Rectangle getBounds () { if ((style & SWT.HORIZONTAL) != 0) { y = rect.bottom - rect.top; width = rect.right - rect.left; - height = OS.GetSystemMetrics (OS.SM_CYHSCROLL); + height = getSystemMetrics (OS.SM_CYHSCROLL); } else { x = rect.right - rect.left; - width = OS.GetSystemMetrics (OS.SM_CXVSCROLL); + width = getSystemMetrics (OS.SM_CXVSCROLL); height = rect.bottom - rect.top; } return new Rectangle (x, y, width, height); @@ -365,9 +365,9 @@ Point getSizeInPixels () { int width, height; if ((style & SWT.HORIZONTAL) != 0) { width = rect.right - rect.left; - height = OS.GetSystemMetrics (OS.SM_CYHSCROLL); + height = getSystemMetrics (OS.SM_CYHSCROLL); } else { - width = OS.GetSystemMetrics (OS.SM_CXVSCROLL); + width = getSystemMetrics (OS.SM_CXVSCROLL); height = rect.bottom - rect.top; } return new Point (width, height); @@ -468,7 +468,7 @@ Rectangle getThumbTrackBoundsInPixels () { int x = 0, y = 0, width, height; if ((style & SWT.HORIZONTAL) != 0) { OS.GetScrollBarInfo(parent.handle, OS.OBJID_HSCROLL, info); - int size = OS.GetSystemMetrics (OS.SM_CYHSCROLL); + int size = getSystemMetrics (OS.SM_CYHSCROLL); y = info.rcScrollBar.top; width = info.rcScrollBar.right - info.rcScrollBar.left; height = size; @@ -481,7 +481,7 @@ Rectangle getThumbTrackBoundsInPixels () { } } else { OS.GetScrollBarInfo(parent.handle, OS.OBJID_VSCROLL, info); - int size = OS.GetSystemMetrics (OS.SM_CYVSCROLL); + int size = getSystemMetrics (OS.SM_CYVSCROLL); x = info.rcScrollBar.left; width = size; height = info.rcScrollBar.bottom - info.rcScrollBar.top; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java index 10eb61112bd..50dfa9b1514 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java @@ -135,8 +135,8 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) { int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE); int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE); OS.AdjustWindowRectEx (rect, bits1, false, bits2); - if (horizontalBar != null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL); - if (verticalBar != null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL); + if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL); + if (verticalBar != null) rect.right += getSystemMetrics (OS.SM_CXVSCROLL); int nWidth = rect.right - rect.left, nHeight = rect.bottom - rect.top; return new Rectangle (rect.left, rect.top, nWidth, nHeight); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index a2f1e7677a5..d5c2a929a6e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -1063,12 +1063,12 @@ Point getMaximumSizeInPixels () { int width = Math.min (Integer.MAX_VALUE, maxWidth); int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { - width = Math.min (width, OS.GetSystemMetrics (OS.SM_CXMAXTRACK)); + width = Math.min (width, getSystemMetrics (OS.SM_CXMAXTRACK)); } int height = Math.min (Integer.MAX_VALUE, maxHeight); if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { if ((style & SWT.RESIZE) != 0) { - height = Math.min (height, OS.GetSystemMetrics (OS.SM_CYMAXTRACK)); + height = Math.min (height, getSystemMetrics (OS.SM_CYMAXTRACK)); } else { RECT rect = new RECT (); int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); @@ -1104,12 +1104,12 @@ Point getMinimumSizeInPixels () { int width = Math.max (0, minWidth); int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { - width = Math.max (width, OS.GetSystemMetrics (OS.SM_CXMINTRACK)); + width = Math.max (width, getSystemMetrics (OS.SM_CXMINTRACK)); } int height = Math.max (0, minHeight); if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { if ((style & SWT.RESIZE) != 0) { - height = Math.max (height, OS.GetSystemMetrics (OS.SM_CYMINTRACK)); + height = Math.max (height, getSystemMetrics (OS.SM_CYMINTRACK)); } else { RECT rect = new RECT (); int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); @@ -1775,9 +1775,9 @@ void setMaximumSizeInPixels (int width, int height) { int widthLimit = 0, heightLimit = 0; int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { - widthLimit = OS.GetSystemMetrics (OS.SM_CXMAXTRACK); + widthLimit = getSystemMetrics (OS.SM_CXMAXTRACK); if ((style & SWT.RESIZE) != 0) { - heightLimit = OS.GetSystemMetrics (OS.SM_CYMAXTRACK); + heightLimit = getSystemMetrics (OS.SM_CYMAXTRACK); } else { RECT rect = new RECT (); int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); @@ -1821,9 +1821,9 @@ void setMinimumSizeInPixels (int width, int height) { int widthLimit = 0, heightLimit = 0; int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { - widthLimit = OS.GetSystemMetrics (OS.SM_CXMINTRACK); + widthLimit = getSystemMetrics (OS.SM_CXMINTRACK); if ((style & SWT.RESIZE) != 0) { - heightLimit = OS.GetSystemMetrics (OS.SM_CYMINTRACK); + heightLimit = getSystemMetrics (OS.SM_CYMINTRACK); } else { RECT rect = new RECT (); int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); @@ -2628,12 +2628,12 @@ LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) { lpwp.cx = Math.max (lpwp.cx, minWidth); int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { - lpwp.cx = Math.max (lpwp.cx, OS.GetSystemMetrics (OS.SM_CXMINTRACK)); + lpwp.cx = Math.max (lpwp.cx, getSystemMetrics (OS.SM_CXMINTRACK)); } lpwp.cy = Math.max (lpwp.cy, minHeight); if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { if ((style & SWT.RESIZE) != 0) { - lpwp.cy = Math.max (lpwp.cy, OS.GetSystemMetrics (OS.SM_CYMINTRACK)); + lpwp.cy = Math.max (lpwp.cy, getSystemMetrics (OS.SM_CYMINTRACK)); } else { RECT rect = new RECT (); int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java index 6d13421e839..ff3f52d0b84 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java @@ -181,11 +181,11 @@ static int checkStyle (int style) { int border = getBorderWidthInPixels (); int width = border * 2, height = border * 2; if ((style & SWT.HORIZONTAL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10; - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + width += getSystemMetrics (OS.SM_CXHSCROLL) * 10; + height += getSystemMetrics (OS.SM_CYHSCROLL); } else { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); - height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10; + width += getSystemMetrics (OS.SM_CXVSCROLL); + height += getSystemMetrics (OS.SM_CYVSCROLL) * 10; } if (wHint != SWT.DEFAULT) width = wHint + (border * 2); if (hHint != SWT.DEFAULT) height = hHint + (border * 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java index ed729ec89f9..c26b42cc191 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java @@ -296,7 +296,7 @@ void addVerifyListener (VerifyListener listener) { height = hHint; else { int borderAdjustment = (style & SWT.BORDER) != 0 ? -1 : 3; - int upDownHeight = OS.GetSystemMetrics (OS.SM_CYVSCROLL); + int upDownHeight = getSystemMetrics (OS.SM_CYVSCROLL); height = Math.max(height, upDownHeight + borderAdjustment); } @@ -339,7 +339,7 @@ void addVerifyListener (VerifyListener listener) { width += 2; height += 2; } - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); + width += getSystemMetrics (OS.SM_CXVSCROLL); return new Rectangle (x, y, width, height); } @@ -1216,7 +1216,7 @@ LRESULT WM_SIZE (long wParam, long lParam) { LRESULT result = super.WM_SIZE (wParam, lParam); if (isDisposed ()) return result; int width = OS.LOWORD (lParam), height = OS.HIWORD (lParam); - int upDownWidth = OS.GetSystemMetrics (OS.SM_CXVSCROLL) - 1; + int upDownWidth = getSystemMetrics (OS.SM_CXVSCROLL) - 1; int textWidth = width - upDownWidth; /* @@ -1226,7 +1226,7 @@ LRESULT WM_SIZE (long wParam, long lParam) { */ int borderAdjustment = 0; if (((style & SWT.BORDER) != 0) && !display.useWsBorderText) { - borderAdjustment = OS.GetSystemMetrics (OS.SM_CYEDGE) - OS.GetSystemMetrics (OS.SM_CYBORDER); + borderAdjustment = getSystemMetrics (OS.SM_CYEDGE) - getSystemMetrics (OS.SM_CYBORDER); /* There is an unexplained 1px additional offset in Windows */ borderAdjustment++; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index c0d9223ac1f..445b8a86d52 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -1479,10 +1479,10 @@ public void clearAll () { int border = getBorderWidthInPixels (); width += border * 2; height += border * 2; if ((style & SWT.V_SCROLL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); + width += getSystemMetrics (OS.SM_CXVSCROLL); } if ((style & SWT.H_SCROLL) != 0) { - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + height += getSystemMetrics (OS.SM_CYHSCROLL); } return new Point (width, height); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java index b1d51eb6454..a284793fcd2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java @@ -789,8 +789,8 @@ public void clearSelection () { // When WS_BORDER is used instead of WS_EX_CLIENTEDGE, compensate the size difference if (isUseWsBorder ()) { - int dx = OS.GetSystemMetrics (OS.SM_CXEDGE) - OS.GetSystemMetrics (OS.SM_CXBORDER); - int dy = OS.GetSystemMetrics (OS.SM_CYEDGE) - OS.GetSystemMetrics (OS.SM_CYBORDER); + int dx = getSystemMetrics (OS.SM_CXEDGE) - getSystemMetrics (OS.SM_CXBORDER); + int dy = getSystemMetrics (OS.SM_CYEDGE) - getSystemMetrics (OS.SM_CYBORDER); rect.x -= dx; rect.y -= dy; rect.width += 2*dx; @@ -969,15 +969,6 @@ void fixAlignment () { @Override int getBorderWidthInPixels () { checkWidget (); - /* - * Feature in Windows 2000 and XP. Despite the fact that WS_BORDER - * is set when the edit control is created, the style bit is cleared. - * The fix is to avoid the check for WS_BORDER and use the SWT widget - * style bits instead. - */ -// if ((style & SWT.BORDER) != 0 && (style & SWT.FLAT) != 0) { -// return OS.GetSystemMetrics (OS.SM_CXBORDER); -// } return super.getBorderWidthInPixels (); } @@ -2095,7 +2086,7 @@ void setMargins () { if ((style & SWT.ICON_SEARCH) != 0) flags |= fLeading; if ((style & SWT.ICON_CANCEL) != 0) flags |= fTrailing; if (flags != 0) { - int iconWidth = OS.GetSystemMetrics (OS.SM_CXSMICON); + int iconWidth = getSystemMetrics (OS.SM_CXSMICON); OS.SendMessage (handle, OS.EM_SETMARGINS, flags, OS.MAKELPARAM(iconWidth, iconWidth)); } } @@ -2958,7 +2949,7 @@ LRESULT WM_SIZE(long wParam, long lParam) { long hwndTrailing = OS.GetDlgItem (handle, rtl ? SWT.ICON_SEARCH : SWT.ICON_CANCEL); int width = OS.LOWORD (lParam); int height = OS.HIWORD (lParam); - int iconWidth = OS.GetSystemMetrics (OS.SM_CXSMICON); + int iconWidth = getSystemMetrics (OS.SM_CXSMICON); int flags = OS.SWP_NOZORDER | OS.SWP_NOACTIVATE | OS.SWP_NOCOPYBITS; if (hwndLeading != 0) OS.SetWindowPos (hwndLeading, 0, 0, 0, iconWidth, height, flags); if (hwndTrailing != 0) OS.SetWindowPos (hwndTrailing, 0, width - iconWidth, 0, iconWidth, height, flags); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index 93252bd4809..597101e72f5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -1860,10 +1860,10 @@ long CompareFunc (long lParam1, long lParam2, long lParamSort) { width += border * 2; height += border * 2; if ((style & SWT.V_SCROLL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); + width += getSystemMetrics (OS.SM_CXVSCROLL); } if ((style & SWT.H_SCROLL) != 0) { - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); + height += getSystemMetrics (OS.SM_CYHSCROLL); } return new Point (width, height); } @@ -5050,7 +5050,7 @@ void setScrollWidth (int width) { if (playout.prc != 0) OS.HeapFree (hHeap, 0, playout.prc); if (playout.pwpos != 0) OS.HeapFree (hHeap, 0, playout.pwpos); OS.SetWindowPos (hwndHeader, OS.HWND_TOP, pos.x - left, pos.y, pos.cx + left, pos.cy, OS.SWP_NOACTIVATE); - int w = pos.cx + (columnCount == 0 && width == 0 ? 0 : OS.GetSystemMetrics (OS.SM_CXVSCROLL)); + int w = pos.cx + (columnCount == 0 && width == 0 ? 0 : getSystemMetrics (OS.SM_CXVSCROLL)); int h = rect.bottom - rect.top - pos.cy; boolean oldIgnore = ignoreResize; ignoreResize = true; @@ -8057,7 +8057,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) { int newX = rect.left + deltaX; rect.right = Math.max (rect.right, rect.left + Math.abs (deltaX)); if (explorerTheme || (findImageControl () != null || hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem))) { - rect.left -= OS.GetSystemMetrics (OS.SM_CXFOCUSBORDER); + rect.left -= getSystemMetrics (OS.SM_CXFOCUSBORDER); OS.InvalidateRect (handle, rect, true); OS.OffsetRect (rect, deltaX, 0); OS.InvalidateRect (handle, rect, true); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java index 90b63310aea..b8c29913d75 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java @@ -392,7 +392,7 @@ public void pack () { if (hwndHeader != 0) { margin = (int)OS.SendMessage (hwndHeader, OS.HDM_GETBITMAPMARGIN, 0, 0); } else { - margin = OS.GetSystemMetrics (OS.SM_CXEDGE) * 3; + margin = getSystemMetrics (OS.SM_CXEDGE) * 3; } headerWidth += margin * 2; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java index c21b3d6aaa6..17a3bad67f0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java @@ -2344,7 +2344,7 @@ LRESULT wmPrint (long hwnd, long wParam, long lParam) { rect.right -= rect.left; rect.bottom -= rect.top; rect.left = rect.top = 0; - int border = OS.GetSystemMetrics (OS.SM_CXEDGE); + int border = getSystemMetrics (OS.SM_CXEDGE); OS.ExcludeClipRect (wParam, border, border, rect.right - border, rect.bottom - border); OS.DrawThemeBackground (display.hEditTheme (), wParam, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null); return new LRESULT (code); @@ -2659,4 +2659,16 @@ int getZoom() { private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) { widget.nativeZoom = newZoom; } + +int getSystemMetrics(int nIndex) { + /* + * DPI dependent metrics were introduced after 2016 version of windows 10 + */ + if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) { + return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(getZoom())); + } + return OS.GetSystemMetrics(nIndex); +} + + }