// Name: msw/ole/dataobj.cpp
// Purpose: implementation of wx[I]DataObject class
// Author: Vadim Zeitlin
-// Modified by:
+// Modified by:
// Created: 10.05.98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
#pragma hdrstop
#endif
-#include <wx/defs.h>
+#include "wx/defs.h"
#if defined(__WIN32__) && !defined(__GNUWIN32__)
-#include <wx/log.h>
-#include <wx/msw/ole/oleutils.h>
-#include <wx/msw/ole/dataobj.h>
+#include "wx/log.h"
+#include "wx/dataobj.h"
+
+#include <windows.h>
+#include <oleauto.h>
#ifndef __WIN32__
#include <ole2.h>
#include <olestd.h>
#endif
+#include "wx/msw/ole/oleutils.h"
+
// ----------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------
// implementation
// ============================================================================
+// ----------------------------------------------------------------------------
+// wxDataFormat
+// ----------------------------------------------------------------------------
+
+void wxDataFormat::SetId(const wxChar *format)
+{
+ m_format = ::RegisterClipboardFormat(format);
+ if ( !m_format )
+ {
+ wxLogError(_("Couldn't register clipboard format '%s'."), format);
+ }
+}
+
+wxString wxDataFormat::GetId() const
+{
+ static const int max = 256;
+
+ wxString s;
+
+ wxCHECK_MSG( !IsStandard(), s,
+ _T("name of predefined format cannot be retrieved") );
+
+ int len = ::GetClipboardFormatName(m_format, s.GetWriteBuf(max), max);
+ s.UngetWriteBuf();
+
+ if ( !len )
+ {
+ wxLogError(_("The clipboard format '%d' doesn't exist."), m_format);
+ }
+
+ return s;
+}
+
// ----------------------------------------------------------------------------
// wxIEnumFORMATETC
// ----------------------------------------------------------------------------
FORMATETC *rgelt,
ULONG *pceltFetched)
{
- wxLogTrace("wxIEnumFORMATETC::Next");
+ wxLogTrace(_T("wxIEnumFORMATETC::Next"));
if ( celt > 1 )
return S_FALSE;
STDMETHODIMP wxIEnumFORMATETC::Skip(ULONG celt)
{
- wxLogTrace("wxIEnumFORMATETC::Skip");
+ wxLogTrace(_T("wxIEnumFORMATETC::Skip"));
if ( m_nCurrent == 0 )
m_nCurrent++;
STDMETHODIMP wxIEnumFORMATETC::Reset()
{
- wxLogTrace("wxIEnumFORMATETC::Reset");
+ wxLogTrace(_T("wxIEnumFORMATETC::Reset"));
m_nCurrent = 0;
STDMETHODIMP wxIEnumFORMATETC::Clone(IEnumFORMATETC **ppenum)
{
- wxLogTrace("wxIEnumFORMATETC::Clone");
+ wxLogTrace(_T("wxIEnumFORMATETC::Clone"));
wxIEnumFORMATETC *pNew = new wxIEnumFORMATETC(m_format.cfFormat);
pNew->AddRef();
// get data functions
STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
{
- wxLogTrace("wxIDataObject::GetData");
+ wxLogTrace(_T("wxIDataObject::GetData"));
// is data is in our format?
HRESULT hr = QueryGetData(pformatetcIn);
STDMETHODIMP wxIDataObject::GetDataHere(FORMATETC *pformatetc,
STGMEDIUM *pmedium)
{
- wxLogTrace("wxIDataObject::GetDataHere");
+ wxLogTrace(_T("wxIDataObject::GetDataHere"));
// put data in caller provided medium
if ( pmedium->tymed != TYMED_HGLOBAL )
// copy data
void *pBuf = GlobalLock(pmedium->hGlobal);
if ( pBuf == NULL ) {
- wxLogLastError("GlobalLock");
+ wxLogLastError(_T("GlobalLock"));
return E_OUTOFMEMORY;
}
STGMEDIUM *pmedium,
BOOL fRelease)
{
- wxLogTrace("wxIDataObject::SetData");
+ wxLogTrace(_T("wxIDataObject::SetData"));
return E_NOTIMPL;
}
{
// do we accept data in this format?
if ( pformatetc == NULL ) {
- wxLogTrace("wxIDataObject::QueryGetData: invalid ptr.");
+ wxLogTrace(_T("wxIDataObject::QueryGetData: invalid ptr."));
return E_INVALIDARG;
}
// the only one allowed by current COM implementation
if ( pformatetc->lindex != -1 ) {
- wxLogTrace("wxIDataObject::QueryGetData: bad lindex %d",
+ wxLogTrace(_T("wxIDataObject::QueryGetData: bad lindex %d"),
pformatetc->lindex);
return DV_E_LINDEX;
}
// we don't support anything other (THUMBNAIL, ICON, DOCPRINT...)
if ( pformatetc->dwAspect != DVASPECT_CONTENT ) {
- wxLogTrace("wxIDataObject::QueryGetData: bad dwAspect %d",
+ wxLogTrace(_T("wxIDataObject::QueryGetData: bad dwAspect %d"),
pformatetc->dwAspect);
return DV_E_DVASPECT;
}
// @@ we only transfer data by global memory (bad for large amounts of it!)
if ( !(pformatetc->tymed & TYMED_HGLOBAL) ) {
- wxLogTrace("wxIDataObject::QueryGetData: %s != TYMED_HGLOBAL.",
+ wxLogTrace(_T("wxIDataObject::QueryGetData: %s != TYMED_HGLOBAL."),
GetTymedName(pformatetc->tymed));
return DV_E_TYMED;
}
// and now check the type of data requested
- if ( m_pDataObject->IsSupportedFormat(pformatetc->cfFormat) ) {
- wxLogTrace("wxIDataObject::QueryGetData: %s ok",
- wxDataObject::GetFormatName(pformatetc->cfFormat));
+ if ( m_pDataObject->IsSupportedFormat((wxDataFormatId)pformatetc->cfFormat) ) {
+ wxLogTrace(_T("wxIDataObject::QueryGetData: %s ok"),
+ wxDataObject::GetFormatName((wxDataFormatId)pformatetc->cfFormat));
return S_OK;
}
else {
- wxLogTrace("wxIDataObject::QueryGetData: %s unsupported",
- wxDataObject::GetFormatName(pformatetc->cfFormat));
+ wxLogTrace(_T("wxIDataObject::QueryGetData: %s unsupported"),
+ wxDataObject::GetFormatName((wxDataFormatId)pformatetc->cfFormat));
return DV_E_FORMATETC;
}
}
STDMETHODIMP wxIDataObject::GetCanonicalFormatEtc(FORMATETC *pFormatetcIn,
FORMATETC *pFormatetcOut)
{
- wxLogTrace("wxIDataObject::GetCanonicalFormatEtc");
+ wxLogTrace(_T("wxIDataObject::GetCanonicalFormatEtc"));
// @@ implementation is trivial, we might want something better here
if ( pFormatetcOut != NULL )
STDMETHODIMP wxIDataObject::EnumFormatEtc(DWORD dwDirection,
IEnumFORMATETC **ppenumFormatEtc)
{
- wxLogTrace("wxIDataObject::EnumFormatEtc");
+ wxLogTrace(_T("wxIDataObject::EnumFormatEtc"));
if ( dwDirection == DATADIR_SET ) {
// we don't allow setting of data anyhow
return E_NOTIMPL;
}
- wxIEnumFORMATETC *pEnum =
+ wxIEnumFORMATETC *pEnum =
new wxIEnumFORMATETC(m_pDataObject->GetPreferredFormat());
pEnum->AddRef();
*ppenumFormatEtc = pEnum;
const char *wxDataObject::GetFormatName(wxDataFormat format)
{
#ifdef __WXDEBUG__
+ // case 'xxx' is not a valid value for switch of enum 'wxDataFormat'
+ #ifdef __VISUALC__
+ #pragma warning(disable:4063)
+ #endif // VC++
+
static char s_szBuf[128];
switch ( format ) {
case CF_TEXT: return "CF_TEXT";
sprintf(s_szBuf, "clipboard format %d (unknown)", format);
return s_szBuf;
}
- #else
+
+ #ifdef __VISUALC__
+ #pragma warning(default:4063)
+ #endif // VC++
+
+#else // !Debug
return "";
-#endif
+#endif // Debug
+}
+
+// ----------------------------------------------------------------------------
+// wxPrivateDataObject
+// ----------------------------------------------------------------------------
+
+wxPrivateDataObject::wxPrivateDataObject()
+{
+ m_size = 0;
+ m_data = NULL;
+}
+
+void wxPrivateDataObject::Free()
+{
+ if ( m_data )
+ free(m_data);
+}
+
+void wxPrivateDataObject::SetData( const void *data, size_t size )
+{
+ Free();
+
+ m_size = size;
+ m_data = malloc(size);
+
+ memcpy( m_data, data, size );
+}
+
+void wxPrivateDataObject::WriteData( void *dest ) const
+{
+ WriteData( m_data, dest );
+}
+
+size_t wxPrivateDataObject::GetSize() const
+{
+ return m_size;
+}
+
+void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
+{
+ memcpy( dest, data, GetSize() );
}
// ----------------------------------------------------------------------------
}
}
+// TODO: OLE parts of wxBitmap/File/MetafileDataObject
+
#endif