Module: wine Branch: master Commit: e80d8fe098a45222520d66406f1da8857fc5d974 URL: https://gitlab.winehq.org/wine/wine/-/commit/e80d8fe098a45222520d66406f1da88...
Author: Jactry Zeng jzeng@codeweavers.com Date: Sun Apr 9 11:10:01 2023 -0500
shell32: Reimplement IFolderView2_SetCurrentViewMode() with modern behaviours.
Only pre-win7 systems return E_INVALIDARG for invalid values, and only pre-vista systems accept FVM_AUTO as a view mode, others fall it back to FVM_ICON. Let's switch to modern behaviours, so that we don't need additional code for handling that when using it to implement IExplorerBrowser_SetFolderSettings().
---
dlls/shell32/shlview.c | 27 +++++++++++---------------- dlls/shell32/tests/shlview.c | 24 +++++++++++++++++++----- 2 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/dlls/shell32/shlview.c b/dlls/shell32/shlview.c index 3d449223620..d58435670c2 100644 --- a/dlls/shell32/shlview.c +++ b/dlls/shell32/shlview.c @@ -2709,25 +2709,20 @@ static HRESULT WINAPI FolderView_GetCurrentViewMode(IFolderView2 *iface, UINT *m
static HRESULT WINAPI FolderView_SetCurrentViewMode(IFolderView2 *iface, UINT mode) { - IShellViewImpl *This = impl_from_IFolderView2(iface); - DWORD dwStyle; - - TRACE("%p, %u.\n", This, mode); + IShellViewImpl *shellview = impl_from_IFolderView2(iface); + DWORD style;
- if((mode < FVM_FIRST || mode > FVM_LAST) && - (mode != FVM_AUTO)) - return E_INVALIDARG; + TRACE("folder view %p, mode %u.\n", iface, mode);
- /* Windows before Vista uses LVM_SETVIEW and possibly - LVM_SETEXTENDEDLISTVIEWSTYLE to set the style of the listview, - while later versions seem to accomplish this through other - means. */ - dwStyle = ViewModeToListStyle(mode); - SetStyle(This, dwStyle, LVS_TYPEMASK); + if (mode == FVM_AUTO) + mode = FVM_ICON;
- /* This will not necessarily be the actual mode set above. - This mimics the behavior of Windows XP. */ - This->FolderSettings.ViewMode = mode; + if (mode >= FVM_FIRST && mode <= FVM_LAST) + { + style = ViewModeToListStyle(mode); + SetStyle(shellview, style, LVS_TYPEMASK); + shellview->FolderSettings.ViewMode = mode; + }
return S_OK; } diff --git a/dlls/shell32/tests/shlview.c b/dlls/shell32/tests/shlview.c index a030c723604..89ff2e71eb0 100644 --- a/dlls/shell32/tests/shlview.c +++ b/dlls/shell32/tests/shlview.c @@ -1110,13 +1110,23 @@ static void test_GetSetCurrentViewMode(void)
hr = IFolderView_SetCurrentViewMode(fview, FVM_AUTO); ok(hr == S_OK, "got (0x%08lx)\n", hr); + viewmode = 0xdeadbeef; + hr = IFolderView_GetCurrentViewMode(fview, &viewmode); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + ok(viewmode == FVM_ICON || broken(viewmode == FVM_AUTO) /* pre vista */, "Got view mode %d.\n", viewmode);
+ hr = IFolderView_SetCurrentViewMode(fview, FVM_LIST); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + viewmode = 0xdeadbeef; + hr = IFolderView_GetCurrentViewMode(fview, &viewmode); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + ok(viewmode == FVM_LIST, "Got view mode %d.\n", viewmode); hr = IFolderView_SetCurrentViewMode(fview, 0); - ok(hr == E_INVALIDARG || broken(hr == S_OK), - "got (0x%08lx)\n", hr); - + ok(hr == S_OK || broken(hr == E_INVALIDARG) /* pre win7 */, "Got hr %#lx.\n", hr); + viewmode = 0xdeadbeef; hr = IFolderView_GetCurrentViewMode(fview, &viewmode); ok(hr == S_OK, "got (0x%08lx)\n", hr); + ok(viewmode == FVM_LIST || broken(viewmode == 0) /* pre vista */, "Got view mode %d.\n", viewmode);
for(i = 1; i < 9; i++) { @@ -1134,8 +1144,12 @@ static void test_GetSetCurrentViewMode(void) }
hr = IFolderView_SetCurrentViewMode(fview, 9); - ok(hr == E_INVALIDARG || broken(hr == S_OK), - "got (0x%08lx)\n", hr); + ok(hr == S_OK || broken(hr == E_INVALIDARG) /* pre win7 */, "Got hr %#lx.\n", hr); + viewmode = 0xdeadbeef; + hr = IFolderView_GetCurrentViewMode(fview, &viewmode); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + ok(viewmode == FVM_CONTENT || broken(viewmode == 9) /* pre vista */ || + broken(viewmode == FVM_THUMBSTRIP) /* vista */, "Got view mode %d.\n", viewmode);
/* Test messages */ hwnd_lv = subclass_listview(hwnd);