Huw Davies : ole32: Store the ole clipboard window' s HWND in the DataObject clipboard format.
Alexandre Julliard
julliard at winehq.org
Mon Mar 23 12:34:57 CDT 2009
Module: wine
Branch: master
Commit: ef4b6b87496ba269cbf9ba71cbdc90b9a6c43f8e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ef4b6b87496ba269cbf9ba71cbdc90b9a6c43f8e
Author: Huw Davies <huw at codeweavers.com>
Date: Mon Mar 23 11:47:19 2009 +0000
ole32: Store the ole clipboard window's HWND in the DataObject clipboard format.
---
dlls/ole32/clipboard.c | 48 +++++++++++++++++++++---------------------
dlls/ole32/tests/clipboard.c | 35 ++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/dlls/ole32/clipboard.c b/dlls/ole32/clipboard.c
index 8a7bdd2..4c6f35f 100644
--- a/dlls/ole32/clipboard.c
+++ b/dlls/ole32/clipboard.c
@@ -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
*/
diff --git a/dlls/ole32/tests/clipboard.c b/dlls/ole32/tests/clipboard.c
index a4f8a62..f5ed06a 100644
--- a/dlls/ole32/tests/clipboard.c
+++ b/dlls/ole32/tests/clipboard.c
@@ -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);
More information about the wine-cvs
mailing list