diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
index ede046a4a1b..2bc6a7b9bc9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
@@ -196,6 +196,7 @@ public class CTabFolder extends Composite {
int[] gradientPercents;
boolean gradientVertical;
boolean showUnselectedImage = true;
+ boolean showSelectedImage = true;
// close, min/max and chevron buttons
boolean showClose = false;
@@ -1366,6 +1367,18 @@ public boolean getUnselectedImageVisible() {
checkWidget();
return showUnselectedImage;
}
+/**
+ * Returns true
if an image appears
+ * in selected tabs.
+ *
+ * @return true
if an image appears in selected tabs
+ *
+ * @since 3.125
+ */
+public boolean getSelectedImageVisible() {
+ checkWidget();
+ return showSelectedImage;
+}
/**
* Return the index of the specified tab or -1 if the tab is not
* in the receiver.
@@ -3693,6 +3706,25 @@ public void setUnselectedImageVisible(boolean visible) {
showUnselectedImage = visible;
updateFolder(REDRAW);
}
+/**
+ * Specify whether the image appears on selected tabs.
+ *
+ * @param visible true
makes the image appear
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @since 3.125
+ */
+public void setSelectedImageVisible(boolean visible) {
+ checkWidget();
+ if (showSelectedImage == visible) return;
+ // display image on selected items
+ showSelectedImage = visible;
+ updateFolder(REDRAW);
+}
/**
* Shows the item. If the item is already showing in the receiver,
* this method simply returns. Otherwise, the items are scrolled until
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java
index d310a3172d2..16d50b624f3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java
@@ -98,6 +98,7 @@ public class CTabFolderRenderer {
static final int ITEM_LEFT_MARGIN = 4;
static final int ITEM_RIGHT_MARGIN = 4;
static final int INTERNAL_SPACING = 4;
+ static final int TABS_WITHOUT_ICONS_PADDING = 14;
static final int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER;
static final String ELLIPSIS = "..."; //$NON-NLS-1$
private static final String CHEVRON_ELLIPSIS = "99+"; //$NON-NLS-1$
@@ -318,10 +319,11 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
Image image = item.getImage();
if (image != null && !image.isDisposed()) {
Rectangle bounds = image.getBounds();
- if ((state & SWT.SELECTED) != 0 || parent.showUnselectedImage) {
+ if (((state & SWT.SELECTED) != 0 && parent.showSelectedImage)
+ || ((state & SWT.SELECTED) == 0 && parent.showUnselectedImage)) {
width += bounds.width;
}
- height = bounds.height;
+ height = bounds.height;
}
String text = null;
if ((state & MINIMUM_SIZE) != 0) {
@@ -355,9 +357,17 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
gc.setFont(gcFont);
}
}
+
+ width += getTextPadding(item, state) * 2;
+
if (parent.showClose || item.showClose) {
if ((state & SWT.SELECTED) != 0 || parent.showUnselectedClose) {
- if (width > 0) width += INTERNAL_SPACING;
+ if (((state & SWT.SELECTED) != 0 && parent.showSelectedImage)
+ || ((state & SWT.SELECTED) == 0 && parent.showUnselectedImage)) {
+ if (width > 0) width += INTERNAL_SPACING;
+ } else {
+ if (width > 0) width -= INTERNAL_SPACING;
+ }
width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x;
}
}
@@ -370,6 +380,27 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
return new Point(width, height);
}
+ /**
+ * Returns padding for the text of a tab when image is not available or is hidden.
+ *
+ * @param item CTabItem
+ * @param state current state
+ *
+ */
+ private int getTextPadding(CTabItem item, int state) {
+ CTabFolder parent = item.getParent();
+ Image image = item.getImage();
+ String text = item.getText();
+
+ if (text != null && parent.getMinimumCharacters() != 0) {
+ if (image == null || image.isDisposed() || ((state & SWT.SELECTED) != 0 && !parent.showSelectedImage)
+ || ((state & SWT.SELECTED) == 0 && !parent.showUnselectedImage))
+ return TABS_WITHOUT_ICONS_PADDING;
+ }
+
+ return 0;
+ }
+
/**
* Given a desired client area for the part
* (as described by the arguments), returns the bounding
@@ -1385,7 +1416,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
int xDraw = x - trim.x;
if (parent.single && (parent.showClose || item.showClose)) xDraw += item.closeRect.width;
Image image = item.getImage();
- if (image != null && !image.isDisposed()) {
+ if (image != null && !image.isDisposed() && parent.showSelectedImage) {
Rectangle imageBounds = image.getBounds();
// only draw image if it won't overlap with close button
int maxImageWidth = rightEdge - xDraw - (trim.width + trim.x);
@@ -1400,6 +1431,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
}
// draw Text
+ xDraw += getTextPadding(item, state);
int textWidth = rightEdge - xDraw - (trim.width + trim.x);
if (!parent.single && item.closeRect.width > 0) textWidth -= item.closeRect.width + INTERNAL_SPACING;
if (textWidth > 0) {
@@ -1613,6 +1645,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
}
}
// draw Text
+ xDraw += getTextPadding(item, state);
int textWidth = x + width - xDraw - (trim.width + trim.x);
if (parent.showUnselectedClose && (parent.showClose || item.showClose)) {
textWidth -= item.closeRect.width + INTERNAL_SPACING;
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java
index 124c4e0a8fc..f4900529746 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java
@@ -468,6 +468,18 @@ public void test_iconWrappedOnNextLine() {
}
}
+@Test
+public void test_selectedImageVisible() {
+ createTabFolder(null);
+
+ ctabFolder.setSelectedImageVisible(true);
+ assertTrue(ctabFolder.getSelectedImageVisible());
+
+ ctabFolder.setSelectedImageVisible(false);
+ assertFalse(ctabFolder.getSelectedImageVisible());
+
+}
+
private void processEvents() {
Display display = shell.getDisplay();