include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / comdlg32 / filedlgbrowser.c
blob14a9da91dc7fbbbe9427a116568ec5af1e149461
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 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winreg.h"
34 #define NO_SHLWAPI_STREAM
35 #include "shlwapi.h"
36 #include "filedlgbrowser.h"
37 #include "cdlg.h"
38 #include "shlguid.h"
39 #include "servprov.h"
40 #include "wine/debug.h"
41 #include "wine/heap.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
45 typedef struct
48 IShellBrowser IShellBrowser_iface;
49 ICommDlgBrowser ICommDlgBrowser_iface;
50 IServiceProvider IServiceProvider_iface;
51 LONG ref; /* Reference counter */
52 HWND hwndOwner; /* Owner dialog of the interface */
54 } IShellBrowserImpl;
56 static inline IShellBrowserImpl *impl_from_IShellBrowser(IShellBrowser *iface)
58 return CONTAINING_RECORD(iface, IShellBrowserImpl, IShellBrowser_iface);
61 static inline IShellBrowserImpl *impl_from_ICommDlgBrowser( ICommDlgBrowser *iface )
63 return CONTAINING_RECORD(iface, IShellBrowserImpl, ICommDlgBrowser_iface);
66 static inline IShellBrowserImpl *impl_from_IServiceProvider( IServiceProvider *iface )
68 return CONTAINING_RECORD(iface, IShellBrowserImpl, IServiceProvider_iface);
71 /**************************************************************************
72 * vtable
74 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
75 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
76 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
79 * Helper functions
82 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
83 static void COMDLG32_DumpSBSPFlags(UINT uflags)
85 if (TRACE_ON(commdlg))
87 unsigned int i;
88 static const struct {
89 DWORD mask;
90 const char *name;
91 } flags[] = {
92 #define FE(x) { x, #x}
93 /* SBSP_DEFBROWSER == 0 */
94 FE(SBSP_SAMEBROWSER),
95 FE(SBSP_NEWBROWSER),
97 /* SBSP_DEFMODE == 0 */
98 FE(SBSP_OPENMODE),
99 FE(SBSP_EXPLOREMODE),
100 FE(SBSP_HELPMODE),
101 FE(SBSP_NOTRANSFERHIST),
103 /* SBSP_ABSOLUTE == 0 */
104 FE(SBSP_RELATIVE),
105 FE(SBSP_PARENT),
106 FE(SBSP_NAVIGATEBACK),
107 FE(SBSP_NAVIGATEFORWARD),
108 FE(SBSP_ALLOW_AUTONAVIGATE),
110 FE(SBSP_NOAUTOSELECT),
111 FE(SBSP_WRITENOHISTORY),
113 FE(SBSP_REDIRECT),
114 FE(SBSP_INITIATEDBYHLINKFRAME),
116 #undef FE
117 TRACE("SBSP Flags: %08x =", uflags);
118 for (i = 0; i < ARRAY_SIZE(flags); i++)
119 if (flags[i].mask & uflags)
120 TRACE("%s ", flags[i].name);
121 TRACE("\n");
125 static void COMDLG32_UpdateCurrentDir(const FileOpenDlgInfos *fodInfos)
127 LPSHELLFOLDER psfDesktop;
128 STRRET strret;
129 HRESULT res;
131 res = SHGetDesktopFolder(&psfDesktop);
132 if (FAILED(res))
133 return;
135 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
136 SHGDN_FORPARSING, &strret);
137 if (SUCCEEDED(res)) {
138 WCHAR wszCurrentDir[MAX_PATH];
140 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
141 if (SUCCEEDED(res))
142 SetCurrentDirectoryW(wszCurrentDir);
145 IShellFolder_Release(psfDesktop);
148 /* copied from shell32 to avoid linking to it */
149 static BOOL COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
151 TRACE("dest=%p len=0x%lx strret=%p pidl=%p\n", dest , len, src, pidl);
153 switch (src->uType)
155 case STRRET_WSTR:
156 lstrcpynW(dest, src->pOleStr, len);
157 CoTaskMemFree(src->pOleStr);
158 break;
160 case STRRET_CSTR:
161 if (len && !MultiByteToWideChar( CP_ACP, 0, src->cStr, -1, dest, len ))
162 ((LPWSTR)dest)[len-1] = 0;
163 break;
165 case STRRET_OFFSET:
166 if (pidl)
168 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->uOffset,
169 -1, dest, len ))
170 ((LPWSTR)dest)[len-1] = 0;
172 break;
174 default:
175 FIXME("unknown type!\n");
176 if (len)
177 { *(LPWSTR)dest = '\0';
179 return(FALSE);
181 return TRUE;
185 * IShellBrowser
188 /**************************************************************************
189 * IShellBrowserImpl_Construct
191 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
193 FileOpenDlgInfos *fodInfos = get_filedlg_infoptr(hwndOwner);
194 IShellBrowserImpl *sb;
196 sb = heap_alloc(sizeof(*sb));
198 /* Initialisation of the member variables */
199 sb->ref=1;
200 sb->hwndOwner = hwndOwner;
202 /* Initialisation of the vTables */
203 sb->IShellBrowser_iface.lpVtbl = &IShellBrowserImpl_Vtbl;
204 sb->ICommDlgBrowser_iface.lpVtbl = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
205 sb->IServiceProvider_iface.lpVtbl = &IShellBrowserImpl_IServiceProvider_Vtbl;
206 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
207 &fodInfos->ShellInfos.pidlAbsCurrent);
209 TRACE("%p\n", sb);
211 return &sb->IShellBrowser_iface;
214 /***************************************************************************
215 * IShellBrowserImpl_QueryInterface
217 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface, REFIID riid, void **ppvObj)
219 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
221 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
223 *ppvObj = NULL;
225 if(IsEqualIID(riid, &IID_IUnknown))
226 *ppvObj = &This->IShellBrowser_iface;
227 else if(IsEqualIID(riid, &IID_IOleWindow))
228 *ppvObj = &This->IShellBrowser_iface;
229 else if(IsEqualIID(riid, &IID_IShellBrowser))
230 *ppvObj = &This->IShellBrowser_iface;
231 else if(IsEqualIID(riid, &IID_ICommDlgBrowser))
232 *ppvObj = &This->ICommDlgBrowser_iface;
233 else if(IsEqualIID(riid, &IID_IServiceProvider))
234 *ppvObj = &This->IServiceProvider_iface;
236 if(*ppvObj) {
237 IUnknown_AddRef((IUnknown*)*ppvObj);
238 return S_OK;
241 FIXME("unsupported interface, %s\n", debugstr_guid(riid));
242 return E_NOINTERFACE;
245 /**************************************************************************
246 * IShellBrowser::AddRef
248 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
250 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
251 ULONG ref = InterlockedIncrement(&This->ref);
253 TRACE("(%p,%lu)\n", This, ref - 1);
255 return ref;
258 /**************************************************************************
259 * IShellBrowserImpl_Release
261 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
263 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
264 ULONG ref = InterlockedDecrement(&This->ref);
266 TRACE("(%p,%lu)\n", This, ref + 1);
268 if (!ref)
269 heap_free(This);
271 return ref;
275 * IOleWindow
278 /**************************************************************************
279 * IShellBrowserImpl_GetWindow (IOleWindow)
281 * Inherited from IOleWindow::GetWindow
283 * See Windows documentation for more details
285 * Note : We will never be window less in the File Open dialog
288 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
289 HWND * phwnd)
291 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
293 TRACE("(%p)\n", This);
295 if(!This->hwndOwner)
296 return E_FAIL;
298 *phwnd = This->hwndOwner;
300 return (*phwnd) ? S_OK : E_UNEXPECTED;
304 /**************************************************************************
305 * IShellBrowserImpl_ContextSensitiveHelp
307 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
308 BOOL fEnterMode)
310 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
312 TRACE("(%p)\n", This);
314 /* Feature not implemented */
315 return E_NOTIMPL;
319 * IShellBrowser
322 /**************************************************************************
323 * IShellBrowserImpl_BrowseObject
325 * See Windows documentation on IShellBrowser::BrowseObject for more details
327 * This function will override user specified flags and will always
328 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
330 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
331 LPCITEMIDLIST pidl,
332 UINT wFlags)
334 HRESULT hRes;
335 IShellFolder *folder;
336 IShellView *psvTmp;
337 FileOpenDlgInfos *fodInfos;
338 LPITEMIDLIST pidlTmp;
339 HWND hwndView;
340 HWND hDlgWnd;
341 BOOL bViewHasFocus;
342 RECT rectView;
344 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
346 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
347 COMDLG32_DumpSBSPFlags(wFlags);
349 fodInfos = get_filedlg_infoptr(This->hwndOwner);
351 /* Format the pidl according to its parameter's category */
352 if(wFlags & SBSP_RELATIVE)
355 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
356 if (FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
357 pidl, NULL, &IID_IShellFolder, (void **)&folder)))
359 ERR("bind to object failed\n");
360 return hRes;
362 /* create an absolute pidl */
363 pidlTmp = ILCombine(fodInfos->ShellInfos.pidlAbsCurrent, pidl);
365 else if(wFlags & SBSP_PARENT)
367 /* Browse the parent folder (ignores the pidl) */
368 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
369 folder = GetShellFolderFromPidl(pidlTmp);
371 else /* SBSP_ABSOLUTE is 0x0000 */
373 /* An absolute pidl (relative from the desktop) */
374 pidlTmp = ILClone(pidl);
375 folder = GetShellFolderFromPidl(pidlTmp);
378 if (!folder)
380 ERR("could not browse to folder\n");
381 ILFree(pidlTmp);
382 return E_FAIL;
385 /* If the pidl to browse to is equal to the actual pidl ...
386 do nothing and pretend you did it*/
387 if (ILIsEqual(pidlTmp, fodInfos->ShellInfos.pidlAbsCurrent))
389 IShellFolder_Release(folder);
390 ILFree(pidlTmp);
391 TRACE("keep current folder\n");
392 return S_OK;
395 /* Release the current DataObject */
396 if (fodInfos->Shell.FOIDataObject)
398 IDataObject_Release(fodInfos->Shell.FOIDataObject);
399 fodInfos->Shell.FOIDataObject = NULL;
402 /* Create the associated view */
403 TRACE("create view object\n");
404 if (FAILED(hRes = IShellFolder_CreateViewObject(folder, fodInfos->ShellInfos.hwndOwner,
405 &IID_IShellView, (void **)&psvTmp)))
407 IShellFolder_Release(folder);
408 ILFree(pidlTmp);
409 return hRes;
412 /* Check if listview has focus */
413 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
415 /* Get the foldersettings from the old view */
416 if(fodInfos->Shell.FOIShellView)
417 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
419 /* Release the old fodInfos->Shell.FOIShellView and update its value.
420 We have to update this early since ShellView_CreateViewWindow of native
421 shell32 calls OnStateChange and needs the correct view here.*/
422 if(fodInfos->Shell.FOIShellView)
424 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
425 IShellView_Release(fodInfos->Shell.FOIShellView);
427 fodInfos->Shell.FOIShellView = psvTmp;
429 /* Release old FOIShellFolder and update its value */
430 if (fodInfos->Shell.FOIShellFolder)
431 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
432 fodInfos->Shell.FOIShellFolder = folder;
434 /* Release old pidlAbsCurrent and update its value */
435 ILFree(fodInfos->ShellInfos.pidlAbsCurrent);
436 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
438 COMDLG32_UpdateCurrentDir(fodInfos);
440 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
441 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
443 /* Create the window */
444 TRACE("create view window\n");
445 if (FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
446 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
447 &rectView, &hwndView)))
449 WARN("Failed to create view window, hr %#lx.\n", hRes);
450 return hRes;
453 fodInfos->ShellInfos.hwndView = hwndView;
455 /* Set view window control id to 5002 */
456 SetWindowLongPtrW(hwndView, GWLP_ID, lst2);
457 SendMessageW( hwndView, WM_SETFONT, SendMessageW( GetParent(hwndView), WM_GETFONT, 0, 0 ), FALSE );
459 /* Select the new folder in the Look In combo box of the Open file dialog */
460 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
462 /* changes the tab order of the ListView to reflect the window's File Dialog */
463 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
464 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
466 /* Since we destroyed the old view if it had focus set focus to the newly created view */
467 if (bViewHasFocus)
468 SetFocus(fodInfos->ShellInfos.hwndView);
470 return hRes;
473 /**************************************************************************
474 * IShellBrowserImpl_EnableModelessSB
476 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
477 BOOL fEnable)
480 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
482 TRACE("(%p)\n", This);
484 /* Feature not implemented */
485 return E_NOTIMPL;
488 /**************************************************************************
489 * IShellBrowserImpl_GetControlWindow
491 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
492 UINT id,
493 HWND *lphwnd)
496 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
498 TRACE("(%p)\n", This);
500 /* Feature not implemented */
501 return E_NOTIMPL;
504 /**************************************************************************
505 * IShellBrowserImpl_GetViewStateStream
507 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
508 DWORD grfMode,
509 LPSTREAM *ppStrm)
512 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
514 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
516 /* Feature not implemented */
517 return E_NOTIMPL;
520 /**************************************************************************
521 * IShellBrowserImpl_InsertMenusSB
523 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
524 HMENU hmenuShared,
525 LPOLEMENUGROUPWIDTHS lpMenuWidths)
528 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
530 TRACE("(%p)\n", This);
532 /* Feature not implemented */
533 return E_NOTIMPL;
536 /**************************************************************************
537 * IShellBrowserImpl_OnViewWindowActive
539 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
540 IShellView *ppshv)
543 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
545 TRACE("(%p)\n", This);
547 /* Feature not implemented */
548 return E_NOTIMPL;
551 /**************************************************************************
552 * IShellBrowserImpl_QueryActiveShellView
554 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
555 IShellView **ppshv)
558 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
560 FileOpenDlgInfos *fodInfos;
562 TRACE("(%p)\n", This);
564 fodInfos = get_filedlg_infoptr(This->hwndOwner);
566 if(!(*ppshv = fodInfos->Shell.FOIShellView))
568 return E_FAIL;
570 IShellView_AddRef(fodInfos->Shell.FOIShellView);
571 return NOERROR;
574 /**************************************************************************
575 * IShellBrowserImpl_RemoveMenusSB
577 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
578 HMENU hmenuShared)
581 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
583 TRACE("(%p)\n", This);
585 /* Feature not implemented */
586 return E_NOTIMPL;
589 /**************************************************************************
590 * IShellBrowserImpl_SendControlMsg
592 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
593 UINT id,
594 UINT uMsg,
595 WPARAM wParam,
596 LPARAM lParam,
597 LRESULT *pret)
600 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
601 LRESULT lres;
603 TRACE("(%p)->(0x%08x 0x%08x 0x%08Ix 0x%08Ix %p)\n", This, id, uMsg, wParam, lParam, pret);
605 switch (id)
607 case FCW_TOOLBAR:
608 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
609 break;
610 default:
611 FIXME("ctrl id: %x\n", id);
612 return E_NOTIMPL;
614 if (pret) *pret = lres;
615 return S_OK;
618 /**************************************************************************
619 * IShellBrowserImpl_SetMenuSB
621 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
622 HMENU hmenuShared,
623 HOLEMENU holemenuReserved,
624 HWND hwndActiveObject)
627 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
629 TRACE("(%p)\n", This);
631 /* Feature not implemented */
632 return E_NOTIMPL;
635 /**************************************************************************
636 * IShellBrowserImpl_SetStatusTextSB
638 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
639 LPCOLESTR lpszStatusText)
642 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
644 TRACE("(%p)\n", This);
646 /* Feature not implemented */
647 return E_NOTIMPL;
650 /**************************************************************************
651 * IShellBrowserImpl_SetToolbarItems
653 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
654 LPTBBUTTON lpButtons,
655 UINT nButtons,
656 UINT uFlags)
659 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
661 TRACE("(%p)\n", This);
663 /* Feature not implemented */
664 return E_NOTIMPL;
667 /**************************************************************************
668 * IShellBrowserImpl_TranslateAcceleratorSB
670 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
671 LPMSG lpmsg,
672 WORD wID)
675 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
677 TRACE("(%p)\n", This);
679 /* Feature not implemented */
680 return E_NOTIMPL;
683 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
685 /* IUnknown */
686 IShellBrowserImpl_QueryInterface,
687 IShellBrowserImpl_AddRef,
688 IShellBrowserImpl_Release,
689 /* IOleWindow */
690 IShellBrowserImpl_GetWindow,
691 IShellBrowserImpl_ContextSensitiveHelp,
692 /* IShellBrowser */
693 IShellBrowserImpl_InsertMenusSB,
694 IShellBrowserImpl_SetMenuSB,
695 IShellBrowserImpl_RemoveMenusSB,
696 IShellBrowserImpl_SetStatusTextSB,
697 IShellBrowserImpl_EnableModelessSB,
698 IShellBrowserImpl_TranslateAcceleratorSB,
699 IShellBrowserImpl_BrowseObject,
700 IShellBrowserImpl_GetViewStateStream,
701 IShellBrowserImpl_GetControlWindow,
702 IShellBrowserImpl_SendControlMsg,
703 IShellBrowserImpl_QueryActiveShellView,
704 IShellBrowserImpl_OnViewWindowActive,
705 IShellBrowserImpl_SetToolbarItems
711 * ICommDlgBrowser
714 /***************************************************************************
715 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
717 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
718 ICommDlgBrowser *iface,
719 REFIID riid,
720 LPVOID *ppvObj)
722 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
724 TRACE("(%p)\n", This);
726 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
729 /**************************************************************************
730 * IShellBrowserImpl_ICommDlgBrowser_AddRef
732 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
734 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
736 TRACE("(%p)\n", This);
738 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
741 /**************************************************************************
742 * IShellBrowserImpl_ICommDlgBrowser_Release
744 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
746 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
748 TRACE("(%p)\n", This);
750 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
753 /**************************************************************************
754 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
756 * Called when a user double-clicks in the view or presses the ENTER key
758 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
759 IShellView *ppshv)
761 LPITEMIDLIST pidl;
762 FileOpenDlgInfos *fodInfos;
764 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
766 TRACE("(%p)\n", This);
768 fodInfos = get_filedlg_infoptr(This->hwndOwner);
770 /* If the selected object is not a folder, send an IDOK command to parent window */
771 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
773 HRESULT hRes;
775 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
776 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
777 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
779 hRes = IShellBrowser_BrowseObject(&This->IShellBrowser_iface,pidl,SBSP_RELATIVE);
780 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
781 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
783 else
785 /* Tell the dialog that the user selected a file */
786 PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
787 hRes = S_OK;
790 ILFree(pidl);
792 return hRes;
795 return E_FAIL;
798 /**************************************************************************
799 * IShellBrowserImpl_OnSelChange
801 static HRESULT IShellBrowserImpl_OnSelChange(IShellBrowserImpl *This, const IShellView *ppshv)
803 FileOpenDlgInfos *fodInfos;
805 fodInfos = get_filedlg_infoptr(This->hwndOwner);
806 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
808 /* release old selections */
809 if (fodInfos->Shell.FOIDataObject)
810 IDataObject_Release(fodInfos->Shell.FOIDataObject);
812 /* get a new DataObject from the ShellView */
813 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
814 &IID_IDataObject, (void**)&fodInfos->Shell.FOIDataObject)))
815 return E_FAIL;
817 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
819 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
820 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
821 return S_OK;
824 /**************************************************************************
825 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
827 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
828 IShellView *ppshv,
829 ULONG uChange)
832 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
834 TRACE("(%p shv=%p)\n", This, ppshv);
836 switch (uChange)
838 case CDBOSC_SETFOCUS:
839 /* FIXME: Reset the default button.
840 This should be taken care of by defdlg. If control
841 other than button receives focus the default button
842 should be restored. */
843 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
845 break;
846 case CDBOSC_KILLFOCUS:
848 FileOpenDlgInfos *fodInfos = get_filedlg_infoptr(This->hwndOwner);
849 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
851 WCHAR szSave[16];
852 LoadStringW(COMDLG32_hInstance, IDS_SAVE_BUTTON, szSave, ARRAY_SIZE(szSave));
853 SetDlgItemTextW(fodInfos->ShellInfos.hwndOwner, IDOK, szSave);
856 break;
857 case CDBOSC_SELCHANGE:
858 return IShellBrowserImpl_OnSelChange(This, ppshv);
859 case CDBOSC_RENAME:
860 /* nothing to do */
861 break;
864 return NOERROR;
867 /* send_includeitem_notification
869 * Sends a CDN_INCLUDEITEM notification for "pidl" to hwndParentDlg
871 static LRESULT send_includeitem_notification(HWND hwndParentDlg, LPCITEMIDLIST pidl)
873 LRESULT hook_result = 0;
874 FileOpenDlgInfos *fodInfos = get_filedlg_infoptr(hwndParentDlg);
876 if(!fodInfos) return 0;
878 if(fodInfos->DlgInfos.hwndCustomDlg)
880 TRACE("call notify CDN_INCLUDEITEM for pidl=%p\n", pidl);
881 if(fodInfos->unicode)
883 OFNOTIFYEXW ofnNotify;
884 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
885 ofnNotify.pidl = (LPITEMIDLIST)pidl;
886 ofnNotify.hdr.hwndFrom = hwndParentDlg;
887 ofnNotify.hdr.idFrom = 0;
888 ofnNotify.hdr.code = CDN_INCLUDEITEM;
889 ofnNotify.lpOFN = fodInfos->ofnInfos;
890 hook_result = SendMessageW(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
892 else
894 OFNOTIFYEXA ofnNotify;
895 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
896 ofnNotify.pidl = (LPITEMIDLIST)pidl;
897 ofnNotify.hdr.hwndFrom = hwndParentDlg;
898 ofnNotify.hdr.idFrom = 0;
899 ofnNotify.hdr.code = CDN_INCLUDEITEM;
900 ofnNotify.lpOFN = (LPOPENFILENAMEA)fodInfos->ofnInfos;
901 hook_result = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
904 TRACE("Retval: 0x%08Ix\n", hook_result);
905 return hook_result;
908 /**************************************************************************
909 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
911 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
912 IShellView * ppshv,
913 LPCITEMIDLIST pidl)
915 FileOpenDlgInfos *fodInfos;
916 ULONG ulAttr;
917 STRRET str;
918 WCHAR szPathW[MAX_PATH];
920 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
922 TRACE("(%p)\n", This);
924 fodInfos = get_filedlg_infoptr(This->hwndOwner);
926 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
927 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
929 if( (ulAttr & SFGAO_HIDDEN) || /* hidden */
930 !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
931 return S_FALSE;
933 /* always include directories and links */
934 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
935 return S_OK;
937 /* if the application takes care of including the item we are done */
938 if(fodInfos->ofnInfos->Flags & OFN_ENABLEINCLUDENOTIFY &&
939 send_includeitem_notification(This->hwndOwner, pidl))
940 return S_OK;
942 /* Check if there is a mask to apply if not */
943 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !fodInfos->ShellInfos.lpstrCurrentFilter[0])
944 return S_OK;
946 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
948 if (COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl))
950 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
951 return S_OK;
954 return S_FALSE;
958 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
960 /* IUnknown */
961 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
962 IShellBrowserImpl_ICommDlgBrowser_AddRef,
963 IShellBrowserImpl_ICommDlgBrowser_Release,
964 /* ICommDlgBrowser */
965 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
966 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
967 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
974 * IServiceProvider
977 /***************************************************************************
978 * IShellBrowserImpl_IServiceProvider_QueryInterface
980 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
981 IServiceProvider *iface,
982 REFIID riid,
983 LPVOID *ppvObj)
985 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
987 FIXME("(%p)\n", This);
989 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
992 /**************************************************************************
993 * IShellBrowserImpl_IServiceProvider_AddRef
995 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
997 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
999 FIXME("(%p)\n", This);
1001 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
1004 /**************************************************************************
1005 * IShellBrowserImpl_IServiceProvider_Release
1007 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
1009 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1011 FIXME("(%p)\n", This);
1013 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
1016 /**************************************************************************
1017 * IShellBrowserImpl_IServiceProvider_Release
1019 * NOTES
1020 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
1021 * riid = IShellBrowser) to call SendControlMsg ().
1023 * FIXME
1024 * this is a hack!
1027 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
1028 IServiceProvider * iface,
1029 REFGUID guidService,
1030 REFIID riid,
1031 void** ppv)
1033 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1035 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
1037 *ppv = NULL;
1038 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
1039 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppv);
1041 FIXME("(%p) unknown interface requested\n", This);
1042 return E_NOINTERFACE;
1046 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
1048 /* IUnknown */
1049 IShellBrowserImpl_IServiceProvider_QueryInterface,
1050 IShellBrowserImpl_IServiceProvider_AddRef,
1051 IShellBrowserImpl_IServiceProvider_Release,
1052 /* IServiceProvider */
1053 IShellBrowserImpl_IServiceProvider_QueryService