@@ -514,19 +514,23 @@ private static interface CursorHandleProvider {
514
514
}
515
515
516
516
private static class StyleCursorHandleProvider implements CursorHandleProvider {
517
- private final int style ;
517
+ private final long lpCursorName ;
518
518
519
519
public StyleCursorHandleProvider (int style ) {
520
- this .style = style ;
520
+ this .lpCursorName = setupCursorFromStyle ( style ) ;
521
521
}
522
522
523
523
@ Override
524
524
public CursorHandle createHandle (Device device , int zoom ) {
525
525
// zoom ignored, LoadCursor handles scaling internally
526
- return setupCursorFromStyle (this .style );
526
+ long handle = OS .LoadCursor (0 , lpCursorName );
527
+ if (handle == 0 ) {
528
+ SWT .error (SWT .ERROR_NO_HANDLES );
529
+ }
530
+ return new CustomCursorHandle (handle );
527
531
}
528
532
529
- private static final CursorHandle setupCursorFromStyle (int style ) {
533
+ private static final long setupCursorFromStyle (int style ) {
530
534
long lpCursorName = 0 ;
531
535
switch (style ) {
532
536
case SWT .CURSOR_HAND :
@@ -598,11 +602,7 @@ private static final CursorHandle setupCursorFromStyle(int style) {
598
602
default :
599
603
SWT .error (SWT .ERROR_INVALID_ARGUMENT );
600
604
}
601
- long handle = OS .LoadCursor (0 , lpCursorName );
602
- if (handle == 0 ) {
603
- SWT .error (SWT .ERROR_NO_HANDLES );
604
- }
605
- return new CustomCursorHandle (handle );
605
+ return lpCursorName ;
606
606
}
607
607
}
608
608
@@ -629,6 +629,13 @@ private static class ImageDataProviderCursorHandleProvider extends HotspotAwareC
629
629
630
630
public ImageDataProviderCursorHandleProvider (ImageDataProvider provider , int hotspotX , int hotspotY ) {
631
631
super (hotspotX , hotspotY );
632
+ ImageData source = provider .getImageData (DEFAULT_ZOOM );
633
+ if (source == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
634
+ /* Check the hotspots */
635
+ if (hotspotX >= source .width || hotspotX < 0 ||
636
+ hotspotY >= source .height || hotspotY < 0 ) {
637
+ SWT .error (SWT .ERROR_INVALID_ARGUMENT );
638
+ }
632
639
this .provider = provider ;
633
640
}
634
641
@@ -651,6 +658,12 @@ private static class ImageDataCursorHandleProvider extends HotspotAwareCursorHan
651
658
652
659
public ImageDataCursorHandleProvider (ImageData source , int hotspotX , int hotspotY ) {
653
660
super (hotspotX , hotspotY );
661
+ if (source == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
662
+ /* Check the hotspots */
663
+ if (hotspotX >= source .width || hotspotX < 0 ||
664
+ hotspotY >= source .height || hotspotY < 0 ) {
665
+ SWT .error (SWT .ERROR_INVALID_ARGUMENT );
666
+ }
654
667
this .source = source ;
655
668
}
656
669
@@ -667,6 +680,16 @@ private static class ImageDataWithMaskCursorHandleProvider extends ImageDataCurs
667
680
668
681
public ImageDataWithMaskCursorHandleProvider (ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
669
682
super (source , hotspotX , hotspotY );
683
+ if (mask == null ) {
684
+ if (source .getTransparencyType () != SWT .TRANSPARENCY_MASK ) {
685
+ SWT .error (SWT .ERROR_NULL_ARGUMENT );
686
+ }
687
+ mask = source .getTransparencyMask ();
688
+ }
689
+ /* Check the bounds. Mask must be the same size as source */
690
+ if (mask .width != source .width || mask .height != source .height ) {
691
+ SWT .error (SWT .ERROR_INVALID_ARGUMENT );
692
+ }
670
693
this .mask = mask ;
671
694
}
672
695
0 commit comments