Sync with trunk head (part 1 or 2)
[reactos.git] / dll / win32 / browseui / bandproxy.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 /*
22 Used by the address band to dispatch navigation changes to the main browser object.
23
24 TODO:
25
26 */
27 #include <windows.h>
28 #include <shlobj.h>
29 #include <shlobj_undoc.h>
30 #include <shlguid.h>
31 #include <shlguid_undoc.h>
32 #include <perhist.h>
33 #include <exdisp.h>
34 #include <tchar.h>
35 #include <atlbase.h>
36 #include <atlcom.h>
37 #include <atlwin.h>
38 #include "resource.h"
39 #include "bandproxy.h"
40
41 CBandProxy::CBandProxy()
42 {
43 }
44
45 CBandProxy::~CBandProxy()
46 {
47 }
48
49 HRESULT CBandProxy::FindBrowserWindow(IUnknown **browser)
50 {
51 CComPtr<IServiceProvider> serviceProvider;
52 CComPtr<IWebBrowser2> webBrowser;
53 HRESULT hResult;
54
55 if (browser == NULL)
56 return E_POINTER;
57 hResult = fSite->QueryInterface(IID_IServiceProvider, (void **)&serviceProvider);
58 if (FAILED (hResult))
59 return hResult;
60 hResult = serviceProvider->QueryService(SID_IWebBrowserApp, IID_IWebBrowser2, (void **)&webBrowser);
61 if (FAILED (hResult))
62 return hResult;
63 *browser = webBrowser.Detach();
64 return S_OK;
65 }
66
67 HRESULT STDMETHODCALLTYPE CBandProxy::SetSite(IUnknown *paramC)
68 {
69 fSite = paramC;
70 return S_OK;
71 }
72
73 HRESULT STDMETHODCALLTYPE CBandProxy::CreateNewWindow(long paramC)
74 {
75 return E_NOTIMPL;
76 }
77
78 HRESULT STDMETHODCALLTYPE CBandProxy::GetBrowserWindow(IUnknown **paramC)
79 {
80 if (paramC == NULL)
81 return E_POINTER;
82 return FindBrowserWindow(paramC);
83 }
84
85 HRESULT STDMETHODCALLTYPE CBandProxy::IsConnected()
86 {
87 CComPtr<IUnknown> webBrowser;
88 HRESULT hResult;
89
90 hResult = FindBrowserWindow(&webBrowser);
91 if (FAILED (hResult) || webBrowser.p == NULL)
92 return S_FALSE;
93 return S_OK;
94 }
95
96 HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToPIDL(LPCITEMIDLIST pidl)
97 {
98 CComPtr<IOleWindow> oleWindow;
99 CComPtr<IServiceProvider> serviceProvider;
100 CComPtr<IUnknown> webBrowserUnknown;
101 CComPtr<IWebBrowser2> webBrowser;
102 HWND browserWindow;
103 CComVariant args;
104 CComVariant emptyVariant;
105 unsigned int arraySize;
106 HRESULT hResult;
107
108 hResult = FindBrowserWindow(&webBrowserUnknown);
109 if (FAILED (hResult))
110 return hResult;
111 hResult = webBrowserUnknown->QueryInterface(IID_IWebBrowserApp, (void **)&webBrowser);
112 if (FAILED (hResult))
113 return hResult;
114 hResult = webBrowser->put_Visible(TRUE);
115 hResult = webBrowser->QueryInterface(IID_IServiceProvider, (void **)&serviceProvider);
116 if (SUCCEEDED (hResult))
117 {
118 hResult = serviceProvider->QueryService(SID_STopLevelBrowser, IID_IOleWindow, (void **)&oleWindow);
119 if (SUCCEEDED (hResult))
120 {
121 hResult = oleWindow->GetWindow(&browserWindow);
122 if (IsIconic(browserWindow))
123 ShowWindow(browserWindow, SW_RESTORE);
124 }
125 }
126 arraySize = ILGetSize(pidl);
127 V_VT(&args) = VT_ARRAY | VT_UI1;
128 V_ARRAY(&args) = SafeArrayCreateVector(VT_UI1, 0, arraySize);
129 if (V_ARRAY(&args) == NULL)
130 return E_OUTOFMEMORY;
131 memcpy(V_ARRAY(&args)->pvData, pidl, arraySize);
132 hResult = webBrowser->Navigate2(&args, &emptyVariant, &emptyVariant, &emptyVariant, &emptyVariant);
133 if (FAILED (hResult))
134 return hResult;
135 return S_OK;
136 }
137
138 HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToURL(long paramC, long param10)
139 {
140 return E_NOTIMPL;
141 }
142
143 HRESULT CreateBandProxy(REFIID riid, void **ppv)
144 {
145 CComObject<CBandProxy> *theBandProxy;
146 HRESULT hResult;
147
148 if (ppv == NULL)
149 return E_POINTER;
150 *ppv = NULL;
151 ATLTRY (theBandProxy = new CComObject<CBandProxy>);
152 if (theBandProxy == NULL)
153 return E_OUTOFMEMORY;
154 hResult = theBandProxy->QueryInterface (riid, (void **)ppv);
155 if (FAILED (hResult))
156 {
157 delete theBandProxy;
158 return hResult;
159 }
160 return S_OK;
161 }