source: trunk/src/comdlg32/filedlgbrowser.c@ 2912

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

merged with latest wine code

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