comparison 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
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
20 import dwt.graphics.Cursor; 20 import dwt.graphics.Cursor;
21 import dwt.graphics.Point; 21 import dwt.graphics.Point;
22 import dwt.graphics.Rectangle; 22 import dwt.graphics.Rectangle;
23 import dwt.internal.cocoa.NSAffineTransform; 23 import dwt.internal.cocoa.NSAffineTransform;
24 import dwt.internal.cocoa.NSApplication; 24 import dwt.internal.cocoa.NSApplication;
25 import dwt.internal.cocoa.NSArray;
25 import dwt.internal.cocoa.NSAutoreleasePool; 26 import dwt.internal.cocoa.NSAutoreleasePool;
26 import dwt.internal.cocoa.NSBezierPath; 27 import dwt.internal.cocoa.NSBezierPath;
27 import dwt.internal.cocoa.NSDate; 28 import dwt.internal.cocoa.NSDate;
28 import dwt.internal.cocoa.NSEvent; 29 import dwt.internal.cocoa.NSEvent;
29 import dwt.internal.cocoa.NSGraphicsContext; 30 import dwt.internal.cocoa.NSGraphicsContext;
49 * <p> 50 * <p>
50 * Note: Rectangle move behavior is assumed unless RESIZE is specified. 51 * Note: Rectangle move behavior is assumed unless RESIZE is specified.
51 * </p><p> 52 * </p><p>
52 * IMPORTANT: This class is <em>not</em> intended to be subclassed. 53 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
53 * </p> 54 * </p>
55 *
56 * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
57 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
54 */ 58 */
55 public class Tracker : Widget { 59 public class Tracker : Widget {
56 Control parent; 60 Control parent;
57 bool tracking, cancelled, stippled; 61 bool tracking, cancelled, stippled;
58 Cursor clientCursor, resizeCursor; 62 Cursor clientCursor, resizeCursor;
438 if (parent !is null) { 442 if (parent !is null) {
439 location = parent.view.convertPoint_toView_(location, parent.view); 443 location = parent.view.convertPoint_toView_(location, parent.view);
440 } else { 444 } else {
441 NSWindow eventWindow = nsEvent.window(); 445 NSWindow eventWindow = nsEvent.window();
442 location = eventWindow.convertBaseToScreen(location); 446 location = eventWindow.convertBaseToScreen(location);
443 location.y = eventWindow.screen().frame().height - location.y; 447 location.y = display.getPrimaryFrame().height - location.y;
444 } 448 }
445 int newX = cast(int)location.x, newY = cast(int)location.y; 449 int newX = cast(int)location.x, newY = cast(int)location.y;
446 if (newX !is oldX || newY !is oldY) { 450 if (newX !is oldX || newY !is oldY) {
447 Rectangle [] oldRectangles = rectangles; 451 Rectangle [] oldRectangles = rectangles;
448 Rectangle [] rectsToErase = new Rectangle [rectangles.length]; 452 Rectangle [] rectsToErase = new Rectangle [rectangles.length];
542 drawRectangles (window, rectangles, false); 546 drawRectangles (window, rectangles, false);
543 } 547 }
544 } 548 }
545 oldX = newX; oldY = newY; 549 oldX = newX; oldY = newY;
546 } 550 }
547 switch (nsEvent.type()) { 551 switch ((int)/*64*/nsEvent.type()) {
548 case OS.NSLeftMouseUp: 552 case OS.NSLeftMouseUp:
549 case OS.NSRightMouseUp: 553 case OS.NSRightMouseUp:
550 case OS.NSOtherMouseUp: 554 case OS.NSOtherMouseUp:
551 tracking = false; 555 tracking = false;
552 } 556 }
553 } 557 }
554 558
555 void key (NSEvent nsEvent) { 559 void key (NSEvent nsEvent) {
556 //TODO send event 560 //TODO send event
557 // if (!sendKeyEvent (DWT.KeyDown, theEvent)) return OS.noErr; 561 // if (!sendKeyEvent (DWT.KeyDown, theEvent)) return OS.noErr;
558 int modifierFlags = nsEvent.modifierFlags(); 562 int /*long*/ modifierFlags = nsEvent.modifierFlags();
559 int stepSize = (modifierFlags & OS.NSControlKeyMask) !is 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE; 563 int stepSize = (modifierFlags & OS.NSControlKeyMask) !is 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
560 int xChange = 0, yChange = 0; 564 int xChange = 0, yChange = 0;
561 switch (nsEvent.keyCode()) { 565 switch (nsEvent.keyCode()) {
562 case 53: /* Esc */ 566 case 53: /* Esc */
563 cancelled = true; 567 cancelled = true;
714 public bool open () { 718 public bool open () {
715 checkWidget (); 719 checkWidget ();
716 cancelled = false; 720 cancelled = false;
717 tracking = true; 721 tracking = true;
718 window = cast(NSWindow)new NSWindow().alloc(); 722 window = cast(NSWindow)new NSWindow().alloc();
719 NSRect frame = NSScreen.mainScreen().frame(); 723 NSArray screens = NSScreen.screens();
720 window = window.initWithContentRect_styleMask_backing_defer_(frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false); 724 float /*double*/ minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE;
725 float /*double*/ minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
726 int count = (int)/*64*/screens.count();
727 for (int i = 0; i < count; i++) {
728 NSScreen screen = new NSScreen(screens.objectAtIndex(i));
729 NSRect frame = screen.frame();
730 float /*double*/ x1 = frame.x, x2 = frame.x + frame.width;
731 float /*double*/ y1 = frame.y, y2 = frame.y + frame.height;
732 if (x1 < minX) minX = x1;
733 if (x2 < minX) minX = x2;
734 if (x1 > maxX) maxX = x1;
735 if (x2 > maxX) maxX = x2;
736 if (y1 < minY) minY = y1;
737 if (y2 < minY) minY = y2;
738 if (y1 > maxY) maxY = y1;
739 if (y2 > maxY) maxY = y2;
740 }
741 NSRect frame = new NSRect();
742 frame.x = minX;
743 frame.y = minY;
744 frame.width = maxX - minX;
745 frame.height = maxY - minY;
746 window = window.initWithContentRect(frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false);
721 window.setOpaque(false); 747 window.setOpaque(false);
722 window.setContentView(null); 748 window.setContentView(null);
723 NSGraphicsContext context = window.graphicsContext(); 749 NSGraphicsContext context = window.graphicsContext();
724 NSGraphicsContext.setCurrentContext(context); 750 NSGraphicsContext.setCurrentContext(context);
725 context.setCompositingOperation(OS.NSCompositeClear); 751 context.setCompositingOperation(OS.NSCompositeClear);
752 frame.x = frame.y = 0;
726 NSBezierPath.fillRect(frame); 753 NSBezierPath.fillRect(frame);
727 window.orderFrontRegardless(); 754 window.orderFrontRegardless();
728 755
729 drawRectangles (window, rectangles, false); 756 drawRectangles (window, rectangles, false);
730 757
743 770
744 Point cursorPos; 771 Point cursorPos;
745 bool down = false; 772 bool down = false;
746 NSApplication application = NSApplication.sharedApplication(); 773 NSApplication application = NSApplication.sharedApplication();
747 NSEvent currentEvent = application.currentEvent(); 774 NSEvent currentEvent = application.currentEvent();
748 switch (currentEvent.type()) { 775 switch ((int)/*64*/currentEvent.type()) {
749 case OS.NSLeftMouseDown: 776 case OS.NSLeftMouseDown:
750 case OS.NSRightMouseDown: 777 case OS.NSRightMouseDown:
751 case OS.NSOtherMouseDown: 778 case OS.NSOtherMouseDown:
752 down = true; 779 down = true;
753 } 780 }
768 /* Tracker behaves like a Dialog with its own OS event loop. */ 795 /* Tracker behaves like a Dialog with its own OS event loop. */
769 while (tracking && !cancelled) { 796 while (tracking && !cancelled) {
770 NSAutoreleasePool pool = cast(NSAutoreleasePool)new NSAutoreleasePool().alloc().init(); 797 NSAutoreleasePool pool = cast(NSAutoreleasePool)new NSAutoreleasePool().alloc().init();
771 NSEvent event = application.nextEventMatchingMask(0, NSDate.distantFuture(), OS.NSDefaultRunLoopMode, true); 798 NSEvent event = application.nextEventMatchingMask(0, NSDate.distantFuture(), OS.NSDefaultRunLoopMode, true);
772 if (event is null) continue; 799 if (event is null) continue;
773 int type = event.type(); 800 int type = (int)/*64*/event.type();
774 switch (type) { 801 switch (type) {
775 case OS.NSLeftMouseUp: 802 case OS.NSLeftMouseUp:
776 case OS.NSRightMouseUp: 803 case OS.NSRightMouseUp:
777 case OS.NSOtherMouseUp: 804 case OS.NSOtherMouseUp:
778 case OS.NSMouseMoved: 805 case OS.NSMouseMoved: