[BROWSEUI]
[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
28 #include "precomp.h"
29
30 CBandProxy::CBandProxy()
31 {
32 }
33
34 CBandProxy::~CBandProxy()
35 {
36 }
37
38 HRESULT CBandProxy::FindBrowserWindow(IUnknown **browser)
39 {
40 CComPtr<IServiceProvider> serviceProvider;
41 CComPtr<IWebBrowser2> webBrowser;
42 HRESULT hResult;
43
44 if (browser == NULL)
45 return E_POINTER;
46 hResult = fSite->QueryInterface(IID_PPV_ARG(IServiceProvider, &serviceProvider));
47 if (FAILED(hResult))
48 return hResult;
49 hResult = serviceProvider->QueryService(
50 SID_IWebBrowserApp, IID_PPV_ARG(IWebBrowser2, &webBrowser));
51 if (FAILED(hResult))
52 return hResult;
53 *browser = webBrowser.Detach();
54 return S_OK;
55 }
56
57 HRESULT STDMETHODCALLTYPE CBandProxy::SetSite(IUnknown *paramC)
58 {
59 fSite = paramC;
60 return S_OK;
61 }
62
63 HRESULT STDMETHODCALLTYPE CBandProxy::CreateNewWindow(long paramC)
64 {
65 return E_NOTIMPL;
66 }
67
68 HRESULT STDMETHODCALLTYPE CBandProxy::GetBrowserWindow(IUnknown **paramC)
69 {
70 if (paramC == NULL)
71 return E_POINTER;
72 return FindBrowserWindow(paramC);
73 }
74
75 HRESULT STDMETHODCALLTYPE CBandProxy::IsConnected()
76 {
77 CComPtr<IUnknown> webBrowser;
78 HRESULT hResult;
79
80 hResult = FindBrowserWindow(&webBrowser);
81 if (FAILED(hResult) || webBrowser.p == NULL)
82 return S_FALSE;
83 return S_OK;
84 }
85
86 HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToPIDL(LPCITEMIDLIST pidl)
87 {
88 CComPtr<IOleWindow> oleWindow;
89 CComPtr<IServiceProvider> serviceProvider;
90 CComPtr<IUnknown> webBrowserUnknown;
91 CComPtr<IWebBrowser2> webBrowser;
92 HWND browserWindow;
93 CComVariant args;
94 CComVariant emptyVariant;
95 unsigned int arraySize;
96 HRESULT hResult;
97
98 hResult = FindBrowserWindow(&webBrowserUnknown);
99 if (FAILED(hResult))
100 return hResult;
101 hResult = webBrowserUnknown->QueryInterface(IID_PPV_ARG(IWebBrowser2, &webBrowser));
102 if (FAILED(hResult))
103 return hResult;
104 hResult = webBrowser->put_Visible(TRUE);
105 hResult = webBrowser->QueryInterface(IID_PPV_ARG(IServiceProvider, &serviceProvider));
106 if (SUCCEEDED(hResult))
107 {
108 hResult = serviceProvider->QueryService(SID_STopLevelBrowser,
109 IID_PPV_ARG(IOleWindow, &oleWindow));
110 if (SUCCEEDED(hResult))
111 {
112 hResult = oleWindow->GetWindow(&browserWindow);
113 if (IsIconic(browserWindow))
114 ShowWindow(browserWindow, SW_RESTORE);
115 }
116 }
117 arraySize = ILGetSize(pidl);
118 V_VT(&args) = VT_ARRAY | VT_UI1;
119 V_ARRAY(&args) = SafeArrayCreateVector(VT_UI1, 0, arraySize);
120 if (V_ARRAY(&args) == NULL)
121 return E_OUTOFMEMORY;
122 memcpy(V_ARRAY(&args)->pvData, pidl, arraySize);
123 hResult = webBrowser->Navigate2(&args, &emptyVariant, &emptyVariant, &emptyVariant, &emptyVariant);
124 if (FAILED(hResult))
125 return hResult;
126 return S_OK;
127 }
128
129 HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToURL(long paramC, long param10)
130 {
131 return E_NOTIMPL;
132 }
133
134 HRESULT CreateBandProxy(REFIID riid, void **ppv)
135 {
136 CComObject<CBandProxy> *theBandProxy;
137 HRESULT hResult;
138
139 if (ppv == NULL)
140 return E_POINTER;
141 *ppv = NULL;
142 ATLTRY (theBandProxy = new CComObject<CBandProxy>);
143 if (theBandProxy == NULL)
144 return E_OUTOFMEMORY;
145 hResult = theBandProxy->QueryInterface(riid, reinterpret_cast<void **>(ppv));
146 if (FAILED(hResult))
147 {
148 delete theBandProxy;
149 return hResult;
150 }
151 return S_OK;
152 }