int deadspace = parent.simple || parent.single ? 0 : parent.curveWidth - parent.curveIndent; int rightEdge = Math.min (x + width - deadspace, parent.getRightItemEdge());
int rightEdge = Math.min (x + width, parent.getRightItemEdge());
void drawSelected(GC gc ) {	Point size = parent.getSize();	int deadspace = parent.simple || parent.single ? 0 : parent.curveWidth - parent.curveIndent;	int rightEdge = Math.min (x + width - deadspace, parent.getRightItemEdge());		//	 Draw selection border across all tabs	int xx = parent.borderLeft;	int yy = parent.onBottom ? size.y - parent.borderBottom - parent.tabHeight - parent.highlight_header : parent.borderTop + parent.tabHeight + 1;	int ww = size.x - parent.borderLeft - parent.borderRight;	int hh = parent.highlight_header - 1;	int[] shape = new int[] {xx,yy, xx+ww,yy, xx+ww,yy+hh, xx,yy+hh};	parent.drawBackground(gc, shape, true);		if (parent.single) {		if (!isShowing()) return;	} else {		// if selected tab scrolled out of view or partially out of view		// just draw bottom line		if (!isShowing()){			int x1 = Math.max(0, parent.borderLeft - 1);			int y1 = (parent.onBottom) ? y - 1 : y + height;			int x2 = size.x - parent.borderRight;			gc.setForeground(CTabFolder.borderColor);			gc.drawLine(x1, y1, x2, y1);			return;		}					// draw selected tab background and outline		shape = null;		if (this.parent.onBottom) {			int[] left = parent.simple ? CTabFolder.SIMPLE_BOTTOM_LEFT_CORNER : CTabFolder.BOTTOM_LEFT_CORNER;			int[] right = parent.simple ? CTabFolder.SIMPLE_BOTTOM_RIGHT_CORNER : parent.curve;			shape = new int[left.length+right.length+8];			int index = 0;			shape[index++] = x; // first point repeated here because below we reuse shape to draw outline			shape[index++] = y - 1;			shape[index++] = x;			shape[index++] = y - 1;			for (int i = 0; i < left.length/2; i++) {				shape[index++] = x + left[2*i];				shape[index++] = y + height + left[2*i+1] - 1;			}			for (int i = 0; i < right.length/2; i++) {				shape[index++] = parent.simple ? rightEdge - 1 + right[2*i] : rightEdge - parent.curveIndent + right[2*i];				shape[index++] = parent.simple ? y + height + right[2*i+1] - 1 : y + right[2*i+1] - 2;			}			shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;			shape[index++] = y - 1;			shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;			shape[index++] = y - 1;		} else {			int[] left = parent.simple ? CTabFolder.SIMPLE_TOP_LEFT_CORNER : CTabFolder.TOP_LEFT_CORNER;			int[] right = parent.simple ? CTabFolder.SIMPLE_TOP_RIGHT_CORNER : parent.curve;			shape = new int[left.length+right.length+8];			int index = 0;			shape[index++] = x; // first point repeated here because below we reuse shape to draw outline			shape[index++] = y + height + 1;			shape[index++] = x;			shape[index++] = y + height + 1;			for (int i = 0; i < left.length/2; i++) {				shape[index++] = x + left[2*i];				shape[index++] = y + left[2*i+1];			}			for (int i = 0; i < right.length/2; i++) {				shape[index++] = parent.simple ? rightEdge - 1 + right[2*i] : rightEdge - parent.curveIndent + right[2*i];				shape[index++] = y + right[2*i+1];			}			shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;			shape[index++] = y + height + 1;			shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;			shape[index++] = y + height + 1;		}		parent.drawBackground(gc, shape, true);				// draw outline		shape[0] = Math.max(0, parent.borderLeft - 1);		shape[shape.length - 2] = size.x - parent.borderRight + 1;		for (int i = 0; i < shape.length/2; i++) {			if (shape[2*i + 1] == y + height + 1) shape[2*i + 1] -= 1;		}		RGB inside = parent.selectionBackground.getRGB();		if (parent.selectionBgImage != null || 		    (parent.selectionGradientColors != null && parent.selectionGradientColors.length > 1)) {		    inside = null;		}		RGB outside = parent.getBackground().getRGB();				if (parent.bgImage != null || 		    (parent.gradientColors != null && parent.gradientColors.length > 1)) {		    outside = null;		}		parent.antialias(shape, CTabFolder.borderColor.getRGB(), inside, outside, gc);		gc.setForeground(CTabFolder.borderColor);		gc.drawPolyline(shape);	}		// draw Image	int xDraw = x + LEFT_MARGIN;	if (parent.single && (parent.showClose || showClose)) xDraw += CTabFolder.BUTTON_SIZE; 	Image image = getImage();	if (image != null) {		Rectangle imageBounds = image.getBounds();		// only draw image if it won't overlap with close button		int maxImageWidth = rightEdge - xDraw - RIGHT_MARGIN;		if (!parent.single && closeRect.width > 0) maxImageWidth -= closeRect.width + INTERNAL_SPACING;		if (imageBounds.width < maxImageWidth) {			int imageX = xDraw;			int imageHeight = imageBounds.height;			int imageY = y + (height - imageHeight) / 2;			imageY += parent.onBottom ? -1 : 1;			int imageWidth = imageBounds.width * imageHeight / imageBounds.height;			gc.drawImage(image, 				         imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height,				         imageX, imageY, imageWidth, imageHeight);			xDraw += imageWidth + INTERNAL_SPACING;		}	}		// draw Text	int textWidth = rightEdge - xDraw - RIGHT_MARGIN;	if (!parent.single && closeRect.width > 0) textWidth -= closeRect.width + INTERNAL_SPACING;	if (textWidth > 0) {		Font gcFont = gc.getFont();		gc.setFont(font == null ? parent.getFont() : font);				if (shortenedText == null || shortenedTextWidth != textWidth) {			shortenedText = shortenText(gc, getText(), textWidth);			shortenedTextWidth = textWidth;		}		Point extent = gc.textExtent(shortenedText, FLAGS);			int textY = y + (height - extent.y) / 2;		textY += parent.onBottom ? -1 : 1;				gc.setForeground(parent.selectionForeground);		gc.drawText(shortenedText, xDraw, textY, FLAGS);		gc.setFont(gcFont);				// draw a Focus rectangle		if (parent.isFocusControl()) {			Display display = getDisplay();			if (parent.simple || parent.single) {				gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));				gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));				gc.drawFocus(xDraw-1, textY-1, extent.x+2, extent.y+2);			} else {				gc.setForeground(display.getSystemColor(CTabFolder.BUTTON_BORDER));				gc.drawLine(xDraw, textY+extent.y+1, xDraw+extent.x+1, textY+extent.y+1);			}		}	}	if (parent.showClose || showClose) drawClose(gc);}