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