[PATCH 0/1] MR10194: dlls/shell32:Implement FolderView2_GetSelection
Implement FolderView2_GetSelection -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10194
From: panhui <panhui@uniontech.com> --- dlls/shell32/shlview.c | 52 ++++++++++++++++++++- dlls/shell32/tests/shlview.c | 90 ++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/dlls/shell32/shlview.c b/dlls/shell32/shlview.c index b1524b1f29f..7a0554b6ca3 100644 --- a/dlls/shell32/shlview.c +++ b/dlls/shell32/shlview.c @@ -3032,8 +3032,56 @@ static HRESULT WINAPI FolderView2_GetSelection(IFolderView2 *iface, BOOL none_im IShellItemArray **array) { IShellViewImpl *This = impl_from_IFolderView2(iface); - FIXME("(%p)->(%d %p), stub\n", This, none_implies_folder, array); - return E_NOTIMPL; + HRESULT hr; + UINT itemCount; + LPITEMIDLIST pidlParent; + IShellItem *psi = NULL; + + TRACE("(%p)->(%d %p), stub\n", This, none_implies_folder, array); + + if (!array) + { + return E_INVALIDARG; + } + + *array = NULL; + if (!This->hWndList || !This->pSFParent) + { + return E_FAIL; + } + + itemCount = ShellView_GetSelections(This); + TRACE("selected items: %d\n", itemCount); + + hr = SHGetIDListFromObject((IUnknown*)This->pSFParent, &pidlParent); + if (FAILED(hr)) + { + ERR("SHGetIDListFromObject failed: %#lx\n", hr); + return hr; + } + + if (itemCount > 0) + { + hr = SHCreateShellItemArray(pidlParent, This->pSFParent, itemCount, + (PCUITEMID_CHILD_ARRAY)This->apidl, array); + } + else if (none_implies_folder) + { + hr = SHCreateItemFromIDList(pidlParent, &IID_IShellItem, (void**)&psi); + if (SUCCEEDED(hr)) + { + hr = SHCreateShellItemArrayFromShellItem(psi, &IID_IShellItemArray, (void**)array); + IShellItem_Release(psi); + } + } + else + { + hr = S_OK; + } + + if (pidlParent) + ILFree(pidlParent); + return hr; } static HRESULT WINAPI FolderView2_GetSelectionState(IFolderView2 *iface, PCUITEMID_CHILD pidl, diff --git a/dlls/shell32/tests/shlview.c b/dlls/shell32/tests/shlview.c index 2cacc3b8f87..56cffceb895 100644 --- a/dlls/shell32/tests/shlview.c +++ b/dlls/shell32/tests/shlview.c @@ -1634,6 +1634,95 @@ static void test_folder_flags(void) destroy_interfaces(desktop, shellview); } +static void test_FolderView2_GetSelection(void) +{ + IShellFolder *desktop; + IShellView *view; + IFolderView2 *fv2; + HWND hwnd_view, hwnd_list; + FOLDERSETTINGS settings = { FVM_ICON, 0 }; + RECT rc = { 0, 0, 100, 100 }; + IShellBrowser *browser; + HRESULT hr; + int itemCount = 0; + DWORD count; + IShellItemArray *psia = (void*)0xdeadbeef; + IShellItemArray *psia1 = NULL; + IShellItemArray *psia2 = NULL; + + create_interfaces(&desktop, &view); + + hr = IShellView_QueryInterface(view, &IID_IFolderView2, (void**)&fv2); + if (hr != S_OK) { + win_skip("IFolderView2 not supported by desktop folder\n"); + destroy_interfaces(desktop, view); + return; + } + + browser = IShellBrowserImpl_Construct(); + + hwnd_view = (HWND)0xdeadbeef; + hr = IShellView_CreateViewWindow(view, NULL, &settings, browser, &rc, &hwnd_view); + ok(hr == S_OK, "got (0x%08lx)\n", hr); + ok(IsWindow(hwnd_view), "got %p\n", hwnd_view); + + hwnd_list = subclass_listview(hwnd_view); + if (!hwnd_list) + { + win_skip("Failed to subclass ListView control\n"); + IShellBrowser_Release(browser); + IFolderView2_Release(fv2); + destroy_interfaces(desktop, view); + return; + } + + hr = IFolderView2_GetSelection(fv2, TRUE, NULL); + ok(hr == E_INVALIDARG, "GetSelection with NULL array returned %08lx\n", hr); + + SendMessageA(hwnd_list, LVM_SETSELECTIONMARK, 0, -1); + + hr = IFolderView2_GetSelection(fv2, FALSE, &psia); + ok(hr == S_OK, "GetSelection(FALSE) returned %08lx\n", hr); + ok(psia == NULL, "Expected NULL array, got %p\n", psia); + + hr = IFolderView2_GetSelection(fv2, TRUE, &psia1); + ok(hr == S_OK, "GetSelection(TRUE) returned %08lx\n", hr); + ok(psia1 != NULL, "Expected non-NULL array\n"); + if (psia1) + { + IShellItemArray_Release(psia1); + } + + hr = IFolderView2_ItemCount(fv2, SVGIO_ALLVIEW, &itemCount); + if (SUCCEEDED(hr) && itemCount > 0) + { + LVITEMW item = {0}; + item.state = LVIS_SELECTED; + item.stateMask = LVIS_SELECTED; + SendMessageW(hwnd_list, LVM_SETITEMSTATE, 0, (LPARAM)&item); + + hr = IFolderView2_GetSelection(fv2, FALSE, &psia2); + ok(hr == S_OK, "GetSelection(FALSE) with selection returned %08lx\n", hr); + ok(psia2 != NULL, "Expected non-NULL array\n"); + + if (psia2) + { + hr = IShellItemArray_GetCount(psia2, &count); + ok(hr == S_OK, "GetCount failed: %08lx\n", hr); + ok(count == 1, "Expected 1 selected item, got %lu\n", count); + IShellItemArray_Release(psia2); + } + + item.state = 0; + SendMessageW(hwnd_list, LVM_SETITEMSTATE, 0, (LPARAM)&item); + } + + IFolderView2_Release(fv2); + IShellView_DestroyViewWindow(view); + IShellBrowser_Release(browser); + destroy_interfaces(desktop, view); +} + START_TEST(shlview) { OleInitialize(NULL); @@ -1651,6 +1740,7 @@ START_TEST(shlview) test_SHCreateShellFolderViewEx(); test_newmenu(); test_folder_flags(); + test_FolderView2_GetSelection(); OleUninitialize(); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10194
participants (2)
-
pan hui (@panhui) -
panhui