2 * Unit test of the IShellView
4 * Copyright 2010 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
39 #include "wine/test.h"
43 #define LISTVIEW_SEQ_INDEX 0
44 #define NUM_MSG_SEQUENCES 1
46 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
48 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
50 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
51 static LONG defwndproc_counter = 0;
55 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
57 msg.message = message;
58 msg.flags = sent|wparam|lparam;
59 if (defwndproc_counter) msg.flags |= defwinproc;
62 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
65 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
70 static HWND subclass_listview(HWND hwnd)
75 /* listview is a first child */
76 listview = FindWindowExA(hwnd, NULL, WC_LISTVIEWA, NULL);
78 oldproc = (WNDPROC)SetWindowLongPtrA(listview, GWLP_WNDPROC,
79 (LONG_PTR)listview_subclass_proc);
80 SetWindowLongPtrA(listview, GWLP_USERDATA, (LONG_PTR)oldproc);
87 const IShellBrowserVtbl *lpVtbl;
91 /* dummy IShellBrowser implementation */
92 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
94 IShellBrowser* IShellBrowserImpl_Construct(void)
96 IShellBrowserImpl *browser;
98 browser = HeapAlloc(GetProcessHeap(), 0, sizeof(*browser));
99 browser->lpVtbl = &IShellBrowserImpl_Vtbl;
102 return (IShellBrowser*)browser;
105 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
109 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
113 if(IsEqualIID(riid, &IID_IUnknown))
117 else if(IsEqualIID(riid, &IID_IOleWindow))
121 else if(IsEqualIID(riid, &IID_IShellBrowser))
128 IUnknown_AddRef( (IShellBrowser*) *ppvObj);
132 return E_NOINTERFACE;
135 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
137 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
138 return InterlockedIncrement(&This->ref);
141 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
143 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
144 ULONG ref = InterlockedDecrement(&This->ref);
148 HeapFree(GetProcessHeap(), 0, This);
154 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser *iface,
157 if (phwnd) *phwnd = GetDesktopWindow();
161 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser *iface,
167 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
174 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
181 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
189 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
197 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
199 LPOLEMENUGROUPWIDTHS lpMenuWidths)
205 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
212 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
219 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
226 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
237 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
239 HOLEMENU holemenuReserved,
240 HWND hwndActiveObject)
246 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
247 LPCOLESTR lpszStatusText)
253 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
254 LPTBBUTTON lpButtons,
262 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
270 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
272 IShellBrowserImpl_QueryInterface,
273 IShellBrowserImpl_AddRef,
274 IShellBrowserImpl_Release,
275 IShellBrowserImpl_GetWindow,
276 IShellBrowserImpl_ContextSensitiveHelp,
277 IShellBrowserImpl_InsertMenusSB,
278 IShellBrowserImpl_SetMenuSB,
279 IShellBrowserImpl_RemoveMenusSB,
280 IShellBrowserImpl_SetStatusTextSB,
281 IShellBrowserImpl_EnableModelessSB,
282 IShellBrowserImpl_TranslateAcceleratorSB,
283 IShellBrowserImpl_BrowseObject,
284 IShellBrowserImpl_GetViewStateStream,
285 IShellBrowserImpl_GetControlWindow,
286 IShellBrowserImpl_SendControlMsg,
287 IShellBrowserImpl_QueryActiveShellView,
288 IShellBrowserImpl_OnViewWindowActive,
289 IShellBrowserImpl_SetToolbarItems
292 static const struct message empty_seq[] = {
296 static const struct message folderview_getspacing_seq[] = {
297 { LVM_GETITEMSPACING, wparam|sent, FALSE },
301 static const struct message folderview_getselectionmarked_seq[] = {
302 { LVM_GETSELECTIONMARK, sent },
306 static const struct message folderview_getfocused_seq[] = {
307 { LVM_GETNEXTITEM, sent|wparam|lparam, -1, LVNI_FOCUSED },
311 static void test_IShellView_CreateViewWindow(void)
313 IShellFolder *desktop;
314 FOLDERSETTINGS settings;
320 hr = SHGetDesktopFolder(&desktop);
321 ok(hr == S_OK, "got (0x%08x)\n", hr);
323 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
324 ok(hr == S_OK, "got (0x%08x)\n", hr);
328 /* crashes on native */
329 hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, NULL, NULL);
332 settings.ViewMode = FVM_ICON;
334 hwnd_view = (HWND)0xdeadbeef;
335 hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, NULL, &hwnd_view);
336 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
337 ok(hwnd_view == 0, "got %p\n", hwnd_view);
339 hwnd_view = (HWND)0xdeadbeef;
340 hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, &r, &hwnd_view);
341 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
342 ok(hwnd_view == 0, "got %p\n", hwnd_view);
344 IShellView_Release(view);
345 IShellFolder_Release(desktop);
348 static void test_IFolderView(void)
350 IShellFolder *desktop;
351 FOLDERSETTINGS settings;
353 IShellBrowser *browser;
355 HWND hwnd_view, hwnd_list;
361 hr = SHGetDesktopFolder(&desktop);
362 ok(hr == S_OK, "got (0x%08x)\n", hr);
364 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
365 ok(hr == S_OK, "got (0x%08x)\n", hr);
367 hr = IShellView_QueryInterface(view, &IID_IFolderView, (void**)&fv);
370 win_skip("IFolderView not supported by desktop folder\n");
371 IShellView_Release(view);
372 IShellFolder_Release(desktop);
376 /* call methods before window creation */
377 hr = IFolderView_GetSpacing(fv, NULL);
378 ok(hr == S_FALSE || broken(hr == S_OK) /* win7 */, "got (0x%08x)\n", hr);
382 /* crashes on Vista and Win2k8 - List not created yet case */
383 hr = IFolderView_GetSpacing(fv, &pt);
386 hr = IFolderView_GetSelectionMarkedItem(fv, NULL);
387 hr = IFolderView_GetFocusedItem(fv, NULL);
390 browser = IShellBrowserImpl_Construct();
392 settings.ViewMode = FVM_ICON;
394 hwnd_view = (HWND)0xdeadbeef;
396 r.right = r.bottom = 100;
397 hr = IShellView_CreateViewWindow(view, NULL, &settings, browser, &r, &hwnd_view);
398 ok(hr == S_OK, "got (0x%08x)\n", hr);
399 ok(IsWindow(hwnd_view), "got %p\n", hwnd_view);
401 hwnd_list = subclass_listview(hwnd_view);
404 win_skip("Failed to subclass ListView control\n");
405 IShellBrowser_Release(browser);
406 IFolderView_Release(fv);
407 IShellView_Release(view);
408 IShellFolder_Release(desktop);
412 /* IFolderView::GetSpacing */
413 flush_sequences(sequences, NUM_MSG_SEQUENCES);
414 hr = IFolderView_GetSpacing(fv, NULL);
415 ok(hr == S_OK, "got (0x%08x)\n", hr);
416 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, empty_seq, "IFolderView::GetSpacing, empty", FALSE);
418 flush_sequences(sequences, NUM_MSG_SEQUENCES);
419 hr = IFolderView_GetSpacing(fv, &pt);
420 ok(hr == S_OK, "got (0x%08x)\n", hr);
421 /* fails with empty sequence on win7 for unknown reason */
422 if (sequences[LISTVIEW_SEQ_INDEX]->count)
424 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_getspacing_seq, "IFolderView::GetSpacing", FALSE);
425 ok(pt.x > 0, "got %d\n", pt.x);
426 ok(pt.y > 0, "got %d\n", pt.y);
427 ret = SendMessageA(hwnd_list, LVM_GETITEMSPACING, 0, 0);
428 ok(pt.x == LOWORD(ret) && pt.y == HIWORD(ret), "got (%d, %d)\n", LOWORD(ret), HIWORD(ret));
431 /* IFolderView::GetSelectionMarkedItem */
435 hr = IFolderView_GetSelectionMarkedItem(fv, NULL);
438 flush_sequences(sequences, NUM_MSG_SEQUENCES);
439 hr = IFolderView_GetSelectionMarkedItem(fv, &ret);
440 ok(hr == S_OK, "got (0x%08x)\n", hr);
441 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_getselectionmarked_seq,
442 "IFolderView::GetSelectionMarkedItem", FALSE);
444 /* IFolderView::GetFocusedItem */
445 flush_sequences(sequences, NUM_MSG_SEQUENCES);
446 hr = IFolderView_GetFocusedItem(fv, &ret);
447 ok(hr == S_OK, "got (0x%08x)\n", hr);
448 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_getfocused_seq,
449 "IFolderView::GetFocusedItem", FALSE);
451 IShellBrowser_Release(browser);
452 IFolderView_Release(fv);
453 IShellView_Release(view);
454 IShellFolder_Release(desktop);
461 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
463 test_IShellView_CreateViewWindow();