Skip to content

Refactor: Move Win32-specific DPI logic to Win32DPIUtils #2281

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 = Win32DPIUtils.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
EventQueue.invokeLater(() -> {
frame.setSize (clientArea.width, clientArea.height);
frame.validate ();
Expand Down Expand Up @@ -286,15 +286,14 @@ public static Shell new_Shell (final Display display, final Canvas parent) {
SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e);
}
if (handle == 0) SWT.error (SWT.ERROR_INVALID_ARGUMENT, null, " [peer not created]");

final Shell shell = Shell.win32_new (display, handle);
final ComponentListener listener = new ComponentAdapter () {
@Override
public void componentResized (ComponentEvent e) {
display.syncExec (() -> {
if (shell.isDisposed()) return;
Dimension dim = parent.getSize ();
shell.setSize(DPIUtil.autoScaleDown(new Point(dim.width, dim.height))); // To Points
shell.setSize(Win32DPIUtils.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,8 @@ int handleContextMenuRequested(long pView, long pArgs) {
// to PIXEL coordinates with the real native zoom value
// independent from the swt.autoScale property:
Point pt = new Point( //
DPIUtil.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
DPIUtil.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
Win32DPIUtils.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
Win32DPIUtils.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
// swt.autoScale property into account
// which is also later considered in Menu#setLocation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ void handleDOMEvent (OleEvent e) {
int screenY = pVarResult.getInt();
pVarResult.dispose();

Point position = DPIUtil.autoScaleDown(new Point(screenX, screenY)); // To Points
Point position = Win32DPIUtils.scaleDown(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
position = browser.getDisplay().map(null, browser, position);
newEvent.x = position.x; newEvent.y = position.y;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ int ShowContextMenu(int dwID, long ppt, long pcmdtReserved, long pdispReserved)
Event event = new Event();
POINT pt = new POINT();
OS.MoveMemory(pt, ppt, POINT.sizeof);
pt.x = DPIUtil.autoScaleDown(pt.x); // To Points
pt.y = DPIUtil.autoScaleDown(pt.y); // To Points
pt.x = DPIUtil.scaleDown(pt.x, DPIUtil.getDeviceZoom()); // To Points
pt.y = DPIUtil.scaleDown(pt.y, DPIUtil.getDeviceZoom()); // To Points
event.x = pt.x;
event.y = pt.y;
browser.notifyListeners(SWT.MenuDetect, event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private void drag(Event dragEvent) {
int offsetX = event.offsetX;
hwndDrag = topControl.handle;
if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) {
offsetX = DPIUtil.scaleUp(image.getBounds(), zoom).width - offsetX;
offsetX = Win32DPIUtils.scaleUp(image.getBounds(), zoom).width - offsetX;
RECT rect = new RECT ();
OS.GetClientRect (topControl.handle, rect);
hwndDrag = OS.CreateWindowEx (
Expand Down Expand Up @@ -538,8 +538,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 = Win32DPIUtils.scaleUp(dragEvent.x, zoom);// To Pixels
pt.y = Win32DPIUtils.scaleUp(dragEvent.y, zoom);// 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 @@ -410,7 +410,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
if (this.control == null) {
// If there is no control for context, the behavior remains as before
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.nativeZoom);
return DPIUtil.scaleDown(new Point(xInPixels, yInPixels), zoom);
return Win32DPIUtils.scaleDown(new Point(xInPixels, yInPixels), zoom);
}
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.control.nativeZoom);
// There is no API to convert absolute values in pixels to display relative
Expand All @@ -419,7 +419,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
POINT pt = new POINT ();
pt.x = xInPixels; pt.y = yInPixels;
OS.ScreenToClient (this.control.handle, pt);
Point p = DPIUtil.scaleDown(new Point (pt.x, pt.y), zoom);
Point p = Win32DPIUtils.scaleDown(new Point (pt.x, pt.y), zoom);
return this.control.toDisplay(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 Win32DPIUtils.AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(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 = Win32DPIUtils.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(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 @@ -16,7 +16,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 Win32DPIUtils.AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(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 = Win32DPIUtils.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(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 = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(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 = Win32DPIUtils.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(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 = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(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 @@ -1370,7 +1370,7 @@ void setBorderSpace(RECT newBorderwidth) {
}
void setBounds() {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
Rectangle area = DPIUtil.scaleUp(frame.getClientArea(), zoom); // To Pixels
Rectangle area = Win32DPIUtils.scaleUp(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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2609,35 +2609,36 @@ static void buildDitheredGradientChannel(int from, int to, int steps,
* @param redBits the number of significant red bits, 0 for palette modes
* @param greenBits the number of significant green bits, 0 for palette modes
* @param blueBits the number of significant blue bits, 0 for palette modes
* @param zoom the zoom of gc drawer used
*/
static void fillGradientRectangle(GC gc, Device device,
int x, int y, int width, int height, boolean vertical,
RGB fromRGB, RGB toRGB,
int redBits, int greenBits, int blueBits) {
int redBits, int greenBits, int blueBits, int zoom) {
/* Create the bitmap and tile it */
ImageData band = createGradientBand(width, height, vertical,
fromRGB, toRGB, redBits, greenBits, blueBits);
Image image = new Image(device, band);
if ((band.width == 1) || (band.height == 1)) {
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(band.height),
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(width),
DPIUtil.autoScaleDown(height));
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(band.height, zoom),
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(width, zoom),
DPIUtil.scaleDown(height, zoom));
} else {
if (vertical) {
for (int dx = 0; dx < width; dx += band.width) {
int blitWidth = width - dx;
if (blitWidth > band.width) blitWidth = band.width;
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(blitWidth), DPIUtil.autoScaleDown(band.height),
DPIUtil.autoScaleDown(dx + x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(blitWidth),
DPIUtil.autoScaleDown(band.height));
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(blitWidth, zoom), DPIUtil.scaleDown(band.height, zoom),
DPIUtil.scaleDown(dx + x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(blitWidth, zoom),
DPIUtil.scaleDown(band.height, zoom));
}
} else {
for (int dy = 0; dy < height; dy += band.height) {
int blitHeight = height - dy;
if (blitHeight > band.height) blitHeight = band.height;
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(blitHeight),
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(dy + y), DPIUtil.autoScaleDown(band.width),
DPIUtil.autoScaleDown(blitHeight));
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(blitHeight, zoom),
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(dy + y, zoom), DPIUtil.scaleDown(band.width, zoom),
DPIUtil.scaleDown(blitHeight, zoom));
}
}
}
Expand Down
Loading
Loading