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

对话框与窗口

开发平台:

Visual C++

  1. // XTPPopupPaintManager.cpp: implementation of the CXTPPopupPaintManager 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/XTPImageManager.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "Common/XTPRichRender.h"
  24. #include "Common/XTPOffice2007Image.h"
  25. #include "XTPPopupPaintManager.h"
  26. #include "XTPPopupItem.h"
  27. #include "XTPPopupControl.h"
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #define new DEBUG_NEW
  32. #endif
  33. //////////////////////////////////////////////////////////////////////
  34. // Construction/Destruction
  35. //////////////////////////////////////////////////////////////////////
  36. CXTPPopupPaintManager::CXTPPopupPaintManager()
  37. {
  38. }
  39. CXTPPopupPaintManager::~CXTPPopupPaintManager()
  40. {
  41. }
  42. void CXTPPopupPaintManager::RefreshMetrics()
  43. {
  44. m_fntText.DeleteObject();
  45. LOGFONT lfIcon;
  46. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  47. VERIFY(m_fntText.CreateFontIndirect(&lfIcon));
  48. m_clrText = GetXtremeColor(COLOR_BTNTEXT);
  49. m_clrBackground.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  50. m_clrFrame.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  51. m_clrButtonSelected = m_clrButtonPressed = (COLORREF)-1;
  52. m_clrButtonPressedBorder.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
  53. m_clrButtonSelectedBorder.SetStandardValue(GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  54. }
  55. void CXTPPopupPaintManager::DrawBackground(CDC* pDC, CXTPPopupControl* pControl, CRect rcClient)
  56. {
  57. if (pControl->GetBackgroundBitmap() > 0)
  58. {
  59. CXTPImageManagerIcon* pImage = pControl->GetImageManager()->GetImage(pControl->GetBackgroundBitmap(), 0);
  60. if (pImage)
  61. {
  62. pImage->Draw(pDC, CPoint(0, 0));
  63. }
  64. }
  65. else
  66. {
  67. XTPDrawHelpers()->GradientFill(pDC, rcClient, m_clrBackground, TRUE);
  68. if (m_clrFrame.clrLight != (COLORREF)-1)
  69. pDC->Draw3dRect(rcClient, m_clrFrame.clrLight, m_clrFrame.clrDark);
  70. }
  71. }
  72. void CXTPPopupPaintManager::DrawButton(CDC* pDC, CXTPPopupItem* pItem)
  73. {
  74. if (pItem->IsPressed() && pItem->IsSelected())
  75. {
  76. if (m_clrButtonPressed != (COLORREF)-1)
  77. pDC->FillSolidRect(pItem->GetRect(), m_clrButtonPressed);
  78. pDC->Draw3dRect(pItem->GetRect(), m_clrButtonPressedBorder.clrLight, m_clrButtonPressedBorder.clrDark);
  79. }
  80. else if (pItem->IsSelected() || pItem->IsPressed())
  81. {
  82. if (m_clrButtonSelected != (COLORREF)-1)
  83. pDC->FillSolidRect(pItem->GetRect(), m_clrButtonSelected);
  84. pDC->Draw3dRect(pItem->GetRect(), m_clrButtonSelectedBorder.clrLight, m_clrButtonSelectedBorder.clrDark);
  85. }
  86. }
  87. void CXTPPopupPaintManager::SetFont(HFONT hFont)
  88. {
  89. LOGFONT lf;
  90. CFont::FromHandle(hFont)->GetLogFont(&lf);
  91. m_fntText.DeleteObject();
  92. m_fntText.CreateFontIndirect(&lf);
  93. }
  94. void CXTPPopupPaintManager::DrawItem(CDC* pDC, CXTPPopupItem* pItem)
  95. {
  96. CRect rc = pItem->GetRect();
  97. if (pItem->GetBackgroundColor() != (COLORREF)-1)
  98. pDC->FillSolidRect(rc, pItem->GetBackgroundColor());
  99. if (pItem->GetBorderColor() != (COLORREF)-1)
  100. pDC->Draw3dRect(rc, pItem->GetBorderColor(), pItem->GetBorderColor());
  101. CXTPImageManagerIcon* pIcon = pItem->GetImage();
  102. if (pIcon)
  103. {
  104. rc.OffsetRect(pItem->GetIconOffset());
  105. if (pItem->IsPressed() && pItem->IsSelected())
  106. {
  107. if (pItem->IsButton())
  108. DrawButton(pDC, pItem);
  109. pIcon->Draw(pDC, rc.TopLeft(), pIcon->GetCheckedIcon());
  110. }
  111. else if (pItem->IsSelected() || pItem->IsPressed())
  112. {
  113. if (pItem->IsButton())
  114. DrawButton(pDC, (CXTPPopupItem*)pItem);
  115. pIcon->Draw(pDC, rc.TopLeft(), pIcon->GetHotIcon());
  116. }
  117. else
  118. {
  119. pIcon->Draw(pDC, rc.TopLeft(), pIcon->GetIcon());
  120. }
  121. return;
  122. }
  123. if (pItem->IsButton())
  124. DrawButton(pDC, (CXTPPopupItem*)pItem);
  125. if (!pItem->GetCaption().IsEmpty())
  126. {
  127. CXTPRichRender* pRichRender = pItem->m_pRichRender;
  128. CFont fntUnderline;
  129. CFont* pFont = pItem->GetTextFont();
  130. if ((pItem->IsSelected() && pItem->IsHyperLink()) || pItem->IsBold())
  131. {
  132. LOGFONT lpLogFont;
  133. pFont->GetLogFont(&lpLogFont);
  134. lpLogFont.lfUnderline = (pItem->IsSelected() && pItem->IsHyperLink());
  135. lpLogFont.lfWeight = pItem->IsBold() ? FW_BOLD : FW_NORMAL;
  136. VERIFY(fntUnderline.CreateFontIndirect(&lpLogFont));
  137. pFont = &fntUnderline;
  138. }
  139. CRect rcText(pItem->GetRect());
  140. CXTPFontDC font(pDC, pFont);
  141. if (pRichRender)
  142. {
  143. pRichRender->DrawText(pDC, rcText);
  144. }
  145. else
  146. {
  147. if ((pItem->GetTextAlignment() & (DT_WORDBREAK | DT_VCENTER)) == (DT_WORDBREAK | DT_VCENTER))
  148. {
  149. CRect rcTextHeight(rcText.left, 0, rcText.right, 0);
  150. pDC->DrawText(pItem->GetCaption(), rcTextHeight, pItem->GetTextAlignment() | DT_CALCRECT);
  151. rcText.top = (rcText.top + rcText.bottom - rcTextHeight.bottom) / 2;
  152. }
  153. pDC->SetBkMode(TRANSPARENT);
  154. pDC->SetTextColor(pItem->GetTextColor() == (COLORREF)-1 ? m_clrText : pItem->GetTextColor());
  155. pDC->DrawText(pItem->GetCaption(), rcText, pItem->GetTextAlignment());
  156. }
  157. }
  158. }
  159. //////////////////////////////////////////////////////////////////////////
  160. // CXTPPopupThemeOffice2000
  161. CXTPPopupThemeOffice2000::CXTPPopupThemeOffice2000()
  162. {
  163. }
  164. CXTPPopupThemeOffice2000::~CXTPPopupThemeOffice2000()
  165. {
  166. }
  167. void CXTPPopupThemeOffice2000::RefreshMetrics()
  168. {
  169. CXTPPopupPaintManager::RefreshMetrics();
  170. m_clrFrame.SetStandardValue(GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DSHADOW));
  171. }
  172. void CXTPPopupThemeOffice2000::DrawBackground(CDC* pDC, CXTPPopupControl* pControl, CRect rcClient)
  173. {
  174. if (pControl->GetBackgroundBitmap() > 0)
  175. {
  176. CXTPPopupPaintManager::DrawBackground(pDC, pControl, rcClient);
  177. return;
  178. }
  179. XTPDrawHelpers()->GradientFill(pDC, rcClient, m_clrBackground, FALSE);
  180. pDC->Draw3dRect(rcClient, m_clrFrame.clrLight, m_clrFrame.clrDark);
  181. rcClient.DeflateRect(1, 1);
  182. //rcClient.DeflateRect(2, 2);
  183. CRect rcBackground(rcClient.left, rcClient.top, rcClient.right, rcClient.top + 22);
  184. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(0, 0, 128), RGB(24, 180, 192), TRUE);
  185. rcClient.DeflateRect(1, 1);
  186. rcBackground = CRect(rcClient.left, rcBackground.top + 23 , rcClient.right, rcClient.bottom);
  187. pDC->Draw3dRect(rcBackground, m_clrFrame.clrDark, m_clrFrame.clrLight);
  188. rcBackground.DeflateRect(1, 1);
  189. pDC->Draw3dRect(rcBackground, m_clrFrame.clrLight, m_clrFrame.clrDark);
  190. rcBackground.DeflateRect(1, 1);
  191. rcBackground.right = rcBackground.left + 30;
  192. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(0, 0, 128), RGB(0, 0, 128), FALSE);
  193. }
  194. //////////////////////////////////////////////////////////////////////////
  195. // CXTPPopupThemeOfficeXP
  196. CXTPPopupThemeOfficeXP::CXTPPopupThemeOfficeXP()
  197. {
  198. }
  199. CXTPPopupThemeOfficeXP::~CXTPPopupThemeOfficeXP()
  200. {
  201. }
  202. void CXTPPopupThemeOfficeXP::RefreshMetrics()
  203. {
  204. CXTPPopupThemeOffice2000::RefreshMetrics();
  205. m_clrBackground.SetStandardValue(GetXtremeColor(XPCOLOR_TOOLBAR_FACE));
  206. m_clrButtonSelected = GetXtremeColor(XPCOLOR_HIGHLIGHT);
  207. m_clrButtonPressed = GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED);
  208. m_clrButtonSelectedBorder.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  209. m_clrButtonPressedBorder.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  210. m_clrFrame.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  211. }
  212. void CXTPPopupThemeOfficeXP::DrawBackground(CDC* pDC, CXTPPopupControl* pControl, CRect rcClient)
  213. {
  214. if (pControl->GetBackgroundBitmap() > 0)
  215. {
  216. CXTPPopupPaintManager::DrawBackground(pDC, pControl, rcClient);
  217. return;
  218. }
  219. XTPDrawHelpers()->GradientFill(pDC, rcClient, m_clrBackground, FALSE);
  220. pDC->Draw3dRect(rcClient, m_clrFrame.clrLight, m_clrFrame.clrDark);
  221. rcClient.DeflateRect(1, 1);
  222. CRect rcBackground(rcClient.left, rcClient.top, rcClient.right, rcClient.top + 22);
  223. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(0, 0, 128), RGB(24, 180, 192), TRUE);
  224. rcBackground = CRect(rcClient.left, rcBackground.top + 22 , rcClient.right, rcClient.bottom);
  225. rcBackground.DeflateRect(1, 1);
  226. rcBackground.right = rcBackground.left + 30;
  227. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(0, 0, 128), RGB(0, 0, 128), FALSE);
  228. }
  229. //////////////////////////////////////////////////////////////////////////
  230. // CXTPPopupThemeOffice2003
  231. CXTPPopupThemeOffice2003::CXTPPopupThemeOffice2003()
  232. {
  233. }
  234. CXTPPopupThemeOffice2003::~CXTPPopupThemeOffice2003()
  235. {
  236. }
  237. void CXTPPopupThemeOffice2003::RefreshMetrics()
  238. {
  239. CXTPPopupThemeOfficeXP::RefreshMetrics();
  240. m_clrBackground.SetStandardValue(XTPColorManager()->grcDockBar.clrDark, XTPColorManager()->grcDockBar.clrLight);//.SetStandardValue(RGB(214, 231, 252), RGB(168, 198, 238));
  241. m_clrGripper.SetStandardValue(XTPColorManager()->grcShortcutBarGripper);
  242. m_clrFrame.SetStandardValue(GetXtremeColor(XPCOLOR_FRAME));
  243. if (!XTPColorManager()->IsLunaColorsDisabled())
  244. {
  245. XTPCurrentSystemTheme systemTheme = XTPColorManager()->GetCurrentSystemTheme();
  246. switch (systemTheme)
  247. {
  248. case xtpSystemThemeBlue:
  249. case xtpSystemThemeRoyale:
  250. case xtpSystemThemeAero:
  251. m_clrButtonSelected = RGB(255, 238, 194);
  252. m_clrButtonPressed = RGB(254, 128, 62);
  253. m_clrButtonPressedBorder.SetStandardValue(RGB(0, 0, 128));
  254. m_clrButtonSelectedBorder.SetStandardValue(RGB(0, 0, 128));
  255. break;
  256. case xtpSystemThemeOlive:
  257. m_clrButtonSelected = RGB(255, 238, 194);
  258. m_clrButtonPressed = RGB(254, 128, 62);
  259. m_clrButtonPressedBorder.SetStandardValue(RGB(63, 93, 56));
  260. m_clrButtonSelectedBorder.SetStandardValue(RGB(63, 93, 56));
  261. break;
  262. case xtpSystemThemeSilver:
  263. m_clrButtonSelected = RGB(255, 238, 194);
  264. m_clrButtonPressed = RGB(254, 128, 62);
  265. m_clrButtonPressedBorder.SetStandardValue(RGB(75, 75, 111));
  266. m_clrButtonSelectedBorder.SetStandardValue(RGB(75, 75, 111));
  267. break;
  268. }
  269. }
  270. }
  271. void CXTPPopupThemeOffice2003::DrawBackground(CDC* pDC, CXTPPopupControl* pControl, CRect rcClient)
  272. {
  273. if (pControl->GetBackgroundBitmap() > 0)
  274. {
  275. CXTPPopupPaintManager::DrawBackground(pDC, pControl, rcClient);
  276. return;
  277. }
  278. XTPDrawHelpers()->GradientFill(pDC, rcClient, m_clrBackground, FALSE);
  279. pDC->Draw3dRect(rcClient, m_clrFrame.clrLight, m_clrFrame.clrDark);
  280. rcClient.DeflateRect(1, 1);
  281. CRect rcGripper(rcClient);
  282. rcGripper.bottom = rcGripper.top + 7;
  283. XTPDrawHelpers()->GradientFill(pDC, rcGripper, m_clrGripper, FALSE);
  284. int nRight = max (2, (rcGripper.Width() - 4 * 9) / 2);
  285. for (int i = 0; i < 9; i++)
  286. {
  287. pDC->FillSolidRect(nRight, rcGripper.top + 1, 2, 2, RGB(40, 50, 71));
  288. pDC->FillSolidRect(nRight + 1, rcGripper.top + 2, 2, 2, RGB(249, 249, 251));
  289. pDC->FillSolidRect(nRight + 1, rcGripper.top + 2, 1, 1, RGB(97, 116, 152));
  290. nRight += 4;
  291. }
  292. }
  293. //////////////////////////////////////////////////////////////////////////
  294. // CXTPPopupThemeOffice2007
  295. CXTPPopupThemeOffice2007::CXTPPopupThemeOffice2007()
  296. {
  297. }
  298. void CXTPPopupThemeOffice2007::RefreshMetrics()
  299. {
  300. CXTPPopupThemeOffice2003::RefreshMetrics();
  301. m_clrBackground.SetStandardValue(
  302. XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("BackgroundLight")),
  303. XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("BackgroundDark")));
  304. m_clrGripper.SetStandardValue(
  305. XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("CaptionLight")),
  306. XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("CaptionDark")));
  307. m_clrFrame.SetStandardValue(
  308. XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("FrameBorder")));
  309. m_clrText = XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("NormalText"));
  310. m_clrButtonSelected = XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("ButtonSelected"));
  311. m_clrButtonPressed = XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("ButtonPressed"));
  312. m_clrButtonPressedBorder.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("ButtonBorder")));
  313. m_clrButtonSelectedBorder.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PopupControl"), _T("ButtonBorder")));
  314. }
  315. //////////////////////////////////////////////////////////////////////////
  316. // CXTPPopupThemeMSN
  317. CXTPPopupThemeMSN::CXTPPopupThemeMSN()
  318. {
  319. }
  320. CXTPPopupThemeMSN::~CXTPPopupThemeMSN()
  321. {
  322. }
  323. void CXTPPopupThemeMSN::RefreshMetrics()
  324. {
  325. CXTPPopupThemeOffice2000::RefreshMetrics();
  326. m_clrButtonSelected = RGB(194, 238, 255);
  327. m_clrButtonSelectedBorder.SetStandardValue(RGB(114, 142, 184));
  328. m_clrButtonPressed = RGB(134, 162, 224);
  329. m_clrButtonPressedBorder.SetStandardValue(RGB(114, 142, 184));
  330. }
  331. void CXTPPopupThemeMSN::DrawBackground(CDC* pDC, CXTPPopupControl* pControl, CRect rcClient)
  332. {
  333. if (pControl->GetBackgroundBitmap() > 0)
  334. {
  335. CXTPPopupPaintManager::DrawBackground(pDC, pControl, rcClient);
  336. return;
  337. }
  338. pDC->Draw3dRect(rcClient, RGB(166, 180, 207), RGB(69, 86, 144));
  339. rcClient.DeflateRect(1, 1);
  340. pDC->Draw3dRect(rcClient, RGB(255, 255, 255), RGB(207, 222, 244));
  341. rcClient.DeflateRect(1, 1);
  342. CRect rcBackground(rcClient.left, rcClient.top, rcClient.right, rcClient.top + 12);
  343. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(207, 215, 236), RGB(255, 255, 255) , FALSE);
  344. rcBackground = CRect(rcClient.left, rcBackground.bottom, rcClient.right, rcClient.top + 23);
  345. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(255, 255, 255), RGB(207, 221, 244), FALSE);
  346. rcBackground = CRect(rcClient.left, rcBackground.bottom, rcClient.right, rcClient.top + 40);
  347. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(207, 221, 244), RGB(255, 255, 255), FALSE);
  348. rcBackground = CRect(rcClient.left, rcBackground.bottom, rcClient.right, rcClient.bottom);
  349. XTPDrawHelpers()->GradientFill(pDC, rcBackground, RGB(255, 255, 255), RGB(207, 221, 244), FALSE);
  350. CRect rcFrame(rcClient.left, rcClient.top + 22, rcClient.right, rcClient.bottom);
  351. pDC->Draw3dRect(rcFrame, RGB(114, 142, 184), RGB(185, 201, 239));
  352. }