Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
7.8 KiB

  1. /****************************************************************************
  2. *
  3. * ICWWEBVW.cpp
  4. *
  5. * Microsoft Confidential
  6. * Copyright (c) Microsoft Corporation 1992-1997
  7. * All rights reserved
  8. *
  9. * This module provides the implementation of the methods for
  10. * the CICWApprentice class.
  11. *
  12. * 07/22/98 donaldm adapted from ICWCONNN
  13. *
  14. ***************************************************************************/
  15. #include "pre.h"
  16. #include "initguid.h"
  17. #include "webvwids.h"
  18. #define VK_N 'N'
  19. #define VK_P 'P'
  20. HRESULT CICWWebView::get_BrowserObject
  21. (
  22. IWebBrowser2 **lpWebBrowser
  23. )
  24. {
  25. ASSERT(m_lpOleSite);
  26. *lpWebBrowser = m_lpOleSite->m_lpWebBrowser;
  27. return S_OK;
  28. }
  29. HRESULT CICWWebView::ConnectToWindow
  30. (
  31. HWND hWnd,
  32. DWORD dwHtmPageType
  33. )
  34. {
  35. ASSERT(m_lpOleSite);
  36. // Set the window long to be this object pointer, since it will be used by the
  37. // wnd proc, assuming it is a WebOC class window attaching
  38. SetWindowLongPtr(hWnd,GWLP_USERDATA,(LPARAM) this);
  39. m_lpOleSite->ConnectBrowserObjectToWindow(hWnd,
  40. dwHtmPageType,
  41. m_bUseBkGndBitmap,
  42. m_hBkGrndBitmap,
  43. &m_rcBkGrnd,
  44. m_szBkGrndColor,
  45. m_szForeGrndColor);
  46. return S_OK;
  47. }
  48. #ifndef UNICODE
  49. HRESULT CICWWebView::DisplayHTML
  50. (
  51. TCHAR * lpszURL
  52. )
  53. {
  54. BSTR bstrURL;
  55. ASSERT(m_lpOleSite);
  56. // Convert to a BSTR for the call to the web browser object
  57. bstrURL = A2W(lpszURL);
  58. // Navigate the Webbrowser object to the requested page
  59. return (m_lpOleSite->m_lpWebBrowser->Navigate(bstrURL, PVAREMPTY, PVAREMPTY, PVAREMPTY, PVAREMPTY));
  60. }
  61. #endif
  62. HRESULT CICWWebView::DisplayHTML
  63. (
  64. BSTR bstrURL
  65. )
  66. {
  67. ASSERT(m_lpOleSite);
  68. // Navigate the Webbrowser object to the requested page
  69. return (m_lpOleSite->m_lpWebBrowser->Navigate(bstrURL, PVAREMPTY, PVAREMPTY, PVAREMPTY, PVAREMPTY));
  70. }
  71. HRESULT CICWWebView::SetHTMLColors
  72. (
  73. LPTSTR lpszForeground,
  74. LPTSTR lpszBackground
  75. )
  76. {
  77. if (NULL == lpszForeground || ('\0' == lpszForeground[0]))
  78. {
  79. lstrcpyn(m_szForeGrndColor, HTML_DEFAULT_COLOR, MAX_COLOR_NAME);
  80. }
  81. else
  82. {
  83. lstrcpyn(m_szForeGrndColor, lpszForeground, MAX_COLOR_NAME);
  84. }
  85. if (NULL == lpszBackground || ('\0' == lpszBackground[0]))
  86. {
  87. lstrcpyn(m_szBkGrndColor, HTML_DEFAULT_BGCOLOR, MAX_COLOR_NAME);
  88. }
  89. else
  90. {
  91. lstrcpyn(m_szBkGrndColor, lpszBackground, MAX_COLOR_NAME);
  92. }
  93. return S_OK;
  94. }
  95. HRESULT CICWWebView::SetHTMLBackgroundBitmap
  96. (
  97. HBITMAP hbm,
  98. LPRECT lpRC
  99. )
  100. {
  101. if (NULL != hbm)
  102. {
  103. m_hBkGrndBitmap = hbm;
  104. CopyRect(&m_rcBkGrnd, lpRC);
  105. m_bUseBkGndBitmap = TRUE;
  106. }
  107. else
  108. {
  109. m_hBkGrndBitmap = NULL;
  110. m_bUseBkGndBitmap = FALSE;
  111. }
  112. return S_OK;
  113. }
  114. HRESULT CICWWebView::HandleKey
  115. (
  116. LPMSG lpMsg
  117. )
  118. {
  119. HRESULT hr = E_FAIL;
  120. ASSERT(m_lpOleSite);
  121. switch(lpMsg->message)
  122. {
  123. case WM_KEYDOWN:
  124. {
  125. //needed to disable certain default IE hot key combos. like launching a new browser window.
  126. if ((lpMsg->wParam == VK_RETURN) || (lpMsg->wParam == VK_F5) || (((lpMsg->wParam == VK_N) || (lpMsg->wParam == VK_P) ) && (GetKeyState(VK_CONTROL) & 0x1000)))
  127. break;
  128. }
  129. default:
  130. {
  131. if(m_lpOleSite->m_lpWebBrowser)
  132. {
  133. IOleInPlaceActiveObject* lpIPA;
  134. if(SUCCEEDED(m_lpOleSite->m_lpWebBrowser->QueryInterface(IID_IOleInPlaceActiveObject,(void**)&lpIPA)))
  135. {
  136. hr = lpIPA->TranslateAccelerator(lpMsg);
  137. lpIPA->Release();
  138. }
  139. }
  140. break;
  141. }
  142. }
  143. return (hr);
  144. }
  145. HRESULT CICWWebView::SetFocus
  146. (
  147. void
  148. )
  149. {
  150. if(m_lpOleSite->m_lpInPlaceObject && !m_lpOleSite->m_fInPlaceActive)
  151. {
  152. m_lpOleSite->InPlaceActivate();
  153. m_lpOleSite->UIActivate();
  154. }
  155. m_lpOleSite->SetFocusToHtmlPage();
  156. return S_OK;
  157. }
  158. //+----------------------------------------------------------------------------
  159. //
  160. // Function CICWWebView::QueryInterface
  161. //
  162. // Synopsis This is the standard QI, with support for
  163. // IID_Unknown, IICW_Extension and IID_ICWApprentice
  164. // (stolen from Inside COM, chapter 7)
  165. //
  166. //
  167. //-----------------------------------------------------------------------------
  168. HRESULT CICWWebView::QueryInterface( REFIID riid, void** ppv )
  169. {
  170. TraceMsg(TF_CWEBVIEW, "CICWWebView::QueryInterface");
  171. if (ppv == NULL)
  172. return(E_INVALIDARG);
  173. *ppv = NULL;
  174. // IID_IICWWebView
  175. if (IID_IICWWebView == riid)
  176. *ppv = (void *)(IICWWebView *)this;
  177. // IID_IUnknown
  178. else if (IID_IUnknown == riid)
  179. *ppv = (void *)this;
  180. else
  181. return(E_NOINTERFACE);
  182. ((LPUNKNOWN)*ppv)->AddRef();
  183. return(S_OK);
  184. }
  185. //+----------------------------------------------------------------------------
  186. //
  187. // Function CICWWebView::AddRef
  188. //
  189. // Synopsis This is the standard AddRef
  190. //
  191. //
  192. //-----------------------------------------------------------------------------
  193. ULONG CICWWebView::AddRef( void )
  194. {
  195. TraceMsg(TF_CWEBVIEW, "CICWWebView::AddRef %d", m_lRefCount + 1);
  196. return InterlockedIncrement(&m_lRefCount) ;
  197. }
  198. //+----------------------------------------------------------------------------
  199. //
  200. // Function CICWWebView::Release
  201. //
  202. // Synopsis This is the standard Release
  203. //
  204. //
  205. //-----------------------------------------------------------------------------
  206. ULONG CICWWebView::Release( void )
  207. {
  208. ASSERT( m_lRefCount > 0 );
  209. InterlockedDecrement(&m_lRefCount);
  210. TraceMsg(TF_CWEBVIEW, "CICWWebView::Release %d", m_lRefCount);
  211. if( 0 == m_lRefCount )
  212. {
  213. if (NULL != m_pServer)
  214. m_pServer->ObjectsDown();
  215. delete this;
  216. return 0;
  217. }
  218. return( m_lRefCount );
  219. }
  220. //+----------------------------------------------------------------------------
  221. //
  222. // Function CICWWebView::CICWWebView
  223. //
  224. // Synopsis This is the constructor, nothing fancy
  225. //
  226. //-----------------------------------------------------------------------------
  227. CICWWebView::CICWWebView
  228. (
  229. CServer* pServer
  230. )
  231. {
  232. TraceMsg(TF_CWEBVIEW, "CICWWebView constructor called");
  233. m_lRefCount = 0;
  234. // Assign the pointer to the server control object.
  235. m_pServer = pServer;
  236. m_bUseBkGndBitmap = FALSE;
  237. lstrcpyn(m_szBkGrndColor, HTML_DEFAULT_BGCOLOR, MAX_COLOR_NAME);
  238. lstrcpyn(m_szForeGrndColor, HTML_DEFAULT_COLOR, MAX_COLOR_NAME);
  239. // Create a new OLE site, which will create an instance of the WebBrowser
  240. m_lpOleSite = new COleSite();
  241. if (m_lpOleSite)
  242. m_lpOleSite->CreateBrowserObject();
  243. }
  244. //+----------------------------------------------------------------------------
  245. //
  246. // Function CICWWebView::~CICWWebView
  247. //
  248. // Synopsis This is the destructor. We want to clean up all the memory
  249. // we allocated in ::Initialize
  250. //
  251. //-----------------------------------------------------------------------------
  252. CICWWebView::~CICWWebView( void )
  253. {
  254. TraceMsg(TF_CWEBVIEW, "CICWWebView destructor called with ref count of %d", m_lRefCount);
  255. if (m_lpOleSite)
  256. {
  257. m_lpOleSite->Release();
  258. delete m_lpOleSite;
  259. }
  260. }