diff options
author | Scott Kovatch <skovatch> | 2010-12-20 23:59:29 +0000 |
---|---|---|
committer | Scott Kovatch <skovatch> | 2010-12-20 23:59:29 +0000 |
commit | 01725ae6a7a6992a9a2b62746d985a9d4dbdb4ca (patch) | |
tree | 8a6bc68606cc831505d15b3e606097048ba1b73e /bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse | |
parent | 46958a15f43936733bc819b97c827c339d68bc9e (diff) | |
download | eclipse.platform.swt-01725ae6a7a6992a9a2b62746d985a9d4dbdb4ca.tar.gz eclipse.platform.swt-01725ae6a7a6992a9a2b62746d985a9d4dbdb4ca.tar.xz eclipse.platform.swt-01725ae6a7a6992a9a2b62746d985a9d4dbdb4ca.zip |
279884 - implement Mac portion of gesture support, and add stubs for all other platforms.
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse')
4 files changed, 216 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java index 3d9df043ce..a7ff638e64 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java @@ -941,6 +941,9 @@ void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { NSEvent nsEvent = new NSEvent(theEvent); boolean handled = false; float /*double*/ delta = nsEvent.deltaY(); + if (display.gestureStarted) { + if (!sendGestureEvent(nsEvent, SWT.GESTURE_PAN, true)) handled = true; + } if (delta != 0) { boolean doit = true; if (hooks (SWT.MouseWheel) || filters (SWT.MouseWheel)) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java index 94b0ad1141..e72bdd255b 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java @@ -385,6 +385,30 @@ public void addFocusListener(FocusListener listener) { } /** + * Removes the listener from the collection of listeners who will + * be notified when gesture events are generated for the control. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see GestureListener + * @see #addGestureListener + */ +public void addGestureListener (GestureListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Gesture, typedListener); +} + +/** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, * by sending it one of the messages defined in the @@ -658,6 +682,16 @@ boolean becomeFirstResponder (int /*long*/ id, int /*long*/ sel) { return super.becomeFirstResponder (id, sel); } +void beginGestureWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + if (!gestureEvent(id, sel, event, SWT.GESTURE_BEGIN)) return; + super.beginGestureWithEvent(id, sel, event); +} + +void endGestureWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + if (!gestureEvent(id, sel, event, SWT.GESTURE_END)) return; + super.endGestureWithEvent(id, sel, event); +} + void calculateVisibleRegion (NSView view, int /*long*/ visibleRgn, boolean clipChildren) { int /*long*/ tempRgn = OS.NewRgn (); if (!view.isHiddenOrHasHiddenAncestor() && isDrawing()) { @@ -1351,6 +1385,17 @@ boolean forceFocus (NSView focusView) { return view.window ().makeFirstResponder (focusView); } +boolean gestureEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event, int detail) { + // For cross-platform compatibility, touch events and gestures are mutually exclusive. + // Don't send a gesture if touch events are enabled for this control. +// if (touchEnabled) return true; + if (!display.sendEvent) return true; + display.sendEvent = false; + if (!isEventView (id)) return true; + NSEvent nsEvent = new NSEvent(event); + return sendGestureEvent (nsEvent, detail, true); +} + /** * Returns the accessible object for the receiver. * If this is the first time this object is requested, @@ -2193,6 +2238,11 @@ void keyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { super.keyUp (id, sel, theEvent); } +void magnifyWithEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + if (!gestureEvent(id, sel, event, SWT.GESTURE_MAGNIFY)) return; + super.magnifyWithEvent(id, sel, event); +} + void markLayout (boolean changed, boolean all) { /* Do nothing */ } @@ -2229,8 +2279,13 @@ Decorations menuShell () { void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { boolean handled = false; if (id == view.id) { + NSEvent nsEvent = new NSEvent(theEvent); + if (display.gestureStarted && hooks(SWT.Gesture)) { + if (!sendGestureEvent(nsEvent, SWT.GESTURE_PAN, true)) { + handled = true; + } + } if (hooks (SWT.MouseWheel) || filters (SWT.MouseWheel)) { - NSEvent nsEvent = new NSEvent(theEvent); if (nsEvent.deltaY() != 0) { if (!sendMouseEvent(nsEvent, SWT.MouseWheel, true)) { handled = true; @@ -2238,7 +2293,6 @@ void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { } } if (hooks (SWT.MouseHorizontalWheel) || filters (SWT.MouseHorizontalWheel)) { - NSEvent nsEvent = new NSEvent(theEvent); if (nsEvent.deltaX() != 0) { if (!sendMouseEvent(nsEvent, SWT.MouseHorizontalWheel, true)) { handled = true; @@ -2728,6 +2782,31 @@ public void removeFocusListener(FocusListener listener) { /** * Removes the listener from the collection of listeners who will + * be notified when a gesture is performed on the control + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see GestureListener + * @see #addGestureListener + * @since 3.7 + */ +public void removeGestureListener (GestureListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Gesture, listener); +} + +/** + * Removes the listener from the collection of listeners who will * be notified when the help events are generated for the control. * * @param listener the listener which should no longer be notified @@ -2994,6 +3073,11 @@ void resized () { sendEvent (SWT.Resize); } +void rotateWithEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + if (!gestureEvent(id, sel, event, SWT.GESTURE_ROTATE)) return; + super.rotateWithEvent(id, sel, event); +} + boolean sendDragEvent (int button, int stateMask, int x, int y) { Event event = new Event (); event.button = button; @@ -3035,6 +3119,56 @@ void sendFocusEvent (int type) { } } +boolean sendGestureEvent (NSEvent nsEvent, int detail, boolean send) { + Event event = new Event (); + NSPoint windowPoint; + NSView view = eventView (); + windowPoint = nsEvent.locationInWindow(); + NSPoint point = view.convertPoint_fromView_(windowPoint, null); + if (!view.isFlipped ()) { + point.y = view.bounds().height - point.y; + } + event.x = (int) point.x; + event.y = (int) point.y; + setInputState (event, nsEvent, SWT.Gesture); + event.detail = detail; + + if (detail == SWT.GESTURE_BEGIN) { + display.gestureStarted = true; + display.rotation = 0.0; + display.magnification = 1.0; + } else if (detail == SWT.GESTURE_END) { + display.gestureStarted = false; + } + + switch (detail) { + case SWT.GESTURE_SWIPE: + event.xDirection = (int) -nsEvent.deltaX(); + event.yDirection = (int) -nsEvent.deltaY(); + break; + case SWT.GESTURE_ROTATE: { + display.rotation += nsEvent.rotation(); + event.rotation = display.rotation; + break; + } + case SWT.GESTURE_MAGNIFY: + display.magnification += nsEvent.magnification(); + event.magnification = display.magnification; + break; + case SWT.GESTURE_PAN: + // Panning increment is expressed in terms of the direction of movement, + // not in terms of scrolling increment. + event.xDirection = (int) -nsEvent.deltaX(); + event.yDirection = (int) -nsEvent.deltaY(); + break; + } + + event.doit = true; + sendEvent (SWT.Gesture, event); + if (isDisposed ()) return false; + return event.doit; +} + boolean sendMouseEvent (NSEvent nsEvent, int type, boolean send) { Shell shell = null; Event event = new Event (); @@ -3944,6 +4078,11 @@ void sort (int [] items) { } } +void swipeWithEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + if (!gestureEvent(id, sel, event, SWT.GESTURE_SWIPE)) return; + super.swipeWithEvent(id, sel, event); +} + NSSize textExtent (String string) { NSAttributedString attribStr = createString(string, null, null, 0, false, true, false); NSSize size = attribStr.size(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index a803944620..43874f46f0 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -104,6 +104,11 @@ public class Display extends Device { boolean disposing; int sendEventCount; + /* gesture event state */ + double rotation; + double magnification; + boolean gestureStarted; + /* Key event management */ int [] deadKeyState = new int[1]; int currentKeyboardUCHRdata; @@ -2130,6 +2135,16 @@ void addEventMethods (int /*long*/ cls, int /*long*/ proc2, int /*long*/ proc3, OS.class_addMethod(cls, OS.sel_acceptsFirstMouse_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_changeColor_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_cancelOperation_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_touchesBeganWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_touchesMovedWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_touchesEndedWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_touchesCancelledWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_beginGestureWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_endGestureWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_swipeWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_rotateWithEvent_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_magnifyWithEvent_, proc3, "@:@"); + } if (proc2 != 0) { OS.class_addMethod(cls, OS.sel_resignFirstResponder, proc2, "@:"); @@ -4774,6 +4789,7 @@ void applicationSendEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event case OS.NSKeyDown: case OS.NSKeyUp: case OS.NSScrollWheel: + // TODO: Add touch detection here... if (window != null) { Shell shell = (Shell) getWidget (window.id); if (shell != null) { @@ -5436,6 +5452,24 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ a widget.windowDidMiniturize(id, sel, arg0); } else if (sel == OS.sel_windowDidDeminiaturize_) { widget.windowDidDeminiturize(id, sel, arg0); + } else if (sel == OS.sel_touchesBeganWithEvent_) { + widget.touchesBeganWithEvent(id, sel, arg0); + } else if (sel == OS.sel_touchesMovedWithEvent_) { + widget.touchesMovedWithEvent(id, sel, arg0); + } else if (sel == OS.sel_touchesEndedWithEvent_) { + widget.touchesEndedWithEvent(id, sel, arg0); + } else if (sel == OS.sel_touchesCancelledWithEvent_) { + widget.touchesCancelledWithEvent(id, sel, arg0); + } else if (sel == OS.sel_beginGestureWithEvent_) { + widget.beginGestureWithEvent(id, sel, arg0); + } else if (sel == OS.sel_endGestureWithEvent_) { + widget.endGestureWithEvent(id, sel, arg0); + } else if (sel == OS.sel_swipeWithEvent_) { + widget.swipeWithEvent(id, sel, arg0); + } else if (sel == OS.sel_magnifyWithEvent_) { + widget.magnifyWithEvent(id, sel, arg0); + } else if (sel == OS.sel_rotateWithEvent_) { + widget.rotateWithEvent(id, sel, arg0); } else if (sel == OS.sel_toolbarAllowedItemIdentifiers_) { return widget.toolbarAllowedItemIdentifiers(id, sel, arg0); } else if (sel == OS.sel_toolbarDefaultItemIdentifiers_) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java index adfa2052a6..32fdb97187 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java @@ -1666,6 +1666,7 @@ boolean setInputState (Event event, NSEvent nsEvent, int type) { case OS.NSScrollWheel: case OS.NSKeyDown: case OS.NSKeyUp: + case OS.NSEventTypeGesture: int state = OS.GetCurrentButtonState (); if ((state & 0x1) != 0) event.stateMask |= SWT.BUTTON1; if ((state & 0x2) != 0) event.stateMask |= SWT.BUTTON3; @@ -1698,6 +1699,7 @@ boolean setInputState (Event event, NSEvent nsEvent, int type) { if (event.keyCode == SWT.COMMAND) event.stateMask &= ~SWT.COMMAND; break; case SWT.KeyUp: + case SWT.Gesture: if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT; if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT; if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL; @@ -1987,6 +1989,42 @@ public String toString () { return getName () + " {" + string + "}"; } +void touchesBeganWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void touchesCancelledWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void touchesEndedWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void touchesMovedWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void beginGestureWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void endGestureWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void magnifyWithEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void rotateWithEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + +void swipeWithEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) { + callSuper(id, sel, event); +} + void resetCursorRects (int /*long*/ id, int /*long*/ sel) { callSuper (id, sel); } |