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

ole32: Move the embed source hack to a separate function.

parent 126ec018
...@@ -126,6 +126,7 @@ static const CHAR OLEClipbrd_WNDCLASS[] = "CLIPBRDWNDCLASS"; ...@@ -126,6 +126,7 @@ static const CHAR OLEClipbrd_WNDCLASS[] = "CLIPBRDWNDCLASS";
static UINT dataobject_clipboard_format; static UINT dataobject_clipboard_format;
static UINT ole_priv_data_clipboard_format; static UINT ole_priv_data_clipboard_format;
static UINT embed_source_clipboard_format;
/* Structure of 'Ole Private Data' clipboard format */ /* Structure of 'Ole Private Data' clipboard format */
typedef struct typedef struct
...@@ -423,39 +424,29 @@ static HGLOBAL OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc ) ...@@ -423,39 +424,29 @@ static HGLOBAL OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc )
return hGlobalDest; return hGlobalDest;
} }
#define MAX_CLIPFORMAT_NAME 80 /************************************************************
* render_embed_source_hack
/*********************************************************************** *
* OLEClipbrd_RenderFormat(LPFORMATETC) * This is clearly a hack and has no place in the clipboard code.
* Render the clipboard data. Note that this call will delegate to the *
* source data object.
* Note: This function assumes it is passed an HGLOBAL format to render.
*/ */
static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pFormatetc) static HRESULT render_embed_source_hack(IDataObject *data, LPFORMATETC fmt)
{ {
STGMEDIUM std; STGMEDIUM std;
HGLOBAL hDup;
HRESULT hr = S_OK;
char szFmtName[MAX_CLIPFORMAT_NAME];
ILockBytes *ptrILockBytes = 0;
HGLOBAL hStorage = 0; HGLOBAL hStorage = 0;
HRESULT hr = S_OK;
ILockBytes *ptrILockBytes;
if (!GetClipboardFormatNameA(pFormatetc->cfFormat, szFmtName, MAX_CLIPFORMAT_NAME))
szFmtName[0] = '\0';
/* If embed source */
if (!strcmp(szFmtName, CF_EMBEDSOURCE))
{
memset(&std, 0, sizeof(STGMEDIUM)); memset(&std, 0, sizeof(STGMEDIUM));
std.tymed = pFormatetc->tymed = TYMED_ISTORAGE; std.tymed = fmt->tymed = TYMED_ISTORAGE;
hStorage = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, 0); hStorage = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, 0);
if (hStorage == NULL) if (hStorage == NULL) return E_OUTOFMEMORY;
HANDLE_ERROR( E_OUTOFMEMORY );
hr = CreateILockBytesOnHGlobal(hStorage, FALSE, &ptrILockBytes); hr = CreateILockBytesOnHGlobal(hStorage, FALSE, &ptrILockBytes);
hr = StgCreateDocfileOnILockBytes(ptrILockBytes, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &std.u.pstg); hr = StgCreateDocfileOnILockBytes(ptrILockBytes, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &std.u.pstg);
ILockBytes_Release(ptrILockBytes);
if (FAILED(hr = IDataObject_GetDataHere(theOleClipboard->pIDataObjectSrc, pFormatetc, &std))) if (FAILED(hr = IDataObject_GetDataHere(theOleClipboard->pIDataObjectSrc, fmt, &std)))
{ {
WARN("() : IDataObject_GetDataHere failed to render clipboard data! (%x)\n", hr); WARN("() : IDataObject_GetDataHere failed to render clipboard data! (%x)\n", hr);
GlobalFree(hStorage); GlobalFree(hStorage);
...@@ -525,6 +516,7 @@ static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pF ...@@ -525,6 +516,7 @@ static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pF
HeapFree(GetProcessHeap(), 0, mfBits); HeapFree(GetProcessHeap(), 0, mfBits);
GlobalUnlock(std2.u.hGlobal); GlobalUnlock(std2.u.hGlobal);
ReleaseStgMedium(&std2);
ReadClassStg(std.u.pstg, &clsID); ReadClassStg(std.u.pstg, &clsID);
ProgIDFromCLSID(&clsID, &strProgID); ProgIDFromCLSID(&clsID, &strProgID);
...@@ -534,38 +526,70 @@ static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pF ...@@ -534,38 +526,70 @@ static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pF
OLECONVERT_CreateCompObjStream(std.u.pstg, strOleTypeName); OLECONVERT_CreateCompObjStream(std.u.pstg, strOleTypeName);
} }
} }
if ( !SetClipboardData( fmt->cfFormat, hStorage ) )
{
WARN("() : Failed to set rendered clipboard data into clipboard!\n");
GlobalFree(hStorage);
hr = CLIPBRD_E_CANT_SET;
} }
else
ReleaseStgMedium(&std);
return hr;
}
/***********************************************************************
* OLEClipbrd_RenderFormat(LPFORMATETC)
* Render the clipboard data. Note that this call will delegate to the
* source data object.
* Note: This function assumes it is passed an HGLOBAL format to render.
*/
static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pFormatetc)
{
STGMEDIUM std;
HGLOBAL hDup;
HRESULT hr;
/* Embed source hack */
if(pFormatetc->cfFormat == embed_source_clipboard_format)
{ {
return render_embed_source_hack(pIDataObject, pFormatetc);
}
if (FAILED(hr = IDataObject_GetData(pIDataObject, pFormatetc, &std))) if (FAILED(hr = IDataObject_GetData(pIDataObject, pFormatetc, &std)))
{ {
WARN("() : IDataObject_GetData failed to render clipboard data! (%x)\n", hr); WARN("() : IDataObject_GetData failed to render clipboard data! (%x)\n", hr);
GlobalFree(hStorage);
return hr; return hr;
} }
/* To put a copy back on the clipboard */ /* To put a copy back on the clipboard */
hStorage = std.u.hGlobal; if(std.tymed != TYMED_HGLOBAL)
{
FIXME("got tymed %x\n", std.tymed);
hr = DV_E_FORMATETC;
goto end;
} }
/* /*
* Put a copy of the rendered data back on the clipboard * Put a copy of the rendered data back on the clipboard
*/ */
if ( !(hDup = OLEClipbrd_GlobalDupMem(hStorage)) ) if ( !(hDup = OLEClipbrd_GlobalDupMem(std.u.hGlobal)) )
HANDLE_ERROR( E_OUTOFMEMORY ); {
hr = E_OUTOFMEMORY;
goto end;
}
if ( !SetClipboardData( pFormatetc->cfFormat, hDup ) ) if ( !SetClipboardData( pFormatetc->cfFormat, hDup ) )
{ {
GlobalFree(hDup);
WARN("() : Failed to set rendered clipboard data into clipboard!\n"); WARN("() : Failed to set rendered clipboard data into clipboard!\n");
GlobalFree(hDup);
hr = CLIPBRD_E_CANT_SET;
} }
CLEANUP: end:
ReleaseStgMedium(&std); ReleaseStgMedium(&std);
return hr; return hr;
} }
...@@ -1106,11 +1130,14 @@ static void register_clipboard_formats(void) ...@@ -1106,11 +1130,14 @@ static void register_clipboard_formats(void)
{ {
static const WCHAR DataObjectW[] = { 'D','a','t','a','O','b','j','e','c','t',0 }; static const WCHAR DataObjectW[] = { 'D','a','t','a','O','b','j','e','c','t',0 };
static const WCHAR OlePrivateDataW[] = { 'O','l','e',' ','P','r','i','v','a','t','e',' ','D','a','t','a',0 }; static const WCHAR OlePrivateDataW[] = { 'O','l','e',' ','P','r','i','v','a','t','e',' ','D','a','t','a',0 };
static const WCHAR EmbedSourceW[] = { 'E','m','b','e','d',' ','S','o','u','r','c','e',0 };
if(!dataobject_clipboard_format) if(!dataobject_clipboard_format)
dataobject_clipboard_format = RegisterClipboardFormatW(DataObjectW); dataobject_clipboard_format = RegisterClipboardFormatW(DataObjectW);
if(!ole_priv_data_clipboard_format) if(!ole_priv_data_clipboard_format)
ole_priv_data_clipboard_format = RegisterClipboardFormatW(OlePrivateDataW); ole_priv_data_clipboard_format = RegisterClipboardFormatW(OlePrivateDataW);
if(!embed_source_clipboard_format)
embed_source_clipboard_format = RegisterClipboardFormatW(EmbedSourceW);
} }
/*********************************************************************** /***********************************************************************
......
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