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