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