]> git.saurik.com Git - wxWidgets.git/commitdiff
Add an accessor to get the current drop source from window.mm so that we can implemen...
authorKevin Ollivier <kevino@theolliviers.com>
Sat, 6 Feb 2010 01:45:58 +0000 (01:45 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Sat, 6 Feb 2010 01:45:58 +0000 (01:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63412 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/dnd.h
src/osx/carbon/dnd.cpp
src/osx/cocoa/dnd.mm
src/osx/cocoa/window.mm
src/osx/dnd_osx.cpp

index f4762f2b03591c5f11a1e7bf991fa63af70e5676..0bb4e9daf96500d802f84ef723b335ae2a2ab740 100644 (file)
@@ -96,6 +96,7 @@ public:
     wxWindow*     GetWindow() { return m_window ; }
     void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
     bool MacInstallDefaultCursor(wxDragResult effect) ;
     wxWindow*     GetWindow() { return m_window ; }
     void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
     bool MacInstallDefaultCursor(wxDragResult effect) ;
+    static wxDropSource* GetCurrentDropSource();
   protected :
 
     wxWindow        *m_window;
   protected :
 
     wxWindow        *m_window;
index b46737b0aa9168b53d8f359c65128f01b6024a2e..0ad4565b4a289a6d2b1c8e54b65154fc4f0aa32f 100644 (file)
@@ -162,6 +162,11 @@ wxDropSource::wxDropSource(wxWindow *win,
     m_window = win;
 }
 
     m_window = win;
 }
 
+wxDropSource* wxDropSource::GetCurrentDropSource()
+{
+    return gTrackingGlobals.m_currentSource;
+}
+
 wxDropSource::wxDropSource(wxDataObject& data,
                            wxWindow *win,
                            const wxCursor &cursorCopy,
 wxDropSource::wxDropSource(wxDataObject& data,
                            wxWindow *win,
                            const wxCursor &cursorCopy,
index 4429d80708eb1ec62c52e465b31c2c4770a1e28c..1345e62b0f013f815f9df88f5ec3c42012489450 100644 (file)
@@ -26,6 +26,8 @@
 #include <AppKit/AppKit.h>
 #include "wx/osx/private.h"
 
 #include <AppKit/AppKit.h>
 #include "wx/osx/private.h"
 
+wxDropSource* gCurrentSource = NULL;
+
 wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
 {
     switch (code)
 wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
 {
     switch (code)
@@ -96,25 +98,6 @@ wxDropTarget::wxDropTarget( wxDataObject *data )
 
 }
 
 
 }
 
-bool wxDropTarget::CurrentDragHasSupportedFormat()
-{
-    if (m_dataObject == NULL)
-        return false;
-
-    return m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
-}
-
-bool wxDropTarget::GetData()
-{
-    if (m_dataObject == NULL)
-        return false;
-
-    if ( !CurrentDragHasSupportedFormat() )
-        return false;
-
-    return m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
-}
-
 //-------------------------------------------------------------------------
 // wxDropSource
 //-------------------------------------------------------------------------
 //-------------------------------------------------------------------------
 // wxDropSource
 //-------------------------------------------------------------------------
@@ -139,6 +122,11 @@ wxDropSource::wxDropSource(wxDataObject& data,
     m_window = win;
 }
 
     m_window = win;
 }
 
+wxDropSource* wxDropSource::GetCurrentDropSource()
+{
+    return gCurrentSource;
+}
+
 wxDragResult wxDropSource::DoDragDrop(int flags)
 {
     wxASSERT_MSG( m_data, wxT("Drop source: no data") );
 wxDragResult wxDropSource::DoDragDrop(int flags)
 {
     wxASSERT_MSG( m_data, wxT("Drop source: no data") );
@@ -171,6 +159,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
         NSEvent* theEvent = (NSEvent*)wxTheApp->MacGetCurrentEvent();
         wxASSERT_MSG(theEvent, "DoDragDrop must be called in response to a mouse down or drag event.");
         
         NSEvent* theEvent = (NSEvent*)wxTheApp->MacGetCurrentEvent();
         wxASSERT_MSG(theEvent, "DoDragDrop must be called in response to a mouse down or drag event.");
         
+        gCurrentSource = this;
         NSImage* image = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
         DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
         [delegate setImplementation: this];
         NSImage* image = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
         DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
         [delegate setImplementation: this];
@@ -184,6 +173,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
         result = NSDragOperationToWxDragResult([delegate code]);
         [delegate release];
         [image release];
         result = NSDragOperationToWxDragResult([delegate code]);
         [delegate release];
         [image release];
+        gCurrentSource = NULL;
     }
 
 
     }
 
 
index 83a5e7f79aae55eb30428c81d180dc4b5b8983df..6d14e6b4591634d6823fd873a15ea17836cd7cd2 100644 (file)
@@ -880,6 +880,45 @@ unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf),
     else if ( sourceDragMask & NSDragOperationMove )
         result = wxDragMove;
 
     else if ( sourceDragMask & NSDragOperationMove )
         result = wxDragMove;
 
+    // FIXME: This doesn't seem the right place for the code, as GiveFeedback
+    // will only get called when the drop target is inside the app itself
+    // but at least some cases will work now.
+    if (wxDropSource* source = wxDropSource::GetCurrentDropSource())
+    {
+        if (!source->GiveFeedback(result))
+        {
+            wxStockCursor cursorID = wxCURSOR_NONE;
+
+            switch (result)
+            {
+                case wxDragCopy:
+                    cursorID = wxCURSOR_COPY_ARROW;
+                    break;
+
+                case wxDragMove:
+                    cursorID = wxCURSOR_ARROW;
+                    break;
+
+                case wxDragNone:
+                    cursorID = wxCURSOR_NO_ENTRY;
+                    break;
+
+                case wxDragError:
+                case wxDragLink:
+                case wxDragCancel:
+                default:
+                    // put these here to make gcc happy
+                    ;
+            }
+
+            if (cursorID != wxCURSOR_NONE)
+            {
+                wxCursor cursor( cursorID );
+                cursor.MacInstall();
+            }
+        }
+    }
+    
     PasteboardRef pboardRef;
     PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
     target->SetCurrentDragPasteboard(pboardRef);
     PasteboardRef pboardRef;
     PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
     target->SetCurrentDragPasteboard(pboardRef);
index c19bf6eb8f0aae1c9bb1df1f083e937fc1bd78e7..b64858930ae504373e76d4c1725f22bf9c2ecb6f 100644 (file)
@@ -61,6 +61,95 @@ wxDragResult wxDropTarget::OnData(
     return GetData() ? def : wxDragNone;
 }
 
     return GetData() ? def : wxDragNone;
 }
 
+bool wxDropTarget::CurrentDragHasSupportedFormat()
+{
+    bool supported = false;
+    if (m_dataObject == NULL)
+        return false;
+
+    if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
+    {
+        wxDataObject* data = currentSource->GetDataObject();
+
+        if ( data )
+        {
+            size_t formatcount = data->GetFormatCount();
+            wxDataFormat *array = new wxDataFormat[formatcount];
+            data->GetAllFormats( array );
+            for (size_t i = 0; !supported && i < formatcount; i++)
+            {
+                wxDataFormat format = array[i];
+                if ( m_dataObject->IsSupported( format ) )
+                {
+                    supported = true;
+                    break;
+                }
+            }
+
+            delete [] array;
+        }
+    }
+
+    if ( !supported )
+    {
+        supported = m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
+    }
+
+    return supported;
+}
+
+bool wxDropTarget::GetData()
+{
+    if (m_dataObject == NULL)
+        return false;
+
+    if ( !CurrentDragHasSupportedFormat() )
+        return false;
+
+    bool transferred = false;
+    if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
+    {
+        wxDataObject* data = currentSource->GetDataObject();
+
+        if (data != NULL)
+        {
+            size_t formatcount = data->GetFormatCount();
+            wxDataFormat *array = new wxDataFormat[formatcount];
+            data->GetAllFormats( array );
+            for (size_t i = 0; !transferred && i < formatcount; i++)
+            {
+                wxDataFormat format = array[i];
+                if ( m_dataObject->IsSupported( format ) )
+                {
+                    int size = data->GetDataSize( format );
+                    transferred = true;
+
+                    if (size == 0)
+                    {
+                        m_dataObject->SetData( format, 0, 0 );
+                    }
+                    else
+                    {
+                        char *d = new char[size];
+                        data->GetDataHere( format, (void*)d );
+                        m_dataObject->SetData( format, size, d );
+                        delete [] d;
+                    }
+                }
+            }
+
+            delete [] array;
+        }
+    }
+
+    if ( !transferred )
+    {
+        transferred = m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
+    }
+
+    return transferred;
+}
+
 //-------------------------------------------------------------------------
 // wxDropSource
 //-------------------------------------------------------------------------
 //-------------------------------------------------------------------------
 // wxDropSource
 //-------------------------------------------------------------------------