Ken Thomases : winemac: Consolidate mouse button handling into -[ WineApplicationController handleMouseButton:].

Alexandre Julliard julliard at winehq.org
Tue May 7 15:54:05 CDT 2013


Module: wine
Branch: master
Commit: e15b82ad1bd9bc69ea2f7a8dfe0bd76d595a7b47
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e15b82ad1bd9bc69ea2f7a8dfe0bd76d595a7b47

Author: Ken Thomases <ken at codeweavers.com>
Date:   Tue May  7 03:00:42 2013 -0500

winemac: Consolidate mouse button handling into -[WineApplicationController handleMouseButton:].

---

 dlls/winemac.drv/cocoa_app.h    |    1 +
 dlls/winemac.drv/cocoa_app.m    |   94 ++++++++++++++++++++++++++++++++++++--
 dlls/winemac.drv/cocoa_window.m |   32 -------------
 3 files changed, 90 insertions(+), 37 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_app.h b/dlls/winemac.drv/cocoa_app.h
index f0cdfc3..5e4d181 100644
--- a/dlls/winemac.drv/cocoa_app.h
+++ b/dlls/winemac.drv/cocoa_app.h
@@ -61,6 +61,7 @@ enum {
     WineWindow* lastTargetWindow;
     BOOL forceNextMouseMoveAbsolute;
     double mouseMoveDeltaX, mouseMoveDeltaY;
+    NSUInteger unmatchedMouseDowns;
 
     NSMutableArray* orderedWineWindows;
 
diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index 3ef84e0..bba9859 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -1219,6 +1219,87 @@ int macdrv_err_on;
         }
     }
 
+    - (void) handleMouseButton:(NSEvent*)theEvent
+    {
+        WineWindow* window = (WineWindow*)[theEvent window];
+
+        if ([window isKindOfClass:[WineWindow class]])
+        {
+            NSEventType type = [theEvent type];
+            BOOL pressed = (type == NSLeftMouseDown || type == NSRightMouseDown || type == NSOtherMouseDown);
+            CGPoint pt = CGEventGetLocation([theEvent CGEvent]);
+            BOOL process;
+
+            if (pressed)
+            {
+                // Test if the click was in the window's content area.
+                NSPoint nspoint = [self flippedMouseLocation:NSPointFromCGPoint(pt)];
+                NSRect contentRect = [window contentRectForFrameRect:[window frame]];
+                process = NSPointInRect(nspoint, contentRect);
+                if (process && [window styleMask] & NSResizableWindowMask)
+                {
+                    // Ignore clicks in the grow box (resize widget).
+                    HIPoint origin = { 0, 0 };
+                    HIThemeGrowBoxDrawInfo info = { 0 };
+                    HIRect bounds;
+                    OSStatus status;
+
+                    info.kind = kHIThemeGrowBoxKindNormal;
+                    info.direction = kThemeGrowRight | kThemeGrowDown;
+                    if ([window styleMask] & NSUtilityWindowMask)
+                        info.size = kHIThemeGrowBoxSizeSmall;
+                    else
+                        info.size = kHIThemeGrowBoxSizeNormal;
+
+                    status = HIThemeGetGrowBoxBounds(&origin, &info, &bounds);
+                    if (status == noErr)
+                    {
+                        NSRect growBox = NSMakeRect(NSMaxX(contentRect) - bounds.size.width,
+                                                    NSMinY(contentRect),
+                                                    bounds.size.width,
+                                                    bounds.size.height);
+                        process = !NSPointInRect(nspoint, growBox);
+                    }
+                }
+                if (process)
+                    unmatchedMouseDowns |= NSEventMaskFromType(type);
+            }
+            else
+            {
+                NSEventType downType = type - 1;
+                NSUInteger downMask = NSEventMaskFromType(downType);
+                process = (unmatchedMouseDowns & downMask) != 0;
+                unmatchedMouseDowns &= ~downMask;
+            }
+
+            if (process)
+            {
+                macdrv_event* event;
+
+                event = macdrv_create_event(MOUSE_BUTTON, window);
+                event->mouse_button.button = [theEvent buttonNumber];
+                event->mouse_button.pressed = pressed;
+                event->mouse_button.x = pt.x;
+                event->mouse_button.y = pt.y;
+                event->mouse_button.time_ms = [self ticksForEventTime:[theEvent timestamp]];
+
+                [window.queue postEvent:event];
+
+                macdrv_release_event(event);
+            }
+        }
+
+        // Since mouse button events deliver absolute cursor position, the
+        // accumulating delta from move events is invalidated.  Make sure
+        // next mouse move event starts over from an absolute baseline.
+        // Also, it's at least possible that the title bar widgets (e.g. close
+        // button, etc.) could enter an internal event loop on a mouse down that
+        // wouldn't exit until a mouse up.  In that case, we'd miss any mouse
+        // dragged events and, after that, any notion of the cursor position
+        // computed from accumulating deltas would be wrong.
+        forceNextMouseMoveAbsolute = TRUE;
+    }
+
     // Returns TRUE if the event was handled and caller should do nothing more
     // with it.  Returns FALSE if the caller should process it as normal and
     // then call -didSendEvent:.
@@ -1240,12 +1321,15 @@ int macdrv_err_on;
         }
         else if (type == NSLeftMouseDown || type == NSLeftMouseUp ||
                  type == NSRightMouseDown || type == NSRightMouseUp ||
-                 type == NSOtherMouseDown || type == NSOtherMouseUp ||
-                 type == NSScrollWheel)
+                 type == NSOtherMouseDown || type == NSOtherMouseUp)
+        {
+            [self handleMouseButton:anEvent];
+        }
+        else if (type == NSScrollWheel)
         {
-            // Since mouse button and scroll wheel events deliver absolute cursor
-            // position, the accumulating delta from move events is invalidated.
-            // Make sure next mouse move event starts over from an absolute baseline.
+            // Since scroll wheel events deliver absolute cursor position, the
+            // accumulating delta from move events is invalidated.  Make sure next
+            // mouse move event starts over from an absolute baseline.
             forceNextMouseMoveAbsolute = TRUE;
         }
         else if (type == NSKeyDown && ![anEvent isARepeat] && [anEvent keyCode] == kVK_Tab)
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
index 80bf9a4..0a751bd 100644
--- a/dlls/winemac.drv/cocoa_window.m
+++ b/dlls/winemac.drv/cocoa_window.m
@@ -250,13 +250,6 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers)
         }
     }
 
-    /* By default, NSView will swallow right-clicks in an attempt to support contextual
-       menus.  We need to bypass that and allow the event to make it to the window. */
-    - (void) rightMouseDown:(NSEvent*)theEvent
-    {
-        [[self window] rightMouseDown:theEvent];
-    }
-
     - (void) addGLContext:(WineOpenGLContext*)context
     {
         if (!glContexts)
@@ -839,23 +832,6 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers)
         [self checkTransparency];
     }
 
-    - (void) postMouseButtonEvent:(NSEvent *)theEvent pressed:(int)pressed
-    {
-        CGPoint pt = CGEventGetLocation([theEvent CGEvent]);
-        macdrv_event* event;
-
-        event = macdrv_create_event(MOUSE_BUTTON, self);
-        event->mouse_button.button = [theEvent buttonNumber];
-        event->mouse_button.pressed = pressed;
-        event->mouse_button.x = pt.x;
-        event->mouse_button.y = pt.y;
-        event->mouse_button.time_ms = [[WineApplicationController sharedController] ticksForEventTime:[theEvent timestamp]];
-
-        [queue postEvent:event];
-
-        macdrv_release_event(event);
-    }
-
     - (void) makeFocused:(BOOL)activate
     {
         WineApplicationController* controller = [WineApplicationController sharedController];
@@ -1061,14 +1037,6 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers)
     /*
      * ---------- NSResponder method overrides ----------
      */
-    - (void) mouseDown:(NSEvent *)theEvent { [self postMouseButtonEvent:theEvent pressed:1]; }
-    - (void) rightMouseDown:(NSEvent *)theEvent { [self mouseDown:theEvent]; }
-    - (void) otherMouseDown:(NSEvent *)theEvent { [self mouseDown:theEvent]; }
-
-    - (void) mouseUp:(NSEvent *)theEvent { [self postMouseButtonEvent:theEvent pressed:0]; }
-    - (void) rightMouseUp:(NSEvent *)theEvent { [self mouseUp:theEvent]; }
-    - (void) otherMouseUp:(NSEvent *)theEvent { [self mouseUp:theEvent]; }
-
     - (void) keyDown:(NSEvent *)theEvent { [self postKeyEvent:theEvent]; }
     - (void) keyUp:(NSEvent *)theEvent   { [self postKeyEvent:theEvent]; }
 




More information about the wine-cvs mailing list