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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarDayViewDay.cpp: implementation of the CXTPCalendarDayViewDay 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 <math.h>
  22. #include "Common/XTPVC50Helpers.h"
  23. #include "XTPCalendarDayViewDay.h"
  24. #include "XTPCalendarDayView.h"
  25. #include "XTPCalendarControl.h"
  26. #include "XTPCalendarTheme.h"
  27. #include "XTPCalendarThemeOffice2007.h"
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #define new DEBUG_NEW
  32. #endif
  33. IMPLEMENT_DYNAMIC(CXTPCalendarDayViewDay, CXTPCalendarViewDay)
  34. IMPLEMENT_DYNAMIC(CXTPCalendarDayViewGroup, CXTPCalendarViewGroup)
  35. //////////////////////////////////////////////////////////////////////
  36. // Construction/Destruction
  37. //////////////////////////////////////////////////////////////////////
  38. CXTPCalendarDayViewDay::CXTPCalendarDayViewDay(CXTPCalendarDayView* pDayView, COleDateTime dtDate)
  39. : TBase(pDayView)
  40. {
  41. m_dtDate = dtDate;
  42. }
  43. CXTPCalendarDayViewDay::~CXTPCalendarDayViewDay()
  44. {
  45. }
  46. void CXTPCalendarDayViewDay::Populate(COleDateTime dtDayDate)
  47. {
  48. m_dtDate = CXTPCalendarUtils::ResetTime(dtDayDate);
  49. m_arViewGroups.RemoveAll();
  50. if (!GetView_())
  51. {
  52. return;
  53. }
  54. OnPrePopulateDay();
  55. CXTPCalendarResources* pResources = GetResources();
  56. if (!pResources)
  57. {
  58. return;
  59. }
  60. int nCount = pResources->GetCount();
  61. for (int i = 0; i < nCount; i++)
  62. {
  63. CXTPCalendarResource* pRC = pResources->GetAt(i);
  64. if (!pRC)
  65. {
  66. ASSERT(FALSE);
  67. continue;
  68. }
  69. CXTPCalendarDayViewGroup* pGroup = new CXTPCalendarDayViewGroup(this);
  70. if (!pGroup)
  71. {
  72. return;
  73. }
  74. m_arViewGroups.Add(pGroup);
  75. pGroup->AddResource(pRC, TRUE);
  76. pGroup->Populate(m_dtDate);
  77. }
  78. }
  79. void CXTPCalendarDayViewDay::AdjustLayout(CDC* pDC, const CRect& rcDay)
  80. {
  81. if (!GetView() || !pDC)
  82. {
  83. ASSERT(FALSE);
  84. return;
  85. }
  86. CXTPCalendarViewDay::AdjustLayout(pDC, rcDay);
  87. //TBase::AdjustLayout(pDC, rcDay);
  88. CRect rcDayHeader = GetView()->GetDayHeaderRectangle();
  89. m_Layout.m_rcDayHeader.SetRect(rcDay.left, rcDayHeader.top, rcDay.right, rcDayHeader.bottom);
  90. CRect rcGroups = rcDay;
  91. rcGroups.top = m_Layout.m_rcDayHeader.bottom;
  92. int nGroupsCount = GetViewGroupsCount();
  93. int nGroupWidth = rcGroups.Width() / max(1, nGroupsCount);
  94. for (int i = 0; i < nGroupsCount; i++)
  95. {
  96. CXTPCalendarDayViewGroup* pViewGroup = GetViewGroup(i);
  97. ASSERT(pViewGroup);
  98. if (pViewGroup)
  99. {
  100. CRect rcGroupI = rcGroups;
  101. rcGroupI.left += nGroupWidth * i;
  102. if (i < nGroupsCount - 1)
  103. {
  104. rcGroupI.right = rcGroupI.left + nGroupWidth;
  105. }
  106. pViewGroup->AdjustLayout(pDC, rcGroupI);
  107. }
  108. }
  109. }
  110. void CXTPCalendarDayViewDay::AdjustLayout2(CDC* pDC, const CRect& rcDay)
  111. {
  112. if (!pDC || !GetView() || !GetView()->GetTheme())
  113. {
  114. ASSERT(FALSE);
  115. return;
  116. }
  117. CXTPCalendarViewDay::AdjustLayout(pDC, rcDay);
  118. GetView()->GetTheme()->GetDayViewPart()->GetDayPart()->AdjustLayout(this, pDC, rcDay);
  119. }
  120. CString CXTPCalendarDayViewDay::GetCaption()
  121. {
  122. COleDateTime dt(m_dtDate);
  123. SYSTEMTIME st;
  124. GETASSYSTEMTIME_DT(dt, st);
  125. CString strHeaderFormat = GetView() ? GetView()->GetDayHeaderFormat() : _T("");
  126. CString strResult = CXTPCalendarUtils::GetDateFormat(&st, strHeaderFormat);
  127. //-------------------------------------------------------------
  128. DWORD dwFlags = XTP_SAFE_GET2(GetView(), GetCalendarControl(), GetAskItemTextFlags(), 0);
  129. if (dwFlags & xtpCalendarItemText_DayViewDayHeader)
  130. {
  131. XTP_CALENDAR_GETITEMTEXT_PARAMS objRequest;
  132. ::ZeroMemory(&objRequest, sizeof(objRequest));
  133. objRequest.nItem = (int)xtpCalendarItemText_DayViewDayHeader;
  134. objRequest.pstrText = &strResult;
  135. objRequest.pViewDay = this;
  136. XTP_SAFE_CALL2(GetView(), GetCalendarControl(), SendNotificationAlways(
  137. XTP_NC_CALENDAR_GETITEMTEXT, (WPARAM)&objRequest, 0));
  138. }
  139. //-------------------------------------------------------------
  140. return strResult;
  141. }
  142. void CXTPCalendarDayViewDay::Draw(CDC* pDC)
  143. {
  144. // draw groups
  145. int nGroupsCount = GetViewGroupsCount();
  146. for (int i = 0; i < nGroupsCount; i++)
  147. {
  148. CXTPCalendarDayViewGroup* pViewGroup = GetViewGroup(i);
  149. ASSERT(pViewGroup);
  150. if (pViewGroup)
  151. {
  152. pViewGroup->Draw(pDC);
  153. }
  154. }
  155. // draw header part
  156. XTP_SAFE_CALL3(GetView(), GetPaintManager(), GetDayViewHeaderPart(),
  157. OnDraw(pDC, this, m_Layout.m_rcDayHeader, GetCaption()) );
  158. }
  159. void CXTPCalendarDayViewDay::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_DAY_VIEW* pInfo)
  160. {
  161. if (!pInfo)
  162. {
  163. ASSERT(FALSE);
  164. return;
  165. }
  166. pInfo->dt = m_dtDate;
  167. pInfo->pViewDay = this;
  168. pInfo->pViewGroup = NULL;
  169. pInfo->pViewEvent = NULL;
  170. pInfo->uHitCode = xtpCalendarHitTestUnknown;
  171. }
  172. void CXTPCalendarDayViewDay::OnMouseMove(UINT nFlags, CPoint point)
  173. {
  174. if (GetView() && GetView()->GetTheme() && GetView()->GetTheme()->GetDayViewPart() &&
  175. GetView()->GetTheme()->GetDayViewPart()->GetDayPart())
  176. GetView()->GetTheme()->GetDayViewPart()->GetDayPart()->OnMouseMove(this, nFlags, point);
  177. TBase::OnMouseMove(nFlags, point);
  178. }
  179. //////////////////////////////////////////////////////////////////////////
  180. CXTPCalendarDayViewGroup::CXTPCalendarDayViewGroup(CXTPCalendarDayViewDay* pViewDay)
  181. : TBase(pViewDay)
  182. {
  183. m_LayoutX.m_rcAllDayEvents.SetRectEmpty();
  184. m_LayoutX.m_rcDayDetails.SetRectEmpty();
  185. m_LayoutX.m_bShowHeader = TRUE;
  186. m_LayoutX.m_nHotState = 0;
  187. m_bExpandUP = FALSE;
  188. m_bExpandDOWN = FALSE;
  189. }
  190. CXTPCalendarDayViewGroup::~CXTPCalendarDayViewGroup()
  191. {
  192. }
  193. void CXTPCalendarDayViewGroup::AdjustLayout(CDC* pDC, const CRect& rcGroup)
  194. {
  195. if (!pDC || !GetViewDay() || !GetViewDay()->GetView())
  196. {
  197. ASSERT(FALSE);
  198. return;
  199. }
  200. m_bExpandUP = FALSE;
  201. m_bExpandDOWN = FALSE;
  202. m_Layout.m_rcGroup = rcGroup;
  203. m_Layout.m_rcGroupHeader = rcGroup;
  204. m_Layout.m_rcGroupHeader.bottom = m_Layout.m_rcGroupHeader.top; // set empty rect
  205. m_LayoutX.m_bShowHeader = XTP_SAFE_GET2(GetViewDay(), GetView(), IsGroupHeaderVisible(), TRUE);
  206. if (m_LayoutX.m_bShowHeader)
  207. {
  208. CRect rcHeader = GetViewDay()->GetView()->GetDayHeaderRectangle();
  209. m_Layout.m_rcGroupHeader.bottom += rcHeader.Height();
  210. }
  211. CRect rcAllDayEvents = GetViewDay()->GetView()->GetAllDayEventsRectangle();
  212. m_LayoutX.m_rcAllDayEvents = rcGroup;
  213. m_LayoutX.m_rcAllDayEvents.top = m_Layout.m_rcGroupHeader.bottom;
  214. m_LayoutX.m_rcAllDayEvents.bottom = m_LayoutX.m_rcAllDayEvents.top + rcAllDayEvents.Height();
  215. m_LayoutX.m_rcDayDetails = rcGroup;
  216. m_LayoutX.m_rcDayDetails.top = m_LayoutX.m_rcAllDayEvents.bottom;
  217. int nAllDayEventPlace = 0;
  218. // adjust layout of events of this day
  219. //m_bExpandUP = FALSE;
  220. //m_bExpandDOWN = FALSE;
  221. int nEventsCount = GetViewEventsCount();
  222. for (int i = 0; i < nEventsCount; i++)
  223. {
  224. CXTPCalendarDayViewEvent* pViewEvent = GetViewEvent(i);
  225. ASSERT(pViewEvent);
  226. if (pViewEvent && pViewEvent->IsMultidayEvent())
  227. {
  228. rcAllDayEvents = m_LayoutX.m_rcAllDayEvents;
  229. rcAllDayEvents.top += 1;
  230. pViewEvent->AdjustLayout(pDC, rcAllDayEvents, nAllDayEventPlace);
  231. nAllDayEventPlace++;
  232. }
  233. }
  234. AdjustDayEvents(pDC);
  235. }
  236. void CXTPCalendarDayViewGroup::AdjustLayout2(CDC* pDC, const CRect& rcGroup)
  237. {
  238. if (!pDC || !GetViewDay() || !GetViewDay()->GetView() || !GetViewDay()->GetView()->GetTheme())
  239. {
  240. ASSERT(FALSE);
  241. return;
  242. }
  243. m_bExpandUP = FALSE;
  244. m_bExpandDOWN = FALSE;
  245. m_Layout.m_rcGroup = rcGroup;
  246. m_Layout.m_rcGroupHeader = rcGroup;
  247. m_Layout.m_rcGroupHeader.bottom = m_Layout.m_rcGroupHeader.top; // set empty rect
  248. GetViewDay()->GetView()->GetTheme()->GetDayViewPart()->GetDayPart()->GetGroupPart()->AdjustLayout(this, pDC, rcGroup);
  249. }
  250. void CXTPCalendarDayViewGroup::Draw(CDC* pDC)
  251. {
  252. int nRowHeight = GetRowHeight();
  253. if (nRowHeight <= 0 ||
  254. !XTP_SAFE_GET2(GetViewDay(), GetView(), GetPaintManager(), NULL))
  255. {
  256. return;
  257. }
  258. int nRowCount = GetVisibleRowCount();
  259. int nTopRow = GetTopRow();
  260. BOOL bAllDayEventSelected = FALSE;
  261. GetViewDay()->GetView()->GetSelection(NULL, NULL, &bAllDayEventSelected);
  262. BOOL bHasSelectedEvents = GetViewDay()->GetView()->HasSelectedViewEvent();
  263. int nGroupIndex = GetGroupIndex();
  264. // draw rows grid
  265. for (int i = 0; i < nRowCount; i++)
  266. {
  267. CRect rcCell(m_Layout.m_rcGroup.left, m_LayoutX.m_rcDayDetails.top + nRowHeight * i, m_Layout.m_rcGroup.right, m_LayoutX.m_rcDayDetails.top + nRowHeight * (i + 1));
  268. COleDateTime dtDateTime = GetCellDateTime(nTopRow + i) + COleDateTimeSpan(0, 0, 0, 1);
  269. BOOL bSelected = !bAllDayEventSelected && !bHasSelectedEvents &&
  270. GetViewDay()->GetView()->SelectionContains(dtDateTime, nGroupIndex);
  271. CXTPCalendarPaintManager::CDayViewCellPart* pViewPart = (CXTPCalendarPaintManager::CDayViewCellPart*)GetCellViewPart(dtDateTime);
  272. ASSERT(pViewPart);
  273. if (pViewPart)
  274. {
  275. XTP_CALENDAR_DAYVIEWCELL_PARAMS cellParams;
  276. ::ZeroMemory(&cellParams, sizeof(cellParams));
  277. cellParams.bSelected = bSelected;
  278. cellParams.nIndex = nTopRow + i;
  279. cellParams.dtBeginTime = dtDateTime;
  280. pViewPart->GetParams(this, cellParams);
  281. //---------------------------------
  282. WPARAM wParam = (WPARAM)this;
  283. LPARAM lParam = (LPARAM)&cellParams;
  284. XTP_SAFE_CALL2(GetViewDay_(), GetView_(),
  285. SendNotification(XTP_NC_CALENDAR_BEFORE_DRAW_DAYVIEWCELL, wParam, lParam));
  286. //---------------------------------
  287. // these members are read only. changed ???
  288. ASSERT(cellParams.bSelected == bSelected);
  289. ASSERT(cellParams.nIndex == nTopRow + i);
  290. ASSERT(cellParams.dtBeginTime == dtDateTime);
  291. // ensure to have default values
  292. cellParams.bSelected = bSelected;
  293. cellParams.nIndex = nTopRow + i;
  294. cellParams.dtBeginTime = dtDateTime;
  295. //---------------------------------
  296. pViewPart->OnDraw(pDC, this, rcCell, cellParams);
  297. }
  298. }
  299. //1. draw no multiday, no selected events
  300. int nEvent = 0;
  301. int nEventsCount = GetViewEventsCount();
  302. for (nEvent = 0; nEvent < nEventsCount; nEvent++)
  303. {
  304. CXTPCalendarDayViewEvent* pViewEvent = GetViewEvent(nEvent);
  305. if (pViewEvent && !pViewEvent->IsMultidayEvent() && !pViewEvent->IsSelected())
  306. {
  307. pViewEvent->Draw(pDC);
  308. }
  309. }
  310. //2. draw no multiday, selected events
  311. for (nEvent = 0; nEvent < nEventsCount; nEvent++)
  312. {
  313. CXTPCalendarDayViewEvent* pViewEvent = GetViewEvent(nEvent);
  314. if (pViewEvent && !pViewEvent->IsMultidayEvent() && pViewEvent->IsSelected())
  315. {
  316. pViewEvent->Draw(pDC);
  317. }
  318. }
  319. // draw header part
  320. if (m_LayoutX.m_bShowHeader)
  321. {
  322. XTP_SAFE_CALL4(GetViewDay(), GetView(), GetPaintManager(), GetDayViewGroupHeaderPart(),
  323.    OnDraw(pDC, this, m_Layout.m_rcGroupHeader, GetCaption()) );
  324. }
  325. // draw all day events area
  326. if (!m_LayoutX.m_rcAllDayEvents.IsRectEmpty())
  327. {
  328. BOOL bSelected = !bHasSelectedEvents && GetViewDay()->GetView()->SelectionContains(GetViewDay()->GetDayDate()) &&
  329. GetViewDay()->GetView()->SelectionContains(GetViewDay()->GetDayDate() + COleDateTimeSpan(0, 23, 59, 59),
  330. nGroupIndex);
  331. XTP_SAFE_CALL4(GetViewDay(), GetView(), GetPaintManager(), GetDayViewAllDayEventsPart(),
  332. OnDraw(pDC, this, m_LayoutX.m_rcAllDayEvents, bSelected) );
  333. }
  334. // draw all day events
  335. for (nEvent = 0; nEvent < nEventsCount; nEvent++)
  336. {
  337. CXTPCalendarDayViewEvent* pViewEvent = GetViewEvent(nEvent);
  338. if (pViewEvent && pViewEvent->IsMultidayEvent())
  339. {
  340. pViewEvent->Draw(pDC);
  341. }
  342. }
  343. }
  344. BOOL CXTPCalendarDayViewGroup::HitTestEx(CPoint pt, XTP_CALENDAR_HITTESTINFO_DAY_VIEW* pHitTest)
  345. {
  346. if (!pHitTest || !GetViewDay())
  347. {
  348. ASSERT(FALSE);
  349. return FALSE;
  350. }
  351. int nHit = XTP_SAFE_GET5(GetViewDay()->GetView(), GetTheme(), GetDayViewPart(), GetDayPart(),
  352.  GetGroupPart(), HitTestScrollButton(this, &pt), 0);
  353. if (nHit)
  354. {
  355. FillHitTestEx(pHitTest);
  356. pHitTest->uHitCode = nHit;
  357. return TRUE;
  358. }
  359. BOOL bHit = FALSE;
  360. //- process selected day events at the first -------------------------
  361. int nEventsCount = GetViewEventsCount();
  362. for (int nEvent = 0; nEvent < nEventsCount; nEvent++)
  363. {
  364. CXTPCalendarDayViewEvent* pViewEvent = GetViewEvent(nEvent);
  365. ASSERT(pViewEvent);
  366. if (pViewEvent && pViewEvent->IsSelected() && !pViewEvent->IsMultidayEvent())
  367. {
  368. bHit = pViewEvent->HitTestEx(pt, pHitTest);
  369. if (bHit)
  370. {
  371. pHitTest->nEvent = nEvent;
  372. pHitTest->pViewEvent = pViewEvent;
  373. break;
  374. }
  375. }
  376. }
  377. //---------------------------------------------------------------------------
  378. if (!bHit)
  379. {
  380. bHit = TBase::HitTestEx(pt, pHitTest);
  381. }
  382. //---------------------------------------------------------------------------
  383. if (!bHit)
  384. {
  385. XTP_CALENDAR_HITTESTINFO_DAY_VIEW hitInfo;
  386. hitInfo.pt = pt;
  387. FillHitTestEx(&hitInfo);
  388. bHit = HitTestDateTime(&hitInfo);
  389. if (bHit)
  390. {
  391. *pHitTest = hitInfo;
  392. }
  393. }
  394. else
  395. {
  396. pHitTest->pt = pt;
  397. HitTestDateTime(pHitTest);
  398. }
  399. return bHit;
  400. }
  401. void CXTPCalendarDayViewGroup::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_DAY_VIEW* pHitTest)
  402. {
  403. ASSERT(pHitTest && GetViewDay());
  404. if (pHitTest && GetViewDay())
  405. {
  406. GetViewDay()->FillHitTestEx(pHitTest);
  407. pHitTest->pViewGroup = this;
  408. }
  409. }
  410. /*
  411. void CXTPCalendarDayViewGroup::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_DAY_VIEW* pInfo)
  412. {
  413. if (!pInfo || !GetViewDay())
  414. {
  415. ASSERT(FALSE);
  416. return;
  417. }
  418. pInfo->dt = GetViewDay()->GetDayDate();
  419. pInfo->pViewDay = GetViewDay();
  420. pInfo->pViewGroup = this;
  421. pInfo->pViewEvent = NULL;
  422. pInfo->uHitCode = xtpCalendarHitTestUnknown;
  423. }
  424. */
  425. BOOL CXTPCalendarDayViewGroup::HitTestDateTime(XTP_CALENDAR_HITTESTINFO_DAY_VIEW* pHitTest)
  426. {
  427. if (!pHitTest || !GetViewDay())
  428. {
  429. ASSERT(FALSE);
  430. return FALSE;
  431. }
  432. int nVisibleRowCount = GetVisibleRowCount();
  433. if (m_LayoutX.m_rcDayDetails.PtInRect(pHitTest->pt) && nVisibleRowCount > 0)
  434. {
  435. int nCell = (pHitTest->pt.y - m_LayoutX.m_rcDayDetails.top) / max(GetRowHeight(), 1);
  436. if (nCell >= 0 && nCell < nVisibleRowCount)
  437. {
  438. pHitTest->dt = GetCellDateTime(nCell + GetTopRow());
  439. pHitTest->bTimePartValid = TRUE;
  440. pHitTest->uHitCode |= xtpCalendarHitTestDayViewCell;
  441. return TRUE;
  442. }
  443. }
  444. if (m_LayoutX.m_rcAllDayEvents.PtInRect(pHitTest->pt) ||
  445. m_Layout.m_rcGroupHeader.PtInRect(pHitTest->pt) ||
  446. GetViewDay()->m_Layout.m_rcDayHeader.PtInRect(pHitTest->pt))
  447. {
  448. pHitTest->dt = GetViewDay()->GetDayDate();
  449. pHitTest->bTimePartValid = FALSE;
  450. pHitTest->uHitCode |= xtpCalendarHitTestDayViewAllDayEvent;
  451. return TRUE;
  452. }
  453. return FALSE;
  454. }
  455. BOOL CXTPCalendarDayViewGroup::OnLButtonDown(UINT nFlags, CPoint point)
  456. {
  457. if (!GetViewDay())
  458. {
  459. ASSERT(FALSE);
  460. return FALSE;
  461. }
  462. if (XTP_SAFE_GET5(GetViewDay()->GetView(), GetTheme(), GetDayViewPart(), GetDayPart(),
  463. GetGroupPart(), OnLButtonDown(this, nFlags, point), FALSE))
  464. {
  465. return TRUE;
  466. }
  467. return TBase::OnLButtonDown(nFlags, point);
  468. }
  469. void CXTPCalendarDayViewGroup::OnMouseMove(UINT nFlags, CPoint point)
  470. {
  471. if (!GetViewDay())
  472. {
  473. ASSERT(FALSE);
  474. return;
  475. }
  476. XTP_SAFE_CALL5(GetViewDay()->GetView(), GetTheme(), GetDayViewPart(), GetDayPart(),
  477.    GetGroupPart(), OnMouseMove(this, nFlags, point));
  478. TBase::OnMouseMove(nFlags, point);
  479. }
  480. void CXTPCalendarDayViewGroup::AdjustDayEvents(CDC* pDC)
  481. {
  482. ASSERT(pDC);
  483. int nViewEventsCount = GetViewEventsCount();
  484. if (!nViewEventsCount || !pDC)
  485. {
  486. return;
  487. }
  488. TViewEventsCollection arCellEViews;
  489. BOOL bRegion = FALSE;
  490. int nRegionMaxSize = 0;
  491. COleDateTime dtMinRegionTime;
  492. COleDateTime dtMaxRegionTime;
  493. int nCount = GetRowCount();
  494. for (int i = 0; i < nCount; i++)
  495. {
  496. COleDateTime dtMinEventTime, dtMaxEventTime;
  497. GetCellEvents(i, &arCellEViews, dtMinEventTime, dtMaxEventTime);
  498. int nEventsCount = arCellEViews.GetCount();
  499. BOOL bRegionEnded = FALSE;
  500. if (i == 0 || dtMinEventTime > dtMaxRegionTime ||
  501. CXTPCalendarUtils::IsEqual(dtMinEventTime, dtMaxRegionTime) )
  502. {
  503. bRegionEnded = bRegion;
  504. // save times for new region
  505. dtMinRegionTime = dtMinEventTime;
  506. dtMaxRegionTime = dtMaxEventTime;
  507. }
  508. else if (nEventsCount)
  509. {
  510. // continue region
  511. dtMinRegionTime = min(dtMinEventTime, dtMinRegionTime);
  512. dtMaxRegionTime = max(dtMaxEventTime, dtMaxRegionTime);
  513. }
  514. if (nEventsCount && !bRegion)
  515. { //Region startted
  516. bRegion = TRUE;
  517. nRegionMaxSize = 0;
  518. }
  519. else if (bRegion && (nEventsCount == 0 || bRegionEnded))
  520. { //Region ended
  521. _OnRegionEnded(pDC, nRegionMaxSize);
  522. bRegion = nEventsCount > 0;
  523. nRegionMaxSize = 0;
  524. }
  525. ASSERT(nEventsCount && bRegion || !bRegion && (!nEventsCount || bRegionEnded) );
  526. nRegionMaxSize = max(nRegionMaxSize, nEventsCount);
  527. CMap<int, int, BOOL, BOOL> mapBusuRegionPlaces;
  528. int nPlace = 0;
  529. //--make busu event places set ----------------------------------
  530. int nE;
  531. for (nE = 0; nE < nEventsCount; nE++)
  532. {
  533. CXTPCalendarDayViewEvent* pViewEvent = arCellEViews.GetAt(nE, FALSE);
  534. if (!pViewEvent)
  535. {
  536. ASSERT(FALSE);
  537. continue;
  538. }
  539. _AddInRegion_IfNeed(pViewEvent);
  540. int nEventPlace = pViewEvent->GetEventPlacePos();
  541. if (nEventPlace != XTP_EVENT_PLACE_POS_UNDEFINED)
  542. {
  543. mapBusuRegionPlaces.SetAt(nEventPlace, TRUE);
  544. nRegionMaxSize = max(nRegionMaxSize, nEventPlace + 1);
  545. }
  546. }
  547. //- assine places to new events for region ------------------------
  548. for (nE = 0; nE < nEventsCount; nE++)
  549. {
  550. CXTPCalendarDayViewEvent* pViewEvent = arCellEViews.GetAt(nE, FALSE);
  551. if (!pViewEvent)
  552. {
  553. ASSERT(FALSE);
  554. continue;
  555. }
  556. int nEventPlace = pViewEvent->GetEventPlacePos();
  557. if (nEventPlace == XTP_EVENT_PLACE_POS_UNDEFINED)
  558. {
  559. BOOL b;
  560. while (mapBusuRegionPlaces.Lookup(nPlace, b))
  561. {
  562. nPlace++;
  563. }
  564. pViewEvent->SetEventPlacePos(nPlace);
  565. if (nPlace >= pViewEvent->GetEventPlaceCount())
  566. {
  567. pViewEvent->SetEventPlaceCount(nPlace + 1);
  568. }
  569. mapBusuRegionPlaces.SetAt(nPlace, TRUE);
  570. nPlace++;
  571. nRegionMaxSize = max(nRegionMaxSize, nPlace);
  572. }
  573. }
  574. }
  575. if (bRegion)
  576. {
  577. _OnRegionEnded(pDC, nRegionMaxSize);
  578. }
  579. }
  580. void CXTPCalendarDayViewGroup::GetCellEvents(int nCell,
  581.  CXTPCalendarDayViewGroup::TBase::TViewEventsCollection* pViewEvents,
  582.  COleDateTime& rdtMinEventTime, COleDateTime& rdtMaxEventTime)
  583. {
  584. if (!pViewEvents || !GetViewDay() || !GetViewDay()->GetView())
  585. {
  586. ASSERT(FALSE);
  587. return;
  588. }
  589. pViewEvents->RemoveAll();
  590. COleDateTime dtCellBegin = GetViewDay()->GetView()->GetCellTime(nCell);
  591. dtCellBegin = CXTPCalendarUtils::UpdateTime(GetViewDay()->GetDayDate(), dtCellBegin);
  592. COleDateTime dtCellEnd = GetViewDay()->GetView()->GetCellTime(nCell);
  593. dtCellEnd += GetViewDay()->GetView()->GetCellDuration();
  594. dtCellEnd -= XTP_HALF_SECOND * 2;
  595. dtCellEnd = CXTPCalendarUtils::UpdateTime(GetViewDay()->GetDayDate(), dtCellEnd);
  596. rdtMinEventTime = dtCellBegin;
  597. rdtMaxEventTime = dtCellEnd;
  598. int nEventsCount = GetViewEventsCount();
  599. for (int i = 0; i < nEventsCount; i++)
  600. {
  601. CXTPCalendarDayViewEvent* pViewEvent = GetViewEvent(i);
  602. if (!pViewEvent || !pViewEvent->GetEvent())
  603. {
  604. ASSERT(FALSE);
  605. continue;
  606. }
  607. if (pViewEvent->IsMultidayEvent())
  608. {
  609. continue;
  610. }
  611. COleDateTime dtS = pViewEvent->GetEvent()->GetStartTime();
  612. COleDateTime dtE = pViewEvent->GetEvent()->GetEndTime();
  613. if (!(dtE < dtCellBegin || dtS > dtCellEnd ||
  614. CXTPCalendarUtils::IsEqual(dtE, dtCellBegin) ||
  615. CXTPCalendarUtils::IsEqual(dtS, dtCellEnd)
  616. ) ||
  617. CXTPCalendarUtils::IsEqual(dtS, dtE) &&
  618. ( CXTPCalendarUtils::IsEqual(dtS, dtCellBegin) ||
  619. CXTPCalendarUtils::IsEqual(dtE, dtCellEnd)
  620. )
  621. )
  622. {
  623. pViewEvents->Add(pViewEvent, TRUE);
  624. if (dtS < rdtMinEventTime)
  625. {
  626. rdtMinEventTime = dtS;
  627. }
  628. if (dtE > rdtMaxEventTime)
  629. {
  630. rdtMaxEventTime = dtE;
  631. }
  632. }
  633. }
  634. }
  635. void CXTPCalendarDayViewGroup::_AddInRegion_IfNeed(CXTPCalendarDayViewEvent* pViewEvent)
  636. {
  637. if (!pViewEvent)
  638. {
  639. ASSERT(FALSE);
  640. return;
  641. }
  642. int nRCount = m_arRegionViewEvents.GetCount();
  643. for (int j = 0; j < nRCount; j++)
  644. {
  645. CXTPCalendarDayViewEvent* pEV = m_arRegionViewEvents.GetAt(j);
  646. if (pViewEvent == pEV)
  647. {
  648. return;
  649. }
  650. }
  651. m_arRegionViewEvents.Add(pViewEvent, TRUE);
  652. pViewEvent->SetEventPlacePos(XTP_EVENT_PLACE_POS_UNDEFINED);
  653. pViewEvent->SetEventPlaceCount(0);
  654. }
  655. void CXTPCalendarDayViewGroup::_OnRegionEnded(CDC* pDC, int nRegionMaxSize)
  656. {
  657. ASSERT(pDC);
  658. int nRCount = m_arRegionViewEvents.GetCount();
  659. for (int j = 0; j < nRCount; j++)
  660. {
  661. CXTPCalendarDayViewEvent* pViewEvent = m_arRegionViewEvents.GetAt(j, FALSE);
  662. if (!pViewEvent)
  663. {
  664. ASSERT(FALSE);
  665. continue;
  666. }
  667. ASSERT(pViewEvent->GetEventPlaceCount() <= nRegionMaxSize);
  668. if (nRegionMaxSize > pViewEvent->GetEventPlaceCount())
  669. {
  670. pViewEvent->SetEventPlaceCount(nRegionMaxSize);
  671. }
  672. int nPlaceNumber = pViewEvent->GetEventPlaceNumber();
  673. pViewEvent->AdjustLayout(pDC, m_LayoutX.m_rcDayDetails, nPlaceNumber);
  674. }
  675. m_arRegionViewEvents.RemoveAll();
  676. }
  677. COleDateTime CXTPCalendarDayViewGroup::GetCellDateTime(int nCell) const
  678. {
  679. if (!GetViewDay() || !GetViewDay()->GetView())
  680. {
  681. return COleDateTime((DATE)0);
  682. }
  683. return CXTPCalendarUtils::UpdateTime(GetViewDay()->GetDayDate(), GetViewDay()->GetView()->GetCellTime(nCell));
  684. }
  685. int CXTPCalendarDayViewGroup::GetDateTimeCell(const COleDateTime& dtTime, BOOL bForEndTime) const
  686. {
  687. if (!GetViewDay() || !GetViewDay()->GetView())
  688. {
  689. return 0;
  690. }
  691. COleDateTime dtTimeOnly = CXTPCalendarUtils::ResetDate(dtTime);
  692. return GetViewDay()->GetView()->GetCellNumber(dtTimeOnly, bForEndTime);
  693. }
  694. BOOL CXTPCalendarDayViewGroup::IsWorkDateTime(const COleDateTime& dtDateTime)
  695. {
  696. if (!XTP_SAFE_GET1(GetViewDay(), GetCalendarControl(), NULL))
  697. {
  698. return FALSE;
  699. }
  700. COleDateTime dtStartW;
  701. COleDateTime dtEndW;
  702. GetViewDay()->GetCalendarControl()->GetWorkDayStartTime(dtStartW);
  703. dtStartW = (double)dtStartW - XTP_HALF_SECOND;
  704. GetViewDay()->GetCalendarControl()->GetWorkDayEndTime(dtEndW);
  705. dtEndW -= COleDateTimeSpan(0, 0, 0, 1);
  706. int nWWMask = GetViewDay()->GetCalendarControl()->GetWorkWeekMask();
  707. int nDayOfWeek = dtDateTime.GetDayOfWeek();
  708. int nDayMask = CXTPCalendarUtils::GetDayOfWeekMask(nDayOfWeek);
  709. COleDateTime dtTime = CXTPCalendarUtils::ResetDate(dtDateTime);
  710. return (nWWMask & nDayMask) && dtTime >= dtStartW && dtTime <= dtEndW;
  711. }
  712. CRect CXTPCalendarDayViewGroup::GetCellRect(int nCell) const
  713. {
  714. nCell -= GetTopRow();
  715. int nRowHeight = GetRowHeight();
  716. return CRect(m_Layout.m_rcGroup.left, m_LayoutX.m_rcDayDetails.top + nRowHeight * nCell, m_Layout.m_rcGroup.right, m_LayoutX.m_rcDayDetails.top + nRowHeight * (nCell + 1));
  717. }
  718. CXTPCalendarViewPart* CXTPCalendarDayViewGroup::GetCellViewPart(const COleDateTime& dtDateTime)
  719. {
  720. if (IsWorkDateTime(dtDateTime))
  721. {
  722. return (CXTPCalendarViewPart*)XTP_SAFE_GET3(GetViewDay(), GetView(),
  723. GetPaintManager(), GetDayViewWorkCellPart(), NULL);
  724. }
  725. return (CXTPCalendarViewPart*)XTP_SAFE_GET3(GetViewDay(), GetView(),
  726. GetPaintManager(), GetDayViewNonworkCellPart(), NULL);
  727. }
  728. int CXTPCalendarDayViewGroup::GetRowHeight() const
  729. {
  730. return XTP_SAFE_GET2(GetViewDay(), GetView(), GetRowHeight(), 1);
  731. }
  732. int CXTPCalendarDayViewGroup::GetRowCount() const
  733. {
  734. return XTP_SAFE_GET2(GetViewDay(), GetView(), m_LayoutX.m_nRowCount, 1);
  735. }
  736. int CXTPCalendarDayViewGroup::GetVisibleRowCount() const
  737. {
  738. return XTP_SAFE_GET2(GetViewDay(), GetView(), m_LayoutX.m_nVisibleRowCount, 1);
  739. }
  740. int CXTPCalendarDayViewGroup::GetTopRow() const
  741. {
  742. return XTP_SAFE_GET2(GetViewDay(), GetView(), m_LayoutX.m_nTopRow, 0);
  743. }
  744. int CXTPCalendarDayViewGroup::GetBusyStatus(COleDateTime dtTime)
  745. {
  746. int nRes = xtpCalendarBusyStatusUnknown;
  747. int nCount = GetViewEventsCount();
  748. for (int i = 0; i < nCount; i++)
  749. {
  750. CXTPCalendarEvent* pEvent = XTP_SAFE_GET1(GetViewEvent(i), GetEvent(), NULL);
  751. if (XTP_SAFE_GET1(GetViewEvent(i), IsMultidayEvent(), FALSE) && pEvent)
  752. {
  753. if (pEvent->IsAllDayEvent() ||
  754. (dtTime >= pEvent->GetStartTime() && dtTime <= pEvent->GetEndTime()))
  755. {
  756. int nEBs = pEvent->GetBusyStatus();
  757. nRes = max(nRes, nEBs);
  758. }
  759. }
  760. }
  761. return nRes;
  762. }
  763. void CXTPCalendarDayViewGroup::FindMinMaxGroupDayEvents(CXTPCalendarDayViewEvent*& rpMin, CXTPCalendarDayViewEvent*& rpMax)
  764. {
  765. rpMin = rpMax = NULL;
  766. COleDateTime dtMin = xtpCalendarDateTime_max;
  767. COleDateTime dtMax = xtpCalendarDateTime_min;
  768. int nCount = GetViewEventsCount();
  769. for (int i = 0; i < nCount; i++)
  770. {
  771. CXTPCalendarDayViewEvent* pEv = GetViewEvent(i);
  772. if (!pEv || !pEv->GetEvent() || pEv->IsMultidayEvent())
  773. continue;
  774. if (pEv->GetEvent()->GetStartTime() < dtMin)
  775. {
  776. dtMin = pEv->GetEvent()->GetStartTime();
  777. rpMin = pEv;
  778. }
  779. if (pEv->GetEvent()->GetStartTime() > dtMax)
  780. {
  781. dtMax = pEv->GetEvent()->GetStartTime();
  782. rpMax = pEv;
  783. }
  784. }
  785. }
  786. BOOL CXTPCalendarDayViewGroup::UserAction_OnScrollDay(XTPCalendarScrollDayButton eButton)
  787. {
  788. XTP_CALENDAR_USERACTION_PARAMS uaParams;
  789. ::ZeroMemory(&uaParams, sizeof(uaParams));
  790. uaParams.m_eAction = xtpCalendarUserAction_OnScrollDay;
  791. uaParams.m_ScrollDayButton.nButton = eButton;
  792. uaParams.m_ScrollDayButton.pViewGroup = this;
  793. BOOL bCancel = FALSE;
  794. XTP_SAFE_CALL2(GetViewDay(), GetCalendarControl(), SendNotification(
  795. XTP_NC_CALENDAR_USERACTION, (WPARAM)&uaParams, (LPARAM)&bCancel));
  796. return bCancel;
  797. }
  798. CRect CXTPCalendarDayViewGroup::GetTooltipRect(const CPoint& ptHit, const XTP_CALENDAR_HITTESTINFO& hitInfo)
  799. {
  800. UNREFERENCED_PARAMETER(ptHit);
  801. int nCell = GetDateTimeCell(hitInfo.dt, FALSE);
  802. CRect rcTip = GetCellRect(nCell);
  803. return rcTip;
  804. }