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

对话框与窗口

开发平台:

Visual C++

  1. // XTPDatePickerPaintManager.cpp: implementation of the CXTPDatePickerPaintManager class.
  2. //
  3. // This file is a part of the XTREME CALENDAR 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 "Resource.h"
  22. #include "Common/XTPColorManager.h"
  23. #include "Common/XTPDrawHelpers.h"
  24. #include "Common/XTPResourceManager.h"
  25. #include "Common/XTPOffice2007Image.h"
  26. #include "XTPCalendarUtils.h"
  27. #include "XTPDatePickerPaintManager.h"
  28. #include "XTPDatePickerControl.h"
  29. #include "XTPDatePickerItemMonth.h"
  30. #include "XTPDatePickerItemDay.h"
  31. #ifdef _DEBUG
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #define new DEBUG_NEW
  35. #endif
  36. //////////////////////////////////////////////////////////////////////
  37. // Construction/Destruction
  38. //////////////////////////////////////////////////////////////////////
  39. CXTPDatePickerPaintManager::CXTPDatePickerPaintManager()
  40. {
  41. m_pControl = NULL;
  42. m_bEnableTheme = TRUE;
  43. m_nPaintTheme = xtpCalendarThemeOffice2003;
  44. // initialize default fonts
  45. LOGFONT lfIcon;
  46. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  47. SetFontIndirect(&lfIcon);
  48. // init metrics
  49. RefreshMetrics();
  50. // init cursor
  51. m_hCursorBack = XTPResourceManager()->LoadCursor(XTP_IDC_DATEPICKER_BACKARROW);
  52. }
  53. void CXTPDatePickerPaintManager::SetFontIndirect(LOGFONT* lFont)
  54. {
  55. // initialize default day item font
  56. m_fontDay.DeleteObject();
  57. VERIFY(m_fontDay.CreateFontIndirect(lFont));
  58. LOGFONT lfBold = *lFont;
  59. lfBold.lfWeight = FW_BOLD;
  60. VERIFY(m_fontDayBold.CreateFontIndirect(&lfBold));
  61. // initialize default non month day item font
  62. m_fontNonMonthDay.DeleteObject();
  63. VERIFY(m_fontNonMonthDay.CreateFontIndirect(lFont));
  64. // initialize default header font
  65. m_fontHeader.DeleteObject();
  66. VERIFY(m_fontHeader.CreateFontIndirect(lFont));
  67. // initialize default days of week font
  68. m_fontDaysOfWeek.DeleteObject();
  69. VERIFY(m_fontDaysOfWeek.CreateFontIndirect(lFont));
  70. // initialize default popup list control font
  71. m_fontListControl.DeleteObject();
  72. VERIFY(m_fontListControl.CreateFontIndirect(lFont));
  73. // initialize default button font
  74. m_fontButton.DeleteObject();
  75. VERIFY(m_fontButton.CreateFontIndirect(lFont));
  76. // initialize default week numbers font
  77. m_fontWeekNumbers.DeleteObject();
  78. lFont->lfHeight -= lFont->lfHeight / 3;
  79. VERIFY(m_fontWeekNumbers.CreateFontIndirect(lFont));
  80. }
  81. CXTPDatePickerPaintManager::~CXTPDatePickerPaintManager()
  82. {
  83. //destructor
  84. }
  85. void CXTPDatePickerPaintManager::RefreshMetrics()
  86. {
  87. RefreshXtremeColors();
  88. // get system params
  89. m_clr3DLight = GetSysColor(COLOR_3DLIGHT);
  90. m_clrBtnText = GetSysColor(COLOR_BTNTEXT);
  91. m_clr3DShadow = GetSysColor(COLOR_3DSHADOW);
  92. m_clrBtnFace = GetSysColor(COLOR_BTNFACE);
  93. // initialize default date picker paint manager settings
  94. m_clrControlBack = GetSysColor(COLOR_WINDOW);
  95. m_clrDayBack = m_clrControlBack;
  96. m_clrDayText = GetSysColor(COLOR_WINDOWTEXT);
  97. m_clrNonMonthDayBack = m_clrDayBack;
  98. m_clrSelectedDayBack = GetXtremeColor(XPCOLOR_HIGHLIGHT_CHECKED);
  99. m_clrSelectedDayText = m_clrDayText;
  100. m_clrStaticBorder = GetXtremeColor(XPCOLOR_STATICFRAME);
  101. m_clrHeaderBack = m_clrBtnFace;
  102. m_clrHeaderText = m_clrDayText;
  103. m_clrDaysOfWeekBack = m_clrDayBack;
  104. m_clrDaysOfWeekText = m_clrDayText;
  105. m_clrWeekNumbersBack = m_clrDayBack;
  106. m_clrWeekNumbersText = m_clrDayText;
  107. m_clrListControlBack = m_clrControlBack;
  108. m_clrListControlText = m_clrDayText;
  109. m_clrWeekNumbersText = m_clrHeaderText;
  110. m_clrHighlightToday = GetSysColor(COLOR_HIGHLIGHT);
  111. m_clrNonMonthDayText = m_clr3DShadow;
  112. m_themeButton.CloseTheme();
  113. BOOL bEnableTheme = m_bEnableTheme &&
  114. (GetPaintTheme() >= xtpCalendarThemeOffice2003);
  115. if (bEnableTheme && !XTPColorManager()->IsLunaColorsDisabled())
  116. {
  117. switch (XTPColorManager()->GetCurrentSystemTheme())
  118. {
  119. case xtpSystemThemeBlue:
  120. case xtpSystemThemeRoyale:
  121. case xtpSystemThemeAero:
  122. m_clrSelectedDayBack = RGB(0xFB, 0xE6, 0x94);
  123. m_clrHighlightToday = RGB(0xBB, 0x55, 0x03);
  124. m_clrHeaderBack = RGB(0x9E, 0xBE, 0xF5);
  125. break;
  126. case xtpSystemThemeOlive:
  127. m_clrSelectedDayBack = RGB(251, 230, 148);
  128. m_clrHighlightToday = RGB(187, 85, 3);
  129. m_clrHeaderBack = RGB(217, 217, 167);
  130. break;
  131. case xtpSystemThemeSilver:
  132. m_clrSelectedDayBack = RGB(251, 230, 148);
  133. m_clrHighlightToday = RGB(187, 85, 3);
  134. m_clrHeaderBack = RGB(215, 215, 229);
  135. break;
  136. }
  137. m_themeButton.OpenTheme(0, L"BUTTON");
  138. }
  139. if (GetPaintTheme() < xtpCalendarThemeOffice2003)
  140. {
  141. m_clrSelectedDayBack = m_clrBtnFace;
  142. m_clrSelectedDayText = RGB(255, 255, 255);
  143. m_clrHighlightToday = RGB(130, 0, 0);
  144. }
  145. }
  146. XTPCalendarTheme CXTPDatePickerPaintManager::GetPaintTheme() const
  147. {
  148. return m_nPaintTheme;
  149. }
  150. void CXTPDatePickerPaintManager::SetPaintTheme(XTPCalendarTheme ePaintTheme)
  151. {
  152. ASSERT(ePaintTheme <= xtpCalendarThemeOffice2003);
  153. m_nPaintTheme = min(xtpCalendarThemeOffice2003, ePaintTheme);
  154. RefreshMetrics();
  155. }
  156. void CXTPDatePickerPaintManager::DrawBackground(CDC* pDC, CRect rcClient)
  157. {
  158. pDC->FillSolidRect(rcClient, GetControlBackColor());
  159. }
  160. void CXTPDatePickerPaintManager::DrawBorder(CDC* pDC, const CXTPDatePickerControl* pControl, CRect& rcClient, BOOL bDraw)
  161. {
  162. XTPDatePickerBorderStyle borderStyle = pControl->GetBorderStyle ();
  163. BOOL bThemed = m_themeButton.IsAppThemed();
  164. if (bDraw)
  165. {
  166. if (borderStyle == xtpDatePickerBorder3D)
  167. {
  168. pDC->Draw3dRect(0, 0, rcClient.Width(), rcClient.Height(), m_clrBtnFace, m_clrBtnText);
  169. pDC->Draw3dRect(1, 1, rcClient.Width()-2, rcClient.Height()-2, m_clrControlBack, m_clr3DShadow);
  170. pDC->Draw3dRect(2, 2, rcClient.Width()-4, rcClient.Height()-4, m_clrBtnFace, m_clrBtnFace);
  171. pDC->Draw3dRect(3, 3, rcClient.Width()-6, rcClient.Height()-6, m_clr3DShadow, m_clrControlBack);
  172. }
  173. if ((borderStyle == xtpDatePickerBorderStatic) || (borderStyle == xtpDatePickerBorderOffice && bThemed))
  174. {
  175. pDC->Draw3dRect(0, 0, rcClient.Width(), rcClient.Height(), m_clrStaticBorder, m_clrStaticBorder);
  176. }
  177. if (borderStyle == xtpDatePickerBorderOffice && !bThemed)
  178. {
  179. pDC->Draw3dRect(0, 0, rcClient.Width(), rcClient.Height(), m_clrBtnFace, m_clrBtnText);
  180. pDC->Draw3dRect(1, 1, rcClient.Width()-2, rcClient.Height()-2, m_clrControlBack, m_clr3DShadow);
  181. pDC->Draw3dRect(2, 2, rcClient.Width()-4, rcClient.Height()-4, m_clrBtnFace, m_clrBtnFace);
  182. }
  183. }
  184. else
  185. {
  186. if (borderStyle == xtpDatePickerBorder3D)
  187. {
  188. rcClient.DeflateRect(4, 4, 4, 4);
  189. }
  190. if ((borderStyle == xtpDatePickerBorderStatic) || (borderStyle == xtpDatePickerBorderOffice && bThemed))
  191. {
  192. rcClient.DeflateRect(1, 1, 1, 1);
  193. }
  194. if (borderStyle == xtpDatePickerBorderOffice && !bThemed)
  195. {
  196. rcClient.DeflateRect(3, 3, 3, 3);
  197. }
  198. }
  199. }
  200. void CXTPDatePickerPaintManager::SetButtonFontIndirect(LOGFONT* lFont)
  201. {
  202. m_fontButton.DeleteObject();
  203. m_fontButton.CreateFontIndirect(lFont);
  204. }
  205. void CXTPDatePickerPaintManager::SetButtonFont(CFont* fontButton)
  206. {
  207. LOGFONT lFont;
  208. fontButton->GetLogFont(&lFont);
  209. SetButtonFontIndirect(&lFont);
  210. }
  211. void CXTPDatePickerPaintManager::Triangle(CDC* pDC, CPoint pt0, CPoint pt1, CPoint pt2, COLORREF clrColor)
  212. {
  213. CXTPPenDC pen (*pDC, clrColor);
  214. CXTPBrushDC brush (*pDC, clrColor);
  215. CPoint pts[3];
  216. pts[0] = pt0;
  217. pts[1] = pt1;
  218. pts[2] = pt2;
  219. pDC->Polygon(pts, 3);
  220. }
  221. void CXTPDatePickerPaintManager::DrawScrollTriangle(CDC* pDC, CRect rcSpot, BOOL bLeftDirection, COLORREF clrColor)
  222. {
  223. CPoint ptCenter(rcSpot.CenterPoint());
  224. if (bLeftDirection)
  225. Triangle(pDC, ptCenter, CPoint(ptCenter.x + 4, ptCenter.y - 4), CPoint(ptCenter.x + 4, ptCenter.y + 4), clrColor);
  226. else
  227. Triangle(pDC, ptCenter, CPoint(ptCenter.x - 4, ptCenter.y - 4), CPoint(ptCenter.x - 4, ptCenter.y + 4), clrColor);
  228. }
  229. void CXTPDatePickerPaintManager::DrawButton(CDC* pDC, const CRect& rcButton, const CString& strButton,
  230. BOOL bIsDown, BOOL bIsHighLight)
  231. {
  232. pDC->SetBkMode(TRANSPARENT);
  233. CRect rcButtonX = rcButton;
  234. rcButtonX.DeflateRect(1, 1, 1, 1);
  235. BOOL bThemed = m_themeButton.IsAppThemed() &&
  236.    GetPaintTheme() >= xtpCalendarThemeOffice2003;
  237. if (!bThemed)
  238. {
  239. pDC->FillSolidRect(rcButton, m_clrBtnFace);
  240. if (bIsDown)
  241. {
  242. pDC->Draw3dRect(rcButton, m_clrBtnText, m_clrBtnFace);
  243. pDC->Draw3dRect(rcButtonX, m_clr3DShadow, m_clrControlBack);
  244. }
  245. else
  246. {
  247. pDC->Draw3dRect(rcButton, m_clrBtnFace, m_clrBtnText);
  248. pDC->Draw3dRect(rcButtonX, m_clrControlBack, m_clr3DShadow);
  249. }
  250. }
  251. else
  252. {
  253. m_themeButton.DrawThemeBackground(pDC->GetSafeHdc(), BP_PUSHBUTTON,
  254. bIsDown ? PBS_PRESSED: bIsHighLight ? PBS_HOT : PBS_NORMAL,
  255. &rcButton, NULL);
  256. }
  257. if (!strButton.IsEmpty())
  258. {
  259. CXTPFontDC autoFont(pDC, &m_fontButton, m_clrBtnText);
  260. pDC->DrawText(strButton, rcButtonX, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
  261. }
  262. }
  263. BOOL CXTPDatePickerPaintManager::DrawDay(CDC* pDC, CXTPDatePickerItemDay* pDay)
  264. {
  265. if (!pDC || !pDay)
  266. {
  267. ASSERT(FALSE);
  268. return FALSE;
  269. }
  270. // check this day item
  271. BOOL bThisMonthItem = FALSE;
  272. BOOL bNextMonthItem = FALSE;
  273. BOOL bPreviousMonthItem = FALSE;
  274. CXTPDatePickerControl* pControl = pDay->GetDatePickerControl();
  275. CXTPDatePickerItemMonth* pMonth = pDay->GetMonth();
  276. COleDateTime dtDay = pDay->GetDate();
  277. CRect rcDay = pDay->GetRect();
  278. if (dtDay.GetYear() > pMonth->GetMonth().GetYear())
  279. bNextMonthItem = TRUE;
  280. else if (dtDay.GetYear() < pMonth->GetMonth().GetYear())
  281. bPreviousMonthItem = TRUE;
  282. else // years the same
  283. {
  284. if (dtDay.GetMonth() > pMonth->GetMonth().GetMonth())
  285. bNextMonthItem = TRUE;
  286. else if (dtDay.GetMonth() < pMonth->GetMonth().GetMonth())
  287. bPreviousMonthItem = TRUE;
  288. else // months the same
  289. bThisMonthItem = TRUE;
  290. }
  291. if (bPreviousMonthItem && !pMonth->GetShowDaysBefore())
  292. return FALSE;
  293. if (bNextMonthItem && !pMonth->GetShowDaysAfter())
  294. return FALSE;
  295. // set default drawing metrics depending on item month position
  296. XTP_DAYITEM_METRICS* pMetrics = new XTP_DAYITEM_METRICS;
  297. pMetrics->clrBackground = bThisMonthItem ?
  298. GetDayBackColor() : GetNonMonthDayBackColor();
  299. pMetrics->clrForeground = bThisMonthItem ?
  300. GetDayTextColor() : GetNonMonthDayTextColor();
  301. pMetrics->SetFont(bThisMonthItem ?
  302. GetDayTextFont() : GetNonMonthDayTextFont());
  303. // call callback function for changing parameters if needed
  304. pControl->GetDayMetrics(dtDay, pMetrics);
  305. // change default drawing metrics if day is selected
  306. if (pControl->IsSelected(dtDay))
  307. {
  308. pMetrics->clrBackground = GetSelectedDayBackColor();
  309. pMetrics->clrForeground = GetSelectedDayTextColor();
  310. }
  311. // apply settings to the DC
  312. pDC->SetBkMode(TRANSPARENT);
  313. pDC->SetTextColor(pMetrics->clrForeground);
  314. // fill background
  315. pDC->FillSolidRect(rcDay, pMetrics->clrBackground);
  316. // make a text for drawing
  317. CString strText;
  318. strText.Format(_T("%i"), dtDay.GetDay());
  319. // draw item content
  320. {
  321. // draw item text
  322. CXTPFontDC fntdc(pDC, pMetrics->GetFont());
  323. pDC->DrawText(strText, &rcDay, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOCLIP);
  324. }
  325. CRect rcFocus = rcDay;
  326. BOOL bToday = FALSE;
  327. // highlight today item
  328. if (pControl->GetHighlightToday() && pDay->IsToday(dtDay))
  329. {
  330. pDC->Draw3dRect(rcDay, GetHighlightTodayColor(), GetHighlightTodayColor());
  331. bToday = TRUE;
  332. }
  333. if (pControl->IsFocused(dtDay) && pControl->GetSafeHwnd() == ::GetFocus())
  334. {
  335. if (!bToday)
  336. {
  337. pDC->SetTextColor(0);
  338. pDC->SetBkColor(RGB(255, 255, 255));
  339. pDC->DrawFocusRect(&rcFocus);
  340. }
  341. else
  342. {
  343. COLORREF clrFocus = GetHighlightTodayColor();
  344. clrFocus = clrFocus ^ RGB(255, 128, 128);
  345. rcFocus.DeflateRect(0, 0, 1, 1);
  346. CPen pen1(PS_DOT, 1, clrFocus);
  347. CXTPPenDC autoPen(pDC, &pen1);
  348. pDC->MoveTo(rcFocus.TopLeft());
  349. pDC->LineTo(rcFocus.right, rcFocus.top);
  350. pDC->LineTo(rcFocus.right, rcFocus.bottom);
  351. pDC->LineTo(rcFocus.left, rcFocus.bottom);
  352. pDC->LineTo(rcFocus.left, rcFocus.top);
  353. }
  354. }
  355. pMetrics->InternalRelease();
  356. return TRUE;
  357. }
  358. void CXTPDatePickerPaintManager::DrawMonthHeader(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  359. {
  360. if (pMonth->m_rcHeader.IsRectEmpty())
  361. return;
  362. CXTPDatePickerControl* pControl = pMonth->m_pControl;
  363. COleDateTime dtMonth = pMonth->GetMonth();
  364. CRect rcHeader = pMonth->m_rcHeader;
  365. CRect rcLeftScroll = pMonth->m_rcLeftScroll;
  366. CRect rcRightScroll = pMonth->m_rcRightScroll;
  367. CXTPClientRect rcClient(pControl);
  368. DrawBorder(pDC, pControl, rcClient, FALSE);
  369. CRect rcHeaderBk = pMonth->m_rcMonth;
  370. rcHeaderBk.bottom = rcHeader.bottom;
  371. // fill background
  372. if (GetPaintTheme() >= xtpCalendarThemeOffice2003)
  373. {
  374. pDC->FillSolidRect(rcHeaderBk, GetHeaderBackColor());
  375. }
  376. else
  377. {
  378. int nVertDiv = 0;
  379. if (pMonth->m_nColumn == 0)
  380. rcHeaderBk.left = rcClient.left + 1;
  381. if (pMonth->m_nColumn == pControl->GetCols() - 1)
  382. {
  383. rcHeaderBk.right = rcClient.right;
  384. nVertDiv = 2;
  385. }
  386. else
  387. {
  388. rcHeaderBk.right += 2;
  389. nVertDiv = 1;
  390. }
  391. pDC->FillSolidRect(rcHeaderBk, GetHeaderBackColor());
  392. pDC->FillSolidRect(rcHeaderBk.left - 1, rcHeaderBk.bottom-1, rcHeaderBk.Width()+1, 1, m_clr3DShadow);
  393. if (nVertDiv == 1)
  394. {
  395. CRect rcDiv = rcHeaderBk;
  396. rcDiv.DeflateRect(0, 1, 3, 2);
  397. rcDiv.left = rcDiv.right - 1;
  398. pDC->FillSolidRect(rcDiv, m_clr3DShadow);
  399. rcDiv.left++;
  400. rcDiv.right++;
  401. pDC->FillSolidRect(rcDiv, m_clrControlBack);
  402. }
  403. else if (nVertDiv == 2)
  404. {
  405. CRect rcDiv = rcHeaderBk;
  406. rcDiv.left = rcDiv.right - 1;
  407. rcDiv.top--;
  408. pDC->FillSolidRect(rcDiv, m_clr3DShadow);
  409. }
  410. }
  411. // draw header text
  412. pDC->SetBkColor(GetHeaderBackColor());
  413. pDC->SetTextColor(GetHeaderTextColor());
  414. CXTPFontDC fnt(pDC, GetHeaderTextFont());
  415. CString strText;
  416. strText.Format(_T("%s %d"), (LPCTSTR)pControl->GetMonthName( dtMonth.GetMonth()), dtMonth.GetYear());
  417. pDC->DrawText(strText, &rcHeader, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
  418. // draw left scroll triangle
  419. if (!rcLeftScroll.IsRectEmpty())
  420. {
  421. // fill background
  422. //pDC->FillSolidRect(rcLeftScroll, GetHeaderBackColor());
  423. // draw left triangle itself
  424. if (pMonth->GetShowLeftScroll())
  425. DrawScrollTriangle(pDC, rcLeftScroll, TRUE);
  426. }
  427. // draw right scroll triangle
  428. if (!rcRightScroll.IsRectEmpty())
  429. {
  430. // fill background
  431. //pDC->FillSolidRect(rcRightScroll, GetHeaderBackColor());
  432. // draw right triangle itself
  433. if (pMonth->GetShowRightScroll())
  434. DrawScrollTriangle(pDC, rcRightScroll, FALSE);
  435. }
  436. }
  437. void CXTPDatePickerPaintManager::DrawDaysOfWeek(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  438. {
  439. if (pMonth->m_rcDaysOfWeek.IsRectEmpty())
  440. return;
  441. CXTPDatePickerControl* pControl = pMonth->m_pControl;
  442. // fill background
  443. pDC->FillSolidRect(pMonth->m_rcDaysOfWeek, GetDaysOfWeekBackColor());
  444. // draw days of week text
  445. pDC->SetBkColor(GetDaysOfWeekBackColor());
  446. pDC->SetTextColor(GetDaysOfWeekTextColor());
  447. CXTPFontDC fnt(pDC, GetDaysOfWeekTextFont());
  448. int nMaxX = 0;
  449. for (int nDayDelta = 0; nDayDelta < XTP_WEEK_DAYS; nDayDelta++)
  450. {
  451. // calc item rect
  452. CXTPDatePickerItemDay* pDay = pMonth->GetDay(nDayDelta);
  453. CRect rcItem(pDay->GetRect());
  454. rcItem.top = pMonth->m_rcDaysOfWeek.top;
  455. rcItem.bottom = pMonth->m_rcDaysOfWeek.bottom - 2;
  456. nMaxX = rcItem.right;
  457. // get item text
  458. CString strText(pControl->GetDayOfWeekName(pDay->GetDate().GetDayOfWeek()));
  459. int nChrLen = (int)_tcsnbcnt(strText, 1);
  460. pDC->DrawText(strText, nChrLen, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
  461. }
  462. // draw bottom line on days of the week
  463. CRect rcBottomLine(pMonth->m_rcDaysOfWeek);
  464. rcBottomLine.bottom--;
  465. rcBottomLine.top = rcBottomLine.bottom - 1;
  466. rcBottomLine.left = pMonth->m_rcWeekNumbers.right - 1;
  467. rcBottomLine.right = nMaxX;
  468. pDC->FillSolidRect(rcBottomLine, GetNonMonthDayTextColor());
  469. }
  470. void CXTPDatePickerPaintManager::DrawWeekNumbers(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  471. {
  472. CXTPDatePickerControl* pControl = pMonth->m_pControl;
  473. if (!pControl->GetShowWeekNumbers() || pMonth->m_rcWeekNumbers.IsRectEmpty())
  474. return;
  475. // fill background
  476. pDC->FillSolidRect(pMonth->m_rcWeekNumbers, GetWeekNumbersBackColor());
  477. // draw week numbers
  478. pDC->SetBkColor(GetWeekNumbersBackColor());
  479. pDC->SetTextColor(GetWeekNumbersTextColor());
  480. CXTPFontDC fnt(pDC, GetWeekNumbersTextFont());
  481. // draw right line on week days
  482. CRect rcLine(pMonth->m_rcWeekNumbers);
  483. for (int nWeek = 0; nWeek < XTP_MAX_WEEKS; nWeek++)
  484. {
  485. // calculate item rectangle (get week middle day)
  486. CXTPDatePickerItemDay* pDayFirst = pMonth->GetDay(nWeek * XTP_WEEK_DAYS);
  487. CXTPDatePickerItemDay* pDayLast = pMonth->GetDay((nWeek + 1) * XTP_WEEK_DAYS - 1);
  488. if (pDayFirst && (pDayFirst->IsVisible() || nWeek < 4) && pDayLast)
  489. {
  490. CRect rcItem(pDayFirst->GetRect());
  491. rcItem.left = pMonth->m_rcWeekNumbers.left;
  492. rcItem.right = pMonth->m_rcWeekNumbers.right - 3;
  493. // get item text
  494. CString strText;
  495. int nWeekNumber = ((pDayLast->GetDate() - COleDateTimeSpan(pControl->GetFirstWeekOfYearDays() - 1)).GetDayOfYear() - 1) / 7 + 1;
  496. strText.Format(_T("%d"), nWeekNumber);
  497. pDC->DrawText(strText, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);
  498. rcLine.bottom = rcItem.bottom;
  499. }
  500. }
  501. pDC->FillSolidRect(rcLine.right - 1, rcLine.top - 1, 1, rcLine.Height(), GetNonMonthDayTextColor());
  502. }
  503. CSize CXTPDatePickerPaintManager::CalcDayRect(CDC* pDC)
  504. {
  505. CFont* fontOld = pDC->SelectObject(&m_fontDay);
  506. CSize szDay = pDC->GetTextExtent(_T("30"), 2);
  507. szDay.cx += 4;
  508. szDay.cy += 2;
  509. pDC->SelectObject(fontOld);
  510. return szDay;
  511. }
  512. CSize CXTPDatePickerPaintManager::CalcMonthHeaderRect(CDC* pDC)
  513. {
  514. CFont* fontOld = pDC->SelectObject(&m_fontHeader);
  515. CSize szHeader = pDC->GetTextExtent(_T(" "), 1);
  516. szHeader.cy += 4;
  517. pDC->SelectObject(fontOld);
  518. return szHeader;
  519. }
  520. CSize CXTPDatePickerPaintManager::CalcDayOfWeekRect(CDC* pDC)
  521. {
  522. CFont* fontOld = pDC->SelectObject(&m_fontDaysOfWeek);
  523. CSize szWeekText = pDC->GetTextExtent(_T(" "), 1);
  524. szWeekText.cy += 4;
  525. pDC->SelectObject(fontOld);
  526. return szWeekText;
  527. }
  528. CSize CXTPDatePickerPaintManager::CalcWeekNumbersRect(CDC* pDC)
  529. {
  530. CFont* fontOld = pDC->SelectObject(&m_fontWeekNumbers);
  531. CSize szWeekNumber = pDC->GetTextExtent(_T("88"), 2);
  532. szWeekNumber.cx += 8;
  533. pDC->SelectObject(fontOld);
  534. return szWeekNumber;
  535. }
  536. CSize CXTPDatePickerPaintManager::CalcMonthRect(CDC* pDC)
  537. {
  538. CSize szDay(CalcDayRect(pDC));
  539. CSize szHeader(CalcMonthHeaderRect(pDC));
  540. CSize szWeekText(CalcDayOfWeekRect(pDC));
  541. CSize szWeekNumber(CalcWeekNumbersRect(pDC));
  542. CSize szMonth(0, 0);
  543. szMonth.cx = (szDay.cx * 7 + szWeekNumber.cx * 2);
  544. szMonth.cy = (szDay.cy * 6 + szWeekText.cy + szHeader.cy);
  545. return szMonth;
  546. }
  547. //***************************************************************************
  548. IMPLEMENT_DYNAMIC(CXTPDatePickerThemePart, CCmdTarget)
  549. IMPLEMENT_DYNAMIC(CXTPDatePickerTheme, CCmdTarget)
  550. IMPLEMENT_DYNCREATE(CXTPDatePickerThemeOffice2007, CXTPDatePickerTheme)
  551. void CXTPDatePickerThemePart::Create(CXTPDatePickerTheme* pTheme)
  552. {
  553. ASSERT(pTheme);
  554. ASSERT(!m_pTheme);
  555. m_pTheme = pTheme;
  556. if (m_pTheme)
  557. {
  558. m_pTheme->m_arMembers.Add(this);
  559. }
  560. }
  561. CXTPDatePickerTheme::~CXTPDatePickerTheme()
  562. {
  563. m_Sink.UnadviseAll();
  564. }
  565. void CXTPDatePickerTheme::SetControl(CXTPDatePickerControl*  pControl)
  566. {
  567. m_Sink.UnadviseAll();
  568. TBase::SetControl(pControl);
  569. if (pControl && XTPOffice2007Images() && XTPOffice2007Images()->GetConnection())
  570. {
  571. m_Sink.Advise(XTPOffice2007Images()->GetConnection(), XTP_NC_COMMON_OFFICE2007IMAGES_CHANGED,
  572.    &CXTPDatePickerTheme::OnEvent_Office2007ImagesChanged);
  573. }
  574. }
  575. void CXTPDatePickerTheme::OnEvent_Office2007ImagesChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  576. {
  577. UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam);
  578. ASSERT(Event == XTP_NC_COMMON_OFFICE2007IMAGES_CHANGED);
  579. if (Event == XTP_NC_COMMON_OFFICE2007IMAGES_CHANGED)
  580. {
  581. RefreshMetrics();
  582. if (GetControl())
  583. GetControl()->RedrawControl();
  584. }
  585. }
  586. void CXTPDatePickerTheme::RefreshMetrics()
  587. {
  588. TBase::RefreshMetrics(); //RefreshXtremeColors();
  589. m_clrBackground.SetStandardValue(GetSysColor(COLOR_WINDOW));
  590. m_clrLineTop.SetStandardValue(GetSysColor(COLOR_3DSHADOW));
  591. m_clrLineLeft.SetStandardValue(GetSysColor(COLOR_3DSHADOW));
  592. //  m_clrLineBottom.SetStandardValue(GetSysColor(COLOR_3DSHADOW));
  593. m_fntBaseFont.SetStandardValue(&m_fontDay);
  594. m_fntBaseFontBold.SetStandardValue(&m_fontDayBold);
  595. //-------------------------------------
  596. int nCount = m_arMembers.GetCount();
  597. for (int i = 0; i < nCount; i++)
  598. {
  599. CXTPDatePickerThemePart* pPart = m_arMembers.GetAt(i);
  600. ASSERT(pPart);
  601. if (pPart)
  602. pPart->RefreshMetrics();
  603. }
  604. }
  605. void CXTPDatePickerTheme::CTODay::RefreshMetrics()
  606. {
  607. ASSERT(m_pTheme);
  608. if (!m_pTheme)
  609. return;
  610. // text colors
  611. m_Normal.fcsetText.clrColor.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  612. m_Normal.fcsetTextBold.clrColor.SetStandardValue(m_Normal.fcsetText.clrColor);
  613. m_Normal.fcsetTextGrayed.clrColor.SetStandardValue(GetSysColor(COLOR_3DSHADOW));
  614. m_Normal.fcsetTextGrayedBold.clrColor.SetStandardValue(m_Normal.fcsetTextGrayed.clrColor);
  615. // Bk colors
  616. m_Normal.fcsetText.clrBkColor.SetStandardValue(m_pTheme->m_clrBackground);
  617. m_Normal.fcsetTextBold.clrBkColor.SetStandardValue(m_pTheme->m_clrBackground);
  618. m_Normal.fcsetTextGrayed.clrBkColor.SetStandardValue(m_pTheme->m_clrBackground);
  619. m_Normal.fcsetTextGrayedBold.clrBkColor.SetStandardValue(m_pTheme->m_clrBackground);
  620. // fonts
  621. m_Normal.fcsetText.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);
  622. m_Normal.fcsetTextGrayed.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);
  623. m_Normal.fcsetTextBold.fntFont.SetStandardValue(m_pTheme->m_fntBaseFontBold);
  624. m_Normal.fcsetTextGrayedBold.fntFont.SetStandardValue(m_pTheme->m_fntBaseFontBold);
  625. //----------------------------------------
  626. // Selected text colors
  627. m_Selected.fcsetText.clrColor.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  628. m_Selected.fcsetTextBold.clrColor.SetStandardValue(m_Normal.fcsetText.clrColor);
  629. m_Selected.fcsetTextGrayed.clrColor.SetStandardValue(GetSysColor(COLOR_3DSHADOW));
  630. m_Selected.fcsetTextGrayedBold.clrColor.SetStandardValue(m_Normal.fcsetTextGrayed.clrColor);
  631. // Selected Bk colors
  632. m_Selected.fcsetText.clrBkColor.SetStandardValue(GetXtremeColor(XPCOLOR_HIGHLIGHT_CHECKED));
  633. m_Selected.fcsetTextBold.clrBkColor.SetStandardValue(m_Selected.fcsetText.clrBkColor);
  634. m_Selected.fcsetTextGrayed.clrBkColor.SetStandardValue(m_Selected.fcsetText.clrBkColor);
  635. m_Selected.fcsetTextGrayedBold.clrBkColor.SetStandardValue(m_Selected.fcsetText.clrBkColor);
  636. // Selected fonts
  637. m_Selected.fcsetText.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);
  638. m_Selected.fcsetTextGrayed.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);
  639. m_Selected.fcsetTextBold.fntFont.SetStandardValue(m_pTheme->m_fntBaseFontBold);
  640. m_Selected.fcsetTextGrayedBold.fntFont.SetStandardValue(m_pTheme->m_fntBaseFontBold);
  641. //----------------------------------
  642. m_clrToodayFrame.SetStandardValue(GetSysColor(COLOR_HIGHLIGHT));
  643. }
  644. void CXTPDatePickerTheme::CTOMonthHeader::RefreshMetrics()
  645. {
  646. ASSERT(m_pTheme);
  647. if (!m_pTheme)
  648. return;
  649. m_clrBackground.SetStandardValue(GetSysColor(COLOR_BTNFACE));
  650. m_clrButtons.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  651. m_Text.clrColor.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  652. m_Text.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);
  653. }
  654. void CXTPDatePickerTheme::CTOWeekDay::RefreshMetrics()
  655. {
  656. ASSERT(m_pTheme);
  657. if (!m_pTheme)
  658. return;
  659. m_Text.clrColor.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  660. m_Text.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);;
  661. }
  662. void CXTPDatePickerTheme::CTOWeekNumber::RefreshMetrics()
  663. {
  664. ASSERT(m_pTheme);
  665. if (!m_pTheme)
  666. return;
  667. m_Text.clrColor.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  668. LOGFONT lFont;
  669. m_pTheme->m_fntBaseFont->GetLogFont(&lFont);
  670. lFont.lfHeight -= lFont.lfHeight / 3;
  671. m_Text.fntFont.SetStandardValue(&lFont);
  672. }
  673. void CXTPDatePickerTheme::CTOButton::RefreshMetrics()
  674. {
  675. ASSERT(m_pTheme);
  676. if (!m_pTheme)
  677. return;
  678. m_Text.clrColor.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  679. m_Text.fntFont.SetStandardValue(m_pTheme->m_fntBaseFont);;
  680. }
  681. void CXTPDatePickerTheme::DrawBackground(CDC* pDC, CRect rcClient)
  682. {
  683. pDC->FillSolidRect(rcClient, m_clrBackground);
  684. }
  685. void CXTPDatePickerTheme::DrawBorder(CDC* pDC, const CXTPDatePickerControl* pControl, CRect& rcClient, BOOL bDraw)
  686. {
  687. // TODO: customize border
  688. TBase::DrawBorder(pDC, pControl, rcClient, bDraw);
  689. }
  690. void CXTPDatePickerTheme::DrawScrollTriangle(CDC* pDC, CRect rcSpot, BOOL bLeftDirection, COLORREF clrColor)
  691. {
  692. // TODO: customize L/R buttons
  693. TBase::DrawScrollTriangle(pDC, rcSpot, bLeftDirection, clrColor);
  694. }
  695. void CXTPDatePickerTheme::DrawButton(CDC* pDC, const CRect& rcButton, const CString& strButton,
  696. BOOL bIsDown, BOOL bIsHighLight)
  697. {
  698. // TODO: customize
  699. TBase::DrawButton(pDC, rcButton, _T(""), bIsDown, bIsHighLight);
  700. if (!strButton.IsEmpty())
  701. {
  702. CRect rcButtonX = rcButton;
  703. rcButtonX.DeflateRect(1, 1, 1, 1);
  704. CXTPFontDC autoFont(pDC, GetButtonPart()->m_Text.fntFont, GetButtonPart()->m_Text.clrColor);
  705. pDC->DrawText(strButton, rcButtonX, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
  706. }
  707. }
  708. CSize CXTPDatePickerTheme::CalcDayRect(CDC* pDC)
  709. {
  710. CArray<CFont*, CFont*> arFonts;
  711. arFonts.Add(GetDayPart()->m_Normal.fcsetText.fntFont);
  712. arFonts.Add(GetDayPart()->m_Normal.fcsetTextBold.fntFont);
  713. arFonts.Add(GetDayPart()->m_Normal.fcsetTextGrayed.fntFont);
  714. arFonts.Add(GetDayPart()->m_Normal.fcsetTextGrayedBold.fntFont);
  715. arFonts.Add(GetDayPart()->m_Selected.fcsetText.fntFont);
  716. arFonts.Add(GetDayPart()->m_Selected.fcsetTextBold.fntFont);
  717. arFonts.Add(GetDayPart()->m_Selected.fcsetTextGrayed.fntFont);
  718. arFonts.Add(GetDayPart()->m_Selected.fcsetTextGrayedBold.fntFont);
  719. CFont* pFontMax = CXTPCalendarUtils::GetMaxHeightFont(arFonts, pDC);
  720. ASSERT(pFontMax);
  721. if (!pFontMax)
  722. return CSize(10, 10);
  723. CXTPFontDC autoFont(pDC, pFontMax);
  724. CSize szDay = pDC->GetTextExtent(_T("30"), 2);
  725. szDay.cx += 4;
  726. szDay.cy += 2;
  727. return szDay;
  728. }
  729. CSize CXTPDatePickerTheme::CalcMonthHeaderRect(CDC* pDC)
  730. {
  731. CXTPFontDC autoFont(pDC, GetMonthHeaderPart()->m_Text.fntFont);
  732. CSize szHeader = pDC->GetTextExtent(_T(" "), 1);
  733. szHeader.cy += 4;
  734. return szHeader;
  735. }
  736. CSize CXTPDatePickerTheme::CalcDayOfWeekRect(CDC* pDC)
  737. {
  738. CXTPFontDC autoFont(pDC, GetWeekDayPart()->m_Text.fntFont);
  739. CSize szWeekText = pDC->GetTextExtent(_T(" "), 1);
  740. szWeekText.cy += 4;
  741. return szWeekText;
  742. }
  743. CSize CXTPDatePickerTheme::CalcWeekNumbersRect(CDC* pDC)
  744. {
  745. CXTPFontDC autoFont(pDC, GetWeekNumberPart()->m_Text.fntFont);
  746. CSize szWeekNumber = pDC->GetTextExtent(_T("88"), 2);
  747. szWeekNumber.cx += 8;
  748. return szWeekNumber;
  749. }
  750. BOOL CXTPDatePickerTheme::DrawDay(CDC* pDC, CXTPDatePickerItemDay* pDay)
  751. {
  752. return GetDayPart()->Draw(pDC, pDay);
  753. }
  754. void CXTPDatePickerTheme::DrawWeekNumbers(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  755. {
  756. GetWeekNumberPart()->Draw(pDC, pMonth);
  757. }
  758. void CXTPDatePickerTheme::DrawDaysOfWeek(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  759. {
  760. GetWeekDayPart()->Draw(pDC, pMonth);
  761. }
  762. void CXTPDatePickerTheme::DrawMonthHeader(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  763. {
  764. GetMonthHeaderPart()->Draw(pDC, pMonth);
  765. }
  766. BOOL CXTPDatePickerTheme::CTODay::Draw(CDC* pDC, CXTPDatePickerItemDay* pDay)
  767. {
  768. if (!pDC || !pDay)
  769. {
  770. ASSERT(FALSE);
  771. return FALSE;
  772. }
  773. // check this day item
  774. BOOL bThisMonthItem = FALSE;
  775. BOOL bNextMonthItem = FALSE;
  776. BOOL bPreviousMonthItem = FALSE;
  777. CXTPDatePickerControl* pControl = pDay->GetDatePickerControl();
  778. CXTPDatePickerItemMonth* pMonth = pDay->GetMonth();
  779. COleDateTime dtDay = pDay->GetDate();
  780. CRect rcDay = pDay->GetRect();
  781. if (dtDay.GetYear() > pMonth->GetMonth().GetYear())
  782. bNextMonthItem = TRUE;
  783. else if (dtDay.GetYear() < pMonth->GetMonth().GetYear())
  784. bPreviousMonthItem = TRUE;
  785. else // years the same
  786. {
  787. if (dtDay.GetMonth() > pMonth->GetMonth().GetMonth())
  788. bNextMonthItem = TRUE;
  789. else if (dtDay.GetMonth() < pMonth->GetMonth().GetMonth())
  790. bPreviousMonthItem = TRUE;
  791. else // months the same
  792. bThisMonthItem = TRUE;
  793. }
  794. if (bPreviousMonthItem && !pMonth->GetShowDaysBefore())
  795. return FALSE;
  796. if (bNextMonthItem && !pMonth->GetShowDaysAfter())
  797. return FALSE;
  798. // set default drawing metrics depending on item month position
  799. XTP_DAYITEM_METRICS* pMetrics = new XTP_DAYITEM_METRICS;
  800. CDayItem& setDI = pControl->IsSelected(dtDay) ? m_Selected : m_Normal;
  801. pMetrics->clrBackground = bThisMonthItem ?
  802. setDI.fcsetText.clrBkColor : setDI.fcsetTextGrayed.clrBkColor;
  803. pMetrics->clrForeground = bThisMonthItem ?
  804. setDI.fcsetText.clrColor : setDI.fcsetTextGrayed.clrColor;
  805. pMetrics->SetFont(bThisMonthItem ?
  806. setDI.fcsetText.fntFont : setDI.fcsetTextGrayed.fntFont);
  807. // call callback function for changing parameters if needed
  808. pControl->GetDayMetrics(dtDay, pMetrics);
  809. // apply settings to the DC
  810. pDC->SetBkMode(TRANSPARENT);
  811. pDC->SetTextColor(pMetrics->clrForeground);
  812. // fill background
  813. pDC->FillSolidRect(rcDay, pMetrics->clrBackground);
  814. // make a text for drawing
  815. CString strText;
  816. strText.Format(_T("%i"), dtDay.GetDay());
  817. // draw item content
  818. {
  819. // draw item text
  820. CXTPFontDC fntdc(pDC, pMetrics->GetFont());
  821. pDC->DrawText(strText, &rcDay, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOCLIP);
  822. }
  823. CRect rcFocus = rcDay;
  824. BOOL bToday = FALSE;
  825. // highlight today item
  826. if (pControl->GetHighlightToday() && pDay->IsToday(dtDay))
  827. {
  828. pDC->Draw3dRect(rcDay, m_clrToodayFrame, m_clrToodayFrame);
  829. bToday = TRUE;
  830. }
  831. if (pControl->IsFocused(dtDay) && pControl->GetSafeHwnd() == ::GetFocus())
  832. {
  833. if (!bToday)
  834. {
  835. pDC->SetTextColor(0);
  836. pDC->SetBkColor(RGB(255, 255, 255));
  837. pDC->DrawFocusRect(&rcFocus);
  838. }
  839. else
  840. {
  841. COLORREF clrFocus = m_clrToodayFrame;
  842. clrFocus = clrFocus ^ RGB(255, 128, 128);
  843. rcFocus.DeflateRect(0, 0, 1, 1);
  844. CPen pen1(PS_DOT, 1, clrFocus);
  845. CXTPPenDC autoPen(pDC, &pen1);
  846. pDC->MoveTo(rcFocus.TopLeft());
  847. pDC->LineTo(rcFocus.right, rcFocus.top);
  848. pDC->LineTo(rcFocus.right, rcFocus.bottom);
  849. pDC->LineTo(rcFocus.left, rcFocus.bottom);
  850. pDC->LineTo(rcFocus.left, rcFocus.top);
  851. }
  852. }
  853. pMetrics->InternalRelease();
  854. return TRUE;
  855. }
  856. void CXTPDatePickerTheme::CTOMonthHeader::Draw(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  857. {
  858. class CXTPDatePickerItemMonth_helper : public CXTPDatePickerItemMonth {
  859. friend class CXTPDatePickerTheme::CTOMonthHeader;
  860. };
  861. CXTPDatePickerItemMonth_helper* pMonthX = (CXTPDatePickerItemMonth_helper*)pMonth;
  862. CXTPDatePickerControl* pControl = pMonthX->m_pControl;
  863. if (pMonthX->m_rcHeader.IsRectEmpty())
  864. return;
  865. COleDateTime dtMonth = pMonth->GetMonth();
  866. CRect rcHeader = pMonthX->m_rcHeader;
  867. CRect rcLeftScroll = pMonthX->m_rcLeftScroll;
  868. CRect rcRightScroll = pMonthX->m_rcRightScroll;
  869. pDC->SetBkMode(TRANSPARENT);
  870. // fill background
  871. pDC->FillSolidRect(rcHeader, m_clrBackground);
  872. // draw header text
  873. CXTPFontDC fnt(pDC, m_Text.fntFont, m_Text.clrColor);
  874. CString strText;
  875. strText.Format(_T("%s %d"), (LPCTSTR)pControl->GetMonthName( dtMonth.GetMonth()), dtMonth.GetYear());
  876. pDC->DrawText(strText, &rcHeader, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
  877. // draw left scroll triangle
  878. if (!rcLeftScroll.IsRectEmpty())
  879. {
  880. // fill background
  881. pDC->FillSolidRect(rcLeftScroll, m_clrBackground);
  882. // draw left triangle itself
  883. if (pMonth->GetShowLeftScroll())
  884. m_pTheme->DrawScrollTriangle(pDC, rcLeftScroll, TRUE, m_clrButtons);
  885. }
  886. // draw right scroll triangle
  887. if (!rcRightScroll.IsRectEmpty())
  888. {
  889. // fill background
  890. pDC->FillSolidRect(rcRightScroll, m_clrBackground);
  891. // draw right triangle itself
  892. if (pMonth->GetShowRightScroll())
  893. m_pTheme->DrawScrollTriangle(pDC, rcRightScroll, FALSE, m_clrButtons);
  894. }
  895. }
  896. void CXTPDatePickerTheme::CTOWeekDay::Draw(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  897. {
  898. class CXTPDatePickerItemMonth_helper : public CXTPDatePickerItemMonth {
  899. friend class CXTPDatePickerTheme::CTOWeekDay;
  900. };
  901. CXTPDatePickerItemMonth_helper* pMonthX = (CXTPDatePickerItemMonth_helper*)pMonth;
  902. CXTPDatePickerControl* pControl = pMonthX->m_pControl;
  903. if (pMonthX->m_rcDaysOfWeek.IsRectEmpty())
  904. return;
  905. pDC->SetBkMode(TRANSPARENT);
  906. // fill background
  907. //pDC->FillSolidRect(pMonthX->m_rcDaysOfWeek, m_Text.clrColor);
  908. // draw days of week text
  909. CXTPFontDC fnt(pDC, m_Text.fntFont, m_Text.clrColor);
  910. int nMaxX = 0;
  911. for (int nDayDelta = 0; nDayDelta < XTP_WEEK_DAYS; nDayDelta++)
  912. {
  913. // calc item rect
  914. CXTPDatePickerItemDay* pDay = pMonthX->GetDay(nDayDelta);
  915. CRect rcItem(pDay->GetRect());
  916. rcItem.top = pMonthX->m_rcDaysOfWeek.top;
  917. rcItem.bottom = pMonthX->m_rcDaysOfWeek.bottom - 2;
  918. nMaxX = rcItem.right;
  919. // get item text
  920. CString strText(pControl->GetDayOfWeekName(pDay->GetDate().GetDayOfWeek()));
  921. int nChrLen = (int)_tcsnbcnt(strText, 1);
  922. pDC->DrawText(strText, nChrLen, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
  923. }
  924. // draw bottom line on days of the week
  925. CRect rcBottomLine(pMonthX->m_rcDaysOfWeek);
  926. rcBottomLine.bottom--;
  927. rcBottomLine.top = rcBottomLine.bottom - 1;
  928. rcBottomLine.left = pMonthX->m_rcWeekNumbers.right - 1;
  929. rcBottomLine.right = nMaxX;
  930. pDC->FillSolidRect(rcBottomLine, m_pTheme->m_clrLineTop);
  931. }
  932. void CXTPDatePickerTheme::CTOWeekNumber::Draw(CDC* pDC, CXTPDatePickerItemMonth* pMonth)
  933. {
  934. class CXTPDatePickerItemMonth_helper : public CXTPDatePickerItemMonth {
  935. friend class CXTPDatePickerTheme::CTOWeekNumber;
  936. };
  937. CXTPDatePickerItemMonth_helper* pMonthX = (CXTPDatePickerItemMonth_helper*)pMonth;
  938. CXTPDatePickerControl* pControl = pMonthX->m_pControl;
  939. if (!pControl->GetShowWeekNumbers() || pMonthX->m_rcWeekNumbers.IsRectEmpty())
  940. return;
  941. pDC->SetBkMode(TRANSPARENT);
  942. // fill background
  943. //pDC->FillSolidRect(pMonthX->m_rcWeekNumbers, m_Text.clrColor);
  944. // draw week numbers
  945. CXTPFontDC fnt(pDC, m_Text.fntFont, m_Text.clrColor);
  946. // draw right line on week days
  947. CRect rcLine(pMonthX->m_rcWeekNumbers);
  948. for (int nWeek = 0; nWeek < XTP_MAX_WEEKS; nWeek++)
  949. {
  950. // calculate item rectangle (get week middle day)
  951. CXTPDatePickerItemDay* pDayFirst = pMonth->GetDay(nWeek * XTP_WEEK_DAYS);
  952. CXTPDatePickerItemDay* pDayLast = pMonth->GetDay((nWeek + 1) * XTP_WEEK_DAYS - 1);
  953. if (pDayFirst && (pDayFirst->IsVisible() || nWeek < 4) && pDayLast)
  954. {
  955. CRect rcItem(pDayFirst->GetRect());
  956. rcItem.left = pMonthX->m_rcWeekNumbers.left;
  957. rcItem.right = pMonthX->m_rcWeekNumbers.right - 3;
  958. // get item text
  959. CString strText;
  960. int nWeekNumber = ((pDayLast->GetDate() - COleDateTimeSpan(pControl->GetFirstWeekOfYearDays() - 1)).GetDayOfYear() - 1) / 7 + 1;
  961. strText.Format(_T("%d"), nWeekNumber);
  962. pDC->DrawText(strText, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);
  963. rcLine.bottom = rcItem.bottom;
  964. }
  965. }
  966. pDC->FillSolidRect(rcLine.right - 1, rcLine.top - 1, 1, rcLine.Height(), m_pTheme->m_clrLineLeft);
  967. }
  968. CXTPDatePickerThemeOffice2007::CXTPDatePickerThemeOffice2007()
  969. {
  970. m_nPaintTheme = xtpCalendarThemeOffice2007;
  971. m_pDayPart = new CTODay();
  972. m_pDayPart->Create(this);
  973. m_pMonthHeader = new CTOMonthHeader();
  974. m_pMonthHeader->Create(this);
  975. m_pWeekDay = new CTOWeekDay();
  976. m_pWeekDay->Create(this);
  977. m_pWeekNumberPart = new CTOWeekNumber();
  978. m_pWeekNumberPart->Create(this);
  979. m_pButtonPart = new CTOButton();
  980. m_pButtonPart->Create(this);
  981. RefreshMetrics();
  982. }
  983. void CXTPDatePickerThemeOffice2007::RefreshMetrics()
  984. {
  985. TBase::RefreshMetrics();
  986. m_clrLineTop.SetStandardValue(GetColor2(_T("Lines"), RGB(154, 198,255)));
  987. m_clrLineLeft.SetStandardValue(m_clrLineTop.GetStandardColor());
  988. }
  989. void CXTPDatePickerThemeOffice2007::SetPaintTheme(XTPCalendarTheme ePaintTheme)
  990. {
  991. ASSERT(ePaintTheme == xtpCalendarThemeOffice2007);
  992. m_nPaintTheme = ePaintTheme;
  993. }
  994. void CXTPDatePickerThemeOffice2007::CTODay::RefreshMetrics()
  995. {
  996. ASSERT(m_pTheme);
  997. if (!m_pTheme)
  998. return;
  999. TBase::RefreshMetrics();
  1000. //----------------------------------------
  1001. // Selected text colors
  1002. m_Selected.fcsetTextGrayed.clrColor.SetStandardValue(m_Selected.fcsetText.clrColor);
  1003. m_Selected.fcsetTextGrayedBold.clrColor.SetStandardValue(m_Selected.fcsetText.clrColor);
  1004. // Selected Bk colors
  1005. m_Selected.fcsetText.clrBkColor.SetStandardValue(RGB(251, 200, 79));
  1006. m_Selected.fcsetTextBold.clrBkColor.SetStandardValue(m_Selected.fcsetText.clrBkColor);
  1007. m_Selected.fcsetTextGrayed.clrBkColor.SetStandardValue(m_Selected.fcsetText.clrBkColor);
  1008. m_Selected.fcsetTextGrayedBold.clrBkColor.SetStandardValue(m_Selected.fcsetText.clrBkColor);
  1009. //----------------------------------
  1010. m_clrToodayFrame.SetStandardValue(RGB(187, 85, 3));
  1011. }
  1012. void CXTPDatePickerThemeOffice2007::CTOMonthHeader::RefreshMetrics()
  1013. {
  1014. TBase::RefreshMetrics();
  1015. m_clrBackground.SetStandardValue(m_pTheme->GetColor2(_T("MonthHeaderBk"), RGB(191, 219, 255)));
  1016. m_clrButtons.SetStandardValue(m_pTheme->GetColor2(_T("MonthHeaderScrollBattons"), RGB(111, 157, 217)));
  1017. }
  1018. COLORREF CXTPDatePickerTheme::GetColor2(LPCTSTR pcszColorName, COLORREF clrDefault)
  1019. {
  1020. if (this == NULL)
  1021. return clrDefault;
  1022. COLORREF clrColor = COLORREF_NULL;
  1023. if (XTPOffice2007Images()->IsValid())
  1024. {
  1025. clrColor = XTPOffice2007Images()->GetImageColor(_T("DatePicker"), pcszColorName);
  1026. }
  1027. if (clrColor == COLORREF_NULL)
  1028. {
  1029. clrColor = clrDefault;
  1030. }
  1031. return clrColor;
  1032. }