diff dwt/widgets/Tracker.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children cfa563df4fdd
line wrap: on
line diff
--- a/dwt/widgets/Tracker.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/Tracker.d	Mon Dec 01 17:07:00 2008 +0100
@@ -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
@@ -22,6 +22,7 @@
 import dwt.graphics.Rectangle;
 import dwt.internal.cocoa.NSAffineTransform;
 import dwt.internal.cocoa.NSApplication;
+import dwt.internal.cocoa.NSArray;
 import dwt.internal.cocoa.NSAutoreleasePool;
 import dwt.internal.cocoa.NSBezierPath;
 import dwt.internal.cocoa.NSDate;
@@ -51,6 +52,9 @@
  * </p><p>
  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
  * </p>
+ *
+ * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class Tracker : Widget {
     Control parent;
@@ -440,7 +444,7 @@
     } else {
         NSWindow eventWindow = nsEvent.window();
         location = eventWindow.convertBaseToScreen(location);
-        location.y = eventWindow.screen().frame().height - location.y;
+        location.y = display.getPrimaryFrame().height - location.y;
     }
     int newX = cast(int)location.x, newY = cast(int)location.y;
     if (newX !is oldX || newY !is oldY) {
@@ -544,7 +548,7 @@
         }
         oldX = newX;  oldY = newY;
     }
-    switch (nsEvent.type()) {
+    switch ((int)/*64*/nsEvent.type()) {
         case OS.NSLeftMouseUp:
         case OS.NSRightMouseUp:
         case OS.NSOtherMouseUp:
@@ -555,7 +559,7 @@
 void key (NSEvent nsEvent) {
     //TODO send event
 //  if (!sendKeyEvent (DWT.KeyDown, theEvent)) return OS.noErr;
-    int modifierFlags = nsEvent.modifierFlags();
+    int /*long*/ modifierFlags = nsEvent.modifierFlags();
     int stepSize = (modifierFlags & OS.NSControlKeyMask) !is 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
     int xChange = 0, yChange = 0;
     switch (nsEvent.keyCode()) {
@@ -716,13 +720,36 @@
     cancelled = false;
     tracking = true;
     window = cast(NSWindow)new NSWindow().alloc();
-    NSRect frame = NSScreen.mainScreen().frame();
-    window = window.initWithContentRect_styleMask_backing_defer_(frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false);
+    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();
+    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;
+        if (x1 < minX) minX = x1;
+        if (x2 < minX) minX = x2;
+        if (x1 > maxX) maxX = x1;
+        if (x2 > maxX) maxX = x2;
+        if (y1 < minY) minY = y1;
+        if (y2 < minY) minY = y2;
+        if (y1 > maxY) maxY = y1;
+        if (y2 > maxY) maxY = y2;
+    }   
+    NSRect frame = new NSRect();
+    frame.x = minX;
+    frame.y = minY;
+    frame.width = maxX - minX;
+    frame.height = maxY - minY;
+    window = window.initWithContentRect(frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false);
     window.setOpaque(false);
     window.setContentView(null);
     NSGraphicsContext context = window.graphicsContext();
     NSGraphicsContext.setCurrentContext(context);
     context.setCompositingOperation(OS.NSCompositeClear);
+    frame.x = frame.y = 0;
     NSBezierPath.fillRect(frame);
     window.orderFrontRegardless();
 
@@ -745,7 +772,7 @@
     bool down = false;
     NSApplication application = NSApplication.sharedApplication();
     NSEvent currentEvent = application.currentEvent();
-    switch (currentEvent.type()) {
+    switch ((int)/*64*/currentEvent.type()) {
         case OS.NSLeftMouseDown:
         case OS.NSRightMouseDown:
         case OS.NSOtherMouseDown:
@@ -770,7 +797,7 @@
         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 = event.type();
+        int type = (int)/*64*/event.type();
         switch (type) {
             case OS.NSLeftMouseUp:
             case OS.NSRightMouseUp: