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().
This commit is contained in:
Jactry Zeng 2023-04-09 11:10:01 -05:00 committed by Alexandre Julliard
parent 7f36382006
commit e80d8fe098
2 changed files with 30 additions and 21 deletions

View file

@ -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;
IShellViewImpl *shellview = impl_from_IFolderView2(iface);
DWORD style;
TRACE("%p, %u.\n", This, mode);
TRACE("folder view %p, mode %u.\n", iface, mode);
if((mode < FVM_FIRST || mode > FVM_LAST) &&
(mode != FVM_AUTO))
return E_INVALIDARG;
if (mode == FVM_AUTO)
mode = FVM_ICON;
/* 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);
/* 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;
}

View file

@ -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);