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