]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/dnd.cpp
Include wx/bitmap.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / mac / carbon / dnd.cpp
index 808dc49fa4296211ab8c87454ad356d114687b09..456a2a90b8b995e39db111d7b457e5a1b0008ff3 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        dnd.cpp
+// Name:        src/mac/carbon/dnd.cpp
 // Purpose:     wxDropTarget, wxDropSource implementations
 // Author:      Stefan Csomor
 // Modified by:
 // Purpose:     wxDropTarget, wxDropSource implementations
 // Author:      Stefan Csomor
 // Modified by:
 #if wxUSE_DRAG_AND_DROP
 
 #include "wx/dnd.h"
 #if wxUSE_DRAG_AND_DROP
 
 #include "wx/dnd.h"
-#include "wx/window.h"
-#include "wx/toplevel.h"
-#include "wx/app.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+    #include "wx/window.h"
+    #include "wx/toplevel.h"
+#endif // WX_PRECOMP
+
 #include "wx/gdicmn.h"
 #include "wx/mac/private.h"
 
 #include "wx/gdicmn.h"
 #include "wx/mac/private.h"
 
@@ -188,7 +192,7 @@ bool wxDropTarget::GetData()
         FlavorType theType;
         FlavorFlags theFlags;
         UInt16 flavors;
         FlavorType theType;
         FlavorFlags theFlags;
         UInt16 flavors;
-        bool firstFileAdded = false;
+        wxString filenamesPassed;
 
         CountDragItems( (DragReference)m_currentDrag, &items );
         for (UInt16 index = 1; index <= items; ++index)
 
         CountDragItems( (DragReference)m_currentDrag, &items );
         for (UInt16 index = 1; index <= items; ++index)
@@ -199,22 +203,22 @@ bool wxDropTarget::GetData()
             wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
             bool hasPreferredFormat = false;
 
             wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
             bool hasPreferredFormat = false;
 
-            for ( UInt16 flavor = 1; flavor <= flavors; ++flavor )
+            for (UInt16 flavor = 1; flavor <= flavors; ++flavor)
             {
                 result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                 wxDataFormat format( theType );
             {
                 result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                 wxDataFormat format( theType );
-                if ( preferredFormat == format )
+                if (preferredFormat == format)
                 {
                     hasPreferredFormat = true;
                     break;
                 }
             }
 
                 {
                     hasPreferredFormat = true;
                     break;
                 }
             }
 
-            for ( UInt16 flavor = 1; flavor <= flavors; ++flavor )
+            for (UInt16 flavor = 1; flavor <= flavors; ++flavor)
             {
                 result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                 wxDataFormat format( theType );
             {
                 result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                 wxDataFormat format( theType );
-                if ( (hasPreferredFormat && format == preferredFormat)
+                if ((hasPreferredFormat && format == preferredFormat)
                     || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
                 {
                     result = GetFlavorFlags( (DragReference)m_currentDrag, theItem, theType, &theFlags );
                     || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
                 {
                     result = GetFlavorFlags( (DragReference)m_currentDrag, theItem, theType, &theFlags );
@@ -224,13 +228,13 @@ bool wxDropTarget::GetData()
                         Ptr theData;
 
                         GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize );
                         Ptr theData;
 
                         GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize );
-                        if ( theType == kScrapFlavorTypeText )
+                        if (theType == kScrapFlavorTypeText)
                         {
                             // this increment is only valid for allocating:
                             // on the next GetFlavorData call it is reset again to the original value
                             dataSize++;
                         }
                         {
                             // this increment is only valid for allocating:
                             // on the next GetFlavorData call it is reset again to the original value
                             dataSize++;
                         }
-                        else if ( theType == kScrapFlavorTypeUnicode )
+                        else if (theType == kScrapFlavorTypeUnicode)
                         {
                             // this increment is only valid for allocating:
                             // on the next GetFlavorData call it is reset again to the original value
                         {
                             // this increment is only valid for allocating:
                             // on the next GetFlavorData call it is reset again to the original value
@@ -243,7 +247,7 @@ bool wxDropTarget::GetData()
                         else
                             theData = NULL;
 
                         else
                             theData = NULL;
 
-                        GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L );
+                        GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*)theData, &dataSize, 0L );
                         switch (theType)
                         {
                         case kScrapFlavorTypeText:
                         switch (theType)
                         {
                         case kScrapFlavorTypeText:
@@ -260,28 +264,16 @@ bool wxDropTarget::GetData()
 #endif
 
                         case kDragFlavorTypeHFS:
 #endif
 
                         case kDragFlavorTypeHFS:
+                            if (theData != NULL)
                             {
                             {
-                                wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
-                                wxASSERT( fdo != NULL );
-
-                                if ((theData != NULL) && (fdo != NULL))
-                                {
-                                    HFSFlavor* theFile = (HFSFlavor*) theData;
-                                    wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );
-
-                                    if ( !firstFileAdded )
-                                    {
-                                        // reset file list
-                                        fdo->SetData( 0, "" );
-                                        firstFileAdded = true;
-                                    }
-
-                                    if (!name.IsEmpty())
-                                        fdo->AddFile( name );
-                                }
+                                HFSFlavor* theFile = (HFSFlavor*)theData;
+                                wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );
+
+                                if (!name.empty())
+                                    filenamesPassed += name + wxT("\n");
                             }
                             break;
                             }
                             break;
+
                         default:
                             m_dataObject->SetData( format, dataSize, theData );
                             break;
                         default:
                             m_dataObject->SetData( format, dataSize, theData );
                             break;
@@ -293,6 +285,12 @@ bool wxDropTarget::GetData()
                 }
             }
         }
                 }
             }
         }
+
+        if (filenamesPassed.length() > 0)
+        {
+            wxCharBuffer buf = filenamesPassed.fn_str();
+            m_dataObject->SetData( wxDataFormat(wxDF_FILENAME), strlen( buf ), (const char*)buf );
+        }
     }
 
     return true;
     }
 
     return true;
@@ -337,15 +335,14 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
 {
     wxASSERT_MSG( m_data, wxT("Drop source: no data") );
 
 {
     wxASSERT_MSG( m_data, wxT("Drop source: no data") );
 
-    if (!m_data)
-        return (wxDragResult) wxDragNone;
-    if (m_data->GetFormatCount() == 0)
-        return (wxDragResult) wxDragNone;
+    if ((m_data == NULL) || (m_data->GetFormatCount() == 0))
+        return (wxDragResult)wxDragNone;
 
     OSStatus result;
     DragReference theDrag;
     RgnHandle dragRegion;
 
     OSStatus result;
     DragReference theDrag;
     RgnHandle dragRegion;
-    if ((result = NewDrag(&theDrag)) != noErr)
+
+    if ((result = NewDrag( &theDrag )) != noErr)
         return wxDragNone;
 
     // add data to drag
         return wxDragNone;
 
     // add data to drag
@@ -428,11 +425,9 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
 #if !TARGET_CARBON // TODO
     ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
 #else
 #if !TARGET_CARBON // TODO
     ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
 #else
-    {
-        EventRecord rec;
-        ev = &rec;
-        wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent(), &rec );
-    }
+    EventRecord rec;
+    ev = &rec;
+    wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent(), &rec );
 #endif
 
     const short dragRegionOuterBoundary = 10;
 #endif
 
     const short dragRegionOuterBoundary = 10;
@@ -624,27 +619,20 @@ pascal OSErr wxMacWindowDragTrackingHandler(
                 {
                   if ( !trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) )
                   {
                 {
                   if ( !trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) )
                   {
-                      switch ( result )
+                      int cursorID = wxCURSOR_NONE;
+
+                      switch (result)
                       {
                           case wxDragCopy:
                       {
                           case wxDragCopy:
-                              {
-                                  wxCursor cursor(wxCURSOR_COPY_ARROW);
-                                  cursor.MacInstall();
-                              }
+                              cursorID = wxCURSOR_COPY_ARROW;
                               break;
 
                           case wxDragMove:
                               break;
 
                           case wxDragMove:
-                              {
-                                  wxCursor cursor(wxCURSOR_ARROW);
-                                  cursor.MacInstall();
-                              }
+                              cursorID = wxCURSOR_ARROW;
                               break;
 
                           case wxDragNone:
                               break;
 
                           case wxDragNone:
-                              {
-                                  wxCursor cursor(wxCURSOR_NO_ENTRY);
-                                  cursor.MacInstall();
-                              }
+                              cursorID = wxCURSOR_NO_ENTRY;
                               break;
 
                           case wxDragError:
                               break;
 
                           case wxDragError:
@@ -654,6 +642,12 @@ pascal OSErr wxMacWindowDragTrackingHandler(
                               // put these here to make gcc happy
                               ;
                       }
                               // put these here to make gcc happy
                               ;
                       }
+
+                      if (cursorID != wxCURSOR_NONE)
+                      {
+                          wxCursor cursor( cursorID );
+                          cursor.MacInstall();
+                      }
                    }
                 }
             }
                    }
                 }
             }