@@ -514,19 +514,23 @@ private static interface CursorHandleProvider {
514514}
515515
516516private static class StyleCursorHandleProvider implements CursorHandleProvider {
517- private final int style ;
517+ private final long lpCursorName ;
518518
519519 public StyleCursorHandleProvider (int style ) {
520- this .style = style ;
520+ this .lpCursorName = setupCursorFromStyle ( style ) ;
521521 }
522522
523523 @ Override
524524 public CursorHandle createHandle (Device device , int zoom ) {
525525 // 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 );
527531 }
528532
529- private static final CursorHandle setupCursorFromStyle (int style ) {
533+ private static final long setupCursorFromStyle (int style ) {
530534 long lpCursorName = 0 ;
531535 switch (style ) {
532536 case SWT .CURSOR_HAND :
@@ -598,11 +602,7 @@ private static final CursorHandle setupCursorFromStyle(int style) {
598602 default :
599603 SWT .error (SWT .ERROR_INVALID_ARGUMENT );
600604 }
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 ;
606606 }
607607}
608608
@@ -629,6 +629,13 @@ private static class ImageDataProviderCursorHandleProvider extends HotspotAwareC
629629
630630 public ImageDataProviderCursorHandleProvider (ImageDataProvider provider , int hotspotX , int hotspotY ) {
631631 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+ }
632639 this .provider = provider ;
633640 }
634641
@@ -651,6 +658,12 @@ private static class ImageDataCursorHandleProvider extends HotspotAwareCursorHan
651658
652659 public ImageDataCursorHandleProvider (ImageData source , int hotspotX , int hotspotY ) {
653660 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+ }
654667 this .source = source ;
655668 }
656669
@@ -667,6 +680,16 @@ private static class ImageDataWithMaskCursorHandleProvider extends ImageDataCurs
667680
668681 public ImageDataWithMaskCursorHandleProvider (ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
669682 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+ }
670693 this .mask = mask ;
671694 }
672695
0 commit comments