X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/17b74d79adcc7bbd5cff4ed500e267289c0083a7..926076161327c12d8535c72235f91cee6d316281:/src/msw/ole/dataobj.cpp diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index d32806d9a0..1699f9dce6 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -28,12 +28,12 @@ #pragma hdrstop #endif -#include +#include "wx/defs.h" #if defined(__WIN32__) && !defined(__GNUWIN32__) -#include -#include +#include "wx/log.h" +#include "wx/dataobj.h" #include #include @@ -43,7 +43,7 @@ #include #endif -#include +#include "wx/msw/ole/oleutils.h" // ---------------------------------------------------------------------------- // functions @@ -101,6 +101,39 @@ private: // 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 // ---------------------------------------------------------------------------- @@ -127,7 +160,7 @@ STDMETHODIMP wxIEnumFORMATETC::Next(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched) { - wxLogTrace("wxIEnumFORMATETC::Next"); + wxLogTrace(_T("wxIEnumFORMATETC::Next")); if ( celt > 1 ) return S_FALSE; @@ -144,7 +177,7 @@ STDMETHODIMP wxIEnumFORMATETC::Next(ULONG celt, STDMETHODIMP wxIEnumFORMATETC::Skip(ULONG celt) { - wxLogTrace("wxIEnumFORMATETC::Skip"); + wxLogTrace(_T("wxIEnumFORMATETC::Skip")); if ( m_nCurrent == 0 ) m_nCurrent++; @@ -154,7 +187,7 @@ STDMETHODIMP wxIEnumFORMATETC::Skip(ULONG celt) STDMETHODIMP wxIEnumFORMATETC::Reset() { - wxLogTrace("wxIEnumFORMATETC::Reset"); + wxLogTrace(_T("wxIEnumFORMATETC::Reset")); m_nCurrent = 0; @@ -163,7 +196,7 @@ STDMETHODIMP wxIEnumFORMATETC::Reset() STDMETHODIMP wxIEnumFORMATETC::Clone(IEnumFORMATETC **ppenum) { - wxLogTrace("wxIEnumFORMATETC::Clone"); + wxLogTrace(_T("wxIEnumFORMATETC::Clone")); wxIEnumFORMATETC *pNew = new wxIEnumFORMATETC(m_format.cfFormat); pNew->AddRef(); @@ -192,7 +225,7 @@ wxIDataObject::wxIDataObject(wxDataObject *pDataObject) // 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); @@ -224,7 +257,7 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium) 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 ) @@ -233,7 +266,7 @@ STDMETHODIMP wxIDataObject::GetDataHere(FORMATETC *pformatetc, // copy data void *pBuf = GlobalLock(pmedium->hGlobal); if ( pBuf == NULL ) { - wxLogLastError("GlobalLock"); + wxLogLastError(_T("GlobalLock")); return E_OUTOFMEMORY; } @@ -249,7 +282,7 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease) { - wxLogTrace("wxIDataObject::SetData"); + wxLogTrace(_T("wxIDataObject::SetData")); return E_NOTIMPL; } @@ -258,40 +291,40 @@ STDMETHODIMP wxIDataObject::QueryGetData(FORMATETC *pformatetc) { // 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((wxDataFormat) pformatetc->cfFormat) ) { - wxLogTrace("wxIDataObject::QueryGetData: %s ok", - wxDataObject::GetFormatName((wxDataFormat) 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((wxDataFormat) pformatetc->cfFormat)); + wxLogTrace(_T("wxIDataObject::QueryGetData: %s unsupported"), + wxDataObject::GetFormatName((wxDataFormatId)pformatetc->cfFormat)); return DV_E_FORMATETC; } } @@ -299,7 +332,7 @@ STDMETHODIMP wxIDataObject::QueryGetData(FORMATETC *pformatetc) 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 ) @@ -310,7 +343,7 @@ STDMETHODIMP wxIDataObject::GetCanonicalFormatEtc(FORMATETC *pFormatetcIn, 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 @@ -399,6 +432,47 @@ const char *wxDataObject::GetFormatName(wxDataFormat format) #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() ); +} + // ---------------------------------------------------------------------------- // private functions // ----------------------------------------------------------------------------