diff --git a/include/wx/osx/dataobj.h b/include/wx/osx/dataobj.h index 82f6913ed1..fa3af42980 100644 --- a/include/wx/osx/dataobj.h +++ b/include/wx/osx/dataobj.h @@ -24,7 +24,12 @@ public: void WriteToSink(wxOSXDataSink *sink) const; bool ReadFromSource(wxOSXDataSource *source); + bool ReadFromSource(wxDataObject *source); bool CanReadFromSource(wxOSXDataSource *source) const; + bool CanReadFromSource(wxDataObject *source) const; + + wxDataFormat GetSupportedFormatInSource(wxOSXDataSource *source) const; + wxDataFormat GetSupportedFormatInSource(wxDataObject *source) const; #if wxOSX_USE_COCOA // adds all the native formats (in descending order of preference) this data object supports diff --git a/src/osx/carbon/dataobj.cpp b/src/osx/carbon/dataobj.cpp index 2dbf820461..fd4ab29b7f 100644 --- a/src/osx/carbon/dataobj.cpp +++ b/src/osx/carbon/dataobj.cpp @@ -329,6 +329,36 @@ void wxDataObject::WriteToSink(wxOSXDataSink * datatransfer) const } } +bool wxDataObject::ReadFromSource(wxDataObject * source) +{ + bool transferred = false; + + size_t formatcount = source->GetFormatCount(); + wxScopedArray array(formatcount); + source->GetAllFormats( array.get() ); + for (size_t i = 0; !transferred && i < formatcount; i++) + { + wxDataFormat format = array[i]; + if ( IsSupported( format, wxDataObject::Set ) ) + { + int size = source->GetDataSize( format ); + transferred = true; + + if (size == 0) + { + SetData( format, 0, 0 ); + } + else + { + wxCharBuffer d(size); + source->GetDataHere( format, d.data() ); + SetData( format, size, d.data() ); + } + } + } + return transferred; +} + bool wxDataObject::ReadFromSource(wxOSXDataSource * source) { bool transferred = false; @@ -439,30 +469,58 @@ bool wxDataObject::ReadFromSource(wxOSXDataSource * source) return transferred; } -bool wxDataObject::CanReadFromSource( wxOSXDataSource * source ) const +wxDataFormat wxDataObject::GetSupportedFormatInSource(wxDataObject *source) const { - bool hasData = false; + wxDataFormat format; + size_t formatcount = source->GetFormatCount(); + wxScopedArray array(formatcount); + + source->GetAllFormats( array.get() ); + for (size_t i = 0; i < formatcount; i++) + { + wxDataFormat testFormat = array[i]; + if ( IsSupported( testFormat, wxDataObject::Set ) ) + { + format = testFormat; + break; + } + } + return format; +} + +wxDataFormat wxDataObject::GetSupportedFormatInSource(wxOSXDataSource *source) const +{ + wxDataFormat format; + size_t formatcount = GetFormatCount(wxDataObject::Set); wxScopedArray array(formatcount); GetAllFormats(array.get(), wxDataObject::Set); - wxString filenamesPassed; - - for (size_t i = 0; !hasData && i < formatcount; i++) + for (size_t i = 0; i < formatcount; i++) { // go through the data in our order of preference wxDataFormat dataFormat = array[i]; if (source->IsSupported(dataFormat)) { - hasData = true; + format = dataFormat; + break; } } - - return hasData; + + return format; } +bool wxDataObject::CanReadFromSource( wxOSXDataSource * source ) const +{ + return GetSupportedFormatInSource(source) != wxDF_INVALID; +} + +bool wxDataObject::CanReadFromSource( wxDataObject * source ) const +{ + return GetSupportedFormatInSource(source) != wxDF_INVALID; +} void wxDataObject::AddSupportedTypes( CFMutableArrayRef cfarray) const { diff --git a/src/osx/dnd_osx.cpp b/src/osx/dnd_osx.cpp index e2864d85a2..9e0ade0128 100644 --- a/src/osx/dnd_osx.cpp +++ b/src/osx/dnd_osx.cpp @@ -36,8 +36,22 @@ wxDragResult wxDropTarget::OnDragOver( wxDataFormat wxDropTarget::GetMatchingPair() { - wxFAIL_MSG("wxDropTarget::GetMatchingPair() not implemented in src/osx/dnd_osx.cpp"); - return wxDF_INVALID; + wxDataFormat supported; + if (m_dataObject != NULL) + { + if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() ) + { + wxDataObject* data = currentSource->GetDataObject(); + + if ( data ) + supported = m_dataObject->GetSupportedFormatInSource(data); + } + + if ( supported == wxDF_INVALID ) + supported = m_dataObject->GetSupportedFormatInSource( m_currentDragPasteboard ); + } + + return supported; } bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) ) @@ -63,37 +77,7 @@ wxDragResult wxDropTarget::OnData( bool wxDropTarget::CurrentDragHasSupportedFormat() { - bool supported = false; - if (m_dataObject == NULL) - return false; - - if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() ) - { - wxDataObject* data = currentSource->GetDataObject(); - - if ( data ) - { - size_t formatcount = data->GetFormatCount(); - wxScopedArray array(formatcount); - data->GetAllFormats( array.get() ); - for (size_t i = 0; !supported && i < formatcount; i++) - { - wxDataFormat format = array[i]; - if ( m_dataObject->IsSupported( format, wxDataObject::Set ) ) - { - supported = true; - break; - } - } - } - } - - if ( !supported ) - { - supported = m_dataObject->CanReadFromSource( m_currentDragPasteboard ); - } - - return supported; + return GetMatchingPair() != wxDF_INVALID; } bool wxDropTarget::GetData() @@ -110,37 +94,11 @@ bool wxDropTarget::GetData() wxDataObject* data = currentSource->GetDataObject(); if (data != NULL) - { - size_t formatcount = data->GetFormatCount(); - wxScopedArray array(formatcount); - data->GetAllFormats( array.get() ); - for (size_t i = 0; !transferred && i < formatcount; i++) - { - wxDataFormat format = array[i]; - if ( m_dataObject->IsSupported( format, wxDataObject::Set ) ) - { - int size = data->GetDataSize( format ); - transferred = true; - - if (size == 0) - { - m_dataObject->SetData( format, 0, 0 ); - } - else - { - wxCharBuffer d(size); - data->GetDataHere( format, d.data() ); - m_dataObject->SetData( format, size, d.data() ); - } - } - } - } + transferred = m_dataObject->ReadFromSource(data); } if ( !transferred ) - { transferred = m_dataObject->ReadFromSource(m_currentDragPasteboard); - } return transferred; }