X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/219b657fbe238ab34cf41394162b87bb5ada3456..4800ca79accc0b96470a327871b2422cbb7ad615:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index d4ec164a93..ff9169dbe5 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -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" @@ -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, @@ -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(); @@ -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; @@ -1214,9 +1206,9 @@ public: 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()); @@ -1253,13 +1245,19 @@ wxString wxURLDataObject::GetURL() const 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) + 1; // size with trailing NUL +#if !wxUSE_UNICODE + SetData(wxDF_TEXT, len, urlMB); +#endif + SetData(wxDataFormat(CFSTR_SHELLURL), len, 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() + 1, url.wc_str()); +#endif } // ----------------------------------------------------------------------------