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

对话框与窗口

开发平台:

Visual C++

  1. // XTFlatControlsTheme.cpp: implementation of the CXTFlatControlsTheme 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 "XTFlatControlsTheme.h"
  22. #include "XTDefines.h"
  23. #include "XTGlobal.h"
  24. #include "XTFlatComboBox.h"
  25. #include "XTHelpers.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #define new DEBUG_NEW
  30. #endif
  31. IMPLEMENT_THEME_FACTORY(CXTFlatComboBoxTheme)
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CXTFlatComboBoxTheme class
  34. //
  35. CXTFlatComboBoxTheme::CXTFlatComboBoxTheme()
  36. {
  37. }
  38. void CXTFlatComboBoxTheme::RefreshMetrics()
  39. {
  40. CXTThemeManagerStyle ::RefreshMetrics();
  41. // get system metrics for border, 3D edge and drop arrow box.
  42. m_sizeThumb.cx = ::GetSystemMetrics(SM_CXHTHUMB);
  43. m_sizeThumb.cy = ::GetSystemMetrics(SM_CYVTHUMB);
  44. m_sizeBorder.cx = ::GetSystemMetrics(SM_CXBORDER);
  45. m_sizeBorder.cy = ::GetSystemMetrics(SM_CYBORDER);
  46. m_sizeEdge.cx = ::GetSystemMetrics(SM_CXEDGE);
  47. m_sizeEdge.cy = ::GetSystemMetrics(SM_CYEDGE);
  48. // define sizes for office arrow and max height.
  49. m_cxArrow = GetDropArrowWidth();
  50. }
  51. void CXTFlatComboBoxTheme::DrawFlatComboBox(CDC* pDC, CXTFlatComboBox* pCombo, int eState)
  52. {
  53. CRect rcItem;
  54. pCombo->GetClientRect(&rcItem);
  55. CRect rcBack(rcItem);
  56. rcBack.DeflateRect(m_sizeEdge);
  57. if (pCombo->IsWindowEnabled())
  58. {
  59. // erase background.
  60. pDC->FillSolidRect(rcBack, GetXtremeColor(COLOR_WINDOW));
  61. CRect rFillColor(rcBack);
  62. rFillColor.DeflateRect(m_sizeBorder);
  63. rFillColor.right -= m_cxArrow;
  64. if (eState == xtMouseHover || eState == xtMouseSelect)
  65. {
  66. rFillColor.right--;
  67. pDC->Draw3dRect(&rcItem, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHILIGHT));
  68. }
  69. if (pCombo->GetEditSel() == (DWORD)CB_ERR)
  70. pDC->FillSolidRect(rFillColor, pCombo->GetBackColor());
  71. }
  72. else
  73. {
  74. pDC->FillSolidRect(rcBack, GetXtremeColor(XPCOLOR_3DFACE));
  75. pDC->Draw3dRect(&rcItem, GetXtremeColor(XPCOLOR_3DSHADOW),
  76. GetXtremeColor(XPCOLOR_3DSHADOW));
  77. }
  78. DrawDownArrow(pDC, rcBack, eState, pCombo);
  79. }
  80. void CXTFlatComboBoxTheme::DrawDownArrow(CDC* pDC, const CRect& rcItem, int eState, CXTFlatComboBox* pCombo)
  81. {
  82. // determine background size.
  83. CRect rcArrow(rcItem);
  84. DrawArrowBack(pDC, rcArrow, eState, pCombo);
  85. CPoint pt;
  86. pt.x = (rcArrow.left + rcArrow.right - 4) / 2;
  87. pt.y = (rcArrow.top + rcArrow.bottom - 2) / 2;
  88. if (eState == xtMouseSelect)
  89. pt.Offset(1, 1);
  90. COLORREF cr = pCombo->IsWindowEnabled() ? GetXtremeColor(COLOR_WINDOWTEXT) : GetXtremeColor(COLOR_3DSHADOW);
  91. pDC->SetPixel(pt.x, pt.y, cr);
  92. pDC->SetPixel(pt.x+1, pt.y, cr);
  93. pDC->SetPixel(pt.x+2, pt.y, cr);
  94. pDC->SetPixel(pt.x+3, pt.y, cr);
  95. pDC->SetPixel(pt.x+4, pt.y, cr);
  96. pDC->SetPixel(pt.x+1, pt.y+1, cr);
  97. pDC->SetPixel(pt.x+2, pt.y+1, cr);
  98. pDC->SetPixel(pt.x+3, pt.y+1, cr);
  99. pDC->SetPixel(pt.x+2, pt.y+2, cr);
  100. }
  101. int CXTFlatComboBoxTheme::GetDropArrowWidth() const
  102. {
  103. TEXTMETRIC tm;
  104. CWindowDC dc(NULL);
  105. CXTPFontDC fontDC(&dc, &XTAuxData().font);
  106. dc.GetTextMetrics(&tm);
  107. int nThumbWidth = __max(15, tm.tmAveCharWidth * 2 + 4);
  108. return min(nThumbWidth, GetSystemMetrics(SM_CXVSCROLL) + 1);
  109. }
  110. void CXTFlatComboBoxTheme::DrawArrowBack(CDC* pDC, CRect& rcArrow, int eState, CXTFlatComboBox* /*pCombo*/)
  111. {
  112. rcArrow.left = rcArrow.right - (m_cxArrow - 4);
  113. if (eState == xtMouseHover)
  114. {
  115. pDC->Draw3dRect(&rcArrow, GetXtremeColor(COLOR_3DHILIGHT), GetXtremeColor(COLOR_3DSHADOW));
  116. rcArrow.DeflateRect(-1, -1);
  117. pDC->Draw3dRect(&rcArrow, GetXtremeColor(COLOR_3DFACE), GetXtremeColor(COLOR_3DFACE));
  118. rcArrow.DeflateRect(1, 1);
  119. }
  120. if (eState == xtMouseSelect)
  121. {
  122. pDC->Draw3dRect(&rcArrow, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHILIGHT));
  123. rcArrow.DeflateRect(-1, -1);
  124. pDC->Draw3dRect(&rcArrow, GetXtremeColor(COLOR_3DFACE), GetXtremeColor(COLOR_3DFACE));
  125. rcArrow.DeflateRect(1, 1);
  126. }
  127. // erase background.
  128. rcArrow.DeflateRect(1, 1);
  129. pDC->FillSolidRect(&rcArrow, GetXtremeColor(COLOR_3DFACE));
  130. }
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CXTFlatComboBoxThemeOfficeXP class
  133. //
  134. CXTFlatComboBoxThemeOfficeXP::CXTFlatComboBoxThemeOfficeXP()
  135. {
  136. }
  137. void CXTFlatComboBoxThemeOfficeXP::DrawArrowBack(CDC* pDC, CRect& rcArrow, int eState, CXTFlatComboBox* /*pCombo*/)
  138. {
  139. rcArrow.left = rcArrow.right - (m_cxArrow - 2);
  140. if (eState == xtMouseHover)
  141. {
  142. pDC->FillSolidRect(&rcArrow, GetXtremeColor(XPCOLOR_HIGHLIGHT));
  143. CXTPPenDC pen(*pDC, GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  144. pDC->MoveTo(rcArrow.left-1, rcArrow.top);
  145. pDC->LineTo(rcArrow.left-1, rcArrow.bottom);
  146. }
  147. else if (eState == xtMouseSelect)
  148. {
  149. pDC->FillSolidRect(&rcArrow, GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED));
  150. CXTPPenDC pen(*pDC, GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  151. pDC->MoveTo(rcArrow.left-1, rcArrow.top);
  152. pDC->LineTo(rcArrow.left-1, rcArrow.bottom);
  153. }
  154. else
  155. {
  156. rcArrow.DeflateRect(1, 1);
  157. pDC->FillSolidRect(&rcArrow, GetXtremeColor(COLOR_3DFACE));
  158. }
  159. }
  160. void CXTFlatComboBoxThemeOfficeXP::DrawDownArrow(CDC* pDC, const CRect& rcItem, int eState, CXTFlatComboBox* pCombo)
  161. {
  162. // determine background size.
  163. CRect rcArrow(rcItem);
  164. DrawArrowBack(pDC, rcArrow, eState, pCombo);
  165. CPoint pt;
  166. pt.x = (rcArrow.left + rcArrow.right - 4) / 2;
  167. pt.y = (rcArrow.top + rcArrow.bottom - 2) / 2;
  168. COLORREF cr = pCombo->IsWindowEnabled() ? GetXtremeColor(COLOR_WINDOWTEXT) : GetXtremeColor(COLOR_3DSHADOW);
  169. pDC->SetPixel(pt.x, pt.y, cr);
  170. pDC->SetPixel(pt.x+1, pt.y, cr);
  171. pDC->SetPixel(pt.x+2, pt.y, cr);
  172. pDC->SetPixel(pt.x+3, pt.y, cr);
  173. pDC->SetPixel(pt.x+4, pt.y, cr);
  174. pDC->SetPixel(pt.x+1, pt.y+1, cr);
  175. pDC->SetPixel(pt.x+2, pt.y+1, cr);
  176. pDC->SetPixel(pt.x+3, pt.y+1, cr);
  177. pDC->SetPixel(pt.x+2, pt.y+2, cr);
  178. }
  179. void CXTFlatComboBoxThemeOfficeXP::DrawFlatComboBox(CDC* pDC, CXTFlatComboBox* pCombo, int eState)
  180. {
  181. CRect rcItem;
  182. pCombo->GetClientRect(&rcItem);
  183. CRect rcBack(rcItem);
  184. rcBack.DeflateRect(m_sizeBorder);
  185. if (pCombo->IsWindowEnabled())
  186. {
  187. pDC->FillSolidRect(rcBack, GetXtremeColor(COLOR_WINDOW));
  188. CRect rFillColor = rcBack;
  189. rFillColor.DeflateRect(m_sizeBorder);
  190. rFillColor.right -= m_cxArrow;
  191. if (eState == xtMouseHover || eState == xtMouseSelect)
  192. {
  193. rFillColor.right--;
  194. pDC->Draw3dRect(&rcItem, GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER),
  195. GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  196. }
  197. else
  198. {
  199. pDC->Draw3dRect(&rcItem, GetXtremeColor(XPCOLOR_3DFACE),
  200. GetXtremeColor(XPCOLOR_3DFACE));
  201. }
  202. if (pCombo->GetEditSel() == (DWORD)CB_ERR)
  203. pDC->FillSolidRect(rFillColor, pCombo->GetBackColor());
  204. }
  205. else
  206. {
  207. pDC->FillSolidRect(rcBack, GetXtremeColor(XPCOLOR_3DFACE));
  208. pDC->Draw3dRect(&rcItem, GetXtremeColor(XPCOLOR_3DSHADOW),
  209. GetXtremeColor(XPCOLOR_3DSHADOW));
  210. }
  211. DrawDownArrow(pDC, rcBack, eState, pCombo);
  212. }
  213. /////////////////////////////////////////////////////////////////////////////
  214. // CXTFlatComboBoxThemeOffice2003 class
  215. //
  216. CXTFlatComboBoxThemeOffice2003::CXTFlatComboBoxThemeOffice2003()
  217. {
  218. }
  219. void CXTFlatComboBoxThemeOffice2003::DrawArrowBack(CDC* pDC, CRect& rcArrow, int eState, CXTFlatComboBox* pCombo)
  220. {
  221. rcArrow.left = rcArrow.right - (m_cxArrow - 2);
  222. if (eState == xtMouseHover)
  223. {
  224. XTPDrawHelpers()->GradientFill(pDC, &rcArrow,
  225. XTPColorManager()->grcLunaSelected, FALSE);
  226. CXTPPenDC pen(*pDC, GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  227. pDC->MoveTo(rcArrow.left-1, rcArrow.top);
  228. pDC->LineTo(rcArrow.left-1, rcArrow.bottom);
  229. }
  230. else if (eState == xtMouseSelect)
  231. {
  232. XTPDrawHelpers()->GradientFill(pDC, &rcArrow,
  233. XTPColorManager()->grcLunaPushed, FALSE);
  234. CXTPPenDC pen(*pDC, GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  235. pDC->MoveTo(rcArrow.left-1, rcArrow.top);
  236. pDC->LineTo(rcArrow.left-1, rcArrow.bottom);
  237. }
  238. else if (pCombo->IsWindowEnabled())
  239. {
  240. rcArrow.DeflateRect(1, 1);
  241. XTPDrawHelpers()->GradientFill(pDC, &rcArrow,
  242. XTPColorManager()->grcMenuItemPopup, FALSE);
  243. }
  244. }
  245. void CXTFlatComboBoxThemeOffice2003::DrawFlatComboBox(CDC* pDC, CXTFlatComboBox* pCombo, int eState)
  246. {
  247. CRect rcItem;
  248. pCombo->GetClientRect(&rcItem);
  249. CRect rcBack(rcItem);
  250. rcBack.DeflateRect(m_sizeBorder);
  251. if (pCombo->IsWindowEnabled())
  252. {
  253. pDC->FillSolidRect(rcBack, GetXtremeColor(COLOR_WINDOW));
  254. CRect rFillColor = rcBack;
  255. rFillColor.DeflateRect(m_sizeBorder);
  256. rFillColor.right -= m_cxArrow;
  257. if (eState == xtMouseHover || eState == xtMouseSelect)
  258. {
  259. rFillColor.right--;
  260. pDC->Draw3dRect(&rcItem, GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER),
  261. GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  262. }
  263. if (pCombo->GetEditSel() == (DWORD)CB_ERR)
  264. pDC->FillSolidRect(rFillColor, pCombo->GetBackColor());
  265. }
  266. else
  267. {
  268. pDC->FillSolidRect(rcBack, GetXtremeColor(XPCOLOR_3DFACE));
  269. pDC->Draw3dRect(&rcItem, GetXtremeColor(XPCOLOR_3DSHADOW),
  270. GetXtremeColor(XPCOLOR_3DSHADOW));
  271. }
  272. DrawDownArrow(pDC, rcBack, eState, pCombo);
  273. }
  274. IMPLEMENT_THEME_FACTORY(CXTFlatEditTheme)
  275. /////////////////////////////////////////////////////////////////////////////
  276. // CXTFlatEditTheme class
  277. CXTFlatEditTheme::CXTFlatEditTheme()
  278. {
  279. }
  280. void CXTFlatEditTheme::RefreshMetrics()
  281. {
  282. CXTThemeManagerStyle ::RefreshMetrics();
  283. }
  284. void CXTFlatEditTheme::DrawBorders(CDC* pDC, CXTFlatEdit* pEdit, const CRect& rWindow, int eState)
  285. {
  286. if (pEdit->IsWindowEnabled())
  287. {
  288. // erase background.
  289. pDC->FillSolidRect(&rWindow, GetXtremeColor(COLOR_WINDOW));
  290. if (eState == xtMouseHover || eState == xtMouseSelect)
  291. {
  292. pDC->Draw3dRect(&rWindow, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHILIGHT));
  293. }
  294. }
  295. else
  296. {
  297. pDC->FillSolidRect(&rWindow, GetXtremeColor(XPCOLOR_3DFACE));
  298. pDC->Draw3dRect(&rWindow, GetXtremeColor(XPCOLOR_3DSHADOW),
  299. GetXtremeColor(XPCOLOR_3DSHADOW));
  300. }
  301. }
  302. /////////////////////////////////////////////////////////////////////////////
  303. // CXTFlatEditThemeOfficeXP class
  304. CXTFlatEditThemeOfficeXP::CXTFlatEditThemeOfficeXP()
  305. {
  306. }
  307. void CXTFlatEditThemeOfficeXP::RefreshMetrics()
  308. {
  309. CXTFlatEditTheme::RefreshMetrics();
  310. m_clrHighlightText.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_TEXT));
  311. m_clrPushedText.SetStandardValue(GetXtremeColor(XPCOLOR_PUSHED_TEXT));
  312. m_clrHighlight.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT));
  313. m_clrPushed.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED));
  314. m_clrFrameHighlight.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  315. m_clrFrameNormal.SetStandardValue(GetXtremeColor(COLOR_WINDOW));
  316. m_clrNormal.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  317. m_clrFrameEdit.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  318. }
  319. void CXTFlatEditThemeOfficeXP::DrawBorders(CDC* pDC, CXTFlatEdit* pEdit, const CRect& rWindow, int eState)
  320. {
  321. if (pEdit->IsWindowEnabled())
  322. {
  323. pDC->FillSolidRect(&rWindow, GetXtremeColor(COLOR_WINDOW));
  324. if (eState == xtMouseHover || eState == xtMouseSelect)
  325. {
  326. pDC->Draw3dRect(&rWindow, GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER),
  327. GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  328. }
  329. }
  330. else
  331. {
  332. pDC->FillSolidRect(&rWindow, GetXtremeColor(XPCOLOR_3DFACE));
  333. pDC->Draw3dRect(&rWindow, GetXtremeColor(XPCOLOR_3DSHADOW),
  334. GetXtremeColor(XPCOLOR_3DSHADOW));
  335. }
  336. }
  337. //////////////////////////////////////////////////////////////////////////
  338. // CXTFlatEditThemeOffice2003
  339. CXTFlatEditThemeOffice2003::CXTFlatEditThemeOffice2003()
  340. {
  341. }
  342. void CXTFlatEditThemeOffice2003::RefreshMetrics()
  343. {
  344. CXTFlatEditThemeOfficeXP::RefreshMetrics();
  345. XTPCurrentSystemTheme systemTheme = XTPColorManager()->GetCurrentSystemTheme();
  346. switch (systemTheme)
  347. {
  348. case xtpSystemThemeBlue:
  349. case xtpSystemThemeRoyale:
  350. case xtpSystemThemeAero:
  351. m_clrHighlightText.SetStandardValue(0);
  352. m_clrPushedText.SetStandardValue(0);
  353. m_clrHighlight.SetStandardValue(RGB(255, 238, 194));
  354. m_clrPushed.SetStandardValue(RGB(254, 128, 62));
  355. m_clrFrameHighlight.SetStandardValue(RGB(0, 0, 128));
  356. m_clrFrameNormal.SetStandardValue(RGB(127, 157, 185));
  357. m_clrNormal.SetStandardValue(RGB(169, 199, 240));
  358. break;
  359. case xtpSystemThemeOlive:
  360. m_clrHighlightText.SetStandardValue(0);
  361. m_clrPushedText.SetStandardValue(0);
  362. m_clrHighlight.SetStandardValue(RGB(255, 238, 194));
  363. m_clrPushed.SetStandardValue(RGB(254, 128, 62));
  364. m_clrFrameHighlight.SetStandardValue(RGB(63, 93, 56));
  365. m_clrFrameNormal.SetStandardValue(RGB(164, 185, 127));
  366. m_clrNormal.SetStandardValue(RGB(197, 212, 159));
  367. break;
  368. case xtpSystemThemeSilver:
  369. m_clrHighlightText.SetStandardValue(0);
  370. m_clrPushedText.SetStandardValue(0);
  371. m_clrHighlight.SetStandardValue(RGB(255, 238, 194));
  372. m_clrPushed.SetStandardValue(RGB(254, 128, 62));
  373. m_clrFrameHighlight.SetStandardValue(RGB(75, 75, 111));
  374. m_clrFrameNormal.SetStandardValue(RGB(165, 172, 178));
  375. m_clrNormal.SetStandardValue(RGB(192, 192, 211));
  376. break;
  377. default:
  378. m_clrFrameNormal.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  379. }
  380. m_clrFrameEdit.SetStandardValue(m_clrFrameNormal);
  381. }
  382. void CXTFlatEditThemeOffice2003::DrawBorders(CDC* pDC, CXTFlatEdit* pEdit, const CRect& rWindow, int eState)
  383. {
  384. if (pEdit->IsWindowEnabled())
  385. {
  386. pDC->FillSolidRect(&rWindow, GetXtremeColor(COLOR_WINDOW));
  387. if (eState == xtMouseHover || eState == xtMouseSelect)
  388. {
  389. pDC->Draw3dRect(&rWindow, GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER),
  390. GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  391. }
  392. }
  393. else
  394. {
  395. pDC->FillSolidRect(&rWindow, GetXtremeColor(XPCOLOR_3DFACE));
  396. pDC->Draw3dRect(&rWindow, GetXtremeColor(XPCOLOR_3DSHADOW),
  397. GetXtremeColor(XPCOLOR_3DSHADOW));
  398. }
  399. }