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

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

Wine 991031 update

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