/** * Displays the Tracker rectangles for manipulation by the user. Returns when the user has either * finished manipulating the rectangles or has cancelled the Tracker. * * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public boolean open() { checkWidget(); cancelled = false; tracking = true; window = (NSWindow) new NSWindow().alloc(); NSRect frame = NSScreen.mainScreen().frame(); window = window.initWithContentRect_styleMask_backing_defer_( frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false); window.setOpaque(false); window.setContentView(null); NSGraphicsContext context = window.graphicsContext(); NSGraphicsContext.setCurrentContext(context); context.setCompositingOperation(OS.NSCompositeClear); NSBezierPath.fillRect(frame); window.orderFrontRegardless(); drawRectangles(window, rectangles, false); /* * If exactly one of UP/DOWN is specified as a style then set the cursor * orientation accordingly (the same is done for LEFT/RIGHT styles below). */ int vStyle = style & (SWT.UP | SWT.DOWN); if (vStyle == SWT.UP || vStyle == SWT.DOWN) { cursorOrientation |= vStyle; } int hStyle = style & (SWT.LEFT | SWT.RIGHT); if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) { cursorOrientation |= hStyle; } Point cursorPos; boolean down = false; NSApplication application = NSApplication.sharedApplication(); NSEvent currentEvent = application.currentEvent(); switch (currentEvent.type()) { case OS.NSLeftMouseDown: case OS.NSRightMouseDown: case OS.NSOtherMouseDown: down = true; } if (down) { cursorPos = display.getCursorLocation(); } else { if ((style & SWT.RESIZE) != 0) { cursorPos = adjustResizeCursor(true); } else { cursorPos = adjustMoveCursor(); } } if (cursorPos != null) { oldX = cursorPos.x; oldY = cursorPos.y; } /* Tracker behaves like a Dialog with its own OS event loop. */ while (tracking && !cancelled) { NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); NSEvent event = application.nextEventMatchingMask( 0, NSDate.distantFuture(), OS.NSDefaultRunLoopMode, true); if (event == null) continue; int type = event.type(); switch (type) { case OS.NSLeftMouseUp: case OS.NSRightMouseUp: case OS.NSOtherMouseUp: case OS.NSMouseMoved: case OS.NSLeftMouseDragged: case OS.NSRightMouseDragged: case OS.NSOtherMouseDragged: mouse(event); break; case OS.NSKeyDown: // case OS.NSKeyUp: case OS.NSFlagsChanged: key(event); break; } /* * Don't dispatch mouse and key events in general, EXCEPT once this * tracker has finished its work. */ boolean dispatch = true; if (!(tracking && !cancelled)) { switch (type) { case OS.NSLeftMouseDown: case OS.NSLeftMouseUp: case OS.NSRightMouseDown: case OS.NSRightMouseUp: case OS.NSOtherMouseDown: case OS.NSOtherMouseUp: case OS.NSMouseMoved: case OS.NSLeftMouseDragged: case OS.NSRightMouseDragged: case OS.NSOtherMouseDragged: case OS.NSMouseEntered: case OS.NSMouseExited: case OS.NSKeyDown: case OS.NSKeyUp: case OS.NSFlagsChanged: dispatch = false; } } if (dispatch) application.sendEvent(event); if (clientCursor != null && resizeCursor == null) { clientCursor.handle.set(); } pool.release(); } if (!isDisposed()) { drawRectangles(window, rectangles, true); } if (window != null) window.close(); tracking = false; window = null; return !cancelled; }