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.

232 lines
6.6 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Behav_GRADIENT.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHBehavior_GRADIENT class,
  7. that dictates how hyperlinks work in the help center.
  8. Revision History:
  9. Davide Massarenti (dmassare) 06/06/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. static const CComBSTR c_bstrStartColor ( L"start-color" );
  15. static const CComBSTR c_bstrEndColor ( L"end-color" );
  16. static const CComBSTR c_bstrGradientType( L"gradient-type" );
  17. static const CComBSTR c_bstrReturnToZero( L"return-to-zero" );
  18. ////////////////////////////////////////////////////////////////////////////////
  19. static COLORREF local_GetColor( /*[in]*/ IHTMLElement* elem ,
  20. /*[in]*/ IHTMLCurrentStyle* style ,
  21. /*[in]*/ BSTR bstrName )
  22. {
  23. CComVariant vColor;
  24. COLORREF color;
  25. bool fSystem;
  26. (void)style->getAttribute( bstrName, 0, &vColor );
  27. (void)MPC::HTML::ConvertColor( vColor, color, fSystem );
  28. return color;
  29. }
  30. ////////////////////////////////////////////////////////////////////////////////
  31. CPCHBehavior_GRADIENT::CPCHBehavior_GRADIENT()
  32. {
  33. __HCP_FUNC_ENTRY( "CPCHBehavior_GRADIENT::CPCHBehavior_GRADIENT" );
  34. m_lCookie = 0; // long m_lCookie;
  35. //
  36. // COLORREF m_clsStart;
  37. // COLORREF m_clsEnd;
  38. m_fHorizontal = true; // bool m_fHorizontal;
  39. m_fReturnToZero = false; // bool m_fReturnToZero;
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. void CPCHBehavior_GRADIENT::GetColors( /*[in]*/ bool fForce )
  43. {
  44. CComPtr<IHTMLCurrentStyle> pStyle;
  45. CComVariant v;
  46. if(m_elem && m_elem2 && SUCCEEDED(m_elem2->get_currentStyle( &pStyle )) && pStyle)
  47. {
  48. m_clsStart = local_GetColor( m_elem, pStyle, c_bstrStartColor );
  49. m_clsEnd = local_GetColor( m_elem, pStyle, c_bstrEndColor );
  50. if(SUCCEEDED(pStyle->getAttribute( c_bstrGradientType, 0, &v )) && v.vt == VT_BSTR &&
  51. SUCCEEDED(v.ChangeType ( VT_I4 )) )
  52. {
  53. if(v.lVal == 0) m_fHorizontal = false;
  54. }
  55. v.Clear();
  56. if(SUCCEEDED(pStyle->getAttribute( c_bstrReturnToZero, 0, &v )) && v.vt == VT_BSTR &&
  57. SUCCEEDED(v.ChangeType ( VT_I4 )) )
  58. {
  59. if(v.lVal != 0) m_fReturnToZero = true;
  60. }
  61. v.Clear();
  62. if(m_fRTL && m_fHorizontal && !m_fReturnToZero)
  63. {
  64. COLORREF tmp;
  65. tmp = m_clsStart;
  66. m_clsStart = m_clsEnd;
  67. m_clsEnd = tmp;
  68. }
  69. }
  70. }
  71. HRESULT CPCHBehavior_GRADIENT::onEvent( DISPID id, DISPPARAMS* pdispparams, VARIANT* )
  72. {
  73. if(id == DISPID_PCH_E_CSSCHANGED)
  74. {
  75. GetColors( /*fForce*/true );
  76. }
  77. return S_OK;
  78. }
  79. ////////////////////////////////////////////////////////////////////////////////
  80. STDMETHODIMP CPCHBehavior_GRADIENT::Init( /*[in]*/ IElementBehaviorSite* pBehaviorSite )
  81. {
  82. __HCP_FUNC_ENTRY( "CPCHBehavior_GRADIENT::Init" );
  83. HRESULT hr;
  84. CComPtr<IDispatch> pDisp;
  85. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHBehavior::Init( pBehaviorSite ));
  86. __MPC_EXIT_IF_METHOD_FAILS(hr, AttachToEvent( NULL, (CLASS_METHOD)onEvent, NULL, &pDisp ));
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, m_parent->Events().RegisterEvents( -1, 0, pDisp, &m_lCookie ));
  88. GetColors( /*fForce*/false );
  89. hr = S_OK;
  90. __HCP_FUNC_CLEANUP;
  91. __HCP_FUNC_EXIT(hr);
  92. }
  93. STDMETHODIMP CPCHBehavior_GRADIENT::Detach()
  94. {
  95. if(m_lCookie)
  96. {
  97. (void)m_parent->Events().UnregisterEvents( m_lCookie );
  98. m_lCookie = 0;
  99. }
  100. return CPCHBehavior::Detach();
  101. }
  102. ////////////////////////////////////////////////////////////////////////////////
  103. #define COLOR2COLOR16(col) (COLOR16)((col) << 8);
  104. STDMETHODIMP CPCHBehavior_GRADIENT::Draw( /*[in]*/ RECT rcBounds ,
  105. /*[in]*/ RECT rcUpdate ,
  106. /*[in]*/ LONG lDrawFlags ,
  107. /*[in]*/ HDC hdc ,
  108. /*[in]*/ LPVOID pvDrawObject )
  109. {
  110. if(m_clsStart != m_clsEnd)
  111. {
  112. TRIVERTEX vert[2];
  113. GRADIENT_RECT gRect;
  114. ULONG dwMode = m_fHorizontal ? GRADIENT_FILL_RECT_H : GRADIENT_FILL_RECT_V;
  115. vert[0].x = rcBounds.left;
  116. vert[0].y = rcBounds.top;
  117. vert[0].Red = COLOR2COLOR16(GetRValue(m_clsStart));
  118. vert[0].Green = COLOR2COLOR16(GetGValue(m_clsStart));
  119. vert[0].Blue = COLOR2COLOR16(GetBValue(m_clsStart));
  120. vert[0].Alpha = 0;
  121. vert[1].x = rcBounds.right;
  122. vert[1].y = rcBounds.bottom;
  123. vert[1].Red = COLOR2COLOR16(GetRValue(m_clsEnd));
  124. vert[1].Green = COLOR2COLOR16(GetGValue(m_clsEnd));
  125. vert[1].Blue = COLOR2COLOR16(GetBValue(m_clsEnd));
  126. vert[1].Alpha = 0;
  127. gRect.UpperLeft = 0;
  128. gRect.LowerRight = 1;
  129. if(m_fReturnToZero)
  130. {
  131. if(m_fHorizontal) vert[1].x = vert[0].x + (rcBounds.right - rcBounds.left) / 2;
  132. else vert[1].y = vert[0].y + (rcBounds.bottom - rcBounds.top ) / 2;
  133. ::GradientFill(hdc, vert, 2, &gRect, 1, dwMode );
  134. if(m_fHorizontal) vert[0].x = rcBounds.right;
  135. else vert[0].y = rcBounds.bottom;
  136. }
  137. ////DebugLog( "GRADIENT %d %d %d %d\n", (int)rcBounds.left, (int)rcBounds.top, (int)rcBounds.right, (int)rcBounds.bottom );
  138. ::GradientFill( hdc, vert, 2, &gRect, 1, dwMode );
  139. }
  140. else
  141. {
  142. HBRUSH hbrush = ::CreateSolidBrush( m_clsStart );
  143. if(hbrush)
  144. {
  145. ::FillRect( hdc, &rcBounds, hbrush );
  146. ::DeleteObject( hbrush );
  147. }
  148. }
  149. return S_OK;
  150. }
  151. STDMETHODIMP CPCHBehavior_GRADIENT::GetPainterInfo( /*[in]*/ HTML_PAINTER_INFO *pInfo )
  152. {
  153. if(pInfo)
  154. {
  155. pInfo->lFlags = HTMLPAINTER_TRANSPARENT;
  156. pInfo->lZOrder = HTMLPAINT_ZORDER_BELOW_CONTENT;
  157. pInfo->iidDrawObject = IID_NULL;
  158. pInfo->rcExpand.left = 0;
  159. pInfo->rcExpand.top = 0;
  160. pInfo->rcExpand.right = 0;
  161. pInfo->rcExpand.bottom = 0;
  162. }
  163. return S_OK;
  164. }
  165. STDMETHODIMP CPCHBehavior_GRADIENT::HitTestPoint( /*[in]*/ POINT pt ,
  166. /*[in]*/ BOOL* pbHit ,
  167. /*[in]*/ LONG* plPartID )
  168. {
  169. return E_NOTIMPL;
  170. }
  171. STDMETHODIMP CPCHBehavior_GRADIENT::OnResize( /*[in]*/ SIZE pt )
  172. {
  173. return E_NOTIMPL;
  174. }