+// wxFileDataObject
+// ----------------------------------------------------------------------------
+
+bool wxFileDataObject::SetData(size_t WXUNUSED(size),
+ const void *WXUNUSED_IN_WINCE(pData))
+{
+#ifndef __WXWINCE__
+ m_filenames.Empty();
+
+ // 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);
+
+ wxCHECK_MSG ( nFiles != (UINT)-1, FALSE, wxT("wrong HDROP handle") );
+
+ // for each file get the length, allocate memory and then get the name
+ wxString str;
+ UINT len, n;
+ for ( n = 0; n < nFiles; n++ ) {
+ // +1 for terminating NUL
+ len = ::DragQueryFile(hdrop, n, NULL, 0) + 1;
+
+ UINT len2 = ::DragQueryFile(hdrop, n, wxStringBuffer(str, len), len);
+ m_filenames.Add(str);
+
+ if ( len2 != len - 1 ) {
+ wxLogDebug(wxT("In wxFileDropTarget::OnDrop DragQueryFile returned\
+ %d characters, %d expected."), len2, len - 1);
+ }
+ }
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+void wxFileDataObject::AddFile(const wxString& file)
+{
+ // just add file to filenames array
+ // all useful data (such as DROPFILES struct) will be
+ // created later as necessary
+ m_filenames.Add(file);
+}
+
+size_t wxFileDataObject::GetDataSize() const
+{
+#ifndef __WXWINCE__
+ // size returned will be the size of the DROPFILES structure, plus the list
+ // of filesnames (null byte separated), plus a double null at the end
+
+ // if no filenames in list, size is 0
+ if ( m_filenames.empty() )
+ return 0;
+
+#if wxUSE_UNICODE_MSLU
+ size_t sizeOfChar;
+ if ( wxGetOsVersion() == wxOS_WINDOWS_9X )
+ {
+ // Win9x always uses ANSI file names and MSLU doesn't help with this
+ sizeOfChar = sizeof(char);
+ }
+ else
+ {
+ sizeOfChar = sizeof(wxChar);
+ }
+#else // !wxUSE_UNICODE_MSLU
+ static const size_t sizeOfChar = sizeof(wxChar);
+#endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
+
+ // inital size of DROPFILES struct + null byte
+ size_t sz = sizeof(DROPFILES) + sizeOfChar;
+
+ const size_t count = m_filenames.size();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ // add filename length plus null byte
+ size_t len;
+#if wxUSE_UNICODE_MSLU
+ if ( sizeOfChar == sizeof(char) )
+ len = strlen(m_filenames[i].mb_str(*wxConvFileName));
+ else
+#endif // wxUSE_UNICODE_MSLU
+ len = m_filenames[i].length();
+
+ sz += (len + 1) * sizeOfChar;
+ }
+
+ return sz;
+#else
+ return 0;
+#endif
+}
+
+bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const
+{
+#ifndef __WXWINCE__
+ // pData points to an externally allocated memory block
+ // created using the size returned by GetDataSize()
+
+ // if pData is NULL, or there are no files, return
+ if ( !pData || m_filenames.empty() )
+ return false;
+
+ // convert data pointer to a DROPFILES struct pointer
+ LPDROPFILES pDrop = (LPDROPFILES) pData;
+
+ // initialize DROPFILES struct
+ pDrop->pFiles = sizeof(DROPFILES);
+ pDrop->fNC = FALSE; // not non-client coords
+#if wxUSE_UNICODE_MSLU
+ pDrop->fWide = wxGetOsVersion() != wxOS_WINDOWS_9X ? TRUE : FALSE;
+#else
+ pDrop->fWide = wxUSE_UNICODE;
+#endif
+
+ const size_t sizeOfChar = pDrop->fWide ? sizeof(wchar_t) : sizeof(char);
+
+ // set start of filenames list (null separated)
+ BYTE *pbuf = (BYTE *)(pDrop + 1);
+
+ const size_t count = m_filenames.size();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ // copy filename to pbuf and add null terminator
+ size_t len;
+#if wxUSE_UNICODE_MSLU
+ if ( sizeOfChar == sizeof(char) )
+ {
+ wxCharBuffer buf(m_filenames[i].mb_str(*wxConvFileName));
+ len = strlen(buf);
+ memcpy(pbuf, buf, len*sizeOfChar);
+ }
+ else
+#endif // wxUSE_UNICODE_MSLU
+ {
+ len = m_filenames[i].length();
+ memcpy(pbuf, m_filenames[i].wx_str(), len*sizeOfChar);
+ }
+
+ pbuf += len*sizeOfChar;
+
+ memset(pbuf, 0, sizeOfChar);
+ pbuf += sizeOfChar;
+ }
+
+ // add final null terminator
+ memset(pbuf, 0, sizeOfChar);
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+// ----------------------------------------------------------------------------
+// wxURLDataObject