DlgWebPage.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. ** Command & Conquer Renegade(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. * NAME
  21. * $Archive: /Commando/Code/Commando/DlgWebPage.cpp $
  22. *
  23. * DESCRIPTION
  24. * Web Browser dialog
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 9 $
  32. * $Modtime: 10/30/01 10:08p $
  33. *
  34. ******************************************************************************/
  35. #include "DlgWebPage.h"
  36. #include "WebBrowser.h"
  37. #include <WWUI\PopupDialog.h>
  38. #include <WWUI\DialogControl.h>
  39. #include <Combat\DirectInput.h>
  40. #include <WW3D2\WW3D.h>
  41. #include "DlgMessageBox.h"
  42. #include "Resource.h"
  43. #include <Combat\String_IDs.h>
  44. #include "WWDebug.h"
  45. /******************************************************************************
  46. *
  47. * NAME
  48. * DlgWebPage::DoDialog
  49. *
  50. * DESCRIPTION
  51. * Show the specified web page.
  52. *
  53. * INPUTS
  54. * Page - Page to display.
  55. *
  56. * RESULT
  57. * NONE
  58. *
  59. ******************************************************************************/
  60. void DlgWebPage::DoDialog(char* page)
  61. {
  62. WWASSERT_PRINT(page && (strlen(page) > 0), "Invalid parameter.\n");
  63. if ((page == NULL) || (strlen(page) == 0))
  64. {
  65. return;
  66. }
  67. DlgWebPage* dialog = new DlgWebPage;
  68. if (dialog)
  69. {
  70. bool success = dialog->FinalizeCreate();
  71. if (success)
  72. {
  73. // If we are using the embedded browser then show the webpage. Otherwise
  74. // ask the user if they want to launch an external browser to view the page.
  75. if (dialog->mBrowser->UsingEmbeddedBrowser())
  76. {
  77. dialog->Start_Dialog();
  78. dialog->mBrowser->ShowWebPage(page);
  79. }
  80. else
  81. {
  82. // Increment the dialog reference so the dialog will be around for the
  83. // message box result.
  84. dialog->Add_Ref();
  85. dialog->mPage = page;
  86. DlgMsgBox::DoDialog(0, IDS_WEB_LAUNCHBROWSER,
  87. DlgMsgBox::YesNo, static_cast< Observer<DlgMsgBoxEvent>* >(dialog));
  88. }
  89. }
  90. // The dialog manager keeps a referenece to the dialog.
  91. dialog->Release_Ref();
  92. }
  93. }
  94. /******************************************************************************
  95. *
  96. * NAME
  97. * DlgWebPage::DlgWebPage
  98. *
  99. * DESCRIPTION
  100. * Default constructor
  101. *
  102. * INPUTS
  103. * NONE
  104. *
  105. * RESULT
  106. * NONE
  107. *
  108. ******************************************************************************/
  109. DlgWebPage::DlgWebPage() :
  110. DialogBaseClass(IDD_WEBPAGE),
  111. mBrowser(NULL)
  112. {
  113. WWDEBUG_SAY(("Instantiating DlgWebPage\n"));
  114. }
  115. /******************************************************************************
  116. *
  117. * NAME
  118. * DlgWebPage::~DlgWebPage
  119. *
  120. * DESCRIPTION
  121. * Destructor
  122. *
  123. * INPUTS
  124. * NONE
  125. *
  126. * RESULT
  127. * NONE
  128. *
  129. ******************************************************************************/
  130. DlgWebPage::~DlgWebPage()
  131. {
  132. WWDEBUG_SAY(("Destroying DlgWebPage\n"));
  133. if (mBrowser)
  134. {
  135. mBrowser->Release();
  136. }
  137. }
  138. /******************************************************************************
  139. *
  140. * NAME
  141. * DlgWebPage::FinalizeCreate
  142. *
  143. * DESCRIPTION
  144. * Finalize object creation. (Initialize object)
  145. *
  146. * INPUTS
  147. * NONE
  148. *
  149. * RESULT
  150. * Success - True if successful; False if failed.
  151. *
  152. ******************************************************************************/
  153. bool DlgWebPage::FinalizeCreate(void)
  154. {
  155. mBrowser = WebBrowser::CreateInstance(MainWindow);
  156. if (mBrowser)
  157. {
  158. Observer<WebEvent>::NotifyMe(*mBrowser);
  159. return true;
  160. }
  161. return false;
  162. }
  163. /******************************************************************************
  164. *
  165. * NAME
  166. * DlgWebPage::Start_Dialog
  167. *
  168. * DESCRIPTION
  169. *
  170. * INPUTS
  171. * NONE
  172. *
  173. * RESULT
  174. * NONE
  175. *
  176. ******************************************************************************/
  177. void DlgWebPage::Start_Dialog(void)
  178. {
  179. DirectInput::Unacquire();
  180. WW3D::Flip_To_Primary();
  181. DialogBaseClass::Start_Dialog();
  182. }
  183. /******************************************************************************
  184. *
  185. * NAME
  186. * DlgWebPage::End_Dialog
  187. *
  188. * DESCRIPTION
  189. *
  190. * INPUTS
  191. * NONE
  192. *
  193. * RESULT
  194. * NONE
  195. *
  196. ******************************************************************************/
  197. void DlgWebPage::End_Dialog(void)
  198. {
  199. DirectInput::Acquire();
  200. DialogBaseClass::End_Dialog();
  201. SetFocus(MainWindow);
  202. }
  203. /******************************************************************************
  204. *
  205. * NAME
  206. * DlgWebPage::On_Frame_Update
  207. *
  208. * DESCRIPTION
  209. *
  210. * INPUTS
  211. * NONE
  212. *
  213. * RESULT
  214. * NONE
  215. *
  216. ******************************************************************************/
  217. void DlgWebPage::On_Frame_Update(void)
  218. {
  219. DialogBaseClass::On_Frame_Update();
  220. if (mBrowser)
  221. {
  222. bool usingEmbedded = mBrowser->UsingEmbeddedBrowser();
  223. if (!usingEmbedded)
  224. {
  225. bool externalRunning = mBrowser->IsExternalBrowserRunning();
  226. bool gameActivated = (GameInFocus || (GetTopWindow(NULL) == MainWindow)
  227. || (GetForegroundWindow() == MainWindow));
  228. if (!externalRunning || gameActivated)
  229. {
  230. WWDEBUG_SAY(("***** Reactivating Game *****\n"));
  231. HWND topWindow = GetTopWindow(NULL);
  232. if (topWindow != MainWindow)
  233. {
  234. SetForegroundWindow(MainWindow);
  235. ShowWindow(MainWindow, SW_RESTORE);
  236. }
  237. End_Dialog();
  238. }
  239. }
  240. }
  241. }
  242. /******************************************************************************
  243. *
  244. * NAME
  245. * DlgWebPage::HandleNotification(WebEvent)
  246. *
  247. * DESCRIPTION
  248. * Handle web event notifications
  249. *
  250. * INPUTS
  251. * WebEvent - WebEvent to handle
  252. *
  253. * RESULT
  254. * NONE
  255. *
  256. ******************************************************************************/
  257. void DlgWebPage::HandleNotification(WebEvent& event)
  258. {
  259. switch (event.Event())
  260. {
  261. case WebEvent::Quit:
  262. End_Dialog();
  263. break;
  264. case WebEvent::CertificationFailed:
  265. {
  266. WebBrowser* browser = event.Subject();
  267. browser->Hide();
  268. DlgMsgBox::DoDialog(IDS_WEB_ERROR, IDS_WEB_PAGEFAILED);
  269. End_Dialog();
  270. }
  271. break;
  272. default:
  273. break;
  274. }
  275. }
  276. /******************************************************************************
  277. *
  278. * NAME
  279. * DlgWebPage::HandleNotification(DlgMsgBoxEvent)
  280. *
  281. * DESCRIPTION
  282. * Handle message box dialog event notifications
  283. *
  284. * INPUTS
  285. * DlgMsgBoxEvent - Message box event to handle.
  286. *
  287. * RESULT
  288. * NONE
  289. *
  290. ******************************************************************************/
  291. void DlgWebPage::HandleNotification(DlgMsgBoxEvent& event)
  292. {
  293. switch (event.Event())
  294. {
  295. case DlgMsgBoxEvent::Yes:
  296. // Start the dialog to monitor the external browser.
  297. Start_Dialog();
  298. mBrowser->ShowWebPage(mPage);
  299. // Release the reference we added to keep the dialog alive until this point.
  300. Release_Ref();
  301. break;
  302. case DlgMsgBoxEvent::No:
  303. // Release the reference we added to keep the dialog alive until this point.
  304. Release_Ref();
  305. break;
  306. default:
  307. break;
  308. }
  309. }