From a22dc50286ff5b97c74cd0b12653f08fe95a1ee7 Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Fri, 27 Apr 2012 21:56:36 -0400 Subject: Bug 377980 - Move org.eclipse.e4.ui.widgets.CTabFolder back to SWT --- .../common/org/eclipse/swt/custom/CTabFolder.java | 1308 ++++++++++++++------ .../org/eclipse/swt/custom/CTabFolderLayout.java | 47 +- .../org/eclipse/swt/custom/CTabFolderRenderer.java | 84 +- 3 files changed, 976 insertions(+), 463 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 27413a2f50..1be6bab776 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -148,24 +148,35 @@ public class CTabFolder extends Composite { boolean showClose = false; boolean showUnselectedClose = true; - Rectangle chevronRect = new Rectangle(0, 0, 0, 0); - int chevronImageState = SWT.NONE; - boolean showChevron = false; - Menu showMenu; - boolean showMin = false; - Rectangle minRect = new Rectangle(0, 0, 0, 0); boolean minimized = false; - int minImageState = SWT.NONE; - boolean showMax = false; - Rectangle maxRect = new Rectangle(0, 0, 0, 0); boolean maximized = false; - int maxImageState = SWT.NONE; + ToolBar minMaxTb; + ToolItem maxItem; + ToolItem minItem; + Image maxImage; + Image minImage; + boolean hoverTb; + Rectangle hoverRect = new Rectangle(0,0,0,0); + boolean hovering; + boolean hoverTimerRunning; + + boolean showChevron = false; + Menu showMenu; + ToolBar chevronTb; + ToolItem chevronItem; + Image chevronImage; + int chevronCount; + boolean chevronVisible = true; Control topRight; - Rectangle topRightRect = new Rectangle(0, 0, 0, 0); int topRightAlignment = SWT.RIGHT; + boolean ignoreResize; + Control[] controls; + int[] controlAlignments; + Rectangle[] controlRects; + Image[] controlBkImages; // when disposing CTabFolder, don't try to layout the items or // change the selection as each child is destroyed. @@ -186,10 +197,8 @@ public class CTabFolder extends Composite { static final int FOREGROUND = SWT.COLOR_WIDGET_FOREGROUND; static final int BACKGROUND = SWT.COLOR_WIDGET_BACKGROUND; - static final int CHEVRON_CHILD_ID = 0; - static final int MINIMIZE_CHILD_ID = 1; - static final int MAXIMIZE_CHILD_ID = 2; - static final int EXTRA_CHILD_ID_COUNT = 3; + //TODO: add setter for spacing? + static final int SPACING = 3; /** * Constructs a new instance of this class given its parent @@ -242,6 +251,10 @@ void init(int style) { selectionForeground = display.getSystemColor(SELECTION_FOREGROUND); selectionBackground = display.getSystemColor(SELECTION_BACKGROUND); renderer = new CTabFolderRenderer(this); + controls = new Control[0]; + controlAlignments = new int[0]; + controlRects = new Rectangle[0]; + controlBkImages = new Image[0]; updateTabHeight(false); // Add all listeners @@ -257,11 +270,13 @@ void init(int style) { case SWT.MouseDown: onMouse(event); break; case SWT.MouseEnter: onMouse(event); break; case SWT.MouseExit: onMouse(event); break; + case SWT.MouseHover: onMouse(event); break; case SWT.MouseMove: onMouse(event); break; case SWT.MouseUp: onMouse(event); break; case SWT.Paint: onPaint(event); break; - case SWT.Resize: onResize(); break; + case SWT.Resize: onResize(event); break; case SWT.Traverse: onTraverse(event); break; + case SWT.Selection: onSelection(event); break; } } }; @@ -276,6 +291,7 @@ void init(int style) { SWT.MouseDown, SWT.MouseEnter, SWT.MouseExit, + SWT.MouseHover, SWT.MouseMove, SWT.MouseUp, SWT.Paint, @@ -413,6 +429,187 @@ public void addSelectionListener(SelectionListener listener) { addListener(SWT.DefaultSelection, typedListener); } +Rectangle[] computeControlBounds (Point size, boolean[][] position) { + if (controls == null || controls.length == 0) return new Rectangle[0]; + Rectangle[] rects = new Rectangle[controls.length]; + for (int i = 0; i < rects.length; i++) { + rects[i] = new Rectangle(0, 0, 0, 0); + } + Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BORDER, SWT.NONE, 0, 0, 0, 0); + int borderRight = trim.width + trim.x; + int borderLeft = -trim.x; + int borderBottom = trim.height + trim.y; + int borderTop = -trim.y; + + Point[] tabControlSize = new Point[controls.length]; + boolean[] overflow = new boolean [controls.length]; + //Left Control + int leftWidth = 0; + int x = borderLeft + SPACING; + int rightWidth = 0; + int allWidth = 0; + for (int i = 0; i < controls.length; i++) { + Point ctrlSize = tabControlSize[i] = controls[i].getVisible() ? controls[i].computeSize(SWT.DEFAULT, SWT.DEFAULT) : new Point(0,0); + int alignment = controlAlignments[i]; + if ((alignment & SWT.LEAD) != 0) { + rects[i].width = ctrlSize.x; + rects[i].height = getControlHeight(ctrlSize); + rects[i].x = x; + rects[i].y = getControlY(size, rects, borderBottom, borderTop, i); + x += ctrlSize.x; + leftWidth += ctrlSize.x; + } else { + if ((alignment & (SWT.FILL | SWT.WRAP)) == 0) { + rightWidth += ctrlSize.x; + } + allWidth += ctrlSize.x; + } + } + if (leftWidth > 0) leftWidth += SPACING * 2; + + int itemWidth = 0; + for (int i = 0; i < items.length; i++) { + if (items[i].showing) itemWidth += items[i].width; + } + + int maxWidth = size.x - borderLeft - leftWidth - borderRight; + int availableWidth = Math.max(0, maxWidth - itemWidth - rightWidth); + if (rightWidth > 0) availableWidth -= SPACING * 2; + x = size.x - borderRight - SPACING; + if (itemWidth + allWidth <= maxWidth) { + //Everything fits + for (int i = 0; i < controls.length; i++) { + int alignment = controlAlignments[i]; + if ((alignment & SWT.TRAIL) != 0) { + Point ctrlSize = tabControlSize[i]; + x -= ctrlSize.x; + rects[i].width = ctrlSize.x; + rects[i].height = getControlHeight(ctrlSize); + rects[i].x = x; + rects[i].y = getControlY(size, rects, borderBottom, borderTop, i); + if ((alignment & (SWT.FILL | SWT.WRAP)) != 0) availableWidth -= ctrlSize.x; + } + } + } else { + for (int i = 0; i < controls.length; i++) { + int alignment = controlAlignments[i]; + Point ctrlSize = tabControlSize[i]; + if ((alignment & SWT.TRAIL) != 0) { + if ((alignment & (SWT.FILL | SWT.WRAP)) == 0) { + x -= ctrlSize.x; + rects[i].width = ctrlSize.x; + rects[i].height = getControlHeight(ctrlSize); + rects[i].x = x; + rects[i].y = getControlY(size, rects, borderBottom, borderTop, i); + } else if (((alignment & (SWT.WRAP)) != 0 && ctrlSize.x < availableWidth)) { + x -= ctrlSize.x; + rects[i].width = ctrlSize.x; + rects[i].height = getControlHeight(ctrlSize); + rects[i].x = x; + rects[i].y = getControlY(size, rects, borderBottom, borderTop, i); + availableWidth -= ctrlSize.x; + } else if ((alignment & (SWT.FILL)) != 0 && (alignment & (SWT.WRAP)) == 0) { + rects[i].width = 0; + rects[i].height = getControlHeight(ctrlSize); + rects[i].x = x; + rects[i].y = getControlY(size, rects, borderBottom, borderTop, i); + } else { + if ((alignment & (SWT.WRAP)) != 0) { + overflow[i] = true; + } + } + } + } + } + + //Any space, distribute amongst FILL + if (availableWidth > 0) { + int fillCount = 0; + for (int i = 0; i < controls.length; i++) { + int alignment = controlAlignments[i]; + if ((alignment & SWT.TRAIL) != 0 && (alignment & SWT.FILL) != 0 && !overflow[i]) { + fillCount++; + } + } + if (fillCount != 0) { + int extraSpace = availableWidth/fillCount; + int addedSpace = 0; + for (int i = 0; i < controls.length; i++) { + int alignment = controlAlignments[i]; + if ((alignment & SWT.TRAIL) != 0) { + if ((alignment & SWT.FILL) != 0 && !overflow[i]) { + rects[i].width += extraSpace; + addedSpace += extraSpace; + } + if (!overflow[i]) { + rects[i].x -= addedSpace; + } + } + } + } + } + + //Go through overflow laying out all wrapped controls + Rectangle bodyTrim = renderer.computeTrim(CTabFolderRenderer.PART_BODY, SWT.NONE, 0, 0, 0, 0); + int bodyRight = bodyTrim.width + bodyTrim.x; + int bodyLeft = -bodyTrim.x; + int bodyWidth = size.x - bodyLeft - bodyRight; + x = size.x - bodyRight; + int y = -bodyTrim.y; + availableWidth = bodyWidth; + int maxHeight = 0; + for (int i = 0; i < controls.length; i++) { + Point ctrlSize = tabControlSize[i]; + if (overflow[i]) { + if (availableWidth > ctrlSize.x) { + x -= ctrlSize.x; + rects[i].width = ctrlSize.x; + rects[i].y = y; + rects[i].height = ctrlSize.y; + rects[i].x = x; + availableWidth -= ctrlSize.x; + maxHeight = Math.max(maxHeight, ctrlSize.y); + } else { + x = size.x - bodyRight; + y += maxHeight; + maxHeight = 0; + availableWidth = bodyWidth; + if (availableWidth > ctrlSize.x) { + //Relayout this control in the next line + i--; + } else { + ctrlSize = controls[i].computeSize(bodyWidth, SWT.DEFAULT); + rects[i].width = bodyWidth; + rects[i].y = y; + rects[i].height = ctrlSize.y; + rects[i].x = size.x - ctrlSize.x - bodyRight; + y += ctrlSize.y; + } + } + } + } + + if (showChevron) { + int i = 0, lastIndex = -1; + while (i < priority.length && items[priority[i]].showing) { + lastIndex = Math.max(lastIndex, priority[i++]); + } + if (lastIndex == -1) lastIndex = selectedIndex; + if (lastIndex != -1) { + CTabItem lastItem = items[lastIndex]; + int w = lastItem.x + lastItem.width + SPACING; + if (!simple && lastIndex == selectedIndex) w -= (renderer.curveIndent - 7); + rects[controls.length - 1].x = w; + } + } + + if (position != null) position[0] = overflow; + return rects; +} + +int getControlHeight(Point ctrlSize) { + return fixedTabHeight == SWT.DEFAULT ? Math.max(tabHeight - 1, ctrlSize.y) : ctrlSize.y; +} /* * This class was not intended to be subclassed but this restriction * cannot be enforced without breaking backward compatibility. @@ -426,7 +623,39 @@ public void addSelectionListener(SelectionListener listener) { //} public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget(); - return renderer.computeTrim(CTabFolderRenderer.PART_BODY, SWT.NONE, x, y, width, height); + Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BODY, SWT.NONE, x, y, width, height); + Point size = new Point(width, height); + int wrapHeight = getWrappedHeight(size); + if (onBottom) { + trim.height += wrapHeight; + } else { + trim.y -= wrapHeight; + trim.height += wrapHeight; + } + return trim; +} +Image createButtonImage(Display display, int button) { + Point size = renderer.computeSize(button, SWT.NONE, null, SWT.DEFAULT, SWT.DEFAULT); + Rectangle trim = renderer.computeTrim(button, SWT.NONE, 0, 0, 0, 0); + Image image = new Image (display, size.x - trim.width, size.y - trim.height); + GC gc = new GC (image); + RGB transparent; + if (button == CTabFolderRenderer.PART_CHEVRON_BUTTON) { + transparent = new RGB(0xFF, 0xFF, 0xFF); + } else { + transparent = new RGB(0xFD, 0, 0); + } + Color transColor = new Color(display, transparent); + gc.setBackground(transColor); + gc.fillRectangle(image.getBounds()); + renderer.draw(button, SWT.NONE, new Rectangle(trim.x, trim.y, size.x, size.y), gc); + gc.dispose (); + transColor.dispose(); + ImageData imageData = image.getImageData(); + imageData.transparentPixel = imageData.palette.getPixel(transparent); + image.dispose(); + image = new Image(display, imageData); + return image; } void createItem (CTabItem item, int index) { if (0 > index || index > getItemCount ())SWT.error (SWT.ERROR_INVALID_RANGE); @@ -440,7 +669,7 @@ void createItem (CTabItem item, int index) { int[] newPriority = new int[priority.length + 1]; int next = 0, priorityIndex = priority.length; for (int i = 0; i < priority.length; i++) { - if (!mru && priority[i] == index) { + if (!mru && (priority[i] == index || (priority[i] == 0 && index+1 == items.length))) { priorityIndex = next++; } newPriority[next++] = priority[i] >= index ? priority[i] + 1 : priority[i]; @@ -525,11 +754,48 @@ public boolean getBorderVisible() { checkWidget(); return borderVisible; } +ToolBar getChevron() { + if (chevronTb == null) { + chevronTb = new ToolBar(this, SWT.FLAT); + initAccessibleChevronTb(); + addTabControl(chevronTb, SWT.TRAIL, -1, false); + } + if (chevronItem == null) { + chevronItem = new ToolItem(chevronTb, SWT.PUSH); + chevronItem.setToolTipText(SWT.getMessage("SWT_ShowList")); + chevronItem.addListener(SWT.Selection, listener); + } + return chevronTb; +} +/** + * Returns true if the chevron button + * is visible when necessary. + * + * @return the visibility of the chevron button + * + * @exception SWTException + * + */ +/*public*/ boolean getChevronVisible() { + checkWidget(); + return chevronVisible; +} public Rectangle getClientArea() { checkWidget(); - Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BODY, SWT.NONE, 0, 0, 0, 0); - if (minimized) return new Rectangle(-trim.x, -trim.y, 0, 0); + //TODO: HACK - find a better way to get padding + Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BODY, SWT.FILL, 0, 0, 0, 0); Point size = getSize(); + int wrapHeight = getWrappedHeight(size); + if (onBottom) { + trim.height += wrapHeight; + } else { + trim.y -= wrapHeight; + trim.height += wrapHeight; + } + if (minimized) return new Rectangle(-trim.x, -trim.y, 0, 0); int width = size.x - trim.width; int height = size.y - trim.height; return new Rectangle(-trim.x, -trim.y, width, height); @@ -572,7 +838,6 @@ public CTabItem getItem (Point pt) { Point size = getSize(); Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BORDER, SWT.NONE, 0, 0, 0, 0); if (size.x <= trim.width) return null; - if (showChevron && chevronRect.contains(pt)) return null; for (int i = 0; i < priority.length; i++) { CTabItem item = items[priority[i]]; Rectangle rect = item.getBounds(); @@ -610,7 +875,19 @@ public CTabItem [] getItems() { System.arraycopy(items, 0, tabItems, 0, items.length); return tabItems; } - +int getLeftItemEdge (GC gc, int part){ + Rectangle trim = renderer.computeTrim(part, SWT.NONE, 0, 0, 0, 0); + int x = -trim.x; + int width = 0; + for (int i = 0; i < controls.length; i++) { + if ((controlAlignments[i] & SWT.LEAD) != 0 && controls[i].getVisible()) { + width += controls[i].computeSize(SWT.DEFAULT, SWT.DEFAULT).x; + } + } + if (width != 0) width += SPACING * 2; + x += width; + return Math.max(0, x); +} /* * Return the lowercase of the first non-'&' character following * an '&' character in the given string. If there are no '&' @@ -775,14 +1052,17 @@ public CTabFolderRenderer getRenderer() { } int getRightItemEdge (GC gc){ Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BORDER, 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, 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; + int x = getSize().x - (trim.width + trim.x); + int width = 0; + for (int i = 0; i < controls.length; i++) { + int align = controlAlignments[i]; + if ((align & SWT.WRAP) == 0 && (align & SWT.LEAD) == 0 && controls[i].getVisible()) { + Point rightSize = controls[i].computeSize(SWT.DEFAULT, SWT.DEFAULT); + width += rightSize.x; + } } + if (width != 0) width += SPACING * 2; + x -= width; return Math.max(0, x); } /** @@ -1005,12 +1285,6 @@ void initAccessible() { int childID = e.childID; if (childID >= 0 && childID < items.length) { name = stripMnemonic(items[childID].getText()); - } else if (childID == items.length + CHEVRON_CHILD_ID) { - name = SWT.getMessage("SWT_ShowList"); //$NON-NLS-1$ - } else if (childID == items.length + MINIMIZE_CHILD_ID) { - name = minimized ? SWT.getMessage("SWT_Restore") : SWT.getMessage("SWT_Minimize"); //$NON-NLS-1$ //$NON-NLS-2$ - } else if (childID == items.length + MAXIMIZE_CHILD_ID) { - name = maximized ? SWT.getMessage("SWT_Restore") : SWT.getMessage("SWT_Maximize"); //$NON-NLS-1$ //$NON-NLS-2$ } e.result = name; } @@ -1056,19 +1330,11 @@ void initAccessible() { } } if (childID == ACC.CHILDID_NONE) { - if (showChevron && chevronRect.contains(testPoint)) { - childID = items.length + CHEVRON_CHILD_ID; - } else if (showMin && minRect.contains(testPoint)) { - childID = items.length + MINIMIZE_CHILD_ID; - } else if (showMax && maxRect.contains(testPoint)) { - childID = items.length + MAXIMIZE_CHILD_ID; - } else { - Rectangle location = getBounds(); - location.x = location.y = 0; - location.height = location.height - getClientArea().height; - if (location.contains(testPoint)) { - childID = ACC.CHILDID_SELF; - } + Rectangle location = getBounds(); + location.x = location.y = 0; + location.height = location.height - getClientArea().height; + if (location.contains(testPoint)) { + childID = ACC.CHILDID_SELF; } } e.childID = childID; @@ -1084,12 +1350,6 @@ void initAccessible() { } else { if (childID >= 0 && childID < items.length && items[childID].isShowing()) { location = items[childID].getBounds(); - } else if (showChevron && childID == items.length + CHEVRON_CHILD_ID) { - location = chevronRect; - } else if (showMin && childID == items.length + MINIMIZE_CHILD_ID) { - location = minRect; - } else if (showMax && childID == items.length + MAXIMIZE_CHILD_ID) { - location = maxRect; } if (location != null) { pt = toDisplay(location.x, location.y); @@ -1104,7 +1364,7 @@ void initAccessible() { } public void getChildCount(AccessibleControlEvent e) { - e.detail = items.length + EXTRA_CHILD_ID_COUNT; + e.detail = items.length; } public void getDefaultAction(AccessibleControlEvent e) { @@ -1113,9 +1373,6 @@ void initAccessible() { if (childID >= 0 && childID < items.length) { action = SWT.getMessage ("SWT_Switch"); //$NON-NLS-1$ } - if (childID >= items.length && childID < items.length + EXTRA_CHILD_ID_COUNT) { - action = SWT.getMessage ("SWT_Press"); //$NON-NLS-1$ - } e.result = action; } @@ -1138,9 +1395,7 @@ void initAccessible() { role = ACC.ROLE_TABFOLDER; } else if (childID >= 0 && childID < items.length) { role = ACC.ROLE_TABITEM; - } else if (childID >= items.length && childID < items.length + EXTRA_CHILD_ID_COUNT) { - role = ACC.ROLE_PUSHBUTTON; - } + } e.detail = role; } @@ -1164,18 +1419,12 @@ void initAccessible() { state |= ACC.STATE_FOCUSED; } } - } else if (childID == items.length + CHEVRON_CHILD_ID) { - state = showChevron ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; - } else if (childID == items.length + MINIMIZE_CHILD_ID) { - state = showMin ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; - } else if (childID == items.length + MAXIMIZE_CHILD_ID) { - state = showMax ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; } e.detail = state; } public void getChildren(AccessibleControlEvent e) { - int childIdCount = items.length + EXTRA_CHILD_ID_COUNT; + int childIdCount = items.length; Object[] children = new Object[childIdCount]; for (int i = 0; i < childIdCount; i++) { children[i] = new Integer(i); @@ -1206,6 +1455,30 @@ void initAccessible() { } }); } +void initAccessibleMinMaxTb() { + minMaxTb.getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getName(AccessibleEvent e) { + if (e.childID != ACC.CHILDID_SELF) { + if (minItem != null && e.childID == minMaxTb.indexOf(minItem)) { + e.result = minItem.getToolTipText(); + } else if (maxItem != null && e.childID == minMaxTb.indexOf(maxItem)) { + e.result = maxItem.getToolTipText(); + } + } + } + }); +} +void initAccessibleChevronTb() { + chevronTb.getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getName(AccessibleEvent e) { + if (e.childID != ACC.CHILDID_SELF) { + if (chevronItem != null && e.childID == chevronTb.indexOf(chevronItem)) { + e.result = chevronItem.getToolTipText(); + } + } + } + }); +} void onKeyDown (Event event) { switch (event.keyCode) { case SWT.ARROW_LEFT: @@ -1232,6 +1505,8 @@ void onKeyDown (Event event) { index = visible [current + offset]; } else { if (showChevron) { + Rectangle chevronRect = chevronItem.getBounds(); + chevronRect = event.display.map(chevronTb, this, chevronRect); CTabFolderEvent e = new CTabFolderEvent(this); e.widget = this; e.time = event.time; @@ -1286,21 +1561,37 @@ void onDispose(Event event) { selectionBackground = null; selectionForeground = null; + if (controlBkImages != null) { + for (int i = 0; i < controlBkImages.length; i++) { + if (controlBkImages[i] != null) { + controlBkImages[i].dispose(); + controlBkImages[i] = null; + } + } + controlBkImages = null; + } + controls = null; + controlAlignments = null; + controlRects = null; + + if (maxImage != null) maxImage.dispose(); + maxImage = null; + + if (minImage != null) minImage.dispose(); + minImage = null; + + if (chevronImage != null) chevronImage.dispose(); + chevronImage = null; + if (renderer != null) renderer.dispose(); renderer = null; } void onDragDetect(Event event) { boolean consume = false; - if (chevronRect.contains(event.x, event.y) || - minRect.contains(event.x, event.y) || - maxRect.contains(event.x, event.y)){ - consume = true; - } else { - for (int i = 0; i < items.length; i++) { - if (items[i].closeRect.contains(event.x, event.y)) { - consume = true; - break; - } + for (int i = 0; i < items.length; i++) { + if (items[i].closeRect.contains(event.x, event.y)) { + consume = true; + break; } } if (consume) { @@ -1344,6 +1635,9 @@ void onMouseDoubleClick(Event event) { } } void onMouse(Event event) { + if( isDisposed() ) { + return; + } int x = event.x, y = event.y; switch (event.type) { case SWT.MouseEnter: { @@ -1351,18 +1645,6 @@ void onMouse(Event event) { break; } case SWT.MouseExit: { - if (minImageState != SWT.NONE) { - minImageState = SWT.NONE; - redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); - } - if (maxImageState != SWT.NONE) { - maxImageState = SWT.NONE; - redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); - } - if (chevronImageState != SWT.NONE) { - chevronImageState = SWT.NONE; - redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false); - } for (int i=0; i * * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance from top to bottom or left to right. The value - * null clears the background gradient. The value null - * can be used inside the array of Color to specify the background color. + * in order of appearance left to right. The value null clears the + * background gradient. The value null can be used inside the array of + * Color to specify the background color. * @param percents an array of integers between 0 and 100 specifying the percent of the width * of the widget at which the color should change. The size of the percents * array must be one less than the size of the colors array. + * * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal. * * @exception SWTException