X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/afd23c224adf19f62353d8ec309db91747cbf237..6505ca85df415198d1686d48253545dcb93a22c6:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index b00c440a15..ded312e08d 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "dataobj.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -79,14 +75,14 @@ public: wxIEnumFORMATETC(const wxDataFormat* formats, ULONG nCount); virtual ~wxIEnumFORMATETC() { delete [] m_formats; } - DECLARE_IUNKNOWN_METHODS; - // IEnumFORMATETC STDMETHODIMP Next(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched); STDMETHODIMP Skip(ULONG celt); STDMETHODIMP Reset(); STDMETHODIMP Clone(IEnumFORMATETC **ppenum); + DECLARE_IUNKNOWN_METHODS; + private: CLIPFORMAT *m_formats; // formats we can provide data in ULONG m_nCount, // number of formats we support @@ -106,12 +102,10 @@ public: virtual ~wxIDataObject(); // normally, wxDataObject controls our lifetime (i.e. we're deleted when it - // is), but in some cases, the situation is inversed, that is we delete it + // is), but in some cases, the situation is reversed, that is we delete it // when this object is deleted - setting this flag enables such logic void SetDeleteFlag() { m_mustDelete = true; } - DECLARE_IUNKNOWN_METHODS; - // IDataObject STDMETHODIMP GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium); STDMETHODIMP GetDataHere(FORMATETC *pformatetc, STGMEDIUM *pmedium); @@ -123,6 +117,8 @@ public: STDMETHODIMP DUnadvise(DWORD dwConnection); STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppenumAdvise); + DECLARE_IUNKNOWN_METHODS; + private: wxDataObject *m_pDataObject; // pointer to C++ class we belong to @@ -323,13 +319,8 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium) return DV_E_FORMATETC; } - if ( !format.IsStandard() ) { - // for custom formats, put the size with the data - alloc the - // space for it - // MB: not completely sure this is correct, - // even if I can't figure out what's wrong - size += m_pDataObject->GetBufferOffset( format ); - } + // we may need extra space for the buffer size + size += m_pDataObject->GetBufferOffset( format ); HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, size); if ( hGlobal == NULL ) { @@ -391,10 +382,14 @@ STDMETHODIMP wxIDataObject::GetDataHere(FORMATETC *pformatetc, } wxDataFormat format = pformatetc->cfFormat; - if ( !format.IsStandard() ) { - // for custom formats, put the size with the data - pBuf = m_pDataObject->SetSizeInBuffer( pBuf, GlobalSize(hGlobal), format ); - } + + // possibly put the size in the beginning of the buffer + pBuf = m_pDataObject->SetSizeInBuffer + ( + pBuf, + ::GlobalSize(hGlobal), + format + ); if ( !m_pDataObject->GetDataHere(format, pBuf) ) return E_UNEXPECTED; @@ -496,14 +491,9 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, break; #endif default: - { - // we suppose that the size precedes the data - pBuf = m_pDataObject->GetSizeFromBuffer( pBuf, &size, format ); - if (! format.IsStandard() ) { - // see GetData for coresponding increment - size -= m_pDataObject->GetBufferOffset( format ); - } - } + pBuf = m_pDataObject-> + GetSizeFromBuffer(pBuf, &size, format); + size -= m_pDataObject->GetBufferOffset(format); } bool ok = m_pDataObject->SetData(format, size, pBuf); @@ -624,7 +614,7 @@ STDMETHODIMP wxIDataObject::EnumFormatEtc(DWORD dwDir, wxDataObject::Direction dir = dwDir == DATADIR_GET ? wxDataObject::Get : wxDataObject::Set; - size_t nFormatCount = m_pDataObject->GetFormatCount(dir); + ULONG nFormatCount = wx_truncate_cast(ULONG, m_pDataObject->GetFormatCount(dir)); wxDataFormat format; wxDataFormat *formats; formats = nFormatCount == 1 ? &format : new wxDataFormat[nFormatCount]; @@ -687,27 +677,50 @@ void wxDataObject::SetAutoDelete() m_pIDataObject = NULL; } -size_t wxDataObject::GetBufferOffset( const wxDataFormat& WXUNUSED(format) ) +size_t wxDataObject::GetBufferOffset(const wxDataFormat& format ) { - return sizeof(size_t); + // if we prepend the size of the data to the buffer itself, account for it + return NeedsVerbatimData(format) ? 0 : sizeof(size_t); } const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size, - const wxDataFormat& WXUNUSED(format) ) + const wxDataFormat& format ) { - size_t* p = (size_t*)buffer; - *size = *p; + SIZE_T realsz = ::HeapSize(::GetProcessHeap(), 0, buffer); + if ( realsz == (SIZE_T)-1 ) + { + // note that HeapSize() does not set last error + wxLogApiError(wxT("HeapSize"), 0); + return NULL; + } - return p + 1; + *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; } void* wxDataObject::SetSizeInBuffer( void* buffer, size_t size, - const wxDataFormat& WXUNUSED(format) ) + const wxDataFormat& format ) { - size_t* p = (size_t*)buffer; - *p = size; + size_t* p = (size_t *)buffer; + if ( !NeedsVerbatimData(format) ) + { + // prepend the size to the data and skip it + *p++ = size; + } - return p + 1; + return p; } #ifdef __WXDEBUG__ @@ -979,7 +992,8 @@ bool wxBitmapDataObject::SetData(const wxDataFormat& format, // wxFileDataObject // ---------------------------------------------------------------------------- -bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *pData) +bool wxFileDataObject::SetData(size_t WXUNUSED(size), + const void *WXUNUSED_IN_WINCE(pData)) { #ifndef __WXWINCE__ m_filenames.Empty(); @@ -1015,7 +1029,6 @@ bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *pData) return true; #else - wxUnusedVar(pData); return false; #endif } @@ -1055,7 +1068,7 @@ size_t wxFileDataObject::GetDataSize() const #endif } -bool wxFileDataObject::GetDataHere(void *pData) const +bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const { #ifndef __WXWINCE__ // pData points to an externally allocated memory block @@ -1095,7 +1108,6 @@ bool wxFileDataObject::GetDataHere(void *pData) const return true; #else - wxUnusedVar(pData); return false; #endif } @@ -1108,7 +1120,7 @@ class CFSTR_SHELLURLDataObject : public wxCustomDataObject { public: CFSTR_SHELLURLDataObject() : wxCustomDataObject(CFSTR_SHELLURL) {} -protected: + virtual size_t GetBufferOffset( const wxDataFormat& WXUNUSED(format) ) { return 0; @@ -1224,6 +1236,7 @@ static const wxChar *GetTymedName(DWORD tymed) #endif // Debug #else // not using OLE at all + // ---------------------------------------------------------------------------- // wxDataObject // ---------------------------------------------------------------------------- @@ -1243,13 +1256,14 @@ void wxDataObject::SetAutoDelete() } #ifdef __WXDEBUG__ -const wxChar *wxDataObject::GetFormatName(wxDataFormat format) +const wxChar *wxDataObject::GetFormatName(wxDataFormat WXUNUSED(format)) { return NULL; } -#endif +#endif // __WXDEBUG__ -#endif +#endif // wxUSE_DATAOBJ + +#endif // wxUSE_OLE/!wxUSE_OLE -#endif