diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java index 937a9015367..8d779a891de 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java @@ -996,7 +996,7 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { /* Refresh Image as per zoom level, if required. */ - srcImage.handleDPIChange(DPIUtil.getDeviceZoom()); + srcImage.handleDPIChange(DPIUtil.getNativeDeviceZoom()); if (data.gdipGraphics != 0) { //TODO - cache bitmap long [] gdipImage = srcImage.createGdipImage(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 333e0ed2be5..3e4956f0d20 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -137,9 +137,9 @@ public final class Image extends Resource implements Drawable { private int styleFlag = SWT.IMAGE_COPY; /** - * Attribute to cache current device zoom level + * Attribute to cache current native zoom level */ - private int currentDeviceZoom = 100; + private int currentNativeZoom = 100; /** * width of the image @@ -161,7 +161,7 @@ public final class Image extends Resource implements Drawable { */ Image (Device device) { super(device); - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); } /** @@ -201,7 +201,7 @@ public final class Image extends Resource implements Drawable { */ public Image(Device device, int width, int height) { super(device); - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); width = DPIUtil.autoScaleUp (width); height = DPIUtil.autoScaleUp (height); init(width, height); @@ -254,7 +254,7 @@ public Image(Device device, Image srcImage, int flag) { this.imageDataProvider = srcImage.imageDataProvider; this.imageFileNameProvider = srcImage.imageFileNameProvider; this.styleFlag = srcImage.styleFlag | flag; - this.currentDeviceZoom = srcImage.currentDeviceZoom; + currentNativeZoom = srcImage.currentNativeZoom; this.dataAtBaseZoom = srcImage.dataAtBaseZoom; switch (flag) { case SWT.IMAGE_COPY: { @@ -293,7 +293,7 @@ public Image(Device device, Image srcImage, int flag) { break; } case SWT.IMAGE_DISABLE: { - ImageData data = srcImage.getImageData(srcImage.currentDeviceZoom); + ImageData data = srcImage.getImageData(srcImage.getZoom()); PaletteData palette = data.palette; RGB[] rgbs = new RGB[3]; rgbs[0] = device.getSystemColor(SWT.COLOR_BLACK).getRGB(); @@ -352,7 +352,7 @@ public Image(Device device, Image srcImage, int flag) { break; } case SWT.IMAGE_GRAY: { - ImageData data = srcImage.getImageData(srcImage.currentDeviceZoom); + ImageData data = srcImage.getImageData(srcImage.getZoom()); PaletteData palette = data.palette; ImageData newData = data; if (!palette.isDirect) { @@ -459,7 +459,7 @@ public Image(Device device, Image srcImage, int flag) { public Image(Device device, Rectangle bounds) { super(device); if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); bounds = DPIUtil.autoScaleUp (bounds); init(bounds.width, bounds.height); init(); @@ -491,7 +491,7 @@ public Image(Device device, Rectangle bounds) { public Image(Device device, ImageData data) { super(device); if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(data, 100); data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom); init(data); @@ -535,7 +535,7 @@ public Image(Device device, ImageData source, ImageData mask) { if (source.width != mask.width || source.height != mask.height) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(applyMask(source, ImageData.convertMask(mask)), 100); source = DPIUtil.autoScaleUp(device, source); mask = DPIUtil.autoScaleUp(device, mask); @@ -599,7 +599,7 @@ public Image(Device device, ImageData source, ImageData mask) { */ public Image (Device device, InputStream stream) { super(device); - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(new ImageData (stream), 100); ImageData data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom); init(data); @@ -641,7 +641,7 @@ public Image (Device device, InputStream stream) { public Image (Device device, String filename) { super(device); if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - currentDeviceZoom = DPIUtil.getDeviceZoom (); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(new ImageData (filename), 100); ImageData data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom); init(data); @@ -680,9 +680,9 @@ public Image (Device device, String filename) { public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); this.imageFileNameProvider = imageFileNameProvider; - currentDeviceZoom = DPIUtil.getDeviceZoom (); - ElementAtZoom fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom); - if (fileName.zoom() == currentDeviceZoom) { + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + ElementAtZoom fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, getZoom()); + if (fileName.zoom() == getZoom()) { initNative (fileName.element()); if (this.handle == 0) init(new ImageData (fileName.element())); } else { @@ -724,26 +724,28 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { public Image(Device device, ImageDataProvider imageDataProvider) { super(device); this.imageDataProvider = imageDataProvider; - currentDeviceZoom = DPIUtil.getDeviceZoom (); - ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, currentDeviceZoom); + currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, getZoom()); ImageData resizedData = DPIUtil.autoScaleImageData(device, data.element(), data.zoom()); init (resizedData); init(); } /** - * Update zoom and refresh the Image based on the zoom level, if required. + * Update zoom and refresh the Image based on the native zoom level, if required. * - * @param deviceZoom zoom in % of the standard resolution the image shall be scaled for + * @param nativeZoom native zoom in % of the monitor on which the image is painted * * @return true if image is refreshed */ -boolean handleDPIChange (int deviceZoom) { +boolean handleDPIChange (int nativeZoom) { + int newZoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); + int oldZoom = this.getZoom(); boolean refreshed = false; if (imageFileNameProvider != null) { - if (deviceZoom != currentDeviceZoom) { - ElementAtZoom filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, deviceZoom); - if (filename.zoom() == deviceZoom) { + if (newZoom != oldZoom) { + ElementAtZoom filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, newZoom); + if (filename.zoom() == newZoom) { /* Release current native resources */ destroy (); initNative(filename.element()); @@ -758,27 +760,27 @@ boolean handleDPIChange (int deviceZoom) { init (); refreshed = true; } - setCurrentDeviceZoom(deviceZoom); + setCurrentNativeZoom(nativeZoom); } } else if (imageDataProvider != null) { - if (deviceZoom != currentDeviceZoom) { - ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, deviceZoom); + if (newZoom != oldZoom) { + ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, newZoom); /* Release current native resources */ destroy (); ImageData resizedData = DPIUtil.autoScaleImageData (device, data.element(), data.zoom()); init(resizedData); init(); refreshed = true; - setCurrentDeviceZoom(deviceZoom); + setCurrentNativeZoom(nativeZoom); } } else if (this.dataAtBaseZoom != null) { // Resizing is only possible with a cached base image - if (deviceZoom != currentDeviceZoom) { - ImageData resizedData = getImageData(deviceZoom); + if (newZoom != oldZoom) { + ImageData resizedData = getImageData(newZoom); destroy (); init(resizedData); init(); refreshed = true; - setCurrentDeviceZoom(deviceZoom); + setCurrentNativeZoom(nativeZoom); } } return refreshed; @@ -1146,7 +1148,7 @@ public boolean equals (Object object) { if (object == this) return true; if (!(object instanceof Image)) return false; Image image = (Image) object; - if (device != image.device || transparentPixel != image.transparentPixel || currentDeviceZoom != image.currentDeviceZoom) return false; + if (device != image.device || transparentPixel != image.transparentPixel || getZoom() != image.getZoom()) return false; if (imageDataProvider != null && image.imageDataProvider != null) { return (styleFlag == image.styleFlag) && imageDataProvider.equals (image.imageDataProvider); } else if (imageFileNameProvider != null && image.imageFileNameProvider != null) { @@ -1243,8 +1245,8 @@ Rectangle getBounds(int zoom) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); // Read the bounds in pixels from native layer. Rectangle bounds = getBoundsInPixelsFromNative(); - if (bounds != null && zoom != currentDeviceZoom) { - bounds = DPIUtil.autoScaleBounds(bounds, zoom, currentDeviceZoom); + if (bounds != null && zoom != getZoom()) { + bounds = DPIUtil.autoScaleBounds(bounds, zoom, getZoom()); } return bounds; } @@ -1347,8 +1349,8 @@ public ImageData getImageData() { */ public ImageData getImageData (int zoom) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - - if (zoom == currentDeviceZoom) { + int currentZoom = getZoom(); + if (zoom == currentZoom) { return getImageDataAtCurrentZoom(); } else if (imageDataProvider != null) { ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, zoom); @@ -1365,12 +1367,12 @@ public ImageData getImageData (int zoom) { } if (this.dataAtBaseZoom == null) { // Cache data at base zoom before resizing it. - this.dataAtBaseZoom = new ElementAtZoom<>(getImageData(this.currentDeviceZoom), this.currentDeviceZoom); + this.dataAtBaseZoom = new ElementAtZoom<>(getImageData(currentZoom), currentZoom); } if (this.dataAtBaseZoom != null) { return DPIUtil.autoScaleImageData(device, this.dataAtBaseZoom, zoom); } else { - return DPIUtil.autoScaleImageData (device, getImageDataAtCurrentZoom (), zoom, currentDeviceZoom); + return DPIUtil.autoScaleImageData (device, getImageDataAtCurrentZoom (), zoom, currentZoom); } } @@ -1685,7 +1687,7 @@ public int hashCode () { if (imageDataProvider != null) { return imageDataProvider.hashCode(); } else if (imageFileNameProvider != null) { - return Objects.hash(imageFileNameProvider, styleFlag, transparentPixel, currentDeviceZoom); + return Objects.hash(imageFileNameProvider, styleFlag, transparentPixel, getZoom()); } else { return (int)handle; } @@ -2256,15 +2258,20 @@ public void setBackground(Color color) { device.internal_dispose_GC(hDC, null); } -private void setCurrentDeviceZoom(int newZoomFactor) { - if (this.currentDeviceZoom != newZoomFactor) { - this.currentDeviceZoom = newZoomFactor; +private void setCurrentNativeZoom(int newNativeZoom) { + int oldZoom = this.getZoom(); + this.currentNativeZoom = newNativeZoom; + if (oldZoom != getZoom()) { // width and height are tied to the current device zoom // they must be reset the the zoom factor changes width = height = -1; } } +private int getZoom() { + return DPIUtil.getZoomForAutoscaleProperty(currentNativeZoom); +} + /** * Returns a string containing a concise, human-readable * description of the receiver. @@ -2319,7 +2326,7 @@ public static Image win32_new(Device device, int type, long handle) { * @noreference This method is not intended to be referenced by clients. */ public static Image win32_new(Image image, int targetZoom) { - if (targetZoom != image.currentDeviceZoom) { + if (targetZoom != image.getZoom()) { image.handleDPIChange(targetZoom); } return image; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java index 07a10815f61..10c3df60191 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java @@ -475,7 +475,7 @@ public void setFont (Font font) { error (SWT.ERROR_INVALID_ARGUMENT); } Shell shell = parent.getShell(); - this.font = font == null ? null : Font.win32_new(font, shell.getNativeZoom()); + this.font = font == null ? null : Font.win32_new(font, shell.nativeZoom); if (hasFocus ()) setIMEFont (); } 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 3be70d9f163..3241f80b19d 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 @@ -717,7 +717,7 @@ int defaultBackground () { } long defaultFont() { - return display.getSystemFont(getShell().getNativeZoom()).handle; + return display.getSystemFont(getShell().nativeZoom).handle; } int defaultForeground () { @@ -1309,7 +1309,7 @@ public Font getFont () { if (font != null) return font; long hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); if (hFont == 0) hFont = defaultFont (); - return Font.win32_new (display, hFont, getShell().getNativeZoom()); + return Font.win32_new (display, hFont, getShell().nativeZoom); } /** @@ -3314,7 +3314,7 @@ public void setCursor (Cursor cursor) { } void setDefaultFont () { - long hFont = display.getSystemFont (getShell().getNativeZoom()).handle; + long hFont = display.getSystemFont (getShell().nativeZoom).handle; OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0); } @@ -3416,7 +3416,7 @@ public void setFont (Font font) { Font newFont = font; if (newFont != null) { if (newFont.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - newFont = Font.win32_new(newFont, getShell().getNativeZoom()); + newFont = Font.win32_new(newFont, getShell().nativeZoom); } long hFont = 0; if (font != null) { @@ -4686,9 +4686,9 @@ public boolean setParent (Composite parent) { if (OS.SetParent (topHandle, parent.handle) == 0) return false; this.parent = parent; // If parent changed, zoom level might need to be adjusted - if (parent.getZoom() != getZoom()) { - int oldZoom = getZoom(); - int newZoom = parent.getZoom(); + if (parent.nativeZoom != nativeZoom) { + int oldZoom = nativeZoom; + int newZoom = parent.nativeZoom; float scalingFactor = 1f * newZoom / oldZoom; DPIZoomChangeRegistry.applyChange(this, newZoom, scalingFactor); } @@ -4884,21 +4884,19 @@ LRESULT WM_DESTROY (long wParam, long lParam) { LRESULT WM_DPICHANGED (long wParam, long lParam) { // Map DPI to Zoom and compare - int nativeZoom = DPIUtil.mapDPIToZoom (OS.HIWORD (wParam)); - int newSWTZoom = DPIUtil.getZoomForAutoscaleProperty (nativeZoom); - int oldSWTZoom = getShell().getZoom(); + int newNativeZoom = DPIUtil.mapDPIToZoom (OS.HIWORD (wParam)); + int oldNativeZoom = getShell().nativeZoom; // Throw the DPI change event if zoom value changes - if (newSWTZoom != oldSWTZoom) { + if (newNativeZoom != oldNativeZoom) { Event event = new Event(); event.type = SWT.ZoomChanged; event.widget = this; - event.detail = newSWTZoom; + event.detail = newNativeZoom; event.doit = true; if (DPIUtil.isAutoScaleOnRuntimeActive()) { - DPIUtil.setDeviceZoom (nativeZoom); - getShell().setNativeZoom(nativeZoom); + DPIUtil.setDeviceZoom (newNativeZoom); } notifyListeners(SWT.ZoomChanged, event); @@ -5791,7 +5789,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac if (!(widget instanceof Control control)) { return; } - resizeFont(control, control.getShell().getNativeZoom()); + resizeFont(control, control.getShell().nativeZoom); Image image = control.getBackgroundImage(); if (image != null) { 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 dd082283883..dd2b34323b0 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 @@ -125,7 +125,6 @@ public class Shell extends Decorations { ToolTip [] toolTips; long hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle, menuItemToolTipHandle; int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT, maxWidth = SWT.DEFAULT, maxHeight = SWT.DEFAULT; - private int nativeZoom; long [] brushes; boolean showWithParent, fullScreen, wasMaximized, modified, center; String toolTitle, balloonTitle; @@ -301,18 +300,14 @@ public Shell (Display display, int style) { state |= FOREIGN_HANDLE; } - int shellZoom; int shellNativeZoom; if (parent != null) { - shellZoom = parent.getZoom(); - shellNativeZoom = parent.getNativeZoom(); + shellNativeZoom = parent.nativeZoom; } else { int mappedDPIZoom = getMonitor().getZoom(); - shellZoom = DPIUtil.getZoomForAutoscaleProperty(mappedDPIZoom); shellNativeZoom = mappedDPIZoom; } - this.setZoom(shellZoom); - this.setNativeZoom(shellNativeZoom); + this.nativeZoom = shellNativeZoom; reskinWidget(); createWidget (); @@ -2650,20 +2645,10 @@ LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) { return result; } -/** - * The native zoom in % of the standard resolution the shell is scaled for - */ -int getNativeZoom() { - return nativeZoom; -} - -void setNativeZoom(int nativeZoom) { - this.nativeZoom = nativeZoom; -} - private void handleZoomEvent(Event event) { - float scalingFactor = 1f * event.detail / getZoom(); - DPIZoomChangeRegistry.applyChange(this, event.detail, scalingFactor); + int newNativeZoom = event.detail; + float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(newNativeZoom) / getZoom(); + DPIZoomChangeRegistry.applyChange(this, newNativeZoom, scalingFactor); } private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java index a827c0fe9a6..15b3fd7ebaa 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java @@ -871,7 +871,7 @@ public void setFont (Font font){ } Font oldFont = this.font; Shell shell = parent.getShell(); - Font newFont = (font == null ? font : Font.win32_new(font, shell.getNativeZoom())); + Font newFont = (font == null ? font : Font.win32_new(font, shell.nativeZoom)); if (oldFont == newFont) return; this.font = newFont; if (oldFont != null && oldFont.equals (newFont)) return; @@ -1293,7 +1293,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac Shell shell = tableItem.parent.getShell(); for (int index = 0; index < cellFonts.length; index++) { Font cellFont = cellFonts[index]; - cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, shell.getNativeZoom()); + cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, shell.nativeZoom); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java index a5cbc6caaef..0138043e362 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java @@ -1390,7 +1390,7 @@ public void setFont (Font font){ Font oldFont = this.font; if (oldFont == font) return; Shell shell = parent.getShell(); - this.font = (font == null ? font : Font.win32_new(font, shell.getNativeZoom())); + this.font = (font == null ? font : Font.win32_new(font, shell.nativeZoom)); if (oldFont != null && oldFont.equals (font)) return; if (font != null) parent.customDraw = true; if ((parent.style & SWT.VIRTUAL) != 0) cached = true; @@ -1445,7 +1445,7 @@ public void setFont (int index, Font font) { Font oldFont = cellFont [index]; if (oldFont == font) return; Shell shell = parent.getShell(); - cellFont [index] = font == null ? font : Font.win32_new(font, shell.getNativeZoom()); + cellFont [index] = font == null ? font : Font.win32_new(font, shell.nativeZoom); if (oldFont != null && oldFont.equals (font)) return; if (font != null) parent.customDraw = true; if ((parent.style & SWT.VIRTUAL) != 0) cached = true; @@ -1838,7 +1838,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac Shell shell = treeItem.parent.getShell(); for (int index = 0; index < cellFonts.length; index++) { Font cellFont = cellFonts[index]; - cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, shell.getNativeZoom()); + cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, shell.nativeZoom); } } for (TreeItem item : treeItem.getItems()) { 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 1fcf440f448..efb713a0019 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 @@ -52,7 +52,19 @@ */ public abstract class Widget { - private int zoom; + /** + * the native zoom of the monitor in percent + * (Warning: This field is platform dependent) + *

+ * IMPORTANT: This field is not part of the SWT + * public API. It is marked public only so that it can be shared + * within the packages provided by SWT. It is not available on all + * platforms and should never be accessed from application code. + *

+ * + * @noreference This field is not intended to be referenced by clients. + */ + protected int nativeZoom; int style, state; Display display; EventTable eventTable; @@ -169,7 +181,7 @@ public Widget (Widget parent, int style) { checkSubclass (); checkParent (parent); this.style = style; - this.zoom = parent != null ? parent.getZoom() : DPIUtil.getDeviceZoom(); + this.nativeZoom = parent != null ? parent.nativeZoom : DPIUtil.getNativeDeviceZoom(); display = parent.display; reskinWidget (); notifyCreationTracker(); @@ -2635,19 +2647,11 @@ void notifyDisposalTracker() { } } - -/** - * The current DPI zoom level the widget is scaled for - */ int getZoom() { - return zoom; -} - -void setZoom(int zoom) { - this.zoom = zoom; + return DPIUtil.getZoomForAutoscaleProperty(nativeZoom); } private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) { - widget.setZoom(newZoom); + widget.nativeZoom = newZoom; } }