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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarMonthViewDay.cpp: implementation of the CXTPCalendarMonthViewDay class.
  2. //
  3. // This file is a part of the XTREME CALENDAR MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Resource.h"
  22. #include "XTPCalendarMonthViewDay.h"
  23. #include "XTPCalendarMonthView.h"
  24. #include "XTPCalendarEvent.h"
  25. #include "XTPCalendarTheme.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. IMPLEMENT_DYNAMIC(CXTPCalendarMonthViewDay, CXTPCalendarViewDay)
  32. //////////////////////////////////////////////////////////////////////////
  33. CXTPCalendarMonthViewGroup::CXTPCalendarMonthViewGroup(CXTPCalendarMonthViewDay* pViewDay)
  34. : TBase(pViewDay)
  35. {
  36. }
  37. CXTPCalendarMonthViewGroup::~CXTPCalendarMonthViewGroup()
  38. {
  39. }
  40. void CXTPCalendarMonthViewGroup::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_MONTH_VIEW* pHitTest)
  41. {
  42. ASSERT(pHitTest && GetViewDay());
  43. if (pHitTest && GetViewDay())
  44. {
  45. GetViewDay()->FillHitTestEx(pHitTest);
  46. pHitTest->pViewGroup = this;
  47. }
  48. }
  49. CRect CXTPCalendarMonthViewGroup::GetTooltipRect(const CPoint& ptHit, const XTP_CALENDAR_HITTESTINFO& hitInfo)
  50. {
  51. UNREFERENCED_PARAMETER(ptHit);
  52. UNREFERENCED_PARAMETER(hitInfo);
  53. CRect rcTip(m_Layout.m_rcGroup);
  54. rcTip.DeflateRect(1, 1, 0, 0);
  55. int nColHeaderHeight = XTP_SAFE_GET2(GetViewDay(), GetView(), GetRowHeight(), 0);
  56. rcTip.top = rcTip.bottom - nColHeaderHeight;
  57. return rcTip;
  58. }
  59. //////////////////////////////////////////////////////////////////////////
  60. CXTPCalendarMonthViewDay::CXTPCalendarMonthViewDay(CXTPCalendarMonthView* pMonthView,
  61. int nWeekIndex, int nWeekDayIndex) :
  62. TBase(pMonthView)
  63. {
  64. ASSERT(pMonthView);
  65. m_nWeekIndex = nWeekIndex;
  66. m_nWeekDayIndex = nWeekDayIndex;
  67. }
  68. CXTPCalendarMonthViewDay::~CXTPCalendarMonthViewDay()
  69. {
  70. }
  71. void CXTPCalendarMonthViewDay::AdjustLayout(CDC* pDC, const CRect& rcDay)
  72. {
  73. TBase::AdjustLayout(pDC, rcDay);
  74. m_Layout.m_rcDayHeader.CopyRect(CalcDayDateRect());
  75. CRect rcDayEvents = GetDayEventsRect();
  76. int nGroups = GetViewGroupsCount();
  77. ASSERT(nGroups == 1);
  78. CXTPCalendarViewGroup* pViewGroup = nGroups ? GetViewGroup_(0) : NULL;
  79. ASSERT(pViewGroup);
  80. if (pViewGroup)
  81. {
  82. pViewGroup->AdjustLayout(pDC, rcDayEvents);
  83. }
  84. }
  85. void CXTPCalendarMonthViewDay::AdjustLayout2(CDC* pDC, const CRect& rcDay)
  86. {
  87. TBase::AdjustLayout(pDC, rcDay);
  88. GetView()->GetTheme()->GetMonthViewPart()->GetDayPart()->AdjustLayout(this, pDC, rcDay);
  89. }
  90. void CXTPCalendarMonthViewDay::Draw(CDC* pDC)
  91. {
  92. if (!GetView() || !GetView()->GetPaintManager())
  93. {
  94. ASSERT(FALSE);
  95. return;
  96. }
  97. //-- Draw day date // '25' or  'July 25'
  98. BOOL bLong = (m_nWeekIndex == 0 && m_nWeekDayIndex == 0);
  99. CString strDate = GetView()->_FormatDayDate(m_dtDate, bLong);
  100. COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
  101. BOOL bToday = (DWORD)dtNow == (DWORD)m_dtDate;
  102. //-------------------------------------------------------------
  103. DWORD dwFlags = XTP_SAFE_GET2(GetView(), GetCalendarControl(), GetAskItemTextFlags(), 0);
  104. if (dwFlags & xtpCalendarItemText_MonthViewDayHeader)
  105. {
  106. XTP_CALENDAR_GETITEMTEXT_PARAMS objRequest;
  107. ::ZeroMemory(&objRequest, sizeof(objRequest));
  108. objRequest.nItem = (int)xtpCalendarItemText_MonthViewDayHeader;
  109. objRequest.pstrText = &strDate;
  110. objRequest.pViewDay = this;
  111. XTP_SAFE_CALL2(GetView(), GetCalendarControl(), SendNotificationAlways(
  112. XTP_NC_CALENDAR_GETITEMTEXT, (WPARAM)&objRequest, 0));
  113. }
  114. //-------------------------------------------------------------
  115. XTP_SAFE_CALL3(GetView(), GetPaintManager(), GetMonthViewEventPart(),
  116. OnDrawDayDate(pDC, m_Layout.m_rcDayHeader, bToday, IsSelected(), strDate));
  117. //-- Draw Events (Group) -----------------
  118. int nGroups = GetViewGroupsCount();
  119. ASSERT(nGroups == 1);
  120. CXTPCalendarViewGroup* pViewGroup = nGroups ? GetViewGroup_(0) : NULL;
  121. ASSERT(pViewGroup);
  122. if (pViewGroup)
  123. {
  124. pViewGroup->Draw(pDC);
  125. }
  126. if (NoAllEventsAreVisible())
  127. {
  128. GetView()->GetPaintManager()->DrawBitmap(XTP_IDB_CALENDAR_EXPANDSIGNDOWN, pDC, GetExpandSignRect());
  129. }
  130. }
  131. void CXTPCalendarMonthViewDay::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_MONTH_VIEW* pInfo)
  132. {
  133. ASSERT(pInfo);
  134. if (!pInfo)
  135. {
  136. return;
  137. }
  138. pInfo->dt = m_dtDate;
  139. pInfo->dayPOS.nWeekIndex = m_nWeekIndex;
  140. pInfo->dayPOS.nWeekDayIndex = m_nWeekDayIndex;
  141. pInfo->nDay = m_nWeekIndex * 7 + m_nWeekDayIndex;
  142. pInfo->nEvent = -1;
  143. pInfo->pViewDay = this;
  144. pInfo->pViewEvent = NULL;
  145. pInfo->uHitCode = xtpCalendarHitTestUnknown;
  146. }
  147. BOOL CXTPCalendarMonthViewDay::HitTestEx(CPoint pt, XTP_CALENDAR_HITTESTINFO_MONTH_VIEW* pHitTest)
  148. {
  149. if (!pHitTest) {
  150. ASSERT(FALSE);
  151. return FALSE;
  152. }
  153. if (m_Layout.m_rcExpandSign.PtInRect(pt))
  154. {
  155. if (XTP_SAFE_GET4(GetView(), GetTheme(), GetMonthViewPart(), GetDayPart(),
  156. HitTestExpandDayButton(this, &pt), 0))
  157. {
  158. FillHitTestEx(pHitTest);
  159. pHitTest->uHitCode = xtpCalendarHitTestDayExpandButton;
  160. return TRUE;
  161. }
  162. }
  163. return TBase::HitTestEx(pt, pHitTest);
  164. }
  165. CRect CXTPCalendarMonthViewDay::CalcDayDateRect() const
  166. {
  167. CRect rcDayDate = m_Layout.m_rcDay;
  168. rcDayDate.DeflateRect(1, 1, 0, 0);
  169. int nColHeaderHeight = XTP_SAFE_GET1(GetView(), GetRowHeight(), 0);
  170. rcDayDate.bottom = rcDayDate.top + min(nColHeaderHeight, rcDayDate.Height());
  171. return rcDayDate;
  172. }
  173. CRect CXTPCalendarMonthViewDay::GetDayEventsRect() const
  174. {
  175. int nColHeaderHeight = m_Layout.m_rcDayHeader.Height();
  176. CRect rcDayEvents = m_Layout.m_rcDay;
  177. //  rcDayEvents.bottom -= min(2, rcDayEvents.Height());
  178. rcDayEvents.top += min(nColHeaderHeight, rcDayEvents.Height());
  179. int nBotSpace = XTP_SAFE_GET5(GetView(), GetCalendarControl(), GetTheme(),
  180. GetMonthViewPart(), GetDayPart(), GetExpandButtonHeight(), 0);
  181. rcDayEvents.bottom -= min(nBotSpace + 2, rcDayEvents.Height());
  182. return rcDayEvents;
  183. }
  184. BOOL CXTPCalendarMonthViewDay::OnLButtonDown(UINT nFlags, CPoint point)
  185. {
  186. if (!GetView() || !GetCalendarControl())
  187. {
  188. ASSERT(FALSE);
  189. return FALSE;
  190. }
  191. if (GetView()->GetTheme())
  192. {
  193. if (XTP_SAFE_GET4(GetView(), GetTheme(), GetMonthViewPart(), GetDayPart(),
  194. OnLButtonDown(this, nFlags, point), FALSE))
  195. {
  196. return TRUE;
  197. }
  198. }
  199. else if (m_Layout.m_rcExpandSign.PtInRect(point))
  200. {
  201. if (UserAction_OnExpandDay(xtpCalendarExpandDayButton_MonthView))
  202. return TRUE;
  203. XTP_SAFE_CALL1(GetCalendarControl(), QueueDayViewSwitch(GetDayDate()));
  204. return TRUE;
  205. }
  206. return TBase::OnLButtonDown(nFlags, point);
  207. }
  208. void CXTPCalendarMonthViewDay::OnMouseMove(UINT nFlags, CPoint point)
  209. {
  210. if (GetView() && GetView()->GetTheme() && GetView()->GetTheme()->GetMonthViewPart() &&
  211. GetView()->GetTheme()->GetMonthViewPart()->GetDayPart())
  212. GetView()->GetTheme()->GetMonthViewPart()->GetDayPart()->OnMouseMove(this, nFlags, point);
  213. TBase::OnMouseMove(nFlags, point);
  214. }