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