Skip to content

Commit 33f0ba6

Browse files
committed
Copy and paste no longer tries to autoscale the image. The image is always copied and pasted at 100% zoom. Fixes #194
Previously, when copying an image in the clipboard example, the image at the current zoom level was stored to clipboard using getImageDataAtCurrentZoom(). However, in normal Windows behavior (e.g., Paint), images are always copied at their original size regardless of the current zoom. When pasting, the image is pasted at 100% zoom, and the application handles zoom internally when displaying the image. To match this behavior, copy and paste now always handle images at 100% scale, ignoring the current zoom and leaving zoom handling to the image class when it is fetched for display. Fixes vi-eclipse/Eclipse-Platform#194
1 parent 8b45dd8 commit 33f0ba6

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/ImageTransfer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import org.eclipse.swt.*;
1717
import org.eclipse.swt.graphics.*;
18-
import org.eclipse.swt.internal.*;
1918
import org.eclipse.swt.internal.ole.win32.*;
2019
import org.eclipse.swt.internal.win32.*;
2120

@@ -184,8 +183,9 @@ public Object nativeToJava(TransferData transferData) {
184183
pSourceBits -= scanline;
185184
}
186185
}
187-
Image image = Image.win32_new(null, SWT.BITMAP, memDib, DPIUtil.getNativeDeviceZoom());
188-
ImageData data = image.getImageData (DPIUtil.getDeviceZoom ());
186+
final int DEFAULT_IMAGE_STORAGE_ZOOM = 100;
187+
Image image = Image.win32_new(null, SWT.BITMAP, memDib, DEFAULT_IMAGE_STORAGE_ZOOM);
188+
ImageData data = image.getImageData ();
189189
OS.DeleteObject(memDib);
190190
image.dispose();
191191
return data;

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.eclipse.swt.graphics.GC;
3131
import org.eclipse.swt.graphics.Image;
3232
import org.eclipse.swt.graphics.ImageData;
33-
import org.eclipse.swt.graphics.ImageDataProvider;
3433
import org.eclipse.swt.graphics.Point;
3534
import org.eclipse.swt.graphics.Rectangle;
3635
import org.eclipse.swt.layout.FillLayout;
@@ -62,38 +61,6 @@ public class ClipboardExample {
6261
Label status;
6362
static final int HSIZE = 100, VSIZE = 60;
6463

65-
static final class AutoScaleImageDataProvider implements ImageDataProvider {
66-
ImageData imageData;
67-
int currentZoom;
68-
public AutoScaleImageDataProvider (ImageData data) {
69-
this.imageData = data;
70-
this.currentZoom = getDeviceZoom ();
71-
}
72-
73-
@Override
74-
public ImageData getImageData (int zoom) {
75-
return autoScaleImageData(imageData, zoom, currentZoom);
76-
}
77-
78-
static ImageData autoScaleImageData (ImageData imageData, int targetZoom, int currentZoom) {
79-
if (imageData == null || targetZoom == currentZoom) return imageData;
80-
float scaleFactor = ((float) targetZoom)/((float) currentZoom);
81-
return imageData.scaledTo (Math.round (imageData.width * scaleFactor), Math.round (imageData.height * scaleFactor));
82-
}
83-
84-
static int getDeviceZoom () {
85-
int zoom = 100;
86-
String value = System.getProperty ("org.eclipse.swt.internal.deviceZoom");
87-
if (value != null) {
88-
try {
89-
zoom = Integer.parseInt(value);
90-
} catch (NumberFormatException e) {
91-
e.printStackTrace();
92-
}
93-
}
94-
return zoom;
95-
}
96-
}
9764

9865
public static void main( String[] args) {
9966
Display display = new Display();
@@ -476,8 +443,8 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
476443
b.addSelectionListener(widgetSelectedAdapter(e -> {
477444
if (copyImage[0] != null) {
478445
status.setText("");
479-
// Fetch ImageData at current zoom and save in the clip-board.
480-
clipboard.setContents(new Object[] {copyImage[0].getImageDataAtCurrentZoom()}, new Transfer[] {ImageTransfer.getInstance()});
446+
// Fetch ImageData and save in the clip-board.
447+
clipboard.setContents(new Object[] {copyImage[0].getImageData()}, new Transfer[] {ImageTransfer.getInstance()});
481448
} else {
482449
status.setText("No image to copy");
483450
}
@@ -540,8 +507,7 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
540507
pasteImage[0].dispose();
541508
}
542509
status.setText("");
543-
// Consume the ImageData at current zoom as-is.
544-
pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
510+
pasteImage[0] = new Image(e.display, imageData);
545511
pasteVBar.setEnabled(true);
546512
pasteHBar.setEnabled(true);
547513
pasteOrigin.x = 0; pasteOrigin.y = 0;

0 commit comments

Comments
 (0)