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

This commit is contained in:
Huw Davies 2009-03-23 11:47:19 +00:00 committed by Alexandre Julliard
parent e77ab142e4
commit ef4b6b8749
2 changed files with 59 additions and 24 deletions

View File

@ -1271,6 +1271,26 @@ static HWND OLEClipbrd_CreateWindow(void)
return hwnd; 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 * Win32 OLE clipboard API
*---------------------------------------------------------------------*/ *---------------------------------------------------------------------*/
@ -1296,10 +1316,6 @@ HRESULT WINAPI OleSetClipboard(IDataObject* pDataObj)
FORMATETC rgelt; FORMATETC rgelt;
BOOL bClipboardOpen = FALSE; BOOL bClipboardOpen = FALSE;
struct oletls *info = COM_CurrentInfo(); struct oletls *info = COM_CurrentInfo();
/*
HGLOBAL hDataObject = 0;
OLEClipbrd **ppDataObject;
*/
TRACE("(%p)\n", pDataObj); TRACE("(%p)\n", pDataObj);
@ -1391,27 +1407,9 @@ HRESULT WINAPI OleSetClipboard(IDataObject* pDataObj)
/* /*
* Windows additionally creates a new "DataObject" clipboard format * Windows additionally creates a new "DataObject" clipboard format
* and stores in on the clipboard. We could possibly store a pointer * and stores the clipboard window's HWND in it
* 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.
*/ */
/* hr = set_dataobject_format(theOleClipboard->hWndClipboard);
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;
CLEANUP: CLEANUP:
@ -1541,6 +1539,8 @@ HRESULT WINAPI OleFlushClipboard(void)
IEnumFORMATETC_Release(penumFormatetc); IEnumFORMATETC_Release(penumFormatetc);
hr = set_dataobject_format(NULL);
/* /*
* Release the source data object we are holding on to * Release the source data object we are holding on to
*/ */

View File

@ -423,6 +423,36 @@ static void test_get_clipboard(void)
IDataObject_Release(data_obj); 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) static void test_set_clipboard(void)
{ {
HRESULT hr; HRESULT hr;
@ -453,6 +483,9 @@ static void test_set_clipboard(void)
hr = OleSetClipboard(data1); hr = OleSetClipboard(data1);
ok(hr == S_OK, "failed to set clipboard to data1, hr = 0x%08x\n", hr); ok(hr == S_OK, "failed to set clipboard to data1, hr = 0x%08x\n", hr);
test_cf_dataobject(TRUE);
hr = OleIsCurrentClipboard(data1); hr = OleIsCurrentClipboard(data1);
ok(hr == S_OK, "expected current clipboard to be data1, hr = 0x%08x\n", hr); ok(hr == S_OK, "expected current clipboard to be data1, hr = 0x%08x\n", hr);
hr = OleIsCurrentClipboard(data2); hr = OleIsCurrentClipboard(data2);
@ -480,6 +513,8 @@ static void test_set_clipboard(void)
hr = OleIsCurrentClipboard(NULL); hr = OleIsCurrentClipboard(NULL);
ok(hr == S_FALSE, "expect S_FALSE, hr = 0x%08x\n", hr); 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); ok(OleSetClipboard(NULL) == S_OK, "failed to clear clipboard, hr = 0x%08x\n", hr);
ref = IDataObject_Release(data1); ref = IDataObject_Release(data1);