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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarView.cpp : implementation file
  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 "Common/XTPPropExchange.h"
  22. #include "Common/XTPVC50Helpers.h"
  23. #include "XTPCalendarView.h"
  24. #include "XTPCalendarViewEvent.h"
  25. #include "XTPCalendarViewDay.h"
  26. #include "XTPCalendarControl.h"
  27. #include "XTPCalendarData.h"
  28. #include "XTPCalendarThemeOffice2007.h"
  29. #include <math.h>
  30. #pragma warning(disable: 4571) // warning C4571: catch(...) blocks compiled with /EHs do not catch or re-throw Structured Exceptions
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. #define XTP_CLIPBOARD_EVENTS_DATA_VER 2
  37. //===========================================================================
  38. IMPLEMENT_DYNAMIC(CXTPCalendarWMHandler, CCmdTarget)
  39. IMPLEMENT_DYNAMIC(CXTPCalendarView, CXTPCalendarWMHandler)
  40. /////////////////////////////////////////////////////////////////////////////
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CXTPCalendarView
  43. CXTPCalendarView::CXTPCalendarView(CXTPCalendarControl* pCalendarControl) :
  44. m_pControl(pCalendarControl)
  45. {
  46. m_rcView.SetRectEmpty();
  47. m_rcTooltip.SetRectEmpty();
  48. m_Layout.m_nRowHeight = 18;
  49. m_eDraggingMode = xtpCalendaDragModeUnknown;
  50. m_ptStartDragging.x = m_ptStartDragging.y = LONG_MAX;
  51. m_bStartedClickInside = FALSE;
  52. m_nTimerID_StartEditSubject = 0;
  53. m_nTimerID_ShowToolTip = 0;
  54. m_eUndoMode = xtpCalendarUndoModeUnknown;
  55. m_bResetUndoBuffer = FALSE;
  56. m_nKeyStateTimerID = 0;
  57. m_pSelectedEvents = new CXTPCalendarViewEvents();
  58. m_pResources = NULL;
  59. _CalculateEventTimeFormat();
  60. m_bScrollV_Disabled = FALSE;
  61. m_bScrollH_Disabled = FALSE;
  62. }
  63. CXTPCalendarView::~CXTPCalendarView()
  64. {
  65. CMDTARGET_RELEASE(m_pSelectedEvents);
  66. CMDTARGET_RELEASE(m_pResources);
  67. ASSERT(m_nTimerID_StartEditSubject == 0);
  68. ASSERT(m_nTimerID_ShowToolTip == 0);
  69. }
  70. void CXTPCalendarView::OnBeforeDestroy()
  71. {
  72. // --- Kill Subject editor
  73. if (IsEditingSubject())
  74. {
  75. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(commit) [CXTPCalendarView::OnBeforeDestroy]"));
  76. EndEditSubject(xtpCalendarEditSubjectCommit, FALSE);
  77. }
  78. if (m_ptrDraggingEventNew)
  79. {
  80. BOOL bChanged = CommitDraggingEvent();
  81. TRACE_DRAGGING(_T("Dragging - CommitDraggingEvent() = %d. [CXTPCalendarView::OnBeforeDestroy] n"), bChanged);
  82. }
  83. // --- Kill tooltip (and timer inside)
  84. ShowToolTip(FALSE);
  85. // --- Clear selected events collection
  86. if (m_pSelectedEvents)
  87. {
  88. m_pSelectedEvents->RemoveAll();
  89. }
  90. // === Call base cleanup code
  91. TBase::OnBeforeDestroy();
  92. }
  93. void CXTPCalendarView::OnActivateView(BOOL bActivate,
  94. CXTPCalendarView* pActivateView,
  95. CXTPCalendarView* pInactiveView)
  96. {
  97. UNREFERENCED_PARAMETER(pActivateView);
  98. UNREFERENCED_PARAMETER(pInactiveView);
  99. if (!bActivate && IsEditingSubject())
  100. {
  101. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(commit) [CXTPCalendarView::OnActivateView(FALSE)] n"));
  102. EndEditSubject(xtpCalendarEditSubjectCommit, FALSE);
  103. }
  104. }
  105. void CXTPCalendarView::RedrawControl()
  106. {
  107. ASSERT(m_pControl);
  108. if (m_pControl)
  109. {
  110. m_pControl->RedrawControl();
  111. }
  112. }
  113. void CXTPCalendarView::Populate()
  114. {
  115. if (IsEditingSubject())
  116. {
  117. EndEditSubject(xtpCalendarEditSubjectCommit);
  118. }
  119. int nCount = GetViewDayCount();
  120. for (int i = 0; i < nCount; i++)
  121. {
  122. CXTPCalendarViewDay* pViewDay = GetViewDay_(i);
  123. COleDateTime dtDay = GetViewDayDate(i);
  124. ASSERT(pViewDay);
  125. if (pViewDay)
  126. {
  127. pViewDay->Populate(dtDay);
  128. }
  129. }
  130. _ReSelectSelectEvents();
  131. }
  132. BOOL CXTPCalendarView::OnLButtonDown(UINT nFlags, CPoint point)
  133. {
  134. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedrawIfNeed);
  135. CSelectionChangedContext selChanged(this);
  136. TRACE_MOUSE(_T("OnLButtonDown - [CXTPCalendarView] (nFlags =%x, point.x =%d, point.y =%d) n"), nFlags, point.x, point.y);
  137. m_bStartedClickInside = TRUE;
  138. //---------------------------------------------------------------------------
  139. TBase::OnLButtonDown(nFlags, point);
  140. //= kill timeout request to edit subject=====================================
  141. if (m_nTimerID_StartEditSubject)
  142. {
  143. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - KillTimer() [CXTPCalendarView::OnLButtonDown(%d, %d)] n"), point.x, point.y);
  144. KillTimer(m_nTimerID_StartEditSubject);
  145. m_nTimerID_StartEditSubject = 0;
  146. m_ptrEditingViewEvent = NULL;
  147. }
  148. //---------------------------------------------------------------------------
  149. XTP_CALENDAR_HITTESTINFO hitInfo;
  150. if (HitTest(point, &hitInfo))
  151. {
  152. if (hitInfo.uHitCode & xtpCalendarHitTestDay_Mask)
  153. {
  154. CXTPCalendarControl::CUpdateContext updateContext1(m_pControl, xtpCalendarUpdateRedraw);
  155. ProcessDaySelection(&hitInfo, nFlags);
  156. }
  157. else
  158. if (hitInfo.uHitCode & xtpCalendarHitTestEvent_Mask)
  159. {
  160. CXTPCalendarControl::CUpdateContext updateContext1(m_pControl, xtpCalendarUpdateRedraw);
  161. ProcessEventSelection(&hitInfo, nFlags);
  162. // set request to start dragging when OnMouseMove()
  163. m_ptStartDragging = point;
  164. TRACE_DRAGGING(_T("Dragging REQUEST point(%d, %d) n"), point.x, point.y);
  165. }
  166. }
  167. //---------------------------------------------------------------------------
  168. BOOL bResetUndoLocal = TRUE;
  169. if (IsEditingSubject())
  170. {
  171. if (!GetSubjectEditorRect().PtInRect(point))
  172. {
  173. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(commit) [CXTPCalendarView::OnLButtonDown(%d, %d)] n"), point.x, point.y);
  174. bResetUndoLocal = m_eDraggingMode != xtpCalendaDragModeEditSubject;
  175. EndEditSubject(xtpCalendarEditSubjectCommit);
  176. }
  177. }
  178. m_bResetUndoBuffer = bResetUndoLocal;
  179. //---------------------------------------------------------------------------
  180. CXTPCalendarThemeOffice2007* pThemeX = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetTheme());
  181. if (pThemeX)
  182. {
  183. XTP_SAFE_CALL1(pThemeX->GetPrevNextEventControllerPartX(), OnLButtonDown(this, nFlags, point));
  184. }
  185. return TRUE;
  186. }
  187. BOOL CXTPCalendarView::OnLButtonUp(UINT nFlags, CPoint point)
  188. {
  189. TRACE_MOUSE(_T("OnLButtonUp - [CXTPCalendarView] (nFlags =%x, point.x =%d, point.y =%d) n"), nFlags, point.x, point.y);
  190. {
  191. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedrawIfNeed);
  192. CSelectionChangedContext selChanged(this);
  193. TBase::OnLButtonUp(nFlags, point);
  194. //---------------------------------------------------------------------------
  195. m_ptStartDragging.x = m_ptStartDragging.y = LONG_MAX;
  196. XTP_CALENDAR_HITTESTINFO hitInfo;
  197. BOOL bHitTest = HitTest(point, &hitInfo);
  198. int nDragMode = m_eDraggingMode;
  199. if (!OnEndDragging(point, &hitInfo))
  200. {
  201. TRACE_DRAGGING(_T("Dragging ENDED. point(%d, %d). [CXTPCalendarView::OnLButtonUp] n"), point.x, point.y);
  202. if (bHitTest)
  203. {
  204. UINT uESmask = xtpCalendarHitTestEventTextArea | xtpCalendarHitTestEventResizeArea_Mask;
  205. if ((hitInfo.uHitCode & uESmask) && !IsEditingSubject() &&
  206. hitInfo.pViewEvent && hitInfo.pViewEvent->IsSelected())
  207. {
  208. BOOL bEnabled = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), bEnableInPlaceEditEventSubject_ByMouseClick, FALSE);
  209. bEnabled = bEnabled && IsSingleEventSelected();
  210. if (bEnabled)
  211. {
  212. bEnabled = !OnBeforeEditOperationNotify(xtpCalendarEO_EditSubject_ByMouseClick, hitInfo.pViewEvent);
  213. }
  214. if (bEnabled)
  215. {
  216. ASSERT(!m_ptrEditingViewEvent);
  217. m_ptrEditingViewEvent = hitInfo.pViewEvent;
  218. m_ptrEditingViewEvent->InternalAddRef();
  219. if (m_nTimerID_StartEditSubject == 0)
  220. {
  221. UINT uTimeOut_ms = GetStartEditSubjectTimeOut();
  222. m_nTimerID_StartEditSubject = SetTimer(uTimeOut_ms);
  223. ASSERT(m_nTimerID_StartEditSubject);
  224. DBG_TRACE_TIMER(_T("SET Timer: ID =%d, m_nTimerID_StartEditSubject, CXTPCalendarView.OnLButtonUp() n"), m_nTimerID_StartEditSubject);
  225. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - StartEditSubject REQUEST. [CXTPCalendarView::OnLButtonUp(%d, %d)] n"), point.x, point.y);
  226. }
  227. }
  228. }
  229. }
  230. }
  231. //---------------------------------------------------------------------------
  232. if (_IsDragModeCopyMove(nDragMode) && bHitTest && hitInfo.pViewDay)
  233. {
  234. UnselectAllEvents();
  235. SelectDay(hitInfo.pViewDay, hitInfo.nGroup);
  236. }
  237. if (GetCalendarControl())
  238. {
  239. GetCalendarControl()->m_mouseMode = xtpCalendarMouseNothing;
  240. }
  241. m_bStartedClickInside = FALSE;
  242. }
  243. OnMouseMove(nFlags, point);
  244. return TRUE;
  245. }
  246. void CXTPCalendarView::OnMouseMove(UINT nFlags, CPoint point)
  247. {
  248. TRACE_MOUSE(_T("OnMouseMove - [CXTPCalendarView] (point.x =%d, point.y =%d) n"),
  249. point.x, point.y);
  250. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedrawIfNeed);
  251. CSelectionChangedContext selChanged(this);
  252. //---------------------------------------------------------------------------
  253. CXTPCalendarThemeOffice2007* pThemeX = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetTheme());
  254. if (pThemeX)
  255. {
  256. XTP_SAFE_CALL1(pThemeX->GetPrevNextEventControllerPartX(), OnMouseMove(this, nFlags, point));
  257. }
  258. //---------------------------------------------------------------------------
  259. TBase::OnMouseMove(nFlags, point);
  260. //---------------------------------------------------------------------------
  261. XTP_CALENDAR_HITTESTINFO hitInfo;
  262. BOOL bHitTest = HitTest(point, &hitInfo);
  263. if (bHitTest && hitInfo != m_LastHitInfo)
  264. {
  265. m_LastHitInfo = hitInfo;
  266. if (nFlags & MK_LBUTTON && m_bStartedClickInside)
  267. {
  268. const int cEpsilon = 2;
  269. if (m_ptStartDragging.x == LONG_MAX || m_ptStartDragging.y == LONG_MAX ||
  270. abs(point.x - m_ptStartDragging.x) >= cEpsilon ||
  271. abs(point.y - m_ptStartDragging.y) >= cEpsilon)
  272. {
  273. if (!m_ptrDraggingEventNew && !m_ptrDraggingEventOrig &&
  274. m_eDraggingMode == xtpCalendaDragModeUnknown)
  275. {
  276. XTP_CALENDAR_HITTESTINFO hitInfoSD;
  277. if (HitTest(m_ptStartDragging, &hitInfoSD))
  278. {
  279. if (hitInfoSD.uHitCode & xtpCalendarHitTestEvent_Mask)
  280. {
  281. int eDragMode = _GetDraggingMode(&hitInfoSD);
  282. if (!IsEditOperationDisabledNotify(_DragMod2Operation(eDragMode), hitInfoSD.pViewEvent))
  283. {
  284. TRACE_DRAGGING(_T("Dragging will START. point(%d, %d). [CXTPCalendarView::OnMouseMove] n"), point.x, point.y);
  285. OnStartDragging(m_ptStartDragging, &hitInfoSD);
  286. }
  287. }
  288. }
  289. }
  290. m_ptStartDragging.x = m_ptStartDragging.y = LONG_MAX;
  291. BOOL bDragging = m_ptrDraggingEventNew && m_eDraggingMode != xtpCalendaDragModeEditSubject;
  292. if (bDragging)
  293. {
  294. CXTPCalendarEventPtr ptrDragEventPrev = m_ptrDraggingEventNew->CloneEvent();
  295. BOOL bDragged = OnDragging(point, &hitInfo);
  296. if (bDragged)
  297. {
  298. XTP_EVENT_DRAG_OPERATION_PARAMS opParamsDrag;
  299. ::ZeroMemory(&opParamsDrag, sizeof(opParamsDrag));
  300. opParamsDrag.eOperation = _DragMod2Operation(m_eDraggingMode);
  301. opParamsDrag.pDraggingEvent = ptrDragEventPrev;
  302. opParamsDrag.pDraggingEventNew = m_ptrDraggingEventNew;
  303. BOOL bHandled = FALSE;
  304. if (m_pControl)
  305. {
  306. m_pControl->SendNotification(XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION,
  307. (WPARAM)&opParamsDrag, (LPARAM)&bHandled);
  308. }
  309. if (bHandled)
  310. {
  311. //rollback
  312. m_ptrDraggingEventNew = ptrDragEventPrev;
  313. }
  314. else
  315. {
  316. TRACE_DRAGGING(_T("Dragging OnDragging change event. point(%d, %d). [CXTPCalendarView::OnMouseMove] n"), point.x, point.y);
  317. }
  318. XTP_SAFE_CALL1(GetCalendarControl(), Populate());
  319. CXTPCalendarControl::CUpdateContext updateContext1(m_pControl, xtpCalendarUpdateLayout | xtpCalendarUpdateRedraw);
  320. if (m_ptrDraggingEventNew && m_ptrDraggingEventOrig &&
  321. (!m_ptrDraggingEventNew->IsEqualStartEnd(m_ptrDraggingEventOrig) ||
  322.  m_ptrDraggingEventNew->GetScheduleID() != m_ptrDraggingEventOrig->GetScheduleID())
  323. )
  324. {
  325. SelectEvent(m_ptrDraggingEventNew);
  326. }
  327. }
  328. }
  329. }
  330. if (m_eDraggingMode == xtpCalendaDragModeUnknown &&
  331. hitInfo.uHitCode & (xtpCalendarHitTestDay_Mask | xtpCalendarHitTestEvent_Mask))
  332. {
  333. if ((hitInfo.uHitCode & xtpCalendarHitTestEvent_Mask) &&
  334. hitInfo.pViewEvent && hitInfo.pViewEvent->IsSelected())
  335. {}
  336. else
  337. {
  338. CXTPCalendarControl::CUpdateContext updateContext1(m_pControl, xtpCalendarUpdateRedraw);
  339. ProcessDaySelection(&hitInfo, nFlags | MK_SHIFT);
  340. }
  341. }
  342. }
  343. // process tooltip events (only when no buttons pressed)
  344. if (0 == nFlags)
  345. {
  346. CRect rcTooltip(GetTooltipRect(point, hitInfo));
  347. if (m_rcTooltip != rcTooltip)
  348. {
  349. // -- kill waiting and hide a tooltip because we switched to another cell
  350. ShowToolTip(FALSE);
  351. // -- start waiting for mouse under regular empty cell
  352. //    (to show later "click to add appointment" button)
  353. UINT uTimeOut_ms = GetShowToolTipTimeOut();
  354. m_nTimerID_ShowToolTip = SetTimer(uTimeOut_ms);
  355. m_rcTooltip = rcTooltip;
  356. ASSERT(m_nTimerID_ShowToolTip);
  357. }
  358. }
  359. }
  360. else if (!bHitTest)
  361. {
  362. XTP_CALENDAR_HITTESTINFO hitInfoEmpty;
  363. m_LastHitInfo = hitInfoEmpty;
  364. }
  365. //===========================================================================
  366. if (GetCalendarControl())
  367. {
  368. if (_IsDragModeCopyMove(m_eDraggingMode) &&
  369. GetCalendarControl()->m_mouseMode != xtpCalendarMouseEventDraggingOut)
  370. {
  371. GetCalendarControl()->m_mouseMode = m_eDraggingMode == xtpCalendaDragModeCopy ?
  372. xtpCalendarMouseEventDragCopy : xtpCalendarMouseEventDragMove;
  373. GetCalendarControl()->UpdateMouseCursor();
  374. }
  375. }
  376. }
  377. void CXTPCalendarView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  378. {
  379. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedrawIfNeed);
  380. CSelectionChangedContext selChanged(this);
  381. TRACE_KEYBOARD(_T("OnChar - [CXTPCalendarView] (nChar =%d, nRepCnt =%d, nFlags =%x) n"), nChar, nRepCnt, nFlags);
  382. TBase::OnChar(nChar, nRepCnt, nFlags);
  383. //========================================================================
  384. BOOL bEnable = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), bEnableInPlaceCreateEvent, FALSE);
  385. if (nChar >= _T(' ') && bEnable)
  386. {
  387. CString strInitialSubj((TCHAR)nChar);
  388. if (!OnInPlaceCreateEvent(strInitialSubj))
  389. {
  390. StartEditNewEventInplace(strInitialSubj);
  391. }
  392. }
  393. }
  394. void CXTPCalendarView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  395. {
  396. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedrawIfNeed);
  397. CSelectionChangedContext selChanged(this);
  398. TRACE_KEYBOARD(_T("OnKeyDown - [CXTPCalendarView] (nChar =%d, nRepCnt =%d, nFlags =%x) n"), nChar, nRepCnt, nFlags);
  399. TBase::OnKeyDown(nChar, nRepCnt, nFlags);
  400. //---------------------------------------------------------------------------
  401. if (nChar == VK_RETURN || nChar == VK_ESCAPE)
  402. {
  403. if (IsEditingSubject())
  404. {
  405. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(). [CXTPCalendarView::OnKeyDown] n"));
  406. CXTPCalendarEventPtr ptrEditingEvent(m_ptrDraggingEventOrig, TRUE);
  407. EndEditSubject((nChar == VK_RETURN) ? xtpCalendarEditSubjectCommit : xtpCalendarEditSubjectCancel);
  408. if (nChar == VK_ESCAPE && ptrEditingEvent)
  409. {
  410. _Undo(ptrEditingEvent);
  411. m_UndoBuffer.Set(m_PrevUndoBuffer);
  412. }
  413. }
  414. if (nChar == VK_ESCAPE && m_ptrDraggingEventNew)
  415. {
  416. CXTPCalendarEventPtr ptrEditingEvent(m_ptrDraggingEventOrig, TRUE);
  417. CancelDraggingEvent();
  418. BOOL bControlUpdated = FALSE;
  419. if (ptrEditingEvent && !m_bResetUndoBuffer)
  420. {
  421. bControlUpdated = _Undo(ptrEditingEvent);
  422. m_UndoBuffer.Set(m_PrevUndoBuffer);
  423. }
  424. if (!bControlUpdated && GetCalendarControl())
  425. {
  426. CXTPCalendarControl::CUpdateContext updateContext1(GetCalendarControl(), xtpCalendarUpdateLayout | xtpCalendarUpdateRedraw);
  427. GetCalendarControl()->Populate();
  428. }
  429. }
  430. }
  431. else if (nChar == VK_F2)
  432. {
  433. if (IsEditingSubject())
  434. {
  435. return;
  436. }
  437. CXTPCalendarViewEvent* pViewEvent = GetLastSelectedViewEvent();
  438. BOOL bEnabled = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), bEnableInPlaceEditEventSubject_ByF2, FALSE);
  439. bEnabled = bEnabled && m_eDraggingMode == xtpCalendaDragModeUnknown && pViewEvent;
  440. if (bEnabled)
  441. {
  442. bEnabled = !OnBeforeEditOperationNotify(xtpCalendarEO_EditSubject_ByF2, pViewEvent);
  443. }
  444. if (bEnabled)
  445. {
  446. ASSERT(!m_ptrDraggingEventOrig && !m_ptrDraggingEventNew && !m_ptrEditingViewEvent);
  447. if (pViewEvent)
  448. {
  449. CXTPCalendarControl::CUpdateContext updateContext1(m_pControl, xtpCalendarUpdateRedraw);
  450. EmptyUndoBuffer();
  451. StartEditSubject(pViewEvent);
  452. }
  453. }
  454. }
  455. else if (nChar == VK_DELETE)
  456. {
  457. if (m_eDraggingMode == xtpCalendaDragModeUnknown && !m_ptrEditingViewEvent)
  458. {
  459. ASSERT(!m_ptrDraggingEventOrig && !m_ptrDraggingEventNew && !m_ptrEditingViewEvent);
  460. CXTPCalendarViewEvent* pViewEvent = GetLastSelectedViewEvent();
  461. if (m_selectedBlock.dtEnd.GetStatus() == COleDateTime::valid &&
  462. GetCalendarControl() && pViewEvent && pViewEvent->IsSelected())
  463. {
  464. CXTPCalendarControl::CUpdateContext updateContext1(GetCalendarControl(), xtpCalendarUpdateRedraw | xtpCalendarUpdateLayout);
  465. VERIFY(GetCalendarControl()->DoDeleteSelectedEvents(pViewEvent));
  466. GetCalendarControl()->Populate();
  467. }
  468. }
  469. }
  470. else if (nChar == VK_TAB)
  471. {
  472. if (m_eDraggingMode == xtpCalendaDragModeUnknown ||
  473. m_eDraggingMode == xtpCalendaDragModeEditSubject)
  474. {
  475. BOOL bShift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0;
  476. CXTPCalendarControl::CUpdateContext updateContext1(m_pControl, xtpCalendarUpdateRedraw);
  477. if (IsEditingSubject())
  478. {
  479. EndEditSubject(xtpCalendarEditSubjectCommit);
  480. }
  481. COleDateTime dtMinStart = GetNextTimeEditByTAB();
  482. CXTPCalendarViewEvent* pViewEvent = GetLastSelectedViewEvent();
  483. CXTPCalendarEvent* pLastEvent = pViewEvent ? pViewEvent->GetEvent() : NULL;
  484. const int cLoopMax = 5000;
  485. int i;
  486. for (i = 0; i < cLoopMax; i++) // to prevent infinite looping
  487. {
  488. pViewEvent = FindEventToEditByTAB(dtMinStart, bShift, pLastEvent);
  489. pLastEvent = pViewEvent ? pViewEvent->GetEvent() : NULL;
  490. if (!pViewEvent || pViewEvent && pViewEvent->IsVisible())
  491. {
  492. break;
  493. }
  494. }
  495. ASSERT(i < cLoopMax); // probably infinite looping ???
  496. UnselectAllEvents();
  497. if (pViewEvent && pViewEvent->IsVisible() && pViewEvent->GetEvent())
  498. {
  499. dtMinStart = pViewEvent->GetEvent()->GetStartTime();
  500. UpdateNextTimeEditByTAB(dtMinStart, bShift);
  501. EmptyUndoBuffer();
  502. BOOL bEnabled = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), bEnableInPlaceEditEventSubject_ByTab, FALSE);
  503. if (bEnabled)
  504. {
  505. bEnabled = !OnBeforeEditOperationNotify(xtpCalendarEO_EditSubject_ByTab, pViewEvent);
  506. }
  507. if (bEnabled)
  508. {
  509. StartEditSubject(pViewEvent);
  510. }
  511. else
  512. {
  513. SelectEvent(pViewEvent->GetEvent());
  514. }
  515. SelectDay(XTP_SAFE_GET2(pViewEvent, GetViewGroup_(), GetViewDay_(), NULL),
  516.   XTP_SAFE_GET2(pViewEvent, GetViewGroup_(), GetGroupIndex(), -1));
  517. }
  518. else
  519. {
  520. dtMinStart = GetViewDayDate(bShift ? GetViewDayCount()-1 : 0);
  521. UpdateNextTimeEditByTAB(dtMinStart, bShift, TRUE);
  522. }
  523. }
  524. }
  525. }
  526. BOOL CXTPCalendarView::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  527. {
  528. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedrawIfNeed);
  529. CSelectionChangedContext selChanged(this);
  530. TRACE_KEYBOARD(_T("OnSysKeyDown - [CXTPCalendarView] (nChar =%d, nRepCnt =%d, nFlags =%x) n"), nChar, nRepCnt, nFlags);
  531. BOOL bHandled = TBase::OnSysKeyDown(nChar, nRepCnt, nFlags);
  532. //---------------------------------------------------------------------------
  533. UINT uAltBit = (((UINT)1) << 13);
  534. if (nChar == VK_BACK && (nFlags & uAltBit))
  535. {
  536. bHandled = TRUE;
  537. if (CanUndo())
  538. {
  539. Undo();
  540. }
  541. else if (CanRedo())
  542. {
  543. Redo();
  544. }
  545. }
  546. return bHandled;
  547. }
  548. BOOL CXTPCalendarView::SetDraggingEvent(CXTPCalendarEvent* pEventOrig)
  549. {
  550. if (m_ptrDraggingEventOrig || m_ptrDraggingEventNew || !pEventOrig)
  551. {
  552. ASSERT(FALSE); // Dragging Event already set,
  553. return FALSE;  // or CommitDraggingEvent() was not called.
  554. }                  // or invalid parameter
  555. TRACE_DRAGGING(_T("Dragging - SetDraggingEvent. ptr =%x. [CXTPCalendarView::SetDraggingEvent] n"), pEventOrig);
  556. pEventOrig->InternalAddRef();
  557. m_ptrDraggingEventOrig = pEventOrig;
  558. m_ptrDraggingEventNew = pEventOrig->CloneEvent();
  559. if (m_ptrDraggingEventNew &&
  560. m_ptrDraggingEventNew->GetRecurrenceState() == xtpCalendarRecurrenceOccurrence)
  561. {
  562. VERIFY(m_ptrDraggingEventNew->MakeAsRException());
  563. }
  564. return TRUE;
  565. }
  566. CXTPCalendarEvent* CXTPCalendarView::GetDraggingEventOrig()
  567. {
  568. return m_ptrDraggingEventOrig;
  569. }
  570. CXTPCalendarEvent* CXTPCalendarView::GetDraggingEventNew()
  571. {
  572. return m_ptrDraggingEventNew;
  573. }
  574. BOOL CXTPCalendarView::CommitDraggingEvent()
  575. {
  576. ASSERT(m_ptrDraggingEventNew);
  577. if (!GetCalendarControl())
  578. {
  579. return FALSE;
  580. }
  581. CXTPAutoResetValue<BOOL> autoSet_UpdateCtrlNf(GetCalendarControl()->m_bUpdateWhenEventChangedNotify);
  582. autoSet_UpdateCtrlNf = FALSE;
  583. if (m_ptrDraggingEventNew && m_ptrDraggingEventOrig)
  584. {
  585. BOOL bDPdiff = m_ptrDraggingEventNew->GetDataProvider() != m_ptrDraggingEventOrig->GetDataProvider();
  586. BOOL bChanged = !m_ptrDraggingEventNew->IsEqualStartEnd(m_ptrDraggingEventOrig);
  587. bChanged = bChanged || m_ptrDraggingEventNew->GetSubject() != m_ptrDraggingEventOrig->GetSubject();
  588. bChanged = bChanged || m_ptrDraggingEventNew->IsAllDayEvent() != m_ptrDraggingEventOrig->IsAllDayEvent();
  589. bChanged = bChanged || m_ptrDraggingEventNew->GetScheduleID() != m_ptrDraggingEventOrig->GetScheduleID();
  590. bChanged = bChanged || bDPdiff;
  591. if (bChanged || m_eDraggingMode == xtpCalendaDragModeCopy)
  592. {
  593. if (!m_UndoBuffer.IsInUndoBuffer(m_ptrDraggingEventOrig) || m_bResetUndoBuffer)
  594. {
  595. m_PrevUndoBuffer.Set(m_UndoBuffer);
  596. EmptyUndoBuffer();
  597. }
  598. CXTPCalendarData* pDataNew = m_ptrDraggingEventNew->GetDataProvider(); // _GetDataProviderForDraggingEvent(m_ptrDraggingEventNew);
  599. CXTPCalendarData* pDataOrig = m_ptrDraggingEventOrig->GetDataProvider();
  600. if (m_eDraggingMode == xtpCalendaDragModeCopy)
  601. {
  602. if (m_ptrDraggingEventNew->GetRecurrenceState() != xtpCalendarRecurrenceNotRecurring)
  603. {
  604. VERIFY(m_ptrDraggingEventNew->RemoveRecurrence() );
  605. }
  606. if (pDataNew)
  607. {
  608. DBG_DATA_VERIFY(pDataNew->AddEvent(m_ptrDraggingEventNew) );
  609. }
  610. }
  611. else
  612. {
  613. m_UndoBuffer.AddUndoAction(m_ptrDraggingEventOrig, m_ptrDraggingEventNew);
  614. m_eUndoMode = xtpCalendarUndoModeUndo;
  615. m_bResetUndoBuffer = FALSE;
  616. if (pDataNew)
  617. {
  618. if (!bDPdiff)
  619. {
  620. // restore event ID for case when m_ptrDraggingEventNew was recreated
  621. // during dragging between providers
  622. m_ptrDraggingEventNew->SetEventID(m_ptrDraggingEventOrig->GetEventID());
  623. DBG_DATA_VERIFY(pDataNew->ChangeEvent(m_ptrDraggingEventNew) );
  624. }
  625. else
  626. {
  627. if (m_ptrDraggingEventNew->GetRecurrenceState() != xtpCalendarRecurrenceNotRecurring)
  628. {
  629. VERIFY(m_ptrDraggingEventNew->RemoveRecurrence() );
  630. }
  631. if (pDataOrig)
  632. {
  633. DBG_DATA_VERIFY(pDataOrig->DeleteEvent(m_ptrDraggingEventOrig) );
  634. }
  635. DBG_DATA_VERIFY(pDataNew->AddEvent(m_ptrDraggingEventNew));
  636. }
  637. }
  638. // for test only
  639. //VERIFY(pData->DeleteEvent(m_ptrDraggingEventOrig));
  640. //VERIFY(pData->AddEvent(m_ptrDraggingEventNew));
  641. }
  642. }
  643. TRACE_DRAGGING(_T("Dragging - CommitDraggingEvent() = %d. ptr =%x. [CXTPCalendarView] n"), bChanged, (CXTPCalendarEvent*)m_ptrDraggingEventOrig);
  644. m_ptrDraggingEventOrig = NULL;
  645. m_ptrDraggingEventNew = NULL;
  646. return bChanged;
  647. }
  648. else if (m_ptrDraggingEventNew)
  649. {
  650. if (!m_UndoBuffer.IsInUndoBuffer(m_ptrDraggingEventNew) || m_bResetUndoBuffer)
  651. {
  652. m_PrevUndoBuffer.Set(m_UndoBuffer);
  653. EmptyUndoBuffer();
  654. }
  655. CXTPCalendarData* pData = m_ptrDraggingEventNew->GetDataProvider(); //_GetDataProviderForDraggingEvent(m_ptrDraggingEventNew);
  656. ASSERT(m_ptrDraggingEventNew->GetRecurrenceState() == xtpCalendarRecurrenceNotRecurring);
  657. if (pData)
  658. {
  659. DBG_DATA_VERIFY( pData->AddEvent(m_ptrDraggingEventNew) );
  660. }
  661. m_UndoBuffer.AddUndoAction(NULL, m_ptrDraggingEventNew);
  662. m_eUndoMode = xtpCalendarUndoModeUndo;
  663. m_bResetUndoBuffer = FALSE;
  664. m_ptrDraggingEventOrig = NULL;
  665. m_ptrDraggingEventNew = NULL;
  666. return TRUE;
  667. }
  668. return FALSE;
  669. }
  670. void CXTPCalendarView::CancelDraggingEvent()
  671. {
  672. ASSERT(m_ptrDraggingEventNew);
  673. m_eDraggingMode = xtpCalendaDragModeUnknown;
  674. if (GetCalendarControl())
  675. {
  676. GetCalendarControl()->m_mouseMode = xtpCalendarMouseNothing;
  677. GetCalendarControl()->UpdateMouseCursor();
  678. }
  679. m_ptrDraggingEventOrig = NULL;
  680. m_ptrDraggingEventNew = NULL;
  681. m_ptStartDragging.x = m_ptStartDragging.y = LONG_MAX;
  682. m_bStartedClickInside = FALSE;
  683. }
  684. CXTPCalendarEventsPtr CXTPCalendarView::RetrieveDayEvents(CXTPCalendarResource* pRC,
  685.   COleDateTime dtDay)
  686. {
  687. ASSERT(pRC);
  688. dtDay = CXTPCalendarUtils::ResetTime(dtDay);
  689. CXTPCalendarEventsPtr ptrEvents = pRC ? pRC->RetrieveDayEvents(dtDay) : new CXTPCalendarEvents();
  690. if (!m_ptrDraggingEventNew || !ptrEvents || !pRC)
  691. {
  692. return ptrEvents;
  693. }
  694. BOOL bIsDragCopy = m_eDraggingMode == xtpCalendaDragModeCopy;
  695. COleDateTime dtDay1 = CXTPCalendarUtils::ResetTime(m_ptrDraggingEventNew->GetStartTime());
  696. COleDateTime dtDay2 = CXTPCalendarUtils::ResetTime(m_ptrDraggingEventNew->GetEndTime());
  697. UINT uSchID = m_ptrDraggingEventNew->GetScheduleID();
  698. BOOL bNewEventScheduleVisible =
  699. m_ptrDraggingEventNew->GetDataProvider() == pRC->GetDataProvider() &&
  700. pRC->ExistsScheduleID(uSchID);
  701. if (!bIsDragCopy)
  702. {
  703. int nCount = ptrEvents->GetCount();
  704. for (int i = nCount-1; i >= 0; i--)
  705. {
  706. CXTPCalendarEvent* pEvent = ptrEvents->GetAt(i, FALSE);
  707. if (!pEvent)
  708. {
  709. continue;
  710. }
  711. if (m_ptrDraggingEventOrig &&
  712. m_ptrDraggingEventOrig->GetDataProvider() == pEvent->GetDataProvider() &&
  713. m_ptrDraggingEventOrig->IsEqualIDs(pEvent) &&
  714. m_ptrDraggingEventOrig->GetScheduleID() == pEvent->GetScheduleID()
  715.    )
  716. {
  717. ptrEvents->RemoveAt(i);
  718. //break;
  719. }
  720. }
  721. }
  722. if (dtDay >= dtDay1 && dtDay <= dtDay2 && bNewEventScheduleVisible)
  723. {
  724. ptrEvents->Add(m_ptrDraggingEventNew);
  725. }
  726. return ptrEvents;
  727. }
  728. XTPCalendarDraggingMode CXTPCalendarView::_GetDraggingMode(XTP_CALENDAR_HITTESTINFO* pHitTest) const
  729. {
  730. if (!pHitTest)
  731. {
  732. ASSERT(FALSE);
  733. return xtpCalendaDragModeUnknown;
  734. }
  735. if (pHitTest->uHitCode & xtpCalendarHitTestEventResizeArea_Mask)
  736. {
  737. if (pHitTest->uHitCode & xtpCalendarHitTestEventResizeBegin)
  738. {
  739. return xtpCalendaDragModeResizeBegin;
  740. }
  741. else if (pHitTest->uHitCode & xtpCalendarHitTestEventResizeEnd)
  742. {
  743. return xtpCalendaDragModeResizeEnd;
  744. }
  745. }
  746. else
  747. {
  748. BOOL bIsCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
  749. return bIsCtrl ? xtpCalendaDragModeCopy : xtpCalendaDragModeMove;
  750. }
  751. return xtpCalendaDragModeUnknown;
  752. }
  753. void CXTPCalendarView::OnStartDragging(CPoint /*point*/, XTP_CALENDAR_HITTESTINFO* pHitTest)
  754. {
  755. if (!pHitTest)
  756. {
  757. ASSERT(FALSE);
  758. return;
  759. }
  760. if ((pHitTest->uHitCode & xtpCalendarHitTestEvent_Mask) == 0)
  761. {
  762. return;
  763. }
  764. //---------------------------------------------------------------------------
  765. if (IsEditingSubject())
  766. {
  767. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(). [CXTPCalendarView::OnStartDragging] n"));
  768. EndEditSubject(xtpCalendarEditSubjectCommit, FALSE);
  769. }
  770. //---------------------------------------------------------------------------
  771. m_spDraggingStartOffset.SetStatus(COleDateTimeSpan::null);
  772. m_eDraggingMode = xtpCalendaDragModeUnknown;
  773. if (!pHitTest->pViewEvent || !pHitTest->pViewEvent->GetEvent())
  774. {
  775. ASSERT(FALSE);
  776. return;
  777. }
  778. m_eDraggingMode = _GetDraggingMode(pHitTest);
  779. ASSERT(m_eDraggingMode != xtpCalendaDragModeUnknown);
  780. if (_IsDragModeCopyMove(m_eDraggingMode))
  781. {
  782. if (pHitTest->bTimePartValid)
  783. {
  784. m_spDraggingStartOffset = pHitTest->dt - pHitTest->pViewEvent->GetEvent()->GetStartTime();
  785. }
  786. else
  787. {
  788. m_spDraggingStartOffset = CXTPCalendarUtils::ResetTime(pHitTest->dt) -
  789.   CXTPCalendarUtils::ResetTime(pHitTest->pViewEvent->GetEvent()->GetStartTime());
  790. }
  791. if (!m_nKeyStateTimerID)
  792. {
  793. m_nKeyStateTimerID = SetTimer(50);
  794. DBG_TRACE_TIMER(_T("SET Timer: ID =%d, m_nKeyStateTimerID, CXTPCalendarView::OnStartDragging() n"), m_nKeyStateTimerID);
  795. }
  796. }
  797. //---------------------------------------------------------------------------
  798. VERIFY(SetDraggingEvent(pHitTest->pViewEvent->GetEvent()));
  799. }
  800. BOOL CXTPCalendarView::OnEndDragging(CPoint point, XTP_CALENDAR_HITTESTINFO* /*phitInfo*/)
  801. {
  802. if (!m_ptrDraggingEventNew || !m_ptrDraggingEventOrig ||
  803. m_eDraggingMode == xtpCalendaDragModeEditSubject)
  804. {
  805. return FALSE;
  806. }
  807. CXTPCalendarEventPtr ptrEventToSelect = m_ptrDraggingEventNew;
  808. BOOL bChanged = CommitDraggingEvent();
  809. int nDragMode = m_eDraggingMode;
  810. m_eDraggingMode = xtpCalendaDragModeUnknown;
  811. TRACE_DRAGGING(_T("Dragging - CommitDraggingEvent() = %d. [CXTPCalendarView::OnEndDragging(%d, %d)] n"), bChanged, point.x, point.y);
  812. if (bChanged && GetCalendarControl())
  813. {
  814. GetCalendarControl()->Populate();
  815. }
  816. UnselectAllEvents();
  817. //---------------------------------------------------------------------------
  818. if (_IsDragModeCopyMove(nDragMode))
  819. {
  820. EmptyUndoBuffer();
  821. }
  822. //---------------------------------------------------------------------------
  823. if (ptrEventToSelect && (nDragMode == xtpCalendaDragModeResizeBegin || nDragMode == xtpCalendaDragModeResizeEnd))
  824. {
  825. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedraw);
  826. COleDateTime dtFVDate = CXTPCalendarUtils::ResetTime(ptrEventToSelect->GetStartTime());
  827. if (nDragMode == xtpCalendaDragModeResizeEnd)
  828. {
  829. dtFVDate = CXTPCalendarUtils::RetriveEventEndDate(ptrEventToSelect);
  830. }
  831. CXTPCalendarViewEvent* pViewEvent = FindViewEvent(ptrEventToSelect, dtFVDate);
  832. if (pViewEvent && pViewEvent->GetEvent())
  833. {
  834. SelectDay(XTP_SAFE_GET2(pViewEvent, GetViewGroup_(), GetViewDay_(), NULL),
  835.   XTP_SAFE_GET2(pViewEvent, GetViewGroup_(), GetGroupIndex(), -1));
  836. BOOL bEnabled = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), bEnableInPlaceEditEventSubject_AfterEventResize, FALSE);
  837. if (bEnabled)
  838. {
  839. bEnabled = !OnBeforeEditOperationNotify(xtpCalendarEO_EditSubject_AfterEventResize, pViewEvent);
  840. }
  841. if (bEnabled)
  842. {
  843. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - StartEditSubject(). [CXTPCalendarView::OnEndDragging(%d, %d)] n"), point.x, point.y);
  844. StartEditSubject(pViewEvent);
  845. }
  846. else
  847. {
  848. SelectEvent(pViewEvent->GetEvent());
  849. }
  850. }
  851. }
  852. SelectEvent(ptrEventToSelect);
  853. return TRUE;
  854. }
  855. CXTPCalendarViewEvent* CXTPCalendarView::FindViewEvent(CXTPCalendarEvent* pEvent, COleDateTime dtDay)
  856. {
  857. if (!pEvent)
  858. {
  859. ASSERT(FALSE);
  860. return NULL;
  861. }
  862. dtDay = CXTPCalendarUtils::ResetTime(dtDay);
  863. CXTPCalendarViewEvent* pFEView = NULL;
  864. BOOL bFDayProceessed = FALSE;
  865. int nCount = GetViewDayCount();
  866. for (int i = 0; i < nCount; i++)
  867. {
  868. CXTPCalendarViewDay* pViewDay = GetViewDay_(i);
  869. if (!pViewDay)
  870. {
  871. ASSERT(FALSE);
  872. continue;
  873. }
  874. COleDateTime dtDayDate = pViewDay->GetDayDate();
  875. int nGroupsCount = pViewDay->GetViewGroupsCount();
  876. for (int g = 0; g < nGroupsCount; g++)
  877. {
  878. CXTPCalendarViewGroup* pViewGroup = pViewDay->GetViewGroup_(g);
  879. ASSERT(pViewGroup);
  880. if (!pViewGroup)
  881. {
  882. continue;
  883. }
  884. int nECount = pViewGroup->GetViewEventsCount();
  885. for (int j = 0; j < nECount; j++)
  886. {
  887. CXTPCalendarViewEvent* pViewEvent = pViewGroup->GetViewEvent_(j);
  888. CXTPCalendarEvent* pEv = pViewEvent ? pViewEvent->GetEvent() : NULL;
  889. if (!pEv)
  890. {
  891. ASSERT(FALSE);
  892. continue;
  893. }
  894. if (pEvent->IsEqualIDs(pEv) && pEvent->IsEqualStartEnd(pEv))
  895. {
  896. if (pViewEvent->IsVisible())
  897. {
  898. pFEView = pViewEvent;
  899. }
  900. if (CXTPCalendarUtils::IsEqual(dtDay, dtDayDate))
  901. {
  902. bFDayProceessed = TRUE;
  903. }
  904. if (pFEView && bFDayProceessed)
  905. {
  906. return pFEView;
  907. }
  908. }
  909. }
  910. }
  911. }
  912. return NULL;
  913. }
  914. BOOL CXTPCalendarView::HasSelectedViewEvent()
  915. {
  916. if (!m_pSelectedEvents)
  917. {
  918. return FALSE;
  919. }
  920. return m_pSelectedEvents->GetCount() > 0;
  921. }
  922. CXTPCalendarViewEvents* CXTPCalendarView::GetSelectedViewEvents()
  923. {
  924. return m_pSelectedEvents;
  925. }
  926. BOOL CXTPCalendarView::IsSingleEventSelected()
  927. {
  928. int nCount = m_pSelectedEvents ? m_pSelectedEvents->GetCount() : 0;
  929. if (nCount == 0)
  930. return FALSE;
  931. if (nCount == 1)
  932. return TRUE;
  933. CXTPCalendarEvent* pEvent = m_pSelectedEvents->GetAt(0)->GetEvent();
  934. for (int i = 0; i < nCount; i++)
  935. {
  936. CXTPCalendarViewEvent* pViewEvent = m_pSelectedEvents->GetAt(i);
  937. ASSERT(pViewEvent);
  938. if (pViewEvent && !pViewEvent->GetEvent()->IsEqualIDs(pEvent))
  939. return FALSE;
  940. }
  941. return TRUE;
  942. }
  943. CXTPCalendarViewEventsPtr CXTPCalendarView::GetSelectedEvents()
  944. {
  945. CXTPCalendarViewEventsPtr ptrEventsWithViews = new CXTPCalendarViewEvents();
  946. CXTPCalendarEvents arEvents;
  947. ASSERT(m_pSelectedEvents);
  948. if (!ptrEventsWithViews || !m_pSelectedEvents)
  949. {
  950. return NULL;
  951. }
  952. int nCount = m_pSelectedEvents->GetCount();
  953. for (int i = 0; i < nCount; i++)
  954. {
  955. CXTPCalendarViewEvent* pViewEvent = m_pSelectedEvents->GetAt(i);
  956. CXTPCalendarEvent* pEvent = pViewEvent ? pViewEvent->GetEvent() : NULL;
  957. if (pEvent && arEvents.Find(pEvent) < 0)
  958. {
  959. arEvents.Add(pEvent, TRUE);
  960. ptrEventsWithViews->Add(pViewEvent, TRUE);
  961. }
  962. }
  963. return ptrEventsWithViews;
  964. }
  965. BOOL CXTPCalendarView::GetSelection(COleDateTime* pBegin, COleDateTime* pEnd,
  966. BOOL* pbAllDayEvent, int* pnGroupIndex,
  967. COleDateTimeSpan* pspSelectionResolution)
  968. {
  969. if (!m_selectedBlock.IsValid())
  970. {
  971. return FALSE;
  972. }
  973. if (pspSelectionResolution)
  974. {
  975. *pspSelectionResolution = COleDateTimeSpan(1, 0, 0, 0);
  976. }
  977. if (pbAllDayEvent)
  978. {
  979. *pbAllDayEvent = TRUE;
  980. }
  981. if (pnGroupIndex)
  982. {
  983. *pnGroupIndex = m_selectedBlock.nGroupIndex;
  984. }
  985. //---------------------------------------------------------------------------
  986. if (pBegin)
  987. {
  988. *pBegin = min(m_selectedBlock.dtBegin, m_selectedBlock.dtEnd);
  989. }
  990. if (pEnd)
  991. {
  992. *pEnd = max(m_selectedBlock.dtBegin, m_selectedBlock.dtEnd) + COleDateTimeSpan(1, 0, 0, 0);
  993. }
  994. return TRUE;
  995. }
  996. void CXTPCalendarView::SetSelection(const COleDateTime& dtBegin, const COleDateTime& dtEnd,
  997. BOOL bAllDayEvent, int nGroupIndex)
  998. {
  999. m_selectedBlock.dtBegin = dtBegin;
  1000. m_selectedBlock.dtEnd = dtEnd;
  1001. m_selectedBlock.bAllDayEvent = bAllDayEvent;
  1002. m_selectedBlock.nGroupIndex = nGroupIndex;
  1003. CSelectionChangedContext selChanged(this, xtpCalendarSelectionDays);
  1004. }
  1005. void CXTPCalendarView::ResetSelection()
  1006. {
  1007. m_selectedBlock.dtBegin.SetStatus(COleDateTime::null);
  1008. m_selectedBlock.dtEnd.SetStatus(COleDateTime::null);
  1009. m_selectedBlock.bAllDayEvent = FALSE;
  1010. m_selectedBlock.nGroupIndex = -1;
  1011. CSelectionChangedContext selChanged(this, xtpCalendarSelectionDays);
  1012. }
  1013. BOOL CXTPCalendarView::SelectionContains(COleDateTime date, int nGroupIndex, BOOL* pbAllDaySelection)
  1014. {
  1015. COleDateTime dtBegin;
  1016. COleDateTime dtEnd;
  1017. int nSelGroupIndex;
  1018. if (GetSelection(&dtBegin, &dtEnd, pbAllDaySelection, &nSelGroupIndex))
  1019. {
  1020. if (nGroupIndex < 0 || nGroupIndex == nSelGroupIndex)
  1021. {
  1022. return (dtBegin <= date && (double)date <= (double)dtEnd - XTP_HALF_SECOND);
  1023. }
  1024. }
  1025. return FALSE;
  1026. }
  1027. COleDateTime CXTPCalendarView::GetNextTimeEditByTAB()
  1028. {
  1029. ASSERT(GetViewDayCount() != 0);
  1030. COleDateTime dtDay;
  1031. if (m_selectedBlock.dtEnd.GetStatus() == COleDateTime::valid)
  1032. {
  1033. dtDay = m_selectedBlock.dtEnd;
  1034. }
  1035. else
  1036. {
  1037. dtDay = GetViewDayDate(0);
  1038. }
  1039. dtDay = CXTPCalendarUtils::ResetTime(dtDay);
  1040. return dtDay;
  1041. }
  1042. void CXTPCalendarView::UpdateNextTimeEditByTAB(COleDateTime dtNext, BOOL /*bReverse*/, BOOL /*bReset*/)
  1043. {
  1044. COleDateTime dtNextDay = CXTPCalendarUtils::ResetTime(dtNext);
  1045. COleDateTime dtCurrDay = CXTPCalendarUtils::ResetTime(GetNextTimeEditByTAB());
  1046. if (dtNextDay != dtCurrDay)
  1047. {
  1048. SelectDay(dtNextDay);
  1049. }
  1050. }
  1051. CXTPCalendarViewEvent* CXTPCalendarView::FindEventToEditByTAB(COleDateTime dtMinStart,
  1052. BOOL bReverse, CXTPCalendarEvent* pAfterEvent)
  1053. {
  1054. COleDateTime dtMinStartDay = CXTPCalendarUtils::ResetTime(dtMinStart);
  1055. COleDateTime dtMinStart2 = dtMinStartDay + COleDateTimeSpan(1, 0, 0, 0);
  1056. BOOL bAfterEventWas = pAfterEvent == NULL;
  1057. if (pAfterEvent)
  1058. {
  1059. COleDateTime dtAEStartDay = CXTPCalendarUtils::ResetTime(pAfterEvent->GetStartTime());
  1060. if (bReverse ? dtAEStartDay > dtMinStartDay : dtAEStartDay < dtMinStartDay)
  1061. {
  1062. bAfterEventWas = TRUE;
  1063. }
  1064. }
  1065. int nDays = GetViewDayCount();
  1066. for (int nDay = bReverse ? nDays-1 : 0; bReverse ? nDay >= 0 : nDay < nDays;
  1067. bReverse ? nDay-- : nDay++)
  1068. {
  1069. CXTPCalendarViewDay* pVDay = GetViewDay_(nDay);
  1070. if (!pVDay)
  1071. {
  1072. ASSERT(FALSE);
  1073. continue;
  1074. }
  1075. COleDateTime dtDay = pVDay->GetDayDate();
  1076. if (bReverse ? dtDay > dtMinStartDay : dtDay < dtMinStartDay)
  1077. {
  1078. continue;
  1079. }
  1080. int nGroupsCount = pVDay->GetViewGroupsCount();
  1081. for (int nGroup = bReverse ? nGroupsCount - 1 : 0;
  1082.  bReverse ? nGroup >= 0 : nGroup < nGroupsCount;
  1083.  bReverse ? nGroup-- : nGroup++)
  1084. {
  1085. CXTPCalendarViewGroup* pViewGroup = pVDay->GetViewGroup_(nGroup);
  1086. ASSERT(pViewGroup);
  1087. if (!pViewGroup)
  1088. {
  1089. continue;
  1090. }
  1091. int nEvents = pViewGroup->GetViewEventsCount();
  1092. for (int nEvent = bReverse ? nEvents - 1 : 0;
  1093.  bReverse ? nEvent >= 0 : nEvent < nEvents;
  1094.  bReverse ? nEvent-- : nEvent++)
  1095. {
  1096. CXTPCalendarViewEvent* pVEvent = pViewGroup->GetViewEvent_(nEvent);
  1097. if (!pVEvent || !pVEvent->GetEvent())
  1098. {
  1099. ASSERT(FALSE);
  1100. continue;
  1101. }
  1102. if (pAfterEvent)
  1103. {
  1104. if (pAfterEvent->IsEqualIDs(pVEvent->GetEvent()))
  1105. {
  1106. bAfterEventWas = TRUE;
  1107. continue;
  1108. }
  1109. }
  1110. COleDateTime dtES = pVEvent->GetEvent()->GetStartTime();
  1111. COleDateTime dtESDay = CXTPCalendarUtils::ResetTime(dtES);
  1112. if (bReverse ? (dtES > dtMinStart2 || dtESDay != dtDay) :
  1113. (dtES < dtMinStart || dtESDay < dtDay))
  1114. {
  1115. continue;
  1116. }
  1117. if (bAfterEventWas)
  1118. {
  1119. return pVEvent;
  1120. }
  1121. }
  1122. }
  1123. }
  1124. return NULL;
  1125. }
  1126. void CXTPCalendarView::UnselectAllEvents()
  1127. {
  1128. if (!m_pSelectedEvents || !GetCalendarControl())
  1129. {
  1130. return;
  1131. }
  1132. int nCount = m_pSelectedEvents->GetCount();
  1133. m_pSelectedEvents->RemoveAll();
  1134. if (nCount)
  1135. {
  1136. CXTPCalendarControl::CUpdateContext updateContext(GetCalendarControl(), xtpCalendarUpdateRedraw);
  1137. CSelectionChangedContext selChanged(this, xtpCalendarSelectionEvents);
  1138. }
  1139. }
  1140. void CXTPCalendarView::_ReSelectSelectEvents()
  1141. {
  1142. if (!m_pSelectedEvents)
  1143. {
  1144. return;
  1145. }
  1146. CXTPCalendarViewEventsPtr ptrSelEvents = GetSelectedEvents();
  1147. m_pSelectedEvents->RemoveAll();
  1148. if (ptrSelEvents)
  1149. {
  1150. int nCount = ptrSelEvents->GetCount();
  1151. for (int i = 0; i < nCount; i++)
  1152. {
  1153. if (ptrSelEvents->GetAt(i))
  1154. {
  1155. SelectEvent(ptrSelEvents->GetAt(i)->GetEvent());
  1156. }
  1157. }
  1158. }
  1159. }
  1160. void CXTPCalendarView::SelectDays(COleDateTime dtNewSel)
  1161. {
  1162. CXTPCalendarControl::CUpdateContext updateContext(GetCalendarControl(), xtpCalendarUpdateRedraw);
  1163. m_selectedBlock.dtEnd = dtNewSel;
  1164. CSelectionChangedContext selChanged(this, xtpCalendarSelectionDays);
  1165. }
  1166. void CXTPCalendarView::SelectDay(COleDateTime dtSelDay, int nGroupIndex)
  1167. {
  1168. CXTPCalendarControl::CUpdateContext updateContext(GetCalendarControl(), xtpCalendarUpdateRedraw);
  1169. m_selectedBlock.dtBegin = m_selectedBlock.dtEnd = dtSelDay;
  1170. m_selectedBlock.nGroupIndex = nGroupIndex;
  1171. CSelectionChangedContext selChanged(this, xtpCalendarSelectionDays);
  1172. }
  1173. void CXTPCalendarView::SelectDay(CXTPCalendarViewDay* pDay, int nGroupIndex)
  1174. {
  1175. ASSERT(pDay);
  1176. if (pDay)
  1177. {
  1178. SelectDay(pDay->GetDayDate(), nGroupIndex);
  1179. }
  1180. }
  1181. void CXTPCalendarView::SelectViewEvent(CXTPCalendarViewEvent* pViewEvent, BOOL bSelect)
  1182. {
  1183. if (!m_pSelectedEvents || !pViewEvent || !pViewEvent->GetEvent())
  1184. {
  1185. ASSERT(FALSE);
  1186. return;
  1187. }
  1188. m_pSelectedEvents->Remove(pViewEvent->GetEvent());
  1189. if (bSelect)
  1190. {
  1191. pViewEvent->InternalAddRef();
  1192. m_pSelectedEvents->Add(pViewEvent);
  1193. }
  1194. CSelectionChangedContext selChanged(this, xtpCalendarSelectionEvents);
  1195. }
  1196. CXTPCalendarViewEvent* CXTPCalendarView::GetLastSelectedViewEvent()
  1197. {
  1198. if (m_pSelectedEvents && m_pSelectedEvents->GetCount() > 0)
  1199. return m_pSelectedEvents->GetAt(m_pSelectedEvents->GetCount() - 1);
  1200. return NULL;
  1201. }
  1202. void CXTPCalendarView::SelectEvent(CXTPCalendarEvent* pEvent, BOOL bSelect)
  1203. {
  1204. if (!pEvent)
  1205. {
  1206. ASSERT(FALSE);
  1207. return;
  1208. }
  1209. int nCount = GetViewDayCount();
  1210. for (int i = 0; i < nCount; i++)
  1211. {
  1212. CXTPCalendarViewDay* pViewDay = GetViewDay_(i);
  1213. if (!pViewDay)
  1214. {
  1215. ASSERT(FALSE);
  1216. continue;
  1217. }
  1218. int nGroupsCount = pViewDay->GetViewGroupsCount();
  1219. for (int g = 0; g < nGroupsCount; g++)
  1220. {
  1221. CXTPCalendarViewGroup* pViewGroup = pViewDay->GetViewGroup_(g);
  1222. ASSERT(pViewGroup);
  1223. if (!pViewGroup)
  1224. {
  1225. continue;
  1226. }
  1227. int nECount = pViewGroup->GetViewEventsCount();
  1228. for (int j = 0; j < nECount; j++)
  1229. {
  1230. CXTPCalendarViewEvent* pViewEvent = pViewGroup->GetViewEvent_(j);
  1231. CXTPCalendarEvent* pEv = pViewEvent ? pViewEvent->GetEvent() : NULL;
  1232. ASSERT(pEv);
  1233. if (pEv && pEvent->IsEqualIDs(pEv) && pEvent->IsEqualStartEnd(pEv))
  1234. {
  1235. CXTPCalendarControl::CUpdateContext updateContext(GetCalendarControl(), xtpCalendarUpdateRedraw);
  1236. SelectViewEvent(pViewEvent, bSelect);
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. BOOL CXTPCalendarView::OnDragging(CPoint /*point*/, XTP_CALENDAR_HITTESTINFO* pHitTest)
  1243. {
  1244. ASSERT(pHitTest);
  1245. if (!pHitTest || !m_ptrDraggingEventNew || m_eDraggingMode == xtpCalendaDragModeEditSubject)
  1246. {
  1247. return FALSE;
  1248. }
  1249. //---------------------------------------------------------------------------
  1250. if (pHitTest->pViewDay)
  1251. {
  1252. if (m_eDraggingMode == xtpCalendaDragModeResizeBegin || m_eDraggingMode == xtpCalendaDragModeResizeEnd)
  1253. {
  1254. SelectDay(pHitTest->pViewDay, pHitTest->nGroup);
  1255. }
  1256. }
  1257. //---------------------------------------------------------------------------
  1258. COleDateTime dtNewTime;
  1259. if (_IsDragModeCopyMove(m_eDraggingMode))
  1260. {
  1261. if (!pHitTest->bTimePartValid)
  1262. {
  1263. dtNewTime = CXTPCalendarUtils::UpdateDate(m_ptrDraggingEventNew->GetStartTime(), pHitTest->dt);
  1264. }
  1265. else
  1266. {
  1267. dtNewTime = pHitTest->dt;
  1268. }
  1269. dtNewTime -= m_spDraggingStartOffset;
  1270. BOOL bChanged = FALSE;
  1271. //------------------------------------
  1272. if (!CXTPCalendarUtils::IsEqual(dtNewTime, m_ptrDraggingEventNew->GetStartTime()))
  1273. {
  1274. m_ptrDraggingEventNew->MoveEvent(dtNewTime);
  1275. bChanged = TRUE;
  1276. }
  1277. //***
  1278. if (bChanged)
  1279. {
  1280. return TRUE;
  1281. }
  1282. }
  1283. else if (m_eDraggingMode == xtpCalendaDragModeResizeBegin)
  1284. {
  1285. dtNewTime = pHitTest->dt;
  1286. COleDateTime dtEventEnd = m_ptrDraggingEventNew->GetEndTime();
  1287. if (!CXTPCalendarUtils::IsEqual(dtNewTime, m_ptrDraggingEventNew->GetStartTime()))
  1288. {
  1289. if (dtNewTime > dtEventEnd)
  1290. {
  1291. dtNewTime = dtEventEnd;
  1292. }
  1293. m_ptrDraggingEventNew->SetStartTime(dtNewTime);
  1294. BOOL bIsZeroStartEnd = CXTPCalendarUtils::IsZeroTime(m_ptrDraggingEventNew->GetStartTime()) &&
  1295. CXTPCalendarUtils::IsZeroTime(m_ptrDraggingEventNew->GetEndTime());
  1296. BOOL bIsZeroLen = CXTPCalendarUtils::IsEqual(m_ptrDraggingEventNew->GetStartTime(),
  1297. m_ptrDraggingEventNew->GetEndTime());
  1298. m_ptrDraggingEventNew->SetAllDayEvent(bIsZeroStartEnd && !bIsZeroLen);
  1299. return TRUE;
  1300. }
  1301. }
  1302. else if (m_eDraggingMode == xtpCalendaDragModeResizeEnd)
  1303. {
  1304. dtNewTime = pHitTest->dt;
  1305. if (!pHitTest->bTimePartValid)
  1306. {
  1307. dtNewTime += COleDateTimeSpan(1, 0, 0, 0);
  1308. }
  1309. COleDateTime dtEventStart = m_ptrDraggingEventNew->GetStartTime();
  1310. if (!CXTPCalendarUtils::IsEqual(dtNewTime, m_ptrDraggingEventNew->GetEndTime()))
  1311. {
  1312. if ((pHitTest->uHitCode & xtpCalendarHitTestDayViewTimeScale) &&
  1313. (pHitTest->pViewDay == NULL))
  1314. {
  1315. dtNewTime.SetDateTime(
  1316. dtEventStart.GetYear(), dtEventStart.GetMonth(), dtEventStart.GetDay(),
  1317. dtNewTime.GetHour(), dtNewTime.GetMinute(), dtNewTime.GetSecond());
  1318. }
  1319. if (dtNewTime < dtEventStart)
  1320. {
  1321. dtNewTime = dtEventStart;
  1322. }
  1323. m_ptrDraggingEventNew->SetEndTime(dtNewTime);
  1324. BOOL bIsZeroStartEnd = CXTPCalendarUtils::IsZeroTime(m_ptrDraggingEventNew->GetStartTime()) &&
  1325. CXTPCalendarUtils::IsZeroTime(m_ptrDraggingEventNew->GetEndTime());
  1326. BOOL bIsZeroLen = CXTPCalendarUtils::IsEqual(m_ptrDraggingEventNew->GetStartTime(),
  1327. m_ptrDraggingEventNew->GetEndTime());
  1328. m_ptrDraggingEventNew->SetAllDayEvent(bIsZeroStartEnd && !bIsZeroLen);
  1329. return TRUE;
  1330. }
  1331. }
  1332. return FALSE;
  1333. }
  1334. COleDateTime CXTPCalendarView::GetLastSelectedDate()
  1335. {
  1336. if (m_selectedBlock.dtEnd.GetStatus() != COleDateTime::valid)
  1337. {
  1338. return GetViewDayDate(GetViewDayCount() / 2);
  1339. }
  1340. return CXTPCalendarUtils::ResetTime(m_selectedBlock.dtEnd);
  1341. }
  1342. int CXTPCalendarView::FindLastSelectedDay()
  1343. {
  1344. COleDateTime dt = GetLastSelectedDate();
  1345. int nCount = GetViewDayCount();
  1346. for (int i = 0; i < nCount; i++)
  1347. {
  1348. CXTPCalendarViewDay* pViewDay = GetViewDay_(i);
  1349. ASSERT(pViewDay);
  1350. if (pViewDay && CXTPCalendarUtils::IsEqual(pViewDay->GetDayDate(), dt))
  1351. return i;
  1352. }
  1353. return -1;
  1354. }
  1355. void CXTPCalendarView::ProcessDaySelection(XTP_CALENDAR_HITTESTINFO* pInfo, UINT nFlags)
  1356. {
  1357. ASSERT(pInfo);
  1358. if (!pInfo)
  1359. {
  1360. UnselectAllEvents();
  1361. return;
  1362. }
  1363. if (nFlags & MK_SHIFT)
  1364. {
  1365. COleDateTime dtNewSelDay = GetViewDayDate(pInfo->nDay);
  1366. SelectDays(dtNewSelDay);
  1367. }
  1368. else
  1369. {
  1370. UnselectAllEvents();
  1371. ASSERT(pInfo->pViewDay);
  1372. if (pInfo->pViewDay)
  1373. {
  1374. pInfo->pViewDay->SetSelected();
  1375. }
  1376. }
  1377. }
  1378. void CXTPCalendarView::ProcessEventSelection(XTP_CALENDAR_HITTESTINFO* pInfo, UINT nFlags)
  1379. {
  1380. ASSERT(pInfo);
  1381. if (!pInfo)
  1382. {
  1383. return;
  1384. }
  1385. BOOL bUnselectEvents = !(nFlags & (MK_SHIFT | MK_CONTROL));
  1386. if (bUnselectEvents)
  1387. UnselectAllEvents();
  1388. ASSERT(pInfo->pViewDay);
  1389. ASSERT(pInfo->pViewEvent);
  1390. if (pInfo->pViewDay)
  1391. {
  1392. pInfo->pViewDay->SetSelected();
  1393. }
  1394. if (pInfo->pViewEvent)
  1395. {
  1396. BOOL bSelect = TRUE;
  1397. if (nFlags & MK_CONTROL)
  1398. {
  1399. bSelect = !pInfo->pViewEvent->IsSelected();
  1400. }
  1401. SelectEvent(pInfo->pViewEvent->GetEvent(), bSelect);
  1402. }
  1403. }
  1404. UINT CXTPCalendarView::SetTimer(UINT uTimeOut_ms)
  1405. {
  1406. if (GetCalendarControl())
  1407. {
  1408. return GetCalendarControl()->SetTimer(uTimeOut_ms);
  1409. }
  1410. return 0;
  1411. }
  1412. void CXTPCalendarView::KillTimer(UINT uTimerID)
  1413. {
  1414. if (GetCalendarControl())
  1415. {
  1416. VERIFY(GetCalendarControl()->KillTimer(uTimerID));
  1417. }
  1418. }
  1419. BOOL CXTPCalendarView::OnTimer(UINT_PTR uTimerID)
  1420. {
  1421. if (TBase::OnTimer(uTimerID))
  1422. {
  1423. return TRUE;
  1424. }
  1425. CXTPCalendarThemeOffice2007* pThemeX = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetTheme());
  1426. if (pThemeX)
  1427. {
  1428. if (pThemeX->OnTimer(uTimerID))
  1429. return TRUE;
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. if (uTimerID == m_nTimerID_StartEditSubject)
  1433. {
  1434. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - KillTimer() [CXTPCalendarView::OnTimer(ID =%d)] n"), uTimerID);
  1435. KillTimer(m_nTimerID_StartEditSubject);
  1436. m_nTimerID_StartEditSubject = 0;
  1437. ASSERT(m_ptrEditingViewEvent);
  1438. if (m_ptrEditingViewEvent)
  1439. {
  1440. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - StartEditSubject(). [CXTPCalendarView::OnTimer(ID =%d)] n"), uTimerID);
  1441. EmptyUndoBuffer();
  1442. StartEditSubject(m_ptrEditingViewEvent);
  1443. }
  1444. return TRUE;
  1445. }
  1446. else if (uTimerID == m_nKeyStateTimerID)
  1447. {
  1448. BOOL bIsCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
  1449. XTPCalendarDraggingMode eDraggingMode = bIsCtrl ? xtpCalendaDragModeCopy : xtpCalendaDragModeMove;
  1450. BOOL bPopulate = FALSE;
  1451. if (!_IsDragModeCopyMove(m_eDraggingMode))
  1452. {
  1453. KillTimer(m_nKeyStateTimerID);
  1454. m_nKeyStateTimerID = 0;
  1455. }
  1456. else if (m_eDraggingMode != eDraggingMode)
  1457. {
  1458. ASSERT(m_ptrDraggingEventNew);
  1459. if (m_ptrDraggingEventNew)
  1460. {
  1461. CXTPCalendarViewEvent* pEventView = FindViewEvent(m_ptrDraggingEventNew, m_ptrDraggingEventNew->GetStartTime());
  1462. if (!IsEditOperationDisabledNotify(_DragMod2Operation(eDraggingMode), pEventView))
  1463. {
  1464. m_eDraggingMode = eDraggingMode;
  1465. bPopulate = TRUE;
  1466. }
  1467. }
  1468. }
  1469. if (bPopulate && GetCalendarControl())
  1470. {
  1471. GetCalendarControl()->Populate();
  1472. GetCalendarControl()->m_mouseMode = m_eDraggingMode == xtpCalendaDragModeCopy ?
  1473. xtpCalendarMouseEventDragCopy : xtpCalendarMouseEventDragMove;
  1474. GetCalendarControl()->UpdateMouseCursor();
  1475. }
  1476. return TRUE;
  1477. }
  1478. else if (uTimerID == m_nTimerID_ShowToolTip)
  1479. {
  1480. ShowToolTip();
  1481. return TRUE;
  1482. }
  1483. return FALSE;
  1484. }
  1485. BOOL CXTPCalendarView::OnLButtonDblClk(UINT nFlags, CPoint point)
  1486. {
  1487. if (m_nTimerID_StartEditSubject)
  1488. {
  1489. KillTimer(m_nTimerID_StartEditSubject);
  1490. m_nTimerID_StartEditSubject = 0;
  1491. m_ptrEditingViewEvent = NULL;
  1492. }
  1493. TRACE_MOUSE(_T("OnLButtonDblClk - [CXTPCalendarView] (nFlags =%x, point.x =%d, point.y =%d) n"), nFlags, point.x, point.y);
  1494. return TBase::OnLButtonDblClk(nFlags, point);
  1495. }
  1496. void CXTPCalendarView::OnDraw(CDC* pDC)
  1497. {
  1498. if (GetTheme())
  1499. {
  1500. Draw2(pDC);
  1501. }
  1502. else
  1503. {
  1504. Draw(pDC);
  1505. }
  1506. }
  1507. void CXTPCalendarView::AdjustLayout(CDC* pDC, const CRect& rcView, BOOL bCallPostAdjustLayout)
  1508. {
  1509. UNREFERENCED_PARAMETER(pDC);
  1510. //  #pragma  NOTE("for beginning development time. uncomment later.")
  1511. //  ASSERT(!GetTheme());
  1512. m_rcView = rcView;
  1513. _CalculateEventTimeFormat();
  1514. if (bCallPostAdjustLayout)
  1515. {
  1516. OnPostAdjustLayout();
  1517. }
  1518. }
  1519. void CXTPCalendarView::AdjustLayout2(CDC* pDC, const CRect& rcView, BOOL bCallPostAdjustLayout)
  1520. {
  1521. UNREFERENCED_PARAMETER(pDC);
  1522. UNREFERENCED_PARAMETER(bCallPostAdjustLayout);
  1523. ASSERT(GetTheme());
  1524. m_rcView = rcView;
  1525. //_CalculateEventTimeFormat();
  1526. //  if (bCallPostAdjustLayout)
  1527. //  {
  1528. //      OnPostAdjustLayout();
  1529. //  }
  1530. }
  1531. CXTPCalendarViewDay* CXTPCalendarView::_GetViewDay(const COleDateTime& dt)
  1532. {
  1533. COleDateTime dtDay = CXTPCalendarUtils::ResetTime(dt);
  1534. int nDaysCount = GetViewDayCount();
  1535. if (!nDaysCount || !GetViewDay_(0))
  1536. {
  1537. return NULL;
  1538. }
  1539. COleDateTime dtDay0 = GetViewDay_(0)->GetDayDate();
  1540. COleDateTimeSpan spShift = dtDay - dtDay0;
  1541. ASSERT((double)spShift == (double)((int)(double)spShift) );
  1542. int nShift = GETTOTAL_DAYS_DTS(spShift); //(int)(double)spShift
  1543. if (nShift < 0)
  1544. {
  1545. nShift = 0;
  1546. }
  1547. if (nShift >= nDaysCount)
  1548. {
  1549. nShift = nDaysCount - 1;
  1550. }
  1551. if (nShift >= 0 && nShift < nDaysCount)
  1552. {
  1553. return GetViewDay_(nShift);
  1554. }
  1555. return NULL;
  1556. }
  1557. void CXTPCalendarView::StartEditNewEventInplace(LPCTSTR pcszInitialSubject)
  1558. {
  1559. if (m_ptrDraggingEventOrig || m_ptrDraggingEventNew || IsEditingSubject())
  1560. {
  1561. MessageBeep(0);
  1562. return;
  1563. }
  1564. BOOL bAllDayEvent = FALSE;
  1565. //---------------------------------------------------------------------------
  1566. COleDateTime dtSelBegin, dtSelEnd;
  1567. int nGroup = 0;
  1568. if (!GetSelection(&dtSelBegin, &dtSelEnd, &bAllDayEvent, &nGroup))
  1569. {
  1570. return;
  1571. }
  1572. //---------------------------------------------------------------------------
  1573. CXTPCalendarData* pData = NULL; //XTP_SAFE_GET1(GetCalendarControl(), GetDataProvider(), NULL);
  1574. CXTPCalendarViewDay* pViewDay = _GetViewDay(dtSelBegin);
  1575. if (!pViewDay)
  1576. {
  1577. return;
  1578. }
  1579. CXTPCalendarViewGroup* pViewGroup = NULL;
  1580. if (pViewDay && nGroup < pViewDay->GetViewGroupsCount() )
  1581. {
  1582. pViewGroup = pViewDay->GetViewGroup_(nGroup);
  1583. pData = pViewGroup ? pViewGroup->GetDataProvider() : NULL;
  1584. }
  1585. //--------------------
  1586. m_ptrDraggingEventNew = pData ? pData->CreateNewEvent() : NULL;
  1587. if (!m_ptrDraggingEventNew)
  1588. {
  1589. return;
  1590. }
  1591. //---------------------------------------------------------------------------
  1592. UINT uScheduleID = XTP_SAFE_GET1(pViewGroup, GetScheduleID(), 0);
  1593. m_ptrDraggingEventNew->SetScheduleID(uScheduleID);
  1594. m_ptrDraggingEventNew->SetStartTime(min(dtSelBegin, dtSelEnd));
  1595. m_ptrDraggingEventNew->SetEndTime(max(dtSelBegin, dtSelEnd));
  1596. m_ptrDraggingEventNew->SetBusyStatus(bAllDayEvent ? xtpCalendarBusyStatusFree : xtpCalendarBusyStatusBusy);
  1597. m_ptrDraggingEventNew->SetAllDayEvent(bAllDayEvent);
  1598. //===========================================================================
  1599. XTP_SAFE_CALL1(GetCalendarControl(), Populate());
  1600. XTP_SAFE_CALL1(GetCalendarControl(), AdjustLayout());
  1601. //---------------------------------------------------------------------------
  1602. COleDateTime dtEventDay = m_ptrDraggingEventNew->GetStartTime();
  1603. dtEventDay = CXTPCalendarUtils::ResetTime(dtEventDay);
  1604. CXTPCalendarViewEvent* pViewEvent = FindViewEvent(m_ptrDraggingEventNew, dtEventDay);
  1605. if (!pViewEvent)
  1606. {
  1607. CancelDraggingEvent();
  1608. return;
  1609. }
  1610. StartEditSubject(pViewEvent);
  1611. CEdit* pEditor = DYNAMIC_DOWNCAST(CEdit, pViewEvent->GetSubjectEditor());
  1612. if (pEditor)
  1613. {
  1614. pEditor->SetWindowText(pcszInitialSubject);
  1615. int nInitTxtLen = (int)_tcsclen(pcszInitialSubject);
  1616. pEditor->SetSel(nInitTxtLen, nInitTxtLen);
  1617. }
  1618. }
  1619. void CXTPCalendarView::StartEditSubject(CXTPCalendarViewEvent* pViewEvent)
  1620. {
  1621. if (!pViewEvent)
  1622. {
  1623. ASSERT(FALSE);
  1624. return;
  1625. }
  1626. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - StartEditSubject(). [CXTPCalendarView] n"));
  1627. //---------------------------------------------------------------------------
  1628. if (m_nTimerID_StartEditSubject)
  1629. {
  1630. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - KillTimer() [CXTPCalendarView::StartEditSubject] n"));
  1631. KillTimer(m_nTimerID_StartEditSubject);
  1632. m_nTimerID_StartEditSubject = 0;
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. m_ptrEditingViewEvent = pViewEvent->StartEditSubject();
  1636. if (!m_ptrEditingViewEvent)
  1637. {
  1638. ASSERT(FALSE);
  1639. return;
  1640. }
  1641. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateRedraw);
  1642. m_ptrEditingViewEvent->InternalAddRef();
  1643. m_eDraggingMode = xtpCalendaDragModeEditSubject;
  1644. if (!m_ptrDraggingEventOrig && !m_ptrDraggingEventNew)
  1645. {
  1646. SetDraggingEvent(m_ptrEditingViewEvent->GetEvent());
  1647. }
  1648. SelectEvent(m_ptrDraggingEventNew);
  1649. }
  1650. void CXTPCalendarView::EndEditSubject(XTPCalendarEndEditSubjectAction eAction, BOOL bUpdateControl)
  1651. {
  1652. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(). [CXTPCalendarView] n"));
  1653. m_eDraggingMode = xtpCalendaDragModeUnknown;
  1654. // kill timeout request to edit subject
  1655. if (m_nTimerID_StartEditSubject)
  1656. {
  1657. ASSERT(m_ptrEditingViewEvent && !m_ptrDraggingEventOrig && !m_ptrDraggingEventNew);
  1658. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - KillTimer() [CXTPCalendarView::EndEditSubject] n"));
  1659. KillTimer(m_nTimerID_StartEditSubject);
  1660. m_nTimerID_StartEditSubject = 0;
  1661. m_ptrEditingViewEvent = NULL;
  1662. return;
  1663. }
  1664. ASSERT(m_ptrEditingViewEvent && m_ptrDraggingEventNew);
  1665. CXTPCalendarEventPtr ptrEventToSelect(m_ptrDraggingEventNew, TRUE);
  1666. BOOL bPopulate = FALSE;
  1667. CString strNewSubject;
  1668. //- end edit subject operation in Event view (kill edit wnd) ----------------
  1669. if (m_ptrEditingViewEvent)
  1670. {
  1671. strNewSubject = m_ptrEditingViewEvent->EndEditSubject();
  1672. }
  1673. m_ptrEditingViewEvent = NULL;
  1674. //---------------------------------------------------------------------------
  1675. if (m_ptrDraggingEventNew)
  1676. {
  1677. if (eAction == xtpCalendarEditSubjectCommit)
  1678. {
  1679. m_ptrDraggingEventNew->SetSubject(strNewSubject);
  1680. bPopulate = CommitDraggingEvent();
  1681. TRACE_DRAGGING(_T("Dragging - CommitDraggingEvent() = %d. [CXTPCalendarView::EndEditSubject] n"), bPopulate);
  1682. }
  1683. else
  1684. if (eAction == xtpCalendarEditSubjectCancel)
  1685. {
  1686. TRACE_DRAGGING(_T("Dragging - CancelDraggingEvent. [CXTPCalendarView::EndEditSubject] n"));
  1687. ptrEventToSelect.SetPtr(m_ptrDraggingEventOrig, TRUE);
  1688. CancelDraggingEvent();
  1689. bPopulate = TRUE;
  1690. }
  1691. else
  1692. {
  1693. ASSERT(FALSE);
  1694. }
  1695. }
  1696. if (bUpdateControl && bPopulate && GetCalendarControl())
  1697. {
  1698. GetCalendarControl()->Populate();
  1699. if (ptrEventToSelect)
  1700. {
  1701. SelectEvent(ptrEventToSelect, TRUE);
  1702. }
  1703. }
  1704. }
  1705. void CXTPCalendarView::OnUpdateEditingSubject(CString strNewSubject)
  1706. {
  1707. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - OnUpdateEditingSubject('%s'). [CXTPCalendarView] n"), strNewSubject);
  1708. ASSERT(m_ptrEditingViewEvent && m_ptrDraggingEventNew);
  1709. if (m_ptrEditingViewEvent && m_ptrDraggingEventNew)
  1710. {
  1711. m_ptrDraggingEventNew->SetSubject(strNewSubject);
  1712. }
  1713. }
  1714. CRect CXTPCalendarView::GetSubjectEditorRect() const
  1715. {
  1716. ASSERT(m_ptrEditingViewEvent);
  1717. if (m_ptrEditingViewEvent)
  1718. {
  1719. return m_ptrEditingViewEvent->GetSubjectEditorRect();
  1720. }
  1721. return CRect(INT_MAX, INT_MAX, INT_MAX, INT_MAX);
  1722. }
  1723. CRect CXTPCalendarView::GetTooltipRect(const CPoint& ptHit, const XTP_CALENDAR_HITTESTINFO& hitInfo)
  1724. {
  1725. CRect rcTip;
  1726. rcTip.SetRectEmpty();
  1727. if (hitInfo.pViewGroup)
  1728. {
  1729. rcTip = hitInfo.pViewGroup->GetTooltipRect(ptHit, hitInfo);
  1730. CXTPCalendarThemeOffice2007* pThemeX = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetTheme());
  1731. if (pThemeX)
  1732. {
  1733. CRect rcExclude = XTP_SAFE_GET2(pThemeX->GetPrevNextEventControllerPartX(),
  1734. GetNextEventButtonPartX(), GetRect(), CRect(0, 0, 0, 0));
  1735. if (!(rcTip.top > rcExclude.bottom || rcTip.bottom < rcExclude.top) &&
  1736. rcTip.right >= rcExclude.left)
  1737. {
  1738. rcTip.right = rcExclude.left - 1;
  1739. }
  1740. rcExclude = XTP_SAFE_GET2(pThemeX->GetPrevNextEventControllerPartX(),
  1741. GetPrevEventButtonPartX(), GetRect(), CRect(0, 0, 0, 0));
  1742. if (!(rcTip.top > rcExclude.bottom || rcTip.bottom < rcExclude.top) &&
  1743. rcTip.left <= rcExclude.right)
  1744. {
  1745. rcTip.left = rcExclude.right + 1;
  1746. }
  1747. }
  1748. }
  1749. return rcTip;
  1750. }
  1751. void CXTPCalendarView::ShowToolTip(BOOL bShow)
  1752. {
  1753. if (m_nTimerID_ShowToolTip)
  1754. {
  1755. KillTimer(m_nTimerID_ShowToolTip);
  1756. m_nTimerID_ShowToolTip = 0;
  1757. }
  1758. if (!bShow)
  1759. {
  1760. // hide a tooltip
  1761. GetCalendarControl()->HideToolTip();
  1762. return;
  1763. }
  1764. if (GetCalendarControl()->IsToolTipVisible())
  1765. {
  1766. return;
  1767. }
  1768. // Verify whether mouse is still under tooltip rect
  1769. CRect rcTooltip;
  1770. rcTooltip.SetRectEmpty();
  1771. CPoint pt;
  1772. GetCursorPos(&pt);
  1773. GetCalendarControl()->ScreenToClient(&pt);
  1774. XTP_CALENDAR_HITTESTINFO hitInfo;
  1775. BOOL bHitTest = HitTest(pt, &hitInfo);
  1776. if (bHitTest)
  1777. {
  1778. rcTooltip = GetTooltipRect(pt, hitInfo);
  1779. }
  1780. if (m_rcTooltip != rcTooltip)
  1781. m_rcTooltip.SetRectEmpty();
  1782. if (m_rcTooltip.IsRectEmpty())
  1783. return;
  1784. // if we are under event view -- do not show this tooltip
  1785. if (NULL != hitInfo.pViewEvent)
  1786. return;
  1787. // Verify whether tooltip option is enabled
  1788. BOOL bTipEnabled = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), bEnableAddNewTooltip, TRUE);
  1789. if (!bTipEnabled)
  1790. return;
  1791. // create tooltip text
  1792. CString strTip = XTP_SAFE_GET2(GetCalendarControl(), GetCalendarOptions(), strTooltipAddNewText, _T("Click to add appointment"));
  1793. // show tooltip window
  1794. CXTPCalendarControl* pCal = GetCalendarControl();
  1795. if (pCal)
  1796. {
  1797. CFont* pFont = &XTP_SAFE_GET2(GetPaintManager(), GetDayViewEventPart(), GetTextFont(), *((CFont*)(NULL)));
  1798. pCal->ShowToolTip(strTip, m_rcTooltip, pFont, TRUE);
  1799. }
  1800. }
  1801. void CXTPCalendarView::_CalculateEventTimeFormat()
  1802. {
  1803. ////////////////////////////////////////////////////////////////////////////
  1804. //  LOCALE_STIME    // time separator
  1805. //
  1806. //  LOCALE_ITLZERO  //leading zeros in time field
  1807. //      0 No leading zeros for hours.
  1808. //      1 Leading zeros for hours.
  1809. //
  1810. //  LOCALE_ITIME    // time format specifier
  1811. //      0 AM / PM 12-hour format.
  1812. //      1 24-hour format.
  1813. //
  1814. //  LOCALE_ITIMEMARKPOSN    // time marker position
  1815. //      0 Use as suffix.
  1816. //      1 Use as prefix.
  1817. //
  1818. //  LOCALE_S1159    // AM designator
  1819. //  LOCALE_S2359    // PM designator
  1820. ////////////////////////////////////////////////////////////////////////////
  1821. CString strTmp;
  1822. CString strTimeSeparator = CXTPCalendarUtils::GetLocaleString(LOCALE_STIME, 16);
  1823. strTmp = CXTPCalendarUtils::GetLocaleString(LOCALE_ITIME, 16);
  1824. BOOL b24_HFormat = _ttoi(strTmp) == 1;
  1825. strTmp = CXTPCalendarUtils::GetLocaleString(LOCALE_ITLZERO, 16);
  1826. BOOL bH_LZero = _ttoi(strTmp) == 1;
  1827. strTmp = CXTPCalendarUtils::GetLocaleString(LOCALE_ITIMEMARKPOSN, 16);
  1828. BOOL bAM_PM_Prefix = _ttoi(strTmp) == 1;
  1829. //---------------------------------------------------------------------------
  1830. CString strTimeFormat;
  1831. strTimeFormat += strTimeSeparator;
  1832. strTimeFormat += _T("mm");
  1833. if (b24_HFormat)
  1834. {
  1835. strTmp = bH_LZero ? _T("HH") : _T("H");
  1836. strTimeFormat = strTmp + strTimeFormat;
  1837. }
  1838. else //12 AM/PM Format
  1839. {
  1840. strTmp = bH_LZero ? _T("hh") : _T("h");
  1841. strTimeFormat = strTmp + strTimeFormat;
  1842. if (bAM_PM_Prefix)
  1843. {
  1844. strTimeFormat = _T("tt ") + strTimeFormat;
  1845. }
  1846. else
  1847. {
  1848. strTimeFormat = strTimeFormat + _T("tt");
  1849. }
  1850. }
  1851. //---------------------------------------------------------------------------
  1852. m_EventTimeFormat.strFormat = strTimeFormat;
  1853. m_EventTimeFormat.b24_HFormat = b24_HFormat;
  1854. m_EventTimeFormat.strAM = CXTPCalendarUtils::GetLocaleString(LOCALE_S1159, 20);
  1855. m_EventTimeFormat.strPM = CXTPCalendarUtils::GetLocaleString(LOCALE_S2359, 20);
  1856. }
  1857. CString CXTPCalendarView::FormatEventTime(COleDateTime dtTime)
  1858. {
  1859. CString strTime;
  1860. SYSTEMTIME st;
  1861. ZeroMemory(&st, sizeof(st));
  1862. if (GETASSYSTEMTIME_DT(dtTime, st))
  1863. {
  1864. strTime = CXTPCalendarUtils::GetTimeFormat(&st, m_EventTimeFormat.strFormat);
  1865. }
  1866. if (strTime.IsEmpty())
  1867. {
  1868. ASSERT(FALSE);
  1869. strTime.Format(_T("%d:%02d"), dtTime.GetHour(), dtTime.GetMinute());
  1870. }
  1871. //- make AM/PM as lower case ---------------------------------------
  1872. if (!m_EventTimeFormat.b24_HFormat)
  1873. {
  1874. CString strAM_lower = m_EventTimeFormat.strAM;
  1875. CString strPM_lower = m_EventTimeFormat.strPM;
  1876. strAM_lower.MakeLower();
  1877. strPM_lower.MakeLower();
  1878. REPLACE_S(strTime, m_EventTimeFormat.strAM, strAM_lower);
  1879. REPLACE_S(strTime, m_EventTimeFormat.strPM, strPM_lower);
  1880. }
  1881. return strTime;
  1882. }
  1883. CString CXTPCalendarView::GetItemTextEventTimeMax()
  1884. {
  1885. COleDateTime dtTestTime;
  1886. dtTestTime.SetTime(23, 59, 59);
  1887. CString strTime = FormatEventTime(dtTestTime);
  1888. DWORD dwFlags = GetCalendarControl()->GetAskItemTextFlags();
  1889. if (dwFlags & (xtpCalendarItemText_EventStartTimeText | xtpCalendarItemText_EventEndTimeText))
  1890. {
  1891. XTP_CALENDAR_GETITEMTEXT_PARAMS objRequest;
  1892. ::ZeroMemory(&objRequest, sizeof(objRequest));
  1893. objRequest.nItem = xtpCalendarItemText_EventStartTimeText /*| xtpCalendarItemText_EventEndTimeText*/;
  1894. objRequest.pstrText = &strTime;
  1895. GetCalendarControl()->SendNotificationAlways(XTP_NC_CALENDAR_GETITEMTEXT, (WPARAM)&objRequest, 0);
  1896. }
  1897. return strTime;
  1898. }
  1899. BOOL CXTPCalendarView::_Undo(CXTPCalendarEvent* pEvent)
  1900. {
  1901. if (IsEditingSubject())
  1902. {
  1903. TRACE_EDIT_SUBJECT(_T("Edit SUBJECT - EndEditSubject(). [CXTPCalendarView::OnKeyDown] n"));
  1904. EndEditSubject(xtpCalendarEditSubjectCommit);
  1905. }
  1906. if (!GetCalendarControl())
  1907. {
  1908. return FALSE;
  1909. }
  1910. CXTPAutoResetValue<BOOL> autoSet_UpdateCtrlNf(GetCalendarControl()->m_bUpdateWhenEventChangedNotify);
  1911. autoSet_UpdateCtrlNf = FALSE;
  1912. //---------------------------------------------------------------------------
  1913. CXTPCalendarEventPtr ptrEventNew;
  1914. CXTPCalendarEventPtr ptrEventOld;
  1915. if (pEvent)
  1916. {
  1917. ptrEventNew = m_UndoBuffer.UndoAllForEvent(pEvent);
  1918. ptrEventOld = m_UndoBuffer.RedoAllForEvent(pEvent);
  1919. }
  1920. else
  1921. {
  1922. CXTPCalendarEventPtr ptrUndoEvent = m_UndoBuffer.GetFirstUndoEvent();
  1923. if (ptrUndoEvent)
  1924. {
  1925. if (m_eUndoMode == xtpCalendarUndoModeUndo)
  1926. {
  1927. ptrEventNew = m_UndoBuffer.UndoAllForEvent(ptrUndoEvent);
  1928. ptrEventOld = m_UndoBuffer.RedoAllForEvent(ptrUndoEvent);
  1929. m_eUndoMode = xtpCalendarUndoModeRedo;
  1930. }
  1931. else
  1932. if (m_eUndoMode == xtpCalendarUndoModeRedo)
  1933. {
  1934. ptrEventNew = m_UndoBuffer.RedoAllForEvent(ptrUndoEvent);
  1935. ptrEventOld = m_UndoBuffer.UndoAllForEvent(ptrUndoEvent);
  1936. m_eUndoMode = xtpCalendarUndoModeUndo;
  1937. }
  1938. else
  1939. {
  1940. ASSERT(FALSE);
  1941. return FALSE;
  1942. }
  1943. }
  1944. }
  1945. //---------------------------------------------------------------------------
  1946. if (ptrEventNew || ptrEventOld)
  1947. {
  1948. CXTPCalendarControl::CUpdateContext updateContext(m_pControl, xtpCalendarUpdateLayout | xtpCalendarUpdateRedraw);
  1949. if (ptrEventNew && ptrEventOld && ptrEventNew->GetDataProvider())
  1950. {
  1951. VERIFY( ptrEventNew->GetDataProvider()->ChangeEvent(ptrEventNew) );
  1952. }
  1953. else if (ptrEventNew && !ptrEventOld && ptrEventNew->GetDataProvider())
  1954. {
  1955. VERIFY( ptrEventNew->GetDataProvider()->AddEvent(ptrEventNew) );
  1956. }
  1957. else if (!ptrEventNew && ptrEventOld && ptrEventOld->GetDataProvider())
  1958. {
  1959. VERIFY( ptrEventOld->GetDataProvider()->DeleteEvent(ptrEventOld) );
  1960. }
  1961. XTP_SAFE_CALL1(GetCalendarControl(), Populate());
  1962. return TRUE;
  1963. }
  1964. return FALSE;
  1965. }
  1966. BOOL CXTPCalendarView::CanUndo()
  1967. {
  1968. if (m_eUndoMode == xtpCalendarUndoModeUndo && m_UndoBuffer.GetCount())
  1969. {
  1970. return TRUE;
  1971. }
  1972. return _CanSubjectEditor(ID_EDIT_UNDO);
  1973. }
  1974. CWnd* CXTPCalendarView::_GetSubjectEditorWnd()
  1975. {
  1976. if (m_ptrEditingViewEvent)
  1977. {
  1978. return m_ptrEditingViewEvent->GetSubjectEditor();
  1979. }
  1980. return NULL;
  1981. }
  1982. BOOL CXTPCalendarView::_CanSubjectEditor(UINT idEditCmd)
  1983. {
  1984. CWnd* pSEditorWnd = _GetSubjectEditorWnd();
  1985. if (!pSEditorWnd)
  1986. {
  1987. return FALSE;
  1988. }
  1989. CEdit* pSEditor = DYNAMIC_DOWNCAST(CEdit, pSEditorWnd);
  1990. if (!pSEditor)
  1991. {
  1992. return FALSE;
  1993. }
  1994. BOOL bSEFocused = CWnd::GetFocus() &&
  1995. CWnd::GetFocus()->GetSafeHwnd() == pSEditorWnd->GetSafeHwnd();
  1996. if (!bSEFocused)
  1997. {
  1998. return FALSE;
  1999. }
  2000. int nSel1 = -1, nSel2 = -1;
  2001. pSEditor->GetSel(nSel1, nSel2);
  2002. switch (idEditCmd)
  2003. {
  2004. case ID_EDIT_UNDO:
  2005. return pSEditor->CanUndo();
  2006. case ID_EDIT_CUT:
  2007. return nSel1 < nSel2;
  2008. case ID_EDIT_COPY:
  2009. return nSel1 < nSel2;
  2010. case ID_EDIT_PASTE:
  2011. return ::IsClipboardFormatAvailable(CF_TEXT);
  2012. }
  2013. return FALSE;
  2014. }
  2015. BOOL CXTPCalendarView::CanRedo()
  2016. {
  2017. return m_eUndoMode == xtpCalendarUndoModeRedo && m_UndoBuffer.GetCount();
  2018. }
  2019. BOOL CXTPCalendarView::Undo()
  2020. {
  2021. ASSERT(m_eUndoMode == xtpCalendarUndoModeUndo || _CanSubjectEditor(ID_EDIT_UNDO));
  2022. return _Undo();
  2023. }
  2024. BOOL CXTPCalendarView::Redo()
  2025. {
  2026. ASSERT(m_eUndoMode == xtpCalendarUndoModeRedo);
  2027. return _Undo();
  2028. }
  2029. CString CXTPCalendarView::_GetMaxWidthFormat(CDC* pDC, CString strFormat, BOOL bMonth)
  2030. {
  2031. if (!pDC)
  2032. {
  2033. ASSERT(FALSE);
  2034. return _T("");
  2035. }
  2036. SYSTEMTIME st;
  2037. ZeroMemory(&st, sizeof(st));
  2038. st.wDay = 20;
  2039. st.wMonth = 1;
  2040. st.wYear = (WORD)CXTPCalendarUtils::GetCurrentTime().GetYear();
  2041. int nMax = 0;
  2042. CString str;
  2043. int nCount = bMonth ? 12 : 7;
  2044. for (int i = 0; i < nCount; i++)
  2045. {
  2046. CString strResult = CXTPCalendarUtils::GetDateFormat(&st, strFormat);
  2047. int nLen = pDC->GetTextExtent(strResult).cx;
  2048. if (nMax < nLen)
  2049. {
  2050. str = strResult;
  2051. nMax = nLen;
  2052. }
  2053. if (bMonth)
  2054. st.wMonth++;
  2055. else
  2056. st.wDay++;
  2057. }
  2058. return str;
  2059. }
  2060. int CXTPCalendarView::_GetMaxWidth(CDC* pDC, CString strFormat)
  2061. {
  2062. if (!pDC)
  2063. {
  2064. ASSERT(FALSE);
  2065. return 1;
  2066. }
  2067. const TCHAR* chFormats[] =
  2068. {
  2069. _T("yyyy"), _T("yyy"), _T("yy"), _T("y"),
  2070. _T("MMMM"), _T("MMM"),
  2071. _T("dddd"), _T("ddd"), _T("dd"), _T("d")
  2072. };
  2073. for (int i = 0; i < _countof(chFormats); i++)
  2074. {
  2075. int nPos = strFormat.Find(chFormats[i]);
  2076. if (nPos >= 0)
  2077. {
  2078. REPLACE_S(strFormat, chFormats[i], _GetMaxWidthFormat(pDC, chFormats[i], i < 2));
  2079. }
  2080. }
  2081. return pDC->GetTextExtent(strFormat).cx;
  2082. }
  2083. void CXTPCalendarView::_RemoveYearPart(CString& strFormat)
  2084. {
  2085. int nStartPos = -1, nEndPos = -1, i;
  2086. BOOL bBracket = FALSE;
  2087. for (i = 0; i < strFormat.GetLength(); i++)
  2088. {
  2089. TCHAR ch = strFormat[i];
  2090. if (ch == _T('''))
  2091. bBracket = !bBracket;
  2092. if (bBracket)
  2093. continue;
  2094. if (ch == _T('m') || ch == _T('M') || ch == _T('D') || ch == _T('d'))
  2095. {
  2096. if (nStartPos == -1)
  2097. nStartPos = i;
  2098. nEndPos = i;
  2099. }
  2100. }
  2101. if (nStartPos != -1 && nEndPos > nStartPos)
  2102. {
  2103. strFormat = strFormat.Mid(nStartPos, nEndPos - nStartPos + 1);
  2104. }
  2105. }
  2106. void CXTPCalendarView::_ReadDefaultHeaderFormats()
  2107. {
  2108. m_strDayHeaderFormatDefaultLong = CXTPCalendarUtils::GetLocaleString(LOCALE_SLONGDATE, 81);
  2109. _RemoveYearPart(m_strDayHeaderFormatDefaultLong);
  2110. m_strDayHeaderFormatDefaultMiddle = m_strDayHeaderFormatDefaultLong;
  2111. REPLACE_S(m_strDayHeaderFormatDefaultMiddle, _T("MMMM"), _T("MMM"));
  2112. m_strDayHeaderFormatDefaultShort = m_strDayHeaderFormatDefaultMiddle;
  2113. REPLACE_S(m_strDayHeaderFormatDefaultShort, _T("dddd"), _T("ddd"));
  2114. m_strDayHeaderFormatDefaultShortest = CXTPCalendarUtils::GetLocaleString(LOCALE_SSHORTDATE, 81);
  2115. _RemoveYearPart(m_strDayHeaderFormatDefaultShortest);
  2116. }
  2117. // nLevel = 0 - Long, 1 - Middle, 2 - Short, 3 - Shortest.
  2118. CString CXTPCalendarView::_GetDayHeaderFormat(int nLevel)
  2119. {
  2120. switch (nLevel)
  2121. {
  2122. case 0:
  2123. return m_strDayHeaderFormatLong.IsEmpty() ? m_strDayHeaderFormatDefaultLong : m_strDayHeaderFormatLong;
  2124. case 1:
  2125. return m_strDayHeaderFormatMiddle.IsEmpty() ? m_strDayHeaderFormatDefaultMiddle : m_strDayHeaderFormatMiddle;
  2126. case 2:
  2127. return m_strDayHeaderFormatShort.IsEmpty() ? m_strDayHeaderFormatDefaultShort : m_strDayHeaderFormatShort;
  2128. case 3:
  2129. return m_strDayHeaderFormatShortest.IsEmpty() ? m_strDayHeaderFormatDefaultShortest : m_strDayHeaderFormatShortest;
  2130. }
  2131. ASSERT(FALSE);
  2132. return _T("");
  2133. }
  2134. void CXTPCalendarView::CalculateHeaderFormat(CDC* pDC, int nWidth, CFont* pTextFont)
  2135. {
  2136. if (!GetCalendarControl() || !pTextFont || !pDC)
  2137. {
  2138. ASSERT(FALSE);
  2139. return;
  2140. }
  2141. _ReadDefaultHeaderFormats();
  2142. CXTPFontDC fnt(pDC, pTextFont);
  2143. int arBorder[] = {40, 35, 20, 0};
  2144. for (int i = 0; i <= 3; i++)
  2145. {
  2146. m_strHeaderFormat = _GetDayHeaderFormat(i);
  2147. int nLen = _GetMaxWidth(pDC, m_strHeaderFormat);
  2148. if (nLen < nWidth - arBorder[i])
  2149. {
  2150. return;
  2151. }
  2152. }
  2153. }
  2154. COleDateTimeSpan CXTPCalendarView::GetEventDurationMin() const
  2155. {
  2156. return COleDateTimeSpan(0.);
  2157. }
  2158. BOOL CXTPCalendarView::CanCut()
  2159. {
  2160. return !IsEditingSubject() && HasSelectedViewEvent() ||
  2161. IsEditingSubject() && _CanSubjectEditor(ID_EDIT_CUT);
  2162. }
  2163. BOOL CXTPCalendarView::CanCopy()
  2164. {
  2165. return !IsEditingSubject() && HasSelectedViewEvent() ||
  2166. IsEditingSubject() && _CanSubjectEditor(ID_EDIT_COPY);
  2167. }
  2168. BOOL CXTPCalendarView::CanPaste()
  2169. {
  2170. if (!GetSelection())
  2171. {
  2172. return FALSE;
  2173. }
  2174. //- Register or get existing Clipboard Format ID -------------------------
  2175. UINT uCF_Event = ::RegisterClipboardFormat(XTPCALENDARCTRL_CF_EVENT);
  2176. BOOL bIsEventInClipboard = ::IsClipboardFormatAvailable(uCF_Event);
  2177. return !IsEditingSubject() && bIsEventInClipboard ||
  2178. IsEditingSubject() && _CanSubjectEditor(ID_EDIT_PASTE);
  2179. }
  2180. BOOL CXTPCalendarView::Cut()
  2181. {
  2182. if (IsEditingSubject() && _GetSubjectEditorWnd())
  2183. {
  2184. if (CanCut())
  2185. {
  2186. _GetSubjectEditorWnd()->SendMessage(WM_CUT);
  2187. return TRUE;
  2188. }
  2189. return FALSE;
  2190. }
  2191. //===========================================================================
  2192. CXTPCalendarViewEventsPtr ptrSelViews = GetSelectedEvents();
  2193. if (!ptrSelViews || !ptrSelViews->GetCount())
  2194. {
  2195. return FALSE;
  2196. }
  2197. if (OnBeforeEditOperationNotify(xtpCalendarEO_Cut, ptrSelViews))
  2198. {
  2199. return FALSE;
  2200. }
  2201. //------------------------------------------------------------------------
  2202. DWORD dwCopyFlags = xtpCalendarCopyFlagCutMask;
  2203. COleDataSource* pData = _CopySelectedEvents(dwCopyFlags);
  2204. if (!pData)
  2205. {
  2206. return FALSE;
  2207. }
  2208. pData->SetClipboard();
  2209. //------------------------------------------------------------------------
  2210. int nCount = ptrSelViews->GetCount();
  2211. for (int i = 0; i < nCount; i++)
  2212. {
  2213. CXTPCalendarViewEvent* pViewEvent = ptrSelViews->GetAt(i, FALSE);
  2214. CXTPCalendarEvent* pEvent = pViewEvent ? pViewEvent->GetEvent() : NULL;
  2215. VERIFY( XTP_SAFE_GET2(pEvent, GetDataProvider(), DeleteEvent(pEvent), FALSE) );
  2216. }
  2217. XTP_SAFE_CALL1(GetCalendarControl(), Populate());
  2218. //---------------------------------------------------------------------------
  2219. return TRUE;
  2220. }
  2221. BOOL CXTPCalendarView::Copy()
  2222. {
  2223. if (IsEditingSubject() && _GetSubjectEditorWnd())
  2224. {
  2225. if (CanCopy())
  2226. {
  2227. _GetSubjectEditorWnd()->SendMessage(WM_COPY);
  2228. return TRUE;
  2229. }
  2230. return FALSE;
  2231. }
  2232. //---------------------------------------------------------------------------
  2233. CXTPCalendarViewEventsPtr ptrSelViews = GetSelectedEvents();
  2234. if (!ptrSelViews || !ptrSelViews->GetCount())
  2235. {
  2236. return FALSE;
  2237. }
  2238. if (OnBeforeEditOperationNotify(xtpCalendarEO_Copy, ptrSelViews))
  2239. {
  2240. return FALSE;
  2241. }
  2242. //===========================================================================
  2243. COleDataSource* pData = _CopySelectedEvents();
  2244. if (!pData)
  2245. {
  2246. return FALSE;
  2247. }
  2248. pData->SetClipboard();
  2249. return TRUE;
  2250. }
  2251. BOOL CXTPCalendarView::Paste()
  2252. {
  2253. if (IsEditingSubject() && _GetSubjectEditorWnd())
  2254. {
  2255. if (CanPaste())
  2256. {
  2257. _GetSubjectEditorWnd()->SendMessage(WM_PASTE);
  2258. return TRUE;
  2259. }
  2260. return FALSE;
  2261. }
  2262. //===========================================================================
  2263. COleDateTime dtSelBegin, dtSelEnd;
  2264. COleDateTimeSpan spSelectionResolution;
  2265. if (!GetSelection(&dtSelBegin, &dtSelEnd, NULL, NULL, &spSelectionResolution))
  2266. {
  2267. return FALSE;
  2268. }
  2269. dtSelBegin = min(dtSelBegin, dtSelEnd);
  2270. // Attach a COleDataObject to the clipboard and paste the data
  2271. COleDataObject objData;
  2272. if (!objData.AttachClipboard())
  2273. {
  2274. return FALSE;
  2275. }
  2276. DWORD dwCopyFlags = 0;
  2277. CXTPCalendarEventsPtr ptrEventsFromCB = _ReadEventsFromClipboard(&objData, &dwCopyFlags);
  2278. if (!ptrEventsFromCB)
  2279. {
  2280. return FALSE;
  2281. }
  2282. if (!GetCalendarControl())
  2283. {
  2284. return FALSE;
  2285. }
  2286. CXTPAutoResetValue<BOOL> autoSet_UpdateCtrlNf(GetCalendarControl()->m_bUpdateWhenEventChangedNotify);
  2287. autoSet_UpdateCtrlNf = FALSE;
  2288. //---------------------------------------------------------------------------
  2289. COleDateTimeSpan spStartShift;
  2290. int nCount = ptrEventsFromCB->GetCount();
  2291. for (int i = 0; i < nCount; i++)
  2292. {
  2293. BOOL bUseChangeEvent = FALSE;
  2294. CXTPCalendarEvent* pNewEvent = ptrEventsFromCB->GetAt(i, FALSE);
  2295. if (!pNewEvent)
  2296. {
  2297. ASSERT(FALSE);
  2298. continue;
  2299. }
  2300. int nRState = pNewEvent->GetRecurrenceState();
  2301. if (nRState == xtpCalendarRecurrenceMaster)
  2302. {
  2303. ASSERT(FALSE); // WARNING. Master event in the clipboard - ???
  2304. VERIFY(pNewEvent->RemoveRecurrence());
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. if (nRState == xtpCalendarRecurrenceOccurrence &&
  2308. dwCopyFlags & xtpCalendarCopyFlagROccurrence2RException)
  2309. {
  2310. VERIFY(pNewEvent->MakeAsRException());
  2311. bUseChangeEvent = TRUE;
  2312. }
  2313. else
  2314. {
  2315. VERIFY(pNewEvent->RemoveRecurrence());
  2316. }
  2317. // Update recurrence state
  2318. nRState = pNewEvent->GetRecurrenceState();
  2319. //---------------------------------------------------------------------------
  2320. if (nRState == xtpCalendarRecurrenceException &&
  2321. dwCopyFlags & xtpCalendarCopyFlagKeepRException)
  2322. {
  2323. CXTPCalendarRecurrencePatternPtr ptrPattern = pNewEvent->GetRecurrencePattern();
  2324. bUseChangeEvent = ptrPattern != NULL;
  2325. }
  2326. if (!bUseChangeEvent && nRState == xtpCalendarRecurrenceException)
  2327. {
  2328. VERIFY( pNewEvent->RemoveRecurrence() );
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. COleDateTime dtEventStart = pNewEvent->GetStartTime();
  2332. if (i == 0)
  2333. {
  2334. spStartShift = dtSelBegin - dtEventStart;
  2335. spStartShift += ((double)spStartShift < 0 ? -1 : 1) * XTP_HALF_SECOND;
  2336. double dCells = (double)spStartShift / (double)spSelectionResolution;
  2337. int nCells = (int)dCells; //+ (dCells >= 0 ? 1 : 0);
  2338. double dCellDrobTime = fabs(dCells - (DWORD)dCells)*(double)spSelectionResolution;
  2339. double dCellDrobTimeLimit = XTP_HALF_SECOND*2*10;
  2340. if (dCells >= 0 && dCellDrobTime > dCellDrobTimeLimit)
  2341. {
  2342. nCells++;
  2343. }
  2344. spStartShift = (double)spSelectionResolution * (double)nCells;
  2345. }
  2346. dtEventStart += spStartShift;
  2347. pNewEvent->MoveEvent(dtEventStart);
  2348. //*******************************************************
  2349. if (OnBeforePasteNotify(pNewEvent, bUseChangeEvent))
  2350. {
  2351. continue;
  2352. }
  2353. //*******************************************************
  2354. //---------------------------------------------------------------------------
  2355. if (bUseChangeEvent)
  2356. {
  2357. VERIFY( XTP_SAFE_GET2(pNewEvent, GetDataProvider(), ChangeEvent(pNewEvent), FALSE) );
  2358. }
  2359. else
  2360. {
  2361. VERIFY( XTP_SAFE_GET2(pNewEvent, GetDataProvider(), AddEvent(pNewEvent), FALSE) );
  2362. }
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. if (dwCopyFlags & xtpCalendarCopyFlagClearCBAfterPaste)
  2366. {
  2367. if (::OpenClipboard(NULL))
  2368. {
  2369. ::EmptyClipboard();
  2370. ::CloseClipboard();
  2371. }
  2372. }
  2373. //---------------------------------------------------------------------------
  2374. XTP_SAFE_CALL1(GetCalendarControl(), Populate());
  2375. return TRUE;
  2376. }
  2377. CXTPCalendarEventsPtr CXTPCalendarView::_ReadEventsFromClipboard(COleDataObject* pData, DWORD* pdwCopyFlags)
  2378. {
  2379. //- Register or get existing Clipboard Format ID -------------------------
  2380. CLIPFORMAT uCF_Event = (CLIPFORMAT)::RegisterClipboardFormat(XTPCALENDARCTRL_CF_EVENT);
  2381. ASSERT(pData);
  2382. if (!pData || !pData->IsDataAvailable(uCF_Event))
  2383. {
  2384. return NULL;
  2385. }
  2386. CXTPCalendarEventsPtr ptrEvents = new CXTPCalendarEvents();
  2387. if (!ptrEvents)
  2388. {
  2389. return NULL;
  2390. }
  2391. const int cErrTextSize = 1024;
  2392. TCHAR szErrText[cErrTextSize + 1];
  2393. try
  2394. {
  2395. HGLOBAL hData = pData->GetGlobalData(uCF_Event);
  2396. if (!hData)
  2397. {
  2398. return NULL;
  2399. }
  2400. CSharedFile fileSahred;
  2401. fileSahred.SetHandle(hData, FALSE);
  2402. CArchive ar(&fileSahred, CArchive::load);
  2403. CXTPPropExchangeArchive px(ar);
  2404. long nSchema = 0;
  2405. DWORD dwCopyFlags = 0;
  2406. PX_Long(&px, _T("Version"), (long&)nSchema);
  2407. px.ExchangeLocale();
  2408. PX_DWord(&px, _T("CopyFlags"), (DWORD&)dwCopyFlags);
  2409. if (nSchema != XTP_CLIPBOARD_EVENTS_DATA_VER)
  2410. {
  2411. ASSERT(FALSE);
  2412. return NULL;
  2413. }
  2414. CXTPPropExchangeSection sec(px.GetSection(_T("Events")));
  2415. CXTPPropExchangeEnumeratorPtr pEnumerator(sec->GetEnumerator(_T("Event")));
  2416. POSITION pos = pEnumerator->GetPosition();
  2417. UINT uScheduleID = 0;
  2418. CXTPCalendarData* pDPsel = _GetDataProviderBySelection(&uScheduleID);
  2419. while (pos)
  2420. {
  2421. CXTPPropExchangeSection secEvent(pEnumerator->GetNext(pos));
  2422. CXTPCalendarData* pDPevent = NULL;
  2423. //-- get data provider --------------------
  2424. CString strDataProvider;
  2425. PX_String(&secEvent, _T("DataProvider_ConnectionString"), strDataProvider, _T(""));
  2426. if (!strDataProvider.IsEmpty())
  2427. {
  2428. pDPevent = _GetDataProviderByConnStr(strDataProvider);
  2429. }
  2430. CXTPCalendarData* pDataProvider = pDPevent ? pDPevent : pDPsel;
  2431. ASSERT(pDataProvider);
  2432. //-- create event and read its data ---------
  2433. CXTPCalendarEventPtr ptrEvent = pDataProvider ? pDataProvider->CreateNewEvent() : NULL;
  2434. if (!ptrEvent)
  2435. {
  2436. return NULL;
  2437. }
  2438. ptrEvent->DoPropExchange(&secEvent);
  2439. //-----------------------------------
  2440. if (!pDPevent || !_IsScheduleVisible(pDPevent, ptrEvent->GetScheduleID()))
  2441. {
  2442. ptrEvent->SetScheduleID(uScheduleID);
  2443. }
  2444. ptrEvents->Add(ptrEvent, TRUE);
  2445. }
  2446. ar.Close(); // detach from file
  2447. //--------------------------------------------------------------------
  2448. if (pdwCopyFlags)
  2449. {
  2450. *pdwCopyFlags = dwCopyFlags;
  2451. }
  2452. return ptrEvents;
  2453. }
  2454. catch(CArchiveException* pE)
  2455. {
  2456. if (pE->GetErrorMessage(szErrText, cErrTextSize))
  2457. {
  2458. TRACE(_T("EXCEPTION: CXTPCalendarView::_ReadEventsFromClipboard() - %sn"), szErrText);
  2459. }
  2460. pE->Delete();
  2461. }
  2462. catch(CFileException* pE)
  2463. {
  2464. if (pE->GetErrorMessage(szErrText, cErrTextSize))
  2465. {
  2466. TRACE(_T("EXCEPTION: CXTPCalendarView::_ReadEventsFromClipboard() - %sn"), szErrText);
  2467. }
  2468. pE->Delete();
  2469. }
  2470. catch(...)
  2471. {
  2472. TRACE(_T("EXCEPTION: CXTPCalendarView::_ReadEventsFromClipboard() - Unhandled Exception!n"));
  2473. }
  2474. ASSERT(FALSE);
  2475. return NULL;
  2476. }
  2477. COleDataSource* CXTPCalendarView::_CopySelectedEvents(DWORD dwCopyFlags)
  2478. {
  2479. CXTPCalendarViewEventsPtr ptrSelViews = GetSelectedEvents();
  2480. if (!ptrSelViews || !ptrSelViews->GetCount())
  2481. {
  2482. return NULL;
  2483. }
  2484. //------------------------------------------------------------------------
  2485. const int cErrTextSize = 1024;
  2486. TCHAR szErrText[cErrTextSize + 1];
  2487. try
  2488. {
  2489. CSharedFile fileSahred(GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
  2490. CArchive ar(&fileSahred, CArchive::store);
  2491. CXTPPropExchangeArchive px(ar);
  2492. long nSchema = XTP_CLIPBOARD_EVENTS_DATA_VER;
  2493. PX_Long(&px, _T("Version"), (long&)nSchema);
  2494. px.ExchangeLocale();
  2495. PX_DWord(&px, _T("CopyFlags"), (DWORD&)dwCopyFlags);
  2496. int nCount = ptrSelViews->GetCount();
  2497. CXTPPropExchangeSection sec(px.GetSection(_T("Events")));
  2498. CXTPPropExchangeEnumeratorPtr pEnumerator(sec->GetEnumerator(_T("Event")));
  2499. POSITION posEnum = pEnumerator->GetPosition((DWORD)nCount);
  2500. for (int i = 0; i < nCount; i++)
  2501. {
  2502. CXTPCalendarViewEvent* pViewEvent = ptrSelViews->GetAt(i, FALSE);
  2503. CXTPCalendarEvent* pEvent = pViewEvent->GetEvent();
  2504. if (!pEvent)
  2505. {
  2506. ASSERT(FALSE);
  2507. continue;
  2508. }
  2509. CXTPPropExchangeSection secEvent(pEnumerator->GetNext(posEnum));
  2510. CString strDataProvider = XTP_SAFE_GET2(pEvent, GetDataProvider(), GetConnectionString(), _T(""));
  2511. PX_String(&secEvent, _T("DataProvider_ConnectionString"), strDataProvider);
  2512. pEvent->DoPropExchange(&secEvent);
  2513. }
  2514. ar.Close(); // perform Flush() and detach from file
  2515. //- Prepare Global data ----------------------------------------------
  2516. DWORD dwDataSize = (DWORD)fileSahred.GetLength();
  2517. HGLOBAL hData = fileSahred.Detach();
  2518. if (!hData)
  2519. {
  2520. ASSERT(FALSE);
  2521. return NULL;
  2522. }
  2523. hData = ::GlobalReAlloc(hData, dwDataSize, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
  2524. if (!hData)
  2525. {
  2526. ASSERT(FALSE);
  2527. return NULL;
  2528. }
  2529. //- Register Clipboard Format ----------------------------------------
  2530. CLIPFORMAT uCF_Event = (CLIPFORMAT)::RegisterClipboardFormat(XTPCALENDARCTRL_CF_EVENT);
  2531. // Cache data
  2532. COleDataSource* pSource = new COleDataSource();
  2533. if (pSource)
  2534. {
  2535. pSource->CacheGlobalData(uCF_Event, hData);
  2536. }
  2537. return pSource;
  2538. }
  2539. catch(CArchiveException* pE)
  2540. {
  2541. if (pE->GetErrorMessage(szErrText, cErrTextSize))
  2542. {
  2543. TRACE(_T("EXCEPTION: CXTPCalendarView::_CopySelectedEvents() - %sn"), szErrText);
  2544. }
  2545. pE->Delete();
  2546. }
  2547. catch(CFileException* pE)
  2548. {
  2549. if (pE->GetErrorMessage(szErrText, cErrTextSize))
  2550. {
  2551. TRACE(_T("EXCEPTION: CXTPCalendarView::_CopySelectedEvents() - %sn"), szErrText);
  2552. }
  2553. pE->Delete();
  2554. }
  2555. catch(...)
  2556. {
  2557. TRACE(_T("EXCEPTION: CXTPCalendarView::_CopySelectedEvents() - Unhandled Exception!n"));
  2558. }
  2559. ASSERT(FALSE);
  2560. return NULL;
  2561. }
  2562. ////////////////////////////////////////////////////////////////////////////
  2563. CXTPCalendarPaintManager* CXTPCalendarView::GetPaintManager()
  2564. {
  2565. ASSERT(m_pControl);
  2566. return m_pControl ? m_pControl->GetPaintManager() : NULL;
  2567. }
  2568. CXTPCalendarTheme* CXTPCalendarView::GetTheme()
  2569. {
  2570. ASSERT(m_pControl);
  2571. return m_pControl ? m_pControl->GetTheme() : NULL;
  2572. }
  2573. void CXTPCalendarView::SendNotification(XTP_NOTIFY_CODE EventCode, WPARAM wParam , LPARAM lParam)
  2574. {
  2575. if (m_pControl)
  2576. {
  2577. m_pControl->SendNotification(EventCode, wParam, lParam);
  2578. }
  2579. }
  2580. BOOL CXTPCalendarView::IsEditOperationDisabledNotify(XTPCalendarEditOperation eOperation, CXTPCalendarViewEvent* pEventView)
  2581. {
  2582. return _EditOperationNotify(XTP_NC_CALENDAR_IS_EVENT_EDIT_OPERATION_DISABLED,
  2583. eOperation, pEventView);
  2584. }
  2585. BOOL CXTPCalendarView::OnBeforeEditOperationNotify(XTPCalendarEditOperation eOperation, CXTPCalendarViewEvent* pEventView)
  2586. {
  2587. if (IsEditOperationDisabledNotify(eOperation, pEventView))
  2588. {
  2589. return TRUE;
  2590. }
  2591. return _EditOperationNotify(XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION,
  2592. eOperation, pEventView);
  2593. }
  2594. BOOL CXTPCalendarView::OnBeforeEditOperationNotify(XTPCalendarEditOperation eOperation, CXTPCalendarViewEvents* pEventViews)
  2595. {
  2596. if (_EditOperationNotify(XTP_NC_CALENDAR_IS_EVENT_EDIT_OPERATION_DISABLED,
  2597. eOperation, NULL, pEventViews))
  2598. {
  2599. return TRUE;
  2600. }
  2601. return _EditOperationNotify(XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION,
  2602. eOperation, NULL, pEventViews);
  2603. }
  2604. BOOL CXTPCalendarView::OnBeforePasteNotify(CXTPCalendarEvent* pEvent, BOOL bPasteWillChangeExistingEvent)
  2605. {
  2606. XTP_EVENT_PASTE_OPERATION_PARAMS opPasteParams;
  2607. ::ZeroMemory(&opPasteParams, sizeof(opPasteParams));
  2608. opPasteParams.eOperation = xtpCalendarEO_Paste;
  2609. opPasteParams.pEvent = pEvent;
  2610. opPasteParams.bPasteWillChangeExistingEvent = bPasteWillChangeExistingEvent;
  2611. BOOL bDisabledHandled = FALSE;
  2612. if (m_pControl)
  2613. {
  2614. m_pControl->SendNotification(XTP_NC_CALENDAR_IS_EVENT_EDIT_OPERATION_DISABLED,
  2615. (WPARAM)&opPasteParams, (LPARAM)&bDisabledHandled);
  2616. }
  2617. if (bDisabledHandled)
  2618. {
  2619. return TRUE;
  2620. }
  2621. if (m_pControl)
  2622. {
  2623. m_pControl->SendNotification(XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION,
  2624.  (WPARAM)&opPasteParams, (LPARAM)&bDisabledHandled);
  2625. }
  2626. return bDisabledHandled;
  2627. }
  2628. BOOL CXTPCalendarView::OnInPlaceCreateEvent(LPCTSTR pcszInitialSubject)
  2629. {
  2630. XTP_EVENT_IN_PLACE_CREATE_EVENT_OPERATION_PARAMS opCrParams;
  2631. ::ZeroMemory(&opCrParams, sizeof(opCrParams));
  2632. opCrParams.eOperation = xtpCalendarEO_InPlaceCreateEvent;
  2633. opCrParams.pcszInitialSubject = pcszInitialSubject;
  2634. BOOL bDisabledHandled = FALSE;
  2635. if (m_pControl)
  2636. {
  2637. m_pControl->SendNotification(XTP_NC_CALENDAR_IS_EVENT_EDIT_OPERATION_DISABLED,
  2638. (WPARAM)&opCrParams, (LPARAM)&bDisabledHandled);
  2639. }
  2640. if (bDisabledHandled)
  2641. {
  2642. return TRUE;
  2643. }
  2644. if (m_pControl)
  2645. {
  2646. m_pControl->SendNotification(XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION,
  2647. (WPARAM)&opCrParams, (LPARAM)&bDisabledHandled);
  2648. }
  2649. return bDisabledHandled;
  2650. }
  2651. BOOL CXTPCalendarView::_EditOperationNotify(XTP_NOTIFY_CODE ncEvent,
  2652. XTPCalendarEditOperation eOperation,
  2653. CXTPCalendarViewEvent* pEventView,
  2654. CXTPCalendarViewEvents* pEventViews)
  2655. {
  2656. ASSERT(pEventView || pEventViews && !(pEventView && pEventViews));
  2657. XTP_EVENT_EDIT_OPERATION_PARAMS opParams;
  2658. ::ZeroMemory(&opParams, sizeof(opParams));
  2659. CXTPCalendarViewEvents arEvents;
  2660. arEvents.Add(pEventView, TRUE);
  2661. opParams.eOperation = eOperation;
  2662. opParams.pEventViews = pEventView ? &arEvents : pEventViews;
  2663. BOOL bDisabledHandled = FALSE;
  2664. if (m_pControl)
  2665. {
  2666. m_pControl->SendNotification(ncEvent, (WPARAM)&opParams, (LPARAM)&bDisabledHandled);
  2667. }
  2668. return bDisabledHandled;
  2669. }
  2670. XTPEnumCalendarUpdateResult CXTPCalendarView::OnEventChanged_InDataProvider(
  2671. XTP_NOTIFY_CODE nfCode, CXTPCalendarEvent* pEvent)
  2672. {
  2673. ASSERT(pEvent);
  2674. if (!pEvent)
  2675. {
  2676. return xtpCalendar_Skip;
  2677. }
  2678. if (nfCode != XTP_NC_CALENDAREVENTWASADDED &&
  2679. nfCode != XTP_NC_CALENDAREVENTWASDELETED &&
  2680. nfCode != XTP_NC_CALENDAREVENTWASCHANGED)
  2681. {
  2682. ASSERT(FALSE);
  2683. return xtpCalendar_Skip;
  2684. }
  2685. int nDaysCount = GetViewDayCount();
  2686. COleDateTime dtFirstDay = nDaysCount ?  XTP_SAFE_GET1(GetViewDay_(0), GetDayDate(), (DATE)0) : (DATE)0;
  2687. COleDateTime dtLastDay = nDaysCount ?  XTP_SAFE_GET1(GetViewDay_(nDaysCount - 1), GetDayDate(), (DATE)0) : (DATE)0;
  2688. if (nfCode == XTP_NC_CALENDAREVENTWASADDED ||
  2689. nfCode == XTP_NC_CALENDAREVENTWASDELETED)
  2690. {
  2691. if (CXTPCalendarUtils::ResetTime(pEvent->GetStartTime()) > dtLastDay ||
  2692. CXTPCalendarUtils::ResetTime(pEvent->GetEndTime()) < dtFirstDay)
  2693. {
  2694. return xtpCalendar_Skip;
  2695. }
  2696. return xtpCalendar_Populate;
  2697. }
  2698. return xtpCalendar_Populate;
  2699. //  *****
  2700. //  An Idea how changing event processing can be optimized
  2701. //  from xtpCalendar_Populate to xtpCalendar_Redraw or even xtpCalendar_Skip.
  2702. //
  2703. //  int nRState_new = pEvent->GetRecurrenceState();
  2704. //  if (nRState_new == xtpCalendarRecurrenceMaster) {
  2705. //      return xtpCalendar_Populate;
  2706. //  }
  2707. //
  2708. //  //-----------------------------------------------------------------------
  2709. //  BOOL bUpdateEvent = FALSE;
  2710. //  int nDays = GetViewDayCount();
  2711. //  for (int nDay = 0; nDay < nDays; nDay++)
  2712. //  {
  2713. //      CXTPCalendarViewDay* pDay = GetViewDay_(nDay);
  2714. //      ASSERT(pDay);
  2715. //      if (!pDay)
  2716. //          continue;
  2717. //
  2718. //
  2719. //      int nEvents = pDay->GetViewEventsCount();
  2720. //      for (int nEvent = 0; nEvent < nEvents; nEvent++)
  2721. //      {
  2722. //          CXTPCalendarViewEvent* pEventView = pDay->GetViewEvent_(nEvent);
  2723. //          if (!pEventView && !pEventView->GetEvent())
  2724. //          {
  2725. //              ASSERT(FALSE);
  2726. //              continue;
  2727. //          }
  2728. //          CXTPCalendarEvent* pEvent_I = pEventView->GetEvent();
  2729. //          if (pEvent_I->GetEventID() == dwEventID)
  2730. //          {
  2731. //              if (!bUpdateEvent)
  2732. //              {
  2733. //                  if (pEvent_I->IsEqualStartEnd(pEvent))
  2734. //                      bUpdateEvent = TRUE;
  2735. //                  else
  2736. //                      return xtpCalendar_Populate;
  2737. //              }
  2738. //
  2739. //              if (bUpdateEvent)
  2740. //              {
  2741. //                  int nRState_I = pEvent_I->GetRecurrenceState();
  2742. //                  //int nRState_new = pEvent->GetRecurrenceState();
  2743. //
  2744. //                  if (nRState_I == xtpCalendarRecurrenceOccurrence)
  2745. //                      pEvent_I->SetRecurrenceState_ExceptionOccurrence(xtpCalendarRecurrenceException);
  2746. //
  2747. //                  pEvent_I->Update(pEvent);
  2748. //
  2749. //                  if (nRState_new == xtpCalendarRecurrenceOccurrence ||
  2750. //                      nRState_new == xtpCalendarRecurrenceException)
  2751. //                  {
  2752. //                      ASSERT(nRState_I == xtpCalendarRecurrenceOccurrence ||
  2753. //                              nRState_I == xtpCalendarRecurrenceException);
  2754. //
  2755. //                      pEvent_I->SetRecurrenceState_ExceptionOccurrence((XTPCalendarEventRecurrenceState)nRState_new);
  2756. //                  }
  2757. //              }
  2758. //          }
  2759. //      }
  2760. //
  2761. //  }
  2762. //
  2763. //  //-----------------------------------------------------------------------
  2764. //  if (!bUpdateEvent &&
  2765. //      !(CXTPCalendarUtils::ResetTime(pEvent->GetStartTime()) > dtLastDay ||
  2766. //        CXTPCalendarUtils::ResetTime(pEvent->GetEndTime()) < dtFirstDay)
  2767. //     )
  2768. //  {
  2769. //      return xtpCalendar_Populate;
  2770. //  }
  2771. //  return bUpdateEvent ? xtpCalendar_Redraw : xtpCalendar_Skip;
  2772. }
  2773. CXTPCalendarData* CXTPCalendarView::_GetDataProviderBySelection(UINT* puScheduleID)
  2774. {
  2775. COleDateTime dtSelBegin;
  2776. int nGroup = 0;
  2777. if (!GetSelection(&dtSelBegin, NULL, NULL, &nGroup))
  2778. {
  2779. return NULL;
  2780. }
  2781. //---------------------------------------------------------------------------
  2782. CXTPCalendarViewDay* pViewDay = _GetViewDay(dtSelBegin);
  2783. if (!pViewDay)
  2784. {
  2785. return NULL;
  2786. }
  2787. CXTPCalendarData* pData = NULL;
  2788. CXTPCalendarViewGroup* pViewGroup = NULL;
  2789. if (pViewDay && nGroup < pViewDay->GetViewGroupsCount() )
  2790. {
  2791. pViewGroup = pViewDay->GetViewGroup_(nGroup);
  2792. if (pViewGroup)
  2793. {
  2794. pData = pViewGroup->GetDataProvider();
  2795. if (puScheduleID)
  2796. {
  2797. *puScheduleID = pViewGroup->GetScheduleID();
  2798. }
  2799. }
  2800. }
  2801. return pData;
  2802. }
  2803. CXTPCalendarData* CXTPCalendarView::_GetDataProviderByConnStr(LPCTSTR pcszConnStr, BOOL bCompareNoCase)
  2804. {
  2805. CXTPCalendarViewDay* pViewDay = GetViewDay_(0);
  2806. COleDateTime dtSelBegin;
  2807. if (GetSelection(&dtSelBegin))
  2808. {
  2809. pViewDay = _GetViewDay(dtSelBegin);
  2810. }
  2811. //---------------------------------------------------------------------------
  2812. if (!pViewDay)
  2813. {
  2814. return NULL;
  2815. }
  2816. int nGCount = pViewDay->GetViewGroupsCount();
  2817. for (int g = 0; g < nGCount; g++)
  2818. {
  2819. CXTPCalendarViewGroup* pViewGroup = pViewDay->GetViewGroup_(g);
  2820. if (pViewGroup)
  2821. {
  2822. CXTPCalendarData* pData = pViewGroup->GetDataProvider();
  2823. if (pData)
  2824. {
  2825. CString strConn_i = pData->GetConnectionString();
  2826. int nCmp = bCompareNoCase ? strConn_i.CompareNoCase(pcszConnStr) : strConn_i.Compare(pcszConnStr);
  2827. if (nCmp == 0)
  2828. {
  2829.  return pData;
  2830. }
  2831. }
  2832. }
  2833. }
  2834. return NULL;
  2835. }
  2836. BOOL CXTPCalendarView::_IsScheduleVisible(CXTPCalendarData* pDataProvider, UINT uScheduleID)
  2837. {
  2838. CXTPCalendarViewDay* pViewDay = GetViewDay_(0);
  2839. COleDateTime dtSelBegin;
  2840. if (GetSelection(&dtSelBegin))
  2841. {
  2842. pViewDay = _GetViewDay(dtSelBegin);
  2843. }
  2844. //---------------------------------------------------------------------------
  2845. if (!pViewDay)
  2846. {
  2847. return FALSE;
  2848. }
  2849. int nGCount = pViewDay->GetViewGroupsCount();
  2850. for (int g = 0; g < nGCount; g++)
  2851. {
  2852. CXTPCalendarViewGroup* pViewGroup = pViewDay->GetViewGroup_(g);
  2853. CXTPCalendarData* pData = pViewGroup ? pViewGroup->GetDataProvider() : NULL;
  2854. if (pData && pData == pDataProvider)
  2855. {
  2856. int nRCCount = XTP_SAFE_GET2(pViewGroup, GetResources(), GetCount(), 0);
  2857. for (int i = 0; i < nRCCount; i++)
  2858. {
  2859. if (XTP_SAFE_GET3(pViewGroup, GetResources(), GetAt(i), ExistsScheduleID(uScheduleID), FALSE))
  2860. {
  2861. return TRUE;
  2862. }
  2863. }
  2864. }
  2865. }
  2866. return FALSE;
  2867. }
  2868. CXTPCalendarWMHandler* CXTPCalendarView::GetChildHandlerAt(int nIndex)
  2869. {
  2870. ASSERT_KINDOF(CXTPCalendarWMHandler, GetViewDay_(nIndex));
  2871. return GetViewDay_(nIndex);
  2872. }
  2873. CXTPCalendarResources* CXTPCalendarView::GetResources()
  2874. {
  2875. ASSERT(this);
  2876. if (m_pResources)
  2877. {
  2878. return m_pResources;
  2879. }
  2880. return GetCalendarControl() ? GetCalendarControl()->GetResources() : NULL;
  2881. }
  2882. void CXTPCalendarView::SetResources(CXTPCalendarResources* pResources)
  2883. {
  2884. BOOL bChanged = TRUE;
  2885. if (!pResources)
  2886. {
  2887. bChanged = m_pResources != NULL;
  2888. CMDTARGET_RELEASE(m_pResources);
  2889. }
  2890. else
  2891. {
  2892. if (!m_pResources)
  2893. {
  2894. m_pResources = new CXTPCalendarResources();
  2895. }
  2896. if (!m_pResources)
  2897. {
  2898. return;
  2899. }
  2900. // copy data to allow using self as input parameter
  2901. CXTPCalendarResources arRes;
  2902. arRes.Append(pResources);
  2903. m_pResources->RemoveAll();
  2904. m_pResources->Append(&arRes);
  2905. }
  2906. if (bChanged)
  2907. {
  2908. SendNotification(XTP_NC_CALENDAR_RESOURCES_WHERE_CHANGED, 1, (LPARAM)this);
  2909. }
  2910. }
  2911. BOOL CXTPCalendarView::IsTodayVisible()
  2912. {
  2913. COleDateTime dtToday = CXTPCalendarUtils::GetCurrentTime();
  2914. dtToday = CXTPCalendarUtils::ResetTime(dtToday);
  2915. int nCount = GetViewDayCount();
  2916. for (int i = 0; i < nCount; i++)
  2917. {
  2918. COleDateTime dtDay = GetViewDayDate(i);
  2919. if (CXTPCalendarUtils::IsEqual(dtDay, dtToday))
  2920. {
  2921. return TRUE;
  2922. }
  2923. }
  2924. return FALSE;
  2925. }
  2926. /////////////////////////////////////////////////////////////////////////////
  2927. CXTPCalendarView::CSelectionChanged_ContextData::CSelectionChanged_ContextData()
  2928. {
  2929. m_nLockCount = 0;
  2930. m_nLockCount_Day = 0;
  2931. m_nLockCount_Event = 0;
  2932. m_bRequest_Day = FALSE;
  2933. m_bRequest_Event = FALSE;
  2934. }
  2935. /////////////////////////////////////////////////////////////////////////////
  2936. //  class CSelectionChangedContext
  2937. //
  2938. CXTPCalendarView::CSelectionChangedContext::CSelectionChangedContext(CXTPCalendarView* pView, int eSelType)
  2939. {
  2940. if (!pView)
  2941. {
  2942. ASSERT(FALSE);
  2943. return;
  2944. }
  2945. m_pView = pView;
  2946. m_eSelType = eSelType;
  2947. m_pView->m_cntSelChanged.m_nLockCount += eSelType == xtpCalendarSelectionUnknown ? 1 : 0;
  2948. m_pView->m_cntSelChanged.m_nLockCount_Day += eSelType == xtpCalendarSelectionDays ? 1 : 0;
  2949. m_pView->m_cntSelChanged.m_nLockCount_Event += eSelType == xtpCalendarSelectionEvents ? 1 : 0;
  2950. }
  2951. CXTPCalendarView::CSelectionChangedContext::~CSelectionChangedContext()
  2952. {
  2953. if (!m_pView)
  2954. {
  2955. ASSERT(FALSE);
  2956. return;
  2957. }
  2958. if (m_eSelType == xtpCalendarSelectionUnknown)
  2959. {
  2960. m_pView->m_cntSelChanged.m_nLockCount--;
  2961. }
  2962. if (m_eSelType == xtpCalendarSelectionDays)
  2963. {
  2964. m_pView->m_cntSelChanged.m_nLockCount_Day--;
  2965. if (m_pView->m_cntSelChanged.m_nLockCount_Day == 0)
  2966. {
  2967. m_pView->m_cntSelChanged.m_bRequest_Day = TRUE;
  2968. }
  2969. }
  2970. if (m_eSelType == xtpCalendarSelectionEvents)
  2971. {
  2972. m_pView->m_cntSelChanged.m_nLockCount_Event--;
  2973. if (m_pView->m_cntSelChanged.m_nLockCount_Event == 0)
  2974. {
  2975. m_pView->m_cntSelChanged.m_bRequest_Event = TRUE;
  2976. }
  2977. }
  2978. if (m_pView->m_cntSelChanged.m_nLockCount == 0 && m_pView->m_cntSelChanged.m_bRequest_Day)
  2979. {
  2980. m_pView->m_cntSelChanged.m_bRequest_Day = FALSE;
  2981. m_pView->SendNotification(XTP_NC_CALENDAR_SELECTION_CHANGED, (WPARAM)xtpCalendarSelectionDays);
  2982. }
  2983. if (m_pView->m_cntSelChanged.m_nLockCount == 0 && m_pView->m_cntSelChanged.m_bRequest_Event)
  2984. {
  2985. m_pView->m_cntSelChanged.m_bRequest_Event = FALSE;
  2986. m_pView->SendNotification(XTP_NC_CALENDAR_SELECTION_CHANGED, (WPARAM)xtpCalendarSelectionEvents);
  2987. }
  2988. }
  2989. /////////////////////////////////////////////////////////////////////////////
  2990. /////////////////////////////////////////////////////////////////////////////
  2991. // CXTPCalendarWMHandler
  2992. CXTPCalendarWMHandler::CXTPCalendarWMHandler()
  2993. {
  2994. }
  2995. int CXTPCalendarWMHandler::GetChildHandlersCount()
  2996. {
  2997. return 0;
  2998. }
  2999. CXTPCalendarWMHandler* CXTPCalendarWMHandler::GetChildHandlerAt(int nIndex)
  3000. {
  3001. UNREFERENCED_PARAMETER(nIndex);
  3002. return NULL;
  3003. }
  3004. BOOL CXTPCalendarWMHandler::OnLButtonDown(UINT nFlags, CPoint point)
  3005. {
  3006. BOOL bHandled = FALSE;
  3007. int nCount = GetChildHandlersCount();
  3008. for (int i = 0; i < nCount; i++)
  3009. {
  3010. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3011. if (pChild && pChild->OnLButtonDown(nFlags, point))
  3012. {
  3013. bHandled = TRUE;
  3014. break;
  3015. }
  3016. }
  3017. return bHandled;
  3018. }
  3019. BOOL CXTPCalendarWMHandler::OnLButtonUp(UINT nFlags, CPoint point)
  3020. {
  3021. BOOL bHandled = FALSE;
  3022. int nCount = GetChildHandlersCount();
  3023. for (int i = 0; i < nCount; i++)
  3024. {
  3025. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3026. if (pChild && pChild->OnLButtonUp(nFlags, point))
  3027. {
  3028. bHandled = TRUE;
  3029. break;
  3030. }
  3031. }
  3032. return bHandled;
  3033. }
  3034. BOOL CXTPCalendarWMHandler::OnLButtonDblClk(UINT nFlags, CPoint point)
  3035. {
  3036. BOOL bHandled = FALSE;
  3037. int nCount = GetChildHandlersCount();
  3038. for (int i = 0; i < nCount; i++)
  3039. {
  3040. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3041. if (pChild && pChild->OnLButtonDblClk(nFlags, point))
  3042. {
  3043. bHandled = TRUE;
  3044. break;
  3045. }
  3046. }
  3047. return bHandled;
  3048. }
  3049. void CXTPCalendarWMHandler::OnMouseMove(UINT nFlags, CPoint point)
  3050. {
  3051. int nCount = GetChildHandlersCount();
  3052. for (int i = 0; i < nCount; i++)
  3053. {
  3054. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3055. if (pChild)
  3056. {
  3057. pChild->OnMouseMove(nFlags, point);
  3058. }
  3059. }
  3060. }
  3061. void CXTPCalendarWMHandler::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  3062. {
  3063. int nCount = GetChildHandlersCount();
  3064. for (int i = 0; i < nCount; i++)
  3065. {
  3066. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3067. if (pChild)
  3068. {
  3069. pChild->OnChar(nChar, nRepCnt, nFlags);
  3070. }
  3071. }
  3072. }
  3073. void CXTPCalendarWMHandler::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  3074. {
  3075. int nCount = GetChildHandlersCount();
  3076. for (int i = 0; i < nCount; i++)
  3077. {
  3078. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3079. if (pChild)
  3080. {
  3081. pChild->OnKeyDown(nChar, nRepCnt, nFlags);
  3082. }
  3083. }
  3084. }
  3085. void CXTPCalendarWMHandler::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  3086. {
  3087. int nCount = GetChildHandlersCount();
  3088. for (int i = 0; i < nCount; i++)
  3089. {
  3090. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3091. if (pChild)
  3092. {
  3093. pChild->OnKeyUp(nChar, nRepCnt, nFlags);
  3094. }
  3095. }
  3096. }
  3097. BOOL CXTPCalendarWMHandler::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  3098. {
  3099. BOOL bHandled = FALSE;
  3100. int nCount = GetChildHandlersCount();
  3101. for (int i = 0; i < nCount; i++)
  3102. {
  3103. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3104. if (pChild && pChild->OnSysKeyDown(nChar, nRepCnt, nFlags))
  3105. {
  3106. bHandled = TRUE;
  3107. break;
  3108. }
  3109. }
  3110. return bHandled;
  3111. }
  3112. BOOL CXTPCalendarWMHandler::OnTimer(UINT_PTR uTimerID)
  3113. {
  3114. int nCount = GetChildHandlersCount();
  3115. for (int i = 0; i < nCount; i++)
  3116. {
  3117. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3118. if (pChild && pChild->OnTimer(uTimerID))
  3119. {
  3120. return TRUE;
  3121. }
  3122. }
  3123. return FALSE;
  3124. }
  3125. void CXTPCalendarWMHandler::OnPostAdjustLayout()
  3126. {
  3127. int nCount = GetChildHandlersCount();
  3128. for (int i = 0; i < nCount; i++)
  3129. {
  3130. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3131. if (pChild)
  3132. {
  3133. pChild->OnPostAdjustLayout();
  3134. }
  3135. }
  3136. }
  3137. void CXTPCalendarWMHandler::OnFinalRelease()
  3138. {
  3139. OnBeforeDestroy();
  3140. CCmdTarget::OnFinalRelease();
  3141. }
  3142. void CXTPCalendarWMHandler::OnBeforeDestroy()
  3143. {
  3144. int nCount = GetChildHandlersCount();
  3145. for (int i = 0; i < nCount; i++)
  3146. {
  3147. CXTPCalendarWMHandler* pChild = GetChildHandlerAt(i);
  3148. if (pChild)
  3149. {
  3150. pChild->OnBeforeDestroy();
  3151. }
  3152. }
  3153. }