dx8webbrowser.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. // Earth And Beyond
  21. // Copyright (c) 2002 Electronic Arts , Inc. - Westwood Studios
  22. //
  23. // File Name : dx8webbrowser.cpp
  24. // Description : Implementation of D3D Embedded Browser wrapper.
  25. // Author : Darren Schueller
  26. // Date of Creation : 6/4/2002
  27. //
  28. //******************************************************************************************
  29. // $Header: $
  30. //******************************************************************************************
  31. #include "dx8webbrowser.h"
  32. #include "ww3d.h"
  33. #include "dx8wrapper.h"
  34. #if ENABLE_EMBEDDED_BROWSER
  35. // Import the Browser Type Library
  36. // BGC, the path for the dll file is pretty odd, no?
  37. // I'll leave it like this till I can figure out a
  38. // better way.
  39. #import "..\..\..\..\..\run\BrowserEngine.DLL" no_namespace
  40. static IFEBrowserEngine2Ptr pBrowser = 0;
  41. HWND DX8WebBrowser::hWnd = 0;
  42. bool DX8WebBrowser::Initialize( const char* badpageurl,
  43. const char* loadingpageurl,
  44. const char* mousefilename,
  45. const char* mousebusyfilename)
  46. {
  47. if(pBrowser == 0)
  48. {
  49. // Initialize COM
  50. CoInitialize(0);
  51. // Create an instance of the browser control
  52. HRESULT hr = pBrowser.CreateInstance(__uuidof(FEBrowserEngine2));
  53. if(hr == REGDB_E_CLASSNOTREG)
  54. {
  55. HMODULE lib = ::LoadLibrary("BrowserEngine.DLL");
  56. if(lib)
  57. {
  58. FARPROC proc = ::GetProcAddress(lib,"DllRegisterServer");
  59. if(proc)
  60. {
  61. proc();
  62. // Create an instance of the browser control
  63. hr = pBrowser.CreateInstance(__uuidof(FEBrowserEngine2));
  64. }
  65. FreeLibrary(lib);
  66. }
  67. }
  68. // Initialize the browser.
  69. if(hr == S_OK)
  70. {
  71. hWnd = (HWND)WW3D::Get_Window();
  72. pBrowser->Initialize(reinterpret_cast<long*>(DX8Wrapper::_Get_D3D_Device8()));
  73. if(badpageurl)
  74. pBrowser->put_BadPageURL(_bstr_t(badpageurl));
  75. if(loadingpageurl)
  76. pBrowser->put_LoadingPageURL(_bstr_t(loadingpageurl));
  77. if(mousefilename)
  78. pBrowser->put_MouseFileName(_bstr_t(mousefilename));
  79. if(mousebusyfilename)
  80. pBrowser->put_MouseBusyFileName(_bstr_t(mousebusyfilename));
  81. }
  82. else
  83. {
  84. pBrowser = 0;
  85. return false;
  86. }
  87. }
  88. return true;
  89. }
  90. void DX8WebBrowser::Shutdown()
  91. {
  92. if(pBrowser)
  93. {
  94. // Shutdown the browser
  95. pBrowser->Shutdown();
  96. // Release the smart pointer.
  97. pBrowser = 0;
  98. hWnd = 0;
  99. // Shut down COM
  100. CoUninitialize();
  101. }
  102. }
  103. // ******************************************************************************************
  104. // * Function Name: DX8WebBrowser::Update
  105. // ******************************************************************************************
  106. // * Description: Updates the browser image surfaces by copying the bits from the browser
  107. // * DCs to the D3D Image surfaces.
  108. // *
  109. // * Return Type:
  110. // *
  111. // * Argument: void
  112. // *
  113. // ******************************************************************************************
  114. void DX8WebBrowser::Update(void)
  115. {
  116. if(pBrowser) pBrowser->D3DUpdate();
  117. };
  118. // ******************************************************************************************
  119. // * Function Name: DX8WebBrowser::Render
  120. // ******************************************************************************************
  121. // * Description: Draws all browsers to the back buffer.
  122. // *
  123. // * Return Type:
  124. // *
  125. // * Argument: int backbufferindex
  126. // *
  127. // ******************************************************************************************
  128. void DX8WebBrowser::Render(int backbufferindex)
  129. {
  130. if(pBrowser) pBrowser->D3DRender(backbufferindex);
  131. };
  132. // ******************************************************************************************
  133. // * Function Name: DX8WebBrowser::CreateBrowser
  134. // ******************************************************************************************
  135. // * Description: Creates a browser window.
  136. // *
  137. // * Return Type:
  138. // *
  139. // * Argument: const char* browsername - This is a "name" used to identify the
  140. // * browser instance. Multiple browsers can
  141. // * be created, and are referenced using this name.
  142. // * Argument: const char* url - The url to display.
  143. // * Argument: int x - The position and size of the browser (in pixels)
  144. // * Argument: int y
  145. // * Argument: int w
  146. // * Argument: int h
  147. // * Argument: int updateticks - When non-zero, this forces the browser image to get updated
  148. // * at the specified rate (number of milliseconds) regardless
  149. // * of paint messages. When this is zero (the default) the browser
  150. // * image is only updated whenever a paint message is received.
  151. // *
  152. // ******************************************************************************************
  153. void DX8WebBrowser::CreateBrowser(const char* browsername, const char* url, int x, int y, int w, int h, int updateticks, LONG options, LPDISPATCH gamedispatch)
  154. {
  155. 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));
  156. if(pBrowser)
  157. {
  158. _bstr_t brsname(browsername);
  159. pBrowser->CreateBrowser(brsname, _bstr_t(url), reinterpret_cast<long>(hWnd), x, y, w, h, options, gamedispatch);
  160. pBrowser->SetUpdateRate(brsname, updateticks);
  161. }
  162. }
  163. // ******************************************************************************************
  164. // * Function Name: DX8WebBrowser::DestroyBrowser
  165. // ******************************************************************************************
  166. // * Description: Destroys the specified browser. This closes the window and releases
  167. // * the browser instance.
  168. // *
  169. // * Return Type:
  170. // *
  171. // * Argument: const char* browsername - The name of the browser to destroy.
  172. // *
  173. // ******************************************************************************************
  174. void DX8WebBrowser::DestroyBrowser(const char* browsername)
  175. {
  176. WWDEBUG_SAY(("DX8WebBrowser::DestroyBrowser - destroying browser %s\n", browsername));
  177. if(pBrowser)
  178. pBrowser->DestroyBrowser(_bstr_t(browsername));
  179. }
  180. // ******************************************************************************************
  181. // * Function Name: DX8WebBrowser::Is_Browser_Open
  182. // ******************************************************************************************
  183. // * Description: This function checks to see if a browser of the specified name exists and
  184. // * is currently open.
  185. // *
  186. // * Return Type:
  187. // *
  188. // * Argument: const char* browsername - The name of the browser to test.
  189. // *
  190. // ******************************************************************************************
  191. bool DX8WebBrowser::Is_Browser_Open(const char* browsername)
  192. {
  193. if(pBrowser == 0) return false;
  194. return (pBrowser->IsOpen(_bstr_t(browsername)) != 0);
  195. }
  196. // ******************************************************************************************
  197. // * Function Name: DX8WebBrowser::Navigate
  198. // ******************************************************************************************
  199. // * Description: This function causes the browser to navigate to the specified page.
  200. // *
  201. // * Return Type:
  202. // *
  203. // * Argument: const char* browsername - The name of the browser to test.
  204. // * const char* url - The url to navigate to.
  205. // *
  206. // ******************************************************************************************
  207. void DX8WebBrowser::Navigate(const char* browsername, const char* url)
  208. {
  209. if(pBrowser == 0) return;
  210. pBrowser->Navigate(_bstr_t(browsername),_bstr_t(url));
  211. }
  212. #endif