+ if (!m_dataObject)
+ return false;
+
+ if ( !CurrentDragHasSupportedFormat() )
+ return false ;
+
+ bool transferred = false ;
+ if ( gTrackingGlobals.m_currentSource != NULL )
+ {
+ wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
+
+ if ( data )
+ {
+ 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 )
+ {
+ UInt16 items ;
+ OSErr result;
+ ItemReference theItem;
+ FlavorType theType ;
+ FlavorFlags theFlags;
+ UInt16 flavors ;
+ bool firstFileAdded = false ;
+
+ CountDragItems((DragReference)m_currentDrag, &items);
+ for (UInt16 index = 1; index <= items; ++index)
+ {
+ flavors = 0 ;
+ GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
+ CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
+ bool hasPreferredFormat = false ;
+ wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
+
+ for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
+ {
+ result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
+ wxDataFormat format(theType) ;
+ if ( preferredFormat == format )
+ {
+ hasPreferredFormat = true ;
+ break ;
+ }
+ }
+
+ for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
+ {
+ result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
+ wxDataFormat format(theType) ;
+ if ( (hasPreferredFormat && format == preferredFormat) || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
+ {
+ result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
+ if (result == noErr)
+ {
+ Size dataSize ;
+ Ptr theData ;
+
+ GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
+ if ( theType == kScrapFlavorTypeText )
+ {
+ // 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 )
+ {
+ // this increment is only valid for allocating, on the next GetFlavorData
+ // call it is reset again to the original value
+ dataSize++ ;
+ dataSize++ ;
+ }
+
+ theData = new char[dataSize];
+ GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
+ if ( theType == kScrapFlavorTypeText )
+ {
+ theData[dataSize] = 0 ;
+ m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
+ }
+ #if wxUSE_UNICODE
+ else if ( theType == kScrapFlavorTypeUnicode )
+ {
+ theData[dataSize] = 0 ;
+ theData[dataSize + 1] = 0 ;
+ m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData );
+ }
+ #endif
+ else if ( theType == kDragFlavorTypeHFS )
+ {
+ HFSFlavor* theFile = (HFSFlavor*) theData ;
+ wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ;
+ if ( !firstFileAdded )
+ {
+ // reset file list
+ ((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
+ firstFileAdded = true ;
+ }
+
+ ((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
+ }
+ else
+ {
+ m_dataObject->SetData( format, dataSize, theData );
+ }
+
+ delete [] theData;
+ }
+ break ;
+ }
+ }
+ }
+ }
+
+ return true ;