server: Added access rights mapping to token objects.
[wine/multimedia.git] / dlls / commdlg / filedlgbrowser.c
blob2b7d678f47ba110a45a789b29055f4a7a547767b
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 LONG ref; /* Reference counter */
54 HWND hwndOwner; /* Owner dialog of the interface */
56 } IShellBrowserImpl;
58 static inline IShellBrowserImpl *impl_from_ICommDlgBrowser( ICommDlgBrowser *iface )
60 return (IShellBrowserImpl *)((char*)iface - FIELD_OFFSET(IShellBrowserImpl, lpVtblCommDlgBrowser));
63 static inline IShellBrowserImpl *impl_from_IServiceProvider( IServiceProvider *iface )
65 return (IShellBrowserImpl *)((char*)iface - FIELD_OFFSET(IShellBrowserImpl, lpVtblServiceProvider));
68 /**************************************************************************
69 * vtable
71 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
72 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
73 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
75 /**************************************************************************
76 * Local Prototypes
79 static HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
81 /**************************************************************************
82 * External Prototypes
84 extern const char *FileOpenDlgInfosStr;
86 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
87 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
88 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
90 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
91 extern void SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
95 * Helper functions
98 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
99 static void COMDLG32_DumpSBSPFlags(UINT uflags)
101 if (TRACE_ON(commdlg))
103 unsigned int i;
104 static const struct {
105 DWORD mask;
106 const char *name;
107 } flags[] = {
108 #define FE(x) { x, #x}
109 /* SBSP_DEFBROWSER == 0 */
110 FE(SBSP_SAMEBROWSER),
111 FE(SBSP_NEWBROWSER),
113 /* SBSP_DEFMODE == 0 */
114 FE(SBSP_OPENMODE),
115 FE(SBSP_EXPLOREMODE),
116 FE(SBSP_HELPMODE),
117 FE(SBSP_NOTRANSFERHIST),
119 /* SBSP_ABSOLUTE == 0 */
120 FE(SBSP_RELATIVE),
121 FE(SBSP_PARENT),
122 FE(SBSP_NAVIGATEBACK),
123 FE(SBSP_NAVIGATEFORWARD),
124 FE(SBSP_ALLOW_AUTONAVIGATE),
126 FE(SBSP_NOAUTOSELECT),
127 FE(SBSP_WRITENOHISTORY),
129 FE(SBSP_REDIRECT),
130 FE(SBSP_INITIATEDBYHLINKFRAME),
132 #undef FE
133 DPRINTF("SBSP Flags: %08x =", uflags);
134 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
135 if (flags[i].mask & uflags)
136 DPRINTF("%s ", flags[i].name);
137 DPRINTF("\n");
141 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
143 LPSHELLFOLDER psfDesktop;
144 STRRET strret;
145 HRESULT res;
147 res = SHGetDesktopFolder(&psfDesktop);
148 if (FAILED(res))
149 return;
151 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
152 SHGDN_FORPARSING, &strret);
153 if (SUCCEEDED(res)) {
154 WCHAR wszCurrentDir[MAX_PATH];
156 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
157 if (SUCCEEDED(res))
158 SetCurrentDirectoryW(wszCurrentDir);
161 IShellFolder_Release(psfDesktop);
164 /* copied from shell32 to avoid linking to it */
165 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
167 TRACE("dest=%p len=0x%lx strret=%p pidl=%p stub\n",dest,len,src,pidl);
169 switch (src->uType)
171 case STRRET_WSTR:
172 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
173 COMDLG32_SHFree(src->u.pOleStr);
174 break;
176 case STRRET_CSTR:
177 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
178 ((LPWSTR)dest)[len-1] = 0;
179 break;
181 case STRRET_OFFSET:
182 if (pidl)
184 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
185 -1, (LPWSTR)dest, len ))
186 ((LPWSTR)dest)[len-1] = 0;
188 break;
190 default:
191 FIXME("unknown type!\n");
192 if (len)
193 { *(LPWSTR)dest = '\0';
195 return(FALSE);
197 return S_OK;
201 * IShellBrowser
204 /**************************************************************************
205 * IShellBrowserImpl_Construct
207 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
209 IShellBrowserImpl *sb;
210 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
212 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
214 /* Initialisation of the member variables */
215 sb->ref=1;
216 sb->hwndOwner = hwndOwner;
218 /* Initialisation of the vTables */
219 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
220 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
221 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
222 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
223 &fodInfos->ShellInfos.pidlAbsCurrent);
225 TRACE("%p\n", sb);
227 return (IShellBrowser *) sb;
230 /***************************************************************************
231 * IShellBrowserImpl_QueryInterface
233 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
234 REFIID riid,
235 LPVOID *ppvObj)
237 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
239 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
241 *ppvObj = NULL;
243 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
244 { *ppvObj = This;
246 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
247 { *ppvObj = (IOleWindow*)This;
250 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
251 { *ppvObj = (IShellBrowser*)This;
254 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
255 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
258 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
259 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
262 if(*ppvObj)
263 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
264 return S_OK;
266 FIXME("Unknown interface requested\n");
267 return E_NOINTERFACE;
270 /**************************************************************************
271 * IShellBrowser::AddRef
273 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
275 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
276 ULONG ref = InterlockedIncrement(&This->ref);
278 TRACE("(%p,%lu)\n", This, ref - 1);
280 return ref;
283 /**************************************************************************
284 * IShellBrowserImpl_Release
286 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
288 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
289 ULONG ref = InterlockedDecrement(&This->ref);
291 TRACE("(%p,%lu)\n", This, ref + 1);
293 if (!ref)
295 COMDLG32_SHFree(This);
296 TRACE("-- destroyed\n");
297 return 0;
299 return ref;
303 * IOleWindow
306 /**************************************************************************
307 * IShellBrowserImpl_GetWindow (IOleWindow)
309 * Inherited from IOleWindow::GetWindow
311 * See Windows documentation for more details
313 * Note : We will never be window less in the File Open dialog
316 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
317 HWND * phwnd)
319 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
321 TRACE("(%p)\n", This);
323 if(!This->hwndOwner)
324 return E_FAIL;
326 *phwnd = This->hwndOwner;
328 return (*phwnd) ? S_OK : E_UNEXPECTED;
332 /**************************************************************************
333 * IShellBrowserImpl_ContextSensitiveHelp
335 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
336 BOOL fEnterMode)
338 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
340 TRACE("(%p)\n", This);
342 /* Feature not implemented */
343 return E_NOTIMPL;
347 * IShellBrowser
350 /**************************************************************************
351 * IShellBrowserImpl_BrowseObject
353 * See Windows documentation on IShellBrowser::BrowseObject for more details
355 * This function will override user specified flags and will always
356 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
358 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
359 LPCITEMIDLIST pidl,
360 UINT wFlags)
362 HRESULT hRes;
363 IShellFolder *psfTmp;
364 IShellView *psvTmp;
365 FileOpenDlgInfos *fodInfos;
366 LPITEMIDLIST pidlTmp;
367 HWND hwndView;
368 HWND hDlgWnd;
369 BOOL bViewHasFocus;
370 RECT rectView;
372 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
374 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
375 COMDLG32_DumpSBSPFlags(wFlags);
377 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
379 /* Format the pidl according to its parameter's category */
380 if(wFlags & SBSP_RELATIVE)
383 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
384 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
385 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
387 ERR("bind to object failed\n");
388 return hRes;
390 /* create an absolute pidl */
391 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
392 (LPITEMIDLIST)pidl);
394 else if(wFlags & SBSP_PARENT)
396 /* Browse the parent folder (ignores the pidl) */
397 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
398 psfTmp = GetShellFolderFromPidl(pidlTmp);
401 else /* SBSP_ABSOLUTE is 0x0000 */
403 /* An absolute pidl (relative from the desktop) */
404 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
405 psfTmp = GetShellFolderFromPidl(pidlTmp);
408 if(!psfTmp)
410 ERR("could not browse to folder\n");
411 return E_FAIL;
414 /* If the pidl to browse to is equal to the actual pidl ...
415 do nothing and pretend you did it*/
416 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
418 IShellFolder_Release(psfTmp);
419 COMDLG32_SHFree(pidlTmp);
420 TRACE("keep current folder\n");
421 return NOERROR;
424 /* Release the current DataObject */
425 if (fodInfos->Shell.FOIDataObject)
427 IDataObject_Release(fodInfos->Shell.FOIDataObject);
428 fodInfos->Shell.FOIDataObject = NULL;
431 /* Create the associated view */
432 TRACE("create view object\n");
433 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
434 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
436 /* Check if listview has focus */
437 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
439 /* Get the foldersettings from the old view */
440 if(fodInfos->Shell.FOIShellView)
441 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
443 /* Release the old fodInfos->Shell.FOIShellView and update its value.
444 We have to update this early since ShellView_CreateViewWindow of native
445 shell32 calls OnStateChange and needs the correct view here.*/
446 if(fodInfos->Shell.FOIShellView)
448 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
449 IShellView_Release(fodInfos->Shell.FOIShellView);
451 fodInfos->Shell.FOIShellView = psvTmp;
453 /* Release old FOIShellFolder and update its value */
454 if (fodInfos->Shell.FOIShellFolder)
455 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
456 fodInfos->Shell.FOIShellFolder = psfTmp;
458 /* Release old pidlAbsCurrent and update its value */
459 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
460 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
462 COMDLG32_UpdateCurrentDir(fodInfos);
464 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
465 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
467 /* Create the window */
468 TRACE("create view window\n");
469 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
470 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
471 &rectView, &hwndView))) goto error;
473 fodInfos->ShellInfos.hwndView = hwndView;
475 /* Select the new folder in the Look In combo box of the Open file dialog */
476 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
478 /* changes the tab order of the ListView to reflect the window's File Dialog */
479 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
480 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
482 /* Since we destroyed the old view if it had focus set focus to the newly created view */
483 if (bViewHasFocus)
484 SetFocus(fodInfos->ShellInfos.hwndView);
486 return hRes;
487 error:
488 ERR("Failed with error 0x%08lx\n", hRes);
489 return hRes;
492 /**************************************************************************
493 * IShellBrowserImpl_EnableModelessSB
495 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
496 BOOL fEnable)
499 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
501 TRACE("(%p)\n", This);
503 /* Feature not implemented */
504 return E_NOTIMPL;
507 /**************************************************************************
508 * IShellBrowserImpl_GetControlWindow
510 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
511 UINT id,
512 HWND *lphwnd)
515 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
517 TRACE("(%p)\n", This);
519 /* Feature not implemented */
520 return E_NOTIMPL;
523 /**************************************************************************
524 * IShellBrowserImpl_GetViewStateStream
526 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
527 DWORD grfMode,
528 LPSTREAM *ppStrm)
531 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
533 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
535 /* Feature not implemented */
536 return E_NOTIMPL;
539 /**************************************************************************
540 * IShellBrowserImpl_InsertMenusSB
542 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
543 HMENU hmenuShared,
544 LPOLEMENUGROUPWIDTHS lpMenuWidths)
547 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
549 TRACE("(%p)\n", This);
551 /* Feature not implemented */
552 return E_NOTIMPL;
555 /**************************************************************************
556 * IShellBrowserImpl_OnViewWindowActive
558 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
559 IShellView *ppshv)
562 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
564 TRACE("(%p)\n", This);
566 /* Feature not implemented */
567 return E_NOTIMPL;
570 /**************************************************************************
571 * IShellBrowserImpl_QueryActiveShellView
573 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
574 IShellView **ppshv)
577 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
579 FileOpenDlgInfos *fodInfos;
581 TRACE("(%p)\n", This);
583 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
585 if(!(*ppshv = fodInfos->Shell.FOIShellView))
587 return E_FAIL;
589 IShellView_AddRef(fodInfos->Shell.FOIShellView);
590 return NOERROR;
593 /**************************************************************************
594 * IShellBrowserImpl_RemoveMenusSB
596 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
597 HMENU hmenuShared)
600 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
602 TRACE("(%p)\n", This);
604 /* Feature not implemented */
605 return E_NOTIMPL;
608 /**************************************************************************
609 * IShellBrowserImpl_SendControlMsg
611 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
612 UINT id,
613 UINT uMsg,
614 WPARAM wParam,
615 LPARAM lParam,
616 LRESULT *pret)
619 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
620 LRESULT lres;
622 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
624 switch (id)
626 case FCW_TOOLBAR:
627 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
628 break;
629 default:
630 FIXME("ctrl id: %x\n", id);
631 return E_NOTIMPL;
633 if (pret) *pret = lres;
634 return S_OK;
637 /**************************************************************************
638 * IShellBrowserImpl_SetMenuSB
640 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
641 HMENU hmenuShared,
642 HOLEMENU holemenuReserved,
643 HWND hwndActiveObject)
646 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
648 TRACE("(%p)\n", This);
650 /* Feature not implemented */
651 return E_NOTIMPL;
654 /**************************************************************************
655 * IShellBrowserImpl_SetStatusTextSB
657 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
658 LPCOLESTR lpszStatusText)
661 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
663 TRACE("(%p)\n", This);
665 /* Feature not implemented */
666 return E_NOTIMPL;
669 /**************************************************************************
670 * IShellBrowserImpl_SetToolbarItems
672 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
673 LPTBBUTTON lpButtons,
674 UINT nButtons,
675 UINT uFlags)
678 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
680 TRACE("(%p)\n", This);
682 /* Feature not implemented */
683 return E_NOTIMPL;
686 /**************************************************************************
687 * IShellBrowserImpl_TranslateAcceleratorSB
689 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
690 LPMSG lpmsg,
691 WORD wID)
694 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
696 TRACE("(%p)\n", This);
698 /* Feature not implemented */
699 return E_NOTIMPL;
702 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
704 /* IUnknown */
705 IShellBrowserImpl_QueryInterface,
706 IShellBrowserImpl_AddRef,
707 IShellBrowserImpl_Release,
708 /* IOleWindow */
709 IShellBrowserImpl_GetWindow,
710 IShellBrowserImpl_ContextSensitiveHelp,
711 /* IShellBrowser */
712 IShellBrowserImpl_InsertMenusSB,
713 IShellBrowserImpl_SetMenuSB,
714 IShellBrowserImpl_RemoveMenusSB,
715 IShellBrowserImpl_SetStatusTextSB,
716 IShellBrowserImpl_EnableModelessSB,
717 IShellBrowserImpl_TranslateAcceleratorSB,
718 IShellBrowserImpl_BrowseObject,
719 IShellBrowserImpl_GetViewStateStream,
720 IShellBrowserImpl_GetControlWindow,
721 IShellBrowserImpl_SendControlMsg,
722 IShellBrowserImpl_QueryActiveShellView,
723 IShellBrowserImpl_OnViewWindowActive,
724 IShellBrowserImpl_SetToolbarItems
730 * ICommDlgBrowser
733 /***************************************************************************
734 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
736 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
737 ICommDlgBrowser *iface,
738 REFIID riid,
739 LPVOID *ppvObj)
741 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
743 TRACE("(%p)\n", This);
745 return IShellBrowserImpl_QueryInterface((IShellBrowser *)This,riid,ppvObj);
748 /**************************************************************************
749 * IShellBrowserImpl_ICommDlgBrowser_AddRef
751 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
753 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
755 TRACE("(%p)\n", This);
757 return IShellBrowserImpl_AddRef((IShellBrowser *)This);
760 /**************************************************************************
761 * IShellBrowserImpl_ICommDlgBrowser_Release
763 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
765 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
767 TRACE("(%p)\n", This);
769 return IShellBrowserImpl_Release((IShellBrowser *)This);
772 /**************************************************************************
773 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
775 * Called when a user double-clicks in the view or presses the ENTER key
777 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
778 IShellView *ppshv)
780 LPITEMIDLIST pidl;
781 FileOpenDlgInfos *fodInfos;
783 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
785 TRACE("(%p)\n", This);
787 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
789 /* If the selected object is not a folder, send an IDOK command to parent window */
790 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
792 HRESULT hRes;
794 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
795 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
796 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
798 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
799 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
801 else
803 /* Tell the dialog that the user selected a file */
804 PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
805 hRes = S_OK;
808 /* Free memory used by pidl */
809 COMDLG32_SHFree((LPVOID)pidl);
811 return hRes;
814 return E_FAIL;
817 /**************************************************************************
818 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
820 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
821 IShellView *ppshv,
822 ULONG uChange)
825 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
827 TRACE("(%p shv=%p)\n", This, ppshv);
829 switch (uChange)
831 case CDBOSC_SETFOCUS:
832 /* FIXME: Reset the default button.
833 This should be taken care of by defdlg. If control
834 other than button receives focus the default button
835 should be restored. */
836 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
838 break;
839 case CDBOSC_KILLFOCUS:
841 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
842 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
843 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
845 break;
846 case CDBOSC_SELCHANGE:
847 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
848 case CDBOSC_RENAME:
849 /* nothing to do */
850 break;
853 return NOERROR;
856 /**************************************************************************
857 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
859 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
860 IShellView * ppshv,
861 LPCITEMIDLIST pidl)
863 FileOpenDlgInfos *fodInfos;
864 ULONG ulAttr;
865 STRRET str;
866 WCHAR szPathW[MAX_PATH];
868 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
870 TRACE("(%p)\n", This);
872 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
874 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
875 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
877 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
878 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
879 return S_FALSE;
881 /* always include directories and links */
882 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
883 return S_OK;
885 /* Check if there is a mask to apply if not */
886 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
887 return S_OK;
889 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
891 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
893 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
894 return S_OK;
897 return S_FALSE;
901 /**************************************************************************
902 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
904 static HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
906 FileOpenDlgInfos *fodInfos;
908 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
910 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
911 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
913 /* release old selections */
914 if (fodInfos->Shell.FOIDataObject)
915 IDataObject_Release(fodInfos->Shell.FOIDataObject);
917 /* get a new DataObject from the ShellView */
918 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
919 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
920 return E_FAIL;
922 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
924 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
925 return S_OK;
928 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
930 /* IUnknown */
931 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
932 IShellBrowserImpl_ICommDlgBrowser_AddRef,
933 IShellBrowserImpl_ICommDlgBrowser_Release,
934 /* ICommDlgBrowser */
935 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
936 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
937 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
944 * IServiceProvider
947 /***************************************************************************
948 * IShellBrowserImpl_IServiceProvider_QueryInterface
950 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
951 IServiceProvider *iface,
952 REFIID riid,
953 LPVOID *ppvObj)
955 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
957 FIXME("(%p)\n", This);
959 return IShellBrowserImpl_QueryInterface((IShellBrowser *)This,riid,ppvObj);
962 /**************************************************************************
963 * IShellBrowserImpl_IServiceProvider_AddRef
965 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
967 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
969 FIXME("(%p)\n", This);
971 return IShellBrowserImpl_AddRef((IShellBrowser *)This);
974 /**************************************************************************
975 * IShellBrowserImpl_IServiceProvider_Release
977 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
979 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
981 FIXME("(%p)\n", This);
983 return IShellBrowserImpl_Release((IShellBrowser *)This);
986 /**************************************************************************
987 * IShellBrowserImpl_IServiceProvider_Release
989 * NOTES
990 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
991 * riid = IShellBrowser) to call SendControlMsg ().
993 * FIXME
994 * this is a hack!
997 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
998 IServiceProvider * iface,
999 REFGUID guidService,
1000 REFIID riid,
1001 void** ppv)
1003 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1005 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
1007 *ppv = NULL;
1008 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
1010 return IShellBrowserImpl_QueryInterface((IShellBrowser *)This,riid,ppv);
1012 FIXME("(%p) unknown interface requested\n", This);
1013 return E_NOINTERFACE;
1017 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
1019 /* IUnknown */
1020 IShellBrowserImpl_IServiceProvider_QueryInterface,
1021 IShellBrowserImpl_IServiceProvider_AddRef,
1022 IShellBrowserImpl_IServiceProvider_Release,
1023 /* IServiceProvider */
1024 IShellBrowserImpl_IServiceProvider_QueryService