Update of /cvsroot/audacity/audacity-src/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv14832

Modified Files:
        Project.cpp Project.h 
Log Message:
Add support for dragging files from iTunes (and possibly others) under OSX.

Index: Project.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.h,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- Project.h   11 Apr 2007 06:07:18 -0000      1.115
+++ Project.h   28 Apr 2007 07:37:33 -0000      1.116
@@ -31,7 +31,6 @@
 #include "toolbars/SelectionBar.h"
 
 #include <wx/defs.h>
-#include <wx/dnd.h>
 #include <wx/event.h>
 #include <wx/log.h>
 #include <wx/dragimag.h>
@@ -93,18 +92,6 @@
    loopedPlay
 };
 
-#if wxUSE_DRAG_AND_DROP
-class AudacityDropTarget : public wxFileDropTarget
-{
- public:
-   AudacityDropTarget(AudacityProject *proj);
-   virtual ~AudacityDropTarget();
-   virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& 
filenames);
- private:
-   AudacityProject *mProject;
-};
-#endif
-
 class AudacityProject:public wxFrame,
                       public TrackPanelListener,
                       public SelectionBarListener,

Index: Project.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.cpp,v
retrieving revision 1.304
retrieving revision 1.305
diff -u -d -r1.304 -r1.305
--- Project.cpp 20 Apr 2007 05:40:53 -0000      1.304
+++ Project.cpp 28 Apr 2007 07:37:32 -0000      1.305
@@ -9,7 +9,7 @@
 *******************************************************************//**
 
 \file Project.cpp
-\brief Implements AudacityProject and AudcityDropTarget.  
+\brief Implements AudacityProject, DropTarget, and FileObject.
 Includes Menus.cpp.
 
 *//****************************************************************//**
@@ -30,9 +30,15 @@
 
 *//****************************************************************//**
 
-\class AudacityDropTarget
-\brief AudacityDropTarget, derived from wxFileDropTarget gives 
-drag and drop functionality for audio files.
+\class DropTarget
+\brief DropTarget, derived from wxFileDropTarget gives drag and drop
+functionality for audio files.
+
+*//****************************************************************//**
+
+\class FileObject
+\brief FileObject, derived from wxFileDataObject gives extended drag
+and drop functionality for audio files.
 
 *//****************************************************************//**
 
@@ -52,42 +58,32 @@
 #include <wx/app.h>
 #include <wx/dc.h>
 #include <wx/dcmemory.h>
+#include <wx/dnd.h>
 #include <wx/docview.h>
-#include <wx/intl.h>
-#include <wx/string.h>
-#include <wx/filefn.h>
+#include <wx/event.h>
 #include <wx/ffile.h>
+#include <wx/filedlg.h>
+#include <wx/filefn.h>
+#include <wx/intl.h>
 #include <wx/log.h>
-#include <wx/timer.h>
+#include <wx/menu.h>
+#include <wx/msgdlg.h>
+#include <wx/notebook.h>
+#include <wx/progdlg.h>
+#include <wx/scrolbar.h>
 #include <wx/sizer.h>
 #include <wx/statusbr.h>
-#include <wx/notebook.h>
-
-#ifdef __MACOSX__
-#include <CoreServices/CoreServices.h>
-#endif
+#include <wx/string.h>
+#include <wx/textfile.h>
+#include <wx/timer.h>
 
-#ifdef __MACOS9__
-#include <Files.h>
-#endif
+#include <wx/arrimpl.cpp>       // this allows for creation of wxObjArray
 
-#ifdef __WXMAC__
-#define __MOVIES__  /* Apple's Movies.h not compatible with Audacity */
+#if defined(__WXMAC__)
+#include <CoreServices/CoreServices.h>
 #include <wx/mac/private.h>
 #endif
 
-#include <wx/dragimag.h>
-#include <wx/generic/dragimgg.h>
-
-#include <wx/event.h>
-#include <wx/filedlg.h>
-#include <wx/msgdlg.h>
-#include <wx/scrolbar.h>
-#include <wx/textfile.h>
-#include <wx/menu.h>
-#include <wx/progdlg.h>
-#include <wx/arrimpl.cpp>       // this allows for creation of wxObjArray
-
 #include "Project.h"
 
 #include "AutoRecovery.h"
@@ -141,11 +137,7 @@
 double AudacityProject::msClipLen = 0.0;
 AudacityProject *AudacityProject::msClipProject = NULL;
 
-#ifdef __WXMAC__
-# ifndef __UNIX__
-#  include <Files.h>
-# endif
-
+#if defined(__WXMAC__)
 const int sbarSpaceWidth = 15;
 const int sbarControlWidth = 16;
 const int sbarExtraLen = 1;
@@ -160,10 +152,8 @@
 const int sbarControlWidth = 15;
 const int sbarExtraLen = 0;
 const int sbarHjump = 30;       //STM: This is how far the thumb jumps when 
the l/r buttons are pressed, or auto-scrolling occurs
-//#include "../images/AudacityLogo48x48.xpm"
 #include "Theme.h"
 #include "AllThemeResources.h"
-
 #endif
 
 //
@@ -219,22 +209,115 @@
 }
 
 #if wxUSE_DRAG_AND_DROP
-AudacityDropTarget::AudacityDropTarget(AudacityProject *proj)
-   : mProject(proj)
+class FileObject: public wxFileDataObject
 {
-}
+public:
+   FileObject::FileObject()
+   {
+   }
 
-AudacityDropTarget::~AudacityDropTarget()
-{
-}
+   bool IsSupportedFormat(const wxDataFormat & format, Direction dir = Get) 
const
+   {
+      if (format.GetType() == wxDF_FILENAME) {
+         return true;
+      }
 
-bool AudacityDropTarget::OnDropFiles(wxCoord x, wxCoord y, const 
wxArrayString& filenames)
+#if defined(__WXMAC__)
+      if (format.GetFormatId() == kDragPromisedFlavorFindFile) {
+         return true;
+      }
+#endif
+
+      return false;
+   }
+};
+
+class DropTarget: public wxFileDropTarget
 {
-   for (unsigned int i = 0; i < filenames.GetCount(); i++)
-      mProject->Import(filenames[i]);
-   mProject->HandleResize(); // Adjust scrollers for new track sizes.
-   return true;
-}
+public:
+   DropTarget(AudacityProject *proj)
+   {
+      mProject = proj;
+
+      SetDataObject(new FileObject());
+   }
+
+   ~DropTarget()
+   {
+   }
+
+#if defined(__WXMAC__)
+   bool GetData()
+   {
+      bool foundSupported = false;
+      bool firstFileAdded = false;
+      OSErr result;
+
+      UInt16 items = 0;
+      CountDragItems((DragReference)m_currentDrag, &items);
+
+      for (UInt16 index = 1; index <= items; index++) {
+
+         DragItemRef theItem = 0;
+         GetDragItemReferenceNumber((DragReference)m_currentDrag, index, 
&theItem);
+
+         UInt16 flavors = 0;
+         CountDragItemFlavors((DragReference)m_currentDrag, theItem , &flavors 
) ;
+
+         for (UInt16 flavor = 1 ;flavor <= flavors; flavor++) {
+
+            FlavorType theType = 0;
+            result = GetFlavorType((DragReference)m_currentDrag, theItem, 
flavor, &theType);
+            if (theType != kDragPromisedFlavorFindFile && theType != 
kDragFlavorTypeHFS) {
+               continue;
+            }
+            foundSupported = true;
+
+            Size dataSize = 0;
+            GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, 
&dataSize);
+
+            Ptr theData = new char[dataSize];
+            GetFlavorData((DragReference)m_currentDrag, theItem, theType, 
(void*) theData, &dataSize, 0L); 
+
+            wxString name;
+            if (theType == kDragPromisedFlavorFindFile) {
+               name = wxMacFSSpec2MacFilename((FSSpec *)theData);
+            }
+            else if (theType == kDragFlavorTypeHFS) {
+               name = wxMacFSSpec2MacFilename(&((HFSFlavor 
*)theData)->fileSpec);
+            }
+
+            delete[] theData;
+
+            if (!firstFileAdded) {
+               // reset file list
+               ((wxFileDataObject*)GetDataObject())->SetData(0, "");
+               firstFileAdded = true;
+            }
+            ((wxFileDataObject*)GetDataObject())->AddFile(name);
+
+            // We only want to process one flavor
+            break;
+         }
+      }
+
+      return foundSupported;
+   }
+#endif
+
+   bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
+   {
+      for (unsigned int i = 0; i < filenames.GetCount(); i++) {
+         mProject->Import(filenames[i]);
+      }
+      mProject->HandleResize(); // Adjust scrollers for new track sizes.
+      return true;
+   }
+
+private:
+   AudacityProject *mProject;
+};
+
 #endif
 
 AudacityProject *CreateNewAudacityProject(wxWindow * parentWindow)
@@ -479,10 +562,6 @@
    mStatusBar = CreateStatusBar(2);
    mStatusBar->SetStatusWidths(2, widths);
 
-#if wxUSE_DRAG_AND_DROP
-   SetDropTarget(new AudacityDropTarget(this));
-#endif
-
    // MM: DirManager is created dynamically, freed on demand via ref-counting
    // MM: We don't need to Ref() here because it start with refcount=1
    mDirManager = new DirManager();
@@ -701,6 +780,13 @@
 
    mTimer = new wxTimer(this, AudacityProjectTimerID);
    mTimer->Start(200);
+
+#if wxUSE_DRAG_AND_DROP
+   // We can import now, so become a drag target
+//   SetDropTarget(new AudacityDropTarget(this));
+//   mTrackPanel->SetDropTarget(new AudacityDropTarget(this));
+   mTrackPanel->SetDropTarget(new DropTarget(this));
+#endif
 }
 
 AudacityProject::~AudacityProject()


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to