Skip to content

Commit f5050ee

Browse files
Refactor Cursor handle to support per-zoom handles
- Removed the dedicated `handle` field from Cursor; all native handles are now stored in `zoomLevelToHandle`. - Updated hashCode, equals, isDisposed, and destroy to work with zoom-level handles.
1 parent d4c3036 commit f5050ee

File tree

1 file changed

+8
-25
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+8
-25
lines changed

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

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@
4949
*/
5050
public final class Cursor extends Resource {
5151

52-
/**
53-
* the handle to the OS cursor resource
54-
* (Warning: This field is platform dependent)
55-
* <p>
56-
* <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
57-
* public API. It is marked public only so that it can be shared
58-
* within the packages provided by SWT. It is not available on all
59-
* platforms and should never be accessed from application code.
60-
* </p>
61-
*
62-
*/
63-
private long handle;
6452
/**
6553
* Attribute to cache current native zoom level
6654
*/
@@ -70,6 +58,8 @@ public final class Cursor extends Resource {
7058

7159
private final CursorHandleProvider cursorHandleProvider;
7260

61+
private boolean isDestroyed;
62+
7363
/**
7464
* Constructs a new cursor given a device and a style
7565
* constant describing the desired cursor appearance.
@@ -119,7 +109,6 @@ public final class Cursor extends Resource {
119109
public Cursor(Device device, int style) {
120110
super(device);
121111
this.cursorHandleProvider = new StyleCursorHandleProvider(style);
122-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
123112
init();
124113
this.device.registerResourceWithZoomSupport(this);
125114
}
@@ -160,7 +149,6 @@ public Cursor(Device device, int style) {
160149
public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
161150
super(device);
162151
this.cursorHandleProvider = new ImageDataWithMaskCursorHandleProvider(source, mask, hotspotX, hotspotY);
163-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
164152
init();
165153
this.device.registerResourceWithZoomSupport(this);
166154
}
@@ -229,7 +217,6 @@ private static CursorHandle setupCursorFromImageData(ImageData source, ImageData
229217
public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
230218
super(device);
231219
this.cursorHandleProvider = new ImageDataCursorHandleProvider(source, hotspotX, hotspotY);
232-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
233220
init();
234221
this.device.registerResourceWithZoomSupport(this);
235222
}
@@ -341,7 +328,6 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
341328
super(device);
342329
if (imageDataProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
343330
this.cursorHandleProvider = new ImageDataProviderCursorHandleProvider(imageDataProvider, hotspotX, hotspotY);
344-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
345331
init();
346332
this.device.registerResourceWithZoomSupport(this);
347333
}
@@ -363,7 +349,7 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
363349
*/
364350
public static Long win32_getHandle (Cursor cursor, int zoom) {
365351
if (cursor.isDisposed()) {
366-
return cursor.handle;
352+
return 0L;
367353
}
368354
if (cursor.zoomLevelToHandle.get(zoom) != null) {
369355
return cursor.zoomLevelToHandle.get(zoom).getHandle();
@@ -376,9 +362,6 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
376362
}
377363

378364
private void setHandleForZoomLevel(CursorHandle handle, Integer zoom) {
379-
if (this.handle == 0) {
380-
this.handle = handle.getHandle(); // Set handle for default zoom level
381-
}
382365
if (zoom != null && !zoomLevelToHandle.containsKey(zoom)) {
383366
zoomLevelToHandle.put(zoom, handle);
384367
}
@@ -407,7 +390,7 @@ private void destroyHandle () {
407390
handle.destroy();
408391
}
409392
zoomLevelToHandle.clear();
410-
handle = 0;
393+
this.isDestroyed = true;
411394
}
412395

413396
/**
@@ -425,7 +408,7 @@ public boolean equals (Object object) {
425408
if (object == this) return true;
426409
if (!(object instanceof Cursor)) return false;
427410
Cursor cursor = (Cursor) object;
428-
return device == cursor.device && handle == cursor.handle;
411+
return device == cursor.device && win32_getHandle(this, DEFAULT_ZOOM) == win32_getHandle(cursor, DEFAULT_ZOOM);
429412
}
430413

431414
/**
@@ -440,7 +423,7 @@ public boolean equals (Object object) {
440423
*/
441424
@Override
442425
public int hashCode () {
443-
return (int)handle;
426+
return win32_getHandle(this, DEFAULT_ZOOM).intValue();
444427
}
445428

446429
/**
@@ -455,7 +438,7 @@ public int hashCode () {
455438
*/
456439
@Override
457440
public boolean isDisposed() {
458-
return handle == 0;
441+
return isDestroyed;
459442
}
460443

461444
/**
@@ -467,7 +450,7 @@ public boolean isDisposed() {
467450
@Override
468451
public String toString () {
469452
if (isDisposed()) return "Cursor {*DISPOSED*}";
470-
return "Cursor {" + handle + "}";
453+
return "Cursor {" + zoomLevelToHandle + "}";
471454
}
472455

473456
@Override

0 commit comments

Comments
 (0)