Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiraj Modi2018-04-13 08:41:49 +0000
committerNiraj Modi2018-04-13 08:41:49 +0000
commit846eb25ee0b561ce111e82fabd9d47c615dc3024 (patch)
treef18de23702a26c42608b4bd93896e2b3c4481c8e
parent77b6aeed18b669d60ad99c25acab47a4d44f010a (diff)
downloadeclipse.platform.swt-DynamicDPI_v4860f.tar.gz
eclipse.platform.swt-DynamicDPI_v4860f.tar.xz
eclipse.platform.swt-DynamicDPI_v4860f.zip
- Resized Button with Image on DPI change.DynamicDPI_v4860f
Change-Id: Iea25be350d071f9e3e8e5fdfa46908886f2fee3f Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet371.java30
3 files changed, 35 insertions, 14 deletions
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 2b9afec0ad..f8f298026c 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
@@ -1416,7 +1416,7 @@ public Rectangle getBounds() {
*/
public Rectangle getBounds(int zoom) {
// Read the bounds in pixels from native layer.
- Rectangle bounds = _getBoundsInPixelsFromNative();
+ Rectangle bounds = getBoundsInPixelsFromNative();
if (bounds != null && zoom != currentDeviceZoom) {
bounds = DPIUtil.autoScaleBounds(bounds, zoom, currentDeviceZoom);
}
@@ -1444,10 +1444,10 @@ public Rectangle getBoundsInPixels() {
if (width != -1 && height != -1) {
return new Rectangle(0, 0, width, height);
}
- return _getBoundsInPixelsFromNative();
+ return getBoundsInPixelsFromNative();
}
-Rectangle _getBoundsInPixelsFromNative() {
+Rectangle getBoundsInPixelsFromNative() {
switch (type) {
case SWT.BITMAP:
BITMAP bm = new BITMAP();
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 9b9db7148a..23d31b6f01 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
@@ -402,6 +402,17 @@ int computeLeftMargin () {
return margin;
}
+@Override
+boolean refreshControlForDPIChange() {
+ boolean refreshed = false;
+ // Refresh image on DPI change
+ if(image != null) {
+ refreshed |= image.refreshImageForZoom(this);
+ _setImage(image);
+ }
+ return refreshed;
+}
+
@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
checkWidget ();
int width = 0, height = 0, border = getBorderWidthInPixels ();
@@ -444,7 +455,7 @@ int computeLeftMargin () {
}
if (hasImage) {
if (image != null) {
- Rectangle rect = image.getBoundsInPixels ();
+ Rectangle rect = image.getBounds(getShell().currentDeviceZoom);
width = rect.width;
if (hasText && text.length () != 0) {
width += MARGIN * 2;
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet371.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet371.java
index 0e8a85ddd1..40f1e855b1 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet371.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet371.java
@@ -65,19 +65,21 @@ public class Snippet371 {
Shell shell = new Shell(display);
shell.setText("Dynamic DPI Test");
shell.setLayout(new RowLayout(SWT.VERTICAL));
- shell.setSize(400, 300);
- Label label = new Label (shell, SWT.NONE);
+ shell.setLocation(100, 200);
+ shell.setSize(400, 400);
+ Label label = new Label (shell, SWT.BORDER);
label.setText("PerMonitorV2 value before:after:Error");
Text text = new Text(shell, SWT.BORDER);
text.setText(DPIUtil.BEFORE + ":" + DPIUtil.AFTER + ":" + DPIUtil.RESULT);
- Composite composite = new Composite(shell, SWT.NONE);
+ Composite composite = new Composite(shell, SWT.BORDER);
composite.setLayout(new RowLayout(SWT.HORIZONTAL));
- Label label1 = new Label (composite, SWT.NONE);
+ Label label1 = new Label (composite, SWT.BORDER);
final Image eclipse = new Image(display, filenameProvider);
label1.setImage (eclipse);
Button createDialog = new Button(composite, SWT.PUSH);
- createDialog.setText("Open image in a new child dialog");
+ createDialog.setText("eclipse in child dialog");
+ createDialog.setImage(eclipse);
createDialog.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
@@ -85,7 +87,7 @@ public class Snippet371 {
dialog.setText("Child Dialog");
RowLayout rowLayout = new RowLayout (SWT.VERTICAL);
dialog.setLayout (rowLayout);
- Label label = new Label (dialog, SWT.NONE);
+ Label label = new Label (dialog, SWT.BORDER);
label.setImage(eclipse);
Point location = shell.getLocation();
dialog.setLocation(location.x + 250, location.y + 50);
@@ -98,24 +100,32 @@ public class Snippet371 {
button.setText("Refresh-Current Monitor [Handle : Zoom] ");
Text text1 = new Text(shell, SWT.BORDER);
Monitor monitor = button.getMonitor();
- text1.setText(monitor.handle + " : " + monitor.getZoom());
+ text1.setText("" + monitor.getZoom());
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
Monitor monitor = button.getMonitor();
- text1.setText(monitor.handle + " : " + monitor.getZoom());
+ text1.setText("" + monitor.getZoom());
}
});
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("Refresh-Both Monitors [Handle : Zoom]");
Text text2 = new Text(shell, SWT.BORDER);
Monitor[] monitors = display.getMonitors();
- text2.setText(monitors[0].handle + " : " + monitors[0].getZoom() + " - " + monitors[1].handle + " : " + monitors[1].getZoom());
+ StringBuffer text2String = new StringBuffer();
+ for (int i = 0; i < monitors.length; i++) {
+ text2String.append(monitors[i].getZoom() + (i < (monitors.length -1) ? " - " : ""));
+ }
+ text2.setText(text2String.toString());
button2.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
Monitor[] monitors = display.getMonitors();
- text2.setText(monitors[0].handle + " : " + monitors[0].getZoom() + " - " + monitors[1].handle + " : " + monitors[1].getZoom());
+ StringBuffer text2String = new StringBuffer();
+ for (int i = 0; i < monitors.length; i++) {
+ text2String.append(monitors[i].getZoom() + (i < (monitors.length -1) ? " - " : ""));
+ }
+ text2.setText(text2String.toString());
}
});

Back to the top