- // the documentation states that the first member of DROPFILES structure
- // is a "DWORD offset of double NUL terminated file list". What they mean by
- // this (I wonder if you see it immediately) is that the list starts at
- // ((char *)&(pDropFiles.pFiles)) + pDropFiles.pFiles. We're also advised to
- // use DragQueryFile to work with this structure, but not told where and how
- // to get HDROP.
- HDROP hdrop = (HDROP)pData; // NB: it works, but I'm not sure about it
-
- // get number of files (magic value -1)
- UINT nFiles = ::DragQueryFile(hdrop, (unsigned)-1, NULL, 0u);
-
- // for each file get the length, allocate memory and then get the name
- char **aszFiles = new char *[nFiles];
- UINT len, n;
- for ( n = 0; n < nFiles; n++ ) {
- // +1 for terminating NUL
- len = ::DragQueryFile(hdrop, n, NULL, 0) + 1;
-
- aszFiles[n] = new char[len];
-
- UINT len2 = ::DragQueryFile(hdrop, n, aszFiles[n], len);
- if ( len2 != len - 1 ) {
- wxLogDebug("In wxFileDropTarget::OnDrop DragQueryFile returned %d "
- "characters, %d expected.", len2, len - 1);
+ // this strucutre describes a data of any type (first field will be
+ // changing) being passed through global memory block.
+ static FORMATETC s_fmtMemory = {
+ 0,
+ NULL,
+ DVASPECT_CONTENT,
+ -1,
+ TYMED_HGLOBAL // TODO is it worth supporting other tymeds here?
+ };
+
+ // get the list of supported formats
+ size_t nFormats = m_dataObject->GetFormatCount(wxDataObject::Set);
+ wxDataFormat format;
+ wxDataFormat *formats;
+ formats = nFormats == 1 ? &format : new wxDataFormat[nFormats];
+
+ m_dataObject->GetAllFormats(formats, wxDataObject::Set);
+
+ // cycle through all supported formats
+ size_t n;
+ for ( n = 0; n < nFormats; n++ ) {
+ s_fmtMemory.cfFormat = formats[n];
+
+ // NB: don't use SUCCEEDED macro here: QueryGetData returns S_FALSE
+ // for file drag and drop (format == CF_HDROP)
+ if ( pIDataSource->QueryGetData(&s_fmtMemory) == S_OK ) {
+ format = formats[n];
+
+ break;
+ }