1999-07-18 17:43:45 +02:00
|
|
|
/*
|
|
|
|
* OLE 2 clipboard support
|
|
|
|
*
|
|
|
|
* Copyright 1999 Noel Borthwick <noel@macadamian.com>
|
2000-03-08 19:49:36 +01:00
|
|
|
* Copyright 2000 Abey George <abey@macadamian.com>
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* 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
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
1999-07-18 17:43:45 +02:00
|
|
|
* NOTES:
|
|
|
|
* This file contains the implementation for the OLE Clipboard and its
|
|
|
|
* internal interfaces. The OLE clipboard interacts with an IDataObject
|
|
|
|
* interface via the OleSetClipboard, OleGetClipboard and
|
|
|
|
* OleIsCurrentClipboard API's. An internal IDataObject delegates
|
|
|
|
* to a client supplied IDataObject or the WIN32 clipboard API depending
|
|
|
|
* on whether OleSetClipboard has been invoked.
|
|
|
|
* Here are some operating scenarios:
|
|
|
|
*
|
|
|
|
* 1. OleSetClipboard called: In this case the internal IDataObject
|
|
|
|
* delegates to the client supplied IDataObject. Additionally OLE takes
|
|
|
|
* ownership of the Windows clipboard and any HGLOCBAL IDataObject
|
|
|
|
* items are placed on the Windows clipboard. This allows non OLE aware
|
|
|
|
* applications to access these. A local WinProc fields WM_RENDERFORMAT
|
|
|
|
* and WM_RENDERALLFORMATS messages in this case.
|
|
|
|
*
|
|
|
|
* 2. OleGetClipboard called without previous OleSetClipboard. Here the internal
|
|
|
|
* IDataObject functionality wraps around the WIN32 clipboard API.
|
|
|
|
*
|
|
|
|
* 3. OleGetClipboard called after previous OleSetClipboard. Here the internal
|
|
|
|
* IDataObject delegates to the source IDataObjects functionality directly,
|
|
|
|
* thereby bypassing the Windows clipboard.
|
|
|
|
*
|
|
|
|
* Implementation references : Inside OLE 2'nd edition by Kraig Brockschmidt
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - Support for pasting between different processes. OLE clipboard support
|
|
|
|
* currently works only for in process copy and paste. Since we internally
|
|
|
|
* store a pointer to the source's IDataObject and delegate to that, this
|
|
|
|
* will fail if the IDataObject client belongs to a different process.
|
|
|
|
* - IDataObject::GetDataHere is not implemented
|
|
|
|
* - OleFlushClipboard needs to additionally handle TYMED_IStorage media
|
|
|
|
* by copying the storage into global memory. Subsequently the default
|
|
|
|
* data object exposed through OleGetClipboard must convert this TYMED_HGLOBAL
|
|
|
|
* back to TYMED_IStorage.
|
|
|
|
* - OLE1 compatibility formats to be synthesized from OLE2 formats and put on
|
|
|
|
* clipboard in OleSetClipboard.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2009-04-16 13:05:11 +02:00
|
|
|
#include <stdio.h>
|
2000-03-24 22:19:02 +01:00
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
2000-12-19 05:53:20 +01:00
|
|
|
#include "winbase.h"
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "wingdi.h"
|
1999-07-18 17:43:45 +02:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
2000-11-30 02:31:28 +01:00
|
|
|
#include "winnls.h"
|
1999-07-18 17:43:45 +02:00
|
|
|
#include "ole2.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-03-08 19:49:36 +01:00
|
|
|
#include "olestd.h"
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2000-03-24 22:19:02 +01:00
|
|
|
#include "storage32.h"
|
|
|
|
|
2008-12-18 21:20:35 +01:00
|
|
|
#include "compobj_private.h"
|
|
|
|
|
2009-01-08 14:15:32 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
2009-04-16 12:49:11 +02:00
|
|
|
/* Structure of 'Ole Private Data' clipboard format */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FORMATETC fmtetc;
|
|
|
|
DWORD first_use; /* Has this cf been added to the list already */
|
|
|
|
DWORD unk[2];
|
|
|
|
} ole_priv_data_entry;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD unk1;
|
|
|
|
DWORD size; /* in bytes of the entire structure */
|
|
|
|
DWORD unk2;
|
|
|
|
DWORD count; /* no. of format entries */
|
|
|
|
DWORD unk3[2];
|
|
|
|
ole_priv_data_entry entries[1]; /* array of size count */
|
|
|
|
/* then follows any DVTARGETDEVICE structures referenced in the FORMATETCs */
|
|
|
|
} ole_priv_data;
|
|
|
|
|
2009-04-16 16:27:24 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* td_offs_to_ptr
|
|
|
|
*
|
|
|
|
* Returns a ptr to a target device at a given offset from the
|
|
|
|
* start of the ole_priv_data.
|
|
|
|
*
|
|
|
|
* Used when unpacking ole private data from the clipboard.
|
|
|
|
*/
|
|
|
|
static inline DVTARGETDEVICE *td_offs_to_ptr(ole_priv_data *data, DWORD_PTR off)
|
|
|
|
{
|
|
|
|
if(off == 0) return NULL;
|
|
|
|
return (DVTARGETDEVICE*)((char*)data + off);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* td_get_offs
|
|
|
|
*
|
|
|
|
* Get the offset from the start of the ole_priv_data of the idx'th
|
|
|
|
* target device.
|
|
|
|
*
|
|
|
|
* Used when packing ole private data to the clipboard.
|
|
|
|
*/
|
|
|
|
static inline DWORD_PTR td_get_offs(ole_priv_data *data, DWORD idx)
|
|
|
|
{
|
|
|
|
if(data->entries[idx].fmtetc.ptd == NULL) return 0;
|
|
|
|
return (char*)data->entries[idx].fmtetc.ptd - (char*)data;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Consumer snapshot. Represents the state of the ole clipboard
|
|
|
|
* returned by OleGetClipboard().
|
|
|
|
*/
|
|
|
|
typedef struct snapshot
|
|
|
|
{
|
2010-12-16 01:04:21 +01:00
|
|
|
IDataObject IDataObject_iface;
|
2009-04-16 13:14:49 +02:00
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
DWORD seq_no; /* Clipboard sequence number corresponding to this snapshot */
|
2009-04-16 13:17:00 +02:00
|
|
|
|
|
|
|
IDataObject *data; /* If we unmarshal a remote data object we hold a ref here */
|
2009-04-16 13:14:49 +02:00
|
|
|
} snapshot;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2009-03-17 13:44:20 +01:00
|
|
|
* ole_clipbrd
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 12:49:11 +02:00
|
|
|
typedef struct ole_clipbrd
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
snapshot *latest_snapshot; /* Latest consumer snapshot */
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:09:04 +02:00
|
|
|
HWND window; /* Hidden clipboard window */
|
2009-04-16 13:09:56 +02:00
|
|
|
IDataObject *src_data; /* Source object passed to OleSetClipboard */
|
2009-04-16 12:49:11 +02:00
|
|
|
ole_priv_data *cached_enum; /* Cached result from the enumeration of src data object */
|
2009-04-16 13:12:03 +02:00
|
|
|
IStream *marshal_data; /* Stream onto which to marshal src_data */
|
2009-04-16 12:49:11 +02:00
|
|
|
} ole_clipbrd;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
static inline snapshot *impl_from_IDataObject(IDataObject *iface)
|
2009-03-17 13:44:20 +01:00
|
|
|
{
|
2010-12-16 01:04:21 +01:00
|
|
|
return CONTAINING_RECORD(iface, snapshot, IDataObject_iface);
|
2009-03-17 13:44:20 +01:00
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2000-03-08 19:49:36 +01:00
|
|
|
typedef struct PresentationDataHeader
|
|
|
|
{
|
|
|
|
BYTE unknown1[28];
|
|
|
|
DWORD dwObjectExtentX;
|
|
|
|
DWORD dwObjectExtentY;
|
|
|
|
DWORD dwSize;
|
|
|
|
} PresentationDataHeader;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
|
|
|
/*
|
2009-03-17 13:44:20 +01:00
|
|
|
* The one and only ole_clipbrd object which is created by OLEClipbrd_Initialize()
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 13:44:20 +01:00
|
|
|
static ole_clipbrd* theOleClipboard;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:07:47 +02:00
|
|
|
static inline HRESULT get_ole_clipbrd(ole_clipbrd **clipbrd)
|
|
|
|
{
|
|
|
|
struct oletls *info = COM_CurrentInfo();
|
|
|
|
*clipbrd = NULL;
|
|
|
|
|
|
|
|
if(!info->ole_inits)
|
|
|
|
return CO_E_NOTINITIALIZED;
|
|
|
|
*clipbrd = theOleClipboard;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Name of our registered OLE clipboard window class
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:06:48 +02:00
|
|
|
static const WCHAR clipbrd_wndclass[] = {'C','L','I','P','B','R','D','W','N','D','C','L','A','S','S',0};
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-23 16:04:56 +02:00
|
|
|
UINT ownerlink_clipboard_format = 0;
|
|
|
|
UINT filename_clipboard_format = 0;
|
|
|
|
UINT filenameW_clipboard_format = 0;
|
|
|
|
UINT dataobject_clipboard_format = 0;
|
|
|
|
UINT embedded_object_clipboard_format = 0;
|
|
|
|
UINT embed_source_clipboard_format = 0;
|
|
|
|
UINT custom_link_source_clipboard_format = 0;
|
|
|
|
UINT link_source_clipboard_format = 0;
|
|
|
|
UINT object_descriptor_clipboard_format = 0;
|
|
|
|
UINT link_source_descriptor_clipboard_format = 0;
|
|
|
|
UINT ole_private_data_clipboard_format = 0;
|
2009-03-17 16:34:31 +01:00
|
|
|
|
2009-04-24 13:02:48 +02:00
|
|
|
static UINT wine_marshal_clipboard_format;
|
|
|
|
|
2014-11-14 01:13:40 +01:00
|
|
|
static inline const char *dump_fmtetc(FORMATETC *fmt)
|
2009-04-16 13:05:11 +02:00
|
|
|
{
|
2014-11-14 01:13:40 +01:00
|
|
|
if (!fmt) return "(null)";
|
|
|
|
return wine_dbg_sprintf("cf %04x ptd %p aspect %x lindex %d tymed %x",
|
|
|
|
fmt->cfFormat, fmt->ptd, fmt->dwAspect, fmt->lindex, fmt->tymed);
|
2009-04-16 13:05:11 +02:00
|
|
|
}
|
|
|
|
|
1999-07-18 17:43:45 +02:00
|
|
|
/*---------------------------------------------------------------------*
|
2009-03-17 15:17:49 +01:00
|
|
|
* Implementation of the internal IEnumFORMATETC interface returned by
|
|
|
|
* the OLE clipboard's IDataObject.
|
1999-07-18 17:43:45 +02:00
|
|
|
*---------------------------------------------------------------------*/
|
|
|
|
|
2009-03-26 16:42:13 +01:00
|
|
|
typedef struct enum_fmtetc
|
|
|
|
{
|
2010-12-16 01:04:21 +01:00
|
|
|
IEnumFORMATETC IEnumFORMATETC_iface;
|
2009-03-26 16:42:13 +01:00
|
|
|
LONG ref;
|
|
|
|
|
2009-03-26 17:20:18 +01:00
|
|
|
UINT pos; /* current enumerator position */
|
2009-03-30 13:00:44 +02:00
|
|
|
ole_priv_data *data;
|
2009-03-26 16:42:13 +01:00
|
|
|
} enum_fmtetc;
|
|
|
|
|
|
|
|
static inline enum_fmtetc *impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
|
|
|
|
{
|
2010-12-16 01:04:21 +01:00
|
|
|
return CONTAINING_RECORD(iface, enum_fmtetc, IEnumFORMATETC_iface);
|
2009-03-26 16:42:13 +01:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_QueryInterface (IUnknown)
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-03-17 15:17:49 +01:00
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_QueryInterface
|
|
|
|
(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-26 16:42:13 +01:00
|
|
|
TRACE("(%p)->(IID: %s, %p)\n", This, debugstr_guid(riid), ppvObj);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
*ppvObj = NULL;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:27:18 +01:00
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IEnumFORMATETC))
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
*ppvObj = iface;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
if(*ppvObj)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-17 15:17:49 +01:00
|
|
|
IEnumFORMATETC_AddRef((IEnumFORMATETC*)*ppvObj);
|
|
|
|
TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
|
|
|
|
return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
TRACE("-- Interface: E_NOINTERFACE\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface)
|
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
2009-03-17 15:17:49 +01:00
|
|
|
TRACE("(%p)->(count=%u)\n",This, This->ref);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface)
|
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
2009-03-17 15:17:49 +01:00
|
|
|
ULONG ref;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
TRACE("(%p)->(count=%u)\n",This, This->ref);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
TRACE("() - destroying IEnumFORMATETC(%p)\n",This);
|
2009-03-30 13:00:44 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2009-03-17 15:17:49 +01:00
|
|
|
}
|
|
|
|
return ref;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_Next (IEnumFORMATETC)
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-03-17 15:17:49 +01:00
|
|
|
* Standard enumerator members for IEnumFORMATETC
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Next
|
|
|
|
(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
2009-03-30 13:00:44 +02:00
|
|
|
UINT cfetch, i;
|
2009-03-17 15:17:49 +01:00
|
|
|
HRESULT hres = S_FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-26 17:20:18 +01:00
|
|
|
TRACE("(%p)->(pos=%u)\n", This, This->pos);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
if (This->pos < This->data->count)
|
2009-03-17 15:17:49 +01:00
|
|
|
{
|
2009-03-30 13:00:44 +02:00
|
|
|
cfetch = This->data->count - This->pos;
|
2009-03-17 15:17:49 +01:00
|
|
|
if (cfetch >= celt)
|
|
|
|
{
|
|
|
|
cfetch = celt;
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
for(i = 0; i < cfetch; i++)
|
|
|
|
{
|
|
|
|
rgelt[i] = This->data->entries[This->pos++].fmtetc;
|
|
|
|
if(rgelt[i].ptd)
|
|
|
|
{
|
2009-04-16 16:27:24 +02:00
|
|
|
DVTARGETDEVICE *target = rgelt[i].ptd;
|
2009-03-30 13:00:44 +02:00
|
|
|
rgelt[i].ptd = CoTaskMemAlloc(target->tdSize);
|
|
|
|
if(!rgelt[i].ptd) return E_OUTOFMEMORY;
|
|
|
|
memcpy(rgelt[i].ptd, target, target->tdSize);
|
|
|
|
}
|
|
|
|
}
|
2009-03-17 15:17:49 +01:00
|
|
|
}
|
|
|
|
else
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-17 15:17:49 +01:00
|
|
|
cfetch = 0;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
if (pceltFethed)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-17 15:17:49 +01:00
|
|
|
*pceltFethed = cfetch;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
return hres;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_Skip (IEnumFORMATETC)
|
|
|
|
*
|
|
|
|
* Standard enumerator members for IEnumFORMATETC
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Skip(LPENUMFORMATETC iface, ULONG celt)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
2009-03-17 15:17:49 +01:00
|
|
|
TRACE("(%p)->(num=%u)\n", This, celt);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-26 17:20:18 +01:00
|
|
|
This->pos += celt;
|
2009-03-30 13:00:44 +02:00
|
|
|
if (This->pos > This->data->count)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-30 13:00:44 +02:00
|
|
|
This->pos = This->data->count;
|
2009-03-17 15:17:49 +01:00
|
|
|
return S_FALSE;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
2009-03-17 15:17:49 +01:00
|
|
|
return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_Reset (IEnumFORMATETC)
|
|
|
|
*
|
|
|
|
* Standard enumerator members for IEnumFORMATETC
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Reset(LPENUMFORMATETC iface)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
2009-03-17 15:17:49 +01:00
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
2009-03-26 17:20:18 +01:00
|
|
|
This->pos = 0;
|
2009-03-17 15:17:49 +01:00
|
|
|
return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
static HRESULT enum_fmtetc_construct(ole_priv_data *data, UINT pos, IEnumFORMATETC **obj);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
|
|
|
* OLEClipbrd_IEnumFORMATETC_Clone (IEnumFORMATETC)
|
|
|
|
*
|
|
|
|
* Standard enumerator members for IEnumFORMATETC
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Clone
|
2009-03-30 13:00:44 +02:00
|
|
|
(LPENUMFORMATETC iface, LPENUMFORMATETC* obj)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc *This = impl_from_IEnumFORMATETC(iface);
|
2009-03-30 13:00:44 +02:00
|
|
|
ole_priv_data *new_data;
|
2009-04-16 16:27:24 +02:00
|
|
|
DWORD i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, obj);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
if ( !obj ) return E_INVALIDARG;
|
|
|
|
*obj = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
new_data = HeapAlloc(GetProcessHeap(), 0, This->data->size);
|
|
|
|
if(!new_data) return E_OUTOFMEMORY;
|
2009-04-16 16:27:24 +02:00
|
|
|
memcpy(new_data, This->data, This->data->size);
|
|
|
|
|
|
|
|
/* Fixup any target device ptrs */
|
|
|
|
for(i = 0; i < This->data->count; i++)
|
|
|
|
new_data->entries[i].fmtetc.ptd =
|
|
|
|
td_offs_to_ptr(new_data, td_get_offs(This->data, i));
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
return enum_fmtetc_construct(new_data, This->pos, obj);
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
static const IEnumFORMATETCVtbl efvt =
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-17 15:17:49 +01:00
|
|
|
OLEClipbrd_IEnumFORMATETC_QueryInterface,
|
|
|
|
OLEClipbrd_IEnumFORMATETC_AddRef,
|
|
|
|
OLEClipbrd_IEnumFORMATETC_Release,
|
|
|
|
OLEClipbrd_IEnumFORMATETC_Next,
|
|
|
|
OLEClipbrd_IEnumFORMATETC_Skip,
|
|
|
|
OLEClipbrd_IEnumFORMATETC_Reset,
|
|
|
|
OLEClipbrd_IEnumFORMATETC_Clone
|
|
|
|
};
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/************************************************************************
|
2009-03-26 17:38:57 +01:00
|
|
|
* enum_fmtetc_construct
|
2009-03-17 15:17:49 +01:00
|
|
|
*
|
2009-03-30 13:00:44 +02:00
|
|
|
* Creates an IEnumFORMATETC enumerator from ole_priv_data which it then owns.
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-30 13:00:44 +02:00
|
|
|
static HRESULT enum_fmtetc_construct(ole_priv_data *data, UINT pos, IEnumFORMATETC **obj)
|
2009-03-17 15:17:49 +01:00
|
|
|
{
|
2009-03-26 16:42:13 +01:00
|
|
|
enum_fmtetc* ef;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-26 17:38:57 +01:00
|
|
|
*obj = NULL;
|
2009-03-26 16:42:13 +01:00
|
|
|
ef = HeapAlloc(GetProcessHeap(), 0, sizeof(*ef));
|
2009-03-26 17:38:57 +01:00
|
|
|
if (!ef) return E_OUTOFMEMORY;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-26 17:41:59 +01:00
|
|
|
ef->ref = 1;
|
2010-12-16 01:04:21 +01:00
|
|
|
ef->IEnumFORMATETC_iface.lpVtbl = &efvt;
|
2009-03-30 13:00:44 +02:00
|
|
|
ef->data = data;
|
|
|
|
ef->pos = pos;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
TRACE("(%p)->()\n", ef);
|
2010-12-16 01:04:21 +01:00
|
|
|
*obj = &ef->IEnumFORMATETC_iface;
|
2009-03-26 17:38:57 +01:00
|
|
|
return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-04-01 15:03:27 +02:00
|
|
|
* dup_global_mem
|
|
|
|
*
|
2009-03-17 15:17:49 +01:00
|
|
|
* Helper method to duplicate an HGLOBAL chunk of memory
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:06:29 +02:00
|
|
|
static HRESULT dup_global_mem( HGLOBAL src, DWORD flags, HGLOBAL *dst )
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-01 15:03:27 +02:00
|
|
|
void *src_ptr, *dst_ptr;
|
|
|
|
DWORD size;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-01 15:03:27 +02:00
|
|
|
*dst = NULL;
|
|
|
|
if ( !src ) return S_FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-01 15:03:27 +02:00
|
|
|
size = GlobalSize(src);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:06:29 +02:00
|
|
|
*dst = GlobalAlloc( flags, size );
|
2009-04-01 15:03:27 +02:00
|
|
|
if ( !*dst ) return E_OUTOFMEMORY;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-01 15:03:27 +02:00
|
|
|
src_ptr = GlobalLock(src);
|
|
|
|
dst_ptr = GlobalLock(*dst);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-01 15:03:27 +02:00
|
|
|
memcpy(dst_ptr, src_ptr, size);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-01 15:03:27 +02:00
|
|
|
GlobalUnlock(*dst);
|
|
|
|
GlobalUnlock(src);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-01 15:03:27 +02:00
|
|
|
return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2011-01-25 16:09:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* dup_metafilepict
|
|
|
|
*
|
|
|
|
* Helper function to duplicate a handle to a METAFILEPICT, and the
|
|
|
|
* contained HMETAFILE.
|
|
|
|
*/
|
|
|
|
static HRESULT dup_metafilepict(HGLOBAL src, HGLOBAL *pdest)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HGLOBAL dest;
|
|
|
|
METAFILEPICT *dest_ptr;
|
|
|
|
|
|
|
|
*pdest = NULL;
|
|
|
|
|
|
|
|
/* Copy the METAFILEPICT structure. */
|
|
|
|
hr = dup_global_mem(src, GMEM_DDESHARE|GMEM_MOVEABLE, &dest);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
dest_ptr = GlobalLock(dest);
|
|
|
|
if (!dest_ptr) return E_FAIL;
|
|
|
|
|
|
|
|
/* Give the new METAFILEPICT a separate HMETAFILE. */
|
|
|
|
dest_ptr->hMF = CopyMetaFileW(dest_ptr->hMF, NULL);
|
|
|
|
if (dest_ptr->hMF)
|
|
|
|
{
|
|
|
|
GlobalUnlock(dest);
|
|
|
|
*pdest = dest;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GlobalUnlock(dest);
|
|
|
|
GlobalFree(dest);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* free_metafilepict
|
|
|
|
*
|
|
|
|
* Helper function to GlobalFree a handle to a METAFILEPICT, and also
|
|
|
|
* free the contained HMETAFILE.
|
|
|
|
*/
|
|
|
|
static void free_metafilepict(HGLOBAL src)
|
|
|
|
{
|
|
|
|
METAFILEPICT *src_ptr;
|
|
|
|
|
|
|
|
src_ptr = GlobalLock(src);
|
|
|
|
if (src_ptr)
|
|
|
|
{
|
|
|
|
DeleteMetaFile(src_ptr->hMF);
|
|
|
|
GlobalUnlock(src);
|
|
|
|
}
|
|
|
|
GlobalFree(src);
|
|
|
|
}
|
|
|
|
|
2011-01-25 04:12:20 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* dup_bitmap
|
|
|
|
*
|
|
|
|
* Helper function to duplicate an HBITMAP.
|
|
|
|
*/
|
|
|
|
static HRESULT dup_bitmap(HBITMAP src, HBITMAP *pdest)
|
|
|
|
{
|
|
|
|
HDC src_dc;
|
|
|
|
HGDIOBJ orig_src_bitmap;
|
|
|
|
BITMAP bm;
|
|
|
|
HBITMAP dest;
|
|
|
|
|
|
|
|
src_dc = CreateCompatibleDC(NULL);
|
|
|
|
orig_src_bitmap = SelectObject(src_dc, src);
|
|
|
|
GetObjectW(src, sizeof bm, &bm);
|
|
|
|
dest = CreateCompatibleBitmap(src_dc, bm.bmWidth, bm.bmHeight);
|
|
|
|
if (dest)
|
|
|
|
{
|
|
|
|
HDC dest_dc = CreateCompatibleDC(NULL);
|
|
|
|
HGDIOBJ orig_dest_bitmap = SelectObject(dest_dc, dest);
|
|
|
|
BitBlt(dest_dc, 0, 0, bm.bmWidth, bm.bmHeight, src_dc, 0, 0, SRCCOPY);
|
|
|
|
SelectObject(dest_dc, orig_dest_bitmap);
|
|
|
|
DeleteDC(dest_dc);
|
|
|
|
}
|
|
|
|
SelectObject(src_dc, orig_src_bitmap);
|
|
|
|
DeleteDC(src_dc);
|
|
|
|
*pdest = dest;
|
|
|
|
return dest ? S_OK : E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
/************************************************************
|
|
|
|
* render_embed_source_hack
|
|
|
|
*
|
|
|
|
* This is clearly a hack and has no place in the clipboard code.
|
|
|
|
*
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-31 17:58:57 +02:00
|
|
|
static HRESULT render_embed_source_hack(IDataObject *data, LPFORMATETC fmt)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-03-31 17:58:57 +02:00
|
|
|
STGMEDIUM std;
|
|
|
|
HGLOBAL hStorage = 0;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
ILockBytes *ptrILockBytes;
|
|
|
|
|
2000-03-08 19:49:36 +01:00
|
|
|
memset(&std, 0, sizeof(STGMEDIUM));
|
2009-03-31 17:58:57 +02:00
|
|
|
std.tymed = fmt->tymed = TYMED_ISTORAGE;
|
2000-03-08 19:49:36 +01:00
|
|
|
|
|
|
|
hStorage = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, 0);
|
2009-03-31 17:58:57 +02:00
|
|
|
if (hStorage == NULL) return E_OUTOFMEMORY;
|
2000-03-08 19:49:36 +01:00
|
|
|
hr = CreateILockBytesOnHGlobal(hStorage, FALSE, &ptrILockBytes);
|
2015-03-13 23:15:59 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
GlobalFree(hStorage);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2000-03-08 19:49:36 +01:00
|
|
|
hr = StgCreateDocfileOnILockBytes(ptrILockBytes, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &std.u.pstg);
|
2009-03-31 17:58:57 +02:00
|
|
|
ILockBytes_Release(ptrILockBytes);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
if (FAILED(hr = IDataObject_GetDataHere(theOleClipboard->src_data, fmt, &std)))
|
2000-03-08 19:49:36 +01:00
|
|
|
{
|
2009-03-31 17:58:57 +02:00
|
|
|
WARN("() : IDataObject_GetDataHere failed to render clipboard data! (%x)\n", hr);
|
|
|
|
GlobalFree(hStorage);
|
|
|
|
return hr;
|
2000-03-08 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (1) /* check whether the presentation data is already -not- present */
|
|
|
|
{
|
2009-03-31 17:58:57 +02:00
|
|
|
FORMATETC fmt2;
|
|
|
|
STGMEDIUM std2;
|
|
|
|
METAFILEPICT *mfp = 0;
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
fmt2.cfFormat = CF_METAFILEPICT;
|
|
|
|
fmt2.ptd = 0;
|
|
|
|
fmt2.dwAspect = DVASPECT_CONTENT;
|
|
|
|
fmt2.lindex = -1;
|
|
|
|
fmt2.tymed = TYMED_MFPICT;
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
memset(&std2, 0, sizeof(STGMEDIUM));
|
|
|
|
std2.tymed = TYMED_MFPICT;
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
/* Get the metafile picture out of it */
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
if (SUCCEEDED(hr = IDataObject_GetData(theOleClipboard->src_data, &fmt2, &std2)))
|
2009-03-31 17:58:57 +02:00
|
|
|
{
|
|
|
|
mfp = GlobalLock(std2.u.hGlobal);
|
|
|
|
}
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
if (mfp)
|
2000-03-08 19:49:36 +01:00
|
|
|
{
|
2009-03-31 17:58:57 +02:00
|
|
|
OLECHAR name[]={ 2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0};
|
|
|
|
IStream *pStream = 0;
|
|
|
|
void *mfBits;
|
|
|
|
PresentationDataHeader pdh;
|
|
|
|
INT nSize;
|
|
|
|
CLSID clsID;
|
|
|
|
LPOLESTR strProgID;
|
|
|
|
CHAR strOleTypeName[51];
|
|
|
|
BYTE OlePresStreamHeader [] =
|
|
|
|
{
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00,
|
|
|
|
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
nSize = GetMetaFileBitsEx(mfp->hMF, 0, NULL);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
memset(&pdh, 0, sizeof(PresentationDataHeader));
|
|
|
|
memcpy(&pdh, OlePresStreamHeader, sizeof(OlePresStreamHeader));
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
pdh.dwObjectExtentX = mfp->xExt;
|
|
|
|
pdh.dwObjectExtentY = mfp->yExt;
|
|
|
|
pdh.dwSize = nSize;
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
hr = IStorage_CreateStream(std.u.pstg, name, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0, &pStream);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
hr = IStream_Write(pStream, &pdh, sizeof(PresentationDataHeader), NULL);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
mfBits = HeapAlloc(GetProcessHeap(), 0, nSize);
|
|
|
|
nSize = GetMetaFileBitsEx(mfp->hMF, nSize, mfBits);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
hr = IStream_Write(pStream, mfBits, nSize, NULL);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
IStream_Release(pStream);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mfBits);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
GlobalUnlock(std2.u.hGlobal);
|
|
|
|
ReleaseStgMedium(&std2);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
ReadClassStg(std.u.pstg, &clsID);
|
|
|
|
ProgIDFromCLSID(&clsID, &strProgID);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, strProgID, -1, strOleTypeName, sizeof(strOleTypeName), NULL, NULL );
|
2012-07-17 08:31:08 +02:00
|
|
|
STORAGE_CreateOleStream(std.u.pstg, 0);
|
2009-03-31 17:58:57 +02:00
|
|
|
OLECONVERT_CreateCompObjStream(std.u.pstg, strOleTypeName);
|
2012-10-28 16:16:45 +01:00
|
|
|
CoTaskMemFree(strProgID);
|
2009-03-31 17:58:57 +02:00
|
|
|
}
|
2000-03-08 19:49:36 +01:00
|
|
|
}
|
2009-03-31 17:58:57 +02:00
|
|
|
|
|
|
|
if ( !SetClipboardData( fmt->cfFormat, hStorage ) )
|
|
|
|
{
|
|
|
|
WARN("() : Failed to set rendered clipboard data into clipboard!\n");
|
|
|
|
GlobalFree(hStorage);
|
|
|
|
hr = CLIPBRD_E_CANT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseStgMedium(&std);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-04-16 12:51:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
* find_format_in_list
|
|
|
|
*
|
|
|
|
* Returns the first entry that matches the provided clipboard format.
|
|
|
|
*/
|
|
|
|
static inline ole_priv_data_entry *find_format_in_list(ole_priv_data_entry *entries, DWORD num, UINT cf)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
for(i = 0; i < num; i++)
|
|
|
|
if(entries[i].fmtetc.cfFormat == cf)
|
|
|
|
return &entries[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:05:26 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* get_data_from_storage
|
|
|
|
*
|
|
|
|
* Returns storage data in an HGLOBAL.
|
|
|
|
*/
|
|
|
|
static HRESULT get_data_from_storage(IDataObject *data, FORMATETC *fmt, HGLOBAL *mem)
|
|
|
|
{
|
|
|
|
HGLOBAL h;
|
|
|
|
IStorage *stg;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC stg_fmt;
|
|
|
|
STGMEDIUM med;
|
|
|
|
ILockBytes *lbs;
|
|
|
|
|
|
|
|
*mem = NULL;
|
|
|
|
|
|
|
|
h = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE, 0 );
|
|
|
|
if(!h) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = CreateILockBytesOnHGlobal(h, FALSE, &lbs);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = StgCreateDocfileOnILockBytes(lbs, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stg);
|
|
|
|
ILockBytes_Release(lbs);
|
|
|
|
}
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
GlobalFree(h);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
stg_fmt = *fmt;
|
|
|
|
med.tymed = stg_fmt.tymed = TYMED_ISTORAGE;
|
|
|
|
med.u.pstg = stg;
|
|
|
|
med.pUnkForRelease = NULL;
|
|
|
|
|
|
|
|
hr = IDataObject_GetDataHere(data, &stg_fmt, &med);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
med.u.pstg = NULL;
|
|
|
|
hr = IDataObject_GetData(data, &stg_fmt, &med);
|
|
|
|
if(FAILED(hr)) goto end;
|
|
|
|
|
|
|
|
hr = IStorage_CopyTo(med.u.pstg, 0, NULL, NULL, stg);
|
|
|
|
ReleaseStgMedium(&med);
|
|
|
|
if(FAILED(hr)) goto end;
|
|
|
|
}
|
|
|
|
*mem = h;
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStorage_Release(stg);
|
|
|
|
if(FAILED(hr)) GlobalFree(h);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:04:56 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* get_data_from_stream
|
|
|
|
*
|
|
|
|
* Returns stream data in an HGLOBAL.
|
|
|
|
*/
|
|
|
|
static HRESULT get_data_from_stream(IDataObject *data, FORMATETC *fmt, HGLOBAL *mem)
|
|
|
|
{
|
|
|
|
HGLOBAL h;
|
|
|
|
IStream *stm = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC stm_fmt;
|
|
|
|
STGMEDIUM med;
|
|
|
|
|
|
|
|
*mem = NULL;
|
|
|
|
|
|
|
|
h = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE, 0 );
|
|
|
|
if(!h) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(h, FALSE, &stm);
|
|
|
|
if(FAILED(hr)) goto error;
|
|
|
|
|
|
|
|
stm_fmt = *fmt;
|
|
|
|
med.tymed = stm_fmt.tymed = TYMED_ISTREAM;
|
|
|
|
med.u.pstm = stm;
|
|
|
|
med.pUnkForRelease = NULL;
|
|
|
|
|
|
|
|
hr = IDataObject_GetDataHere(data, &stm_fmt, &med);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
LARGE_INTEGER offs;
|
|
|
|
ULARGE_INTEGER pos;
|
|
|
|
|
|
|
|
med.u.pstm = NULL;
|
|
|
|
hr = IDataObject_GetData(data, &stm_fmt, &med);
|
|
|
|
if(FAILED(hr)) goto error;
|
|
|
|
|
|
|
|
offs.QuadPart = 0;
|
|
|
|
IStream_Seek(med.u.pstm, offs, STREAM_SEEK_CUR, &pos);
|
|
|
|
IStream_Seek(med.u.pstm, offs, STREAM_SEEK_SET, NULL);
|
|
|
|
hr = IStream_CopyTo(med.u.pstm, stm, pos, NULL, NULL);
|
|
|
|
ReleaseStgMedium(&med);
|
|
|
|
if(FAILED(hr)) goto error;
|
|
|
|
}
|
|
|
|
*mem = h;
|
|
|
|
IStream_Release(stm);
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if(stm) IStream_Release(stm);
|
|
|
|
GlobalFree(h);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* get_data_from_global
|
|
|
|
*
|
|
|
|
* Returns global data in an HGLOBAL.
|
|
|
|
*/
|
|
|
|
static HRESULT get_data_from_global(IDataObject *data, FORMATETC *fmt, HGLOBAL *mem)
|
|
|
|
{
|
|
|
|
HGLOBAL h;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC mem_fmt;
|
|
|
|
STGMEDIUM med;
|
|
|
|
|
|
|
|
*mem = NULL;
|
|
|
|
|
|
|
|
mem_fmt = *fmt;
|
|
|
|
mem_fmt.tymed = TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
hr = IDataObject_GetData(data, &mem_fmt, &med);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
2009-04-16 13:06:29 +02:00
|
|
|
hr = dup_global_mem(med.u.hGlobal, GMEM_DDESHARE|GMEM_MOVEABLE, &h);
|
2009-04-16 13:04:56 +02:00
|
|
|
|
|
|
|
if(SUCCEEDED(hr)) *mem = h;
|
|
|
|
|
|
|
|
ReleaseStgMedium(&med);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:09:21 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_data_from_enhmetafile
|
|
|
|
*/
|
2009-06-19 21:26:48 +02:00
|
|
|
static HRESULT get_data_from_enhmetafile(IDataObject *data, FORMATETC *fmt, HGLOBAL *mem)
|
|
|
|
{
|
|
|
|
HENHMETAFILE copy;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC mem_fmt;
|
|
|
|
STGMEDIUM med;
|
|
|
|
|
|
|
|
*mem = NULL;
|
|
|
|
|
|
|
|
mem_fmt = *fmt;
|
|
|
|
mem_fmt.tymed = TYMED_ENHMF;
|
|
|
|
|
|
|
|
hr = IDataObject_GetData(data, &mem_fmt, &med);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
copy = CopyEnhMetaFileW(med.u.hEnhMetaFile, NULL);
|
|
|
|
if(copy) *mem = (HGLOBAL)copy;
|
|
|
|
else hr = E_FAIL;
|
|
|
|
|
|
|
|
ReleaseStgMedium(&med);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:09:21 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_data_from_metafilepict
|
|
|
|
*/
|
|
|
|
static HRESULT get_data_from_metafilepict(IDataObject *data, FORMATETC *fmt, HGLOBAL *mem)
|
|
|
|
{
|
|
|
|
HGLOBAL copy;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC mem_fmt;
|
|
|
|
STGMEDIUM med;
|
|
|
|
|
|
|
|
*mem = NULL;
|
|
|
|
|
|
|
|
mem_fmt = *fmt;
|
|
|
|
mem_fmt.tymed = TYMED_MFPICT;
|
|
|
|
|
|
|
|
hr = IDataObject_GetData(data, &mem_fmt, &med);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = dup_metafilepict(med.u.hMetaFilePict, ©);
|
|
|
|
|
2011-01-28 20:49:50 +01:00
|
|
|
if(SUCCEEDED(hr)) *mem = copy;
|
2011-01-25 16:09:21 +01:00
|
|
|
|
|
|
|
ReleaseStgMedium(&med);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-01-25 04:12:20 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_data_from_bitmap
|
|
|
|
*
|
|
|
|
* Returns bitmap in an HBITMAP.
|
|
|
|
*/
|
|
|
|
static HRESULT get_data_from_bitmap(IDataObject *data, FORMATETC *fmt, HBITMAP *hbm)
|
|
|
|
{
|
|
|
|
HBITMAP copy;
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC mem_fmt;
|
|
|
|
STGMEDIUM med;
|
|
|
|
|
|
|
|
*hbm = NULL;
|
|
|
|
|
|
|
|
mem_fmt = *fmt;
|
|
|
|
mem_fmt.tymed = TYMED_GDI;
|
|
|
|
|
|
|
|
hr = IDataObject_GetData(data, &mem_fmt, &med);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = dup_bitmap(med.u.hBitmap, ©);
|
|
|
|
|
2011-01-28 20:49:50 +01:00
|
|
|
if(SUCCEEDED(hr)) *hbm = copy;
|
2011-01-25 04:12:20 +01:00
|
|
|
|
|
|
|
ReleaseStgMedium(&med);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
/***********************************************************************
|
2009-03-31 18:02:32 +02:00
|
|
|
* render_format
|
|
|
|
*
|
2009-03-31 17:58:57 +02:00
|
|
|
* Render the clipboard data. Note that this call will delegate to the
|
|
|
|
* source data object.
|
|
|
|
*/
|
2009-03-31 18:02:32 +02:00
|
|
|
static HRESULT render_format(IDataObject *data, LPFORMATETC fmt)
|
2009-03-31 17:58:57 +02:00
|
|
|
{
|
2011-01-25 04:12:20 +01:00
|
|
|
HANDLE clip_data = NULL; /* HGLOBAL unless otherwise specified */
|
2009-03-31 17:58:57 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* Embed source hack */
|
2009-03-31 18:02:32 +02:00
|
|
|
if(fmt->cfFormat == embed_source_clipboard_format)
|
2009-03-31 17:58:57 +02:00
|
|
|
{
|
2009-03-31 18:02:32 +02:00
|
|
|
return render_embed_source_hack(data, fmt);
|
2009-03-31 17:58:57 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 13:05:26 +02:00
|
|
|
if(fmt->tymed & TYMED_ISTORAGE)
|
|
|
|
{
|
|
|
|
hr = get_data_from_storage(data, fmt, &clip_data);
|
|
|
|
}
|
|
|
|
else if(fmt->tymed & TYMED_ISTREAM)
|
2005-03-14 11:46:50 +01:00
|
|
|
{
|
2009-04-16 13:04:56 +02:00
|
|
|
hr = get_data_from_stream(data, fmt, &clip_data);
|
2005-03-14 11:46:50 +01:00
|
|
|
}
|
2009-04-16 13:04:56 +02:00
|
|
|
else if(fmt->tymed & TYMED_HGLOBAL)
|
|
|
|
{
|
|
|
|
hr = get_data_from_global(data, fmt, &clip_data);
|
|
|
|
}
|
2009-06-19 21:26:48 +02:00
|
|
|
else if(fmt->tymed & TYMED_ENHMF)
|
|
|
|
{
|
|
|
|
hr = get_data_from_enhmetafile(data, fmt, &clip_data);
|
|
|
|
}
|
2011-01-25 16:09:21 +01:00
|
|
|
else if(fmt->tymed & TYMED_MFPICT)
|
|
|
|
{
|
|
|
|
/* Returns global handle to METAFILEPICT, containing a copied HMETAFILE */
|
|
|
|
hr = get_data_from_metafilepict(data, fmt, &clip_data);
|
|
|
|
}
|
2011-01-25 04:12:20 +01:00
|
|
|
else if(fmt->tymed & TYMED_GDI)
|
|
|
|
{
|
|
|
|
/* Returns HBITMAP not HGLOBAL */
|
|
|
|
hr = get_data_from_bitmap(data, fmt, (HBITMAP *)&clip_data);
|
|
|
|
}
|
2009-04-16 13:04:56 +02:00
|
|
|
else
|
2009-03-31 17:58:57 +02:00
|
|
|
{
|
2009-04-16 13:04:56 +02:00
|
|
|
FIXME("Unhandled tymed %x\n", fmt->tymed);
|
2009-03-31 17:58:57 +02:00
|
|
|
hr = DV_E_FORMATETC;
|
|
|
|
}
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2009-04-16 13:04:56 +02:00
|
|
|
if(SUCCEEDED(hr))
|
2009-03-31 17:58:57 +02:00
|
|
|
{
|
2009-04-16 13:04:56 +02:00
|
|
|
if ( !SetClipboardData(fmt->cfFormat, clip_data) )
|
|
|
|
{
|
|
|
|
WARN("() : Failed to set rendered clipboard data into clipboard!\n");
|
2011-01-25 16:09:21 +01:00
|
|
|
if(fmt->tymed & TYMED_MFPICT)
|
|
|
|
free_metafilepict(clip_data);
|
2011-01-25 04:12:20 +01:00
|
|
|
else if(fmt->tymed & TYMED_GDI)
|
|
|
|
DeleteObject(clip_data);
|
2011-01-25 16:09:21 +01:00
|
|
|
else
|
|
|
|
GlobalFree(clip_data);
|
2009-04-16 13:04:56 +02:00
|
|
|
hr = CLIPBRD_E_CANT_SET;
|
|
|
|
}
|
2009-03-31 17:58:57 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-31 17:58:57 +02:00
|
|
|
return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Implementation of the internal IDataObject interface exposed by
|
1999-07-18 17:43:45 +02:00
|
|
|
* the OLE clipboard.
|
|
|
|
*---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_QueryInterface
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_QueryInterface(IDataObject *iface,
|
|
|
|
REFIID riid, void **ppvObject)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
snapshot *This = impl_from_IDataObject(iface);
|
2009-03-17 15:33:33 +01:00
|
|
|
TRACE("(%p)->(IID:%s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-18 17:43:45 +02:00
|
|
|
if ( (This==0) || (ppvObject==0) )
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-18 17:43:45 +02:00
|
|
|
*ppvObject = 0;
|
|
|
|
|
2009-03-17 15:33:33 +01:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IDataObject, riid))
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
2009-03-17 15:33:33 +01:00
|
|
|
else
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2000-01-18 06:09:49 +01:00
|
|
|
WARN( "() : asking for unsupported interface %s\n", debugstr_guid(riid));
|
1999-07-18 17:43:45 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-18 17:43:45 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppvObject);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_AddRef
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static ULONG WINAPI snapshot_AddRef(IDataObject *iface)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
snapshot *This = impl_from_IDataObject(iface);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p)->(count=%u)\n", This, This->ref);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_Release
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static ULONG WINAPI snapshot_Release(IDataObject *iface)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
snapshot *This = impl_from_IDataObject(iface);
|
|
|
|
ULONG ref;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p)->(count=%u)\n", This, This->ref);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
ole_clipbrd *clipbrd;
|
|
|
|
HRESULT hr = get_ole_clipbrd(&clipbrd);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:17:00 +02:00
|
|
|
if(This->data) IDataObject_Release(This->data);
|
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if(SUCCEEDED(hr) && clipbrd->latest_snapshot == This)
|
|
|
|
clipbrd->latest_snapshot = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 13:13:39 +02:00
|
|
|
/************************************************************
|
|
|
|
* get_current_ole_clip_window
|
|
|
|
*
|
|
|
|
* Return the window that owns the ole clipboard.
|
|
|
|
*
|
|
|
|
* If the clipboard is flushed or not owned by ole this will
|
|
|
|
* return NULL.
|
|
|
|
*/
|
|
|
|
static HWND get_current_ole_clip_window(void)
|
|
|
|
{
|
|
|
|
HGLOBAL h;
|
|
|
|
HWND *ptr, wnd;
|
|
|
|
|
|
|
|
h = GetClipboardData(dataobject_clipboard_format);
|
|
|
|
if(!h) return NULL;
|
|
|
|
ptr = GlobalLock(h);
|
|
|
|
if(!ptr) return NULL;
|
|
|
|
wnd = *ptr;
|
|
|
|
GlobalUnlock(h);
|
|
|
|
return wnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* get_current_dataobject
|
|
|
|
*
|
|
|
|
* Return an unmarshalled IDataObject if there is a current
|
|
|
|
* (ie non-flushed) object on the ole clipboard.
|
|
|
|
*/
|
|
|
|
static HRESULT get_current_dataobject(IDataObject **data)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
HWND wnd = get_current_ole_clip_window();
|
|
|
|
HGLOBAL h;
|
|
|
|
void *ptr;
|
|
|
|
IStream *stm;
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
|
|
|
|
*data = NULL;
|
|
|
|
if(!wnd) return S_FALSE;
|
|
|
|
|
2009-04-24 13:02:48 +02:00
|
|
|
h = GetClipboardData(wine_marshal_clipboard_format);
|
2009-04-16 13:13:39 +02:00
|
|
|
if(!h) return S_FALSE;
|
2009-04-24 13:02:48 +02:00
|
|
|
if(GlobalSize(h) == 0) return S_FALSE;
|
2009-04-16 13:13:39 +02:00
|
|
|
ptr = GlobalLock(h);
|
|
|
|
if(!ptr) return S_FALSE;
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stm);
|
|
|
|
if(FAILED(hr)) goto end;
|
|
|
|
|
|
|
|
hr = IStream_Write(stm, ptr, GlobalSize(h), NULL);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
IStream_Seek(stm, pos, STREAM_SEEK_SET, NULL);
|
|
|
|
hr = CoUnmarshalInterface(stm, &IID_IDataObject, (void**)data);
|
|
|
|
}
|
|
|
|
IStream_Release(stm);
|
|
|
|
|
|
|
|
end:
|
|
|
|
GlobalUnlock(h);
|
|
|
|
return hr;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-17 16:20:12 +02:00
|
|
|
static DWORD get_tymed_from_nonole_cf(UINT cf)
|
|
|
|
{
|
|
|
|
if(cf >= 0xc000) return TYMED_ISTREAM | TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
switch(cf)
|
|
|
|
{
|
|
|
|
case CF_TEXT:
|
|
|
|
case CF_OEMTEXT:
|
|
|
|
case CF_UNICODETEXT:
|
|
|
|
return TYMED_ISTREAM | TYMED_HGLOBAL;
|
|
|
|
case CF_ENHMETAFILE:
|
|
|
|
return TYMED_ENHMF;
|
|
|
|
case CF_METAFILEPICT:
|
|
|
|
return TYMED_MFPICT;
|
2014-11-13 22:50:42 +01:00
|
|
|
case CF_BITMAP:
|
|
|
|
return TYMED_GDI;
|
2009-04-17 16:20:12 +02:00
|
|
|
default:
|
|
|
|
FIXME("returning TYMED_NULL for cf %04x\n", cf);
|
|
|
|
return TYMED_NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
/***********************************************************
|
|
|
|
* get_priv_data
|
|
|
|
*
|
|
|
|
* Returns a copy of the Ole Private Data
|
|
|
|
*/
|
|
|
|
static HRESULT get_priv_data(ole_priv_data **data)
|
|
|
|
{
|
|
|
|
HGLOBAL handle;
|
|
|
|
HRESULT hr = S_OK;
|
2009-04-17 16:20:12 +02:00
|
|
|
ole_priv_data *ret = NULL;
|
2009-04-16 13:32:58 +02:00
|
|
|
|
|
|
|
*data = NULL;
|
|
|
|
|
2009-04-23 16:04:56 +02:00
|
|
|
handle = GetClipboardData( ole_private_data_clipboard_format );
|
2009-04-16 13:32:58 +02:00
|
|
|
if(handle)
|
|
|
|
{
|
|
|
|
ole_priv_data *src = GlobalLock(handle);
|
|
|
|
if(src)
|
|
|
|
{
|
2009-04-16 16:27:24 +02:00
|
|
|
DWORD i;
|
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
/* FIXME: sanity check on size */
|
2009-04-17 16:20:12 +02:00
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, src->size);
|
|
|
|
if(!ret)
|
2009-04-16 13:32:58 +02:00
|
|
|
{
|
|
|
|
GlobalUnlock(handle);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2009-04-17 16:20:12 +02:00
|
|
|
memcpy(ret, src, src->size);
|
2009-04-16 13:32:58 +02:00
|
|
|
GlobalUnlock(handle);
|
2009-04-16 16:27:24 +02:00
|
|
|
|
|
|
|
/* Fixup any target device offsets to ptrs */
|
2009-04-17 16:20:12 +02:00
|
|
|
for(i = 0; i < ret->count; i++)
|
|
|
|
ret->entries[i].fmtetc.ptd =
|
|
|
|
td_offs_to_ptr(ret, (DWORD_PTR) ret->entries[i].fmtetc.ptd);
|
2009-04-16 13:32:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:20:12 +02:00
|
|
|
if(!ret) /* Non-ole data */
|
|
|
|
{
|
|
|
|
UINT cf;
|
|
|
|
DWORD count = 0, idx, size = FIELD_OFFSET(ole_priv_data, entries);
|
|
|
|
|
|
|
|
for(cf = 0; (cf = EnumClipboardFormats(cf)) != 0; count++)
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
GetClipboardFormatNameA(cf, buf, sizeof(buf));
|
2009-06-09 13:00:30 +02:00
|
|
|
TRACE("cf %04x %s\n", cf, buf);
|
2009-04-17 16:20:12 +02:00
|
|
|
}
|
|
|
|
TRACE("count %d\n", count);
|
|
|
|
size += count * sizeof(ret->entries[0]);
|
|
|
|
|
|
|
|
/* There are holes in fmtetc so zero init */
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
if(!ret) return E_OUTOFMEMORY;
|
|
|
|
ret->size = size;
|
|
|
|
ret->count = count;
|
|
|
|
|
|
|
|
for(cf = 0, idx = 0; (cf = EnumClipboardFormats(cf)) != 0; idx++)
|
|
|
|
{
|
|
|
|
ret->entries[idx].fmtetc.cfFormat = cf;
|
|
|
|
ret->entries[idx].fmtetc.ptd = NULL;
|
|
|
|
ret->entries[idx].fmtetc.dwAspect = DVASPECT_CONTENT;
|
|
|
|
ret->entries[idx].fmtetc.lindex = -1;
|
|
|
|
ret->entries[idx].fmtetc.tymed = get_tymed_from_nonole_cf(cf);
|
|
|
|
ret->entries[idx].first_use = 1;
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 13:32:58 +02:00
|
|
|
|
2009-04-17 16:20:12 +02:00
|
|
|
*data = ret;
|
2009-04-16 13:32:58 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* get_stgmed_for_global
|
|
|
|
*
|
|
|
|
* Returns a stg medium with a copy of the global handle
|
|
|
|
*/
|
|
|
|
static HRESULT get_stgmed_for_global(HGLOBAL h, STGMEDIUM *med)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
med->tymed = TYMED_NULL;
|
|
|
|
|
|
|
|
hr = dup_global_mem(h, GMEM_MOVEABLE, &med->u.hGlobal);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr)) med->tymed = TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:34:07 +02:00
|
|
|
/************************************************************************
|
|
|
|
* get_stgmed_for_stream
|
|
|
|
*
|
|
|
|
* Returns a stg medium with a stream based on the handle
|
|
|
|
*/
|
|
|
|
static HRESULT get_stgmed_for_stream(HGLOBAL h, STGMEDIUM *med)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HGLOBAL dst;
|
|
|
|
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
med->tymed = TYMED_NULL;
|
|
|
|
|
|
|
|
hr = dup_global_mem(h, GMEM_MOVEABLE, &dst);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(dst, TRUE, &med->u.pstm);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
GlobalFree(dst);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
med->tymed = TYMED_ISTREAM;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:34:25 +02:00
|
|
|
/************************************************************************
|
|
|
|
* get_stgmed_for_storage
|
|
|
|
*
|
|
|
|
* Returns a stg medium with a storage based on the handle
|
|
|
|
*/
|
|
|
|
static HRESULT get_stgmed_for_storage(HGLOBAL h, STGMEDIUM *med)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HGLOBAL dst;
|
|
|
|
ILockBytes *lbs;
|
|
|
|
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
med->tymed = TYMED_NULL;
|
|
|
|
|
|
|
|
hr = dup_global_mem(h, GMEM_MOVEABLE, &dst);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = CreateILockBytesOnHGlobal(dst, TRUE, &lbs);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
GlobalFree(dst);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = StgOpenStorageOnILockBytes(lbs, NULL, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, NULL, 0, &med->u.pstg);
|
|
|
|
ILockBytes_Release(lbs);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
GlobalFree(dst);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
med->tymed = TYMED_ISTORAGE;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-06-22 12:58:52 +02:00
|
|
|
/************************************************************************
|
|
|
|
* get_stgmed_for_emf
|
|
|
|
*
|
|
|
|
* Returns a stg medium with an enhanced metafile based on the handle
|
|
|
|
*/
|
|
|
|
static HRESULT get_stgmed_for_emf(HENHMETAFILE hemf, STGMEDIUM *med)
|
|
|
|
{
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
med->tymed = TYMED_NULL;
|
|
|
|
|
|
|
|
med->u.hEnhMetaFile = CopyEnhMetaFileW(hemf, NULL);
|
|
|
|
if(!med->u.hEnhMetaFile) return E_OUTOFMEMORY;
|
|
|
|
med->tymed = TYMED_ENHMF;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-13 22:50:42 +01:00
|
|
|
/************************************************************************
|
|
|
|
* get_stgmed_for_bitmap
|
|
|
|
*
|
|
|
|
* Returns a stg medium with a bitmap based on the handle
|
|
|
|
*/
|
|
|
|
static HRESULT get_stgmed_for_bitmap(HBITMAP hbmp, STGMEDIUM *med)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
med->tymed = TYMED_NULL;
|
|
|
|
|
|
|
|
hr = dup_bitmap(hbmp, &med->u.hBitmap);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
med->tymed = TYMED_GDI;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-16 17:49:35 +02:00
|
|
|
static inline BOOL string_off_equal(const DVTARGETDEVICE *t1, WORD off1, const DVTARGETDEVICE *t2, WORD off2)
|
|
|
|
{
|
|
|
|
const WCHAR *str1, *str2;
|
|
|
|
|
|
|
|
if(off1 == 0 && off2 == 0) return TRUE;
|
|
|
|
if(off1 == 0 || off2 == 0) return FALSE;
|
|
|
|
|
|
|
|
str1 = (const WCHAR*)((const char*)t1 + off1);
|
|
|
|
str2 = (const WCHAR*)((const char*)t2 + off2);
|
|
|
|
|
|
|
|
return !lstrcmpW(str1, str2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL td_equal(const DVTARGETDEVICE *t1, const DVTARGETDEVICE *t2)
|
|
|
|
{
|
|
|
|
if(t1 == NULL && t2 == NULL) return TRUE;
|
|
|
|
if(t1 == NULL || t2 == NULL) return FALSE;
|
|
|
|
|
|
|
|
if(!string_off_equal(t1, t1->tdDriverNameOffset, t2, t2->tdDriverNameOffset))
|
|
|
|
return FALSE;
|
|
|
|
if(!string_off_equal(t1, t1->tdDeviceNameOffset, t2, t2->tdDeviceNameOffset))
|
|
|
|
return FALSE;
|
|
|
|
if(!string_off_equal(t1, t1->tdPortNameOffset, t2, t2->tdPortNameOffset))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME check devmode? */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-07-18 17:43:45 +02:00
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_GetData
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:32:58 +02:00
|
|
|
static HRESULT WINAPI snapshot_GetData(IDataObject *iface, FORMATETC *fmt,
|
|
|
|
STGMEDIUM *med)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:17:00 +02:00
|
|
|
snapshot *This = impl_from_IDataObject(iface);
|
2009-04-16 13:32:58 +02:00
|
|
|
HANDLE h;
|
2009-04-16 13:17:00 +02:00
|
|
|
HRESULT hr;
|
2009-04-16 13:32:58 +02:00
|
|
|
ole_priv_data *enum_data = NULL;
|
|
|
|
ole_priv_data_entry *entry;
|
|
|
|
DWORD mask;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-22 16:26:04 +02:00
|
|
|
TRACE("(%p, %p {%s}, %p)\n", iface, fmt, dump_fmtetc(fmt), med);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
if ( !fmt || !med ) return E_INVALIDARG;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:17:00 +02:00
|
|
|
if ( !OpenClipboard(NULL)) return CLIPBRD_E_CANT_OPEN;
|
|
|
|
|
|
|
|
if(!This->data)
|
|
|
|
hr = get_current_dataobject(&This->data);
|
|
|
|
|
|
|
|
if(This->data)
|
|
|
|
{
|
2009-04-16 13:32:58 +02:00
|
|
|
hr = IDataObject_GetData(This->data, fmt, med);
|
2009-04-16 13:17:00 +02:00
|
|
|
CloseClipboard();
|
|
|
|
return hr;
|
|
|
|
}
|
2009-04-16 13:13:39 +02:00
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
h = GetClipboardData(fmt->cfFormat);
|
|
|
|
if(!h)
|
|
|
|
{
|
|
|
|
hr = DV_E_FORMATETC;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
hr = get_priv_data(&enum_data);
|
|
|
|
if(FAILED(hr)) goto end;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
entry = find_format_in_list(enum_data->entries, enum_data->count, fmt->cfFormat);
|
|
|
|
if(entry)
|
2009-04-16 13:35:06 +02:00
|
|
|
{
|
2009-04-16 17:49:35 +02:00
|
|
|
if(!td_equal(fmt->ptd, entry->fmtetc.ptd))
|
|
|
|
{
|
|
|
|
hr = DV_E_FORMATETC;
|
|
|
|
goto end;
|
|
|
|
}
|
2009-04-16 13:32:58 +02:00
|
|
|
mask = fmt->tymed & entry->fmtetc.tymed;
|
2009-04-16 13:35:06 +02:00
|
|
|
if(!mask) mask = fmt->tymed & (TYMED_ISTREAM | TYMED_HGLOBAL);
|
|
|
|
}
|
2009-04-16 13:32:58 +02:00
|
|
|
else /* non-Ole format */
|
|
|
|
mask = fmt->tymed & TYMED_HGLOBAL;
|
2002-02-19 19:22:28 +01:00
|
|
|
|
2009-04-16 13:34:25 +02:00
|
|
|
if(mask & TYMED_ISTORAGE)
|
|
|
|
hr = get_stgmed_for_storage(h, med);
|
|
|
|
else if(mask & TYMED_HGLOBAL)
|
2009-04-16 13:32:58 +02:00
|
|
|
hr = get_stgmed_for_global(h, med);
|
2009-04-16 13:34:07 +02:00
|
|
|
else if(mask & TYMED_ISTREAM)
|
|
|
|
hr = get_stgmed_for_stream(h, med);
|
2009-06-22 12:58:52 +02:00
|
|
|
else if(mask & TYMED_ENHMF)
|
|
|
|
hr = get_stgmed_for_emf((HENHMETAFILE)h, med);
|
2014-11-13 22:50:42 +01:00
|
|
|
else if(mask & TYMED_GDI)
|
|
|
|
hr = get_stgmed_for_bitmap((HBITMAP)h, med);
|
2009-04-16 13:32:58 +02:00
|
|
|
else
|
|
|
|
{
|
2009-04-30 14:48:46 +02:00
|
|
|
FIXME("Unhandled tymed - mask %x req tymed %x\n", mask, fmt->tymed);
|
2009-04-16 13:32:58 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:13:39 +02:00
|
|
|
end:
|
2009-04-16 17:49:35 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, enum_data);
|
2009-04-16 13:32:58 +02:00
|
|
|
if ( !CloseClipboard() ) hr = CLIPBRD_E_CANT_CLOSE;
|
|
|
|
return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 13:13:39 +02:00
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_GetDataHere
|
2009-04-16 13:13:39 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_GetDataHere(IDataObject *iface, FORMATETC *fmt,
|
|
|
|
STGMEDIUM *med)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-30 14:48:46 +02:00
|
|
|
snapshot *This = impl_from_IDataObject(iface);
|
|
|
|
HANDLE h;
|
|
|
|
HRESULT hr;
|
|
|
|
ole_priv_data *enum_data = NULL;
|
|
|
|
ole_priv_data_entry *entry;
|
|
|
|
TYMED supported;
|
|
|
|
|
|
|
|
if ( !fmt || !med ) return E_INVALIDARG;
|
|
|
|
|
2010-05-26 01:27:58 +02:00
|
|
|
TRACE("(%p, %p {%s}, %p (tymed %x)\n", iface, fmt, dump_fmtetc(fmt), med, med->tymed);
|
|
|
|
|
2009-04-30 14:48:46 +02:00
|
|
|
if ( !OpenClipboard(NULL)) return CLIPBRD_E_CANT_OPEN;
|
|
|
|
|
|
|
|
if(!This->data)
|
|
|
|
hr = get_current_dataobject(&This->data);
|
|
|
|
|
|
|
|
if(This->data)
|
|
|
|
{
|
|
|
|
hr = IDataObject_GetDataHere(This->data, fmt, med);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
CloseClipboard();
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h = GetClipboardData(fmt->cfFormat);
|
|
|
|
if(!h)
|
|
|
|
{
|
|
|
|
hr = DV_E_FORMATETC;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = get_priv_data(&enum_data);
|
|
|
|
if(FAILED(hr)) goto end;
|
|
|
|
|
|
|
|
entry = find_format_in_list(enum_data->entries, enum_data->count, fmt->cfFormat);
|
|
|
|
if(entry)
|
|
|
|
{
|
|
|
|
if(!td_equal(fmt->ptd, entry->fmtetc.ptd))
|
|
|
|
{
|
|
|
|
hr = DV_E_FORMATETC;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
supported = entry->fmtetc.tymed;
|
|
|
|
}
|
|
|
|
else /* non-Ole format */
|
|
|
|
supported = TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
switch(med->tymed)
|
|
|
|
{
|
|
|
|
case TYMED_HGLOBAL:
|
|
|
|
{
|
|
|
|
DWORD src_size = GlobalSize(h);
|
|
|
|
DWORD dst_size = GlobalSize(med->u.hGlobal);
|
|
|
|
hr = E_FAIL;
|
|
|
|
if(dst_size >= src_size)
|
|
|
|
{
|
|
|
|
void *src = GlobalLock(h);
|
|
|
|
void *dst = GlobalLock(med->u.hGlobal);
|
|
|
|
|
|
|
|
memcpy(dst, src, src_size);
|
|
|
|
GlobalUnlock(med->u.hGlobal);
|
|
|
|
GlobalUnlock(h);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TYMED_ISTREAM:
|
|
|
|
{
|
|
|
|
DWORD src_size = GlobalSize(h);
|
|
|
|
void *src = GlobalLock(h);
|
|
|
|
hr = IStream_Write(med->u.pstm, src, src_size, NULL);
|
|
|
|
GlobalUnlock(h);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TYMED_ISTORAGE:
|
|
|
|
{
|
|
|
|
STGMEDIUM copy;
|
|
|
|
if(!(supported & TYMED_ISTORAGE))
|
|
|
|
{
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = get_stgmed_for_storage(h, ©);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IStorage_CopyTo(copy.u.pstg, 0, NULL, NULL, med->u.pstg);
|
|
|
|
ReleaseStgMedium(©);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled tymed - supported %x req tymed %x\n", supported, med->tymed);
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, enum_data);
|
|
|
|
if ( !CloseClipboard() ) hr = CLIPBRD_E_CANT_CLOSE;
|
|
|
|
return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_QueryGetData
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* The OLE Clipboard's implementation of this method delegates to
|
1999-07-18 17:43:45 +02:00
|
|
|
* a data source if there is one or wraps around the windows clipboard
|
|
|
|
* function IsClipboardFormatAvailable() otherwise.
|
|
|
|
*
|
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_QueryGetData(IDataObject *iface, FORMATETC *fmt)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-22 16:26:04 +02:00
|
|
|
FIXME("(%p, %p {%s})\n", iface, fmt, dump_fmtetc(fmt));
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if (!fmt) return E_INVALIDARG;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if ( fmt->dwAspect != DVASPECT_CONTENT ) return DV_E_FORMATETC;
|
2008-04-15 19:29:32 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if ( fmt->lindex != -1 ) return DV_E_FORMATETC;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
return (IsClipboardFormatAvailable(fmt->cfFormat)) ? S_OK : DV_E_CLIPFORMAT;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_GetCanonicalFormatEtc
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_GetCanonicalFormatEtc(IDataObject *iface, FORMATETC *fmt_in,
|
|
|
|
FORMATETC *fmt_out)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", iface, fmt_in, fmt_out);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if ( !fmt_in || !fmt_out ) return E_INVALIDARG;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
*fmt_out = *fmt_in;
|
|
|
|
return DATA_S_SAMEFORMATETC;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_SetData
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-04-16 13:14:49 +02:00
|
|
|
* The OLE Clipboard does not implement this method
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_SetData(IDataObject *iface, FORMATETC *fmt,
|
|
|
|
STGMEDIUM *med, BOOL release)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p, %p, %p, %d): not implemented\n", iface, fmt, med, release);
|
|
|
|
return E_NOTIMPL;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_EnumFormatEtc
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_EnumFormatEtc(IDataObject *iface, DWORD dir,
|
|
|
|
IEnumFORMATETC **enum_fmt)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:32:58 +02:00
|
|
|
HRESULT hr;
|
2009-03-30 13:00:44 +02:00
|
|
|
ole_priv_data *data = NULL;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p, %x, %p)\n", iface, dir, enum_fmt);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
*enum_fmt = NULL;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
if ( dir != DATADIR_GET ) return E_NOTIMPL;
|
2009-04-16 13:09:19 +02:00
|
|
|
if ( !OpenClipboard(NULL) ) return CLIPBRD_E_CANT_OPEN;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:32:58 +02:00
|
|
|
hr = get_priv_data(&data);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
if(FAILED(hr)) goto end;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
hr = enum_fmtetc_construct( data, 0, enum_fmt );
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 13:00:44 +02:00
|
|
|
end:
|
|
|
|
if ( !CloseClipboard() ) hr = CLIPBRD_E_CANT_CLOSE;
|
|
|
|
return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_DAdvise
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-04-16 13:14:49 +02:00
|
|
|
* The OLE Clipboard does not implement this method
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_DAdvise(IDataObject *iface, FORMATETC *fmt,
|
|
|
|
DWORD flags, IAdviseSink *sink,
|
|
|
|
DWORD *conn)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p, %p, %x, %p, %p): not implemented\n", iface, fmt, flags, sink, conn);
|
|
|
|
return E_NOTIMPL;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_DUnadvise
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-04-16 13:14:49 +02:00
|
|
|
* The OLE Clipboard does not implement this method
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_DUnadvise(IDataObject* iface, DWORD conn)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p, %d): not implemented\n", iface, conn);
|
|
|
|
return E_NOTIMPL;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2009-04-16 13:14:49 +02:00
|
|
|
* snapshot_EnumDAdvise
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
|
|
|
* The OLE Clipboard does not implement this method
|
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
static HRESULT WINAPI snapshot_EnumDAdvise(IDataObject* iface,
|
|
|
|
IEnumSTATDATA** enum_advise)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
TRACE("(%p, %p): not implemented\n", iface, enum_advise);
|
|
|
|
return E_NOTIMPL;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
static const IDataObjectVtbl snapshot_vtable =
|
2009-03-17 15:17:49 +01:00
|
|
|
{
|
2009-04-16 13:14:49 +02:00
|
|
|
snapshot_QueryInterface,
|
|
|
|
snapshot_AddRef,
|
|
|
|
snapshot_Release,
|
|
|
|
snapshot_GetData,
|
|
|
|
snapshot_GetDataHere,
|
|
|
|
snapshot_QueryGetData,
|
|
|
|
snapshot_GetCanonicalFormatEtc,
|
|
|
|
snapshot_SetData,
|
|
|
|
snapshot_EnumFormatEtc,
|
|
|
|
snapshot_DAdvise,
|
|
|
|
snapshot_DUnadvise,
|
|
|
|
snapshot_EnumDAdvise
|
2009-03-17 15:17:49 +01:00
|
|
|
};
|
1999-07-18 17:43:45 +02:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------*
|
2009-03-17 15:17:49 +01:00
|
|
|
* Internal implementation methods for the OLE clipboard
|
1999-07-18 17:43:45 +02:00
|
|
|
*---------------------------------------------------------------------*/
|
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
static snapshot *snapshot_construct(DWORD seq_no)
|
|
|
|
{
|
|
|
|
snapshot *This;
|
|
|
|
|
|
|
|
This = HeapAlloc( GetProcessHeap(), 0, sizeof(*This) );
|
|
|
|
if (!This) return NULL;
|
|
|
|
|
2010-12-16 01:04:21 +01:00
|
|
|
This->IDataObject_iface.lpVtbl = &snapshot_vtable;
|
2009-04-16 13:14:49 +02:00
|
|
|
This->ref = 0;
|
|
|
|
This->seq_no = seq_no;
|
2009-04-16 13:17:00 +02:00
|
|
|
This->data = NULL;
|
2009-04-16 13:14:49 +02:00
|
|
|
|
|
|
|
return This;
|
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/*********************************************************
|
2009-04-16 13:16:17 +02:00
|
|
|
* register_clipboard_formats
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 16:34:31 +01:00
|
|
|
static void register_clipboard_formats(void)
|
|
|
|
{
|
2009-04-23 16:04:56 +02:00
|
|
|
static const WCHAR OwnerLink[] = {'O','w','n','e','r','L','i','n','k',0};
|
|
|
|
static const WCHAR FileName[] = {'F','i','l','e','N','a','m','e',0};
|
|
|
|
static const WCHAR FileNameW[] = {'F','i','l','e','N','a','m','e','W',0};
|
|
|
|
static const WCHAR DataObject[] = {'D','a','t','a','O','b','j','e','c','t',0};
|
|
|
|
static const WCHAR EmbeddedObject[] = {'E','m','b','e','d','d','e','d',' ','O','b','j','e','c','t',0};
|
|
|
|
static const WCHAR EmbedSource[] = {'E','m','b','e','d',' ','S','o','u','r','c','e',0};
|
|
|
|
static const WCHAR CustomLinkSource[] = {'C','u','s','t','o','m',' ','L','i','n','k',' ','S','o','u','r','c','e',0};
|
|
|
|
static const WCHAR LinkSource[] = {'L','i','n','k',' ','S','o','u','r','c','e',0};
|
|
|
|
static const WCHAR ObjectDescriptor[] = {'O','b','j','e','c','t',' ','D','e','s','c','r','i','p','t','o','r',0};
|
|
|
|
static const WCHAR LinkSourceDescriptor[] = {'L','i','n','k',' ','S','o','u','r','c','e',' ',
|
|
|
|
'D','e','s','c','r','i','p','t','o','r',0};
|
|
|
|
static const WCHAR OlePrivateData[] = {'O','l','e',' ','P','r','i','v','a','t','e',' ','D','a','t','a',0};
|
|
|
|
|
2009-04-24 13:02:48 +02:00
|
|
|
static const WCHAR WineMarshalledDataObject[] = {'W','i','n','e',' ','M','a','r','s','h','a','l','l','e','d',' ',
|
|
|
|
'D','a','t','a','O','b','j','e','c','t',0};
|
|
|
|
|
2009-04-23 16:04:56 +02:00
|
|
|
ownerlink_clipboard_format = RegisterClipboardFormatW(OwnerLink);
|
|
|
|
filename_clipboard_format = RegisterClipboardFormatW(FileName);
|
|
|
|
filenameW_clipboard_format = RegisterClipboardFormatW(FileNameW);
|
|
|
|
dataobject_clipboard_format = RegisterClipboardFormatW(DataObject);
|
|
|
|
embedded_object_clipboard_format = RegisterClipboardFormatW(EmbeddedObject);
|
|
|
|
embed_source_clipboard_format = RegisterClipboardFormatW(EmbedSource);
|
|
|
|
custom_link_source_clipboard_format = RegisterClipboardFormatW(CustomLinkSource);
|
|
|
|
link_source_clipboard_format = RegisterClipboardFormatW(LinkSource);
|
|
|
|
object_descriptor_clipboard_format = RegisterClipboardFormatW(ObjectDescriptor);
|
|
|
|
link_source_descriptor_clipboard_format = RegisterClipboardFormatW(LinkSourceDescriptor);
|
|
|
|
ole_private_data_clipboard_format = RegisterClipboardFormatW(OlePrivateData);
|
2009-04-24 13:02:48 +02:00
|
|
|
|
|
|
|
wine_marshal_clipboard_format = RegisterClipboardFormatW(WineMarshalledDataObject);
|
2009-03-17 16:34:31 +01:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* OLEClipbrd_Initialize()
|
|
|
|
* Initializes the OLE clipboard.
|
|
|
|
*/
|
|
|
|
void OLEClipbrd_Initialize(void)
|
|
|
|
{
|
2009-04-16 13:16:17 +02:00
|
|
|
register_clipboard_formats();
|
2009-03-17 16:34:31 +01:00
|
|
|
|
2009-04-16 13:16:17 +02:00
|
|
|
if ( !theOleClipboard )
|
|
|
|
{
|
|
|
|
ole_clipbrd* clipbrd;
|
|
|
|
HGLOBAL h;
|
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
clipbrd = HeapAlloc( GetProcessHeap(), 0, sizeof(*clipbrd) );
|
|
|
|
if (!clipbrd) return;
|
|
|
|
|
|
|
|
clipbrd->latest_snapshot = NULL;
|
|
|
|
clipbrd->window = NULL;
|
|
|
|
clipbrd->src_data = NULL;
|
|
|
|
clipbrd->cached_enum = NULL;
|
|
|
|
|
|
|
|
h = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, 0);
|
|
|
|
if(!h)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, clipbrd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(CreateStreamOnHGlobal(h, TRUE, &clipbrd->marshal_data)))
|
|
|
|
{
|
|
|
|
GlobalFree(h);
|
|
|
|
HeapFree(GetProcessHeap(), 0, clipbrd);
|
|
|
|
return;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:16:17 +02:00
|
|
|
theOleClipboard = clipbrd;
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* OLEClipbrd_UnInitialize()
|
|
|
|
* Un-Initializes the OLE clipboard
|
|
|
|
*/
|
|
|
|
void OLEClipbrd_UnInitialize(void)
|
|
|
|
{
|
2009-04-16 13:16:17 +02:00
|
|
|
ole_clipbrd *clipbrd = theOleClipboard;
|
2009-04-16 13:14:49 +02:00
|
|
|
|
2009-04-16 13:16:17 +02:00
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
if ( clipbrd )
|
|
|
|
{
|
|
|
|
static const WCHAR ole32W[] = {'o','l','e','3','2',0};
|
|
|
|
HINSTANCE hinst = GetModuleHandleW(ole32W);
|
|
|
|
|
|
|
|
if ( clipbrd->window )
|
|
|
|
{
|
|
|
|
DestroyWindow(clipbrd->window);
|
|
|
|
UnregisterClassW( clipbrd_wndclass, hinst );
|
|
|
|
}
|
|
|
|
|
|
|
|
IStream_Release(clipbrd->marshal_data);
|
2009-12-29 19:59:37 +01:00
|
|
|
if (clipbrd->src_data) IDataObject_Release(clipbrd->src_data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, clipbrd->cached_enum);
|
2009-04-16 13:16:17 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, clipbrd);
|
|
|
|
theOleClipboard = NULL;
|
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-24 14:49:24 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* set_clipboard_formats
|
|
|
|
*
|
2009-04-16 13:05:11 +02:00
|
|
|
* Enumerate all formats supported by the source and make
|
2009-03-24 14:49:24 +01:00
|
|
|
* those formats available using delayed rendering using SetClipboardData.
|
2009-04-16 13:05:11 +02:00
|
|
|
* Cache the enumeration list and make that list visibile as the
|
|
|
|
* 'Ole Private Data' format on the clipboard.
|
2009-03-24 14:49:24 +01:00
|
|
|
*
|
|
|
|
*/
|
2009-04-16 12:49:11 +02:00
|
|
|
static HRESULT set_clipboard_formats(ole_clipbrd *clipbrd, IDataObject *data)
|
2009-03-24 14:49:24 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
FORMATETC fmt;
|
|
|
|
IEnumFORMATETC *enum_fmt;
|
2009-03-26 14:32:16 +01:00
|
|
|
HGLOBAL priv_data_handle;
|
2009-04-16 16:27:24 +02:00
|
|
|
DWORD_PTR target_offset;
|
2009-03-26 14:32:16 +01:00
|
|
|
ole_priv_data *priv_data;
|
|
|
|
DWORD count = 0, needed = sizeof(*priv_data), idx;
|
2009-03-24 14:49:24 +01:00
|
|
|
|
|
|
|
hr = IDataObject_EnumFormatEtc(data, DATADIR_GET, &enum_fmt);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
2009-03-26 14:32:16 +01:00
|
|
|
while(IEnumFORMATETC_Next(enum_fmt, 1, &fmt, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
needed += sizeof(priv_data->entries[0]);
|
|
|
|
if(fmt.ptd)
|
|
|
|
{
|
|
|
|
needed += fmt.ptd->tdSize;
|
|
|
|
CoTaskMemFree(fmt.ptd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Windows pads the list with two empty ole_priv_data_entries, one
|
|
|
|
* after the entries array and one after the target device data.
|
|
|
|
* Allocating with zero init to zero these pads. */
|
|
|
|
|
|
|
|
needed += sizeof(priv_data->entries[0]); /* initialisation of needed includes one of these. */
|
|
|
|
priv_data_handle = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE | GMEM_ZEROINIT, needed);
|
|
|
|
priv_data = GlobalLock(priv_data_handle);
|
|
|
|
|
|
|
|
priv_data->unk1 = 0;
|
|
|
|
priv_data->size = needed;
|
|
|
|
priv_data->unk2 = 1;
|
|
|
|
priv_data->count = count;
|
|
|
|
priv_data->unk3[0] = 0;
|
|
|
|
priv_data->unk3[1] = 0;
|
|
|
|
|
|
|
|
IEnumFORMATETC_Reset(enum_fmt);
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
target_offset = FIELD_OFFSET(ole_priv_data, entries[count + 1]); /* count entries + one pad. */
|
|
|
|
|
2009-03-24 14:49:24 +01:00
|
|
|
while(IEnumFORMATETC_Next(enum_fmt, 1, &fmt, NULL) == S_OK)
|
|
|
|
{
|
2009-04-16 13:05:11 +02:00
|
|
|
TRACE("%s\n", dump_fmtetc(&fmt));
|
2009-03-26 14:32:16 +01:00
|
|
|
|
|
|
|
priv_data->entries[idx].fmtetc = fmt;
|
|
|
|
if(fmt.ptd)
|
|
|
|
{
|
|
|
|
memcpy((char*)priv_data + target_offset, fmt.ptd, fmt.ptd->tdSize);
|
|
|
|
priv_data->entries[idx].fmtetc.ptd = (DVTARGETDEVICE*)target_offset;
|
|
|
|
target_offset += fmt.ptd->tdSize;
|
|
|
|
CoTaskMemFree(fmt.ptd);
|
|
|
|
}
|
|
|
|
|
2009-04-16 12:51:45 +02:00
|
|
|
priv_data->entries[idx].first_use = !find_format_in_list(priv_data->entries, idx, fmt.cfFormat);
|
2009-03-26 14:32:16 +01:00
|
|
|
priv_data->entries[idx].unk[0] = 0;
|
|
|
|
priv_data->entries[idx].unk[1] = 0;
|
|
|
|
|
2009-04-16 13:05:11 +02:00
|
|
|
if (priv_data->entries[idx].first_use)
|
|
|
|
SetClipboardData(fmt.cfFormat, NULL);
|
|
|
|
|
2009-03-26 14:32:16 +01:00
|
|
|
idx++;
|
2009-03-24 14:49:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IEnumFORMATETC_Release(enum_fmt);
|
2009-03-26 14:32:16 +01:00
|
|
|
|
2009-04-16 12:49:11 +02:00
|
|
|
/* Cache the list and fixup any target device offsets to ptrs */
|
|
|
|
clipbrd->cached_enum = HeapAlloc(GetProcessHeap(), 0, needed);
|
|
|
|
memcpy(clipbrd->cached_enum, priv_data, needed);
|
|
|
|
for(idx = 0; idx < clipbrd->cached_enum->count; idx++)
|
2009-04-16 16:27:24 +02:00
|
|
|
clipbrd->cached_enum->entries[idx].fmtetc.ptd =
|
|
|
|
td_offs_to_ptr(clipbrd->cached_enum, (DWORD_PTR)clipbrd->cached_enum->entries[idx].fmtetc.ptd);
|
2009-04-16 12:49:11 +02:00
|
|
|
|
2009-03-26 14:32:16 +01:00
|
|
|
GlobalUnlock(priv_data_handle);
|
2009-12-29 20:00:53 +01:00
|
|
|
if(!SetClipboardData(ole_private_data_clipboard_format, priv_data_handle))
|
|
|
|
{
|
|
|
|
GlobalFree(priv_data_handle);
|
|
|
|
return CLIPBRD_E_CANT_SET;
|
|
|
|
}
|
2009-03-26 14:32:16 +01:00
|
|
|
|
2009-03-24 14:49:24 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:09:04 +02:00
|
|
|
static HWND create_clipbrd_window(void);
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_clipbrd_window
|
|
|
|
*/
|
|
|
|
static inline HRESULT get_clipbrd_window(ole_clipbrd *clipbrd, HWND *wnd)
|
|
|
|
{
|
|
|
|
if ( !clipbrd->window )
|
|
|
|
clipbrd->window = create_clipbrd_window();
|
|
|
|
|
|
|
|
*wnd = clipbrd->window;
|
|
|
|
return *wnd ? S_OK : E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:12:03 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* release_marshal_data
|
|
|
|
*
|
|
|
|
* Releases the data and sets the stream back to zero size.
|
|
|
|
*/
|
|
|
|
static inline void release_marshal_data(IStream *stm)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
ULARGE_INTEGER size;
|
|
|
|
pos.QuadPart = size.QuadPart = 0;
|
|
|
|
|
|
|
|
IStream_Seek(stm, pos, STREAM_SEEK_SET, NULL);
|
|
|
|
CoReleaseMarshalData(stm);
|
|
|
|
IStream_Seek(stm, pos, STREAM_SEEK_SET, NULL);
|
|
|
|
IStream_SetSize(stm, size);
|
|
|
|
}
|
|
|
|
|
2009-04-24 13:02:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* expose_marshalled_dataobject
|
|
|
|
*
|
|
|
|
* Sets the marshalled dataobject to the clipboard. In the flushed case
|
|
|
|
* we set a zero sized HGLOBAL to clear the old marshalled data.
|
|
|
|
*/
|
|
|
|
static HRESULT expose_marshalled_dataobject(ole_clipbrd *clipbrd, IDataObject *data)
|
|
|
|
{
|
|
|
|
HGLOBAL h;
|
|
|
|
|
|
|
|
if(data)
|
|
|
|
{
|
|
|
|
HGLOBAL h_stm;
|
|
|
|
GetHGlobalFromStream(clipbrd->marshal_data, &h_stm);
|
|
|
|
dup_global_mem(h_stm, GMEM_DDESHARE|GMEM_MOVEABLE, &h);
|
|
|
|
}
|
|
|
|
else /* flushed */
|
|
|
|
h = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 0);
|
|
|
|
|
|
|
|
if(!h) return E_OUTOFMEMORY;
|
|
|
|
|
2009-12-29 20:00:53 +01:00
|
|
|
if(!SetClipboardData(wine_marshal_clipboard_format, h))
|
|
|
|
{
|
|
|
|
GlobalFree(h);
|
|
|
|
return CLIPBRD_E_CANT_SET;
|
|
|
|
}
|
2009-04-24 13:02:48 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-16 13:08:11 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_src_dataobject
|
|
|
|
*
|
|
|
|
* Clears and sets the clipboard's src IDataObject.
|
2009-04-16 13:12:03 +02:00
|
|
|
*
|
|
|
|
* To marshal the source dataobject we do something rather different from Windows.
|
2009-04-24 13:02:48 +02:00
|
|
|
* We set a clipboard format which contains the marshalled data.
|
|
|
|
* Windows sets two window props one of which is an IID, the other is an endpoint number.
|
2009-04-16 13:08:11 +02:00
|
|
|
*/
|
|
|
|
static HRESULT set_src_dataobject(ole_clipbrd *clipbrd, IDataObject *data)
|
|
|
|
{
|
2009-04-16 13:12:03 +02:00
|
|
|
HRESULT hr;
|
|
|
|
HWND wnd;
|
|
|
|
|
|
|
|
if(FAILED(hr = get_clipbrd_window(clipbrd, &wnd))) return hr;
|
2009-04-16 13:08:11 +02:00
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
if(clipbrd->src_data)
|
2009-04-16 13:08:11 +02:00
|
|
|
{
|
2009-04-16 13:12:03 +02:00
|
|
|
release_marshal_data(clipbrd->marshal_data);
|
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
IDataObject_Release(clipbrd->src_data);
|
|
|
|
clipbrd->src_data = NULL;
|
2009-04-16 13:08:11 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, clipbrd->cached_enum);
|
|
|
|
clipbrd->cached_enum = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data)
|
|
|
|
{
|
2009-04-16 13:12:03 +02:00
|
|
|
IUnknown *unk;
|
|
|
|
|
2009-04-16 13:08:11 +02:00
|
|
|
IDataObject_AddRef(data);
|
2009-04-16 13:09:56 +02:00
|
|
|
clipbrd->src_data = data;
|
2009-04-16 13:12:03 +02:00
|
|
|
|
|
|
|
IDataObject_QueryInterface(data, &IID_IUnknown, (void**)&unk);
|
|
|
|
hr = CoMarshalInterface(clipbrd->marshal_data, &IID_IDataObject, unk,
|
|
|
|
MSHCTX_LOCAL, NULL, MSHLFLAGS_TABLESTRONG);
|
|
|
|
IUnknown_Release(unk); /* Don't hold a ref on IUnknown, we have one on IDataObject. */
|
|
|
|
if(FAILED(hr)) return hr;
|
2009-04-16 13:08:11 +02:00
|
|
|
hr = set_clipboard_formats(clipbrd, data);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* clipbrd_wndproc
|
|
|
|
*/
|
|
|
|
static LRESULT CALLBACK clipbrd_wndproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
ole_clipbrd *clipbrd;
|
|
|
|
|
|
|
|
get_ole_clipbrd(&clipbrd);
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_RENDERFORMAT:
|
|
|
|
{
|
|
|
|
UINT cf = wparam;
|
|
|
|
ole_priv_data_entry *entry;
|
|
|
|
|
|
|
|
TRACE("(): WM_RENDERFORMAT(cfFormat=%x)\n", cf);
|
|
|
|
entry = find_format_in_list(clipbrd->cached_enum->entries, clipbrd->cached_enum->count, cf);
|
|
|
|
|
|
|
|
if(entry)
|
2009-04-16 13:09:56 +02:00
|
|
|
render_format(clipbrd->src_data, &entry->fmtetc);
|
2009-04-16 13:08:11 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_RENDERALLFORMATS:
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
ole_priv_data_entry *entries = clipbrd->cached_enum->entries;
|
|
|
|
|
|
|
|
TRACE("(): WM_RENDERALLFORMATS\n");
|
|
|
|
|
|
|
|
for(i = 0; i < clipbrd->cached_enum->count; i++)
|
|
|
|
{
|
|
|
|
if(entries[i].first_use)
|
2009-04-16 13:09:56 +02:00
|
|
|
render_format(clipbrd->src_data, &entries[i].fmtetc);
|
2009-04-16 13:08:11 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_DESTROYCLIPBOARD:
|
|
|
|
{
|
|
|
|
TRACE("(): WM_DESTROYCLIPBOARD\n");
|
|
|
|
|
|
|
|
set_src_dataobject(clipbrd, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProcW(hwnd, message, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-04-16 13:09:04 +02:00
|
|
|
* create_clipbrd_window
|
2009-04-16 13:08:11 +02:00
|
|
|
*/
|
2009-04-16 13:09:04 +02:00
|
|
|
static HWND create_clipbrd_window(void)
|
2009-04-16 13:08:11 +02:00
|
|
|
{
|
|
|
|
WNDCLASSEXW class;
|
|
|
|
static const WCHAR ole32W[] = {'o','l','e','3','2',0};
|
|
|
|
static const WCHAR title[] = {'C','l','i','p','b','o','a','r','d','W','i','n','d','o','w',0};
|
|
|
|
HINSTANCE hinst = GetModuleHandleW(ole32W);
|
|
|
|
|
|
|
|
class.cbSize = sizeof(class);
|
|
|
|
class.style = 0;
|
|
|
|
class.lpfnWndProc = clipbrd_wndproc;
|
|
|
|
class.cbClsExtra = 0;
|
|
|
|
class.cbWndExtra = 0;
|
|
|
|
class.hInstance = hinst;
|
|
|
|
class.hIcon = 0;
|
|
|
|
class.hCursor = 0;
|
|
|
|
class.hbrBackground = 0;
|
|
|
|
class.lpszMenuName = NULL;
|
|
|
|
class.lpszClassName = clipbrd_wndclass;
|
|
|
|
class.hIconSm = NULL;
|
|
|
|
|
|
|
|
RegisterClassExW(&class);
|
|
|
|
|
|
|
|
return CreateWindowW(clipbrd_wndclass, title, WS_POPUP | WS_CLIPSIBLINGS | WS_OVERLAPPED,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
NULL, NULL, hinst, 0);
|
|
|
|
}
|
|
|
|
|
2009-03-24 14:49:24 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* set_dataobject_format
|
|
|
|
*
|
|
|
|
* Windows creates a 'DataObject' clipboard format that contains the
|
|
|
|
* clipboard window's HWND or NULL if the Ole clipboard has been flushed.
|
|
|
|
*/
|
2009-03-23 12:47:19 +01:00
|
|
|
static HRESULT set_dataobject_format(HWND hwnd)
|
|
|
|
{
|
|
|
|
HGLOBAL h = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(hwnd));
|
|
|
|
HWND *data;
|
|
|
|
|
|
|
|
if(!h) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
data = GlobalLock(h);
|
|
|
|
*data = hwnd;
|
|
|
|
GlobalUnlock(h);
|
|
|
|
|
|
|
|
if(!SetClipboardData(dataobject_clipboard_format, h))
|
|
|
|
{
|
|
|
|
GlobalFree(h);
|
|
|
|
return CLIPBRD_E_CANT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/*---------------------------------------------------------------------*
|
|
|
|
* Win32 OLE clipboard API
|
|
|
|
*---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OleSetClipboard [OLE32.@]
|
|
|
|
* Places a pointer to the specified data object onto the clipboard,
|
|
|
|
* making the data object accessible to the OleGetClipboard function.
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-03-17 15:17:49 +01:00
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* S_OK IDataObject pointer placed on the clipboard
|
|
|
|
* CLIPBRD_E_CANT_OPEN OpenClipboard failed
|
|
|
|
* CLIPBRD_E_CANT_EMPTY EmptyClipboard failed
|
|
|
|
* CLIPBRD_E_CANT_CLOSE CloseClipboard failed
|
|
|
|
* CLIPBRD_E_CANT_SET SetClipboard failed
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:08:11 +02:00
|
|
|
HRESULT WINAPI OleSetClipboard(IDataObject* data)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:07:47 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ole_clipbrd *clipbrd;
|
2009-04-16 13:09:04 +02:00
|
|
|
HWND wnd;
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:08:11 +02:00
|
|
|
TRACE("(%p)\n", data);
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:07:47 +02:00
|
|
|
if(FAILED(hr = get_ole_clipbrd(&clipbrd))) return hr;
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:09:04 +02:00
|
|
|
if(FAILED(hr = get_clipbrd_window(clipbrd, &wnd))) return hr;
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:09:04 +02:00
|
|
|
if ( !OpenClipboard(wnd) ) return CLIPBRD_E_CANT_OPEN;
|
2009-03-17 15:17:49 +01:00
|
|
|
|
|
|
|
if ( !EmptyClipboard() )
|
2009-03-30 16:33:28 +02:00
|
|
|
{
|
|
|
|
hr = CLIPBRD_E_CANT_EMPTY;
|
|
|
|
goto end;
|
|
|
|
}
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:08:11 +02:00
|
|
|
hr = set_src_dataobject(clipbrd, data);
|
|
|
|
if(FAILED(hr)) goto end;
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-17 14:44:27 +02:00
|
|
|
if(data)
|
2009-04-24 13:02:48 +02:00
|
|
|
{
|
|
|
|
hr = expose_marshalled_dataobject(clipbrd, data);
|
|
|
|
if(FAILED(hr)) goto end;
|
2009-04-17 14:44:27 +02:00
|
|
|
hr = set_dataobject_format(wnd);
|
2009-04-24 13:02:48 +02:00
|
|
|
}
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-30 16:33:28 +02:00
|
|
|
end:
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:07:47 +02:00
|
|
|
if ( !CloseClipboard() ) hr = CLIPBRD_E_CANT_CLOSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
if ( FAILED(hr) )
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-24 13:02:48 +02:00
|
|
|
expose_marshalled_dataobject(clipbrd, NULL);
|
2009-04-16 13:08:11 +02:00
|
|
|
set_src_dataobject(clipbrd, NULL);
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OleGetClipboard [OLE32.@]
|
|
|
|
* Returns a pointer to our internal IDataObject which represents the conceptual
|
|
|
|
* state of the Windows clipboard. If the current clipboard already contains
|
|
|
|
* an IDataObject, our internal IDataObject will delegate to this object.
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:14:49 +02:00
|
|
|
HRESULT WINAPI OleGetClipboard(IDataObject **obj)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:07:47 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ole_clipbrd *clipbrd;
|
2009-04-16 13:14:49 +02:00
|
|
|
DWORD seq_no;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", obj);
|
|
|
|
|
|
|
|
if(!obj) return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:07:47 +02:00
|
|
|
if(FAILED(hr = get_ole_clipbrd(&clipbrd))) return hr;
|
2009-03-17 15:17:49 +01:00
|
|
|
|
2009-04-16 13:14:49 +02:00
|
|
|
seq_no = GetClipboardSequenceNumber();
|
|
|
|
if(clipbrd->latest_snapshot && clipbrd->latest_snapshot->seq_no != seq_no)
|
|
|
|
clipbrd->latest_snapshot = NULL;
|
|
|
|
|
|
|
|
if(!clipbrd->latest_snapshot)
|
|
|
|
{
|
|
|
|
clipbrd->latest_snapshot = snapshot_construct(seq_no);
|
|
|
|
if(!clipbrd->latest_snapshot) return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2010-12-16 01:04:21 +01:00
|
|
|
*obj = &clipbrd->latest_snapshot->IDataObject_iface;
|
2009-04-16 13:14:49 +02:00
|
|
|
IDataObject_AddRef(*obj);
|
|
|
|
|
|
|
|
return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* OleFlushClipboard [OLE32.@]
|
|
|
|
* Renders the data from the source IDataObject into the windows clipboard
|
1999-07-18 17:43:45 +02:00
|
|
|
*
|
2009-03-17 15:17:49 +01:00
|
|
|
* TODO: OleFlushClipboard needs to additionally handle TYMED_IStorage media
|
|
|
|
* by copying the storage into global memory. Subsequently the default
|
|
|
|
* data object exposed through OleGetClipboard must convert this TYMED_HGLOBAL
|
|
|
|
* back to TYMED_IStorage.
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-03-17 15:17:49 +01:00
|
|
|
HRESULT WINAPI OleFlushClipboard(void)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:07:47 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ole_clipbrd *clipbrd;
|
2009-04-16 13:09:04 +02:00
|
|
|
HWND wnd;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
TRACE("()\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:07:47 +02:00
|
|
|
if(FAILED(hr = get_ole_clipbrd(&clipbrd))) return hr;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:09:04 +02:00
|
|
|
if(FAILED(hr = get_clipbrd_window(clipbrd, &wnd))) return hr;
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
/*
|
|
|
|
* Already flushed or no source DataObject? Nothing to do.
|
|
|
|
*/
|
2009-04-16 13:09:56 +02:00
|
|
|
if (!clipbrd->src_data) return S_OK;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:09:04 +02:00
|
|
|
if (!OpenClipboard(wnd)) return CLIPBRD_E_CANT_OPEN;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:34:43 +02:00
|
|
|
SendMessageW(wnd, WM_RENDERALLFORMATS, 0, 0);
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-03-23 12:47:19 +01:00
|
|
|
hr = set_dataobject_format(NULL);
|
|
|
|
|
2009-04-24 13:02:48 +02:00
|
|
|
expose_marshalled_dataobject(clipbrd, NULL);
|
2009-04-16 13:08:11 +02:00
|
|
|
set_src_dataobject(clipbrd, NULL);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-30 16:33:28 +02:00
|
|
|
if ( !CloseClipboard() ) hr = CLIPBRD_E_CANT_CLOSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|
|
|
|
|
2009-03-17 15:17:49 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OleIsCurrentClipboard [OLE32.@]
|
1999-07-18 17:43:45 +02:00
|
|
|
*/
|
2009-04-16 13:09:56 +02:00
|
|
|
HRESULT WINAPI OleIsCurrentClipboard(IDataObject *data)
|
1999-07-18 17:43:45 +02:00
|
|
|
{
|
2009-04-16 13:09:56 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ole_clipbrd *clipbrd;
|
|
|
|
TRACE("()\n");
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
if(FAILED(hr = get_ole_clipbrd(&clipbrd))) return hr;
|
1999-07-18 17:43:45 +02:00
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
if (data == NULL) return S_FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-04-16 13:09:56 +02:00
|
|
|
return (data == clipbrd->src_data) ? S_OK : S_FALSE;
|
1999-07-18 17:43:45 +02:00
|
|
|
}
|