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

对话框与窗口

开发平台:

Visual C++

  1. // XTMenuListBoxTheme.cpp: implementation of the CXTMenuListBoxTheme 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/XTPDrawHelpers.h"
  22. #include "Common/XTPImageManager.h"
  23. #include "XTDefines.h"
  24. #include "XTUtil.h"
  25. #include "XTGlobal.h"
  26. #include "XTMenuListBox.h"
  27. #include "XTMenuListBoxTheme.h"
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #define new DEBUG_NEW
  32. #endif
  33. IMPLEMENT_THEME_FACTORY(CXTMenuListBoxTheme)
  34. //===========================================================================
  35. // CXTMenuListBoxTheme class
  36. //===========================================================================
  37. CXTMenuListBoxTheme::CXTMenuListBoxTheme()
  38. {
  39. }
  40. CXTMenuListBoxTheme::~CXTMenuListBoxTheme()
  41. {
  42. }
  43. void CXTMenuListBoxTheme::RefreshMetrics()
  44. {
  45. CXTThemeManagerStyle ::RefreshMetrics();
  46. m_cxIcon = ::GetSystemMetrics(SM_CXICON);
  47. m_cyIcon = ::GetSystemMetrics(SM_CYICON);
  48. m_cyEdge = ::GetSystemMetrics(SM_CYEDGE)*2;
  49. // normal colors
  50. m_crgBack.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  51. m_crgItemBorder.SetStandardValue(GetXtremeColor(COLOR_3DDKSHADOW), GetXtremeColor(COLOR_3DHILIGHT));
  52. m_crItemText.SetStandardValue(GetXtremeColor(COLOR_WINDOW));
  53. m_crItemTextDisabled.SetStandardValue(GetXtremeColor(COLOR_GRAYTEXT));
  54. // hot, pressed colors
  55. m_crgItemBackHot.SetStandardValue(COLORREF_NULL, COLORREF_NULL);
  56. m_crgItemBackPressed.SetStandardValue(COLORREF_NULL, COLORREF_NULL);
  57. }
  58. void CXTMenuListBoxTheme::DrawItem(CXTMenuListBox* pMenuListBox, LPDRAWITEMSTRUCT lpDIS)
  59. {
  60. // Define temporary variables.
  61. CDC*  pDC = CDC::FromHandle (lpDIS->hDC);
  62. CRect rcIcon = lpDIS->rcItem;
  63. CRect rcText = lpDIS->rcItem;
  64. int   iItemID = lpDIS->itemID;
  65. // if empty, draw focus rect.
  66. if (iItemID < 0)
  67. {
  68. rcIcon.bottom = rcIcon.top + 15;
  69. pDC->DrawFocusRect(rcIcon);
  70. return;
  71. }
  72. // Get the menu item.
  73. CXTMenuListBox::CONTENT_ITEM* pCI = pMenuListBox->GetMenuItem(iItemID);
  74. ASSERT(pCI);
  75. if (!pCI)
  76. return;
  77. // set the text foreground and background colors.
  78. pDC->SetTextColor(GetTextColor());
  79. // repaint the background.
  80. pDC->SetBkMode(TRANSPARENT);
  81. long iMargin = (rcIcon.Width()-m_cxIcon)/2;
  82. rcIcon.top += m_cyEdge;
  83. rcIcon.left += iMargin;
  84. rcIcon.right = rcIcon.left + m_cxIcon;
  85. rcIcon.bottom = rcIcon.top + m_cyIcon;
  86. int iOffset = 0;
  87. BOOL bSelected = FALSE;
  88. BOOL bPressed = FALSE;
  89. if ((lpDIS->itemState & ODS_SELECTED) && pCI->m_bEnabled)
  90. {
  91. bSelected = TRUE;
  92. CRect rcBorder(rcIcon);
  93. rcBorder.InflateRect(2, 2);
  94. if (::GetKeyState(VK_LBUTTON) < 0)
  95. {
  96. if (!m_crgItemBackPressed.IsNull())
  97. XTPDrawHelpers()->GradientFill(pDC, rcBorder, m_crgItemBackPressed, FALSE);
  98. pDC->Draw3dRect(&rcBorder,
  99. m_crgItemBorder.clrLight, m_crgItemBorder.clrDark);
  100. iOffset = 1;
  101. bPressed = TRUE;
  102. }
  103. else
  104. {
  105. if (!m_crgItemBackHot.IsNull())
  106. XTPDrawHelpers()->GradientFill(pDC, rcBorder, m_crgItemBackHot, FALSE);
  107. pDC->Draw3dRect(&rcBorder,
  108. m_crgItemBorder.clrDark, m_crgItemBorder.clrLight);
  109. iOffset = -1;
  110. }
  111. }
  112. LOGFONT lf;
  113. pMenuListBox->GetFont()->GetLogFont(&lf);
  114. if (bSelected && !pMenuListBox->m_bNoUnderline)
  115. lf.lfUnderline = 1;
  116. // select the font used by the button text.
  117. CFont font;
  118. font.CreateFontIndirect(&lf);
  119. CXTPFontDC fnt(pDC, &font);
  120. // get the text height.
  121. int iTextHeight = pMenuListBox->GetTextHeight(pCI->m_strText);
  122. // define the text rect.
  123. rcText.top = rcText.bottom - (iTextHeight + m_cyEdge);
  124. rcText.left += m_cyEdge;
  125. rcText.right -= m_cyEdge;
  126. if ((pMenuListBox->m_bNoBorder) && (iOffset != 0))
  127. {
  128. rcIcon.OffsetRect(iOffset, iOffset);
  129. rcText.OffsetRect(iOffset, iOffset);
  130. }
  131. if (pCI->m_pIcon)
  132. {
  133. DrawImage(pDC, rcIcon, pCI->m_pIcon, pCI->m_bEnabled, bSelected, bPressed);
  134. }
  135. DrawText(pDC, rcText, pCI);
  136. }
  137. void CXTMenuListBoxTheme::DrawImage(CDC* pDC, CRect& rcIcon, CXTPImageManagerIcon* pImage, BOOL bEnabled, BOOL /*bSelected*/, BOOL /*bPressed*/)
  138. {
  139. CPoint pt(rcIcon.TopLeft());
  140. if (bEnabled)
  141. {
  142. pImage->Draw(pDC, pt);
  143. }
  144. else
  145. {
  146. if (pImage->HasDisabledIcon() || pImage->IsAlpha())
  147. {
  148. pImage->Draw(pDC, pt, pImage->GetDisabledIcon());
  149. }
  150. else
  151. {
  152. pDC->DrawState(pt, rcIcon.Size(), pImage->GetIcon(), DST_ICON | DSS_DISABLED, (HBRUSH)NULL);
  153. }
  154. }
  155. }
  156. void CXTMenuListBoxTheme::DrawText(CDC* pDC, CRect& rcText, CXTMenuListBox::CONTENT_ITEM* pCI)
  157. {
  158. if (!pCI->m_bEnabled)
  159. {
  160. CRect rc = rcText;
  161. rc.OffsetRect(1, 1);
  162. pDC->SetTextColor(GetXtremeColor(COLOR_WINDOW));
  163. pDC->DrawText(pCI->m_strText, rc,
  164. DT_CENTER | DT_TOP | DT_END_ELLIPSIS);
  165. pDC->SetTextColor(GetXtremeColor(COLOR_3DSHADOW));
  166. }
  167. pDC->DrawText(pCI->m_strText, rcText,
  168. DT_CENTER | DT_TOP | DT_END_ELLIPSIS);
  169. }
  170. COLORREF CXTMenuListBoxTheme::GetBackColor()
  171. {
  172. return m_crgBack;
  173. }
  174. COLORREF CXTMenuListBoxTheme::GetTextColor()
  175. {
  176. return m_crItemText;
  177. }
  178. //////////////////////////////////////////////////////////////////////////
  179. // CXTMenuListBoxThemeOfficeXP
  180. CXTMenuListBoxThemeOfficeXP::CXTMenuListBoxThemeOfficeXP()
  181. {
  182. }
  183. void CXTMenuListBoxThemeOfficeXP::RefreshMetrics()
  184. {
  185. CXTMenuListBoxTheme::RefreshMetrics();
  186. // normal colors
  187. m_crgBack.SetStandardValue(GetXtremeColor(XPCOLOR_TOOLBAR_FACE));
  188. m_crItemText.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  189. m_crgItemBorder.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER), GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  190. m_crItemTextDisabled.SetStandardValue(GetXtremeColor(XPCOLOR_GRAYTEXT));
  191. // hot, pressed colors
  192. m_crgItemBackHot.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT), GetXtremeColor(XPCOLOR_HIGHLIGHT));
  193. m_crgItemBackPressed.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED), GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED));
  194. }
  195. void CXTMenuListBoxThemeOfficeXP::DrawImage(CDC* pDC, CRect& rcIcon, CXTPImageManagerIcon* pImage, BOOL bEnabled, BOOL bSelected, BOOL bPressed)
  196. {
  197. ASSERT(pImage);
  198. if (!pImage)
  199. return;
  200. CPoint pt(rcIcon.TopLeft());
  201. if (bEnabled)
  202. {
  203. if (!bSelected && !bPressed)
  204. {
  205. pImage->Draw(pDC, pt, pImage->GetFadedIcon());
  206. }
  207. else if (bSelected && !bPressed)
  208. {
  209. pImage->Draw(pDC, CPoint(pt.x + 1, pt.y + 1), pImage->GetShadowIcon());
  210. pImage->Draw(pDC, CPoint(pt.x - 1, pt.y - 1), pImage->GetHotIcon());
  211. }
  212. else
  213. {
  214. pImage->Draw(pDC, rcIcon.TopLeft());
  215. }
  216. }
  217. else
  218. {
  219. if (pImage->HasDisabledIcon() || pImage->IsAlpha())
  220. {
  221. pImage->Draw(pDC, pt, pImage->GetDisabledIcon());
  222. }
  223. else
  224. {
  225. pImage->DrawMono(pDC, pt, pImage->GetIcon(), 0, m_crItemTextDisabled);
  226. }
  227. }
  228. }
  229. void CXTMenuListBoxThemeOfficeXP::DrawText(CDC* pDC, CRect& rcText, CXTMenuListBox::CONTENT_ITEM* pCI)
  230. {
  231. pDC->SetTextColor(pCI->m_bEnabled ? m_crItemText : m_crItemTextDisabled);
  232. pDC->DrawText(pCI->m_strText, rcText, DT_CENTER | DT_TOP | DT_END_ELLIPSIS);
  233. }
  234. //////////////////////////////////////////////////////////////////////////
  235. //  CXTMenuListBoxThemeOffice2003
  236. CXTMenuListBoxThemeOffice2003::CXTMenuListBoxThemeOffice2003()
  237. {
  238. }
  239. void CXTMenuListBoxThemeOffice2003::RefreshMetrics()
  240. {
  241. CXTMenuListBoxThemeOfficeXP::RefreshMetrics();
  242. if (!XTPColorManager()->IsLunaColorsDisabled())
  243. {
  244. XTPCurrentSystemTheme systemTheme = XTPColorManager()->GetCurrentSystemTheme();
  245. switch (systemTheme)
  246. {
  247. case xtpSystemThemeBlue:
  248. case xtpSystemThemeRoyale:
  249. case xtpSystemThemeAero:
  250. // normal colors
  251. m_crgBack.SetStandardValue(RGB(0xdd, 0xec, 0xfe), RGB(0x4a, 0x7a, 0xc9));
  252. m_crgItemBorder.SetStandardValue(RGB(0x00, 0x00, 0x80), RGB(0x00, 0x00, 0x80));
  253. m_crItemText.SetStandardValue(RGB(0x00, 0x00, 0x00));
  254. m_crItemTextDisabled.SetStandardValue(RGB(0x6d, 0x96, 0xd0));
  255. // hot, pressed colors
  256. m_crgItemBackHot.SetStandardValue(RGB(0xff, 0xf0, 0xc5), RGB(0xff, 0xd6, 0x9b));
  257. m_crgItemBackPressed.SetStandardValue(RGB(0xfe, 0x90, 0x4d), RGB(0xfe, 0xc9, 0x85));
  258. break;
  259. case xtpSystemThemeOlive:
  260. // normal colors
  261. m_crgBack.SetStandardValue(RGB(0xf3, 0xf2, 0xe7), RGB(0x9f, 0xab, 0x80));
  262. m_crgItemBorder.SetStandardValue(RGB(0x3f, 0x5d, 0x38), RGB(0x3f, 0x5d, 0x38));
  263. m_crItemText.SetStandardValue(RGB(0x00, 0x00, 0x00));
  264. m_crItemTextDisabled.SetStandardValue(RGB(0x9f, 0xae, 0x7a));
  265. // hot, pressed colors
  266. m_crgItemBackHot.SetStandardValue(RGB(0xff, 0xf0, 0xc5), RGB(0xff, 0xd6, 0x9b));
  267. m_crgItemBackPressed.SetStandardValue(RGB(0xfe, 0x90, 0x4d), RGB(0xfe, 0xc9, 0x85));
  268. break;
  269. case xtpSystemThemeSilver:
  270. // normal colors
  271. m_crgBack.SetStandardValue(RGB(0xee, 0xee, 0xf4), RGB(0xa2, 0xa2, 0xb5));
  272. m_crgItemBorder.SetStandardValue(RGB(0x4b, 0x4b, 0x6f), RGB(0x4b, 0x4b, 0x6f));
  273. m_crItemText.SetStandardValue(RGB(0x00, 0x00, 0x00));
  274. m_crItemTextDisabled.SetStandardValue(RGB(0xa8, 0xa7, 0xbe));
  275. // hot, pressed colors
  276. m_crgItemBackHot.SetStandardValue(RGB(0xff, 0xf0, 0xc5), RGB(0xff, 0xd6, 0x9b));
  277. m_crgItemBackPressed.SetStandardValue(RGB(0xfe, 0x90, 0x4d), RGB(0xfe, 0xc9, 0x85));
  278. break;
  279. default:
  280. // normal colors
  281. m_crgBack.SetStandardValue(XTPColorManager()->LightColor(GetXtremeColor(COLOR_3DFACE),
  282. GetXtremeColor(COLOR_WINDOW), 0xcd), GetXtremeColor(COLOR_3DFACE));
  283. break;
  284. }
  285. }
  286. }
  287. void CXTMenuListBoxThemeOffice2003::DrawImage(CDC* pDC, CRect& rcIcon, CXTPImageManagerIcon* pImage, BOOL bEnabled, BOOL /*bSelected*/, BOOL /*bPressed*/)
  288. {
  289. CPoint pt(rcIcon.TopLeft());
  290. if (bEnabled)
  291. {
  292. pImage->Draw(pDC, pt);
  293. }
  294. else
  295. {
  296. if (pImage->HasDisabledIcon() || pImage->IsAlpha())
  297. {
  298. pImage->Draw(pDC, pt, pImage->GetDisabledIcon());
  299. }
  300. else
  301. {
  302. pImage->DrawMono(pDC, pt, pImage->GetIcon(), 0, m_crItemTextDisabled);
  303. }
  304. }
  305. }