@@ -878,44 +878,57 @@ void drawBody(GC gc, Rectangle bounds, int state) {
878
878
}
879
879
}
880
880
881
- void drawClose (GC gc , Rectangle closeRect , int closeImageState ) {
881
+ void drawClose (GC gc , Rectangle closeRect , int closeImageState , boolean showDirtyIndicator ) {
882
882
if (closeRect .width == 0 || closeRect .height == 0 ) return ;
883
883
884
- // draw X with length of this constant
885
- final int lineLength = 8 ;
886
- int x = closeRect .x + Math .max (1 , (closeRect .width -lineLength )/2 );
887
- int y = closeRect .y + Math .max (1 , (closeRect .height -lineLength )/2 );
888
- y += parent .onBottom ? -1 : 1 ;
889
884
int originalLineWidth = gc .getLineWidth ();
890
- Color originalForeground = gc .getForeground ();
891
- switch (closeImageState & (SWT .HOT | SWT .SELECTED | SWT .BACKGROUND )) {
892
- case SWT .NONE : {
893
- drawCloseLines (gc , x , y , lineLength , false );
894
- break ;
895
- }
896
- case SWT .HOT : {
897
- drawCloseLines (gc , x , y , lineLength , true );
898
- break ;
899
- }
900
- case SWT .SELECTED : {
901
- drawCloseLines (gc , x , y , lineLength , true );
902
- break ;
903
- }
904
- case SWT .BACKGROUND : {
905
- int [] shape = new int [] {x ,y , x +10 ,y , x +10 ,y +10 , x ,y +10 };
906
- drawBackground (gc , shape , false );
907
- break ;
908
- }
909
- }
910
- gc .setLineWidth (originalLineWidth );
911
- gc .setForeground (originalForeground );
885
+ int state = closeImageState & (SWT .HOT | SWT .SELECTED | SWT .BACKGROUND );
886
+ if (state == SWT .NONE ) {
887
+ if (showDirtyIndicator )
888
+ drawDirtyIndicator (gc , closeRect , false );
889
+ else
890
+ drawCloseButton (gc , closeRect , false );
891
+ } else if (state == SWT .HOT || state == SWT .SELECTED ) {
892
+ drawCloseButton (gc , closeRect , true );
893
+ } else if (state == SWT .BACKGROUND ) {
894
+ if (showDirtyIndicator )
895
+ drawDirtyIndicator (gc , closeRect , false );
896
+ else
897
+ drawBackground (gc , closeRect , SWT .BACKGROUND );
898
+ }
899
+ gc .setLineWidth (originalLineWidth );
900
+ }
901
+
902
+ private void drawDirtyIndicator (GC gc , Rectangle closeRect , boolean hot ) {
903
+ String DIRTY_INDICATOR = "●" ;
904
+
905
+ Point stringExtent = gc .stringExtent (DIRTY_INDICATOR );
906
+ int x = closeRect .x + (closeRect .width - stringExtent .x ) / 2 ;
907
+ int y = closeRect .y + (closeRect .height - stringExtent .y ) / 2 ;
908
+ gc .drawString (DIRTY_INDICATOR , x , y , true );
909
+ }
910
+
911
+ private void drawCloseBackground (GC gc , Rectangle closeRect , Color backgroundColor ) {
912
+ Color originalBackground = gc .getBackground ();
913
+ gc .setBackground (backgroundColor );
914
+ gc .setForeground (originalBackground );
915
+ gc .fillRoundRectangle (closeRect .x + 1 , closeRect .y + 2 , closeRect .width - 2 , closeRect .height - 2 , 4 , 4 );
916
+ gc .setBackground (originalBackground );
912
917
}
913
918
914
- private void drawCloseLines (GC gc , int x , int y , int lineLength , boolean hot ) {
919
+
920
+ private void drawCloseButton (GC gc , Rectangle closeRect , boolean hot ) {
915
921
if (hot ) {
916
- gc .setLineWidth (gc .getLineWidth () + 2 );
917
- gc .setForeground (getFillColor ());
922
+ drawCloseBackground (gc , closeRect , parent .getDisplay ().getSystemColor (SWT .COLOR_WIDGET_NORMAL_SHADOW ));
923
+ // gc.setLineWidth(gc.getLineWidth() + 2);
924
+ gc .setForeground (gc .getBackground ());
918
925
}
926
+ // draw X with length of this constant
927
+ final int lineLength = 9 ;
928
+ int x = closeRect .x + Math .max (1 , (closeRect .width -lineLength )/2 );
929
+ int y = closeRect .y + Math .max (1 , (closeRect .height -lineLength )/2 );
930
+ y += parent .onBottom ? -1 : 1 ;
931
+
919
932
gc .setLineCap (SWT .CAP_ROUND );
920
933
gc .drawLine (x , y , x + lineLength , y + lineLength );
921
934
gc .drawLine (x , y + lineLength , x + lineLength , y );
@@ -1464,7 +1477,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
1464
1477
gc .setBackground (orginalBackground );
1465
1478
}
1466
1479
}
1467
- if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState );
1480
+ if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState , item . showDirty );
1468
1481
}
1469
1482
}
1470
1483
@@ -1673,7 +1686,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
1673
1686
gc .setFont (gcFont );
1674
1687
}
1675
1688
// draw close
1676
- if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState );
1689
+ if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState , item . showDirty );
1677
1690
}
1678
1691
}
1679
1692
0 commit comments