@@ -334,20 +334,31 @@ public long getHandle(int targetZoom) {
334
334
if (!zoomToHandle .containsKey (targetZoom )) {
335
335
int scaledWidth = DPIUtil .scaleUp (DPIUtil .scaleDown (width , this .zoom ), targetZoom );
336
336
int scaledHeight = DPIUtil .scaleUp (DPIUtil .scaleDown (height , this .zoom ), targetZoom );
337
- long handle = OS .ImageList_Create (scaledWidth , scaledHeight , flags , 16 , 16 );
338
- int count = OS .ImageList_GetImageCount (handle );
339
- for (int i = 0 ; i < images . length ; i ++) {
337
+ long newImageListHandle = OS .ImageList_Create (scaledWidth , scaledHeight , flags , 16 , 16 );
338
+ int count = OS .ImageList_GetImageCount (handle );
339
+ for (int i = 0 ; i < count ; i ++) {
340
340
Image image = images [i ];
341
341
if (image != null ) {
342
- set (i , image , count , handle , targetZoom );
343
- count ++;
342
+ set (i , image , i , newImageListHandle , targetZoom );
343
+ } else {
344
+ addPlaceholderImageToImageList (newImageListHandle , scaledWidth , scaledHeight );
344
345
}
345
346
}
346
- zoomToHandle .put (targetZoom , handle );
347
+ zoomToHandle .put (targetZoom , newImageListHandle );
347
348
}
348
349
return zoomToHandle .get (targetZoom );
349
350
}
350
351
352
+ private void addPlaceholderImageToImageList (long imageListHandle , int bitmapWidth , int bitmapHeight ) {
353
+ long hDC = OS .GetDC (0 );
354
+ if (hDC == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
355
+ long placeholderBitmapHandle = OS .CreateCompatibleBitmap (hDC , bitmapWidth , bitmapHeight );
356
+ if (placeholderBitmapHandle == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
357
+ OS .ImageList_Add (imageListHandle , placeholderBitmapHandle , placeholderBitmapHandle );
358
+ OS .DeleteObject (placeholderBitmapHandle );
359
+ OS .ReleaseDC (0 , hDC );
360
+ }
361
+
351
362
public Point getImageSize () {
352
363
int [] cx = new int [1 ], cy = new int [1 ];
353
364
OS .ImageList_GetIconSize (handle , cx , cy );
@@ -389,10 +400,10 @@ private void setForAllHandles(int index, Image image, int count) {
389
400
zoomToHandle .forEach ((zoom , handle ) -> set (index , image , count , handle , zoom ));
390
401
}
391
402
392
- void set (int index , Image image , int count , long handle , int zoom ) {
403
+ void set (int index , Image image , int count , long listHandle , int zoom ) {
393
404
long hImage = Image .win32_getHandle (image , zoom );
394
405
int [] cx = new int [1 ], cy = new int [1 ];
395
- OS .ImageList_GetIconSize (handle , cx , cy );
406
+ OS .ImageList_GetIconSize (listHandle , cx , cy );
396
407
switch (image .type ) {
397
408
case SWT .BITMAP : {
398
409
/*
@@ -443,18 +454,18 @@ void set (int index, Image image, int count, long handle, int zoom) {
443
454
break ;
444
455
}
445
456
if (index == count ) {
446
- OS .ImageList_Add (handle , hBitmap , hMask );
457
+ OS .ImageList_Add (listHandle , hBitmap , hMask );
447
458
} else {
448
459
/* Note that the mask must always be replaced even for TRANSPARENCY_NONE */
449
- OS .ImageList_Replace (handle , index , hBitmap , hMask );
460
+ OS .ImageList_Replace (listHandle , index , hBitmap , hMask );
450
461
}
451
462
if (hMask != 0 ) OS .DeleteObject (hMask );
452
463
if (hBitmap != hImage ) OS .DeleteObject (hBitmap );
453
464
break ;
454
465
}
455
466
case SWT .ICON : {
456
467
long hIcon = copyIcon (hImage , cx [0 ], cy [0 ]);
457
- OS .ImageList_ReplaceIcon (handle , index == count ? -1 : index , hIcon );
468
+ OS .ImageList_ReplaceIcon (listHandle , index == count ? -1 : index , hIcon );
458
469
OS .DestroyIcon (hIcon );
459
470
break ;
460
471
}
0 commit comments