]> git.saurik.com Git - wxWidgets.git/commitdiff
enabling cursor events, fixes #15044
authorStefan Csomor <csomor@advancedconcepts.ch>
Sat, 2 Mar 2013 13:01:57 +0000 (13:01 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Sat, 2 Mar 2013 13:01:57 +0000 (13:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73595 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/cocoa/private.h
src/osx/cocoa/window.mm

index b759a862b3b9f3968d637b6ddf752cd661a79167..949558c335633ff6c1faa45dadbc13f34bd452fd 100644 (file)
@@ -138,6 +138,8 @@ public :
 
     virtual void        SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
     virtual void        SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
+    void                SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent);
+    virtual bool        SetupCursor(NSEvent* event);
 
 
 #if !wxOSX_USE_NATIVE_FLIPPED
index 0f8d583014313b7205cad012fb42b681baf53ef2..351bfe1f5337127156b7035c374b3b82ff1b28b0 100644 (file)
@@ -462,11 +462,8 @@ bool g_lastButtonWasFakeRight = false ;
 - (CGFloat)scrollingDeltaY;
 @end
 
-void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
+void wxWidgetCocoaImpl::SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent* nsEvent)
 {
-    int eventType = [nsEvent type];
-    UInt32 modifiers = [nsEvent modifierFlags] ;
-
     NSPoint locationInWindow = [nsEvent locationInWindow];
     
     // adjust coordinates for the window of the target view
@@ -474,20 +471,30 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve
     {
         if ( [nsEvent window] != nil )
             locationInWindow = [[nsEvent window] convertBaseToScreen:locationInWindow];
-
+        
         if ( [m_osxView window] != nil )
             locationInWindow = [[m_osxView window] convertScreenToBase:locationInWindow];
     }
-
+    
     NSPoint locationInView = [m_osxView convertPoint:locationInWindow fromView:nil];
     wxPoint locationInViewWX = wxFromNSPoint( m_osxView, locationInView );
+        
+    x = locationInViewWX.x;
+    y = locationInViewWX.y;
+
+}
+
+void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
+{
+    int eventType = [nsEvent type];
+    UInt32 modifiers = [nsEvent modifierFlags] ;
+    
+    SetupCoordinates(wxevent.m_x, wxevent.m_y, nsEvent);
 
     // these parameters are not given for all events
     UInt32 button = [nsEvent buttonNumber];
     UInt32 clickCount = 0;
 
-    wxevent.m_x = locationInViewWX.x;
-    wxevent.m_y = locationInViewWX.y;
     wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
     wxevent.m_rawControlDown = modifiers & NSControlKeyMask;
     wxevent.m_altDown = modifiers & NSAlternateKeyMask;
@@ -1176,20 +1183,40 @@ void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 
 void wxWidgetCocoaImpl::cursorUpdate(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
-    NSCursor *cursor = (NSCursor*)GetWXPeer()->GetCursor().GetHCURSOR();
-    if (cursor == NULL)
+    if ( !SetupCursor(event) )
     {
         wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
-        superimpl(slf, (SEL)_cmd, event);
+            superimpl(slf, (SEL)_cmd, event);
     }
-    else 
+ }
+
+bool wxWidgetCocoaImpl::SetupCursor(WX_NSEvent event)
+{
+    extern wxCursor gGlobalCursor;
+    
+    if ( gGlobalCursor.IsOk() )
     {
-        [cursor set];
+        gGlobalCursor.MacInstall();
+        return true;
+    }
+    else
+    {
+        wxWindow* cursorTarget = GetWXPeer();
+        wxCoord x,y;
+        SetupCoordinates(x, y, event);
+        wxPoint cursorPoint( x , y ) ;
+        
+        while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
+        {
+            cursorTarget = cursorTarget->GetParent() ;
+            if ( cursorTarget )
+                cursorPoint += cursorTarget->GetPosition();
+        }
+        
+        return cursorTarget != NULL;
     }
 }
 
-
-
 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
     if ( [event type] == NSKeyDown )
@@ -2539,7 +2566,11 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
 {
     wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
     SetupMouseEvent(wxevent , event) ;
-    return GetWXPeer()->HandleWindowEvent(wxevent);
+    bool result = GetWXPeer()->HandleWindowEvent(wxevent);
+    
+    (void)SetupCursor(event);
+
+    return result;
 }
 
 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
@@ -2656,11 +2687,13 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
     {
         NSView* cv = [tlw contentView];
         c = new wxWidgetCocoaImpl( now, cv, true );
-        // increase ref count, because the impl destructor will decrement it again
-        CFRetain(cv);
-        if ( !now->IsShown() )
-            [cv setHidden:NO];
-        
+        if ( cv != nil )
+        {
+            // increase ref count, because the impl destructor will decrement it again
+            CFRetain(cv);
+            if ( !now->IsShown() )
+                [cv setHidden:NO];
+        }
     }
     else
     {