ReactOS 0.4.16-dev-106-g10b08aa
webchild.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2004, 2005 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // webchild.cpp
24 //
25 // Martin Fuchs, 08.02.2004
26 //
27
28#include <precomp.h>
29
30#include "webchild.h"
31
32#include <comutil.h>
33
34Variant::Variant(const VARIANT& var)
35{
36 VariantInit(this);
37 CheckError(VariantCopy(this, const_cast<VARIANT*>(&var)));
38}
39
40Variant::Variant(const VARIANT* var)
41{
42 VariantInit(this);
43 CheckError(VariantCopy(this, const_cast<VARIANT*>(var)));
44}
45
46Variant::~Variant()
47{
48 VariantClear(this);
49}
50
51
52Variant::operator long() const
53{
54 Variant v;
56 return V_I4(&v);
57}
58
59Variant::operator bool() const
60{
61 Variant v;
63 return V_BOOL(&v)? true: false;
64}
65
66Variant::operator IDispatch*() const
67{
68 Variant v;
70 return V_DISPATCH(&v);
71}
72
73Variant::operator VARIANT_BOOL() const
74{
75 Variant v;
77 return V_BOOL(&v);
78}
79
80
81void BStr::assign(BSTR s)
82{
83 if (!SysReAllocString(&_p, s))
85}
86
87void BStr::assign(const VARIANT& var)
88{
89 if (V_VT(&var) == VT_BSTR)
90 assign(V_BSTR(&var));
91 else {
92 Variant v;
93 CheckError(VariantChangeType(&v, const_cast<VARIANT*>(&var), 0, VT_BSTR));
94 assign(V_BSTR(&v));
95 }
96}
97
98
100 : _browser_initialized(false)
101{
102}
103
104void BrowserNavigator::attach(IWebBrowser* browser)
105{
106 _browser = browser;
107}
108
110{
112 _browser->Navigate(BStr(url), NULL, NULL, NULL, NULL);
113 else {
114 _new_url = url;
115
116 _browser->Navigate(BStr(L"about:blank"), NULL, NULL, NULL, NULL);
117 }
118}
119
121{
122 _new_html_txt = html_txt;
123
124 goto_url(TEXT("about:blank"));
125}
126
128{
129 while(len-- > 0)
130 *d++ = (unsigned char)*s++;
131}
132
134{
136
137 bool nav = false;
138
139 if (!_new_url.empty()) {
140 if (!_tcscmp(url,TEXT("about:blank")) && _new_url!=TEXT("about:blank")) {
141 _browser->Navigate(BStr(_new_url), NULL, NULL, NULL, NULL);
142 ++nav;
143 }
144
145 _new_url.erase();
146 }
147
148 if (!nav && !_new_html_txt.empty()) {
149 int len = _new_html_txt.length();
150 HGLOBAL hHtmlText = GlobalAlloc(GPTR, len);
151
152 if (!hHtmlText) {
153 T2nA_binary(_new_html_txt, (char*)hHtmlText, len);
154 _new_html_txt.erase();
155
156 SIfacePtr<IStream> pStream;
157 HRESULT hr = CreateStreamOnHGlobal(hHtmlText, TRUE, &pStream);
158
159 if (SUCCEEDED(hr)) {
160 SIfacePtr<IDispatch> pHtmlDoc;
161 CheckError(_browser->get_Document(&pHtmlDoc));
162
163 SIfacePtr<IPersistStreamInit> pPersistStreamInit;
164 pHtmlDoc.QueryInterface(IID_IPersistStreamInit, &pPersistStreamInit);
165
166 CheckError(pPersistStreamInit->InitNew());
167 CheckError(pPersistStreamInit->Load(pStream));
168 } else
169 GlobalFree(hHtmlText);
170 }
171 }
172}
173
174
176{
178
179 if (!pWnd)
180 return 0;
181
182 return *pWnd;
183}
184
186 {0x1339B54C, 0x3453, 0x11D2, {0x93, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
187
188
190 : super(hwnd, info),
191 web_super(_navigator)
192{
193 // first try to create a web control with MS IE's CLASSID
194 HRESULT hr = create_control(hwnd, CLSID_WebBrowser, IID_IWebBrowser2);
195
196 // If this failed, try to use Mozilla's web control
197 if (FAILED(hr))
198 hr = create_control(hwnd, CLSID_MozillaBrowser, IID_IWebBrowser2);
199
200 if (SUCCEEDED(hr)) {
202
203 _connector = auto_ptr<EventConnector>(new EventConnector(_control, DIID_DWebBrowserEvents2, this));
204
205 _control->Navigate(BStr(info._path), &vtMissing, &vtMissing, &vtMissing, &vtMissing);
206 //browser->Navigate2(&Variant(info._path), &vtMissing, &vtMissing, &vtMissing, &vtMissing);
207 }
208}
209
211{
212 try {
213 switch(nmsg) {
214 case WM_ERASEBKGND:
215 if (!_control) {
216 HDC hdc = (HDC)wparam;
217 ClientRect rect(_hwnd);
218
219 HBRUSH hbrush = CreateSolidBrush(RGB(200,200,235));
220 BkMode mode(hdc, TRANSPARENT);
221 TextColor color(hdc, RGB(200,40,40));
223 DrawText(hdc, TEXT("Sorry - no web browser control could be loaded."), -1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
225 }
226
227 return TRUE;
228
229 case PM_DISPATCH_COMMAND: {
230 if (!_control)
231 return FALSE;
232
233 HRESULT hr = E_FAIL;
234
235 switch(LOWORD(wparam)) {
236 case ID_GO_BACK:
237 hr = _control->GoBack();
238 break;
239
240 case ID_GO_FORWARD:
241 hr = _control->GoForward();
242 break;
243
244 case ID_GO_UP:
246 break;
247
248 case ID_GO_HOME:
249 hr = _control->GoHome();
250 break;
251
252 case ID_GO_SEARCH:
253 hr = _control->GoSearch();
254 break;
255
256 case ID_REFRESH:
257 hr = _control->Refresh();
258 break;
259
260 case ID_STOP:
261 hr = _control->Stop();
262 break;
263
264 default:
265 return super::WndProc(nmsg, wparam, lparam);
266 }
267
268 if (FAILED(hr) && hr!=E_FAIL)
270
271 return TRUE;}
272
273 default:
274 return super::WndProc(nmsg, wparam, lparam);
275 }
276 } catch(COMException& e) {
277 HandleException(e, _hwnd);
278 }
279
280 return 0;
281}
282
283
285{
287
288 return url;
289}
static HBRUSH hbrush
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
#define ID_STOP
Definition: resource.h:19
#define ID_REFRESH
Definition: resource.h:16
_variant_t vtMissing(DISP_E_PARAMNOTFOUND, VT_ERROR)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
OLECHAR * BSTR
Definition: compat.h:2293
short VARIANT_BOOL
Definition: compat.h:2290
@ VT_BSTR
Definition: compat.h:2303
@ VT_I4
Definition: compat.h:2298
@ VT_BOOL
Definition: compat.h:2306
@ VT_DISPATCH
Definition: compat.h:2304
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
unsigned char
Definition: typeof.h:29
#define RGB(r, g, b)
Definition: precomp.h:71
pKey DeleteObject()
const GLdouble * v
Definition: gl.h:2040
GLdouble s
Definition: gl.h:2039
GLuint color
Definition: glext.h:6243
GLenum mode
Definition: glext.h:6217
GLenum GLsizei len
Definition: glext.h:6722
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define _tcscmp
Definition: tchar.h:1424
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define TEXT(s)
Definition: k32.h:26
#define d
Definition: ke_i.h:81
#define e
Definition: ke_i.h:82
#define ID_GO_UP
Definition: resource.h:210
#define ID_GO_HOME
Definition: resource.h:208
#define ID_GO_SEARCH
Definition: resource.h:209
#define ID_GO_FORWARD
Definition: resource.h:207
#define ID_GO_BACK
Definition: resource.h:206
#define PM_DISPATCH_COMMAND
Definition: window.h:265
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
static const WCHAR url[]
Definition: encode.c:1432
const char * var
Definition: shader.c:5666
unsigned int UINT
Definition: ndis.h:50
#define bool
Definition: nsiface.idl:72
#define L(x)
Definition: ntvdm.h:50
INT WINAPI SysReAllocString(LPBSTR old, LPCOLESTR str)
Definition: oleaut.c:467
#define V_BOOL(A)
Definition: oleauto.h:224
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
#define V_I4(A)
Definition: oleauto.h:247
#define V_DISPATCH(A)
Definition: oleauto.h:239
const GUID IID_IPersistStreamInit
#define LOWORD(l)
Definition: pedump.c:82
#define long
Definition: qsort.c:33
void HandleException(COMException &e, HWND hwnd)
Exception Handler for COM exceptions.
#define THROW_EXCEPTION(hr)
Definition: shellclasses.h:161
void CheckError(HRESULT hr)
Definition: shellclasses.h:167
HRESULT hr
Definition: shlfolder.c:183
& rect
Definition: startmenu.cpp:1413
#define false
Definition: stdbool.h:37
void set_html_page(const String &html_txt)
Definition: webchild.cpp:120
void goto_url(LPCTSTR url)
Definition: webchild.cpp:109
SIfacePtr< IWebBrowser > _browser
Definition: webchild.h:518
String _new_url
Definition: webchild.h:519
void attach(IWebBrowser *browser)
Definition: webchild.cpp:104
bool _browser_initialized
Definition: webchild.h:521
void navigated(LPCTSTR url)
Definition: webchild.cpp:133
String _new_html_txt
Definition: webchild.h:520
Exception with context information.
Definition: shellclasses.h:114
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
Definition: webchild.h:354
HRESULT create_control(HWND hwnd, REFIID clsid, REFIID riid)
Definition: webchild.h:335
wrapper class for COM interface pointers
Definition: shellclasses.h:333
HRESULT QueryInterface(REFIID riid, I *p)
Definition: shellclasses.h:417
encapsulation of Web control in MDI child windows
Definition: webchild.h:836
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
Definition: webchild.cpp:210
virtual String jump_to_int(LPCTSTR url)
Definition: webchild.cpp:284
BrowserNavigator _navigator
Definition: webchild.h:1012
static WebChildWindow * create(const FileChildWndInfo &info)
Definition: webchild.h:842
WebChildWindow(HWND hwnd, const WebChildWndInfo &info)
Definition: webchild.cpp:189
auto_ptr< EventConnector > _connector
Definition: webchild.h:1013
information structure for creation of WebChildWindow
Definition: filechild.h:80
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:748
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
HWND create_webchildwindow(const WebChildWndInfo &info)
Definition: webchild.cpp:175
void T2nA_binary(LPCTSTR s, LPSTR d, int len)
Definition: webchild.cpp:127
static const CLSID CLSID_MozillaBrowser
Definition: webchild.cpp:185
#define GPTR
Definition: winbase.h:296
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define TRANSPARENT
Definition: wingdi.h:950
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define WM_ERASEBKGND
Definition: winuser.h:1628
#define DT_CENTER
Definition: winuser.h:527
#define DT_SINGLELINE
Definition: winuser.h:540
#define DrawText
Definition: winuser.h:5783
#define DT_VCENTER
Definition: winuser.h:543
char * LPSTR
Definition: xmlstorage.h:182
const CHAR * LPCTSTR
Definition: xmlstorage.h:193