X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/51edda6af0e2005c1cc581331863984f0ef48b5d..2a31049201e9c1ff9f515eb9d144ae392f4b4e5a:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 21eae48819..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,11 +410,6 @@ 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; @@ -484,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 @@ -508,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); @@ -736,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")); @@ -776,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; @@ -1065,7 +1054,7 @@ static size_t wxGetNumOfBitmapColors(size_t bitsPerPixel) } } -size_t wxConvertBitmapToDIB(BITMAPINFO *pbi, const wxBitmap& bitmap) +size_t wxConvertBitmapToDIB(LPBITMAPINFO pbi, const wxBitmap& bitmap) { wxASSERT_MSG( bitmap.Ok(), wxT("invalid bmp can't be converted to DIB") ); @@ -1139,7 +1128,7 @@ size_t wxConvertBitmapToDIB(BITMAPINFO *pbi, const wxBitmap& bitmap) return dwLen + bi.biSizeImage; } -wxBitmap wxConvertDIBToBitmap(const BITMAPINFO *pbmi) +wxBitmap wxConvertDIBToBitmap(const LPBITMAPINFO pbmi) { // here we get BITMAPINFO struct followed by the actual bitmap bits and // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info