set svn:eol-style to native
[reactos.git] / reactos / lib / 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winnls.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winreg.h"
36
37 #define NO_SHLWAPI_STREAM
38 #include "shlwapi.h"
39 #include "filedlgbrowser.h"
40 #include "cdlg.h"
41 #include "shlguid.h"
42 #include "servprov.h"
43 #include "wine/debug.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
46
47 typedef struct
48 {
49
50 const IShellBrowserVtbl *lpVtbl;
51 const ICommDlgBrowserVtbl *lpVtblCommDlgBrowser;
52 const IServiceProviderVtbl *lpVtblServiceProvider;
53 DWORD ref; /* Reference counter */
54 HWND hwndOwner; /* Owner dialog of the interface */
55
56 } IShellBrowserImpl;
57
58 /**************************************************************************
59 * vtable
60 */
61 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
62 static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;
63 static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;
64
65 /**************************************************************************
66 * Local Prototypes
67 */
68
69 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv);
70 #if 0
71 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
72 #endif
73
74 /**************************************************************************
75 * External Prototypes
76 */
77 extern const char *FileOpenDlgInfosStr;
78
79 extern IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
80 extern LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
81 extern LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
82
83 extern int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
84 extern void SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
85
86
87 /*
88 * Helper functions
89 */
90
91 #define add_flag(a) if (flags & a) {strcat(str, #a );strcat(str," ");}
92 static void COMDLG32_DumpSBSPFlags(UINT uflags)
93 {
94 if (TRACE_ON(commdlg))
95 {
96 unsigned int i;
97 static const struct {
98 DWORD mask;
99 const char *name;
100 } flags[] = {
101 #define FE(x) { x, #x}
102 /* SBSP_DEFBROWSER == 0 */
103 FE(SBSP_SAMEBROWSER),
104 FE(SBSP_NEWBROWSER),
105
106 /* SBSP_DEFMODE == 0 */
107 FE(SBSP_OPENMODE),
108 FE(SBSP_EXPLOREMODE),
109 FE(SBSP_HELPMODE),
110 FE(SBSP_NOTRANSFERHIST),
111
112 /* SBSP_ABSOLUTE == 0 */
113 FE(SBSP_RELATIVE),
114 FE(SBSP_PARENT),
115 FE(SBSP_NAVIGATEBACK),
116 FE(SBSP_NAVIGATEFORWARD),
117 FE(SBSP_ALLOW_AUTONAVIGATE),
118
119 FE(SBSP_NOAUTOSELECT),
120 FE(SBSP_WRITENOHISTORY),
121
122 FE(SBSP_REDIRECT),
123 FE(SBSP_INITIATEDBYHLINKFRAME),
124 };
125 #undef FE
126 DPRINTF("SBSP Flags: %08x =", uflags);
127 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
128 if (flags[i].mask & uflags)
129 DPRINTF("%s ", flags[i].name);
130 DPRINTF("\n");
131 }
132 }
133
134 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)
135 {
136 LPSHELLFOLDER psfDesktop;
137 STRRET strret;
138 HRESULT res;
139
140 res = SHGetDesktopFolder(&psfDesktop);
141 if (FAILED(res))
142 return;
143
144 res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,
145 SHGDN_FORPARSING, &strret);
146 if (SUCCEEDED(res)) {
147 WCHAR wszCurrentDir[MAX_PATH];
148
149 res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);
150 if (SUCCEEDED(res))
151 SetCurrentDirectoryW(wszCurrentDir);
152 }
153
154 IShellFolder_Release(psfDesktop);
155 }
156
157 /* copied from shell32 to avoid linking to it */
158 static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPCITEMIDLIST pidl)
159 {
160 TRACE("dest=%p len=0x%lx strret=%p pidl=%p stub\n",dest,len,src,pidl);
161
162 switch (src->uType)
163 {
164 case STRRET_WSTR:
165 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
166 COMDLG32_SHFree(src->u.pOleStr);
167 break;
168
169 case STRRET_CSTR:
170 if (len && !MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, (LPWSTR)dest, len ))
171 ((LPWSTR)dest)[len-1] = 0;
172 break;
173
174 case STRRET_OFFSET:
175 if (pidl)
176 {
177 if (len && !MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset,
178 -1, (LPWSTR)dest, len ))
179 ((LPWSTR)dest)[len-1] = 0;
180 }
181 break;
182
183 default:
184 FIXME("unknown type!\n");
185 if (len)
186 { *(LPWSTR)dest = '\0';
187 }
188 return(FALSE);
189 }
190 return S_OK;
191 }
192
193 /*
194 * IShellBrowser
195 */
196
197 /**************************************************************************
198 * IShellBrowserImpl_Construct
199 */
200 IShellBrowser * IShellBrowserImpl_Construct(HWND hwndOwner)
201 {
202 IShellBrowserImpl *sb;
203 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
204
205 sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
206
207 /* Initialisation of the member variables */
208 sb->ref=1;
209 sb->hwndOwner = hwndOwner;
210
211 /* Initialisation of the vTables */
212 sb->lpVtbl = &IShellBrowserImpl_Vtbl;
213 sb->lpVtblCommDlgBrowser = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
214 sb->lpVtblServiceProvider = &IShellBrowserImpl_IServiceProvider_Vtbl;
215 SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
216 &fodInfos->ShellInfos.pidlAbsCurrent);
217
218 TRACE("%p\n", sb);
219
220 return (IShellBrowser *) sb;
221 }
222
223 /***************************************************************************
224 * IShellBrowserImpl_QueryInterface
225 */
226 HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
227 REFIID riid,
228 LPVOID *ppvObj)
229 {
230 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
231
232 TRACE("(%p)\n\t%s\n", This, debugstr_guid(riid));
233
234 *ppvObj = NULL;
235
236 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
237 { *ppvObj = This;
238 }
239 else if(IsEqualIID(riid, &IID_IOleWindow)) /*IOleWindow*/
240 { *ppvObj = (IOleWindow*)This;
241 }
242
243 else if(IsEqualIID(riid, &IID_IShellBrowser)) /*IShellBrowser*/
244 { *ppvObj = (IShellBrowser*)This;
245 }
246
247 else if(IsEqualIID(riid, &IID_ICommDlgBrowser)) /*ICommDlgBrowser*/
248 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblCommDlgBrowser);
249 }
250
251 else if(IsEqualIID(riid, &IID_IServiceProvider)) /* IServiceProvider */
252 { *ppvObj = (ICommDlgBrowser*) &(This->lpVtblServiceProvider);
253 }
254
255 if(*ppvObj)
256 { IUnknown_AddRef( (IShellBrowser*) *ppvObj);
257 return S_OK;
258 }
259 FIXME("Unknown interface requested\n");
260 return E_NOINTERFACE;
261 }
262
263 /**************************************************************************
264 * IShellBrowser::AddRef
265 */
266 ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
267 {
268 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
269 ULONG ref = InterlockedIncrement(&This->ref);
270
271 TRACE("(%p,%lu)\n", This, ref - 1);
272
273 return ref;
274 }
275
276 /**************************************************************************
277 * IShellBrowserImpl_Release
278 */
279 ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
280 {
281 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
282 ULONG ref = InterlockedDecrement(&This->ref);
283
284 TRACE("(%p,%lu)\n", This, ref + 1);
285
286 if (!ref)
287 {
288 COMDLG32_SHFree(This);
289 TRACE("-- destroyed\n");
290 return 0;
291 }
292 return ref;
293 }
294
295 /*
296 * IOleWindow
297 */
298
299 /**************************************************************************
300 * IShellBrowserImpl_GetWindow (IOleWindow)
301 *
302 * Inherited from IOleWindow::GetWindow
303 *
304 * See Windows documentation for more details
305 *
306 * Note : We will never be window less in the File Open dialog
307 *
308 */
309 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
310 HWND * phwnd)
311 {
312 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
313
314 TRACE("(%p)\n", This);
315
316 if(!This->hwndOwner)
317 return E_FAIL;
318
319 *phwnd = This->hwndOwner;
320
321 return (*phwnd) ? S_OK : E_UNEXPECTED;
322
323 }
324
325 /**************************************************************************
326 * IShellBrowserImpl_ContextSensitiveHelp
327 */
328 HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser * iface,
329 BOOL fEnterMode)
330 {
331 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
332
333 TRACE("(%p)\n", This);
334
335 /* Feature not implemented */
336 return E_NOTIMPL;
337 }
338
339 /*
340 * IShellBrowser
341 */
342
343 /**************************************************************************
344 * IShellBrowserImpl_BrowseObject
345 *
346 * See Windows documentation on IShellBrowser::BrowseObject for more details
347 *
348 * This function will override user specified flags and will always
349 * use SBSP_DEFBROWSER and SBSP_DEFMODE.
350 */
351 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
352 LPCITEMIDLIST pidl,
353 UINT wFlags)
354 {
355 HRESULT hRes;
356 IShellFolder *psfTmp;
357 IShellView *psvTmp;
358 FileOpenDlgInfos *fodInfos;
359 LPITEMIDLIST pidlTmp;
360 HWND hwndView;
361 HWND hDlgWnd;
362 BOOL bViewHasFocus;
363 RECT rectView;
364
365 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
366
367 TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags);
368 COMDLG32_DumpSBSPFlags(wFlags);
369
370 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
371
372 /* Format the pidl according to its parameter's category */
373 if(wFlags & SBSP_RELATIVE)
374 {
375
376 /* SBSP_RELATIVE A relative pidl (relative from the current folder) */
377 if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
378 pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
379 {
380 ERR("bind to object failed\n");
381 return hRes;
382 }
383 /* create an absolute pidl */
384 pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
385 (LPITEMIDLIST)pidl);
386 }
387 else if(wFlags & SBSP_PARENT)
388 {
389 /* Browse the parent folder (ignores the pidl) */
390 pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
391 psfTmp = GetShellFolderFromPidl(pidlTmp);
392
393 }
394 else /* SBSP_ABSOLUTE is 0x0000 */
395 {
396 /* An absolute pidl (relative from the desktop) */
397 pidlTmp = COMDLG32_PIDL_ILClone((LPITEMIDLIST)pidl);
398 psfTmp = GetShellFolderFromPidl(pidlTmp);
399 }
400
401 if(!psfTmp)
402 {
403 ERR("could not browse to folder\n");
404 return E_FAIL;
405 }
406
407 /* If the pidl to browse to is equal to the actual pidl ...
408 do nothing and pretend you did it*/
409 if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
410 {
411 IShellFolder_Release(psfTmp);
412 COMDLG32_SHFree(pidlTmp);
413 TRACE("keep current folder\n");
414 return NOERROR;
415 }
416
417 /* Release the current DataObject */
418 if (fodInfos->Shell.FOIDataObject)
419 {
420 IDataObject_Release(fodInfos->Shell.FOIDataObject);
421 fodInfos->Shell.FOIDataObject = NULL;
422 }
423
424 /* Create the associated view */
425 TRACE("create view object\n");
426 if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
427 &IID_IShellView, (LPVOID *)&psvTmp))) goto error;
428
429 /* Check if listview has focus */
430 bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
431
432 /* Get the foldersettings from the old view */
433 if(fodInfos->Shell.FOIShellView)
434 IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
435
436 /* Release the old fodInfos->Shell.FOIShellView and update its value.
437 We have to update this early since ShellView_CreateViewWindow of native
438 shell32 calls OnStateChange and needs the correct view here.*/
439 if(fodInfos->Shell.FOIShellView)
440 {
441 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
442 IShellView_Release(fodInfos->Shell.FOIShellView);
443 }
444 fodInfos->Shell.FOIShellView = psvTmp;
445
446 /* Release old FOIShellFolder and update its value */
447 if (fodInfos->Shell.FOIShellFolder)
448 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
449 fodInfos->Shell.FOIShellFolder = psfTmp;
450
451 /* Release old pidlAbsCurrent and update its value */
452 COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
453 fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
454
455 COMDLG32_UpdateCurrentDir(fodInfos);
456
457 GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView);
458 MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2);
459
460 /* Create the window */
461 TRACE("create view window\n");
462 if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
463 &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
464 &rectView, &hwndView))) goto error;
465
466 fodInfos->ShellInfos.hwndView = hwndView;
467
468 /* Select the new folder in the Look In combo box of the Open file dialog */
469 FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
470
471 /* changes the tab order of the ListView to reflect the window's File Dialog */
472 hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
473 SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
474
475 /* Since we destroyed the old view if it had focus set focus to the newly created view */
476 if (bViewHasFocus)
477 SetFocus(fodInfos->ShellInfos.hwndView);
478
479 return hRes;
480 error:
481 ERR("Failed with error 0x%08lx\n", hRes);
482 return hRes;
483 }
484
485 /**************************************************************************
486 * IShellBrowserImpl_EnableModelessSB
487 */
488 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
489 BOOL fEnable)
490
491 {
492 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
493
494 TRACE("(%p)\n", This);
495
496 /* Feature not implemented */
497 return E_NOTIMPL;
498 }
499
500 /**************************************************************************
501 * IShellBrowserImpl_GetControlWindow
502 */
503 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
504 UINT id,
505 HWND *lphwnd)
506
507 {
508 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
509
510 TRACE("(%p)\n", This);
511
512 /* Feature not implemented */
513 return E_NOTIMPL;
514 }
515 /**************************************************************************
516 * IShellBrowserImpl_GetViewStateStream
517 */
518 HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
519 DWORD grfMode,
520 LPSTREAM *ppStrm)
521
522 {
523 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
524
525 FIXME("(%p 0x%08lx %p)\n", This, grfMode, ppStrm);
526
527 /* Feature not implemented */
528 return E_NOTIMPL;
529 }
530 /**************************************************************************
531 * IShellBrowserImpl_InsertMenusSB
532 */
533 HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
534 HMENU hmenuShared,
535 LPOLEMENUGROUPWIDTHS lpMenuWidths)
536
537 {
538 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
539
540 TRACE("(%p)\n", This);
541
542 /* Feature not implemented */
543 return E_NOTIMPL;
544 }
545 /**************************************************************************
546 * IShellBrowserImpl_OnViewWindowActive
547 */
548 HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
549 IShellView *ppshv)
550
551 {
552 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
553
554 TRACE("(%p)\n", This);
555
556 /* Feature not implemented */
557 return E_NOTIMPL;
558 }
559 /**************************************************************************
560 * IShellBrowserImpl_QueryActiveShellView
561 */
562 HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
563 IShellView **ppshv)
564
565 {
566 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
567
568 FileOpenDlgInfos *fodInfos;
569
570 TRACE("(%p)\n", This);
571
572 fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
573
574 if(!(*ppshv = fodInfos->Shell.FOIShellView))
575 {
576 return E_FAIL;
577 }
578 IShellView_AddRef(fodInfos->Shell.FOIShellView);
579 return NOERROR;
580 }
581 /**************************************************************************
582 * IShellBrowserImpl_RemoveMenusSB
583 */
584 HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
585 HMENU hmenuShared)
586
587 {
588 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
589
590 TRACE("(%p)\n", This);
591
592 /* Feature not implemented */
593 return E_NOTIMPL;
594 }
595 /**************************************************************************
596 * IShellBrowserImpl_SendControlMsg
597 */
598 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 = (IShellBrowserImpl *)iface;
607 LRESULT lres;
608
609 TRACE("(%p)->(0x%08x 0x%08x 0x%08x 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 * IShellBrowserImpl_SetMenuSB
625 */
626 HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
627 HMENU hmenuShared,
628 HOLEMENU holemenuReserved,
629 HWND hwndActiveObject)
630
631 {
632 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
633
634 TRACE("(%p)\n", This);
635
636 /* Feature not implemented */
637 return E_NOTIMPL;
638 }
639 /**************************************************************************
640 * IShellBrowserImpl_SetStatusTextSB
641 */
642 HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
643 LPCOLESTR lpszStatusText)
644
645 {
646 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
647
648 TRACE("(%p)\n", This);
649
650 /* Feature not implemented */
651 return E_NOTIMPL;
652 }
653 /**************************************************************************
654 * IShellBrowserImpl_SetToolbarItems
655 */
656 HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
657 LPTBBUTTON lpButtons,
658 UINT nButtons,
659 UINT uFlags)
660
661 {
662 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
663
664 TRACE("(%p)\n", This);
665
666 /* Feature not implemented */
667 return E_NOTIMPL;
668 }
669 /**************************************************************************
670 * IShellBrowserImpl_TranslateAcceleratorSB
671 */
672 HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
673 LPMSG lpmsg,
674 WORD wID)
675
676 {
677 IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
678
679 TRACE("(%p)\n", This);
680
681 /* Feature not implemented */
682 return E_NOTIMPL;
683 }
684
685 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
686 {
687 /* IUnknown */
688 IShellBrowserImpl_QueryInterface,
689 IShellBrowserImpl_AddRef,
690 IShellBrowserImpl_Release,
691 /* IOleWindow */
692 IShellBrowserImpl_GetWindow,
693 IShellBrowserImpl_ContextSensitiveHelp,
694 /* IShellBrowser */
695 IShellBrowserImpl_InsertMenusSB,
696 IShellBrowserImpl_SetMenuSB,
697 IShellBrowserImpl_RemoveMenusSB,
698 IShellBrowserImpl_SetStatusTextSB,
699 IShellBrowserImpl_EnableModelessSB,
700 IShellBrowserImpl_TranslateAcceleratorSB,
701 IShellBrowserImpl_BrowseObject,
702 IShellBrowserImpl_GetViewStateStream,
703 IShellBrowserImpl_GetControlWindow,
704 IShellBrowserImpl_SendControlMsg,
705 IShellBrowserImpl_QueryActiveShellView,
706 IShellBrowserImpl_OnViewWindowActive,
707 IShellBrowserImpl_SetToolbarItems
708 };
709
710
711
712 /*
713 * ICommDlgBrowser
714 */
715
716 /***************************************************************************
717 * IShellBrowserImpl_ICommDlgBrowser_QueryInterface
718 */
719 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(
720 ICommDlgBrowser *iface,
721 REFIID riid,
722 LPVOID *ppvObj)
723 {
724 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
725
726 TRACE("(%p)\n", This);
727
728 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
729 }
730
731 /**************************************************************************
732 * IShellBrowserImpl_ICommDlgBrowser_AddRef
733 */
734 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_AddRef(ICommDlgBrowser * iface)
735 {
736 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
737
738 TRACE("(%p)\n", This);
739
740 return IShellBrowserImpl_AddRef(This);
741 }
742
743 /**************************************************************************
744 * IShellBrowserImpl_ICommDlgBrowser_Release
745 */
746 ULONG WINAPI IShellBrowserImpl_ICommDlgBrowser_Release(ICommDlgBrowser * iface)
747 {
748 _ICOM_THIS_FromICommDlgBrowser(IShellBrowser,iface);
749
750 TRACE("(%p)\n", This);
751
752 return IShellBrowserImpl_Release(This);
753 }
754 /**************************************************************************
755 * IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand
756 *
757 * Called when a user double-clicks in the view or presses the ENTER key
758 */
759 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnDefaultCommand(ICommDlgBrowser *iface,
760 IShellView *ppshv)
761 {
762 LPITEMIDLIST pidl;
763 FileOpenDlgInfos *fodInfos;
764
765 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,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 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBrowser *iface,
803 IShellView *ppshv,
804 ULONG uChange)
805 {
806
807 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,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 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 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,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 HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
887 {
888 FileOpenDlgInfos *fodInfos;
889
890 _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,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 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryInterface(
933 IServiceProvider *iface,
934 REFIID riid,
935 LPVOID *ppvObj)
936 {
937 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
938
939 FIXME("(%p)\n", This);
940
941 return IShellBrowserImpl_QueryInterface(This,riid,ppvObj);
942 }
943
944 /**************************************************************************
945 * IShellBrowserImpl_IServiceProvider_AddRef
946 */
947 ULONG WINAPI IShellBrowserImpl_IServiceProvider_AddRef(IServiceProvider * iface)
948 {
949 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
950
951 FIXME("(%p)\n", This);
952
953 return IShellBrowserImpl_AddRef(This);
954 }
955
956 /**************************************************************************
957 * IShellBrowserImpl_IServiceProvider_Release
958 */
959 ULONG WINAPI IShellBrowserImpl_IServiceProvider_Release(IServiceProvider * iface)
960 {
961 _ICOM_THIS_FromIServiceProvider(IShellBrowser,iface);
962
963 FIXME("(%p)\n", This);
964
965 return IShellBrowserImpl_Release(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 HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
980 IServiceProvider * iface,
981 REFGUID guidService,
982 REFIID riid,
983 void** ppv)
984 {
985 _ICOM_THIS_FromIServiceProvider(IShellBrowser,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(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 };