quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / comdlg32 / filedlgbrowser.c
blob776abfcef2f068de7e6d84381e067bdd35507445
1 /*
2 * Implementation of IShellBrowser for the File Open common dialog
4 * Copyright 1999 Francois Boisvert
5 * Copyright 1999, 2000 Juergen Schmied
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winnls.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winreg.h"
37 #define NO_SHLWAPI_STREAM
38 #include "shlwapi.h"
39 #include "filedlgbrowser.h"
40 #include "cdlg.h"
41 #include "shlguid.h"
42 #include "servprov.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
47 typedef struct
50 IShellBrowser IShellBrowser_iface;
51 ICommDlgBrowser ICommDlgBrowser_iface;
52 IServiceProvider IServiceProvider_iface;
53 LONG ref; /* Reference counter */
54 HWND hwndOwner; /* Owner dialog of the interface */
56 } IShellBrowserImpl;
58 static inline IShellBrowserImpl *impl_from_IShellBrowser(IShellBrowser *iface)
60 return CONTAINING_RECORD(iface, IShellBrowserImpl, IShellBrowser_iface);
63 static inline IShellBrowserImpl *impl_from_ICommDlgBrowser( ICommDlgBrowser *iface )
65 return CONTAINING_RECORD(iface, IShellBrowserImpl, ICommDlgBrowser_iface);
68 static inline IShellBrowserImpl *impl_from_IServiceProvider( IServiceProvider *iface )
70 return CONTAINING_RECORD(iface, IShellBrowserImpl, IServiceProvider_iface);
73 /**************************************************************************
74 * vtable
76 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
77 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
78 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
81 * Helper functions
84 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
85 static void COMDLG32_DumpSBSPFlags(UINT uflags)
87 if (TRACE_ON(commdlg))
89 unsigned int i;
90 static const struct {
91 DWORD mask;
92 const char *name;
93 } flags[] = {
94 #define FE(x) { x, #x}
95 /* SBSP_DEFBROWSER == 0 */
96 FE(SBSP_SAMEBROWSER),
97 FE(SBSP_NEWBROWSER),
99 /* SBSP_DEFMODE == 0 */
100 FE(SBSP_OPENMODE),
101 FE(SBSP_EXPLOREMODE),
102 FE(SBSP_HELPMODE),
103 FE(SBSP_NOTRANSFERHIST),
105 /* SBSP_ABSOLUTE == 0 */
106 FE(SBSP_RELATIVE),
107 FE(SBSP_PARENT),
108 FE(SBSP_NAVIGATEBACK),
109 FE(SBSP_NAVIGATEFORWARD),
110 FE(SBSP_ALLOW_AUTONAVIGATE),
112 FE(SBSP_NOAUTOSELECT),
113 FE(SBSP_WRITENOHISTORY),
115 FE(SBSP_REDIRECT),
116 FE(SBSP_INITIATEDBYHLINKFRAME),
118 #undef FE
119 TRACE("SBSP Flags: %08x =", uflags);
120 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
121 if (flags[i].mask & uflags)
122 TRACE("%s ", flags[i].name);
123 TRACE("\n");
127 static void COMDLG32_UpdateCurrentDir(const FileOpenDlgInfos *fodInfos)
129 LPSHELLFOLDER psfDesktop;
130 STRRET strret;
131 HRESULT res;
133 res = SHGetDesktopFolder(&psfDesktop);
134 if (FAILED(res))
135 return;
137 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
138 SHGDN_FORPARSING, &strret);
139 if (SUCCEEDED(res)) {
140 WCHAR wszCurrentDir[MAX_PATH];
142 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
143 if (SUCCEEDED(res))
144 SetCurrentDirectoryW(wszCurrentDir);
147 IShellFolder_Release(psfDesktop);
150 /* copied from shell32 to avoid linking to it */
151 static BOOL COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
153 TRACE("dest=%p len=0x%x strret=%p pidl=%p stub\n",dest,len,src,pidl);
155 switch (src->uType)
157 case STRRET_WSTR:
158 lstrcpynW(dest, src->u.pOleStr, len);
159 COMDLG32_SHFree(src->u.pOleStr);
160 break;
162 case STRRET_CSTR:
163 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ))
164 ((LPWSTR)dest)[len-1] = 0;
165 break;
167 case STRRET_OFFSET:
168 if (pidl)
170 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
171 -1, dest, len ))
172 ((LPWSTR)dest)[len-1] = 0;
174 break;
176 default:
177 FIXME("unknown type!\n");
178 if (len)
179 { *(LPWSTR)dest = '\0';
181 return(FALSE);
183 return TRUE;
187 * IShellBrowser
190 /**************************************************************************
191 * IShellBrowserImpl_Construct
193 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
195 IShellBrowserImpl *sb;
196 FileOpenDlgInfos *fodInfos = GetPropA(hwndOwner,FileOpenDlgInfosStr);
198 sb = COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
200 /* Initialisation of the member variables */
201 sb->ref=1;
202 sb->hwndOwner = hwndOwner;
204 /* Initialisation of the vTables */
205 sb->IShellBrowser_iface.lpVtbl = &IShellBrowserImpl_Vtbl;
206 sb->ICommDlgBrowser_iface.lpVtbl = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
207 sb->IServiceProvider_iface.lpVtbl = &IShellBrowserImpl_IServiceProvider_Vtbl;
208 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
209 &fodInfos->ShellInfos.pidlAbsCurrent);
211 TRACE("%p\n", sb);
213 return &sb->IShellBrowser_iface;
216 /***************************************************************************
217 * IShellBrowserImpl_QueryInterface
219 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
220 REFIID riid,
221 LPVOID *ppvObj)
223 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
225 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
227 *ppvObj = NULL;
229 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
230 { *ppvObj = This;
232 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
233 { *ppvObj = This;
236 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
237 { *ppvObj = This;
240 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
241 *ppvObj = &This->ICommDlgBrowser_iface;
242 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
243 *ppvObj = &This->IServiceProvider_iface;
245 if(*ppvObj)
246 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
247 return S_OK;
249 FIXME("Unknown interface requested\n");
250 return E_NOINTERFACE;
253 /**************************************************************************
254 * IShellBrowser::AddRef
256 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
258 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
259 ULONG ref = InterlockedIncrement(&This->ref);
261 TRACE("(%p,%u)\n", This, ref - 1);
263 return ref;
266 /**************************************************************************
267 * IShellBrowserImpl_Release
269 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
271 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
272 ULONG ref = InterlockedDecrement(&This->ref);
274 TRACE("(%p,%u)\n", This, ref + 1);
276 if (!ref)
278 COMDLG32_SHFree(This);
279 TRACE("-- destroyed\n");
280 return 0;
282 return ref;
286 * IOleWindow
289 /**************************************************************************
290 * IShellBrowserImpl_GetWindow (IOleWindow)
292 * Inherited from IOleWindow::GetWindow
294 * See Windows documentation for more details
296 * Note : We will never be window less in the File Open dialog
299 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
300 HWND * phwnd)
302 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
304 TRACE("(%p)\n", This);
306 if(!This->hwndOwner)
307 return E_FAIL;
309 *phwnd = This->hwndOwner;
311 return (*phwnd) ? S_OK : E_UNEXPECTED;
315 /**************************************************************************
316 * IShellBrowserImpl_ContextSensitiveHelp
318 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
319 BOOL fEnterMode)
321 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
323 TRACE("(%p)\n", This);
325 /* Feature not implemented */
326 return E_NOTIMPL;
330 * IShellBrowser
333 /**************************************************************************
334 * IShellBrowserImpl_BrowseObject
336 * See Windows documentation on IShellBrowser::BrowseObject for more details
338 * This function will override user specified flags and will always
339 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
341 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
342 LPCITEMIDLIST pidl,
343 UINT wFlags)
345 HRESULT hRes;
346 IShellFolder *psfTmp;
347 IShellView *psvTmp;
348 FileOpenDlgInfos *fodInfos;
349 LPITEMIDLIST pidlTmp;
350 HWND hwndView;
351 HWND hDlgWnd;
352 BOOL bViewHasFocus;
353 RECT rectView;
355 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
357 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
358 COMDLG32_DumpSBSPFlags(wFlags);
360 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
362 /* Format the pidl according to its parameter's category */
363 if(wFlags & SBSP_RELATIVE)
366 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
367 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
368 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
370 ERR("bind to object failed\n");
371 return hRes;
373 /* create an absolute pidl */
374 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent, pidl);
376 else if(wFlags & SBSP_PARENT)
378 /* Browse the parent folder (ignores the pidl) */
379 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
380 psfTmp = GetShellFolderFromPidl(pidlTmp);
383 else /* SBSP_ABSOLUTE is 0x0000 */
385 /* An absolute pidl (relative from the desktop) */
386 pidlTmp = COMDLG32_PIDL_ILClone(pidl);
387 psfTmp = GetShellFolderFromPidl(pidlTmp);
390 if(!psfTmp)
392 ERR("could not browse to folder\n");
393 return E_FAIL;
396 /* If the pidl to browse to is equal to the actual pidl ...
397 do nothing and pretend you did it*/
398 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
400 IShellFolder_Release(psfTmp);
401 COMDLG32_SHFree(pidlTmp);
402 TRACE("keep current folder\n");
403 return NOERROR;
406 /* Release the current DataObject */
407 if (fodInfos->Shell.FOIDataObject)
409 IDataObject_Release(fodInfos->Shell.FOIDataObject);
410 fodInfos->Shell.FOIDataObject = NULL;
413 /* Create the associated view */
414 TRACE("create view object\n");
415 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
416 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
418 /* Check if listview has focus */
419 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
421 /* Get the foldersettings from the old view */
422 if(fodInfos->Shell.FOIShellView)
423 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
425 /* Release the old fodInfos->Shell.FOIShellView and update its value.
426 We have to update this early since ShellView_CreateViewWindow of native
427 shell32 calls OnStateChange and needs the correct view here.*/
428 if(fodInfos->Shell.FOIShellView)
430 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
431 IShellView_Release(fodInfos->Shell.FOIShellView);
433 fodInfos->Shell.FOIShellView = psvTmp;
435 /* Release old FOIShellFolder and update its value */
436 if (fodInfos->Shell.FOIShellFolder)
437 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
438 fodInfos->Shell.FOIShellFolder = psfTmp;
440 /* Release old pidlAbsCurrent and update its value */
441 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
442 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
444 COMDLG32_UpdateCurrentDir(fodInfos);
446 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
447 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
449 /* Create the window */
450 TRACE("create view window\n");
451 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
452 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
453 &rectView, &hwndView))) goto error;
455 fodInfos->ShellInfos.hwndView = hwndView;
457 /* Set view window control id to 5002 */
458 SetWindowLongPtrW(hwndView, GWLP_ID, lst2);
460 /* Select the new folder in the Look In combo box of the Open file dialog */
461 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
463 /* changes the tab order of the ListView to reflect the window's File Dialog */
464 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
465 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
467 /* Since we destroyed the old view if it had focus set focus to the newly created view */
468 if (bViewHasFocus)
469 SetFocus(fodInfos->ShellInfos.hwndView);
471 return hRes;
472 error:
473 ERR("Failed with error 0x%08x\n", hRes);
474 return hRes;
477 /**************************************************************************
478 * IShellBrowserImpl_EnableModelessSB
480 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
481 BOOL fEnable)
484 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
486 TRACE("(%p)\n", This);
488 /* Feature not implemented */
489 return E_NOTIMPL;
492 /**************************************************************************
493 * IShellBrowserImpl_GetControlWindow
495 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
496 UINT id,
497 HWND *lphwnd)
500 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
502 TRACE("(%p)\n", This);
504 /* Feature not implemented */
505 return E_NOTIMPL;
508 /**************************************************************************
509 * IShellBrowserImpl_GetViewStateStream
511 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
512 DWORD grfMode,
513 LPSTREAM *ppStrm)
516 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
518 FIXME("(%p 0x%08x %p)\n", This, grfMode, ppStrm);
520 /* Feature not implemented */
521 return E_NOTIMPL;
524 /**************************************************************************
525 * IShellBrowserImpl_InsertMenusSB
527 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
528 HMENU hmenuShared,
529 LPOLEMENUGROUPWIDTHS lpMenuWidths)
532 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
534 TRACE("(%p)\n", This);
536 /* Feature not implemented */
537 return E_NOTIMPL;
540 /**************************************************************************
541 * IShellBrowserImpl_OnViewWindowActive
543 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
544 IShellView *ppshv)
547 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
549 TRACE("(%p)\n", This);
551 /* Feature not implemented */
552 return E_NOTIMPL;
555 /**************************************************************************
556 * IShellBrowserImpl_QueryActiveShellView
558 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
559 IShellView **ppshv)
562 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
564 FileOpenDlgInfos *fodInfos;
566 TRACE("(%p)\n", This);
568 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
570 if(!(*ppshv = fodInfos->Shell.FOIShellView))
572 return E_FAIL;
574 IShellView_AddRef(fodInfos->Shell.FOIShellView);
575 return NOERROR;
578 /**************************************************************************
579 * IShellBrowserImpl_RemoveMenusSB
581 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
582 HMENU hmenuShared)
585 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
587 TRACE("(%p)\n", This);
589 /* Feature not implemented */
590 return E_NOTIMPL;
593 /**************************************************************************
594 * IShellBrowserImpl_SendControlMsg
596 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
597 UINT id,
598 UINT uMsg,
599 WPARAM wParam,
600 LPARAM lParam,
601 LRESULT *pret)
604 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
605 LRESULT lres;
607 TRACE("(%p)->(0x%08x 0x%08x 0x%08lx 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
609 switch (id)
611 case FCW_TOOLBAR:
612 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
613 break;
614 default:
615 FIXME("ctrl id: %x\n", id);
616 return E_NOTIMPL;
618 if (pret) *pret = lres;
619 return S_OK;
622 /**************************************************************************
623 * IShellBrowserImpl_SetMenuSB
625 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
626 HMENU hmenuShared,
627 HOLEMENU holemenuReserved,
628 HWND hwndActiveObject)
631 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
633 TRACE("(%p)\n", This);
635 /* Feature not implemented */
636 return E_NOTIMPL;
639 /**************************************************************************
640 * IShellBrowserImpl_SetStatusTextSB
642 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
643 LPCOLESTR lpszStatusText)
646 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
648 TRACE("(%p)\n", This);
650 /* Feature not implemented */
651 return E_NOTIMPL;
654 /**************************************************************************
655 * IShellBrowserImpl_SetToolbarItems
657 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
658 LPTBBUTTON lpButtons,
659 UINT nButtons,
660 UINT uFlags)
663 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
665 TRACE("(%p)\n", This);
667 /* Feature not implemented */
668 return E_NOTIMPL;
671 /**************************************************************************
672 * IShellBrowserImpl_TranslateAcceleratorSB
674 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
675 LPMSG lpmsg,
676 WORD wID)
679 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
681 TRACE("(%p)\n", This);
683 /* Feature not implemented */
684 return E_NOTIMPL;
687 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
689 /* IUnknown */
690 IShellBrowserImpl_QueryInterface,
691 IShellBrowserImpl_AddRef,
692 IShellBrowserImpl_Release,
693 /* IOleWindow */
694 IShellBrowserImpl_GetWindow,
695 IShellBrowserImpl_ContextSensitiveHelp,
696 /* IShellBrowser */
697 IShellBrowserImpl_InsertMenusSB,
698 IShellBrowserImpl_SetMenuSB,
699 IShellBrowserImpl_RemoveMenusSB,
700 IShellBrowserImpl_SetStatusTextSB,
701 IShellBrowserImpl_EnableModelessSB,
702 IShellBrowserImpl_TranslateAcceleratorSB,
703 IShellBrowserImpl_BrowseObject,
704 IShellBrowserImpl_GetViewStateStream,
705 IShellBrowserImpl_GetControlWindow,
706 IShellBrowserImpl_SendControlMsg,
707 IShellBrowserImpl_QueryActiveShellView,
708 IShellBrowserImpl_OnViewWindowActive,
709 IShellBrowserImpl_SetToolbarItems
715 * ICommDlgBrowser
718 /***************************************************************************
719 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
721 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
722 ICommDlgBrowser *iface,
723 REFIID riid,
724 LPVOID *ppvObj)
726 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
728 TRACE("(%p)\n", This);
730 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
733 /**************************************************************************
734 * IShellBrowserImpl_ICommDlgBrowser_AddRef
736 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
738 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
740 TRACE("(%p)\n", This);
742 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
745 /**************************************************************************
746 * IShellBrowserImpl_ICommDlgBrowser_Release
748 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
750 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
752 TRACE("(%p)\n", This);
754 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
757 /**************************************************************************
758 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
760 * Called when a user double-clicks in the view or presses the ENTER key
762 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
763 IShellView *ppshv)
765 LPITEMIDLIST pidl;
766 FileOpenDlgInfos *fodInfos;
768 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
770 TRACE("(%p)\n", This);
772 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
774 /* If the selected object is not a folder, send an IDOK command to parent window */
775 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
777 HRESULT hRes;
779 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
780 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
781 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
783 hRes = IShellBrowser_BrowseObject(&This->IShellBrowser_iface,pidl,SBSP_RELATIVE);
784 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
785 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
787 else
789 /* Tell the dialog that the user selected a file */
790 PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
791 hRes = S_OK;
794 /* Free memory used by pidl */
795 COMDLG32_SHFree(pidl);
797 return hRes;
800 return E_FAIL;
803 /**************************************************************************
804 * IShellBrowserImpl_OnSelChange
806 static HRESULT IShellBrowserImpl_OnSelChange(IShellBrowserImpl *This, const IShellView *ppshv)
808 FileOpenDlgInfos *fodInfos;
810 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
811 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
813 /* release old selections */
814 if (fodInfos->Shell.FOIDataObject)
815 IDataObject_Release(fodInfos->Shell.FOIDataObject);
817 /* get a new DataObject from the ShellView */
818 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
819 &IID_IDataObject, (void**)&fodInfos->Shell.FOIDataObject)))
820 return E_FAIL;
822 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
824 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
825 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
826 return S_OK;
829 /**************************************************************************
830 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
832 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
833 IShellView *ppshv,
834 ULONG uChange)
837 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
839 TRACE("(%p shv=%p)\n", This, ppshv);
841 switch (uChange)
843 case CDBOSC_SETFOCUS:
844 /* FIXME: Reset the default button.
845 This should be taken care of by defdlg. If control
846 other than button receives focus the default button
847 should be restored. */
848 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
850 break;
851 case CDBOSC_KILLFOCUS:
853 FileOpenDlgInfos *fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
854 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
856 WCHAR szSave[16];
857 LoadStringW(COMDLG32_hInstance, IDS_SAVE_BUTTON, szSave, sizeof(szSave)/sizeof(WCHAR));
858 SetDlgItemTextW(fodInfos->ShellInfos.hwndOwner, IDOK, szSave);
861 break;
862 case CDBOSC_SELCHANGE:
863 return IShellBrowserImpl_OnSelChange(This, ppshv);
864 case CDBOSC_RENAME:
865 /* nothing to do */
866 break;
869 return NOERROR;
872 /* send_includeitem_notification
874 * Sends a CDN_INCLUDEITEM notification for "pidl" to hwndParentDlg
876 static LRESULT send_includeitem_notification(HWND hwndParentDlg, LPCITEMIDLIST pidl)
878 LRESULT hook_result = 0;
879 FileOpenDlgInfos *fodInfos = GetPropA(hwndParentDlg, FileOpenDlgInfosStr);
881 if(!fodInfos) return 0;
883 if(fodInfos->DlgInfos.hwndCustomDlg)
885 TRACE("call notify CDN_INCLUDEITEM for pidl=%p\n", pidl);
886 if(fodInfos->unicode)
888 OFNOTIFYEXW ofnNotify;
889 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
890 ofnNotify.pidl = (LPITEMIDLIST)pidl;
891 ofnNotify.hdr.hwndFrom = hwndParentDlg;
892 ofnNotify.hdr.idFrom = 0;
893 ofnNotify.hdr.code = CDN_INCLUDEITEM;
894 ofnNotify.lpOFN = fodInfos->ofnInfos;
895 hook_result = SendMessageW(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
897 else
899 OFNOTIFYEXA ofnNotify;
900 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
901 ofnNotify.pidl = (LPITEMIDLIST)pidl;
902 ofnNotify.hdr.hwndFrom = hwndParentDlg;
903 ofnNotify.hdr.idFrom = 0;
904 ofnNotify.hdr.code = CDN_INCLUDEITEM;
905 ofnNotify.lpOFN = (LPOPENFILENAMEA)fodInfos->ofnInfos;
906 hook_result = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
909 TRACE("Retval: 0x%08lx\n", hook_result);
910 return hook_result;
913 /**************************************************************************
914 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
916 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
917 IShellView * ppshv,
918 LPCITEMIDLIST pidl)
920 FileOpenDlgInfos *fodInfos;
921 ULONG ulAttr;
922 STRRET str;
923 WCHAR szPathW[MAX_PATH];
925 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
927 TRACE("(%p)\n", This);
929 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
931 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
932 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
934 if( (ulAttr & SFGAO_HIDDEN) || /* hidden */
935 !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
936 return S_FALSE;
938 /* always include directories and links */
939 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
940 return S_OK;
942 /* if the application takes care of including the item we are done */
943 if(fodInfos->ofnInfos->Flags & OFN_ENABLEINCLUDENOTIFY &&
944 send_includeitem_notification(This->hwndOwner, pidl))
945 return S_OK;
947 /* Check if there is a mask to apply if not */
948 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
949 return S_OK;
951 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
953 if (COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl))
955 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
956 return S_OK;
959 return S_FALSE;
963 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
965 /* IUnknown */
966 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
967 IShellBrowserImpl_ICommDlgBrowser_AddRef,
968 IShellBrowserImpl_ICommDlgBrowser_Release,
969 /* ICommDlgBrowser */
970 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
971 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
972 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
979 * IServiceProvider
982 /***************************************************************************
983 * IShellBrowserImpl_IServiceProvider_QueryInterface
985 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
986 IServiceProvider *iface,
987 REFIID riid,
988 LPVOID *ppvObj)
990 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
992 FIXME("(%p)\n", This);
994 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
997 /**************************************************************************
998 * IShellBrowserImpl_IServiceProvider_AddRef
1000 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
1002 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1004 FIXME("(%p)\n", This);
1006 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
1009 /**************************************************************************
1010 * IShellBrowserImpl_IServiceProvider_Release
1012 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
1014 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1016 FIXME("(%p)\n", This);
1018 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
1021 /**************************************************************************
1022 * IShellBrowserImpl_IServiceProvider_Release
1024 * NOTES
1025 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
1026 * riid = IShellBrowser) to call SendControlMsg ().
1028 * FIXME
1029 * this is a hack!
1032 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
1033 IServiceProvider * iface,
1034 REFGUID guidService,
1035 REFIID riid,
1036 void** ppv)
1038 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1040 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
1042 *ppv = NULL;
1043 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
1044 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppv);
1046 FIXME("(%p) unknown interface requested\n", This);
1047 return E_NOINTERFACE;
1051 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
1053 /* IUnknown */
1054 IShellBrowserImpl_IServiceProvider_QueryInterface,
1055 IShellBrowserImpl_IServiceProvider_AddRef,
1056 IShellBrowserImpl_IServiceProvider_Release,
1057 /* IServiceProvider */
1058 IShellBrowserImpl_IServiceProvider_QueryService