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.

378 lines
10 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. MarsHost.cpp
  5. Abstract:
  6. Initialization of mars
  7. Revision History:
  8. Anand Arvind (aarvind) 2000-01-05
  9. created
  10. Seong Kook Khang (SKKhang) 05/10/00
  11. Clean up, merge with MarsEvnt.cpp, etc. for Whistler.
  12. ******************************************************************************/
  13. #include "stdwin.h"
  14. #include "stdatl.h"
  15. #include "rstrpriv.h"
  16. #include "rstrmgr.h"
  17. #include "MarsHost.h"
  18. /////////////////////////////////////////////////////////////////////////////
  19. //
  20. // CSRWebBrowserEvents
  21. //
  22. /////////////////////////////////////////////////////////////////////////////
  23. CSRWebBrowserEvents::CSRWebBrowserEvents()
  24. {
  25. }
  26. CSRWebBrowserEvents::~CSRWebBrowserEvents()
  27. {
  28. Detach();
  29. }
  30. void CSRWebBrowserEvents::Attach( /*[in]*/ IWebBrowser2* pWB )
  31. {
  32. Detach();
  33. m_pWB2 = pWB;
  34. if( m_pWB2 )
  35. {
  36. CSRWebBrowserEvents_DispWBE2::DispEventAdvise( m_pWB2 );
  37. }
  38. }
  39. void CSRWebBrowserEvents::Detach()
  40. {
  41. if( m_pWB2 )
  42. {
  43. CSRWebBrowserEvents_DispWBE2::DispEventUnadvise( m_pWB2 );
  44. m_pWB2.Release();
  45. }
  46. }
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CSRWebBrowserEvents - DWebBrowserEvents2 event methods
  49. void __stdcall CSRWebBrowserEvents::BeforeNavigate2( IDispatch *pDisp,
  50. VARIANT *URL,
  51. VARIANT *Flags,
  52. VARIANT *TargetFrameName,
  53. VARIANT *PostData,
  54. VARIANT *Headers,
  55. VARIANT_BOOL *Cancel )
  56. {
  57. //
  58. // We control navigation with the CanNavigatePage but for all help links
  59. // navigation should be auto-enabled. All Help links have a OnLink_ as
  60. // part of the URL so if this is contained in the URL
  61. //
  62. if( V_BSTR(URL) != NULL && wcsstr( V_BSTR(URL), L"OnLink_") != NULL )
  63. {
  64. *Cancel = VARIANT_FALSE ;
  65. }
  66. else
  67. {
  68. if ( g_pRstrMgr->GetCanNavigatePage() )
  69. {
  70. *Cancel = VARIANT_FALSE ;
  71. }
  72. else
  73. {
  74. *Cancel = VARIANT_TRUE ;
  75. }
  76. };
  77. }
  78. void __stdcall CSRWebBrowserEvents::NewWindow2( IDispatch **ppDisp,
  79. VARIANT_BOOL *Cancel )
  80. {
  81. }
  82. void __stdcall CSRWebBrowserEvents::NavigateComplete2( IDispatch *pDisp,
  83. VARIANT *URL )
  84. {
  85. }
  86. void __stdcall CSRWebBrowserEvents::DocumentComplete( IDispatch *pDisp,
  87. VARIANT *URL )
  88. {
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. //
  92. // CSRMarsHost
  93. //
  94. /////////////////////////////////////////////////////////////////////////////
  95. //#define PANEL_NAVBAR L"NavBar"
  96. #define PANEL_CONTENTS L"Contents"
  97. CSRMarsHost::CSRMarsHost()
  98. {
  99. m_fPassivated = false;
  100. m_cWebBrowserEvents = NULL;
  101. }
  102. CSRMarsHost::~CSRMarsHost()
  103. {
  104. (void)Passivate();
  105. if ( m_cWebBrowserEvents )
  106. {
  107. m_cWebBrowserEvents->Release();
  108. }
  109. }
  110. HRESULT CSRMarsHost::FinalConstruct()
  111. {
  112. HRESULT hr = S_OK ;
  113. hr = CSRWebBrowserEvents_Object::CreateInstance( &m_cWebBrowserEvents );
  114. if ( FAILED(hr) )
  115. goto Exit;
  116. m_cWebBrowserEvents->AddRef();
  117. Exit:
  118. return( hr );
  119. }
  120. HRESULT CSRMarsHost::Passivate()
  121. {
  122. m_fPassivated = true;
  123. if ( m_cWebBrowserEvents )
  124. {
  125. m_cWebBrowserEvents->Detach();
  126. }
  127. return( S_OK );
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CSRMarsHost - IMarsHost methods
  131. STDMETHODIMP CSRMarsHost::OnHostNotify( /*[in]*/ MARSHOSTEVENT event,
  132. /*[in]*/ IUnknown *punk,
  133. /*[in]*/ LPARAM lParam )
  134. {
  135. HRESULT hr;
  136. if( event == MARSHOST_ON_WIN_INIT )
  137. {
  138. g_pRstrMgr->SetFrameHwnd( (HWND)lParam );
  139. }
  140. if( event == MARSHOST_ON_WIN_PASSIVATE )
  141. {
  142. g_pRstrMgr->SetFrameHwnd( NULL );
  143. }
  144. //
  145. // Handle panel-related things.
  146. //
  147. if( event == MARSHOST_ON_PANEL_CONTROL_CREATE )
  148. {
  149. CComQIPtr<IMarsPanel> panel = punk;
  150. if( panel )
  151. {
  152. CComBSTR name;
  153. hr = panel->get_name( &name );
  154. if( FAILED(hr) )
  155. {
  156. goto Exit;
  157. }
  158. if( name == PANEL_CONTENTS )
  159. {
  160. CComPtr<IDispatch> disp;
  161. if( SUCCEEDED(panel->get_content( &disp )) )
  162. {
  163. CComQIPtr<IWebBrowser2> wb2( disp );
  164. if( wb2 )
  165. {
  166. wb2->put_RegisterAsDropTarget( VARIANT_FALSE );
  167. m_cWebBrowserEvents->Attach( wb2 );
  168. }
  169. }
  170. }
  171. }
  172. }
  173. hr = S_OK;
  174. Exit:
  175. return( hr );
  176. }
  177. STDMETHODIMP CSRMarsHost::OnNewWindow2( /*[in,out]*/ IDispatch **ppDisp ,
  178. /*[in,out]*/ VARIANT_BOOL *Cancel )
  179. {
  180. return( S_OK );
  181. }
  182. STDMETHODIMP CSRMarsHost::FindBehavior( /*[in]*/ IMarsPanel *pPanel,
  183. /*[in]*/ BSTR bstrBehavior,
  184. /*[in]*/ BSTR bstrBehaviorUrl,
  185. /*[in]*/ IElementBehaviorSite *pSite,
  186. /*[retval, out]*/ IElementBehavior **ppBehavior )
  187. {
  188. return( S_OK );
  189. }
  190. STDMETHODIMP CSRMarsHost::OnShowChrome( /*[in]*/ BSTR bstrWebPanel,
  191. /*[in]*/ DISPID dispidEvent,
  192. /*[in]*/ BOOL fVisible,
  193. /*[in]*/ BSTR bstrCurrentPlace,
  194. /*[in]*/ IMarsPanelCollection *pMarsPanelCollection )
  195. {
  196. return( S_OK );
  197. }
  198. STDMETHODIMP CSRMarsHost::PreTranslateMessage( /*[in]*/ MSG *msg )
  199. {
  200. HRESULT hr = S_OK;
  201. switch( msg->message )
  202. {
  203. case WM_CLOSE:
  204. {
  205. if ( g_pRstrMgr->DenyClose() )
  206. {
  207. goto Exit; // Cancel close when restoring
  208. }
  209. }
  210. break;
  211. case WM_DISPLAYCHANGE :
  212. {
  213. //
  214. // If display changes to 640x480 from something higher then
  215. // the window has to be resized to fit in the new display
  216. //
  217. RECT rc;
  218. DWORD dwWidth = LOWORD(msg->lParam);
  219. DWORD dwHeight = HIWORD(msg->lParam);
  220. CWindow cWnd;
  221. cWnd.Attach( msg->hwnd );
  222. if ( dwHeight < 540 )
  223. {
  224. rc.left = 0;
  225. rc.top = 0;
  226. rc.right = 620;
  227. rc.bottom = 420;
  228. //g_cRestoreShell.m_dwCurrentWidth = rc.right ;
  229. //g_cRestoreShell.m_dwCurrentHeight = rc.bottom ;
  230. ::AdjustWindowRectEx( &rc, cWnd.GetStyle(), FALSE, cWnd.GetExStyle() );
  231. ::SetWindowPos(msg->hwnd,
  232. NULL,
  233. 0,
  234. 0,
  235. rc.right-rc.left,
  236. rc.bottom-rc.top,
  237. SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER);
  238. cWnd.CenterWindow(::GetDesktopWindow()); // ignore error return if any
  239. }
  240. else
  241. {
  242. rc.left = 0;
  243. rc.top = 0;
  244. rc.right = 770;
  245. rc.bottom = 540;
  246. //g_cRestoreShell.m_dwCurrentWidth = rc.right ;
  247. //g_cRestoreShell.m_dwCurrentHeight = rc.bottom ;
  248. ::AdjustWindowRectEx( &rc, cWnd.GetStyle(), FALSE, cWnd.GetExStyle() );
  249. ::SetWindowPos(msg->hwnd,
  250. NULL,
  251. 0,
  252. 0,
  253. rc.right-rc.left,
  254. rc.bottom-rc.top,
  255. SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER);
  256. cWnd.CenterWindow(::GetDesktopWindow()); // ignore error return if any
  257. }
  258. }
  259. break;
  260. case WM_LBUTTONDOWN:
  261. case WM_MBUTTONDOWN:
  262. case WM_RBUTTONDOWN:
  263. {
  264. if ( msg->wParam & MK_CONTROL ||
  265. msg->wParam & MK_SHIFT ||
  266. GetKeyState(VK_MENU) < 0 )
  267. {
  268. goto Exit; // IE opens link in a seperate page so force cancelling
  269. }
  270. }
  271. break;
  272. case WM_SYSKEYDOWN:
  273. case WM_SYSKEYUP:
  274. {
  275. if ( ( HIWORD(msg->lParam) & KF_ALTDOWN ) != 0 ) // Alt pressed
  276. {
  277. if ( msg->wParam == VK_LEFT ||
  278. msg->wParam == VK_RIGHT )
  279. {
  280. goto Exit; // IE does not cancel Alt-Left so force cancelling
  281. }
  282. }
  283. }
  284. break;
  285. case WM_KEYDOWN:
  286. case WM_KEYUP:
  287. {
  288. switch( msg->wParam )
  289. {
  290. case VK_F5:
  291. goto Exit; // Disable refresh...
  292. case 'N':
  293. if ( GetKeyState(VK_CONTROL) < 0 )
  294. {
  295. goto Exit; // Disable Ctrl-N combination
  296. }
  297. }
  298. }
  299. break;
  300. case WM_MOUSEWHEEL:
  301. //
  302. // Disable Mouse Wheel navigation... not used in SR
  303. //
  304. return( S_OK );
  305. }
  306. hr = E_NOTIMPL;
  307. Exit:
  308. return( hr );
  309. }
  310. // end of file