Made the buttons in the filedlg change when selecting a different
[wine.git] / dlls / commdlg / filedlgbrowser.c
blob1c487f12611eda2f5604f6102e06fe832988ac46
1 /*
2 * Implementation of IShellBrowser for the File Open common dialog
3 *
5 */
7 #include <stdio.h>
8 #include "unknwn.h"
9 #include "filedlgbrowser.h"
10 #include "winuser.h"
11 #include "heap.h"
12 #include "wine/obj_dataobject.h"
13 #include "debugtools.h"
14 #include "cdlg.h"
15 #include "wine/undocshell.h"
17 DEFAULT_DEBUG_CHANNEL(commdlg)
19 #define SETDefFormatEtc(fe,cf,med) \
20 { \
21 (fe).cfFormat = cf;\
22 (fe).dwAspect = DVASPECT_CONTENT; \
23 (fe).ptd =NULL;\
24 (fe).tymed = med;\
25 (fe).lindex = -1;\
29 /**************************************************************************
30 * Structure
32 static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl =
34 /* IUnknown */
35 IShellBrowserImpl_QueryInterface,
36 IShellBrowserImpl_AddRef,
37 IShellBrowserImpl_Release,
38 /* IOleWindow */
39 IShellBrowserImpl_GetWindow,
40 IShellBrowserImpl_ContextSensitiveHelp,
41 /* IShellBrowser */
42 IShellBrowserImpl_InsertMenusSB,
43 IShellBrowserImpl_SetMenuSB,
44 IShellBrowserImpl_RemoveMenusSB,
45 IShellBrowserImpl_SetStatusTextSB,
46 IShellBrowserImpl_EnableModelessSB,
47 IShellBrowserImpl_TranslateAcceleratorSB,
48 IShellBrowserImpl_BrowseObject,
49 IShellBrowserImpl_GetViewStateStream,
50 IShellBrowserImpl_GetControlWindow,
51 IShellBrowserImpl_SendControlMsg,
52 IShellBrowserImpl_QueryActiveShellView,
53 IShellBrowserImpl_OnViewWindowActive,
54 IShellBrowserImpl_SetToolbarItems
57 static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl =
59 /* IUnknown */
60 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
61 IShellBrowserImpl_ICommDlgBrowser_AddRef,
62 IShellBrowserImpl_ICommDlgBrowser_Release,
63 /* ICommDlgBrowser */
64 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
65 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
66 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
70 /**************************************************************************
71 * Local Prototypes
74 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
75 #if 0
76 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
77 #endif
79 /**************************************************************************
80 * External Prototypes
82 extern const char *FileOpenDlgInfosStr;
84 extern HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
85 extern HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
86 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
87 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
88 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
90 extern BOOL FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,
91 LPITEMIDLIST pidlCurrentFolder,
92 LPSTR lpstrMask);
94 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
95 extern BOOL FILEDLG95_OnOpen(HWND hwnd);
96 extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
99 /**************************************************************************
100 * IShellBrowserImpl_Construct
102 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
104 IShellBrowserImpl *sb;
105 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
107 sb=(IShellBrowserImpl*)SHAlloc(sizeof(IShellBrowserImpl));
109 /* Initialisation of the member variables */
110 sb->ref=1;
111 sb->hwndOwner = hwndOwner;
113 /* Initialisation of the vTables */
114 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
115 sb->lpVtbl2 = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
117 COMDLG32_SHGetSpecialFolderLocation(hwndOwner,
118 CSIDL_DESKTOP,
119 &fodInfos->ShellInfos.pidlAbsCurrent);
121 TRACE("%p\n", sb);
123 return (IShellBrowser *) sb;
126 /**************************************************************************
129 * The INTERFACE of the IShellBrowser object
134 * IUnknown
137 /***************************************************************************
138 * IShellBrowserImpl_QueryInterface
140 HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
141 REFIID riid,
142 LPVOID *ppvObj)
144 ICOM_THIS(IShellBrowserImpl, iface);
146 TRACE("(%p)\n", This);
148 *ppvObj = NULL;
150 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
151 { *ppvObj = This;
153 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
154 { *ppvObj = (IOleWindow*)This;
157 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
158 { *ppvObj = (IShellBrowser*)This;
161 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
162 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtbl2);
165 if(*ppvObj)
166 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
167 return S_OK;
169 return E_NOINTERFACE;
172 /**************************************************************************
173 * IShellBrowser::AddRef
175 ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
177 ICOM_THIS(IShellBrowserImpl, iface);
179 TRACE("(%p)\n", This);
181 return ++(This->ref);
184 /**************************************************************************
185 * IShellBrowserImpl_Release
187 ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
189 ICOM_THIS(IShellBrowserImpl, iface);
191 TRACE("(%p)\n", This);
193 if (!--(This->ref))
195 COMDLG32_SHFree(This);
196 return 0;
198 return This->ref;
202 * IOleWindow
205 /**************************************************************************
206 * IShellBrowserImpl_GetWindow (IOleWindow)
208 * Inherited from IOleWindow::GetWindow
210 * See Windows documentation for more details
212 * Note : We will never be window less in the File Open dialog
215 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
216 HWND * phwnd)
218 ICOM_THIS(IShellBrowserImpl, iface);
220 TRACE("(%p)\n", This);
222 if(!This->hwndOwner)
223 return E_FAIL;
225 *phwnd = This->hwndOwner;
227 return (*phwnd) ? S_OK : E_UNEXPECTED;
231 /**************************************************************************
232 * IShellBrowserImpl_ContextSensitiveHelp
234 HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
235 BOOL fEnterMode)
237 ICOM_THIS(IShellBrowserImpl, iface);
239 TRACE("(%p)\n", This);
241 /* Feature not implemented */
242 return E_NOTIMPL;
246 * IShellBrowser
249 /**************************************************************************
250 * IShellBrowserImpl_BrowseObject
252 * See Windows documentation on IShellBrowser::BrowseObject for more details
254 * This function will override user specified flags and will always
255 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
257 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
258 LPCITEMIDLIST pidl,
259 UINT wFlags)
261 HRESULT hRes;
262 IShellFolder *psfTmp;
263 IShellView *psvTmp;
264 FileOpenDlgInfos *fodInfos;
265 LPITEMIDLIST pidlTmp;
267 ICOM_THIS(IShellBrowserImpl, iface);
269 TRACE("(%p)\n", This);
271 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
273 /* Format the pidl according to its parameter's category */
274 if(wFlags & SBSP_RELATIVE)
277 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
278 hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
279 pidl,
280 NULL,
281 &IID_IShellFolder,
282 (LPVOID *)&psfTmp);
283 if(FAILED(hRes))
285 return hRes;
287 /* create an absolute pidl */
288 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
289 (LPITEMIDLIST)pidl);
292 else if(wFlags & SBSP_PARENT)
294 /* Browse the parent folder (ignores the pidl) */
296 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
297 psfTmp = GetShellFolderFromPidl(pidlTmp);
300 else
302 /* An absolute pidl (relative from the desktop) */
303 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
304 psfTmp = GetShellFolderFromPidl(pidlTmp);
308 /* Retrieve the IShellFolder interface of the pidl specified folder */
309 if(!psfTmp)
310 return E_FAIL;
312 /* If the pidl to browse to is equal to the actual pidl ...
313 do nothing and pretend you did it*/
314 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
316 IShellFolder_Release(psfTmp);
317 COMDLG32_SHFree(pidlTmp);
318 return NOERROR;
321 /* Release the current fodInfos->Shell.FOIShellFolder and update its value */
322 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
323 fodInfos->Shell.FOIShellFolder = psfTmp;
325 /* Create the associated view */
326 if(SUCCEEDED(hRes = IShellFolder_CreateViewObject(psfTmp,
327 fodInfos->ShellInfos.hwndOwner,
328 &IID_IShellView,
329 (LPVOID *)&psvTmp)))
331 HWND hwndView;
332 /* Get the foldersettings from the old view */
333 if(fodInfos->Shell.FOIShellView)
335 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView,
336 &fodInfos->ShellInfos.folderSettings);
339 /* Create the window */
340 if(SUCCEEDED(hRes = IShellView_CreateViewWindow(psvTmp,
341 NULL,
342 &fodInfos->ShellInfos.folderSettings,
343 fodInfos->Shell.FOIShellBrowser,
344 &fodInfos->ShellInfos.rectView,
345 &hwndView)))
347 /* Fit the created view in the appropriate RECT */
348 MoveWindow(hwndView,
349 fodInfos->ShellInfos.rectView.left,
350 fodInfos->ShellInfos.rectView.top,
351 fodInfos->ShellInfos.rectView.right-fodInfos->ShellInfos.rectView.left,
352 fodInfos->ShellInfos.rectView.bottom-fodInfos->ShellInfos.rectView.top,
353 FALSE);
355 /* Select the new folder in the Look In combo box of the Open file dialog */
357 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,pidlTmp);
359 /* Release old pidlAbsCurrent memory and update its value */
360 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
361 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
363 /* Release the current fodInfos->Shell.FOIShellView and update its value */
364 if(fodInfos->Shell.FOIShellView)
366 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
367 IShellView_Release(fodInfos->Shell.FOIShellView);
369 #if 0
370 ShowWindow(fodInfos->ShellInfos.hwndView,SW_HIDE);
371 #endif
372 fodInfos->Shell.FOIShellView = psvTmp;
374 fodInfos->ShellInfos.hwndView = hwndView;
376 return NOERROR;
380 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
381 return hRes;
384 /**************************************************************************
385 * IShellBrowserImpl_EnableModelessSB
387 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
388 BOOL fEnable)
391 ICOM_THIS(IShellBrowserImpl, iface);
393 TRACE("(%p)\n", This);
395 /* Feature not implemented */
396 return E_NOTIMPL;
399 /**************************************************************************
400 * IShellBrowserImpl_GetControlWindow
402 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
403 UINT id,
404 HWND *lphwnd)
407 ICOM_THIS(IShellBrowserImpl, iface);
409 TRACE("(%p)\n", This);
411 /* Feature not implemented */
412 return E_NOTIMPL;
414 /**************************************************************************
415 * IShellBrowserImpl_GetViewStateStream
417 HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
418 DWORD grfMode,
419 LPSTREAM *ppStrm)
422 ICOM_THIS(IShellBrowserImpl, iface);
424 TRACE("(%p)\n", This);
426 /* Feature not implemented */
427 return E_NOTIMPL;
429 /**************************************************************************
430 * IShellBrowserImpl_InsertMenusSB
432 HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
433 HMENU hmenuShared,
434 LPOLEMENUGROUPWIDTHS lpMenuWidths)
437 ICOM_THIS(IShellBrowserImpl, iface);
439 TRACE("(%p)\n", This);
441 /* Feature not implemented */
442 return E_NOTIMPL;
444 /**************************************************************************
445 * IShellBrowserImpl_OnViewWindowActive
447 HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
448 IShellView *ppshv)
451 ICOM_THIS(IShellBrowserImpl, iface);
453 TRACE("(%p)\n", This);
455 /* Feature not implemented */
456 return E_NOTIMPL;
458 /**************************************************************************
459 * IShellBrowserImpl_QueryActiveShellView
461 HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
462 IShellView **ppshv)
465 ICOM_THIS(IShellBrowserImpl, iface);
467 FileOpenDlgInfos *fodInfos;
469 TRACE("(%p)\n", This);
471 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
473 if(!(*ppshv = fodInfos->Shell.FOIShellView))
475 return E_FAIL;
477 IShellView_AddRef(fodInfos->Shell.FOIShellView);
478 return NOERROR;
480 /**************************************************************************
481 * IShellBrowserImpl_RemoveMenusSB
483 HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
484 HMENU hmenuShared)
487 ICOM_THIS(IShellBrowserImpl, iface);
489 TRACE("(%p)\n", This);
491 /* Feature not implemented */
492 return E_NOTIMPL;
494 /**************************************************************************
495 * IShellBrowserImpl_SendControlMsg
497 HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
498 UINT id,
499 UINT uMsg,
500 WPARAM wParam,
501 LPARAM lParam,
502 LRESULT *pret)
505 ICOM_THIS(IShellBrowserImpl, iface);
506 LRESULT lres;
508 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
510 switch (id)
512 case FCW_TOOLBAR:
513 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
514 break;
515 default:
516 FIXME("ctrl id: %x\n", id);
517 return E_NOTIMPL;
519 if (pret) *pret = lres;
520 return S_OK;
522 /**************************************************************************
523 * IShellBrowserImpl_SetMenuSB
525 HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
526 HMENU hmenuShared,
527 HOLEMENU holemenuReserved,
528 HWND hwndActiveObject)
531 ICOM_THIS(IShellBrowserImpl, iface);
533 TRACE("(%p)\n", This);
535 /* Feature not implemented */
536 return E_NOTIMPL;
538 /**************************************************************************
539 * IShellBrowserImpl_SetStatusTextSB
541 HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
542 LPCOLESTR lpszStatusText)
545 ICOM_THIS(IShellBrowserImpl, iface);
547 TRACE("(%p)\n", This);
549 /* Feature not implemented */
550 return E_NOTIMPL;
552 /**************************************************************************
553 * IShellBrowserImpl_SetToolbarItems
555 HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
556 LPTBBUTTON lpButtons,
557 UINT nButtons,
558 UINT uFlags)
561 ICOM_THIS(IShellBrowserImpl, iface);
563 TRACE("(%p)\n", This);
565 /* Feature not implemented */
566 return E_NOTIMPL;
568 /**************************************************************************
569 * IShellBrowserImpl_TranslateAcceleratorSB
571 HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
572 LPMSG lpmsg,
573 WORD wID)
576 ICOM_THIS(IShellBrowserImpl, iface);
578 TRACE("(%p)\n", This);
580 /* Feature not implemented */
581 return E_NOTIMPL;
585 * ICommDlgBrowser
588 /***************************************************************************
589 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
591 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(ICommDlgBrowser *iface,
592 REFIID riid,
593 LPVOID *ppvObj)
595 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
597 TRACE("(%p)\n", This);
599 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
602 /**************************************************************************
603 * IShellBrowserImpl_ICommDlgBrowser_AddRef
605 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
607 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
609 TRACE("(%p)\n", This);
611 return IShellBrowserImpl_AddRef(This);
614 /**************************************************************************
615 * IShellBrowserImpl_ICommDlgBrowser_Release
617 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
619 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
621 TRACE("(%p)\n", This);
623 return IShellBrowserImpl_Release(This);
625 /**************************************************************************
626 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
628 * Called when a user double-clicks in the view or presses the ENTER key
630 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
631 IShellView *ppshv)
633 LPITEMIDLIST pidl;
634 FileOpenDlgInfos *fodInfos;
636 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
638 TRACE("(%p)\n", This);
640 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
642 /* If the selected object is not a folder, send a IDOK command to parent window */
643 if((pidl = GetSelectedPidl(ppshv)))
645 HRESULT hRes;
647 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
648 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
649 if (ulAttr)
650 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
651 /* Tell the dialog that the user selected a file */
652 else
654 hRes = FILEDLG95_OnOpen(This->hwndOwner);
657 /* Free memory used by pidl */
658 COMDLG32_SHFree((LPVOID)pidl);
660 return hRes;
663 return E_FAIL;
666 /**************************************************************************
667 * IShellBrowserImpl_ICommDlgBrowser_OnStateChange
669 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
670 IShellView *ppshv,
671 ULONG uChange)
674 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
676 TRACE("(%p)\n", This);
678 switch (uChange)
680 case CDBOSC_SETFOCUS:
681 break;
682 case CDBOSC_KILLFOCUS:
684 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
685 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
686 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
688 break;
689 case CDBOSC_SELCHANGE:
690 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
691 case CDBOSC_RENAME:
692 break;
695 return NOERROR;
697 /**************************************************************************
698 * IShellBrowserImpl_ICommDlgBrowser_IncludeObject
700 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
701 IShellView * ppshv,
702 LPCITEMIDLIST pidl)
704 FileOpenDlgInfos *fodInfos;
705 ULONG ulAttr;
706 STRRET str;
707 WCHAR szPathW[MAX_PATH];
709 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
711 TRACE("(%p)\n", This);
713 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
715 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
716 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
719 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
720 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
721 return S_FALSE;
722 /* always include directorys and links */
723 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
724 return S_OK;
725 /* Check if there is a mask to apply if not */
726 if(!fodInfos->ShellInfos.lpstrCurrentFilter ||
727 !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
728 return S_OK;
730 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_FORPARSING, &str)))
731 { if (SUCCEEDED(StrRetToBufW(&str, pidl,szPathW, MAX_PATH)))
733 if (COMDLG32_PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
734 return S_OK;
737 return S_FALSE;
741 /**************************************************************************
742 * IShellBrowserImpl_ICommDlgBrowser_OnSelChange
744 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
746 LPITEMIDLIST pidl;
747 FileOpenDlgInfos *fodInfos;
748 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
750 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
751 TRACE("(%p)\n", This);
753 if((pidl = GetSelectedPidl(ppshv)))
755 HRESULT hRes = E_FAIL;
756 char lpstrFileName[MAX_PATH];
758 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
759 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
760 if (!ulAttr)
762 if(SUCCEEDED(hRes = GetName(fodInfos->Shell.FOIShellFolder,pidl,SHGDN_NORMAL,lpstrFileName)))
763 SetWindowTextA(fodInfos->DlgInfos.hwndFileName,lpstrFileName);
764 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
765 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
767 else
768 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Open");
770 fodInfos->DlgInfos.dwDlgProp |= FODPROP_USEVIEW;
772 COMDLG32_SHFree((LPVOID)pidl);
773 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
774 return hRes;
776 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
777 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
779 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
780 return E_FAIL;
783 /***********************************************************************
784 * GetSelectedPidl
786 * Return the pidl of the first selected item in the view
788 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv)
791 IDataObject *doSelected;
792 LPITEMIDLIST pidlSelected = NULL;
794 TRACE("sv=%p\n", ppshv);
796 /* Get an IDataObject from the view */
797 if(SUCCEEDED(IShellView_GetItemObject(ppshv,
798 SVGIO_SELECTION,
799 &IID_IDataObject,
800 (LPVOID *)&doSelected)))
802 STGMEDIUM medium;
803 FORMATETC formatetc;
805 /* Set the FORMATETC structure*/
806 SETDefFormatEtc(formatetc,
807 RegisterClipboardFormatA(CFSTR_SHELLIDLIST),
808 TYMED_HGLOBAL);
810 /* Get the pidl from IDataObject */
811 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
813 LPIDA cida = GlobalLock(medium.u.hGlobal);
814 TRACE("cida=%p\n", cida);
815 pidlSelected = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[1]]));
817 if(medium.pUnkForRelease)
818 IUnknown_Release(medium.pUnkForRelease);
819 else
821 GlobalUnlock(medium.u.hGlobal);
822 GlobalFree(medium.u.hGlobal);
825 IDataObject_Release(doSelected);
826 return pidlSelected;
829 return NULL;