]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/dnd_osx.cpp
Get wxSearchCtrl text events working, and share the text event handler code among...
[wxWidgets.git] / src / osx / dnd_osx.cpp
index c19bf6eb8f0aae1c9bb1df1f083e937fc1bd78e7..b64858930ae504373e76d4c1725f22bf9c2ecb6f 100644 (file)
@@ -61,6 +61,95 @@ wxDragResult wxDropTarget::OnData(
     return GetData() ? def : wxDragNone;
 }
 
+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();
+            wxDataFormat *array = new wxDataFormat[formatcount];
+            data->GetAllFormats( array );
+            for (size_t i = 0; !supported && i < formatcount; i++)
+            {
+                wxDataFormat format = array[i];
+                if ( m_dataObject->IsSupported( format ) )
+                {
+                    supported = true;
+                    break;
+                }
+            }
+
+            delete [] array;
+        }
+    }
+
+    if ( !supported )
+    {
+        supported = m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
+    }
+
+    return supported;
+}
+
+bool wxDropTarget::GetData()
+{
+    if (m_dataObject == NULL)
+        return false;
+
+    if ( !CurrentDragHasSupportedFormat() )
+        return false;
+
+    bool transferred = false;
+    if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
+    {
+        wxDataObject* data = currentSource->GetDataObject();
+
+        if (data != NULL)
+        {
+            size_t formatcount = data->GetFormatCount();
+            wxDataFormat *array = new wxDataFormat[formatcount];
+            data->GetAllFormats( array );
+            for (size_t i = 0; !transferred && i < formatcount; i++)
+            {
+                wxDataFormat format = array[i];
+                if ( m_dataObject->IsSupported( format ) )
+                {
+                    int size = data->GetDataSize( format );
+                    transferred = true;
+
+                    if (size == 0)
+                    {
+                        m_dataObject->SetData( format, 0, 0 );
+                    }
+                    else
+                    {
+                        char *d = new char[size];
+                        data->GetDataHere( format, (void*)d );
+                        m_dataObject->SetData( format, size, d );
+                        delete [] d;
+                    }
+                }
+            }
+
+            delete [] array;
+        }
+    }
+
+    if ( !transferred )
+    {
+        transferred = m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
+    }
+
+    return transferred;
+}
+
 //-------------------------------------------------------------------------
 // wxDropSource
 //-------------------------------------------------------------------------