- Resized Button with Image on DPI change. Change-Id: Iea25be350d071f9e3e8e5fdfa46908886f2fee3f Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
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 2b9afec..f8f2980 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(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 @@ 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 9b9db71..23d31b6 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 @@ 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 @@ } 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 0e8a85d..40f1e85 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 @@ 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 @@ 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 @@ 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()); } });