// ----------------------------------------------------------------------------
#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 <windows.h>
+#include "wx/msw/private.h" // includes <windows.h>
+
#ifdef wxUSE_NORLANDER_HEADERS
#include <ole2.h>
#endif
#include <shlobj.h>
-#include "wx/msw/ole/oleutils.h"
+#include "wx/msw/ole/oleutils.h"
+
+#include "wx/msw/dib.h"
// ----------------------------------------------------------------------------
// functions
#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
// ----------------------------------------------------------------------------
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
// ============================================================================
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;
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);
}
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
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 ) {
// 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:
size = 0;
break;
+ case CF_METAFILEPICT:
+ size = sizeof(METAFILEPICT);
+ break;
+
default:
{
// we suppose that the size precedes the data
}
}
- wxDataFormat format = pformatetc->cfFormat;
bool ok = m_pDataObject->SetData(format, size, pBuf);
GlobalUnlock(pmedium->hGlobal);
}
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);
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"));
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;
// 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;
#endif // Unicode/Ansi
// set start of filenames list (null separated)
- wxChar *pbuf = (BYTE *)pDrop + sizeof(DROPFILES);
+ wxChar *pbuf = (wxChar*) ((BYTE *)pDrop + sizeof(DROPFILES));
size_t count = m_filenames.GetCount();
for (size_t i = 0; i < count; i++ )
}
}
-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") );
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