Fix declarations.
[wine/dcerpc.git] / dlls / commdlg / filedlgbrowser.c
blob529f314efc196f0e119c844a085239efd3f38e9a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 const IShellBrowserVtbl *lpVtbl;
51 const ICommDlgBrowserVtbl *lpVtblCommDlgBrowser;
52 const IServiceProviderVtbl *lpVtblServiceProvider;
53 DWORD ref; /* Reference counter */
54 HWND hwndOwner; /* Owner dialog of the interface */
56 } IShellBrowserImpl;
58 /**************************************************************************
59 * vtable
61 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
62 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
63 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
65 /**************************************************************************
66 * Local Prototypes
69 static HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
71 /**************************************************************************
72 * External Prototypes
74 extern const char *FileOpenDlgInfosStr;
76 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
77 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
78 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
80 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
81 extern void SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
85 * Helper functions
88 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
89 static void COMDLG32_DumpSBSPFlags(UINT uflags)
91 if (TRACE_ON(commdlg))
93 unsigned int i;
94 static const struct {
95 DWORD mask;
96 const char *name;
97 } flags[] = {
98 #define FE(x) { x, #x}
99 /* SBSP_DEFBROWSER == 0 */
100 FE(SBSP_SAMEBROWSER),
101 FE(SBSP_NEWBROWSER),
103 /* SBSP_DEFMODE == 0 */
104 FE(SBSP_OPENMODE),
105 FE(SBSP_EXPLOREMODE),
106 FE(SBSP_HELPMODE),
107 FE(SBSP_NOTRANSFERHIST),
109 /* SBSP_ABSOLUTE == 0 */
110 FE(SBSP_RELATIVE),
111 FE(SBSP_PARENT),
112 FE(SBSP_NAVIGATEBACK),
113 FE(SBSP_NAVIGATEFORWARD),
114 FE(SBSP_ALLOW_AUTONAVIGATE),
116 FE(SBSP_NOAUTOSELECT),
117 FE(SBSP_WRITENOHISTORY),
119 FE(SBSP_REDIRECT),
120 FE(SBSP_INITIATEDBYHLINKFRAME),
122 #undef FE
123 DPRINTF("SBSP Flags: %08x =", uflags);
124 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
125 if (flags[i].mask & uflags)
126 DPRINTF("%s ", flags[i].name);
127 DPRINTF("\n");
131 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
133 LPSHELLFOLDER psfDesktop;
134 STRRET strret;
135 HRESULT res;
137 res = SHGetDesktopFolder(&psfDesktop);
138 if (FAILED(res))
139 return;
141 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
142 SHGDN_FORPARSING, &strret);
143 if (SUCCEEDED(res)) {
144 WCHAR wszCurrentDir[MAX_PATH];
146 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
147 if (SUCCEEDED(res))
148 SetCurrentDirectoryW(wszCurrentDir);
151 IShellFolder_Release(psfDesktop);
154 /* copied from shell32 to avoid linking to it */
155 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
157 TRACE("dest=%p len=0x%lx strret=%p pidl=%p stub\n",dest,len,src,pidl);
159 switch (src->uType)
161 case STRRET_WSTR:
162 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
163 COMDLG32_SHFree(src->u.pOleStr);
164 break;
166 case STRRET_CSTR:
167 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
168 ((LPWSTR)dest)[len-1] = 0;
169 break;
171 case STRRET_OFFSET:
172 if (pidl)
174 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
175 -1, (LPWSTR)dest, len ))
176 ((LPWSTR)dest)[len-1] = 0;
178 break;
180 default:
181 FIXME("unknown type!\n");
182 if (len)
183 { *(LPWSTR)dest = '\0';
185 return(FALSE);
187 return S_OK;
191 * IShellBrowser
194 /**************************************************************************
195 * IShellBrowserImpl_Construct
197 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
199 IShellBrowserImpl *sb;
200 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
202 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
204 /* Initialisation of the member variables */
205 sb->ref=1;
206 sb->hwndOwner = hwndOwner;
208 /* Initialisation of the vTables */
209 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
210 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
211 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
212 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
213 &fodInfos->ShellInfos.pidlAbsCurrent);
215 TRACE("%p\n", sb);
217 return (IShellBrowser *) sb;
220 /***************************************************************************
221 * IShellBrowserImpl_QueryInterface
223 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
224 REFIID riid,
225 LPVOID *ppvObj)
227 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
229 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
231 *ppvObj = NULL;
233 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
234 { *ppvObj = This;
236 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
237 { *ppvObj = (IOleWindow*)This;
240 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
241 { *ppvObj = (IShellBrowser*)This;
244 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
245 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
248 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
249 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
252 if(*ppvObj)
253 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
254 return S_OK;
256 FIXME("Unknown interface requested\n");
257 return E_NOINTERFACE;
260 /**************************************************************************
261 * IShellBrowser::AddRef
263 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
265 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
266 ULONG ref = InterlockedIncrement(&This->ref);
268 TRACE("(%p,%lu)\n", This, ref - 1);
270 return ref;
273 /**************************************************************************
274 * IShellBrowserImpl_Release
276 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
278 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
279 ULONG ref = InterlockedDecrement(&This->ref);
281 TRACE("(%p,%lu)\n", This, ref + 1);
283 if (!ref)
285 COMDLG32_SHFree(This);
286 TRACE("-- destroyed\n");
287 return 0;
289 return ref;
293 * IOleWindow
296 /**************************************************************************
297 * IShellBrowserImpl_GetWindow (IOleWindow)
299 * Inherited from IOleWindow::GetWindow
301 * See Windows documentation for more details
303 * Note : We will never be window less in the File Open dialog
306 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
307 HWND * phwnd)
309 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
311 TRACE("(%p)\n", This);
313 if(!This->hwndOwner)
314 return E_FAIL;
316 *phwnd = This->hwndOwner;
318 return (*phwnd) ? S_OK : E_UNEXPECTED;
322 /**************************************************************************
323 * IShellBrowserImpl_ContextSensitiveHelp
325 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
326 BOOL fEnterMode)
328 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
330 TRACE("(%p)\n", This);
332 /* Feature not implemented */
333 return E_NOTIMPL;
337 * IShellBrowser
340 /**************************************************************************
341 * IShellBrowserImpl_BrowseObject
343 * See Windows documentation on IShellBrowser::BrowseObject for more details
345 * This function will override user specified flags and will always
346 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
348 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
349 LPCITEMIDLIST pidl,
350 UINT wFlags)
352 HRESULT hRes;
353 IShellFolder *psfTmp;
354 IShellView *psvTmp;
355 FileOpenDlgInfos *fodInfos;
356 LPITEMIDLIST pidlTmp;
357 HWND hwndView;
358 HWND hDlgWnd;
359 BOOL bViewHasFocus;
360 RECT rectView;
362 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
364 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
365 COMDLG32_DumpSBSPFlags(wFlags);
367 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
369 /* Format the pidl according to its parameter's category */
370 if(wFlags & SBSP_RELATIVE)
373 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
374 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
375 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
377 ERR("bind to object failed\n");
378 return hRes;
380 /* create an absolute pidl */
381 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
382 (LPITEMIDLIST)pidl);
384 else if(wFlags & SBSP_PARENT)
386 /* Browse the parent folder (ignores the pidl) */
387 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
388 psfTmp = GetShellFolderFromPidl(pidlTmp);
391 else /* SBSP_ABSOLUTE is 0x0000 */
393 /* An absolute pidl (relative from the desktop) */
394 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
395 psfTmp = GetShellFolderFromPidl(pidlTmp);
398 if(!psfTmp)
400 ERR("could not browse to folder\n");
401 return E_FAIL;
404 /* If the pidl to browse to is equal to the actual pidl ...
405 do nothing and pretend you did it*/
406 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
408 IShellFolder_Release(psfTmp);
409 COMDLG32_SHFree(pidlTmp);
410 TRACE("keep current folder\n");
411 return NOERROR;
414 /* Release the current DataObject */
415 if (fodInfos->Shell.FOIDataObject)
417 IDataObject_Release(fodInfos->Shell.FOIDataObject);
418 fodInfos->Shell.FOIDataObject = NULL;
421 /* Create the associated view */
422 TRACE("create view object\n");
423 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
424 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
426 /* Check if listview has focus */
427 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
429 /* Get the foldersettings from the old view */
430 if(fodInfos->Shell.FOIShellView)
431 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
433 /* Release the old fodInfos->Shell.FOIShellView and update its value.
434 We have to update this early since ShellView_CreateViewWindow of native
435 shell32 calls OnStateChange and needs the correct view here.*/
436 if(fodInfos->Shell.FOIShellView)
438 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
439 IShellView_Release(fodInfos->Shell.FOIShellView);
441 fodInfos->Shell.FOIShellView = psvTmp;
443 /* Release old FOIShellFolder and update its value */
444 if (fodInfos->Shell.FOIShellFolder)
445 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
446 fodInfos->Shell.FOIShellFolder = psfTmp;
448 /* Release old pidlAbsCurrent and update its value */
449 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
450 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
452 COMDLG32_UpdateCurrentDir(fodInfos);
454 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
455 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
457 /* Create the window */
458 TRACE("create view window\n");
459 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
460 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
461 &rectView, &hwndView))) goto error;
463 fodInfos->ShellInfos.hwndView = hwndView;
465 /* Select the new folder in the Look In combo box of the Open file dialog */
466 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
468 /* changes the tab order of the ListView to reflect the window's File Dialog */
469 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
470 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
472 /* Since we destroyed the old view if it had focus set focus to the newly created view */
473 if (bViewHasFocus)
474 SetFocus(fodInfos->ShellInfos.hwndView);
476 return hRes;
477 error:
478 ERR("Failed with error 0x%08lx\n", hRes);
479 return hRes;
482 /**************************************************************************
483 * IShellBrowserImpl_EnableModelessSB
485 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
486 BOOL fEnable)
489 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
491 TRACE("(%p)\n", This);
493 /* Feature not implemented */
494 return E_NOTIMPL;
497 /**************************************************************************
498 * IShellBrowserImpl_GetControlWindow
500 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
501 UINT id,
502 HWND *lphwnd)
505 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
507 TRACE("(%p)\n", This);
509 /* Feature not implemented */
510 return E_NOTIMPL;
513 /**************************************************************************
514 * IShellBrowserImpl_GetViewStateStream
516 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
517 DWORD grfMode,
518 LPSTREAM *ppStrm)
521 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
523 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
525 /* Feature not implemented */
526 return E_NOTIMPL;
529 /**************************************************************************
530 * IShellBrowserImpl_InsertMenusSB
532 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
533 HMENU hmenuShared,
534 LPOLEMENUGROUPWIDTHS lpMenuWidths)
537 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
539 TRACE("(%p)\n", This);
541 /* Feature not implemented */
542 return E_NOTIMPL;
545 /**************************************************************************
546 * IShellBrowserImpl_OnViewWindowActive
548 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
549 IShellView *ppshv)
552 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
554 TRACE("(%p)\n", This);
556 /* Feature not implemented */
557 return E_NOTIMPL;
560 /**************************************************************************
561 * IShellBrowserImpl_QueryActiveShellView
563 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
564 IShellView **ppshv)
567 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
569 FileOpenDlgInfos *fodInfos;
571 TRACE("(%p)\n", This);
573 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
575 if(!(*ppshv = fodInfos->Shell.FOIShellView))
577 return E_FAIL;
579 IShellView_AddRef(fodInfos->Shell.FOIShellView);
580 return NOERROR;
583 /**************************************************************************
584 * IShellBrowserImpl_RemoveMenusSB
586 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
587 HMENU hmenuShared)
590 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
592 TRACE("(%p)\n", This);
594 /* Feature not implemented */
595 return E_NOTIMPL;
598 /**************************************************************************
599 * IShellBrowserImpl_SendControlMsg
601 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
602 UINT id,
603 UINT uMsg,
604 WPARAM wParam,
605 LPARAM lParam,
606 LRESULT *pret)
609 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
610 LRESULT lres;
612 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
614 switch (id)
616 case FCW_TOOLBAR:
617 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
618 break;
619 default:
620 FIXME("ctrl id: %x\n", id);
621 return E_NOTIMPL;
623 if (pret) *pret = lres;
624 return S_OK;
627 /**************************************************************************
628 * IShellBrowserImpl_SetMenuSB
630 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
631 HMENU hmenuShared,
632 HOLEMENU holemenuReserved,
633 HWND hwndActiveObject)
636 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
638 TRACE("(%p)\n", This);
640 /* Feature not implemented */
641 return E_NOTIMPL;
644 /**************************************************************************
645 * IShellBrowserImpl_SetStatusTextSB
647 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
648 LPCOLESTR lpszStatusText)
651 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
653 TRACE("(%p)\n", This);
655 /* Feature not implemented */
656 return E_NOTIMPL;
659 /**************************************************************************
660 * IShellBrowserImpl_SetToolbarItems
662 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
663 LPTBBUTTON lpButtons,
664 UINT nButtons,
665 UINT uFlags)
668 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
670 TRACE("(%p)\n", This);
672 /* Feature not implemented */
673 return E_NOTIMPL;
676 /**************************************************************************
677 * IShellBrowserImpl_TranslateAcceleratorSB
679 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
680 LPMSG lpmsg,
681 WORD wID)
684 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
686 TRACE("(%p)\n", This);
688 /* Feature not implemented */
689 return E_NOTIMPL;
692 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
694 /* IUnknown */
695 IShellBrowserImpl_QueryInterface,
696 IShellBrowserImpl_AddRef,
697 IShellBrowserImpl_Release,
698 /* IOleWindow */
699 IShellBrowserImpl_GetWindow,
700 IShellBrowserImpl_ContextSensitiveHelp,
701 /* IShellBrowser */
702 IShellBrowserImpl_InsertMenusSB,
703 IShellBrowserImpl_SetMenuSB,
704 IShellBrowserImpl_RemoveMenusSB,
705 IShellBrowserImpl_SetStatusTextSB,
706 IShellBrowserImpl_EnableModelessSB,
707 IShellBrowserImpl_TranslateAcceleratorSB,
708 IShellBrowserImpl_BrowseObject,
709 IShellBrowserImpl_GetViewStateStream,
710 IShellBrowserImpl_GetControlWindow,
711 IShellBrowserImpl_SendControlMsg,
712 IShellBrowserImpl_QueryActiveShellView,
713 IShellBrowserImpl_OnViewWindowActive,
714 IShellBrowserImpl_SetToolbarItems
720 * ICommDlgBrowser
723 /***************************************************************************
724 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
726 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
727 ICommDlgBrowser *iface,
728 REFIID riid,
729 LPVOID *ppvObj)
731 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
733 TRACE("(%p)\n", This);
735 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
738 /**************************************************************************
739 * IShellBrowserImpl_ICommDlgBrowser_AddRef
741 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
743 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
745 TRACE("(%p)\n", This);
747 return IShellBrowserImpl_AddRef(This);
750 /**************************************************************************
751 * IShellBrowserImpl_ICommDlgBrowser_Release
753 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
755 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
757 TRACE("(%p)\n", This);
759 return IShellBrowserImpl_Release(This);
762 /**************************************************************************
763 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
765 * Called when a user double-clicks in the view or presses the ENTER key
767 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
768 IShellView *ppshv)
770 LPITEMIDLIST pidl;
771 FileOpenDlgInfos *fodInfos;
773 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
775 TRACE("(%p)\n", This);
777 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
779 /* If the selected object is not a folder, send an IDOK command to parent window */
780 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
782 HRESULT hRes;
784 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
785 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
786 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
788 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
789 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
791 else
793 /* Tell the dialog that the user selected a file */
794 PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
795 hRes = S_OK;
798 /* Free memory used by pidl */
799 COMDLG32_SHFree((LPVOID)pidl);
801 return hRes;
804 return E_FAIL;
807 /**************************************************************************
808 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
810 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
811 IShellView *ppshv,
812 ULONG uChange)
815 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
817 TRACE("(%p shv=%p)\n", This, ppshv);
819 switch (uChange)
821 case CDBOSC_SETFOCUS:
822 /* FIXME: Reset the default button.
823 This should be taken care of by defdlg. If control
824 other than button receives focus the default button
825 should be restored. */
826 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
828 break;
829 case CDBOSC_KILLFOCUS:
831 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
832 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
833 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
835 break;
836 case CDBOSC_SELCHANGE:
837 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
838 case CDBOSC_RENAME:
839 /* nothing to do */
840 break;
843 return NOERROR;
846 /**************************************************************************
847 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
849 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
850 IShellView * ppshv,
851 LPCITEMIDLIST pidl)
853 FileOpenDlgInfos *fodInfos;
854 ULONG ulAttr;
855 STRRET str;
856 WCHAR szPathW[MAX_PATH];
858 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
860 TRACE("(%p)\n", This);
862 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
864 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
865 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
867 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
868 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
869 return S_FALSE;
871 /* always include directories and links */
872 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
873 return S_OK;
875 /* Check if there is a mask to apply if not */
876 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
877 return S_OK;
879 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
881 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
883 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
884 return S_OK;
887 return S_FALSE;
891 /**************************************************************************
892 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
894 static HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
896 FileOpenDlgInfos *fodInfos;
898 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
900 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
901 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
903 /* release old selections */
904 if (fodInfos->Shell.FOIDataObject)
905 IDataObject_Release(fodInfos->Shell.FOIDataObject);
907 /* get a new DataObject from the ShellView */
908 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
909 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
910 return E_FAIL;
912 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
914 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
915 return S_OK;
918 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
920 /* IUnknown */
921 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
922 IShellBrowserImpl_ICommDlgBrowser_AddRef,
923 IShellBrowserImpl_ICommDlgBrowser_Release,
924 /* ICommDlgBrowser */
925 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
926 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
927 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
934 * IServiceProvider
937 /***************************************************************************
938 * IShellBrowserImpl_IServiceProvider_QueryInterface
940 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
941 IServiceProvider *iface,
942 REFIID riid,
943 LPVOID *ppvObj)
945 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
947 FIXME("(%p)\n", This);
949 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
952 /**************************************************************************
953 * IShellBrowserImpl_IServiceProvider_AddRef
955 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
957 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
959 FIXME("(%p)\n", This);
961 return IShellBrowserImpl_AddRef(This);
964 /**************************************************************************
965 * IShellBrowserImpl_IServiceProvider_Release
967 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
969 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
971 FIXME("(%p)\n", This);
973 return IShellBrowserImpl_Release(This);
976 /**************************************************************************
977 * IShellBrowserImpl_IServiceProvider_Release
979 * NOTES
980 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
981 * riid = IShellBrowser) to call SendControlMsg ().
983 * FIXME
984 * this is a hack!
987 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
988 IServiceProvider * iface,
989 REFGUID guidService,
990 REFIID riid,
991 void** ppv)
993 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
995 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
997 *ppv = NULL;
998 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
1000 return IShellBrowserImpl_QueryInterface(This,riid,ppv);
1002 FIXME("(%p) unknown interface requested\n", This);
1003 return E_NOINTERFACE;
1007 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
1009 /* IUnknown */
1010 IShellBrowserImpl_IServiceProvider_QueryInterface,
1011 IShellBrowserImpl_IServiceProvider_AddRef,
1012 IShellBrowserImpl_IServiceProvider_Release,
1013 /* IServiceProvider */
1014 IShellBrowserImpl_IServiceProvider_QueryService