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

对话框与窗口

开发平台:

Visual C++

  1. // XTCaptionTheme.cpp: implementation of the CXTCaptionTheme 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/XTPWinThemeWrapper.h"
  23. #include "XTThemeManager.h"
  24. #include "XTButtonTheme.h"
  25. #include "XTDefines.h"
  26. #include "XTButton.h"
  27. #include "XTCaption.h"
  28. #include "XTCaptionTheme.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. IMPLEMENT_THEME_FACTORY(CXTCaptionTheme)
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CXTCaptionTheme
  37. CXTCaptionTheme::CXTCaptionTheme()
  38. {
  39. }
  40. void CXTCaptionTheme::RefreshMetrics()
  41. {
  42. CXTThemeManagerStyle ::RefreshMetrics();
  43. m_clrEdgeShadow.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  44. m_clrEdgeLight.SetStandardValue(GetXtremeColor(COLOR_3DHILIGHT));
  45. }
  46. void CXTCaptionTheme::DrawCaptionBack(CDC* pDC, CXTCaption* pCaption, CRect& rcItem)
  47. {
  48. CRect rc = rcItem;
  49. // Set the background mode to transparent.
  50. pDC->SetBkMode(TRANSPARENT);
  51. // repaint the background.
  52. pDC->FillSolidRect(rc, pCaption->m_clrBorder);
  53. // draw the caption border.
  54. if (pCaption->m_dwExStyle & CPWS_EX_GROOVE_EDGE)
  55. {
  56. pDC->Draw3dRect(rc, m_clrEdgeShadow, m_clrEdgeLight);
  57. rc.DeflateRect(1, 1);
  58. pDC->Draw3dRect(rc, m_clrEdgeLight, m_clrEdgeShadow);
  59. if (pCaption->m_nBorder == 0)
  60. {
  61. rc.DeflateRect(1, 1);
  62. }
  63. }
  64. else
  65. if (pCaption->m_dwExStyle & CPWS_EX_RAISED_EDGE)
  66. {
  67. pDC->Draw3dRect(rc, m_clrEdgeLight, m_clrEdgeShadow);
  68. if (pCaption->m_nBorder == 0)
  69. {
  70. rc.DeflateRect(1, 1);
  71. }
  72. }
  73. // draw the caption banner border.
  74. rc.DeflateRect(pCaption->m_nBorder, pCaption->m_nBorder);
  75. pDC->FillSolidRect(rc, pCaption->m_clrFace);
  76. }
  77. void CXTCaptionTheme::DrawCaptionText(CDC* pDC, CXTCaption* pCaption)
  78. {
  79. // if the caption text is empty, return.
  80. if (pCaption->GetCaptionText().IsEmpty())
  81. {
  82. return;
  83. }
  84. // Get the display area for the text.
  85. CRect rcText(pCaption->GetTextRect());
  86. // Set the text color and select the caption font.
  87. CXTPFontDC fontDC(pDC, pCaption->GetFont());
  88. pDC->SetTextColor(pCaption->m_clrText);
  89. // draw the text, and select the original font.
  90. pDC->DrawText(pCaption->GetCaptionText(), rcText,
  91. DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_CENTER | DT_NOPREFIX);
  92. }
  93. void CXTCaptionTheme::DrawCaptionIcon(CDC* pDC, CXTCaption* pCaption, CRect& rcItem)
  94. {
  95. // If no icon was defined, just return.
  96. if (pCaption->m_hIcon == NULL)
  97. return;
  98. CRect rc = rcItem;
  99. rc.left = (rc.right - pCaption->m_sizeIcon.cx)-(pCaption->m_nBorder + 2);
  100. // stop the icon at the left hand border
  101. if (rc.left < pCaption->m_nBorder)
  102. {
  103. rc.left = pCaption->m_nBorder;
  104. }
  105. rc.top = (rcItem.Height() - pCaption->m_sizeIcon.cy)/2;
  106. rc.right = rc.left + pCaption->m_sizeIcon.cx;
  107. rc.bottom = rc.top + pCaption->m_sizeIcon.cy;
  108. // Only draw the icon if it will fit into the space between the borders
  109. if (rc.right < rcItem.right - pCaption->m_nBorder)
  110. {
  111. // draw the icon associated with the caption.
  112. ::DrawIconEx(pDC->GetSafeHdc(), rc.left, rc.top, pCaption->m_hIcon,
  113. rc.Width(), rc.Height(), NULL, (HBRUSH)NULL, DI_NORMAL);
  114. }
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CXTCaptionThemeOfficeXP
  118. void CXTCaptionThemeOfficeXP::DrawCaptionBack(CDC* pDC, CXTCaption* pCaption, CRect& rcItem)
  119. {
  120. CRect rc = rcItem;
  121. pDC->SetBkMode(TRANSPARENT);
  122. // repaint the background.
  123. pDC->FillSolidRect(rc, pCaption->m_clrBorder);
  124. if (!pCaption->IsAppCaption())
  125. {
  126. pDC->Draw3dRect(rc, GetXtremeColor(COLOR_3DHILIGHT), GetXtremeColor(COLOR_3DSHADOW));
  127. }
  128. else
  129. {
  130. // draw the caption banner border.
  131. rc.DeflateRect(pCaption->m_nBorder, pCaption->m_nBorder);
  132. pDC->FillSolidRect(rc, pCaption->m_clrFace);
  133. }
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CXTCaptionThemeOffice2003
  137. CXTCaptionThemeOffice2003::CXTCaptionThemeOffice2003()
  138. {
  139. }
  140. CXTCaptionThemeOffice2003::CXTCaptionThemeOffice2003(BOOL /*bPrimaryCaption*/)
  141. {
  142. XT_ERROR_MSG("CXTCaptionThemeOffice2003::CXTCaptionThemeOffice2003(BOOL bPrimaryCaption) has been deprecated.nn"
  143. "Use CXTCaption::SetAppCaption(bool bAppCaption) to set the application's primary caption.");
  144. }
  145. void CXTCaptionThemeOffice2003::DrawCaptionBack(CDC* pDC, CXTCaption* pCaption, CRect& rcItem)
  146. {
  147. pDC->SetBkMode(TRANSPARENT);
  148. if (pCaption->IsAppCaption())
  149. {
  150. XTPDrawHelpers()->GradientFill(pDC, rcItem, XTPColorManager()->grcCaption, FALSE);
  151. pDC->Draw3dRect(rcItem, GetXtremeColor(XPCOLOR_FRAME), GetXtremeColor(XPCOLOR_FRAME));
  152. }
  153. else
  154. {
  155. XTPDrawHelpers()->GradientFill(pDC, rcItem, XTPColorManager()->grcToolBar, FALSE);
  156. pDC->FillSolidRect(rcItem.left, rcItem.bottom - 1, rcItem.Width(), 1, GetXtremeColor(XPCOLOR_FRAME));
  157. }
  158. }
  159. IMPLEMENT_THEME_FACTORY(CXTCaptionButtonTheme)
  160. /////////////////////////////////////////////////////////////////////////////
  161. // CXTCaptionButtonTheme
  162. CXTCaptionButtonTheme::CXTCaptionButtonTheme()
  163. {
  164. m_bOffsetHiliteText = FALSE;
  165. }
  166. BOOL CXTCaptionButtonTheme::DrawButtonThemeBackground(LPDRAWITEMSTRUCT lpDIS, CXTButton* pButton)
  167. {
  168. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  169. if (::IsWindow(pCaption->GetSafeHwnd()))
  170. {
  171. SetColorFace(pCaption->m_clrFace);
  172. }
  173. return CXTButtonTheme::DrawButtonThemeBackground(lpDIS, pButton);
  174. }
  175. COLORREF CXTCaptionButtonTheme::GetTextColor(UINT /*nState*/, CXTButton* pButton)
  176. {
  177. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  178. if (::IsWindow(pCaption->GetSafeHwnd()))
  179. {
  180. return pCaption->m_clrText;
  181. }
  182. return m_crText;
  183. }
  184. void CXTCaptionButtonTheme::DrawButtonText(CDC* pDC, UINT nState, CRect& rcItem, CXTButton* pButton)
  185. {
  186. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  187. if (::IsWindow(pCaption->GetSafeHwnd()))
  188. {
  189. if (pCaption->IsAppCaption() && !pCaption->GetCaptionText().IsEmpty())
  190. {
  191. // select font into device context.
  192. CXTPFontDC fontDC(pDC, GetThemeFont(pButton));
  193. pDC->SetTextColor(GetTextColor(nState, pButton));
  194. if (nState & ODS_SELECTED && m_bOffsetHiliteText)
  195. rcItem.OffsetRect(1, 1);
  196. // draw the text, and select the original font.
  197. pDC->DrawText(pCaption->GetCaptionText(), rcItem,
  198. DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_CENTER | DT_NOPREFIX);
  199. }
  200. }
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CXTCaptionButtonThemeOfficeXP
  204. CXTCaptionButtonThemeOfficeXP::CXTCaptionButtonThemeOfficeXP()
  205. {
  206. m_bAnimateIcon = FALSE;
  207. m_bFadedIcon = FALSE;
  208. m_bOffsetHiliteText = FALSE;
  209. }
  210. COLORREF CXTCaptionButtonThemeOfficeXP::GetTextColor(UINT nState, CXTButton* pButton)
  211. {
  212. if (nState & ODS_DISABLED)
  213. return GetXtremeColor(COLOR_GRAYTEXT);
  214. if (pButton->GetHilite() || (nState & ODS_SELECTED))
  215. return m_crTextHilite;
  216. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  217. if (::IsWindow(pCaption->GetSafeHwnd()))
  218. {
  219. return pCaption->m_clrText;
  220. }
  221. return m_crText;
  222. }
  223. BOOL CXTCaptionButtonThemeOfficeXP::DrawButtonThemeBackground(LPDRAWITEMSTRUCT lpDIS, CXTButton* pButton)
  224. {
  225. // define some temporary variables.
  226. CDC*  pDC = CDC::FromHandle(lpDIS->hDC);
  227. CRect rcItem = lpDIS->rcItem;
  228. int   nState = lpDIS->itemState;
  229. // Paint the background.
  230. if (pButton->GetHilite() || (nState & ODS_SELECTED))
  231. {
  232. pDC->FillSolidRect(rcItem, (nState & ODS_SELECTED) ?
  233. GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED) : GetXtremeColor(XPCOLOR_HIGHLIGHT));
  234. pDC->Draw3dRect(rcItem, GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER),
  235. GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  236. }
  237. else
  238. {
  239. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  240. if (::IsWindow(pCaption->GetSafeHwnd()))
  241. {
  242. m_crBack = pCaption->m_clrFace;
  243. }
  244. pDC->FillSolidRect(rcItem, m_crBack);
  245. if (m_bWordTheme)
  246. {
  247. pDC->Draw3dRect(rcItem,
  248. m_crBorderShadow, m_crBorderShadow);
  249. }
  250. }
  251. return TRUE;
  252. }
  253. void CXTCaptionButtonThemeOfficeXP::DrawButtonText(CDC* pDC, UINT nState, CRect& rcItem, CXTButton* pButton)
  254. {
  255. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  256. if (::IsWindow(pCaption->GetSafeHwnd()))
  257. {
  258. if (pCaption->IsAppCaption() && !pCaption->GetCaptionText().IsEmpty())
  259. {
  260. // select font into device context.
  261. CXTPFontDC fontDC(pDC, GetThemeFont(pButton));
  262. pDC->SetTextColor(GetTextColor(nState, pButton));
  263. if (nState & ODS_SELECTED && m_bOffsetHiliteText)
  264. rcItem.OffsetRect(1, 1);
  265. // draw the text, and select the original font.
  266. pDC->DrawText(pCaption->GetCaptionText(), rcItem,
  267. DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_CENTER | DT_NOPREFIX);
  268. }
  269. }
  270. }
  271. /////////////////////////////////////////////////////////////////////////////
  272. // CXTCaptionButtonThemeOffice2003
  273. BOOL CXTCaptionButtonThemeOffice2003::GetGradientValues(CRect& rButton, CXTCaption* pCaption, CXTPPaintManagerColorGradient& clr)
  274. {
  275. if (!::IsWindow(pCaption->GetSafeHwnd()))
  276. return FALSE;
  277. // get caption and button coordinates.
  278. CXTPClientRect rCaption(pCaption);
  279. pCaption->ScreenToClient(&rButton);
  280. // get the caption's device context.
  281. CClientDC dc(pCaption);
  282. // create a memory device context to simulate caption background.
  283. CDC memDC;
  284. if (memDC.CreateCompatibleDC(&dc))
  285. {
  286. CBitmap bitmap;
  287. bitmap.CreateCompatibleBitmap(&dc, rCaption.Width(), rCaption.Height());
  288. CBitmap* pBmp = memDC.SelectObject(&bitmap);
  289. // draw a gradient to the memory device context that matches what should be drawn
  290. // on the caption background.
  291. XTPDrawHelpers()->GradientFill(&memDC, rCaption, pCaption->IsAppCaption() ?
  292. XTPColorManager()->grcCaption: XTPColorManager()->grcToolBar, FALSE);
  293. // determine the light color gradient.
  294. COLORREF crLight = memDC.GetPixel(rButton.TopLeft());
  295. // determine the dark color gradient.
  296. COLORREF crDark = memDC.GetPixel(rButton.BottomRight());
  297. // set the gradient to and from values.
  298. clr.SetStandardValue(crLight, crDark);
  299. // cleanup GDI
  300. memDC.SelectObject(pBmp);
  301. memDC.DeleteDC();
  302. bitmap.DeleteObject();
  303. return TRUE;
  304. }
  305. return FALSE;
  306. }
  307. BOOL CXTCaptionButtonThemeOffice2003::DrawButtonThemeBackground(LPDRAWITEMSTRUCT lpDIS, CXTButton* pButton)
  308. {
  309. if (!::IsWindow(pButton->GetSafeHwnd()))
  310. return FALSE;
  311. CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  312. CRect rc = lpDIS->rcItem;
  313. int nState = lpDIS->itemState;
  314. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  315. if (::IsWindow(pCaption->GetSafeHwnd()))
  316. {
  317. BOOL bHilite = pButton->GetHilite();
  318. BOOL bSelected = (nState & ODS_SELECTED) != 0;
  319. // Paint the background.
  320. if (bSelected || bHilite)
  321. {
  322. XTPDrawHelpers()->GradientFill(pDC, rc, bSelected ?
  323. XTPColorManager()->grcLunaPushed: XTPColorManager()->grcLunaSelected, FALSE);
  324. pDC->Draw3dRect(&rc, GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER),
  325. GetMSO2003Color(XPCOLOR_HIGHLIGHT_BORDER));
  326. }
  327. else
  328. {
  329. CXTPWindowRect rButton(pButton);
  330. CXTPPaintManagerColorGradient clr;
  331. GetGradientValues(rButton, pCaption, clr);
  332. XTPDrawHelpers()->GradientFill(pDC, rc, clr, FALSE);
  333. }
  334. return TRUE;
  335. }
  336. return CXTButtonThemeOffice2003::DrawButtonThemeBackground(lpDIS, pButton);
  337. }
  338. COLORREF CXTCaptionButtonThemeOffice2003::GetTextColor(UINT nState, CXTButton* pButton)
  339. {
  340. if (nState & ODS_DISABLED)
  341. return GetXtremeColor(COLOR_GRAYTEXT);
  342. if (pButton->GetHilite() || (nState & ODS_SELECTED))
  343. return m_crTextHilite;
  344. CXTCaption* pCaption = ((CXTCaptionButton*)pButton)->GetCaption();
  345. if (::IsWindow(pCaption->GetSafeHwnd()))
  346. {
  347. return pCaption->m_clrText;
  348. }
  349. return m_crText;
  350. }