Mercurial > projects > dwt-mac
diff dwt/layout/FillLayout.d @ 40:fbe68c33eeee
Sync layout with dwt-linux
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 14:41:31 +0200 |
parents | a9ab4c738ed8 |
children | d8635bb48c7c |
line wrap: on
line diff
--- a/dwt/layout/FillLayout.d Tue Oct 07 14:41:16 2008 +0200 +++ b/dwt/layout/FillLayout.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,36 +7,40 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwt.layout.FillLayout; -import dwt.dwthelper.utils; - 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.Composite; import dwt.widgets.Scrollable; +import dwt.layout.FillData; + +import tango.util.Convert; +import dwt.dwthelper.utils; /** - * <code>FillLayout</code> is the simplest layout class. It lays out - * controls in a single row or column, forcing them to be the same size. + * <code>FillLayout</code> is the simplest layout class. It lays out + * controls in a single row or column, forcing them to be the same size. * <p> - * Initially, the controls will all be as tall as the tallest control, - * and as wide as the widest. <code>FillLayout</code> does not wrap, - * but you can specify margins and spacing. You might use it to - * lay out buttons in a task bar or tool bar, or to stack checkboxes - * in a <code>Group</code>. <code>FillLayout</code> can also be used - * when a <code>Composite</code> only has one child. For example, - * if a <code>Shell</code> has a single <code>Group</code> child, - * <code>FillLayout</code> will cause the <code>Group</code> to + * Initially, the controls will all be as tall as the tallest control, + * and as wide as the widest. <code>FillLayout</code> does not wrap, + * but you can specify margins and spacing. You might use it to + * lay out buttons in a task bar or tool bar, or to stack checkboxes + * in a <code>Group</code>. <code>FillLayout</code> can also be used + * when a <code>Composite</code> only has one child. For example, + * if a <code>Shell</code> has a single <code>Group</code> child, + * <code>FillLayout</code> will cause the <code>Group</code> to * completely fill the <code>Shell</code> (if margins are 0). * </p> * <p> * Example code: first a <code>FillLayout</code> is created and - * its type field is set, and then the layout is set into the + * its type field is set, and then the layout is set into the * <code>Composite</code>. Note that in a <code>FillLayout</code>, * children are always the same size, and they fill all available space. * <pre> @@ -45,10 +49,13 @@ * shell.setLayout(fillLayout); * </pre> * </p> + * + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: LayoutExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public final class FillLayout : Layout { /** - * type specifies how controls will be positioned + * type specifies how controls will be positioned * within the layout. * * The default value is HORIZONTAL. @@ -59,37 +66,37 @@ * </ul> */ public int type = DWT.HORIZONTAL; - + /** * marginWidth specifies the number of pixels of horizontal margin * that will be placed along the left and right edges of the layout. * * The default value is 0. - * + * * @since 3.0 */ public int marginWidth = 0; - + /** * marginHeight specifies the number of pixels of vertical margin * that will be placed along the top and bottom edges of the layout. * * The default value is 0. - * + * * @since 3.0 */ public int marginHeight = 0; - + /** * spacing specifies the number of pixels between the edge of one cell * and the edge of its neighbouring cell. * * The default value is 0. - * + * * @since 3.0 */ public int spacing = 0; - + /** * Constructs a new instance of this class. */ @@ -100,14 +107,14 @@ * Constructs a new instance of this class given the type. * * @param type the type of fill layout - * + * * @since 2.0 */ public this (int type) { this.type = type; } -protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) { +override protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) { Control [] children = composite.getChildren (); int count = children.length; int maxWidth = 0, maxHeight = 0; @@ -155,8 +162,8 @@ } else { // TEMPORARY CODE int trimX, trimY; - if ( null !is cast(Scrollable)control ) { - Rectangle rect = (cast(Scrollable) control).computeTrim (0, 0, 0, 0); + if ( auto sa = cast(Scrollable)control ) { + Rectangle rect = sa.computeTrim (0, 0, 0, 0); trimX = rect.width; trimY = rect.height; } else { @@ -169,20 +176,20 @@ return size; } -protected bool flushCache (Control control) { +override protected bool flushCache (Control control) { Object data = control.getLayoutData(); if (data !is null) (cast(FillData)data).flushCache(); return true; } 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 ]; } -protected void layout (Composite composite, bool flushCache) { +override protected void layout (Composite composite, bool flushCache) { Rectangle rect = composite.getClientArea (); Control [] children = composite.getChildren (); int count = children.length; @@ -228,14 +235,14 @@ * * @return a string representation of the layout */ -public String toString () { - String string = getName ()+" {"; - string += "type="+((type is DWT.VERTICAL) ? "DWT.VERTICAL" : "DWT.HORIZONTAL")+" "; - if (marginWidth !is 0) string += "marginWidth="+marginWidth+" "; - if (marginHeight !is 0) string += "marginHeight="+marginHeight+" "; - if (spacing !is 0) string += "spacing="+spacing+" "; +override public String toString () { + String string = getName () ~ " {"; + string ~= "type="~((type is DWT.VERTICAL) ? "DWT.VERTICAL" : "DWT.HORIZONTAL")~" "; + if (marginWidth !is 0) string ~= "marginWidth="~to!(String)(marginWidth)~" "; + if (marginHeight !is 0) string ~= "marginHeight="~to!(String)(marginHeight)~" "; + if (spacing !is 0) string ~= "spacing="~to!(String)(spacing)~" "; string = string.trim(); - string += "}"; + string ~= "}"; return string; } }