@@ -360,15 +360,13 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
360
360
361
361
width += getTextPadding (item , state ) * 2 ;
362
362
363
- if (parent .showClose || item .showClose ) {
364
- if ((state & SWT .SELECTED ) != 0 || parent .showUnselectedClose ) {
365
- if (!applyLargeTextPadding (parent )) {
366
- if (width > 0 ) width += INTERNAL_SPACING ;
367
- } else {
368
- if (width > 0 ) width -= INTERNAL_SPACING ;
369
- }
370
- width += computeSize (PART_CLOSE_BUTTON , SWT .NONE , gc , SWT .DEFAULT , SWT .DEFAULT ).x ;
363
+ if (shouldDrawCloseIcon (item )) {
364
+ if (!applyLargeTextPadding (parent )) {
365
+ if (width > 0 ) width += INTERNAL_SPACING ;
366
+ } else {
367
+ if (width > 0 ) width -= INTERNAL_SPACING ;
371
368
}
369
+ width += computeSize (PART_CLOSE_BUTTON , SWT .NONE , gc , SWT .DEFAULT , SWT .DEFAULT ).x ;
372
370
}
373
371
}
374
372
break ;
@@ -379,6 +377,13 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
379
377
return new Point (width , height );
380
378
}
381
379
380
+ private boolean shouldDrawCloseIcon (CTabItem item ) {
381
+ CTabFolder folder = item .getParent ();
382
+ boolean showClose = folder .showClose || item .showClose ;
383
+ boolean isSelectedOrShowCloseForUnselected = (item .state & SWT .SELECTED ) != 0 || folder .showUnselectedClose ;
384
+ return showClose && isSelectedOrShowCloseForUnselected ;
385
+ }
386
+
382
387
/**
383
388
* Returns padding for the text of a tab when image is not available or is hidden.
384
389
*
@@ -1416,7 +1421,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
1416
1421
// draw Image
1417
1422
Rectangle trim = computeTrim (itemIndex , SWT .NONE , 0 , 0 , 0 , 0 );
1418
1423
int xDraw = x - trim .x ;
1419
- if (parent .single && ( parent . showClose || item . showClose )) xDraw += item .closeRect .width ;
1424
+ if (parent .single && shouldDrawCloseIcon ( item )) xDraw += item .closeRect .width ;
1420
1425
Image image = item .getImage ();
1421
1426
if (image != null && !image .isDisposed () && parent .showSelectedImage ) {
1422
1427
Rectangle imageBounds = image .getBounds ();
@@ -1469,7 +1474,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
1469
1474
gc .setBackground (orginalBackground );
1470
1475
}
1471
1476
}
1472
- if (parent . showClose || item . showClose ) drawClose (gc , item .closeRect , item .closeImageState );
1477
+ if (shouldDrawCloseIcon ( item ) ) drawClose (gc , item .closeRect , item .closeImageState );
1473
1478
}
1474
1479
}
1475
1480
@@ -1631,7 +1636,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
1631
1636
Rectangle imageBounds = image .getBounds ();
1632
1637
// only draw image if it won't overlap with close button
1633
1638
int maxImageWidth = x + width - xDraw - (trim .width + trim .x );
1634
- if (parent . showUnselectedClose && ( parent . showClose || item . showClose )) {
1639
+ if (shouldDrawCloseIcon ( item )) {
1635
1640
maxImageWidth -= item .closeRect .width + INTERNAL_SPACING ;
1636
1641
}
1637
1642
if (imageBounds .width < maxImageWidth ) {
@@ -1649,7 +1654,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
1649
1654
// draw Text
1650
1655
xDraw += getTextPadding (item , state );
1651
1656
int textWidth = x + width - xDraw - (trim .width + trim .x );
1652
- if (parent . showUnselectedClose && ( parent . showClose || item . showClose )) {
1657
+ if (shouldDrawCloseIcon ( item )) {
1653
1658
textWidth -= item .closeRect .width + INTERNAL_SPACING ;
1654
1659
}
1655
1660
if (textWidth > 0 ) {
@@ -1667,7 +1672,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
1667
1672
gc .setFont (gcFont );
1668
1673
}
1669
1674
// draw close
1670
- if (parent . showUnselectedClose && ( parent . showClose || item . showClose )) drawClose (gc , item .closeRect , item .closeImageState );
1675
+ if (shouldDrawCloseIcon ( item )) drawClose (gc , item .closeRect , item .closeImageState );
1671
1676
}
1672
1677
}
1673
1678
0 commit comments