@@ -877,44 +877,59 @@ void drawBody(GC gc, Rectangle bounds, int state) {
877
877
}
878
878
}
879
879
880
- void drawClose (GC gc , Rectangle closeRect , int closeImageState ) {
880
+ void drawClose (GC gc , Rectangle closeRect , int closeImageState , boolean showDirtyIndicator ) {
881
881
if (closeRect .width == 0 || closeRect .height == 0 ) return ;
882
882
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 ;
888
883
int originalLineWidth = gc .getLineWidth ();
889
884
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 );
907
895
}
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 );
910
904
gc .setForeground (originalForeground );
911
905
}
912
906
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 ) {
914
922
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 ());
917
926
}
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
+
918
933
gc .setLineCap (SWT .CAP_ROUND );
919
934
gc .drawLine (x , y , x + lineLength , y + lineLength );
920
935
gc .drawLine (x , y + lineLength , x + lineLength , y );
@@ -1463,7 +1478,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
1463
1478
gc .setBackground (orginalBackground );
1464
1479
}
1465
1480
}
1466
- if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState );
1481
+ if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState , item . showDirty );
1467
1482
}
1468
1483
}
1469
1484
@@ -1672,7 +1687,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
1672
1687
gc .setFont (gcFont );
1673
1688
}
1674
1689
// draw close
1675
- if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState );
1690
+ if (shouldDrawCloseIcon (item )) drawClose (gc , item .closeRect , item .closeImageState , item . showDirty );
1676
1691
}
1677
1692
}
1678
1693
0 commit comments