Skip to content

Commit 339f09d

Browse files
Initialization handles without creating a Cursor instance
In win32_getHandle, a new cursor instance is created to retrieve the OS handle. With this change, we are able to safely retrieve the handle without creating a cursor instance.
1 parent 9baef58 commit 339f09d

File tree

1 file changed

+5
-6
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+5
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
430430
if (cursor.zoomLevelToHandle.get(zoom) != null) {
431431
return cursor.zoomLevelToHandle.get(zoom);
432432
}
433-
434433
if (cursor.source == null) {
435434
cursor.setHandleForZoomLevel(cursor.handle, zoom);
436435
} else {
@@ -444,12 +443,12 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
444443
source = DPIUtil.scaleImageData(cursor.device, cursor.source, zoom, DEFAULT_ZOOM);
445444
}
446445
if (cursor.isIcon) {
447-
Cursor newCursor = new Cursor(cursor.device, source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
448-
cursor.setHandleForZoomLevel(newCursor.handle, zoom);
446+
long handle = setupCursorFromImageData(cursor.getDevice(), source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
447+
cursor.setHandleForZoomLevel(handle, zoom);
449448
} else {
450-
ImageData mask = DPIUtil.scaleImageData(cursor.device, cursor.mask, zoom, DEFAULT_ZOOM);
451-
Cursor newCursor = new Cursor(cursor.device, source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
452-
cursor.setHandleForZoomLevel(newCursor.handle, zoom);
449+
ImageData mask = DPIUtil.scaleImageData(cursor.getDevice(), cursor.mask, zoom, DEFAULT_ZOOM);
450+
long handle = setupCursorFromImageData(source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
451+
cursor.setHandleForZoomLevel(handle, zoom);
453452
}
454453
}
455454
return cursor.zoomLevelToHandle.get(zoom);

0 commit comments

Comments
 (0)