changeset 99:33959bbb30af

CBanner, CBannerLayout, CLayoutData
author Frank Benoit <benoit@tionex.de>
date Fri, 18 Jan 2008 02:57:41 +0100
parents bf44a537c2e9
children 3ec1765539d0
files dwt/custom/CBanner.d dwt/custom/CBannerLayout.d dwt/custom/CLayoutData.d
diffstat 3 files changed, 798 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/custom/CBanner.d	Fri Jan 18 02:57:41 2008 +0100
@@ -0,0 +1,555 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.custom.CBanner;
+
+
+
+import dwt.DWT;
+import dwt.DWTException;
+import dwt.graphics.Color;
+import dwt.graphics.Cursor;
+import dwt.graphics.GC;
+import dwt.graphics.Point;
+import dwt.graphics.RGB;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Composite;
+import dwt.widgets.Control;
+import dwt.widgets.Event;
+import dwt.widgets.Layout;
+import dwt.widgets.Listener;
+import dwt.custom.CBannerLayout;
+
+import Math = tango.math.Math;
+
+
+/**
+ * Instances of this class implement a Composite that lays out its
+ * children and allows programmatic control of the layout. It draws
+ * a separator between the left and right children which can be dragged
+ * to resize the right control.
+ * CBanner is used in the workbench to layout the toolbar area and
+ * perspective switching toolbar.
+ * <p>
+ * Note that although this class is a subclass of <code>Composite</code>,
+ * it does not make sense to set a layout on it.
+ * </p><p>
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>NONE</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>(None)</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
+ *
+ * @since 3.0
+ */
+
+public class CBanner : Composite {
+
+    Control left;
+    Control right;
+    Control bottom;
+
+    bool simple = true;
+
+    int[] curve;
+    int curveStart = 0;
+    Rectangle curveRect;
+    int curve_width = 5;
+    int curve_indent = -2;
+
+    int rightWidth = DWT.DEFAULT;
+    int rightMinWidth = 0;
+    int rightMinHeight = 0;
+    Cursor resizeCursor;
+    bool dragging = false;
+    int rightDragDisplacement = 0;
+
+    static const int OFFSCREEN = -200;
+    static const int BORDER_BOTTOM = 2;
+    static const int BORDER_TOP = 3;
+    static const int BORDER_STRIPE = 1;
+    static const int CURVE_TAIL = 200;
+    static const int BEZIER_RIGHT = 30;
+    static const int BEZIER_LEFT = 30;
+    static const int MIN_LEFT = 10;
+    static int BORDER1 = DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW;
+
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>DWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>DWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a widget which will be the parent of the new instance (cannot be null)
+ * @param style the style of widget to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception DWTException <ul>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * </ul>
+ *
+ */
+public this(Composite parent, int style) {
+    curveRect = new Rectangle(0, 0, 0, 0);
+    super(parent, checkStyle(style));
+    super.setLayout(new CBannerLayout());
+    resizeCursor = new Cursor(getDisplay(), DWT.CURSOR_SIZEWE);
+
+    Listener listener = new class() Listener {
+        public void handleEvent(Event e) {
+            switch (e.type) {
+                case DWT.Dispose:
+                    onDispose(); break;
+                case DWT.MouseDown:
+                    onMouseDown (e.x, e.y); break;
+                case DWT.MouseExit:
+                    onMouseExit(); break;
+                case DWT.MouseMove:
+                    onMouseMove(e.x, e.y); break;
+                case DWT.MouseUp:
+                    onMouseUp(); break;
+                case DWT.Paint:
+                    onPaint(e.gc); break;
+                case DWT.Resize:
+                    onResize(); break;
+            }
+        }
+    };
+    int[] events = [DWT.Dispose, DWT.MouseDown, DWT.MouseExit, DWT.MouseMove, DWT.MouseUp, DWT.Paint, DWT.Resize];
+    for (int i = 0; i < events.length; i++) {
+        addListener(events[i], listener);
+    }
+}
+static int[] bezier(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, int count) {
+    // The parametric equations for a Bezier curve for x[t] and y[t] where  0 <= t <=1 are:
+    // x[t] = x0+3(x1-x0)t+3(x0+x2-2x1)t^2+(x3-x0+3x1-3x2)t^3
+    // y[t] = y0+3(y1-y0)t+3(y0+y2-2y1)t^2+(y3-y0+3y1-3y2)t^3
+    double a0 = x0;
+    double a1 = 3*(x1 - x0);
+    double a2 = 3*(x0 + x2 - 2*x1);
+    double a3 = x3 - x0 + 3*x1 - 3*x2;
+    double b0 = y0;
+    double b1 = 3*(y1 - y0);
+    double b2 = 3*(y0 + y2 - 2*y1);
+    double b3 = y3 - y0 + 3*y1 - 3*y2;
+
+    int[] polygon = new int[2*count + 2];
+    for (int i = 0; i <= count; i++) {
+        double t = cast(double)i / cast(double)count;
+        polygon[2*i] = cast(int)(a0 + a1*t + a2*t*t + a3*t*t*t);
+        polygon[2*i + 1] = cast(int)(b0 + b1*t + b2*t*t + b3*t*t*t);
+    }
+    return polygon;
+}
+static int checkStyle (int style) {
+    return DWT.NONE;
+}
+/**
+* Returns the Control that appears on the bottom side of the banner.
+*
+* @return the control that appears on the bottom side of the banner or null
+*
+* @exception DWTException <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.0
+*/
+public Control getBottom() {
+    checkWidget();
+    return bottom;
+}
+public Rectangle getClientArea() {
+    return new Rectangle(0, 0, 0, 0);
+}
+
+/**
+* Returns the Control that appears on the left side of the banner.
+*
+* @return the control that appears on the left side of the banner or null
+*
+* @exception DWTException <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.0
+*/
+public Control getLeft() {
+    checkWidget();
+    return left;
+}
+
+/**
+* Returns the Control that appears on the right side of the banner.
+*
+* @return the control that appears on the right side of the banner or null
+*
+* @exception DWTException <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.0
+*/
+public Control getRight() {
+    checkWidget();
+    return right;
+}
+/**
+ * Returns the minimum size of the control that appears on the right of the banner.
+ *
+ * @return the minimum size of the control that appears on the right of the banner
+ *
+ * @since 3.1
+ */
+public Point getRightMinimumSize() {
+    checkWidget();
+    return new Point(rightMinWidth, rightMinHeight);
+}
+/**
+ * Returns the width of the control that appears on the right of the banner.
+ *
+ * @return the width of the control that appears on the right of the banner
+ *
+ * @since 3.0
+ */
+public int getRightWidth() {
+    checkWidget();
+    if (right is null) return 0;
+    if (rightWidth is DWT.DEFAULT) {
+        Point size = right.computeSize(DWT.DEFAULT, DWT.DEFAULT, false);
+        return size.x;
+    }
+    return rightWidth;
+}
+/**
+ * Returns <code>true</code> if the CBanner is rendered
+ * with a simple, traditional shape.
+ *
+ * @return <code>true</code> if the CBanner is rendered with a simple shape
+ *
+ * @since 3.0
+ */
+public bool getSimple() {
+    checkWidget();
+    return simple;
+}
+void onDispose() {
+    if (resizeCursor !is null) resizeCursor.dispose();
+    resizeCursor = null;
+    left = null;
+    right = null;
+    bottom = null;
+}
+void onMouseDown (int x, int y) {
+    if (curveRect.contains(x, y)) {
+        dragging = true;
+        rightDragDisplacement = curveStart - x + curve_width - curve_indent;
+    }
+}
+void onMouseExit() {
+    if (!dragging) setCursor(cast(Cursor)null);
+}
+void onMouseMove(int x, int y) {
+    if (dragging) {
+        Point size = getSize();
+        if (!(0 < x && x < size.x)) return;
+        rightWidth = Math.max(0, size.x - x - rightDragDisplacement);
+        if (rightMinWidth is DWT.DEFAULT) {
+            Point minSize = right.computeSize(rightMinWidth, rightMinHeight);
+            rightWidth = Math.max(minSize.x, rightWidth);
+        } else {
+            rightWidth = Math.max(rightMinWidth, rightWidth);
+        }
+        layout(false);
+        return;
+    }
+    if (curveRect.contains(x, y)) {
+        setCursor(resizeCursor);
+    } else {
+        setCursor(cast(Cursor)null);
+    }
+}
+void onMouseUp () {
+    dragging = false;
+}
+void onPaint(GC gc) {
+//   Useful for debugging paint problems
+//  {
+//  Point size = getSize();
+//  gc.setBackground(getDisplay().getSystemColor(DWT.COLOR_GREEN));
+//  gc.fillRectangle(-10, -10, size.x+20, size.y+20);
+//  }
+    if (left is null && right is null) return;
+    Point size = getSize();
+    Color border1 = getDisplay().getSystemColor(BORDER1);
+    if (bottom !is null) {
+        int y = bottom.getBounds().y - BORDER_STRIPE - 1;
+        gc.setForeground(border1);
+        gc.drawLine(0, y, size.x, y);
+    }
+    if (left is null || right is null) return;
+    int[] line1 = new int[curve.length+6];
+    int index = 0;
+    int x = curveStart;
+    line1[index++] = x + 1;
+    line1[index++] = size.y - BORDER_STRIPE;
+    for (int i = 0; i < curve.length/2; i++) {
+        line1[index++]=x+curve[2*i];
+        line1[index++]=curve[2*i+1];
+    }
+    line1[index++] = x + curve_width;
+    line1[index++] = 0;
+    line1[index++] = size.x;
+    line1[index++] = 0;
+
+    Color background = getBackground();
+
+    if (getDisplay().getDepth() >= 15) {
+        // Anti- aliasing
+        int[] line2 = new int[line1.length];
+        index = 0;
+        for (int i = 0; i < line1.length/2; i++) {
+            line2[index] = line1[index++]  - 1;
+            line2[index] = line1[index++];
+        }
+        int[] line3 = new int[line1.length];
+        index = 0;
+        for (int i = 0; i < line1.length/2; i++) {
+            line3[index] = line1[index++] + 1;
+            line3[index] = line1[index++];
+        }
+        RGB from = border1.getRGB();
+        RGB to = background.getRGB();
+        int red = from.red + 3*(to.red - from.red)/4;
+        int green = from.green + 3*(to.green - from.green)/4;
+        int blue = from.blue + 3*(to.blue - from.blue)/4;
+        Color color = new Color(getDisplay(), red, green, blue);
+        gc.setForeground(color);
+        gc.drawPolyline(line2);
+        gc.drawPolyline(line3);
+        color.dispose();
+
+        // draw tail fading to background
+        int x1 = Math.max(0, curveStart - CURVE_TAIL);
+        gc.setForeground(background);
+        gc.setBackground(border1);
+        gc.fillGradientRectangle(x1, size.y - BORDER_STRIPE, curveStart-x1+1, 1, false);
+    } else {
+        // draw solid tail
+        int x1 = Math.max(0, curveStart - CURVE_TAIL);
+        gc.setForeground(border1);
+        gc.drawLine(x1, size.y - BORDER_STRIPE, curveStart+1, size.y - BORDER_STRIPE);
+    }
+
+    // draw border
+    gc.setForeground(border1);
+    gc.drawPolyline(line1);
+}
+
+void onResize() {
+    updateCurve(getSize().y);
+}
+/**
+* Set the control that appears on the bottom side of the banner.
+* The bottom control is optional.  Setting the bottom control to null will remove it from
+* the banner - however, the creator of the control must dispose of the control.
+*
+* @param control the control to be displayed on the bottom or null
+*
+* @exception DWTException <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>
+*    <li>ERROR_INVALID_ARGUMENT - if the bottom control was not created as a child of the receiver</li>
+* </ul>
+*
+* @since 3.0
+*/
+public void setBottom(Control control) {
+    checkWidget();
+    if (control !is null && control.getParent() !is this) {
+        DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    }
+    if (bottom !is null && !bottom.isDisposed()) {
+        Point size = bottom.getSize();
+        bottom.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y);
+    }
+    bottom = control;
+    layout(false);
+}
+/**
+ * Sets the layout which is associated with the receiver to be
+ * the argument which may be null.
+ * <p>
+ * Note: No Layout can be set on this Control because it already
+ * manages the size and position of its children.
+ * </p>
+ *
+ * @param layout the receiver's new layout or null
+ *
+ * @exception DWTException <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>
+ */
+public void setLayout (Layout layout) {
+    checkWidget();
+    return;
+}
+
+/**
+* Set the control that appears on the left side of the banner.
+* The left control is optional.  Setting the left control to null will remove it from
+* the banner - however, the creator of the control must dispose of the control.
+*
+* @param control the control to be displayed on the left or null
+*
+* @exception DWTException <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>
+*    <li>ERROR_INVALID_ARGUMENT - if the left control was not created as a child of the receiver</li>
+* </ul>
+*
+* @since 3.0
+*/
+public void setLeft(Control control) {
+    checkWidget();
+    if (control !is null && control.getParent() !is this) {
+        DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    }
+    if (left !is null && !left.isDisposed()) {
+        Point size = left.getSize();
+        left.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y);
+    }
+    left = control;
+    layout(false);
+}
+/**
+* Set the control that appears on the right side of the banner.
+* The right control is optional.  Setting the right control to null will remove it from
+* the banner - however, the creator of the control must dispose of the control.
+*
+* @param control the control to be displayed on the right or null
+*
+* @exception DWTException <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>
+*    <li>ERROR_INVALID_ARGUMENT - if the right control was not created as a child of the receiver</li>
+* </ul>
+*
+* @since 3.0
+*/
+public void setRight(Control control) {
+    checkWidget();
+    if (control !is null && control.getParent() !is this) {
+        DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    }
+    if (right !is null && !right.isDisposed()) {
+        Point size = right.getSize();
+        right.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y);
+    }
+    right = control;
+    layout(false);
+}
+/**
+ * Set the minimum height of the control that appears on the right side of the banner.
+ *
+ * @param size the minimum size of the control on the right
+ *
+ * @exception DWTException <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>
+ *    <li>ERROR_INVALID_ARGUMENT - if the size is null or the values of size are less than DWT.DEFAULT</li>
+ * </ul>
+ *
+ * @since 3.1
+ */
+public void setRightMinimumSize(Point size) {
+    checkWidget();
+    if (size is null || size.x < DWT.DEFAULT || size.y < DWT.DEFAULT) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    rightMinWidth = size.x;
+    rightMinHeight = size.y;
+    layout(false);
+}
+/**
+ * Set the width of the control that appears on the right side of the banner.
+ *
+ * @param width the width of the control on the right
+ *
+ * @exception DWTException <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>
+ *    <li>ERROR_INVALID_ARGUMENT - if width is less than DWT.DEFAULT</li>
+ * </ul>
+ *
+ * @since 3.0
+ */
+public void setRightWidth(int width) {
+    checkWidget();
+    if (width < DWT.DEFAULT) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    rightWidth = width;
+    layout(false);
+}
+/**
+ * Sets the shape that the CBanner will use to render itself.
+ *
+ * @param simple <code>true</code> if the CBanner should render itself in a simple, traditional style
+ *
+ * @exception DWTException <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.0
+ */
+public void setSimple(bool simple) {
+    checkWidget();
+    if (this.simple !is simple) {
+        this.simple = simple;
+        if (simple) {
+            curve_width = 5;
+            curve_indent = -2;
+        } else {
+            curve_width = 50;
+            curve_indent = 5;
+        }
+        updateCurve(getSize().y);
+        layout(false);
+        redraw();
+    }
+}
+void updateCurve(int height) {
+    int h = height - BORDER_STRIPE;
+    if (simple) {
+        curve = [0,h, 1,h, 2,h-1, 3,h-2,
+                                   3,2, 4,1, 5,0];
+    } else {
+        curve = bezier(0, h+1, BEZIER_LEFT, h+1,
+                             curve_width-BEZIER_RIGHT, 0, curve_width, 0,
+                             curve_width);
+    }
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/custom/CBannerLayout.d	Fri Jan 18 02:57:41 2008 +0100
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.custom.CBannerLayout;
+
+
+import dwt.DWT;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Composite;
+import dwt.widgets.Control;
+import dwt.widgets.Layout;
+import dwt.widgets.Scrollable;
+import dwt.custom.CBanner;
+import dwt.custom.CLayoutData;
+
+import Math = tango.math.Math;
+
+/**
+ * This class provides the layout for CBanner
+ *
+ * @see CBanner
+ */
+class CBannerLayout : Layout {
+
+protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
+    CBanner banner = cast(CBanner)composite;
+    Control left = banner.left;
+    Control right = banner.right;
+    Control bottom = banner.bottom;
+    bool showCurve = left !is null && right !is null;
+    int height = hHint;
+    int width = wHint;
+
+    // Calculate component sizes
+    Point bottomSize = new Point(0, 0);
+    if (bottom !is null) {
+        int trim = computeTrim(bottom);
+        int w = wHint is DWT.DEFAULT ? DWT.DEFAULT : Math.max(0, width - trim);
+        bottomSize = computeChildSize(bottom, w, DWT.DEFAULT, flushCache);
+    }
+    Point rightSize = new Point(0, 0);
+    if (right !is null) {
+        int trim = computeTrim(right);
+        int w = DWT.DEFAULT;
+        if (banner.rightWidth !is DWT.DEFAULT) {
+            w = banner.rightWidth - trim;
+            if (left !is null) {
+                w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim);
+            }
+            w = Math.max(0, w);
+        }
+        rightSize = computeChildSize(right, w, DWT.DEFAULT, flushCache);
+        if (wHint !is DWT.DEFAULT) {
+            width -= rightSize.x + banner.curve_width - 2* banner.curve_indent;
+        }
+    }
+    Point leftSize = new Point(0, 0);
+    if (left !is null) {
+        int trim = computeTrim(left);
+        int w = wHint is DWT.DEFAULT ? DWT.DEFAULT : Math.max(0, width - trim);
+        leftSize = computeChildSize(left, w, DWT.DEFAULT, flushCache);
+    }
+
+    // Add up sizes
+    width = leftSize.x + rightSize.x;
+    height = bottomSize.y;
+    if (bottom !is null && (left !is null || right !is null)) {
+        height += CBanner.BORDER_STRIPE + 2;
+    }
+    if (left !is null) {
+        if (right is null) {
+            height += leftSize.y;
+        } else {
+            height += Math.max(leftSize.y, banner.rightMinHeight is DWT.DEFAULT ? rightSize.y : banner.rightMinHeight);
+        }
+    } else {
+        height += rightSize.y;
+    }
+    if (showCurve) {
+        width += banner.curve_width - 2*banner.curve_indent;
+        height +=  CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE;
+    }
+
+    if (wHint !is DWT.DEFAULT) width = wHint;
+    if (hHint !is DWT.DEFAULT) height = hHint;
+
+    return new Point(width, height);
+}
+Point computeChildSize(Control control, int wHint, int hHint, bool flushCache) {
+    Object data = control.getLayoutData();
+    if (data is null || !( null !is cast(CLayoutData)data)) {
+        data = new CLayoutData();
+        control.setLayoutData(data);
+    }
+    return (cast(CLayoutData)data).computeSize(control, wHint, hHint, flushCache);
+}
+int computeTrim(Control c) {
+    if ( auto s = cast(Scrollable)c) {
+        Rectangle rect = s.computeTrim (0, 0, 0, 0);
+        return rect.width;
+    }
+    return c.getBorderWidth () * 2;
+}
+protected bool flushCache(Control control) {
+    Object data = control.getLayoutData();
+    if ( auto ld = cast(CLayoutData)data ) ld.flushCache();
+    return true;
+}
+protected void layout(Composite composite, bool flushCache) {
+    CBanner banner = cast(CBanner)composite;
+    Control left = banner.left;
+    Control right = banner.right;
+    Control bottom = banner.bottom;
+
+    Point size = banner.getSize();
+    bool showCurve = left !is null && right !is null;
+    int width = size.x - 2*banner.getBorderWidth();
+    int height = size.y - 2*banner.getBorderWidth();
+
+    Point bottomSize = new Point(0, 0);
+    if (bottom !is null) {
+        int trim = computeTrim(bottom);
+        int w = Math.max(0, width - trim);
+        bottomSize = computeChildSize(bottom, w, DWT.DEFAULT, flushCache);
+        height -= bottomSize.y + CBanner.BORDER_STRIPE + 2;
+    }
+    if (showCurve) height -=  CBanner.BORDER_TOP + CBanner.BORDER_BOTTOM + 2*CBanner.BORDER_STRIPE;
+    height = Math.max(0, height);
+    Point rightSize = new Point(0,0);
+    if (right !is null) {
+        int trim = computeTrim(right);
+        int w = DWT.DEFAULT;
+        if (banner.rightWidth !is DWT.DEFAULT) {
+            w = banner.rightWidth - trim;
+            if (left !is null) {
+                w = Math.min(w, width - banner.curve_width + 2* banner.curve_indent - CBanner.MIN_LEFT - trim);
+            }
+            w = Math.max(0, w);
+        }
+        rightSize = computeChildSize(right, w, DWT.DEFAULT, flushCache);
+        width = width - (rightSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent);
+    }
+    Point leftSize = new Point(0, 0);
+    if (left !is null) {
+        int trim = computeTrim(left);
+        int w = Math.max(0, width - trim);
+        leftSize = computeChildSize(left, w, DWT.DEFAULT, flushCache);
+    }
+
+    int x = 0;
+    int y = 0;
+    int oldStart = banner.curveStart;
+    Rectangle leftRect = null;
+    Rectangle rightRect = null;
+    Rectangle bottomRect = null;
+    if (bottom !is null) {
+        bottomRect = new Rectangle(x, y+size.y-bottomSize.y, bottomSize.x, bottomSize.y);
+    }
+    if (showCurve) y += CBanner.BORDER_TOP + CBanner.BORDER_STRIPE;
+    if(left !is null) {
+        leftRect = new Rectangle(x, y, leftSize.x, leftSize.y);
+        banner.curveStart = x + leftSize.x - banner.curve_indent;
+        x += leftSize.x - banner.curve_indent + banner.curve_width - banner.curve_indent;
+    }
+    if (right !is null) {
+        if (left !is null) {
+            rightSize.y = Math.max(leftSize.y, banner.rightMinHeight is DWT.DEFAULT ? rightSize.y : banner.rightMinHeight);
+        }
+        rightRect = new Rectangle(x, y, rightSize.x, rightSize.y);
+    }
+    if (banner.curveStart < oldStart) {
+        banner.redraw(banner.curveStart - CBanner.CURVE_TAIL, 0, oldStart + banner.curve_width - banner.curveStart + CBanner.CURVE_TAIL + 5, size.y, false);
+    }
+    if (banner.curveStart > oldStart) {
+        banner.redraw(oldStart - CBanner.CURVE_TAIL, 0, banner.curveStart + banner.curve_width - oldStart + CBanner.CURVE_TAIL + 5, size.y, false);
+    }
+    /*
+     * The paint events must be flushed in order to make the curve draw smoothly
+     * while the user drags the divider.
+     * On Windows, it is necessary to flush the paints before the children are
+     * resized because otherwise the children (particularly toolbars) will flash.
+     */
+    banner.update();
+    banner.curveRect = new Rectangle(banner.curveStart, 0, banner.curve_width, size.y);
+    if (bottomRect !is null) bottom.setBounds(bottomRect);
+    if (rightRect !is null) right.setBounds(rightRect);
+    if (leftRect !is null) left.setBounds(leftRect);
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/custom/CLayoutData.d	Fri Jan 18 02:57:41 2008 +0100
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.custom.CLayoutData;
+
+
+import dwt.DWT;
+import dwt.graphics.Point;
+import dwt.widgets.Control;
+
+class CLayoutData {
+
+    int defaultWidth = -1, defaultHeight = -1;
+    int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
+
+Point computeSize (Control control, int wHint, int hHint, bool flushCache_) {
+    if (flushCache_) flushCache();
+    if (wHint is DWT.DEFAULT && hHint is DWT.DEFAULT) {
+        if (defaultWidth is -1 || defaultHeight is -1) {
+            Point size = control.computeSize (wHint, hHint, flushCache_);
+            defaultWidth = size.x;
+            defaultHeight = size.y;
+        }
+        return new Point(defaultWidth, defaultHeight);
+    }
+    if (currentWidth is -1 || currentHeight is -1 || wHint !is currentWhint || hHint !is currentHhint) {
+        Point size = control.computeSize (wHint, hHint, flushCache_);
+        currentWhint = wHint;
+        currentHhint = hHint;
+        currentWidth = size.x;
+        currentHeight = size.y;
+    }
+    return new Point(currentWidth, currentHeight);
+}
+void flushCache () {
+    defaultWidth = defaultHeight = -1;
+    currentWidth = currentHeight = -1;
+}
+}