@@ -473,10 +473,10 @@ void drawBackground(GC gc, Rectangle bounds, int state) {
473473 int [] percents = selected ? parent .selectionGradientPercents : parent .gradientPercents ;
474474 boolean vertical = selected ? parent .selectionGradientVertical : parent .gradientVertical ;
475475
476- drawBackground (gc , null , bounds .x , bounds .y , bounds .width , bounds .height , defaultBackground , image , colors , percents , vertical );
476+ drawBackground (gc , bounds .x , bounds .y , bounds .width , bounds .height , defaultBackground , image , colors , percents , vertical );
477477 }
478478
479- void drawBackground (GC gc , int [] shape , boolean selected ) {
479+ void drawBackground (GC gc , boolean selected ) {
480480 Color defaultBackground = selected && parent .shouldHighlight () ? parent .selectionBackground : parent .getBackground ();
481481 Image image = selected ? parent .selectionBgImage : null ;
482482 Color [] colors = selected && parent .shouldHighlight () ? parent .selectionGradientColors : parent .gradientColors ;
@@ -495,19 +495,10 @@ void drawBackground(GC gc, int[] shape, boolean selected) {
495495 x += 1 ; width -= 2 ;
496496 }
497497 int y = parent .onBottom ? size .y - borderBottom - height : borderTop ;
498- drawBackground (gc , shape , x , y , width , height , defaultBackground , image , colors , percents , vertical );
498+ drawBackground (gc , x , y , width , height , defaultBackground , image , colors , percents , vertical );
499499 }
500500
501- void drawBackground (GC gc , int [] shape , int x , int y , int width , int height , Color defaultBackground , Image image , Color [] colors , int [] percents , boolean vertical ) {
502- Region clipping = null , region = null ;
503- if (shape != null ) {
504- clipping = new Region ();
505- gc .getClipping (clipping );
506- region = new Region ();
507- region .add (shape );
508- region .intersect (clipping );
509- gc .setClipping (region );
510- }
501+ void drawBackground (GC gc , int x , int y , int width , int height , Color defaultBackground , Image image , Color [] colors , int [] percents , boolean vertical ) {
511502 if (image != null ) {
512503 // draw the background image in shape
513504 gc .setBackground (defaultBackground );
@@ -581,26 +572,12 @@ void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Col
581572 }
582573 }
583574 } else {
584- // draw a solid background using default background in shape
575+ // draw a solid background
585576 if ((parent .getStyle () & SWT .NO_BACKGROUND ) != 0 || !defaultBackground .equals (parent .getBackground ())) {
586577 gc .setBackground (defaultBackground );
587578 gc .fillRectangle (x , y , width , height );
588579 }
589580 }
590- if (shape != null ) {
591- gc .setClipping (clipping );
592- clipping .dispose ();
593- region .dispose ();
594- }
595- }
596-
597- /*
598- * Draw the border of the tab
599- */
600- void drawBorder (GC gc , int [] shape ) {
601-
602- gc .setForeground (parent .getDisplay ().getSystemColor (BORDER1_COLOR ));
603- gc .drawPolyline (shape );
604581 }
605582
606583 void drawBody (GC gc , Rectangle bounds , int state ) {
@@ -641,15 +618,8 @@ void drawBody(GC gc, Rectangle bounds, int state) {
641618 x2 -highlight_margin ,y2 -highlight_margin , x2 -highlight_margin ,y1 ,
642619 x2 ,y1 , x2 ,y2 , x1 ,y2 };
643620 }
644- // If horizontal gradient, show gradient across the whole area
645- if (selectedIndex != -1 && parent .selectionGradientColors != null && parent .selectionGradientColors .length > 1 && !parent .selectionGradientVertical ) {
646- drawBackground (gc , shape , true );
647- } else if (selectedIndex == -1 && parent .gradientColors != null && parent .gradientColors .length > 1 && !parent .gradientVertical ) {
648- drawBackground (gc , shape , false );
649- } else {
650- gc .setBackground (selectedIndex != -1 && parent .shouldHighlight () ? parent .selectionBackground : parent .getBackground ());
651- gc .fillPolygon (shape );
652- }
621+ gc .setBackground (selectedIndex != -1 && parent .shouldHighlight () ? parent .selectionBackground : parent .getBackground ());
622+ gc .fillPolygon (shape );
653623 }
654624 //Draw client area
655625 if ((parent .getStyle () & SWT .NO_BACKGROUND ) != 0 ) {
@@ -715,8 +685,7 @@ void drawClose(GC gc, Rectangle closeRect, int closeImageState) {
715685 break ;
716686 }
717687 case SWT .BACKGROUND : {
718- int [] shape = new int [] {x ,y , x +10 ,y , x +10 ,y +10 , x ,y +10 };
719- drawBackground (gc , shape , false );
688+ drawBackground (gc , x , y , 10 , 10 , parent .getBackground (), null , null , null , false );
720689 break ;
721690 }
722691 }
@@ -793,11 +762,10 @@ private void drawChevronContent(GC gc, int x, int y, String chevronString) {
793762 * Draw the unselected border for the receiver on the left.
794763 */
795764 void drawLeftUnselectedBorder (GC gc , Rectangle bounds , int state ) {
765+ gc .setForeground (parent .getDisplay ().getSystemColor (BORDER1_COLOR ));
796766 int x = bounds .x ;
797767 int y = bounds .y ;
798768 int height = bounds .height ;
799-
800- gc .setForeground (parent .getDisplay ().getSystemColor (BORDER1_COLOR ));
801769 if (parent .onBottom ) {
802770 gc .drawLine (x , y - 1 , x , y + height - 1 );
803771 } else {
@@ -908,11 +876,10 @@ void drawHighlight(GC gc, Rectangle bounds, int state, int rightEdge) {
908876 * Draw the unselected border for the receiver on the right.
909877 */
910878 void drawRightUnselectedBorder (GC gc , Rectangle bounds , int state ) {
879+ gc .setForeground (parent .getDisplay ().getSystemColor (BORDER1_COLOR ));
911880 int x = bounds .x + bounds .width - 1 ;
912881 int y = bounds .y ;
913882 int height = bounds .height ;
914-
915- gc .setForeground (parent .getDisplay ().getSystemColor (BORDER1_COLOR ));
916883 if (parent .onBottom ) {
917884 gc .drawLine (x , y + height - 1 , x , y - 1 );
918885 } else {
@@ -942,9 +909,8 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
942909 int yy = parent .onBottom ? size .y - borderBottom - parent .tabHeight - highlight_header : borderTop + parent .tabHeight + 1 ;
943910 int ww = size .x - borderLeft - borderRight ;
944911 int hh = highlight_header - 1 ;
945- int [] shape = new int [] {xx ,yy , xx +ww ,yy , xx +ww ,yy +hh , xx ,yy +hh };
946912 if (parent .selectionGradientColors != null && !parent .selectionGradientVertical ) {
947- drawBackground (gc , shape , parent .shouldHighlight ());
913+ drawBackground (gc , parent .shouldHighlight ());
948914 } else {
949915 gc .setBackground (parent .shouldHighlight () ? parent .selectionBackground : parent .getBackground ());
950916 gc .fillRectangle (xx , yy , ww , hh );
@@ -965,43 +931,19 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
965931 }
966932
967933 // draw selected tab background and outline
968- shape = new int [ 12 ] ;
934+ int [] shape = null ;
969935 if (parent .onBottom ) {
970- int index = 0 ;
971- shape [index ++] = x ; // first point repeated here because below we reuse shape to draw outline
972- shape [index ++] = y - 1 ;
973- shape [index ++] = x ;
974- shape [index ++] = y - 1 ;
975- shape [index ++] = x ;
976- shape [index ++] = y + height ;
977936 if (borderLeft == 0 && itemIndex == parent .firstIndex ) {
978- shape [index - 2 ] += x ;
979- shape [index - 1 ] += y + height ;
937+ shape = new int [] {x , y -1 , x , y +height , x , y +height , rightEdge -1 , y +height -1 , rightEdge -1 , y -1 , rightEdge -1 , y -1 };
938+ } else {
939+ shape = new int [] {x , y -1 , x , y -1 , x , y +height -1 , rightEdge -1 , y +height -1 , rightEdge -1 , y -1 , rightEdge -1 , y -1 };
980940 }
981- shape [index ++] = rightEdge - 1 ;
982- shape [index ++] = y + height - 1 ;
983- shape [index ++] = rightEdge - 1 ;
984- shape [index ++] = y - 1 ;
985- shape [index ++] = rightEdge - 1 ;
986- shape [index ++] = y - 1 ;
987941 } else {
988- int index = 0 ;
989- shape [index ++] = x ; // first point repeated here because below we reuse shape to draw outline
990- shape [index ++] = y + height + 1 ;
991- shape [index ++] = x ;
992- shape [index ++] = y + height + 1 ;
993- shape [index ++] = x ;
994- shape [index ++] = y ;
995942 if (borderLeft == 0 && itemIndex == parent .firstIndex ) {
996- shape [index - 2 ] += x ;
997- shape [index - 1 ] += y ;
943+ shape = new int [] {x , y +height +1 , x , y , x , y , rightEdge -1 , y , rightEdge -1 , y +height +1 , rightEdge -1 , y +height +1 };
944+ } else {
945+ shape = new int [] {x , y +height +1 , x , y +height +1 , x , y , rightEdge -1 , y , rightEdge -1 , y +height +1 , rightEdge -1 , y +height +1 };
998946 }
999- shape [index ++] = rightEdge - 1 ;
1000- shape [index ++] = y ;
1001- shape [index ++] = rightEdge - 1 ;
1002- shape [index ++] = y + height + 1 ;
1003- shape [index ++] = rightEdge - 1 ;
1004- shape [index ++] = y + height + 1 ;
1005947 }
1006948
1007949 Rectangle clipping = gc .getClipping ();
@@ -1013,18 +955,18 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
1013955 if (tabInPaint ) {
1014956 // fill in tab background
1015957 if (parent .selectionGradientColors != null && !parent .selectionGradientVertical ) {
1016- drawBackground (gc , shape , true );
958+ drawBackground (gc , true );
1017959 } else {
1018960 Color defaultBackground = parent .shouldHighlight () ? parent .selectionBackground : parent .getBackground ();
1019961 Image image = parent .selectionBgImage ;
1020962 Color [] colors = parent .selectionGradientColors ;
1021963 int [] percents = parent .selectionGradientPercents ;
1022964 boolean vertical = parent .selectionGradientVertical ;
1023965 xx = x ;
1024- yy = parent .onBottom ? y -1 : y + 1 ;
966+ yy = parent .onBottom ? y - 1 : y + 1 ;
1025967 ww = width ;
1026968 hh = height ;
1027- drawBackground (gc , shape , xx , yy , ww , hh , defaultBackground , image , colors , percents , vertical );
969+ drawBackground (gc , xx , yy , ww , hh , defaultBackground , image , colors , percents , vertical );
1028970 }
1029971 }
1030972
@@ -1158,9 +1100,9 @@ void drawTabArea(GC gc, Rectangle bounds, int state) {
11581100
11591101 // If horizontal gradient, show gradient across the whole area
11601102 if (selectedIndex != -1 && parent .selectionGradientColors != null && parent .selectionGradientColors .length > 1 && !parent .selectionGradientVertical ) {
1161- drawBackground (gc , shape , true );
1103+ drawBackground (gc , true );
11621104 } else if (selectedIndex == -1 && parent .gradientColors != null && parent .gradientColors .length > 1 && !parent .gradientVertical ) {
1163- drawBackground (gc , shape , false );
1105+ drawBackground (gc , false );
11641106 } else {
11651107 gc .setBackground (selectedIndex != -1 && parent .shouldHighlight () ? parent .selectionBackground : parent .getBackground ());
11661108 gc .fillPolygon (shape );
@@ -1178,44 +1120,18 @@ void drawTabArea(GC gc, Rectangle bounds, int state) {
11781120 int y = parent .onBottom ? size .y - borderBottom - tabHeight : borderTop ;
11791121 int width = size .x - borderLeft - borderRight + 1 ;
11801122 int height = tabHeight - 1 ;
1181- int [] shape = new int [ 8 ] ;
1123+ int [] shape ;
11821124 // Draw Tab Header
11831125 if (parent .onBottom ) {
1184- int index = 0 ;
1185- shape [index ++] = x ;
1186- shape [index ++] = y - highlight_header ;
1187- shape [index ++] = x ;
1188- shape [index ++] = y + height ;
1189- if (borderLeft == 0 )
1190- shape [index - 1 ] += 1 ;
1191- shape [index ++] = x + width ;
1192- shape [index ++] = y + height ;
1193- if (borderLeft == 0 )
1194- shape [index - 1 ] += 1 ;
1195- shape [index ++] = x + width ;
1196- shape [index ++] = y - highlight_header ;
1126+ int bottomY = y + height + (borderLeft == 0 ? 1 : 0 );
1127+ shape = new int [] {x , y -highlight_header , x , bottomY , x +width , bottomY , x +width , y -highlight_header };
11971128 } else {
1198- int index = 0 ;
1199- shape [index ++] = x ;
1200- shape [index ++] = y + height + highlight_header + 1 ;
1201- shape [index ++] = x ;
1202- shape [index ++] = y ;
1203- shape [index ++] = x + width ;
1204- shape [index ++] = y ;
1205- shape [index ++] = x + width ;
1206- shape [index ++] = y + height + highlight_header + 1 ;
1129+ shape = new int [] {x , y +height +highlight_header +1 , x , y , x +width , y , x +width , y +height +highlight_header +1 };
12071130 }
12081131 // Fill in background
12091132 boolean single = parent .single ;
12101133 boolean bkSelected = single && selectedIndex != -1 ;
1211- drawBackground (gc , shape , bkSelected );
1212- // Fill in parent background for non-rectangular shape
1213- Region r = new Region ();
1214- r .add (new Rectangle (x , y , width + 1 , height + 1 ));
1215- r .subtract (shape );
1216- gc .setBackground (parent .getParent ().getBackground ());
1217- fillRegion (gc , r );
1218- r .dispose ();
1134+ drawBackground (gc , bkSelected );
12191135
12201136 // Draw selected tab
12211137 if (selectedIndex == -1 ) {
@@ -1302,16 +1218,6 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
13021218 }
13031219 }
13041220
1305- void fillRegion (GC gc , Region region ) {
1306- // NOTE: region passed in to this function will be modified
1307- Region clipping = new Region ();
1308- gc .getClipping (clipping );
1309- region .intersect (clipping );
1310- gc .setClipping (region );
1311- gc .fillRectangle (region .getBounds ());
1312- gc .setClipping (clipping );
1313- clipping .dispose ();
1314- }
13151221
13161222 Color getFillColor () {
13171223 if (fillColor == null ) {
0 commit comments