]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/dnd.cpp
Added extra width for controls to avoid edge being clipped
[wxWidgets.git] / src / mac / carbon / dnd.cpp
index 0a42702a8fcca677274f8296b00d2be47e9c3d64..6f5a325730d958ad9d86d8e4b46e8fbfeac7f4ac 100644 (file)
@@ -37,6 +37,8 @@ typedef struct
     wxWindow *m_currentTargetWindow;
     wxDropTarget *m_currentTarget;
     wxDropSource *m_currentSource;
     wxWindow *m_currentTargetWindow;
     wxDropTarget *m_currentTarget;
     wxDropSource *m_currentSource;
+    wxDragResult m_result;
+    int m_flags;
 } MacTrackingGlobals;
 
 MacTrackingGlobals gTrackingGlobals;
 } MacTrackingGlobals;
 
 MacTrackingGlobals gTrackingGlobals;
@@ -264,10 +266,12 @@ bool wxDropTarget::GetData()
                             if (theData != NULL)
                             {
                                 HFSFlavor* theFile = (HFSFlavor*)theData;
                             if (theData != NULL)
                             {
                                 HFSFlavor* theFile = (HFSFlavor*)theData;
+#ifndef __LP64__
                                 wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );
 
                                 if (!name.empty())
                                     filenamesPassed += name + wxT("\n");
                                 wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );
 
                                 if (!name.empty())
                                     filenamesPassed += name + wxT("\n");
+#endif
                             }
                             break;
 
                             }
                             break;
 
@@ -345,7 +349,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
     size_t formatCount = m_data->GetFormatCount();
     wxDataFormat *formats = new wxDataFormat[formatCount];
     m_data->GetAllFormats( formats );
     size_t formatCount = m_data->GetFormatCount();
     wxDataFormat *formats = new wxDataFormat[formatCount];
     m_data->GetAllFormats( formats );
-    ItemReference theItem = 1;
+    ItemReference theItem = (ItemReference) 1;
 
     for ( size_t i = 0; i < formatCount; ++i )
     {
 
     for ( size_t i = 0; i < formatCount; ++i )
     {
@@ -371,6 +375,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
         {
             HFSFlavor  theFlavor;
             OSErr err = noErr;
         {
             HFSFlavor  theFlavor;
             OSErr err = noErr;
+#ifndef __LP64__
             CInfoPBRec cat;
 
             wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec );
             CInfoPBRec cat;
 
             wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec );
@@ -381,8 +386,10 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
             cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
             cat.hFileInfo.ioFDirIndex = 0;
             err = PBGetCatInfoSync( &cat );
             cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
             cat.hFileInfo.ioFDirIndex = 0;
             err = PBGetCatInfoSync( &cat );
-            if (err == noErr)
+#endif
+          if (err == noErr)
             {
             {
+#ifndef __LP64__
                 theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
                 if (theFlavor.fileSpec.parID == fsRtParID)
                 {
                 theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
                 if (theFlavor.fileSpec.parID == fsRtParID)
                 {
@@ -399,7 +406,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
                     theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
                     theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
                 }
                     theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
                     theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
                 }
-
+#endif
                 AddDragItemFlavor( theDrag, theItem, type, &theFlavor, sizeof(theFlavor), 0 );
             }
         }
                 AddDragItemFlavor( theDrag, theItem, type, &theFlavor, sizeof(theFlavor), 0 );
             }
         }
@@ -450,18 +457,15 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
     // only when drag was successfully completed
 
     gTrackingGlobals.m_currentSource = this;
     // only when drag was successfully completed
 
     gTrackingGlobals.m_currentSource = this;
+    gTrackingGlobals.m_result = wxDragNone;
+    gTrackingGlobals.m_flags = flags;
+
     TrackDrag( theDrag, ev, dragRegion );
     DisposeRgn( dragRegion );
     DisposeDrag( theDrag );
     gTrackingGlobals.m_currentSource = NULL;
 
     TrackDrag( theDrag, ev, dragRegion );
     DisposeRgn( dragRegion );
     DisposeDrag( theDrag );
     gTrackingGlobals.m_currentSource = NULL;
 
-    bool optionDown = GetCurrentKeyModifiers() & optionKey;
-    wxDragResult dndresult = wxDragCopy;
-    if ( flags != wxDrag_CopyOnly )
-        // on mac the option key is always the indication for copy
-        dndresult = optionDown ? wxDragCopy : wxDragMove;
-
-    return dndresult;
+    return gTrackingGlobals.m_result;
 }
 
 bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
 }
 
 bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
@@ -541,7 +545,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
 
             GetDragMouse( theDrag, &mouse, 0L );
             localMouse = mouse;
 
             GetDragMouse( theDrag, &mouse, 0L );
             localMouse = mouse;
-            GlobalToLocal( &localMouse );
+            wxMacGlobalToLocal( theWindow, &localMouse );
 
             {
                 wxWindow *win = NULL;
 
             {
                 wxWindow *win = NULL;
@@ -566,7 +570,9 @@ pascal OSErr wxMacWindowDragTrackingHandler(
                         // this window is left
                         if ( trackingGlobals->m_currentTarget )
                         {
                         // this window is left
                         if ( trackingGlobals->m_currentTarget )
                         {
+#ifndef __LP64__
                             HideDragHilite( theDrag );
                             HideDragHilite( theDrag );
+#endif
                             trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                             trackingGlobals->m_currentTarget->OnLeave();
                             trackingGlobals->m_currentTarget = NULL;
                             trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                             trackingGlobals->m_currentTarget->OnLeave();
                             trackingGlobals->m_currentTarget = NULL;
@@ -595,7 +601,9 @@ pascal OSErr wxMacWindowDragTrackingHandler(
                                 RgnHandle hiliteRgn = NewRgn();
                                 Rect r = { y, x, y + win->GetSize().y, x + win->GetSize().x };
                                 RectRgn( hiliteRgn, &r );
                                 RgnHandle hiliteRgn = NewRgn();
                                 Rect r = { y, x, y + win->GetSize().y, x + win->GetSize().x };
                                 RectRgn( hiliteRgn, &r );
+#ifndef __LP64__
                                 ShowDragHilite( theDrag, hiliteRgn, true );
                                 ShowDragHilite( theDrag, hiliteRgn, true );
+#endif
                                 DisposeRgn( hiliteRgn );
                             }
                         }
                                 DisposeRgn( hiliteRgn );
                             }
                         }
@@ -657,7 +665,9 @@ pascal OSErr wxMacWindowDragTrackingHandler(
             {
                 trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                 trackingGlobals->m_currentTarget->OnLeave();
             {
                 trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                 trackingGlobals->m_currentTarget->OnLeave();
+#ifndef __LP64__
                 HideDragHilite( theDrag );
                 HideDragHilite( theDrag );
+#endif
                 trackingGlobals->m_currentTarget = NULL;
             }
             trackingGlobals->m_currentTargetWindow = NULL;
                 trackingGlobals->m_currentTarget = NULL;
             }
             trackingGlobals->m_currentTargetWindow = NULL;
@@ -684,7 +694,7 @@ pascal OSErr wxMacWindowDragReceiveHandler(
         trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
         GetDragMouse( theDrag, &mouse, 0L );
         localMouse = mouse;
         trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
         GetDragMouse( theDrag, &mouse, 0L );
         localMouse = mouse;
-        GlobalToLocal( &localMouse );
+        wxMacGlobalToLocal( theWindow, &localMouse );
         localx = localMouse.h;
         localy = localMouse.v;
 
         localx = localMouse.h;
         localy = localMouse.v;
 
@@ -693,13 +703,20 @@ pascal OSErr wxMacWindowDragReceiveHandler(
             trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx, &localy );
         if ( trackingGlobals->m_currentTarget->OnDrop( localx, localy ) )
         {
             trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx, &localy );
         if ( trackingGlobals->m_currentTarget->OnDrop( localx, localy ) )
         {
-            bool optionDown = GetCurrentKeyModifiers() & optionKey;
-            wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
-            trackingGlobals->m_currentTarget->OnData( localx, localy, result );
+            // the option key indicates copy in Mac UI, if it's not pressed do
+            // move by default if it's allowed at all
+            wxDragResult
+                result = !(trackingGlobals->m_flags & wxDrag_AllowMove) ||
+                            (GetCurrentKeyModifiers() & optionKey)
+                            ? wxDragCopy
+                            : wxDragMove;
+            trackingGlobals->m_result =
+                trackingGlobals->m_currentTarget->OnData( localx, localy, result );
         }
     }
 
     return noErr;
 }
 
         }
     }
 
     return noErr;
 }
 
-#endif
+#endif // wxUSE_DRAG_AND_DROP
+