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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarWeekViewEvent.cpp: implementation of the CXTPCalendarWeekViewEvent 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 "XTPCalendarWeekViewDay.h"
  22. #include "XTPCalendarWeekViewEvent.h"
  23. #include "XTPCalendarWeekView.h"
  24. #include "XTPCalendarPaintManager.h"
  25. #include "XTPCalendarControl.h"
  26. #include "XTPCalendarData.h"
  27. #include "XTPCalendarTheme.h"
  28. //////////////////////////////////////////////////////////////////////
  29. // Construction/Destruction
  30. //////////////////////////////////////////////////////////////////////
  31. IMPLEMENT_DYNAMIC(CXTPCalendarWeekViewEvent, CXTPCalendarViewEvent)
  32. CXTPCalendarWeekViewEvent::CXTPCalendarWeekViewEvent(CXTPCalendarEvent* pEvent,
  33.  CXTPCalendarWeekViewGroup* pViewGroup)
  34. : TBase(pEvent, pViewGroup)
  35. {
  36. }
  37. CXTPCalendarWeekViewEvent::~CXTPCalendarWeekViewEvent()
  38. {
  39. }
  40. int CXTPCalendarWeekViewEvent::CalcIconsRect(CRect rc)
  41. {
  42. rc.top -= 2;
  43. rc.bottom -= 2;
  44. return TBase::CalcIconsRect(rc);
  45. }
  46. void CXTPCalendarWeekViewEvent::AdjustLayout(CDC* pDC, const CRect& rcEventMax, int nEventPlaceNumber)
  47. {
  48. CXTPCalendarEvent* pEvent = GetEvent();
  49. if (!pEvent || !pDC)
  50. {
  51. ASSERT(FALSE);
  52. return;
  53. }
  54. TBase::AdjustLayout(pDC, rcEventMax, nEventPlaceNumber);
  55. //---------------------------------------------------
  56. CString strLoc = GetItemTextLocation();
  57. CString strEventText = GetItemTextSubject();
  58. if (strLoc.GetLength() > 0)
  59. {
  60. strEventText += _T(" (") + strLoc + _T(")");
  61. }
  62. m_szText = XTP_SAFE_GET5(GetViewGroup(), GetViewDay(), GetView(), GetPaintManager(),
  63. GetDayViewEventPart(), GetTextExtent(pDC, strEventText), CSize(0));
  64. //---------------------------------------------------
  65. if (!IsMultidayEvent())
  66. {
  67. m_nMultiDayEventFlags = xtpCalendarMultiDayNoMultiDay;
  68. int nEventHeight = XTP_SAFE_GET3(GetViewGroup(), GetViewDay(), GetView(), GetRowHeight(), 0);
  69. m_rcEventMax.top = rcEventMax.top + nEventHeight * nEventPlaceNumber + 1;
  70. m_rcEventMax.bottom = m_rcEventMax.top + nEventHeight - 2;
  71. m_rcEventMax.left += 1;
  72. m_rcEvent.top = m_rcEventMax.top;
  73. m_rcEvent.bottom = m_rcEventMax.bottom;
  74. m_rcEvent.DeflateRect(4, 0, 4, 0);
  75. m_rcText.CopyRect(m_rcEvent);
  76. int nTimeCellWidth = 0;
  77. if (IsTimeAsClock())
  78. {
  79. nTimeCellWidth = 2 + XTP_SAFE_GET4(GetViewGroup(), GetViewDay(), GetView(), GetPaintManager(), GetClockSize().cx, 0);
  80. }
  81. else
  82. {
  83. CString strTime = XTP_SAFE_GET3(GetViewGroup(), GetViewDay(), GetView(), GetItemTextEventTimeMax(), _T(""));
  84. nTimeCellWidth = 2 + XTP_SAFE_GET5(GetViewGroup(), GetViewDay(), GetView(), GetPaintManager(), GetWeekViewEventPart(), GetTextExtent(pDC, strTime).cx, 0);
  85. }
  86. DWORD dwOpt = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), dwAdditionalOptions, 0);
  87. int nText = nTimeCellWidth + CalcIconsRect(m_rcText) + 5;
  88. if (m_rcText.Width() - nText > 1 ||
  89. (dwOpt & (xtpCalendarOptWeekViewShowStartTimeAlways | xtpCalendarOptWeekViewShowEndTimeAlways)))
  90. {
  91. m_rcStartTime.CopyRect(m_rcEvent);
  92. m_rcStartTime.right = min(m_rcStartTime.left + nTimeCellWidth, m_rcEvent.right);
  93. m_rcText.left = m_rcStartTime.right;
  94. if (IsShowEndTime() &&
  95. (m_rcText.Width() - nText > 1 || (dwOpt & xtpCalendarOptWeekViewShowEndTimeAlways)))
  96. {
  97. m_rcEndTime.CopyRect(m_rcStartTime);
  98. m_rcEndTime.OffsetRect(m_rcStartTime.Width() + 1, 0);
  99. m_rcEndTime.right = min(m_rcEndTime.right, m_rcEvent.right);
  100. m_rcText.left = m_rcEndTime.right;
  101. }
  102. m_rcText.left = min(m_rcText.left + 5, m_rcText.right);
  103. }
  104. CRect rcIcon(m_rcText);
  105. rcIcon.OffsetRect(0, (m_rcText.Height() - 11)/2 - 1);
  106. m_rcText.left = min(m_rcText.left + CalcIconsRect(rcIcon) + 3 , m_rcEvent.right);
  107. m_rcSubjectEditor.CopyRect(m_rcText);
  108. m_rcSubjectEditor.left = max(m_rcStartTime.right, m_rcEndTime.right);
  109. m_rcSubjectEditor.right = m_rcEventMax.right;
  110. m_rcSubjectEditor.top++;
  111. m_rcSubjectEditor.bottom--;
  112. }
  113. else
  114. {
  115. //calc icons rect
  116. AdjustMultidayEvent(rcEventMax, nEventPlaceNumber);
  117. if (!pEvent->IsAllDayEvent() &&
  118. m_nMultiDayEventFlags & xtpCalendarMultiDayLast
  119.   )
  120. {
  121. COleDateTimeSpan spDay(1, 0, 0, 0);
  122. COleDateTime dtDay = XTP_SAFE_GET2(GetViewGroup_(), GetViewDay_(), GetDayDate(), (DATE)0);
  123. if (dtDay != m_ptrEvent->GetEndTime() - spDay)
  124. {
  125. CSize szClock = XTP_SAFE_GET4(GetViewGroup(), GetViewDay(), GetView(), GetPaintManager(), GetClockSize(), CSize(0));
  126. m_rcLastClock.CopyRect(m_rcEvent);
  127. m_rcLastClock.top -= 1;
  128. m_rcLastClock.bottom -= 1;
  129. m_rcLastClock.right += 1;
  130. m_rcLastClock.left = m_rcLastClock.right - szClock.cx;
  131. m_rcText.right = m_rcLastClock.left;
  132. }
  133. }
  134. }
  135. }
  136. void CXTPCalendarWeekViewEvent::AdjustLayout2(CDC* pDC, const CRect& rcEventMax, int nEventPlaceNumber)
  137. {
  138. TBase::AdjustLayout(pDC, rcEventMax, nEventPlaceNumber);
  139. m_nMultiDayEventFlags = 0;
  140. CXTPCalendarEvent* pEvent = GetEvent();
  141. if (!pEvent  || !pDC ||
  142. !XTP_SAFE_GET2(GetViewGroup(), GetViewDay(), GetView(), NULL) ||
  143. !XTP_SAFE_GET3(GetViewGroup(), GetViewDay(), GetView(), GetTheme(), NULL) )
  144. {
  145. ASSERT(FALSE);
  146. return;
  147. }
  148. CXTPCalendarTheme* pTheme = GetViewGroup()->GetViewDay()->GetView()->GetTheme();
  149. // all-day event
  150. if (IsMultidayEvent())
  151. {
  152. // to calculate multiday-flags
  153. AdjustMultidayEvent(rcEventMax, nEventPlaceNumber);
  154. pTheme->GetWeekViewPart()->GetDayPart()->GetMultiDayEventPart()->AdjustLayout(this, pDC, rcEventMax, nEventPlaceNumber);
  155. return;
  156. }
  157. m_nMultiDayEventFlags = xtpCalendarMultiDayNoMultiDay;
  158. pTheme->GetWeekViewPart()->GetDayPart()->GetSingleDayEventPart()->AdjustLayout(this, pDC, rcEventMax, nEventPlaceNumber);
  159. }
  160. void CXTPCalendarWeekViewEvent::Draw(CDC* pDC)
  161. {
  162. XTP_SAFE_CALL5(GetViewGroup(), GetViewDay(), GetView(), GetPaintManager(), GetWeekViewEventPart(),
  163. OnDraw(pDC, this) );
  164. }
  165. BOOL CXTPCalendarWeekViewEvent::HitTestEx(CPoint point, XTP_CALENDAR_HITTESTINFO_WEEK_VIEW* pInfo)
  166. {
  167. if (!m_rcEventMax.PtInRect(point) || !IsVisible())
  168. {
  169. return FALSE;
  170. }
  171. if (!pInfo || !GetViewGroup() || !GetViewGroup()->GetViewDay() || !GetEvent())
  172. {
  173. ASSERT(FALSE);
  174. return FALSE;
  175. }
  176. pInfo->dt = GetViewGroup()->GetViewDay()->GetDayDate();
  177. pInfo->pViewDay = GetViewGroup()->GetViewDay();
  178. pInfo->pViewGroup = GetViewGroup();
  179. pInfo->pViewEvent = this;
  180. BOOL bAllDay = GetEvent()->IsAllDayEvent();
  181. BOOL bNoMDay = (m_nMultiDayEventFlags & xtpCalendarMultiDayFMLmask) == 0;
  182. if (IsVisible() && bNoMDay && !bAllDay)
  183. pInfo->uHitCode = xtpCalendarHitTestEventDragArea;
  184. else
  185. pInfo->uHitCode = xtpCalendarHitTestUnknown;
  186. BOOL bIsResizable = m_nMultiDayEventFlags & xtpCalendarMultiDayFirst ||
  187. m_nMultiDayEventFlags & xtpCalendarMultiDayLast;
  188. CRect rcBegin = m_rcEventMax;
  189. rcBegin.right = min(m_rcEvent.left + 5, m_rcEvent.right);
  190. if ((!bIsResizable || (m_nMultiDayEventFlags & xtpCalendarMultiDayLast)) && !bAllDay)
  191. {
  192. rcBegin = m_rcEvent;
  193. rcBegin.right = rcBegin.left;
  194. }
  195. CRect rcEnd = m_rcEventMax;
  196. rcEnd.left = max(m_rcEvent.right - 5, m_rcEvent.left);
  197. if ((!bIsResizable || (m_nMultiDayEventFlags & xtpCalendarMultiDayFirst)) && !bAllDay)
  198. {
  199. rcEnd = m_rcEvent;
  200. rcEnd.left = rcEnd.right;
  201. }
  202. if (bIsResizable && rcBegin.PtInRect(point) && IsVisible())
  203. {
  204. pInfo->uHitCode = xtpCalendarHitTestEventResizeHArea | xtpCalendarHitTestEventResizeBegin;
  205. return TRUE;
  206. }
  207. if (bIsResizable && rcEnd.PtInRect(point) && IsVisible())
  208. {
  209. pInfo->uHitCode = xtpCalendarHitTestEventResizeHArea | xtpCalendarHitTestEventResizeEnd;
  210. return TRUE;
  211. }
  212. CRect rcText(m_rcEvent);
  213. if (bNoMDay && !bAllDay)
  214. {
  215. rcText.left = rcText.left + GetStartTimeRect().Width() + GetEndTimeRect().Width();
  216. rcText.left += 5;
  217. rcText.right = rcEnd.left;
  218. }
  219. if (rcText.PtInRect(point))
  220. {
  221. pInfo->uHitCode = xtpCalendarHitTestEventTextArea;
  222. //*pInfo = tmpInfo;
  223. return TRUE;
  224. }
  225. return TRUE;
  226. }
  227. BOOL CXTPCalendarWeekViewEvent::IsVisible()
  228. {
  229. ASSERT(XTP_SAFE_GET1(GetViewGroup(), GetViewDay(), NULL));
  230. if (!XTP_SAFE_GET1(GetViewGroup(), GetViewDay(), NULL))
  231. {
  232. return FALSE;
  233. }
  234. CRect rcDayEvents = GetViewGroup()->GetViewDay()->GetDayEventsRect();
  235. BOOL bVisible = m_rcEvent.bottom <= rcDayEvents.bottom;
  236. return bVisible;
  237. }
  238. BOOL CXTPCalendarWeekViewEvent::IsShowEndTime()
  239. {
  240. return XTP_SAFE_GET1(GetCalendarControl(), WeekView_IsShowEndDate(), FALSE);
  241. }
  242. BOOL CXTPCalendarWeekViewEvent::IsTimeAsClock()
  243. {
  244. return XTP_SAFE_GET1(GetCalendarControl(), WeekView_IsShowTimeAsClocks(), FALSE);
  245. }
  246. CFont* CXTPCalendarWeekViewEvent::GetSubjectEditorFont()
  247. {
  248. CFont* pFont = &XTP_SAFE_GET5(GetViewGroup(), GetViewDay(), GetView(), GetPaintManager(), GetWeekViewEventPart(), GetTextFont(), *((CFont*)(NULL)));
  249. ASSERT(pFont);
  250. return pFont;
  251. }
  252. void CXTPCalendarWeekViewEvent::OnPostAdjustLayout()
  253. {
  254. TBase::OnPostAdjustLayout();
  255. BOOL bIsAllDayEvent = XTP_SAFE_GET1(GetEvent(), IsAllDayEvent(), FALSE);
  256. BOOL bAMDay = m_nMultiDayEventFlags & xtpCalendarMultiDayFirst ||
  257.   m_nMultiDayEventFlags & xtpCalendarMultiDayMiddle ||
  258.   m_nMultiDayEventFlags & xtpCalendarMultiDayLast ||
  259.   bIsAllDayEvent;
  260. if (bAMDay)
  261. {
  262. m_rcSubjectEditor.left = m_rcEvent.left;
  263. m_rcSubjectEditor.right = m_rcEvent.right;
  264. if (m_nMultiDayEventFlags & xtpCalendarMultiDayFirst ||
  265. bIsAllDayEvent)
  266. {
  267. m_rcSubjectEditor.left += 1;
  268. }
  269. m_rcReminderGlyph.OffsetRect(0, (m_rcText.Height() - 11)/2 - 1);
  270. m_rcRecurrenceGlyph.OffsetRect(0, (m_rcText.Height() - 11)/2 - 1);
  271. m_rcMeetingGlyph.OffsetRect(0, (m_rcText.Height() - 11)/2 - 1);
  272. m_rcPrivateGlyph.OffsetRect(0, (m_rcText.Height() - 11)/2 - 1);
  273. }
  274. BOOL bOutOfBorders = m_rcText.Width() < m_szText.cx;
  275. SetTextOutOfBorders(bOutOfBorders);
  276. }