diff options
author | Bogdan Gheorghe <gheorghe> | 2010-02-25 18:06:22 +0000 |
---|---|---|
committer | Bogdan Gheorghe <gheorghe> | 2010-02-25 18:06:22 +0000 |
commit | cc83d934c7ecd9490a10ee8ca6f056b3625a0872 (patch) | |
tree | c3cd90155d8a98284658ce4721ff47604e0655f4 /bundles/org.eclipse.swt | |
parent | 9bf79aea63cb1a27afc9b9e1a2eba4b0f8c6e3b1 (diff) | |
download | eclipse.platform.swt-cc83d934c7ecd9490a10ee8ca6f056b3625a0872.tar.gz eclipse.platform.swt-cc83d934c7ecd9490a10ee8ca6f056b3625a0872.tar.xz eclipse.platform.swt-cc83d934c7ecd9490a10ee8ca6f056b3625a0872.zip |
CTabFolder refactor
Diffstat (limited to 'bundles/org.eclipse.swt')
7 files changed, 145 insertions, 71 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 81203034ea..ed0ea51061 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 @@ -298,29 +298,9 @@ static int checkStyle (Composite parent, int style) { // MULTI is the default if ((style & SWT.MULTI) != 0) style = style & ~SWT.SINGLE; // reduce the flash by not redrawing the entire area on a Resize event - style |= SWT.NO_REDRAW_RESIZE; - //TEMPORARY CODE - /* - * The default background on carbon and some GTK themes is not a solid color - * but a texture. To show the correct default background, we must allow - * the operating system to draw it and therefore, we can not use the - * NO_BACKGROUND style. The NO_BACKGROUND style is not required on platforms - * that use double buffering which is true in both of these cases. - */ - String platform = SWT.getPlatform(); - if ("cocoa".equals(platform) || "carbon".equals(platform) || "gtk".equals(platform)) return style; //$NON-NLS-1$ //$NON-NLS-2$ - - //TEMPORARY CODE - /* - * In Right To Left orientation on Windows, all GC calls that use a brush are drawing - * offset by one pixel. This results in some parts of the CTabFolder not drawing correctly. - * To alleviate some of the appearance problems, allow the OS to draw the background. - * This does not draw correctly but the result is less obviously wrong. - */ - if ((style & SWT.RIGHT_TO_LEFT) != 0) return style; - if ((parent.getStyle() & SWT.MIRRORED) != 0 && (style & SWT.LEFT_TO_RIGHT) == 0) return style; - - return style | SWT.NO_BACKGROUND; + style |= SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED; + + return style; } /** @@ -764,7 +744,19 @@ public boolean getMRUVisible() { checkWidget(); return mru; } -/*public*/ CTabFolderRenderer getRenderer() { +/** + * WARNING: API UNDER CONSTRUCTION + * + * Returns the receiver's renderer. + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> + * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> + * </ul> + * + * @since 3.6 + */ +public CTabFolderRenderer getRenderer() { checkWidget(); return renderer; } @@ -772,7 +764,7 @@ 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 (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 (topRight != null && topRightAlignment != SWT.FILL) { Point rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT); @@ -1905,6 +1897,8 @@ public void setBackground (Color color) { redraw(); } /** + * WARNING: API UNDER CONSTRUCTION + * * Specify a gradient of colours to be drawn in the background of the unselected tabs. * For example to draw a gradient that varies from dark blue to blue and then to * white, use the following call to setBackground: @@ -1929,12 +1923,14 @@ public void setBackground (Color color) { * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> * </ul> * - * @since 3.0 + * @since 3.6 */ -void setBackground(Color[] colors, int[] percents) { +public void setBackground(Color[] colors, int[] percents) { setBackground(colors, percents, false); } /** + * WARNING: API UNDER CONSTRUCTION + * * Specify a gradient of colours to be drawn in the background of the unselected tab. * For example to draw a vertical gradient that varies from dark blue to blue and then to * white, use the following call to setBackground: @@ -1961,9 +1957,9 @@ void setBackground(Color[] colors, int[] percents) { * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> * </ul> * - * @since 3.0 + * @since 3.6 */ -void setBackground(Color[] colors, int[] percents, boolean vertical) { +public void setBackground(Color[] colors, int[] percents, boolean vertical) { checkWidget(); if (colors != null) { if (percents == null || percents.length != colors.length - 1) { @@ -2304,7 +2300,7 @@ boolean setItemLocation(GC gc) { width += item.width; item.showing = i == 0 ? true : item.width > 0 && width <= maxWidth; } - int x = 0; + int x = -renderer.computeTrim(CTabFolderRenderer.PART_HEADER, SWT.NONE, 0, 0, 0, 0).x; int defaultX = getDisplay().getBounds().width + 10; // off screen firstIndex = items.length - 1; for (int i = 0; i < items.length; i++) { @@ -2619,15 +2615,36 @@ public void setMRUVisible(boolean show) { if (updateItems()) redrawTabs(); } } -/*public*/ void setRenderer(CTabFolderRenderer renderer) { +/** + * WARNING: API UNDER CONSTRUCTION + * + * Sets the renderer which is associated with the receiver to be + * the argument which may be null. In the case of null, the default + * renderer is used. + * + * @param renderer a new renderer + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> + * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> + * </ul> + * + * @since 3.6 + */ +public void setRenderer(CTabFolderRenderer renderer) { checkWidget(); - if (this.renderer != null) { - this.renderer.dispose(); - } - if (renderer == null) { - renderer = new CTabFolderRenderer(this); - } + if (this.renderer == renderer) return; + if (this.renderer != null) this.renderer.dispose(); + if (renderer == null) renderer = new CTabFolderRenderer(this); this.renderer = renderer; + updateTabHeight(false); + Rectangle rectBefore = getClientArea(); + updateItems(); + Rectangle rectAfter = getClientArea(); + if (!rectBefore.equals(rectAfter)) { + notifyListeners(SWT.Resize, new Event()); + } + redraw(); } /** * Set the selection to the tab at the specified item. 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 61d54b0600..46381efeda 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 @@ -14,7 +14,12 @@ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; -/*public*/ class CTabFolderRenderer { +/** +* WARNING: API UNDER CONSTRUCTION +* +* @since 3.6 +*/ +public class CTabFolderRenderer { protected CTabFolder parent; @@ -94,10 +99,11 @@ import org.eclipse.swt.widgets.*; public static final int PART_BODY = -1; public static final int PART_HEADER = -2; public static final int PART_BORDER = -3; - public static final int PART_MAX_BUTTON = -4; - public static final int PART_MIN_BUTTON = -5; - public static final int PART_CHEVRON_BUTTON = -6; - public static final int PART_CLOSE_BUTTON = -7; + public static final int PART_BACKGROUND = -4; + public static final int PART_MAX_BUTTON = -5; + public static final int PART_MIN_BUTTON = -6; + public static final int PART_CHEVRON_BUTTON = -7; + public static final int PART_CLOSE_BUTTON = -8; public static final int MINIMUM_SIZE = 1 << 24; //TODO: Should this be a state? @@ -391,6 +397,9 @@ import org.eclipse.swt.widgets.*; protected void draw (int part, int state, Rectangle bounds, GC gc) { switch (part) { + case PART_BACKGROUND: + this.drawBackground(gc, bounds, state); + break; case PART_BODY: drawBody(gc, bounds, state); break; @@ -419,6 +428,17 @@ import org.eclipse.swt.widgets.*; } } + void drawBackground(GC gc, Rectangle bounds, int state) { + boolean selected = (state & SWT.SELECTED) != 0; + Color defaultBackground = selected ? parent.selectionBackground : parent.getBackground(); + Image image = selected ? parent.selectionBgImage : null; + Color[] colors = selected ? parent.selectionGradientColors : parent.gradientColors; + int[] percents = selected ? parent.selectionGradientPercents : parent.gradientPercents; + boolean vertical = selected ? parent.selectionGradientVertical : parent.gradientVertical; + + drawBackground(gc, null, bounds.x, bounds.y, bounds.width, bounds.height, defaultBackground, image, colors, percents, vertical); + } + void drawBackground(GC gc, int[] shape, boolean selected) { Color defaultBackground = selected ? parent.selectionBackground : parent.getBackground(); Image image = selected ? parent.selectionBgImage : null; @@ -442,13 +462,15 @@ import org.eclipse.swt.widgets.*; } void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Color defaultBackground, Image image, Color[] colors, int[] percents, boolean vertical) { - Region clipping = new Region(); - gc.getClipping(clipping); - Region region = new Region(); - region.add(shape); - region.intersect(clipping); - gc.setClipping(region); - + Region clipping = null, region = null; + if (shape != null) { + clipping = new Region(); + gc.getClipping(clipping); + region = new Region(); + region.add(shape); + region.intersect(clipping); + gc.setClipping(region); + } if (image != null) { // draw the background image in shape gc.setBackground(defaultBackground); @@ -529,9 +551,11 @@ import org.eclipse.swt.widgets.*; gc.fillRectangle(x, y, width, height); } } - gc.setClipping(clipping); - clipping.dispose(); - region.dispose(); + if (shape != null) { + gc.setClipping(clipping); + clipping.dispose(); + region.dispose(); + } } /* diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java index 5ca958ded8..b83796e25f 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java @@ -112,14 +112,7 @@ void clearArea (int x, int y, int width, int height) { * @since 3.2 */ public void drawBackground (GC gc, int x, int y, int width, int height) { - checkWidget (); - if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - RECT rect = new RECT (); - OS.SetRect (rect, x, y, x + width, y + height); - int /*long*/ hDC = gc.handle; - int pixel = background == -1 ? gc.getBackground ().handle : -1; - drawBackground (hDC, rect, pixel); + drawBackground(gc, x, y, width, height, 0, 0); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java index 37352bfa79..e2233e7d4e 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java @@ -314,6 +314,46 @@ void createHandle () { } } +/** + * WARNING: API UNDER CONSTRUCTION + * + * Fills the interior of the rectangle specified by the arguments, + * with the receiver's background. + * + * <p>The <code>offsetX</code> and <code>offsetY</code> are used to map from + * the gc origin to the origin of the parent image background. This is useful + * to ensure proper alignment of the image background.</p> + * + * @param gc the gc where the rectangle is to be filled + * @param x the x coordinate of the rectangle to be filled + * @param y the y coordinate of the rectangle to be filled + * @param width the width of the rectangle to be filled + * @param height the height of the rectangle to be filled + * @param offsetX the image background x offset + * @param offsetY the image background y offset + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.6 + */ +public void drawBackground(GC gc, int x, int y, int width, int height, int offsetX, int offsetY) { + checkWidget (); + if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); + if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + RECT rect = new RECT (); + OS.SetRect (rect, x, y, x + width, y + height); + int /*long*/ hDC = gc.handle; + int pixel = background == -1 ? gc.getBackground ().handle : -1; + drawBackground (hDC, rect, pixel, offsetX, offsetY); +} + Composite findDeferredControl () { return layoutCount > 0 ? this : parent.findDeferredControl (); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index 9e34758ba5..267db9be54 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -804,14 +804,14 @@ void drawBackground (int /*long*/ hDC) { } void drawBackground (int /*long*/ hDC, RECT rect) { - drawBackground (hDC, rect, -1); + drawBackground (hDC, rect, -1, 0, 0); } -void drawBackground (int /*long*/ hDC, RECT rect, int pixel) { +void drawBackground (int /*long*/ hDC, RECT rect, int pixel, int tx, int ty) { Control control = findBackgroundControl (); if (control != null) { if (control.backgroundImage != null) { - fillImageBackground (hDC, control, rect); + fillImageBackground (hDC, control, rect, tx, ty); return; } pixel = control.getBackgroundPixel (); @@ -831,14 +831,14 @@ void drawBackground (int /*long*/ hDC, RECT rect, int pixel) { fillBackground (hDC, pixel, rect); } -void drawImageBackground (int /*long*/ hDC, int /*long*/ hwnd, int /*long*/ hBitmap, RECT rect) { +void drawImageBackground (int /*long*/ hDC, int /*long*/ hwnd, int /*long*/ hBitmap, RECT rect, int tx, int ty) { RECT rect2 = new RECT (); OS.GetClientRect (hwnd, rect2); OS.MapWindowPoints (hwnd, handle, rect2, 2); int /*long*/ hBrush = findBrush (hBitmap, OS.BS_PATTERN); POINT lpPoint = new POINT (); OS.GetWindowOrgEx (hDC, lpPoint); - OS.SetBrushOrgEx (hDC, -rect2.left - lpPoint.x, -rect2.top - lpPoint.y, lpPoint); + OS.SetBrushOrgEx (hDC, -rect2.left - lpPoint.x - tx, -rect2.top - lpPoint.y - ty, lpPoint); int /*long*/ hOldBrush = OS.SelectObject (hDC, hBrush); OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY); OS.SetBrushOrgEx (hDC, lpPoint.x, lpPoint.y, null); @@ -867,12 +867,12 @@ void fillBackground (int /*long*/ hDC, int pixel, RECT rect) { OS.FillRect (hDC, rect, findBrush (pixel, OS.BS_SOLID)); } -void fillImageBackground (int /*long*/ hDC, Control control, RECT rect) { +void fillImageBackground (int /*long*/ hDC, Control control, RECT rect, int tx, int ty) { if (rect.left > rect.right || rect.top > rect.bottom) return; if (control != null) { Image image = control.backgroundImage; if (image != null) { - control.drawImageBackground (hDC, handle, image.handle, rect); + control.drawImageBackground (hDC, handle, image.handle, rect, tx, ty); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index 69093f88af..893b17af78 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -652,7 +652,7 @@ LRESULT CDDS_PREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lP if (control != null && control.backgroundImage != null) { RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); - fillImageBackground (nmcd.hdc, control, rect); + fillImageBackground (nmcd.hdc, control, rect, 0, 0); } else { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) { if (OS.IsWindowEnabled (handle)) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index f7561a8031..dbdba64403 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -719,9 +719,9 @@ LRESULT CDDS_ITEMPOSTPAINT (NMTVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long if (i == 0) { int right = Math.min (rect.right, width); OS.SetRect (rect, rect.left, rect.top, right, rect.bottom); - if (drawBackground) fillImageBackground (hDC, control, rect); + if (drawBackground) fillImageBackground (hDC, control, rect, 0, 0); } else { - if (drawBackground) fillImageBackground (hDC, control, rect); + if (drawBackground) fillImageBackground (hDC, control, rect, 0, 0); } } } @@ -984,7 +984,7 @@ LRESULT CDDS_ITEMPREPAINT (NMTVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long* OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); RECT cellRect = item.getBounds (index, true, true, true, true, true, hDC); if (clrSortBk != -1) { - drawBackground (hDC, cellRect, clrSortBk); + drawBackground (hDC, cellRect, clrSortBk, 0, 0); } else { if (OS.IsWindowEnabled (handle) || findImageControl () != null) { drawBackground (hDC, rect); |