Skip to content

Commit 03cc46e

Browse files
HeikoKlareakoch-yatta
authored andcommitted
[Win32] Autoscale cursor even on widgets that have autoscaling disabled
Cursors are initialized with the zoom of the control on which they are set. However, cursors are usually expected to scale according to the autoscaled UI around those controls for which autoscaling was disabled. This change adapts the cursor initializations to use the autoscale zoom of the containing shell instead of the zoom of the control itself. In consequence, cursors will have the same size in the whole shell, no matter on which control they are set.
1 parent 55b5adf commit 03cc46e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ public void setData(String key, Object value) {
12831283
if (autoScaleDisabled) {
12841284
this.nativeZoom = 100;
12851285
} else {
1286-
this.nativeZoom = (int) getData(DATA_SHELL_ZOOM);
1286+
this.nativeZoom = getShellZoom();
12871287
}
12881288
}
12891289
}
@@ -4817,6 +4817,13 @@ int getZoom() {
48174817
return super.getZoom();
48184818
}
48194819

4820+
int getShellZoom() {
4821+
if (getData(DATA_SHELL_ZOOM) instanceof Integer shellZoom) {
4822+
return shellZoom;
4823+
}
4824+
return nativeZoom;
4825+
}
4826+
48204827
abstract TCHAR windowClass ();
48214828

48224829
abstract long windowProc ();
@@ -5503,7 +5510,7 @@ LRESULT WM_SETCURSOR (long wParam, long lParam) {
55035510
if (control == null) return null;
55045511
Cursor cursor = control.findCursor ();
55055512
if (cursor != null) {
5506-
OS.SetCursor (Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getNativeZoom())));
5513+
OS.SetCursor (Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getShellZoom())));
55075514
return LRESULT.ONE;
55085515
}
55095516
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ LRESULT WM_SETCURSOR (long wParam, long lParam) {
27192719
RECT rect = new RECT ();
27202720
OS.GetClientRect (handle, rect);
27212721
if (OS.PtInRect (rect, pt)) {
2722-
OS.SetCursor (Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getNativeZoom())));
2722+
OS.SetCursor (Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getShellZoom())));
27232723
switch (msg) {
27242724
case OS.WM_LBUTTONDOWN:
27252725
case OS.WM_RBUTTONDOWN:

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ public void setCursor(Cursor newCursor) {
823823
checkWidget();
824824
clientCursor = newCursor;
825825
if (newCursor != null) {
826-
if (inEvent) OS.SetCursor (Cursor.win32_getHandle(clientCursor, DPIUtil.getZoomForAutoscaleProperty(getNativeZoom())));
826+
if (inEvent) OS.SetCursor (Cursor.win32_getHandle(clientCursor, DPIUtil.getZoomForAutoscaleProperty(parent != null ? parent.getShellZoom() : getNativeZoom())));
827827
}
828828
}
829829

@@ -892,7 +892,7 @@ long transparentProc (long hwnd, long msg, long wParam, long lParam) {
892892
break;
893893
case OS.WM_SETCURSOR:
894894
if (clientCursor != null) {
895-
OS.SetCursor (Cursor.win32_getHandle(clientCursor, DPIUtil.getZoomForAutoscaleProperty(getNativeZoom())));
895+
OS.SetCursor (Cursor.win32_getHandle(clientCursor, DPIUtil.getZoomForAutoscaleProperty(parent != null ? parent.getShellZoom() : getNativeZoom())));
896896
return 1;
897897
}
898898
if (resizeCursor != 0) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4665,7 +4665,7 @@ void setCursor () {
46654665
* is IDC_ARROW.
46664666
*/
46674667
Cursor cursor = findCursor ();
4668-
long hCursor = cursor == null ? OS.LoadCursor (0, OS.IDC_ARROW) : Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getNativeZoom()));
4668+
long hCursor = cursor == null ? OS.LoadCursor (0, OS.IDC_ARROW) : Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getShellZoom()));
46694669
OS.SetCursor (hCursor);
46704670
}
46714671

0 commit comments

Comments
 (0)