5de7aaf06ef6e61ef4143b7404da9deeb21fe273
[reactos.git] / dll / win32 / browseui / shellbrowser.cpp
1 /*
2 * ReactOS Explorer
3 *
4 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "precomp.h"
22
23 #include <shellapi.h>
24 #include <htiframe.h>
25
26 extern "C"
27 BOOL WINAPI Shell_GetImageLists(
28 _Out_ HIMAGELIST *phiml,
29 _Out_ HIMAGELIST *phimlSmall
30 );
31
32 extern HRESULT IUnknown_ShowDW(IUnknown * punk, BOOL fShow);
33
34 #include "newatlinterfaces.h"
35
36
37 /*
38 TODO:
39 **Provide implementation of new and delete that use LocalAlloc
40 **Persist history for shell view isn't working correctly, possibly because of the mismatch between traveling and updating the travel log. The
41 view doesn't restore the selection correctly.
42 **Build explorer.exe, browseui.dll, comctl32.dll, shdocvw.dll, shell32.dll, shlwapi.dll into a directory and run them for testing...
43 **Add brand band bitmaps to shell32.dll
44 **If Go button on address bar is clicked, each time a new duplicate entry is added to travel log
45 ****The current entry is updated in travel log before doing the travel, which means when traveling back the update of the
46 current state overwrites the wrong entry's contents. This needs to be changed.
47 ****Fix close of browser window to release all objects
48 ****Given only a GUID in ShowBrowserBar, what is the correct way to determine if the bar is vertical or horizontal?
49 **When a new bar is added to base bar site, how is base bar told so it can resize?
50 **Does the base bar site have a classid?
51 **What should refresh command send to views to make them refresh?
52 **When new bar is created, what status notifications need to be fired?
53 **How does keyboard filtering dispatch?
54 **For deferred persist history load, how does the view connect up and get the state?
55 How does context menu send open, cut, rename commands to its site (the shell view)?
56 **Fix browser to implement IProfferService and hold onto brand band correctly - this will allow animations.
57
58 **Route View->Toolbars commands to internet toolbar
59 **Handle travel log items in View->Go
60 **Fix ShowBrowserBar to pass correct size on when bar is shown
61 ****Fix SetBorderSpaceDW to cascade resize to subsequent bars
62 ****Make ShowToolbar check if bar is already created before creating it again
63 ****Shell should fill in the list of explorer bars in the View submenus
64 **Add folder menu in the file menu
65 **Fix CShellBrowser::GetBorderDW to compute available size correctly
66 **When a new bar is shown, re-fire the navigate event. This makes the explorer band select the correct folder
67 **Implement support for refresh. Forward refresh to explorer bar (refresh on toolbar and in menu is dispatched different)
68 Make folders toolbar item update state appropriately
69 Read list of bands from registry on launch
70 Read list of bars from registry on launch
71 If the folders or search bars don't exist, disable the toolbar buttons
72 If the favorites or history bars don't exist, disable the toolbar butons
73 Fix Apply to all Folders in Folder Options
74 Implement close command
75 Add explorer band context menu to file menu
76 Add code to allow restore of internet toolbar from registry
77 Fix code that calls FireNavigateComplete to pass the correct new path
78
79 What are the other command ids for QueryStatus/FireCommandStateChange?
80
81 Add handler for cabinet settings change
82 Add handler for system metrics change (renegotiate border space?)
83 Add handler for theme change and forward to contained windows
84
85 When folders are shown, the status bar text should change
86 Add code to save/restore shell view settings
87 Implement tabbing between frames
88 Fix handling of focus everywhere
89 Most keyboard shortcuts don't work, such as F2 for rename, F5 for refresh (see list in "explorer keyboard shortcuts")
90
91 The status bar doesn't show help text for items owned by frame during menu tracking
92 Stub out frame command handlers
93 "Arrange icons by" group is not checked properly
94
95 When folders are hidden, icon is the same as the current shell object being displayed. When folders are shown,
96 the icon is always an open folder with magnifying glass
97 Fix bars to calculate height correctly
98 Hookup policies for everything...
99 Investigate toolbar message WM_USER+93
100 Investigate toolbar message WM_USER+100 (Adds extra padding between parts of buttons with BTNS_DROPDOWN | BTNS_SHOWTEXT style
101
102 Vertical Explorer Bar CATID_InfoBand
103 Horizontal Explorer Bar CATID_CommBand
104 Desk Band CATID_DeskBand
105
106 cache of bars
107 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Discardable\PostSetup\Component Categories\{00021493-0000-0000-C000-000000000046}\Enum
108 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Discardable\PostSetup\Component Categories\{00021494-0000-0000-C000-000000000046}\Enum
109
110 create key here with CLSID of bar to register tool band
111 HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Toolbar
112
113 */
114
115 #ifndef __GNUC__
116 #pragma comment(linker, \
117 "\"/manifestdependency:type='Win32' "\
118 "name='Microsoft.Windows.Common-Controls' "\
119 "version='6.0.0.0' "\
120 "processorArchitecture='*' "\
121 "publicKeyToken='6595b64144ccf1df' "\
122 "language='*'\"")
123 #endif // __GNUC__
124
125 struct categoryCacheHeader
126 {
127 long dwSize; // size of header only
128 long version; // currently 1
129 SYSTEMTIME writeTime; // time we were written to registry
130 long classCount; // number of classes following
131 };
132
133 static const unsigned int folderOptionsPageCountMax = 20;
134 static const long BTP_UPDATE_CUR_HISTORY = 1;
135 static const long BTP_UPDATE_NEXT_HISTORY = 2;
136
137 BOOL createNewStuff = false;
138
139
140 // this class is private to browseui.dll and is not registered externally?
141 //DEFINE_GUID(CLSID_ShellFldSetExt, 0x6D5313C0, 0x8C62, 0x11D1, 0xB2, 0xCD, 0x00, 0x60, 0x97, 0xDF, 0x8C, 0x11);
142
143
144 extern HRESULT CreateTravelLog(REFIID riid, void **ppv);
145 extern HRESULT CreateBaseBar(REFIID riid, void **ppv);
146 extern HRESULT CreateBaseBarSite(REFIID riid, void **ppv);
147
148 // temporary
149 extern HRESULT CreateInternetToolbar(REFIID riid, void **ppv);
150
151
152 HMENU SHGetMenuFromID(HMENU topMenu, int theID)
153 {
154 MENUITEMINFO menuItemInfo;
155
156 menuItemInfo.cbSize = sizeof(menuItemInfo);
157 menuItemInfo.fMask = MIIM_SUBMENU;
158 if (!GetMenuItemInfo(topMenu, theID, FALSE, &menuItemInfo))
159 return NULL;
160 return menuItemInfo.hSubMenu;
161 }
162
163 void SHCheckMenuItem(HMENU theMenu, int theID, BOOL checked)
164 {
165 MENUITEMINFO menuItemInfo;
166
167 menuItemInfo.cbSize = sizeof(menuItemInfo);
168 menuItemInfo.fMask = MIIM_STATE;
169 if (GetMenuItemInfo(theMenu, theID, FALSE, &menuItemInfo))
170 {
171 if (checked)
172 menuItemInfo.fState |= MF_CHECKED;
173 else
174 menuItemInfo.fState &= ~MF_CHECKED;
175 SetMenuItemInfo(theMenu, theID, FALSE, &menuItemInfo);
176 }
177 }
178
179 void DeleteMenuItems(HMENU theMenu, unsigned int firstIDToDelete, unsigned int lastIDToDelete)
180 {
181 MENUITEMINFO menuItemInfo;
182 int menuItemCount;
183 int curIndex;
184
185 menuItemCount = GetMenuItemCount(theMenu);
186 curIndex = 0;
187 while (curIndex < menuItemCount)
188 {
189 menuItemInfo.cbSize = sizeof(menuItemInfo);
190 menuItemInfo.fMask = MIIM_ID;
191 if (GetMenuItemInfo(theMenu, curIndex, TRUE, &menuItemInfo) &&
192 menuItemInfo.wID >= firstIDToDelete && menuItemInfo.wID <= lastIDToDelete)
193 {
194 DeleteMenu(theMenu, curIndex, MF_BYPOSITION);
195 menuItemCount--;
196 }
197 else
198 curIndex++;
199 }
200 }
201
202 HRESULT WINAPI SHBindToFolder(LPCITEMIDLIST path, IShellFolder **newFolder)
203 {
204 CComPtr<IShellFolder> desktop;
205
206 HRESULT hr = ::SHGetDesktopFolder(&desktop);
207 if (FAILED_UNEXPECTEDLY(hr))
208 return E_FAIL;
209 if (path == NULL || path->mkid.cb == 0)
210 {
211 *newFolder = desktop;
212 desktop.p->AddRef ();
213 return S_OK;
214 }
215 return desktop->BindToObject (path, NULL, IID_PPV_ARG(IShellFolder, newFolder));
216 }
217
218 static const TCHAR szCabinetWndClass[] = TEXT("CabinetWClassX");
219 static const TCHAR szExploreWndClass[] = TEXT("ExploreWClassX");
220
221 class CDockManager;
222 class CShellBrowser;
223
224 class CToolbarProxy :
225 public CWindowImpl<CToolbarProxy, CWindow, CControlWinTraits>
226 {
227 private:
228 CComPtr<IExplorerToolbar> fExplorerToolbar;
229 public:
230 void Initialize(HWND parent, IUnknown *explorerToolbar);
231
232 private:
233
234 // message handlers
235 LRESULT OnAddBitmap(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
236 LRESULT OnForwardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
237
238 BEGIN_MSG_MAP(CToolbarProxy)
239 MESSAGE_HANDLER(TB_ADDBITMAP, OnAddBitmap)
240 MESSAGE_RANGE_HANDLER(WM_USER, 0x7fff, OnForwardMessage)
241 END_MSG_MAP()
242 };
243
244 void CToolbarProxy::Initialize(HWND parent, IUnknown *explorerToolbar)
245 {
246 HWND myWindow;
247 HRESULT hResult;
248
249 myWindow = SHCreateWorkerWindowW(0, parent, 0, WS_CHILD, NULL, 0);
250 if (myWindow != NULL)
251 {
252 SubclassWindow(myWindow);
253 SetWindowPos(NULL, -32000, -32000, 0, 0, SWP_NOOWNERZORDER | SWP_NOZORDER);
254 hResult = explorerToolbar->QueryInterface(
255 IID_PPV_ARG(IExplorerToolbar, &fExplorerToolbar));
256 }
257 }
258
259 LRESULT CToolbarProxy::OnAddBitmap(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
260 {
261 long int result;
262 HRESULT hResult;
263
264 result = 0;
265 if (fExplorerToolbar.p != NULL)
266 {
267 hResult = fExplorerToolbar->AddBitmap(&CGID_ShellBrowser, 1, (long)wParam,
268 reinterpret_cast<TBADDBITMAP *>(lParam), &result, RGB(192, 192, 192));
269 hResult = fExplorerToolbar->AddBitmap(&CGID_ShellBrowser, 2, (long)wParam,
270 reinterpret_cast<TBADDBITMAP *>(lParam), &result, RGB(192, 192, 192));
271 }
272 return result;
273 }
274
275 LRESULT CToolbarProxy::OnForwardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
276 {
277 LRESULT result;
278 HRESULT hResult;
279
280 result = 0;
281 if (fExplorerToolbar.p != NULL)
282 hResult = fExplorerToolbar->SendToolbarMsg(&CGID_ShellBrowser, uMsg, wParam, lParam, &result);
283 return result;
284 }
285
286 /*
287 Switch to a new bar when it receives an Exec(CGID_IDeskBand, 1, 1, vaIn, NULL);
288 where vaIn will be a VT_UNKNOWN with the new bar. It also sends a RB_SHOWBAND to the
289 rebar
290 */
291
292 class CShellBrowser :
293 public CWindowImpl<CShellBrowser, CWindow, CFrameWinTraits>,
294 public CComObjectRootEx<CComMultiThreadModelNoCS>,
295 public IShellBrowser,
296 public IDropTarget,
297 public IServiceProvider,
298 public IProfferServiceImpl<CShellBrowser>,
299 public IShellBrowserService,
300 public IWebBrowser2,
301 public ITravelLogClient,
302 public IPersistHistory,
303 public IDockingWindowSite,
304 public IOleCommandTarget,
305 public IBrowserService2,
306 public IConnectionPointContainerImpl<CShellBrowser>,
307 public MyIConnectionPointImpl<CShellBrowser, &DIID_DWebBrowserEvents2>,
308 public MyIConnectionPointImpl<CShellBrowser, &DIID_DWebBrowserEvents>
309 {
310 private:
311 class barInfo
312 {
313 public:
314 RECT borderSpace;
315 CComPtr<IUnknown> clientBar;
316 HWND hwnd;
317 };
318 static const int BIInternetToolbar = 0;
319 static const int BIVerticalBaseBar = 1;
320 static const int BIHorizontalBaseBar = 2;
321
322 HWND fCurrentShellViewWindow; // our currently hosted shell view window
323 CComPtr<IShellFolder> fCurrentShellFolder; //
324 CComPtr<IShellView> fCurrentShellView; //
325 LPITEMIDLIST fCurrentDirectoryPIDL; //
326 HWND fStatusBar;
327 bool fStatusBarVisible;
328 CToolbarProxy fToolbarProxy;
329 barInfo fClientBars[3];
330 CComPtr<ITravelLog> fTravelLog;
331 HMENU fCurrentMenuBar;
332 CABINETSTATE fCabinetState;
333 // The next three fields support persisted history for shell views.
334 // They do not need to be reference counted.
335 IOleObject *fHistoryObject;
336 IStream *fHistoryStream;
337 IBindCtx *fHistoryBindContext;
338 HACCEL m_hAccel;
339 public:
340 #if 0
341 ULONG InternalAddRef()
342 {
343 OutputDebugString(_T("AddRef\n"));
344 return CComObjectRootEx<CComMultiThreadModelNoCS>::InternalAddRef();
345 }
346 ULONG InternalRelease()
347 {
348 OutputDebugString(_T("Release\n"));
349 return CComObjectRootEx<CComMultiThreadModelNoCS>::InternalRelease();
350 }
351 #endif
352
353 CShellBrowser();
354 ~CShellBrowser();
355 HRESULT Initialize(LPITEMIDLIST pidl, long b, long c, long d);
356 public:
357 HRESULT BrowseToPIDL(LPCITEMIDLIST pidl, long flags);
358 HRESULT BrowseToPath(IShellFolder *newShellFolder, LPCITEMIDLIST absolutePIDL,
359 FOLDERSETTINGS *folderSettings, long flags);
360 HRESULT GetMenuBand(REFIID riid, void **shellMenu);
361 HRESULT GetBaseBar(bool vertical, IUnknown **theBaseBar);
362 HRESULT ShowBand(const CLSID &classID, bool vertical);
363 HRESULT NavigateToParent();
364 HRESULT DoFolderOptions();
365 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
366 void RepositionBars();
367 virtual WNDPROC GetWindowProc()
368 {
369 return WindowProc;
370 }
371 HRESULT FireEvent(DISPID dispIdMember, int argCount, VARIANT *arguments);
372 HRESULT FireNavigateComplete(const wchar_t *newDirectory);
373 HRESULT FireCommandStateChange(bool newState, int commandID);
374 HRESULT FireCommandStateChangeAll();
375 HRESULT UpdateForwardBackState();
376 void UpdateGotoMenu(HMENU theMenu);
377 void UpdateViewMenu(HMENU theMenu);
378
379 /* // *** IDockingWindowFrame methods ***
380 virtual HRESULT STDMETHODCALLTYPE AddToolbar(IUnknown *punkSrc, LPCWSTR pwszItem, DWORD dwAddFlags);
381 virtual HRESULT STDMETHODCALLTYPE RemoveToolbar(IUnknown *punkSrc, DWORD dwRemoveFlags);
382 virtual HRESULT STDMETHODCALLTYPE FindToolbar(LPCWSTR pwszItem, REFIID riid, void **ppv);
383 */
384
385 // *** IDockingWindowSite methods ***
386 virtual HRESULT STDMETHODCALLTYPE GetBorderDW(IUnknown* punkObj, LPRECT prcBorder);
387 virtual HRESULT STDMETHODCALLTYPE RequestBorderSpaceDW(IUnknown* punkObj, LPCBORDERWIDTHS pbw);
388 virtual HRESULT STDMETHODCALLTYPE SetBorderSpaceDW(IUnknown* punkObj, LPCBORDERWIDTHS pbw);
389
390 // *** IOleCommandTarget methods ***
391 virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds,
392 OLECMD prgCmds[ ], OLECMDTEXT *pCmdText);
393 virtual HRESULT STDMETHODCALLTYPE Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
394 DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut);
395
396 // *** IOleWindow methods ***
397 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd);
398 virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode);
399
400 // *** IShellBrowser methods ***
401 virtual HRESULT STDMETHODCALLTYPE InsertMenusSB(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
402 virtual HRESULT STDMETHODCALLTYPE SetMenuSB(HMENU hmenuShared, HOLEMENU holemenuRes, HWND hwndActiveObject);
403 virtual HRESULT STDMETHODCALLTYPE RemoveMenusSB(HMENU hmenuShared);
404 virtual HRESULT STDMETHODCALLTYPE SetStatusTextSB(LPCOLESTR pszStatusText);
405 virtual HRESULT STDMETHODCALLTYPE EnableModelessSB(BOOL fEnable);
406 virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorSB(MSG *pmsg, WORD wID);
407 virtual HRESULT STDMETHODCALLTYPE BrowseObject(LPCITEMIDLIST pidl, UINT wFlags);
408 virtual HRESULT STDMETHODCALLTYPE GetViewStateStream(DWORD grfMode, IStream **ppStrm);
409 virtual HRESULT STDMETHODCALLTYPE GetControlWindow(UINT id, HWND *lphwnd);
410 virtual HRESULT STDMETHODCALLTYPE SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret);
411 virtual HRESULT STDMETHODCALLTYPE QueryActiveShellView(IShellView **ppshv);
412 virtual HRESULT STDMETHODCALLTYPE OnViewWindowActive(IShellView *ppshv);
413 virtual HRESULT STDMETHODCALLTYPE SetToolbarItems(LPTBBUTTON lpButtons, UINT nButtons, UINT uFlags);
414
415 // *** IDropTarget methods ***
416 virtual HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
417 virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
418 virtual HRESULT STDMETHODCALLTYPE DragLeave();
419 virtual HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
420
421 // *** IServiceProvider methods ***
422 virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
423
424 // *** IShellBowserService methods ***
425 virtual HRESULT STDMETHODCALLTYPE GetPropertyBag(long flags, REFIID riid, void **ppvObject);
426
427 // *** IDispatch methods ***
428 virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo);
429 virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo);
430 virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(
431 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId);
432 virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
433 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
434
435 // *** IBrowserService methods ***
436 virtual HRESULT STDMETHODCALLTYPE GetParentSite(IOleInPlaceSite **ppipsite);
437 virtual HRESULT STDMETHODCALLTYPE SetTitle(IShellView *psv, LPCWSTR pszName);
438 virtual HRESULT STDMETHODCALLTYPE GetTitle(IShellView *psv, LPWSTR pszName, DWORD cchName);
439 virtual HRESULT STDMETHODCALLTYPE GetOleObject(IOleObject **ppobjv);
440 virtual HRESULT STDMETHODCALLTYPE GetTravelLog(ITravelLog **pptl);
441 virtual HRESULT STDMETHODCALLTYPE ShowControlWindow(UINT id, BOOL fShow);
442 virtual HRESULT STDMETHODCALLTYPE IsControlWindowShown(UINT id, BOOL *pfShown);
443 virtual HRESULT STDMETHODCALLTYPE IEGetDisplayName(LPCITEMIDLIST pidl, LPWSTR pwszName, UINT uFlags);
444 virtual HRESULT STDMETHODCALLTYPE IEParseDisplayName(UINT uiCP, LPCWSTR pwszPath, LPITEMIDLIST *ppidlOut);
445 virtual HRESULT STDMETHODCALLTYPE DisplayParseError(HRESULT hres, LPCWSTR pwszPath);
446 virtual HRESULT STDMETHODCALLTYPE NavigateToPidl(LPCITEMIDLIST pidl, DWORD grfHLNF);
447 virtual HRESULT STDMETHODCALLTYPE SetNavigateState(BNSTATE bnstate);
448 virtual HRESULT STDMETHODCALLTYPE GetNavigateState(BNSTATE *pbnstate);
449 virtual HRESULT STDMETHODCALLTYPE NotifyRedirect(IShellView *psv, LPCITEMIDLIST pidl, BOOL *pfDidBrowse);
450 virtual HRESULT STDMETHODCALLTYPE UpdateWindowList();
451 virtual HRESULT STDMETHODCALLTYPE UpdateBackForwardState();
452 virtual HRESULT STDMETHODCALLTYPE SetFlags(DWORD dwFlags, DWORD dwFlagMask);
453 virtual HRESULT STDMETHODCALLTYPE GetFlags(DWORD *pdwFlags);
454 virtual HRESULT STDMETHODCALLTYPE CanNavigateNow( void);
455 virtual HRESULT STDMETHODCALLTYPE GetPidl(LPITEMIDLIST *ppidl);
456 virtual HRESULT STDMETHODCALLTYPE SetReferrer(LPCITEMIDLIST pidl);
457 virtual DWORD STDMETHODCALLTYPE GetBrowserIndex();
458 virtual HRESULT STDMETHODCALLTYPE GetBrowserByIndex(DWORD dwID, IUnknown **ppunk);
459 virtual HRESULT STDMETHODCALLTYPE GetHistoryObject(IOleObject **ppole, IStream **pstm, IBindCtx **ppbc);
460 virtual HRESULT STDMETHODCALLTYPE SetHistoryObject(IOleObject *pole, BOOL fIsLocalAnchor);
461 virtual HRESULT STDMETHODCALLTYPE CacheOLEServer(IOleObject *pole);
462 virtual HRESULT STDMETHODCALLTYPE GetSetCodePage(VARIANT *pvarIn, VARIANT *pvarOut);
463 virtual HRESULT STDMETHODCALLTYPE OnHttpEquiv(IShellView *psv, BOOL fDone, VARIANT *pvarargIn, VARIANT *pvarargOut);
464 virtual HRESULT STDMETHODCALLTYPE GetPalette(HPALETTE *hpal);
465 virtual HRESULT STDMETHODCALLTYPE RegisterWindow(BOOL fForceRegister, int swc);
466
467 // *** IBrowserService2 methods ***
468 virtual LRESULT STDMETHODCALLTYPE WndProcBS(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
469 virtual HRESULT STDMETHODCALLTYPE SetAsDefFolderSettings();
470 virtual HRESULT STDMETHODCALLTYPE GetViewRect(RECT *prc);
471 virtual HRESULT STDMETHODCALLTYPE OnSize(WPARAM wParam);
472 virtual HRESULT STDMETHODCALLTYPE OnCreate(struct tagCREATESTRUCTW *pcs);
473 virtual LRESULT STDMETHODCALLTYPE OnCommand(WPARAM wParam, LPARAM lParam);
474 virtual HRESULT STDMETHODCALLTYPE OnDestroy();
475 virtual LRESULT STDMETHODCALLTYPE OnNotify(struct tagNMHDR *pnm);
476 virtual HRESULT STDMETHODCALLTYPE OnSetFocus();
477 virtual HRESULT STDMETHODCALLTYPE OnFrameWindowActivateBS(BOOL fActive);
478 virtual HRESULT STDMETHODCALLTYPE ReleaseShellView();
479 virtual HRESULT STDMETHODCALLTYPE ActivatePendingView();
480 virtual HRESULT STDMETHODCALLTYPE CreateViewWindow(IShellView *psvNew, IShellView *psvOld, LPRECT prcView, HWND *phwnd);
481 virtual HRESULT STDMETHODCALLTYPE CreateBrowserPropSheetExt(REFIID riid, void **ppv);
482 virtual HRESULT STDMETHODCALLTYPE GetViewWindow(HWND *phwndView);
483 virtual HRESULT STDMETHODCALLTYPE GetBaseBrowserData(LPCBASEBROWSERDATA *pbbd);
484 virtual LPBASEBROWSERDATA STDMETHODCALLTYPE PutBaseBrowserData( void);
485 virtual HRESULT STDMETHODCALLTYPE InitializeTravelLog(ITravelLog *ptl, DWORD dw);
486 virtual HRESULT STDMETHODCALLTYPE SetTopBrowser();
487 virtual HRESULT STDMETHODCALLTYPE Offline(int iCmd);
488 virtual HRESULT STDMETHODCALLTYPE AllowViewResize(BOOL f);
489 virtual HRESULT STDMETHODCALLTYPE SetActivateState(UINT u);
490 virtual HRESULT STDMETHODCALLTYPE UpdateSecureLockIcon(int eSecureLock);
491 virtual HRESULT STDMETHODCALLTYPE InitializeDownloadManager();
492 virtual HRESULT STDMETHODCALLTYPE InitializeTransitionSite();
493 virtual HRESULT STDMETHODCALLTYPE _Initialize(HWND hwnd, IUnknown *pauto);
494 virtual HRESULT STDMETHODCALLTYPE _CancelPendingNavigationAsync( void);
495 virtual HRESULT STDMETHODCALLTYPE _CancelPendingView();
496 virtual HRESULT STDMETHODCALLTYPE _MaySaveChanges();
497 virtual HRESULT STDMETHODCALLTYPE _PauseOrResumeView(BOOL fPaused);
498 virtual HRESULT STDMETHODCALLTYPE _DisableModeless();
499 virtual HRESULT STDMETHODCALLTYPE _NavigateToPidl(LPCITEMIDLIST pidl, DWORD grfHLNF, DWORD dwFlags);
500 virtual HRESULT STDMETHODCALLTYPE _TryShell2Rename(IShellView *psv, LPCITEMIDLIST pidlNew);
501 virtual HRESULT STDMETHODCALLTYPE _SwitchActivationNow();
502 virtual HRESULT STDMETHODCALLTYPE _ExecChildren(IUnknown *punkBar, BOOL fBroadcast, const GUID *pguidCmdGroup,
503 DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
504 virtual HRESULT STDMETHODCALLTYPE _SendChildren(
505 HWND hwndBar, BOOL fBroadcast, UINT uMsg, WPARAM wParam, LPARAM lParam);
506 virtual HRESULT STDMETHODCALLTYPE GetFolderSetData(struct tagFolderSetData *pfsd);
507 virtual HRESULT STDMETHODCALLTYPE _OnFocusChange(UINT itb);
508 virtual HRESULT STDMETHODCALLTYPE v_ShowHideChildWindows(BOOL fChildOnly);
509 virtual UINT STDMETHODCALLTYPE _get_itbLastFocus();
510 virtual HRESULT STDMETHODCALLTYPE _put_itbLastFocus(UINT itbLastFocus);
511 virtual HRESULT STDMETHODCALLTYPE _UIActivateView(UINT uState);
512 virtual HRESULT STDMETHODCALLTYPE _GetViewBorderRect(RECT *prc);
513 virtual HRESULT STDMETHODCALLTYPE _UpdateViewRectSize();
514 virtual HRESULT STDMETHODCALLTYPE _ResizeNextBorder(UINT itb);
515 virtual HRESULT STDMETHODCALLTYPE _ResizeView();
516 virtual HRESULT STDMETHODCALLTYPE _GetEffectiveClientArea(LPRECT lprectBorder, HMONITOR hmon);
517 virtual IStream *STDMETHODCALLTYPE v_GetViewStream(LPCITEMIDLIST pidl, DWORD grfMode, LPCWSTR pwszName);
518 virtual LRESULT STDMETHODCALLTYPE ForwardViewMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
519 virtual HRESULT STDMETHODCALLTYPE SetAcceleratorMenu(HACCEL hacc);
520 virtual int STDMETHODCALLTYPE _GetToolbarCount();
521 virtual LPTOOLBARITEM STDMETHODCALLTYPE _GetToolbarItem(int itb);
522 virtual HRESULT STDMETHODCALLTYPE _SaveToolbars(IStream *pstm);
523 virtual HRESULT STDMETHODCALLTYPE _LoadToolbars(IStream *pstm);
524 virtual HRESULT STDMETHODCALLTYPE _CloseAndReleaseToolbars(BOOL fClose);
525 virtual HRESULT STDMETHODCALLTYPE v_MayGetNextToolbarFocus(LPMSG lpMsg, UINT itbNext,
526 int citb, LPTOOLBARITEM *pptbi, HWND *phwnd);
527 virtual HRESULT STDMETHODCALLTYPE _ResizeNextBorderHelper(UINT itb, BOOL bUseHmonitor);
528 virtual UINT STDMETHODCALLTYPE _FindTBar(IUnknown *punkSrc);
529 virtual HRESULT STDMETHODCALLTYPE _SetFocus(LPTOOLBARITEM ptbi, HWND hwnd, LPMSG lpMsg);
530 virtual HRESULT STDMETHODCALLTYPE v_MayTranslateAccelerator(MSG *pmsg);
531 virtual HRESULT STDMETHODCALLTYPE _GetBorderDWHelper(IUnknown *punkSrc, LPRECT lprectBorder, BOOL bUseHmonitor);
532 virtual HRESULT STDMETHODCALLTYPE v_CheckZoneCrossing(LPCITEMIDLIST pidl);
533
534 // *** IWebBrowser methods ***
535 virtual HRESULT STDMETHODCALLTYPE GoBack();
536 virtual HRESULT STDMETHODCALLTYPE GoForward();
537 virtual HRESULT STDMETHODCALLTYPE GoHome();
538 virtual HRESULT STDMETHODCALLTYPE GoSearch();
539 virtual HRESULT STDMETHODCALLTYPE Navigate(BSTR URL, VARIANT *Flags, VARIANT *TargetFrameName,
540 VARIANT *PostData, VARIANT *Headers);
541 virtual HRESULT STDMETHODCALLTYPE Refresh();
542 virtual HRESULT STDMETHODCALLTYPE Refresh2(VARIANT *Level);
543 virtual HRESULT STDMETHODCALLTYPE Stop();
544 virtual HRESULT STDMETHODCALLTYPE get_Application(IDispatch **ppDisp);
545 virtual HRESULT STDMETHODCALLTYPE get_Parent(IDispatch **ppDisp);
546 virtual HRESULT STDMETHODCALLTYPE get_Container(IDispatch **ppDisp);
547 virtual HRESULT STDMETHODCALLTYPE get_Document(IDispatch **ppDisp);
548 virtual HRESULT STDMETHODCALLTYPE get_TopLevelContainer(VARIANT_BOOL *pBool);
549 virtual HRESULT STDMETHODCALLTYPE get_Type(BSTR *Type);
550 virtual HRESULT STDMETHODCALLTYPE get_Left(long *pl);
551 virtual HRESULT STDMETHODCALLTYPE put_Left(long Left);
552 virtual HRESULT STDMETHODCALLTYPE get_Top(long *pl);
553 virtual HRESULT STDMETHODCALLTYPE put_Top(long Top);
554 virtual HRESULT STDMETHODCALLTYPE get_Width(long *pl);
555 virtual HRESULT STDMETHODCALLTYPE put_Width(long Width);
556 virtual HRESULT STDMETHODCALLTYPE get_Height(long *pl);
557 virtual HRESULT STDMETHODCALLTYPE put_Height(long Height);
558 virtual HRESULT STDMETHODCALLTYPE get_LocationName(BSTR *LocationName);
559 virtual HRESULT STDMETHODCALLTYPE get_LocationURL(BSTR *LocationURL);
560 virtual HRESULT STDMETHODCALLTYPE get_Busy(VARIANT_BOOL *pBool);
561
562 // *** IWebBrowserApp methods ***
563 virtual HRESULT STDMETHODCALLTYPE Quit();
564 virtual HRESULT STDMETHODCALLTYPE ClientToWindow(int *pcx, int *pcy);
565 virtual HRESULT STDMETHODCALLTYPE PutProperty(BSTR Property, VARIANT vtValue);
566 virtual HRESULT STDMETHODCALLTYPE GetProperty(BSTR Property, VARIANT *pvtValue);
567 virtual HRESULT STDMETHODCALLTYPE get_Name(BSTR *Name);
568 virtual HRESULT STDMETHODCALLTYPE get_HWND(SHANDLE_PTR *pHWND);
569 virtual HRESULT STDMETHODCALLTYPE get_FullName(BSTR *FullName);
570 virtual HRESULT STDMETHODCALLTYPE get_Path(BSTR *Path);
571 virtual HRESULT STDMETHODCALLTYPE get_Visible(VARIANT_BOOL *pBool);
572 virtual HRESULT STDMETHODCALLTYPE put_Visible(VARIANT_BOOL Value);
573 virtual HRESULT STDMETHODCALLTYPE get_StatusBar(VARIANT_BOOL *pBool);
574 virtual HRESULT STDMETHODCALLTYPE put_StatusBar(VARIANT_BOOL Value);
575 virtual HRESULT STDMETHODCALLTYPE get_StatusText(BSTR *StatusText);
576 virtual HRESULT STDMETHODCALLTYPE put_StatusText(BSTR StatusText);
577 virtual HRESULT STDMETHODCALLTYPE get_ToolBar(int *Value);
578 virtual HRESULT STDMETHODCALLTYPE put_ToolBar(int Value);
579 virtual HRESULT STDMETHODCALLTYPE get_MenuBar(VARIANT_BOOL *Value);
580 virtual HRESULT STDMETHODCALLTYPE put_MenuBar(VARIANT_BOOL Value);
581 virtual HRESULT STDMETHODCALLTYPE get_FullScreen(VARIANT_BOOL *pbFullScreen);
582 virtual HRESULT STDMETHODCALLTYPE put_FullScreen(VARIANT_BOOL bFullScreen);
583
584 // *** IWebBrowser2 methods ***
585 virtual HRESULT STDMETHODCALLTYPE Navigate2(VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName,
586 VARIANT *PostData, VARIANT *Headers);
587 virtual HRESULT STDMETHODCALLTYPE QueryStatusWB(OLECMDID cmdID, OLECMDF *pcmdf);
588 virtual HRESULT STDMETHODCALLTYPE ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt,
589 VARIANT *pvaIn, VARIANT *pvaOut);
590 virtual HRESULT STDMETHODCALLTYPE ShowBrowserBar(VARIANT *pvaClsid, VARIANT *pvarShow, VARIANT *pvarSize);
591 virtual HRESULT STDMETHODCALLTYPE get_ReadyState(READYSTATE *plReadyState);
592 virtual HRESULT STDMETHODCALLTYPE get_Offline(VARIANT_BOOL *pbOffline);
593 virtual HRESULT STDMETHODCALLTYPE put_Offline(VARIANT_BOOL bOffline);
594 virtual HRESULT STDMETHODCALLTYPE get_Silent(VARIANT_BOOL *pbSilent);
595 virtual HRESULT STDMETHODCALLTYPE put_Silent(VARIANT_BOOL bSilent);
596 virtual HRESULT STDMETHODCALLTYPE get_RegisterAsBrowser(VARIANT_BOOL *pbRegister);
597 virtual HRESULT STDMETHODCALLTYPE put_RegisterAsBrowser(VARIANT_BOOL bRegister);
598 virtual HRESULT STDMETHODCALLTYPE get_RegisterAsDropTarget(VARIANT_BOOL *pbRegister);
599 virtual HRESULT STDMETHODCALLTYPE put_RegisterAsDropTarget(VARIANT_BOOL bRegister);
600 virtual HRESULT STDMETHODCALLTYPE get_TheaterMode(VARIANT_BOOL *pbRegister);
601 virtual HRESULT STDMETHODCALLTYPE put_TheaterMode(VARIANT_BOOL bRegister);
602 virtual HRESULT STDMETHODCALLTYPE get_AddressBar(VARIANT_BOOL *Value);
603 virtual HRESULT STDMETHODCALLTYPE put_AddressBar(VARIANT_BOOL Value);
604 virtual HRESULT STDMETHODCALLTYPE get_Resizable(VARIANT_BOOL *Value);
605 virtual HRESULT STDMETHODCALLTYPE put_Resizable(VARIANT_BOOL Value);
606
607 // *** ITravelLogClient methods ***
608 virtual HRESULT STDMETHODCALLTYPE FindWindowByIndex(DWORD dwID, IUnknown **ppunk);
609 virtual HRESULT STDMETHODCALLTYPE GetWindowData(IStream *pStream, LPWINDOWDATA pWinData);
610 virtual HRESULT STDMETHODCALLTYPE LoadHistoryPosition(LPWSTR pszUrlLocation, DWORD dwPosition);
611
612 // *** IPersist methods ***
613 virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID);
614
615 // *** IPersistHistory methods ***
616 virtual HRESULT STDMETHODCALLTYPE LoadHistory(IStream *pStream, IBindCtx *pbc);
617 virtual HRESULT STDMETHODCALLTYPE SaveHistory(IStream *pStream);
618 virtual HRESULT STDMETHODCALLTYPE SetPositionCookie(DWORD dwPositioncookie);
619 virtual HRESULT STDMETHODCALLTYPE GetPositionCookie(DWORD *pdwPositioncookie);
620
621 // message handlers
622 LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
623 LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
624 LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
625 LRESULT OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
626 LRESULT RelayMsgToShellView(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
627 LRESULT OnClose(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
628 LRESULT OnFolderOptions(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
629 LRESULT OnMapNetworkDrive(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
630 LRESULT OnDisconnectNetworkDrive(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
631 LRESULT OnAboutReactOS(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
632 LRESULT OnGoBack(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
633 LRESULT OnGoForward(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
634 LRESULT OnGoUpLevel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
635 LRESULT OnBackspace(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
636 LRESULT OnGoHome(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
637 LRESULT OnIsThisLegal(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
638 LRESULT OnToggleStatusBarVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
639 LRESULT OnToggleToolbarLock(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
640 LRESULT OnToggleToolbarBandVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
641 LRESULT OnToggleAddressBandVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
642 LRESULT OnToggleLinksBandVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
643 LRESULT OnToggleTextLabels(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
644 LRESULT OnToolbarCustomize(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
645 LRESULT OnGoTravel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
646 LRESULT RelayCommands(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
647
648 static ATL::CWndClassInfo& GetWndClassInfo()
649 {
650 static ATL::CWndClassInfo wc =
651 {
652 { sizeof(WNDCLASSEX), CS_DBLCLKS, StartWindowProc,
653 0, 0, NULL, LoadIcon(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDI_CABINET)),
654 LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW + 1), NULL, szCabinetWndClass, NULL },
655 NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
656 };
657 return wc;
658 }
659
660 BEGIN_MSG_MAP(CShellBrowser)
661 MESSAGE_HANDLER(WM_CREATE, OnCreate)
662 MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
663 MESSAGE_HANDLER(WM_SIZE, OnSize)
664 MESSAGE_HANDLER(WM_INITMENUPOPUP, OnInitMenuPopup)
665 MESSAGE_HANDLER(WM_MEASUREITEM, RelayMsgToShellView)
666 MESSAGE_HANDLER(WM_DRAWITEM, RelayMsgToShellView)
667 MESSAGE_HANDLER(WM_MENUSELECT, RelayMsgToShellView)
668 COMMAND_ID_HANDLER(IDM_FILE_CLOSE, OnClose)
669 COMMAND_ID_HANDLER(IDM_TOOLS_FOLDEROPTIONS, OnFolderOptions)
670 COMMAND_ID_HANDLER(IDM_TOOLS_MAPNETWORKDRIVE, OnMapNetworkDrive)
671 COMMAND_ID_HANDLER(IDM_TOOLS_DISCONNECTNETWORKDRIVE, OnDisconnectNetworkDrive)
672 COMMAND_ID_HANDLER(IDM_HELP_ABOUT, OnAboutReactOS)
673 COMMAND_ID_HANDLER(IDM_GOTO_BACK, OnGoBack)
674 COMMAND_ID_HANDLER(IDM_GOTO_FORWARD, OnGoForward)
675 COMMAND_ID_HANDLER(IDM_GOTO_UPONELEVEL, OnGoUpLevel)
676 COMMAND_ID_HANDLER(IDM_GOTO_HOMEPAGE, OnGoHome)
677 COMMAND_ID_HANDLER(IDM_HELP_ISTHISCOPYLEGAL, OnIsThisLegal)
678 COMMAND_ID_HANDLER(IDM_VIEW_STATUSBAR, OnToggleStatusBarVisible)
679 COMMAND_ID_HANDLER(IDM_TOOLBARS_LOCKTOOLBARS, OnToggleToolbarLock)
680 COMMAND_ID_HANDLER(IDM_TOOLBARS_STANDARDBUTTONS, OnToggleToolbarBandVisible)
681 COMMAND_ID_HANDLER(IDM_TOOLBARS_ADDRESSBAR, OnToggleAddressBandVisible)
682 COMMAND_ID_HANDLER(IDM_TOOLBARS_LINKSBAR, OnToggleLinksBandVisible)
683 COMMAND_ID_HANDLER(IDM_TOOLBARS_TEXTLABELS, OnToggleTextLabels)
684 COMMAND_ID_HANDLER(IDM_TOOLBARS_CUSTOMIZE, OnToolbarCustomize)
685 COMMAND_ID_HANDLER(IDM_BACKSPACE, OnBackspace)
686 COMMAND_RANGE_HANDLER(IDM_GOTO_TRAVEL_FIRSTTARGET, IDM_GOTO_TRAVEL_LASTTARGET, OnGoTravel)
687 MESSAGE_HANDLER(WM_COMMAND, RelayCommands)
688 END_MSG_MAP()
689
690 BEGIN_CONNECTION_POINT_MAP(CShellBrowser)
691 CONNECTION_POINT_ENTRY(DIID_DWebBrowserEvents2)
692 CONNECTION_POINT_ENTRY(DIID_DWebBrowserEvents)
693 END_CONNECTION_POINT_MAP()
694
695 BEGIN_COM_MAP(CShellBrowser)
696 COM_INTERFACE_ENTRY_IID(IID_IDockingWindowSite, IDockingWindowSite)
697 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
698 COM_INTERFACE_ENTRY2_IID(IID_IOleWindow, IOleWindow, IDockingWindowSite)
699 COM_INTERFACE_ENTRY_IID(IID_IShellBrowser, IShellBrowser)
700 COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
701 COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
702 COM_INTERFACE_ENTRY_IID(IID_IProfferService, IProfferService)
703 COM_INTERFACE_ENTRY_IID(IID_IShellBrowserService, IShellBrowserService)
704 COM_INTERFACE_ENTRY_IID(IID_IDispatch, IDispatch)
705 COM_INTERFACE_ENTRY_IID(IID_IConnectionPointContainer, IConnectionPointContainer)
706 COM_INTERFACE_ENTRY_IID(IID_IWebBrowser, IWebBrowser)
707 COM_INTERFACE_ENTRY_IID(IID_IWebBrowserApp, IWebBrowserApp)
708 COM_INTERFACE_ENTRY_IID(IID_IWebBrowser2, IWebBrowser2)
709 COM_INTERFACE_ENTRY_IID(IID_ITravelLogClient, ITravelLogClient)
710 COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
711 COM_INTERFACE_ENTRY_IID(IID_IPersistHistory, IPersistHistory)
712 COM_INTERFACE_ENTRY_IID(IID_IBrowserService, IBrowserService)
713 COM_INTERFACE_ENTRY_IID(IID_IBrowserService2, IBrowserService2)
714 END_COM_MAP()
715 };
716
717 extern HRESULT CreateProgressDialog(REFIID riid, void **ppv);
718
719 CShellBrowser::CShellBrowser()
720 {
721 fCurrentShellViewWindow = NULL;
722 fCurrentDirectoryPIDL = NULL;
723 fStatusBar = NULL;
724 fStatusBarVisible = true;
725 memset(fClientBars, 0, sizeof(fClientBars));
726 fCurrentMenuBar = NULL;
727 fHistoryObject = NULL;
728 fHistoryStream = NULL;
729 fHistoryBindContext = NULL;
730 }
731
732 CShellBrowser::~CShellBrowser()
733 {
734 }
735
736 HRESULT CShellBrowser::Initialize(LPITEMIDLIST pidl, long b, long c, long d)
737 {
738 CComPtr<IPersistStreamInit> persistStreamInit;
739 HRESULT hResult;
740 CComPtr<IUnknown> clientBar;
741
742 _AtlInitialConstruct();
743
744 fCabinetState.cLength = sizeof(fCabinetState);
745 if (ReadCabinetState(&fCabinetState, sizeof(fCabinetState)) == FALSE)
746 {
747 }
748
749 // create window
750 Create(HWND_DESKTOP);
751 if (m_hWnd == NULL)
752 return E_FAIL;
753
754 #if 0
755 hResult = CoCreateInstance(CLSID_InternetToolbar, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IUnknown, &fClientBars[BIInternetToolbar].clientBar));
756 if (FAILED_UNEXPECTEDLY(hResult))
757 return hResult;
758 #else
759 hResult = CreateInternetToolbar(IID_PPV_ARG(IUnknown, &clientBar));
760 if (FAILED_UNEXPECTEDLY(hResult))
761 return hResult;
762 #endif
763
764 fClientBars[BIInternetToolbar].clientBar = clientBar;
765
766 // create interfaces
767 hResult = clientBar->QueryInterface(IID_PPV_ARG(IPersistStreamInit, &persistStreamInit));
768 if (FAILED_UNEXPECTEDLY(hResult))
769 return hResult;
770
771 hResult = IUnknown_SetSite(clientBar, static_cast<IShellBrowser *>(this));
772 if (FAILED_UNEXPECTEDLY(hResult))
773 return hResult;
774
775 hResult = IUnknown_Exec(clientBar, CGID_PrivCITCommands, 1, 1 /* or 0 */, NULL, NULL);
776 if (FAILED_UNEXPECTEDLY(hResult))
777 return hResult;
778
779 // TODO: create settingsStream from registry entry
780 //if (settingsStream.p)
781 //{
782 // hResult = persistStreamInit->Load(settingsStream);
783 // if (FAILED_UNEXPECTEDLY(hResult))
784 // return hResult;
785 //}
786 //else
787 {
788 hResult = persistStreamInit->InitNew();
789 if (FAILED_UNEXPECTEDLY(hResult))
790 return hResult;
791 }
792
793 hResult = IUnknown_ShowDW(clientBar, TRUE);
794 if (FAILED_UNEXPECTEDLY(hResult))
795 return hResult;
796
797 fToolbarProxy.Initialize(m_hWnd, clientBar);
798
799
800 // create status bar
801 fStatusBar = CreateWindow(STATUSCLASSNAMEW, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
802 SBT_NOBORDERS | SBT_TOOLTIPS, 0, 0, 500, 20, m_hWnd, (HMENU)0xa001,
803 _AtlBaseModule.GetModuleInstance(), 0);
804 fStatusBarVisible = true;
805
806
807 // browse
808 hResult = BrowseToPIDL(pidl, BTP_UPDATE_NEXT_HISTORY);
809 if (FAILED_UNEXPECTEDLY(hResult))
810 return hResult;
811
812 ShowWindow(SW_SHOWNORMAL);
813
814 return S_OK;
815 }
816
817 HRESULT CShellBrowser::BrowseToPIDL(LPCITEMIDLIST pidl, long flags)
818 {
819 CComPtr<IShellFolder> newFolder;
820 FOLDERSETTINGS newFolderSettings;
821 HRESULT hResult;
822
823 // called by shell view to browse to new folder
824 // also called by explorer band to navigate to new folder
825 hResult = SHBindToFolder(pidl, &newFolder);
826 if (FAILED_UNEXPECTEDLY(hResult))
827 return hResult;
828
829 newFolderSettings.ViewMode = FVM_ICON;
830 newFolderSettings.fFlags = 0;
831 hResult = BrowseToPath(newFolder, pidl, &newFolderSettings, flags);
832 if (FAILED_UNEXPECTEDLY(hResult))
833 return hResult;
834 return S_OK;
835 }
836
837 BOOL WINAPI _ILIsDesktop(LPCITEMIDLIST pidl)
838 {
839 return (pidl == NULL || pidl->mkid.cb == 0);
840 }
841
842 BOOL WINAPI _ILIsPidlSimple(LPCITEMIDLIST pidl)
843 {
844 LPCITEMIDLIST pidlnext;
845 WORD length;
846 BOOL ret;
847
848 ret = TRUE;
849 if (! _ILIsDesktop(pidl))
850 {
851 length = pidl->mkid.cb;
852 pidlnext =
853 reinterpret_cast<LPCITEMIDLIST>(
854 reinterpret_cast<const BYTE *>(pidl) + length);
855 if (pidlnext->mkid.cb != 0)
856 ret = FALSE;
857 }
858 return ret;
859 }
860
861 HRESULT WINAPI SHBindToFolderIDListParent(IShellFolder *unused, LPCITEMIDLIST pidl,
862 const IID *riid, LPVOID *ppv, LPITEMIDLIST *ppidlLast)
863 {
864 CComPtr<IShellFolder> psf;
865 LPITEMIDLIST pidlChild;
866 LPITEMIDLIST pidlParent;
867 HRESULT hResult;
868
869 hResult = E_FAIL;
870 if (ppv == NULL)
871 return E_POINTER;
872 *ppv = NULL;
873 if (ppidlLast != NULL)
874 *ppidlLast = NULL;
875 if (_ILIsPidlSimple(pidl))
876 {
877 if (ppidlLast != NULL)
878 *ppidlLast = ILClone(pidl);
879 hResult = SHGetDesktopFolder((IShellFolder **)ppv);
880 }
881 else
882 {
883 pidlChild = ILClone(ILFindLastID(pidl));
884 pidlParent = ILClone(pidl);
885 ILRemoveLastID(pidlParent);
886 hResult = SHGetDesktopFolder(&psf);
887 if (SUCCEEDED(hResult))
888 hResult = psf->BindToObject(pidlParent, NULL, *riid, ppv);
889 if (SUCCEEDED(hResult) && ppidlLast != NULL)
890 *ppidlLast = pidlChild;
891 else
892 ILFree(pidlChild);
893 ILFree(pidlParent);
894 }
895 return hResult;
896 }
897
898 HRESULT IEGetNameAndFlagsEx(LPITEMIDLIST pidl, SHGDNF uFlags, long param10,
899 LPWSTR pszBuf, UINT cchBuf, SFGAOF *rgfInOut)
900 {
901 CComPtr<IShellFolder> parentFolder;
902 LPITEMIDLIST childPIDL;
903 STRRET L108;
904 HRESULT hResult;
905
906 hResult = SHBindToFolderIDListParent(NULL, pidl, &IID_PPV_ARG(IShellFolder, &parentFolder), &childPIDL);
907 if (FAILED(hResult))
908 return hResult;
909
910 hResult = parentFolder->GetDisplayNameOf(childPIDL, uFlags, &L108);
911 if (FAILED(hResult))
912 return hResult;
913
914 StrRetToBufW(&L108, childPIDL, pszBuf, cchBuf);
915 if (rgfInOut)
916 {
917 hResult = parentFolder->GetAttributesOf(1, const_cast<LPCITEMIDLIST *>(&childPIDL), rgfInOut);
918 if (FAILED(hResult))
919 return hResult;
920 }
921
922 ILFree(childPIDL);
923 return S_OK;
924 }
925
926 long IEGetNameAndFlags(LPITEMIDLIST pidl, SHGDNF uFlags, LPWSTR pszBuf, UINT cchBuf, SFGAOF *rgfInOut)
927 {
928 return IEGetNameAndFlagsEx(pidl, uFlags, 0, pszBuf, cchBuf, rgfInOut);
929 }
930
931 HRESULT CShellBrowser::BrowseToPath(IShellFolder *newShellFolder,
932 LPCITEMIDLIST absolutePIDL, FOLDERSETTINGS *folderSettings, long flags)
933 {
934 CComPtr<IObjectWithSite> objectWithSite;
935 CComPtr<IShellFolder> saveCurrentShellFolder;
936 CComPtr<IShellView> saveCurrentShellView;
937 CComPtr<IShellView> newShellView;
938 CComPtr<ITravelLog> travelLog;
939 HWND newShellViewWindow;
940 BOOL windowUpdateIsLocked;
941 RECT shellViewWindowBounds;
942 HWND previousView;
943 HCURSOR saveCursor;
944 wchar_t newTitle[MAX_PATH];
945 SHGDNF nameFlags;
946 HRESULT hResult;
947
948 if (newShellFolder == NULL)
949 return E_INVALIDARG;
950
951 hResult = GetTravelLog(&travelLog);
952 if (FAILED_UNEXPECTEDLY(hResult))
953 return hResult;
954
955 // update history
956 if (flags & BTP_UPDATE_CUR_HISTORY)
957 {
958 if (travelLog->CountEntries(static_cast<IDropTarget *>(this)) > 0)
959 hResult = travelLog->UpdateEntry(static_cast<IDropTarget *>(this), FALSE);
960 // what to do with error? Do we want to halt browse because state save failed?
961 }
962
963 if (fCurrentShellView)
964 {
965 fCurrentShellView->UIActivate(SVUIA_DEACTIVATE);
966 }
967
968 // create view object
969 hResult = newShellFolder->CreateViewObject(m_hWnd, IID_PPV_ARG(IShellView, &newShellView));
970 if (FAILED_UNEXPECTEDLY(hResult))
971 return hResult;
972 previousView = fCurrentShellViewWindow;
973
974 // enter updating section
975 saveCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
976 windowUpdateIsLocked = LockWindowUpdate(TRUE);
977 if (fCurrentShellView != NULL)
978 ::SendMessage(fCurrentShellViewWindow, WM_SETREDRAW, 0, 0);
979
980 // set site
981 hResult = newShellView->QueryInterface(IID_PPV_ARG(IObjectWithSite, &objectWithSite));
982 if (SUCCEEDED(hResult) && objectWithSite.p != NULL)
983 hResult = objectWithSite->SetSite(static_cast<IDropTarget *>(this));
984
985 // update folder and view
986 saveCurrentShellFolder = fCurrentShellFolder;
987 saveCurrentShellView = fCurrentShellView;
988 fCurrentShellFolder = newShellFolder;
989 fCurrentShellView = newShellView;
990
991 // get boundary
992 if (previousView != NULL)
993 ::GetWindowRect(previousView, &shellViewWindowBounds);
994 else
995 ZeroMemory(&shellViewWindowBounds, sizeof(shellViewWindowBounds));
996 ::MapWindowPoints(0, m_hWnd, reinterpret_cast<POINT *>(&shellViewWindowBounds), 2);
997
998 // create view window
999 hResult = newShellView->CreateViewWindow(saveCurrentShellView, folderSettings,
1000 this, &shellViewWindowBounds, &newShellViewWindow);
1001 if (FAILED_UNEXPECTEDLY(hResult) || newShellViewWindow == NULL)
1002 {
1003 fCurrentShellView = saveCurrentShellView;
1004 fCurrentShellFolder = saveCurrentShellFolder;
1005 ::SendMessage(fCurrentShellViewWindow, WM_SETREDRAW, 1, 0);
1006 if (windowUpdateIsLocked)
1007 LockWindowUpdate(FALSE);
1008 SetCursor(saveCursor);
1009 return hResult;
1010 }
1011
1012 if (objectWithSite.p != NULL)
1013 hResult = objectWithSite->SetSite(NULL);
1014
1015 // update current pidl
1016 ILFree(fCurrentDirectoryPIDL);
1017 fCurrentDirectoryPIDL = ILClone(absolutePIDL);
1018
1019 // update view window
1020 if (saveCurrentShellView != NULL)
1021 saveCurrentShellView->DestroyViewWindow();
1022 fCurrentShellViewWindow = newShellViewWindow;
1023
1024 // no use
1025 saveCurrentShellView.Release();
1026 saveCurrentShellFolder.Release();
1027
1028 hResult = newShellView->UIActivate(SVUIA_ACTIVATE_FOCUS);
1029
1030 // leave updating section
1031 if (windowUpdateIsLocked)
1032 LockWindowUpdate(FALSE);
1033 SetCursor(saveCursor);
1034
1035 // update history
1036 if (flags & BTP_UPDATE_NEXT_HISTORY)
1037 {
1038 hResult = travelLog->AddEntry(static_cast<IDropTarget *>(this), FALSE);
1039 hResult = travelLog->UpdateEntry(static_cast<IDropTarget *>(this), FALSE);
1040 }
1041
1042 // completed
1043 nameFlags = SHGDN_FORADDRESSBAR | SHGDN_FORPARSING;
1044 hResult = IEGetNameAndFlags(fCurrentDirectoryPIDL, nameFlags, newTitle,
1045 sizeof(newTitle) / sizeof(wchar_t), NULL);
1046 if (SUCCEEDED(hResult))
1047 {
1048 FireNavigateComplete(newTitle);
1049 }
1050 else
1051 {
1052 FireNavigateComplete(L"ERROR");
1053 }
1054
1055 if (fCabinetState.fFullPathTitle)
1056 nameFlags = SHGDN_FORADDRESSBAR | SHGDN_FORPARSING;
1057 else
1058 nameFlags = SHGDN_FORADDRESSBAR;
1059 hResult = IEGetNameAndFlags(fCurrentDirectoryPIDL, nameFlags, newTitle,
1060 sizeof(newTitle) / sizeof(wchar_t), NULL);
1061 if (SUCCEEDED(hResult))
1062 {
1063 SetWindowText(newTitle);
1064
1065 LPCITEMIDLIST pidlChild;
1066 INT index, indexOpen;
1067 HIMAGELIST himlSmall, himlLarge;
1068
1069 CComPtr<IShellFolder> sf;
1070 SHBindToParent(absolutePIDL, IID_PPV_ARG(IShellFolder, &sf), &pidlChild);
1071
1072 index = SHMapPIDLToSystemImageListIndex(sf, pidlChild, &indexOpen);
1073
1074 Shell_GetImageLists(&himlLarge, &himlSmall);
1075
1076 HICON icSmall = ImageList_GetIcon(himlSmall, indexOpen, 0);
1077 HICON icLarge = ImageList_GetIcon(himlLarge, indexOpen, 0);
1078
1079 SendMessage(WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(icSmall));
1080 SendMessage(WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(icLarge));
1081 }
1082
1083 // TODO: Update the window icon
1084
1085 FireCommandStateChangeAll();
1086 hResult = UpdateForwardBackState();
1087 return S_OK;
1088 }
1089
1090 HRESULT CShellBrowser::GetMenuBand(REFIID riid, void **shellMenu)
1091 {
1092 CComPtr<IServiceProvider> serviceProvider;
1093 CComPtr<IBandSite> bandSite;
1094 CComPtr<IDeskBand> deskBand;
1095 HRESULT hResult;
1096
1097 if (!fClientBars[BIInternetToolbar].clientBar)
1098 return E_FAIL;
1099
1100 hResult = IUnknown_QueryService(fClientBars[BIInternetToolbar].clientBar, SID_IBandSite, IID_PPV_ARG(IBandSite, &bandSite));
1101 if (FAILED_UNEXPECTEDLY(hResult))
1102 return hResult;
1103
1104 hResult = bandSite->QueryBand(1, &deskBand, NULL, NULL, 0);
1105 if (FAILED_UNEXPECTEDLY(hResult))
1106 return hResult;
1107
1108 return deskBand->QueryInterface(riid, shellMenu);
1109 }
1110
1111 HRESULT CShellBrowser::GetBaseBar(bool vertical, IUnknown **theBaseBar)
1112 {
1113 CComPtr<IUnknown> newBaseBar;
1114 CComPtr<IDeskBar> deskBar;
1115 CComPtr<IUnknown> newBaseBarSite;
1116 CComPtr<IObjectWithSite> objectWithSite;
1117 CComPtr<IDeskBarClient> deskBarClient;
1118 IUnknown **cache;
1119 HRESULT hResult;
1120
1121 if (vertical)
1122 cache = &fClientBars[BIVerticalBaseBar].clientBar.p;
1123 else
1124 cache = &fClientBars[BIHorizontalBaseBar].clientBar.p;
1125 if (*cache == NULL)
1126 {
1127 hResult = CreateBaseBar(IID_PPV_ARG(IUnknown, &newBaseBar));
1128 if (FAILED_UNEXPECTEDLY(hResult))
1129 return hResult;
1130 hResult = CreateBaseBarSite(IID_PPV_ARG(IUnknown, &newBaseBarSite));
1131 if (FAILED_UNEXPECTEDLY(hResult))
1132 return hResult;
1133
1134 // tell the new base bar about the shell browser
1135 hResult = newBaseBar->QueryInterface(IID_PPV_ARG(IObjectWithSite, &objectWithSite));
1136 if (FAILED_UNEXPECTEDLY(hResult))
1137 return hResult;
1138 hResult = objectWithSite->SetSite(static_cast<IDropTarget *>(this));
1139 if (FAILED_UNEXPECTEDLY(hResult))
1140 return hResult;
1141
1142 // tell the new base bar about the new base bar site
1143 hResult = newBaseBar->QueryInterface(IID_PPV_ARG(IDeskBar, &deskBar));
1144 if (FAILED_UNEXPECTEDLY(hResult))
1145 return hResult;
1146 hResult = deskBar->SetClient(newBaseBarSite);
1147 if (FAILED_UNEXPECTEDLY(hResult))
1148 return hResult;
1149
1150 // tell the new base bar site about the new base bar
1151 hResult = newBaseBarSite->QueryInterface(IID_PPV_ARG(IDeskBarClient, &deskBarClient));
1152 if (FAILED_UNEXPECTEDLY(hResult))
1153 return hResult;
1154 hResult = deskBarClient->SetDeskBarSite(newBaseBar);
1155 if (FAILED_UNEXPECTEDLY(hResult))
1156 return hResult;
1157
1158 *cache = newBaseBar.Detach();
1159 }
1160 return (*cache)->QueryInterface(IID_PPV_ARG(IUnknown, theBaseBar));
1161 }
1162
1163 HRESULT CShellBrowser::ShowBand(const CLSID &classID, bool vertical)
1164 {
1165 CComPtr<IDockingWindow> dockingWindow;
1166 CComPtr<IOleCommandTarget> oleCommandTarget;
1167 CComPtr<IUnknown> baseBarSite;
1168 CComPtr<IUnknown> newBand;
1169 CComPtr<IUnknown> theBaseBar;
1170 CComPtr<IDeskBar> deskBar;
1171 VARIANT vaIn;
1172 HRESULT hResult;
1173
1174 __debugbreak();
1175
1176 hResult = GetBaseBar(vertical, (IUnknown **)&theBaseBar);
1177 if (FAILED_UNEXPECTEDLY(hResult))
1178 return hResult;
1179 hResult = CoCreateInstance(classID, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IUnknown, &newBand));
1180 if (FAILED_UNEXPECTEDLY(hResult))
1181 return hResult;
1182 hResult = theBaseBar->QueryInterface(IID_PPV_ARG(IDeskBar, &deskBar));
1183 if (FAILED_UNEXPECTEDLY(hResult))
1184 return hResult;
1185 hResult = deskBar->GetClient(&baseBarSite);
1186 if (FAILED_UNEXPECTEDLY(hResult))
1187 return hResult;
1188 hResult = theBaseBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
1189 if (FAILED_UNEXPECTEDLY(hResult))
1190 return hResult;
1191 hResult = baseBarSite->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &oleCommandTarget));
1192 if (FAILED_UNEXPECTEDLY(hResult))
1193 return hResult;
1194 V_VT(&vaIn) = VT_UNKNOWN;
1195 V_UNKNOWN(&vaIn) = newBand.p;
1196 hResult = oleCommandTarget->Exec(&CGID_IDeskBand, 1, 1, &vaIn, NULL);
1197 if (FAILED_UNEXPECTEDLY(hResult))
1198 return hResult;
1199 hResult = dockingWindow->ShowDW(TRUE);
1200 if (FAILED_UNEXPECTEDLY(hResult))
1201 return hResult;
1202 return S_OK;
1203 }
1204
1205 HRESULT CShellBrowser::NavigateToParent()
1206 {
1207 LPITEMIDLIST newDirectory;
1208 HRESULT hResult;
1209
1210 newDirectory = ILClone(fCurrentDirectoryPIDL);
1211 if (newDirectory == NULL)
1212 return E_OUTOFMEMORY;
1213 ILRemoveLastID(newDirectory);
1214 hResult = BrowseToPIDL(newDirectory, BTP_UPDATE_CUR_HISTORY | BTP_UPDATE_NEXT_HISTORY);
1215 ILFree(newDirectory);
1216 if (FAILED_UNEXPECTEDLY(hResult))
1217 return hResult;
1218 return S_OK;
1219 }
1220
1221 BOOL CALLBACK AddFolderOptionsPage(HPROPSHEETPAGE thePage, LPARAM lParam)
1222 {
1223 PROPSHEETHEADER *sheetInfo;
1224
1225 sheetInfo = (PROPSHEETHEADER *)lParam;
1226 if (sheetInfo->nPages >= folderOptionsPageCountMax)
1227 return FALSE;
1228 sheetInfo->phpage[sheetInfo->nPages] = thePage;
1229 sheetInfo->nPages++;
1230 return TRUE;
1231 }
1232
1233 HRESULT CShellBrowser::DoFolderOptions()
1234 {
1235 CComPtr<IShellPropSheetExt> folderOptionsSheet;
1236 CComPtr<IObjectWithSite> objectWithSite;
1237 PROPSHEETHEADER m_PropSheet;
1238 HPROPSHEETPAGE m_psp[folderOptionsPageCountMax];
1239 // CComPtr<IGlobalFolderSettings> globalSettings;
1240 // SHELLSTATE2 shellState;
1241 HRESULT hResult;
1242
1243 memset(m_psp, 0, sizeof(m_psp));
1244 memset(&m_PropSheet, 0, sizeof(m_PropSheet));
1245
1246 // create sheet object
1247 hResult = CoCreateInstance(CLSID_ShellFldSetExt, NULL, CLSCTX_INPROC_SERVER,
1248 IID_PPV_ARG(IShellPropSheetExt, &folderOptionsSheet));
1249 if (FAILED_UNEXPECTEDLY(hResult))
1250 return E_FAIL;
1251
1252 // must set site in order for Apply to all Folders on Advanced page to be enabled
1253 hResult = folderOptionsSheet->QueryInterface(IID_PPV_ARG(IObjectWithSite, &objectWithSite));
1254 if (SUCCEEDED(hResult) && objectWithSite.p != NULL)
1255 hResult = objectWithSite->SetSite(static_cast<IDispatch *>(this));
1256 m_PropSheet.phpage = m_psp;
1257
1258 #if 0
1259 hResult = CoCreateInstance(CLSID_GlobalFolderSettings, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IGlobalFolderSettings, &globalSettings));
1260 if (FAILED_UNEXPECTEDLY(hResult))
1261 return E_FAIL;
1262 hResult = globalSettings->Get(&shellState, sizeof(shellState));
1263 if (FAILED_UNEXPECTEDLY(hResult))
1264 return E_FAIL;
1265 #endif
1266
1267 // add pages
1268 hResult = folderOptionsSheet->AddPages(AddFolderOptionsPage, reinterpret_cast<LPARAM>(&m_PropSheet));
1269 if (FAILED_UNEXPECTEDLY(hResult))
1270 return E_FAIL;
1271
1272 if (fCurrentShellView != NULL)
1273 {
1274 hResult = fCurrentShellView->AddPropertySheetPages(
1275 0, AddFolderOptionsPage, reinterpret_cast<LPARAM>(&m_PropSheet));
1276 if (FAILED_UNEXPECTEDLY(hResult))
1277 return E_FAIL;
1278 }
1279
1280 // show sheet
1281 m_PropSheet.dwSize = sizeof(PROPSHEETHEADER);
1282 m_PropSheet.dwFlags = 0;
1283 m_PropSheet.hwndParent = m_hWnd;
1284 m_PropSheet.hInstance = _AtlBaseModule.GetResourceInstance();
1285 m_PropSheet.pszCaption = _T("Folder Options");
1286 m_PropSheet.nStartPage = 0;
1287 PropertySheet(&m_PropSheet);
1288 return S_OK;
1289 }
1290
1291 LRESULT CALLBACK CShellBrowser::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1292 {
1293 CShellBrowser *pThis = reinterpret_cast<CShellBrowser *>(hWnd);
1294 _ATL_MSG msg(pThis->m_hWnd, uMsg, wParam, lParam);
1295 LRESULT lResult;
1296 const _ATL_MSG *previousMessage;
1297 BOOL handled;
1298 WNDPROC saveWindowProc;
1299 HRESULT hResult;
1300
1301 hWnd = pThis->m_hWnd;
1302 previousMessage = pThis->m_pCurrentMsg;
1303 pThis->m_pCurrentMsg = &msg;
1304
1305 CComPtr<IMenuBand> menuBand;
1306 hResult = pThis->GetMenuBand(IID_PPV_ARG(IMenuBand, &menuBand));
1307 if (SUCCEEDED(hResult) && menuBand.p != NULL)
1308 {
1309 hResult = menuBand->TranslateMenuMessage(&msg, &lResult);
1310 if (hResult == S_OK)
1311 return lResult;
1312 uMsg = msg.message;
1313 wParam = msg.wParam;
1314 lParam = msg.lParam;
1315 }
1316 menuBand.Release();
1317
1318 handled = pThis->ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lResult, 0);
1319 ATLASSERT(pThis->m_pCurrentMsg == &msg);
1320 if (handled == FALSE)
1321 {
1322 if (uMsg == WM_NCDESTROY)
1323 {
1324 saveWindowProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hWnd, GWL_WNDPROC));
1325 lResult = pThis->DefWindowProc(uMsg, wParam, lParam);
1326 if (saveWindowProc == reinterpret_cast<WNDPROC>(GetWindowLongPtr(hWnd, GWL_WNDPROC)))
1327 SetWindowLongPtr(hWnd, GWL_WNDPROC, (LONG_PTR)pThis->m_pfnSuperWindowProc);
1328 pThis->m_dwState |= WINSTATE_DESTROYED;
1329 }
1330 else
1331 lResult = pThis->DefWindowProc(uMsg, wParam, lParam);
1332 }
1333 pThis->m_pCurrentMsg = previousMessage;
1334 if (previousMessage == NULL && (pThis->m_dwState & WINSTATE_DESTROYED) != 0)
1335 {
1336 pThis->m_dwState &= ~WINSTATE_DESTROYED;
1337 pThis->m_hWnd = NULL;
1338 pThis->OnFinalMessage(hWnd);
1339 }
1340 return lResult;
1341 }
1342
1343 void CShellBrowser::RepositionBars()
1344 {
1345 RECT clientRect;
1346 RECT statusRect;
1347 int x;
1348
1349 GetClientRect(&clientRect);
1350
1351 if (fStatusBarVisible && fStatusBar)
1352 {
1353 ::GetWindowRect(fStatusBar, &statusRect);
1354 ::SetWindowPos(fStatusBar, NULL, clientRect.left, clientRect.bottom - (statusRect.bottom - statusRect.top),
1355 clientRect.right - clientRect.left,
1356 statusRect.bottom - statusRect.top, SWP_NOOWNERZORDER | SWP_NOZORDER);
1357 clientRect.bottom -= statusRect.bottom - statusRect.top;
1358 }
1359
1360 for (x = 0; x < 3; x++)
1361 {
1362 HWND hwnd = fClientBars[x].hwnd;
1363 RECT borderSpace = fClientBars[x].borderSpace;
1364 if (hwnd == NULL && fClientBars[x].clientBar != NULL)
1365 {
1366 IUnknown_GetWindow(fClientBars[x].clientBar, &hwnd);
1367 fClientBars[x].hwnd = hwnd;
1368 }
1369 if (hwnd != NULL)
1370 {
1371 RECT toolbarRect = clientRect;
1372 if (borderSpace.top != 0)
1373 {
1374 toolbarRect.bottom = toolbarRect.top + borderSpace.top;
1375 }
1376 else if (borderSpace.bottom != 0)
1377 {
1378 toolbarRect.top = toolbarRect.bottom - borderSpace.bottom;
1379 }
1380 else if (borderSpace.left != 0)
1381 {
1382 toolbarRect.right = toolbarRect.left + borderSpace.left;
1383 }
1384 else if (borderSpace.right != 0)
1385 {
1386 toolbarRect.left = toolbarRect.right - borderSpace.right;
1387 }
1388
1389 ::SetWindowPos(hwnd, NULL,
1390 toolbarRect.left,
1391 toolbarRect.top,
1392 toolbarRect.right - toolbarRect.left,
1393 toolbarRect.bottom - toolbarRect.top,
1394 SWP_NOOWNERZORDER | SWP_NOZORDER);
1395
1396 if (borderSpace.top != 0)
1397 {
1398 clientRect.top = toolbarRect.bottom;
1399 }
1400 else if (borderSpace.bottom != 0)
1401 {
1402 clientRect.bottom = toolbarRect.top;
1403 }
1404 else if (borderSpace.left != 0)
1405 {
1406 clientRect.left = toolbarRect.right;
1407 }
1408 else if (borderSpace.right != 0)
1409 {
1410 clientRect.right = toolbarRect.left;
1411 }
1412 }
1413 }
1414 ::SetWindowPos(fCurrentShellViewWindow, NULL, clientRect.left, clientRect.top,
1415 clientRect.right - clientRect.left,
1416 clientRect.bottom - clientRect.top, SWP_NOOWNERZORDER | SWP_NOZORDER);
1417 }
1418
1419 HRESULT CShellBrowser::FireEvent(DISPID dispIdMember, int argCount, VARIANT *arguments)
1420 {
1421 DISPPARAMS params;
1422 CComDynamicUnkArray &vec = IConnectionPointImpl<CShellBrowser, &DIID_DWebBrowserEvents2>::m_vec;
1423 CComDynamicUnkArray &vec2 = IConnectionPointImpl<CShellBrowser, &DIID_DWebBrowserEvents>::m_vec;
1424 HRESULT hResult;
1425
1426 params.rgvarg = arguments;
1427 params.rgdispidNamedArgs = NULL;
1428 params.cArgs = argCount;
1429 params.cNamedArgs = 0;
1430 IUnknown** pp = vec.begin();
1431 while (pp < vec.end())
1432 {
1433 if (*pp != NULL)
1434 {
1435 CComPtr<IDispatch> theDispatch;
1436
1437 hResult = (*pp)->QueryInterface(IID_PPV_ARG(IDispatch, &theDispatch));
1438 hResult = theDispatch->Invoke(dispIdMember, GUID_NULL, 0, DISPATCH_METHOD, &params, NULL, NULL, NULL);
1439 }
1440 pp++;
1441 }
1442 pp = vec2.begin();
1443 while (pp < vec2.end())
1444 {
1445 if (*pp != NULL)
1446 {
1447 CComPtr<IDispatch> theDispatch;
1448
1449 hResult = (*pp)->QueryInterface(IID_PPV_ARG(IDispatch, &theDispatch));
1450 hResult = theDispatch->Invoke(dispIdMember, GUID_NULL, 0, DISPATCH_METHOD, &params, NULL, NULL, NULL);
1451 }
1452 pp++;
1453 }
1454 return S_OK;
1455 }
1456
1457 HRESULT CShellBrowser::FireNavigateComplete(const wchar_t *newDirectory)
1458 {
1459 // these two variants intentionally to do use CComVariant because it would double free/release
1460 // or does not need to dispose at all
1461 VARIANT varArg[2];
1462 VARIANT varArgs;
1463 CComBSTR tempString(newDirectory);
1464
1465 V_VT(&varArgs) = VT_BSTR;
1466 V_BSTR(&varArgs) = tempString.m_str;
1467
1468 V_VT(&varArg[0]) = VT_VARIANT | VT_BYREF;
1469 V_VARIANTREF(&varArg[0]) = &varArgs;
1470 V_VT(&varArg[1]) = VT_DISPATCH;
1471 V_DISPATCH(&varArg[1]) = (IDispatch *)this;
1472
1473 return FireEvent(DISPID_NAVIGATECOMPLETE2, 2, varArg);
1474 }
1475
1476 HRESULT CShellBrowser::FireCommandStateChange(bool newState, int commandID)
1477 {
1478 VARIANT varArg[2];
1479
1480 V_VT(&varArg[0]) = VT_BOOL;
1481 V_BOOL(&varArg[0]) = newState ? VARIANT_TRUE : VARIANT_FALSE;
1482 V_VT(&varArg[1]) = VT_I4;
1483 V_I4(&varArg[1]) = commandID;
1484
1485 return FireEvent(DISPID_COMMANDSTATECHANGE, 2, varArg);
1486 }
1487
1488 HRESULT CShellBrowser::FireCommandStateChangeAll()
1489 {
1490 return FireCommandStateChange(false, -1);
1491 }
1492
1493 HRESULT CShellBrowser::UpdateForwardBackState()
1494 {
1495 CComPtr<ITravelLog> travelLog;
1496 CComPtr<ITravelEntry> unusedEntry;
1497 bool canGoBack;
1498 bool canGoForward;
1499 HRESULT hResult;
1500
1501 canGoBack = false;
1502 canGoForward = false;
1503 hResult = GetTravelLog(&travelLog);
1504 if (FAILED_UNEXPECTEDLY(hResult))
1505 return hResult;
1506 hResult = travelLog->GetTravelEntry(static_cast<IDropTarget *>(this), TLOG_BACK, &unusedEntry);
1507 if (SUCCEEDED(hResult))
1508 {
1509 canGoBack = true;
1510 unusedEntry.Release();
1511 }
1512 hResult = travelLog->GetTravelEntry(static_cast<IDropTarget *>(this), TLOG_FORE, &unusedEntry);
1513 if (SUCCEEDED(hResult))
1514 {
1515 canGoForward = true;
1516 unusedEntry.Release();
1517 }
1518 hResult = FireCommandStateChange(canGoBack, 2);
1519 hResult = FireCommandStateChange(canGoForward, 1);
1520 return S_OK;
1521 }
1522
1523 void CShellBrowser::UpdateGotoMenu(HMENU theMenu)
1524 {
1525 CComPtr<ITravelLog> travelLog;
1526 int position;
1527 MENUITEMINFO menuItemInfo;
1528 HRESULT hResult;
1529
1530 DeleteMenuItems(theMenu, IDM_GOTO_TRAVEL_FIRST, IDM_GOTO_TRAVEL_LAST);
1531
1532 position = GetMenuItemCount(theMenu);
1533 hResult = GetTravelLog(&travelLog);
1534 if (FAILED_UNEXPECTEDLY(hResult))
1535 return;
1536 hResult = travelLog->InsertMenuEntries(static_cast<IDropTarget *>(this), theMenu, position,
1537 IDM_GOTO_TRAVEL_FIRSTTARGET, IDM_GOTO_TRAVEL_LASTTARGET, TLMENUF_BACKANDFORTH | TLMENUF_CHECKCURRENT);
1538 if (SUCCEEDED(hResult))
1539 {
1540 menuItemInfo.cbSize = sizeof(menuItemInfo);
1541 menuItemInfo.fMask = MIIM_TYPE | MIIM_ID;
1542 menuItemInfo.fType = MF_SEPARATOR;
1543 menuItemInfo.wID = IDM_GOTO_TRAVEL_SEP;
1544 InsertMenuItem(theMenu, position, TRUE, &menuItemInfo);
1545 }
1546 }
1547
1548 void CShellBrowser::UpdateViewMenu(HMENU theMenu)
1549 {
1550 CComPtr<IOleCommandTarget> oleCommandTarget;
1551 CComPtr<ITravelLog> travelLog;
1552 HMENU gotoMenu;
1553 OLECMD commandList[5];
1554 HMENU toolbarMenuBar;
1555 HMENU toolbarMenu;
1556 MENUITEMINFO menuItemInfo;
1557 HRESULT hResult;
1558
1559 gotoMenu = SHGetMenuFromID(theMenu, FCIDM_MENU_EXPLORE);
1560 if (gotoMenu != NULL)
1561 UpdateGotoMenu(gotoMenu);
1562
1563 commandList[0].cmdID = ITID_TOOLBARBANDSHOWN;
1564 commandList[1].cmdID = ITID_ADDRESSBANDSHOWN;
1565 commandList[2].cmdID = ITID_LINKSBANDSHOWN;
1566 commandList[3].cmdID = ITID_TOOLBARLOCKED;
1567 commandList[4].cmdID = ITID_CUSTOMIZEENABLED;
1568
1569 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
1570 IID_PPV_ARG(IOleCommandTarget, &oleCommandTarget));
1571 if (SUCCEEDED(hResult))
1572 hResult = oleCommandTarget->QueryStatus(&CGID_PrivCITCommands, 5, commandList, NULL);
1573 if (FAILED_UNEXPECTEDLY(hResult))
1574 DeleteMenu(theMenu, IDM_VIEW_TOOLBARS, MF_BYCOMMAND);
1575 else
1576 {
1577 menuItemInfo.cbSize = sizeof(menuItemInfo);
1578 menuItemInfo.fMask = MIIM_SUBMENU;
1579 GetMenuItemInfo(theMenu, IDM_VIEW_TOOLBARS, FALSE, &menuItemInfo);
1580 DestroyMenu(menuItemInfo.hSubMenu);
1581
1582 toolbarMenuBar = LoadMenu(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDM_CABINET_CONTEXTMENU));
1583 toolbarMenu = GetSubMenu(toolbarMenuBar, 0);
1584 RemoveMenu(toolbarMenuBar, 0, MF_BYPOSITION);
1585 DestroyMenu(toolbarMenuBar);
1586
1587 SHCheckMenuItem(toolbarMenu, IDM_TOOLBARS_STANDARDBUTTONS, commandList[0].cmdf);
1588 SHCheckMenuItem(toolbarMenu, IDM_TOOLBARS_ADDRESSBAR, commandList[1].cmdf & OLECMDF_ENABLED);
1589 SHCheckMenuItem(toolbarMenu, IDM_TOOLBARS_LINKSBAR, commandList[2].cmdf & OLECMDF_ENABLED);
1590 SHCheckMenuItem(toolbarMenu, IDM_TOOLBARS_LOCKTOOLBARS, commandList[3].cmdf & OLECMDF_ENABLED);
1591 if ((commandList[4].cmdf & OLECMDF_ENABLED) == 0)
1592 DeleteMenu(toolbarMenu, IDM_TOOLBARS_CUSTOMIZE, MF_BYCOMMAND);
1593 DeleteMenu(toolbarMenu, IDM_TOOLBARS_TEXTLABELS, MF_BYCOMMAND);
1594 DeleteMenu(toolbarMenu, IDM_TOOLBARS_GOBUTTON, MF_BYCOMMAND);
1595
1596 menuItemInfo.cbSize = sizeof(menuItemInfo);
1597 menuItemInfo.fMask = MIIM_SUBMENU;
1598 menuItemInfo.hSubMenu = toolbarMenu;
1599 SetMenuItemInfo(theMenu, IDM_VIEW_TOOLBARS, FALSE, &menuItemInfo);
1600 }
1601 SHCheckMenuItem(theMenu, IDM_VIEW_STATUSBAR, fStatusBarVisible ? TRUE : FALSE);
1602 }
1603
1604 bool IUnknownIsEqual(IUnknown *int1, IUnknown *int2)
1605 {
1606 CComPtr<IUnknown> int1Retry;
1607 CComPtr<IUnknown> int2Retry;
1608 HRESULT hResult;
1609
1610 if (int1 == int2)
1611 return true;
1612 if (int1 == NULL || int2 == NULL)
1613 return false;
1614 hResult = int1->QueryInterface(IID_PPV_ARG(IUnknown, &int1Retry));
1615 if (FAILED_UNEXPECTEDLY(hResult))
1616 return false;
1617 hResult = int2->QueryInterface(IID_PPV_ARG(IUnknown, &int2Retry));
1618 if (FAILED_UNEXPECTEDLY(hResult))
1619 return false;
1620 if (int1Retry == int2Retry)
1621 return true;
1622 return false;
1623 }
1624
1625 HRESULT STDMETHODCALLTYPE CShellBrowser::GetBorderDW(IUnknown *punkObj, LPRECT prcBorder)
1626 {
1627 static const INT excludeItems[] = { 1, 1, 1, 0xa001, 0, 0 };
1628
1629 RECT availableBounds;
1630
1631 GetEffectiveClientRect(m_hWnd, &availableBounds, excludeItems);
1632 for (INT x = 0; x < 3; x++)
1633 {
1634 if (fClientBars[x].clientBar.p != NULL && !IUnknownIsEqual(fClientBars[x].clientBar, punkObj))
1635 {
1636 availableBounds.top += fClientBars[x].borderSpace.top;
1637 availableBounds.left += fClientBars[x].borderSpace.left;
1638 availableBounds.bottom -= fClientBars[x].borderSpace.bottom;
1639 availableBounds.right -= fClientBars[x].borderSpace.right;
1640 }
1641 }
1642 *prcBorder = availableBounds;
1643 return S_OK;
1644 }
1645
1646 HRESULT STDMETHODCALLTYPE CShellBrowser::RequestBorderSpaceDW(IUnknown* punkObj, LPCBORDERWIDTHS pbw)
1647 {
1648 return S_OK;
1649 }
1650
1651 HRESULT STDMETHODCALLTYPE CShellBrowser::SetBorderSpaceDW(IUnknown* punkObj, LPCBORDERWIDTHS pbw)
1652 {
1653 for (INT x = 0; x < 3; x++)
1654 {
1655 if (IUnknownIsEqual(fClientBars[x].clientBar, punkObj))
1656 {
1657 fClientBars[x].borderSpace = *pbw;
1658 // if this bar changed size, it cascades and forces all subsequent bars to resize
1659 RepositionBars();
1660 return S_OK;
1661 }
1662 }
1663 return E_INVALIDARG;
1664 }
1665
1666 HRESULT STDMETHODCALLTYPE CShellBrowser::QueryStatus(const GUID *pguidCmdGroup,
1667 ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText)
1668 {
1669 CComPtr<IOleCommandTarget> commandTarget;
1670 HRESULT hResult;
1671
1672 if (prgCmds == NULL)
1673 return E_INVALIDARG;
1674 if (pguidCmdGroup == NULL)
1675 {
1676 if (fCurrentShellView.p != NULL)
1677 {
1678 hResult = fCurrentShellView->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &commandTarget));
1679 if (SUCCEEDED(hResult) && commandTarget.p != NULL)
1680 return commandTarget->QueryStatus(NULL, 1, prgCmds, pCmdText);
1681 }
1682 while (cCmds != 0)
1683 {
1684 prgCmds->cmdf = 0;
1685 prgCmds++;
1686 cCmds--;
1687 }
1688 }
1689 else if (IsEqualIID(*pguidCmdGroup, CGID_Explorer))
1690 {
1691 while (cCmds != 0)
1692 {
1693 switch (prgCmds->cmdID)
1694 {
1695 case 0x1c: // search
1696 prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
1697 break;
1698 case 0x1d: // history
1699 prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
1700 break;
1701 case 0x1e: // favorites
1702 prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
1703 break;
1704 case 0x23: // folders
1705 prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED | OLECMDF_LATCHED;
1706 break;
1707 default:
1708 prgCmds->cmdf = 0;
1709 break;
1710 }
1711 prgCmds++;
1712 cCmds--;
1713 }
1714 }
1715 else if (IsEqualIID(*pguidCmdGroup, CGID_ShellBrowser))
1716 {
1717 while (cCmds != 0)
1718 {
1719 switch (prgCmds->cmdID)
1720 {
1721 case 0xa022: // up level
1722 prgCmds->cmdf = OLECMDF_SUPPORTED;
1723 if (fCurrentDirectoryPIDL->mkid.cb != 0)
1724 prgCmds->cmdf |= OLECMDF_ENABLED;
1725 break;
1726 }
1727 prgCmds++;
1728 cCmds--;
1729 }
1730 }
1731 return S_OK;
1732 }
1733
1734 HRESULT STDMETHODCALLTYPE CShellBrowser::Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
1735 DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
1736 {
1737 HRESULT hResult;
1738
1739 if (IsEqualIID(*pguidCmdGroup, CGID_Explorer))
1740 {
1741 switch (nCmdID)
1742 {
1743 case 0x23:
1744 hResult = ShowBand(CLSID_ExplorerBand, true);
1745 return S_OK;
1746 case 0x27:
1747 if (nCmdexecopt == 1)
1748 {
1749 // pvaIn is a VT_UNKNOWN with a band that is being hidden
1750 }
1751 else
1752 {
1753 // update zones part of the status bar
1754 }
1755 return S_OK;
1756 case 0x35: // don't do this, and the internet toolbar doesn't create a menu band
1757 V_VT(pvaOut) = VT_INT_PTR;
1758 V_INTREF(pvaOut) = reinterpret_cast<INT *>(
1759 LoadMenu(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDM_CABINET_MAINMENU)));
1760 return S_OK;
1761 case 0x38:
1762 // indicate if this cabinet was opened as a browser
1763 return S_FALSE;
1764 default:
1765 return E_NOTIMPL;
1766 }
1767 }
1768 else if (IsEqualIID(*pguidCmdGroup, CGID_InternetButtons))
1769 {
1770 switch (nCmdID)
1771 {
1772 case 0x23:
1773 // placeholder
1774 return S_OK;
1775 }
1776 }
1777 else if (IsEqualIID(*pguidCmdGroup, CGID_Theater))
1778 {
1779 switch (nCmdID)
1780 {
1781 case 6:
1782 // what is theater mode and why do we receive this?
1783 return E_NOTIMPL;
1784 }
1785 }
1786 else if (IsEqualIID(*pguidCmdGroup, CGID_MenuBand))
1787 {
1788 switch (nCmdID)
1789 {
1790 case 14:
1791 // initialize favorites menu
1792 return S_OK;
1793 }
1794 }
1795 else if (IsEqualIID(*pguidCmdGroup, CGID_ShellDocView))
1796 {
1797 switch (nCmdID)
1798 {
1799 case 0x12:
1800 // refresh on toolbar clicked
1801 return S_OK;
1802 case 0x4d:
1803 // tell the view if it should hide the task pane or not
1804 return (fClientBars[BIVerticalBaseBar].clientBar.p == NULL) ? S_FALSE : S_OK;
1805 }
1806 }
1807 else if (IsEqualIID(*pguidCmdGroup, CGID_ShellBrowser))
1808 {
1809 switch (nCmdID)
1810 {
1811 case 40994:
1812 return NavigateToParent();
1813 }
1814 }
1815 else if (IsEqualIID(*pguidCmdGroup, CGID_IExplorerToolbar))
1816 {
1817 switch (nCmdID)
1818 {
1819 case 0x7063:
1820 return DoFolderOptions();
1821 }
1822 }
1823 else if (IsEqualIID(*pguidCmdGroup, CGID_DefView))
1824 {
1825 switch (nCmdID)
1826 {
1827 case 1:
1828 // Reset All Folders option in Folder Options
1829 break;
1830 }
1831 }
1832 else
1833 {
1834 return E_NOTIMPL;
1835 }
1836 return E_NOTIMPL;
1837 }
1838
1839 HRESULT STDMETHODCALLTYPE CShellBrowser::GetWindow(HWND *lphwnd)
1840 {
1841 if (lphwnd == NULL)
1842 return E_POINTER;
1843 *lphwnd = m_hWnd;
1844 return S_OK;
1845 }
1846
1847 HRESULT STDMETHODCALLTYPE CShellBrowser::ContextSensitiveHelp(BOOL fEnterMode)
1848 {
1849 return E_NOTIMPL;
1850 }
1851
1852 HRESULT STDMETHODCALLTYPE CShellBrowser::InsertMenusSB(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
1853 {
1854 HMENU mainMenu = LoadMenu(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDM_CABINET_MAINMENU));
1855
1856 //DbgPrint("Menu from shell32:\n");
1857 //DbgDumpMenu(hmenuShared);
1858
1859 //DbgPrint("Menu from browseui:\n");
1860 //DbgDumpMenu(mainMenu);
1861
1862 Shell_MergeMenus(hmenuShared, mainMenu, 0, 0, FCIDM_BROWSERLAST, MM_SUBMENUSHAVEIDS);
1863
1864 //DbgPrint("Merged menu:\n");
1865 //DbgDumpMenu(hmenuShared);
1866
1867 int GCCU(itemCount3) = GetMenuItemCount(hmenuShared);
1868 Unused(itemCount3);
1869
1870 DestroyMenu(mainMenu);
1871
1872 lpMenuWidths->width[0] = 2;
1873 lpMenuWidths->width[2] = 3;
1874 lpMenuWidths->width[4] = 1;
1875 return S_OK;
1876 }
1877
1878 HRESULT STDMETHODCALLTYPE CShellBrowser::SetMenuSB(HMENU hmenuShared, HOLEMENU holemenuRes, HWND hwndActiveObject)
1879 {
1880 CComPtr<IShellMenu> shellMenu;
1881 HRESULT hResult;
1882
1883 //DbgPrint("SetMenuSB:\n");
1884 //DbgDumpMenu(hmenuShared);
1885
1886 if (hmenuShared && IsMenu(hmenuShared) == FALSE)
1887 return E_FAIL;
1888 hResult = GetMenuBand(IID_PPV_ARG(IShellMenu, &shellMenu));
1889 if (FAILED_UNEXPECTEDLY(hResult))
1890 return hResult;
1891 hResult = shellMenu->SetMenu(hmenuShared, NULL, SMSET_DONTOWN);
1892 if (FAILED_UNEXPECTEDLY(hResult))
1893 return hResult;
1894 fCurrentMenuBar = hmenuShared;
1895 return S_OK;
1896 }
1897
1898 HRESULT STDMETHODCALLTYPE CShellBrowser::RemoveMenusSB(HMENU hmenuShared)
1899 {
1900 if (hmenuShared == fCurrentMenuBar)
1901 {
1902 //DestroyMenu(fCurrentMenuBar);
1903 SetMenuSB(NULL, NULL, NULL);
1904 }
1905 return S_OK;
1906 }
1907
1908 HRESULT STDMETHODCALLTYPE CShellBrowser::SetStatusTextSB(LPCOLESTR pszStatusText)
1909 {
1910 //
1911 if (pszStatusText)
1912 {
1913 ::SetWindowText(fStatusBar, pszStatusText);
1914 }
1915 else
1916 {
1917
1918 }
1919 return E_NOTIMPL;
1920 }
1921
1922 HRESULT STDMETHODCALLTYPE CShellBrowser::EnableModelessSB(BOOL fEnable)
1923 {
1924 return E_NOTIMPL;
1925 }
1926
1927 HRESULT STDMETHODCALLTYPE CShellBrowser::TranslateAcceleratorSB(MSG *pmsg, WORD wID)
1928 {
1929 if (!::TranslateAcceleratorW(m_hWnd, m_hAccel, pmsg))
1930 return S_FALSE;
1931 return S_OK;
1932 }
1933
1934 HRESULT STDMETHODCALLTYPE CShellBrowser::BrowseObject(LPCITEMIDLIST pidl, UINT wFlags)
1935 {
1936 return BrowseToPIDL(pidl, BTP_UPDATE_CUR_HISTORY | BTP_UPDATE_NEXT_HISTORY);
1937 }
1938
1939 HRESULT STDMETHODCALLTYPE CShellBrowser::GetViewStateStream(DWORD grfMode, IStream **ppStrm)
1940 {
1941 return E_NOTIMPL;
1942 }
1943
1944 HRESULT STDMETHODCALLTYPE CShellBrowser::GetControlWindow(UINT id, HWND *lphwnd)
1945 {
1946 if (lphwnd == NULL)
1947 return E_POINTER;
1948 *lphwnd = NULL;
1949 switch(id)
1950 {
1951 case FCW_TOOLBAR:
1952 *lphwnd = fToolbarProxy.m_hWnd;
1953 return S_OK;
1954 case FCW_STATUS:
1955 *lphwnd = fStatusBar;
1956 return S_OK;
1957 case FCW_TREE:
1958 // find the directory browser and return it
1959 // this should be used only to determine if a tree is present
1960 return S_OK;
1961 case FCW_PROGRESS:
1962 // is this a progress dialog?
1963 return S_OK;
1964 }
1965 return S_OK;
1966 }
1967
1968 HRESULT STDMETHODCALLTYPE CShellBrowser::SendControlMsg(
1969 UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret)
1970 {
1971 LPARAM result;
1972
1973 if (pret != NULL)
1974 *pret = 0;
1975 switch(id)
1976 {
1977 case FCW_TOOLBAR:
1978 result = fToolbarProxy.SendMessage(uMsg, wParam, lParam);
1979 if (pret != NULL)
1980 *pret = result;
1981 break;
1982 case FCW_STATUS:
1983 result = SendMessage(fStatusBar, uMsg, wParam, lParam);
1984 if (pret != NULL)
1985 *pret = result;
1986 break;
1987 }
1988 return S_OK;
1989 }
1990
1991 HRESULT STDMETHODCALLTYPE CShellBrowser::QueryActiveShellView(IShellView **ppshv)
1992 {
1993 if (ppshv == NULL)
1994 return E_POINTER;
1995 *ppshv = fCurrentShellView;
1996 if (fCurrentShellView.p != NULL)
1997 fCurrentShellView.p->AddRef();
1998 return S_OK;
1999 }
2000
2001 HRESULT STDMETHODCALLTYPE CShellBrowser::OnViewWindowActive(IShellView *ppshv)
2002 {
2003 return E_NOTIMPL;
2004 }
2005
2006 HRESULT STDMETHODCALLTYPE CShellBrowser::SetToolbarItems(LPTBBUTTON lpButtons, UINT nButtons, UINT uFlags)
2007 {
2008 return E_NOTIMPL;
2009 }
2010
2011 HRESULT STDMETHODCALLTYPE CShellBrowser::DragEnter(
2012 IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
2013 {
2014 return E_NOTIMPL;
2015 }
2016
2017 HRESULT STDMETHODCALLTYPE CShellBrowser::DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
2018 {
2019 return E_NOTIMPL;
2020 }
2021
2022 HRESULT STDMETHODCALLTYPE CShellBrowser::DragLeave()
2023 {
2024 return E_NOTIMPL;
2025 }
2026
2027 HRESULT STDMETHODCALLTYPE CShellBrowser::Drop(
2028 IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
2029 {
2030 return E_NOTIMPL;
2031 }
2032
2033 HRESULT STDMETHODCALLTYPE CShellBrowser::QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
2034 {
2035 // view does a query for SID_STopLevelBrowser, IID_IShellBrowserService
2036 // the returned interface has a method GetPropertyBag on it
2037 if (IsEqualIID(guidService, SID_STopLevelBrowser))
2038 return this->QueryInterface(riid, ppvObject);
2039 if (IsEqualIID(guidService, SID_SShellBrowser))
2040 return this->QueryInterface(riid, ppvObject);
2041 if (IsEqualIID(guidService, SID_ITargetFrame2))
2042 return this->QueryInterface(riid, ppvObject);
2043 if (IsEqualIID(guidService, SID_IWebBrowserApp)) // without this, the internet toolbar won't reflect notifications
2044 return this->QueryInterface(riid, ppvObject);
2045 if (IsEqualIID(guidService, SID_SProxyBrowser))
2046 return this->QueryInterface(riid, ppvObject);
2047 if (IsEqualIID(guidService, SID_IExplorerToolbar))
2048 return fClientBars[BIInternetToolbar].clientBar->QueryInterface(riid, ppvObject);
2049 if (IsEqualIID(riid, IID_IShellBrowser))
2050 return this->QueryInterface(riid, ppvObject);
2051 return E_NOINTERFACE;
2052 }
2053
2054 HRESULT STDMETHODCALLTYPE CShellBrowser::GetPropertyBag(long flags, REFIID riid, void **ppvObject)
2055 {
2056 if (ppvObject == NULL)
2057 return E_POINTER;
2058 *ppvObject = NULL;
2059 return E_NOTIMPL;
2060 }
2061
2062 HRESULT STDMETHODCALLTYPE CShellBrowser::GetTypeInfoCount(UINT *pctinfo)
2063 {
2064 return E_NOTIMPL;
2065 }
2066
2067 HRESULT STDMETHODCALLTYPE CShellBrowser::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
2068 {
2069 return E_NOTIMPL;
2070 }
2071
2072 HRESULT STDMETHODCALLTYPE CShellBrowser::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames,
2073 UINT cNames, LCID lcid, DISPID *rgDispId)
2074 {
2075 return E_NOTIMPL;
2076 }
2077
2078 HRESULT STDMETHODCALLTYPE CShellBrowser::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
2079 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2080 {
2081 return E_NOTIMPL;
2082 }
2083
2084 HRESULT STDMETHODCALLTYPE CShellBrowser::GetParentSite(IOleInPlaceSite **ppipsite)
2085 {
2086 return E_NOTIMPL;
2087 }
2088
2089 HRESULT STDMETHODCALLTYPE CShellBrowser::SetTitle(IShellView *psv, LPCWSTR pszName)
2090 {
2091 return E_NOTIMPL;
2092 }
2093
2094 HRESULT STDMETHODCALLTYPE CShellBrowser::GetTitle(IShellView *psv, LPWSTR pszName, DWORD cchName)
2095 {
2096 return E_NOTIMPL;
2097 }
2098
2099 HRESULT STDMETHODCALLTYPE CShellBrowser::GetOleObject(IOleObject **ppobjv)
2100 {
2101 return E_NOTIMPL;
2102 }
2103
2104 HRESULT STDMETHODCALLTYPE CShellBrowser::GetTravelLog(ITravelLog **pptl)
2105 {
2106 HRESULT hResult;
2107
2108 // called by toolbar when displaying tooltips
2109 if (pptl == NULL)
2110 return E_FAIL;
2111
2112 *pptl = NULL;
2113 if (fTravelLog.p == NULL)
2114 {
2115 hResult = CreateTravelLog(IID_PPV_ARG(ITravelLog, &fTravelLog));
2116 if (FAILED_UNEXPECTEDLY(hResult))
2117 return hResult;
2118 }
2119 *pptl = fTravelLog.p;
2120 fTravelLog.p->AddRef();
2121 return S_OK;
2122 }
2123
2124 HRESULT STDMETHODCALLTYPE CShellBrowser::ShowControlWindow(UINT id, BOOL fShow)
2125 {
2126 return E_NOTIMPL;
2127 }
2128
2129 HRESULT STDMETHODCALLTYPE CShellBrowser::IsControlWindowShown(UINT id, BOOL *pfShown)
2130 {
2131 return E_NOTIMPL;
2132 }
2133
2134 HRESULT STDMETHODCALLTYPE CShellBrowser::IEGetDisplayName(LPCITEMIDLIST pidl, LPWSTR pwszName, UINT uFlags)
2135 {
2136 return E_NOTIMPL;
2137 }
2138
2139 HRESULT STDMETHODCALLTYPE CShellBrowser::IEParseDisplayName(UINT uiCP, LPCWSTR pwszPath, LPITEMIDLIST *ppidlOut)
2140 {
2141 return E_NOTIMPL;
2142 }
2143
2144 HRESULT STDMETHODCALLTYPE CShellBrowser::DisplayParseError(HRESULT hres, LPCWSTR pwszPath)
2145 {
2146 return E_NOTIMPL;
2147 }
2148
2149 HRESULT STDMETHODCALLTYPE CShellBrowser::NavigateToPidl(LPCITEMIDLIST pidl, DWORD grfHLNF)
2150 {
2151 return E_NOTIMPL;
2152 }
2153
2154 HRESULT STDMETHODCALLTYPE CShellBrowser::SetNavigateState(BNSTATE bnstate)
2155 {
2156 return E_NOTIMPL;
2157 }
2158
2159 HRESULT STDMETHODCALLTYPE CShellBrowser::GetNavigateState(BNSTATE *pbnstate)
2160 {
2161 return E_NOTIMPL;
2162 }
2163
2164 HRESULT STDMETHODCALLTYPE CShellBrowser::NotifyRedirect(IShellView *psv, LPCITEMIDLIST pidl, BOOL *pfDidBrowse)
2165 {
2166 return E_NOTIMPL;
2167 }
2168
2169 HRESULT STDMETHODCALLTYPE CShellBrowser::UpdateWindowList()
2170 {
2171 return E_NOTIMPL;
2172 }
2173
2174 HRESULT STDMETHODCALLTYPE CShellBrowser::UpdateBackForwardState()
2175 {
2176 return E_NOTIMPL;
2177 }
2178
2179 HRESULT STDMETHODCALLTYPE CShellBrowser::SetFlags(DWORD dwFlags, DWORD dwFlagMask)
2180 {
2181 return E_NOTIMPL;
2182 }
2183
2184 HRESULT STDMETHODCALLTYPE CShellBrowser::GetFlags(DWORD *pdwFlags)
2185 {
2186 return E_NOTIMPL;
2187 }
2188
2189 HRESULT STDMETHODCALLTYPE CShellBrowser::CanNavigateNow()
2190 {
2191 return E_NOTIMPL;
2192 }
2193
2194 HRESULT STDMETHODCALLTYPE CShellBrowser::GetPidl(LPITEMIDLIST *ppidl)
2195 {
2196 // called by explorer bar to get current pidl
2197 if (ppidl == NULL)
2198 return E_POINTER;
2199 *ppidl = ILClone(fCurrentDirectoryPIDL);
2200 return S_OK;
2201 }
2202
2203 HRESULT STDMETHODCALLTYPE CShellBrowser::SetReferrer(LPCITEMIDLIST pidl)
2204 {
2205 return E_NOTIMPL;
2206 }
2207
2208 DWORD STDMETHODCALLTYPE CShellBrowser::GetBrowserIndex()
2209 {
2210 return -1;
2211 }
2212
2213 HRESULT STDMETHODCALLTYPE CShellBrowser::GetBrowserByIndex(DWORD dwID, IUnknown **ppunk)
2214 {
2215 return E_NOTIMPL;
2216 }
2217
2218 HRESULT STDMETHODCALLTYPE CShellBrowser::GetHistoryObject(IOleObject **ppole, IStream **pstm, IBindCtx **ppbc)
2219 {
2220 if (ppole == NULL || pstm == NULL || ppbc == NULL)
2221 return E_INVALIDARG;
2222 *ppole = fHistoryObject;
2223 if (fHistoryObject != NULL)
2224 fHistoryObject->AddRef();
2225 *pstm = fHistoryStream;
2226 if (fHistoryStream != NULL)
2227 fHistoryStream->AddRef();
2228 *ppbc = fHistoryBindContext;
2229 if (fHistoryBindContext != NULL)
2230 fHistoryBindContext->AddRef();
2231 fHistoryObject = NULL;
2232 fHistoryStream = NULL;
2233 fHistoryBindContext = NULL;
2234 if (*ppole == NULL)
2235 return E_FAIL;
2236 return S_OK;
2237 }
2238
2239 HRESULT STDMETHODCALLTYPE CShellBrowser::SetHistoryObject(IOleObject *pole, BOOL fIsLocalAnchor)
2240 {
2241 return E_NOTIMPL;
2242 }
2243
2244 HRESULT STDMETHODCALLTYPE CShellBrowser::CacheOLEServer(IOleObject *pole)
2245 {
2246 return E_NOTIMPL;
2247 }
2248
2249 HRESULT STDMETHODCALLTYPE CShellBrowser::GetSetCodePage(VARIANT *pvarIn, VARIANT *pvarOut)
2250 {
2251 return E_NOTIMPL;
2252 }
2253
2254 HRESULT STDMETHODCALLTYPE CShellBrowser::OnHttpEquiv(
2255 IShellView *psv, BOOL fDone, VARIANT *pvarargIn, VARIANT *pvarargOut)
2256 {
2257 return E_NOTIMPL;
2258 }
2259
2260 HRESULT STDMETHODCALLTYPE CShellBrowser::GetPalette(HPALETTE *hpal)
2261 {
2262 return E_NOTIMPL;
2263 }
2264
2265 HRESULT STDMETHODCALLTYPE CShellBrowser::RegisterWindow(BOOL fForceRegister, int swc)
2266 {
2267 return E_NOTIMPL;
2268 }
2269
2270 LRESULT STDMETHODCALLTYPE CShellBrowser::WndProcBS(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2271 {
2272 return E_NOTIMPL;
2273 }
2274
2275 HRESULT STDMETHODCALLTYPE CShellBrowser::SetAsDefFolderSettings()
2276 {
2277 return E_NOTIMPL;
2278 }
2279
2280 HRESULT STDMETHODCALLTYPE CShellBrowser::GetViewRect(RECT *prc)
2281 {
2282 return E_NOTIMPL;
2283 }
2284
2285 HRESULT STDMETHODCALLTYPE CShellBrowser::OnSize(WPARAM wParam)
2286 {
2287 return E_NOTIMPL;
2288 }
2289
2290 HRESULT STDMETHODCALLTYPE CShellBrowser::OnCreate(struct tagCREATESTRUCTW *pcs)
2291 {
2292 m_hAccel = LoadAcceleratorsW(GetModuleHandle(L"browseui.dll"), MAKEINTRESOURCEW(256));
2293 return S_OK;
2294 }
2295
2296 LRESULT STDMETHODCALLTYPE CShellBrowser::OnCommand(WPARAM wParam, LPARAM lParam)
2297 {
2298 return 0;
2299 }
2300
2301 HRESULT STDMETHODCALLTYPE CShellBrowser::OnDestroy()
2302 {
2303 return E_NOTIMPL;
2304 }
2305
2306 LRESULT STDMETHODCALLTYPE CShellBrowser::OnNotify(struct tagNMHDR *pnm)
2307 {
2308 return 0;
2309 }
2310
2311 HRESULT STDMETHODCALLTYPE CShellBrowser::OnSetFocus()
2312 {
2313 return E_NOTIMPL;
2314 }
2315
2316 HRESULT STDMETHODCALLTYPE CShellBrowser::OnFrameWindowActivateBS(BOOL fActive)
2317 {
2318 return E_NOTIMPL;
2319 }
2320
2321 HRESULT STDMETHODCALLTYPE CShellBrowser::ReleaseShellView()
2322 {
2323 return E_NOTIMPL;
2324 }
2325
2326 HRESULT STDMETHODCALLTYPE CShellBrowser::ActivatePendingView()
2327 {
2328 return E_NOTIMPL;
2329 }
2330
2331 HRESULT STDMETHODCALLTYPE CShellBrowser::CreateViewWindow(
2332 IShellView *psvNew, IShellView *psvOld, LPRECT prcView, HWND *phwnd)
2333 {
2334 return E_NOTIMPL;
2335 }
2336
2337 HRESULT STDMETHODCALLTYPE CShellBrowser::CreateBrowserPropSheetExt(REFIID riid, void **ppv)
2338 {
2339 return E_NOTIMPL;
2340 }
2341
2342 HRESULT STDMETHODCALLTYPE CShellBrowser::GetViewWindow(HWND *phwndView)
2343 {
2344 return E_NOTIMPL;
2345 }
2346
2347 HRESULT STDMETHODCALLTYPE CShellBrowser::GetBaseBrowserData(LPCBASEBROWSERDATA *pbbd)
2348 {
2349 return E_NOTIMPL;
2350 }
2351
2352 LPBASEBROWSERDATA STDMETHODCALLTYPE CShellBrowser::PutBaseBrowserData()
2353 {
2354 return NULL;
2355 }
2356
2357 HRESULT STDMETHODCALLTYPE CShellBrowser::InitializeTravelLog(ITravelLog *ptl, DWORD dw)
2358 {
2359 return E_NOTIMPL;
2360 }
2361
2362 HRESULT STDMETHODCALLTYPE CShellBrowser::SetTopBrowser()
2363 {
2364 return E_NOTIMPL;
2365 }
2366
2367 HRESULT STDMETHODCALLTYPE CShellBrowser::Offline(int iCmd)
2368 {
2369 return E_NOTIMPL;
2370 }
2371
2372 HRESULT STDMETHODCALLTYPE CShellBrowser::AllowViewResize(BOOL f)
2373 {
2374 return E_NOTIMPL;
2375 }
2376
2377 HRESULT STDMETHODCALLTYPE CShellBrowser::SetActivateState(UINT u)
2378 {
2379 return E_NOTIMPL;
2380 }
2381
2382 HRESULT STDMETHODCALLTYPE CShellBrowser::UpdateSecureLockIcon(int eSecureLock)
2383 {
2384 return E_NOTIMPL;
2385 }
2386
2387 HRESULT STDMETHODCALLTYPE CShellBrowser::InitializeDownloadManager()
2388 {
2389 return E_NOTIMPL;
2390 }
2391
2392 HRESULT STDMETHODCALLTYPE CShellBrowser::InitializeTransitionSite()
2393 {
2394 return E_NOTIMPL;
2395 }
2396
2397 HRESULT STDMETHODCALLTYPE CShellBrowser::_Initialize(HWND hwnd, IUnknown *pauto)
2398 {
2399 return E_NOTIMPL;
2400 }
2401
2402 HRESULT STDMETHODCALLTYPE CShellBrowser::_CancelPendingNavigationAsync()
2403 {
2404 return E_NOTIMPL;
2405 }
2406
2407 HRESULT STDMETHODCALLTYPE CShellBrowser::_CancelPendingView()
2408 {
2409 return E_NOTIMPL;
2410 }
2411
2412 HRESULT STDMETHODCALLTYPE CShellBrowser::_MaySaveChanges()
2413 {
2414 return E_NOTIMPL;
2415 }
2416
2417 HRESULT STDMETHODCALLTYPE CShellBrowser::_PauseOrResumeView(BOOL fPaused)
2418 {
2419 return E_NOTIMPL;
2420 }
2421
2422 HRESULT STDMETHODCALLTYPE CShellBrowser::_DisableModeless()
2423 {
2424 return E_NOTIMPL;
2425 }
2426
2427 HRESULT STDMETHODCALLTYPE CShellBrowser::_NavigateToPidl(LPCITEMIDLIST pidl, DWORD grfHLNF, DWORD dwFlags)
2428 {
2429 return E_NOTIMPL;
2430 }
2431
2432 HRESULT STDMETHODCALLTYPE CShellBrowser::_TryShell2Rename(IShellView *psv, LPCITEMIDLIST pidlNew)
2433 {
2434 return E_NOTIMPL;
2435 }
2436
2437 HRESULT STDMETHODCALLTYPE CShellBrowser::_SwitchActivationNow()
2438 {
2439 return E_NOTIMPL;
2440 }
2441
2442 HRESULT STDMETHODCALLTYPE CShellBrowser::_ExecChildren(IUnknown *punkBar, BOOL fBroadcast,
2443 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
2444 {
2445 return E_NOTIMPL;
2446 }
2447
2448 HRESULT STDMETHODCALLTYPE CShellBrowser::_SendChildren(
2449 HWND hwndBar, BOOL fBroadcast, UINT uMsg, WPARAM wParam, LPARAM lParam)
2450 {
2451 return E_NOTIMPL;
2452 }
2453
2454 HRESULT STDMETHODCALLTYPE CShellBrowser::GetFolderSetData(struct tagFolderSetData *pfsd)
2455 {
2456 return E_NOTIMPL;
2457 }
2458
2459 HRESULT STDMETHODCALLTYPE CShellBrowser::_OnFocusChange(UINT itb)
2460 {
2461 return E_NOTIMPL;
2462 }
2463
2464 HRESULT STDMETHODCALLTYPE CShellBrowser::v_ShowHideChildWindows(BOOL fChildOnly)
2465 {
2466 return E_NOTIMPL;
2467 }
2468
2469 UINT STDMETHODCALLTYPE CShellBrowser::_get_itbLastFocus()
2470 {
2471 return 0;
2472 }
2473
2474 HRESULT STDMETHODCALLTYPE CShellBrowser::_put_itbLastFocus(UINT itbLastFocus)
2475 {
2476 return E_NOTIMPL;
2477 }
2478
2479 HRESULT STDMETHODCALLTYPE CShellBrowser::_UIActivateView(UINT uState)
2480 {
2481 return E_NOTIMPL;
2482 }
2483
2484 HRESULT STDMETHODCALLTYPE CShellBrowser::_GetViewBorderRect(RECT *prc)
2485 {
2486 return E_NOTIMPL;
2487 }
2488
2489 HRESULT STDMETHODCALLTYPE CShellBrowser::_UpdateViewRectSize()
2490 {
2491 return E_NOTIMPL;
2492 }
2493
2494 HRESULT STDMETHODCALLTYPE CShellBrowser::_ResizeNextBorder(UINT itb)
2495 {
2496 return E_NOTIMPL;
2497 }
2498
2499 HRESULT STDMETHODCALLTYPE CShellBrowser::_ResizeView()
2500 {
2501 return E_NOTIMPL;
2502 }
2503
2504 HRESULT STDMETHODCALLTYPE CShellBrowser::_GetEffectiveClientArea(LPRECT lprectBorder, HMONITOR hmon)
2505 {
2506 return E_NOTIMPL;
2507 }
2508
2509 IStream *STDMETHODCALLTYPE CShellBrowser::v_GetViewStream(LPCITEMIDLIST pidl, DWORD grfMode, LPCWSTR pwszName)
2510 {
2511 return NULL;
2512 }
2513
2514 LRESULT STDMETHODCALLTYPE CShellBrowser::ForwardViewMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
2515 {
2516 return 0;
2517 }
2518
2519 HRESULT STDMETHODCALLTYPE CShellBrowser::SetAcceleratorMenu(HACCEL hacc)
2520 {
2521 return E_NOTIMPL;
2522 }
2523
2524 int STDMETHODCALLTYPE CShellBrowser::_GetToolbarCount()
2525 {
2526 return 0;
2527 }
2528
2529 LPTOOLBARITEM STDMETHODCALLTYPE CShellBrowser::_GetToolbarItem(int itb)
2530 {
2531 return NULL;
2532 }
2533
2534 HRESULT STDMETHODCALLTYPE CShellBrowser::_SaveToolbars(IStream *pstm)
2535 {
2536 return E_NOTIMPL;
2537 }
2538
2539 HRESULT STDMETHODCALLTYPE CShellBrowser::_LoadToolbars(IStream *pstm)
2540 {
2541 return E_NOTIMPL;
2542 }
2543
2544 HRESULT STDMETHODCALLTYPE CShellBrowser::_CloseAndReleaseToolbars(BOOL fClose)
2545 {
2546 return E_NOTIMPL;
2547 }
2548
2549 HRESULT STDMETHODCALLTYPE CShellBrowser::v_MayGetNextToolbarFocus(
2550 LPMSG lpMsg, UINT itbNext, int citb, LPTOOLBARITEM *pptbi, HWND *phwnd)
2551 {
2552 return E_NOTIMPL;
2553 }
2554
2555 HRESULT STDMETHODCALLTYPE CShellBrowser::_ResizeNextBorderHelper(UINT itb, BOOL bUseHmonitor)
2556 {
2557 return E_NOTIMPL;
2558 }
2559
2560 UINT STDMETHODCALLTYPE CShellBrowser::_FindTBar(IUnknown *punkSrc)
2561 {
2562 return 0;
2563 }
2564
2565 HRESULT STDMETHODCALLTYPE CShellBrowser::_SetFocus(LPTOOLBARITEM ptbi, HWND hwnd, LPMSG lpMsg)
2566 {
2567 return E_NOTIMPL;
2568 }
2569
2570 extern HRESULT IUnknown_HasFocusIO(IUnknown * punk);
2571 extern HRESULT IUnknown_TranslateAcceleratorIO(IUnknown * punk, MSG * pmsg);
2572 HRESULT STDMETHODCALLTYPE CShellBrowser::v_MayTranslateAccelerator(MSG *pmsg)
2573 {
2574 for (int i = 0; i < 3; i++)
2575 {
2576 if (IUnknown_TranslateAcceleratorIO(fClientBars[i].clientBar, pmsg) == S_OK)
2577 return S_OK;
2578 }
2579
2580 if (fCurrentShellView->TranslateAcceleratorW(pmsg) != S_OK)
2581 {
2582 if (TranslateAcceleratorSB(pmsg, 0) != S_OK)
2583 return S_FALSE;
2584 return S_OK;
2585 }
2586 return S_OK;
2587 }
2588
2589 HRESULT STDMETHODCALLTYPE CShellBrowser::_GetBorderDWHelper(IUnknown *punkSrc, LPRECT lprectBorder, BOOL bUseHmonitor)
2590 {
2591 return E_NOTIMPL;
2592 }
2593
2594 HRESULT STDMETHODCALLTYPE CShellBrowser::v_CheckZoneCrossing(LPCITEMIDLIST pidl)
2595 {
2596 return E_NOTIMPL;
2597 }
2598
2599 HRESULT STDMETHODCALLTYPE CShellBrowser::GoBack()
2600 {
2601 CComPtr<ITravelLog> travelLog;
2602 HRESULT hResult;
2603
2604 hResult = GetTravelLog(&travelLog);
2605 if (FAILED_UNEXPECTEDLY(hResult))
2606 return hResult;
2607 return travelLog->Travel(static_cast<IDropTarget *>(this), TLOG_BACK);
2608 }
2609
2610 HRESULT STDMETHODCALLTYPE CShellBrowser::GoForward()
2611 {
2612 CComPtr<ITravelLog> travelLog;
2613 HRESULT hResult;
2614
2615 hResult = GetTravelLog(&travelLog);
2616 if (FAILED_UNEXPECTEDLY(hResult))
2617 return hResult;
2618 return travelLog->Travel(static_cast<IDropTarget *>(this), TLOG_FORE);
2619 }
2620
2621 HRESULT STDMETHODCALLTYPE CShellBrowser::GoHome()
2622 {
2623 return E_NOTIMPL;
2624 }
2625
2626 HRESULT STDMETHODCALLTYPE CShellBrowser::GoSearch()
2627 {
2628 return E_NOTIMPL;
2629 }
2630
2631 HRESULT STDMETHODCALLTYPE CShellBrowser::Navigate(BSTR URL, VARIANT *Flags,
2632 VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
2633 {
2634 return E_NOTIMPL;
2635 }
2636
2637 HRESULT STDMETHODCALLTYPE CShellBrowser::Refresh()
2638 {
2639 VARIANT level;
2640
2641 V_VT(&level) = VT_I4;
2642 V_I4(&level) = 4;
2643 return Refresh2(&level);
2644 }
2645
2646 HRESULT STDMETHODCALLTYPE CShellBrowser::Refresh2(VARIANT *Level)
2647 {
2648 CComPtr<IOleCommandTarget> oleCommandTarget;
2649 HRESULT hResult;
2650
2651 hResult = fCurrentShellView->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &oleCommandTarget));
2652 if (FAILED_UNEXPECTEDLY(hResult))
2653 return hResult;
2654 return oleCommandTarget->Exec(NULL, 22, 1, Level, NULL);
2655 }
2656
2657 HRESULT STDMETHODCALLTYPE CShellBrowser::Stop()
2658 {
2659 return E_NOTIMPL;
2660 }
2661
2662 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Application(IDispatch **ppDisp)
2663 {
2664 return E_NOTIMPL;
2665 }
2666
2667 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Parent(IDispatch **ppDisp)
2668 {
2669 return E_NOTIMPL;
2670 }
2671
2672 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Container(IDispatch **ppDisp)
2673 {
2674 return E_NOTIMPL;
2675 }
2676
2677 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Document(IDispatch **ppDisp)
2678 {
2679 return E_NOTIMPL;
2680 }
2681
2682 HRESULT STDMETHODCALLTYPE CShellBrowser::get_TopLevelContainer(VARIANT_BOOL *pBool)
2683 {
2684 return E_NOTIMPL;
2685 }
2686
2687 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Type(BSTR *Type)
2688 {
2689 return E_NOTIMPL;
2690 }
2691 #ifdef __exdisp_h__
2692 #define long LONG
2693 #endif
2694 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Left(long *pl)
2695 {
2696 return E_NOTIMPL;
2697 }
2698
2699 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Left(long Left)
2700 {
2701 return E_NOTIMPL;
2702 }
2703
2704 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Top(long *pl)
2705 {
2706 return E_NOTIMPL;
2707 }
2708
2709 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Top(long Top)
2710 {
2711 return E_NOTIMPL;
2712 }
2713
2714 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Width(long *pl)
2715 {
2716 return E_NOTIMPL;
2717 }
2718
2719 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Width(long Width)
2720 {
2721 return E_NOTIMPL;
2722 }
2723
2724 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Height(long *pl)
2725 {
2726 return E_NOTIMPL;
2727 }
2728
2729 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Height(long Height)
2730 {
2731 return E_NOTIMPL;
2732 }
2733 #ifdef __exdisp_h__
2734 #undef long
2735 #endif
2736 HRESULT STDMETHODCALLTYPE CShellBrowser::get_LocationName(BSTR *LocationName)
2737 {
2738 return E_NOTIMPL;
2739 }
2740
2741 HRESULT STDMETHODCALLTYPE CShellBrowser::get_LocationURL(BSTR *LocationURL)
2742 {
2743 return E_NOTIMPL;
2744 }
2745
2746 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Busy(VARIANT_BOOL *pBool)
2747 {
2748 return E_NOTIMPL;
2749 }
2750
2751 HRESULT STDMETHODCALLTYPE CShellBrowser::Quit()
2752 {
2753 return E_NOTIMPL;
2754 }
2755
2756 HRESULT STDMETHODCALLTYPE CShellBrowser::ClientToWindow(int *pcx, int *pcy)
2757 {
2758 return E_NOTIMPL;
2759 }
2760
2761 HRESULT STDMETHODCALLTYPE CShellBrowser::PutProperty(BSTR Property, VARIANT vtValue)
2762 {
2763 return E_NOTIMPL;
2764 }
2765
2766 HRESULT STDMETHODCALLTYPE CShellBrowser::GetProperty(BSTR Property, VARIANT *pvtValue)
2767 {
2768 return E_NOTIMPL;
2769 }
2770
2771 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Name(BSTR *Name)
2772 {
2773 return E_NOTIMPL;
2774 }
2775
2776 HRESULT STDMETHODCALLTYPE CShellBrowser::get_HWND(SHANDLE_PTR *pHWND)
2777 {
2778 return E_NOTIMPL;
2779 }
2780
2781 HRESULT STDMETHODCALLTYPE CShellBrowser::get_FullName(BSTR *FullName)
2782 {
2783 return E_NOTIMPL;
2784 }
2785
2786 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Path(BSTR *Path)
2787 {
2788 return E_NOTIMPL;
2789 }
2790
2791 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Visible(VARIANT_BOOL *pBool)
2792 {
2793 return E_NOTIMPL;
2794 }
2795
2796 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Visible(VARIANT_BOOL Value)
2797 {
2798 return E_NOTIMPL;
2799 }
2800
2801 HRESULT STDMETHODCALLTYPE CShellBrowser::get_StatusBar(VARIANT_BOOL *pBool)
2802 {
2803 return E_NOTIMPL;
2804 }
2805
2806 HRESULT STDMETHODCALLTYPE CShellBrowser::put_StatusBar(VARIANT_BOOL Value)
2807 {
2808 return E_NOTIMPL;
2809 }
2810
2811 HRESULT STDMETHODCALLTYPE CShellBrowser::get_StatusText(BSTR *StatusText)
2812 {
2813 return E_NOTIMPL;
2814 }
2815
2816 HRESULT STDMETHODCALLTYPE CShellBrowser::put_StatusText(BSTR StatusText)
2817 {
2818 return E_NOTIMPL;
2819 }
2820
2821 HRESULT STDMETHODCALLTYPE CShellBrowser::get_ToolBar(int *Value)
2822 {
2823 return E_NOTIMPL;
2824 }
2825
2826 HRESULT STDMETHODCALLTYPE CShellBrowser::put_ToolBar(int Value)
2827 {
2828 return E_NOTIMPL;
2829 }
2830
2831 HRESULT STDMETHODCALLTYPE CShellBrowser::get_MenuBar(VARIANT_BOOL *Value)
2832 {
2833 return E_NOTIMPL;
2834 }
2835
2836 HRESULT STDMETHODCALLTYPE CShellBrowser::put_MenuBar(VARIANT_BOOL Value)
2837 {
2838 return E_NOTIMPL;
2839 }
2840
2841 HRESULT STDMETHODCALLTYPE CShellBrowser::get_FullScreen(VARIANT_BOOL *pbFullScreen)
2842 {
2843 return E_NOTIMPL;
2844 }
2845
2846 HRESULT STDMETHODCALLTYPE CShellBrowser::put_FullScreen(VARIANT_BOOL bFullScreen)
2847 {
2848 return E_NOTIMPL;
2849 }
2850
2851 HRESULT STDMETHODCALLTYPE CShellBrowser::Navigate2(VARIANT *URL, VARIANT *Flags,
2852 VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
2853 {
2854 LPITEMIDLIST pidl;
2855 HRESULT hResult;
2856
2857 // called from drive combo box to navigate to a directory
2858 if (V_VT(URL) != (VT_ARRAY | VT_UI1))
2859 return E_INVALIDARG;
2860 if (V_ARRAY(URL)->cDims != 1 || V_ARRAY(URL)->cbElements != 1)
2861 return E_INVALIDARG;
2862 pidl = (LPITEMIDLIST)V_ARRAY(URL)->pvData;
2863 hResult = BrowseToPIDL((LPITEMIDLIST)pidl, BTP_UPDATE_CUR_HISTORY | BTP_UPDATE_NEXT_HISTORY);
2864 if (FAILED_UNEXPECTEDLY(hResult))
2865 return hResult;
2866 return S_OK;
2867 }
2868
2869 HRESULT STDMETHODCALLTYPE CShellBrowser::QueryStatusWB(OLECMDID cmdID, OLECMDF *pcmdf)
2870 {
2871 return E_NOTIMPL;
2872 }
2873
2874 HRESULT STDMETHODCALLTYPE CShellBrowser::ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt,
2875 VARIANT *pvaIn, VARIANT *pvaOut)
2876 {
2877 return E_NOTIMPL;
2878 }
2879
2880 HRESULT STDMETHODCALLTYPE CShellBrowser::ShowBrowserBar(VARIANT *pvaClsid, VARIANT *pvarShow, VARIANT *pvarSize)
2881 {
2882 CLSID classID;
2883 bool vertical;
2884
2885 // called to show search bar
2886 if (V_VT(pvaClsid) != VT_BSTR)
2887 return E_INVALIDARG;
2888 CLSIDFromString(V_BSTR(pvaClsid), &classID);
2889 // TODO: properly compute the value of vertical
2890 vertical = true;
2891 return ShowBand(classID, vertical);
2892 }
2893
2894 HRESULT STDMETHODCALLTYPE CShellBrowser::get_ReadyState(READYSTATE *plReadyState)
2895 {
2896 return E_NOTIMPL;
2897 }
2898
2899 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Offline(VARIANT_BOOL *pbOffline)
2900 {
2901 return E_NOTIMPL;
2902 }
2903
2904 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Offline(VARIANT_BOOL bOffline)
2905 {
2906 return E_NOTIMPL;
2907 }
2908
2909 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Silent(VARIANT_BOOL *pbSilent)
2910 {
2911 return E_NOTIMPL;
2912 }
2913
2914 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Silent(VARIANT_BOOL bSilent)
2915 {
2916 return E_NOTIMPL;
2917 }
2918
2919 HRESULT STDMETHODCALLTYPE CShellBrowser::get_RegisterAsBrowser(VARIANT_BOOL *pbRegister)
2920 {
2921 return E_NOTIMPL;
2922 }
2923
2924 HRESULT STDMETHODCALLTYPE CShellBrowser::put_RegisterAsBrowser(VARIANT_BOOL bRegister)
2925 {
2926 return E_NOTIMPL;
2927 }
2928
2929 HRESULT STDMETHODCALLTYPE CShellBrowser::get_RegisterAsDropTarget(VARIANT_BOOL *pbRegister)
2930 {
2931 return E_NOTIMPL;
2932 }
2933
2934 HRESULT STDMETHODCALLTYPE CShellBrowser::put_RegisterAsDropTarget(VARIANT_BOOL bRegister)
2935 {
2936 return E_NOTIMPL;
2937 }
2938
2939 HRESULT STDMETHODCALLTYPE CShellBrowser::get_TheaterMode(VARIANT_BOOL *pbRegister)
2940 {
2941 return E_NOTIMPL;
2942 }
2943
2944 HRESULT STDMETHODCALLTYPE CShellBrowser::put_TheaterMode(VARIANT_BOOL bRegister)
2945 {
2946 return E_NOTIMPL;
2947 }
2948
2949 HRESULT STDMETHODCALLTYPE CShellBrowser::get_AddressBar(VARIANT_BOOL *Value)
2950 {
2951 return E_NOTIMPL;
2952 }
2953
2954 HRESULT STDMETHODCALLTYPE CShellBrowser::put_AddressBar(VARIANT_BOOL Value)
2955 {
2956 return E_NOTIMPL;
2957 }
2958
2959 HRESULT STDMETHODCALLTYPE CShellBrowser::get_Resizable(VARIANT_BOOL *Value)
2960 {
2961 return E_NOTIMPL;
2962 }
2963
2964 HRESULT STDMETHODCALLTYPE CShellBrowser::put_Resizable(VARIANT_BOOL Value)
2965 {
2966 return E_NOTIMPL;
2967 }
2968
2969 HRESULT STDMETHODCALLTYPE CShellBrowser::FindWindowByIndex(DWORD dwID, IUnknown **ppunk)
2970 {
2971 return E_NOTIMPL;
2972 }
2973
2974 HRESULT STDMETHODCALLTYPE CShellBrowser::GetWindowData(IStream *pStream, LPWINDOWDATA pWinData)
2975 {
2976 if (pWinData == NULL)
2977 return E_POINTER;
2978
2979 pWinData->dwWindowID = -1;
2980 pWinData->uiCP = 0;
2981 pWinData->pidl = ILClone(fCurrentDirectoryPIDL);
2982 pWinData->lpszUrl = NULL;
2983 pWinData->lpszUrlLocation = NULL;
2984 pWinData->lpszTitle = NULL;
2985 return S_OK;
2986 }
2987
2988 HRESULT STDMETHODCALLTYPE CShellBrowser::LoadHistoryPosition(LPWSTR pszUrlLocation, DWORD dwPosition)
2989 {
2990 return E_NOTIMPL;
2991 }
2992
2993 HRESULT STDMETHODCALLTYPE CShellBrowser::GetClassID(CLSID *pClassID)
2994 {
2995 return E_NOTIMPL;
2996 }
2997
2998 HRESULT STDMETHODCALLTYPE CShellBrowser::LoadHistory(IStream *pStream, IBindCtx *pbc)
2999 {
3000 CComPtr<IPersistHistory> viewPersistHistory;
3001 CComPtr<IOleObject> viewHistoryObject;
3002 persistState oldState;
3003 ULONG numRead;
3004 LPITEMIDLIST pidl;
3005 HRESULT hResult;
3006
3007 hResult = pStream->Read(&oldState, sizeof(oldState), &numRead);
3008 if (FAILED_UNEXPECTEDLY(hResult))
3009 return hResult;
3010 if (numRead != sizeof(oldState) || oldState.dwSize != sizeof(oldState))
3011 return E_FAIL;
3012 if (oldState.browseType != 2)
3013 return E_FAIL;
3014 pidl = static_cast<LPITEMIDLIST>(CoTaskMemAlloc(oldState.pidlSize));
3015 if (pidl == NULL)
3016 return E_OUTOFMEMORY;
3017 hResult = pStream->Read(pidl, oldState.pidlSize, &numRead);
3018 if (FAILED_UNEXPECTEDLY(hResult))
3019 {
3020 ILFree(pidl);
3021 return hResult;
3022 }
3023 if (numRead != oldState.pidlSize)
3024 {
3025 ILFree(pidl);
3026 return E_FAIL;
3027 }
3028 hResult = CoCreateInstance(oldState.persistClass, NULL, CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_SERVER,
3029 IID_PPV_ARG(IOleObject, &viewHistoryObject));
3030 fHistoryObject = viewHistoryObject;
3031 fHistoryStream = pStream;
3032 fHistoryBindContext = pbc;
3033 hResult = BrowseToPIDL(pidl, BTP_UPDATE_CUR_HISTORY);
3034 fHistoryObject = NULL;
3035 fHistoryStream = NULL;
3036 fHistoryBindContext = NULL;
3037 ILFree(pidl);
3038 if (FAILED_UNEXPECTEDLY(hResult))
3039 return hResult;
3040 return S_OK;
3041 }
3042
3043 HRESULT STDMETHODCALLTYPE CShellBrowser::SaveHistory(IStream *pStream)
3044 {
3045 CComPtr<IPersistHistory> viewPersistHistory;
3046 persistState newState;
3047 HRESULT hResult;
3048
3049 hResult = fCurrentShellView->GetItemObject(
3050 SVGIO_BACKGROUND, IID_PPV_ARG(IPersistHistory, &viewPersistHistory));
3051 memset(&newState, 0, sizeof(newState));
3052 newState.dwSize = sizeof(newState);
3053 newState.browseType = 2;
3054 newState.browserIndex = GetBrowserIndex();
3055 if (viewPersistHistory.p != NULL)
3056 {
3057 hResult = viewPersistHistory->GetClassID(&newState.persistClass);
3058 if (FAILED_UNEXPECTEDLY(hResult))
3059 return hResult;
3060 }
3061 newState.pidlSize = ILGetSize(fCurrentDirectoryPIDL);
3062 hResult = pStream->Write(&newState, sizeof(newState), NULL);
3063 if (FAILED_UNEXPECTEDLY(hResult))
3064 return hResult;
3065 hResult = pStream->Write(fCurrentDirectoryPIDL, newState.pidlSize, NULL);
3066 if (FAILED_UNEXPECTEDLY(hResult))
3067 return hResult;
3068 if (viewPersistHistory.p != NULL)
3069 {
3070 hResult = viewPersistHistory->SaveHistory(pStream);
3071 if (FAILED_UNEXPECTEDLY(hResult))
3072 return hResult;
3073 }
3074 return S_OK;
3075 }
3076
3077 HRESULT STDMETHODCALLTYPE CShellBrowser::SetPositionCookie(DWORD dwPositioncookie)
3078 {
3079 return E_NOTIMPL;
3080 }
3081
3082 HRESULT STDMETHODCALLTYPE CShellBrowser::GetPositionCookie(DWORD *pdwPositioncookie)
3083 {
3084 return E_NOTIMPL;
3085 }
3086
3087 LRESULT CShellBrowser::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
3088 {
3089 OnCreate(reinterpret_cast<LPCREATESTRUCT> (lParam));
3090 return 0;
3091 }
3092
3093 template<class T>
3094 void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
3095 {
3096 if (cptr.p != NULL)
3097 {
3098 int nrc = cptr->Release();
3099 if (nrc > 0)
3100 {
3101 DbgPrint("WARNING: Unexpected RefCount > 0!\n");
3102 if (forceRelease)
3103 {
3104 while (nrc > 0)
3105 {
3106 nrc = cptr->Release();
3107 }
3108 }
3109 }
3110 cptr.Detach();
3111 }
3112 }
3113
3114 LRESULT CShellBrowser::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
3115 {
3116 HRESULT hr;
3117 // TODO: rip down everything
3118 {
3119 fCurrentShellView->DestroyViewWindow();
3120 fCurrentShellView->UIActivate(SVUIA_DEACTIVATE);
3121 ReleaseCComPtrExpectZero(fCurrentShellView);
3122
3123 for (int i = 0; i < 3; i++)
3124 {
3125 if (fClientBars[i].clientBar == NULL)
3126 continue;
3127 IDockingWindow * pdw;
3128 hr = fClientBars[i].clientBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &pdw));
3129 if (FAILED_UNEXPECTEDLY(hr))
3130 continue;
3131 pdw->ShowDW(FALSE);
3132 pdw->CloseDW(0);
3133 pdw->Release();
3134 ReleaseCComPtrExpectZero(fClientBars[i].clientBar);
3135 }
3136 ReleaseCComPtrExpectZero(fTravelLog);
3137
3138 fCurrentShellFolder.Release();
3139 ILFree(fCurrentDirectoryPIDL);
3140 ::DestroyWindow(fStatusBar);
3141 DestroyMenu(fCurrentMenuBar);
3142 }
3143 PostQuitMessage(0);
3144 return 0;
3145 }
3146
3147 LRESULT CShellBrowser::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
3148 {
3149 CComPtr<IDockingWindow> dockingWindow;
3150 RECT availableBounds;
3151 static const INT excludeItems[] = {1, 1, 1, 0xa001, 0, 0};
3152 HRESULT hResult;
3153
3154 if (wParam != SIZE_MINIMIZED)
3155 {
3156 GetEffectiveClientRect(m_hWnd, &availableBounds, excludeItems);
3157 for (INT x = 0; x < 3; x++)
3158 {
3159 if (fClientBars[x].clientBar != NULL)
3160 {
3161 hResult = fClientBars[x].clientBar->QueryInterface(
3162 IID_PPV_ARG(IDockingWindow, &dockingWindow));
3163 if (SUCCEEDED(hResult) && dockingWindow != NULL)
3164 {
3165 hResult = dockingWindow->ResizeBorderDW(
3166 &availableBounds, static_cast<IDropTarget *>(this), TRUE);
3167 break;
3168 }
3169 }
3170 }
3171 RepositionBars();
3172 }
3173 return 1;
3174 }
3175
3176 LRESULT CShellBrowser::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
3177 {
3178 HMENU theMenu;
3179 LPARAM menuIndex = lParam;
3180
3181 theMenu = reinterpret_cast<HMENU>(wParam);
3182
3183 if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_FILE))
3184 {
3185 menuIndex = 0;
3186 }
3187 else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_EDIT))
3188 {
3189 menuIndex = 1;
3190 }
3191 else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_VIEW))
3192 {
3193 UpdateViewMenu(theMenu);
3194 menuIndex = 2;
3195 }
3196 else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_FAVORITES))
3197 {
3198 menuIndex = 3;
3199 }
3200 else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_TOOLS))
3201 {
3202 menuIndex = 4;
3203 }
3204 else if (theMenu == SHGetMenuFromID(fCurrentMenuBar, FCIDM_MENU_HELP))
3205 {
3206 menuIndex = 5;
3207 }
3208
3209 //DbgPrint("Before relay:\n");
3210 //DbgDumpMenu(theMenu);
3211
3212 LRESULT ret = RelayMsgToShellView(uMsg, wParam, menuIndex, bHandled);
3213
3214 //DbgPrint("After relay:\n");
3215 //DbgDumpMenu(theMenu);
3216
3217 return ret;
3218 }
3219
3220 LRESULT CShellBrowser::RelayMsgToShellView(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
3221 {
3222 if (fCurrentShellViewWindow != NULL)
3223 return SendMessage(fCurrentShellViewWindow, uMsg, wParam, lParam);
3224 return 0;
3225 }
3226
3227 LRESULT CShellBrowser::OnClose(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3228 {
3229 return 0;
3230 }
3231
3232 LRESULT CShellBrowser::OnFolderOptions(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3233 {
3234 HRESULT hResult;
3235
3236 hResult = DoFolderOptions();
3237 return 0;
3238 }
3239
3240 LRESULT CShellBrowser::OnMapNetworkDrive(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3241 {
3242 #ifndef __REACTOS__
3243 WNetConnectionDialog(m_hWnd, RESOURCETYPE_DISK);
3244 #endif /* __REACTOS__ */
3245 return 0;
3246 }
3247
3248 LRESULT CShellBrowser::OnDisconnectNetworkDrive(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3249 {
3250 #ifndef __REACTOS__
3251 WNetDisconnectDialog(m_hWnd, RESOURCETYPE_DISK);
3252 #endif /* __REACTOS__ */
3253 return 0;
3254 }
3255
3256 LRESULT CShellBrowser::OnAboutReactOS(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3257 {
3258 ShellAbout(m_hWnd, _T("ReactOS"), _T(""), NULL);
3259 return 0;
3260 }
3261
3262 LRESULT CShellBrowser::OnGoBack(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3263 {
3264 HRESULT hResult;
3265
3266 hResult = GoBack();
3267 return 0;
3268 }
3269
3270 LRESULT CShellBrowser::OnGoForward(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3271 {
3272 HRESULT hResult;
3273
3274 hResult = GoForward();
3275 return 0;
3276 }
3277
3278 LRESULT CShellBrowser::OnGoUpLevel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3279 {
3280 HRESULT hResult;
3281
3282 hResult = NavigateToParent();
3283 return 0;
3284 }
3285
3286 LRESULT CShellBrowser::OnGoHome(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3287 {
3288 HRESULT hResult;
3289
3290 hResult = GoHome();
3291 return 0;
3292 }
3293
3294 LRESULT CShellBrowser::OnBackspace(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3295 {
3296 HRESULT hResult;
3297
3298 // FIXME: This does not appear to be what windows does.
3299 hResult = NavigateToParent();
3300 return 0;
3301 }
3302
3303 LRESULT CShellBrowser::OnIsThisLegal(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3304 {
3305 HRESULT hResult;
3306
3307 typedef HRESULT (WINAPI *PSHOpenNewFrame)(LPITEMIDLIST pidl, IUnknown *b, long c, long d);
3308 PSHOpenNewFrame Func = NULL;
3309 HMODULE Module = GetModuleHandle(TEXT("browseui.dll"));
3310 if (Module != NULL)
3311 Func = reinterpret_cast<PSHOpenNewFrame>(GetProcAddress(Module, (LPCSTR) 103));
3312 if (Func != NULL)
3313 {
3314 LPITEMIDLIST desktopPIDL;
3315
3316 hResult = SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 0, &desktopPIDL);
3317 if (SUCCEEDED(hResult))
3318 {
3319 hResult = Func(desktopPIDL, NULL, -1, 1);
3320 }
3321 }
3322 return 0;
3323 }
3324
3325 LRESULT CShellBrowser::OnToggleStatusBarVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3326 {
3327 fStatusBarVisible = !fStatusBarVisible;
3328 // TODO: trigger a relayout of contained items
3329 return 0;
3330 }
3331
3332 LRESULT CShellBrowser::OnToggleToolbarLock(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3333 {
3334 CComPtr<IOleCommandTarget> commandTarget;
3335 HRESULT hResult;
3336
3337 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
3338 IID_PPV_ARG(IOleCommandTarget, &commandTarget));
3339 if (FAILED_UNEXPECTEDLY(hResult))
3340 return 0;
3341 hResult = commandTarget->Exec(&CGID_PrivCITCommands, ITID_TOOLBARLOCKED, 0, NULL, NULL);
3342 return 0;
3343 }
3344
3345 LRESULT CShellBrowser::OnToggleToolbarBandVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3346 {
3347 CComPtr<IOleCommandTarget> commandTarget;
3348 HRESULT hResult;
3349
3350 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
3351 IID_PPV_ARG(IOleCommandTarget, &commandTarget));
3352 if (FAILED_UNEXPECTEDLY(hResult))
3353 return 0;
3354 hResult = commandTarget->Exec(&CGID_PrivCITCommands, ITID_TOOLBARBANDSHOWN, 0, NULL, NULL);
3355 return 0;
3356 }
3357
3358 LRESULT CShellBrowser::OnToggleAddressBandVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3359 {
3360 CComPtr<IOleCommandTarget> commandTarget;
3361 HRESULT hResult;
3362
3363 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
3364 IID_PPV_ARG(IOleCommandTarget, &commandTarget));
3365 if (FAILED_UNEXPECTEDLY(hResult))
3366 return 0;
3367 hResult = commandTarget->Exec(&CGID_PrivCITCommands, ITID_ADDRESSBANDSHOWN, 0, NULL, NULL);
3368 return 0;
3369 }
3370
3371 LRESULT CShellBrowser::OnToggleLinksBandVisible(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3372 {
3373 CComPtr<IOleCommandTarget> commandTarget;
3374 HRESULT hResult;
3375
3376 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
3377 IID_PPV_ARG(IOleCommandTarget, &commandTarget));
3378 if (FAILED_UNEXPECTEDLY(hResult))
3379 return 0;
3380 hResult = commandTarget->Exec(&CGID_PrivCITCommands, ITID_LINKSBANDSHOWN, 0, NULL, NULL);
3381 return 0;
3382 }
3383
3384 LRESULT CShellBrowser::OnToggleTextLabels(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3385 {
3386 CComPtr<IOleCommandTarget> commandTarget;
3387 HRESULT hResult;
3388
3389 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
3390 IID_PPV_ARG(IOleCommandTarget, &commandTarget));
3391 if (FAILED_UNEXPECTEDLY(hResult))
3392 return 0;
3393 hResult = commandTarget->Exec(&CGID_PrivCITCommands, ITID_TEXTLABELS, 0, NULL, NULL);
3394 return 0;
3395 }
3396
3397 LRESULT CShellBrowser::OnToolbarCustomize(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3398 {
3399 CComPtr<IOleCommandTarget> commandTarget;
3400 HRESULT hResult;
3401
3402 hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
3403 IID_PPV_ARG(IOleCommandTarget, &commandTarget));
3404 if (FAILED_UNEXPECTEDLY(hResult))
3405 return 0;
3406 hResult = commandTarget->Exec(&CGID_PrivCITCommands, ITID_CUSTOMIZEENABLED, 0, NULL, NULL);
3407 return 0;
3408 }
3409
3410 LRESULT CShellBrowser::OnGoTravel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
3411 {
3412 return 0;
3413 }
3414
3415 LRESULT CShellBrowser::RelayCommands(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
3416 {
3417 if (HIWORD(wParam) == 0 && LOWORD(wParam) < FCIDM_SHVIEWLAST && fCurrentShellViewWindow != NULL)
3418 return SendMessage(fCurrentShellViewWindow, uMsg, wParam, lParam);
3419 return 0;
3420 }
3421
3422 static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
3423 {
3424 CComPtr<CShellBrowser> theCabinet;
3425 HRESULT hResult;
3426 MSG Msg;
3427 BOOL Ret;
3428
3429 ATLTRY(theCabinet = new CComObject<CShellBrowser>);
3430 if (theCabinet == NULL)
3431 {
3432 return E_OUTOFMEMORY;
3433 }
3434
3435 hResult = theCabinet->Initialize(parameters->directoryPIDL, 0, 0, 0);
3436 if (FAILED_UNEXPECTEDLY(hResult))
3437 return E_OUTOFMEMORY;
3438
3439 while ((Ret = GetMessage(&Msg, NULL, 0, 0)) != 0)
3440 {
3441 if (Ret == -1)
3442 {
3443 // Error: continue or exit?
3444 break;
3445 }
3446
3447 if (Msg.message == WM_QUIT)
3448 break;
3449
3450 if (theCabinet->v_MayTranslateAccelerator(&Msg) != S_OK)
3451 {
3452 TranslateMessage(&Msg);
3453 DispatchMessage(&Msg);
3454 }
3455 }
3456
3457 //TerminateProcess(GetCurrentProcess(), hResult);
3458
3459 int nrc = theCabinet->Release();
3460 if (nrc > 0)
3461 {
3462 DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked, process will never terminate. Terminating forcefully.\n", nrc);
3463
3464 //TerminateProcess(GetCurrentProcess(), 1);
3465 }
3466
3467 theCabinet.Detach();
3468
3469 return hResult;
3470 }
3471
3472 DWORD WINAPI BrowserThreadProc(LPVOID lpThreadParameter)
3473 {
3474 HRESULT hr;
3475 IEThreadParamBlock * parameters = (IEThreadParamBlock *) lpThreadParameter;
3476 INITCOMMONCONTROLSEX iccex =
3477 {
3478 sizeof(iccex),
3479 0xFFFF /* everything! */
3480 };
3481
3482 OleInitialize(NULL);
3483 InitCommonControlsEx(&iccex);
3484
3485 ATLTRY(hr = ExplorerMessageLoop(parameters));
3486
3487 OleUninitialize();
3488
3489 return hr;
3490 }