diff options
author | Bogdan Gheorghe <gheorghe> | 2010-03-04 19:38:24 +0000 |
---|---|---|
committer | Bogdan Gheorghe <gheorghe> | 2010-03-04 19:38:24 +0000 |
commit | 444917b413ab57ed5d6b6ade8c5b5c63d6e5c5c4 (patch) | |
tree | cfc79e5c33b630468b03a7a55dee10ff7f5876da | |
parent | f72c857e9c5ef7f08cd69b3c2eb92b3aafb02d91 (diff) | |
download | eclipse.platform.swt-444917b413ab57ed5d6b6ade8c5b5c63d6e5c5c4.tar.gz eclipse.platform.swt-444917b413ab57ed5d6b6ade8c5b5c63d6e5c5c4.tar.xz eclipse.platform.swt-444917b413ab57ed5d6b6ade8c5b5c63d6e5c5c4.zip |
CTabFolder javadoc
4 files changed, 144 insertions, 34 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java index 5da21fef39..7d5bf31390 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java @@ -763,9 +763,9 @@ public CTabFolderRenderer getRenderer() { int getRightItemEdge (GC gc){ Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_HEADER, SWT.NONE, 0, 0, 0, 0); int x = getSize().x - (trim.width + trim.x) - 3; //TODO: add setter for spacing? - if (showMin) x -= renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc).x; - if (showMax) x -= renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc).x; - if (showChevron) x -= renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc).x; + if (showMin) x -= renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; + if (showMax) x -= renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; + if (showChevron) x -= renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; if (topRight != null && topRightAlignment != SWT.FILL) { Point rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT); x -= rightSize.x + 3; @@ -2065,7 +2065,7 @@ void setButtonBounds(GC gc) { oldHeight = maxRect.height; maxRect.x = maxRect.y = maxRect.width = maxRect.height = 0; if (showMax) { - Point maxSize = renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc); + Point maxSize = renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT); maxRect.x = size.x - borderRight - maxSize.x - 3; if (borderRight > 0) maxRect.x += 1; maxRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - maxSize.y)/2: borderTop + (tabHeight - maxSize.y)/2; @@ -2087,7 +2087,7 @@ void setButtonBounds(GC gc) { oldHeight = minRect.height; minRect.x = minRect.y = minRect.width = minRect.height = 0; if (showMin) { - Point minSize = renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc); + Point minSize = renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT); minRect.x = size.x - borderRight - maxRect.width - minSize.x - 3; if (borderRight > 0) minRect.x += 1; minRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - minSize.y)/2: borderTop + (tabHeight - minSize.y)/2; @@ -2120,7 +2120,7 @@ void setButtonBounds(GC gc) { } else { // fill size is 0 if item compressed CTabItem item = items[selectedIndex]; - int chevronWidth = renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc).x; + int chevronWidth = renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; if (item.x + item.width + 7 + chevronWidth >= rightEdge) break; topRightRect.x = item.x + item.width + 7 + chevronWidth; topRightRect.width = rightEdge - topRightRect.x; @@ -2167,7 +2167,7 @@ void setButtonBounds(GC gc) { oldWidth = chevronRect.width; oldHeight = chevronRect.height; chevronRect.x = chevronRect.y = chevronRect.height = chevronRect.width = 0; - Point chevronSize = renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc); + Point chevronSize = renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT); if (single) { if (selectedIndex == -1 || items.length > 1) { chevronRect.width = chevronSize.x; @@ -2270,7 +2270,7 @@ boolean setItemLocation(GC gc) { int borderTop = -trim.y; Point size = getSize(); int y = onBottom ? Math.max(borderBottom, size.y - borderBottom - tabHeight) : borderTop; - Point closeButtonSize = renderer.computeSize(CTabFolderRenderer.PART_CLOSE_BUTTON, 0, gc); + Point closeButtonSize = renderer.computeSize(CTabFolderRenderer.PART_CLOSE_BUTTON, 0, gc, SWT.DEFAULT, SWT.DEFAULT); if (single) { int defaultX = getDisplay().getBounds().width + 10; // off screen for (int i = 0; i < items.length; i++) { @@ -2340,7 +2340,7 @@ boolean setItemSize(GC gc) { showChevron = true; if (selectedIndex != -1) { CTabItem tab = items[selectedIndex]; - int width = renderer.computeSize(selectedIndex, SWT.SELECTED, gc).x; + int width = renderer.computeSize(selectedIndex, SWT.SELECTED, gc, SWT.DEFAULT, SWT.DEFAULT).x; width = Math.min(width, getRightItemEdge(gc) - borderLeft); if (tab.height != tabHeight || tab.width != width) { changed = true; @@ -2350,7 +2350,7 @@ boolean setItemSize(GC gc) { tab.width = width; tab.closeRect.width = tab.closeRect.height = 0; if (showClose || tab.showClose) { - Point closeSize = renderer.computeSize(selectedIndex, SWT.SELECTED, gc); + Point closeSize = renderer.computeSize(selectedIndex, SWT.SELECTED, gc, SWT.DEFAULT, SWT.DEFAULT); tab.closeRect.width = closeSize.x; tab.closeRect.height = closeSize.y; } @@ -2363,8 +2363,8 @@ boolean setItemSize(GC gc) { int[] widths; int tabAreaWidth = size.x - borderLeft - borderRight - 3; - if (showMin) tabAreaWidth -= renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc).x; - if (showMax) tabAreaWidth -= renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc).x; + if (showMin) tabAreaWidth -= renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; + if (showMax) tabAreaWidth -= renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; if (topRightAlignment == SWT.RIGHT && topRight != null) { Point rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT, false); tabAreaWidth -= rightSize.x + 3; @@ -2378,14 +2378,14 @@ boolean setItemSize(GC gc) { int index = priority[i]; int state = CTabFolderRenderer.MINIMUM_SIZE; if (index == selectedIndex) state |= SWT.SELECTED; - minWidths[index] = renderer.computeSize(index, state, gc).x; + minWidths[index] = renderer.computeSize(index, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; minWidth += minWidths[index]; if (minWidth > tabAreaWidth) break; } if (minWidth > tabAreaWidth) { // full compression required and a chevron showChevron = items.length > 1; - if (showChevron) tabAreaWidth -= renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc).x; + if (showChevron) tabAreaWidth -= renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; widths = minWidths; int index = selectedIndex != -1 ? selectedIndex : 0; if (tabAreaWidth < widths[index]) { @@ -2397,7 +2397,7 @@ boolean setItemSize(GC gc) { for (int i = 0; i < items.length; i++) { int state = 0; if (i == selectedIndex) state |= SWT.SELECTED; - maxWidths[i] = renderer.computeSize(i, state, gc).x; + maxWidths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; maxWidth += maxWidths[i]; } if (maxWidth <= tabAreaWidth) { @@ -2442,7 +2442,7 @@ boolean setItemSize(GC gc) { tab.closeRect.width = tab.closeRect.height = 0; if (showClose || tab.showClose) { if (i == selectedIndex || showUnselectedClose) { - Point closeSize = renderer.computeSize(CTabFolderRenderer.PART_CLOSE_BUTTON, SWT.NONE, gc); + Point closeSize = renderer.computeSize(CTabFolderRenderer.PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT); tab.closeRect.width = closeSize.x; tab.closeRect.height = closeSize.y; } @@ -3269,7 +3269,7 @@ boolean updateItems(int showIndex) { for (int i = priority[0]; i <= showIndex; i++) { int state = CTabFolderRenderer.MINIMUM_SIZE; if (i == selectedIndex) state |= SWT.SELECTED; - widths[i] = renderer.computeSize(i, state, gc).x; + widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; width += widths[i]; if (width > maxWidth) break; } @@ -3278,7 +3278,7 @@ boolean updateItems(int showIndex) { for (int i = showIndex; i >= 0; i--) { int state = CTabFolderRenderer.MINIMUM_SIZE; if (i == selectedIndex) state |= SWT.SELECTED; - if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc).x; + if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; width += widths[i]; if (width > maxWidth) break; firstIndex = i; @@ -3288,7 +3288,7 @@ boolean updateItems(int showIndex) { for (int i = showIndex + 1; i < items.length; i++) { int state = CTabFolderRenderer.MINIMUM_SIZE; if (i == selectedIndex) state |= SWT.SELECTED; - widths[i] = renderer.computeSize(i, state, gc).x; + widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; width += widths[i]; if (width >= maxWidth) break; } @@ -3296,7 +3296,7 @@ boolean updateItems(int showIndex) { for (int i = priority[0] - 1; i >= 0; i--) { int state = CTabFolderRenderer.MINIMUM_SIZE; if (i == selectedIndex) state |= SWT.SELECTED; - if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc).x; + if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; width += widths[i]; if (width > maxWidth) break; firstIndex = i; @@ -3332,7 +3332,7 @@ boolean updateItems(int showIndex) { boolean updateTabHeight(boolean force){ int oldHeight = tabHeight; GC gc = new GC(this); - tabHeight = renderer.computeSize(CTabFolderRenderer.PART_HEADER, SWT.NONE, gc).y; + tabHeight = renderer.computeSize(CTabFolderRenderer.PART_HEADER, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).y; gc.dispose(); if (!force && tabHeight == oldHeight) return false; oldSize = null; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java index 2bba73a552..02b09c58fb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java @@ -31,18 +31,18 @@ protected Point computeSize(Composite composite, int wHint, int hHint, boolean f GC gc = new GC(folder); for (int i = 0; i < items.length; i++) { if (folder.single) { - tabW = Math.max(tabW, renderer.computeSize(i, SWT.SELECTED, gc).x); + tabW = Math.max(tabW, renderer.computeSize(i, SWT.SELECTED, gc, SWT.DEFAULT, SWT.DEFAULT).x); } else { int state = 0; if (i == selectedIndex) state |= SWT.SELECTED; - tabW += renderer.computeSize(i, state, gc).x; + tabW += renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x; } } tabW += 3; - if (folder.showMax) tabW += renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc).x; - if (folder.showMin) tabW += renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc).x; - if (folder.single) tabW += renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc).x; + if (folder.showMax) tabW += renderer.computeSize(CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; + if (folder.showMin) tabW += renderer.computeSize(CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; + if (folder.single) tabW += renderer.computeSize(CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; if (folder.topRight != null) { Point pt = folder.topRight.computeSize(SWT.DEFAULT, folder.tabHeight, flushCache); tabW += 3 + pt.x; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java index 46381efeda..68f2644851 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java @@ -15,10 +15,14 @@ import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; /** -* WARNING: API UNDER CONSTRUCTION -* -* @since 3.6 -*/ + * WARNING: API UNDER CONSTRUCTION + * Instances of this class provide all of the measuring and drawing functionality + * required by <code>CTabFolder</code>. This class can be subclassed in order to + * customize the look of a CTabFolder. + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * @since 3.6 + */ public class CTabFolderRenderer { protected CTabFolder parent; @@ -107,7 +111,22 @@ public class CTabFolderRenderer { public static final int MINIMUM_SIZE = 1 << 24; //TODO: Should this be a state? + + /** + * Constructs a new instance of this class given its parent. + * + * @param parent CTabFolder + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> + * </ul> + * + * @see Widget#getStyle + */ protected CTabFolderRenderer(CTabFolder parent) { + if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if (parent.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); this.parent = parent; int style = parent.getStyle(); highlight_header = (style & SWT.FLAT) != 0 ? 1 : 3; @@ -158,7 +177,38 @@ public class CTabFolderRenderer { } } - protected Point computeSize (int part, int state, GC gc) { + /** + * Returns the preferred size of the receiver. + * <p> + * The <em>preferred size</em> of a control is the size that it would + * best be displayed at. The width hint and height hint arguments + * allow the caller to ask a control questions such as "Given a particular + * width, how high does the control need to be to show all of the contents?" + * To indicate that the caller does not wish to constrain a particular + * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. + * </p><p> + * The <code>part</code> value indicated what component the preferred size is + * to be calculated for. Valid values are any of the part constants: + * <ul> + * <li>PART_BODY</li> <li>PART_HEADER</li> <li>PART_BORDER</li> + * <li>PART_BACKGROUND</li> <li>PART_MAX_BUTTON</li> + * <li>PART_MIN_BUTTON</li> <li>PART_CHEVRON_BUTTON</li> + * <li>PART_CLOSE_BUTTON</li> <li>an integer, greater than 0, which coincides + * with the CTabItem index.</li> + * </ul> + * + * </p> + * @param part a part constant + * @param state current state (can be <code>SWT.NONE</code> or <code>SWT.SELECTED</code> when + * passing in a CTabItem index to indicate a selected CTabIten) + * @param gc the gc of the receiver + * @param wHint the width hint (can be <code>SWT.DEFAULT</code>) + * @param hHint the height hint (can be <code>SWT.DEFAULT</code>) + * @return the preferred size of the control + * + * @since 3.6 + */ + protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) { int width = 0, height = 0; switch (part) { case PART_HEADER: @@ -170,7 +220,7 @@ public class CTabFolderRenderer { height = gc.textExtent("Default", FLAGS).y + ITEM_TOP_MARGIN + ITEM_BOTTOM_MARGIN; //$NON-NLS-1$ } else { for (int i=0; i < items.length; i++) { - height = Math.max(height, computeSize(i, SWT.NONE, gc).y); + height = Math.max(height, computeSize(i, SWT.NONE, gc, wHint, hHint).y); } } gc.dispose(); @@ -233,7 +283,7 @@ public class CTabFolderRenderer { if (parent.showClose || item.showClose) { if ((state & SWT.SELECTED) != 0 || parent.showUnselectedClose) { if (width > 0) width += INTERNAL_SPACING; - width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc).x; + width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; } } } @@ -245,6 +295,32 @@ public class CTabFolderRenderer { return new Point(width, height); } + /** + * Given a desired <em>client area</em> for the receiver + * (as described by the arguments), returns the bounding + * rectangle which would be required to produce that client + * area. + * <p> + * In other words, it returns a rectangle such that, if the + * receiver's bounds were set to that rectangle, the area + * of the receiver which is capable of displaying data + * (that is, not covered by the "trimmings") would be the + * rectangle described by the arguments (relative to the + * receiver's parent). + * </p> + * + * @param part one of the part constants + * @param state the state of the part + * @param x the desired x coordinate of the client area + * @param y the desired y coordinate of the client area + * @param width the desired width of the client area + * @param height the desired height of the client area + * @return the required bounds to produce the given client area + * + * @see CTabFolderRenderer#computeSize(int, int, GC, int, int) valid part values + * + * @since 3.6 + */ protected Rectangle computeTrim (int part, int state, int x, int y, int width, int height) { int borderLeft = parent.borderVisible ? 1 : 0; int borderRight = borderLeft; @@ -370,6 +446,13 @@ public class CTabFolderRenderer { } } + /** + * Dispose of any operating system resources associated with + * the renderer. Called by the CTabFolder parent upon receiving + * the dispose event. + * + * @since 3.6 + */ protected void dispose() { disposeAntialiasColors(); disposeSelectionHighlightGradientColors(); @@ -395,6 +478,33 @@ public class CTabFolderRenderer { selectionHighlightGradientColorsCache = null; } + /** + * Draw a specified part of the CTabFolder using the provided bounds and GC. + * <p>The valid CTabFolder part constants are: + * <ul> + * <li>PART_BODY - the entire body of the CTabFolder</li> + * <li>PART_HEADER - the upper tab area of the CTabFolder</li> + * <li>PART_BORDER - the border of the CTabFolder</li> + * <li>PART_BACKGROUND - the background of the CTabFolder</li> + * <li>PART_MAX_BUTTON</li> + * <li>PART_MIN_BUTTON</li> + * <li>PART_CHEVRON_BUTTON</li> + * <li>PART_CLOSE_BUTTON</li> + * <li>Some integer, greater than 0, which coincides with the CTabItem index.</li> + * </ul> + * </p> + * <p> + * The state flag is used to indicate whether the foreground, background or both is to be drawn and, in + * the case of drawing a CTabItem, whether that item is selected. + * </p> + * + * @param part part to draw (valid values listed above) + * @param state state of the part (can be any combination of SWT.BACKGROUND, SWT.FOREGROUND and SWT.SELECTED) + * @param bounds the bounds of the part + * @param gc the gc to draw the part on + * + * @since 3.6 + */ protected void draw (int part, int state, Rectangle bounds, GC gc) { switch (part) { case PART_BACKGROUND: diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java index e5b2eee2ad..d32dece69f 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java @@ -379,7 +379,7 @@ public void setImage (Image image) { if (selected) { GC gc = new GC(parent); if (parent.single && (parent.showClose || showClose)) { - imageX += renderer.computeSize(CTabFolderRenderer.PART_CLOSE_BUTTON, SWT.NONE, gc).x; + imageX += renderer.computeSize(CTabFolderRenderer.PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; } int rightEdge = Math.min (x + width, parent.getRightItemEdge(gc)); gc.dispose(); |