@@ -135,6 +135,11 @@ public final class Cursor extends Resource {
135
135
*/
136
136
public Cursor (Device device , int style ) {
137
137
this (device );
138
+ this .handle = setupCursorFromStyle (style );
139
+ init ();
140
+ }
141
+
142
+ private static long setupCursorFromStyle (int style ) {
138
143
long lpCursorName = 0 ;
139
144
switch (style ) {
140
145
case SWT .CURSOR_HAND : lpCursorName = OS .IDC_HAND ; break ;
@@ -162,9 +167,9 @@ public Cursor(Device device, int style) {
162
167
default :
163
168
SWT .error (SWT .ERROR_INVALID_ARGUMENT );
164
169
}
165
- handle = OS .LoadCursor (0 , lpCursorName );
170
+ long handle = OS .LoadCursor (0 , lpCursorName );
166
171
if (handle == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
167
- init () ;
172
+ return handle ;
168
173
}
169
174
170
175
/**
@@ -207,6 +212,12 @@ public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int
207
212
this .hotspotX = hotspotX ;
208
213
this .hotspotY = hotspotY ;
209
214
this .imageDataProvider = null ;
215
+ this .handle = setupCursorFromImageData (source , mask , hotspotX , hotspotY );
216
+ init ();
217
+ this .device .registerResourceWithZoomSupport (this );
218
+ }
219
+
220
+ private static long setupCursorFromImageData (ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
210
221
if (source == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
211
222
if (mask == null ) {
212
223
if (source .getTransparencyType () != SWT .TRANSPARENCY_MASK ) {
@@ -233,10 +244,9 @@ public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int
233
244
234
245
/* Create the cursor */
235
246
long hInst = OS .GetModuleHandle (null );
236
- handle = OS .CreateCursor (hInst , hotspotX , hotspotY , source .width , source .height , sourceData , maskData );
247
+ long handle = OS .CreateCursor (hInst , hotspotX , hotspotY , source .width , source .height , sourceData , maskData );
237
248
if (handle == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
238
- init ();
239
- this .device .registerResourceWithZoomSupport (this );
249
+ return handle ;
240
250
}
241
251
242
252
/**
@@ -275,10 +285,13 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
275
285
this .hotspotX = hotspotX ;
276
286
this .hotspotY = hotspotY ;
277
287
this .imageDataProvider = null ;
278
- setupCursorFromImageData (source );
288
+ this .handle = setupCursorFromImageData (device , source , hotspotX , hotspotY );
289
+ isIcon = true ;
290
+ init ();
291
+ this .device .registerResourceWithZoomSupport (this );
279
292
}
280
293
281
- private void setupCursorFromImageData (ImageData source ) {
294
+ private static long setupCursorFromImageData (Device device , ImageData source , int hotspotX , int hotspotY ) {
282
295
if (source == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
283
296
/* Check the hotspots */
284
297
if (hotspotX >= source .width || hotspotX < 0 ||
@@ -333,7 +346,7 @@ private void setupCursorFromImageData(ImageData source) {
333
346
if (hMask == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
334
347
} else {
335
348
ImageData mask = source .getTransparencyMask ();
336
- long [] result = Image .initIcon (this . device , source , mask );
349
+ long [] result = Image .initIcon (device , source , mask );
337
350
hBitmap = result [0 ];
338
351
hMask = result [1 ];
339
352
}
@@ -344,13 +357,12 @@ private void setupCursorFromImageData(ImageData source) {
344
357
info .hbmMask = hMask ;
345
358
info .xHotspot = hotspotX ;
346
359
info .yHotspot = hotspotY ;
347
- handle = OS .CreateIconIndirect (info );
360
+ long handle = OS .CreateIconIndirect (info );
348
361
OS .DeleteObject (hBitmap );
349
362
OS .DeleteObject (hMask );
350
363
if (handle == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
351
- isIcon = true ;
352
- init ();
353
- this .device .registerResourceWithZoomSupport (this );
364
+
365
+ return handle ;
354
366
}
355
367
356
368
/**
@@ -390,7 +402,10 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
390
402
this .mask = null ;
391
403
this .hotspotX = hotspotX ;
392
404
this .hotspotY = hotspotY ;
393
- setupCursorFromImageData (this .source );
405
+ this .handle = setupCursorFromImageData (device , this .source , hotspotX , hotspotY );
406
+ isIcon = true ;
407
+ init ();
408
+ this .device .registerResourceWithZoomSupport (this );
394
409
}
395
410
396
411
/**
0 commit comments