Mercurial > projects > dwt-mac
diff dwt/layout/FormData.d @ 40:fbe68c33eeee
Sync layout with dwt-linux
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 14:41:31 +0200 |
parents | e831403a80a9 |
children | d8635bb48c7c |
line wrap: on
line diff
--- a/dwt/layout/FormData.d Tue Oct 07 14:41:16 2008 +0200 +++ b/dwt/layout/FormData.d Tue Oct 07 14:41:31 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -7,22 +7,26 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwt.layout.FormData; -import dwt.dwthelper.utils; - import dwt.DWT; import dwt.graphics.Point; import dwt.widgets.Control; +import dwt.layout.FormAttachment; + +import tango.util.Convert; +import dwt.dwthelper.utils; /** - * Instances of this class are used to define the attachments - * of a control in a <code>FormLayout</code>. + * Instances of this class are used to define the attachments + * of a control in a <code>FormLayout</code>. * <p> - * To set a <code>FormData</code> object into a control, you use the - * <code>setLayoutData ()</code> method. To define attachments for the + * To set a <code>FormData</code> object into a control, you use the + * <code>setLayoutData ()</code> method. To define attachments for the * <code>FormData</code>, set the fields directly, like this: * <pre> * FormData data = new FormData(); @@ -32,22 +36,23 @@ * </pre> * </p> * <p> - * <code>FormData</code> contains the <code>FormAttachments</code> for + * <code>FormData</code> contains the <code>FormAttachments</code> for * each edge of the control that the <code>FormLayout</code> uses to * determine the size and position of the control. <code>FormData</code> * objects also allow you to set the width and height of controls within - * a <code>FormLayout</code>. + * a <code>FormLayout</code>. * </p> - * + * * @see FormLayout * @see FormAttachment - * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * * @since 2.0 */ public final class FormData { /** * width specifies the preferred width in pixels. This value - * is the wHint passed into Control.computeSize(int, int, bool) + * is the wHint passed into Control.computeSize(int, int, bool) * to determine the preferred size of the control. * * The default value is DWT.DEFAULT. @@ -57,7 +62,7 @@ public int width = DWT.DEFAULT; /** * height specifies the preferred height in pixels. This value - * is the hHint passed into Control.computeSize(int, int, bool) + * is the hHint passed into Control.computeSize(int, int, bool) * to determine the preferred size of the control. * * The default value is DWT.DEFAULT. @@ -66,7 +71,7 @@ */ public int height = DWT.DEFAULT; /** - * left specifies the attachment of the left side of + * left specifies the attachment of the left side of * the control. */ public FormAttachment left; @@ -84,25 +89,25 @@ * control. */ public FormAttachment bottom; - + int cacheWidth = -1, cacheHeight = -1; int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1; int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1; FormAttachment cacheLeft, cacheRight, cacheTop, cacheBottom; bool isVisited, needed; - + /** * Constructs a new instance of FormData using * default values. */ public this () { } - + /** * Constructs a new instance of FormData according to the parameters. * A value of DWT.DEFAULT indicates that no minimum width or * no minimum height is specified. - * + * * @param width a minimum width for the control * @param height a minimum height for the control */ @@ -111,11 +116,11 @@ this.height = height; } -void computeSize (Control control, int wHint, int hHint, bool flushCache) { +void computeSize (Control control, int wHint, int hHint, bool flushCache_) { if (cacheWidth !is -1 && cacheHeight !is -1) return; if (wHint is this.width && hHint is this.height) { if (defaultWidth is -1 || defaultHeight is -1 || wHint !is defaultWhint || hHint !is defaultHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); + Point size = control.computeSize (wHint, hHint, flushCache_); defaultWhint = wHint; defaultHhint = hHint; defaultWidth = size.x; @@ -126,7 +131,7 @@ return; } if (currentWidth is -1 || currentHeight is -1 || wHint !is currentWhint || hHint !is currentHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); + Point size = control.computeSize (wHint, hHint, flushCache_); currentWhint = wHint; currentHhint = hHint; currentWidth = size.x; @@ -175,7 +180,7 @@ FormData bottomData = cast(FormData) bottomControl.getLayoutData (); FormAttachment bottomAttachment = bottomData.getBottomAttachment (bottomControl, spacing, flushCache); switch (bottom.alignment) { - case DWT.BOTTOM: + case DWT.BOTTOM: cacheBottom = bottomAttachment.plus (bottom.offset); break; case DWT.CENTER: { @@ -186,7 +191,7 @@ } default: { FormAttachment topAttachment = bottomData.getTopAttachment (bottomControl, spacing, flushCache); - cacheBottom = topAttachment.plus (bottom.offset - spacing); + cacheBottom = topAttachment.plus (bottom.offset - spacing); break; } } @@ -227,18 +232,18 @@ } default: { FormAttachment rightAttachment = leftData.getRightAttachment (leftControl, spacing, flushCache); - cacheLeft = rightAttachment.plus (left.offset + spacing); + cacheLeft = rightAttachment.plus (left.offset + spacing); } } - isVisited = false; + isVisited = false; return cacheLeft; } - + String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index is -1) return string; - return string.substring (index + 1, string.length ()); + String string = this.classinfo.name; + int index = string.lastIndexOf( '.'); + if (index is -1 ) return string; + return string[ index + 1 .. string.length ]; } FormAttachment getRightAttachment (Control control, int spacing, bool flushCache) { @@ -263,7 +268,7 @@ FormData rightData = cast(FormData) rightControl.getLayoutData (); FormAttachment rightAttachment = rightData.getRightAttachment (rightControl, spacing, flushCache); switch (right.alignment) { - case DWT.RIGHT: + case DWT.RIGHT: cacheRight = rightAttachment.plus (right.offset); break; case DWT.CENTER: { @@ -329,16 +334,16 @@ * * @return a string representation of the FormData object */ -public String toString () { - String string = getName()+" {"; - if (width !is DWT.DEFAULT) string += "width="+width+" "; - if (height !is DWT.DEFAULT) string += "height="+height+" "; - if (left !is null) string += "left="+left+" "; - if (right !is null) string += "right="+right+" "; - if (top !is null) string += "top="+top+" "; - if (bottom !is null) string += "bottom="+bottom+" "; +override public String toString () { + String string = getName()~" {"; + if (width !is DWT.DEFAULT) string ~= "width="~to!(String)(width)~" "; + if (height !is DWT.DEFAULT) string ~= "height="~to!(String)(height)~" "; + if (left !is null) string ~= "left="~to!(String)(left)~" "; + if (right !is null) string ~= "right="~to!(String)(right)~" "; + if (top !is null) string ~= "top="~to!(String)(top)~" "; + if (bottom !is null) string ~= "bottom="~to!(String)(bottom)~" "; string = string.trim(); - string += "}"; + string ~= "}"; return string; }