ole32: OleFlushClipboard shouldn't call EmptyClipboard.

This commit is contained in:
Huw Davies 2009-03-26 13:38:18 +00:00 committed by Alexandre Julliard
parent 524a99a2da
commit b7a2e83ddb
2 changed files with 26 additions and 32 deletions

View File

@ -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;

View File

@ -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);