# HG changeset patch # User Frank Benoit # Date 1201262513 -3600 # Node ID bf9fe45b4422a41fa32e10cb5d78108e3b2410b3 # Parent 20e70c5494d7b20c74d8da17a321a9864a5bf7bf C, Platform, Point, Rectangle diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/DWT.d --- a/dwt/DWT.d Fri Jan 25 13:00:42 2008 +0100 +++ b/dwt/DWT.d Fri Jan 25 13:01:53 2008 +0100 @@ -10,7 +10,7 @@ * Port to the D Programming language: * Frank Benoit *******************************************************************************/ -package dwt.DWT; +module dwt.DWT; import dwt.internal.Compatibility; @@ -3429,7 +3429,8 @@ * */ public static char[] getMessage(char[] key) { - return Compatibility.getMessage(key); + //return Compatibility.getMessage(key); + return ""; } /** diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/DWTError.d --- a/dwt/DWTError.d Fri Jan 25 13:00:42 2008 +0100 +++ b/dwt/DWTError.d Fri Jan 25 13:01:53 2008 +0100 @@ -74,7 +74,7 @@ * * @param message the detail message for the exception */ -public this (String message) { +public this (char[] message) { this (DWT.ERROR_UNSPECIFIED, message); } @@ -153,3 +153,7 @@ } } +} + + + diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/DWTException.d --- a/dwt/DWTException.d Fri Jan 25 13:00:42 2008 +0100 +++ b/dwt/DWTException.d Fri Jan 25 13:01:53 2008 +0100 @@ -144,4 +144,5 @@ } } +} diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/graphics/Point.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/Point.d Fri Jan 25 13:01:53 2008 +0100 @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +module dwt.graphics.Point; + + +public import dwt.internal.SerializableCompatibility; + +import tango.text.convert.Format; + +/** + * Instances of this class represent places on the (x, y) + * coordinate plane. + *

+ * The coordinate space for rectangles and points is considered + * to have increasing values downward and to the right from its + * origin making this the normal, computer graphics oriented notion + * of (x, y) coordinates rather than the strict mathematical one. + *

+ *

+ * The hashCode() method in this class uses the values of the public + * fields to compute the hash value. When storing instances of the + * class in hashed collections, do not modify these fields after the + * object has been inserted. + *

+ *

+ * Application code does not need to explicitly release the + * resources managed by each instance when those instances are no longer + * required, and thus no dispose() method is provided. + *

+ * + * @see Rectangle + */ + +public final class Point : SerializableCompatibility { + + /** + * the x coordinate of the point + */ + public int x; + + /** + * the y coordinate of the point + */ + public int y; + + //static final long serialVersionUID = 3257002163938146354L; + +/** + * Constructs a new point with the given x and y coordinates. + * + * @param x the x coordinate of the new point + * @param y the y coordinate of the new point + */ +public this (int x, int y) { + this.x = x; + this.y = y; +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode() + */ +public override int opEquals (Object object) { + if (object is this) return true; + if ( auto p = cast(Point)object ){ + return (p.x is this.x) && (p.y is this.y); + } + return false; +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals(Object) + */ +public hash_t toHash () { + return x ^ y; +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the point + */ +public char[] toString () { + return Format( "Point {}, {}}", x, y );; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ +} + +} + diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/graphics/Rectangle.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/Rectangle.d Fri Jan 25 13:01:53 2008 +0100 @@ -0,0 +1,351 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +module dwt.graphics.Rectangle; + +public import dwt.graphics.Point; +public import dwt.internal.SerializableCompatibility; + +import dwt.DWT; +import dwt.DWTError; +import tango.text.convert.Format; + +/** + * Instances of this class represent rectangular areas in an + * (x, y) coordinate system. The top left corner of the rectangle + * is specified by its x and y values, and the extent of the + * rectangle is specified by its width and height. + *

+ * The coordinate space for rectangles and points is considered + * to have increasing values downward and to the right from its + * origin making this the normal, computer graphics oriented notion + * of (x, y) coordinates rather than the strict mathematical one. + *

+ *

+ * The hashCode() method in this class uses the values of the public + * fields to compute the hash value. When storing instances of the + * class in hashed collections, do not modify these fields after the + * object has been inserted. + *

+ *

+ * Application code does not need to explicitly release the + * resources managed by each instance when those instances are no longer + * required, and thus no dispose() method is provided. + *

+ * + * @see Point + */ + +public final class Rectangle : SerializableCompatibility { + + /** + * the x coordinate of the rectangle + */ + public int x; + + /** + * the y coordinate of the rectangle + */ + public int y; + + /** + * the width of the rectangle + */ + public int width; + + /** + * the height of the rectangle + */ + public int height; + + //static final long serialVersionUID = 3256439218279428914L; + +/** + * Construct a new instance of this class given the + * x, y, width and height values. + * + * @param x the x coordinate of the origin of the rectangle + * @param y the y coordinate of the origin of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + */ +public this (int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; +} + +/** + * Destructively replaces the x, y, width and height values + * in the receiver with ones which represent the union of the + * rectangles specified by the receiver and the given rectangle. + *

+ * The union of two rectangles is the smallest single rectangle + * that completely covers both of the areas covered by the two + * given rectangles. + *

+ * + * @param rect the rectangle to merge with the receiver + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ */ +public void add (Rectangle rect) { + if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + int left = x < rect.x ? x : rect.x; + int top = y < rect.y ? y : rect.y; + int lhs = x + width; + int rhs = rect.x + rect.width; + int right = lhs > rhs ? lhs : rhs; + lhs = y + height; + rhs = rect.y + rect.height; + int bottom = lhs > rhs ? lhs : rhs; + x = left; y = top; width = right - left; height = bottom - top; +} + +/** + * Returns true if the point specified by the + * arguments is inside the area specified by the receiver, + * and false otherwise. + * + * @param x the x coordinate of the point to test for containment + * @param y the y coordinate of the point to test for containment + * @return true if the rectangle contains the point and false otherwise + */ +public bool contains (int x, int y) { + return (x >= this.x) && (y >= this.y) && ((x - this.x) < width) && ((y - this.y) < height); +} + +/** + * Returns true if the given point is inside the + * area specified by the receiver, and false + * otherwise. + * + * @param pt the point to test for containment + * @return true if the rectangle contains the point and false otherwise + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ */ +public bool contains (Point pt) { + if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + return contains(pt.x, pt.y); +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode() + */ +public override int opEquals (Object object) { + if (object is this) return true; + if( auto r = cast(Rectangle) object ){ + return (r.x is this.x) && (r.y is this.y) && (r.width is this.width) && (r.height is this.height); + } + return false; +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals(Object) + */ +public override hash_t toHash () { + return x ^ y ^ width ^ height; +} + +/** + * Destructively replaces the x, y, width and height values + * in the receiver with ones which represent the intersection of the + * rectangles specified by the receiver and the given rectangle. + * + * @param rect the rectangle to intersect with the receiver + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ * + * since 3.0 + */ +public void intersect (Rectangle rect) { + if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + if (this is rect) return; + int left = x > rect.x ? x : rect.x; + int top = y > rect.y ? y : rect.y; + int lhs = x + width; + int rhs = rect.x + rect.width; + int right = lhs < rhs ? lhs : rhs; + lhs = y + height; + rhs = rect.y + rect.height; + int bottom = lhs < rhs ? lhs : rhs; + x = right < left ? 0 : left; + y = bottom < top ? 0 : top; + width = right < left ? 0 : right - left; + height = bottom < top ? 0 : bottom - top; +} + +/** + * Returns a new rectangle which represents the intersection + * of the receiver and the given rectangle. + *

+ * The intersection of two rectangles is the rectangle that + * covers the area which is contained within both rectangles. + *

+ * + * @param rect the rectangle to intersect with the receiver + * @return the intersection of the receiver and the argument + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ */ +public Rectangle intersection (Rectangle rect) { + if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + if (this is rect) return new Rectangle (x, y, width, height); + int left = x > rect.x ? x : rect.x; + int top = y > rect.y ? y : rect.y; + int lhs = x + width; + int rhs = rect.x + rect.width; + int right = lhs < rhs ? lhs : rhs; + lhs = y + height; + rhs = rect.y + rect.height; + int bottom = lhs < rhs ? lhs : rhs; + return new Rectangle ( + right < left ? 0 : left, + bottom < top ? 0 : top, + right < left ? 0 : right - left, + bottom < top ? 0 : bottom - top); +} + +/** + * Returns true if the rectangle described by the + * arguments intersects with the receiver and false + * otherwise. + *

+ * Two rectangles intersect if the area of the rectangle + * representing their intersection is not empty. + *

+ * + * @param x the x coordinate of the origin of the rectangle + * @param y the y coordinate of the origin of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + * @return true if the rectangle intersects with the receiver, and false otherwise + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ * + * @see #intersection(Rectangle) + * @see #isEmpty() + * + * @since 3.0 + */ +public bool intersects (int x, int y, int width, int height) { + return (x < this.x + this.width) && (y < this.y + this.height) && + (x + width > this.x) && (y + height > this.y); +} + +/** + * Returns true if the given rectangle intersects + * with the receiver and false otherwise. + *

+ * Two rectangles intersect if the area of the rectangle + * representing their intersection is not empty. + *

+ * + * @param rect the rectangle to test for intersection + * @return true if the rectangle intersects with the receiver, and false otherwise + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ * + * @see #intersection(Rectangle) + * @see #isEmpty() + */ +public bool intersects (Rectangle rect) { + if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + return rect is this || intersects (rect.x, rect.y, rect.width, rect.height); +} + +/** + * Returns true if the receiver does not cover any + * area in the (x, y) coordinate plane, and false if + * the receiver does cover some area in the plane. + *

+ * A rectangle is considered to cover area in the + * (x, y) coordinate plane if both its width and height are + * non-zero. + *

+ * + * @return true if the receiver is empty, and false otherwise + */ +public bool isEmpty () { + return (width <= 0) || (height <= 0); +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the rectangle + */ +public override char[] toString () { + return Format( "Rectangle {}, {}, {}, {}}", x, y, width, height ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ +} + +/** + * Returns a new rectangle which represents the union of + * the receiver and the given rectangle. + *

+ * The union of two rectangles is the smallest single rectangle + * that completely covers both of the areas covered by the two + * given rectangles. + *

+ * + * @param rect the rectangle to perform union with + * @return the union of the receiver and the argument + * + * @exception IllegalArgumentException
    + *
  • ERROR_NULL_ARGUMENT - if the argument is null
  • + *
+ * + * @see #add(Rectangle) + */ +public Rectangle makeUnion (Rectangle rect) { + if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + int left = x < rect.x ? x : rect.x; + int top = y < rect.y ? y : rect.y; + int lhs = x + width; + int rhs = rect.x + rect.width; + int right = lhs > rhs ? lhs : rhs; + lhs = y + height; + rhs = rect.y + rect.height; + int bottom = lhs > rhs ? lhs : rhs; + return new Rectangle (left, top, right - left, bottom - top); +} + +} diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/internal/C.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/C.d Fri Jan 25 13:01:53 2008 +0100 @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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.internal.C; + +import dwt.internal.Platform; + +public class C : Platform { + +//public static final native void free (int /*long*/ ptr); +//public static final native int /*long*/ getenv (byte[] wcsToMbcs); +//public static final native int /*long*/ malloc (int /*long*/ size); +} diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/internal/Library.d --- a/dwt/internal/Library.d Fri Jan 25 13:00:42 2008 +0100 +++ b/dwt/internal/Library.d Fri Jan 25 13:01:53 2008 +0100 @@ -46,11 +46,11 @@ //public static const int JAVA_VERSION; public static const int SWT_VERSION = .buildSWT_VERSION(MAJOR_VERSION, MINOR_VERSION); - version( linux ){ - static const char[] SEPARATOR = "\n"; + version( Windows ){ + static const char[] SEPARATOR = "\r\n"; } else { - static assert( false, "only linux supported for this port" ); + static assert( false, "only windows supported for this port" ); } diff -r 20e70c5494d7 -r bf9fe45b4422 dwt/internal/Platform.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/Platform.d Fri Jan 25 13:01:53 2008 +0100 @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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.internal.Platform; + +public class Platform { + +public static const char[] PLATFORM = "win32"; //$NON-NLS-1$ + +}