Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dx8webbrowser.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19//******************************************************************************************
20//
21// Earth And Beyond
22// Copyright (c) 2002 Electronic Arts , Inc. - Westwood Studios
23//
24// File Name : dx8webbrowser.cpp
25// Description : Implementation of D3D Embedded Browser wrapper.
26// Author : Darren Schueller
27// Date of Creation : 6/4/2002
28//
29//******************************************************************************************
30// $Header: $
31//******************************************************************************************
32
33#include "dx8webbrowser.h"
34#include "ww3d.h"
35#include "dx8wrapper.h"
36
37#if ENABLE_EMBEDDED_BROWSER
38
39// Import the Browser Type Library
40// BGC, the path for the dll file is pretty odd, no?
41// I'll leave it like this till I can figure out a
42// better way.
43#import "..\..\..\..\..\run\BrowserEngine.DLL" no_namespace
44
45static IFEBrowserEngine2Ptr pBrowser = 0;
46
47HWND DX8WebBrowser::hWnd = 0;
48
49bool DX8WebBrowser::Initialize( const char* badpageurl,
50 const char* loadingpageurl,
51 const char* mousefilename,
52 const char* mousebusyfilename)
53{
54 if(pBrowser == 0)
55 {
56 // Initialize COM
57 CoInitialize(0);
58
59 // Create an instance of the browser control
60 HRESULT hr = pBrowser.CreateInstance(__uuidof(FEBrowserEngine2));
61
62 if(hr == REGDB_E_CLASSNOTREG)
63 {
64 HMODULE lib = ::LoadLibrary("BrowserEngine.DLL");
65 if(lib)
66 {
67 FARPROC proc = ::GetProcAddress(lib,"DllRegisterServer");
68 if(proc)
69 {
70 proc();
71 // Create an instance of the browser control
72 hr = pBrowser.CreateInstance(__uuidof(FEBrowserEngine2));
73 }
74 FreeLibrary(lib);
75 }
76 }
77
78 // Initialize the browser.
79 if(hr == S_OK)
80 {
81 hWnd = (HWND)WW3D::Get_Window();
82 pBrowser->Initialize(reinterpret_cast<long*>(DX8Wrapper::_Get_D3D_Device8()));
83
84 if(badpageurl)
85 pBrowser->put_BadPageURL(_bstr_t(badpageurl));
86
87 if(loadingpageurl)
88 pBrowser->put_LoadingPageURL(_bstr_t(loadingpageurl));
89
90 if(mousefilename)
91 pBrowser->put_MouseFileName(_bstr_t(mousefilename));
92
93 if(mousebusyfilename)
94 pBrowser->put_MouseBusyFileName(_bstr_t(mousebusyfilename));
95 }
96 else
97 {
98 pBrowser = 0;
99 return false;
100 }
101 }
102
103 return true;
104}
105
107{
108 if(pBrowser)
109 {
110 // Shutdown the browser
111 pBrowser->Shutdown();
112
113 // Release the smart pointer.
114 pBrowser = 0;
115
116 hWnd = 0;
117
118 // Shut down COM
119 CoUninitialize();
120 }
121}
122
123
124// ******************************************************************************************
125// * Function Name: DX8WebBrowser::Update
126// ******************************************************************************************
127// * Description: Updates the browser image surfaces by copying the bits from the browser
128// * DCs to the D3D Image surfaces.
129// *
130// * Return Type:
131// *
132// * Argument: void
133// *
134// ******************************************************************************************
136{
137 if(pBrowser) pBrowser->D3DUpdate();
138};
139
140
141// ******************************************************************************************
142// * Function Name: DX8WebBrowser::Render
143// ******************************************************************************************
144// * Description: Draws all browsers to the back buffer.
145// *
146// * Return Type:
147// *
148// * Argument: int backbufferindex
149// *
150// ******************************************************************************************
151void DX8WebBrowser::Render(int backbufferindex)
152{
153 if(pBrowser) pBrowser->D3DRender(backbufferindex);
154};
155
156// ******************************************************************************************
157// * Function Name: DX8WebBrowser::CreateBrowser
158// ******************************************************************************************
159// * Description: Creates a browser window.
160// *
161// * Return Type:
162// *
163// * Argument: const char* browsername - This is a "name" used to identify the
164// * browser instance. Multiple browsers can
165// * be created, and are referenced using this name.
166// * Argument: const char* url - The url to display.
167// * Argument: int x - The position and size of the browser (in pixels)
168// * Argument: int y
169// * Argument: int w
170// * Argument: int h
171// * Argument: int updateticks - When non-zero, this forces the browser image to get updated
172// * at the specified rate (number of milliseconds) regardless
173// * of paint messages. When this is zero (the default) the browser
174// * image is only updated whenever a paint message is received.
175// *
176// ******************************************************************************************
177void DX8WebBrowser::CreateBrowser(const char* browsername, const char* url, int x, int y, int w, int h, int updateticks, LONG options, LPDISPATCH gamedispatch)
178{
179 WWDEBUG_SAY(("DX8WebBrowser::CreateBrowser - Creating browser with the name %s, url = %s, (x, y, w, h) = (%d, %d, %d, %d), update ticks = %d\n", browsername, url, x, y, h, w, updateticks));
180 if(pBrowser)
181 {
182 _bstr_t brsname(browsername);
183 pBrowser->CreateBrowser(brsname, _bstr_t(url), reinterpret_cast<long>(hWnd), x, y, w, h, options, gamedispatch);
184 pBrowser->SetUpdateRate(brsname, updateticks);
185 }
186}
187
188
189// ******************************************************************************************
190// * Function Name: DX8WebBrowser::DestroyBrowser
191// ******************************************************************************************
192// * Description: Destroys the specified browser. This closes the window and releases
193// * the browser instance.
194// *
195// * Return Type:
196// *
197// * Argument: const char* browsername - The name of the browser to destroy.
198// *
199// ******************************************************************************************
200void DX8WebBrowser::DestroyBrowser(const char* browsername)
201{
202 WWDEBUG_SAY(("DX8WebBrowser::DestroyBrowser - destroying browser %s\n", browsername));
203 if(pBrowser)
204 pBrowser->DestroyBrowser(_bstr_t(browsername));
205}
206
207
208// ******************************************************************************************
209// * Function Name: DX8WebBrowser::Is_Browser_Open
210// ******************************************************************************************
211// * Description: This function checks to see if a browser of the specified name exists and
212// * is currently open.
213// *
214// * Return Type:
215// *
216// * Argument: const char* browsername - The name of the browser to test.
217// *
218// ******************************************************************************************
219bool DX8WebBrowser::Is_Browser_Open(const char* browsername)
220{
221 if(pBrowser == 0) return false;
222 return (pBrowser->IsOpen(_bstr_t(browsername)) != 0);
223}
224
225// ******************************************************************************************
226// * Function Name: DX8WebBrowser::Navigate
227// ******************************************************************************************
228// * Description: This function causes the browser to navigate to the specified page.
229// *
230// * Return Type:
231// *
232// * Argument: const char* browsername - The name of the browser to test.
233// * const char* url - The url to navigate to.
234// *
235// ******************************************************************************************
236void DX8WebBrowser::Navigate(const char* browsername, const char* url)
237{
238 if(pBrowser == 0) return;
239 pBrowser->Navigate(_bstr_t(browsername),_bstr_t(url));
240}
241
242#endif
static void DestroyBrowser(const char *browsername)
static void CreateBrowser(const char *browsername, const char *url, int x, int y, int w, int h, int updateticks=0, LONG options=BROWSEROPTION_SCROLLBARS|BROWSEROPTION_3DBORDER, LPDISPATCH gamedispatch=0)
static void Render(int backbufferindex)
static void Update(void)
static bool Is_Browser_Open(const char *browsername)
static bool Initialize(const char *badpageurl=0, const char *loadingpageurl=0, const char *mousefilename=0, const char *mousebusyfilename=0)
static void Navigate(const char *browsername, const char *url)
static void Shutdown(void)
static IDirect3DDevice8 * _Get_D3D_Device8()
Definition dx8wrapper.h:530
static void * Get_Window(void)
Definition ww3d.cpp:489
#define WWDEBUG_SAY(x)
Definition wwdebug.h:114