Huw Davies : ole32: OleFlushClipboard shouldn't call EmptyClipboard.

Alexandre Julliard julliard at winehq.org
Thu Mar 26 11:05:48 CDT 2009


Module: wine
Branch: master
Commit: b7a2e83ddb87fe71cb2691a4e8e2845e2de25bb4
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b7a2e83ddb87fe71cb2691a4e8e2845e2de25bb4

Author: Huw Davies <huw at codeweavers.com>
Date:   Thu Mar 26 13:38:18 2009 +0000

ole32: OleFlushClipboard shouldn't call EmptyClipboard.

---

 dlls/ole32/clipboard.c       |   36 ++++--------------------------------
 dlls/ole32/tests/clipboard.c |   22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/dlls/ole32/clipboard.c b/dlls/ole32/clipboard.c
index 008e35b..34946ff 100644
--- a/dlls/ole32/clipboard.c
+++ b/dlls/ole32/clipboard.c
@@ -1474,13 +1474,9 @@ HRESULT WINAPI OleFlushClipboard(void)
   FORMATETC rgelt;
   HRESULT hr = S_OK;
   BOOL bClipboardOpen = FALSE;
-  IDataObject* pIDataObjectSrc = NULL;
 
   TRACE("()\n");
 
-  /*
-   * Make sure we have a clipboard object
-   */
   OLEClipbrd_Initialize();
 
   /*
@@ -1489,30 +1485,14 @@ HRESULT WINAPI OleFlushClipboard(void)
   if (!theOleClipboard->pIDataObjectSrc)
     return S_OK;
 
-  /*
-   * Addref and save the source data object we are holding on to temporarily,
-   * since it will be released when we empty the clipboard.
-   */
-  pIDataObjectSrc = theOleClipboard->pIDataObjectSrc;
-  IDataObject_AddRef(pIDataObjectSrc);
-
-  /*
-   * Open the Windows clipboard
-   */
   if ( !(bClipboardOpen = OpenClipboard(theOleClipboard->hWndClipboard)) )
     HANDLE_ERROR( CLIPBRD_E_CANT_OPEN );
 
   /*
-   * Empty the current clipboard
-   */
-  if ( !EmptyClipboard() )
-    HANDLE_ERROR( CLIPBRD_E_CANT_EMPTY );
-
-  /*
    * Render all HGLOBAL formats supported by the source into
    * the windows clipboard.
    */
-  if ( FAILED( hr = IDataObject_EnumFormatEtc( pIDataObjectSrc,
+  if ( FAILED( hr = IDataObject_EnumFormatEtc( theOleClipboard->pIDataObjectSrc,
                                                DATADIR_GET,
                                                &penumFormatetc) ))
   {
@@ -1528,10 +1508,7 @@ HRESULT WINAPI OleFlushClipboard(void)
             GetClipboardFormatNameA(rgelt.cfFormat, szFmtName, sizeof(szFmtName)-1)
               ? szFmtName : "");
 
-      /*
-       * Render the clipboard data
-       */
-      if ( FAILED(OLEClipbrd_RenderFormat( pIDataObjectSrc, &rgelt )) )
+      if ( FAILED(OLEClipbrd_RenderFormat( theOleClipboard->pIDataObjectSrc, &rgelt )) )
         continue;
     }
   }
@@ -1540,16 +1517,11 @@ HRESULT WINAPI OleFlushClipboard(void)
 
   hr = set_dataobject_format(NULL);
 
-  /*
-   * Release the source data object we are holding on to
-   */
-  IDataObject_Release(pIDataObjectSrc);
+  IDataObject_Release(theOleClipboard->pIDataObjectSrc);
+  theOleClipboard->pIDataObjectSrc = NULL;
 
 CLEANUP:
 
-  /*
-   * Close Windows clipboard (It remains associated with our window)
-   */
   if ( bClipboardOpen && !CloseClipboard() )
     hr = CLIPBRD_E_CANT_CLOSE;
 
diff --git a/dlls/ole32/tests/clipboard.c b/dlls/ole32/tests/clipboard.c
index bc7e727..121783d 100644
--- a/dlls/ole32/tests/clipboard.c
+++ b/dlls/ole32/tests/clipboard.c
@@ -625,6 +625,7 @@ static void test_set_clipboard(void)
     HRESULT hr;
     ULONG ref;
     LPDATAOBJECT data1, data2, data_cmpl;
+    HGLOBAL hblob, h;
 
     cf_stream = RegisterClipboardFormatA("stream format");
     cf_storage = RegisterClipboardFormatA("storage format");
@@ -681,6 +682,16 @@ static void test_set_clipboard(void)
     hr = OleIsCurrentClipboard(NULL);
     ok(hr == S_FALSE, "expect S_FALSE, hr = 0x%08x\n", hr);
 
+    /* put a format directly onto the clipboard to show
+       OleFlushClipboard doesn't empty the clipboard */
+    hblob = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT, 10);
+    OpenClipboard(NULL);
+    h = SetClipboardData(cf_onemore, hblob);
+    ok(h == hblob, "got %p\n", h);
+    h = GetClipboardData(cf_onemore);
+    ok(h == hblob, "got %p\n", h);
+    CloseClipboard();
+
     hr = OleFlushClipboard();
     ok(hr == S_OK, "failed to flush clipboard, hr = 0x%08x\n", hr);
     hr = OleIsCurrentClipboard(data1);
@@ -690,10 +701,21 @@ static void test_set_clipboard(void)
     hr = OleIsCurrentClipboard(NULL);
     ok(hr == S_FALSE, "expect S_FALSE, hr = 0x%08x\n", hr);
 
+    /* format should survive the flush */
+    OpenClipboard(NULL);
+    h = GetClipboardData(cf_onemore);
+    ok(h == hblob, "got %p\n", h);
+    CloseClipboard();
+
     test_cf_dataobject(NULL);
 
     ok(OleSetClipboard(NULL) == S_OK, "failed to clear clipboard, hr = 0x%08x\n", hr);
 
+    OpenClipboard(NULL);
+    h = GetClipboardData(cf_onemore);
+    ok(h == NULL, "got %p\n", h);
+    CloseClipboard();
+
     hr = OleSetClipboard(data_cmpl);
     ok(hr == S_OK, "failed to set clipboard to complex data, hr = 0x%08x\n", hr);
     test_cf_dataobject(data_cmpl);




More information about the wine-cvs mailing list