Mercurial > projects > dwt-mac
diff dwt/graphics/Cursor.d @ 35:7d135fe0caf2
Ported dwt.graphics.Cursor and dwt.widgets.MenuItem
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 14 Sep 2008 23:32:29 +0200 |
parents | a9ab4c738ed8 |
children | db5a898b2119 |
line wrap: on
line diff
--- 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 <jacob.carlborg@gmail.com> *******************************************************************************/ 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 <code>true</code> 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 <code>true</code> if the cursor has been disposed, * and <code>false</code> otherwise. @@ -388,7 +403,7 @@ */ public String toString () { if (isDisposed()) return "Cursor {*DISPOSED*}"; - return "Cursor {" + handle + "}"; + return Format("Cursor {{}{}" , handle , "}"); } /**