From: Jactry Zeng jzeng@codeweavers.com
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 | 21 ++++++++------------- dlls/shell32/tests/shlview.c | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/dlls/shell32/shlview.c b/dlls/shell32/shlview.c index 2a6abf7c8cf..d91e3d1f9a6 100644 --- a/dlls/shell32/shlview.c +++ b/dlls/shell32/shlview.c @@ -2714,20 +2714,15 @@ static HRESULT WINAPI FolderView_SetCurrentViewMode(IFolderView2 *iface, UINT mo
TRACE("%p, %u.\n", This, mode);
- if((mode < FVM_FIRST || mode > FVM_LAST) && - (mode != FVM_AUTO)) - return E_INVALIDARG; - - /* 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) + { + dwStyle = ViewModeToListStyle(mode); + SetStyle(This, dwStyle, LVS_TYPEMASK); + This->FolderSettings.ViewMode = mode; + }
return S_OK; } diff --git a/dlls/shell32/tests/shlview.c b/dlls/shell32/tests/shlview.c index 72d7411fcd5..0e1374e1bf1 100644 --- a/dlls/shell32/tests/shlview.c +++ b/dlls/shell32/tests/shlview.c @@ -1110,13 +1110,20 @@ static void test_GetSetCurrentViewMode(void)
hr = IFolderView_SetCurrentViewMode(fview, FVM_AUTO); ok(hr == S_OK, "got (0x%08lx)\n", hr); + 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); + 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); 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 +1141,8 @@ 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); + ok(viewmode == FVM_CONTENT || broken(viewmode == FVM_THUMBSTRIP) /* vista */, "Got view mode %d.\n", viewmode);
/* Test messages */ hwnd_lv = subclass_listview(hwnd);