X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/daac16bba04f40b8a064799963dc49ec180aaae9..b404a8f3b072129c107c6d9a5e0f6f53cd34807b:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 83511b7be1..156605e408 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: msw/ole/dataobj.cpp +// Name: src/msw/ole/dataobj.cpp // Purpose: implementation of wx[I]DataObject class // Author: Vadim Zeitlin // Modified by: @@ -28,6 +28,7 @@ #include "wx/intl.h" #include "wx/log.h" #include "wx/utils.h" + #include "wx/wxcrtvararg.h" #endif #include "wx/dataobj.h" @@ -53,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 @@ -89,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); }; // ---------------------------------------------------------------------------- @@ -125,7 +126,7 @@ private: bool m_mustDelete; - DECLARE_NO_COPY_CLASS(wxIDataObject) + wxDECLARE_NO_COPY_CLASS(wxIDataObject); }; // ============================================================================ @@ -136,9 +137,9 @@ private: // wxDataFormat // ---------------------------------------------------------------------------- -void wxDataFormat::SetId(const wxChar *format) +void wxDataFormat::SetId(const wxString& format) { - m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format); + m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format.wx_str()); if ( !m_format ) { wxLogError(_("Couldn't register clipboard format '%s'."), format); @@ -159,6 +160,7 @@ wxString wxDataFormat::GetId() const if ( !len ) { wxLogError(_("The clipboard format '%d' doesn't exist."), m_format); + return wxEmptyString; } return s; @@ -684,13 +686,14 @@ size_t wxDataObject::GetBufferOffset(const wxDataFormat& format ) return NeedsVerbatimData(format) ? 0 : sizeof(size_t); } -const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size, - const wxDataFormat& format ) +const void *wxDataObject::GetSizeFromBuffer(const void *buffer, + size_t *size, + const wxDataFormat& WXUNUSED(format)) { // 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)); + const size_t realsz = ::HeapSize(::GetProcessHeap(), 0, + const_cast(buffer)); if ( realsz == (size_t)-1 ) { // note that HeapSize() does not set last error @@ -700,18 +703,7 @@ const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size, *size = realsz; - // check if this data has its size prepended (as it was by default for wx - // programs prior 2.6.3): - size_t *p = (size_t *)buffer; - if ( *p == realsz ) - { - if ( NeedsVerbatimData(format) ) - wxLogDebug(wxT("Apparent data format mismatch: size not needed")); - - p++; // this data has its size prepended; skip first DWORD - } - - return p; + return buffer; } void* wxDataObject::SetSizeInBuffer( void* buffer, size_t size, @@ -727,7 +719,7 @@ void* wxDataObject::SetSizeInBuffer( void* buffer, size_t size, return p; } -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL const wxChar *wxDataObject::GetFormatName(wxDataFormat format) { @@ -772,7 +764,7 @@ const wxChar *wxDataObject::GetFormatName(wxDataFormat format) #endif // VC++ } -#endif // Debug +#endif // wxDEBUG_LEVEL // ---------------------------------------------------------------------------- // wxBitmapDataObject supports CF_DIB format @@ -860,7 +852,7 @@ bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf) wxBitmap bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes); bitmap.SetHBITMAP((WXHBITMAP)hbmp); - if ( !bitmap.Ok() ) { + if ( !bitmap.IsOk() ) { wxFAIL_MSG(wxT("pasting/dropping invalid bitmap")); return false; @@ -906,7 +898,7 @@ size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *pBuf) const { - wxASSERT_MSG( m_bitmap.Ok(), wxT("copying invalid bitmap") ); + wxASSERT_MSG( m_bitmap.IsOk(), wxT("copying invalid bitmap") ); HBITMAP hbmp = (HBITMAP)m_bitmap.GetHBITMAP(); if ( format.GetFormatId() == CF_DIB ) @@ -985,7 +977,7 @@ bool wxBitmapDataObject::SetData(const wxDataFormat& format, m_bitmap.SetHBITMAP((WXHBITMAP)hbmp); - wxASSERT_MSG( m_bitmap.Ok(), wxT("pasting invalid bitmap") ); + wxASSERT_MSG( m_bitmap.IsOk(), wxT("pasting invalid bitmap") ); return true; } @@ -1057,7 +1049,7 @@ size_t wxFileDataObject::GetDataSize() const #if wxUSE_UNICODE_MSLU size_t sizeOfChar; - if ( wxGetOsVersion() == wxWIN95 ) + if ( wxGetOsVersion() == wxOS_WINDOWS_9X ) { // Win9x always uses ANSI file names and MSLU doesn't help with this sizeOfChar = sizeof(char); @@ -1080,7 +1072,7 @@ size_t wxFileDataObject::GetDataSize() const size_t len; #if wxUSE_UNICODE_MSLU if ( sizeOfChar == sizeof(char) ) - len = strlen(wxConvFileName->cWC2MB(m_filenames[i])); + len = strlen(m_filenames[i].mb_str(*wxConvFileName)); else #endif // wxUSE_UNICODE_MSLU len = m_filenames[i].length(); @@ -1111,7 +1103,7 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const pDrop->pFiles = sizeof(DROPFILES); pDrop->fNC = FALSE; // not non-client coords #if wxUSE_UNICODE_MSLU - pDrop->fWide = wxGetOsVersion() != wxWIN95 ? TRUE : FALSE; + pDrop->fWide = wxGetOsVersion() != wxOS_WINDOWS_9X ? TRUE : FALSE; #else pDrop->fWide = wxUSE_UNICODE; #endif @@ -1129,7 +1121,7 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const #if wxUSE_UNICODE_MSLU if ( sizeOfChar == sizeof(char) ) { - wxCharBuffer buf(wxConvFileName->cWC2MB(m_filenames[i])); + wxCharBuffer buf(m_filenames[i].mb_str(*wxConvFileName)); len = strlen(buf); memcpy(pbuf, buf, len*sizeOfChar); } @@ -1137,7 +1129,7 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const #endif // wxUSE_UNICODE_MSLU { len = m_filenames[i].length(); - memcpy(pbuf, m_filenames[i].c_str(), len*sizeOfChar); + memcpy(pbuf, m_filenames[i].wx_str(), len*sizeOfChar); } pbuf += len*sizeOfChar; @@ -1159,6 +1151,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 wxT("CFSTR_SHELLURL") +#endif + class CFSTR_SHELLURLDataObject : public wxCustomDataObject { public: @@ -1184,33 +1182,16 @@ 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); }; 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 - // support both + // we support CF_TEXT and CFSTR_SHELLURL formats which are basically the + // same but it seems that some browsers only provide one of them so we have + // to support both Add(new wxTextDataObject); Add(new CFSTR_SHELLURLDataObject()); @@ -1236,31 +1217,63 @@ 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; } void wxURLDataObject::SetURL(const wxString& url) { - SetData(wxDataFormat(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT), - url.Length()+1, url.c_str()); + wxCharBuffer urlMB(url.mb_str()); + if ( urlMB ) + { + 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); +#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); + } - // CFSTR_SHELLURL is always supposed to be ANSI... - wxWX2MBbuf urlA = (wxWX2MBbuf)url.mbc_str(); - size_t len = strlen(urlA); - SetData(wxDataFormat(CFSTR_SHELLURL), len+1, (const char*)urlA); +#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