# HG changeset patch # User Jacob Carlborg # Date 1230491240 -3600 # Node ID 102ff2adce19dbbcf64994b79620bd550e43d726 # Parent 844f65808a36fbdd5552105ebf039185622913ba Ported dwt.widgets.Tracker diff -r 844f65808a36 -r 102ff2adce19 dwt/internal/cocoa/OS.d --- a/dwt/internal/cocoa/OS.d Sun Dec 28 19:47:54 2008 +0100 +++ b/dwt/internal/cocoa/OS.d Sun Dec 28 20:07:20 2008 +0100 @@ -2836,7 +2836,7 @@ public static const int NSColorRenderingIntentRelativeColorimetric = 2; public static const int NSColorRenderingIntentSaturation = 4; public static const Cocoa.NSUInteger NSCommandKeyMask = 1048576; -public static const int NSCompositeClear = 0; +alias Cocoa.NSCompositingOperation.NSCompositeClear NSCompositeClear; public static const int NSCompositeCopy = 1; public static const int NSCompositeDestinationAtop = 9; public static const int NSCompositeDestinationIn = 7; diff -r 844f65808a36 -r 102ff2adce19 dwt/widgets/Tracker.d --- a/dwt/widgets/Tracker.d Sun Dec 28 19:47:54 2008 +0100 +++ b/dwt/widgets/Tracker.d Sun Dec 28 20:07:20 2008 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.widgets.Tracker; @@ -34,6 +37,15 @@ import dwt.internal.cocoa.NSWindow; import dwt.internal.cocoa.OS; +import dwt.internal.c.Carbon; +import dwt.internal.objc.cocoa.Cocoa; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.TypedListener; +import dwt.widgets.Widget; + /** * Instances of this class implement rubber banding rectangles that are * drawn onto a parent Composite or Display. @@ -60,7 +72,8 @@ Control parent; bool tracking, cancelled, stippled; Cursor clientCursor, resizeCursor; - Rectangle [] rectangles = new Rectangle [0], proportions = rectangles; + Rectangle [] rectangles; + Rectangle [] proportions; Rectangle bounds; int cursorOrientation = DWT.NONE; bool inEvent = false; @@ -70,8 +83,14 @@ /* * The following values mirror step sizes on Windows */ - final static int STEPSIZE_SMALL = 1; - final static int STEPSIZE_LARGE = 9; + const static int STEPSIZE_SMALL = 1; + const static int STEPSIZE_LARGE = 9; + + static this () + { + rectangles = new Rectangle [0]; + proportions = rectangles; + } /** * Constructs a new instance of this class given its parent @@ -387,12 +406,12 @@ frame.width = rect.width; frame.height = rect.height; if (erase) { - frame.width++; - frame.height++; + frame.size.width++; + frame.size.height++; NSBezierPath.fillRect(frame); } else { - frame.x += 0.5f; - frame.y += 0.5f; + frame.origin.x += 0.5f; + frame.origin.y += 0.5f; NSBezierPath.strokeRect(frame); } } @@ -548,18 +567,19 @@ } oldX = newX; oldY = newY; } - switch ((int)/*64*/nsEvent.type()) { + switch (cast(int)/*64*/nsEvent.type()) { case OS.NSLeftMouseUp: case OS.NSRightMouseUp: case OS.NSOtherMouseUp: tracking = false; + default: } } void key (NSEvent nsEvent) { //TODO send event // if (!sendKeyEvent (DWT.KeyDown, theEvent)) return OS.noErr; - int /*long*/ modifierFlags = nsEvent.modifierFlags(); + NSUInteger modifierFlags = nsEvent.modifierFlags(); int stepSize = (modifierFlags & OS.NSControlKeyMask) !is 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE; int xChange = 0, yChange = 0; switch (nsEvent.keyCode()) { @@ -583,6 +603,7 @@ case 125: /* Down arrow */ yChange = stepSize; break; + default: } if (xChange !is 0 || yChange !is 0) { Rectangle [] oldRectangles = rectangles; @@ -719,16 +740,16 @@ checkWidget (); cancelled = false; tracking = true; - window = cast(NSWindow)new NSWindow().alloc(); + window = cast(NSWindow)(new NSWindow()).alloc(); NSArray screens = NSScreen.screens(); - float /*double*/ minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE; - float /*double*/ minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE; - int count = (int)/*64*/screens.count(); + CGFloat minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE; + CGFloat minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE; + int count = cast(int)/*64*/screens.count(); for (int i = 0; i < count; i++) { NSScreen screen = new NSScreen(screens.objectAtIndex(i)); NSRect frame = screen.frame(); - float /*double*/ x1 = frame.x, x2 = frame.x + frame.width; - float /*double*/ y1 = frame.y, y2 = frame.y + frame.height; + CGFloat x1 = frame.x, x2 = frame.x + frame.width; + CGFloat y1 = frame.y, y2 = frame.y + frame.height; if (x1 < minX) minX = x1; if (x2 < minX) minX = x2; if (x1 > maxX) maxX = x1; @@ -772,11 +793,12 @@ bool down = false; NSApplication application = NSApplication.sharedApplication(); NSEvent currentEvent = application.currentEvent(); - switch ((int)/*64*/currentEvent.type()) { + switch (currentEvent.type()) { case OS.NSLeftMouseDown: case OS.NSRightMouseDown: case OS.NSOtherMouseDown: down = true; + default: } if (down) { cursorPos = display.getCursorLocation(); @@ -794,10 +816,10 @@ /* Tracker behaves like a Dialog with its own OS event loop. */ while (tracking && !cancelled) { - NSAutoreleasePool pool = cast(NSAutoreleasePool)new NSAutoreleasePool().alloc().init(); + NSAutoreleasePool pool = cast(NSAutoreleasePool)(new NSAutoreleasePool()).alloc().init(); NSEvent event = application.nextEventMatchingMask(0, NSDate.distantFuture(), OS.NSDefaultRunLoopMode, true); if (event is null) continue; - int type = (int)/*64*/event.type(); + NSEventType type = event.type(); switch (type) { case OS.NSLeftMouseUp: case OS.NSRightMouseUp: @@ -813,6 +835,7 @@ case OS.NSFlagsChanged: key(event); break; + default: } /* * Don't dispatch mouse and key events in general, EXCEPT once this @@ -837,6 +860,7 @@ case OS.NSKeyUp: case OS.NSFlagsChanged: dispatch = false; + default: } } if (dispatch) application.sendEvent(event); @@ -1077,9 +1101,9 @@ public void setRectangles (Rectangle [] rectangles) { checkWidget (); if (rectangles is null) error (DWT.ERROR_NULL_ARGUMENT); - int length = rectangles.length; - this.rectangles = new Rectangle [length]; - for (int i = 0; i < length; i++) { + size_t length_ = rectangles.length; + this.rectangles = new Rectangle [length_]; + for (size_t i = 0; i < length_; i++) { Rectangle current = rectangles [i]; if (current is null) error (DWT.ERROR_NULL_ARGUMENT); this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);