Bug 534820 - [HiDPI][Win10][GTK] Support dynamic-scaling on DPI change
- Display.getDeviceZoom now fetches Primary monitor's zoom on Win8.1 and
above.
- Code refactoring in Button/Label/Widget classes

Change-Id: I7d0577b1a69937fb76eca43640b232fc865070f8
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
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 7ae4528..ba046e6 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
@@ -338,12 +338,7 @@
 			boolean hasImage = image != null, hasText = true;
 			if (hasImage) {
 				if (image != null) {
-					// There exists a possibility of DPI change
-					if (image.setZoom(this.currentDeviceZoom)) {
-						_setImage(image);
-						updateImageList();
-					}
-					Rectangle rect = image.getBounds(getShell().currentDeviceZoom);
+					Rectangle rect = image.getBounds(this.currentDeviceZoom);
 					width = rect.width;
 					if (hasText && text.length () != 0) {
 						width += MARGIN * 2;
@@ -1081,13 +1076,12 @@
 @Override
 public boolean setZoom (int zoom) {
 	boolean refreshed = super.setZoom (zoom);
+	this.currentDeviceZoom = zoom;
 	// Refresh the image
 	if(image != null) {
 		refreshed = image.setZoom (zoom);
-		if (refreshed) {
-			_setImage  (image);
-			updateImageList();
-		}
+		_setImage  (image);
+		updateImageList();
 	}
 	return refreshed;
 }
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 3499e18..a7247ce 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -2025,6 +2025,18 @@
 	return modalDialog;
 }
 
+/**
+ * @since 3.108
+ */
+@Override
+protected int getDeviceZoom() {
+	/* Win8.1 and above we pick zoom for the primary monitor zoom. */
+	if (OS.WIN32_VERSION >= OS.VERSION (6, 3)) {
+		return getPrimaryMonitor().getZoom();
+	}
+	return super.getDeviceZoom();
+}
+
 Monitor getMonitor (long /*int*/ hmonitor) {
 	MONITORINFO lpmi = new MONITORINFO ();
 	lpmi.cbSize = MONITORINFO.sizeof;
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 6067693..aa0a5b3 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -129,14 +129,13 @@
 }
 
 @Override
-boolean refreshControlForDPIChange() {
+public boolean setZoom (int zoom) {
 	boolean refreshed = false;
+	this.currentDeviceZoom = zoom;
 	// Refresh image on DPI change
 	if(image != null) {
 		refreshed = image.setZoom (this.currentDeviceZoom);
-		if (refreshed) {
-			setImage  (image);
-		}
+		setImage  (image);
 	}
 	return refreshed;
 }
@@ -161,8 +160,6 @@
 	boolean drawImage = (bits & OS.SS_OWNERDRAW) == OS.SS_OWNERDRAW;
 	if (drawImage) {
 		if (image != null) {
-			// There exists a possibility of DPI change
-//			if (image.setZoom(this.currentDeviceZoom)) setImage  (image);
 			Rectangle rect = image.getBounds(this.currentDeviceZoom);
 			width += rect.width;
 			height += rect.height;
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 d3f6407..d50dbb1 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -46,7 +46,8 @@
  */
 public abstract class Widget {
 	/**
-	 * s
+	 * Specify current zoom level for the widget.
+	 *
 	 * @since 3.108
 	 */
 	protected int currentDeviceZoom = DPIUtil.getDeviceZoom();