for (int i = 0; i < minWidths.length; i++) { minWidths[i] = items[i].preferredWidth(gc, i == selectedIndex, true); minWidth += minWidths[i];
for (int i = 0; i < priority.length; i++) { int index = priority[i]; minWidths[index] = items[index].preferredWidth(gc, index == selectedIndex, true); minWidth += minWidths[index]; if (mru && minWidth > tabAreaWidth) break;
boolean setItemSize() {	boolean changed = false;	if (isDisposed()) return changed;	showChevron = false;	Point size = getSize();	if (size.x <= 0 || size.y <= 0) return changed;	xClient = borderLeft + marginWidth + highlight_margin;	if (onBottom) {		yClient = borderTop + highlight_margin + marginHeight;	} else {		yClient = borderTop + tabHeight + highlight_header + marginHeight; 	}	if (single) {		showChevron = true;		if (selectedIndex != -1) {			CTabItem tab = items[selectedIndex];			GC gc = new GC(this);			int width = tab.preferredWidth(gc, true, false);			gc.dispose();			width = Math.min(width, getRightItemEdge() - borderLeft);			if (tab.height != tabHeight || tab.width != width) {				changed = true;				tab.shortenedText = null;				tab.shortenedTextWidth = 0;				tab.height = tabHeight;				tab.width = width;				tab.closeRect.width = tab.closeRect.height = 0;				if (showClose || tab.showClose) {					tab.closeRect.width = BUTTON_SIZE;					tab.closeRect.height = BUTTON_SIZE;				}			}		}		return changed;	}		if (items.length == 0) return changed;	int[] widths;	GC gc = new GC(this);	int tabAreaWidth = size.x - borderLeft - borderRight - 3;	if (showMin) tabAreaWidth -= BUTTON_SIZE;	if (showMax) tabAreaWidth -= BUTTON_SIZE;	if (topRightAlignment == SWT.RIGHT && topRight != null) {		Point rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);		tabAreaWidth -= rightSize.x + 3;	}	if (!simple) tabAreaWidth -= curveWidth - 2*curveIndent;	tabAreaWidth = Math.max(0, tabAreaWidth);		// First, try the minimum tab size at full compression.	int minWidth = 0;	int[] minWidths = new int[items.length];		for (int i = 0; i < minWidths.length; i++) {		minWidths[i] = items[i].preferredWidth(gc, i == selectedIndex, true);		minWidth += minWidths[i];	}	if (minWidth > tabAreaWidth) {		// full compression required and a chevron		showChevron = items.length > 1;		if (showChevron) tabAreaWidth -= 3*BUTTON_SIZE/2;		widths = minWidths;		int index = selectedIndex != -1 ? selectedIndex : 0;		if (tabAreaWidth < widths[index]) {			widths[index] = Math.max(0, tabAreaWidth);		}	} else {		int maxWidth = 0;		int[] maxWidths = new int[items.length];		for (int i = 0; i < items.length; i++) {			maxWidths[i] = items[i].preferredWidth(gc, i == selectedIndex, false);			maxWidth += maxWidths[i];		}		if (maxWidth <= tabAreaWidth) {			// no compression required			widths = maxWidths;		} else {			// determine compression for each item			int extra = (tabAreaWidth - minWidth) / items.length;			while (true) {				int large = 0, totalWidth = 0;				for (int i = 0 ; i < items.length; i++) {					if (maxWidths[i] > minWidths[i] + extra) {						totalWidth += minWidths[i] + extra;						large++;					} else {						totalWidth += maxWidths[i];					}				}				if (totalWidth >= tabAreaWidth) {					extra--;					break;				}				if (large == 0 || tabAreaWidth - totalWidth < large) break;				extra++;			}			widths = new int[items.length];			for (int i = 0; i < items.length; i++) {				widths[i] = Math.min(maxWidths[i], minWidths[i] + extra);			}		}	}	gc.dispose();	for (int i = 0; i < items.length; i++) {		CTabItem tab = items[i];		int width = widths[i];		if (tab.height != tabHeight || tab.width != width) {			changed = true;			tab.shortenedText = null;			tab.shortenedTextWidth = 0;			tab.height = tabHeight;			tab.width = width;			tab.closeRect.width = tab.closeRect.height = 0;			if (showClose || tab.showClose) {				if (i == selectedIndex || showUnselectedClose) {					tab.closeRect.width = BUTTON_SIZE;					tab.closeRect.height = BUTTON_SIZE;				}			}		}	}	return changed;}