@@ -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
0 commit comments