// ----------------------------------------------------------------------------
#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 <olestd.h>
#endif
-#include "wx/msw/ole/oleutils.h"
+#include <shlobj.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;
return TRUE;
}
+void wxFileDataObject::AddFile(const wxString& file)
+{
+ // just add file to filenames array
+ // all useful data (such as DROPFILES struct) will be
+ // created later as necessary
+ m_filenames.Add(file);
+}
+
+size_t wxFileDataObject::GetDataSize() const
+{
+ // size returned will be the size of the DROPFILES structure,
+ // plus the list of filesnames (null byte separated), plus
+ // a double null at the end
+
+ // if no filenames in list, size is 0
+ if ( m_filenames.GetCount() == 0 )
+ return 0;
+
+ // inital size of DROPFILES struct + null byte
+ size_t sz = sizeof(DROPFILES) + 1;
+
+ size_t count = m_filenames.GetCount();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ // add filename length plus null byte
+ sz += m_filenames[i].Len() + 1;
+ }
+
+ return sz;
+}
+
+bool wxFileDataObject::GetDataHere(void *pData) const
+{
+ // pData points to an externally allocated memory block
+ // created using the size returned by GetDataSize()
+
+ // if pData is NULL, or there are no files, return
+ if ( !pData || m_filenames.GetCount() == 0 )
+ return FALSE;
+
+ // convert data pointer to a DROPFILES struct pointer
+ LPDROPFILES pDrop = (LPDROPFILES) pData;
+
+ // initialize DROPFILES struct
+ pDrop->pFiles = sizeof(DROPFILES);
+ 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)
+ wxChar *pbuf = (wxChar*) ((BYTE *)pDrop + sizeof(DROPFILES));
+
+ size_t count = m_filenames.GetCount();
+ for (size_t i = 0; i < count; i++ )
+ {
+ // copy filename to pbuf and add null terminator
+ size_t len = m_filenames[i].Len();
+ memcpy(pbuf, m_filenames[i], len);
+ pbuf += len;
+ *pbuf++ = wxT('\0');
+ }
+
+ *pbuf = wxT('\0'); // add final null terminator
+
+ return TRUE;
+}
+
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
}
}
-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