Skip to content

Commit

Permalink
Replaced the DPIUtil scale by scale with zoom call
Browse files Browse the repository at this point in the history
This commit replaces the DPIUtil calls from clients in win32 which are
still using DPIUtil autoScale calls, with scale calls utilizing the zoom
available within the clients.

contributes to #62 and #127
  • Loading branch information
amartya4256 authored and HeikoKlare committed Jul 23, 2024
1 parent 40b4fc6 commit c66545b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
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.autoScaleUp(parent.getClientArea()); // To Pixels
final Rectangle clientArea = DPIUtil.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(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 @@ -530,9 +530,10 @@ private void drag(Event dragEvent) {
*/
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
OS.RedrawWindow (topControl.handle, null, 0, flags);
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
POINT pt = new POINT ();
pt.x = DPIUtil.autoScaleUp(dragEvent.x);// To Pixels
pt.y = DPIUtil.autoScaleUp(dragEvent.y);// To Pixels
pt.x = DPIUtil.scaleUp(dragEvent.x, zoom);// To Pixels
pt.y = DPIUtil.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 @@ -281,8 +281,9 @@ 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) {
pt_x = DPIUtil.autoScaleDown(pt_x);// To Points
pt_y = DPIUtil.autoScaleDown(pt_y);// To Points
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points
selectedDataType = null;
selectedOperation = DND.DROP_NONE;
if (iDataObject != null) iDataObject.Release();
Expand Down Expand Up @@ -348,8 +349,9 @@ int DragOver_64(int grfKeyState, long pt, long pdwEffect) {
}

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

Expand Down Expand Up @@ -403,8 +405,9 @@ 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 {
pt_x = DPIUtil.autoScaleDown(pt_x);// To Points
pt_y = DPIUtil.autoScaleDown(pt_y);// To Points
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points
pt_y = DPIUtil.scaleDown(pt_y, zoom);// 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 @@ -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.autoScaleUp(table.toControl(coordinates)); // To Pixels
coordinates = DPIUtil.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 @@ -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.autoScaleUp(tree.toControl(coordinates)); // To Pixels
coordinates = DPIUtil.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.autoScaleUp(getClientArea()); // To Pixels
Rectangle area = DPIUtil.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.autoScaleUp(getSize()); // To Pixels
Point size = DPIUtil.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.autoScaleUp(getClientArea()); // To Pixels
Rectangle area = DPIUtil.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 @@ -1369,11 +1369,12 @@ void setBorderSpace(RECT newBorderwidth) {
setBounds();
}
void setBounds() {
Rectangle area = DPIUtil.autoScaleUp(frame.getClientArea()); // To Pixels
setBounds(DPIUtil.autoScaleDown(borderWidths.left),
DPIUtil.autoScaleDown(borderWidths.top),
DPIUtil.autoScaleDown(area.width - borderWidths.left - borderWidths.right),
DPIUtil.autoScaleDown(area.height - borderWidths.top - borderWidths.bottom));
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));
setObjectRects();
}
private void setExtent(int width, int height){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ long EnumFontFamProc (long lpelfe, long lpntme, long FontType, long lParam) {
*/
public Rectangle getBounds() {
checkDevice ();
return DPIUtil.autoScaleDown(getBoundsInPixels());
return DPIUtil.scaleDown(getBoundsInPixels(), getDeviceZoom());
}

private Rectangle getBoundsInPixels () {
Expand Down Expand Up @@ -514,7 +514,7 @@ public Point getDPI () {
int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
int dpiY = OS.GetDeviceCaps (hDC, OS.LOGPIXELSY);
internal_dispose_GC (hDC, null);
return DPIUtil.autoScaleDown(new Point (dpiX, dpiY));
return DPIUtil.scaleDown(new Point (dpiX, dpiY), getDeviceZoom());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ public final class Image extends Resource implements Drawable {
public Image(Device device, int width, int height) {
super(device);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
width = DPIUtil.autoScaleUp (width);
height = DPIUtil.autoScaleUp (height);
final int zoom = getZoom();
width = DPIUtil.scaleUp (width, zoom);
height = DPIUtil.scaleUp (height, zoom);
init(width, height);
init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class Widget {
*
* @noreference This field is not intended to be referenced by clients.
*/
protected int nativeZoom;
public int nativeZoom;
int style, state;
Display display;
EventTable eventTable;
Expand Down

0 comments on commit c66545b

Please sign in to comment.