XTExcelTabCtrlTheme.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:11k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTExcelTabCtrlTheme.cpp: implementation of the CXTExcelTabCtrlTheme class.
  2. //
  3. // This file is a part of the XTREME CONTROLS MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPIntel80Helpers.h"
  22. #include "XTExcelTabCtrlTheme.h"
  23. #include "XTDefines.h"
  24. #include "XTUtil.h"
  25. #include "XTGlobal.h"
  26. #include "XTMemDC.h"
  27. #include "XTVC50Helpers.h"
  28. #include "XTExcelTabCtrl.h"
  29. #ifdef _DEBUG
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #define new DEBUG_NEW
  33. #endif
  34. IMPLEMENT_THEME_FACTORY(CXTExcelTabCtrlTheme)
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CXTExcelTabCtrlTheme class
  37. //
  38. CXTExcelTabCtrlTheme::CXTExcelTabCtrlTheme()
  39. {
  40. }
  41. CXTExcelTabCtrlTheme::~CXTExcelTabCtrlTheme()
  42. {
  43. }
  44. void CXTExcelTabCtrlTheme::RefreshMetrics()
  45. {
  46. CXTThemeManagerStyle ::RefreshMetrics();
  47. m_cy = ::GetSystemMetrics(SM_CYHSCROLL);
  48. m_cx = ::GetSystemMetrics(SM_CXHSCROLL)-1;
  49. m_clr3DFace.SetStandardValue(GetXtremeColor(COLOR_BTNFACE));
  50. m_clr3DFacePushed.SetStandardValue(GetXtremeColor(COLOR_BTNFACE));
  51. m_clr3DFaceHilite.SetStandardValue(GetXtremeColor(COLOR_BTNFACE));
  52. m_clrBtnText.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  53. m_clrBtnTextPushed.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  54. m_clrBtnTextHilite.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  55. m_clrBtnTextGray.SetStandardValue(GetXtremeColor(COLOR_GRAYTEXT));
  56. m_clrWindow.SetStandardValue(GetXtremeColor(COLOR_WINDOW));
  57. m_clrWindowText.SetStandardValue(GetXtremeColor(COLOR_WINDOWTEXT));
  58. m_clr3DHilight.SetStandardValue(GetXtremeColor(COLOR_3DHILIGHT));
  59. m_clr3DShadow.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  60. m_clrBorder3DHilite.SetStandardValue(GetXtremeColor(COLOR_3DHILIGHT));
  61. m_clrBorder3DShadow.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  62. }
  63. COLORREF CXTExcelTabCtrlTheme::GetTabBackColor(CXTTcbItem* pTcbItem) const
  64. {
  65. return (pTcbItem->crTabBack == COLORREF_NULL) ? m_clr3DFace : pTcbItem->crTabBack;
  66. }
  67. COLORREF CXTExcelTabCtrlTheme::GetTabTextColor(CXTTcbItem* pTcbItem) const
  68. {
  69. return (pTcbItem->crTabText == COLORREF_NULL) ? m_clrBtnText : pTcbItem->crTabText;
  70. }
  71. COLORREF CXTExcelTabCtrlTheme::GetSelTabBackColor(CXTTcbItem* pTcbItem) const
  72. {
  73. return (pTcbItem->crTabSelBack == COLORREF_NULL) ? m_clrWindow : pTcbItem->crTabSelBack;
  74. }
  75. COLORREF CXTExcelTabCtrlTheme::GetSelTabTextColor(CXTTcbItem* pTcbItem) const
  76. {
  77. return (pTcbItem->crTabSelText == COLORREF_NULL) ? m_clrWindowText : pTcbItem->crTabSelText;
  78. }
  79. //////////////////////////////////////////////////////////////////////////
  80. //
  81. //     Height ************************
  82. //          *| |                  |  *
  83. //          *| |xxxxxxxxxxxxxxxxxx|   *
  84. //         *  | |         |        |    *
  85. //        *---+-+         |        +-----*
  86. //           |         Text
  87. //         Base  
  88. //                Margin
  89. //
  90. //      Base = Height / 2
  91. //      Margin = Base / 2
  92. //
  93. int CXTExcelTabCtrlTheme::DrawTab(CDC* pDC, CXTExcelTabCtrl* pTabCtrl, const CPoint& pt, bool bSelected, CXTTcbItem* pTcbItem)
  94. {
  95. if (pDC == NULL || pTcbItem == NULL || !::IsWindow(pTabCtrl->GetSafeHwnd()))
  96. return -1;
  97. // Saves the current state of the device context, we will
  98. // restore the state when the method looses scope. This will
  99. // simplify selecting objects.
  100. const int nSavedDC = pDC->SaveDC();
  101. const int iHeight = m_cy;
  102. const int iBase = iHeight / 2;
  103. const int iWidth = iHeight + iHeight / 2; // 2 bases + 2 margins
  104. const bool bBottom = (pTabCtrl->GetTabStyle() & FTS_XT_BOTTOM) == FTS_XT_BOTTOM;
  105. pDC->SelectObject(pTabCtrl->GetTabFont(bSelected));
  106. const CSize szText = pDC->GetTextExtent(pTcbItem->szTabLabel);
  107. CRect rcText;
  108. rcText.left = pt.x + iBase + iBase / 2;
  109. rcText.top = pt.y + ((iHeight - szText.cy)/2)-1;
  110. rcText.right = rcText.left + szText.cx;
  111. rcText.bottom = rcText.top + szText.cy;
  112. COLORREF crBack = GetTabBackColor(pTcbItem);
  113. COLORREF crFore = GetTabTextColor(pTcbItem);
  114. if (bSelected)
  115. {
  116. crBack = GetSelTabBackColor(pTcbItem);
  117. crFore = GetSelTabTextColor(pTcbItem);
  118. }
  119. CPen penBack(PS_SOLID, 1, crBack);
  120. CPen penWindow(PS_SOLID, 1, m_clr3DHilight);
  121. CPen penShadow(PS_SOLID, 1, m_clr3DShadow);
  122. CPen penOutline(PS_SOLID, 1, m_clrBtnText);
  123. CBrush brush;
  124. brush.CreateSolidBrush(crBack);
  125. POINT points[] =
  126. {
  127. { pt.x, pt.y + iHeight - 1 },
  128. { pt.x + iBase - 1, pt.y               },
  129. { pt.x + szText.cx + iWidth - iBase - 1, pt.y               },
  130. { pt.x + szText.cx + iWidth - 1, pt.y + iHeight - 1 }
  131. };
  132. // swap vertical coordinates
  133. if (bBottom)
  134. {
  135. points[0].y = points[1].y;
  136. points[2].y = points[3].y;
  137. points[1].y = points[2].y;
  138. points[3].y = points[0].y;
  139. }
  140. pDC->SelectObject(&penOutline);
  141. pDC->SetBkColor(crBack);
  142. pDC->SelectObject(&brush);
  143. pDC->Polygon(points, 4);
  144. pDC->SetTextColor(crFore);
  145. pDC->DrawText(pTcbItem->szTabLabel, rcText, DT_CENTER);
  146. pDC->SelectObject(&penShadow);
  147. if (bSelected)
  148. {
  149. pDC->MoveTo(pt.x + iBase, points[1].y);
  150. pDC->LineTo(pt.x + iBase * 2 + szText.cx - 1, points[1].y);
  151. pDC->SelectObject(&penBack);
  152. pDC->MoveTo(pt.x + 1, points[0].y);
  153. pDC->LineTo(pt.x + szText.cx + iWidth - 1, points[0].y);
  154. }
  155. else
  156. {
  157. // highlight line on left
  158. pDC->SelectObject(&penWindow);
  159. pDC->MoveTo(pt.x + 1, points[0].y);
  160. pDC->LineTo(pt.x + 1 + iBase, points[0].y + iHeight);
  161. // shadow line on top
  162. pDC->SelectObject(&penShadow);
  163. pDC->MoveTo(pt.x, points[0].y);
  164. pDC->LineTo(pt.x + szText.cx + iWidth, points[0].y);
  165. // shadow line on bottom
  166. pDC->MoveTo(pt.x + iBase, points[1].y);
  167. pDC->LineTo(pt.x + szText.cx + iHeight - 1, points[1].y);
  168. }
  169. // Cleanup.
  170. pDC->RestoreDC(nSavedDC);
  171. brush.DeleteObject();
  172. return szText.cx + iWidth;
  173. }
  174. void CXTExcelTabCtrlTheme::DrawButtonBack(CDC* pDC, CRect& rect, CXTExcelTabCtrlButtonState& state)
  175. {
  176. if (state.m_bPressed && state.m_bHilight)
  177. {
  178. pDC->Draw3dRect(rect, m_clrBorder3DShadow, m_clrBorder3DHilite);
  179. }
  180. else
  181. {
  182. pDC->Draw3dRect(rect, m_clrBorder3DHilite, m_clrBorder3DShadow);
  183. }
  184. rect.DeflateRect(1, 1);
  185. pDC->FillSolidRect(rect, m_clr3DFace);
  186. }
  187. void CXTExcelTabCtrlTheme::DrawButton(CDC* pDC, CXTExcelTabCtrl* /*pTabCtrl*/, CXTExcelTabCtrlButtonState& state)
  188. {
  189. CRect r(state.m_rect);
  190. if (r.IsRectEmpty()) return;
  191. DrawButtonBack(pDC, r, state);
  192. COLORREF clrBtnText = m_clrBtnText;
  193. if (state.m_bEnabled)
  194. {
  195. if (state.m_bPressed)
  196. {
  197. clrBtnText = m_clrBtnTextPushed;
  198. }
  199. else if (state.m_bHilight)
  200. {
  201. clrBtnText = m_clrBtnTextHilite;
  202. }
  203. }
  204. else
  205. {
  206. clrBtnText = m_clrBtnTextGray;
  207. }
  208. CPen pen(PS_SOLID, 1, clrBtnText);
  209. CPen *pOldPen = pDC->SelectObject(&pen);
  210. int direction = 1 - ((state.m_IconType & 0xFF00) >> 8);
  211. int x = (direction < 0) ? r.right : r.left, y;
  212. const int arrow_cy = r.Width() / 2 + 2;
  213. const int arrow_cx = (arrow_cy + 1) / 2 + 1;
  214. const int top = r.top + (r.Height() - arrow_cy) / 2;
  215. x += (((r.Width() - arrow_cx) / 2) * direction);
  216. y = top;
  217. // draw arrow
  218. int height = arrow_cy;
  219. while (height > 0)
  220. {
  221. pDC->MoveTo(x, y);
  222. pDC->LineTo(x, y + height);
  223. y += 1;
  224. x += direction;
  225. height -= 2;
  226. }
  227. if (state.m_IconType & 0xFF)
  228. {
  229. x += (1 * direction);
  230. pDC->MoveTo(x, top);
  231. pDC->LineTo(x, top + arrow_cy);
  232. }
  233. pDC->SelectObject(pOldPen);
  234. }
  235. /////////////////////////////////////////////////////////////////////////////
  236. // CXTExcelTabCtrlThemeOfficeXP class
  237. //
  238. void CXTExcelTabCtrlThemeOfficeXP::RefreshMetrics()
  239. {
  240. CXTExcelTabCtrlTheme::RefreshMetrics();
  241. m_clr3DFacePushed.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED));
  242. m_clr3DFaceHilite.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT));
  243. m_clrBtnText.SetStandardValue(GetXtremeColor(XPCOLOR_TOOLBAR_TEXT));
  244. m_clrBtnTextPushed.SetStandardValue(GetXtremeColor(XPCOLOR_PUSHED_TEXT));
  245. m_clrBtnTextHilite.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_TEXT));
  246. m_clrBtnTextGray.SetStandardValue(GetXtremeColor(XPCOLOR_GRAYTEXT));
  247. m_clrBorder3DHilite.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  248. m_clrBorder3DShadow.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  249. }
  250. void CXTExcelTabCtrlThemeOfficeXP::DrawButtonBack(CDC* pDC, CRect& rect, CXTExcelTabCtrlButtonState& state)
  251. {
  252. if (state.m_bEnabled && state.m_bHilight)
  253. {
  254. if (state.m_bPressed)
  255. {
  256. pDC->FillSolidRect(rect, m_clr3DFacePushed);
  257. pDC->Draw3dRect(rect, m_clrBorder3DHilite, m_clrBorder3DHilite);
  258. }
  259. else
  260. {
  261. pDC->FillSolidRect(rect, m_clr3DFaceHilite);
  262. pDC->Draw3dRect(rect, m_clrBorder3DHilite, m_clrBorder3DHilite);
  263. }
  264. }
  265. else
  266. {
  267. pDC->FillSolidRect(rect, m_clr3DFace);
  268. pDC->Draw3dRect(rect, m_clr3DFace, m_clr3DFace);
  269. }
  270. rect.DeflateRect(1, 1);
  271. }
  272. /////////////////////////////////////////////////////////////////////////////
  273. // CXTExcelTabCtrlThemeOffice2003 class
  274. //
  275. void CXTExcelTabCtrlThemeOffice2003::RefreshMetrics()
  276. {
  277. CXTExcelTabCtrlThemeOfficeXP::RefreshMetrics();
  278. if (XTPColorManager()->GetCurrentSystemTheme() != xtpSystemThemeUnknown)
  279. {
  280. m_clr3DFacePushed.SetStandardValue(GetMSO2003Color(XPCOLOR_HIGHLIGHT_PUSHED));
  281. m_clr3DFaceHilite.SetStandardValue(GetMSO2003Color(XPCOLOR_HIGHLIGHT));
  282. m_clrBtnTextPushed.SetStandardValue(GetMSO2003Color(XPCOLOR_PUSHED_TEXT));
  283. m_clrBtnTextHilite.SetStandardValue(GetMSO2003Color(XPCOLOR_HIGHLIGHT_TEXT));
  284. m_clrBorder3DShadow.SetStandardValue(GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  285. m_clrBorder3DHilite.SetStandardValue(GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  286. }
  287. }
  288. void CXTExcelTabCtrlThemeOffice2003::DrawButtonBack(CDC* pDC, CRect& rect, CXTExcelTabCtrlButtonState& state)
  289. {
  290. if (state.m_bEnabled && state.m_bHilight)
  291. {
  292. if (state.m_bPressed)
  293. {
  294. XTPDrawHelpers()->GradientFill(pDC, &rect,
  295. XTPColorManager()->grcLunaPushed, FALSE);
  296. }
  297. else
  298. {
  299. XTPDrawHelpers()->GradientFill(pDC, &rect,
  300. XTPColorManager()->grcLunaSelected, FALSE);
  301. }
  302. pDC->Draw3dRect(&rect, m_clrBorder3DHilite, m_clrBorder3DHilite);
  303. }
  304. else
  305. {
  306. pDC->FillSolidRect(rect, m_clr3DFace);
  307. pDC->Draw3dRect(rect, m_clr3DFace, m_clr3DFace);
  308. }
  309. rect.DeflateRect(1, 1);
  310. }