Authors: David Hammerton <david@transgaming.com>, Peter Hunnisett <peter@transgaming...
[wine.git] / dlls / commdlg / filedlgbrowser.c
blob7d0d649d83623e02b50d2dad294280768f3ba98c
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 <stdio.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winreg.h"
32 #define NO_SHLWAPI_STREAM
33 #include "shlwapi.h"
34 #include "filedlgbrowser.h"
35 #include "cdlg.h"
36 #include "shlguid.h"
37 #include "wine/obj_serviceprovider.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
42 typedef struct
45 ICOM_VTABLE(IShellBrowser) * lpVtbl;
46 ICOM_VTABLE(ICommDlgBrowser) * lpVtblCommDlgBrowser;
47 ICOM_VTABLE(IServiceProvider)* lpVtblServiceProvider;
48 DWORD ref; /* Reference counter */
49 HWND hwndOwner; /* Owner dialog of the interface */
51 } IShellBrowserImpl;
53 /**************************************************************************
54 * vtable
56 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl;
57 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl;
58 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl;
60 /**************************************************************************
61 * Local Prototypes
64 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
65 #if 0
66 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
67 #endif
69 /**************************************************************************
70 * External Prototypes
72 extern const char *FileOpenDlgInfosStr;
74 extern HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
75 extern HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
76 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
77 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
78 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
80 extern BOOL FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,
81 LPITEMIDLIST pidlCurrentFolder,
82 LPSTR lpstrMask);
84 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
85 extern BOOL FILEDLG95_OnOpen(HWND hwnd);
86 extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
90 * Helper functions
93 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
95 char lpstrPath[MAX_PATH];
96 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
97 SetCurrentDirectoryA(lpstrPath);
98 TRACE("new current folder %s\n", lpstrPath);
101 /* copied from shell32 to avoid linking to it */
102 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
104 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
106 switch (src->uType)
108 case STRRET_WSTR:
109 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
110 COMDLG32_SHFree(src->u.pOleStr);
111 break;
113 case STRRET_CSTRA:
114 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
115 ((LPWSTR)dest)[len-1] = 0;
116 break;
118 case STRRET_OFFSETA:
119 if (pidl)
121 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
122 -1, (LPWSTR)dest, len ))
123 ((LPWSTR)dest)[len-1] = 0;
125 break;
127 default:
128 FIXME("unknown type!\n");
129 if (len)
130 { *(LPWSTR)dest = '\0';
132 return(FALSE);
134 return S_OK;
138 * IShellBrowser
141 /**************************************************************************
142 * IShellBrowserImpl_Construct
144 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
146 IShellBrowserImpl *sb;
147 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
149 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
151 /* Initialisation of the member variables */
152 sb->ref=1;
153 sb->hwndOwner = hwndOwner;
155 /* Initialisation of the vTables */
156 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
157 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
158 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
159 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
160 &fodInfos->ShellInfos.pidlAbsCurrent);
162 TRACE("%p\n", sb);
164 return (IShellBrowser *) sb;
167 /***************************************************************************
168 * IShellBrowserImpl_QueryInterface
170 HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
171 REFIID riid,
172 LPVOID *ppvObj)
174 ICOM_THIS(IShellBrowserImpl, iface);
176 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
178 *ppvObj = NULL;
180 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
181 { *ppvObj = This;
183 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
184 { *ppvObj = (IOleWindow*)This;
187 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
188 { *ppvObj = (IShellBrowser*)This;
191 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
192 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
195 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
196 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
199 if(*ppvObj)
200 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
201 return S_OK;
203 FIXME("Unknown interface requested\n");
204 return E_NOINTERFACE;
207 /**************************************************************************
208 * IShellBrowser::AddRef
210 ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
212 ICOM_THIS(IShellBrowserImpl, iface);
214 TRACE("(%p)\n", This);
216 return ++(This->ref);
219 /**************************************************************************
220 * IShellBrowserImpl_Release
222 ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
224 ICOM_THIS(IShellBrowserImpl, iface);
226 TRACE("(%p)\n", This);
228 if (!--(This->ref))
230 HeapFree(GetProcessHeap(),0, This);
231 return 0;
233 return This->ref;
237 * IOleWindow
240 /**************************************************************************
241 * IShellBrowserImpl_GetWindow (IOleWindow)
243 * Inherited from IOleWindow::GetWindow
245 * See Windows documentation for more details
247 * Note : We will never be window less in the File Open dialog
250 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
251 HWND * phwnd)
253 ICOM_THIS(IShellBrowserImpl, iface);
255 TRACE("(%p)\n", This);
257 if(!This->hwndOwner)
258 return E_FAIL;
260 *phwnd = This->hwndOwner;
262 return (*phwnd) ? S_OK : E_UNEXPECTED;
266 /**************************************************************************
267 * IShellBrowserImpl_ContextSensitiveHelp
269 HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
270 BOOL fEnterMode)
272 ICOM_THIS(IShellBrowserImpl, iface);
274 TRACE("(%p)\n", This);
276 /* Feature not implemented */
277 return E_NOTIMPL;
281 * IShellBrowser
284 /**************************************************************************
285 * IShellBrowserImpl_BrowseObject
287 * See Windows documentation on IShellBrowser::BrowseObject for more details
289 * This function will override user specified flags and will always
290 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
292 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
293 LPCITEMIDLIST pidl,
294 UINT wFlags)
296 HRESULT hRes;
297 IShellFolder *psfTmp;
298 IShellView *psvTmp;
299 FileOpenDlgInfos *fodInfos;
300 LPITEMIDLIST pidlTmp;
301 HWND hwndView;
302 HWND hDlgWnd;
303 BOOL bViewHasFocus;
305 ICOM_THIS(IShellBrowserImpl, iface);
307 TRACE("(%p)(%p,0x%08x)\n", This, pidl, wFlags);
309 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
311 /* Format the pidl according to its parameter's category */
312 if(wFlags & SBSP_RELATIVE)
315 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
316 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
317 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
319 ERR("bind to object failed\n");
320 return hRes;
322 /* create an absolute pidl */
323 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
324 (LPITEMIDLIST)pidl);
326 else if(wFlags & SBSP_PARENT)
328 /* Browse the parent folder (ignores the pidl) */
329 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
330 psfTmp = GetShellFolderFromPidl(pidlTmp);
333 else /* SBSP_ABSOLUTE is 0x0000 */
335 /* An absolute pidl (relative from the desktop) */
336 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
337 psfTmp = GetShellFolderFromPidl(pidlTmp);
340 if(!psfTmp)
342 ERR("could not browse to folder\n");
343 return E_FAIL;
346 /* If the pidl to browse to is equal to the actual pidl ...
347 do nothing and pretend you did it*/
348 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
350 IShellFolder_Release(psfTmp);
351 COMDLG32_SHFree(pidlTmp);
352 TRACE("keep current folder\n");
353 return NOERROR;
356 /* Release the current DataObject */
357 if (fodInfos->Shell.FOIDataObject)
359 IDataObject_Release(fodInfos->Shell.FOIDataObject);
360 fodInfos->Shell.FOIDataObject = NULL;
363 /* Create the associated view */
364 TRACE("create view object\n");
365 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
366 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
368 /* Check if listview has focus */
369 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
371 /* Get the foldersettings from the old view */
372 if(fodInfos->Shell.FOIShellView)
373 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
375 /* Release the old fodInfos->Shell.FOIShellView and update its value.
376 We have to update this early since ShellView_CreateViewWindow of native
377 shell32 calls OnStateChange and needs the correct view here.*/
378 if(fodInfos->Shell.FOIShellView)
380 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
381 IShellView_Release(fodInfos->Shell.FOIShellView);
383 fodInfos->Shell.FOIShellView = psvTmp;
385 /* Release old FOIShellFolder and update its value */
386 if (fodInfos->Shell.FOIShellFolder)
387 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
388 fodInfos->Shell.FOIShellFolder = psfTmp;
390 /* Release old pidlAbsCurrent and update its value */
391 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
392 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
394 COMDLG32_UpdateCurrentDir(fodInfos);
396 /* Create the window */
397 TRACE("create view window\n");
398 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
399 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
400 &fodInfos->ShellInfos.rectView, &hwndView))) goto error;
402 fodInfos->ShellInfos.hwndView = hwndView;
404 /* Select the new folder in the Look In combo box of the Open file dialog */
405 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
407 /* changes the tab order of the ListView to reflect the window's File Dialog */
408 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
409 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
411 /* Since we destroyed the old view if it had focus set focus to the newly created view */
412 if (bViewHasFocus)
413 SetFocus(fodInfos->ShellInfos.hwndView);
415 return hRes;
416 error:
417 ERR("Failed with error 0x%08lx\n", hRes);
418 return hRes;
421 /**************************************************************************
422 * IShellBrowserImpl_EnableModelessSB
424 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
425 BOOL fEnable)
428 ICOM_THIS(IShellBrowserImpl, iface);
430 TRACE("(%p)\n", This);
432 /* Feature not implemented */
433 return E_NOTIMPL;
436 /**************************************************************************
437 * IShellBrowserImpl_GetControlWindow
439 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
440 UINT id,
441 HWND *lphwnd)
444 ICOM_THIS(IShellBrowserImpl, iface);
446 TRACE("(%p)\n", This);
448 /* Feature not implemented */
449 return E_NOTIMPL;
451 /**************************************************************************
452 * IShellBrowserImpl_GetViewStateStream
454 HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
455 DWORD grfMode,
456 LPSTREAM *ppStrm)
459 ICOM_THIS(IShellBrowserImpl, iface);
461 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
463 /* Feature not implemented */
464 return E_NOTIMPL;
466 /**************************************************************************
467 * IShellBrowserImpl_InsertMenusSB
469 HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
470 HMENU hmenuShared,
471 LPOLEMENUGROUPWIDTHS lpMenuWidths)
474 ICOM_THIS(IShellBrowserImpl, iface);
476 TRACE("(%p)\n", This);
478 /* Feature not implemented */
479 return E_NOTIMPL;
481 /**************************************************************************
482 * IShellBrowserImpl_OnViewWindowActive
484 HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
485 IShellView *ppshv)
488 ICOM_THIS(IShellBrowserImpl, iface);
490 TRACE("(%p)\n", This);
492 /* Feature not implemented */
493 return E_NOTIMPL;
495 /**************************************************************************
496 * IShellBrowserImpl_QueryActiveShellView
498 HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
499 IShellView **ppshv)
502 ICOM_THIS(IShellBrowserImpl, iface);
504 FileOpenDlgInfos *fodInfos;
506 TRACE("(%p)\n", This);
508 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
510 if(!(*ppshv = fodInfos->Shell.FOIShellView))
512 return E_FAIL;
514 IShellView_AddRef(fodInfos->Shell.FOIShellView);
515 return NOERROR;
517 /**************************************************************************
518 * IShellBrowserImpl_RemoveMenusSB
520 HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
521 HMENU hmenuShared)
524 ICOM_THIS(IShellBrowserImpl, iface);
526 TRACE("(%p)\n", This);
528 /* Feature not implemented */
529 return E_NOTIMPL;
531 /**************************************************************************
532 * IShellBrowserImpl_SendControlMsg
534 HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
535 UINT id,
536 UINT uMsg,
537 WPARAM wParam,
538 LPARAM lParam,
539 LRESULT *pret)
542 ICOM_THIS(IShellBrowserImpl, iface);
543 LRESULT lres;
545 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
547 switch (id)
549 case FCW_TOOLBAR:
550 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
551 break;
552 default:
553 FIXME("ctrl id: %x\n", id);
554 return E_NOTIMPL;
556 if (pret) *pret = lres;
557 return S_OK;
559 /**************************************************************************
560 * IShellBrowserImpl_SetMenuSB
562 HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
563 HMENU hmenuShared,
564 HOLEMENU holemenuReserved,
565 HWND hwndActiveObject)
568 ICOM_THIS(IShellBrowserImpl, iface);
570 TRACE("(%p)\n", This);
572 /* Feature not implemented */
573 return E_NOTIMPL;
575 /**************************************************************************
576 * IShellBrowserImpl_SetStatusTextSB
578 HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
579 LPCOLESTR lpszStatusText)
582 ICOM_THIS(IShellBrowserImpl, iface);
584 TRACE("(%p)\n", This);
586 /* Feature not implemented */
587 return E_NOTIMPL;
589 /**************************************************************************
590 * IShellBrowserImpl_SetToolbarItems
592 HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
593 LPTBBUTTON lpButtons,
594 UINT nButtons,
595 UINT uFlags)
598 ICOM_THIS(IShellBrowserImpl, iface);
600 TRACE("(%p)\n", This);
602 /* Feature not implemented */
603 return E_NOTIMPL;
605 /**************************************************************************
606 * IShellBrowserImpl_TranslateAcceleratorSB
608 HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
609 LPMSG lpmsg,
610 WORD wID)
613 ICOM_THIS(IShellBrowserImpl, iface);
615 TRACE("(%p)\n", This);
617 /* Feature not implemented */
618 return E_NOTIMPL;
621 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl =
623 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
624 /* IUnknown */
625 IShellBrowserImpl_QueryInterface,
626 IShellBrowserImpl_AddRef,
627 IShellBrowserImpl_Release,
628 /* IOleWindow */
629 IShellBrowserImpl_GetWindow,
630 IShellBrowserImpl_ContextSensitiveHelp,
631 /* IShellBrowser */
632 IShellBrowserImpl_InsertMenusSB,
633 IShellBrowserImpl_SetMenuSB,
634 IShellBrowserImpl_RemoveMenusSB,
635 IShellBrowserImpl_SetStatusTextSB,
636 IShellBrowserImpl_EnableModelessSB,
637 IShellBrowserImpl_TranslateAcceleratorSB,
638 IShellBrowserImpl_BrowseObject,
639 IShellBrowserImpl_GetViewStateStream,
640 IShellBrowserImpl_GetControlWindow,
641 IShellBrowserImpl_SendControlMsg,
642 IShellBrowserImpl_QueryActiveShellView,
643 IShellBrowserImpl_OnViewWindowActive,
644 IShellBrowserImpl_SetToolbarItems
650 * ICommDlgBrowser
653 /***************************************************************************
654 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
656 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
657 ICommDlgBrowser *iface,
658 REFIID riid,
659 LPVOID *ppvObj)
661 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
663 TRACE("(%p)\n", This);
665 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
668 /**************************************************************************
669 * IShellBrowserImpl_ICommDlgBrowser_AddRef
671 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
673 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
675 TRACE("(%p)\n", This);
677 return IShellBrowserImpl_AddRef(This);
680 /**************************************************************************
681 * IShellBrowserImpl_ICommDlgBrowser_Release
683 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
685 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
687 TRACE("(%p)\n", This);
689 return IShellBrowserImpl_Release(This);
691 /**************************************************************************
692 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
694 * Called when a user double-clicks in the view or presses the ENTER key
696 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
697 IShellView *ppshv)
699 LPITEMIDLIST pidl;
700 FileOpenDlgInfos *fodInfos;
702 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
704 TRACE("(%p)\n", This);
706 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
708 /* If the selected object is not a folder, send a IDOK command to parent window */
709 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
711 HRESULT hRes;
713 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
714 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
715 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
717 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
719 else
721 /* Tell the dialog that the user selected a file */
722 hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
725 /* Free memory used by pidl */
726 COMDLG32_SHFree((LPVOID)pidl);
728 return hRes;
731 return E_FAIL;
734 /**************************************************************************
735 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
737 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
738 IShellView *ppshv,
739 ULONG uChange)
742 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
744 TRACE("(%p shv=%p)\n", This, ppshv);
746 switch (uChange)
748 case CDBOSC_SETFOCUS:
749 /* FIXME: Reset the default button.
750 This should be taken care of by defdlg. If control
751 other than button receives focus the default button
752 should be restored. */
753 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
755 break;
756 case CDBOSC_KILLFOCUS:
758 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
759 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
760 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
762 break;
763 case CDBOSC_SELCHANGE:
764 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
765 case CDBOSC_RENAME:
766 /* nothing to do */
767 break;
770 return NOERROR;
773 /**************************************************************************
774 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
776 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
777 IShellView * ppshv,
778 LPCITEMIDLIST pidl)
780 FileOpenDlgInfos *fodInfos;
781 ULONG ulAttr;
782 STRRET str;
783 WCHAR szPathW[MAX_PATH];
785 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
787 TRACE("(%p)\n", This);
789 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
791 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
792 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
794 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
795 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
796 return S_FALSE;
798 /* always include directories and links */
799 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
800 return S_OK;
802 /* Check if there is a mask to apply if not */
803 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
804 return S_OK;
806 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
808 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
810 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
811 return S_OK;
814 return S_FALSE;
818 /**************************************************************************
819 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
821 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
823 FileOpenDlgInfos *fodInfos;
825 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
827 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
828 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
830 /* release old selections */
831 if (fodInfos->Shell.FOIDataObject)
832 IDataObject_Release(fodInfos->Shell.FOIDataObject);
834 /* get a new DataObject from the ShellView */
835 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
836 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
837 return E_FAIL;
839 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
841 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
842 return S_OK;
845 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl =
847 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
848 /* IUnknown */
849 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
850 IShellBrowserImpl_ICommDlgBrowser_AddRef,
851 IShellBrowserImpl_ICommDlgBrowser_Release,
852 /* ICommDlgBrowser */
853 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
854 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
855 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
862 * IServiceProvider
865 /***************************************************************************
866 * IShellBrowserImpl_IServiceProvider_QueryInterface
868 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
869 IServiceProvider *iface,
870 REFIID riid,
871 LPVOID *ppvObj)
873 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
875 FIXME("(%p)\n", This);
877 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
880 /**************************************************************************
881 * IShellBrowserImpl_IServiceProvider_AddRef
883 ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
885 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
887 FIXME("(%p)\n", This);
889 return IShellBrowserImpl_AddRef(This);
892 /**************************************************************************
893 * IShellBrowserImpl_IServiceProvider_Release
895 ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
897 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
899 FIXME("(%p)\n", This);
901 return IShellBrowserImpl_Release(This);
904 /**************************************************************************
905 * IShellBrowserImpl_IServiceProvider_Release
907 * NOTES
908 * the w2k shellview asks for
909 * guidService = SID_STopLevelBrowser
910 * riid = IShellBrowser
912 * FIXME
913 * this is a hack!
916 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
917 IServiceProvider * iface,
918 REFGUID guidService,
919 REFIID riid,
920 void** ppv)
922 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
924 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
926 *ppv = NULL;
927 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
929 return IShellBrowserImpl_QueryInterface(This,riid,ppv);
931 FIXME("(%p) unknown interface requested\n", This);
932 return E_NOINTERFACE;
936 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl =
938 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
939 /* IUnknown */
940 IShellBrowserImpl_IServiceProvider_QueryInterface,
941 IShellBrowserImpl_IServiceProvider_AddRef,
942 IShellBrowserImpl_IServiceProvider_Release,
943 /* IServiceProvider */
944 IShellBrowserImpl_IServiceProvider_QueryService