49
49
*/
50
50
public final class Cursor extends Resource {
51
51
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 ;
64
52
/**
65
53
* Attribute to cache current native zoom level
66
54
*/
@@ -70,6 +58,8 @@ public final class Cursor extends Resource {
70
58
71
59
private final CursorHandleProvider cursorHandleProvider ;
72
60
61
+ private boolean isDestroyed ;
62
+
73
63
/**
74
64
* Constructs a new cursor given a device and a style
75
65
* constant describing the desired cursor appearance.
@@ -119,7 +109,6 @@ public final class Cursor extends Resource {
119
109
public Cursor (Device device , int style ) {
120
110
super (device );
121
111
this .cursorHandleProvider = new StyleCursorHandleProvider (style );
122
- this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM ).getHandle ();
123
112
init ();
124
113
this .device .registerResourceWithZoomSupport (this );
125
114
}
@@ -160,7 +149,6 @@ public Cursor(Device device, int style) {
160
149
public Cursor (Device device , ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
161
150
super (device );
162
151
this .cursorHandleProvider = new ImageDataWithMaskCursorHandleProvider (source , mask , hotspotX , hotspotY );
163
- this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM ).getHandle ();
164
152
init ();
165
153
this .device .registerResourceWithZoomSupport (this );
166
154
}
@@ -229,7 +217,6 @@ private static CursorHandle setupCursorFromImageData(ImageData source, ImageData
229
217
public Cursor (Device device , ImageData source , int hotspotX , int hotspotY ) {
230
218
super (device );
231
219
this .cursorHandleProvider = new ImageDataCursorHandleProvider (source , hotspotX , hotspotY );
232
- this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM ).getHandle ();
233
220
init ();
234
221
this .device .registerResourceWithZoomSupport (this );
235
222
}
@@ -341,7 +328,6 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
341
328
super (device );
342
329
if (imageDataProvider == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
343
330
this .cursorHandleProvider = new ImageDataProviderCursorHandleProvider (imageDataProvider , hotspotX , hotspotY );
344
- this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM ).getHandle ();
345
331
init ();
346
332
this .device .registerResourceWithZoomSupport (this );
347
333
}
@@ -363,7 +349,7 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
363
349
*/
364
350
public static Long win32_getHandle (Cursor cursor , int zoom ) {
365
351
if (cursor .isDisposed ()) {
366
- return cursor . handle ;
352
+ return 0L ;
367
353
}
368
354
if (cursor .zoomLevelToHandle .get (zoom ) != null ) {
369
355
return cursor .zoomLevelToHandle .get (zoom ).getHandle ();
@@ -376,9 +362,6 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
376
362
}
377
363
378
364
private void setHandleForZoomLevel (CursorHandle handle , Integer zoom ) {
379
- if (this .handle == 0 ) {
380
- this .handle = handle .getHandle (); // Set handle for default zoom level
381
- }
382
365
if (zoom != null && !zoomLevelToHandle .containsKey (zoom )) {
383
366
zoomLevelToHandle .put (zoom , handle );
384
367
}
@@ -407,7 +390,7 @@ private void destroyHandle () {
407
390
handle .destroy ();
408
391
}
409
392
zoomLevelToHandle .clear ();
410
- handle = 0 ;
393
+ this . isDestroyed = true ;
411
394
}
412
395
413
396
/**
@@ -425,7 +408,7 @@ public boolean equals (Object object) {
425
408
if (object == this ) return true ;
426
409
if (!(object instanceof Cursor )) return false ;
427
410
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 ) ;
429
412
}
430
413
431
414
/**
@@ -440,7 +423,7 @@ public boolean equals (Object object) {
440
423
*/
441
424
@ Override
442
425
public int hashCode () {
443
- return ( int ) handle ;
426
+ return win32_getHandle ( this , DEFAULT_ZOOM ). intValue () ;
444
427
}
445
428
446
429
/**
@@ -455,7 +438,7 @@ public int hashCode () {
455
438
*/
456
439
@ Override
457
440
public boolean isDisposed () {
458
- return handle == 0 ;
441
+ return isDestroyed ;
459
442
}
460
443
461
444
/**
@@ -467,7 +450,7 @@ public boolean isDisposed() {
467
450
@ Override
468
451
public String toString () {
469
452
if (isDisposed ()) return "Cursor {*DISPOSED*}" ;
470
- return "Cursor {" + handle + "}" ;
453
+ return "Cursor {" + zoomLevelToHandle + "}" ;
471
454
}
472
455
473
456
@ Override
0 commit comments