Skip to content

Commit 75da5aa

Browse files
committed
CTabFolderRender: Factor out shared functionality related to close icon
1 parent 2cdfd97 commit 75da5aa

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,13 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
360360

361361
width += getTextPadding(item, state) * 2;
362362

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;
371368
}
369+
width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x;
372370
}
373371
}
374372
break;
@@ -379,6 +377,13 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
379377
return new Point(width, height);
380378
}
381379

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+
382387
/**
383388
* Returns padding for the text of a tab when image is not available or is hidden.
384389
*
@@ -1416,7 +1421,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
14161421
// draw Image
14171422
Rectangle trim = computeTrim(itemIndex, SWT.NONE, 0, 0, 0, 0);
14181423
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;
14201425
Image image = item.getImage();
14211426
if (image != null && !image.isDisposed() && parent.showSelectedImage) {
14221427
Rectangle imageBounds = image.getBounds();
@@ -1469,7 +1474,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
14691474
gc.setBackground(orginalBackground);
14701475
}
14711476
}
1472-
if (parent.showClose || item.showClose) drawClose(gc, item.closeRect, item.closeImageState);
1477+
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState);
14731478
}
14741479
}
14751480

@@ -1631,7 +1636,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
16311636
Rectangle imageBounds = image.getBounds();
16321637
// only draw image if it won't overlap with close button
16331638
int maxImageWidth = x + width - xDraw - (trim.width + trim.x);
1634-
if (parent.showUnselectedClose && (parent.showClose || item.showClose)) {
1639+
if (shouldDrawCloseIcon(item)) {
16351640
maxImageWidth -= item.closeRect.width + INTERNAL_SPACING;
16361641
}
16371642
if (imageBounds.width < maxImageWidth) {
@@ -1649,7 +1654,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
16491654
// draw Text
16501655
xDraw += getTextPadding(item, state);
16511656
int textWidth = x + width - xDraw - (trim.width + trim.x);
1652-
if (parent.showUnselectedClose && (parent.showClose || item.showClose)) {
1657+
if (shouldDrawCloseIcon(item)) {
16531658
textWidth -= item.closeRect.width + INTERNAL_SPACING;
16541659
}
16551660
if (textWidth > 0) {
@@ -1667,7 +1672,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
16671672
gc.setFont(gcFont);
16681673
}
16691674
// 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);
16711676
}
16721677
}
16731678

0 commit comments

Comments
 (0)