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.

206 lines
5.7 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. MarsHost.cpp
  5. Abstract:
  6. This file contains the implementation of the CHCPMarsHost class,
  7. which is used to control the behavior of Mars.
  8. Revision History:
  9. Davide Massarenti (dmassare) 08/24/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. #define SCREEN_WIDTH_MIN (800)
  14. #define SCREEN_HEIGHT_MIN (600)
  15. #define WINDOW_WIDTH_MIN (800)
  16. #define WINDOW_HEIGHT_MIN (650)
  17. /////////////////////////////////////////////////////////////////////////////
  18. HRESULT CPCHBootstrapper::ForwardQueryInterface( void* pv, REFIID iid, void** ppvObject, DWORD_PTR offset )
  19. {
  20. CPCHBootstrapper* pThis = (CPCHBootstrapper*)pv;
  21. return pThis->m_parent ? pThis->m_parent->QueryInterface( iid, ppvObject ) : E_NOINTERFACE;
  22. }
  23. STDMETHODIMP CPCHBootstrapper::SetSite(IUnknown *pUnkSite)
  24. {
  25. CComQIPtr<IServiceProvider> sp = pUnkSite;
  26. m_spUnkSite = pUnkSite;
  27. m_parent.Release();
  28. if(sp)
  29. {
  30. if(FAILED(sp->QueryService( SID_SElementBehaviorFactory, IID_IPCHHelpCenterExternal, (void **)&m_parent )) || m_parent == NULL)
  31. {
  32. //
  33. // BIG IE BUG: dialogs don't delegate properly, so we have to fix it somehow.....
  34. //
  35. (void)CPCHHelpCenterExternal::s_GLOBAL->QueryInterface( IID_IPCHHelpCenterExternal, (void **)&m_parent );
  36. }
  37. }
  38. return S_OK;
  39. }
  40. STDMETHODIMP CPCHBootstrapper::GetSite(REFIID riid, void **ppvSite)
  41. {
  42. HRESULT hRes = E_POINTER;
  43. if(ppvSite != NULL)
  44. {
  45. if(m_spUnkSite)
  46. {
  47. hRes = m_spUnkSite->QueryInterface( riid, ppvSite );
  48. }
  49. else
  50. {
  51. *ppvSite = NULL;
  52. hRes = E_FAIL;
  53. }
  54. }
  55. return hRes;
  56. }
  57. STDMETHODIMP CPCHBootstrapper::GetInterfaceSafetyOptions( /*[in ]*/ REFIID riid ,
  58. /*[out]*/ DWORD *pdwSupportedOptions ,
  59. /*[out]*/ DWORD *pdwEnabledOptions )
  60. {
  61. if(pdwSupportedOptions) *pdwSupportedOptions = 0;
  62. if(pdwEnabledOptions ) *pdwEnabledOptions = 0;
  63. if(IsEqualIID(riid, IID_IDispatch ) ||
  64. IsEqualIID(riid, IID_IDispatchEx) )
  65. {
  66. if(pdwSupportedOptions) *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
  67. if(pdwEnabledOptions ) *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
  68. }
  69. return S_OK;
  70. }
  71. STDMETHODIMP CPCHBootstrapper::SetInterfaceSafetyOptions( /*[in]*/ REFIID riid ,
  72. /*[in]*/ DWORD dwOptionSetMask ,
  73. /*[in]*/ DWORD dwEnabledOptions )
  74. {
  75. return S_OK;
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. CPCHMarsHost::CPCHMarsHost()
  79. {
  80. m_parent = NULL; // CPCHHelpCenterExternal* m_parent;
  81. // MPC::wstring m_strTitle;
  82. // MPC::wstring m_strCmdLine;
  83. // MARSTHREADPARAM m_mtp;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. HRESULT CPCHMarsHost::Init( /*[in]*/ CPCHHelpCenterExternal* parent, /*[in]*/ const MPC::wstring& szTitle, /*[out]*/ MARSTHREADPARAM*& pMTP )
  87. {
  88. __HCP_FUNC_ENTRY( "CPCHMarsHost::Init" );
  89. HRESULT hr;
  90. HINSTANCE hInst = ::GetModuleHandle( NULL );
  91. HICON hIcon = ::LoadIcon( hInst, MAKEINTRESOURCE(IDI_HELPCENTER) );
  92. m_parent = parent;
  93. m_strTitle = szTitle;
  94. m_strCmdLine = HC_HELPSET_ROOT HC_HELPSET_SUB_SYSTEM L"\\HelpCtr.mmf"; MPC::SubstituteEnvVariables( m_strCmdLine );
  95. ::ZeroMemory( &m_mtp, sizeof(m_mtp) ); m_mtp.cbSize = sizeof(m_mtp);
  96. m_mtp.hIcon = hIcon;
  97. m_mtp.nCmdShow = SW_SHOWDEFAULT;
  98. m_mtp.pwszTitle = m_strTitle .c_str();
  99. m_mtp.pwszPanelURL = m_strCmdLine.c_str();
  100. if(parent->DoesPersistSettings())
  101. {
  102. m_mtp.dwFlags |= MTF_MANAGE_WINDOW_SIZE;
  103. }
  104. if(parent->CanDisplayWindow () == false ||
  105. parent->HasLayoutDefinition() == true )
  106. {
  107. m_mtp.dwFlags |= MTF_DONT_SHOW_WINDOW;
  108. }
  109. pMTP = &m_mtp;
  110. hr = S_OK;
  111. // __HCP_FUNC_CLEANUP;
  112. __HCP_FUNC_EXIT(hr);
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. STDMETHODIMP CPCHMarsHost::OnHostNotify( /*[in]*/ MARSHOSTEVENT event ,
  116. /*[in]*/ IUnknown *punk ,
  117. /*[in]*/ LPARAM lParam )
  118. {
  119. if(event == MARSHOST_ON_WIN_SETPOS)
  120. {
  121. WINDOWPLACEMENT* wp = (WINDOWPLACEMENT*)lParam;
  122. //
  123. // Only adjust size if it's the first time through and not a controlled invocation.
  124. //
  125. if(wp && m_parent && m_parent->DoesPersistSettings() && !(m_mtp.dwFlags & MTF_RESTORING_FROM_REGISTRY))
  126. {
  127. RECT rc;
  128. //
  129. // If the screen is large enough, don't open always maximized.
  130. //
  131. if(::SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 ))
  132. {
  133. LONG Screen_width = rc.right - rc.left;
  134. LONG Screen_height = rc.bottom - rc.top;
  135. LONG Window_height = wp->rcNormalPosition.bottom - wp->rcNormalPosition.top;
  136. if(Screen_width < SCREEN_WIDTH_MIN ||
  137. Screen_height < SCREEN_HEIGHT_MIN )
  138. {
  139. wp->showCmd = SW_MAXIMIZE;
  140. }
  141. else if(Window_height < WINDOW_HEIGHT_MIN)
  142. {
  143. wp->rcNormalPosition.top = rc.top + (Screen_height - WINDOW_HEIGHT_MIN) / 2;
  144. wp->rcNormalPosition.bottom = wp->rcNormalPosition.top + WINDOW_HEIGHT_MIN;
  145. }
  146. }
  147. }
  148. return S_OK;
  149. }
  150. return m_parent->OnHostNotify( event, punk, lParam );
  151. }
  152. ////////////////////////////////////////////////////////////////////////////////
  153. STDMETHODIMP CPCHMarsHost::PreTranslateMessage( /*[in]*/ MSG* msg )
  154. {
  155. return m_parent->PreTranslateMessage( msg );
  156. }