# HG changeset patch # User Jacob Carlborg # Date 1221427949 -7200 # Node ID 7d135fe0caf27f6f43d0ccc2b494cb61b6a1a5f6 # Parent 5123b17c98efe0601064af04b8f233e980812cc4 Ported dwt.graphics.Cursor and dwt.widgets.MenuItem diff -r 5123b17c98ef -r 7d135fe0caf2 dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dsss.conf Sun Sep 14 23:32:29 2008 +0200 @@ -0,0 +1,38 @@ +[dwt] +buildflags+=-framework=Cocoa +exclude=dwt/browser +exclude=dwt/dnd +exclude=dwt/effects +exclude=dwt/graphics/TextLayout.d +exclude=dwt/internal/cocoa/DOM* +exclude=dwt/internal/cocoa/MacGenerator.d +exclude=dwt/internal/cocoa/Web* +exclude=dwt/internal/theme +exclude=dwt/layout +exclude=dwt/opengl +exclude=dwt/printing +exclude=dwt/program +exclude=dwt/widgets/ColorDialog.d +exclude=dwt/widgets/Combo.d +exclude=dwt/widgets/CoolBar.d +exclude=dwt/widgets/CoolItem.d +exclude=dwt/widgets/DateTime.d +exclude=dwt/widgets/DirectoryDialog.d +exclude=dwt/widgets/ExpandBar.d +exclude=dwt/widgets/ExpandItem.d +exclude=dwt/widgets/FileDialog.d +exclude=dwt/widgets/FontDialog.d +exclude=dwt/widgets/Group.d +exclude=dwt/widgets/Label.d +exclude=dwt/widgets/Link.d +exclude=dwt/widgets/List.d +exclude=dwt/widgets/MessageBox.d +exclude=dwt/widgets/ProgressBar.d +exclude=dwt/widgets/Sash.d +exclude=dwt/widgets/Scale.d +exclude=dwt/widgets/Slider.d +exclude=dwt/widgets/Spinner.d +exclude=dwt/widgets/Ta* +exclude=dwt/widgets/Text.d +exclude=dwt/widgets/Too* +exclude=dwt/widgets/Tr* \ No newline at end of file diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/browser/Safari.d --- a/dwt/browser/Safari.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/browser/Safari.d Sun Sep 14 23:32:29 2008 +0200 @@ -43,7 +43,7 @@ import dwt.internal.cocoa.NSURLDownload; import dwt.internal.cocoa.NSURLRequest; import dwt.internal.cocoa.OS; -import dwt.internal.cocoa.DWTWebViewDelegate; +import dwt.internal.cocoa.SWTWebViewDelegate; import dwt.internal.cocoa.WebDataSource; import dwt.internal.cocoa.WebDocumentRepresentation; import dwt.internal.cocoa.WebFrame; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/dwthelper/utils.d --- a/dwt/dwthelper/utils.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/dwthelper/utils.d Sun Sep 14 23:32:29 2008 +0200 @@ -525,6 +525,10 @@ static alias CharacterIsWhitespace isWhitespace; } +String new_String( String cont, int offset, int len ){ + return cont[ offset .. offset+len ].dup; +} + public String toUpperCase( String str ){ return tango.text.Unicode.toUpper( str ); } diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/graphics/Cursor.d --- a/dwt/graphics/Cursor.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/graphics/Cursor.d Sun Sep 14 23:32:29 2008 +0200 @@ -7,11 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.graphics.Cursor; -import dwt.dwthelper.utils; - import dwt.DWT; import dwt.DWTError; @@ -23,6 +24,16 @@ import dwt.internal.cocoa.NSString; import dwt.internal.cocoa.OS; +import tango.text.convert.Format; + +import dwt.dwthelper.utils; +import dwt.graphics.Device; +import dwt.graphics.ImageData; +import dwt.graphics.PaletteData; +import dwt.graphics.Resource; +import dwt.graphics.RGB; +import dwt.internal.cocoa.NSInteger; + /** * Instances of this class manage operating system resources that * specify the appearance of the on-screen pointer. To create a @@ -222,19 +233,19 @@ } void createNSCursor(int hotspotX, int hotspotY, byte[] buffer, int width, int height) { - NSImage nsImage = cast(NSImage)new NSImage().alloc(); - NSBitmapImageRep nsImageRep = cast(NSBitmapImageRep)new NSBitmapImageRep().alloc(); - handle = cast(NSCursor)new NSCursor().alloc(); - NSSize size = new NSSize(); + NSImage nsImage = cast(NSImage)(new NSImage()).alloc(); + NSBitmapImageRep nsImageRep = cast(NSBitmapImageRep)(new NSBitmapImageRep()).alloc(); + handle = cast(NSCursor)(new NSCursor()).alloc(); + NSSize size = NSSize(); size.width = width; size.height = height; nsImage = nsImage.initWithSize(size); - nsImageRep = nsImageRep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, width, height, + nsImageRep = nsImageRep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, cast(NSInteger) width, cast(NSInteger) height, 8, 4, true, false, new NSString(OS.NSDeviceRGBColorSpace()), - OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, width * 4, 32); + OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, cast(NSInteger) (width * 4, 32)); OS.memmove(nsImageRep.bitmapData(), buffer, buffer.length); nsImage.addRepresentation(nsImageRep); - NSPoint point = new NSPoint(); + NSPoint point = NSPoint(); point.x = hotspotX; point.y = hotspotY; handle = handle.initWithImage_hotSpot_(nsImage, point); @@ -345,13 +356,15 @@ * * @see #hashCode */ -public bool equals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!( null !is cast(Cursor)object )) return false; Cursor cursor = cast(Cursor) object; return device is cursor.device && handle is cursor.handle; } +alias opEequals equals; + /** * Returns an integer hash code for the receiver. Any two * objects that return true when passed to @@ -362,10 +375,12 @@ * * @see #equals */ -public int hashCode () { - return handle !is null ? handle.id : 0; +public hast_t toHash () { + return handle !is null ? handle.id_ : 0; } +alias toHash hashCode; + /** * Returns true if the cursor has been disposed, * and false otherwise. @@ -388,7 +403,7 @@ */ public String toString () { if (isDisposed()) return "Cursor {*DISPOSED*}"; - return "Cursor {" + handle + "}"; + return Format("Cursor {{}{}" , handle , "}"); } /** diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/graphics/FontData.d --- a/dwt/graphics/FontData.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/graphics/FontData.d Sun Sep 14 23:32:29 2008 +0200 @@ -215,7 +215,7 @@ * * @see #hashCode */ -public bool opEquals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!( null !is cast(FontData)object )) return false; FontData data = cast(FontData)object; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/graphics/GlyphMetrics.d --- a/dwt/graphics/GlyphMetrics.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/graphics/GlyphMetrics.d Sun Sep 14 23:32:29 2008 +0200 @@ -82,7 +82,7 @@ * * @see #hashCode() */ -public bool opEquals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!( null !is cast(GlyphMetrics)object )) return false; GlyphMetrics metrics = cast(GlyphMetrics)object; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/graphics/Image.d --- a/dwt/graphics/Image.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/graphics/Image.d Sun Sep 14 23:32:29 2008 +0200 @@ -562,7 +562,7 @@ * * @see #hashCode */ -public bool opEquals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!( null !is cast(Image)object )) return false; Image image = cast(Image)object; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/graphics/Point.d --- a/dwt/graphics/Point.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/graphics/Point.d Sun Sep 14 23:32:29 2008 +0200 @@ -78,7 +78,7 @@ * * @see #hashCode() */ -public bool opEquals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!( null !is cast(Point)object )) return false; Point p = cast(Point)object; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/graphics/Rectangle.d --- a/dwt/graphics/Rectangle.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/graphics/Rectangle.d Sun Sep 14 23:32:29 2008 +0200 @@ -155,7 +155,7 @@ * * @see #hashCode() */ -public bool opEquals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!( null !is cast(Rectangle)object )) return false; Rectangle r = cast(Rectangle)object; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/internal/Callback.d --- a/dwt/internal/Callback.d Sun Sep 14 01:45:57 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,263 +0,0 @@ -/******************************************************************************* - * 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: - * Jacob Carlborg - *******************************************************************************/ -module dwt.internal.Callback; - - -import dwt.internal.C; - -/** - * Instances of this class represent entry points into Java - * which can be invoked from operating system level callback - * routines. - *

- * IMPORTANT: A callback is only valid when invoked on the - * thread which created it. The results are undefined (and - * typically bad) when a callback is passed out to the - * operating system (or other code) in such a way that the - * callback is called from a different thread. - */ - -public class Callback { - - Object object; - String method, signature; - int argCount; - int /*long*/ address, errorResult; - boolean isStatic, isArrayBased; - - static final String PTR_SIGNATURE = C.PTR_SIZEOF == 4 ? "I" : "J"; //$NON-NLS-1$ //$NON-NLS-2$ - static final String SIGNATURE_0 = getSignature(0); - static final String SIGNATURE_1 = getSignature(1); - static final String SIGNATURE_2 = getSignature(2); - static final String SIGNATURE_3 = getSignature(3); - static final String SIGNATURE_4 = getSignature(4); - static final String SIGNATURE_N = "(["+PTR_SIGNATURE+")"+PTR_SIGNATURE; //$NON-NLS-1$ //$NON-NLS-2$ - -/** - * Constructs a new instance of this class given an object - * to send the message to, a string naming the method to - * invoke and an argument count. Note that, if the object - * is an instance of Class it is assumed that - * the method is a static method on that class. - * - * @param object the object to send the message to - * @param method the name of the method to invoke - * @param argCount the number of arguments that the method takes - */ -public this (Object object, String method, int argCount) { - this (object, method, argCount, false); -} - -/** - * Constructs a new instance of this class given an object - * to send the message to, a string naming the method to - * invoke, an argument count and a flag indicating whether - * or not the arguments will be passed in an array. Note - * that, if the object is an instance of Class - * it is assumed that the method is a static method on that - * class. - * - * @param object the object to send the message to - * @param method the name of the method to invoke - * @param argCount the number of arguments that the method takes - * @param isArrayBased true if the arguments should be passed in an array and false otherwise - */ -public this (Object object, String method, int argCount, boolean isArrayBased) { - this (object, method, argCount, isArrayBased, 0); -} - -/** - * Constructs a new instance of this class given an object - * to send the message to, a string naming the method to - * invoke, an argument count, a flag indicating whether - * or not the arguments will be passed in an array and a value - * to return when an exception happens. Note that, if - * the object is an instance of Class - * it is assumed that the method is a static method on that - * class. - * - * @param object the object to send the message to - * @param method the name of the method to invoke - * @param argCount the number of arguments that the method takes - * @param isArrayBased true if the arguments should be passed in an array and false otherwise - * @param errorResult the return value if the java code throws an exception - */ -public this (Object object, String method, int argCount, boolean isArrayBased, int /*long*/ errorResult) { - - /* Set the callback fields */ - this.object = object; - this.method = method; - this.argCount = argCount; - this.isStatic = cast(ClassInfo) object; - this.isArrayBased = isArrayBased; - this.errorResult = errorResult; - - /* Inline the common cases */ - if (isArrayBased) { - signature = SIGNATURE_N; - } else { - switch (argCount) { - case 0: signature = SIGNATURE_0; break; //$NON-NLS-1$ - case 1: signature = SIGNATURE_1; break; //$NON-NLS-1$ - case 2: signature = SIGNATURE_2; break; //$NON-NLS-1$ - case 3: signature = SIGNATURE_3; break; //$NON-NLS-1$ - case 4: signature = SIGNATURE_4; break; //$NON-NLS-1$ - default: - signature = getSignature(argCount); - } - } - - /* Bind the address */ - address = bind (this, object, method, signature, argCount, isStatic, isArrayBased, errorResult); -} - -/** - * Allocates the native level resources associated with the - * callback. This method is only invoked from within the - * constructor for the argument. - * - * @param callback the callback to bind - * @param object the callback's object - * @param method the callback's method - * @param signature the callback's method signature - * @param argCount the callback's method argument count - * @param isStatic whether the callback's method is static - * @param isArrayBased whether the callback's method is array based - * @param errorResult the callback's error result - */ -static synchronized int /*long*/ bind (Callback callback, Object object, String method, String signature, int argCount, boolean isStatic, boolean isArrayBased, int /*long*/ errorResult) -{ - return c.bind(callback, object, method, signature, argCount, isStatic, isArrayBased, errorResult); -} - -/** - * Releases the native level resources associated with the callback, - * and removes all references between the callback and - * other objects. This helps to prevent (bad) application code - * from accidentally holding onto extraneous garbage. - */ -public void dispose () { - if (object is null) return; - unbind (this); - object = method = signature = null; - address = 0; -} - -/** - * Returns the address of a block of machine code which will - * invoke the callback represented by the receiver. - * - * @return the callback address - */ -public int /*long*/ getAddress () { - return address; -} - -/** - * Returns the SWT platform name. - * - * @return the platform name of the currently running SWT - */ -public static String getPlatform (); - -/** - * Returns the number of times the system has been recursively entered - * through a callback. - *

- * Note: This should not be called by application code. - *

- * - * @return the entry count - * - * @since 2.1 - */ -public static int getEntryCount () -{ - return c.getEntryCount; -} - -static String getSignature(int argCount) { - String signature = "("; //$NON-NLS-1$ - for (int i = 0; i < argCount; i++) signature = PTR_SIGNATURE; - signature += ")" ~ PTR_SIGNATURE; //$NON-NLS-1$ - return signature; -} - -/** - * Indicates whether or not callbacks which are triggered at the - * native level should cause the messages described by the matching - * Callback objects to be invoked. This method is used - * to safely shut down SWT when it is run within environments - * which can generate spurious events. - *

- * Note: This should not be called by application code. - *

- * - * @param enable true if callbacks should be invoked - */ -public static final synchronized void setEnabled (boolean enable) -{ - return c.setEnabled(enable); -} - -/** - * Returns whether or not callbacks which are triggered at the - * native level should cause the messages described by the matching - * Callback objects to be invoked. This method is used - * to safely shut down SWT when it is run within environments - * which can generate spurious events. - *

- * Note: This should not be called by application code. - *

- * - * @return true if callbacks should not be invoked - */ -public static final synchronized boolean getEnabled () -{ - return c.getEnabled; -} - -/** - * This might be called directly from native code in environments - * which can generate spurious events. Check before removing it. - * - * @deprecated - * - * @param ignore true if callbacks should not be invoked - */ -static final void ignoreCallbacks (boolean ignore) { - setEnabled (!ignore); -} - -/** - * Immediately wipes out all native level state associated - * with all callbacks. - *

- * WARNING: This operation is extremely dangerous, - * and should never be performed by application code. - *

- */ -public static final synchronized void reset (); - -/** - * Releases the native level resources associated with the callback. - * - * @see #dispose - */ -static final synchronized void unbind (Callback callback) -{ - c.unbind(callback); -} - -} diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/internal/cocoa/SWTWindowDelegate.d --- a/dwt/internal/cocoa/SWTWindowDelegate.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/internal/cocoa/SWTWindowDelegate.d Sun Sep 14 23:32:29 2008 +0200 @@ -11,7 +11,7 @@ * Port to the D programming language: * Jacob Carlborg *******************************************************************************/ -module dwt.internal.cocoa.DWTWindowDelegate; +module dwt.internal.cocoa.SWTWindowDelegate; import dwt.internal.cocoa.NSInteger; import dwt.internal.cocoa.NSObject; diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/widgets/Button.d --- a/dwt/widgets/Button.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/widgets/Button.d Sun Sep 14 23:32:29 2008 +0200 @@ -36,7 +36,6 @@ import dwt.internal.cocoa.NSInteger; import dwt.widgets.Composite; import dwt.widgets.Decorations; -import dwt.widgets.ImageList; import dwt.widgets.TypedListener; /** diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/widgets/MenuItem.d --- a/dwt/widgets/MenuItem.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/widgets/MenuItem.d Sun Sep 14 23:32:29 2008 +0200 @@ -7,11 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.widgets.MenuItem; -import dwt.dwthelper.utils; - import dwt.DWT; import dwt.DWTException; @@ -26,6 +27,15 @@ import dwt.internal.cocoa.OS; import dwt.internal.cocoa.SWTMenu; +import dwt.dwthelper.utils; +import dwt.internal.cocoa.NSInteger; +import dwt.widgets.Decorations; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Item; +import dwt.widgets.Menu; +import dwt.widgets.TypedListener; + /** * Instances of this class represent a selectable user interface object * that issues notification when pressed and released. @@ -224,7 +234,7 @@ NSMenu createEmptyMenu () { if ((parent.style & DWT.BAR) !is 0) { - return cast(NSMenu) new SWTMenu ().alloc ().init (); + return cast(NSMenu) (new SWTMenu ()).alloc ().init (); } return null; } @@ -555,11 +565,11 @@ this.accelerator = accelerator; int key = accelerator & DWT.KEY_MASK; int virtualKey = Display.untranslateKey (key); - NSString string = null; + NSString str = null; if (virtualKey !is 0) { - string = NSString.stringWith (cast(wchar)virtualKey + ""); + str = NSString.stringWith (Integer.toString(virtualKey)); } else { - string = NSString.stringWith (cast(wchar)key + "").lowercaseString(); + str = NSString.stringWith (Integer.toString(key)).lowercaseString(); } nsItem.setKeyEquivalent (string); int mask = 0; @@ -568,7 +578,7 @@ // if ((accelerator & DWT.COMMAND) !is 0) mask &= ~OS.kMenuNoCommandModifier; if ((accelerator & DWT.COMMAND) !is 0) mask |= OS.NSCommandKeyMask; if ((accelerator & DWT.ALT) !is 0) mask |= OS.NSAlternateKeyMask; - nsItem.setKeyEquivalentModifierMask (mask); + nsItem.setKeyEquivalentModifierMask (cast(NSUInteger) mask); if ((this.accelerator is 0 && accelerator !is 0) || (this.accelerator !is 0 && accelerator is 0)) { updateText (); } @@ -760,7 +770,7 @@ j--; } } - String text = new String (buffer, 0, j); + String text = new_String (buffer, 0, j); NSMenu submenu = nsItem.submenu (); NSString label = NSString.stringWith (text); if(submenu !is null && (parent.getStyle () & DWT.BAR) !is 0) { diff -r 5123b17c98ef -r 7d135fe0caf2 dwt/widgets/Monitor.d --- a/dwt/widgets/Monitor.d Sun Sep 14 01:45:57 2008 +0200 +++ b/dwt/widgets/Monitor.d Sun Sep 14 23:32:29 2008 +0200 @@ -45,7 +45,7 @@ * * @see #hashCode() */ -public bool opEquals (Object object) { +public int opEquals (Object object) { if (object is this) return true; if (!(cast(dwt.widgets.Monitor.Monitor) object)) return false; dwt.widgets.Monitor.Monitor monitor = cast(dwt.widgets.Monitor.Monitor) object;