Source code of Windows XP (NT5)
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.

134 lines
3.5 KiB

  1. // HTMLImpl.h : Declaration of the CHTMLPageImpl
  2. #ifndef __HTMLIMPL_H_
  3. #define __HTMLIMPL_H_
  4. #include "Nusrmgr.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CHTMLPageImpl
  7. template <typename T, typename I>
  8. class CHTMLPageImpl :
  9. public ITaskPage,
  10. public IDispatchImpl<I, &__uuidof(I), &LIBID_NUSRMGRLib>
  11. {
  12. public:
  13. CHTMLPageImpl() : _pTaskFrame(NULL), _pBag(NULL) {}
  14. ~CHTMLPageImpl() { ATOMICRELEASE(_pTaskFrame); ATOMICRELEASE(_pBag); }
  15. // ITaskPage
  16. public:
  17. STDMETHOD(SetFrame)(ITaskFrame* pFrame)
  18. {
  19. ATOMICRELEASE(_pTaskFrame);
  20. ATOMICRELEASE(_pBag);
  21. _pTaskFrame = pFrame;
  22. if (_pTaskFrame)
  23. {
  24. _pTaskFrame->AddRef();
  25. _pTaskFrame->GetPropertyBag(IID_IPropertyBag, (void**)&_pBag);
  26. }
  27. return S_OK;
  28. }
  29. STDMETHOD(GetObjectCount)(UINT nArea, UINT *pVal)
  30. {
  31. if (!pVal)
  32. return E_POINTER;
  33. *pVal = nArea < ARRAYSIZE(T::c_aHTML) ? 1 : 0;
  34. return S_OK;
  35. }
  36. STDMETHOD(CreateObject)(UINT nArea, UINT nIndex, REFIID riid, void **ppv)
  37. {
  38. if (nArea >= ARRAYSIZE(T::c_aHTML))
  39. return E_UNEXPECTED;
  40. CComPtr<ITaskUI_HTMLControl> spContent;
  41. HRESULT hr = spContent.CoCreateInstance(__uuidof(TaskUI_HTMLControl));
  42. if (SUCCEEDED(hr))
  43. {
  44. hr = spContent->Initialize((BSTR)T::c_aHTML[nArea], static_cast<I*>(this));
  45. if (SUCCEEDED(hr))
  46. {
  47. hr = spContent->QueryInterface(riid, ppv);
  48. }
  49. }
  50. return hr;
  51. }
  52. STDMETHOD(Reinitialize)(/*[in]*/ ULONG /*reserved*/)
  53. {
  54. return E_NOTIMPL;
  55. }
  56. // IExternalUI
  57. public:
  58. STDMETHOD(get_cssPath)(/*[out, retval]*/ BSTR *pVal)
  59. {
  60. if (NULL == pVal)
  61. return E_POINTER;
  62. *pVal = NULL;
  63. if (NULL == _pBag)
  64. return E_UNEXPECTED;
  65. CComVariant var;
  66. if (SUCCEEDED(_pBag->Read(UA_PROP_CSSPATH, &var, NULL)))
  67. {
  68. *pVal = var.bstrVal;
  69. var.vt = VT_EMPTY;
  70. }
  71. return S_OK;
  72. }
  73. STDMETHOD(navigate)(/*[in]*/ VARIANT varClsid, /*[in]*/ VARIANT_BOOL bTrimHistory, /*[in]*/ VARIANT var2)
  74. {
  75. if (NULL == _pTaskFrame || NULL == _pBag)
  76. return E_UNEXPECTED;
  77. _pBag->Write(UA_PROP_PAGEINITDATA, &var2);
  78. if (varClsid.vt == VT_BSTR)
  79. {
  80. CLSID clsid;
  81. if (SUCCEEDED(CLSIDFromString(varClsid.bstrVal, &clsid)))
  82. return _pTaskFrame->ShowPage(clsid, !(VARIANT_FALSE == bTrimHistory));
  83. else
  84. MessageBoxW(NULL, varClsid.bstrVal, (var2.vt == VT_BSTR ? var2.bstrVal : L"navigate"), MB_OK);
  85. }
  86. return S_OK;
  87. }
  88. STDMETHOD(goBack)(/*[in, optional, defaultvalue=1]*/ VARIANT varCount)
  89. {
  90. if (NULL == _pTaskFrame)
  91. return E_UNEXPECTED;
  92. int cBack = 1;
  93. if (SUCCEEDED(VariantChangeType(&varCount, &varCount, 0, VT_I4)))
  94. cBack = varCount.lVal;
  95. if (-1 == cBack)
  96. _pTaskFrame->Home();
  97. else
  98. _pTaskFrame->Back(cBack);
  99. return S_OK;
  100. }
  101. STDMETHOD(goForward)()
  102. {
  103. if (NULL == _pTaskFrame)
  104. return E_UNEXPECTED;
  105. _pTaskFrame->Forward();
  106. return S_OK;
  107. }
  108. STDMETHOD(showHelp)(/*[in]*/ VARIANT var)
  109. {
  110. if (var.vt == VT_BSTR)
  111. MessageBoxW(NULL, var.bstrVal, L"showHelp", MB_OK);
  112. return S_OK;
  113. }
  114. protected:
  115. ITaskFrame* _pTaskFrame;
  116. IPropertyBag* _pBag;
  117. };
  118. #endif //__HTMLIMPL_H_