Get rid of the no longer used ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
[wine/multimedia.git] / dlls / commdlg / filedlgbrowser.c
blobab4f5d1f49e59c34a58e8021ea8337c8bcc13db3
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 NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winreg.h"
35 #define NO_SHLWAPI_STREAM
36 #include "shlwapi.h"
37 #include "filedlgbrowser.h"
38 #include "cdlg.h"
39 #include "shlguid.h"
40 #include "servprov.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
45 typedef struct
48 IShellBrowserVtbl * lpVtbl;
49 ICommDlgBrowserVtbl * lpVtblCommDlgBrowser;
50 IServiceProviderVtbl* lpVtblServiceProvider;
51 DWORD ref; /* Reference counter */
52 HWND hwndOwner; /* Owner dialog of the interface */
54 } IShellBrowserImpl;
56 /**************************************************************************
57 * vtable
59 static IShellBrowserVtbl IShellBrowserImpl_Vtbl;
60 static ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
61 static IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
63 /**************************************************************************
64 * Local Prototypes
67 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
68 #if 0
69 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
70 #endif
72 /**************************************************************************
73 * External Prototypes
75 extern const char *FileOpenDlgInfosStr;
77 extern HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
78 extern HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
79 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
80 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
81 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
83 extern BOOL FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,
84 LPITEMIDLIST pidlCurrentFolder,
85 LPSTR lpstrMask);
87 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
88 extern BOOL FILEDLG95_OnOpen(HWND hwnd);
89 extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
93 * Helper functions
96 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
98 char lpstrPath[MAX_PATH];
99 if(SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath)) {
100 SetCurrentDirectoryA(lpstrPath);
101 TRACE("new current folder %s\n", lpstrPath);
105 /* copied from shell32 to avoid linking to it */
106 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
108 TRACE("dest=%p len=0x%lx strret=%p pidl=%p stub\n",dest,len,src,pidl);
110 switch (src->uType)
112 case STRRET_WSTR:
113 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
114 COMDLG32_SHFree(src->u.pOleStr);
115 break;
117 case STRRET_CSTR:
118 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
119 ((LPWSTR)dest)[len-1] = 0;
120 break;
122 case STRRET_OFFSET:
123 if (pidl)
125 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
126 -1, (LPWSTR)dest, len ))
127 ((LPWSTR)dest)[len-1] = 0;
129 break;
131 default:
132 FIXME("unknown type!\n");
133 if (len)
134 { *(LPWSTR)dest = '\0';
136 return(FALSE);
138 return S_OK;
142 * IShellBrowser
145 /**************************************************************************
146 * IShellBrowserImpl_Construct
148 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
150 IShellBrowserImpl *sb;
151 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
153 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
155 /* Initialisation of the member variables */
156 sb->ref=1;
157 sb->hwndOwner = hwndOwner;
159 /* Initialisation of the vTables */
160 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
161 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
162 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
163 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
164 &fodInfos->ShellInfos.pidlAbsCurrent);
166 TRACE("%p\n", sb);
168 return (IShellBrowser *) sb;
171 /***************************************************************************
172 * IShellBrowserImpl_QueryInterface
174 HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
175 REFIID riid,
176 LPVOID *ppvObj)
178 ICOM_THIS(IShellBrowserImpl, iface);
180 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
182 *ppvObj = NULL;
184 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
185 { *ppvObj = This;
187 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
188 { *ppvObj = (IOleWindow*)This;
191 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
192 { *ppvObj = (IShellBrowser*)This;
195 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
196 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
199 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
200 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
203 if(*ppvObj)
204 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
205 return S_OK;
207 FIXME("Unknown interface requested\n");
208 return E_NOINTERFACE;
211 /**************************************************************************
212 * IShellBrowser::AddRef
214 ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
216 ICOM_THIS(IShellBrowserImpl, iface);
218 TRACE("(%p,%lu)\n", This, This->ref);
220 return ++(This->ref);
223 /**************************************************************************
224 * IShellBrowserImpl_Release
226 ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
228 ICOM_THIS(IShellBrowserImpl, iface);
230 TRACE("(%p,%lu)\n", This, This->ref);
232 if (!--(This->ref))
234 COMDLG32_SHFree(This);
235 TRACE("-- destroyed\n");
236 return 0;
238 return This->ref;
242 * IOleWindow
245 /**************************************************************************
246 * IShellBrowserImpl_GetWindow (IOleWindow)
248 * Inherited from IOleWindow::GetWindow
250 * See Windows documentation for more details
252 * Note : We will never be window less in the File Open dialog
255 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
256 HWND * phwnd)
258 ICOM_THIS(IShellBrowserImpl, iface);
260 TRACE("(%p)\n", This);
262 if(!This->hwndOwner)
263 return E_FAIL;
265 *phwnd = This->hwndOwner;
267 return (*phwnd) ? S_OK : E_UNEXPECTED;
271 /**************************************************************************
272 * IShellBrowserImpl_ContextSensitiveHelp
274 HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
275 BOOL fEnterMode)
277 ICOM_THIS(IShellBrowserImpl, iface);
279 TRACE("(%p)\n", This);
281 /* Feature not implemented */
282 return E_NOTIMPL;
286 * IShellBrowser
289 /**************************************************************************
290 * IShellBrowserImpl_BrowseObject
292 * See Windows documentation on IShellBrowser::BrowseObject for more details
294 * This function will override user specified flags and will always
295 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
297 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
298 LPCITEMIDLIST pidl,
299 UINT wFlags)
301 HRESULT hRes;
302 IShellFolder *psfTmp;
303 IShellView *psvTmp;
304 FileOpenDlgInfos *fodInfos;
305 LPITEMIDLIST pidlTmp;
306 HWND hwndView;
307 HWND hDlgWnd;
308 BOOL bViewHasFocus;
309 RECT rectView;
311 ICOM_THIS(IShellBrowserImpl, iface);
313 TRACE("(%p)(pidl=%p,flags=0x%08x(%s))\n", This, pidl, wFlags,
314 (wFlags & SBSP_RELATIVE) ? "SBSP_RELATIVE" :
315 (wFlags & SBSP_PARENT) ? "SBSP_PARENT" :
316 (wFlags & SBSP_ABSOLUTE) ? "SBSP_ABSOLUTE" : "SBPS_????");
318 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
320 /* Format the pidl according to its parameter's category */
321 if(wFlags & SBSP_RELATIVE)
324 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
325 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
326 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
328 ERR("bind to object failed\n");
329 return hRes;
331 /* create an absolute pidl */
332 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
333 (LPITEMIDLIST)pidl);
335 else if(wFlags & SBSP_PARENT)
337 /* Browse the parent folder (ignores the pidl) */
338 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
339 psfTmp = GetShellFolderFromPidl(pidlTmp);
342 else /* SBSP_ABSOLUTE is 0x0000 */
344 /* An absolute pidl (relative from the desktop) */
345 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
346 psfTmp = GetShellFolderFromPidl(pidlTmp);
349 if(!psfTmp)
351 ERR("could not browse to folder\n");
352 return E_FAIL;
355 /* If the pidl to browse to is equal to the actual pidl ...
356 do nothing and pretend you did it*/
357 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
359 IShellFolder_Release(psfTmp);
360 COMDLG32_SHFree(pidlTmp);
361 TRACE("keep current folder\n");
362 return NOERROR;
365 /* Release the current DataObject */
366 if (fodInfos->Shell.FOIDataObject)
368 IDataObject_Release(fodInfos->Shell.FOIDataObject);
369 fodInfos->Shell.FOIDataObject = NULL;
372 /* Create the associated view */
373 TRACE("create view object\n");
374 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
375 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
377 /* Check if listview has focus */
378 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
380 /* Get the foldersettings from the old view */
381 if(fodInfos->Shell.FOIShellView)
382 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
384 /* Release the old fodInfos->Shell.FOIShellView and update its value.
385 We have to update this early since ShellView_CreateViewWindow of native
386 shell32 calls OnStateChange and needs the correct view here.*/
387 if(fodInfos->Shell.FOIShellView)
389 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
390 IShellView_Release(fodInfos->Shell.FOIShellView);
392 fodInfos->Shell.FOIShellView = psvTmp;
394 /* Release old FOIShellFolder and update its value */
395 if (fodInfos->Shell.FOIShellFolder)
396 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
397 fodInfos->Shell.FOIShellFolder = psfTmp;
399 /* Release old pidlAbsCurrent and update its value */
400 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
401 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
403 COMDLG32_UpdateCurrentDir(fodInfos);
405 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
406 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
408 /* Create the window */
409 TRACE("create view window\n");
410 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
411 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
412 &rectView, &hwndView))) goto error;
414 fodInfos->ShellInfos.hwndView = hwndView;
416 /* Select the new folder in the Look In combo box of the Open file dialog */
417 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
419 /* changes the tab order of the ListView to reflect the window's File Dialog */
420 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
421 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
423 /* Since we destroyed the old view if it had focus set focus to the newly created view */
424 if (bViewHasFocus)
425 SetFocus(fodInfos->ShellInfos.hwndView);
427 return hRes;
428 error:
429 ERR("Failed with error 0x%08lx\n", hRes);
430 return hRes;
433 /**************************************************************************
434 * IShellBrowserImpl_EnableModelessSB
436 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
437 BOOL fEnable)
440 ICOM_THIS(IShellBrowserImpl, iface);
442 TRACE("(%p)\n", This);
444 /* Feature not implemented */
445 return E_NOTIMPL;
448 /**************************************************************************
449 * IShellBrowserImpl_GetControlWindow
451 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
452 UINT id,
453 HWND *lphwnd)
456 ICOM_THIS(IShellBrowserImpl, iface);
458 TRACE("(%p)\n", This);
460 /* Feature not implemented */
461 return E_NOTIMPL;
463 /**************************************************************************
464 * IShellBrowserImpl_GetViewStateStream
466 HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
467 DWORD grfMode,
468 LPSTREAM *ppStrm)
471 ICOM_THIS(IShellBrowserImpl, iface);
473 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
475 /* Feature not implemented */
476 return E_NOTIMPL;
478 /**************************************************************************
479 * IShellBrowserImpl_InsertMenusSB
481 HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
482 HMENU hmenuShared,
483 LPOLEMENUGROUPWIDTHS lpMenuWidths)
486 ICOM_THIS(IShellBrowserImpl, iface);
488 TRACE("(%p)\n", This);
490 /* Feature not implemented */
491 return E_NOTIMPL;
493 /**************************************************************************
494 * IShellBrowserImpl_OnViewWindowActive
496 HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
497 IShellView *ppshv)
500 ICOM_THIS(IShellBrowserImpl, iface);
502 TRACE("(%p)\n", This);
504 /* Feature not implemented */
505 return E_NOTIMPL;
507 /**************************************************************************
508 * IShellBrowserImpl_QueryActiveShellView
510 HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
511 IShellView **ppshv)
514 ICOM_THIS(IShellBrowserImpl, iface);
516 FileOpenDlgInfos *fodInfos;
518 TRACE("(%p)\n", This);
520 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
522 if(!(*ppshv = fodInfos->Shell.FOIShellView))
524 return E_FAIL;
526 IShellView_AddRef(fodInfos->Shell.FOIShellView);
527 return NOERROR;
529 /**************************************************************************
530 * IShellBrowserImpl_RemoveMenusSB
532 HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
533 HMENU hmenuShared)
536 ICOM_THIS(IShellBrowserImpl, iface);
538 TRACE("(%p)\n", This);
540 /* Feature not implemented */
541 return E_NOTIMPL;
543 /**************************************************************************
544 * IShellBrowserImpl_SendControlMsg
546 HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
547 UINT id,
548 UINT uMsg,
549 WPARAM wParam,
550 LPARAM lParam,
551 LRESULT *pret)
554 ICOM_THIS(IShellBrowserImpl, iface);
555 LRESULT lres;
557 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
559 switch (id)
561 case FCW_TOOLBAR:
562 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
563 break;
564 default:
565 FIXME("ctrl id: %x\n", id);
566 return E_NOTIMPL;
568 if (pret) *pret = lres;
569 return S_OK;
571 /**************************************************************************
572 * IShellBrowserImpl_SetMenuSB
574 HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
575 HMENU hmenuShared,
576 HOLEMENU holemenuReserved,
577 HWND hwndActiveObject)
580 ICOM_THIS(IShellBrowserImpl, iface);
582 TRACE("(%p)\n", This);
584 /* Feature not implemented */
585 return E_NOTIMPL;
587 /**************************************************************************
588 * IShellBrowserImpl_SetStatusTextSB
590 HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
591 LPCOLESTR lpszStatusText)
594 ICOM_THIS(IShellBrowserImpl, iface);
596 TRACE("(%p)\n", This);
598 /* Feature not implemented */
599 return E_NOTIMPL;
601 /**************************************************************************
602 * IShellBrowserImpl_SetToolbarItems
604 HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
605 LPTBBUTTON lpButtons,
606 UINT nButtons,
607 UINT uFlags)
610 ICOM_THIS(IShellBrowserImpl, iface);
612 TRACE("(%p)\n", This);
614 /* Feature not implemented */
615 return E_NOTIMPL;
617 /**************************************************************************
618 * IShellBrowserImpl_TranslateAcceleratorSB
620 HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
621 LPMSG lpmsg,
622 WORD wID)
625 ICOM_THIS(IShellBrowserImpl, iface);
627 TRACE("(%p)\n", This);
629 /* Feature not implemented */
630 return E_NOTIMPL;
633 static IShellBrowserVtbl IShellBrowserImpl_Vtbl =
635 /* IUnknown */
636 IShellBrowserImpl_QueryInterface,
637 IShellBrowserImpl_AddRef,
638 IShellBrowserImpl_Release,
639 /* IOleWindow */
640 IShellBrowserImpl_GetWindow,
641 IShellBrowserImpl_ContextSensitiveHelp,
642 /* IShellBrowser */
643 IShellBrowserImpl_InsertMenusSB,
644 IShellBrowserImpl_SetMenuSB,
645 IShellBrowserImpl_RemoveMenusSB,
646 IShellBrowserImpl_SetStatusTextSB,
647 IShellBrowserImpl_EnableModelessSB,
648 IShellBrowserImpl_TranslateAcceleratorSB,
649 IShellBrowserImpl_BrowseObject,
650 IShellBrowserImpl_GetViewStateStream,
651 IShellBrowserImpl_GetControlWindow,
652 IShellBrowserImpl_SendControlMsg,
653 IShellBrowserImpl_QueryActiveShellView,
654 IShellBrowserImpl_OnViewWindowActive,
655 IShellBrowserImpl_SetToolbarItems
661 * ICommDlgBrowser
664 /***************************************************************************
665 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
667 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
668 ICommDlgBrowser *iface,
669 REFIID riid,
670 LPVOID *ppvObj)
672 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
674 TRACE("(%p)\n", This);
676 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
679 /**************************************************************************
680 * IShellBrowserImpl_ICommDlgBrowser_AddRef
682 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
684 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
686 TRACE("(%p)\n", This);
688 return IShellBrowserImpl_AddRef(This);
691 /**************************************************************************
692 * IShellBrowserImpl_ICommDlgBrowser_Release
694 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
696 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
698 TRACE("(%p)\n", This);
700 return IShellBrowserImpl_Release(This);
702 /**************************************************************************
703 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
705 * Called when a user double-clicks in the view or presses the ENTER key
707 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
708 IShellView *ppshv)
710 LPITEMIDLIST pidl;
711 FileOpenDlgInfos *fodInfos;
713 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
715 TRACE("(%p)\n", This);
717 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
719 /* If the selected object is not a folder, send a IDOK command to parent window */
720 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
722 HRESULT hRes;
724 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
725 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
726 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
728 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
729 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
731 else
733 /* Tell the dialog that the user selected a file */
734 hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
737 /* Free memory used by pidl */
738 COMDLG32_SHFree((LPVOID)pidl);
740 return hRes;
743 return E_FAIL;
746 /**************************************************************************
747 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
749 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
750 IShellView *ppshv,
751 ULONG uChange)
754 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
756 TRACE("(%p shv=%p)\n", This, ppshv);
758 switch (uChange)
760 case CDBOSC_SETFOCUS:
761 /* FIXME: Reset the default button.
762 This should be taken care of by defdlg. If control
763 other than button receives focus the default button
764 should be restored. */
765 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
767 break;
768 case CDBOSC_KILLFOCUS:
770 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
771 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
772 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
774 break;
775 case CDBOSC_SELCHANGE:
776 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
777 case CDBOSC_RENAME:
778 /* nothing to do */
779 break;
782 return NOERROR;
785 /**************************************************************************
786 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
788 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
789 IShellView * ppshv,
790 LPCITEMIDLIST pidl)
792 FileOpenDlgInfos *fodInfos;
793 ULONG ulAttr;
794 STRRET str;
795 WCHAR szPathW[MAX_PATH];
797 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
799 TRACE("(%p)\n", This);
801 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
803 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
804 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
806 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
807 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
808 return S_FALSE;
810 /* always include directories and links */
811 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
812 return S_OK;
814 /* Check if there is a mask to apply if not */
815 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
816 return S_OK;
818 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
820 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
822 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
823 return S_OK;
826 return S_FALSE;
830 /**************************************************************************
831 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
833 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
835 FileOpenDlgInfos *fodInfos;
837 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
839 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
840 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
842 /* release old selections */
843 if (fodInfos->Shell.FOIDataObject)
844 IDataObject_Release(fodInfos->Shell.FOIDataObject);
846 /* get a new DataObject from the ShellView */
847 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
848 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
849 return E_FAIL;
851 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
853 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
854 return S_OK;
857 static ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =
859 /* IUnknown */
860 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
861 IShellBrowserImpl_ICommDlgBrowser_AddRef,
862 IShellBrowserImpl_ICommDlgBrowser_Release,
863 /* ICommDlgBrowser */
864 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
865 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
866 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
873 * IServiceProvider
876 /***************************************************************************
877 * IShellBrowserImpl_IServiceProvider_QueryInterface
879 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
880 IServiceProvider *iface,
881 REFIID riid,
882 LPVOID *ppvObj)
884 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
886 FIXME("(%p)\n", This);
888 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
891 /**************************************************************************
892 * IShellBrowserImpl_IServiceProvider_AddRef
894 ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
896 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
898 FIXME("(%p)\n", This);
900 return IShellBrowserImpl_AddRef(This);
903 /**************************************************************************
904 * IShellBrowserImpl_IServiceProvider_Release
906 ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
908 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
910 FIXME("(%p)\n", This);
912 return IShellBrowserImpl_Release(This);
915 /**************************************************************************
916 * IShellBrowserImpl_IServiceProvider_Release
918 * NOTES
919 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
920 * riid = IShellBrowser) to call SendControlMsg ().
922 * FIXME
923 * this is a hack!
926 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
927 IServiceProvider * iface,
928 REFGUID guidService,
929 REFIID riid,
930 void** ppv)
932 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
934 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
936 *ppv = NULL;
937 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
939 return IShellBrowserImpl_QueryInterface(This,riid,ppv);
941 FIXME("(%p) unknown interface requested\n", This);
942 return E_NOINTERFACE;
946 static IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =
948 /* IUnknown */
949 IShellBrowserImpl_IServiceProvider_QueryInterface,
950 IShellBrowserImpl_IServiceProvider_AddRef,
951 IShellBrowserImpl_IServiceProvider_Release,
952 /* IServiceProvider */
953 IShellBrowserImpl_IServiceProvider_QueryService