X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/abb88ef36b622958aee316eae76c79b145b831dd..1cd44b9c5f49407329c3da220ca8212e65e97d6c:/src/msw/ole/dataobj.cpp?ds=sidebyside diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 21c81b5bb4..540d2330bf 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -54,18 +54,18 @@ #include "wx/msw/dib.h" #ifndef CFSTR_SHELLURL -#define CFSTR_SHELLURL _T("UniformResourceLocator") +#define CFSTR_SHELLURL wxT("UniformResourceLocator") #endif // ---------------------------------------------------------------------------- // functions // ---------------------------------------------------------------------------- -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL static const wxChar *GetTymedName(DWORD tymed); -#else // !Debug +#else // !wxDEBUG_LEVEL #define GetTymedName(tymed) wxEmptyString -#endif // Debug/!Debug +#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL // ---------------------------------------------------------------------------- // wxIEnumFORMATETC interface implementation @@ -90,7 +90,7 @@ private: ULONG m_nCount, // number of formats we support m_nCurrent; // current enum position - DECLARE_NO_COPY_CLASS(wxIEnumFORMATETC) + wxDECLARE_NO_COPY_CLASS(wxIEnumFORMATETC); }; // ---------------------------------------------------------------------------- @@ -126,7 +126,7 @@ private: bool m_mustDelete; - DECLARE_NO_COPY_CLASS(wxIDataObject) + wxDECLARE_NO_COPY_CLASS(wxIDataObject); }; // ============================================================================ @@ -688,12 +688,12 @@ size_t wxDataObject::GetBufferOffset(const wxDataFormat& format ) const void *wxDataObject::GetSizeFromBuffer(const void *buffer, size_t *size, - const wxDataFormat& format) + const wxDataFormat& WXUNUSED(format)) { // hack: the third parameter is declared non-const in Wine's headers so // cast away the const const size_t realsz = ::HeapSize(::GetProcessHeap(), 0, - wx_const_cast(void*, buffer)); + const_cast(buffer)); if ( realsz == (size_t)-1 ) { // note that HeapSize() does not set last error @@ -719,7 +719,7 @@ void* wxDataObject::SetSizeInBuffer( void* buffer, size_t size, return p; } -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL const wxChar *wxDataObject::GetFormatName(wxDataFormat format) { @@ -764,7 +764,7 @@ const wxChar *wxDataObject::GetFormatName(wxDataFormat format) #endif // VC++ } -#endif // Debug +#endif // wxDEBUG_LEVEL // ---------------------------------------------------------------------------- // wxBitmapDataObject supports CF_DIB format @@ -1154,7 +1154,7 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const // Work around bug in Wine headers #if defined(__WINE__) && defined(CFSTR_SHELLURL) && wxUSE_UNICODE #undef CFSTR_SHELLURL -#define CFSTR_SHELLURL _T("CFSTR_SHELLURL") +#define CFSTR_SHELLURL wxT("CFSTR_SHELLURL") #endif class CFSTR_SHELLURLDataObject : public wxCustomDataObject @@ -1182,24 +1182,7 @@ public: return buffer; } -#if wxUSE_UNICODE - virtual bool GetDataHere( void* buffer ) const - { - // CFSTR_SHELLURL is _always_ ANSI! - wxCharBuffer char_buffer( GetDataSize() ); - wxCustomDataObject::GetDataHere( (void*)char_buffer.data() ); - wxString unicode_buffer( char_buffer, wxConvLibc ); - memcpy( buffer, unicode_buffer.c_str(), - ( unicode_buffer.length() + 1 ) * sizeof(wxChar) ); - - return true; - } - virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format), - void *buf) const - { return GetDataHere(buf); } -#endif - - DECLARE_NO_COPY_CLASS(CFSTR_SHELLURLDataObject) + wxDECLARE_NO_COPY_CLASS(CFSTR_SHELLURLDataObject); }; @@ -1234,11 +1217,30 @@ bool wxURLDataObject::SetData(const wxDataFormat& format, wxString wxURLDataObject::GetURL() const { wxString url; - wxCHECK_MSG( m_dataObjectLast, url, _T("no data in wxURLDataObject") ); + wxCHECK_MSG( m_dataObjectLast, url, wxT("no data in wxURLDataObject") ); - size_t len = m_dataObjectLast->GetDataSize(); + if ( m_dataObjectLast->GetPreferredFormat() == CFSTR_SHELLURL ) + { + const size_t len = m_dataObjectLast->GetDataSize(); + if ( !len ) + return wxString(); - m_dataObjectLast->GetDataHere(wxStringBuffer(url, len)); + // CFSTR_SHELLURL is always ANSI so we need to convert it from it in + // Unicode build +#if wxUSE_UNICODE + wxCharBuffer buf(len); + + if ( m_dataObjectLast->GetDataHere(buf.data()) ) + url = buf; +#else // !wxUSE_UNICODE + // in ANSI build no conversion is necessary + m_dataObjectLast->GetDataHere(wxStringBuffer(url, len)); +#endif // wxUSE_UNICODE/!wxUSE_UNICODE + } + else // must be wxTextDataObject + { + url = static_cast(m_dataObjectLast)->GetText(); + } return url; } @@ -1248,19 +1250,30 @@ void wxURLDataObject::SetURL(const wxString& url) wxCharBuffer urlMB(url.mb_str()); if ( urlMB ) { - const size_t len = strlen(urlMB) + 1; // size with trailing NUL + const size_t len = strlen(urlMB); + +#if !wxUSE_UNICODE + // wxTextDataObject takes the number of characters in the string, not + // the size of the buffer (which would be len+1) SetData(wxDF_TEXT, len, urlMB); - SetData(wxDataFormat(CFSTR_SHELLURL), len, urlMB); +#endif // !wxUSE_UNICODE + + // however CFSTR_SHELLURLDataObject doesn't append NUL automatically + // but we probably still want to have it on the clipboard (just to be + // safe), so do append it + SetData(wxDataFormat(CFSTR_SHELLURL), len + 1, urlMB); } - SetData(wxDF_UNICODETEXT, url.length() + 1, url.wc_str()); +#if wxUSE_UNICODE + SetData(wxDF_UNICODETEXT, url.length()*sizeof(wxChar), url.wc_str()); +#endif } // ---------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------- -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL static const wxChar *GetTymedName(DWORD tymed) { @@ -1301,12 +1314,10 @@ void wxDataObject::SetAutoDelete() { } -#ifdef __WXDEBUG__ const wxChar *wxDataObject::GetFormatName(wxDataFormat WXUNUSED(format)) { return NULL; } -#endif // __WXDEBUG__ #endif // wxUSE_DATAOBJ