Replaced some GetProcAddress() imports by the standard dll import
[wine.git] / dlls / commdlg / filedlgbrowser.c
blobac1b6c1abf089f0693bce59864371e2f4d539039
1 /*
2 * Implementation of IShellBrowser for the File Open common dialog
3 *
5 */
7 #include <stdio.h>
9 #include "windef.h"
10 #include "winbase.h"
11 #include "winnls.h"
12 #include "wingdi.h"
13 #include "winuser.h"
14 #include "heap.h"
15 #include "debugtools.h"
17 #include "shlwapi.h"
18 #include "filedlgbrowser.h"
19 #include "cdlg.h"
20 #include "shlguid.h"
21 #include "wine/obj_serviceprovider.h"
23 DEFAULT_DEBUG_CHANNEL(commdlg);
25 typedef struct
28 ICOM_VTABLE(IShellBrowser) * lpVtbl;
29 ICOM_VTABLE(ICommDlgBrowser) * lpVtblCommDlgBrowser;
30 ICOM_VTABLE(IServiceProvider)* lpVtblServiceProvider;
31 DWORD ref; /* Reference counter */
32 HWND hwndOwner; /* Owner dialog of the interface */
34 } IShellBrowserImpl;
36 /**************************************************************************
37 * vtable
39 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl;
40 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl;
41 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl;
43 /**************************************************************************
44 * Local Prototypes
47 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
48 #if 0
49 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
50 #endif
52 /**************************************************************************
53 * External Prototypes
55 extern const char *FileOpenDlgInfosStr;
57 extern HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
58 extern HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
59 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
60 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
61 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
63 extern BOOL FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,
64 LPITEMIDLIST pidlCurrentFolder,
65 LPSTR lpstrMask);
67 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
68 extern BOOL FILEDLG95_OnOpen(HWND hwnd);
69 extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
73 * Helper functions
76 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
78 char lpstrPath[MAX_PATH];
79 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
80 SetCurrentDirectoryA(lpstrPath);
81 TRACE("new current folder %s\n", lpstrPath);
84 /* copied from shell32 to avoid linking to it */
85 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
87 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
89 switch (src->uType)
91 case STRRET_WSTR:
92 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
93 COMDLG32_SHFree(src->u.pOleStr);
94 break;
96 case STRRET_CSTRA:
97 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
98 ((LPWSTR)dest)[len-1] = 0;
99 break;
101 case STRRET_OFFSETA:
102 if (pidl)
104 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
105 -1, (LPWSTR)dest, len ))
106 ((LPWSTR)dest)[len-1] = 0;
108 break;
110 default:
111 FIXME("unknown type!\n");
112 if (len)
113 { *(LPWSTR)dest = '\0';
115 return(FALSE);
117 return S_OK;
121 * IShellBrowser
124 /**************************************************************************
125 * IShellBrowserImpl_Construct
127 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
129 IShellBrowserImpl *sb;
130 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
132 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
134 /* Initialisation of the member variables */
135 sb->ref=1;
136 sb->hwndOwner = hwndOwner;
138 /* Initialisation of the vTables */
139 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
140 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
141 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
142 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
143 &fodInfos->ShellInfos.pidlAbsCurrent);
145 TRACE("%p\n", sb);
147 return (IShellBrowser *) sb;
150 /***************************************************************************
151 * IShellBrowserImpl_QueryInterface
153 HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
154 REFIID riid,
155 LPVOID *ppvObj)
157 ICOM_THIS(IShellBrowserImpl, iface);
159 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
161 *ppvObj = NULL;
163 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
164 { *ppvObj = This;
166 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
167 { *ppvObj = (IOleWindow*)This;
170 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
171 { *ppvObj = (IShellBrowser*)This;
174 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
175 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
178 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
179 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
182 if(*ppvObj)
183 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
184 return S_OK;
186 FIXME("Unknown interface requested\n");
187 return E_NOINTERFACE;
190 /**************************************************************************
191 * IShellBrowser::AddRef
193 ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
195 ICOM_THIS(IShellBrowserImpl, iface);
197 TRACE("(%p)\n", This);
199 return ++(This->ref);
202 /**************************************************************************
203 * IShellBrowserImpl_Release
205 ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
207 ICOM_THIS(IShellBrowserImpl, iface);
209 TRACE("(%p)\n", This);
211 if (!--(This->ref))
213 HeapFree(GetProcessHeap(),0, This);
214 return 0;
216 return This->ref;
220 * IOleWindow
223 /**************************************************************************
224 * IShellBrowserImpl_GetWindow (IOleWindow)
226 * Inherited from IOleWindow::GetWindow
228 * See Windows documentation for more details
230 * Note : We will never be window less in the File Open dialog
233 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
234 HWND * phwnd)
236 ICOM_THIS(IShellBrowserImpl, iface);
238 TRACE("(%p)\n", This);
240 if(!This->hwndOwner)
241 return E_FAIL;
243 *phwnd = This->hwndOwner;
245 return (*phwnd) ? S_OK : E_UNEXPECTED;
249 /**************************************************************************
250 * IShellBrowserImpl_ContextSensitiveHelp
252 HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
253 BOOL fEnterMode)
255 ICOM_THIS(IShellBrowserImpl, iface);
257 TRACE("(%p)\n", This);
259 /* Feature not implemented */
260 return E_NOTIMPL;
264 * IShellBrowser
267 /**************************************************************************
268 * IShellBrowserImpl_BrowseObject
270 * See Windows documentation on IShellBrowser::BrowseObject for more details
272 * This function will override user specified flags and will always
273 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
275 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
276 LPCITEMIDLIST pidl,
277 UINT wFlags)
279 HRESULT hRes;
280 IShellFolder *psfTmp;
281 IShellView *psvTmp;
282 FileOpenDlgInfos *fodInfos;
283 LPITEMIDLIST pidlTmp;
284 HWND hwndView;
285 HWND hDlgWnd;
286 BOOL bViewHasFocus;
288 ICOM_THIS(IShellBrowserImpl, iface);
290 TRACE("(%p)(%p,0x%08x)\n", This, pidl, wFlags);
292 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
294 /* Format the pidl according to its parameter's category */
295 if(wFlags & SBSP_RELATIVE)
298 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
299 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
300 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
302 ERR("bind to object failed\n");
303 return hRes;
305 /* create an absolute pidl */
306 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
307 (LPITEMIDLIST)pidl);
309 else if(wFlags & SBSP_PARENT)
311 /* Browse the parent folder (ignores the pidl) */
312 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
313 psfTmp = GetShellFolderFromPidl(pidlTmp);
316 else /* SBSP_ABSOLUTE is 0x0000 */
318 /* An absolute pidl (relative from the desktop) */
319 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
320 psfTmp = GetShellFolderFromPidl(pidlTmp);
323 if(!psfTmp)
325 ERR("could not browse to folder\n");
326 return E_FAIL;
329 /* If the pidl to browse to is equal to the actual pidl ...
330 do nothing and pretend you did it*/
331 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
333 IShellFolder_Release(psfTmp);
334 COMDLG32_SHFree(pidlTmp);
335 TRACE("keep current folder\n");
336 return NOERROR;
339 /* Release the current DataObject */
340 if (fodInfos->Shell.FOIDataObject)
342 IDataObject_Release(fodInfos->Shell.FOIDataObject);
343 fodInfos->Shell.FOIDataObject = NULL;
346 /* Create the associated view */
347 TRACE("create view object\n");
348 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
349 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
351 /* Check if listview has focus */
352 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
354 /* Get the foldersettings from the old view */
355 if(fodInfos->Shell.FOIShellView)
356 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
358 /* Release the old fodInfos->Shell.FOIShellView and update its value.
359 We have to update this early since ShellView_CreateViewWindow of native
360 shell32 calls OnStateChange and needs the correct view here.*/
361 if(fodInfos->Shell.FOIShellView)
363 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
364 IShellView_Release(fodInfos->Shell.FOIShellView);
366 fodInfos->Shell.FOIShellView = psvTmp;
368 /* Release old FOIShellFolder and update its value */
369 if (fodInfos->Shell.FOIShellFolder)
370 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
371 fodInfos->Shell.FOIShellFolder = psfTmp;
373 /* Release old pidlAbsCurrent and update its value */
374 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
375 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
377 COMDLG32_UpdateCurrentDir(fodInfos);
379 /* Create the window */
380 TRACE("create view window\n");
381 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
382 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
383 &fodInfos->ShellInfos.rectView, &hwndView))) goto error;
385 fodInfos->ShellInfos.hwndView = hwndView;
387 /* Select the new folder in the Look In combo box of the Open file dialog */
388 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
390 /* changes the tab order of the ListView to reflect the window's File Dialog */
391 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
392 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
394 /* Since we destroyed the old view if it had focus set focus to the newly created view */
395 if (bViewHasFocus)
396 SetFocus(fodInfos->ShellInfos.hwndView);
398 return hRes;
399 error:
400 ERR("Failed with error 0x%08lx\n", hRes);
401 return hRes;
404 /**************************************************************************
405 * IShellBrowserImpl_EnableModelessSB
407 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
408 BOOL fEnable)
411 ICOM_THIS(IShellBrowserImpl, iface);
413 TRACE("(%p)\n", This);
415 /* Feature not implemented */
416 return E_NOTIMPL;
419 /**************************************************************************
420 * IShellBrowserImpl_GetControlWindow
422 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
423 UINT id,
424 HWND *lphwnd)
427 ICOM_THIS(IShellBrowserImpl, iface);
429 TRACE("(%p)\n", This);
431 /* Feature not implemented */
432 return E_NOTIMPL;
434 /**************************************************************************
435 * IShellBrowserImpl_GetViewStateStream
437 HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
438 DWORD grfMode,
439 LPSTREAM *ppStrm)
442 ICOM_THIS(IShellBrowserImpl, iface);
444 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
446 /* Feature not implemented */
447 return E_NOTIMPL;
449 /**************************************************************************
450 * IShellBrowserImpl_InsertMenusSB
452 HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
453 HMENU hmenuShared,
454 LPOLEMENUGROUPWIDTHS lpMenuWidths)
457 ICOM_THIS(IShellBrowserImpl, iface);
459 TRACE("(%p)\n", This);
461 /* Feature not implemented */
462 return E_NOTIMPL;
464 /**************************************************************************
465 * IShellBrowserImpl_OnViewWindowActive
467 HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
468 IShellView *ppshv)
471 ICOM_THIS(IShellBrowserImpl, iface);
473 TRACE("(%p)\n", This);
475 /* Feature not implemented */
476 return E_NOTIMPL;
478 /**************************************************************************
479 * IShellBrowserImpl_QueryActiveShellView
481 HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
482 IShellView **ppshv)
485 ICOM_THIS(IShellBrowserImpl, iface);
487 FileOpenDlgInfos *fodInfos;
489 TRACE("(%p)\n", This);
491 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
493 if(!(*ppshv = fodInfos->Shell.FOIShellView))
495 return E_FAIL;
497 IShellView_AddRef(fodInfos->Shell.FOIShellView);
498 return NOERROR;
500 /**************************************************************************
501 * IShellBrowserImpl_RemoveMenusSB
503 HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
504 HMENU hmenuShared)
507 ICOM_THIS(IShellBrowserImpl, iface);
509 TRACE("(%p)\n", This);
511 /* Feature not implemented */
512 return E_NOTIMPL;
514 /**************************************************************************
515 * IShellBrowserImpl_SendControlMsg
517 HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
518 UINT id,
519 UINT uMsg,
520 WPARAM wParam,
521 LPARAM lParam,
522 LRESULT *pret)
525 ICOM_THIS(IShellBrowserImpl, iface);
526 LRESULT lres;
528 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
530 switch (id)
532 case FCW_TOOLBAR:
533 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
534 break;
535 default:
536 FIXME("ctrl id: %x\n", id);
537 return E_NOTIMPL;
539 if (pret) *pret = lres;
540 return S_OK;
542 /**************************************************************************
543 * IShellBrowserImpl_SetMenuSB
545 HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
546 HMENU hmenuShared,
547 HOLEMENU holemenuReserved,
548 HWND hwndActiveObject)
551 ICOM_THIS(IShellBrowserImpl, iface);
553 TRACE("(%p)\n", This);
555 /* Feature not implemented */
556 return E_NOTIMPL;
558 /**************************************************************************
559 * IShellBrowserImpl_SetStatusTextSB
561 HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
562 LPCOLESTR lpszStatusText)
565 ICOM_THIS(IShellBrowserImpl, iface);
567 TRACE("(%p)\n", This);
569 /* Feature not implemented */
570 return E_NOTIMPL;
572 /**************************************************************************
573 * IShellBrowserImpl_SetToolbarItems
575 HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
576 LPTBBUTTON lpButtons,
577 UINT nButtons,
578 UINT uFlags)
581 ICOM_THIS(IShellBrowserImpl, iface);
583 TRACE("(%p)\n", This);
585 /* Feature not implemented */
586 return E_NOTIMPL;
588 /**************************************************************************
589 * IShellBrowserImpl_TranslateAcceleratorSB
591 HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
592 LPMSG lpmsg,
593 WORD wID)
596 ICOM_THIS(IShellBrowserImpl, iface);
598 TRACE("(%p)\n", This);
600 /* Feature not implemented */
601 return E_NOTIMPL;
604 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl =
606 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
607 /* IUnknown */
608 IShellBrowserImpl_QueryInterface,
609 IShellBrowserImpl_AddRef,
610 IShellBrowserImpl_Release,
611 /* IOleWindow */
612 IShellBrowserImpl_GetWindow,
613 IShellBrowserImpl_ContextSensitiveHelp,
614 /* IShellBrowser */
615 IShellBrowserImpl_InsertMenusSB,
616 IShellBrowserImpl_SetMenuSB,
617 IShellBrowserImpl_RemoveMenusSB,
618 IShellBrowserImpl_SetStatusTextSB,
619 IShellBrowserImpl_EnableModelessSB,
620 IShellBrowserImpl_TranslateAcceleratorSB,
621 IShellBrowserImpl_BrowseObject,
622 IShellBrowserImpl_GetViewStateStream,
623 IShellBrowserImpl_GetControlWindow,
624 IShellBrowserImpl_SendControlMsg,
625 IShellBrowserImpl_QueryActiveShellView,
626 IShellBrowserImpl_OnViewWindowActive,
627 IShellBrowserImpl_SetToolbarItems
633 * ICommDlgBrowser
636 /***************************************************************************
637 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
639 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
640 ICommDlgBrowser *iface,
641 REFIID riid,
642 LPVOID *ppvObj)
644 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
646 TRACE("(%p)\n", This);
648 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
651 /**************************************************************************
652 * IShellBrowserImpl_ICommDlgBrowser_AddRef
654 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
656 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
658 TRACE("(%p)\n", This);
660 return IShellBrowserImpl_AddRef(This);
663 /**************************************************************************
664 * IShellBrowserImpl_ICommDlgBrowser_Release
666 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
668 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
670 TRACE("(%p)\n", This);
672 return IShellBrowserImpl_Release(This);
674 /**************************************************************************
675 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
677 * Called when a user double-clicks in the view or presses the ENTER key
679 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
680 IShellView *ppshv)
682 LPITEMIDLIST pidl;
683 FileOpenDlgInfos *fodInfos;
685 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
687 TRACE("(%p)\n", This);
689 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
691 /* If the selected object is not a folder, send a IDOK command to parent window */
692 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
694 HRESULT hRes;
696 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
697 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
698 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
700 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
702 else
704 /* Tell the dialog that the user selected a file */
705 hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
708 /* Free memory used by pidl */
709 COMDLG32_SHFree((LPVOID)pidl);
711 return hRes;
714 return E_FAIL;
717 /**************************************************************************
718 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
720 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
721 IShellView *ppshv,
722 ULONG uChange)
725 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
727 TRACE("(%p shv=%p)\n", This, ppshv);
729 switch (uChange)
731 case CDBOSC_SETFOCUS:
732 /* FIXME: Reset the default button.
733 This should be taken care of by defdlg. If control
734 other than button receives focus the default button
735 should be restored. */
736 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
738 break;
739 case CDBOSC_KILLFOCUS:
741 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
742 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
743 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
745 break;
746 case CDBOSC_SELCHANGE:
747 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
748 case CDBOSC_RENAME:
749 /* nothing to do */
750 break;
753 return NOERROR;
756 /**************************************************************************
757 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
759 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
760 IShellView * ppshv,
761 LPCITEMIDLIST pidl)
763 FileOpenDlgInfos *fodInfos;
764 ULONG ulAttr;
765 STRRET str;
766 WCHAR szPathW[MAX_PATH];
768 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
770 TRACE("(%p)\n", This);
772 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
774 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
775 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
777 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
778 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
779 return S_FALSE;
781 /* always include directorys and links */
782 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
783 return S_OK;
785 /* Check if there is a mask to apply if not */
786 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
787 return S_OK;
789 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
791 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
793 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
794 return S_OK;
797 return S_FALSE;
801 /**************************************************************************
802 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
804 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
806 FileOpenDlgInfos *fodInfos;
808 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
810 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
811 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
813 /* release old selections */
814 if (fodInfos->Shell.FOIDataObject)
815 IDataObject_Release(fodInfos->Shell.FOIDataObject);
817 /* get a new DataObject from the ShellView */
818 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
819 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
820 return E_FAIL;
822 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
824 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
825 return S_OK;
828 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl =
830 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
831 /* IUnknown */
832 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
833 IShellBrowserImpl_ICommDlgBrowser_AddRef,
834 IShellBrowserImpl_ICommDlgBrowser_Release,
835 /* ICommDlgBrowser */
836 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
837 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
838 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
845 * IServiceProvider
848 /***************************************************************************
849 * IShellBrowserImpl_IServiceProvider_QueryInterface
851 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
852 IServiceProvider *iface,
853 REFIID riid,
854 LPVOID *ppvObj)
856 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
858 FIXME("(%p)\n", This);
860 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
863 /**************************************************************************
864 * IShellBrowserImpl_IServiceProvider_AddRef
866 ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
868 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
870 FIXME("(%p)\n", This);
872 return IShellBrowserImpl_AddRef(This);
875 /**************************************************************************
876 * IShellBrowserImpl_IServiceProvider_Release
878 ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
880 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
882 FIXME("(%p)\n", This);
884 return IShellBrowserImpl_Release(This);
887 /**************************************************************************
888 * IShellBrowserImpl_IServiceProvider_Release
890 * NOTES
891 * the w2k shellview asks for
892 * guidService = SID_STopLevelBrowser
893 * riid = IShellBrowser
895 * FIXME
896 * this is a hack!
899 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
900 IServiceProvider * iface,
901 REFGUID guidService,
902 REFIID riid,
903 void** ppv)
905 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
907 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
909 *ppv = NULL;
910 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
912 return IShellBrowserImpl_QueryInterface(This,riid,ppv);
914 FIXME("(%p) unknown interface requested\n", This);
915 return E_NOINTERFACE;
919 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl =
921 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
922 /* IUnknown */
923 IShellBrowserImpl_IServiceProvider_QueryInterface,
924 IShellBrowserImpl_IServiceProvider_AddRef,
925 IShellBrowserImpl_IServiceProvider_Release,
926 /* IServiceProvider */
927 IShellBrowserImpl_IServiceProvider_QueryService