wined3d: Factor out acquire_graphics_pipeline_resources().
[wine.git] / dlls / comdlg32 / filedlgbrowser.c
bloba225e9e590ee0006feecca10a68175cdd2ed0550
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
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winreg.h"
36 #define NO_SHLWAPI_STREAM
37 #include "shlwapi.h"
38 #include "filedlgbrowser.h"
39 #include "cdlg.h"
40 #include "shlguid.h"
41 #include "servprov.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
46 typedef struct
49 IShellBrowser IShellBrowser_iface;
50 ICommDlgBrowser ICommDlgBrowser_iface;
51 IServiceProvider IServiceProvider_iface;
52 LONG ref; /* Reference counter */
53 HWND hwndOwner; /* Owner dialog of the interface */
55 } IShellBrowserImpl;
57 static inline IShellBrowserImpl *impl_from_IShellBrowser(IShellBrowser *iface)
59 return CONTAINING_RECORD(iface, IShellBrowserImpl, IShellBrowser_iface);
62 static inline IShellBrowserImpl *impl_from_ICommDlgBrowser( ICommDlgBrowser *iface )
64 return CONTAINING_RECORD(iface, IShellBrowserImpl, ICommDlgBrowser_iface);
67 static inline IShellBrowserImpl *impl_from_IServiceProvider( IServiceProvider *iface )
69 return CONTAINING_RECORD(iface, IShellBrowserImpl, IServiceProvider_iface);
72 /**************************************************************************
73 * vtable
75 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
76 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
77 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
80 * Helper functions
83 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
84 static void COMDLG32_DumpSBSPFlags(UINT uflags)
86 if (TRACE_ON(commdlg))
88 unsigned int i;
89 static const struct {
90 DWORD mask;
91 const char *name;
92 } flags[] = {
93 #define FE(x) { x, #x}
94 /* SBSP_DEFBROWSER == 0 */
95 FE(SBSP_SAMEBROWSER),
96 FE(SBSP_NEWBROWSER),
98 /* SBSP_DEFMODE == 0 */
99 FE(SBSP_OPENMODE),
100 FE(SBSP_EXPLOREMODE),
101 FE(SBSP_HELPMODE),
102 FE(SBSP_NOTRANSFERHIST),
104 /* SBSP_ABSOLUTE == 0 */
105 FE(SBSP_RELATIVE),
106 FE(SBSP_PARENT),
107 FE(SBSP_NAVIGATEBACK),
108 FE(SBSP_NAVIGATEFORWARD),
109 FE(SBSP_ALLOW_AUTONAVIGATE),
111 FE(SBSP_NOAUTOSELECT),
112 FE(SBSP_WRITENOHISTORY),
114 FE(SBSP_REDIRECT),
115 FE(SBSP_INITIATEDBYHLINKFRAME),
117 #undef FE
118 TRACE("SBSP Flags: %08x =", uflags);
119 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
120 if (flags[i].mask & uflags)
121 TRACE("%s ", flags[i].name);
122 TRACE("\n");
126 static void COMDLG32_UpdateCurrentDir(const FileOpenDlgInfos *fodInfos)
128 LPSHELLFOLDER psfDesktop;
129 STRRET strret;
130 HRESULT res;
132 res = SHGetDesktopFolder(&psfDesktop);
133 if (FAILED(res))
134 return;
136 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
137 SHGDN_FORPARSING, &strret);
138 if (SUCCEEDED(res)) {
139 WCHAR wszCurrentDir[MAX_PATH];
141 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
142 if (SUCCEEDED(res))
143 SetCurrentDirectoryW(wszCurrentDir);
146 IShellFolder_Release(psfDesktop);
149 /* copied from shell32 to avoid linking to it */
150 static BOOL COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
152 TRACE("dest=%p len=0x%x strret=%p pidl=%p\n", dest , len, src, pidl);
154 switch (src->uType)
156 case STRRET_WSTR:
157 lstrcpynW(dest, src->u.pOleStr, len);
158 COMDLG32_SHFree(src->u.pOleStr);
159 break;
161 case STRRET_CSTR:
162 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ))
163 ((LPWSTR)dest)[len-1] = 0;
164 break;
166 case STRRET_OFFSET:
167 if (pidl)
169 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
170 -1, dest, len ))
171 ((LPWSTR)dest)[len-1] = 0;
173 break;
175 default:
176 FIXME("unknown type!\n");
177 if (len)
178 { *(LPWSTR)dest = '\0';
180 return(FALSE);
182 return TRUE;
186 * IShellBrowser
189 /**************************************************************************
190 * IShellBrowserImpl_Construct
192 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
194 FileOpenDlgInfos *fodInfos = get_filedlg_infoptr(hwndOwner);
195 IShellBrowserImpl *sb;
197 sb = COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
199 /* Initialisation of the member variables */
200 sb->ref=1;
201 sb->hwndOwner = hwndOwner;
203 /* Initialisation of the vTables */
204 sb->IShellBrowser_iface.lpVtbl = &IShellBrowserImpl_Vtbl;
205 sb->ICommDlgBrowser_iface.lpVtbl = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
206 sb->IServiceProvider_iface.lpVtbl = &IShellBrowserImpl_IServiceProvider_Vtbl;
207 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
208 &fodInfos->ShellInfos.pidlAbsCurrent);
210 TRACE("%p\n", sb);
212 return &sb->IShellBrowser_iface;
215 /***************************************************************************
216 * IShellBrowserImpl_QueryInterface
218 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface, REFIID riid, void **ppvObj)
220 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
222 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
224 *ppvObj = NULL;
226 if(IsEqualIID(riid, &IID_IUnknown))
227 *ppvObj = &This->IShellBrowser_iface;
228 else if(IsEqualIID(riid, &IID_IOleWindow))
229 *ppvObj = &This->IShellBrowser_iface;
230 else if(IsEqualIID(riid, &IID_IShellBrowser))
231 *ppvObj = &This->IShellBrowser_iface;
232 else if(IsEqualIID(riid, &IID_ICommDlgBrowser))
233 *ppvObj = &This->ICommDlgBrowser_iface;
234 else if(IsEqualIID(riid, &IID_IServiceProvider))
235 *ppvObj = &This->IServiceProvider_iface;
237 if(*ppvObj) {
238 IUnknown_AddRef((IUnknown*)*ppvObj);
239 return S_OK;
242 FIXME("unsupported interface, %s\n", debugstr_guid(riid));
243 return E_NOINTERFACE;
246 /**************************************************************************
247 * IShellBrowser::AddRef
249 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
251 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
252 ULONG ref = InterlockedIncrement(&This->ref);
254 TRACE("(%p,%u)\n", This, ref - 1);
256 return ref;
259 /**************************************************************************
260 * IShellBrowserImpl_Release
262 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
264 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
265 ULONG ref = InterlockedDecrement(&This->ref);
267 TRACE("(%p,%u)\n", This, ref + 1);
269 if (!ref)
271 COMDLG32_SHFree(This);
272 TRACE("-- destroyed\n");
274 return ref;
278 * IOleWindow
281 /**************************************************************************
282 * IShellBrowserImpl_GetWindow (IOleWindow)
284 * Inherited from IOleWindow::GetWindow
286 * See Windows documentation for more details
288 * Note : We will never be window less in the File Open dialog
291 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
292 HWND * phwnd)
294 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
296 TRACE("(%p)\n", This);
298 if(!This->hwndOwner)
299 return E_FAIL;
301 *phwnd = This->hwndOwner;
303 return (*phwnd) ? S_OK : E_UNEXPECTED;
307 /**************************************************************************
308 * IShellBrowserImpl_ContextSensitiveHelp
310 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
311 BOOL fEnterMode)
313 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
315 TRACE("(%p)\n", This);
317 /* Feature not implemented */
318 return E_NOTIMPL;
322 * IShellBrowser
325 /**************************************************************************
326 * IShellBrowserImpl_BrowseObject
328 * See Windows documentation on IShellBrowser::BrowseObject for more details
330 * This function will override user specified flags and will always
331 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
333 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
334 LPCITEMIDLIST pidl,
335 UINT wFlags)
337 HRESULT hRes;
338 IShellFolder *psfTmp;
339 IShellView *psvTmp;
340 FileOpenDlgInfos *fodInfos;
341 LPITEMIDLIST pidlTmp;
342 HWND hwndView;
343 HWND hDlgWnd;
344 BOOL bViewHasFocus;
345 RECT rectView;
347 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
349 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
350 COMDLG32_DumpSBSPFlags(wFlags);
352 fodInfos = get_filedlg_infoptr(This->hwndOwner);
354 /* Format the pidl according to its parameter's category */
355 if(wFlags & SBSP_RELATIVE)
358 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
359 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
360 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
362 ERR("bind to object failed\n");
363 return hRes;
365 /* create an absolute pidl */
366 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent, pidl);
368 else if(wFlags & SBSP_PARENT)
370 /* Browse the parent folder (ignores the pidl) */
371 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
372 psfTmp = GetShellFolderFromPidl(pidlTmp);
375 else /* SBSP_ABSOLUTE is 0x0000 */
377 /* An absolute pidl (relative from the desktop) */
378 pidlTmp = COMDLG32_PIDL_ILClone(pidl);
379 psfTmp = GetShellFolderFromPidl(pidlTmp);
382 if(!psfTmp)
384 ERR("could not browse to folder\n");
385 return E_FAIL;
388 /* If the pidl to browse to is equal to the actual pidl ...
389 do nothing and pretend you did it*/
390 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
392 IShellFolder_Release(psfTmp);
393 COMDLG32_SHFree(pidlTmp);
394 TRACE("keep current folder\n");
395 return NOERROR;
398 /* Release the current DataObject */
399 if (fodInfos->Shell.FOIDataObject)
401 IDataObject_Release(fodInfos->Shell.FOIDataObject);
402 fodInfos->Shell.FOIDataObject = NULL;
405 /* Create the associated view */
406 TRACE("create view object\n");
407 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
408 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
410 /* Check if listview has focus */
411 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
413 /* Get the foldersettings from the old view */
414 if(fodInfos->Shell.FOIShellView)
415 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
417 /* Release the old fodInfos->Shell.FOIShellView and update its value.
418 We have to update this early since ShellView_CreateViewWindow of native
419 shell32 calls OnStateChange and needs the correct view here.*/
420 if(fodInfos->Shell.FOIShellView)
422 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
423 IShellView_Release(fodInfos->Shell.FOIShellView);
425 fodInfos->Shell.FOIShellView = psvTmp;
427 /* Release old FOIShellFolder and update its value */
428 if (fodInfos->Shell.FOIShellFolder)
429 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
430 fodInfos->Shell.FOIShellFolder = psfTmp;
432 /* Release old pidlAbsCurrent and update its value */
433 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
434 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
436 COMDLG32_UpdateCurrentDir(fodInfos);
438 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
439 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
441 /* Create the window */
442 TRACE("create view window\n");
443 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
444 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
445 &rectView, &hwndView))) goto error;
447 fodInfos->ShellInfos.hwndView = hwndView;
449 /* Set view window control id to 5002 */
450 SetWindowLongPtrW(hwndView, GWLP_ID, lst2);
451 SendMessageW( hwndView, WM_SETFONT, SendMessageW( GetParent(hwndView), WM_GETFONT, 0, 0 ), FALSE );
453 /* Select the new folder in the Look In combo box of the Open file dialog */
454 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
456 /* changes the tab order of the ListView to reflect the window's File Dialog */
457 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
458 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
460 /* Since we destroyed the old view if it had focus set focus to the newly created view */
461 if (bViewHasFocus)
462 SetFocus(fodInfos->ShellInfos.hwndView);
464 return hRes;
465 error:
466 ERR("Failed with error 0x%08x\n", hRes);
467 return hRes;
470 /**************************************************************************
471 * IShellBrowserImpl_EnableModelessSB
473 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
474 BOOL fEnable)
477 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
479 TRACE("(%p)\n", This);
481 /* Feature not implemented */
482 return E_NOTIMPL;
485 /**************************************************************************
486 * IShellBrowserImpl_GetControlWindow
488 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
489 UINT id,
490 HWND *lphwnd)
493 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
495 TRACE("(%p)\n", This);
497 /* Feature not implemented */
498 return E_NOTIMPL;
501 /**************************************************************************
502 * IShellBrowserImpl_GetViewStateStream
504 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
505 DWORD grfMode,
506 LPSTREAM *ppStrm)
509 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
511 FIXME("(%p 0x%08x %p)\n", This, grfMode, ppStrm);
513 /* Feature not implemented */
514 return E_NOTIMPL;
517 /**************************************************************************
518 * IShellBrowserImpl_InsertMenusSB
520 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
521 HMENU hmenuShared,
522 LPOLEMENUGROUPWIDTHS lpMenuWidths)
525 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
527 TRACE("(%p)\n", This);
529 /* Feature not implemented */
530 return E_NOTIMPL;
533 /**************************************************************************
534 * IShellBrowserImpl_OnViewWindowActive
536 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
537 IShellView *ppshv)
540 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
542 TRACE("(%p)\n", This);
544 /* Feature not implemented */
545 return E_NOTIMPL;
548 /**************************************************************************
549 * IShellBrowserImpl_QueryActiveShellView
551 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
552 IShellView **ppshv)
555 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
557 FileOpenDlgInfos *fodInfos;
559 TRACE("(%p)\n", This);
561 fodInfos = get_filedlg_infoptr(This->hwndOwner);
563 if(!(*ppshv = fodInfos->Shell.FOIShellView))
565 return E_FAIL;
567 IShellView_AddRef(fodInfos->Shell.FOIShellView);
568 return NOERROR;
571 /**************************************************************************
572 * IShellBrowserImpl_RemoveMenusSB
574 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
575 HMENU hmenuShared)
578 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
580 TRACE("(%p)\n", This);
582 /* Feature not implemented */
583 return E_NOTIMPL;
586 /**************************************************************************
587 * IShellBrowserImpl_SendControlMsg
589 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
590 UINT id,
591 UINT uMsg,
592 WPARAM wParam,
593 LPARAM lParam,
594 LRESULT *pret)
597 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
598 LRESULT lres;
600 TRACE("(%p)->(0x%08x 0x%08x 0x%08lx 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
602 switch (id)
604 case FCW_TOOLBAR:
605 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
606 break;
607 default:
608 FIXME("ctrl id: %x\n", id);
609 return E_NOTIMPL;
611 if (pret) *pret = lres;
612 return S_OK;
615 /**************************************************************************
616 * IShellBrowserImpl_SetMenuSB
618 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
619 HMENU hmenuShared,
620 HOLEMENU holemenuReserved,
621 HWND hwndActiveObject)
624 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
626 TRACE("(%p)\n", This);
628 /* Feature not implemented */
629 return E_NOTIMPL;
632 /**************************************************************************
633 * IShellBrowserImpl_SetStatusTextSB
635 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
636 LPCOLESTR lpszStatusText)
639 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
641 TRACE("(%p)\n", This);
643 /* Feature not implemented */
644 return E_NOTIMPL;
647 /**************************************************************************
648 * IShellBrowserImpl_SetToolbarItems
650 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
651 LPTBBUTTON lpButtons,
652 UINT nButtons,
653 UINT uFlags)
656 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
658 TRACE("(%p)\n", This);
660 /* Feature not implemented */
661 return E_NOTIMPL;
664 /**************************************************************************
665 * IShellBrowserImpl_TranslateAcceleratorSB
667 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
668 LPMSG lpmsg,
669 WORD wID)
672 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
674 TRACE("(%p)\n", This);
676 /* Feature not implemented */
677 return E_NOTIMPL;
680 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
682 /* IUnknown */
683 IShellBrowserImpl_QueryInterface,
684 IShellBrowserImpl_AddRef,
685 IShellBrowserImpl_Release,
686 /* IOleWindow */
687 IShellBrowserImpl_GetWindow,
688 IShellBrowserImpl_ContextSensitiveHelp,
689 /* IShellBrowser */
690 IShellBrowserImpl_InsertMenusSB,
691 IShellBrowserImpl_SetMenuSB,
692 IShellBrowserImpl_RemoveMenusSB,
693 IShellBrowserImpl_SetStatusTextSB,
694 IShellBrowserImpl_EnableModelessSB,
695 IShellBrowserImpl_TranslateAcceleratorSB,
696 IShellBrowserImpl_BrowseObject,
697 IShellBrowserImpl_GetViewStateStream,
698 IShellBrowserImpl_GetControlWindow,
699 IShellBrowserImpl_SendControlMsg,
700 IShellBrowserImpl_QueryActiveShellView,
701 IShellBrowserImpl_OnViewWindowActive,
702 IShellBrowserImpl_SetToolbarItems
708 * ICommDlgBrowser
711 /***************************************************************************
712 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
714 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
715 ICommDlgBrowser *iface,
716 REFIID riid,
717 LPVOID *ppvObj)
719 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
721 TRACE("(%p)\n", This);
723 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
726 /**************************************************************************
727 * IShellBrowserImpl_ICommDlgBrowser_AddRef
729 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
731 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
733 TRACE("(%p)\n", This);
735 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
738 /**************************************************************************
739 * IShellBrowserImpl_ICommDlgBrowser_Release
741 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
743 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
745 TRACE("(%p)\n", This);
747 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
750 /**************************************************************************
751 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
753 * Called when a user double-clicks in the view or presses the ENTER key
755 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
756 IShellView *ppshv)
758 LPITEMIDLIST pidl;
759 FileOpenDlgInfos *fodInfos;
761 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
763 TRACE("(%p)\n", This);
765 fodInfos = get_filedlg_infoptr(This->hwndOwner);
767 /* If the selected object is not a folder, send an IDOK command to parent window */
768 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
770 HRESULT hRes;
772 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
773 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
774 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
776 hRes = IShellBrowser_BrowseObject(&This->IShellBrowser_iface,pidl,SBSP_RELATIVE);
777 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
778 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
780 else
782 /* Tell the dialog that the user selected a file */
783 PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
784 hRes = S_OK;
787 /* Free memory used by pidl */
788 COMDLG32_SHFree(pidl);
790 return hRes;
793 return E_FAIL;
796 /**************************************************************************
797 * IShellBrowserImpl_OnSelChange
799 static HRESULT IShellBrowserImpl_OnSelChange(IShellBrowserImpl *This, const IShellView *ppshv)
801 FileOpenDlgInfos *fodInfos;
803 fodInfos = get_filedlg_infoptr(This->hwndOwner);
804 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
806 /* release old selections */
807 if (fodInfos->Shell.FOIDataObject)
808 IDataObject_Release(fodInfos->Shell.FOIDataObject);
810 /* get a new DataObject from the ShellView */
811 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
812 &IID_IDataObject, (void**)&fodInfos->Shell.FOIDataObject)))
813 return E_FAIL;
815 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
817 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
818 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
819 return S_OK;
822 /**************************************************************************
823 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
825 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
826 IShellView *ppshv,
827 ULONG uChange)
830 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
832 TRACE("(%p shv=%p)\n", This, ppshv);
834 switch (uChange)
836 case CDBOSC_SETFOCUS:
837 /* FIXME: Reset the default button.
838 This should be taken care of by defdlg. If control
839 other than button receives focus the default button
840 should be restored. */
841 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
843 break;
844 case CDBOSC_KILLFOCUS:
846 FileOpenDlgInfos *fodInfos = get_filedlg_infoptr(This->hwndOwner);
847 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
849 WCHAR szSave[16];
850 LoadStringW(COMDLG32_hInstance, IDS_SAVE_BUTTON, szSave, sizeof(szSave)/sizeof(WCHAR));
851 SetDlgItemTextW(fodInfos->ShellInfos.hwndOwner, IDOK, szSave);
854 break;
855 case CDBOSC_SELCHANGE:
856 return IShellBrowserImpl_OnSelChange(This, ppshv);
857 case CDBOSC_RENAME:
858 /* nothing to do */
859 break;
862 return NOERROR;
865 /* send_includeitem_notification
867 * Sends a CDN_INCLUDEITEM notification for "pidl" to hwndParentDlg
869 static LRESULT send_includeitem_notification(HWND hwndParentDlg, LPCITEMIDLIST pidl)
871 LRESULT hook_result = 0;
872 FileOpenDlgInfos *fodInfos = get_filedlg_infoptr(hwndParentDlg);
874 if(!fodInfos) return 0;
876 if(fodInfos->DlgInfos.hwndCustomDlg)
878 TRACE("call notify CDN_INCLUDEITEM for pidl=%p\n", pidl);
879 if(fodInfos->unicode)
881 OFNOTIFYEXW ofnNotify;
882 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
883 ofnNotify.pidl = (LPITEMIDLIST)pidl;
884 ofnNotify.hdr.hwndFrom = hwndParentDlg;
885 ofnNotify.hdr.idFrom = 0;
886 ofnNotify.hdr.code = CDN_INCLUDEITEM;
887 ofnNotify.lpOFN = fodInfos->ofnInfos;
888 hook_result = SendMessageW(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
890 else
892 OFNOTIFYEXA ofnNotify;
893 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
894 ofnNotify.pidl = (LPITEMIDLIST)pidl;
895 ofnNotify.hdr.hwndFrom = hwndParentDlg;
896 ofnNotify.hdr.idFrom = 0;
897 ofnNotify.hdr.code = CDN_INCLUDEITEM;
898 ofnNotify.lpOFN = (LPOPENFILENAMEA)fodInfos->ofnInfos;
899 hook_result = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
902 TRACE("Retval: 0x%08lx\n", hook_result);
903 return hook_result;
906 /**************************************************************************
907 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
909 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
910 IShellView * ppshv,
911 LPCITEMIDLIST pidl)
913 FileOpenDlgInfos *fodInfos;
914 ULONG ulAttr;
915 STRRET str;
916 WCHAR szPathW[MAX_PATH];
918 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
920 TRACE("(%p)\n", This);
922 fodInfos = get_filedlg_infoptr(This->hwndOwner);
924 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
925 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
927 if( (ulAttr & SFGAO_HIDDEN) || /* hidden */
928 !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
929 return S_FALSE;
931 /* always include directories and links */
932 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
933 return S_OK;
935 /* if the application takes care of including the item we are done */
936 if(fodInfos->ofnInfos->Flags & OFN_ENABLEINCLUDENOTIFY &&
937 send_includeitem_notification(This->hwndOwner, pidl))
938 return S_OK;
940 /* Check if there is a mask to apply if not */
941 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !fodInfos->ShellInfos.lpstrCurrentFilter[0])
942 return S_OK;
944 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
946 if (COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl))
948 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
949 return S_OK;
952 return S_FALSE;
956 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
958 /* IUnknown */
959 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
960 IShellBrowserImpl_ICommDlgBrowser_AddRef,
961 IShellBrowserImpl_ICommDlgBrowser_Release,
962 /* ICommDlgBrowser */
963 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
964 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
965 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
972 * IServiceProvider
975 /***************************************************************************
976 * IShellBrowserImpl_IServiceProvider_QueryInterface
978 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
979 IServiceProvider *iface,
980 REFIID riid,
981 LPVOID *ppvObj)
983 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
985 FIXME("(%p)\n", This);
987 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
990 /**************************************************************************
991 * IShellBrowserImpl_IServiceProvider_AddRef
993 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
995 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
997 FIXME("(%p)\n", This);
999 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
1002 /**************************************************************************
1003 * IShellBrowserImpl_IServiceProvider_Release
1005 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
1007 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1009 FIXME("(%p)\n", This);
1011 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
1014 /**************************************************************************
1015 * IShellBrowserImpl_IServiceProvider_Release
1017 * NOTES
1018 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
1019 * riid = IShellBrowser) to call SendControlMsg ().
1021 * FIXME
1022 * this is a hack!
1025 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
1026 IServiceProvider * iface,
1027 REFGUID guidService,
1028 REFIID riid,
1029 void** ppv)
1031 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1033 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
1035 *ppv = NULL;
1036 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
1037 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppv);
1039 FIXME("(%p) unknown interface requested\n", This);
1040 return E_NOINTERFACE;
1044 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
1046 /* IUnknown */
1047 IShellBrowserImpl_IServiceProvider_QueryInterface,
1048 IShellBrowserImpl_IServiceProvider_AddRef,
1049 IShellBrowserImpl_IServiceProvider_Release,
1050 /* IServiceProvider */
1051 IShellBrowserImpl_IServiceProvider_QueryService