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 committed Jul 17, 2024
1 parent 51e85e0 commit 03f5906
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 29 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(), 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 @@ -410,7 +410,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 @@ -517,7 +517,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,8 @@ 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);
width = DPIUtil.scaleUp (width, getZoom());
height = DPIUtil.scaleUp (height, getZoom());
init(width, height);
init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ private int getCheckboxTextOffset(long hdc) {
OS.GetThemePartSize(display.hButtonTheme(), hdc, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, null, OS.TS_TRUE, size);
result += size.cx;
} else {
result += DPIUtil.autoScaleUpUsingNativeDPI(13);
result += DPIUtil.scaleUp(13, nativeZoom);
}

// Windows uses half width of '0' as checkbox-to-text distance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) {
* NOTE: autoScaleUpUsingNativeDPI() is used to avoid problems
* with applications that disable automatic scaling.
*/
struct.itemWidth = DPIUtil.autoScaleUpUsingNativeDPI(5);
struct.itemWidth = DPIUtil.scaleUp(5, nativeZoom);
OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6915,7 +6915,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
* Sort indicator size needs to scale as per the Native Windows OS DPI level
* when header is custom drawn. For more details refer bug 537097.
*/
int leg = DPIUtil.autoScaleUpUsingNativeDPI(3);
int leg = DPIUtil.scaleUp(3, nativeZoom);
if (sortDirection == SWT.UP) {
OS.Polyline(nmcd.hdc, new int[] {center-leg, 1+leg, center+1, 0}, 2);
OS.Polyline(nmcd.hdc, new int[] {center+leg, 1+leg, center-1, 0}, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,7 @@ public void setTopItem (TreeItem item) {
* In a Tree without imageList, the indent also controls the chevron (glyph) size.
*/
private void calculateAndApplyIndentSize() {
int indent = DPIUtil.autoScaleUpUsingNativeDPI(DEFAULT_INDENT);
int indent = DPIUtil.scaleUp(DEFAULT_INDENT, nativeZoom);
OS.SendMessage(handle, OS.TVM_SETINDENT, indent, 0);
}

Expand Down Expand Up @@ -7884,7 +7884,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
* Sort indicator size needs to scale as per the Native Windows OS DPI level
* when header is custom drawn. For more details refer bug 537097.
*/
int leg = DPIUtil.autoScaleUpUsingNativeDPI(3);
int leg = DPIUtil.scaleUp(3, nativeZoom);
if (sortDirection == SWT.UP) {
OS.Polyline(nmcd.hdc, new int[] {center-leg, 1+leg, center+1, 0}, 2);
OS.Polyline(nmcd.hdc, new int[] {center+leg, 1+leg, center-1, 0}, 2);
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 03f5906

Please sign in to comment.