]> git.saurik.com Git - wxWidgets.git/commitdiff
add more high-level event concepts, fixing native button number
authorStefan Csomor <csomor@advancedconcepts.ch>
Tue, 11 Jun 2013 22:25:21 +0000 (22:25 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Tue, 11 Jun 2013 22:25:21 +0000 (22:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74169 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/uiaction_osx.cpp

index d480f8381771c2879399ba6a9bdb6e2cb5d5e02f..5c1bbade278bb149fcfca1f7ae36200788e70072 100644 (file)
@@ -53,7 +53,53 @@ CGEventType CGEventTypeForMouseButton(int button, bool isDown)
             return isDown ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
     }
 }
+    
+CGEventType CGEventTypeForMouseDrag(int button)
+{
+    switch ( button )
+    {
+        case wxMOUSE_BTN_LEFT:
+            return kCGEventLeftMouseDragged;
+            break;
+            
+        case wxMOUSE_BTN_RIGHT:
+            return kCGEventRightMouseDragged;
+            break;
+            
+            // All the other buttons use the constant OtherMouseDown but we still
+            // want to check for invalid parameters so assert first
+        default:
+            wxFAIL_MSG("Unsupported button passed in.");
+            // fall back to the only known remaining case
+            
+        case wxMOUSE_BTN_MIDDLE:
+            return kCGEventOtherMouseDragged;
+            break;
+    }
+
+}
 
+CGMouseButton CGButtonForMouseButton(int button)
+{
+    switch ( button )
+    {
+        case wxMOUSE_BTN_LEFT:
+            return kCGMouseButtonLeft;
+            
+        case wxMOUSE_BTN_RIGHT:
+            return kCGMouseButtonRight;
+            
+            // All the other buttons use the constant OtherMouseDown but we still
+            // want to check for invalid parameters so assert first
+        default:
+            wxFAIL_MSG("Unsupported button passed in.");
+            // fall back to the only known remaining case
+            
+        case wxMOUSE_BTN_MIDDLE:
+            return kCGMouseButtonCenter;
+    }
+}
+    
 CGPoint GetMousePosition()
 {
     int x, y;
@@ -72,7 +118,48 @@ bool wxUIActionSimulator::MouseDown(int button)
 {
     CGEventType type = CGEventTypeForMouseButton(button, true);
     wxCFRef<CGEventRef> event(
-            CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));
+            CGEventCreateMouseEvent(NULL, type, GetMousePosition(), CGButtonForMouseButton(button)));
+
+    if ( !event )
+        return false;
+
+    CGEventSetType(event, type);
+    CGEventPost(tap, event);
+    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
+    if (loop)
+        loop->SetShouldWaitForEvent(true);
+    
+    return true;
+}
+
+bool wxUIActionSimulator::MouseMove(long x, long y)
+{
+    CGPoint pos;
+    pos.x = x;
+    pos.y = y;
+
+    CGEventType type = kCGEventMouseMoved;
+    wxCFRef<CGEventRef> event(
+            CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft));
+
+    if ( !event )
+        return false;
+
+    CGEventSetType(event, type);
+    CGEventPost(tap, event);
+
+    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
+    if (loop)
+        loop->SetShouldWaitForEvent(true);
+    
+    return true;
+}
+
+bool wxUIActionSimulator::MouseUp(int button)
+{
+    CGEventType type = CGEventTypeForMouseButton(button, false);
+    wxCFRef<CGEventRef> event(
+            CGEventCreateMouseEvent(NULL, type, GetMousePosition(), CGButtonForMouseButton(button)));
 
     if ( !event )
         return false;
@@ -91,14 +178,14 @@ bool wxUIActionSimulator::MouseDblClick(int button)
     CGEventType downtype = CGEventTypeForMouseButton(button, true);
     CGEventType uptype = CGEventTypeForMouseButton(button, false);
     wxCFRef<CGEventRef> event(
-                              CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), button));
+                              CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), CGButtonForMouseButton(button)));
     
     if ( !event )
         return false;
     
     CGEventSetType(event,downtype);
     CGEventPost(tap, event);
-
+    
     CGEventSetType(event, uptype);
     CGEventPost(tap, event);
     
@@ -115,38 +202,30 @@ bool wxUIActionSimulator::MouseDblClick(int button)
     return true;
 }
 
-bool wxUIActionSimulator::MouseMove(long x, long y)
+bool wxUIActionSimulator::MouseClickAndDragTo(long x, long y, int button)
 {
-    CGPoint pos;
-    pos.x = x;
-    pos.y = y;
+    CGEventType downtype = CGEventTypeForMouseButton(button, true);
+    CGEventType uptype = CGEventTypeForMouseButton(button, false);
+    CGEventType dragtype = CGEventTypeForMouseDrag(button) ;
 
-    CGEventType type = kCGEventMouseMoved;
     wxCFRef<CGEventRef> event(
-            CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft));
-
+                              CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), CGButtonForMouseButton(button)));
+    
     if ( !event )
         return false;
-
-    CGEventSetType(event, type);
+    
+    CGEventSetType(event,downtype);
     CGEventPost(tap, event);
-    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
-    if (loop)
-        loop->SetShouldWaitForEvent(true);
     
-    return true;
-}
-
-bool wxUIActionSimulator::MouseUp(int button)
-{
-    CGEventType type = CGEventTypeForMouseButton(button, false);
-    wxCFRef<CGEventRef> event(
-            CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));
-
-    if ( !event )
-        return false;
-
-    CGEventSetType(event, type);
+    CGPoint pos;
+    pos.x = x;
+    pos.y = y;
+    
+    CGEventSetType(event, dragtype);
+    CGEventSetLocation(event,pos);
+    CGEventPost(tap, event);
+    
+    CGEventSetType(event, uptype);
     CGEventPost(tap, event);
     wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
     if (loop)