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

Last change on this file since 3216 was 3216, checked in by cbratschi, 26 years ago

* empty log message *

File size: 25.6 KB
Line 
1/*
2 * Implementation of IShellBrowser for the File Open common dialog
3 *
4 */
5
6#ifdef __WIN32OS2__
7#include <windef.h>
8#include <winbase.h>
9#include <wingdi.h>
10#include <winuser.h>
11#include <heapstring.h>
12#include <misc.h>
13
14#endif
15
16#include <stdio.h>
17#include "unknwn.h"
18#include "filedlgbrowser.h"
19#include "winuser.h"
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);
105extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
106
107
108/**************************************************************************
109* IShellBrowserImpl_Construct
110*/
111IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
112{
113 IShellBrowserImpl *sb;
114 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
115
116 sb=(IShellBrowserImpl*)SHAlloc(sizeof(IShellBrowserImpl));
117
118 /* Initialisation of the member variables */
119 sb->ref=1;
120 sb->hwndOwner = hwndOwner;
121
122 /* Initialisation of the vTables */
123 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
124 sb->lpVtbl2 = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
125
126 COMDLG32_SHGetSpecialFolderLocation(hwndOwner,
127 CSIDL_DESKTOP,
128 &fodInfos->ShellInfos.pidlAbsCurrent);
129
130 TRACE("%p\n", sb);
131
132 return (IShellBrowser *) sb;
133}
134
135/**************************************************************************
136*
137*
138* The INTERFACE of the IShellBrowser object
139*
140*/
141
142/*
143 * IUnknown
144 */
145
146/***************************************************************************
147* IShellBrowserImpl_QueryInterface
148*/
149HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
150 REFIID riid,
151 LPVOID *ppvObj)
152{
153 ICOM_THIS(IShellBrowserImpl, iface);
154
155 TRACE("(%p)\n", This);
156
157 *ppvObj = NULL;
158
159 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
160 { *ppvObj = This;
161 }
162 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
163 { *ppvObj = (IOleWindow*)This;
164 }
165
166 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
167 { *ppvObj = (IShellBrowser*)This;
168 }
169
170 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
171 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtbl2);
172 }
173
174 if(*ppvObj)
175 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
176 return S_OK;
177 }
178 return E_NOINTERFACE;
179}
180
181/**************************************************************************
182* IShellBrowser::AddRef
183*/
184ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
185{
186 ICOM_THIS(IShellBrowserImpl, iface);
187
188 TRACE("(%p)\n", This);
189
190 return ++(This->ref);
191}
192
193/**************************************************************************
194* IShellBrowserImpl_Release
195*/
196ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
197{
198 ICOM_THIS(IShellBrowserImpl, iface);
199
200 TRACE("(%p)\n", This);
201
202 if (!--(This->ref))
203 {
204 COMDLG32_SHFree(This);
205 return 0;
206 }
207 return This->ref;
208}
209
210/*
211 * IOleWindow
212 */
213
214/**************************************************************************
215* IShellBrowserImpl_GetWindow (IOleWindow)
216*
217* Inherited from IOleWindow::GetWindow
218*
219* See Windows documentation for more details
220*
221* Note : We will never be window less in the File Open dialog
222*
223*/
224HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
225 HWND * phwnd)
226{
227 ICOM_THIS(IShellBrowserImpl, iface);
228
229 TRACE("(%p)\n", This);
230
231 if(!This->hwndOwner)
232 return E_FAIL;
233
234 *phwnd = This->hwndOwner;
235
236 return (*phwnd) ? S_OK : E_UNEXPECTED;
237
238}
239
240/**************************************************************************
241* IShellBrowserImpl_ContextSensitiveHelp
242*/
243HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
244 BOOL fEnterMode)
245{
246 ICOM_THIS(IShellBrowserImpl, iface);
247
248 TRACE("(%p)\n", This);
249
250 /* Feature not implemented */
251 return E_NOTIMPL;
252}
253
254/*
255 * IShellBrowser
256 */
257
258/**************************************************************************
259* IShellBrowserImpl_BrowseObject
260*
261* See Windows documentation on IShellBrowser::BrowseObject for more details
262*
263* This function will override user specified flags and will always
264* use SBSP_DEFBROWSER and SBSP_DEFMODE.
265*/
266HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
267 LPCITEMIDLIST pidl,
268 UINT wFlags)
269{
270 HRESULT hRes;
271 IShellFolder *psfTmp;
272 IShellView *psvTmp;
273 FileOpenDlgInfos *fodInfos;
274 LPITEMIDLIST pidlTmp;
275
276 ICOM_THIS(IShellBrowserImpl, iface);
277
278 TRACE("(%p)\n", This);
279
280 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
281
282 /* Format the pidl according to its parameter's category */
283 if(wFlags & SBSP_RELATIVE)
284 {
285
286 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
287 hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
288 pidl,
289 NULL,
290 &IID_IShellFolder,
291 (LPVOID *)&psfTmp);
292 if(FAILED(hRes))
293 {
294 return hRes;
295 }
296 /* create an absolute pidl */
297 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
298 (LPITEMIDLIST)pidl);
299
300 }
301 else if(wFlags & SBSP_PARENT)
302 {
303 /* Browse the parent folder (ignores the pidl) */
304
305 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
306 psfTmp = GetShellFolderFromPidl(pidlTmp);
307
308 }
309 else
310 {
311 /* An absolute pidl (relative from the desktop) */
312 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
313 psfTmp = GetShellFolderFromPidl(pidlTmp);
314 }
315
316
317 /* Retrieve the IShellFolder interface of the pidl specified folder */
318 if(!psfTmp)
319 return E_FAIL;
320
321 /* If the pidl to browse to is equal to the actual pidl ...
322 do nothing and pretend you did it*/
323 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
324 {
325 IShellFolder_Release(psfTmp);
326 COMDLG32_SHFree(pidlTmp);
327 return NOERROR;
328 }
329
330 /* Release the current fodInfos->Shell.FOIShellFolder and update its value */
331 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
332 fodInfos->Shell.FOIShellFolder = psfTmp;
333
334 /* Create the associated view */
335 if(SUCCEEDED(hRes = IShellFolder_CreateViewObject(psfTmp,
336 fodInfos->ShellInfos.hwndOwner,
337 &IID_IShellView,
338 (LPVOID *)&psvTmp)))
339 {
340 HWND hwndView;
341 /* Get the foldersettings from the old view */
342 if(fodInfos->Shell.FOIShellView)
343 {
344 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView,
345 &fodInfos->ShellInfos.folderSettings);
346 }
347
348 /* Create the window */
349 if(SUCCEEDED(hRes = IShellView_CreateViewWindow(psvTmp,
350 NULL,
351 &fodInfos->ShellInfos.folderSettings,
352 fodInfos->Shell.FOIShellBrowser,
353 &fodInfos->ShellInfos.rectView,
354 &hwndView)))
355 {
356 /* Fit the created view in the appropriate RECT */
357 MoveWindow(hwndView,
358 fodInfos->ShellInfos.rectView.left,
359 fodInfos->ShellInfos.rectView.top,
360 fodInfos->ShellInfos.rectView.right-fodInfos->ShellInfos.rectView.left,
361 fodInfos->ShellInfos.rectView.bottom-fodInfos->ShellInfos.rectView.top,
362 FALSE);
363
364 /* Select the new folder in the Look In combo box of the Open file dialog */
365
366 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,pidlTmp);
367
368 /* Release old pidlAbsCurrent memory and update its value */
369 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
370 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
371
372 /* Release the current fodInfos->Shell.FOIShellView and update its value */
373 if(fodInfos->Shell.FOIShellView)
374 {
375 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
376 IShellView_Release(fodInfos->Shell.FOIShellView);
377 }
378#if 0
379 ShowWindow(fodInfos->ShellInfos.hwndView,SW_HIDE);
380#endif
381 fodInfos->Shell.FOIShellView = psvTmp;
382
383 fodInfos->ShellInfos.hwndView = hwndView;
384
385 return NOERROR;
386 }
387 }
388
389 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
390 return hRes;
391}
392
393/**************************************************************************
394* IShellBrowserImpl_EnableModelessSB
395*/
396HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
397 BOOL fEnable)
398
399{
400 ICOM_THIS(IShellBrowserImpl, iface);
401
402 TRACE("(%p)\n", This);
403
404 /* Feature not implemented */
405 return E_NOTIMPL;
406}
407
408/**************************************************************************
409* IShellBrowserImpl_GetControlWindow
410*/
411HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
412 UINT id,
413 HWND *lphwnd)
414
415{
416 ICOM_THIS(IShellBrowserImpl, iface);
417
418 TRACE("(%p)\n", This);
419
420 /* Feature not implemented */
421 return E_NOTIMPL;
422}
423/**************************************************************************
424* IShellBrowserImpl_GetViewStateStream
425*/
426HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
427 DWORD grfMode,
428 LPSTREAM *ppStrm)
429
430{
431 ICOM_THIS(IShellBrowserImpl, iface);
432
433 TRACE("(%p)\n", This);
434
435 /* Feature not implemented */
436 return E_NOTIMPL;
437}
438/**************************************************************************
439* IShellBrowserImpl_InsertMenusSB
440*/
441HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
442 HMENU hmenuShared,
443 LPOLEMENUGROUPWIDTHS lpMenuWidths)
444
445{
446 ICOM_THIS(IShellBrowserImpl, iface);
447
448 TRACE("(%p)\n", This);
449
450 /* Feature not implemented */
451 return E_NOTIMPL;
452}
453/**************************************************************************
454* IShellBrowserImpl_OnViewWindowActive
455*/
456HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
457 IShellView *ppshv)
458
459{
460 ICOM_THIS(IShellBrowserImpl, iface);
461
462 TRACE("(%p)\n", This);
463
464 /* Feature not implemented */
465 return E_NOTIMPL;
466}
467/**************************************************************************
468* IShellBrowserImpl_QueryActiveShellView
469*/
470HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
471 IShellView **ppshv)
472
473{
474 ICOM_THIS(IShellBrowserImpl, iface);
475
476 FileOpenDlgInfos *fodInfos;
477
478 TRACE("(%p)\n", This);
479
480 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
481
482 if(!(*ppshv = fodInfos->Shell.FOIShellView))
483 {
484 return E_FAIL;
485 }
486 IShellView_AddRef(fodInfos->Shell.FOIShellView);
487 return NOERROR;
488}
489/**************************************************************************
490* IShellBrowserImpl_RemoveMenusSB
491*/
492HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
493 HMENU hmenuShared)
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_SendControlMsg
505*/
506HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
507 UINT id,
508 UINT uMsg,
509 WPARAM wParam,
510 LPARAM lParam,
511 LRESULT *pret)
512
513{
514 ICOM_THIS(IShellBrowserImpl, iface);
515 LRESULT lres;
516
517 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
518
519 switch (id)
520 {
521 case FCW_TOOLBAR:
522 lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
523 break;
524 default:
525 FIXME("ctrl id: %x\n", id);
526 return E_NOTIMPL;
527 }
528 if (pret) *pret = lres;
529 return S_OK;
530}
531/**************************************************************************
532* IShellBrowserImpl_SetMenuSB
533*/
534HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
535 HMENU hmenuShared,
536 HOLEMENU holemenuReserved,
537 HWND hwndActiveObject)
538
539{
540 ICOM_THIS(IShellBrowserImpl, iface);
541
542 TRACE("(%p)\n", This);
543
544 /* Feature not implemented */
545 return E_NOTIMPL;
546}
547/**************************************************************************
548* IShellBrowserImpl_SetStatusTextSB
549*/
550HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
551 LPCOLESTR lpszStatusText)
552
553{
554 ICOM_THIS(IShellBrowserImpl, iface);
555
556 TRACE("(%p)\n", This);
557
558 /* Feature not implemented */
559 return E_NOTIMPL;
560}
561/**************************************************************************
562* IShellBrowserImpl_SetToolbarItems
563*/
564HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
565 LPTBBUTTON lpButtons,
566 UINT nButtons,
567 UINT uFlags)
568
569{
570 ICOM_THIS(IShellBrowserImpl, iface);
571
572 TRACE("(%p)\n", This);
573
574 /* Feature not implemented */
575 return E_NOTIMPL;
576}
577/**************************************************************************
578* IShellBrowserImpl_TranslateAcceleratorSB
579*/
580HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
581 LPMSG lpmsg,
582 WORD wID)
583
584{
585 ICOM_THIS(IShellBrowserImpl, iface);
586
587 TRACE("(%p)\n", This);
588
589 /* Feature not implemented */
590 return E_NOTIMPL;
591}
592
593/*
594 * ICommDlgBrowser
595 */
596
597/***************************************************************************
598* IShellBrowserImpl_ICommDlgBrowser_QueryInterface
599*/
600HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(ICommDlgBrowser *iface,
601 REFIID riid,
602 LPVOID *ppvObj)
603{
604 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
605
606 TRACE("(%p)\n", This);
607
608 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
609}
610
611/**************************************************************************
612* IShellBrowserImpl_ICommDlgBrowser_AddRef
613*/
614ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
615{
616 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
617
618 TRACE("(%p)\n", This);
619
620 return IShellBrowserImpl_AddRef(This);
621}
622
623/**************************************************************************
624* IShellBrowserImpl_ICommDlgBrowser_Release
625*/
626ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
627{
628 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
629
630 TRACE("(%p)\n", This);
631
632 return IShellBrowserImpl_Release(This);
633}
634/**************************************************************************
635* IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
636*
637* Called when a user double-clicks in the view or presses the ENTER key
638*/
639HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
640 IShellView *ppshv)
641{
642 LPITEMIDLIST pidl;
643 FileOpenDlgInfos *fodInfos;
644
645 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
646
647 TRACE("(%p)\n", This);
648
649 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
650
651 /* If the selected object is not a folder, send a IDOK command to parent window */
652 pidl = GetSelectedPidl(ppshv);
653 if (pidl)
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 pidl = GetSelectedPidl(ppshv);
764 if (pidl)
765 {
766 HRESULT hRes = E_FAIL;
767 char lpstrFileName[MAX_PATH];
768 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
769
770 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
771 if (!ulAttr)
772 {
773 if(SUCCEEDED(hRes = GetName(fodInfos->Shell.FOIShellFolder,pidl,SHGDN_NORMAL,lpstrFileName)))
774 SetWindowTextA(fodInfos->DlgInfos.hwndFileName,lpstrFileName);
775 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
776 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
777 }
778 else
779 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Open");
780
781 fodInfos->DlgInfos.dwDlgProp |= FODPROP_USEVIEW;
782
783 COMDLG32_SHFree((LPVOID)pidl);
784 SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
785 return hRes;
786 }
787 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
788 SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
789
790 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
791 return E_FAIL;
792}
793
794/***********************************************************************
795 * GetSelectedPidl
796 *
797 * Return the pidl of the first selected item in the view
798 */
799LPITEMIDLIST GetSelectedPidl(IShellView *ppshv)
800{
801
802 IDataObject *doSelected;
803 LPITEMIDLIST pidlSelected = NULL;
804
805 TRACE("sv=%p\n", ppshv);
806
807 /* Get an IDataObject from the view */
808 if(SUCCEEDED(IShellView_GetItemObject(ppshv,
809 SVGIO_SELECTION,
810 &IID_IDataObject,
811 (LPVOID *)&doSelected)))
812 {
813 STGMEDIUM medium;
814 FORMATETC formatetc;
815
816 /* Set the FORMATETC structure*/
817 SETDefFormatEtc(formatetc,
818 RegisterClipboardFormatA(CFSTR_SHELLIDLIST),
819 TYMED_HGLOBAL);
820
821 /* Get the pidl from IDataObject */
822 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
823 {
824 LPIDA cida = GlobalLock(medium.u.hGlobal);
825 TRACE("cida=%p\n", cida);
826 pidlSelected = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[1]]));
827
828 if(medium.pUnkForRelease)
829 IUnknown_Release(medium.pUnkForRelease);
830 else
831 {
832 GlobalUnlock(medium.u.hGlobal);
833 GlobalFree(medium.u.hGlobal);
834 }
835 }
836 IDataObject_Release(doSelected);
837 return pidlSelected;
838 }
839
840 return NULL;
841}
842
843
844
845
846
Note: See TracBrowser for help on using the repository browser.