X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8b85d24e4cc885263d3bb72bd36a759fbd25631d..75515c52a48086d39f1584caec03fefaacb37306:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 90e8ab88cb..14d98afe93 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -18,26 +18,27 @@ // ---------------------------------------------------------------------------- #ifdef __GNUG__ - #pragma implementation "dataobj.h" + #pragma implementation "dataobj.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #if defined(__BORLANDC__) - #pragma hdrstop + #pragma hdrstop #endif + +#if defined(__WIN32__) && !defined(__GNUWIN32_OLD__) + #ifndef WX_PRECOMP -#include "wx/intl.h" + #include "wx/intl.h" + #include "wx/log.h" #endif -#include "wx/defs.h" - -#if defined(__WIN32__) && !defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS) -#include "wx/log.h" #include "wx/dataobj.h" -#include +#include "wx/msw/private.h" // includes + #ifdef wxUSE_NORLANDER_HEADERS #include #endif @@ -50,7 +51,9 @@ #include -#include "wx/msw/ole/oleutils.h" +#include "wx/msw/ole/oleutils.h" + +#include "wx/msw/dib.h" // ---------------------------------------------------------------------------- // functions @@ -62,10 +65,6 @@ #define GetTymedName(tymed) "" #endif // Debug/!Debug -// to be moved into wx/msw/bitmap.h -extern size_t wxConvertBitmapToDIB(BITMAPINFO *pbi, const wxBitmap& bitmap); -extern wxBitmap wxConvertDIBToBitmap(const BITMAPINFO *bmi); - // ---------------------------------------------------------------------------- // wxIEnumFORMATETC interface implementation // ---------------------------------------------------------------------------- @@ -124,22 +123,6 @@ private: bool m_mustDelete; }; -// ---------------------------------------------------------------------------- -// small helper class for getting screen DC (we're working with bitmaps and -// DIBs here) -// ---------------------------------------------------------------------------- - -class ScreenHDC -{ -public: - ScreenHDC() { m_hdc = GetDC(NULL); } - ~ScreenHDC() { ReleaseDC(NULL, m_hdc); } - operator HDC() const { return m_hdc; } - -private: - HDC m_hdc; -}; - // ============================================================================ // implementation // ============================================================================ @@ -315,6 +298,12 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium) break; case wxDF_METAFILE: + pmedium->hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, + sizeof(METAFILEPICT)); + if ( !pmedium->hGlobal ) { + wxLogLastError("GlobalAlloc"); + return E_OUTOFMEMORY; + } pmedium->tymed = TYMED_MFPICT; break; @@ -351,7 +340,7 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium) hr = GetDataHere(pformatetcIn, pmedium); if ( FAILED(hr) ) { // free resources we allocated - if ( pmedium->tymed == TYMED_HGLOBAL ) { + if ( pmedium->tymed & (TYMED_HGLOBAL | TYMED_MFPICT) ) { GlobalFree(pmedium->hGlobal); } @@ -375,11 +364,6 @@ STDMETHODIMP wxIDataObject::GetDataHere(FORMATETC *pformatetc, break; case TYMED_MFPICT: - // this should be copied on bitmaps - but I don't have time for - // this now - wxFAIL_MSG(wxT("TODO - no support for metafiles in wxDataObject")); - break; - case TYMED_HGLOBAL: { // copy data @@ -426,13 +410,21 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, break; case TYMED_MFPICT: - // this should be copied on bitmaps - but I don't have time for - // this now - wxFAIL_MSG(wxT("TODO - no support for metafiles in wxDataObject")); - break; - case TYMED_HGLOBAL: { + wxDataFormat format = pformatetc->cfFormat; + + // this is quite weird, but for file drag and drop, explorer + // calls our SetData() with the formats we do *not* support! + // + // as we can't fix this bug in explorer (it's a bug because it + // should only use formats returned by EnumFormatEtc), do the + // check here + if ( !m_pDataObject->IsSupportedFormat(format) ) { + // go away! + return DV_E_FORMATETC; + } + // copy data void *pBuf = GlobalLock(pmedium->hGlobal); if ( pBuf == NULL ) { @@ -447,7 +439,7 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, // synthetise it for known formats and we suppose that all data // in custom formats starts with a DWORD containing the size size_t size; - switch ( pformatetc->cfFormat ) + switch ( format ) { case CF_TEXT: case CF_OEMTEXT: @@ -471,6 +463,10 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, size = 0; break; + case CF_METAFILEPICT: + size = sizeof(METAFILEPICT); + break; + default: { // we suppose that the size precedes the data @@ -480,7 +476,6 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, } } - wxDataFormat format = pformatetc->cfFormat; bool ok = m_pDataObject->SetData(format, size, pBuf); GlobalUnlock(pmedium->hGlobal); @@ -496,11 +491,17 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, } if ( fRelease ) { - // we own the medium, so we must release it - but do *not* free the - // bitmap handle fi we have it because we have copied it elsewhere - if ( pmedium->tymed == TYMED_GDI ) + // we own the medium, so we must release it - but do *not* free any + // data we pass by handle because we have copied it elsewhere + switch ( pmedium->tymed ) { - pmedium->hBitmap = 0; + case TYMED_GDI: + pmedium->hBitmap = 0; + break; + + case TYMED_MFPICT: + pmedium->hMetaFilePict = 0; + break; } ReleaseStgMedium(pmedium); @@ -724,12 +725,12 @@ size_t wxBitmapDataObject::GetDataSize() const bool wxBitmapDataObject::GetDataHere(void *buf) const { - return wxConvertBitmapToDIB((BITMAPINFO *)buf, GetBitmap()) != 0; + return wxConvertBitmapToDIB((LPBITMAPINFO)buf, GetBitmap()) != 0; } bool wxBitmapDataObject::SetData(size_t len, const void *buf) { - wxBitmap bitmap(wxConvertDIBToBitmap((const BITMAPINFO *)buf)); + wxBitmap bitmap(wxConvertDIBToBitmap((const LPBITMAPINFO)buf)); if ( !bitmap.Ok() ) { wxFAIL_MSG(wxT("pasting/dropping invalid bitmap")); @@ -764,7 +765,7 @@ bool wxBitmapDataObject2::GetDataHere(void *pBuf) const return TRUE; } -bool wxBitmapDataObject2::SetData(size_t len, const void *pBuf) +bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf) { HBITMAP hbmp = *(HBITMAP *)pBuf; @@ -928,6 +929,8 @@ bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *pData) // get number of files (magic value -1) UINT nFiles = ::DragQueryFile(hdrop, (unsigned)-1, NULL, 0u); + wxCHECK_MSG ( nFiles != (UINT)-1, FALSE, wxT("wrong HDROP handle") ); + // for each file get the length, allocate memory and then get the name wxString str; UINT len, n; @@ -963,17 +966,19 @@ size_t wxFileDataObject::GetDataSize() const // a double null at the end // if no filenames in list, size is 0 - if (m_filenames.GetCount() == 0) return 0; + if ( m_filenames.GetCount() == 0 ) + return 0; // inital size of DROPFILES struct + null byte size_t sz = sizeof(DROPFILES) + 1; - int i; - for (i=0; ipFiles = sizeof(DROPFILES); - pDrop->fNC = FALSE; + pDrop->fNC = FALSE; // not non-client coords +#if wxUSE_UNICODE + pDrop->fWide = TRUE; +#else // ANSI pDrop->fWide = FALSE; +#endif // Unicode/Ansi // set start of filenames list (null separated) - char *pbuf = (char*)pDrop + sizeof(DROPFILES); + wxChar *pbuf = (wxChar*) ((BYTE *)pDrop + sizeof(DROPFILES)); - size_t i; - for (i=0; i