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