Arg 3 of CoGetClassObject is COSERVERINFO*, added some more debug.
[wine.git] / dlls / commdlg / filedlgbrowser.c
blob3feebee7410d7511032cdc75137ef67b08ed79b7
1 /*
2 * Implementation of IShellBrowser for the File Open common dialog
3 *
5 */
7 #include <stdio.h>
8 #include <string.h>
10 #include "windef.h"
11 #include "winbase.h"
12 #include "winnls.h"
13 #include "wingdi.h"
14 #include "winuser.h"
15 #include "heap.h"
16 #include "debugtools.h"
18 #include "shlwapi.h"
19 #include "filedlgbrowser.h"
20 #include "cdlg.h"
21 #include "shlguid.h"
22 #include "wine/obj_serviceprovider.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg);
26 typedef struct
29 ICOM_VTABLE(IShellBrowser) * lpVtbl;
30 ICOM_VTABLE(ICommDlgBrowser) * lpVtblCommDlgBrowser;
31 ICOM_VTABLE(IServiceProvider)* lpVtblServiceProvider;
32 DWORD ref; /* Reference counter */
33 HWND hwndOwner; /* Owner dialog of the interface */
35 } IShellBrowserImpl;
37 /**************************************************************************
38 * vtable
40 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl;
41 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl;
42 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl;
44 /**************************************************************************
45 * Local Prototypes
48 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
49 #if 0
50 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
51 #endif
53 /**************************************************************************
54 * External Prototypes
56 extern const char *FileOpenDlgInfosStr;
58 extern HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
59 extern HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
60 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
61 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
62 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
64 extern BOOL FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,
65 LPITEMIDLIST pidlCurrentFolder,
66 LPSTR lpstrMask);
68 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
69 extern BOOL FILEDLG95_OnOpen(HWND hwnd);
70 extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
74 * Helper functions
77 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
79 char lpstrPath[MAX_PATH];
80 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
81 SetCurrentDirectoryA(lpstrPath);
82 TRACE("new current folder %s\n", lpstrPath);
85 /* copied from shell32 to avoid linking to it */
86 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
88 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
90 switch (src->uType)
92 case STRRET_WSTR:
93 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
94 COMDLG32_SHFree(src->u.pOleStr);
95 break;
97 case STRRET_CSTRA:
98 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
99 ((LPWSTR)dest)[len-1] = 0;
100 break;
102 case STRRET_OFFSETA:
103 if (pidl)
105 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
106 -1, (LPWSTR)dest, len ))
107 ((LPWSTR)dest)[len-1] = 0;
109 break;
111 default:
112 FIXME("unknown type!\n");
113 if (len)
114 { *(LPWSTR)dest = '\0';
116 return(FALSE);
118 return S_OK;
122 * IShellBrowser
125 /**************************************************************************
126 * IShellBrowserImpl_Construct
128 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
130 IShellBrowserImpl *sb;
131 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
133 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
135 /* Initialisation of the member variables */
136 sb->ref=1;
137 sb->hwndOwner = hwndOwner;
139 /* Initialisation of the vTables */
140 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
141 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
142 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
143 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
144 &fodInfos->ShellInfos.pidlAbsCurrent);
146 TRACE("%p\n", sb);
148 return (IShellBrowser *) sb;
151 /***************************************************************************
152 * IShellBrowserImpl_QueryInterface
154 HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
155 REFIID riid,
156 LPVOID *ppvObj)
158 ICOM_THIS(IShellBrowserImpl, iface);
160 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
162 *ppvObj = NULL;
164 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
165 { *ppvObj = This;
167 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
168 { *ppvObj = (IOleWindow*)This;
171 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
172 { *ppvObj = (IShellBrowser*)This;
175 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
176 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
179 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
180 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
183 if(*ppvObj)
184 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
185 return S_OK;
187 FIXME("Unknown interface requested\n");
188 return E_NOINTERFACE;
191 /**************************************************************************
192 * IShellBrowser::AddRef
194 ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
196 ICOM_THIS(IShellBrowserImpl, iface);
198 TRACE("(%p)\n", This);
200 return ++(This->ref);
203 /**************************************************************************
204 * IShellBrowserImpl_Release
206 ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
208 ICOM_THIS(IShellBrowserImpl, iface);
210 TRACE("(%p)\n", This);
212 if (!--(This->ref))
214 HeapFree(GetProcessHeap(),0, This);
215 return 0;
217 return This->ref;
221 * IOleWindow
224 /**************************************************************************
225 * IShellBrowserImpl_GetWindow (IOleWindow)
227 * Inherited from IOleWindow::GetWindow
229 * See Windows documentation for more details
231 * Note : We will never be window less in the File Open dialog
234 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
235 HWND * phwnd)
237 ICOM_THIS(IShellBrowserImpl, iface);
239 TRACE("(%p)\n", This);
241 if(!This->hwndOwner)
242 return E_FAIL;
244 *phwnd = This->hwndOwner;
246 return (*phwnd) ? S_OK : E_UNEXPECTED;
250 /**************************************************************************
251 * IShellBrowserImpl_ContextSensitiveHelp
253 HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
254 BOOL fEnterMode)
256 ICOM_THIS(IShellBrowserImpl, iface);
258 TRACE("(%p)\n", This);
260 /* Feature not implemented */
261 return E_NOTIMPL;
265 * IShellBrowser
268 /**************************************************************************
269 * IShellBrowserImpl_BrowseObject
271 * See Windows documentation on IShellBrowser::BrowseObject for more details
273 * This function will override user specified flags and will always
274 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
276 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
277 LPCITEMIDLIST pidl,
278 UINT wFlags)
280 HRESULT hRes;
281 IShellFolder *psfTmp;
282 IShellView *psvTmp;
283 FileOpenDlgInfos *fodInfos;
284 LPITEMIDLIST pidlTmp;
285 HWND hwndView;
286 HWND hDlgWnd;
287 BOOL bViewHasFocus;
289 ICOM_THIS(IShellBrowserImpl, iface);
291 TRACE("(%p)(%p,0x%08x)\n", This, pidl, wFlags);
293 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
295 /* Format the pidl according to its parameter's category */
296 if(wFlags & SBSP_RELATIVE)
299 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
300 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
301 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
303 ERR("bind to object failed\n");
304 return hRes;
306 /* create an absolute pidl */
307 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
308 (LPITEMIDLIST)pidl);
310 else if(wFlags & SBSP_PARENT)
312 /* Browse the parent folder (ignores the pidl) */
313 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
314 psfTmp = GetShellFolderFromPidl(pidlTmp);
317 else /* SBSP_ABSOLUTE is 0x0000 */
319 /* An absolute pidl (relative from the desktop) */
320 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
321 psfTmp = GetShellFolderFromPidl(pidlTmp);
324 if(!psfTmp)
326 ERR("could not browse to folder\n");
327 return E_FAIL;
330 /* If the pidl to browse to is equal to the actual pidl ...
331 do nothing and pretend you did it*/
332 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
334 IShellFolder_Release(psfTmp);
335 COMDLG32_SHFree(pidlTmp);
336 TRACE("keep current folder\n");
337 return NOERROR;
340 /* Release the current DataObject */
341 if (fodInfos->Shell.FOIDataObject)
343 IDataObject_Release(fodInfos->Shell.FOIDataObject);
344 fodInfos->Shell.FOIDataObject = NULL;
347 /* Create the associated view */
348 TRACE("create view object\n");
349 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
350 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
352 /* Check if listview has focus */
353 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
355 /* Get the foldersettings from the old view */
356 if(fodInfos->Shell.FOIShellView)
357 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
359 /* Release the old fodInfos->Shell.FOIShellView and update its value.
360 We have to update this early since ShellView_CreateViewWindow of native
361 shell32 calls OnStateChange and needs the correct view here.*/
362 if(fodInfos->Shell.FOIShellView)
364 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
365 IShellView_Release(fodInfos->Shell.FOIShellView);
367 fodInfos->Shell.FOIShellView = psvTmp;
369 /* Release old FOIShellFolder and update its value */
370 if (fodInfos->Shell.FOIShellFolder)
371 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
372 fodInfos->Shell.FOIShellFolder = psfTmp;
374 /* Release old pidlAbsCurrent and update its value */
375 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
376 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
378 COMDLG32_UpdateCurrentDir(fodInfos);
380 /* Create the window */
381 TRACE("create view window\n");
382 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
383 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
384 &fodInfos->ShellInfos.rectView, &hwndView))) goto error;
386 fodInfos->ShellInfos.hwndView = hwndView;
388 /* Select the new folder in the Look In combo box of the Open file dialog */
389 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
391 /* changes the tab order of the ListView to reflect the window's File Dialog */
392 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
393 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
395 /* Since we destroyed the old view if it had focus set focus to the newly created view */
396 if (bViewHasFocus)
397 SetFocus(fodInfos->ShellInfos.hwndView);
399 return hRes;
400 error:
401 ERR("Failed with error 0x%08lx\n", hRes);
402 return hRes;
405 /**************************************************************************
406 * IShellBrowserImpl_EnableModelessSB
408 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
409 BOOL fEnable)
412 ICOM_THIS(IShellBrowserImpl, iface);
414 TRACE("(%p)\n", This);
416 /* Feature not implemented */
417 return E_NOTIMPL;
420 /**************************************************************************
421 * IShellBrowserImpl_GetControlWindow
423 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
424 UINT id,
425 HWND *lphwnd)
428 ICOM_THIS(IShellBrowserImpl, iface);
430 TRACE("(%p)\n", This);
432 /* Feature not implemented */
433 return E_NOTIMPL;
435 /**************************************************************************
436 * IShellBrowserImpl_GetViewStateStream
438 HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
439 DWORD grfMode,
440 LPSTREAM *ppStrm)
443 ICOM_THIS(IShellBrowserImpl, iface);
445 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
447 /* Feature not implemented */
448 return E_NOTIMPL;
450 /**************************************************************************
451 * IShellBrowserImpl_InsertMenusSB
453 HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
454 HMENU hmenuShared,
455 LPOLEMENUGROUPWIDTHS lpMenuWidths)
458 ICOM_THIS(IShellBrowserImpl, iface);
460 TRACE("(%p)\n", This);
462 /* Feature not implemented */
463 return E_NOTIMPL;
465 /**************************************************************************
466 * IShellBrowserImpl_OnViewWindowActive
468 HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
469 IShellView *ppshv)
472 ICOM_THIS(IShellBrowserImpl, iface);
474 TRACE("(%p)\n", This);
476 /* Feature not implemented */
477 return E_NOTIMPL;
479 /**************************************************************************
480 * IShellBrowserImpl_QueryActiveShellView
482 HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
483 IShellView **ppshv)
486 ICOM_THIS(IShellBrowserImpl, iface);
488 FileOpenDlgInfos *fodInfos;
490 TRACE("(%p)\n", This);
492 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
494 if(!(*ppshv = fodInfos->Shell.FOIShellView))
496 return E_FAIL;
498 IShellView_AddRef(fodInfos->Shell.FOIShellView);
499 return NOERROR;
501 /**************************************************************************
502 * IShellBrowserImpl_RemoveMenusSB
504 HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
505 HMENU hmenuShared)
508 ICOM_THIS(IShellBrowserImpl, iface);
510 TRACE("(%p)\n", This);
512 /* Feature not implemented */
513 return E_NOTIMPL;
515 /**************************************************************************
516 * IShellBrowserImpl_SendControlMsg
518 HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
519 UINT id,
520 UINT uMsg,
521 WPARAM wParam,
522 LPARAM lParam,
523 LRESULT *pret)
526 ICOM_THIS(IShellBrowserImpl, iface);
527 LRESULT lres;
529 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
531 switch (id)
533 case FCW_TOOLBAR:
534 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
535 break;
536 default:
537 FIXME("ctrl id: %x\n", id);
538 return E_NOTIMPL;
540 if (pret) *pret = lres;
541 return S_OK;
543 /**************************************************************************
544 * IShellBrowserImpl_SetMenuSB
546 HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
547 HMENU hmenuShared,
548 HOLEMENU holemenuReserved,
549 HWND hwndActiveObject)
552 ICOM_THIS(IShellBrowserImpl, iface);
554 TRACE("(%p)\n", This);
556 /* Feature not implemented */
557 return E_NOTIMPL;
559 /**************************************************************************
560 * IShellBrowserImpl_SetStatusTextSB
562 HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
563 LPCOLESTR lpszStatusText)
566 ICOM_THIS(IShellBrowserImpl, iface);
568 TRACE("(%p)\n", This);
570 /* Feature not implemented */
571 return E_NOTIMPL;
573 /**************************************************************************
574 * IShellBrowserImpl_SetToolbarItems
576 HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
577 LPTBBUTTON lpButtons,
578 UINT nButtons,
579 UINT uFlags)
582 ICOM_THIS(IShellBrowserImpl, iface);
584 TRACE("(%p)\n", This);
586 /* Feature not implemented */
587 return E_NOTIMPL;
589 /**************************************************************************
590 * IShellBrowserImpl_TranslateAcceleratorSB
592 HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
593 LPMSG lpmsg,
594 WORD wID)
597 ICOM_THIS(IShellBrowserImpl, iface);
599 TRACE("(%p)\n", This);
601 /* Feature not implemented */
602 return E_NOTIMPL;
605 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl =
607 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
608 /* IUnknown */
609 IShellBrowserImpl_QueryInterface,
610 IShellBrowserImpl_AddRef,
611 IShellBrowserImpl_Release,
612 /* IOleWindow */
613 IShellBrowserImpl_GetWindow,
614 IShellBrowserImpl_ContextSensitiveHelp,
615 /* IShellBrowser */
616 IShellBrowserImpl_InsertMenusSB,
617 IShellBrowserImpl_SetMenuSB,
618 IShellBrowserImpl_RemoveMenusSB,
619 IShellBrowserImpl_SetStatusTextSB,
620 IShellBrowserImpl_EnableModelessSB,
621 IShellBrowserImpl_TranslateAcceleratorSB,
622 IShellBrowserImpl_BrowseObject,
623 IShellBrowserImpl_GetViewStateStream,
624 IShellBrowserImpl_GetControlWindow,
625 IShellBrowserImpl_SendControlMsg,
626 IShellBrowserImpl_QueryActiveShellView,
627 IShellBrowserImpl_OnViewWindowActive,
628 IShellBrowserImpl_SetToolbarItems
634 * ICommDlgBrowser
637 /***************************************************************************
638 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
640 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
641 ICommDlgBrowser *iface,
642 REFIID riid,
643 LPVOID *ppvObj)
645 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
647 TRACE("(%p)\n", This);
649 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
652 /**************************************************************************
653 * IShellBrowserImpl_ICommDlgBrowser_AddRef
655 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
657 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
659 TRACE("(%p)\n", This);
661 return IShellBrowserImpl_AddRef(This);
664 /**************************************************************************
665 * IShellBrowserImpl_ICommDlgBrowser_Release
667 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
669 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
671 TRACE("(%p)\n", This);
673 return IShellBrowserImpl_Release(This);
675 /**************************************************************************
676 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
678 * Called when a user double-clicks in the view or presses the ENTER key
680 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
681 IShellView *ppshv)
683 LPITEMIDLIST pidl;
684 FileOpenDlgInfos *fodInfos;
686 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
688 TRACE("(%p)\n", This);
690 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
692 /* If the selected object is not a folder, send a IDOK command to parent window */
693 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
695 HRESULT hRes;
697 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
698 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
699 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
701 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
703 else
705 /* Tell the dialog that the user selected a file */
706 hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
709 /* Free memory used by pidl */
710 COMDLG32_SHFree((LPVOID)pidl);
712 return hRes;
715 return E_FAIL;
718 /**************************************************************************
719 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
721 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
722 IShellView *ppshv,
723 ULONG uChange)
726 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
728 TRACE("(%p shv=%p)\n", This, ppshv);
730 switch (uChange)
732 case CDBOSC_SETFOCUS:
733 /* FIXME: Reset the default button.
734 This should be taken care of by defdlg. If control
735 other than button receives focus the default button
736 should be restored. */
737 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
739 break;
740 case CDBOSC_KILLFOCUS:
742 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
743 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
744 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
746 break;
747 case CDBOSC_SELCHANGE:
748 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
749 case CDBOSC_RENAME:
750 /* nothing to do */
751 break;
754 return NOERROR;
757 /**************************************************************************
758 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
760 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
761 IShellView * ppshv,
762 LPCITEMIDLIST pidl)
764 FileOpenDlgInfos *fodInfos;
765 ULONG ulAttr;
766 STRRET str;
767 WCHAR szPathW[MAX_PATH];
769 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
771 TRACE("(%p)\n", This);
773 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
775 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
776 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
778 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
779 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
780 return S_FALSE;
782 /* always include directorys and links */
783 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
784 return S_OK;
786 /* Check if there is a mask to apply if not */
787 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
788 return S_OK;
790 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
792 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
794 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
795 return S_OK;
798 return S_FALSE;
802 /**************************************************************************
803 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
805 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
807 FileOpenDlgInfos *fodInfos;
809 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
811 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
812 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
814 /* release old selections */
815 if (fodInfos->Shell.FOIDataObject)
816 IDataObject_Release(fodInfos->Shell.FOIDataObject);
818 /* get a new DataObject from the ShellView */
819 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
820 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
821 return E_FAIL;
823 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
825 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
826 return S_OK;
829 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl =
831 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
832 /* IUnknown */
833 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
834 IShellBrowserImpl_ICommDlgBrowser_AddRef,
835 IShellBrowserImpl_ICommDlgBrowser_Release,
836 /* ICommDlgBrowser */
837 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
838 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
839 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
846 * IServiceProvider
849 /***************************************************************************
850 * IShellBrowserImpl_IServiceProvider_QueryInterface
852 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
853 IServiceProvider *iface,
854 REFIID riid,
855 LPVOID *ppvObj)
857 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
859 FIXME("(%p)\n", This);
861 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
864 /**************************************************************************
865 * IShellBrowserImpl_IServiceProvider_AddRef
867 ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
869 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
871 FIXME("(%p)\n", This);
873 return IShellBrowserImpl_AddRef(This);
876 /**************************************************************************
877 * IShellBrowserImpl_IServiceProvider_Release
879 ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
881 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
883 FIXME("(%p)\n", This);
885 return IShellBrowserImpl_Release(This);
888 /**************************************************************************
889 * IShellBrowserImpl_IServiceProvider_Release
891 * NOTES
892 * the w2k shellview asks for
893 * guidService = SID_STopLevelBrowser
894 * riid = IShellBrowser
896 * FIXME
897 * this is a hack!
900 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
901 IServiceProvider * iface,
902 REFGUID guidService,
903 REFIID riid,
904 void** ppv)
906 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
908 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
910 *ppv = NULL;
911 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
913 return IShellBrowserImpl_QueryInterface(This,riid,ppv);
915 FIXME("(%p) unknown interface requested\n", This);
916 return E_NOINTERFACE;
920 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl =
922 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
923 /* IUnknown */
924 IShellBrowserImpl_IServiceProvider_QueryInterface,
925 IShellBrowserImpl_IServiceProvider_AddRef,
926 IShellBrowserImpl_IServiceProvider_Release,
927 /* IServiceProvider */
928 IShellBrowserImpl_IServiceProvider_QueryService