source: trunk/src/comdlg32/filedlgbrowser.cpp@ 1548

Last change on this file since 1548 was 1548, checked in by sandervl, 26 years ago

Port of Wine common dialogs (not all)

File size: 24.7 KB
Line 
1/* $Id: filedlgbrowser.cpp,v 1.1 1999-11-02 19:09:42 sandervl Exp $ */
2/*
3 * Implementation of IShellBrowser for the File Open common dialog (990815)
4 *
5 *
6 */
7// ><DJR 17.05.99 Force to use C-interfaces for now to prevent CALLBACK definition compiler error
8#define CINTERFACE 1
9
10#include <stdio.h>
11#include "unknwn.h"
12#include <os2win.h>
13#include "filedlgbrowser.h"
14#include "heap.h"
15#include "commctrl.h"
16#include "wine/obj_dataobject.h"
17#include "debugtools.h"
18#include "cdlg.h"
19#include "wine/undocshell.h"
20
21DEFAULT_DEBUG_CHANNEL(commdlg)
22
23#define SETDefFormatEtc(fe,cf,med) \
24{ \
25 (fe).cfFormat = cf;\
26 (fe).dwAspect = DVASPECT_CONTENT; \
27 (fe).ptd =NULL;\
28 (fe).tymed = med;\
29 (fe).lindex = -1;\
30};
31
32
33/**************************************************************************
34* Structure
35*/
36static ICOM_VTABLE(IShellBrowser) IShellBrowserImpl_Vtbl =
37{
38 /* IUnknown */
39 IShellBrowserImpl_QueryInterface,
40 IShellBrowserImpl_AddRef,
41 IShellBrowserImpl_Release,
42 /* IOleWindow */
43 IShellBrowserImpl_GetWindow,
44 IShellBrowserImpl_ContextSensitiveHelp,
45 /* IShellBrowser */
46 IShellBrowserImpl_InsertMenusSB,
47 IShellBrowserImpl_SetMenuSB,
48 IShellBrowserImpl_RemoveMenusSB,
49 IShellBrowserImpl_SetStatusTextSB,
50 IShellBrowserImpl_EnableModelessSB,
51 IShellBrowserImpl_TranslateAcceleratorSB,
52 IShellBrowserImpl_BrowseObject,
53 IShellBrowserImpl_GetViewStateStream,
54 IShellBrowserImpl_GetControlWindow,
55 IShellBrowserImpl_SendControlMsg,
56 IShellBrowserImpl_QueryActiveShellView,
57 IShellBrowserImpl_OnViewWindowActive,
58 IShellBrowserImpl_SetToolbarItems
59};
60
61static ICOM_VTABLE(ICommDlgBrowser) IShellBrowserImpl_ICommDlgBrowser_Vtbl =
62{
63 /* IUnknown */
64 IShellBrowserImpl_ICommDlgBrowser_QueryInterface,
65 IShellBrowserImpl_ICommDlgBrowser_AddRef,
66 IShellBrowserImpl_ICommDlgBrowser_Release,
67 /* ICommDlgBrowser */
68 IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand,
69 IShellBrowserImpl_ICommDlgBrowser_OnStateChange,
70 IShellBrowserImpl_ICommDlgBrowser_IncludeObject
71};
72
73
74/**************************************************************************
75* Local Prototypes
76*/
77
78HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
79LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
80
81/**************************************************************************
82* External Prototypes
83*/
84extern const char *FileOpenDlgInfosStr;
85
86extern HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
87extern HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
88extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
89extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
90extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
91
92extern BOOL FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,
93 LPITEMIDLIST pidlCurrentFolder,
94 LPSTR lpstrMask);
95
96extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
97extern BOOL FILEDLG95_OnOpen(HWND hwnd);
98
99
100/**************************************************************************
101* IShellBrowserImpl_Construct
102*/
103IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
104{
105 IShellBrowserImpl *sb;
106 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
107
108 sb=(IShellBrowserImpl*)SHAlloc(sizeof(IShellBrowserImpl));
109
110 /* Initialisation of the member variables */
111 sb->ref=1;
112 sb->hwndOwner = hwndOwner;
113
114 /* Initialisation of the vTables */
115 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
116 sb->lpVtbl2 = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
117
118 SHGetSpecialFolderLocation(hwndOwner,
119 CSIDL_DESKTOP,
120 &fodInfos->ShellInfos.pidlAbsCurrent);
121
122 TRACE("%p\n", sb);
123
124 return (IShellBrowser *) sb;
125}
126
127/**************************************************************************
128*
129*
130* The INTERFACE of the IShellBrowser object
131*
132*/
133
134/*
135 * IUnknown
136 */
137
138/***************************************************************************
139* IShellBrowserImpl_QueryInterface
140*/
141HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
142 REFIID riid,
143 LPVOID *ppvObj)
144{
145 ICOM_THIS(IShellBrowserImpl, iface);
146
147 TRACE("(%p)\n", This);
148
149 *ppvObj = NULL;
150
151 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
152 { *ppvObj = This;
153 }
154 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
155 { *ppvObj = (IOleWindow*)This;
156 }
157
158 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
159 { *ppvObj = (IShellBrowser*)This;
160 }
161
162 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
163 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtbl2);
164 }
165
166 if(*ppvObj)
167 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
168 return S_OK;
169 }
170 return E_NOINTERFACE;
171}
172
173/**************************************************************************
174* IShellBrowser::AddRef
175*/
176ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
177{
178 ICOM_THIS(IShellBrowserImpl, iface);
179
180 TRACE("(%p)\n", This);
181
182 return ++(This->ref);
183}
184
185/**************************************************************************
186* IShellBrowserImpl_Release
187*/
188ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
189{
190 ICOM_THIS(IShellBrowserImpl, iface);
191
192 TRACE("(%p)\n", This);
193
194 if (!--(This->ref))
195 {
196 SHFree(This);
197 return 0;
198 }
199 return This->ref;
200}
201
202/*
203 * IOleWindow
204 */
205
206/**************************************************************************
207* IShellBrowserImpl_GetWindow (IOleWindow)
208*
209* Inherited from IOleWindow::GetWindow
210*
211* See Windows documentation for more details
212*
213* Note : We will never be window less in the File Open dialog
214*
215*/
216HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
217 HWND * phwnd)
218{
219 ICOM_THIS(IShellBrowserImpl, iface);
220
221 TRACE("(%p)\n", This);
222
223 if(!This->hwndOwner)
224 return E_FAIL;
225
226 *phwnd = This->hwndOwner;
227
228 return (*phwnd) ? S_OK : E_UNEXPECTED;
229
230}
231
232/**************************************************************************
233* IShellBrowserImpl_ContextSensitiveHelp
234*/
235HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
236 BOOL fEnterMode)
237{
238 ICOM_THIS(IShellBrowserImpl, iface);
239
240 TRACE("(%p)\n", This);
241
242 /* Feature not implemented */
243 return E_NOTIMPL;
244}
245
246/*
247 * IShellBrowser
248 */
249
250/**************************************************************************
251* IShellBrowserImpl_BrowseObject
252*
253* See Windows documentation on IShellBrowser::BrowseObject for more details
254*
255* This function will override user specified flags and will always
256* use SBSP_DEFBROWSER and SBSP_DEFMODE.
257*/
258HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
259 LPCITEMIDLIST pidl,
260 UINT wFlags)
261{
262 HRESULT hRes;
263 IShellFolder *psfTmp;
264 IShellView *psvTmp;
265 FileOpenDlgInfos *fodInfos;
266 LPITEMIDLIST pidlTmp;
267
268 ICOM_THIS(IShellBrowserImpl, iface);
269
270 TRACE("(%p)\n", This);
271
272 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
273
274 /* Format the pidl according to its parameter's category */
275 if(wFlags & SBSP_RELATIVE)
276 {
277
278 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
279 hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
280 pidl,
281 NULL,
282 &IID_IShellFolder,
283 (LPVOID *)&psfTmp);
284 if(FAILED(hRes))
285 {
286 return hRes;
287 }
288 /* create an absolute pidl */
289 pidlTmp = ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
290 (LPITEMIDLIST)pidl);
291
292 }
293 else if(wFlags & SBSP_PARENT)
294 {
295 /* Browse the parent folder (ignores the pidl) */
296
297 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
298 psfTmp = GetShellFolderFromPidl(pidlTmp);
299
300 }
301 else
302 {
303 /* An absolute pidl (relative from the desktop) */
304 pidlTmp = ILClone((LPITEMIDLIST)pidl);
305 psfTmp = GetShellFolderFromPidl(pidlTmp);
306 }
307
308 /* Retrieve the IShellFolder interface of the pidl specified folder */
309 if(!psfTmp)
310 return E_FAIL;
311
312 /* Release the current fodInfos->Shell.FOIShellFolder and update its value */
313 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
314 fodInfos->Shell.FOIShellFolder = psfTmp;
315
316 /* Create the associated view */
317 if(SUCCEEDED(hRes = IShellFolder_CreateViewObject(psfTmp,
318 fodInfos->ShellInfos.hwndOwner,
319 &IID_IShellView,
320 (LPVOID *)&psvTmp)))
321 {
322 HWND hwndView;
323 /* Get the foldersettings from the old view */
324 if(fodInfos->Shell.FOIShellView)
325 {
326 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView,
327 &fodInfos->ShellInfos.folderSettings);
328 }
329
330 /* Create the window */
331 if(SUCCEEDED(hRes = IShellView_CreateViewWindow(psvTmp,
332 NULL,
333 &fodInfos->ShellInfos.folderSettings,
334 fodInfos->Shell.FOIShellBrowser,
335 &fodInfos->ShellInfos.rectView,
336 &hwndView)))
337 {
338 /* Fit the created view in the appropriate RECT */
339 MoveWindow(hwndView,
340 fodInfos->ShellInfos.rectView.left,
341 fodInfos->ShellInfos.rectView.top,
342 fodInfos->ShellInfos.rectView.right-fodInfos->ShellInfos.rectView.left,
343 fodInfos->ShellInfos.rectView.bottom-fodInfos->ShellInfos.rectView.top,
344 FALSE);
345
346 /* Select the new folder in the Look In combo box of the Open file dialog */
347
348 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,pidlTmp);
349
350 /* Release old pidlAbsCurrent memory and update its value */
351 SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
352 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
353
354 /* Release the current fodInfos->Shell.FOIShellView and update its value */
355 if(fodInfos->Shell.FOIShellView)
356 {
357 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
358 IShellView_Release(fodInfos->Shell.FOIShellView);
359 }
360#if 0
361 ShowWindow(fodInfos->ShellInfos.hwndView,SW_HIDE);
362#endif
363 fodInfos->Shell.FOIShellView = psvTmp;
364
365 fodInfos->ShellInfos.hwndView = hwndView;
366
367 return NOERROR;
368 }
369 }
370
371 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
372 return hRes;
373}
374
375/**************************************************************************
376* IShellBrowserImpl_EnableModelessSB
377*/
378HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
379 BOOL fEnable)
380
381{
382 ICOM_THIS(IShellBrowserImpl, iface);
383
384 TRACE("(%p)\n", This);
385
386 /* Feature not implemented */
387 return E_NOTIMPL;
388}
389
390/**************************************************************************
391* IShellBrowserImpl_GetControlWindow
392*/
393HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
394 UINT id,
395 HWND *lphwnd)
396
397{
398 ICOM_THIS(IShellBrowserImpl, iface);
399
400 TRACE("(%p)\n", This);
401
402 /* Feature not implemented */
403 return E_NOTIMPL;
404}
405/**************************************************************************
406* IShellBrowserImpl_GetViewStateStream
407*/
408HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
409 DWORD grfMode,
410 LPSTREAM *ppStrm)
411
412{
413 ICOM_THIS(IShellBrowserImpl, iface);
414
415 TRACE("(%p)\n", This);
416
417 /* Feature not implemented */
418 return E_NOTIMPL;
419}
420/**************************************************************************
421* IShellBrowserImpl_InsertMenusSB
422*/
423HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
424 HMENU hmenuShared,
425 LPOLEMENUGROUPWIDTHS lpMenuWidths)
426
427{
428 ICOM_THIS(IShellBrowserImpl, iface);
429
430 TRACE("(%p)\n", This);
431
432 /* Feature not implemented */
433 return E_NOTIMPL;
434}
435/**************************************************************************
436* IShellBrowserImpl_OnViewWindowActive
437*/
438HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
439 IShellView *ppshv)
440
441{
442 ICOM_THIS(IShellBrowserImpl, iface);
443
444 TRACE("(%p)\n", This);
445
446 /* Feature not implemented */
447 return E_NOTIMPL;
448}
449/**************************************************************************
450* IShellBrowserImpl_QueryActiveShellView
451*/
452HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
453 IShellView **ppshv)
454
455{
456 ICOM_THIS(IShellBrowserImpl, iface);
457
458 FileOpenDlgInfos *fodInfos;
459
460 TRACE("(%p)\n", This);
461
462 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
463
464 if(!(*ppshv = fodInfos->Shell.FOIShellView))
465 {
466 return E_FAIL;
467 }
468 IShellView_AddRef(fodInfos->Shell.FOIShellView);
469 return NOERROR;
470}
471/**************************************************************************
472* IShellBrowserImpl_RemoveMenusSB
473*/
474HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
475 HMENU hmenuShared)
476
477{
478 ICOM_THIS(IShellBrowserImpl, iface);
479
480 TRACE("(%p)\n", This);
481
482 /* Feature not implemented */
483 return E_NOTIMPL;
484}
485/**************************************************************************
486* IShellBrowserImpl_SendControlMsg
487*/
488HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
489 UINT id,
490 UINT uMsg,
491 WPARAM wParam,
492 LPARAM lParam,
493 LRESULT *pret)
494
495{
496 ICOM_THIS(IShellBrowserImpl, iface);
497
498 TRACE("(%p)\n", This);
499
500 /* Feature not implemented */
501 return E_NOTIMPL;
502}
503/**************************************************************************
504* IShellBrowserImpl_SetMenuSB
505*/
506HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
507 HMENU hmenuShared,
508 HOLEMENU holemenuReserved,
509 HWND hwndActiveObject)
510
511{
512 ICOM_THIS(IShellBrowserImpl, iface);
513
514 TRACE("(%p)\n", This);
515
516 /* Feature not implemented */
517 return E_NOTIMPL;
518}
519/**************************************************************************
520* IShellBrowserImpl_SetStatusTextSB
521*/
522HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
523 LPCOLESTR lpszStatusText)
524
525{
526 ICOM_THIS(IShellBrowserImpl, iface);
527
528 TRACE("(%p)\n", This);
529
530 /* Feature not implemented */
531 return E_NOTIMPL;
532}
533/**************************************************************************
534* IShellBrowserImpl_SetToolbarItems
535*/
536HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
537 LPTBBUTTON lpButtons,
538 UINT nButtons,
539 UINT uFlags)
540
541{
542 ICOM_THIS(IShellBrowserImpl, iface);
543
544 TRACE("(%p)\n", This);
545
546 /* Feature not implemented */
547 return E_NOTIMPL;
548}
549/**************************************************************************
550* IShellBrowserImpl_TranslateAcceleratorSB
551*/
552HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
553 LPMSG lpmsg,
554 WORD wID)
555
556{
557 ICOM_THIS(IShellBrowserImpl, iface);
558
559 TRACE("(%p)\n", This);
560
561 /* Feature not implemented */
562 return E_NOTIMPL;
563}
564
565/*
566 * ICommDlgBrowser
567 */
568
569/***************************************************************************
570* IShellBrowserImpl_ICommDlgBrowser_QueryInterface
571*/
572HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(ICommDlgBrowser *iface,
573 REFIID riid,
574 LPVOID *ppvObj)
575{
576 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
577
578 TRACE("(%p)\n", This);
579
580 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
581}
582
583/**************************************************************************
584* IShellBrowserImpl_ICommDlgBrowser_AddRef
585*/
586ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
587{
588 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
589
590 TRACE("(%p)\n", This);
591
592 return IShellBrowserImpl_AddRef(This);
593}
594
595/**************************************************************************
596* IShellBrowserImpl_ICommDlgBrowser_Release
597*/
598ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
599{
600 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
601
602 TRACE("(%p)\n", This);
603
604 return IShellBrowserImpl_Release(This);
605}
606/**************************************************************************
607* IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
608*
609* Called when a user double-clicks in the view or presses the ENTER key
610*/
611HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
612 IShellView *ppshv)
613{
614 LPITEMIDLIST pidl;
615 FileOpenDlgInfos *fodInfos;
616
617 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
618
619 TRACE("(%p)\n", This);
620
621 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
622
623 /* If the selected object is not a folder, send a IDOK command to parent window */
624 if((pidl = GetSelectedPidl(ppshv)))
625 {
626 HRESULT hRes;
627
628 /* Selected item is a directory so browse to it */
629
630 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
631 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
632 if (ulAttr)
633 hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
634 /* Tell the dialog that the user selected a file */
635 else
636 hRes = FILEDLG95_OnOpen(This->hwndOwner);
637
638 /* Free memory used by pidl */
639 SHFree((LPVOID)pidl);
640
641 return hRes;
642 }
643
644 return E_FAIL;
645}
646
647/**************************************************************************
648* IShellBrowserImpl_ICommDlgBrowser_OnStateChange
649*/
650HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
651 IShellView *ppshv,
652 ULONG uChange)
653{
654
655 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
656
657 TRACE("(%p)\n", This);
658
659 switch (uChange)
660 {
661 case CDBOSC_SETFOCUS:
662 break;
663 case CDBOSC_KILLFOCUS:
664 break;
665 case CDBOSC_SELCHANGE:
666 return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
667 case CDBOSC_RENAME:
668 break;
669 }
670
671 return NOERROR;
672}
673/**************************************************************************
674* IShellBrowserImpl_ICommDlgBrowser_IncludeObject
675*/
676HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
677 IShellView * ppshv,
678 LPCITEMIDLIST pidl)
679{
680 FileOpenDlgInfos *fodInfos;
681 ULONG ulAttr;
682 STRRET str;
683 WCHAR szPathW[MAX_PATH];
684
685 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
686
687 TRACE("(%p)\n", This);
688
689 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
690
691 ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
692 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
693
694
695 if( (ulAttr & SFGAO_HIDDEN) /* hidden */
696 | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
697 return S_FALSE;
698 /* always include directorys and links */
699 if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
700 return S_OK;
701 /* Check if there is a mask to apply if not */
702 if(!fodInfos->ShellInfos.lpstrCurrentFilter ||
703 !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
704 return S_OK;
705
706 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_FORPARSING, &str)))
707 { if (SUCCEEDED(StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
708 {
709 if (PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
710 return S_OK;
711 }
712 }
713 return S_FALSE;
714
715}
716
717/**************************************************************************
718* IShellBrowserImpl_ICommDlgBrowser_OnSelChange
719*/
720HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
721{
722 LPITEMIDLIST pidl;
723
724 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
725
726 TRACE("(%p)\n", This);
727
728 if((pidl = GetSelectedPidl(ppshv)))
729 {
730 HRESULT hRes = E_FAIL;
731 char lpstrFileName[MAX_PATH];
732
733 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
734
735 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
736 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
737 if (!ulAttr)
738 {
739 if(SUCCEEDED(hRes = GetName(fodInfos->Shell.FOIShellFolder,pidl,SHGDN_NORMAL,lpstrFileName)))
740 SetWindowTextA(fodInfos->DlgInfos.hwndFileName,lpstrFileName);
741 }
742
743 SHFree((LPVOID)pidl);
744 return hRes;
745 }
746
747 return E_FAIL;
748}
749
750/***********************************************************************
751 * GetSelectedPidl
752 *
753 * Return the pidl of the first selected item in the view
754 */
755LPITEMIDLIST GetSelectedPidl(IShellView *ppshv)
756{
757
758 IDataObject *doSelected;
759 LPITEMIDLIST pidlSelected = NULL;
760
761 TRACE("sv=%p\n", ppshv);
762
763 /* Get an IDataObject from the view */
764 if(SUCCEEDED(IShellView_GetItemObject(ppshv,
765 SVGIO_SELECTION,
766 &IID_IDataObject,
767 (LPVOID *)&doSelected)))
768 {
769 STGMEDIUM medium;
770 FORMATETC formatetc;
771
772 /* Set the FORMATETC structure*/
773 SETDefFormatEtc(formatetc,
774 RegisterClipboardFormatA(CFSTR_SHELLIDLIST),
775 TYMED_HGLOBAL);
776
777 /* Get the pidl from IDataObject */
778 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
779 {
780 LPIDA cida = (LPIDA)GlobalLock(medium.u.hGlobal);
781 TRACE("cida=%p\n", cida);
782 pidlSelected = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[1]]));
783
784 if(medium.pUnkForRelease)
785 IUnknown_Release(medium.pUnkForRelease);
786 else
787 {
788 GlobalUnlock(medium.u.hGlobal);
789 GlobalFree(medium.u.hGlobal);
790 }
791 }
792 IDataObject_Release(doSelected);
793 return pidlSelected;
794 }
795
796 return NULL;
797}
798
799
800
801
802
Note: See TracBrowser for help on using the repository browser.