2006-02-22 19:56:11 +01:00
|
|
|
/*
|
|
|
|
* Richedit clipboard handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Kevin Koltzau
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-02-22 19:56:11 +01:00
|
|
|
*/
|
|
|
|
|
2015-03-18 18:59:06 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2006-02-22 19:56:11 +01:00
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
|
|
|
static UINT cfRTF = 0;
|
|
|
|
|
|
|
|
typedef struct DataObjectImpl {
|
2010-12-09 10:27:26 +01:00
|
|
|
IDataObject IDataObject_iface;
|
2006-02-22 19:56:11 +01:00
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
FORMATETC *fmtetc;
|
|
|
|
UINT fmtetc_cnt;
|
|
|
|
|
|
|
|
HANDLE unicode;
|
|
|
|
HANDLE rtf;
|
|
|
|
} DataObjectImpl;
|
|
|
|
|
|
|
|
typedef struct EnumFormatImpl {
|
2010-12-09 10:27:26 +01:00
|
|
|
IEnumFORMATETC IEnumFORMATETC_iface;
|
2006-02-22 19:56:11 +01:00
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
FORMATETC *fmtetc;
|
|
|
|
UINT fmtetc_cnt;
|
|
|
|
|
|
|
|
UINT cur;
|
|
|
|
} EnumFormatImpl;
|
|
|
|
|
2007-08-11 17:07:50 +02:00
|
|
|
static HRESULT EnumFormatImpl_Create(const FORMATETC *fmtetc, UINT size, LPENUMFORMATETC *lplpformatetc);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
2010-12-09 10:27:26 +01:00
|
|
|
static inline DataObjectImpl *impl_from_IDataObject(IDataObject *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, DataObjectImpl, IDataObject_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline EnumFormatImpl *impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, EnumFormatImpl, IEnumFORMATETC_iface);
|
|
|
|
}
|
|
|
|
|
2006-02-22 19:56:11 +01:00
|
|
|
static HRESULT WINAPI EnumFormatImpl_QueryInterface(IEnumFORMATETC *iface, REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
TRACE("%p %s\n", This, debugstr_guid(riid));
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumFORMATETC)) {
|
|
|
|
IEnumFORMATETC_AddRef(iface);
|
2009-01-30 10:40:02 +01:00
|
|
|
*ppvObj = This;
|
2006-02-22 19:56:11 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI EnumFormatImpl_AddRef(IEnumFORMATETC *iface)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-02-22 19:56:11 +01:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI EnumFormatImpl_Release(IEnumFORMATETC *iface)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(!ref) {
|
2006-10-24 07:24:48 +02:00
|
|
|
GlobalFree(This->fmtetc);
|
2007-12-07 23:42:22 +01:00
|
|
|
heap_free(This);
|
2006-02-22 19:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumFormatImpl_Next(IEnumFORMATETC *iface, ULONG celt,
|
|
|
|
FORMATETC *rgelt, ULONG *pceltFetched)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
ULONG count = 0;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(!rgelt)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
count = min(celt, This->fmtetc_cnt-This->cur);
|
|
|
|
if(count > 0) {
|
|
|
|
memcpy(rgelt, This->fmtetc+This->cur, count*sizeof(FORMATETC));
|
|
|
|
This->cur += count;
|
|
|
|
}
|
|
|
|
if(pceltFetched)
|
|
|
|
*pceltFetched = count;
|
|
|
|
return count == celt ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumFormatImpl_Skip(IEnumFORMATETC *iface, ULONG celt)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
ULONG count = 0;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p)->(%d)\n", This, celt);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
count = min(celt, This->fmtetc_cnt-This->cur);
|
|
|
|
This->cur += count;
|
|
|
|
return count == celt ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumFormatImpl_Reset(IEnumFORMATETC *iface)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
This->cur = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumFormatImpl_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
EnumFormatImpl *This = impl_from_IEnumFORMATETC(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)->(%p)\n", This, ppenum);
|
|
|
|
|
|
|
|
if(!ppenum)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
hr = EnumFormatImpl_Create(This->fmtetc, This->fmtetc_cnt, ppenum);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
hr = IEnumFORMATETC_Skip(*ppenum, This->cur);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumFORMATETCVtbl VT_EnumFormatImpl = {
|
|
|
|
EnumFormatImpl_QueryInterface,
|
|
|
|
EnumFormatImpl_AddRef,
|
|
|
|
EnumFormatImpl_Release,
|
|
|
|
EnumFormatImpl_Next,
|
|
|
|
EnumFormatImpl_Skip,
|
|
|
|
EnumFormatImpl_Reset,
|
|
|
|
EnumFormatImpl_Clone
|
|
|
|
};
|
|
|
|
|
2016-07-12 10:03:57 +02:00
|
|
|
static HRESULT EnumFormatImpl_Create(const FORMATETC *fmtetc, UINT fmtetc_cnt,
|
|
|
|
IEnumFORMATETC **formatetc)
|
2006-02-22 19:56:11 +01:00
|
|
|
{
|
|
|
|
EnumFormatImpl *ret;
|
|
|
|
TRACE("\n");
|
|
|
|
|
2007-12-07 23:42:22 +01:00
|
|
|
ret = heap_alloc(sizeof(EnumFormatImpl));
|
2010-12-09 10:27:26 +01:00
|
|
|
ret->IEnumFORMATETC_iface.lpVtbl = &VT_EnumFormatImpl;
|
2006-02-22 19:56:11 +01:00
|
|
|
ret->ref = 1;
|
|
|
|
ret->cur = 0;
|
|
|
|
ret->fmtetc_cnt = fmtetc_cnt;
|
2006-10-24 07:24:48 +02:00
|
|
|
ret->fmtetc = GlobalAlloc(GMEM_ZEROINIT, fmtetc_cnt*sizeof(FORMATETC));
|
2006-02-22 19:56:11 +01:00
|
|
|
memcpy(ret->fmtetc, fmtetc, fmtetc_cnt*sizeof(FORMATETC));
|
2016-07-12 10:03:57 +02:00
|
|
|
*formatetc = &ret->IEnumFORMATETC_iface;
|
2006-02-22 19:56:11 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_QueryInterface(IDataObject *iface, REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDataObject)) {
|
|
|
|
IDataObject_AddRef(iface);
|
2009-01-30 10:40:02 +01:00
|
|
|
*ppvObj = This;
|
2006-02-22 19:56:11 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DataObjectImpl_AddRef(IDataObject* iface)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-02-22 19:56:11 +01:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DataObjectImpl_Release(IDataObject* iface)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p) ref=%d\n",This, ref);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(!ref) {
|
|
|
|
if(This->unicode) GlobalFree(This->unicode);
|
|
|
|
if(This->rtf) GlobalFree(This->rtf);
|
|
|
|
if(This->fmtetc) GlobalFree(This->fmtetc);
|
2007-12-07 23:42:22 +01:00
|
|
|
heap_free(This);
|
2006-02-22 19:56:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_GetData(IDataObject* iface, FORMATETC *pformatetc, STGMEDIUM *pmedium)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p)->(fmt=0x%08x tym=0x%08x)\n", This, pformatetc->cfFormat, pformatetc->tymed);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(pformatetc->lindex != -1)
|
|
|
|
return DV_E_LINDEX;
|
|
|
|
|
|
|
|
if(!(pformatetc->tymed & TYMED_HGLOBAL))
|
|
|
|
return DV_E_TYMED;
|
|
|
|
|
|
|
|
if(This->unicode && pformatetc->cfFormat == CF_UNICODETEXT)
|
|
|
|
pmedium->u.hGlobal = This->unicode;
|
|
|
|
else if(This->rtf && pformatetc->cfFormat == cfRTF)
|
|
|
|
pmedium->u.hGlobal = This->rtf;
|
|
|
|
else
|
|
|
|
return DV_E_FORMATETC;
|
|
|
|
|
|
|
|
pmedium->tymed = TYMED_HGLOBAL;
|
|
|
|
pmedium->pUnkForRelease = (LPUNKNOWN)iface;
|
|
|
|
IUnknown_AddRef(pmedium->pUnkForRelease);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_GetDataHere(IDataObject* iface, FORMATETC *pformatetc, STGMEDIUM *pmedium)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_QueryGetData(IDataObject* iface, FORMATETC *pformatetc)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
UINT i;
|
|
|
|
BOOL foundFormat = FALSE;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p)->(fmt=0x%08x tym=0x%08x)\n", This, pformatetc->cfFormat, pformatetc->tymed);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(pformatetc->lindex != -1)
|
|
|
|
return DV_E_LINDEX;
|
|
|
|
|
|
|
|
for(i=0; i<This->fmtetc_cnt; i++) {
|
|
|
|
if(This->fmtetc[i].cfFormat == pformatetc->cfFormat) {
|
|
|
|
foundFormat = TRUE;
|
|
|
|
if(This->fmtetc[i].tymed == pformatetc->tymed)
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundFormat?DV_E_FORMATETC:DV_E_TYMED;
|
|
|
|
}
|
|
|
|
|
2008-03-13 21:52:32 +01:00
|
|
|
static HRESULT WINAPI DataObjectImpl_GetCanonicalFormatEtc(IDataObject* iface, FORMATETC *pformatetcIn,
|
2006-02-22 19:56:11 +01:00
|
|
|
FORMATETC *pformatetcOut)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2008-03-13 21:52:32 +01:00
|
|
|
TRACE("(%p)->(%p,%p)\n", This, pformatetcIn, pformatetcOut);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(pformatetcOut) {
|
2008-03-13 21:52:32 +01:00
|
|
|
*pformatetcOut = *pformatetcIn;
|
2006-02-22 19:56:11 +01:00
|
|
|
pformatetcOut->ptd = NULL;
|
|
|
|
}
|
|
|
|
return DATA_S_SAMEFORMATETC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_SetData(IDataObject* iface, FORMATETC *pformatetc,
|
|
|
|
STGMEDIUM *pmedium, BOOL fRelease)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_EnumFormatEtc(IDataObject* iface, DWORD dwDirection,
|
|
|
|
IEnumFORMATETC **ppenumFormatEtc)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("(%p)->(%d)\n", This, dwDirection);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
|
|
|
if(dwDirection != DATADIR_GET) {
|
2006-10-13 21:25:54 +02:00
|
|
|
FIXME("Unsupported direction: %d\n", dwDirection);
|
2006-02-22 19:56:11 +01:00
|
|
|
/* WinXP riched20 also returns E_NOTIMPL in this case */
|
2009-06-02 07:57:37 +02:00
|
|
|
*ppenumFormatEtc = NULL;
|
2006-02-22 19:56:11 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return EnumFormatImpl_Create(This->fmtetc, This->fmtetc_cnt, ppenumFormatEtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_DAdvise(IDataObject* iface, FORMATETC *pformatetc, DWORD advf,
|
|
|
|
IAdviseSink *pAdvSink, DWORD *pdwConnection)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_DUnadvise(IDataObject* iface, DWORD dwConnection)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataObjectImpl_EnumDAdvise(IDataObject* iface, IEnumSTATDATA **ppenumAdvise)
|
|
|
|
{
|
2010-12-09 10:27:26 +01:00
|
|
|
DataObjectImpl *This = impl_from_IDataObject(iface);
|
2006-02-22 19:56:11 +01:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDataObjectVtbl VT_DataObjectImpl =
|
|
|
|
{
|
|
|
|
DataObjectImpl_QueryInterface,
|
|
|
|
DataObjectImpl_AddRef,
|
|
|
|
DataObjectImpl_Release,
|
|
|
|
DataObjectImpl_GetData,
|
|
|
|
DataObjectImpl_GetDataHere,
|
|
|
|
DataObjectImpl_QueryGetData,
|
|
|
|
DataObjectImpl_GetCanonicalFormatEtc,
|
|
|
|
DataObjectImpl_SetData,
|
|
|
|
DataObjectImpl_EnumFormatEtc,
|
|
|
|
DataObjectImpl_DAdvise,
|
|
|
|
DataObjectImpl_DUnadvise,
|
|
|
|
DataObjectImpl_EnumDAdvise
|
|
|
|
};
|
|
|
|
|
2009-08-13 14:44:05 +02:00
|
|
|
static HGLOBAL get_unicode_text(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
|
2006-02-22 19:56:11 +01:00
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
int pars = 0;
|
2006-02-22 19:56:11 +01:00
|
|
|
WCHAR *data;
|
|
|
|
HANDLE ret;
|
2009-08-12 15:05:51 +02:00
|
|
|
ME_DisplayItem *para;
|
2009-08-13 14:44:05 +02:00
|
|
|
int nEnd = ME_GetCursorOfs(start) + nChars;
|
2009-08-12 15:05:51 +02:00
|
|
|
|
|
|
|
/* count paragraphs in range */
|
2009-08-13 14:44:05 +02:00
|
|
|
para = start->pPara;
|
2009-08-12 15:05:51 +02:00
|
|
|
while((para = para->member.para.next_para) &&
|
2009-08-13 14:44:05 +02:00
|
|
|
para->member.para.nCharOfs <= nEnd)
|
2009-08-12 15:05:51 +02:00
|
|
|
pars++;
|
2006-02-22 19:56:11 +01:00
|
|
|
|
2009-08-13 14:44:05 +02:00
|
|
|
ret = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * (nChars + pars + 1));
|
2008-11-03 22:36:03 +01:00
|
|
|
data = GlobalLock(ret);
|
2014-07-21 18:41:29 +02:00
|
|
|
ME_GetTextW(editor, data, nChars + pars, start, nChars, TRUE, FALSE);
|
2006-02-22 19:56:11 +01:00
|
|
|
GlobalUnlock(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct tagME_GlobalDestStruct
|
|
|
|
{
|
|
|
|
HGLOBAL hData;
|
|
|
|
int nLength;
|
|
|
|
} ME_GlobalDestStruct;
|
|
|
|
|
|
|
|
static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
|
|
|
|
{
|
|
|
|
ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
|
|
|
|
int nMaxSize;
|
|
|
|
BYTE *pDest;
|
|
|
|
|
|
|
|
nMaxSize = GlobalSize(pData->hData);
|
|
|
|
if (pData->nLength+cb+1 >= cb) {
|
|
|
|
/* round up to 2^17 */
|
|
|
|
int nNewSize = (((nMaxSize+cb+1)|0x1FFFF)+1) & 0xFFFE0000;
|
|
|
|
pData->hData = GlobalReAlloc(pData->hData, nNewSize, 0);
|
|
|
|
}
|
2008-11-03 22:36:03 +01:00
|
|
|
pDest = GlobalLock(pData->hData);
|
2006-02-22 19:56:11 +01:00
|
|
|
memcpy(pDest + pData->nLength, lpBuff, cb);
|
|
|
|
pData->nLength += cb;
|
|
|
|
pDest[pData->nLength] = '\0';
|
|
|
|
GlobalUnlock(pData->hData);
|
|
|
|
*pcb = cb;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:22 +02:00
|
|
|
static HGLOBAL get_rtf_text(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
|
2006-02-22 19:56:11 +01:00
|
|
|
{
|
|
|
|
EDITSTREAM es;
|
|
|
|
ME_GlobalDestStruct gds;
|
|
|
|
|
|
|
|
gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
|
|
|
|
gds.nLength = 0;
|
|
|
|
es.dwCookie = (DWORD_PTR)&gds;
|
|
|
|
es.pfnCallback = ME_AppendToHGLOBAL;
|
2009-08-13 14:44:22 +02:00
|
|
|
ME_StreamOutRange(editor, SF_RTF, start, nChars, &es);
|
2006-02-22 19:56:11 +01:00
|
|
|
GlobalReAlloc(gds.hData, gds.nLength+1, 0);
|
|
|
|
return gds.hData;
|
|
|
|
}
|
|
|
|
|
2016-07-12 10:03:57 +02:00
|
|
|
HRESULT ME_GetDataObject(ME_TextEditor *editor, const ME_Cursor *start, int nChars,
|
|
|
|
IDataObject **dataobj)
|
2006-02-22 19:56:11 +01:00
|
|
|
{
|
|
|
|
DataObjectImpl *obj;
|
2009-08-13 14:44:05 +02:00
|
|
|
TRACE("(%p,%d,%d)\n", editor, ME_GetCursorOfs(start), nChars);
|
2006-02-22 19:56:11 +01:00
|
|
|
|
2007-12-07 23:42:22 +01:00
|
|
|
obj = heap_alloc(sizeof(DataObjectImpl));
|
2006-02-22 19:56:11 +01:00
|
|
|
if(cfRTF == 0)
|
|
|
|
cfRTF = RegisterClipboardFormatA("Rich Text Format");
|
|
|
|
|
2010-12-09 10:27:26 +01:00
|
|
|
obj->IDataObject_iface.lpVtbl = &VT_DataObjectImpl;
|
2006-02-22 19:56:11 +01:00
|
|
|
obj->ref = 1;
|
2009-08-13 14:44:05 +02:00
|
|
|
obj->unicode = get_unicode_text(editor, start, nChars);
|
2006-02-22 19:56:11 +01:00
|
|
|
obj->rtf = NULL;
|
|
|
|
|
|
|
|
obj->fmtetc_cnt = 1;
|
2006-02-23 05:04:56 +01:00
|
|
|
if(editor->mode & TM_RICHTEXT)
|
|
|
|
obj->fmtetc_cnt++;
|
2006-10-24 07:24:48 +02:00
|
|
|
obj->fmtetc = GlobalAlloc(GMEM_ZEROINIT, obj->fmtetc_cnt*sizeof(FORMATETC));
|
2006-02-22 19:56:11 +01:00
|
|
|
InitFormatEtc(obj->fmtetc[0], CF_UNICODETEXT, TYMED_HGLOBAL);
|
|
|
|
if(editor->mode & TM_RICHTEXT) {
|
2009-08-13 14:44:22 +02:00
|
|
|
obj->rtf = get_rtf_text(editor, start, nChars);
|
2006-02-22 19:56:11 +01:00
|
|
|
InitFormatEtc(obj->fmtetc[1], cfRTF, TYMED_HGLOBAL);
|
|
|
|
}
|
|
|
|
|
2016-07-12 10:03:57 +02:00
|
|
|
*dataobj = &obj->IDataObject_iface;
|
2006-02-22 19:56:11 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|