diff dwt/layout/RowLayout.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/RowLayout.d	Tue Oct 07 14:41:16 2008 +0200
+++ b/dwt/layout/RowLayout.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,35 +7,40 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.layout.RowLayout;
 
-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.layout.RowData;
+import tango.util.Convert;
+import Math = tango.math.Math;
+import dwt.dwthelper.utils;
+
 
 /**
- * Instances of this class determine the size and position of the 
- * children of a <code>Composite</code> by placing them either in 
- * horizontal rows or vertical columns within the parent <code>Composite</code>. 
+ * Instances of this class determine the size and position of the
+ * children of a <code>Composite</code> by placing them either in
+ * horizontal rows or vertical columns within the parent <code>Composite</code>.
  * <p>
  * <code>RowLayout</code> aligns all controls in one row if the
  * <code>type</code> is set to horizontal, and one column if it is
- * set to vertical. It has the ability to wrap, and provides configurable 
- * margins and spacing. <code>RowLayout</code> has a number of configuration 
- * fields. In addition, the height and width of each control in a 
+ * set to vertical. It has the ability to wrap, and provides configurable
+ * margins and spacing. <code>RowLayout</code> has a number of configuration
+ * fields. In addition, the height and width of each control in a
  * <code>RowLayout</code> can be specified by setting a <code>RowData</code>
  * object into the control using <code>setLayoutData ()</code>.
  * </p>
  * <p>
- * The following example code creates a <code>RowLayout</code>, sets all 
- * of its fields to non-default values, and then sets it into a 
- * <code>Shell</code>. 
+ * The following example code creates a <code>RowLayout</code>, sets all
+ * of its fields to non-default values, and then sets it into a
+ * <code>Shell</code>.
  * <pre>
  *      RowLayout rowLayout = new RowLayout();
  *      rowLayout.wrap = false;
@@ -54,42 +59,45 @@
  *      shell.setLayout(new RowLayout());
  * </pre>
  * </p>
- * 
+ *
  * @see RowData
+ * @see <a href="http://www.eclipse.org/swt/snippets/#rowlayout">RowLayout snippets</a>
+ * @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 RowLayout : Layout {
-    
+
     /**
-     * type specifies whether the layout places controls in rows or 
+     * type specifies whether the layout places controls in rows or
      * columns.
-     * 
+     *
      * The default value is HORIZONTAL.
-     * 
+     *
      * Possible values are: <ul>
      *    <li>HORIZONTAL: Position the controls horizontally from left to right</li>
      *    <li>VERTICAL: Position the controls vertically from top to bottom</li>
      * </ul>
-     * 
+     *
      * @since 2.0
      */
     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;
@@ -101,7 +109,7 @@
      * The default value is 3.
      */
     public int spacing = 3;
-            
+
     /**
      * wrap specifies whether a control will be wrapped to the next
      * row if there is insufficient space on the current row.
@@ -112,22 +120,22 @@
 
     /**
      * pack specifies whether all controls in the layout take
-     * their preferred size.  If pack is false, all controls will 
-     * have the same size which is the size required to accommodate the 
-     * largest preferred height and the largest preferred width of all 
+     * their preferred size.  If pack is false, all controls will
+     * have the same size which is the size required to accommodate the
+     * largest preferred height and the largest preferred width of all
      * the controls in the layout.
      *
      * The default value is true.
      */
     public bool pack = true;
-    
+
     /**
      * fill specifies whether the controls in a row should be
      * all the same height for horizontal layouts, or the same
      * width for vertical layouts.
      *
      * The default value is false.
-     * 
+     *
      * @since 3.0
      */
     public bool fill = false;
@@ -193,56 +201,56 @@
  * Constructs a new instance of this class given the type.
  *
  * @param type the type of row 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_) {
     Point extent;
     if (type is DWT.HORIZONTAL) {
-        extent = layoutHorizontal (composite, false, (wHint !is DWT.DEFAULT) && wrap, wHint, flushCache);
+        extent = layoutHorizontal (composite, false, (wHint !is DWT.DEFAULT) && wrap, wHint, flushCache_);
     } else {
-        extent = layoutVertical (composite, false, (hHint !is DWT.DEFAULT) && wrap, hHint, flushCache);
+        extent = layoutVertical (composite, false, (hHint !is DWT.DEFAULT) && wrap, hHint, flushCache_);
     }
     if (wHint !is DWT.DEFAULT) extent.x = wHint;
     if (hHint !is DWT.DEFAULT) extent.y = hHint;
     return extent;
 }
 
-Point computeSize (Control control, bool flushCache) {
+Point computeSize (Control control, bool flushCache_) {
     int wHint = DWT.DEFAULT, hHint = DWT.DEFAULT;
     RowData data = cast(RowData) control.getLayoutData ();
     if (data !is null) {
         wHint = data.width;
         hHint = data.height;
     }
-    return control.computeSize (wHint, hHint, flushCache);
+    return control.computeSize (wHint, hHint, flushCache_);
 }
 
-protected bool flushCache (Control control) {
+override protected bool flushCache (Control control) {
     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 clientArea = composite.getClientArea ();
     if (type is DWT.HORIZONTAL) {
-        layoutHorizontal (composite, true, wrap, clientArea.width, flushCache);
+        layoutHorizontal (composite, true, wrap, clientArea.width, flushCache_);
     } else {
-        layoutVertical (composite, true, wrap, clientArea.height, flushCache);
+        layoutVertical (composite, true, wrap, clientArea.height, flushCache_);
     }
 }
 
-Point layoutHorizontal (Composite composite, bool move, bool wrap, int width, bool flushCache) {
+Point layoutHorizontal (Composite composite, bool move, bool wrap, int width, bool flushCache_) {
     Control [] children = composite.getChildren ();
     int count = 0;
     for (int i=0; i<children.length; i++) {
@@ -250,7 +258,7 @@
         RowData data = cast(RowData) control.getLayoutData ();
         if (data is null || !data.exclude) {
             children [count++] = children [i];
-        } 
+        }
     }
     if (count is 0) {
         return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
@@ -259,7 +267,7 @@
     if (!pack) {
         for (int i=0; i<count; i++) {
             Control child = children [i];
-            Point size = computeSize (child, flushCache);
+            Point size = computeSize (child, flushCache_);
             childWidth = Math.max (childWidth, size.x);
             childHeight = Math.max (childHeight, size.y);
         }
@@ -282,7 +290,7 @@
     for (int i=0; i<count; i++) {
         Control child = children [i];
         if (pack) {
-            Point size = computeSize (child, flushCache);
+            Point size = computeSize (child, flushCache_);
             childWidth = size.x;
             childHeight = size.y;
         }
@@ -361,7 +369,7 @@
     return new Point (maxX, y + maxHeight + marginBottom + marginHeight);
 }
 
-Point layoutVertical (Composite composite, bool move, bool wrap, int height, bool flushCache) {
+Point layoutVertical (Composite composite, bool move, bool wrap, int height, bool flushCache_) {
     Control [] children = composite.getChildren ();
     int count = 0;
     for (int i=0; i<children.length; i++) {
@@ -369,7 +377,7 @@
         RowData data = cast(RowData) control.getLayoutData ();
         if (data is null || !data.exclude) {
             children [count++] = children [i];
-        } 
+        }
     }
     if (count is 0) {
         return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
@@ -378,7 +386,7 @@
     if (!pack) {
         for (int i=0; i<count; i++) {
             Control child = children [i];
-            Point size = computeSize (child, flushCache);
+            Point size = computeSize (child, flushCache_);
             childWidth = Math.max (childWidth, size.x);
             childHeight = Math.max (childHeight, size.y);
         }
@@ -401,7 +409,7 @@
     for (int i=0; i<count; i++) {
         Control child = children [i];
         if (pack) {
-            Point size = computeSize (child, flushCache);
+            Point size = computeSize (child, flushCache_);
             childWidth = size.x;
             childHeight = size.y;
         }
@@ -487,22 +495,22 @@
  *
  * @return a string representation of the layout
  */
-public String toString () {
-    String string = getName ()+" {";
-    string += "type="+((type !is DWT.HORIZONTAL) ? "DWT.VERTICAL" : "DWT.HORIZONTAL")+" ";
-    if (marginWidth !is 0) string += "marginWidth="+marginWidth+" ";
-    if (marginHeight !is 0) string += "marginHeight="+marginHeight+" ";
-    if (marginLeft !is 0) string += "marginLeft="+marginLeft+" ";
-    if (marginTop !is 0) string += "marginTop="+marginTop+" ";
-    if (marginRight !is 0) string += "marginRight="+marginRight+" ";
-    if (marginBottom !is 0) string += "marginBottom="+marginBottom+" ";
-    if (spacing !is 0) string += "spacing="+spacing+" ";
-    string += "wrap="+wrap+" ";
-    string += "pack="+pack+" ";
-    string += "fill="+fill+" ";
-    string += "justify="+justify+" ";
+override public String toString () {
+    String string = getName ()~" {";
+    string ~= "type="~((type !is DWT.HORIZONTAL) ? "DWT.VERTICAL" : "DWT.HORIZONTAL")~" ";
+    if (marginWidth !is 0) string ~= "marginWidth="~to!(String)(marginWidth)~" ";
+    if (marginHeight !is 0) string ~= "marginHeight="~to!(String)(marginHeight)~" ";
+    if (marginLeft !is 0) string ~= "marginLeft="~to!(String)(marginLeft)~" ";
+    if (marginTop !is 0) string ~= "marginTop="~to!(String)(marginTop)~" ";
+    if (marginRight !is 0) string ~= "marginRight="~to!(String)(marginRight)~" ";
+    if (marginBottom !is 0) string ~= "marginBottom="~to!(String)(marginBottom)~" ";
+    if (spacing !is 0) string ~= "spacing="~to!(String)(spacing)~" ";
+    string ~= "wrap="~to!(String)(wrap)~" ";
+    string ~= "pack="~to!(String)(pack)~" ";
+    string ~= "fill="~to!(String)(fill)~" ";
+    string ~= "justify="~to!(String)(justify)~" ";
     string = string.trim();
-    string += "}";
+    string ~= "}";
     return string;
 }
 }