]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/dnd.mm
Spell contributor name correctly.
[wxWidgets.git] / src / osx / cocoa / dnd.mm
index 4429d80708eb1ec62c52e465b31c2c4770a1e28c..6c9e4e418d6e16d9b38b854c17514c2b7f5b7481 100644 (file)
 
 #ifndef WX_PRECOMP
     #include "wx/app.h"
-    #include "wx/evtloop.h"
     #include "wx/toplevel.h"
     #include "wx/gdicmn.h"
     #include "wx/wx.h"
 #endif // WX_PRECOMP
 
-#include <AppKit/AppKit.h>
+#include "wx/evtloop.h"
+
 #include "wx/osx/private.h"
 
+wxDropSource* gCurrentSource = NULL;
+
 wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
 {
     switch (code)
@@ -53,6 +55,7 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
 - (void)setImplementation: (wxDropSource *)dropSource;
 - (BOOL)finished;
 - (NSDragOperation)code;
+- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint;
 - (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
 @end
 
@@ -82,6 +85,48 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
     return resultCode;
 }
 
+- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint
+{
+    bool optionDown = GetCurrentKeyModifiers() & optionKey;
+    wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
+    
+    if (wxDropSource* source = impl)
+    {
+        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();
+            }
+        }
+    }
+}
+
 - (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
 {
     resultCode = operation;
@@ -96,25 +141,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
 //-------------------------------------------------------------------------
@@ -139,6 +165,11 @@ wxDropSource::wxDropSource(wxDataObject& data,
     m_window = win;
 }
 
+wxDropSource* wxDropSource::GetCurrentDropSource()
+{
+    return gCurrentSource;
+}
+
 wxDragResult wxDropSource::DoDragDrop(int flags)
 {
     wxASSERT_MSG( m_data, wxT("Drop source: no data") );
@@ -171,6 +202,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.");
         
+        gCurrentSource = this;
         NSImage* image = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
         DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
         [delegate setImplementation: this];
@@ -184,6 +216,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
         result = NSDragOperationToWxDragResult([delegate code]);
         [delegate release];
         [image release];
+        gCurrentSource = NULL;
     }