From: Zebediah Figura zfigura@codeweavers.com
Make the logic in do_paste() a bit more idiomatic. --- dlls/shell32/shlview_cmenu.c | 66 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-)
diff --git a/dlls/shell32/shlview_cmenu.c b/dlls/shell32/shlview_cmenu.c index e00306ee2a9..6951bbd4216 100644 --- a/dlls/shell32/shlview_cmenu.c +++ b/dlls/shell32/shlview_cmenu.c @@ -358,20 +358,24 @@ static HRESULT paste_pidls(ContextMenu *menu, ITEMIDLIST **pidls, unsigned int c return hr; }
+static HRESULT get_data_format(IDataObject *data, UINT cf, STGMEDIUM *medium) +{ + FORMATETC format; + + InitFormatEtc(format, cf, TYMED_HGLOBAL); + return IDataObject_GetData(data, &format, medium); +} + static HRESULT do_paste(ContextMenu *menu) { IDataObject *data; HRESULT hr; STGMEDIUM medium; - FORMATETC formatetc; - HRESULT format_hr;
if (FAILED(hr = OleGetClipboard(&data))) return hr;
- InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL); - format_hr = IDataObject_GetData(data, &formatetc, &medium); - if (SUCCEEDED(format_hr)) + if (SUCCEEDED(get_data_format(data, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), &medium))) { CIDA *cida = GlobalLock(medium.hGlobal); ITEMIDLIST **pidls; @@ -398,45 +402,39 @@ static HRESULT do_paste(ContextMenu *menu) } ReleaseStgMedium(&medium); } - else + else if (SUCCEEDED(get_data_format(data, CF_HDROP, &medium))) { - InitFormatEtc(formatetc, CF_HDROP, TYMED_HGLOBAL); - format_hr = IDataObject_GetData(data, &formatetc, &medium); - if (SUCCEEDED(format_hr)) - { - WCHAR path[MAX_PATH]; - ITEMIDLIST **pidls; - UINT count; + WCHAR path[MAX_PATH]; + ITEMIDLIST **pidls; + UINT count;
- count = DragQueryFileW(medium.hGlobal, -1, NULL, 0); - pidls = SHAlloc(count * sizeof(ITEMIDLIST*)); - if (pidls) + count = DragQueryFileW(medium.hGlobal, -1, NULL, 0); + pidls = SHAlloc(count * sizeof(ITEMIDLIST*)); + if (pidls) + { + for (unsigned int i = 0; i < count; i++) { - for (unsigned int i = 0; i < count; i++) + DragQueryFileW(medium.hGlobal, i, path, ARRAY_SIZE(path)); + if (!(pidls[i] = ILCreateFromPathW(path))) { - DragQueryFileW(medium.hGlobal, i, path, ARRAY_SIZE(path)); - if (!(pidls[i] = ILCreateFromPathW(path))) - { - hr = E_FAIL; - break; - } + hr = E_FAIL; + break; } - if (SUCCEEDED(hr)) - hr = paste_pidls(menu, pidls, count); - _ILFreeaPidl(pidls, count); } - else - { - hr = HRESULT_FROM_WIN32(GetLastError()); - } - ReleaseStgMedium(&medium); + if (SUCCEEDED(hr)) + hr = paste_pidls(menu, pidls, count); + _ILFreeaPidl(pidls, count); + } + else + { + hr = HRESULT_FROM_WIN32(GetLastError()); } + ReleaseStgMedium(&medium); } - - if (FAILED(format_hr)) + else { ERR("Cannot paste any clipboard formats.\n"); - hr = format_hr; + hr = E_FAIL; }
IDataObject_Release(data);