Skip to content

Commit c05ab70

Browse files
committed
Change rendering of dirty indicator in tabs - using a square on close
1 parent 37b22fb commit c05ab70

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

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

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -877,44 +877,59 @@ void drawBody(GC gc, Rectangle bounds, int state) {
877877
}
878878
}
879879

880-
void drawClose(GC gc, Rectangle closeRect, int closeImageState) {
880+
void drawClose(GC gc, Rectangle closeRect, int closeImageState, boolean showDirtyIndicator) {
881881
if (closeRect.width == 0 || closeRect.height == 0) return;
882882

883-
// draw X with length of this constant
884-
final int lineLength = 8;
885-
int x = closeRect.x + Math.max(1, (closeRect.width-lineLength)/2);
886-
int y = closeRect.y + Math.max(1, (closeRect.height-lineLength)/2);
887-
y += parent.onBottom ? -1 : 1;
888883
int originalLineWidth = gc.getLineWidth();
889884
Color originalForeground = gc.getForeground();
890-
switch (closeImageState & (SWT.HOT | SWT.SELECTED | SWT.BACKGROUND)) {
891-
case SWT.NONE: {
892-
drawCloseLines(gc, x, y , lineLength, false);
893-
break;
894-
}
895-
case SWT.HOT: {
896-
drawCloseLines(gc, x, y , lineLength, true);
897-
break;
898-
}
899-
case SWT.SELECTED: {
900-
drawCloseLines(gc, x, y , lineLength, true);
901-
break;
902-
}
903-
case SWT.BACKGROUND: {
904-
int[] shape = new int[] {x,y, x+10,y, x+10,y+10, x,y+10};
905-
drawBackground(gc, shape, false);
906-
break;
885+
int state = closeImageState & (SWT.HOT | SWT.SELECTED | SWT.BACKGROUND);
886+
if (state == SWT.NONE) {
887+
if (showDirtyIndicator) drawDirtyIndicator(gc, closeRect, originalForeground, false);
888+
drawCloseButton(gc, closeRect, false);
889+
} else if (state == SWT.HOT || state == SWT.SELECTED) {
890+
if (showDirtyIndicator) {
891+
drawDirtyIndicator(gc, closeRect, originalForeground, true);
892+
drawCloseButton(gc, closeRect, false);
893+
} else {
894+
drawCloseButton(gc, closeRect, true);
907895
}
908-
}
909-
gc.setLineWidth(originalLineWidth);
896+
} else if (state == SWT.BACKGROUND) {
897+
if (showDirtyIndicator)
898+
drawDirtyIndicator(gc, closeRect, originalForeground, false);
899+
else
900+
drawBackground(gc, closeRect, SWT.BACKGROUND);
901+
902+
}
903+
gc.setLineWidth(originalLineWidth);
910904
gc.setForeground(originalForeground);
911905
}
912906

913-
private void drawCloseLines(GC gc, int x, int y, int lineLength, boolean hot) {
907+
private void drawDirtyIndicator(GC gc, Rectangle closeRect, Color originalForeground, boolean hot) {
908+
Color indicatorColor = hot ? getFillColor() : originalForeground;
909+
drawCloseBackground(gc, closeRect, indicatorColor);
910+
}
911+
912+
private void drawCloseBackground(GC gc, Rectangle closeRect, Color backgroundColor) {
913+
Color originalBackground = gc.getBackground();
914+
gc.setBackground(backgroundColor);
915+
gc.setForeground(originalBackground);
916+
gc.fillRoundRectangle(closeRect.x + 3, closeRect.y + 4, closeRect.width - 5, closeRect.height - 5, 4, 4);
917+
gc.setBackground(originalBackground);
918+
}
919+
920+
921+
private void drawCloseButton(GC gc, Rectangle closeRect, boolean hot) {
914922
if (hot) {
915-
gc.setLineWidth(gc.getLineWidth() + 2);
916-
gc.setForeground(getFillColor());
923+
drawCloseBackground(gc, closeRect, parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
924+
// gc.setLineWidth(gc.getLineWidth() + 2);
925+
gc.setForeground(gc.getBackground());
917926
}
927+
// draw X with length of this constant
928+
final int lineLength = 6;
929+
int x = closeRect.x + Math.max(1, (closeRect.width-lineLength)/2);
930+
int y = closeRect.y + Math.max(1, (closeRect.height-lineLength)/2);
931+
y += parent.onBottom ? -1 : 1;
932+
918933
gc.setLineCap(SWT.CAP_ROUND);
919934
gc.drawLine(x, y, x + lineLength, y + lineLength);
920935
gc.drawLine(x, y + lineLength, x + lineLength, y);
@@ -1463,7 +1478,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
14631478
gc.setBackground(orginalBackground);
14641479
}
14651480
}
1466-
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState);
1481+
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState, item.showDirty);
14671482
}
14681483
}
14691484

@@ -1672,7 +1687,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
16721687
gc.setFont(gcFont);
16731688
}
16741689
// draw close
1675-
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState);
1690+
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState, item.showDirty);
16761691
}
16771692
}
16781693

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class CTabItem extends Item {
5555
int closeImageState = SWT.BACKGROUND;
5656
int state = SWT.NONE;
5757
boolean showClose = false;
58+
boolean showDirty = false;
5859
boolean showing = false;
5960

6061
/**
@@ -276,6 +277,12 @@ public boolean getShowClose() {
276277
checkWidget();
277278
return showClose;
278279
}
280+
281+
public boolean getShowDirty() {
282+
checkWidget();
283+
return showClose;
284+
}
285+
279286
/**
280287
* Returns the receiver's tool tip text, or null if it has
281288
* not been set.
@@ -490,6 +497,14 @@ public void setShowClose(boolean close) {
490497
showClose = close;
491498
parent.updateFolder(CTabFolder.REDRAW_TABS);
492499
}
500+
501+
public void setShowDirty(boolean dirty) {
502+
checkWidget();
503+
if (showDirty == dirty) return;
504+
showDirty = dirty;
505+
parent.updateFolder(CTabFolder.REDRAW_TABS);
506+
}
507+
493508
/**
494509
* Sets the text to display on the tab.
495510
* A carriage return '\n' allows to display multi line text.

0 commit comments

Comments
 (0)