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.

186 lines
4.7 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ProtocolShell.cpp
  5. Abstract:
  6. This file contains the implementation of the CHCPProcotolShell class,
  7. just a thin wrapper around CHCPProcotolRoot and CHCPProcotolInfo.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 02/15/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. CHCPProtocolEnvironment::CHCPProtocolEnvironment()
  15. {
  16. m_fHighContrast = false; // bool m_fHighContrast;
  17. m_f16Colors = false; // bool m_f16Colors;
  18. // Taxonomy::Instance m_inst;
  19. //
  20. // MPC::string m_strCSS;
  21. UpdateState();
  22. }
  23. CHCPProtocolEnvironment::~CHCPProtocolEnvironment()
  24. {
  25. }
  26. ////////////////////
  27. CHCPProtocolEnvironment* CHCPProtocolEnvironment::s_GLOBAL( NULL );
  28. HRESULT CHCPProtocolEnvironment::InitializeSystem()
  29. {
  30. if(s_GLOBAL == NULL)
  31. {
  32. s_GLOBAL = new CHCPProtocolEnvironment;
  33. }
  34. return s_GLOBAL ? S_OK : E_OUTOFMEMORY;
  35. }
  36. void CHCPProtocolEnvironment::FinalizeSystem()
  37. {
  38. if(s_GLOBAL)
  39. {
  40. delete s_GLOBAL; s_GLOBAL = NULL;
  41. }
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. bool CHCPProtocolEnvironment::UpdateState()
  45. {
  46. DEVMODE dm;
  47. HIGHCONTRAST hc; hc.cbSize = sizeof( hc );
  48. bool fHighContrast = false;
  49. bool f16Colors = false;
  50. bool fRes;
  51. if(::EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &dm ))
  52. {
  53. if(dm.dmBitsPerPel < 8)
  54. {
  55. f16Colors = true;
  56. }
  57. }
  58. if(::SystemParametersInfo( SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0 ))
  59. {
  60. if(hc.dwFlags & HCF_HIGHCONTRASTON)
  61. {
  62. fHighContrast = true;
  63. }
  64. }
  65. fRes = (m_fHighContrast != fHighContrast) ||
  66. (m_f16Colors != f16Colors ) ||
  67. (m_strCSS.size() != 0 ) ;
  68. m_fHighContrast = fHighContrast;
  69. m_f16Colors = f16Colors;
  70. m_strCSS = "";
  71. return fRes;
  72. }
  73. void CHCPProtocolEnvironment::ReformatURL( CComBSTR& bstrURL )
  74. {
  75. if(bstrURL != NULL)
  76. {
  77. WCHAR szTmp[MAX_PATH];
  78. LPCWSTR szExtSrc;
  79. LPWSTR szExtDst;
  80. StringCchCopyW( szTmp, ARRAYSIZE(szTmp), bstrURL );
  81. szExtSrc = wcsrchr( bstrURL, '.' );
  82. szExtDst = wcsrchr( szTmp , '.' );
  83. if(szExtDst)
  84. {
  85. szExtDst[0] = 0;
  86. if(m_inst.m_fDesktop)
  87. {
  88. StringCchCatW( szTmp, ARRAYSIZE(szTmp), L"__DESKTOP" );
  89. StringCchCatW( szTmp, ARRAYSIZE(szTmp), szExtSrc );
  90. if(MPC::FileSystemObject::IsFile( szTmp ))
  91. {
  92. bstrURL = szTmp; return;
  93. }
  94. }
  95. if(m_inst.m_fServer)
  96. {
  97. StringCchCatW( szTmp, ARRAYSIZE(szTmp), L"__SERVER" );
  98. StringCchCatW( szTmp, ARRAYSIZE(szTmp), szExtSrc );
  99. if(MPC::FileSystemObject::IsFile( szTmp ))
  100. {
  101. bstrURL = szTmp; return;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. void CHCPProtocolEnvironment::SetHelpLocation( /*[in]*/ const Taxonomy::Instance& inst )
  108. {
  109. m_inst = inst;
  110. }
  111. LPCWSTR CHCPProtocolEnvironment::HelpLocation()
  112. {
  113. return m_inst.m_strHelpFiles.size() ? m_inst.m_strHelpFiles.c_str() : HC_HELPSVC_HELPFILES_DEFAULT;
  114. }
  115. LPCWSTR CHCPProtocolEnvironment::System() // Only MUI-based SKUs get relocated
  116. {
  117. return (m_inst.m_fMUI && m_inst.m_strSystem.size()) ? m_inst.m_strSystem.c_str() : HC_HELPSET_ROOT;
  118. }
  119. const Taxonomy::Instance& CHCPProtocolEnvironment::Instance()
  120. {
  121. return m_inst;
  122. }
  123. HRESULT CHCPProtocolEnvironment::GetCSS( /*[out]*/ CComPtr<IStream>& stream )
  124. {
  125. __HCP_FUNC_ENTRY( "CHCPProtocolEnvironment::GetCSS" );
  126. HRESULT hr;
  127. DWORD dwWritten;
  128. LARGE_INTEGER liFilePos = { 0, 0 };
  129. __MPC_EXIT_IF_METHOD_FAILS(hr, ProcessCSS());
  130. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CreateStreamOnHGlobal( NULL, TRUE, &stream ));
  131. __MPC_EXIT_IF_METHOD_FAILS(hr, stream->Write( m_strCSS.c_str(), m_strCSS.size(), &dwWritten ));
  132. // Rewind the Stream.
  133. __MPC_EXIT_IF_METHOD_FAILS(hr, stream->Seek( liFilePos, STREAM_SEEK_SET, NULL ));
  134. hr = S_OK;
  135. __HCP_FUNC_CLEANUP;
  136. __HCP_FUNC_EXIT(hr);
  137. }