12#include <wx/dataobj.h>
22#if wxUSE_DRAG_AND_DROP
23class FileObject final :
public wxFileDataObject
30 bool IsSupportedFormat(
const wxDataFormat &
format, Direction WXUNUSED(dir =
Get))
const
33 if (
format.GetType() == wxDF_FILENAME) {
38#if !wxCHECK_VERSION(3, 0, 0)
39 if (
format.GetFormatId() == kDragPromisedFlavorFindFile) {
49class DropTarget final :
public wxFileDropTarget
57 SetDataObject(
safenew FileObject());
65#if !wxCHECK_VERSION(3, 0, 0)
66 bool GetData()
override
68 bool foundSupported =
false;
69 bool firstFileAdded =
false;
73 CountDragItems((DragReference)m_currentDrag, &items);
75 for (UInt16 index = 1; index <= items; index++) {
77 DragItemRef theItem = 0;
78 GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
81 CountDragItemFlavors((DragReference)m_currentDrag, theItem , &flavors ) ;
83 for (UInt16 flavor = 1 ;flavor <= flavors; flavor++) {
85 FlavorType theType = 0;
86 result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor, &theType);
87 if (theType != kDragPromisedFlavorFindFile && theType != kDragFlavorTypeHFS) {
90 foundSupported =
true;
93 GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
96 GetFlavorData((DragReference)m_currentDrag, theItem, theType, (
void*) theData.get(), &dataSize, 0L);
99 if (theType == kDragPromisedFlavorFindFile) {
100 name = wxMacFSSpec2MacFilename((FSSpec *)theData.get());
102 else if (theType == kDragFlavorTypeHFS) {
103 name = wxMacFSSpec2MacFilename(&((HFSFlavor *)theData.get())->fileSpec);
106 if (!firstFileAdded) {
108 ((wxFileDataObject*)GetDataObject())->SetData(0,
"");
109 firstFileAdded =
true;
112 ((wxFileDataObject*)GetDataObject())->AddFile(
name);
118 return foundSupported;
122 bool OnDrop(wxCoord x, wxCoord y)
override
125#if !wxCHECK_VERSION(3, 0, 0)
126 bool firstFileAdded =
false;
130 CountDragItems((DragReference)m_currentDrag, &items);
132 for (UInt16 index = 1; index <= items; index++) {
134 DragItemRef theItem = 0;
135 GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
138 CountDragItemFlavors((DragReference)m_currentDrag, theItem , &flavors ) ;
140 for (UInt16 flavor = 1 ;flavor <= flavors; flavor++) {
142 FlavorType theType = 0;
143 result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor, &theType);
144 if (theType != kDragPromisedFlavorFindFile && theType != kDragFlavorTypeHFS) {
151 return CurrentDragHasSupportedFormat();
156 bool OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
const wxArrayString& filenames)
override
160 return GuardedCall< bool > ( [&] {
161 wxArrayString sortednames(filenames);
164 auto cleanup =
finally( [&] {
168 for (
const auto &
name : sortednames)
172 viewport.ZoomFitHorizontallyAndShowTrack(
nullptr);
Declare abstract class AudacityException, some often-used subclasses, and GuardedCall.
const TranslatableString name
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
bool Import(const FilePath &fileName, bool addToHistory=true)
static ProjectFileManager & Get(AudacityProject &project)
static TrackPanel & Get(AudacityProject &project)
static Viewport & Get(AudacityProject &project)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
FILES_API int CompareNoCase(const wxString &first, const wxString &second)