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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarPaintManager.cpp : implementation file
  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 <math.h>
  22. #include "Resource.h"
  23. #include "Common/XTPVC50Helpers.h"
  24. #include "Common/XTPVC80Helpers.h"
  25. #include "Common/XTPResourceManager.h"
  26. #include "XTPCalendarControl.h"
  27. #include "XTPCalendarPaintManager.h"
  28. #include "XTPCalendarDayViewEvent.h"
  29. #include "XTPCalendarEvent.h"
  30. #include "XTPCalendarEventLabel.h"
  31. #include "XTPCalendarDayView.h"
  32. #include "XTPCalendarWeekView.h"
  33. #include "XTPCalendarMonthView.h"
  34. #include "XTPCalendarData.h"
  35. #include "XTPCalendarDayViewTimeScale.h"
  36. static const double dXTPMaxAlpha2003 = 75.;
  37. static const LPCTSTR cszGlyphsFontName = _T("MS Outlook");
  38. #ifdef _DEBUG
  39. #define new DEBUG_NEW
  40. #undef THIS_FILE
  41. static char THIS_FILE[] = __FILE__;
  42. #endif
  43. void CXTPCalendarPaintManager::CDayViewEventPart::OnDraw(CDC* pDC, CXTPCalendarDayViewEvent* pViewEvent)
  44. {
  45. if (!pDC || !pViewEvent || !pViewEvent->GetEvent() || !m_pPaintManager)
  46. {
  47. ASSERT(FALSE);
  48. return;
  49. }
  50. CRect rcEvent(pViewEvent->GetEventRect());
  51. if (rcEvent.IsRectEmpty())
  52. {
  53. return;
  54. }
  55. // fill event background
  56. CXTPCalendarEventLabel* ptrLabel = pViewEvent->GetEvent()->GetLabel();
  57. COLORREF crBackground = ptrLabel ? ptrLabel->m_clrColor : GetBackgroundColor();
  58. BOOL bSelected = pViewEvent->IsSelected();
  59. int nMDEFlags = pViewEvent->GetMultiDayEventFlags();
  60. BOOL bMultiDay = (nMDEFlags & xtpCalendarMultiDayFMLmask) != 0;
  61. DWORD dwAdditionalOpt = XTP_SAFE_GET3(pViewEvent, GetCalendarControl(), GetCalendarOptions(), dwAdditionalOptions, 0);
  62. CString strLoc = pViewEvent->GetItemTextLocation();
  63. CString strText = pViewEvent->GetItemTextSubject();
  64. if (strLoc.GetLength() > 0)
  65. {
  66. if (dwAdditionalOpt & xtpCalendarOptDayViewNoWordBreak)
  67. {
  68. strText += _T("n(") + strLoc + _T(")");
  69. }
  70. else
  71. {
  72. strText += _T(" (") + strLoc + _T(")");
  73. }
  74. }
  75. CString strTime;
  76. if (!bMultiDay)
  77. {
  78. COleDateTime dtStart = pViewEvent->GetEvent()->GetStartTime();
  79. COleDateTime dtEnd = pViewEvent->GetEvent()->GetEndTime();
  80. DWORD dwTimeFlags = xtpCalendarItemText_EventStartTimeText;
  81. if (!CXTPCalendarUtils::IsEqual(dtStart, dtEnd))
  82. dwTimeFlags = dwTimeFlags | xtpCalendarItemText_EventEndTimeText;
  83. strTime = pViewEvent->GetItemText(dwTimeFlags, pViewEvent->HideEventTime() ? _T("") : NULL);
  84. }
  85. CRect rcBorder(rcEvent);
  86. rcBorder.left += 1;
  87. pDC->FillSolidRect(rcBorder, crBackground);
  88. pDC->FillSolidRect(rcBorder.left, rcBorder.top, rcBorder.Width(), 1, m_pPaintManager->m_clrWindowText);
  89. pDC->FillSolidRect(rcBorder.left - 1, rcBorder.bottom - (bMultiDay ? 1 : 0),
  90. rcBorder.Width() + 1, 1, m_pPaintManager->m_clrWindowText);
  91. if (!bMultiDay)
  92. {
  93. pDC->FillSolidRect(rcBorder.right, rcBorder.top, 1, rcBorder.Height()+1, m_pPaintManager->m_clrWindowText);
  94. }
  95. if (bSelected && bMultiDay)
  96. {
  97. pDC->FillSolidRect(rcEvent.left, rcEvent.top + 1, rcEvent.Width(), rcEvent.Height() - 2, m_pPaintManager->m_clrButtonFace);
  98. pDC->FillSolidRect(rcEvent.left, rcEvent.top - 1, rcEvent.Width()+1, 1, m_pPaintManager->m_clrWindowText);
  99. pDC->FillSolidRect(rcEvent.left, rcEvent.bottom, rcEvent.Width()+1, 1, m_pPaintManager->m_clrWindowText);
  100. }
  101. if (nMDEFlags & xtpCalendarMultiDayFirst)
  102. {
  103. pDC->FillSolidRect(rcEvent.left, rcEvent.top, 1, rcEvent.Height(), m_pPaintManager->m_clrWindowText);
  104. rcEvent.left++;
  105. if (pViewEvent->GetFirstClockRect().Width() > 0)
  106. {
  107. m_pPaintManager->DrawClock(
  108. pDC,
  109. pViewEvent->GetEvent()->GetStartTime(),
  110. pViewEvent->GetFirstClockRect(),
  111. crBackground,
  112. xtpCalendarClockAlignLeft);
  113. }
  114. }
  115. if (nMDEFlags & xtpCalendarMultiDayLast)
  116. {
  117. pDC->FillSolidRect(rcEvent.right, rcEvent.top, 1, rcEvent.Height(), m_pPaintManager->m_clrWindowText);
  118. rcEvent.right -= 2;
  119. if (pViewEvent->GetLastClockRect().Width() > 0)
  120. {
  121. m_pPaintManager->DrawClock(
  122. pDC,
  123. pViewEvent->GetEvent()->GetEndTime(),
  124. pViewEvent->GetLastClockRect(),
  125. crBackground,
  126. xtpCalendarClockAlignLeft);
  127. }
  128. }
  129. UINT uAlign = 0;
  130. UINT uAlignWordBreak = 0;
  131. CRect rcText(pViewEvent->GetTextRect());
  132. CRect rcTime(rcText);
  133. BOOL bTimeOutOfBorders = FALSE;
  134. //  draw busy border
  135. if (!bMultiDay)
  136. {
  137. rcText.top += min(2, rcText.Height());
  138. rcTime.top = rcText.top;
  139. int nBusyStatus = pViewEvent->GetEvent()->GetBusyStatus();
  140. // fill busy area
  141. CRect rcBusyArea(rcEvent);
  142. //  draw border
  143. rcBusyArea.right = rcBusyArea.left + 7;
  144. //rcText.left = rcBusyArea.right + 3;
  145. pDC->FillSolidRect(rcBusyArea, m_pPaintManager->m_clrWindowText);
  146. //  draw background
  147. rcBusyArea.DeflateRect(1, 1, 1, 0);
  148. pDC->FillSolidRect(rcBusyArea, m_pPaintManager->m_clrWindow);
  149. if (pViewEvent->GetTimeframeRect().top == LONG_MAX ||
  150. pViewEvent->GetTimeframeRect().bottom == LONG_MAX)
  151. {
  152. POINT arBusyPoints[] =
  153. {
  154. {rcEvent.left, rcEvent.top},
  155. {rcEvent.left + 7, rcEvent.top},
  156. {rcEvent.left + 7, rcEvent.top + 7},
  157. {rcEvent.left, rcEvent.top}
  158. };
  159. const int cBPCount = sizeof(arBusyPoints) / sizeof(arBusyPoints[0]);
  160. CRgn rgnBusy;
  161. BOOL bRgn = rgnBusy.CreatePolygonRgn(arBusyPoints, cBPCount, ALTERNATE);
  162. ASSERT(bRgn);
  163. if (bRgn)
  164. {
  165. m_pPaintManager->DrawBusyStatus(pDC, rgnBusy, nBusyStatus);
  166. }
  167. }
  168. else
  169. {
  170. //  draw busy border
  171. rcBusyArea.top = pViewEvent->GetTimeframeRect().top;
  172. rcBusyArea.bottom = pViewEvent->GetTimeframeRect().bottom;
  173. pDC->FillSolidRect(rcBusyArea, m_pPaintManager->m_clrWindowText);
  174. //  draw busy color
  175. rcBusyArea.DeflateRect(0, 1, 0, 1);
  176. m_pPaintManager->DrawBusyStatus(pDC, rcBusyArea, nBusyStatus);
  177. }
  178. // draw shadow
  179. if (!bSelected)
  180. m_pPaintManager->DrawShadow(pDC, pViewEvent->GetEventRect());
  181. // draw border
  182. if (bSelected)
  183. {
  184. CBrush brushBorder(m_pPaintManager->m_clrWindowText);
  185. CRect rcBorder2(pViewEvent->GetEventRect());
  186. rcBorder2.right += 1;
  187. CRect rcBorderTop(rcBorder2);
  188. rcBorderTop.bottom = rcBorderTop.top + 1;
  189. rcBorderTop.top -= 5;
  190. m_pPaintManager->DrawBusyStatus(pDC, rcBorderTop, nBusyStatus);
  191. pDC->FrameRect(&rcBorderTop, &brushBorder);
  192. CRect rcBorderBottom(rcBorder2);
  193. rcBorderBottom.top = rcBorderBottom.bottom;
  194. rcBorderBottom.bottom += 6;
  195. m_pPaintManager->DrawBusyStatus(pDC, rcBorderBottom, nBusyStatus);
  196. pDC->FrameRect(&rcBorderBottom, &brushBorder);
  197. }
  198. rcText.right -= 4;
  199. uAlignWordBreak = (dwAdditionalOpt & xtpCalendarOptDayViewNoWordBreak) ? DT_WORD_ELLIPSIS : DT_WORDBREAK;
  200. uAlign |= DT_LEFT | uAlignWordBreak | DT_EDITCONTROL;
  201. //---------------------------------------------------------------------------
  202. if (!strTime.IsEmpty())
  203. {
  204. CString strTest = strTime;
  205. if (dwAdditionalOpt & xtpCalendarOptDayViewNoWordBreak)
  206. strTest += _T(" W...");
  207. CSize szTime = GetTextExtent(pDC, strTest);
  208. if (szTime.cx <= rcText.Width())
  209. {
  210. strText = strTime + _T(" ") + strText;
  211. strTime.Empty();
  212. }
  213. else
  214. {
  215. bTimeOutOfBorders = TRUE;
  216. rcTime.bottom = rcTime.top + szTime.cy;
  217. rcText.top = rcTime.bottom;
  218. }
  219. }
  220. }
  221. else
  222. {
  223. rcText.left += 3;
  224. CSize szText = GetTextExtent(pDC, strText);
  225. if (pViewEvent->IsMultyDayTextAlign() || szText.cx + 2 > rcText.Width())
  226. {
  227. uAlign |= DT_LEFT;
  228. }
  229. else
  230. {
  231. uAlign |= DT_CENTER;
  232. }
  233. uAlign |= DT_SINGLELINE;
  234. }
  235. m_pPaintManager->DrawIcons(pDC, pViewEvent);
  236. // draw event time, if need
  237. if (!strTime.IsEmpty())
  238. {
  239. DrawText(pDC, strTime, rcTime, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
  240. }
  241. // draw event text
  242. DrawText(pDC, strText, rcText, uAlign | DT_VCENTER);
  243. // update OutOfBorders flag
  244. int nX_need = 0, nY_need = 0;
  245. if (uAlign & DT_SINGLELINE)
  246. {
  247. CSize szText = GetTextExtent(pDC, strText);
  248. nX_need = szText.cx;
  249. }
  250. else
  251. {
  252. CRect rcNeeded(0, 0, rcText.Width(), 0);
  253. DrawText(pDC, strText, rcNeeded, DT_CALCRECT | uAlignWordBreak);
  254. nY_need = rcNeeded.Height();
  255. }
  256. BOOL bOutOfBorders = nY_need > rcText.Height() ||
  257.  nX_need > rcText.Width() ||
  258.  bTimeOutOfBorders;
  259. pViewEvent->SetTextOutOfBorders(bOutOfBorders);
  260. }
  261. //////////////////////////////////////////////////////////////////////////
  262. CXTPCalendarPaintManager::CXTPShadowDrawer::CXTPShadowDrawer(CDC* pDC, double dMaxAlpha)
  263. : m_pDC(pDC), m_dMaxAlpha(dMaxAlpha)
  264. {
  265. ASSERT(m_pDC);
  266. }
  267. CXTPCalendarPaintManager::CXTPShadowDrawer::~CXTPShadowDrawer()
  268. {
  269. }
  270. int CXTPCalendarPaintManager::CXTPShadowDrawer::CheckValue(int iValue)
  271. {
  272. return ((iValue > 255) ? 255 : ((iValue < 0) ? 0 : iValue));
  273. }
  274. COLORREF CXTPCalendarPaintManager::CXTPShadowDrawer::AlphaPixel(const COLORREF crPixel, const UINT i)
  275. {
  276. return RGB(
  277.    CheckValue(GetRValue(crPixel)-i),
  278.    CheckValue(GetGValue(crPixel)-i),
  279.    CheckValue(GetBValue(crPixel)-i));
  280. }
  281. void CXTPCalendarPaintManager::DrawShadow(CDC* pDC, const CRect& rcRect)
  282. {
  283. ASSERT(pDC);
  284. if (!pDC || pDC->IsPrinting())
  285. {
  286. return;
  287. }
  288. CXTPShadowDrawer oShadow(pDC, dXTPMaxAlpha2003);
  289. CRect rcVShadow(rcRect);
  290. rcVShadow.left = rcVShadow.right;
  291. rcVShadow.right += 5;
  292. rcVShadow.top += 5;
  293. oShadow.DrawShadowRectPart(rcVShadow, CXTPShadowDrawer::xtpShadowLR);
  294. CRect rcHShadow(rcRect);
  295. rcHShadow.left += 7;
  296. rcHShadow.top = rcHShadow.bottom + 1;
  297. rcHShadow.bottom += 6;
  298. oShadow.DrawShadowRectPart(rcHShadow, CXTPShadowDrawer::xtpShadowTB);
  299. CRect rcTRShadow(rcVShadow);
  300. rcTRShadow.bottom = rcTRShadow.top;
  301. rcTRShadow.top -= 5;
  302. oShadow.DrawShadowRectPart(rcTRShadow, CXTPShadowDrawer::xtpShadowBR);
  303. CRect rcBRShadow(rcVShadow);
  304. rcBRShadow.top = rcBRShadow.bottom;
  305. rcBRShadow.bottom += 5;
  306. oShadow.DrawShadowRectPart(rcBRShadow, CXTPShadowDrawer::xtpShadowTR);
  307. CRect rcBLShadow(rcRect);
  308. rcBLShadow.right = rcBLShadow.left + 7;
  309. rcBLShadow.top = rcBLShadow.bottom + 1;
  310. rcBLShadow.bottom += 6;
  311. oShadow.DrawShadowRectPart(rcBLShadow, CXTPShadowDrawer::xtpShadowBL);
  312. }
  313. void CXTPCalendarPaintManager::CXTPShadowDrawer::DrawShadowRectPart(const CRect& rcShadow, const XTPShadowPart part)
  314. {
  315. ASSERT(m_pDC);
  316. if (!m_pDC || !m_pDC->GetSafeHdc())
  317. {
  318. return;
  319. }
  320. // start processing
  321. HDC hdc;               // handle of the DC we will create
  322. HBITMAP hbitmap;       // bitmap handle
  323. BITMAPINFO bmi;        // bitmap header
  324. ULONG   ulBitmapWidth, ulBitmapHeight;      // bitmap width/height
  325. VOID *pvBits;          // pointer to DIB section
  326. // create a DC for our bitmap -- the source DC for AlphaBlend
  327. hdc = ::CreateCompatibleDC(m_pDC->GetSafeHdc());
  328. if (!hdc)
  329. return;
  330. // setup bitmap info
  331. // zero the memory for the bitmap info
  332. ZeroMemory(&bmi, sizeof(BITMAPINFO));
  333. // set the bitmap width and height. Later on, the blending will occur in the center of each of the three areas.
  334. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  335. bmi.bmiHeader.biWidth = ulBitmapWidth = max(rcShadow.Width(), 0);
  336. bmi.bmiHeader.biHeight = ulBitmapHeight = max(rcShadow.Height(), 0);
  337. bmi.bmiHeader.biPlanes = 1;
  338. bmi.bmiHeader.biBitCount = 32;         // four 8-bit components
  339. bmi.bmiHeader.biCompression = BI_RGB;
  340. bmi.bmiHeader.biSizeImage = ulBitmapWidth * ulBitmapHeight * 4;
  341. // create our DIB section and select the bitmap into the dc
  342. if ((ulBitmapWidth > 0) && (ulBitmapHeight > 0))
  343. {
  344. hbitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0x0);
  345. if (hbitmap)
  346. {
  347. HGDIOBJ hOld = SelectObject(hdc, hbitmap);
  348. // Copy old picture values to the created bitmap
  349. if (::BitBlt(hdc, 0, 0, ulBitmapWidth, ulBitmapHeight,
  350. m_pDC->GetSafeHdc(), rcShadow.left, rcShadow.top, SRCCOPY))
  351. {
  352. // Adjust all pixels of the picture
  353. switch (part)
  354. {
  355. case xtpShadowLR:
  356. ApplyShadowLR((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  357. break;
  358. case xtpShadowTB:
  359. ApplyShadowTB((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  360. break;
  361. case xtpShadowTR:
  362. ApplyShadowTR((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  363. break;
  364. case xtpShadowBR:
  365. ApplyShadowBR((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  366. break;
  367. case xtpShadowBL:
  368. ApplyShadowBL((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  369. break;
  370. case xtpShadow2007Right:
  371. ApplyShadow2007Right((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  372. break;
  373. case xtpShadow2007Bottom:
  374. ApplyShadow2007Bottom((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  375. break;
  376. case xtpShadow2007TopRight:
  377. ApplyShadow2007TR((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  378. break;
  379. case xtpShadow2007BottomLeft:
  380. ApplyShadow2007BL((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  381. break;
  382. case xtpShadow2007BottomRight:
  383. ApplyShadow2007BR((UINT*)pvBits, ulBitmapWidth, ulBitmapHeight);
  384. break;
  385. default:
  386. break;
  387. }
  388. // Copy modified picture to the old DC
  389. if (pvBits)
  390. {
  391. m_pDC->BitBlt(rcShadow.left, rcShadow.top, ulBitmapWidth, ulBitmapHeight, CDC::FromHandle(hdc), 0, 0, SRCCOPY);
  392. }
  393. }
  394. // do cleanup
  395. SelectObject(hdc, hOld);
  396. DeleteObject(hbitmap);
  397. }
  398. }
  399. // do cleanup
  400. DeleteDC(hdc);
  401. }
  402. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadowLR(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  403. {
  404. if (!pBitmap)
  405. return;
  406. UINT nAlpha = 0;
  407. const double dPercentsPerPixel = m_dMaxAlpha / (double)ulBitmapWidth;
  408. double dAlpha = m_dMaxAlpha;
  409. for (ULONG x = 0; x < ulBitmapWidth; x++)
  410. {
  411. nAlpha = (UINT)dAlpha;
  412. if (nAlpha != 0)
  413. {
  414. for (ULONG y = 0; y < ulBitmapHeight; y++)
  415. {
  416. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  417. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  418. }
  419. }
  420. dAlpha -= dPercentsPerPixel;
  421. }
  422. }
  423. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadowTB(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  424. {
  425. if (!pBitmap)
  426. return;
  427. UINT nAlpha = 0;
  428. const double dPercentsPerPixel = m_dMaxAlpha / (double)ulBitmapHeight;
  429. double dAlpha = 0;
  430. for (ULONG y = 0; y < ulBitmapHeight; y++)
  431. {
  432. nAlpha = (UINT)(dAlpha);
  433. if (nAlpha != 0)
  434. {
  435. for (ULONG x = 0; x < ulBitmapWidth; x++)
  436. {
  437. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  438. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  439. }
  440. }
  441. dAlpha += dPercentsPerPixel;
  442. }
  443. }
  444. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadowTR(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  445. {
  446. if (!pBitmap)
  447. return;
  448. UINT nAlpha = 0;
  449. const double dPercentsPerPixel = m_dMaxAlpha / (double)min(ulBitmapWidth, ulBitmapHeight);
  450. for (ULONG y = 0; y < ulBitmapHeight; y++)
  451. {
  452. for (ULONG x = 0; x < ulBitmapWidth; x++)
  453. {
  454. nAlpha = (UINT)(m_dMaxAlpha - sqrt((double)(ulBitmapHeight - y)*(x)) * dPercentsPerPixel);
  455. nAlpha = min(nAlpha, (UINT)((ulBitmapWidth - x) * dPercentsPerPixel));
  456. nAlpha = min(nAlpha, (UINT)((y + 1) * dPercentsPerPixel));
  457. if (nAlpha != 0)
  458. {
  459. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  460. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  461. }
  462. }
  463. }
  464. }
  465. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadow2007Right(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  466. {
  467. if (!pBitmap)
  468. return;
  469. ASSERT(5 == ulBitmapWidth); // ToDo: make shadow rect more than 5x? pixels
  470. static const UINT uiShadow[5] = {38, 34, 30, 27, 25};
  471. UINT nAlpha = 0;
  472. for (ULONG y = 0; y < ulBitmapHeight; y++)
  473. {
  474. for (ULONG x = 0; x < ulBitmapWidth; x++)
  475. {
  476. nAlpha = uiShadow[x];
  477. if (nAlpha != 0)
  478. {
  479. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  480. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  481. }
  482. }
  483. }
  484. }
  485. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadow2007Bottom(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  486. {
  487. if (!pBitmap)
  488. return;
  489. static const UINT uiShadow[3] = {50, 40, 25};
  490. UINT nAlpha = 0;
  491. for (ULONG y = 0; y < ulBitmapHeight; y++)
  492. {
  493. if (0 == y)
  494. nAlpha = uiShadow[2];
  495. else if (1 == y)
  496. nAlpha = uiShadow[1];
  497. else
  498. nAlpha = uiShadow[0];
  499. for (ULONG x = 0; x < ulBitmapWidth; x++)
  500. {
  501. if (nAlpha != 0)
  502. {
  503. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  504. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  505. }
  506. }
  507. }
  508. }
  509. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadow2007TR(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  510. {
  511. if (!pBitmap)
  512. return;
  513. ASSERT(5 == ulBitmapWidth); // ToDo: make shadow rect more than 5x6 pixels
  514. ASSERT(6 == ulBitmapHeight);
  515. static const UINT nShadowTR[6][5] =
  516. {
  517. {22, 17,  7,  0,  0},
  518. {31, 33, 35, 15,  0},
  519. {32, 30, 28, 34, 10},
  520. {35, 32, 29, 30, 21},
  521. {37, 33, 30, 27, 25},
  522. {38, 34, 30, 27, 25}
  523. };
  524. UINT nAlpha = 0;
  525. for (ULONG y = 0; y < ulBitmapHeight; y++)
  526. {
  527. for (ULONG x = 0; x < ulBitmapWidth; x++)
  528. {
  529. nAlpha = nShadowTR[5-y][x];
  530. if (nAlpha != 0)
  531. {
  532. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  533. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  534. }
  535. }
  536. }
  537. }
  538. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadow2007BL(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  539. {
  540. if (!pBitmap)
  541. return;
  542. ASSERT(5 == ulBitmapHeight); // ToDo: make shadow rect more than 5x6 pixels
  543. ASSERT(5 == ulBitmapWidth);
  544. static const UINT uiShadowBL[5][5] =
  545. {
  546. {33, 30, 34, 44, 50},
  547. {19, 33, 33, 40, 50},
  548. {10, 35, 30, 35, 43},
  549. { 0, 18, 35, 30, 33},
  550. { 0,  0, 11, 24, 25}
  551. };
  552. UINT nAlpha = 0;
  553. for (ULONG y = 0; y < ulBitmapHeight; y++)
  554. {
  555. for (ULONG x = 0; x < ulBitmapWidth; x++)
  556. {
  557. nAlpha = uiShadowBL[4-y][x];
  558. if (nAlpha != 0)
  559. {
  560. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  561. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  562. }
  563. }
  564. }
  565. }
  566. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadow2007BR(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  567. {
  568. if (!pBitmap)
  569. return;
  570. ASSERT(3+5 == ulBitmapHeight); // ToDo: make shadow rect more than 5x6 pixels
  571. ASSERT(3+5 == ulBitmapWidth);
  572. static const UINT uiShadowBL[8][8] =
  573. {
  574. {255,255,200,255,255,255,255,255},
  575. {255,255,200,255,255,255,255,255},
  576. {200,200,205,255,255,255,255,255},
  577. {255,255,255,213,215,219,224,230},
  578. {255,255,255,217,219,223,224,233},
  579. {255,255,255,219,221,225,221,241},
  580. {255,255,255,226,226,221,236,254},
  581. {255,255,255,230,231,241,254,255}
  582. };
  583. UINT nAlpha = 0;
  584. for (ULONG y = 0; y < ulBitmapHeight; y++)
  585. {
  586. for (ULONG x = 0; x < ulBitmapWidth; x++)
  587. {
  588. nAlpha = 255 - uiShadowBL[7-y][x];
  589. if (nAlpha != 0)
  590. {
  591. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  592. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  593. }
  594. }
  595. }
  596. }
  597. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadowBR(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  598. {
  599. if (!pBitmap)
  600. return;
  601. UINT nAlpha = 0;
  602. const double dPercentsPerPixel = m_dMaxAlpha / (double)min(ulBitmapHeight, ulBitmapWidth);
  603. for (ULONG y = 0; y < ulBitmapHeight; y++)
  604. {
  605. for (ULONG x = 0; x < ulBitmapWidth; x++)
  606. {
  607. nAlpha = (UINT)(m_dMaxAlpha - sqrt((double)y * x) * dPercentsPerPixel);
  608. nAlpha = min(nAlpha, (UINT)((ulBitmapWidth - x) * dPercentsPerPixel));
  609. nAlpha = min(nAlpha, (UINT)((ulBitmapHeight - y) * dPercentsPerPixel));
  610. if (nAlpha != 0)
  611. {
  612. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  613. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  614. }
  615. }
  616. }
  617. }
  618. void CXTPCalendarPaintManager::CXTPShadowDrawer::ApplyShadowBL(UINT* pBitmap, const ULONG ulBitmapWidth, const ULONG ulBitmapHeight)
  619. {
  620. if (!pBitmap)
  621. return;
  622. UINT nAlpha = 0;
  623. const double dPercentsPerPixel = m_dMaxAlpha / (double)min(ulBitmapHeight, ulBitmapWidth);
  624. for (ULONG y = 0; y < ulBitmapHeight; y++)
  625. {
  626. for (ULONG x = 0; x < ulBitmapWidth; x++)
  627. {
  628. nAlpha = (UINT)(m_dMaxAlpha - sqrt((double)(ulBitmapHeight - y)*(ulBitmapWidth - x)) * dPercentsPerPixel);
  629. nAlpha = min(nAlpha, (UINT)(x * dPercentsPerPixel));
  630. nAlpha = min(nAlpha, (UINT)((y) * dPercentsPerPixel));
  631. if (nAlpha != 0)
  632. {
  633. UINT uiPixel = pBitmap[x + y * ulBitmapWidth];
  634. pBitmap[x + y * ulBitmapWidth] = AlphaPixel(uiPixel, nAlpha);
  635. }
  636. }
  637. }
  638. }
  639. void CXTPCalendarPaintManager::CDayViewTimeScaleCellPart::RefreshMetrics()
  640. {
  641. m_nHourWidth = m_nMinWidth = 0;
  642. LOGFONT lfIcon;
  643. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  644. STRCPY_S(lfIcon.lfFaceName, LF_FACESIZE, _T("Tahoma"));
  645. m_fntTimeText.SetStandardValue(&lfIcon);
  646. }
  647. void CXTPCalendarPaintManager::CDayViewTimeScaleCellPart::CalcWidth(CDC* pDC,
  648. const CString& strHour, const CString& strMin,
  649. int nHourHeight, int& nWidth)
  650. {
  651. ASSERT(pDC);
  652. if (!pDC || !m_pPaintManager)
  653. return;
  654. CSize szMin(0, 0), szHour(0, 0);
  655. {
  656. CXTPFontDC fnt(pDC, &GetTextFont());
  657. szMin = pDC->GetTextExtent(strMin);
  658. }
  659. {
  660. CRect rcDefaultCell(0, 0, 100, nHourHeight);
  661. AdjustTimeFont(pDC, rcDefaultCell);
  662. CXTPFontDC fnt(pDC, m_fntTimeText);
  663. szHour = pDC->GetTextExtent(strHour);
  664. // check also widest hours number
  665. CSize szHour2 = pDC->GetTextExtent(_T("88"), 2);
  666. if (szHour2.cx > szHour.cx)
  667. {
  668. szHour = szHour2;
  669. }
  670. }
  671. m_nHourWidth = szHour.cx;
  672. m_nMinWidth = szMin.cx;
  673. nWidth = max(42, szHour.cx + szMin.cx + 17);
  674. }
  675. void CXTPCalendarPaintManager::CDayViewTimeScaleCellPart::AdjustTimeFont(CDC* pDC, CRect rcCell)
  676. {
  677. ASSERT(pDC);
  678. if (!pDC)
  679. {
  680. return;
  681. }
  682. rcCell.DeflateRect(5, 6, 1, 7);
  683. LOGFONT lfIcon;
  684. ((CFont*)m_fntTimeText)->GetLogFont(&lfIcon);
  685. CSize szText;
  686. {
  687. CXTPFontDC fontBig(pDC, m_fntTimeText);
  688. szText = pDC->GetTextExtent(_T("88"), 2);
  689. }
  690. int nParam1 = rcCell.Width() * szText.cy;
  691. int nParam2 = rcCell.Height() * szText.cx;
  692. if (nParam1 > nParam2)
  693. {
  694. lfIcon.lfHeight = ::MulDiv(lfIcon.lfHeight, rcCell.Height(), szText.cy);
  695. }
  696. else
  697. {
  698. lfIcon.lfHeight = ::MulDiv(lfIcon.lfHeight, rcCell.Width(), szText.cx);
  699. }
  700. m_fntTimeText.SetStandardValue(&lfIcon);
  701. }
  702. void CXTPCalendarPaintManager::CDayViewTimeScaleCellPart::DrawHourCell(CDC* pDC, CRect rc, CString strText, BOOL bFillBackground)
  703. {
  704. if (!pDC || !m_pPaintManager)
  705. {
  706. ASSERT(FALSE);
  707. return;
  708. }
  709. if (bFillBackground)
  710. pDC->FillSolidRect(rc, GetBackgroundColor());
  711. pDC->FillSolidRect(rc.right - 1, rc.top, 1, rc.Height(), m_pPaintManager->m_clr3DShadow);
  712. rc.DeflateRect(0, 0, 4, 0);
  713. DrawText(pDC, strText, rc, DT_VCENTER | DT_RIGHT | DT_SINGLELINE);
  714. rc.DeflateRect(5, 0, 0, 0);
  715. pDC->FillSolidRect(rc.left, rc.bottom - 1, rc.Width(), 1, m_pPaintManager->m_clr3DShadow);
  716. }
  717. void CXTPCalendarPaintManager::CDayViewTimeScaleCellPart::DrawBigHourCell(CDC* pDC, CRect rc, CString strHour, CString strMin, int nRowPerHour, BOOL bFillBackground)
  718. {
  719. if (!pDC || !m_pPaintManager)
  720. {
  721. ASSERT(FALSE);
  722. return;
  723. }
  724. // Fill background
  725. if (bFillBackground)
  726. pDC->FillSolidRect(rc, GetBackgroundColor());
  727. pDC->FillSolidRect(rc.right - 1, rc.top, 1, rc.Height(), m_pPaintManager->m_clr3DShadow);
  728. // Calculate coordinates
  729. CRect rcMinutesText(rc);
  730. rcMinutesText.bottom = rcMinutesText.top + rc.Height() / nRowPerHour;
  731. rcMinutesText.left += m_nHourWidth + 10;
  732. CRect rcHoursText(rc);
  733. rcHoursText.right = rcMinutesText.left;
  734. rcHoursText.DeflateRect(0, 4, 4, 7);
  735. // Draw hours text
  736. CXTPFontDC fontBig(pDC, m_fntTimeText, GetTextColor());
  737. pDC->DrawText(strHour, rcHoursText, DT_TOP | DT_RIGHT | DT_SINGLELINE | DT_NOCLIP);
  738. // draw minutes text
  739. DrawText(pDC, strMin, rcMinutesText, DT_VCENTER | DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
  740. // draw small lines
  741. if (nRowPerHour > 2)
  742. {
  743. BOOL bShowMinutes = XTP_SAFE_GET3(m_pPaintManager, m_pControl, GetCalendarOptions(), bDayView_TimeScaleShowMinutes, FALSE);
  744. CString strMinEx;
  745. for (int i = 1; i < nRowPerHour; i++)
  746. {
  747. int y = rc.top + i * rc.Height() / nRowPerHour;
  748. pDC->FillSolidRect(rcMinutesText.left, y - 1, rcMinutesText.Width(), 1, m_pPaintManager->m_clr3DShadow);
  749. //------------------------------------------
  750. if (bShowMinutes)
  751. {
  752. int nMinEx = 60 / nRowPerHour * i;
  753. strMinEx.Format(_T("%02d"), nMinEx);
  754. CRect rcMinEx = rcMinutesText;
  755. rcMinEx.top = y;
  756. rcMinEx.bottom = y + rc.Height();
  757. DrawText(pDC, strMinEx, rcMinEx, DT_TOP | DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
  758. }
  759. }
  760. }
  761. // draw line below
  762. rc.DeflateRect(5, 0, 4, 0);
  763. pDC->FillSolidRect(rc.left, rc.bottom - 1, rc.Width(), 1, m_pPaintManager->m_clr3DShadow);
  764. }
  765. void CXTPCalendarPaintManager::CDayViewTimeScaleHeaderPart::OnDraw(CDC* pDC, CXTPCalendarDayView* /*pView*/, CRect rc, CString strText)
  766. {
  767. if (!pDC || !m_pPaintManager)
  768. {
  769. ASSERT(FALSE);
  770. return;
  771. }
  772. pDC->FillSolidRect(rc, GetBackgroundColor());
  773. pDC->FillSolidRect(rc.right - 1, rc.top, 1, rc.Height(), m_pPaintManager->m_clr3DShadow);
  774. rc.DeflateRect(1, 0, 4, 0);
  775. pDC->FillSolidRect(rc.left, rc.bottom - 1, rc.Width(), 1, m_pPaintManager->m_clr3DShadow);
  776. rc.DeflateRect(1, 2);
  777. DrawText(pDC, strText, rc, DT_BOTTOM | DT_LEFT | DT_SINGLELINE);
  778. }
  779. void CXTPCalendarPaintManager::CDayViewTimeScaleHeaderPart::DrawNowLine(CDC* pDC,
  780. CXTPCalendarDayView* pView, CRect rc, int y, BOOL bDrawBk)
  781. {
  782. if (!pDC || !pView || !m_pPaintManager)
  783. {
  784. ASSERT(FALSE);
  785. return;
  786. }
  787. int nHeight = GETTOTAL_MINUTES_DTS(pView->GetScaleInterval()) >= 60 ? 5 : 10;
  788. CRect rcNowLine = rc;
  789. rcNowLine.top = y - nHeight;
  790. rcNowLine.bottom = y + 1;
  791. rcNowLine.left += 5;
  792. rcNowLine.right -= 1;
  793. BOOL bXPTheme = m_pPaintManager->GetCurrentSystemTheme() != xtpSystemThemeUnknown;
  794. if (bDrawBk)
  795. {
  796. if (bXPTheme)
  797. {
  798. XTPDrawHelpers()->GradientFill(pDC, &rcNowLine, m_pPaintManager->m_grclrToday, FALSE);
  799. }
  800. }
  801. else
  802. {
  803. rcNowLine.top = rcNowLine.bottom - 1;
  804. pDC->FillSolidRect(&rcNowLine, m_pPaintManager->m_clrUnderLineHdr);
  805. }
  806. }
  807. void CXTPCalendarPaintManager::CDayViewTimeScaleHeaderPart::DrawExpandSigns(CDC* pDC,
  808. CXTPCalendarDayView* pView, const CRect& rcTSHours)
  809. {
  810. if (!pDC || !pView || !m_pPaintManager)
  811. {
  812. ASSERT(FALSE);
  813. return;
  814. }
  815. // draw expand signs
  816. CRect rcSignUp(rcTSHours);
  817. CRect rcSignDown(rcTSHours);
  818. CSize szSign(m_pPaintManager->GetExpandSignSize());
  819. rcSignUp.left = rcTSHours.right - szSign.cx;
  820. rcSignDown.left = rcTSHours.right - szSign.cx;
  821. rcSignDown.top = rcSignDown.bottom - szSign.cy;
  822. CImageList* pilExpSgn = &m_pPaintManager->m_ilExpandSigns;
  823. if (pView->IsExpandUp())
  824. {
  825. m_pPaintManager->DrawBitmap(pilExpSgn, pDC, rcSignUp,
  826. CXTPCalendarPaintManager::idxExpandSignUp);
  827. }
  828. if (pView->IsExpandDown())
  829. {
  830. m_pPaintManager->DrawBitmap(pilExpSgn, pDC, rcSignDown,
  831. CXTPCalendarPaintManager::idxExpandSignDown);
  832. }
  833. }
  834. void CXTPCalendarPaintManager::CDayViewCellPart::GetParams(CXTPCalendarDayViewGroup* pViewGroup,
  835.    XTP_CALENDAR_DAYVIEWCELL_PARAMS& rCellParams)
  836. {
  837. if (!pViewGroup || !m_pPaintManager)
  838. {
  839. ASSERT(FALSE);
  840. return;
  841. }
  842. rCellParams.clrBackgroundColor =  rCellParams.bSelected ? m_pPaintManager->m_clrHighlight : GetBackgroundColor();
  843. }
  844. void CXTPCalendarPaintManager::CDayViewCellPart::OnDraw(CDC* pDC,
  845. CXTPCalendarDayViewGroup* pViewGroup, CRect rc,
  846. const XTP_CALENDAR_DAYVIEWCELL_PARAMS& cellParams)
  847. {
  848. if (!pDC || !pViewGroup || !m_pPaintManager)
  849. {
  850. ASSERT(FALSE);
  851. return;
  852. }
  853. COleDateTime dtTime = cellParams.dtBeginTime;
  854. CRect rcBusyStatus(rc);
  855. rcBusyStatus.right = rcBusyStatus.left + 6;
  856. pDC->FillSolidRect(&rcBusyStatus, m_pPaintManager->m_clrWindow);
  857. int nDayBusyStatus = pViewGroup->GetBusyStatus(dtTime);
  858. if (nDayBusyStatus != xtpCalendarBusyStatusUnknown)
  859. {
  860. m_pPaintManager->DrawBusyStatus(pDC, rcBusyStatus, nDayBusyStatus);
  861. }
  862. if (XTP_SAFE_GET2(pViewGroup, GetViewDay(), GetDayIndex(), 0) != 0 ||
  863. pViewGroup->GetGroupIndex() != 0)
  864. {
  865. pDC->FillSolidRect(rc.left, rc.top, 1, rc.Height(), m_pPaintManager->m_clrWindowText);
  866. }
  867. int nDayDeviderX = 0;//pViewGroup->GetGroupIndex() ? -2 : 0;
  868. pDC->FillSolidRect(rc.left + 6 + nDayDeviderX, rc.top, 1, rc.Height(), m_pPaintManager->m_clrWindowText);
  869. rc.left += 7 + nDayDeviderX;
  870. if (m_pPaintManager->GetPaintTheme() >= xtpCalendarThemeOffice2003 ||
  871. cellParams.bSelected)
  872. {
  873. pDC->FillSolidRect(rc, cellParams.clrBackgroundColor);
  874. }
  875. else
  876. {
  877. WORD arBits[2] = {0xAA, 0x55};
  878. // Use the bit pattern to create a bitmap.
  879. CBitmap bm;
  880. bm.CreateBitmap(8,2,1,1, arBits);
  881. CBrush brush;
  882. brush.CreatePatternBrush(&bm);
  883. COLORREF clrTxt0 = pDC->SetTextColor(cellParams.clrBackgroundColor);
  884. COLORREF clrBk0 = pDC->SetBkColor(m_clrBackgroundSlave);
  885. pDC->FillRect(rc, &brush);
  886. pDC->SetTextColor(clrTxt0);
  887. pDC->SetBkColor(clrBk0);
  888. }
  889. if (dtTime.GetMinute() == 0 && dtTime.GetHour() != 0)
  890. {
  891. pDC->FillSolidRect(rc.left, rc.top - 1, rc.Width(), 1, m_clrHour);
  892. }
  893. pDC->FillSolidRect(rc.left, rc.bottom - 1, rc.Width(), 1, m_clrShadow);
  894. }
  895. void CXTPCalendarPaintManager::CDayViewAllDayEventsPart::OnDraw(CDC* pDC,
  896. CXTPCalendarDayViewGroup* pViewGroup, CRect rc, BOOL bSelected)
  897. {
  898. if (!pDC || !pViewGroup || !pViewGroup->GetViewDay() || !m_pPaintManager)
  899. {
  900. ASSERT(FALSE);
  901. return;
  902. }
  903. if (bSelected)
  904. {
  905. pDC->FillSolidRect(rc, m_pPaintManager->m_clrWindow);
  906. pDC->FillSolidRect(rc.left, rc.top, rc.Width(), 1, m_pPaintManager->m_clr3DShadow);
  907. pDC->FillSolidRect(rc.left, rc.bottom - 1, rc.Width(), 1, m_pPaintManager->m_clr3DShadow);
  908. }
  909. else
  910. {
  911. pDC->FillSolidRect(rc, GetBackgroundColor());
  912. }
  913. if (pViewGroup->GetViewDay()->GetDayIndex() || pViewGroup->GetGroupIndex())
  914. {
  915. pDC->FillSolidRect(rc.left, rc.top + 1, 1, rc.Height() - 2, 0);
  916. }
  917. }
  918. void CXTPCalendarPaintManager::CDayViewHeaderPart::OnDraw(CDC* pDC,
  919. CXTPCalendarDayViewDay* pViewDay, CRect rc, CString strText)
  920. {
  921. if (!pDC || !pViewDay || !pViewDay->GetView() || !m_pPaintManager)
  922. {
  923. ASSERT(FALSE);
  924. return;
  925. }
  926. BOOL bIsCurrent = FALSE;
  927. COleDateTime dtCurrent =  CXTPCalendarUtils::GetCurrentTime();
  928. dtCurrent = CXTPCalendarUtils::ResetTime(dtCurrent);
  929. COleDateTime dtDay;
  930. bIsCurrent = pViewDay->GetDayDate() == dtCurrent;
  931. pDC->FillSolidRect(rc, GetBackgroundColor());
  932. CRect rcHeader(rc);
  933. m_pPaintManager->DrawHeader(pDC, rcHeader, FALSE, bIsCurrent);
  934. BOOL bFirstDay = pViewDay->GetDayIndex() == 0;
  935. BOOL bLastDay = pViewDay->GetDayIndex() == pViewDay->GetView()->GetViewDayCount() - 1;
  936. pDC->FillSolidRect(rc.left, rc.top, rc.Width(), 1, m_clrTopLeftBorder);
  937. pDC->FillSolidRect(rc.left, rc.top + (bFirstDay ? 0: 2), 1, rc.Height() -  (bFirstDay ? 0 : 3), m_clrTopLeftBorder);
  938. pDC->FillSolidRect(rc.right - 1, rc.top + (bLastDay ? 0: 2), 1, rc.Height() - (bLastDay ? 0 : 3), m_pPaintManager->m_clr3DShadow);
  939. rc.DeflateRect(2, 0, 2, 0);
  940. DrawLine_CenterLR(pDC, strText, rc, DT_VCENTER);
  941. }
  942. void CXTPCalendarPaintManager::CDayViewGroupHeaderPart::OnDraw(CDC* pDC,
  943. CXTPCalendarDayViewGroup* pViewGroup, CRect rc, CString strText)
  944. {
  945. if (!pDC || !pViewGroup || !pViewGroup->GetViewDay() || !m_pPaintManager)
  946. {
  947. ASSERT(FALSE);
  948. return;
  949. }
  950. pDC->FillSolidRect(rc, GetBackgroundColor());
  951. CRect rcHeader(rc);
  952. m_pPaintManager->DrawHeader(pDC, rcHeader, FALSE, FALSE);
  953. CXTPCalendarDayViewDay* pViewDay = pViewGroup->GetViewDay();
  954. BOOL bFirstGroup = pViewDay->GetDayIndex() == 0 &&
  955.    pViewGroup->GetGroupIndex() == 0;
  956. BOOL bLastGroup = pViewDay->GetDayIndex() == pViewDay->GetView()->GetViewDayCount() - 1 &&
  957. pViewGroup->GetGroupIndex() == pViewDay->GetViewGroupsCount() - 1;          ;
  958. pDC->FillSolidRect(rc.left, rc.top, rc.Width(), 1, m_clrTopLeftBorder);
  959. pDC->FillSolidRect(rc.left, rc.top + (bFirstGroup ? 0: 2), 1, rc.Height() -  (bFirstGroup ? 0 : 3), m_clrTopLeftBorder);
  960. pDC->FillSolidRect(rc.right - 1, rc.top + (bLastGroup ? 0: 2), 1, rc.Height() - (bLastGroup ? 0 : 3), m_pPaintManager->m_clr3DShadow);
  961. rc.DeflateRect(2, 0, 2, 0);
  962. DrawLine_CenterLR(pDC, strText, rc, DT_VCENTER);
  963. }
  964. void CXTPCalendarPaintManager::DrawHeader(CDC* pDC, CRect& rcHeader,
  965. BOOL bIsSelected, BOOL bIsCurrent)
  966. {
  967. DrawHeader(pDC, rcHeader, bIsSelected, bIsCurrent, m_grclrToday,
  968.   m_clrUnderLineHdr);
  969. }
  970. void CXTPCalendarPaintManager::DrawHeader(CDC* pDC, CRect& rcHeader,
  971. BOOL bIsSelected, BOOL bIsCurrent, const CXTPPaintManagerColorGradient& grclr, COLORREF clrUnderLineHdr)
  972. {
  973. ASSERT(pDC);
  974. if (!pDC)
  975. {
  976. return;
  977. }
  978. if (!bIsSelected)
  979. pDC->FillSolidRect(rcHeader, m_clrButtonFace);
  980. if (bIsCurrent)
  981. {
  982. if (grclr.clrDark != grclr.clrLight)
  983. {
  984. XTPDrawHelpers()->GradientFill(pDC, &rcHeader, grclr, FALSE);
  985. }
  986. else
  987. {
  988. pDC->FillSolidRect(rcHeader, grclr.clrDark);
  989. }
  990. pDC->FillSolidRect(rcHeader.left, rcHeader.bottom -1 ,
  991. rcHeader.Width(), 1, clrUnderLineHdr);
  992. }
  993. if (bIsSelected)
  994. {
  995. pDC->FillSolidRect(rcHeader, m_clrHighlight);
  996. }
  997. }
  998. void CXTPCalendarPaintManager::CWeekViewPart::DrawDayHeader(CDC* pDC,
  999. CRect rcDay, int nHeaderHeight,
  1000. CString strHeader, BOOL bIsCurrent, BOOL bIsSelected)
  1001. {
  1002. if (!pDC || !m_pPaintManager)
  1003. {
  1004. ASSERT(FALSE);
  1005. return;
  1006. }
  1007. if (m_pPaintManager->GetPaintTheme() != xtpCalendarThemeOffice2003)
  1008. {
  1009. bIsCurrent = FALSE;
  1010. }
  1011. CRect rcHeader(rcDay);
  1012. // draw header top line
  1013. m_pPaintManager->DrawHorizontalLine(pDC, rcDay.left + 1, rcDay.top,
  1014.  rcDay.Width()+1);
  1015. rcHeader.DeflateRect(2, 2, 1, rcHeader.Height() - nHeaderHeight - 1);
  1016. CRect rcText(rcHeader);
  1017. rcText.DeflateRect(1, 0, 3, 1);
  1018. // draw header contents
  1019. CRect rcHeader2(rcHeader);
  1020. rcHeader2.bottom -= 1;
  1021. if (bIsCurrent && bIsSelected)
  1022. {
  1023. m_pPaintManager->DrawHeader(pDC, rcHeader2, FALSE, bIsCurrent);
  1024. CRect rcSel = CRect(rcHeader2);
  1025. CSize  szText = GetTextExtent(pDC, strHeader);
  1026. rcSel.left = rcSel.right - (szText.cx + 7);
  1027. rcSel.bottom--;
  1028. m_pPaintManager->DrawHeader(pDC, rcSel, bIsSelected, FALSE);
  1029. }
  1030. else
  1031. {
  1032. m_pPaintManager->DrawHeader(pDC, rcHeader2, bIsSelected, bIsCurrent);
  1033. }
  1034. // draw header bottom line
  1035. if (!bIsCurrent)
  1036. {
  1037. CRect rcBottomLine(rcHeader);
  1038. rcBottomLine.top = --rcBottomLine.bottom - 1;
  1039. if (!bIsSelected)
  1040. rcBottomLine.DeflateRect(2, 0, 2, 0);
  1041. pDC->FillSolidRect(rcBottomLine, m_clrHeaderBottomLine);
  1042. }
  1043. // draw header text
  1044. pDC->SetBkMode(TRANSPARENT);
  1045. SetTextColor(bIsSelected ? m_clrTextHighLightColor : m_clrTextNormalColor);
  1046. DrawText(pDC, strHeader, rcText, DT_VCENTER | DT_RIGHT | DT_SINGLELINE);
  1047. }
  1048. void CXTPCalendarPaintManager::CWeekViewPart::OnDraw(CDC* pDC, CXTPCalendarWeekView* pWeekView)
  1049. {
  1050. if (!pDC || !pWeekView || !m_pPaintManager)
  1051. {
  1052. ASSERT(FALSE);
  1053. return;
  1054. }
  1055. CRect rcView(pWeekView->GetViewRect());
  1056. pDC->FillSolidRect(rcView, m_clrBackground);
  1057. //draw grid
  1058. int nDayWidth = pWeekView->GetDayWidth();
  1059. m_pPaintManager->DrawVerticalLine(pDC, rcView.left + nDayWidth - 1, rcView.top, rcView.bottom);
  1060. // draw headers
  1061. BOOL bIsSelected = FALSE;
  1062. BOOL bIsCurrent = FALSE;
  1063. COleDateTime dtCurrent = CXTPCalendarUtils::ResetTime(COleDateTime::GetCurrentTime());
  1064. COleDateTime dtDay;
  1065. int nDayHeaderHeight = pWeekView->GetDayHeaderHeight();
  1066. for (int nDay = 0; nDay < 7; nDay++)
  1067. {
  1068. CXTPCalendarWeekViewDay* pWDay = pWeekView->GetViewDay(nDay);
  1069. ASSERT(pWDay);
  1070. if (!pWDay)
  1071. {
  1072. continue;
  1073. }
  1074. CString strDate = pWDay->GetCaption();
  1075. dtDay = pWDay->GetDayDate();
  1076. bIsSelected = pWDay->IsSelected();
  1077. bIsCurrent = CXTPCalendarUtils::IsEqual(dtDay, dtCurrent);
  1078. //-------------------------------------------------------------
  1079. DrawDayHeader(pDC, pWDay->GetDayRect(), nDayHeaderHeight,
  1080.   strDate, bIsCurrent, bIsSelected);
  1081. }
  1082. }
  1083. void CXTPCalendarPaintManager::CWeekViewEventPart::DrawBorder(CDC* pDC,
  1084. CRect rcView, CXTPCalendarWeekViewEvent* pWeekViewEvent)
  1085. {
  1086. if (!pDC || !pWeekViewEvent || !pWeekViewEvent->GetEvent() || !m_pPaintManager)
  1087. {
  1088. ASSERT(FALSE);
  1089. return;
  1090. }
  1091. int nBorderWidth = pWeekViewEvent->IsSelected() ? 2 : 1;
  1092. int nMDEFlags = pWeekViewEvent->GetMultiDayEventFlags();
  1093. BOOL bAllDay = pWeekViewEvent->GetEvent()->IsAllDayEvent();
  1094. if (pWeekViewEvent->IsSelected() &&
  1095. (nMDEFlags & xtpCalendarMultiDayFirst ||
  1096.  nMDEFlags & xtpCalendarMultiDayLast ||
  1097.  nMDEFlags & xtpCalendarMultiDayMiddle)
  1098.  )
  1099. {
  1100. rcView.top--;
  1101. rcView.bottom++;
  1102. }
  1103. if (bAllDay ||
  1104. nMDEFlags & xtpCalendarMultiDayFirst ||
  1105. nMDEFlags & xtpCalendarMultiDayLast ||
  1106. nMDEFlags & xtpCalendarMultiDayMiddle)
  1107. {
  1108. pDC->FillSolidRect(rcView.left, rcView.top , rcView.Width(), nBorderWidth, m_clrTextNormalColor);
  1109. pDC->FillSolidRect(rcView.left, rcView.bottom - nBorderWidth, rcView.Width(), nBorderWidth, m_clrTextNormalColor);
  1110. }
  1111. if (nMDEFlags & xtpCalendarMultiDayFirst)
  1112. {
  1113. pDC->FillSolidRect(rcView.left, rcView.top, 1, rcView.Height(), m_clrTextNormalColor);
  1114. }
  1115. if (nMDEFlags & xtpCalendarMultiDayLast)
  1116. {
  1117. pDC->FillSolidRect(rcView.right, rcView.top, 1, rcView.Height(), m_clrTextNormalColor);
  1118. }
  1119. }
  1120. int CXTPCalendarPaintManager::CWeekViewEventPart::DrawTimes(CDC* pDC, CXTPCalendarWeekViewEvent* pWeekViewEvent)
  1121. {
  1122. if (!pDC || !pWeekViewEvent || !pWeekViewEvent->GetEvent() || !m_pPaintManager)
  1123. {
  1124. ASSERT(FALSE);
  1125. return 0;
  1126. }
  1127. COLORREF clrBackground = pWeekViewEvent->IsSelected() ? m_pPaintManager->m_clrHighlight : m_clrBackground;
  1128. CXTPCalendarEventLabel* ptrLabel = pWeekViewEvent->GetEvent()->GetLabel();
  1129. COLORREF clrLabel = ptrLabel ? ptrLabel->m_clrColor : clrBackground;
  1130. clrBackground = clrLabel;
  1131. CRect rcStart(pWeekViewEvent->GetStartTimeRect());
  1132. CRect rcEnd(pWeekViewEvent->GetEndTimeRect());
  1133. COleDateTime dtStart(pWeekViewEvent->GetEvent()->GetStartTime());
  1134. if (pWeekViewEvent->IsTimeAsClock())
  1135. {
  1136. m_pPaintManager->DrawClock(pDC, dtStart, rcStart, clrBackground, xtpCalendarClockAlignCenter);
  1137. }
  1138. else
  1139. {
  1140. CString strStartTime = pWeekViewEvent->GetItemTextStartTime();
  1141. DrawLineEx(pDC, strStartTime, &rcStart, DT_RIGHT | DT_VCENTER, DT_LEFT | DT_VCENTER);
  1142. }
  1143. if (pWeekViewEvent->IsShowEndTime())
  1144. {
  1145. COleDateTime dtEnd(pWeekViewEvent->GetEvent()->GetEndTime());
  1146. if (pWeekViewEvent->IsTimeAsClock())
  1147. {
  1148. m_pPaintManager->DrawClock(pDC, dtEnd, rcEnd, clrBackground, xtpCalendarClockAlignCenter);
  1149. }
  1150. else
  1151. {
  1152. CString strEndTime = pWeekViewEvent->GetItemTextEndTime();
  1153. DrawLineEx(pDC, strEndTime, &rcEnd, DT_RIGHT | DT_VCENTER, DT_LEFT | DT_VCENTER);
  1154. }
  1155. }
  1156. return 0;
  1157. }
  1158. void CXTPCalendarPaintManager::CWeekViewEventPart::DrawSubj(CDC* pDC,
  1159. CXTPCalendarWeekViewEvent* pWeekViewEvent)
  1160. {
  1161. if (!pDC || !pWeekViewEvent || !pWeekViewEvent->GetEvent() || !m_pPaintManager)
  1162. {
  1163. ASSERT(FALSE);
  1164. return;
  1165. }
  1166. CRect rcText(pWeekViewEvent->GetTextRect());
  1167. CString strLoc = pWeekViewEvent->GetItemTextLocation();
  1168. CString strEventText = pWeekViewEvent->GetItemTextSubject();
  1169. if (strLoc.GetLength() > 0)
  1170. {
  1171. strEventText += _T(" (") + strLoc + _T(")");
  1172. }
  1173. int nDayEventFlags = pWeekViewEvent->GetMultiDayEventFlags();
  1174. int nAlign = DT_CENTER;
  1175. if (pWeekViewEvent->IsMultyDayTextAlign() || GetTextExtent(pDC, strEventText).cx >= rcText.Width())
  1176. nAlign = DT_LEFT;
  1177. //nAlign
  1178. if (pWeekViewEvent->GetEvent()->IsAllDayEvent() ||
  1179. nDayEventFlags & xtpCalendarMultiDayFirst ||
  1180. nDayEventFlags & xtpCalendarMultiDayMiddle ||
  1181. nDayEventFlags & xtpCalendarMultiDayLast
  1182.   )
  1183. DrawText(pDC, strEventText, &rcText, nAlign | DT_VCENTER | DT_SINGLELINE);
  1184. else
  1185. DrawText(pDC, strEventText, &rcText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
  1186. }
  1187. void CXTPCalendarPaintManager::CWeekViewEventPart::OnDraw(CDC* pDC,
  1188. CXTPCalendarWeekViewEvent* pWeekViewEvent)
  1189. {
  1190. if (!pDC || !pWeekViewEvent || !pWeekViewEvent->GetEvent() || !m_pPaintManager)
  1191. {
  1192. ASSERT(FALSE);
  1193. return;
  1194. }
  1195. CRect rcView(pWeekViewEvent->GetViewEventRect());
  1196. CRect rcViewMax(rcView);
  1197. CString strEventText;
  1198. BOOL bSelected = pWeekViewEvent->IsSelected();
  1199. int nDayEventFlags = pWeekViewEvent->GetMultiDayEventFlags();
  1200. BOOL bMday = (nDayEventFlags & xtpCalendarMultiDayFMLmask) != 0;
  1201. BOOL bAllDay = pWeekViewEvent->GetEvent()->IsAllDayEvent();
  1202. CXTPCalendarEventLabel* ptrLabel = pWeekViewEvent->GetEvent()->GetLabel();
  1203. BOOL bLabel = (ptrLabel && ptrLabel->m_nLabelID != XTP_CALENDAR_NONE_LABEL_ID);
  1204. COLORREF clrBackground = m_clrBackground;
  1205. SetTextColor(m_clrTextNormalColor);
  1206. if (bMday || bAllDay)
  1207. clrBackground = RGB(255, 255, 255);
  1208. if (bLabel && ptrLabel)
  1209. clrBackground = ptrLabel->m_clrColor;
  1210. if (bSelected)
  1211. {
  1212. rcViewMax.CopyRect(pWeekViewEvent->GetViewEventRectMax());
  1213. clrBackground = m_pPaintManager->m_clrHighlight;
  1214. SetTextColor(m_clrTextHighLightColor);
  1215. }
  1216. if (bMday || bAllDay)
  1217. pDC->FillSolidRect(rcView, clrBackground);
  1218. else
  1219. pDC->FillSolidRect(rcViewMax, clrBackground);
  1220. // Draw border for long event
  1221. DrawBorder(pDC, rcView, pWeekViewEvent);
  1222. // Draw Clock for Long Events
  1223. if (nDayEventFlags & xtpCalendarMultiDayFirst)
  1224. {
  1225. m_pPaintManager->DrawClock(pDC,
  1226.    pWeekViewEvent->GetEvent()->GetStartTime(),
  1227.    pWeekViewEvent->GetFirstClockRect(),
  1228.    clrBackground,
  1229.    xtpCalendarClockAlignLeft);
  1230. }
  1231. else if (nDayEventFlags & xtpCalendarMultiDayLast)
  1232. {
  1233. m_pPaintManager->DrawClock(pDC,
  1234.    pWeekViewEvent->GetEvent()->GetEndTime(),
  1235.    pWeekViewEvent->GetLastClockRect(),
  1236.    clrBackground,
  1237.    xtpCalendarClockAlignRight);
  1238. }
  1239. // 3 Draw time start/end and  icons
  1240. clrBackground = bSelected ? m_pPaintManager->m_clrHighlight : m_clrBackground;
  1241. if (!bMday && !bAllDay)
  1242. {
  1243. DrawTimes(pDC, pWeekViewEvent);
  1244. }
  1245. m_pPaintManager->DrawIcons(pDC, pWeekViewEvent);
  1246. // 5 Draw Text
  1247. DrawSubj(pDC, pWeekViewEvent);
  1248. }
  1249. void CXTPCalendarPaintManager::CMonthViewGridPart::OnDrawGrid(CDC* pDC,
  1250. CXTPCalendarMonthView* pMonthView)
  1251. {
  1252. if (!pDC || !pMonthView || !pMonthView->GetGrid() ||
  1253. !pMonthView->GetCalendarControl() || !m_pPaintManager)
  1254. {
  1255. ASSERT(FALSE);
  1256. return;
  1257. }
  1258. COLORREF clrGridLine = RGB(0, 0, 0);
  1259. BOOL bCompressWeD = pMonthView->GetCalendarControl()->MonthView_IsCompressWeekendDays();
  1260. int nWeeksCount = pMonthView->GetGrid()->GetWeeksCount();
  1261. COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
  1262. int nCurrentMonth = dtNow.GetMonth();
  1263. int nWhiteMonthColorIdx = nCurrentMonth % 2;
  1264. for (int nWeek = 0; nWeek < nWeeksCount; nWeek++)
  1265. {
  1266. for (int nDayIdx = 0; nDayIdx < 7; nDayIdx++)
  1267. {
  1268. COleDateTime dtDay = pMonthView->GetGrid()->GetDayDate(nWeek, nDayIdx);
  1269. CRect rcB = pMonthView->GetGrid()->GetDayRect(nWeek, nDayIdx, TRUE);
  1270. //Draw Grid lines
  1271. if (nWeek > 0)
  1272. {
  1273. pDC->FillSolidRect(rcB.left, rcB.top, rcB.Width(), 1, clrGridLine);
  1274. }
  1275. if (nWeek < nWeeksCount-1)
  1276. {
  1277. pDC->FillSolidRect(rcB.left, rcB.bottom, rcB.Width(), 1, clrGridLine);
  1278. }
  1279. int nWDay = dtDay.GetDayOfWeek();
  1280. BOOL bCompressedCol_Su = bCompressWeD && nDayIdx == 1 && nWDay == 1;
  1281. if (nDayIdx > 0 && !bCompressedCol_Su)
  1282. {
  1283. pDC->FillSolidRect(rcB.left, rcB.top, 1, rcB.Height(), clrGridLine);
  1284. }
  1285. //Fill Grid cells background
  1286. CRect rcDay = pMonthView->GetGrid()->GetDayRect(nWeek, nDayIdx, FALSE);
  1287. int nMonth = dtDay.GetMonth();
  1288. COLORREF clrBackground = nMonth % 2 == nWhiteMonthColorIdx ? m_clrBackground : m_clrBackground2;
  1289. if (nDayIdx == 0)
  1290. {
  1291. rcDay.left--;
  1292. }
  1293. pDC->FillSolidRect(&rcDay, clrBackground);
  1294. }
  1295. }
  1296. }
  1297. void CXTPCalendarPaintManager::CMonthViewHeaderPart::OnDraw(CDC* pDC,
  1298. CXTPCalendarMonthView* pMonthView, CRect rc,
  1299. int nCollIndex, CString strText)
  1300. {
  1301. if (!pDC || !pMonthView || !pMonthView->GetGrid() || !m_pPaintManager)
  1302. {
  1303. ASSERT(FALSE);
  1304. return;
  1305. }
  1306. pDC->FillSolidRect(rc, GetBackgroundColor());
  1307. BOOL bFirstDay = nCollIndex == 0;
  1308. BOOL bLastDay = nCollIndex == pMonthView->GetGrid()->GetColsCount() - 1;
  1309. pDC->FillSolidRect(rc.left, rc.top, rc.Width(), 1, m_clrTopLeftBorder);
  1310. pDC->FillSolidRect(rc.left, rc.top + (bFirstDay ? 0: 2), 1, rc.Height() -  (bFirstDay ? 1 : 3), m_clrTopLeftBorder);
  1311. pDC->FillSolidRect(rc.right - 1, rc.top + (bLastDay ? 0: 2), 1, rc.Height() - (bLastDay ? 1 : 3), m_pPaintManager->m_clr3DShadow);
  1312. pDC->FillSolidRect(rc.left, rc.bottom, rc.Width(), 1, m_pPaintManager->m_clr3DShadow);
  1313. rc.DeflateRect(2, 0, 2, 0);
  1314. DrawLine_CenterLR(pDC, strText, rc, DT_VCENTER);
  1315. }
  1316. void CXTPCalendarPaintManager::CMonthViewEventPart::OnDrawDayDate(CDC* pDC,
  1317. CRect rc, BOOL bToday,
  1318. BOOL bSelected, CString strText)
  1319. {
  1320. if (!pDC || !m_pPaintManager)
  1321. {
  1322. ASSERT(FALSE);
  1323. return;
  1324. }
  1325. rc.DeflateRect(1, 1, 1, 1);
  1326. BOOL bXPTheme = m_pPaintManager->GetCurrentSystemTheme() != xtpSystemThemeUnknown;
  1327. if (m_pPaintManager->GetPaintTheme() != xtpCalendarThemeOffice2003)
  1328. {
  1329. bXPTheme = bToday = FALSE;
  1330. }
  1331. if (bSelected && bToday)
  1332. {
  1333. CRect rcSel = CRect(rc);
  1334. CRect rcUnSel = CRect(rc);
  1335. CSize  szText = GetTextExtent(pDC, strText);
  1336. rcSel.left = rcSel.right - (szText.cx + 7);
  1337. rcUnSel.right = rcUnSel.left + rcUnSel.Width() - (szText.cx + 7);
  1338. if (bXPTheme)
  1339. m_pPaintManager->DrawHeader(pDC, rcUnSel, FALSE, bToday);
  1340. else
  1341. m_pPaintManager->DrawHeader(pDC, rcUnSel, FALSE, bToday,
  1342. m_grclrClassicSelDay, m_clrClassicUnderline);
  1343. m_pPaintManager->DrawHeader(pDC, rcSel, bSelected, FALSE);
  1344. }
  1345. else
  1346. if (bSelected || bToday)
  1347. {
  1348. if (bXPTheme)
  1349. m_pPaintManager->DrawHeader(pDC, rc, bSelected, bToday);
  1350. else
  1351. m_pPaintManager->DrawHeader(pDC, rc, bSelected, bToday,
  1352. m_grclrClassicSelDay, m_clrClassicUnderline);
  1353. }
  1354. if (bSelected)
  1355. {
  1356. SetTextColor(m_clrTextHighLightColor);
  1357. }
  1358. rc.DeflateRect(0, 0, 5, 0);
  1359. DrawText(pDC, strText, rc, DT_VCENTER | DT_RIGHT | DT_SINGLELINE);
  1360. m_clrTextColor.SetDefaultValue();
  1361. }
  1362. void CXTPCalendarPaintManager::CMonthViewEventPart::OnDrawEvent(CDC* pDC,
  1363. CXTPCalendarMonthViewEvent* pViewEvent)
  1364. {
  1365. if (!pDC || !pViewEvent || !pViewEvent->GetEvent() || !m_pPaintManager)
  1366. {
  1367. ASSERT(FALSE);
  1368. return;
  1369. }
  1370. CRect rcEvent = pViewEvent->GetEventRect();
  1371. CRect rcText = pViewEvent->GetTextRect();
  1372. CXTPCalendarEvent* prtEvent = pViewEvent->GetEvent();
  1373. BOOL bSelected = pViewEvent->IsSelected();
  1374. int nMDEFlags = pViewEvent->GetMultiDayEventFlags();
  1375. CRect rcClockFirst(0, 0, 0, 0);
  1376. CRect rcClockLast(0, 0, 0, 0);
  1377. COleDateTime dtClockFirst;
  1378. COleDateTime dtClockLast;
  1379. COLORREF clrBackground;
  1380. if (nMDEFlags & xtpCalendarMultiDayFirst)
  1381. {
  1382. rcClockFirst.CopyRect(pViewEvent->GetFirstClockRect());
  1383. dtClockFirst = pViewEvent->GetEvent()->GetStartTime();
  1384. }
  1385. if (nMDEFlags & xtpCalendarMultiDayLast)
  1386. {
  1387. rcClockLast.CopyRect(pViewEvent->GetLastClockRect());
  1388. dtClockLast = pViewEvent->GetEvent()->GetEndTime();
  1389. }
  1390. if (bSelected)
  1391. {
  1392. if (nMDEFlags & xtpCalendarMultiDayFMLmask)
  1393. {
  1394. rcEvent.top--;
  1395. rcEvent.bottom++;
  1396. }
  1397. else
  1398. {
  1399. rcEvent.left = pViewEvent->m_rcEventMax.left + 2;
  1400. rcEvent.right = pViewEvent->m_rcEventMax.right - 2;
  1401. }
  1402. SetTextColor(m_clrTextHighLightColor);
  1403. clrBackground = m_pPaintManager->m_clrHighlight;
  1404. pDC->FillSolidRect(&rcEvent, m_pPaintManager->m_clrHighlight);
  1405. clrBackground = m_pPaintManager->m_clrHighlight;
  1406. }
  1407. else
  1408. {
  1409. CXTPCalendarEventLabel* ptrLabel = pViewEvent->GetEvent()->GetLabel();
  1410. COLORREF clrLabel = ptrLabel ? ptrLabel->m_clrColor : RGB(255, 255, 255);
  1411. BOOL bNoneLabel = ptrLabel ? (ptrLabel->m_nLabelID == XTP_CALENDAR_NONE_LABEL_ID) : TRUE;
  1412. clrBackground = clrLabel;
  1413. if (nMDEFlags & xtpCalendarMultiDayFMLmask || !bNoneLabel)
  1414. {
  1415. pDC->FillSolidRect(&rcEvent, clrLabel);
  1416. }
  1417. }
  1418. UINT uAlign = DT_LEFT;
  1419. CString strLoc = pViewEvent->GetItemTextLocation();
  1420. CString strText = pViewEvent->GetItemTextSubject();
  1421. if (strLoc.GetLength() > 0)
  1422. {
  1423. strText += _T(" (") + strLoc + _T(")");
  1424. }
  1425. if (nMDEFlags & xtpCalendarMultiDayFMLmask)
  1426. {
  1427. int nBY = bSelected ? 2 : 1;
  1428. pDC->FillSolidRect(rcEvent.left, rcEvent.top, rcEvent.Width(), nBY, m_clrMultiDayEventFrameColor);
  1429. pDC->FillSolidRect(rcEvent.left, rcEvent.bottom - nBY, rcEvent.Width(), nBY, m_clrMultiDayEventFrameColor);
  1430. if (nMDEFlags & xtpCalendarMultiDayFirst)
  1431. {
  1432. pDC->FillSolidRect(rcEvent.left, rcEvent.top, 1, rcEvent.Height(), m_clrMultiDayEventFrameColor);
  1433. }
  1434. if (nMDEFlags & xtpCalendarMultiDayLast)
  1435. {
  1436. pDC->FillSolidRect(rcEvent.right, rcEvent.top, 1, rcEvent.Height(), m_clrMultiDayEventFrameColor);
  1437. }
  1438. //CSize szSpace = GetTextExtent(pDC, _T(" "));
  1439. rcText.left += 1;//min(1, szSpace.cx/2);
  1440. rcText.right -= 1;
  1441. CSize szText = GetTextExtent(pDC, strText);
  1442. if (pViewEvent->IsMultyDayTextAlign() || szText.cx > rcText.Width())
  1443. uAlign = DT_LEFT;
  1444. else
  1445. uAlign = DT_CENTER;
  1446. }
  1447. // draw clocks for multyday events
  1448. if ((nMDEFlags & xtpCalendarMultiDayFirst) || (nMDEFlags & xtpCalendarMultiDayLast))
  1449. {
  1450. if (rcClockFirst.Width() > 0)
  1451. m_pPaintManager->DrawClock(
  1452. pDC,
  1453. dtClockFirst,
  1454. rcClockFirst,
  1455. clrBackground,
  1456. xtpCalendarClockAlignLeft);
  1457. if (rcClockLast.Width() > 0)
  1458. m_pPaintManager->DrawClock(
  1459. pDC,
  1460. dtClockLast,
  1461. rcClockLast,
  1462. clrBackground,
  1463. xtpCalendarClockAlignLeft);
  1464. }
  1465. //CRect rcText = pViewEvent->GetTextRect();
  1466. if (nMDEFlags & xtpCalendarMultiDayNoMultiDay)
  1467. {
  1468. //IsTimeAsClock()
  1469. COleDateTime dtStart(prtEvent->GetStartTime());
  1470. COleDateTime dtEnd(prtEvent->GetEndTime());
  1471. CString strStartTime = pViewEvent->GetItemTextStartTime();
  1472. CString strEndTime = pViewEvent->GetItemTextEndTime();
  1473. CRect rcStart(pViewEvent->GetStartTimeRect());
  1474. CRect rcEnd(pViewEvent->GetEndTimeRect());
  1475. if (pViewEvent->IsTimeAsClock())
  1476. {
  1477. m_pPaintManager->DrawClock(pDC, dtStart, rcStart, clrBackground, xtpCalendarClockAlignCenter);
  1478. m_pPaintManager->DrawClock(pDC, dtEnd, rcEnd, clrBackground, xtpCalendarClockAlignCenter);
  1479. }
  1480. else
  1481. {
  1482. DrawLineEx(pDC, strStartTime, rcStart, DT_RIGHT | DT_VCENTER, DT_LEFT | DT_VCENTER );
  1483. DrawLineEx(pDC, strEndTime, rcEnd, DT_RIGHT | DT_VCENTER, DT_LEFT | DT_VCENTER );
  1484. }
  1485. }
  1486. DrawText(pDC, strText, rcText, uAlign | DT_VCENTER | DT_SINGLELINE);
  1487. m_pPaintManager->DrawIcons(pDC, pViewEvent);
  1488. m_clrTextColor.SetDefaultValue();
  1489. }
  1490. /////////////////////////////////////////////////////////////////////////////
  1491. // CXTPCalendarPaintManager
  1492. #define ADDVIEWPART(theClass, parent)
  1493. m_p##theClass = (C##theClass*)AddViewPart(new C##theClass(m_p##parent));
  1494. CXTPCalendarPaintManager::CXTPCalendarPaintManager()
  1495. {
  1496. m_pGlyphsFont = NULL;
  1497. m_szClockRect.cx = 15;
  1498. m_szClockRect.cy = 15;
  1499. m_szExpandSign.cx = m_szExpandSign.cy = 0;
  1500. m_pControl = NULL;
  1501. m_bEnableTheme = TRUE;
  1502. m_dwAskItemTextFlags = 0;
  1503. m_pControlPart = (CControlPart*)AddViewPart(new CControlPart());
  1504. ADDVIEWPART(DayViewTimeScaleHeaderPart, ControlPart);
  1505. ADDVIEWPART(DayViewTimeScaleCellPart, DayViewTimeScaleHeaderPart);
  1506. ADDVIEWPART(DayViewCellPart, ControlPart);
  1507. ADDVIEWPART(DayViewWorkCellPart, DayViewCellPart);
  1508. ADDVIEWPART(DayViewNonworkCellPart, DayViewCellPart);
  1509. ADDVIEWPART(DayViewHeaderPart, ControlPart);
  1510. ADDVIEWPART(DayViewGroupHeaderPart, ControlPart);
  1511. ADDVIEWPART(DayViewAllDayEventsPart, ControlPart);
  1512. ADDVIEWPART(DayViewEventPart, ControlPart);
  1513. ADDVIEWPART(WeekViewPart, ControlPart);
  1514. ADDVIEWPART(WeekViewEventPart, ControlPart);
  1515. ADDVIEWPART(MonthViewGridPart, ControlPart);
  1516. ADDVIEWPART(MonthViewHeaderPart, ControlPart);
  1517. ADDVIEWPART(MonthViewEventPart, ControlPart);
  1518. //-----------------------------------------------------------------------
  1519. CBitmap bmpSignUp, bmpSignDown;
  1520. VERIFY(XTPResourceManager()->LoadBitmap(&bmpSignUp, XTP_IDB_CALENDAR_EXPANDSIGNUP) );
  1521. VERIFY(XTPResourceManager()->LoadBitmap(&bmpSignDown, XTP_IDB_CALENDAR_EXPANDSIGNDOWN) );
  1522. CSize szSexpandSign = GetExpandSignSize();
  1523. VERIFY(m_ilExpandSigns.Create(szSexpandSign.cx, szSexpandSign.cy, ILC_COLOR24 | ILC_MASK, 0, 1));
  1524. COLORREF clrMask = RGB(255, 0, 255);
  1525. m_ilExpandSigns.Add(&bmpSignUp, clrMask);
  1526. m_ilExpandSigns.Add(&bmpSignDown, clrMask);
  1527. //-----------------------------------------------------------------------
  1528. VERIFY(m_ilGlyphs.Create(16, 11, ILC_COLOR24 | ILC_MASK, 0, 1));
  1529. CBitmap bmp;
  1530. VERIFY(XTPResourceManager()->LoadBitmap(&bmp, XTP_IDB_CALENDAR_EVENT_GLYPHS));
  1531. m_ilGlyphs.Add(&bmp, RGB(255, 0, 255));
  1532. m_CurrSystemTheme = xtpSystemThemeUnknown;
  1533. m_nPaintTheme = xtpCalendarThemeOffice2003;
  1534. RefreshMetrics();
  1535. }
  1536. CXTPCalendarPaintManager::~CXTPCalendarPaintManager()
  1537. {
  1538. while (!m_lstViewParts.IsEmpty())
  1539. {
  1540. delete m_lstViewParts.RemoveHead();
  1541. }
  1542. SAFE_DELETE(m_pGlyphsFont);
  1543. }
  1544. void CXTPCalendarPaintManager::RefreshMetrics()
  1545. {
  1546. RefreshXtremeColors();
  1547. m_clrButtonFace.SetStandardValue(GetSysColor(COLOR_BTNFACE));
  1548. m_clrButtonFaceText.SetStandardValue(GetSysColor(COLOR_BTNTEXT));
  1549. m_clrWindow.SetStandardValue(GetSysColor(COLOR_WINDOW));
  1550. m_clrWindowText.SetStandardValue(GetSysColor(COLOR_WINDOWTEXT));
  1551. m_clr3DShadow.SetStandardValue(GetSysColor(COLOR_3DSHADOW));
  1552. m_clrHighlight.SetStandardValue(GetSysColor(COLOR_HIGHLIGHT));
  1553. InitBusyStatusDefaultColors();
  1554. POSITION pos = m_lstViewParts.GetHeadPosition();
  1555. while (pos)
  1556. {
  1557. CXTPCalendarViewPart* pPart = m_lstViewParts.GetNext(pos);
  1558. ASSERT(pPart);
  1559. if (pPart)
  1560. {
  1561. pPart->RefreshMetrics();
  1562. }
  1563. }
  1564. m_grclrToday.SetStandardValue(m_clrButtonFace, m_clrButtonFace);
  1565. m_clrUnderLineHdr = m_clrHighlight;
  1566. if (m_nPaintTheme >= xtpCalendarThemeOffice2003)
  1567. {
  1568. m_CurrSystemTheme = xtpSystemThemeUnknown;
  1569. if (m_bEnableTheme && !XTPColorManager()->IsLunaColorsDisabled())
  1570. {
  1571. m_CurrSystemTheme = XTPColorManager()->GetCurrentSystemTheme();
  1572. if (m_CurrSystemTheme != xtpSystemThemeUnknown)
  1573. {
  1574. m_grclrToday.SetStandardValue(m_clrButtonFace, RGB(250, 203, 91));
  1575. m_clrUnderLineHdr = RGB(187, 85, 3);
  1576. }
  1577. }
  1578. }
  1579. //-----------------------------------------------------------------------
  1580. SAFE_DELETE(m_pGlyphsFont);
  1581. BOOL bFontExists = XTPDrawHelpers()->FontExists(cszGlyphsFontName);
  1582. if (bFontExists)
  1583. {
  1584. m_pGlyphsFont = new CFont();
  1585. if (m_pGlyphsFont)
  1586. {
  1587. LOGFONT lfGlupth;
  1588. ::ZeroMemory(&lfGlupth, sizeof(lfGlupth));
  1589. STRCPY_S(lfGlupth.lfFaceName, LF_FACESIZE, cszGlyphsFontName);
  1590. lfGlupth.lfCharSet = SYMBOL_CHARSET;
  1591. lfGlupth.lfHeight = -11;
  1592. lfGlupth.lfWeight = FW_NORMAL;
  1593. if (!m_pGlyphsFont->CreateFontIndirect(&lfGlupth))
  1594. {
  1595. SAFE_DELETE(m_pGlyphsFont);
  1596. }
  1597. }
  1598. }
  1599. if (!m_pGlyphsFont)
  1600. {
  1601. TRACE(_T("WARNING! Calendar PaintManeger: cannot create 'MS Outlook' font. Standard bitmaps are used. n"));
  1602. }
  1603. }
  1604. void CXTPCalendarPaintManager::CDayViewWorkCellPart::RefreshMetrics()
  1605. {
  1606. if (m_pPaintManager->GetPaintTheme() <= xtpCalendarThemeOffice2000 ||
  1607. m_pPaintManager->GetPaintTheme() == xtpCalendarThemeOfficeXP)
  1608. {
  1609. if (m_pPaintManager->GetPaintTheme() <= xtpCalendarThemeOffice2000)
  1610. m_clrBackground.SetStandardValue(RGB(255, 255, 255));
  1611. else
  1612. m_clrBackground.SetStandardValue(RGB(255, 255, 0));
  1613. m_clrBackgroundSlave.SetStandardValue(RGB(255, 255, 255));
  1614. m_clrShadow.SetStandardValue(RGB(128, 128, 128));
  1615. m_clrHour.SetStandardValue(RGB(128, 128, 128));
  1616. }
  1617. else if (m_pPaintManager->GetPaintTheme() >= xtpCalendarThemeOffice2003)
  1618. {
  1619. m_clrBackground.SetStandardValue(RGB(255, 255, 213));
  1620. m_clrShadow.SetStandardValue(RGB(243, 228, 177));
  1621. m_clrHour.SetStandardValue(RGB(234, 208, 152));
  1622. }
  1623. else {
  1624. ASSERT(FALSE);
  1625. }
  1626. }
  1627. void CXTPCalendarPaintManager::CDayViewNonworkCellPart::RefreshMetrics()
  1628. {
  1629. if (m_pPaintManager->GetPaintTheme() <= xtpCalendarThemeOffice2000 ||
  1630. m_pPaintManager->GetPaintTheme() == xtpCalendarThemeOfficeXP)
  1631. {
  1632. m_clrBackground.SetStandardValue(RGB(255, 255, 0));
  1633. m_clrBackgroundSlave.SetStandardValue(RGB(128, 128, 128));
  1634. if (m_pPaintManager->GetPaintTheme() <= xtpCalendarThemeOffice2000)
  1635. {
  1636. m_clrBackground.SetStandardValue(RGB(212, 208, 200));
  1637. m_clrBackgroundSlave.SetStandardValue(RGB(212, 208, 200));
  1638. }
  1639. m_clrShadow.SetStandardValue(RGB(128, 128, 128));
  1640. m_clrHour.SetStandardValue(RGB(128, 128, 128));
  1641. }
  1642. else if (m_pPaintManager->GetPaintTheme() >= xtpCalendarThemeOffice2003)
  1643. {
  1644. m_clrBackground.SetStandardValue(RGB(255, 244, 188));
  1645. m_clrBackgroundSlave.SetStandardValue(RGB(255, 244, 188));
  1646. m_clrShadow.SetStandardValue(RGB(243, 228, 177));
  1647. m_clrHour.SetStandardValue(RGB(234, 208, 152));
  1648. }
  1649. else {
  1650. ASSERT(FALSE);
  1651. }
  1652. }
  1653. void CXTPCalendarPaintManager::CMonthViewGridPart::RefreshMetrics()
  1654. {
  1655. if (m_pPaintManager->GetPaintTheme() <= xtpCalendarThemeOffice2000 ||
  1656. m_pPaintManager->GetPaintTheme() == xtpCalendarThemeOfficeXP)
  1657. {
  1658. m_clrBackground.SetStandardValue(RGB(255, 255, 255));
  1659. m_clrBackground2.SetStandardValue(RGB(215, 211, 203));
  1660. }
  1661. else if (m_pPaintManager->GetPaintTheme() >= xtpCalendarThemeOffice2003)
  1662. {
  1663. m_clrBackground.SetStandardValue(RGB(255, 255, 213));
  1664. m_clrBackground2.SetStandardValue(RGB(255, 244, 188));
  1665. }
  1666. else {
  1667. ASSERT(FALSE);
  1668. }
  1669. }
  1670. void CXTPCalendarPaintManager::CWeekViewPart::RefreshMetrics()
  1671. {
  1672. m_clrTextColor.SetStandardValue(m_pPaintManager->m_clrButtonFaceText);
  1673. m_clrTextHighLightColor = RGB(255, 255, 255);
  1674. m_clrTextNormalColor = m_pPaintManager->m_clrButtonFaceText;
  1675. m_clrHeaderBottomLine = m_pPaintManager->m_clr3DShadow;
  1676. LOGFONT lfIcon;
  1677. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  1678. m_fntText.SetStandardValue(&lfIcon);
  1679. if (m_pPaintManager->GetPaintTheme() <= xtpCalendarThemeOffice2000 ||
  1680. m_pPaintManager->GetPaintTheme() == xtpCalendarThemeOfficeXP)
  1681. {
  1682. m_clrBackground.SetStandardValue(RGB(255, 255, 255));
  1683. }
  1684. else if (m_pPaintManager->GetPaintTheme() >= xtpCalendarThemeOffice2003)
  1685. {
  1686. m_clrBackground.SetStandardValue(RGB(255, 255, 213));
  1687. }
  1688. else {
  1689. ASSERT(FALSE);
  1690. }
  1691. }
  1692. CXTPCalendarViewPart* CXTPCalendarPaintManager::AddViewPart(CXTPCalendarViewPart* pPart)
  1693. {
  1694. ASSERT(pPart);
  1695. if (pPart)
  1696. {
  1697. m_lstViewParts.AddTail(pPart);
  1698. pPart->m_pPaintManager = this;
  1699. }
  1700. return pPart;
  1701. }
  1702. void CXTPCalendarPaintManager::DrawLine(CDC* pDC, int x, int y, int cx, int cy)
  1703. {
  1704. ASSERT(pDC);
  1705. if (!pDC)
  1706. {
  1707. return;
  1708. }
  1709. pDC->MoveTo(x, y);
  1710. pDC->LineTo(x + cx, y + cy);
  1711. }
  1712. void CXTPCalendarPaintManager::DrawHorizontalLine(CDC* pDC, int x, int y, int cx)
  1713. {
  1714. DrawLine(pDC, x, y, cx, 0);
  1715. }
  1716. void CXTPCalendarPaintManager::DrawVerticalLine(CDC* pDC, int x, int y, int cy)
  1717. {
  1718. DrawLine(pDC, x, y, 0, cy);
  1719. }
  1720. int CXTPCalendarPaintManager::DrawBitmap(CImageList* pImageList, CDC* pDC,
  1721.  CRect rcView, int iIcon, UINT uFlags)
  1722. {
  1723. ASSERT(pImageList && pDC);
  1724. if (!pImageList || !pDC)
  1725. {
  1726. return 0;
  1727. }
  1728. int nImageBound = rcView.left;
  1729. if (rcView.left >= rcView.right - 2)
  1730. return nImageBound;
  1731. POINT ptIcon;
  1732. IMAGEINFO imgInf;
  1733. if (!pImageList->GetImageInfo(iIcon, &imgInf))
  1734. return nImageBound;
  1735. CSize szImage(imgInf.rcImage.right - imgInf.rcImage.left, imgInf.rcImage.bottom - imgInf.rcImage.top);
  1736. CSize szView(rcView.Size());
  1737. ptIcon.x = rcView.left;
  1738. ptIcon.y = rcView.top;
  1739. szImage.cx = min(szImage.cx, szView.cx);
  1740. if (uFlags & DT_VCENTER)
  1741. {
  1742. ptIcon.y = rcView.top + (szView.cy - szImage.cy) /2 + 1;
  1743. }
  1744. IMAGELISTDRAWINDIRECT_S(pImageList, pDC, iIcon, ptIcon, szImage);
  1745. return szImage.cx;
  1746. }
  1747. int CXTPCalendarPaintManager::DrawBitmap(UINT nIDResource, CDC* pDC, CRect rcBitmap)
  1748. {
  1749. ASSERT(pDC);
  1750. if (!pDC)
  1751. {
  1752. return 0;
  1753. }
  1754. CBitmap bmpIcon;
  1755. if (!XTPResourceManager()->LoadBitmap(&bmpIcon, nIDResource))
  1756. return 0;
  1757. BITMAP bmpInfo;
  1758. bmpIcon.GetBitmap(&bmpInfo);
  1759. CImageList ilBitmap;
  1760. VERIFY(ilBitmap.Create(bmpInfo.bmWidth, bmpInfo.bmHeight, ILC_COLOR24 | ILC_MASK, 0, 1));
  1761. ilBitmap.Add(&bmpIcon, RGB(255, 0 , 255));
  1762. CRect rcBitmap2 = rcBitmap;
  1763. rcBitmap2.bottom = rcBitmap2.top + bmpInfo.bmHeight;
  1764. DrawBitmap(&ilBitmap, pDC, rcBitmap2, 0);
  1765. // Don't work correctly for the printer
  1766. //
  1767. //  CXTPCompatibleDC dcMem(pDC, &bmpIcon);
  1768. //
  1769. // Get the size of the bitmap
  1770. //  BITMAP bmpInfo;
  1771. //  bmpIcon.GetBitmap(&bmpInfo);
  1772. //  pDC->BitBlt(rcBitmap.left, rcBitmap.top,
  1773. //              bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMem,
  1774. //              0, 0, SRCCOPY);
  1775. return bmpInfo.bmWidth;
  1776. }
  1777. CSize CXTPCalendarPaintManager::GetBitmapSize(UINT nIDResource)
  1778. {
  1779. CBitmap bmpIcon;
  1780. VERIFY(XTPResourceManager()->LoadBitmap(&bmpIcon, nIDResource));
  1781. BITMAP bmpInfo;
  1782. bmpIcon.GetBitmap(&bmpInfo);
  1783. CSize szIcon(bmpInfo.bmWidth, bmpInfo.bmHeight);
  1784. return szIcon;
  1785. }
  1786. const CSize CXTPCalendarPaintManager::GetExpandSignSize()
  1787. {
  1788. // if sign size is not initialized, initialize it
  1789. if (!(m_szExpandSign.cx | m_szExpandSign.cy))
  1790. {
  1791. m_szExpandSign = GetBitmapSize(XTP_IDB_CALENDAR_EXPANDSIGNDOWN);
  1792. }
  1793. return m_szExpandSign;
  1794. }
  1795. int CXTPCalendarPaintManager::DrawClock(CDC* pDC, COleDateTime dtClockTime,
  1796. CRect rcView, COLORREF clrBackground, XTPCalendarClockAlignFlags cafAlign)
  1797. {
  1798. ASSERT(pDC);
  1799. if (!pDC)
  1800. {
  1801. return 0;
  1802. }
  1803. static const CPoint arrHours[] =
  1804. {
  1805. CPoint(0, -6),
  1806. CPoint(3, -5),
  1807. CPoint(5, -3),
  1808. CPoint(6, 0),
  1809. CPoint(5, 3),
  1810. CPoint(3, 5),
  1811. CPoint(0, 6),
  1812. CPoint(-3, 5),
  1813. CPoint(-5, 3),
  1814. CPoint(-6, 0),
  1815. CPoint(-5, -3),
  1816. CPoint(-3, -5),
  1817. CPoint(0, -6)
  1818. };
  1819. static const CPoint arrHalfHours[] =
  1820. {
  1821. CPoint(1, -5),
  1822. CPoint(3, -3),
  1823. CPoint(4, -1),
  1824. CPoint(5, 1),
  1825. CPoint(3, 3),
  1826. CPoint(1, 5),
  1827. CPoint(-1, 5),
  1828. CPoint(-3, 3),
  1829. CPoint(-5, 1),
  1830. CPoint(-5, -1),
  1831. CPoint(-3, -3),
  1832. CPoint(-1, -5),
  1833. CPoint(1, -5)
  1834. };
  1835. if (rcView.Width() < m_szClockRect.cx || rcView.Height() < m_szClockRect.cy)
  1836. return 0;
  1837. CPoint ptClock(rcView.left, rcView.top);
  1838. if (cafAlign == xtpCalendarClockAlignLeft)
  1839. ptClock.Offset(1, (rcView.Height() - m_szClockRect.cy)/2 + 1);
  1840. else if (cafAlign == xtpCalendarClockAlignRight)
  1841. ptClock.Offset(rcView.Width() - m_szClockRect.cx - 1,
  1842.    (rcView.Height() - m_szClockRect.cy)/2 + 1);
  1843. else if (cafAlign == xtpCalendarClockAlignCenter)
  1844. ptClock.Offset((rcView.Width() - m_szClockRect.cx)/2,
  1845.    (rcView.Height() - m_szClockRect.cy)/2 + 1);
  1846. CRect rcClock(0, 0, 0, 0);
  1847. rcClock.SetRect(ptClock.x, ptClock.y,
  1848. ptClock.x + m_szClockRect.cx,
  1849. ptClock.y + m_szClockRect.cy);
  1850. int nHour = dtClockTime.GetHour();
  1851. int nMin = dtClockTime.GetMinute() /5;
  1852. COLORREF clrFill;
  1853. COLORREF clrItems;
  1854. if (nHour >= 12)
  1855. {
  1856. clrFill = RGB(0, 0, 0);
  1857. clrItems = clrBackground;
  1858. }
  1859. else
  1860. {
  1861. clrFill = clrBackground;
  1862. clrItems = RGB(0, 0, 0);
  1863. }
  1864. nHour = nHour > 12 ? nHour - 12 : nHour;
  1865. CXTPBrushDC brushClock(pDC->m_hDC, clrFill);
  1866. CPoint ptCenter(rcClock.CenterPoint());
  1867. pDC->Ellipse(rcClock);
  1868. CXTPPenDC penItems(pDC->m_hDC, clrItems);
  1869. int x = 0;
  1870. int y = 0;
  1871. for (int i = 0; i <= 12; i++)
  1872. {
  1873. pDC->SetPixel(ptCenter.x + arrHours[i].x,
  1874.   ptCenter.y + arrHours[i].y, clrItems);
  1875. if (nHour == i)
  1876. {
  1877. if (nMin >= 6)
  1878. {
  1879. x = arrHalfHours[i].x;
  1880. y = arrHalfHours[i].y;
  1881. }
  1882. else
  1883. {
  1884. x = arrHours[i].x;
  1885. y = arrHours[i].y;
  1886. x = x > 0 ? x -1 : x == 0 ? 0 : x + 1;
  1887. y = y > 0 ? y -1 : y == 0 ? 0 : y + 1;
  1888. }
  1889. pDC->MoveTo(ptCenter);
  1890. pDC->LineTo(ptCenter.x+ x, ptCenter.y + y);
  1891. }
  1892. if (nMin == i)
  1893. {
  1894. pDC->MoveTo(ptCenter);
  1895. pDC->LineTo(ptCenter.x + arrHours[i].x,
  1896. ptCenter.y + arrHours[i].y);
  1897. }
  1898. }
  1899. return m_szClockRect.cx;
  1900. }
  1901. void CXTPCalendarPaintManager::SetControl(CXTPCalendarControl* pControl)
  1902. {
  1903. m_pControl = pControl;
  1904. }
  1905. int CXTPCalendarPaintManager::DrawIconChar(CDC* pDC, CRect rc, TCHAR ch)
  1906. {
  1907. if (!pDC || !m_pGlyphsFont || !m_pGlyphsFont->m_hObject)
  1908. {
  1909. ASSERT(FALSE);
  1910. return 0;
  1911. }
  1912. CFont* pPrevFnt = pDC->SelectObject(m_pGlyphsFont);
  1913. pDC->SetTextColor(GetControlPart()->GetTextColor());
  1914. TCHAR cszCh[2] = {ch, 0};
  1915. UINT uFlags = DT_VCENTER | DT_LEFT; // DT_CENTER;
  1916. //CSize szChar = pDC->GetTextExtent(szCh, 1);
  1917. CRect rcNeed = rc;
  1918. pDC->DrawText(cszCh, 1, rcNeed, uFlags | DT_CALCRECT);
  1919. rc.bottom = rc.top + rcNeed.Height();
  1920. pDC->DrawText(cszCh, 1, rc, uFlags);
  1921. pDC->SelectObject(pPrevFnt);
  1922. //return szChar.cx;
  1923. return rcNeed.Width();
  1924. }
  1925. int CXTPCalendarPaintManager::DrawIcons(CDC* pDC, CXTPCalendarViewEvent* pViewEvent)
  1926. {
  1927. if (!pViewEvent || !pViewEvent->GetEvent())
  1928. {
  1929. ASSERT(FALSE);
  1930. return 0;
  1931. }
  1932. BOOL bUseFont = XTP_SAFE_GET3(pViewEvent, GetCalendarControl(),
  1933. GetCalendarOptions(), bUseOutlookFontGlyphs, FALSE);
  1934. bUseFont = bUseFont && m_pGlyphsFont;
  1935. int nWidth = 0;
  1936. if (pViewEvent->GetEvent()->IsReminder() &&
  1937. !pViewEvent->GetReminderGlyphRect().IsRectEmpty())
  1938. {
  1939. if (bUseFont)
  1940. {
  1941. nWidth += DrawIconChar(pDC, pViewEvent->GetReminderGlyphRect(), 0x41);
  1942. }
  1943. else
  1944. {
  1945. nWidth += DrawBitmap(&m_ilGlyphs, pDC,
  1946. pViewEvent->GetReminderGlyphRect(), 0, DT_VCENTER);
  1947. }
  1948. }
  1949. int nRecurrenceState = pViewEvent->GetEvent()->GetRecurrenceState();
  1950. if (!pViewEvent->GetRecurrenceGlyphRect().IsRectEmpty())
  1951. {
  1952. if ((nRecurrenceState == xtpCalendarRecurrenceMaster) || (nRecurrenceState == xtpCalendarRecurrenceOccurrence))
  1953. {
  1954. if (bUseFont)
  1955. {
  1956. nWidth += DrawIconChar(pDC, pViewEvent->GetRecurrenceGlyphRect(), 0x43);
  1957. }
  1958. else
  1959. {
  1960. nWidth += DrawBitmap(&m_ilGlyphs, pDC,
  1961.  pViewEvent->GetRecurrenceGlyphRect(), 1, DT_VCENTER);
  1962. }
  1963. }
  1964. else if (nRecurrenceState == xtpCalendarRecurrenceException)
  1965. {
  1966. if (bUseFont)
  1967. {
  1968. nWidth += DrawIconChar(pDC, pViewEvent->GetRecurrenceGlyphRect(), 0x44);
  1969. }
  1970. else
  1971. {
  1972. nWidth += DrawBitmap(&m_ilGlyphs, pDC,
  1973. pViewEvent->GetRecurrenceGlyphRect(), 2, DT_VCENTER);
  1974. }
  1975. }
  1976. }
  1977. if (pViewEvent->GetEvent()->IsMeeting() &&
  1978. !pViewEvent->GetMeetingGlyphRect().IsRectEmpty())
  1979. {
  1980. if (bUseFont)
  1981. {
  1982. nWidth += DrawIconChar(pDC, pViewEvent->GetMeetingGlyphRect(), 0x45);
  1983. }
  1984. else
  1985. {
  1986. nWidth += DrawBitmap(&m_ilGlyphs, pDC,
  1987. pViewEvent->GetMeetingGlyphRect(), 3, DT_VCENTER);
  1988. }
  1989. }
  1990. if (pViewEvent->GetEvent()->IsPrivate() &&
  1991. !pViewEvent->GetPrivateGlyphRect().IsRectEmpty())
  1992. {
  1993. if (bUseFont)
  1994. {
  1995. nWidth += DrawIconChar(pDC, pViewEvent->GetPrivateGlyphRect(), 0x42);
  1996. }
  1997. else
  1998. {
  1999. nWidth += DrawBitmap(&m_ilGlyphs, pDC,
  2000. pViewEvent->GetPrivateGlyphRect(), 4, DT_VCENTER);
  2001. }
  2002. }
  2003. return nWidth;
  2004. }
  2005. void CXTPCalendarPaintManager::InitBusyStatusDefaultColors()
  2006. {
  2007. m_brushTentative.DeleteObject();
  2008. m_bmpTentativePattern.DeleteObject();
  2009. VERIFY(XTPResourceManager()->LoadBitmap(&m_bmpTentativePattern, XTP_IDB_CALENDAR_TENATIVE_PATTERN));
  2010. VERIFY(m_brushTentative.CreatePatternBrush(&m_bmpTentativePattern));
  2011. CXTPCalendarViewPartBrushValue* pBVal_Free = _GetAtGrow_BusyStatusBrushValue(xtpCalendarBusyStatusFree, TRUE);
  2012. CXTPCalendarViewPartBrushValue* pBVal_Tentative = _GetAtGrow_BusyStatusBrushValue(xtpCalendarBusyStatusTentative, TRUE);
  2013. CXTPCalendarViewPartBrushValue* pBVal_Busy = _GetAtGrow_BusyStatusBrushValue(xtpCalendarBusyStatusBusy, TRUE);
  2014. CXTPCalendarViewPartBrushValue* pBVal_OutOO = _GetAtGrow_BusyStatusBrushValue(xtpCalendarBusyStatusOutOfOffice, TRUE);
  2015. if (pBVal_Free)
  2016. {
  2017. pBVal_Free->SetStandardValue(new CBrush(RGB(0xFF, 0xFF, 0xFF)), TRUE);
  2018. }
  2019. if (pBVal_Tentative)
  2020. {
  2021. pBVal_Tentative->SetStandardValue(&m_brushTentative, FALSE);
  2022. }
  2023. if (pBVal_Busy)
  2024. {
  2025. pBVal_Busy->SetStandardValue(new CBrush(RGB(0, 0, 0xFF)), TRUE);
  2026. }
  2027. if (pBVal_OutOO)
  2028. {
  2029. pBVal_OutOO->SetStandardValue(new CBrush(RGB(132, 0, 132)), TRUE);
  2030. }
  2031. }
  2032. void CXTPCalendarPaintManager::SetBusyStatusBrush(int eBusyStatus, CBrush* pBrush, BOOL bAutodeleteBrush)
  2033. {
  2034. if (eBusyStatus < 0 || !pBrush)
  2035. {
  2036. ASSERT(FALSE);
  2037. return;
  2038. }
  2039. CXTPCalendarViewPartBrushValue* pBVal = _GetAtGrow_BusyStatusBrushValue(eBusyStatus, TRUE);
  2040. ASSERT(pBVal);
  2041. if (pBVal)
  2042. {
  2043. pBVal->SetCustomValue(pBrush, bAutodeleteBrush);
  2044. }
  2045. }
  2046. CBrush* CXTPCalendarPaintManager::GetBusyStatusBrush(int nBusyStatus)
  2047. {
  2048. CXTPCalendarViewPartBrushValue* pBVal = _GetAtGrow_BusyStatusBrushValue(nBusyStatus, TRUE);
  2049. ASSERT(pBVal);
  2050. if (pBVal)
  2051. {
  2052. CBrush* pBrush = pBVal->GetValue();
  2053. return pBrush;
  2054. }
  2055. return NULL;
  2056. }
  2057. CXTPCalendarViewPartBrushValue* CXTPCalendarPaintManager::_GetAtGrow_BusyStatusBrushValue(
  2058. int nBusyStatus, BOOL bGrow)
  2059. {
  2060. if (nBusyStatus < 0)
  2061. {
  2062. //ASSERT(FALSE);
  2063. nBusyStatus = 0;
  2064. }
  2065. int nCount = (int)m_arBusyStatusBrushes.GetSize();
  2066. if (nBusyStatus >= nCount || m_arBusyStatusBrushes[nBusyStatus] == NULL)
  2067. {
  2068. if (!bGrow)
  2069. {
  2070. return NULL;
  2071. }
  2072. m_arBusyStatusBrushes.SetAtGrow(nBusyStatus, new CXTPCalendarViewPartBrushValue);
  2073. }
  2074. CXTPCalendarViewPartBrushValue* pBVal = m_arBusyStatusBrushes[nBusyStatus];
  2075. return pBVal;
  2076. }
  2077. void CXTPCalendarPaintManager::DrawBusyStatus(CDC* pDC, CRect& rcRect, int eBusyStatus)
  2078. {
  2079. CBrush* pBrush = GetBusyStatusBrush(eBusyStatus);
  2080. if (!pBrush || !pDC)
  2081. {
  2082. ASSERT(FALSE);
  2083. return;
  2084. }
  2085. pDC->FillRect(&rcRect, pBrush);
  2086. }
  2087. void CXTPCalendarPaintManager::DrawBusyStatus(CDC* pDC, CRgn& rgnBusy, int eBusyStatus)
  2088. {
  2089. CBrush* pBrush = GetBusyStatusBrush(eBusyStatus);
  2090. if (!pBrush || !pDC)
  2091. {
  2092. ASSERT(FALSE);
  2093. return;
  2094. }
  2095. CBrush brBorder(m_clrWindowText);
  2096. VERIFY(pDC->FillRgn(&rgnBusy, pBrush));
  2097. VERIFY(pDC->FrameRgn(&rgnBusy, &brBorder, 1, 1));
  2098. }
  2099. //////////////////////////////////////////////////////////////////////////