Commit ef4b6b87 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

ole32: Store the ole clipboard window's HWND in the DataObject clipboard format.

parent e77ab142
......@@ -1271,6 +1271,26 @@ static HWND OLEClipbrd_CreateWindow(void)
return hwnd;
}
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;
}
/*---------------------------------------------------------------------*
* Win32 OLE clipboard API
*---------------------------------------------------------------------*/
......@@ -1296,10 +1316,6 @@ HRESULT WINAPI OleSetClipboard(IDataObject* pDataObj)
FORMATETC rgelt;
BOOL bClipboardOpen = FALSE;
struct oletls *info = COM_CurrentInfo();
/*
HGLOBAL hDataObject = 0;
OLEClipbrd **ppDataObject;
*/
TRACE("(%p)\n", pDataObj);
......@@ -1391,27 +1407,9 @@ HRESULT WINAPI OleSetClipboard(IDataObject* pDataObj)
/*
* Windows additionally creates a new "DataObject" clipboard format
* and stores in on the clipboard. We could possibly store a pointer
* to our internal IDataObject interface on the clipboard. I'm not
* sure what the use of this is though.
* Enable the code below for this functionality.
* and stores the clipboard window's HWND in it
*/
/*
theOleClipboard->cfDataObj = RegisterClipboardFormatA("DataObject");
hDataObject = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT,
sizeof(OLEClipbrd *));
if (hDataObject==0)
HANDLE_ERROR( E_OUTOFMEMORY );
ppDataObject = GlobalLock(hDataObject);
*ppDataObject = theOleClipboard;
GlobalUnlock(hDataObject);
if ( !SetClipboardData( theOleClipboard->cfDataObj, hDataObject ) )
HANDLE_ERROR( CLIPBRD_E_CANT_SET );
*/
hr = S_OK;
hr = set_dataobject_format(theOleClipboard->hWndClipboard);
CLEANUP:
......@@ -1541,6 +1539,8 @@ HRESULT WINAPI OleFlushClipboard(void)
IEnumFORMATETC_Release(penumFormatetc);
hr = set_dataobject_format(NULL);
/*
* Release the source data object we are holding on to
*/
......
......@@ -423,6 +423,36 @@ static void test_get_clipboard(void)
IDataObject_Release(data_obj);
}
static void test_cf_dataobject(BOOL dataobject_active)
{
UINT cf = 0;
UINT cf_dataobject = RegisterClipboardFormatA("DataObject");
BOOL found_dataobject = FALSE;
OpenClipboard(NULL);
do
{
cf = EnumClipboardFormats(cf);
if(cf == cf_dataobject)
{
HGLOBAL h = GetClipboardData(cf);
HWND *ptr = GlobalLock(h);
DWORD size = GlobalSize(h);
HWND clip_owner = GetClipboardOwner();
found_dataobject = TRUE;
ok(size >= sizeof(*ptr), "size %d\n", size);
if(dataobject_active)
ok(*ptr == clip_owner, "hwnd %p clip_owner %p\n", *ptr, clip_owner);
else /* ole clipboard flushed */
ok(*ptr == NULL, "hwnd %p\n", *ptr);
GlobalUnlock(h);
}
} while(cf);
CloseClipboard();
ok(found_dataobject, "didn't find cf_dataobject\n");
}
static void test_set_clipboard(void)
{
HRESULT hr;
......@@ -453,6 +483,9 @@ static void test_set_clipboard(void)
hr = OleSetClipboard(data1);
ok(hr == S_OK, "failed to set clipboard to data1, hr = 0x%08x\n", hr);
test_cf_dataobject(TRUE);
hr = OleIsCurrentClipboard(data1);
ok(hr == S_OK, "expected current clipboard to be data1, hr = 0x%08x\n", hr);
hr = OleIsCurrentClipboard(data2);
......@@ -480,6 +513,8 @@ static void test_set_clipboard(void)
hr = OleIsCurrentClipboard(NULL);
ok(hr == S_FALSE, "expect S_FALSE, hr = 0x%08x\n", hr);
test_cf_dataobject(FALSE);
ok(OleSetClipboard(NULL) == S_OK, "failed to clear clipboard, hr = 0x%08x\n", hr);
ref = IDataObject_Release(data1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment