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

Last change on this file since 21512 was 21512, checked in by dmik, 15 years ago

Aligned the STRRET definition and made it available through shlwapi.h and shlobj.h for compatibility with Win32.

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