comdlg32: Scale the shell folder list in the open dialog with the font size.
[wine/multimedia.git] / dlls / comdlg32 / filedlgbrowser.c
blob499ebb7f4fec841d136a38c1e7706197501ea180
1 /*
2 * Implementation of IShellBrowser for the File Open common dialog
4 * Copyright 1999 Francois Boisvert
5 * Copyright 1999, 2000 Juergen Schmied
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winnls.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winreg.h"
37 #define NO_SHLWAPI_STREAM
38 #include "shlwapi.h"
39 #include "filedlgbrowser.h"
40 #include "cdlg.h"
41 #include "shlguid.h"
42 #include "servprov.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
47 typedef struct
50 IShellBrowser IShellBrowser_iface;
51 ICommDlgBrowser ICommDlgBrowser_iface;
52 IServiceProvider IServiceProvider_iface;
53 LONG ref; /* Reference counter */
54 HWND hwndOwner; /* Owner dialog of the interface */
56 } IShellBrowserImpl;
58 static inline IShellBrowserImpl *impl_from_IShellBrowser(IShellBrowser *iface)
60 return CONTAINING_RECORD(iface, IShellBrowserImpl, IShellBrowser_iface);
63 static inline IShellBrowserImpl *impl_from_ICommDlgBrowser( ICommDlgBrowser *iface )
65 return CONTAINING_RECORD(iface, IShellBrowserImpl, ICommDlgBrowser_iface);
68 static inline IShellBrowserImpl *impl_from_IServiceProvider( IServiceProvider *iface )
70 return CONTAINING_RECORD(iface, IShellBrowserImpl, IServiceProvider_iface);
73 /**************************************************************************
74 * vtable
76 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
77 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
78 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
81 * Helper functions
84 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
85 static void COMDLG32_DumpSBSPFlags(UINT uflags)
87 if (TRACE_ON(commdlg))
89 unsigned int i;
90 static const struct {
91 DWORD mask;
92 const char *name;
93 } flags[] = {
94 #define FE(x) { x, #x}
95 /* SBSP_DEFBROWSER == 0 */
96 FE(SBSP_SAMEBROWSER),
97 FE(SBSP_NEWBROWSER),
99 /* SBSP_DEFMODE == 0 */
100 FE(SBSP_OPENMODE),
101 FE(SBSP_EXPLOREMODE),
102 FE(SBSP_HELPMODE),
103 FE(SBSP_NOTRANSFERHIST),
105 /* SBSP_ABSOLUTE == 0 */
106 FE(SBSP_RELATIVE),
107 FE(SBSP_PARENT),
108 FE(SBSP_NAVIGATEBACK),
109 FE(SBSP_NAVIGATEFORWARD),
110 FE(SBSP_ALLOW_AUTONAVIGATE),
112 FE(SBSP_NOAUTOSELECT),
113 FE(SBSP_WRITENOHISTORY),
115 FE(SBSP_REDIRECT),
116 FE(SBSP_INITIATEDBYHLINKFRAME),
118 #undef FE
119 TRACE("SBSP Flags: %08x =", uflags);
120 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
121 if (flags[i].mask & uflags)
122 TRACE("%s ", flags[i].name);
123 TRACE("\n");
127 static void COMDLG32_UpdateCurrentDir(const FileOpenDlgInfos *fodInfos)
129 LPSHELLFOLDER psfDesktop;
130 STRRET strret;
131 HRESULT res;
133 res = SHGetDesktopFolder(&psfDesktop);
134 if (FAILED(res))
135 return;
137 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
138 SHGDN_FORPARSING, &strret);
139 if (SUCCEEDED(res)) {
140 WCHAR wszCurrentDir[MAX_PATH];
142 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
143 if (SUCCEEDED(res))
144 SetCurrentDirectoryW(wszCurrentDir);
147 IShellFolder_Release(psfDesktop);
150 /* copied from shell32 to avoid linking to it */
151 static BOOL COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
153 TRACE("dest=%p len=0x%x strret=%p pidl=%p\n", dest , len, src, pidl);
155 switch (src->uType)
157 case STRRET_WSTR:
158 lstrcpynW(dest, src->u.pOleStr, len);
159 COMDLG32_SHFree(src->u.pOleStr);
160 break;
162 case STRRET_CSTR:
163 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ))
164 ((LPWSTR)dest)[len-1] = 0;
165 break;
167 case STRRET_OFFSET:
168 if (pidl)
170 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
171 -1, dest, len ))
172 ((LPWSTR)dest)[len-1] = 0;
174 break;
176 default:
177 FIXME("unknown type!\n");
178 if (len)
179 { *(LPWSTR)dest = '\0';
181 return(FALSE);
183 return TRUE;
187 * IShellBrowser
190 /**************************************************************************
191 * IShellBrowserImpl_Construct
193 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
195 IShellBrowserImpl *sb;
196 FileOpenDlgInfos *fodInfos = GetPropA(hwndOwner,FileOpenDlgInfosStr);
198 sb = COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
200 /* Initialisation of the member variables */
201 sb->ref=1;
202 sb->hwndOwner = hwndOwner;
204 /* Initialisation of the vTables */
205 sb->IShellBrowser_iface.lpVtbl = &IShellBrowserImpl_Vtbl;
206 sb->ICommDlgBrowser_iface.lpVtbl = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
207 sb->IServiceProvider_iface.lpVtbl = &IShellBrowserImpl_IServiceProvider_Vtbl;
208 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
209 &fodInfos->ShellInfos.pidlAbsCurrent);
211 TRACE("%p\n", sb);
213 return &sb->IShellBrowser_iface;
216 /***************************************************************************
217 * IShellBrowserImpl_QueryInterface
219 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
220 REFIID riid,
221 LPVOID *ppvObj)
223 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
225 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
227 *ppvObj = NULL;
229 if(IsEqualIID(riid, &IID_IUnknown))
230 *ppvObj = &This->IShellBrowser_iface;
231 else if(IsEqualIID(riid, &IID_IOleWindow))
232 *ppvObj = &This->IShellBrowser_iface;
233 else if(IsEqualIID(riid, &IID_IShellBrowser))
234 *ppvObj = &This->IShellBrowser_iface;
235 else if(IsEqualIID(riid, &IID_ICommDlgBrowser))
236 *ppvObj = &This->ICommDlgBrowser_iface;
237 else if(IsEqualIID(riid, &IID_IServiceProvider))
238 *ppvObj = &This->IServiceProvider_iface;
240 if(*ppvObj) {
241 IUnknown_AddRef((IUnknown*)*ppvObj);
242 return S_OK;
245 FIXME("Unknown interface requested\n");
246 return E_NOINTERFACE;
249 /**************************************************************************
250 * IShellBrowser::AddRef
252 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
254 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
255 ULONG ref = InterlockedIncrement(&This->ref);
257 TRACE("(%p,%u)\n", This, ref - 1);
259 return ref;
262 /**************************************************************************
263 * IShellBrowserImpl_Release
265 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
267 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
268 ULONG ref = InterlockedDecrement(&This->ref);
270 TRACE("(%p,%u)\n", This, ref + 1);
272 if (!ref)
274 COMDLG32_SHFree(This);
275 TRACE("-- destroyed\n");
276 return 0;
278 return ref;
282 * IOleWindow
285 /**************************************************************************
286 * IShellBrowserImpl_GetWindow (IOleWindow)
288 * Inherited from IOleWindow::GetWindow
290 * See Windows documentation for more details
292 * Note : We will never be window less in the File Open dialog
295 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
296 HWND * phwnd)
298 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
300 TRACE("(%p)\n", This);
302 if(!This->hwndOwner)
303 return E_FAIL;
305 *phwnd = This->hwndOwner;
307 return (*phwnd) ? S_OK : E_UNEXPECTED;
311 /**************************************************************************
312 * IShellBrowserImpl_ContextSensitiveHelp
314 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
315 BOOL fEnterMode)
317 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
319 TRACE("(%p)\n", This);
321 /* Feature not implemented */
322 return E_NOTIMPL;
326 * IShellBrowser
329 /**************************************************************************
330 * IShellBrowserImpl_BrowseObject
332 * See Windows documentation on IShellBrowser::BrowseObject for more details
334 * This function will override user specified flags and will always
335 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
337 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
338 LPCITEMIDLIST pidl,
339 UINT wFlags)
341 HRESULT hRes;
342 IShellFolder *psfTmp;
343 IShellView *psvTmp;
344 FileOpenDlgInfos *fodInfos;
345 LPITEMIDLIST pidlTmp;
346 HWND hwndView;
347 HWND hDlgWnd;
348 BOOL bViewHasFocus;
349 RECT rectView;
351 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
353 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
354 COMDLG32_DumpSBSPFlags(wFlags);
356 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
358 /* Format the pidl according to its parameter's category */
359 if(wFlags & SBSP_RELATIVE)
362 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
363 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
364 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
366 ERR("bind to object failed\n");
367 return hRes;
369 /* create an absolute pidl */
370 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent, pidl);
372 else if(wFlags & SBSP_PARENT)
374 /* Browse the parent folder (ignores the pidl) */
375 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
376 psfTmp = GetShellFolderFromPidl(pidlTmp);
379 else /* SBSP_ABSOLUTE is 0x0000 */
381 /* An absolute pidl (relative from the desktop) */
382 pidlTmp = COMDLG32_PIDL_ILClone(pidl);
383 psfTmp = GetShellFolderFromPidl(pidlTmp);
386 if(!psfTmp)
388 ERR("could not browse to folder\n");
389 return E_FAIL;
392 /* If the pidl to browse to is equal to the actual pidl ...
393 do nothing and pretend you did it*/
394 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
396 IShellFolder_Release(psfTmp);
397 COMDLG32_SHFree(pidlTmp);
398 TRACE("keep current folder\n");
399 return NOERROR;
402 /* Release the current DataObject */
403 if (fodInfos->Shell.FOIDataObject)
405 IDataObject_Release(fodInfos->Shell.FOIDataObject);
406 fodInfos->Shell.FOIDataObject = NULL;
409 /* Create the associated view */
410 TRACE("create view object\n");
411 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
412 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
414 /* Check if listview has focus */
415 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
417 /* Get the foldersettings from the old view */
418 if(fodInfos->Shell.FOIShellView)
419 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
421 /* Release the old fodInfos->Shell.FOIShellView and update its value.
422 We have to update this early since ShellView_CreateViewWindow of native
423 shell32 calls OnStateChange and needs the correct view here.*/
424 if(fodInfos->Shell.FOIShellView)
426 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
427 IShellView_Release(fodInfos->Shell.FOIShellView);
429 fodInfos->Shell.FOIShellView = psvTmp;
431 /* Release old FOIShellFolder and update its value */
432 if (fodInfos->Shell.FOIShellFolder)
433 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
434 fodInfos->Shell.FOIShellFolder = psfTmp;
436 /* Release old pidlAbsCurrent and update its value */
437 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
438 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
440 COMDLG32_UpdateCurrentDir(fodInfos);
442 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
443 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
445 /* Create the window */
446 TRACE("create view window\n");
447 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
448 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
449 &rectView, &hwndView))) goto error;
451 fodInfos->ShellInfos.hwndView = hwndView;
453 /* Set view window control id to 5002 */
454 SetWindowLongPtrW(hwndView, GWLP_ID, lst2);
455 SendMessageW( hwndView, WM_SETFONT, SendMessageW( GetParent(hwndView), WM_GETFONT, 0, 0 ), FALSE );
457 /* Select the new folder in the Look In combo box of the Open file dialog */
458 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
460 /* changes the tab order of the ListView to reflect the window's File Dialog */
461 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
462 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
464 /* Since we destroyed the old view if it had focus set focus to the newly created view */
465 if (bViewHasFocus)
466 SetFocus(fodInfos->ShellInfos.hwndView);
468 return hRes;
469 error:
470 ERR("Failed with error 0x%08x\n", hRes);
471 return hRes;
474 /**************************************************************************
475 * IShellBrowserImpl_EnableModelessSB
477 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
478 BOOL fEnable)
481 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
483 TRACE("(%p)\n", This);
485 /* Feature not implemented */
486 return E_NOTIMPL;
489 /**************************************************************************
490 * IShellBrowserImpl_GetControlWindow
492 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
493 UINT id,
494 HWND *lphwnd)
497 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
499 TRACE("(%p)\n", This);
501 /* Feature not implemented */
502 return E_NOTIMPL;
505 /**************************************************************************
506 * IShellBrowserImpl_GetViewStateStream
508 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
509 DWORD grfMode,
510 LPSTREAM *ppStrm)
513 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
515 FIXME("(%p 0x%08x %p)\n", This, grfMode, ppStrm);
517 /* Feature not implemented */
518 return E_NOTIMPL;
521 /**************************************************************************
522 * IShellBrowserImpl_InsertMenusSB
524 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
525 HMENU hmenuShared,
526 LPOLEMENUGROUPWIDTHS lpMenuWidths)
529 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
531 TRACE("(%p)\n", This);
533 /* Feature not implemented */
534 return E_NOTIMPL;
537 /**************************************************************************
538 * IShellBrowserImpl_OnViewWindowActive
540 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
541 IShellView *ppshv)
544 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
546 TRACE("(%p)\n", This);
548 /* Feature not implemented */
549 return E_NOTIMPL;
552 /**************************************************************************
553 * IShellBrowserImpl_QueryActiveShellView
555 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
556 IShellView **ppshv)
559 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
561 FileOpenDlgInfos *fodInfos;
563 TRACE("(%p)\n", This);
565 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
567 if(!(*ppshv = fodInfos->Shell.FOIShellView))
569 return E_FAIL;
571 IShellView_AddRef(fodInfos->Shell.FOIShellView);
572 return NOERROR;
575 /**************************************************************************
576 * IShellBrowserImpl_RemoveMenusSB
578 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
579 HMENU hmenuShared)
582 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
584 TRACE("(%p)\n", This);
586 /* Feature not implemented */
587 return E_NOTIMPL;
590 /**************************************************************************
591 * IShellBrowserImpl_SendControlMsg
593 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
594 UINT id,
595 UINT uMsg,
596 WPARAM wParam,
597 LPARAM lParam,
598 LRESULT *pret)
601 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
602 LRESULT lres;
604 TRACE("(%p)->(0x%08x 0x%08x 0x%08lx 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
606 switch (id)
608 case FCW_TOOLBAR:
609 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
610 break;
611 default:
612 FIXME("ctrl id: %x\n", id);
613 return E_NOTIMPL;
615 if (pret) *pret = lres;
616 return S_OK;
619 /**************************************************************************
620 * IShellBrowserImpl_SetMenuSB
622 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
623 HMENU hmenuShared,
624 HOLEMENU holemenuReserved,
625 HWND hwndActiveObject)
628 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
630 TRACE("(%p)\n", This);
632 /* Feature not implemented */
633 return E_NOTIMPL;
636 /**************************************************************************
637 * IShellBrowserImpl_SetStatusTextSB
639 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
640 LPCOLESTR lpszStatusText)
643 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
645 TRACE("(%p)\n", This);
647 /* Feature not implemented */
648 return E_NOTIMPL;
651 /**************************************************************************
652 * IShellBrowserImpl_SetToolbarItems
654 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
655 LPTBBUTTON lpButtons,
656 UINT nButtons,
657 UINT uFlags)
660 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
662 TRACE("(%p)\n", This);
664 /* Feature not implemented */
665 return E_NOTIMPL;
668 /**************************************************************************
669 * IShellBrowserImpl_TranslateAcceleratorSB
671 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
672 LPMSG lpmsg,
673 WORD wID)
676 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
678 TRACE("(%p)\n", This);
680 /* Feature not implemented */
681 return E_NOTIMPL;
684 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
686 /* IUnknown */
687 IShellBrowserImpl_QueryInterface,
688 IShellBrowserImpl_AddRef,
689 IShellBrowserImpl_Release,
690 /* IOleWindow */
691 IShellBrowserImpl_GetWindow,
692 IShellBrowserImpl_ContextSensitiveHelp,
693 /* IShellBrowser */
694 IShellBrowserImpl_InsertMenusSB,
695 IShellBrowserImpl_SetMenuSB,
696 IShellBrowserImpl_RemoveMenusSB,
697 IShellBrowserImpl_SetStatusTextSB,
698 IShellBrowserImpl_EnableModelessSB,
699 IShellBrowserImpl_TranslateAcceleratorSB,
700 IShellBrowserImpl_BrowseObject,
701 IShellBrowserImpl_GetViewStateStream,
702 IShellBrowserImpl_GetControlWindow,
703 IShellBrowserImpl_SendControlMsg,
704 IShellBrowserImpl_QueryActiveShellView,
705 IShellBrowserImpl_OnViewWindowActive,
706 IShellBrowserImpl_SetToolbarItems
712 * ICommDlgBrowser
715 /***************************************************************************
716 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
718 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
719 ICommDlgBrowser *iface,
720 REFIID riid,
721 LPVOID *ppvObj)
723 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
725 TRACE("(%p)\n", This);
727 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
730 /**************************************************************************
731 * IShellBrowserImpl_ICommDlgBrowser_AddRef
733 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
735 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
737 TRACE("(%p)\n", This);
739 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
742 /**************************************************************************
743 * IShellBrowserImpl_ICommDlgBrowser_Release
745 static ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
747 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
749 TRACE("(%p)\n", This);
751 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
754 /**************************************************************************
755 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
757 * Called when a user double-clicks in the view or presses the ENTER key
759 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
760 IShellView *ppshv)
762 LPITEMIDLIST pidl;
763 FileOpenDlgInfos *fodInfos;
765 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
767 TRACE("(%p)\n", This);
769 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
771 /* If the selected object is not a folder, send an IDOK command to parent window */
772 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
774 HRESULT hRes;
776 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
777 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
778 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
780 hRes = IShellBrowser_BrowseObject(&This->IShellBrowser_iface,pidl,SBSP_RELATIVE);
781 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
782 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
784 else
786 /* Tell the dialog that the user selected a file */
787 PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
788 hRes = S_OK;
791 /* Free memory used by pidl */
792 COMDLG32_SHFree(pidl);
794 return hRes;
797 return E_FAIL;
800 /**************************************************************************
801 * IShellBrowserImpl_OnSelChange
803 static HRESULT IShellBrowserImpl_OnSelChange(IShellBrowserImpl *This, const IShellView *ppshv)
805 FileOpenDlgInfos *fodInfos;
807 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
808 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
810 /* release old selections */
811 if (fodInfos->Shell.FOIDataObject)
812 IDataObject_Release(fodInfos->Shell.FOIDataObject);
814 /* get a new DataObject from the ShellView */
815 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
816 &IID_IDataObject, (void**)&fodInfos->Shell.FOIDataObject)))
817 return E_FAIL;
819 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
821 if(fodInfos->ofnInfos->Flags & OFN_EXPLORER)
822 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
823 return S_OK;
826 /**************************************************************************
827 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
829 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
830 IShellView *ppshv,
831 ULONG uChange)
834 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
836 TRACE("(%p shv=%p)\n", This, ppshv);
838 switch (uChange)
840 case CDBOSC_SETFOCUS:
841 /* FIXME: Reset the default button.
842 This should be taken care of by defdlg. If control
843 other than button receives focus the default button
844 should be restored. */
845 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
847 break;
848 case CDBOSC_KILLFOCUS:
850 FileOpenDlgInfos *fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
851 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
853 WCHAR szSave[16];
854 LoadStringW(COMDLG32_hInstance, IDS_SAVE_BUTTON, szSave, sizeof(szSave)/sizeof(WCHAR));
855 SetDlgItemTextW(fodInfos->ShellInfos.hwndOwner, IDOK, szSave);
858 break;
859 case CDBOSC_SELCHANGE:
860 return IShellBrowserImpl_OnSelChange(This, ppshv);
861 case CDBOSC_RENAME:
862 /* nothing to do */
863 break;
866 return NOERROR;
869 /* send_includeitem_notification
871 * Sends a CDN_INCLUDEITEM notification for "pidl" to hwndParentDlg
873 static LRESULT send_includeitem_notification(HWND hwndParentDlg, LPCITEMIDLIST pidl)
875 LRESULT hook_result = 0;
876 FileOpenDlgInfos *fodInfos = GetPropA(hwndParentDlg, FileOpenDlgInfosStr);
878 if(!fodInfos) return 0;
880 if(fodInfos->DlgInfos.hwndCustomDlg)
882 TRACE("call notify CDN_INCLUDEITEM for pidl=%p\n", pidl);
883 if(fodInfos->unicode)
885 OFNOTIFYEXW ofnNotify;
886 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
887 ofnNotify.pidl = (LPITEMIDLIST)pidl;
888 ofnNotify.hdr.hwndFrom = hwndParentDlg;
889 ofnNotify.hdr.idFrom = 0;
890 ofnNotify.hdr.code = CDN_INCLUDEITEM;
891 ofnNotify.lpOFN = fodInfos->ofnInfos;
892 hook_result = SendMessageW(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
894 else
896 OFNOTIFYEXA ofnNotify;
897 ofnNotify.psf = fodInfos->Shell.FOIShellFolder;
898 ofnNotify.pidl = (LPITEMIDLIST)pidl;
899 ofnNotify.hdr.hwndFrom = hwndParentDlg;
900 ofnNotify.hdr.idFrom = 0;
901 ofnNotify.hdr.code = CDN_INCLUDEITEM;
902 ofnNotify.lpOFN = (LPOPENFILENAMEA)fodInfos->ofnInfos;
903 hook_result = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg, WM_NOTIFY, 0, (LPARAM)&ofnNotify);
906 TRACE("Retval: 0x%08lx\n", hook_result);
907 return hook_result;
910 /**************************************************************************
911 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
913 static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
914 IShellView * ppshv,
915 LPCITEMIDLIST pidl)
917 FileOpenDlgInfos *fodInfos;
918 ULONG ulAttr;
919 STRRET str;
920 WCHAR szPathW[MAX_PATH];
922 IShellBrowserImpl *This = impl_from_ICommDlgBrowser(iface);
924 TRACE("(%p)\n", This);
926 fodInfos = GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
928 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
929 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
931 if( (ulAttr & SFGAO_HIDDEN) || /* hidden */
932 !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
933 return S_FALSE;
935 /* always include directories and links */
936 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
937 return S_OK;
939 /* if the application takes care of including the item we are done */
940 if(fodInfos->ofnInfos->Flags & OFN_ENABLEINCLUDENOTIFY &&
941 send_includeitem_notification(This->hwndOwner, pidl))
942 return S_OK;
944 /* Check if there is a mask to apply if not */
945 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
946 return S_OK;
948 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
950 if (COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl))
952 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
953 return S_OK;
956 return S_FALSE;
960 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
962 /* IUnknown */
963 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
964 IShellBrowserImpl_ICommDlgBrowser_AddRef,
965 IShellBrowserImpl_ICommDlgBrowser_Release,
966 /* ICommDlgBrowser */
967 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
968 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
969 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
976 * IServiceProvider
979 /***************************************************************************
980 * IShellBrowserImpl_IServiceProvider_QueryInterface
982 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
983 IServiceProvider *iface,
984 REFIID riid,
985 LPVOID *ppvObj)
987 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
989 FIXME("(%p)\n", This);
991 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppvObj);
994 /**************************************************************************
995 * IShellBrowserImpl_IServiceProvider_AddRef
997 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
999 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1001 FIXME("(%p)\n", This);
1003 return IShellBrowserImpl_AddRef(&This->IShellBrowser_iface);
1006 /**************************************************************************
1007 * IShellBrowserImpl_IServiceProvider_Release
1009 static ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
1011 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1013 FIXME("(%p)\n", This);
1015 return IShellBrowserImpl_Release(&This->IShellBrowser_iface);
1018 /**************************************************************************
1019 * IShellBrowserImpl_IServiceProvider_Release
1021 * NOTES
1022 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
1023 * riid = IShellBrowser) to call SendControlMsg ().
1025 * FIXME
1026 * this is a hack!
1029 static HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
1030 IServiceProvider * iface,
1031 REFGUID guidService,
1032 REFIID riid,
1033 void** ppv)
1035 IShellBrowserImpl *This = impl_from_IServiceProvider(iface);
1037 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
1039 *ppv = NULL;
1040 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
1041 return IShellBrowserImpl_QueryInterface(&This->IShellBrowser_iface,riid,ppv);
1043 FIXME("(%p) unknown interface requested\n", This);
1044 return E_NOINTERFACE;
1048 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
1050 /* IUnknown */
1051 IShellBrowserImpl_IServiceProvider_QueryInterface,
1052 IShellBrowserImpl_IServiceProvider_AddRef,
1053 IShellBrowserImpl_IServiceProvider_Release,
1054 /* IServiceProvider */
1055 IShellBrowserImpl_IServiceProvider_QueryService