changeset 96:aee1890f38c3

SashForm, SashFromData, SashFromLayout
author Frank Benoit <benoit@tionex.de>
date Fri, 08 Feb 2008 11:57:24 +0100
parents 04d34191e2e9
children 2e6eb5bd2c16
files dwt/custom/SashForm.d dwt/custom/SashFormData.d dwt/custom/SashFormLayout.d dwt/widgets/Button.d
diffstat 4 files changed, 654 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/custom/SashForm.d	Fri Feb 08 11:57:24 2008 +0100
@@ -0,0 +1,406 @@
+/*******************************************************************************
+ * 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
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwt.custom.SashForm;
+
+
+
+import dwt.DWT;
+import dwt.DWTException;
+import dwt.graphics.Color;
+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.widgets.Sash;
+import dwt.custom.SashFormLayout;
+import dwt.custom.SashFormData;
+
+import dwt.dwthelper.utils;
+
+/**
+ * The SashForm is a composite control that lays out its children in a
+ * row or column arrangement (as specified by the orientation) and places
+ * a Sash between each child. One child may be maximized to occupy the
+ * entire size of the SashForm.  The relative sizes of the children may
+ * be specified using weights.
+ * <p>
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
+ * </dl>
+ * </p>
+ */
+public class SashForm : Composite {
+
+    public int SASH_WIDTH = 3;
+
+    int sashStyle;
+    Sash[] sashes;
+    // Remember background and foreground
+    // colors to determine whether to set
+    // sashes to the default color (null) or
+    // a specific color
+    Color background = null;
+    Color foreground = null;
+    Control[] controls;
+    Control maxControl = null;
+    Listener sashListener;
+    static const int DRAG_MINIMUM = 20;
+
+/**
+ * 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>
+ *
+ * @see DWT#HORIZONTAL
+ * @see DWT#VERTICAL
+ * @see #getStyle()
+ */
+public this(Composite parent, int style) {
+    super(parent, checkStyle(style));
+    super.setLayout(new SashFormLayout());
+    sashStyle = ((style & DWT.VERTICAL) !is 0) ? DWT.HORIZONTAL : DWT.VERTICAL;
+    if ((style & DWT.BORDER) !is 0) sashStyle |= DWT.BORDER;
+    if ((style & DWT.SMOOTH) !is 0) sashStyle |= DWT.SMOOTH;
+    sashListener = new class() Listener {
+        public void handleEvent(Event e) {
+            onDragSash(e);
+        }
+    };
+}
+static int checkStyle (int style) {
+    int mask = DWT.BORDER | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
+    return style & mask;
+}
+/**
+ * Returns DWT.HORIZONTAL if the controls in the SashForm are laid out side by side
+ * or DWT.VERTICAL   if the controls in the SashForm are laid out top to bottom.
+ *
+ * @return DWT.HORIZONTAL or DWT.VERTICAL
+ */
+public int getOrientation() {
+    //checkWidget();
+    return (sashStyle & DWT.VERTICAL) !is 0 ? DWT.HORIZONTAL : DWT.VERTICAL;
+}
+public override int getStyle() {
+    int style = super.getStyle();
+    style |= getOrientation() is DWT.VERTICAL ? DWT.VERTICAL : DWT.HORIZONTAL;
+    if ((sashStyle & DWT.SMOOTH) !is 0) style |= DWT.SMOOTH;
+    return style;
+}
+/**
+ * Answer the control that currently is maximized in the SashForm.
+ * This value may be null.
+ *
+ * @return the control that currently is maximized or null
+ */
+public Control getMaximizedControl(){
+    //checkWidget();
+    return this.maxControl;
+}
+/**
+ * Answer the relative weight of each child in the SashForm.  The weight represents the
+ * percent of the total width (if SashForm has Horizontal orientation) or
+ * total height (if SashForm has Vertical orientation) each control occupies.
+ * The weights are returned in order of the creation of the widgets (weight[0]
+ * corresponds to the weight of the first child created).
+ *
+ * @return the relative weight of each child
+ *
+ * @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 int[] getWeights() {
+    checkWidget();
+    Control[] cArray = getControls(false);
+    int[] ratios = new int[cArray.length];
+    for (int i = 0; i < cArray.length; i++) {
+        Object data = cArray[i].getLayoutData();
+        if ( auto sfd = cast(SashFormData)data ) {
+            ratios[i] = cast(int)(sfd.weight * 1000 >> 16);
+        } else {
+            ratios[i] = 200;
+        }
+    }
+    return ratios;
+}
+Control[] getControls(bool onlyVisible) {
+    Control[] children = getChildren();
+    Control[] result = new Control[0];
+    for (int i = 0; i < children.length; i++) {
+        if ( null !is cast(Sash)children[i]) continue;
+        if (onlyVisible && !children[i].getVisible()) continue;
+
+        Control[] newResult = new Control[result.length + 1];
+        System.arraycopy(result, 0, newResult, 0, result.length);
+        newResult[result.length] = children[i];
+        result = newResult;
+    }
+    return result;
+}
+void onDragSash(Event event) {
+    Sash sash = cast(Sash)event.widget;
+    int sashIndex = -1;
+    for (int i= 0; i < sashes.length; i++) {
+        if (sashes[i] is sash) {
+            sashIndex = i;
+            break;
+        }
+    }
+    if (sashIndex is -1) return;
+
+    Control c1 = controls[sashIndex];
+    Control c2 = controls[sashIndex + 1];
+    Rectangle b1 = c1.getBounds();
+    Rectangle b2 = c2.getBounds();
+
+    Rectangle sashBounds = sash.getBounds();
+    Rectangle area = getClientArea();
+    bool correction = false;
+    if (getOrientation() is DWT.HORIZONTAL) {
+        correction = b1.width < DRAG_MINIMUM || b2.width < DRAG_MINIMUM;
+        int totalWidth = b2.x + b2.width - b1.x;
+        int shift = event.x - sashBounds.x;
+        b1.width += shift;
+        b2.x += shift;
+        b2.width -= shift;
+        if (b1.width < DRAG_MINIMUM) {
+            b1.width = DRAG_MINIMUM;
+            b2.x = b1.x + b1.width + sashBounds.width;
+            b2.width = totalWidth - b2.x;
+            event.x = b1.x + b1.width;
+            event.doit = false;
+        }
+        if (b2.width < DRAG_MINIMUM) {
+            b1.width = totalWidth - DRAG_MINIMUM - sashBounds.width;
+            b2.x = b1.x + b1.width + sashBounds.width;
+            b2.width = DRAG_MINIMUM;
+            event.x = b1.x + b1.width;
+            event.doit = false;
+        }
+        Object data1 = c1.getLayoutData();
+        if (data1 is null || !( null !is cast(SashFormData)data1 )) {
+            data1 = new SashFormData();
+            c1.setLayoutData(data1);
+        }
+        Object data2 = c2.getLayoutData();
+        if (data2 is null || !( null !is cast(SashFormData)data2 )) {
+            data2 = new SashFormData();
+            c2.setLayoutData(data2);
+        }
+        (cast(SashFormData)data1).weight = ((cast(long)b1.width << 16) + area.width - 1) / area.width;
+        (cast(SashFormData)data2).weight = ((cast(long)b2.width << 16) + area.width - 1) / area.width;
+    } else {
+        correction = b1.height < DRAG_MINIMUM || b2.height < DRAG_MINIMUM;
+        int totalHeight = b2.y + b2.height - b1.y;
+        int shift = event.y - sashBounds.y;
+        b1.height += shift;
+        b2.y += shift;
+        b2.height -= shift;
+        if (b1.height < DRAG_MINIMUM) {
+            b1.height = DRAG_MINIMUM;
+            b2.y = b1.y + b1.height + sashBounds.height;
+            b2.height = totalHeight - b2.y;
+            event.y = b1.y + b1.height;
+            event.doit = false;
+        }
+        if (b2.height < DRAG_MINIMUM) {
+            b1.height = totalHeight - DRAG_MINIMUM - sashBounds.height;
+            b2.y = b1.y + b1.height + sashBounds.height;
+            b2.height = DRAG_MINIMUM;
+            event.y = b1.y + b1.height;
+            event.doit = false;
+        }
+        Object data1 = c1.getLayoutData();
+        if (data1 is null || !( null !is cast(SashFormData)data1 )) {
+            data1 = new SashFormData();
+            c1.setLayoutData(data1);
+        }
+        Object data2 = c2.getLayoutData();
+        if (data2 is null || !(null !is cast(SashFormData)data2 )) {
+            data2 = new SashFormData();
+            c2.setLayoutData(data2);
+        }
+        (cast(SashFormData)data1).weight = ((cast(long)b1.height << 16) + area.height - 1) / area.height;
+        (cast(SashFormData)data2).weight = ((cast(long)b2.height << 16) + area.height - 1) / area.height;
+    }
+    if (correction || (event.doit && event.detail !is DWT.DRAG)) {
+        c1.setBounds(b1);
+        sash.setBounds(event.x, event.y, event.width, event.height);
+        c2.setBounds(b2);
+    }
+}
+/**
+ * If orientation is DWT.HORIZONTAL, lay the controls in the SashForm
+ * out side by side.  If orientation is DWT.VERTICAL, lay the
+ * controls in the SashForm out top to bottom.
+ *
+ * @param orientation DWT.HORIZONTAL or DWT.VERTICAL
+ *
+ * @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 value of orientation is not DWT.HORIZONTAL or DWT.VERTICAL
+ * </ul>
+ */
+public void setOrientation(int orientation) {
+    checkWidget();
+    if (getOrientation() is orientation) return;
+    if (orientation !is DWT.HORIZONTAL && orientation !is DWT.VERTICAL) {
+        DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    }
+    sashStyle &= ~(DWT.HORIZONTAL | DWT.VERTICAL);
+    sashStyle |= orientation is DWT.VERTICAL ? DWT.HORIZONTAL : DWT.VERTICAL;
+    for (int i = 0; i < sashes.length; i++) {
+        sashes[i].dispose();
+        sashes[i] = new Sash(this, sashStyle);
+        sashes[i].setBackground(background);
+        sashes[i].setForeground(foreground);
+        sashes[i].addListener(DWT.Selection, sashListener);
+    }
+    layout(false);
+}
+public override void setBackground (Color color) {
+    super.setBackground(color);
+    background = color;
+    for (int i = 0; i < sashes.length; i++) {
+        sashes[i].setBackground(background);
+    }
+}
+public override void setForeground (Color color) {
+    super.setForeground(color);
+    foreground = color;
+    for (int i = 0; i < sashes.length; i++) {
+        sashes[i].setForeground(foreground);
+    }
+}
+/**
+ * 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 override void setLayout (Layout layout) {
+    checkWidget();
+    return;
+}
+/**
+ * Specify the control that should take up the entire client area of the SashForm.
+ * If one control has been maximized, and this method is called with a different control,
+ * the previous control will be minimized and the new control will be maximized.
+ * If the value of control is null, the SashForm will minimize all controls and return to
+ * the default layout where all controls are laid out separated by sashes.
+ *
+ * @param control the control to be maximized 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 setMaximizedControl(Control control){
+    checkWidget();
+    if (control is null) {
+        if (maxControl !is null) {
+            this.maxControl = null;
+            layout(false);
+            for (int i= 0; i < sashes.length; i++){
+                sashes[i].setVisible(true);
+            }
+        }
+        return;
+    }
+
+    for (int i= 0; i < sashes.length; i++){
+        sashes[i].setVisible(false);
+    }
+    maxControl = control;
+    layout(false);
+}
+
+/**
+ * Specify the relative weight of each child in the SashForm.  This will determine
+ * what percent of the total width (if SashForm has Horizontal orientation) or
+ * total height (if SashForm has Vertical orientation) each control will occupy.
+ * The weights must be positive values and there must be an entry for each
+ * non-sash child of the SashForm.
+ *
+ * @param weights the relative weight of each child
+ *
+ * @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 weights value is null or of incorrect length (must match the number of children)</li>
+ * </ul>
+ */
+public void setWeights(int[] weights) {
+    checkWidget();
+    Control[] cArray = getControls(false);
+    if (weights is null || weights.length !is cArray.length) {
+        DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    }
+
+    int total = 0;
+    for (int i = 0; i < weights.length; i++) {
+        if (weights[i] < 0) {
+            DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+        }
+        total += weights[i];
+    }
+    if (total is 0) {
+        DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    }
+    for (int i = 0; i < cArray.length; i++) {
+        Object data = cArray[i].getLayoutData();
+        if (data is null || !( null !is cast(SashFormData)data )) {
+            data = new SashFormData();
+            cArray[i].setLayoutData(data);
+        }
+        (cast(SashFormData)data).weight = ((cast(long)weights[i] << 16) + total - 1) / total;
+    }
+
+    layout(false);
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/custom/SashFormData.d	Fri Feb 08 11:57:24 2008 +0100
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 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
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwt.custom.SashFormData;
+
+static import tango.text.Util;
+import tango.util.Convert;
+
+class SashFormData {
+
+    long weight;
+
+char[] getName () {
+    char[] string = this.classinfo.name;
+    int index = tango.text.Util.locatePrior( string ,'.' );
+    if (index is string.length ) return string;
+    return string[ index + 1 .. $ ];
+}
+
+/**
+ * Returns a string containing a concise, human-readable
+ * description of the receiver.
+ *
+ * @return a string representation of the event
+ */
+public override char[] toString () {
+    return getName()~" {weight="~to!(char[])(weight)~"}"; //$NON-NLS-2$
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/custom/SashFormLayout.d	Fri Feb 08 11:57:24 2008 +0100
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 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
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwt.custom.SashFormLayout;
+
+
+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.Sash;
+import dwt.custom.SashForm;
+import dwt.custom.SashFormData;
+
+import dwt.dwthelper.utils;
+
+/**
+ * This class provides the layout for SashForm
+ *
+ * @see SashForm
+ */
+class SashFormLayout : Layout {
+protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
+    SashForm sashForm = cast(SashForm)composite;
+    Control[] cArray = sashForm.getControls(true);
+    int width = 0;
+    int height = 0;
+    if (cArray.length is 0) {
+        if (wHint !is DWT.DEFAULT) width = wHint;
+        if (hHint !is DWT.DEFAULT) height = hHint;
+        return new Point(width, height);
+    }
+    // determine control sizes
+    bool vertical = sashForm.getOrientation() is DWT.VERTICAL;
+    int maxIndex = 0;
+    int maxValue = 0;
+    for (int i = 0; i < cArray.length; i++) {
+        if (vertical) {
+            Point size = cArray[i].computeSize(wHint, DWT.DEFAULT, flushCache);
+            if (size.y > maxValue) {
+                maxIndex = i;
+                maxValue = size.y;
+            }
+            width = Math.max(width, size.x);
+        } else {
+            Point size = cArray[i].computeSize(DWT.DEFAULT, hHint, flushCache);
+            if (size.x > maxValue) {
+                maxIndex = i;
+                maxValue = size.x;
+            }
+            height = Math.max(height, size.y);
+        }
+    }
+    // get the ratios
+    long[] ratios = new long[cArray.length];
+    long total = 0;
+    for (int i = 0; i < cArray.length; i++) {
+        Object data = cArray[i].getLayoutData();
+        if ( auto sfd = cast(SashFormData)data) {
+            ratios[i] = sfd.weight;
+        } else {
+            data = new SashFormData();
+            cArray[i].setLayoutData(data);
+            (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000;
+
+        }
+        total += ratios[i];
+    }
+    if (ratios[maxIndex] > 0) {
+        int sashwidth = sashForm.sashes.length > 0 ? sashForm.SASH_WIDTH + sashForm.sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH;
+        if (vertical) {
+            height += cast(int)(total * maxValue / ratios[maxIndex]) + (cArray.length - 1) * sashwidth;
+        } else {
+            width += cast(int)(total * maxValue / ratios[maxIndex]) + (cArray.length - 1) * sashwidth;
+        }
+    }
+    width += sashForm.getBorderWidth()*2;
+    height += sashForm.getBorderWidth()*2;
+    if (wHint !is DWT.DEFAULT) width = wHint;
+    if (hHint !is DWT.DEFAULT) height = hHint;
+    return new Point(width, height);
+}
+
+protected override bool flushCache(Control control) {
+    return true;
+}
+
+protected override void layout(Composite composite, bool flushCache) {
+    SashForm sashForm = cast(SashForm)composite;
+    Rectangle area = sashForm.getClientArea();
+    if (area.width <= 1 || area.height <= 1) return;
+
+    Control[] newControls = sashForm.getControls(true);
+    if (sashForm.controls.length is 0 && newControls.length is 0) return;
+    sashForm.controls = newControls;
+
+    Control[] controls = sashForm.controls;
+
+    if (sashForm.maxControl !is null && !sashForm.maxControl.isDisposed()) {
+        for (int i= 0; i < controls.length; i++){
+            if (controls[i] !is sashForm.maxControl) {
+                controls[i].setBounds(-200, -200, 0, 0);
+            } else {
+                controls[i].setBounds(area);
+            }
+        }
+        return;
+    }
+
+    // keep just the right number of sashes
+    if (sashForm.sashes.length < controls.length - 1) {
+        Sash[] newSashes = new Sash[controls.length - 1];
+        System.arraycopy(sashForm.sashes, 0, newSashes, 0, sashForm.sashes.length);
+        for (int i = sashForm.sashes.length; i < newSashes.length; i++) {
+            newSashes[i] = new Sash(sashForm, sashForm.sashStyle);
+            newSashes[i].setBackground(sashForm.background);
+            newSashes[i].setForeground(sashForm.foreground);
+            newSashes[i].addListener(DWT.Selection, sashForm.sashListener);
+        }
+        sashForm.sashes = newSashes;
+    }
+    if (sashForm.sashes.length > controls.length - 1) {
+        if (controls.length is 0) {
+            for (int i = 0; i < sashForm.sashes.length; i++) {
+                sashForm.sashes[i].dispose();
+            }
+            sashForm.sashes = new Sash[0];
+        } else {
+            Sash[] newSashes = new Sash[controls.length - 1];
+            System.arraycopy(sashForm.sashes, 0, newSashes, 0, newSashes.length);
+            for (int i = controls.length - 1; i < sashForm.sashes.length; i++) {
+                sashForm.sashes[i].dispose();
+            }
+            sashForm.sashes = newSashes;
+        }
+    }
+    if (controls.length is 0) return;
+    Sash[] sashes = sashForm.sashes;
+    // get the ratios
+    long[] ratios = new long[controls.length];
+    long total = 0;
+    for (int i = 0; i < controls.length; i++) {
+        Object data = controls[i].getLayoutData();
+        if ( auto sfd = cast(SashFormData)data ) {
+            ratios[i] = sfd.weight;
+        } else {
+            data = new SashFormData();
+            controls[i].setLayoutData(data);
+            (cast(SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000;
+
+        }
+        total += ratios[i];
+    }
+
+    int sashwidth = sashes.length > 0 ? sashForm.SASH_WIDTH + sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH;
+    if (sashForm.getOrientation() is DWT.HORIZONTAL) {
+        int width = cast(int)(ratios[0] * (area.width - sashes.length * sashwidth) / total);
+        int x = area.x;
+        controls[0].setBounds(x, area.y, width, area.height);
+        x += width;
+        for (int i = 1; i < controls.length - 1; i++) {
+            sashes[i - 1].setBounds(x, area.y, sashwidth, area.height);
+            x += sashwidth;
+            width = cast(int)(ratios[i] * (area.width - sashes.length * sashwidth) / total);
+            controls[i].setBounds(x, area.y, width, area.height);
+            x += width;
+        }
+        if (controls.length > 1) {
+            sashes[sashes.length - 1].setBounds(x, area.y, sashwidth, area.height);
+            x += sashwidth;
+            width = area.width - x;
+            controls[controls.length - 1].setBounds(x, area.y, width, area.height);
+        }
+    } else {
+        int height = cast(int)(ratios[0] * (area.height - sashes.length * sashwidth) / total);
+        int y = area.y;
+        controls[0].setBounds(area.x, y, area.width, height);
+        y += height;
+        for (int i = 1; i < controls.length - 1; i++) {
+            sashes[i - 1].setBounds(area.x, y, area.width, sashwidth);
+            y += sashwidth;
+            height = cast(int)(ratios[i] * (area.height - sashes.length * sashwidth) / total);
+            controls[i].setBounds(area.x, y, area.width, height);
+            y += height;
+        }
+        if (controls.length > 1) {
+            sashes[sashes.length - 1].setBounds(area.x, y, area.width, sashwidth);
+            y += sashwidth;
+            height = area.height - y;
+            controls[controls.length - 1].setBounds(area.x, y, area.width, height);
+        }
+
+    }
+}
+}
--- a/dwt/widgets/Button.d	Thu Feb 07 02:08:50 2008 +0100
+++ b/dwt/widgets/Button.d	Fri Feb 08 11:57:24 2008 +0100
@@ -360,7 +360,7 @@
 
 override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) {
     if (handle is null) return LRESULT.ZERO;
-    return cast(LRESULT) ButtonProc( hwnd, msg, wParam, lParam);
+    return cast(LRESULT) OS.CallWindowProc ( ButtonProc, hwnd, msg, wParam, lParam);
 }
 
 static int checkStyle (int style) {
@@ -401,7 +401,7 @@
         auto hDC = OS.GetDC (handle);
         HFONT newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
         if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont);
-        TCHAR* buffer = StrToTCHARz(text);
+        TCHAR* buffer = StrToTCHARz( getCodePage (), text);
         RECT rect;
         int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
         OS.DrawText (hDC, buffer, -1, &rect, flags);
@@ -477,7 +477,7 @@
                     height = Math.max (height, lptm.tmHeight);
                 } else {
                     extra = Math.max (MARGIN * 2, lptm.tmAveCharWidth);
-                    TCHAR* buffer = StrToTCHARz(text);
+                    TCHAR* buffer = StrToTCHARz( getCodePage (), text);
                     RECT rect;
                     int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
                     OS.DrawText (hDC, buffer, -1, &rect, flags);
@@ -547,7 +547,7 @@
             bool hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) !is 0;
             if (!hasImage) {
                 char[] string = enabled ? text : " " ~ text ~ " ";
-                TCHAR* buffer = StrToTCHARz (string);
+                TCHAR* buffer = StrToTCHARz (getCodePage (), string);
                 OS.SetWindowText (handle, buffer);
             }
         }