XTPCalendarWeekViewDay.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 "XTPCalendarWeekViewDay.h"
  23. #include "XTPCalendarWeekView.h"
  24. #include "XTPCalendarEvent.h"
  25. #include "XTPCalendarPaintManager.h"
  26. #include "XTPCalendarTheme.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. //////////////////////////////////////////////////////////////////////////
  33. CXTPCalendarWeekViewGroup::CXTPCalendarWeekViewGroup(CXTPCalendarWeekViewDay* pViewDay)
  34. : TBase(pViewDay)
  35. {
  36. }
  37. CXTPCalendarWeekViewGroup::~CXTPCalendarWeekViewGroup()
  38. {
  39. }
  40. void CXTPCalendarWeekViewGroup::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_WEEK_VIEW* pHitTest)
  41. {
  42. ASSERT(pHitTest && GetViewDay());
  43. if (pHitTest && GetViewDay())
  44. {
  45. GetViewDay()->FillHitTestEx(pHitTest);
  46. pHitTest->pViewGroup = this;
  47. }
  48. }
  49. //////////////////////////////////////////////////////////////////////////
  50. IMPLEMENT_DYNAMIC(CXTPCalendarWeekViewDay, CXTPCalendarViewDay)
  51. CXTPCalendarWeekViewDay::CXTPCalendarWeekViewDay(CXTPCalendarWeekView* pWeekView)
  52. : TBase(pWeekView)
  53. {}
  54. CXTPCalendarWeekViewDay::~CXTPCalendarWeekViewDay()
  55. {
  56. }
  57. void CXTPCalendarWeekViewDay::FillHitTestEx(XTP_CALENDAR_HITTESTINFO_WEEK_VIEW* pInfo)
  58. {
  59. ASSERT(pInfo);
  60. if (!pInfo)
  61. {
  62. return;
  63. }
  64. pInfo->dt = m_dtDate;
  65. pInfo->pViewDay = GetPThis();
  66. pInfo->uHitCode = xtpCalendarHitTestEvent_Mask;
  67. }
  68. BOOL CXTPCalendarWeekViewDay::HitTestEx(CPoint pt, XTP_CALENDAR_HITTESTINFO_WEEK_VIEW* pHitTest)
  69. {
  70. if (!pHitTest) {
  71. ASSERT(FALSE);
  72. return FALSE;
  73. }
  74. if (m_Layout.m_rcExpandSign.PtInRect(pt))
  75. {
  76. if (XTP_SAFE_GET4(GetView(), GetTheme(), GetWeekViewPart(), GetDayPart(),
  77. HitTestExpandDayButton(this, &pt), 0))
  78. {
  79. FillHitTestEx(pHitTest);
  80. pHitTest->uHitCode = xtpCalendarHitTestDayExpandButton;
  81. return TRUE;
  82. }
  83. }
  84. return TBase::HitTestEx(pt, pHitTest);
  85. }
  86. void CXTPCalendarWeekViewDay::AdjustLayout(CDC* pDC, const CRect& rcDay)
  87. {
  88. if (!GetView() || !pDC)
  89. {
  90. ASSERT(FALSE);
  91. return;
  92. }
  93. int nHeaderHeight = GetView()->GetDayHeaderHeight();
  94. m_Layout.m_rcDay.CopyRect(&rcDay);
  95. m_Layout.m_rcDayHeader.CopyRect(&rcDay);
  96. m_Layout.m_rcDayHeader.bottom = m_Layout.m_rcDayHeader.top + nHeaderHeight;
  97. m_Layout.m_rcDayHeader.DeflateRect(1, 1, 1, 0);
  98. CRect rcDayEvents = rcDay;
  99. rcDayEvents.DeflateRect(1, nHeaderHeight, 1, 1);
  100. //-------------------------------------
  101. int nGroups = GetViewGroupsCount();
  102. ASSERT(nGroups == 1);
  103. CXTPCalendarViewGroup* pViewGroup = nGroups ? GetViewGroup_(0) : NULL;
  104. ASSERT(pViewGroup);
  105. if (pViewGroup)
  106. {
  107. pViewGroup->AdjustLayout(pDC, rcDayEvents);
  108. }
  109. }
  110. void CXTPCalendarWeekViewDay::AdjustLayout2(CDC* pDC, const CRect& rcDay)
  111. {
  112. TBase::AdjustLayout(pDC, rcDay);
  113. XTP_SAFE_CALL4(GetView(), GetTheme(), GetWeekViewPart(), GetDayPart(), AdjustLayout(this, pDC, rcDay));
  114. }
  115. void CXTPCalendarWeekViewDay::Draw(CDC* pDC)
  116. {
  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. XTP_SAFE_CALL2(GetView(), GetPaintManager(),
  129. DrawBitmap(XTP_IDB_CALENDAR_EXPANDSIGNDOWN, pDC, GetExpandSignRect()) );
  130. }
  131. }
  132. CRect CXTPCalendarWeekViewDay::GetDayEventsRect() const
  133. {
  134. int nColHeaderHeight = XTP_SAFE_GET1(GetView(), GetRowHeight(), 0);
  135. CRect rcDayEvents = m_Layout.m_rcDay;
  136. //rcDayEvents.bottom -= min(2, rcDayEvents.Height());
  137. rcDayEvents.top += min(nColHeaderHeight + 0, rcDayEvents.Height());
  138. int nBotSpace = XTP_SAFE_GET5(GetView(), GetCalendarControl(), GetTheme(),
  139. GetWeekViewPart(), GetDayPart(), GetExpandButtonHeight(), 0);
  140. rcDayEvents.bottom -= min(nBotSpace + 2, rcDayEvents.Height());
  141. return rcDayEvents;
  142. }
  143. BOOL CXTPCalendarWeekViewDay::OnLButtonDown(UINT nFlags, CPoint point)
  144. {
  145. if (!GetView() || !GetCalendarControl())
  146. {
  147. ASSERT(FALSE);
  148. return FALSE;
  149. }
  150. if (GetView()->GetTheme())
  151. {
  152. if (XTP_SAFE_GET4(GetView(), GetTheme(), GetWeekViewPart(), GetDayPart(),
  153. OnLButtonDown(this, nFlags, point), FALSE))
  154. {
  155. return TRUE;
  156. }
  157. }
  158. else if (m_Layout.m_rcExpandSign.PtInRect(point))
  159. {
  160. if (UserAction_OnExpandDay(xtpCalendarExpandDayButton_WeekView))
  161. return TRUE;
  162. XTP_SAFE_CALL1(GetCalendarControl(), QueueDayViewSwitch(GetDayDate()));
  163. return TRUE;
  164. }
  165. return TBase::OnLButtonDown(nFlags, point);
  166. }
  167. void CXTPCalendarWeekViewDay::OnMouseMove(UINT nFlags, CPoint point)
  168. {
  169. if (GetView() && GetView()->GetTheme() && GetView()->GetTheme()->GetWeekViewPart() &&
  170. GetView()->GetTheme()->GetWeekViewPart()->GetDayPart())
  171. GetView()->GetTheme()->GetWeekViewPart()->GetDayPart()->OnMouseMove(this, nFlags, point);
  172. TBase::OnMouseMove(nFlags, point);
  173. }
  174. CString CXTPCalendarWeekViewDay::GetCaption()
  175. {
  176. if (!GetView() || !GetCalendarControl())
  177. {
  178. ASSERT(FALSE);
  179. return _T("");
  180. }
  181. CString strHeaderFormat = GetView()->GetDayHeaderFormat();
  182. SYSTEMTIME st;
  183. COleDateTime dtDay = GetDayDate();
  184. GETASSYSTEMTIME_DT(dtDay, st);
  185. CString strDate = CXTPCalendarUtils::GetDateFormat(&st, strHeaderFormat);
  186. //-------------------------------------------------------------
  187. DWORD dwFlags = GetCalendarControl()->GetAskItemTextFlags();
  188. if (dwFlags & xtpCalendarItemText_WeekViewDayHeader)
  189. {
  190. XTP_CALENDAR_GETITEMTEXT_PARAMS objRequest;
  191. ::ZeroMemory(&objRequest, sizeof(objRequest));
  192. objRequest.nItem = (int)xtpCalendarItemText_WeekViewDayHeader;
  193. objRequest.pstrText = &strDate;
  194. objRequest.pViewDay = this;
  195. GetCalendarControl()->SendNotificationAlways(XTP_NC_CALENDAR_GETITEMTEXT,
  196. (WPARAM)&objRequest, 0);
  197. }
  198. //-------------------------------------------------------------
  199. return strDate;
  200. }