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.

495 lines
16 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Options.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHOptions class,
  7. which is used to store the list of favorite contents.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 05/10/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. #define OFFSET1(field) offsetof(CPCHOptions, field), -1
  15. #define OFFSET2(field,flag) offsetof(CPCHOptions, field), offsetof(CPCHOptions, flag)
  16. static const WCHAR c_HSS_private[] = HC_REGISTRY_HELPCTR_USER;
  17. static const WCHAR c_HSS_ie [] = HC_REGISTRY_HELPCTR_IE;
  18. static const WCHAR c_HSS_ie_main[] = HC_REGISTRY_HELPCTR_IE L"\\Main";
  19. const CPCHOptions::OptionsDef CPCHOptions::c_tbl[] =
  20. {
  21. { c_HSS_private, L"SKU" , OFFSET1(m_ths.m_strSKU ), CPCHOptions::c_Type_STRING , false },
  22. { c_HSS_private, L"Language" , OFFSET1(m_ths.m_lLCID ), CPCHOptions::c_Type_long , false },
  23. { c_HSS_private, L"ShowFavorites" , OFFSET2(m_ShowFavorites , m_flag_ShowFavorites ), CPCHOptions::c_Type_VARIANT_BOOL, true },
  24. { c_HSS_private, L"ShowHistory" , OFFSET2(m_ShowHistory , m_flag_ShowHistory ), CPCHOptions::c_Type_VARIANT_BOOL, true },
  25. { c_HSS_private, L"FontSize" , OFFSET2(m_FontSize , m_flag_FontSize ), CPCHOptions::c_Type_FONTSIZE , true },
  26. { c_HSS_private, L"TextLabels" , OFFSET2(m_TextLabels , m_flag_TextLabels ), CPCHOptions::c_Type_TEXTLABELS , true },
  27. { c_HSS_ie_main, L"Disable Script Debugger", OFFSET2(m_DisableScriptDebugger, m_flag_DisableScriptDebugger), CPCHOptions::c_Type_DWORD , true },
  28. };
  29. const CPCHOptions::OptionsDef CPCHOptions::c_tbl_TS[] =
  30. {
  31. { HC_REGISTRY_HELPCTR, L"DefaultTerminalServerSKU" , OFFSET1(m_ths_TS.m_strSKU), CPCHOptions::c_Type_STRING, false },
  32. { HC_REGISTRY_HELPCTR, L"DefaultTerminalServerLanguage", OFFSET1(m_ths_TS.m_lLCID ), CPCHOptions::c_Type_long , false },
  33. };
  34. /////////////////////////////////////////////////////////////////////////////
  35. CPCHOptions::CPCHOptions()
  36. {
  37. m_fLoaded = false; // bool m_fLoaded;
  38. m_fDirty = false; // bool m_fDirty;
  39. m_fNoSave = false; // bool m_fNoSave;
  40. //
  41. // Taxonomy::HelpSet m_ths;
  42. // Taxonomy::HelpSet m_ths_TS;
  43. m_ShowFavorites = VARIANT_TRUE; m_flag_ShowFavorites = false; // VARIANT_BOOL m_ShowFavorites; bool m_flag_ShowFavorites;
  44. m_ShowHistory = VARIANT_TRUE; m_flag_ShowHistory = false; // VARIANT_BOOL m_ShowHistory; bool m_flag_ShowHistory;
  45. m_FontSize = OPT_MEDIUM; m_flag_FontSize = false; // OPT_FONTSIZE m_FontSize; bool m_flag_FontSize;
  46. m_TextLabels = TB_ALL; m_flag_TextLabels = false; // TB_MODE m_TextLabels; bool m_flag_TextLabels;
  47. //
  48. m_DisableScriptDebugger = 1; m_flag_DisableScriptDebugger = false; // DWORD m_DisableScriptDebugger; bool m_flag_DisableScriptDebugger;
  49. }
  50. ////////////////////
  51. CPCHOptions* CPCHOptions::s_GLOBAL( NULL );
  52. HRESULT CPCHOptions::InitializeSystem()
  53. {
  54. HRESULT hr;
  55. if(s_GLOBAL) return S_OK;
  56. if(SUCCEEDED(hr = MPC::CreateInstance( &CPCHOptions::s_GLOBAL )))
  57. {
  58. hr = CPCHOptions::s_GLOBAL->Load( /*fForce*/true );
  59. }
  60. return hr;
  61. }
  62. void CPCHOptions::FinalizeSystem()
  63. {
  64. if(s_GLOBAL)
  65. {
  66. s_GLOBAL->Release(); s_GLOBAL = NULL;
  67. }
  68. }
  69. ////////////////////////////////////////////////////////////////////////////////
  70. void CPCHOptions::ReadTable( /*[in]*/ const OptionsDef* tbl ,
  71. /*[in]*/ int len ,
  72. /*[in]*/ MPC::RegKey& rk )
  73. {
  74. HRESULT hr;
  75. const OptionsDef* ptr = tbl;
  76. const OptionsDef* ptrLast = NULL;
  77. CComVariant v;
  78. bool fFound;
  79. for(int i=0; i<len; i++, ptr++)
  80. {
  81. if(ptr->iOffsetFlag == -1)
  82. {
  83. switch(ptr->iType)
  84. {
  85. case c_Type_bool : *( (bool *)((BYTE*)this + ptr->iOffset) ) = false; break;
  86. case c_Type_long : *( (long *)((BYTE*)this + ptr->iOffset) ) = 0; break;
  87. case c_Type_DWORD : *( (DWORD *)((BYTE*)this + ptr->iOffset) ) = 0; break;
  88. case c_Type_VARIANT_BOOL: *( (VARIANT_BOOL*)((BYTE*)this + ptr->iOffset) ) = VARIANT_FALSE; break;
  89. case c_Type_STRING : *( (MPC::wstring*)((BYTE*)this + ptr->iOffset) ) = L""; break;
  90. case c_Type_FONTSIZE : *( (OPT_FONTSIZE*)((BYTE*)this + ptr->iOffset) ) = OPT_MEDIUM; break;
  91. case c_Type_TEXTLABELS : *( (TB_MODE *)((BYTE*)this + ptr->iOffset) ) = TB_SELECTED; break;
  92. }
  93. }
  94. else
  95. {
  96. *( (bool*)((BYTE*)this + ptr->iOffsetFlag) ) = false;
  97. }
  98. if(!ptrLast || wcscmp( ptr->szKey, ptrLast->szKey ))
  99. {
  100. ptrLast = NULL;
  101. if(FAILED(rk.Attach( ptr->szKey ))) continue;
  102. ptrLast = ptr;
  103. }
  104. if(FAILED(rk.get_Value( v, fFound, ptr->szValue )) || !fFound) continue;
  105. switch(ptr->iType)
  106. {
  107. case c_Type_bool : hr = v.ChangeType( VT_BOOL ); break;
  108. case c_Type_long : hr = v.ChangeType( VT_I4 ); break;
  109. case c_Type_DWORD : hr = v.ChangeType( VT_I4 ); break;
  110. case c_Type_VARIANT_BOOL: hr = v.ChangeType( VT_BOOL ); break;
  111. case c_Type_STRING : hr = v.ChangeType( VT_BSTR ); break;
  112. case c_Type_FONTSIZE : hr = v.ChangeType( VT_I4 ); break;
  113. case c_Type_TEXTLABELS : hr = v.ChangeType( VT_I4 ); break;
  114. }
  115. if(FAILED(hr)) continue;
  116. if(ptr->iOffsetFlag != -1)
  117. {
  118. *( (bool*)((BYTE*)this + ptr->iOffsetFlag) ) = true;
  119. }
  120. switch(ptr->iType)
  121. {
  122. case c_Type_bool : *( (bool *)((BYTE*)this + ptr->iOffset) ) = v.boolVal == VARIANT_TRUE; break;
  123. case c_Type_long : *( (long *)((BYTE*)this + ptr->iOffset) ) = v.lVal ; break;
  124. case c_Type_DWORD : *( (DWORD *)((BYTE*)this + ptr->iOffset) ) = v.lVal ; break;
  125. case c_Type_VARIANT_BOOL: *( (VARIANT_BOOL*)((BYTE*)this + ptr->iOffset) ) = v.boolVal ; break;
  126. case c_Type_STRING : *( (MPC::wstring*)((BYTE*)this + ptr->iOffset) ) = SAFEBSTR( v.bstrVal) ; break;
  127. case c_Type_FONTSIZE : *( (OPT_FONTSIZE*)((BYTE*)this + ptr->iOffset) ) = (OPT_FONTSIZE)v.lVal ; break;
  128. case c_Type_TEXTLABELS : *( (TB_MODE *)((BYTE*)this + ptr->iOffset) ) = (TB_MODE )v.lVal ; break;
  129. }
  130. }
  131. }
  132. void CPCHOptions::WriteTable( /*[in]*/ const OptionsDef* tbl ,
  133. /*[in]*/ int len ,
  134. /*[in]*/ MPC::RegKey& rk )
  135. {
  136. HRESULT hr;
  137. const OptionsDef* ptr = c_tbl;
  138. const OptionsDef* ptrLast = NULL;
  139. CComVariant v;
  140. bool fFound;
  141. for(int i=0; i<len; i++, ptr++)
  142. {
  143. if(!ptr->fSaveAlways && m_fNoSave) continue;
  144. if(ptr->iOffsetFlag != -1)
  145. {
  146. if(*( (bool*)((BYTE*)this + ptr->iOffsetFlag) ) == false) continue;
  147. }
  148. if(!ptrLast || wcscmp( ptr->szKey, ptrLast->szKey ))
  149. {
  150. ptrLast = NULL;
  151. if(FAILED(rk.Attach( ptr->szKey ))) continue;
  152. if(FAILED(rk.Create( ))) continue;
  153. ptrLast = ptr;
  154. }
  155. switch(ptr->iType)
  156. {
  157. case c_Type_bool : v.Clear(); v.vt = VT_BOOL; v.boolVal = *( (bool *)((BYTE*)this + ptr->iOffset) ) ? VARIANT_TRUE : VARIANT_FALSE; break;
  158. case c_Type_long : v = *( (long *)((BYTE*)this + ptr->iOffset) ) ; break;
  159. case c_Type_DWORD : v = (long)*( (DWORD *)((BYTE*)this + ptr->iOffset) ) ; break;
  160. case c_Type_VARIANT_BOOL: v.Clear(); v.vt = VT_BOOL; v.boolVal = *( (VARIANT_BOOL*)((BYTE*)this + ptr->iOffset) ) ; break;
  161. case c_Type_STRING : v = ( (MPC::wstring*)((BYTE*)this + ptr->iOffset) )->c_str() ; break;
  162. case c_Type_FONTSIZE : v = (long)*( (OPT_FONTSIZE*)((BYTE*)this + ptr->iOffset) ) ; break;
  163. case c_Type_TEXTLABELS : v = (long)*( (TB_MODE *)((BYTE*)this + ptr->iOffset) ) ; break;
  164. }
  165. (void)rk.put_Value( v, ptr->szValue, /*fExpand*/false );
  166. }
  167. }
  168. /////////////////////////////////////////////////////////////////////////////
  169. HRESULT CPCHOptions::Load( /*[in]*/ bool fForce )
  170. {
  171. __HCP_FUNC_ENTRY( "CPCHOptions::Load" );
  172. HRESULT hr;
  173. if(!m_fLoaded || fForce)
  174. {
  175. MPC::RegKey rk;
  176. __MPC_EXIT_IF_METHOD_FAILS(hr, rk.SetRoot( HKEY_CURRENT_USER, KEY_READ )); ReadTable( c_tbl, ARRAYSIZE(c_tbl), rk );
  177. if(::GetSystemMetrics( SM_REMOTESESSION ))
  178. {
  179. __MPC_EXIT_IF_METHOD_FAILS(hr, rk.SetRoot( HKEY_LOCAL_MACHINE, KEY_READ )); ReadTable( c_tbl_TS, ARRAYSIZE(c_tbl_TS), rk );
  180. }
  181. m_fLoaded = true;
  182. }
  183. hr = S_OK;
  184. __HCP_FUNC_CLEANUP;
  185. __HCP_FUNC_EXIT(hr);
  186. }
  187. HRESULT CPCHOptions::Save( /*[in]*/ bool fForce )
  188. {
  189. __HCP_FUNC_ENTRY( "CPCHOptions::Save" );
  190. HRESULT hr;
  191. if(m_fDirty)
  192. {
  193. MPC::RegKey rk;
  194. __MPC_EXIT_IF_METHOD_FAILS(hr, rk.SetRoot( HKEY_CURRENT_USER, KEY_ALL_ACCESS )); WriteTable( c_tbl, ARRAYSIZE(c_tbl), rk );
  195. m_fDirty = false;
  196. }
  197. hr = S_OK;
  198. __HCP_FUNC_CLEANUP;
  199. __HCP_FUNC_EXIT(hr);
  200. }
  201. /////////////////////////////////////////////////////////////////////////////
  202. #define GET_BEGIN(hr,pVal) \
  203. HRESULT hr; \
  204. \
  205. if(!pVal) return E_POINTER; \
  206. \
  207. if(FAILED(hr = Load( /*fForce*/false ))) return hr
  208. #define GET_END(hr) \
  209. return hr
  210. #define PUT_BEGIN(hr) \
  211. HRESULT hr; \
  212. \
  213. if(FAILED(hr = Load( /*fForce*/false ))) return hr
  214. #define PUT_END(hr) \
  215. m_fDirty = true; \
  216. return S_OK
  217. STDMETHODIMP CPCHOptions::get_ShowFavorites( /*[out, retval]*/ VARIANT_BOOL *pVal )
  218. {
  219. GET_BEGIN(hr,pVal);
  220. *pVal = m_ShowFavorites;
  221. GET_END(hr);
  222. }
  223. STDMETHODIMP CPCHOptions::put_ShowFavorites( /*[in]*/ VARIANT_BOOL newVal )
  224. {
  225. PUT_BEGIN(hr);
  226. m_ShowFavorites = newVal;
  227. m_flag_ShowFavorites = true;
  228. PUT_END(hr);
  229. }
  230. STDMETHODIMP CPCHOptions::get_ShowHistory( /*[out, retval]*/ VARIANT_BOOL *pVal )
  231. {
  232. GET_BEGIN(hr,pVal);
  233. *pVal = m_ShowHistory;
  234. GET_END(hr);
  235. }
  236. STDMETHODIMP CPCHOptions::put_ShowHistory( /*[in]*/ VARIANT_BOOL newVal )
  237. {
  238. PUT_BEGIN(hr);
  239. m_ShowHistory = newVal;
  240. m_flag_ShowHistory = true;
  241. PUT_END(hr);
  242. }
  243. STDMETHODIMP CPCHOptions::get_FontSize( /*[out, retval]*/ OPT_FONTSIZE *pVal )
  244. {
  245. GET_BEGIN(hr,pVal);
  246. *pVal = m_FontSize;
  247. GET_END(hr);
  248. }
  249. STDMETHODIMP CPCHOptions::put_FontSize( /*[in]*/ OPT_FONTSIZE newVal )
  250. {
  251. PUT_BEGIN(hr);
  252. m_FontSize = newVal;
  253. m_flag_FontSize = true;
  254. PUT_END(hr);
  255. }
  256. STDMETHODIMP CPCHOptions::get_TextLabels( /*[out, retval]*/ TB_MODE *pVal )
  257. {
  258. GET_BEGIN(hr,pVal);
  259. *pVal = m_TextLabels;
  260. GET_END(hr);
  261. }
  262. STDMETHODIMP CPCHOptions::put_TextLabels( /*[in]*/ TB_MODE newVal )
  263. {
  264. PUT_BEGIN(hr);
  265. m_TextLabels = newVal;
  266. m_flag_TextLabels = true;
  267. PUT_END(hr);
  268. }
  269. STDMETHODIMP CPCHOptions::get_DisableScriptDebugger( /*[out, retval]*/ VARIANT_BOOL *pVal )
  270. {
  271. GET_BEGIN(hr,pVal);
  272. *pVal = m_DisableScriptDebugger ? VARIANT_TRUE : VARIANT_FALSE;
  273. GET_END(hr);
  274. }
  275. STDMETHODIMP CPCHOptions::put_DisableScriptDebugger( /*[in]*/ VARIANT_BOOL newVal )
  276. {
  277. PUT_BEGIN(hr);
  278. m_DisableScriptDebugger = (newVal == VARIANT_TRUE) ? 1 : 0;
  279. m_flag_DisableScriptDebugger = true;
  280. PUT_END(hr);
  281. }
  282. STDMETHODIMP CPCHOptions::Apply()
  283. {
  284. __HCP_FUNC_ENTRY( "CPCHOptions::Apply" );
  285. HRESULT hr;
  286. CPCHHelpCenterExternal* ext = CPCHHelpCenterExternal::s_GLOBAL;
  287. if(!ext)
  288. {
  289. __MPC_SET_ERROR_AND_EXIT(hr, E_POINTER);
  290. }
  291. (void)Save();
  292. __MPC_EXIT_IF_METHOD_FAILS(hr, ext->Events().FireEvent_OptionsChanged());
  293. {
  294. for(int i = HSCPANEL_NAVBAR; i<= HSCPANEL_HHWINDOW; i++)
  295. {
  296. IMarsPanel* pPanel = ext->Panel( (HscPanel)i );
  297. if(pPanel)
  298. {
  299. CComPtr<IDispatch> disp;
  300. if(i == HSCPANEL_HHWINDOW)
  301. {
  302. CComPtr<IWebBrowser2> wb2; wb2.Attach( ext->HHWindow() );
  303. disp = wb2;
  304. }
  305. else
  306. {
  307. (void)pPanel->get_content( &disp );
  308. }
  309. __MPC_EXIT_IF_METHOD_FAILS(hr, ApplySettings( ext, disp ));
  310. }
  311. }
  312. }
  313. {
  314. IMarsWindowOM* shell = ext->Shell();
  315. if(shell)
  316. {
  317. __MPC_EXIT_IF_METHOD_FAILS(hr, shell->refreshLayout());
  318. }
  319. }
  320. hr = S_OK;
  321. __HCP_FUNC_CLEANUP;
  322. __HCP_FUNC_EXIT(hr);
  323. }
  324. HRESULT CPCHOptions::put_CurrentHelpSet( /*[in]*/ Taxonomy::HelpSet& ths )
  325. {
  326. PUT_BEGIN(hr);
  327. m_ths = ths;
  328. PUT_END(hr);
  329. }
  330. ////////////////////////////////////////////////////////////////////////////////
  331. HRESULT CPCHOptions::ApplySettings( /*[in]*/ CPCHHelpCenterExternal* ext, /*[in]*/ IUnknown* unk )
  332. {
  333. __HCP_FUNC_ENTRY( "CPCHOptions::ApplySettings" );
  334. HRESULT hr;
  335. CComQIPtr<IOleCommandTarget> oct( unk );
  336. if(oct)
  337. {
  338. CComVariant vIn;
  339. CComVariant vOut;
  340. if(SUCCEEDED(oct->Exec( 0, OLECMDID_GETZOOMRANGE, OLECMDEXECOPT_DONTPROMPTUSER, NULL, &vOut )) && vOut.vt == VT_I4)
  341. {
  342. int iZoomMin = (SHORT)LOWORD(vOut.lVal);
  343. int iZoomMax = (SHORT)HIWORD(vOut.lVal);
  344. int iZoom;
  345. switch(m_FontSize)
  346. {
  347. case OPT_SMALL : iZoom = iZoomMin + 1 ; break;
  348. case OPT_MEDIUM: iZoom = (iZoomMin + iZoomMax + 1)/2; break;
  349. case OPT_LARGE : iZoom = iZoomMax - 1 ; break;
  350. }
  351. vIn = (long)iZoom;
  352. (void)oct->Exec( 0, OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &vIn, &vOut );
  353. }
  354. }
  355. hr = S_OK;
  356. __HCP_FUNC_EXIT(hr);
  357. }