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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarViewDay.cpp: implementation of the CXTPCalendarViewDay 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 "XTPCalendarViewDay.h"
  22. #include "XTPCalendarViewEvent.h"
  23. #include "XTPCalendarControl.h"
  24. #include "XTPCalendarData.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #define new DEBUG_NEW
  29. #endif
  30. IMPLEMENT_DYNAMIC(CXTPCalendarViewGroup, CXTPCalendarWMHandler)
  31. IMPLEMENT_DYNAMIC(CXTPCalendarViewDay, CXTPCalendarWMHandler)
  32. //////////////////////////////////////////////////////////////////////////
  33. CXTPCalendarViewGroup::CXTPCalendarViewGroup()
  34. {
  35. m_pResources = new CXTPCalendarResources();
  36. m_Layout.m_rcGroup.SetRectEmpty();
  37. m_Layout.m_rcGroupHeader.SetRectEmpty();
  38. }
  39. CXTPCalendarViewGroup::~CXTPCalendarViewGroup()
  40. {
  41. CMDTARGET_RELEASE(m_pResources);
  42. }
  43. void CXTPCalendarViewGroup::AddResource(CXTPCalendarResource* pResource, BOOL bWithAddRef)
  44. {
  45. ASSERT(pResource);
  46. if (m_pResources && pResource)
  47. {
  48. m_pResources->Add(pResource, bWithAddRef);
  49. }
  50. }
  51. void CXTPCalendarViewGroup::SetResources(CXTPCalendarResources* pResources)
  52. {
  53. if (!m_pResources)
  54. {
  55. return;
  56. }
  57. m_pResources->RemoveAll();
  58. ASSERT(pResources);
  59. if (pResources)
  60. {
  61. m_pResources->Append(pResources);
  62. }
  63. }
  64. CXTPCalendarData* CXTPCalendarViewGroup::GetDataProvider()
  65. {
  66. if (m_pResources && m_pResources->GetCount() && m_pResources->GetAt(0))
  67. {
  68. return m_pResources->GetAt(0)->GetDataProvider();
  69. }
  70. return NULL;
  71. }
  72. UINT CXTPCalendarViewGroup::GetScheduleID()
  73. {
  74. UINT uScheduleID = XTP_CALENDAR_UNKNOWN_SCHEDULE_ID;
  75. if (XTP_SAFE_GET1(GetResources(), GetCount(), 0) &&
  76. XTP_SAFE_GET3(GetResources(), GetAt(0), GetSchedules(), GetSize(), 0) )
  77. {
  78. uScheduleID = XTP_SAFE_GET3(GetResources(), GetAt(0), GetSchedules(),
  79. GetAt(0), 0);
  80. }
  81. return uScheduleID;
  82. }
  83. int CXTPCalendarViewGroup::GetGroupIndex() const
  84. {
  85. if (!GetViewDay_())
  86. {
  87. return -1;
  88. }
  89. for (int i = 0; i < GetViewDay_()->GetViewGroupsCount(); i++)
  90. {
  91. if (GetViewDay_()->GetViewGroup_(i) == this)
  92. return i;
  93. }
  94. ASSERT(FALSE);
  95. return -1;
  96. }
  97. CString CXTPCalendarViewGroup::GetCaption()
  98. {
  99. if (!m_pResources)
  100. {
  101. return _T("");
  102. }
  103. //BOOL bShowAll = TRUE;
  104. CString strCaption;
  105. int nResCount = m_pResources->GetCount();
  106. for (int i = 0; i < nResCount; i++)
  107. {
  108. if (m_pResources->GetAt(i) /* && m_pResources->GetAt(i)->GetSchedules()*/)
  109. {
  110. if (!strCaption.IsEmpty())
  111. {
  112. strCaption += _T(", ");
  113. }
  114. strCaption += m_pResources->GetAt(i)->GetName();
  115. }
  116. }
  117. WPARAM wParam = (WPARAM)this;
  118. LPARAM lParam = (LPARAM)(CString*)&strCaption;
  119. XTP_SAFE_CALL3(GetViewDay_(), GetView_(), GetCalendarControl(),
  120. SendNotification(XTP_NC_CALENDAR_GETGROPVIEWCAPTION, wParam, lParam));
  121. return strCaption;
  122. }
  123. CRect CXTPCalendarViewGroup::GetTooltipRect(const CPoint& ptHit, const XTP_CALENDAR_HITTESTINFO& hitInfo)
  124. {
  125. UNREFERENCED_PARAMETER(ptHit);
  126. UNREFERENCED_PARAMETER(hitInfo);
  127. CRect rcTip;
  128. rcTip.SetRectEmpty();
  129. return rcTip;
  130. }
  131. void CXTPCalendarViewGroup::AdjustLayout(CDC* pDC, const CRect& rcGroup)
  132. {
  133. m_Layout.m_rcGroup = rcGroup;
  134. int nCount = GetViewEventsCount();
  135. for (int i = 0; i < nCount; i++)
  136. {
  137. CXTPCalendarViewEvent* pViewEvent = GetViewEvent_(i);
  138. ASSERT(pViewEvent);
  139. if (pViewEvent)
  140. {
  141. pViewEvent->AdjustLayout(pDC, rcGroup, i);
  142. }
  143. }
  144. }
  145. void CXTPCalendarViewGroup::AdjustLayout2(CDC* pDC, const CRect& rcGroup)
  146. {
  147. CXTPCalendarTheme* pTheme = XTP_SAFE_GET2(GetViewDay_(), GetView_(), GetTheme(), NULL);
  148. ASSERT(pTheme);
  149. //XTP_SAFE_CALL4(pTheme, Get_mw_ViewPart(), GetDayPart(), GetGroupPart(), AdjustLayout(this, pDC, rcGroup));
  150. m_Layout.m_rcGroup = rcGroup;
  151. int nCount = GetViewEventsCount();
  152. for (int i = 0; i < nCount; i++)
  153. {
  154. CXTPCalendarViewEvent* pVEvent = GetViewEvent_(i);
  155. ASSERT(pVEvent);
  156. if (pVEvent)
  157. {
  158. pVEvent->AdjustLayout2(pDC, rcGroup, i);
  159. }
  160. }
  161. }
  162. void CXTPCalendarViewGroup::Draw(CDC* pDC)
  163. {
  164. int nCount = GetViewEventsCount();
  165. for (int i = 0; i < nCount; i++)
  166. {
  167. CXTPCalendarViewEvent* pViewEvent = GetViewEvent_(i);
  168. ASSERT(pViewEvent);
  169. if (pViewEvent && pViewEvent->IsVisible())
  170. {
  171. pViewEvent->Draw(pDC);
  172. }
  173. }
  174. }
  175. CXTPCalendarWMHandler* CXTPCalendarViewGroup::GetChildHandlerAt(int nIndex)
  176. {
  177. ASSERT_KINDOF(CXTPCalendarWMHandler, GetViewEvent_(nIndex));
  178. return GetViewEvent_(nIndex);
  179. }
  180. UINT CXTPCalendarViewGroup::SetTimer(UINT uTimeOut_ms)
  181. {
  182. return XTP_SAFE_GET1(GetViewDay_(), SetTimer(uTimeOut_ms), 0);
  183. }
  184. void CXTPCalendarViewGroup::KillTimer(UINT uTimerID)
  185. {
  186. XTP_SAFE_CALL1(GetViewDay_(), KillTimer(uTimerID) );
  187. }
  188. void CXTPCalendarViewGroup::OnPrePopulate(CXTPCalendarEvents* pEvents)
  189. {
  190. WPARAM wParam = (WPARAM)(CXTPCalendarViewGroup*)this;
  191. LPARAM lParam = (LPARAM)pEvents;
  192. XTP_SAFE_CALL3(GetViewDay_(), GetView_(), GetCalendarControl(), SendNotification(
  193.    XTP_NC_CALENDAR_PREPOPULATE, wParam, lParam));
  194. }
  195. //////////////////////////////////////////////////////////////////////
  196. // Construction/Destruction
  197. //////////////////////////////////////////////////////////////////////
  198. CXTPCalendarViewDay::CXTPCalendarViewDay(CXTPCalendarView* pView)
  199. {
  200. UNUSED_ALWAYS(pView);
  201. m_dtDate.SetStatus(COleDateTime::null);
  202. m_pResources = NULL;
  203. m_Layout.m_rcExpandSign.SetRectEmpty();
  204. m_Layout.m_nHotState = 0;
  205. m_Layout.m_rcDay.SetRectEmpty();
  206. m_Layout.m_rcDayHeader.SetRectEmpty();
  207. }
  208. CXTPCalendarViewDay::~CXTPCalendarViewDay()
  209. {
  210. }
  211. int CXTPCalendarViewDay::GetViewEventsCount()
  212. {
  213. int nGroups = GetViewGroupsCount();
  214. ASSERT(nGroups <= 1);
  215. if (nGroups == 1 && GetViewGroup_(0))
  216. {
  217. return GetViewGroup_(0)->GetViewEventsCount();
  218. }
  219. return 0;
  220. }
  221. CXTPCalendarViewEvent* CXTPCalendarViewDay::GetViewEvent_(int nIndex)
  222. {
  223. int nGroups = GetViewGroupsCount();
  224. ASSERT(nGroups <= 1);
  225. if (nGroups == 1 && GetViewGroup_(0))
  226. {
  227. return GetViewGroup_(0)->GetViewEvent_(nIndex);
  228. }
  229. return NULL;
  230. }
  231. CXTPCalendarControl* CXTPCalendarViewDay::GetCalendarControl()
  232. {
  233. ASSERT(this);
  234. if (!this)
  235. {
  236. return NULL;
  237. }
  238. return XTP_SAFE_GET1(GetView_(), GetCalendarControl(), NULL);
  239. }
  240. CXTPCalendarResources* CXTPCalendarViewDay::GetResources()
  241. {
  242. ASSERT(this);
  243. if (m_pResources)
  244. {
  245. return m_pResources;
  246. }
  247. return  GetView_() ? GetView_()->GetResources() : NULL;
  248. }
  249. void CXTPCalendarViewDay::SetResources(CXTPCalendarResources* pResources)
  250. {
  251. BOOL bChanged = TRUE;
  252. if (!pResources)
  253. {
  254. bChanged = m_pResources != NULL;
  255. CMDTARGET_RELEASE(m_pResources);
  256. }
  257. else
  258. {
  259. if (!m_pResources)
  260. m_pResources = new CXTPCalendarResources();
  261. if (!m_pResources)
  262. return;
  263. // copy data to allow using self as input parameter
  264. CXTPCalendarResources arRes;
  265. arRes.Append(pResources);
  266. m_pResources->RemoveAll();
  267. m_pResources->Append(&arRes);
  268. }
  269. if (bChanged && GetView_())
  270. {
  271. GetView_()->SendNotification(XTP_NC_CALENDAR_RESOURCES_WHERE_CHANGED, 2, (LPARAM)this);
  272. }
  273. }
  274. void CXTPCalendarViewDay::AdjustLayout(CDC* pDC, const CRect& rcDay)
  275. {
  276. UNREFERENCED_PARAMETER(pDC);
  277. m_Layout.m_rcDay.CopyRect(&rcDay);
  278. m_Layout.m_rcDayHeader.SetRectEmpty();
  279. m_Layout.m_rcExpandSign.SetRect(rcDay.right, rcDay.bottom, rcDay.right, rcDay.bottom);
  280. m_Layout.m_nHotState = 0;
  281. }
  282. //BOOL CXTPCalendarViewDay::OnLButtonDown(UINT nFlags, CPoint point)
  283. //{
  284. //  if (GetView_() && !GetView_()->GetTheme() && m_Layout.m_rcExpandSign.PtInRect(point))
  285. //  {
  286. //      XTP_SAFE_CALL1(GetCalendarControl(), QueueDayViewSwitch(m_dtDate) );
  287. //      return TRUE;
  288. //  }
  289. //
  290. //  return TBase::OnLButtonDown(nFlags, point);
  291. //}
  292. BOOL CXTPCalendarViewDay::UserAction_OnExpandDay(XTPCalendarExpandDayButton eButton)
  293. {
  294. XTP_CALENDAR_USERACTION_PARAMS uaParams;
  295. ::ZeroMemory(&uaParams, sizeof(uaParams));
  296. uaParams.m_eAction = xtpCalendarUserAction_OnExpandDay;
  297. uaParams.m_ExpandDayButton.nButton = eButton;
  298. uaParams.m_ExpandDayButton.pViewDay = this;
  299. BOOL bCancel = FALSE;
  300. if (GetCalendarControl())
  301. GetCalendarControl()->SendNotification(XTP_NC_CALENDAR_USERACTION, (WPARAM)&uaParams,
  302.    (LPARAM)&bCancel);
  303. return bCancel;
  304. }
  305. CXTPCalendarViewEvent* CXTPCalendarViewGroup::GetViewEventByEvent_(CXTPCalendarEvent* pEvent)
  306. {
  307. if (!pEvent)
  308. {
  309. ASSERT(FALSE);
  310. return NULL;
  311. }
  312. int nCount = GetViewEventsCount();
  313. for (int i = 0; i < nCount; i++)
  314. {
  315. CXTPCalendarViewEvent* pView = GetViewEvent_(i);
  316. if (!pView)
  317. {
  318. ASSERT(FALSE);
  319. continue;
  320. }
  321. BOOL bIDsEqual = pEvent->IsEqualIDs(pView->GetEvent());
  322. BOOL bTimesEqual = pEvent->IsEqualStartEnd(pView->GetEvent());
  323. if (bIDsEqual && bTimesEqual)
  324. {
  325. return pView;
  326. }
  327. }
  328. return NULL;
  329. }
  330. CXTPCalendarViewEvent* CXTPCalendarViewGroup::GetViewEventByPlace_(int nEventPlace)
  331. {
  332. int nCount = GetViewEventsCount();
  333. for (int i = 0; i < nCount; i++)
  334. {
  335. CXTPCalendarViewEvent* pView = GetViewEvent_(i);
  336. if (!pView)
  337. {
  338. ASSERT(FALSE);
  339. continue;
  340. }
  341. int nPlace = pView->GetEventPlaceNumber();
  342. if (nPlace == nEventPlace)
  343. {
  344. return pView;
  345. }
  346. }
  347. return NULL;
  348. }
  349. void CXTPCalendarViewGroup::ExchangeEventPlace(CXTPCalendarViewEvent* pViewEvent, int nNewPlace)
  350. {
  351. if (!pViewEvent)
  352. {
  353. ASSERT(FALSE);
  354. return;
  355. }
  356. int nCurentPlace = pViewEvent->GetEventPlaceNumber();
  357. if (nCurentPlace == nNewPlace)
  358. {
  359. return;
  360. }
  361. CXTPCalendarViewEvent* pViewEventNew = GetViewEventByPlace_(nNewPlace);
  362. if (pViewEventNew)
  363. {
  364. pViewEventNew->ChangeEventPlace(nCurentPlace);
  365. }
  366. pViewEvent->ChangeEventPlace(nNewPlace);
  367. }
  368. BOOL CXTPCalendarViewDay::_NoAllEventsAreVisible()
  369. {
  370. //  m_Layout.m_rcExpandSign.SetRect(m_Layout.m_rcDay.right, m_Layout.m_rcDay.bottom, m_Layout.m_rcDay.right, m_Layout.m_rcDay.bottom);
  371. int nGroups = GetViewGroupsCount();
  372. for (int g = 0; g < nGroups; g++)
  373. {
  374. CXTPCalendarViewGroup* pGroup = GetViewGroup_(g);
  375. ASSERT(pGroup);
  376. if (!pGroup)
  377. {
  378. continue;
  379. }
  380. int nCount = pGroup->GetViewEventsCount();
  381. for (int i = 0; i < nCount; i++)
  382. {
  383. CXTPCalendarViewEvent* pView = pGroup->GetViewEvent_(i);
  384. ASSERT(pView);
  385. if (pView && !pView->IsVisible())
  386. {
  387. return TRUE;
  388. }
  389. }
  390. }
  391. return FALSE;
  392. }
  393. UINT CXTPCalendarViewDay::SetTimer(UINT uTimeOut_ms)
  394. {
  395. return XTP_SAFE_GET1(GetView_(), SetTimer(uTimeOut_ms), 0);
  396. }
  397. void CXTPCalendarViewDay::KillTimer(UINT uTimerID)
  398. {
  399. XTP_SAFE_CALL1(GetView_(), KillTimer(uTimerID));
  400. }
  401. BOOL CXTPCalendarViewDay::IsSelected() const
  402. {
  403. return XTP_SAFE_GET1(GetView_(), SelectionContains(GetDayDate()), FALSE);
  404. }
  405. void CXTPCalendarViewDay::SetSelected()
  406. {
  407. XTP_SAFE_CALL1(GetView_(), SetSelection(GetDayDate(), GetDayDate()));
  408. }
  409. int CXTPCalendarViewDay::GetDayIndex() const
  410. {
  411. if (!GetView_())
  412. {
  413. return -1;
  414. }
  415. for (int i = 0; i < GetView_()->GetViewDayCount(); i++)
  416. {
  417. if (GetView_()->GetViewDay_(i) == this)
  418. return i;
  419. }
  420. ASSERT(FALSE);
  421. return -1;
  422. }
  423. void CXTPCalendarViewDay::OnPrePopulateDay()
  424. {
  425. WPARAM wParam = (WPARAM)(CXTPCalendarViewDay*)this;
  426. XTP_SAFE_CALL2(GetView_(), GetCalendarControl(), SendNotification(
  427.    XTP_NC_CALENDAR_PREPOPULATE_DAY, wParam, 0));
  428. }