X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8e24848f67a655c6845420caf00a29100e38d9f..823b6635f6be00ef24a858b9766c601d9227b920:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index ded312e08d..4cfcee5e9e 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -27,6 +27,7 @@ #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" + #include "wx/utils.h" #endif #include "wx/dataobj.h" @@ -158,6 +159,7 @@ wxString wxDataFormat::GetId() const if ( !len ) { wxLogError(_("The clipboard format '%d' doesn't exist."), m_format); + return wxEmptyString; } return s; @@ -686,8 +688,11 @@ size_t wxDataObject::GetBufferOffset(const wxDataFormat& format ) const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size, const wxDataFormat& format ) { - SIZE_T realsz = ::HeapSize(::GetProcessHeap(), 0, buffer); - if ( realsz == (SIZE_T)-1 ) + // hack: the third parameter is declared non-const in Wine's headers so + // cast away the const + size_t realsz = ::HeapSize(::GetProcessHeap(), 0, + wx_const_cast(void*, buffer)); + if ( realsz == (size_t)-1 ) { // note that HeapSize() does not set last error wxLogApiError(wxT("HeapSize"), 0); @@ -1044,22 +1049,44 @@ void wxFileDataObject::AddFile(const wxString& 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 + // 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.GetCount() == 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) + (1 * sizeof(wxChar)); + size_t sz = sizeof(DROPFILES) + sizeOfChar; - size_t count = m_filenames.GetCount(); + const size_t count = m_filenames.size(); for ( size_t i = 0; i < count; i++ ) { // add filename length plus null byte - sz += (m_filenames[i].Len() + 1) * sizeof(wxChar); + size_t len; +#if wxUSE_UNICODE_MSLU + if ( sizeOfChar == sizeof(char) ) + len = strlen(wxConvFileName->cWC2MB(m_filenames[i])); + else +#endif // wxUSE_UNICODE_MSLU + len = m_filenames[i].length(); + + sz += (len + 1) * sizeOfChar; } return sz; @@ -1075,7 +1102,7 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const // created using the size returned by GetDataSize() // if pData is NULL, or there are no files, return - if ( !pData || m_filenames.GetCount() == 0 ) + if ( !pData || m_filenames.empty() ) return false; // convert data pointer to a DROPFILES struct pointer @@ -1084,27 +1111,44 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const // initialize DROPFILES struct pDrop->pFiles = sizeof(DROPFILES); pDrop->fNC = FALSE; // not non-client coords -#if wxUSE_UNICODE - pDrop->fWide = TRUE; -#else // ANSI - pDrop->fWide = FALSE; -#endif // Unicode/Ansi +#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) - wxChar *pbuf = (wxChar*) ((BYTE *)pDrop + sizeof(DROPFILES)); + BYTE *pbuf = (BYTE *)(pDrop + 1); - size_t count = m_filenames.GetCount(); - for (size_t i = 0; i < count; i++ ) + 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 = m_filenames[i].Len(); - memcpy(pbuf, m_filenames[i], len*sizeof(wxChar)); - pbuf += len; - *pbuf++ = wxT('\0'); + size_t len; +#if wxUSE_UNICODE_MSLU + if ( sizeOfChar == sizeof(char) ) + { + wxCharBuffer buf(wxConvFileName->cWC2MB(m_filenames[i])); + len = strlen(buf); + memcpy(pbuf, buf, len*sizeOfChar); + } + else +#endif // wxUSE_UNICODE_MSLU + { + len = m_filenames[i].length(); + memcpy(pbuf, m_filenames[i].c_str(), len*sizeOfChar); + } + + pbuf += len*sizeOfChar; + + memset(pbuf, 0, sizeOfChar); + pbuf += sizeOfChar; } // add final null terminator - *pbuf = wxT('\0'); + memset(pbuf, 0, sizeOfChar); return true; #else @@ -1116,6 +1160,12 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const // wxURLDataObject // ---------------------------------------------------------------------------- +// Work around bug in Wine headers +#if defined(__WINE__) && defined(CFSTR_SHELLURL) && wxUSE_UNICODE +#undef CFSTR_SHELLURL +#define CFSTR_SHELLURL _T("CFSTR_SHELLURL") +#endif + class CFSTR_SHELLURLDataObject : public wxCustomDataObject { public: @@ -1163,7 +1213,7 @@ public: -wxURLDataObject::wxURLDataObject() +wxURLDataObject::wxURLDataObject(const wxString& url) { // we support CF_TEXT and CFSTR_SHELLURL formats which are basicly the same // but it seems that some browsers only provide one of them so we have to @@ -1173,6 +1223,9 @@ wxURLDataObject::wxURLDataObject() // we don't have any data yet m_dataObjectLast = NULL; + + if ( !url.empty() ) + SetURL(url); } bool wxURLDataObject::SetData(const wxDataFormat& format,