Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getZoomForAutoscaleProperty calls for win32 #1401

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static Frame new_Frame (final Composite parent) {

parent.getDisplay().asyncExec(() -> {
if (parent.isDisposed()) return;
final Rectangle clientArea = DPIUtil.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
final Rectangle clientArea = DPIUtil.scaleUp(parent.getClientArea(), parent.nativeZoom); // To Pixels
EventQueue.invokeLater(() -> {
frame.setSize (clientArea.width, clientArea.height);
frame.validate ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,7 @@ void updateButtons() {
if (showMax) {
if (minMaxTb == null) {
minMaxTb = new ToolBar(this, SWT.FLAT);
minMaxTb.setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_MAGENTA));
initAccessibleMinMaxTb();
addTabControl(minMaxTb, SWT.TRAIL, 0, false);
}
Expand All @@ -2542,6 +2543,7 @@ void updateButtons() {
if (showMin) {
if (minMaxTb == null) {
minMaxTb = new ToolBar(this, SWT.FLAT);
minMaxTb.setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_MAGENTA));
initAccessibleMinMaxTb();
addTabControl(minMaxTb, SWT.TRAIL, 0, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ private void drag(Event dragEvent) {
hwndDrag = 0;
topControl = null;
if (image != null) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
imagelist = new ImageList(SWT.NONE, zoom);
imagelist = new ImageList(SWT.NONE, nativeZoom);
imagelist.add(image);
topControl = control.getShell();
/*
Expand Down Expand Up @@ -520,7 +519,7 @@ private void drag(Event dragEvent) {
null);
OS.ShowWindow (hwndDrag, OS.SW_SHOW);
}
OS.ImageList_BeginDrag(imagelist.getHandle(zoom), 0, offsetX, event.offsetY);
OS.ImageList_BeginDrag(imagelist.getHandle(nativeZoom), 0, offsetX, event.offsetY);
/*
* Feature in Windows. When ImageList_DragEnter() is called,
* it takes a snapshot of the screen If a drag is started
Expand All @@ -532,8 +531,8 @@ private void drag(Event dragEvent) {
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
OS.RedrawWindow (topControl.handle, null, 0, flags);
POINT pt = new POINT ();
pt.x = DPIUtil.scaleUp(dragEvent.x, zoom);// To Pixels
pt.y = DPIUtil.scaleUp(dragEvent.y, zoom);// To Pixels
pt.x = DPIUtil.scaleUp(dragEvent.x, nativeZoom);// To Pixels
pt.y = DPIUtil.scaleUp(dragEvent.y, nativeZoom);// To Pixels
OS.MapWindowPoints (control.handle, 0, pt, 1);
RECT rect = new RECT ();
OS.GetWindowRect (hwndDrag, rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,8 @@ int DragEnter_64(long pDataObject, int grfKeyState, long pt, long pdwEffect) {
}

int DragEnter(long pDataObject, int grfKeyState, int pt_x, int pt_y, long pdwEffect) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points
pt_x = DPIUtil.scaleDown(pt_x, nativeZoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, nativeZoom);// To Points
selectedDataType = null;
selectedOperation = DND.DROP_NONE;
if (iDataObject != null) iDataObject.Release();
Expand Down Expand Up @@ -349,9 +348,8 @@ int DragOver_64(int grfKeyState, long pt, long pdwEffect) {
}

int DragOver(int grfKeyState, int pt_x, int pt_y, long pdwEffect) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points
pt_x = DPIUtil.scaleDown(pt_x, nativeZoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, nativeZoom);// To Points
if (iDataObject == null) return COM.S_FALSE;
int oldKeyOperation = keyOperation;

Expand Down Expand Up @@ -405,9 +403,8 @@ int Drop_64(long pDataObject, int grfKeyState, long pt, long pdwEffect) {

int Drop(long pDataObject, int grfKeyState, int pt_x, int pt_y, long pdwEffect) {
try {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points
pt_x = DPIUtil.scaleDown(pt_x, nativeZoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, nativeZoom);// To Points
DNDEvent event = new DNDEvent();
event.widget = this;
event.time = OS.GetMessageTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.DPIUtil.*;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.widgets.*;
Expand Down Expand Up @@ -147,7 +146,7 @@ Image getDragSourceImage(DragSourceEvent event) {
data.transparentPixel = shdi.crColorKey << 8;
}
Display display = control.getDisplay();
dragSourceImage = new Image(display, new AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
dragSourceImage = new Image(display, new AutoScaleImageDataProvider(display, data, control.nativeZoom));
OS.SelectObject (memHdc, oldMemBitmap);
OS.DeleteDC (memHdc);
OS.DeleteObject (memDib);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void dragOver(DropTargetEvent event) {
int effect = checkEffect(event.feedback);
long handle = table.handle;
Point coordinates = new Point(event.x, event.y);
coordinates = DPIUtil.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
coordinates = DPIUtil.scaleUp(table.toControl(coordinates), table.nativeZoom); // To Pixels
LVHITTESTINFO pinfo = new LVHITTESTINFO();
pinfo.x = coordinates.x;
pinfo.y = coordinates.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.DPIUtil.*;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.widgets.*;
Expand Down Expand Up @@ -146,7 +145,7 @@ Image getDragSourceImage(DragSourceEvent event) {
data.transparentPixel = shdi.crColorKey << 8;
}
Display display = control.getDisplay ();
dragSourceImage = new Image (display, new AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
dragSourceImage = new Image (display, new AutoScaleImageDataProvider(display, data, control.nativeZoom));
OS.SelectObject (memHdc, oldMemBitmap);
OS.DeleteDC (memHdc);
OS.DeleteObject (memDib);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void dragOver(DropTargetEvent event) {
int effect = checkEffect(event.feedback);
long handle = tree.handle;
Point coordinates = new Point(event.x, event.y);
coordinates = DPIUtil.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
coordinates = DPIUtil.scaleUp(tree.toControl(coordinates), tree.nativeZoom); // To Pixels
TVHITTESTINFO lpht = new TVHITTESTINFO ();
lpht.x = coordinates.x;
lpht.y = coordinates.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ protected int GetWindow(long phwnd) {
return COM.S_OK;
}
RECT getRect() {
Rectangle area = DPIUtil.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
Rectangle area = DPIUtil.scaleUp(getClientArea(), nativeZoom); // To Pixels
RECT rect = new RECT();
rect.left = area.x;
rect.top = area.y;
Expand Down Expand Up @@ -987,14 +987,14 @@ private int OnInPlaceDeactivate() {
return COM.S_OK;
}
private int OnPosRectChange(long lprcPosRect) {
Point size = DPIUtil.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
Point size = DPIUtil.scaleUp(getSize(), nativeZoom); // To Pixels
setExtent(size.x, size.y);
return COM.S_OK;
}
private void onPaint(Event e) {
if (state == STATE_RUNNING || state == STATE_INPLACEACTIVE) {
SIZE size = getExtent();
Rectangle area = DPIUtil.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
Rectangle area = DPIUtil.scaleUp(getClientArea(), nativeZoom); // To Pixels
RECT rect = new RECT();
if (getProgramID().startsWith("Excel.Sheet")) { //$NON-NLS-1$
rect.left = area.x; rect.right = area.x + (area.height * size.cx / size.cy);
Expand Down Expand Up @@ -1369,12 +1369,11 @@ void setBorderSpace(RECT newBorderwidth) {
setBounds();
}
void setBounds() {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
Rectangle area = DPIUtil.scaleDown(frame.getClientArea(), zoom); // To Pixels
setBounds(DPIUtil.scaleDown(borderWidths.left, zoom),
DPIUtil.scaleDown(borderWidths.top, zoom),
DPIUtil.scaleDown(area.width - borderWidths.left - borderWidths.right, zoom),
DPIUtil.scaleDown(area.height - borderWidths.top - borderWidths.bottom, zoom));
Rectangle area = DPIUtil.scaleDown(frame.getClientArea(), nativeZoom); // To Pixels
setBounds(DPIUtil.scaleDown(borderWidths.left, nativeZoom),
DPIUtil.scaleDown(borderWidths.top, nativeZoom),
DPIUtil.scaleDown(area.width - borderWidths.left - borderWidths.right, nativeZoom),
DPIUtil.scaleDown(area.height - borderWidths.top - borderWidths.bottom, nativeZoom));
setObjectRects();
}
private void setExtent(int width, int height){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void tearDownTest() {

protected void changeDPIZoom (int nativeZoom) {
DPIUtil.setDeviceZoom(nativeZoom);
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(nativeZoom) / DPIUtil.getZoomForAutoscaleProperty(shell.nativeZoom);
float scalingFactor = 1f * nativeZoom / shell.nativeZoom;
DPIZoomChangeRegistry.applyChange(shell, nativeZoom, scalingFactor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public static int getDeviceZoom() {

public static void setDeviceZoom (int nativeDeviceZoom) {
DPIUtil.nativeDeviceZoom = nativeDeviceZoom;
int deviceZoom = getZoomForAutoscaleProperty (nativeDeviceZoom);
int deviceZoom = nativeDeviceZoom;

DPIUtil.deviceZoom = deviceZoom;
System.setProperty("org.eclipse.swt.internal.deviceZoom", Integer.toString(deviceZoom));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public int getLeading() {
}

private int getZoom() {
return DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
return nativeZoom;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,12 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei
if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);

int deviceZoom = getZoom();
int deviceZoom = image.useDeviceZoom ? DPIUtil.getZoomForAutoscaleProperty(getZoom()) : getZoom();
Rectangle src = DPIUtil.scaleUp(drawable, new Rectangle(srcX, srcY, srcWidth, srcHeight), deviceZoom);
Rectangle dest = DPIUtil.scaleUp(drawable, new Rectangle(destX, destY, destWidth, destHeight), deviceZoom);
destX = DPIUtil.scaleUp(destX, getZoom());
destY = DPIUtil.scaleUp(destY, getZoom());
destWidth = DPIUtil.scaleUp(destWidth, deviceZoom);
destHeight = DPIUtil.scaleUp(destHeight, deviceZoom);
if (deviceZoom != 100) {
/*
* This is a HACK! Due to rounding errors at fractional scale factors,
Expand All @@ -996,13 +999,13 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei
}
}
}
drawImage(image, src.x, src.y, src.width, src.height, dest.x, dest.y, dest.width, dest.height, false);
drawImage(image, src.x, src.y, src.width, src.height, destX, destY, destWidth, destHeight, false);
}

void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
if (data.gdipGraphics != 0) {
//TODO - cache bitmap
long [] gdipImage = srcImage.createGdipImage(getZoom());
long [] gdipImage = srcImage.createGdipImage(DPIUtil.getZoomForAutoscaleProperty(getZoom()));
long img = gdipImage[0];
int imgWidth = Gdip.Image_GetWidth(img);
int imgHeight = Gdip.Image_GetHeight(img);
Expand Down Expand Up @@ -3932,7 +3935,7 @@ void init(Drawable drawable, GCData data, long hDC) {
}
Image image = data.image;
if (image != null) {
data.hNullBitmap = OS.SelectObject(hDC, Image.win32_getHandle(image, DPIUtil.getZoomForAutoscaleProperty(data.nativeZoom)));
data.hNullBitmap = OS.SelectObject(hDC, Image.win32_getHandle(image, data.nativeZoom));
image.memGC = this;
}
int layout = data.layout;
Expand Down Expand Up @@ -5160,7 +5163,7 @@ private static int sin(int angle, int length) {
}

private int getZoom() {
return DPIUtil.getZoomForAutoscaleProperty(data.nativeZoom);
return data.nativeZoom;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public final class Image extends Resource implements Drawable {

private HashMap<Integer, Long> zoomLevelToHandle = new HashMap<>();

boolean useDeviceZoom = false;

/**
* Prevents uninitialized instances from being created outside the package.
*/
Expand Down Expand Up @@ -256,6 +258,7 @@ public Image(Device device, Image srcImage, int flag) {
this.type = srcImage.type;
this.imageDataProvider = srcImage.imageDataProvider;
this.imageFileNameProvider = srcImage.imageFileNameProvider;
this.useDeviceZoom = srcImage.useDeviceZoom;
this.styleFlag = srcImage.styleFlag | flag;
initialNativeZoom = srcImage.initialNativeZoom;
this.dataAtBaseZoom = srcImage.dataAtBaseZoom;
Expand Down Expand Up @@ -350,6 +353,7 @@ public Image(Device device, Image srcImage, int flag) {
*/
public Image(Device device, Rectangle bounds) {
super(device);
useDeviceZoom = true;
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
bounds = DPIUtil.scaleUp (bounds, getZoom());
Expand Down Expand Up @@ -492,6 +496,7 @@ public Image(Device device, ImageData source, ImageData mask) {
public Image (Device device, InputStream stream) {
super(device);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
useDeviceZoom = true;
this.dataAtBaseZoom = new ElementAtZoom<>(new ImageData (stream), 100);
ImageData data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom);
init(data, getZoom());
Expand Down Expand Up @@ -534,6 +539,7 @@ public Image (Device device, String filename) {
super(device);
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
useDeviceZoom = true;
this.dataAtBaseZoom = new ElementAtZoom<>(new ImageData (filename), 100);
ImageData data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom);
init(data, getZoom());
Expand Down Expand Up @@ -573,6 +579,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
super(device);
this.imageFileNameProvider = imageFileNameProvider;
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
useDeviceZoom = true;
ElementAtZoom<String> fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, getZoom());
if (fileName.zoom() == getZoom()) {
long handle = initNative (fileName.element(), getZoom());
Expand Down Expand Up @@ -620,6 +627,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
public Image(Device device, ImageDataProvider imageDataProvider) {
super(device);
this.imageDataProvider = imageDataProvider;
useDeviceZoom = true;
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
ElementAtZoom<ImageData> data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, getZoom());
ImageData resizedData = DPIUtil.scaleImageData(device, data.element(), getZoom(), data.zoom());
Expand Down Expand Up @@ -788,6 +796,9 @@ private ImageData applyGrayImageData(ImageData data, int pHeight, int pWidth) {
* @noreference This method is not intended to be referenced by clients.
*/
public static Long win32_getHandle (Image image, int zoom) {
if(image.useDeviceZoom) {
zoom = DPIUtil.getZoomForAutoscaleProperty(zoom);
}
if(image.isDisposed()) {
return image.handle;
}
Expand All @@ -809,7 +820,7 @@ public static Long win32_getHandle (Image image, int zoom) {
image.init(newData, zoom);
}
} else if (image.imageDataProvider != null) {
ElementAtZoom<ImageData> imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, zoom);
ElementAtZoom<ImageData> imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, image.getZoom());
ImageData resizedData = DPIUtil.scaleImageData (image.device, imageCandidate.element(), zoom, imageCandidate.zoom());
ImageData newData = image.adaptImageDataIfDisabledOrGray(resizedData);
image.init(newData, zoom);
Expand Down Expand Up @@ -1008,6 +1019,9 @@ long initNative(String filename, int zoom) {
}

long [] createGdipImage(Integer zoom) {
if(useDeviceZoom) {
zoom = DPIUtil.getZoomForAutoscaleProperty(zoom);
}
long handle = Image.win32_getHandle(this, zoom);
switch (type) {
case SWT.BITMAP: {
Expand Down Expand Up @@ -1305,6 +1319,9 @@ public Rectangle getBounds() {
}

Rectangle getBounds(int zoom) {
if(useDeviceZoom) {
zoom = DPIUtil.getZoomForAutoscaleProperty(zoom);
}
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
// Read the bounds in pixels from native layer.
Rectangle bounds = getBoundsInPixelsFromNative();
Expand Down Expand Up @@ -1411,6 +1428,9 @@ public ImageData getImageData() {
* @since 3.106
*/
public ImageData getImageData (int zoom) {
if(useDeviceZoom) {
zoom = DPIUtil.getZoomForAutoscaleProperty(zoom);
}
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int currentZoom = getZoom();
if (zoom == currentZoom) {
Expand Down Expand Up @@ -2333,7 +2353,10 @@ public void setBackground(Color color) {
}

private int getZoom() {
return DPIUtil.getZoomForAutoscaleProperty(initialNativeZoom);
if(useDeviceZoom) {
return DPIUtil.getZoomForAutoscaleProperty(initialNativeZoom);
}
return initialNativeZoom;
}
/**
* Returns a string containing a concise, human-readable
Expand Down
Loading
Loading