Fix definition of LookupPrivilegeNameW and declare it.
[wine/multimedia.git] / dlls / commdlg / filedlgbrowser.c
blobdb1ade8b0c9ce8cf921c95a737265a7b3af2377d
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 ICOM_VTABLE(IShellBrowser) * lpVtbl;
49 ICOM_VTABLE(ICommDlgBrowser) * lpVtblCommDlgBrowser;
50 ICOM_VTABLE(IServiceProvider)* lpVtblServiceProvider;
51 DWORD ref; /* Reference counter */
52 HWND hwndOwner; /* Owner dialog of the interface */
54 } IShellBrowserImpl;
56 /**************************************************************************
57 * vtable
59 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl;
60 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl;
61 static ICOM_VTABLE(IServiceProvider) 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 ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl =
635 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
636 /* IUnknown */
637 IShellBrowserImpl_QueryInterface,
638 IShellBrowserImpl_AddRef,
639 IShellBrowserImpl_Release,
640 /* IOleWindow */
641 IShellBrowserImpl_GetWindow,
642 IShellBrowserImpl_ContextSensitiveHelp,
643 /* IShellBrowser */
644 IShellBrowserImpl_InsertMenusSB,
645 IShellBrowserImpl_SetMenuSB,
646 IShellBrowserImpl_RemoveMenusSB,
647 IShellBrowserImpl_SetStatusTextSB,
648 IShellBrowserImpl_EnableModelessSB,
649 IShellBrowserImpl_TranslateAcceleratorSB,
650 IShellBrowserImpl_BrowseObject,
651 IShellBrowserImpl_GetViewStateStream,
652 IShellBrowserImpl_GetControlWindow,
653 IShellBrowserImpl_SendControlMsg,
654 IShellBrowserImpl_QueryActiveShellView,
655 IShellBrowserImpl_OnViewWindowActive,
656 IShellBrowserImpl_SetToolbarItems
662 * ICommDlgBrowser
665 /***************************************************************************
666 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
668 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
669 ICommDlgBrowser *iface,
670 REFIID riid,
671 LPVOID *ppvObj)
673 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
675 TRACE("(%p)\n", This);
677 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
680 /**************************************************************************
681 * IShellBrowserImpl_ICommDlgBrowser_AddRef
683 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
685 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
687 TRACE("(%p)\n", This);
689 return IShellBrowserImpl_AddRef(This);
692 /**************************************************************************
693 * IShellBrowserImpl_ICommDlgBrowser_Release
695 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
697 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
699 TRACE("(%p)\n", This);
701 return IShellBrowserImpl_Release(This);
703 /**************************************************************************
704 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
706 * Called when a user double-clicks in the view or presses the ENTER key
708 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
709 IShellView *ppshv)
711 LPITEMIDLIST pidl;
712 FileOpenDlgInfos *fodInfos;
714 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
716 TRACE("(%p)\n", This);
718 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
720 /* If the selected object is not a folder, send a IDOK command to parent window */
721 if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
723 HRESULT hRes;
725 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
726 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, (LPCITEMIDLIST *)&pidl, &ulAttr);
727 if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
729 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
730 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_FOLDERCHANGE);
732 else
734 /* Tell the dialog that the user selected a file */
735 hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
738 /* Free memory used by pidl */
739 COMDLG32_SHFree((LPVOID)pidl);
741 return hRes;
744 return E_FAIL;
747 /**************************************************************************
748 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
750 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
751 IShellView *ppshv,
752 ULONG uChange)
755 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
757 TRACE("(%p shv=%p)\n", This, ppshv);
759 switch (uChange)
761 case CDBOSC_SETFOCUS:
762 /* FIXME: Reset the default button.
763 This should be taken care of by defdlg. If control
764 other than button receives focus the default button
765 should be restored. */
766 SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
768 break;
769 case CDBOSC_KILLFOCUS:
771 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
772 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
773 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
775 break;
776 case CDBOSC_SELCHANGE:
777 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
778 case CDBOSC_RENAME:
779 /* nothing to do */
780 break;
783 return NOERROR;
786 /**************************************************************************
787 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
789 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
790 IShellView * ppshv,
791 LPCITEMIDLIST pidl)
793 FileOpenDlgInfos *fodInfos;
794 ULONG ulAttr;
795 STRRET str;
796 WCHAR szPathW[MAX_PATH];
798 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
800 TRACE("(%p)\n", This);
802 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
804 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
805 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
807 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
808 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
809 return S_FALSE;
811 /* always include directories and links */
812 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
813 return S_OK;
815 /* Check if there is a mask to apply if not */
816 if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
817 return S_OK;
819 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
821 if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
823 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
824 return S_OK;
827 return S_FALSE;
831 /**************************************************************************
832 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
834 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
836 FileOpenDlgInfos *fodInfos;
838 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
840 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
841 TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
843 /* release old selections */
844 if (fodInfos->Shell.FOIDataObject)
845 IDataObject_Release(fodInfos->Shell.FOIDataObject);
847 /* get a new DataObject from the ShellView */
848 if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
849 &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
850 return E_FAIL;
852 FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
854 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
855 return S_OK;
858 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl =
860 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
861 /* IUnknown */
862 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
863 IShellBrowserImpl_ICommDlgBrowser_AddRef,
864 IShellBrowserImpl_ICommDlgBrowser_Release,
865 /* ICommDlgBrowser */
866 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
867 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
868 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
875 * IServiceProvider
878 /***************************************************************************
879 * IShellBrowserImpl_IServiceProvider_QueryInterface
881 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
882 IServiceProvider *iface,
883 REFIID riid,
884 LPVOID *ppvObj)
886 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
888 FIXME("(%p)\n", This);
890 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
893 /**************************************************************************
894 * IShellBrowserImpl_IServiceProvider_AddRef
896 ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
898 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
900 FIXME("(%p)\n", This);
902 return IShellBrowserImpl_AddRef(This);
905 /**************************************************************************
906 * IShellBrowserImpl_IServiceProvider_Release
908 ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
910 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
912 FIXME("(%p)\n", This);
914 return IShellBrowserImpl_Release(This);
917 /**************************************************************************
918 * IShellBrowserImpl_IServiceProvider_Release
920 * NOTES
921 * the w2k shellview asks for (guidService = SID_STopLevelBrowser,
922 * riid = IShellBrowser) to call SendControlMsg ().
924 * FIXME
925 * this is a hack!
928 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
929 IServiceProvider * iface,
930 REFGUID guidService,
931 REFIID riid,
932 void** ppv)
934 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
936 FIXME("(%p)\n\t%s\n\t%s\n", This,debugstr_guid(guidService), debugstr_guid(riid) );
938 *ppv = NULL;
939 if(guidService && IsEqualIID(guidService, &SID_STopLevelBrowser))
941 return IShellBrowserImpl_QueryInterface(This,riid,ppv);
943 FIXME("(%p) unknown interface requested\n", This);
944 return E_NOINTERFACE;
948 static ICOM_VTABLE(IServiceProvider) IShellBrowserImpl_IServiceProvider_Vtbl =
950 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
951 /* IUnknown */
952 IShellBrowserImpl_IServiceProvider_QueryInterface,
953 IShellBrowserImpl_IServiceProvider_AddRef,
954 IShellBrowserImpl_IServiceProvider_Release,
955 /* IServiceProvider */
956 IShellBrowserImpl_IServiceProvider_QueryService