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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarControl.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 "Resource.h"
  22. #include "Common/XTPResourceManager.h"
  23. #include "Common/XTPVC50Helpers.h"
  24. #include "Common/XTPImageManager.h"
  25. #include "Common/XTPSystemHelpers.h"
  26. #include "Common/XTPMarkupRender.h"
  27. #include "Common/XTPOffice2007Image.h"
  28. #include "XTPTopLevelWndMsgNotifier.h"
  29. #include "XTPCalendarUtils.h"
  30. #include "XTPCalendarPaintManager.h"
  31. #include "XTPCalendarNotifications.h"
  32. #include "XTPCalendarDayView.h"
  33. #include "XTPCalendarWeekView.h"
  34. #include "XTPCalendarMonthView.h"
  35. #include "XTPCalendarControl.h"
  36. #include "XTPCalendarResource.h"
  37. #include "XTPCalendarData.h"
  38. #include "XTPCalendarMemoryDataProvider.h"
  39. #include "XTPCalendarDatabaseDataProvider.h"
  40. #include "XTPCalendarMAPIDataProvider.h"
  41. #include "XTPCalendarCustomDataProvider.h"
  42. #include "XTPCalendarRemindersManager.h"
  43. #include "XTPCalendarOccurSeriesChooseDlg.h"
  44. #include "XTPCalendarTheme.h"
  45. #include "XTPCalendarThemeOffice2007.h"
  46. #ifdef _DEBUG
  47. #define new DEBUG_NEW
  48. #undef THIS_FILE
  49. static char THIS_FILE[] = __FILE__;
  50. #endif
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CXTPCalendarControl
  53. #define XTP_CALENDAR_POPULATE_REQUEST_TIMEOUT   200
  54. #define XTP_CALENDAR_REDRAW_REQUEST_TIMEOUT     200
  55. #define XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID   1
  56. #define XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMEOUT   250
  57. #define XTP_CALENDAR_FIRST_DYN_TIMERID          10
  58. //#ifdef _DEBUG
  59. //  const COleDateTimeSpan cspRemindersUpdatePeriod(0, 0,15,0);
  60. //#else
  61. const COleDateTimeSpan cspRemindersUpdatePeriod(0, 2,0,0);
  62. //#endif
  63. /////////////////////////////////////////////////////////////////////////////
  64. BOOL IsEventExists(CXTPCalendarData* pData, CXTPCalendarEvent* pEvent)
  65. {
  66. if (pEvent->GetRecurrenceState() == xtpCalendarRecurrenceNotRecurring)
  67. {
  68. DWORD dwEventID = pEvent->GetEventID();
  69. CXTPCalendarEventPtr ptrEv = pData->GetEvent(dwEventID);
  70. return ptrEv != NULL;
  71. }
  72. else
  73. {
  74. DWORD dwPatternID = pEvent->GetRecurrencePatternID();
  75. CXTPCalendarRecurrencePatternPtr ptrPat = pData->GetRecurrencePattern(dwPatternID);
  76. return ptrPat != NULL;
  77. }
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. CXTPCalendarControl::CXTPCalendarControl()
  81. {
  82. RegisterWindowClass();
  83. m_pConnect = new CXTPNotifyConnection();
  84. m_bChanged = TRUE;
  85. m_nLockUpdateCount = m_nLockAdjustCount = 0;
  86. m_bAdjustScrollBar = FALSE;
  87. m_pActiveView = NULL;
  88. m_lcidActiveLocale = CXTPCalendarUtils::GetActiveLCID();
  89. m_pPaintManager = new CXTPCalendarPaintManager();
  90. if (m_pPaintManager)
  91. m_pPaintManager->SetControl(this);
  92. m_pTheme = NULL;
  93. m_mouseMode = xtpCalendarMouseNothing;
  94. m_nRowsPerWheel = 1;
  95. m_uNextTimerID = XTP_CALENDAR_FIRST_DYN_TIMERID;
  96. //---------------------------------------------------------------------------
  97. m_strUndoUIText = _T("&UndotAlt+BackSpace, Ctrl+Z");
  98. m_strRedoUIText = _T("&RedotAlt+BackSpace, Ctrl+Z");
  99. //---------------------------------------------------------------------------
  100. m_pMonthView = 0;
  101. m_pWeekView = 0;
  102. m_pDayView = 0;
  103. m_bDeleteOnFinalRelease = FALSE;
  104. m_bDisableRedraw = FALSE;
  105. m_bEnableToolTips = TRUE;
  106. m_bEnableSendNotifications = TRUE;
  107. m_uPopulateRequest_TimerID = 0;
  108. m_uRedrawRequest_TimerID = 0;
  109. m_bUpdateWhenEventChangedNotify = TRUE;
  110. m_pRemindersManager = NULL;
  111. m_cnidOnReminders = 0;
  112. m_spRemindersUpdatePeriod = cspRemindersUpdatePeriod;
  113. m_pOptions = new CXTPCalendarOptions();
  114. m_pResourcesNf = new CXTPCalendarResourcesNf();
  115. //By default add one resource with memory DataProvider
  116. SetDataProvider(xtpCalendarDataProviderMemory);
  117. ASSERT(GetDataProvider()->IsOpen());
  118. //EnableReminders(TRUE);
  119. m_pMarkupContext = NULL;
  120. //-----------------------------------------------------------------------
  121. if (XTPGetTopLevelWndMsgNotifier())
  122. {
  123. XTPGetTopLevelWndMsgNotifier()->Advise(this, WM_TIMECHANGE);
  124. XTPGetTopLevelWndMsgNotifier()->Advise(this, XTP_WM_TIME_ZONE_CHANGED);
  125. }
  126. //  CXTPCalendarThemeOffice2007* pTheme2007 = new CXTPCalendarThemeOffice2007();
  127. //  SetTheme(pTheme2007);
  128. //*** TEST of customization ***
  129. // EXAMPLE: customize root settings
  130. //  pTheme2007->GetEventPartX()->m_fcsetSelected.clrBorder = RGB(0, 230, 0);
  131. //  pTheme2007->GetEventPartX()->m_fcsetSelected.fcsetSubject.clrColor = RGB(255, 0, 0);
  132. //  pTheme2007->GetEventPartX()->m_fcsetSelected.fcsetLocation.clrColor = RGB(0, 255, 0);
  133. //  // customize particular settings
  134. //  pTheme2007->GetDayViewPartX()->GetDayPartX()->GetGroupPartX()->GetSingleDayEventPartX()->m_fcsetSelected.clrBorder = RGB(255, 100, 230);
  135. /*
  136. LOGFONT lf;
  137. pTheme2007->GetDayViewPartX()->GetHeaderPartX()->m_TextLeft.fcsetTodaySelected.fntFont->GetLogFont(&lf);
  138. lf.lfHeight *= 2;
  139. //pTheme2007->GetDayViewPartX()->GetHeaderPartX()->m_TextLeft.fcsetTodaySelected.fntFont.SetCustomValue(&lf);
  140. lf.lfHeight = lf.lfHeight * 3 / 2;
  141. lf.lfItalic = 1;
  142. //pTheme2007->GetDayViewPartX()->GetDayPartX()->GetGroupPartX()->GetSingleDayEventPartX()->m_fcsetNormal.fcsetSubject.fntFont.SetCustomValue(&lf);
  143. //pTheme2007->GetDayViewPartX()->GetTimeScalePart()->m_fcsetAMPM.clrColor = RGB(200, 33, 12);
  144. pTheme2007->RefreshMetrics();
  145. */
  146. // end EXAMPLE.
  147. }
  148. CXTPCalendarControl::~CXTPCalendarControl()
  149. {
  150. //---------------------------------------------------------------------------
  151. if (XTPGetTopLevelWndMsgNotifier())
  152. {
  153. XTPGetTopLevelWndMsgNotifier()->Unadvise(this);
  154. }
  155. m_cnidOnReminders = 0;
  156. //m_Sink_DP.UnadviseAll();
  157. CMDTARGET_RELEASE(m_pResourcesNf);
  158. CMDTARGET_RELEASE(m_pActiveView);
  159. CMDTARGET_RELEASE(m_pDayView);
  160. CMDTARGET_RELEASE(m_pWeekView);
  161. CMDTARGET_RELEASE(m_pMonthView);
  162. CMDTARGET_RELEASE(m_pPaintManager);
  163. CMDTARGET_RELEASE(m_pTheme);
  164. CMDTARGET_RELEASE(m_pConnect);
  165. CMDTARGET_RELEASE(m_pRemindersManager);
  166. CMDTARGET_RELEASE(m_pOptions);
  167. XTPMarkupReleaseContext(m_pMarkupContext);
  168. if (::IsWindow(m_wndTip.GetSafeHwnd()))
  169. {
  170. m_wndTip.DestroyWindow();
  171. }
  172. if (::IsWindow(GetSafeHwnd()))
  173. {
  174. DestroyWindow();
  175. }
  176. }
  177. CScrollBar* CXTPCalendarControl::GetScrollBarCtrl(int nBar) const
  178. {
  179. if (DYNAMIC_DOWNCAST(CView, GetParent()))
  180. return GetParent()->GetScrollBarCtrl(nBar);
  181. return 0;
  182. }
  183. void CXTPCalendarControl::OnDestroy()
  184. {
  185. OnBeforeDestroy();
  186. CWnd::OnDestroy();
  187. }
  188. void CXTPCalendarControl::OnBeforeDestroy()
  189. {
  190. if (m_pActiveView)
  191. {
  192. m_pActiveView->OnBeforeDestroy();
  193. }
  194. if (m_pDayView)
  195. {
  196. m_pDayView->OnBeforeDestroy();
  197. }
  198. if (m_pWeekView)
  199. {
  200. m_pWeekView->OnBeforeDestroy();
  201. }
  202. if (m_pMonthView)
  203. {
  204. m_pMonthView->OnBeforeDestroy();
  205. }
  206. }
  207. BOOL CXTPCalendarControl::RegisterWindowClass(HINSTANCE hInstance /*= NULL*/)
  208. {
  209. return XTPDrawHelpers()->RegisterWndClass(hInstance,
  210. XTPCALENDARCTRL_CLASSNAME, CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW);
  211. }
  212. BOOL CXTPCalendarControl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  213. {
  214. if (!CWnd::Create(XTPCALENDARCTRL_CLASSNAME, NULL, dwStyle, rect, pParentWnd, nID))
  215. return FALSE;
  216. return TRUE;
  217. }
  218. void CXTPCalendarControl::PreSubclassWindow()
  219. {
  220. _InitCalendarView();
  221. }
  222. void CXTPCalendarControl::_InitCalendarView()
  223. {
  224. //-----------------------------------------------------------------------
  225. SetActiveView(GetDayView());
  226. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetDayView());
  227. if (!pDayView)
  228. {
  229. return;
  230. }
  231. COleDateTime dtStartDate = CXTPCalendarUtils::GetCurrentTime();
  232. pDayView->ResetSelection();
  233. pDayView->ShowDay(dtStartDate);
  234. pDayView->ScrollToWorkDayBegin();
  235. }
  236. void CXTPCalendarControl::LockUpdate()
  237. {
  238. m_nLockUpdateCount++;
  239. }
  240. void CXTPCalendarControl::UnlockUpdate()
  241. {
  242. m_nLockUpdateCount--;
  243. if (m_nLockUpdateCount == 0 && m_bChanged)
  244. {
  245. RedrawControl();
  246. }
  247. }
  248. void CXTPCalendarControl::BeginUpdate()
  249. {
  250. m_nLockUpdateCount++;
  251. }
  252. void CXTPCalendarControl::EndUpdate()
  253. {
  254. m_bChanged = TRUE;
  255. m_nLockUpdateCount--;
  256. if (m_nLockUpdateCount == 0)
  257. {
  258. RedrawControl();
  259. }
  260. }
  261. void CXTPCalendarControl::BeginAdjust(BOOL bWithScrollBar)
  262. {
  263. if (m_nLockAdjustCount == 0)
  264. {
  265. m_bAdjustScrollBar = FALSE;
  266. }
  267. m_nLockAdjustCount++;
  268. m_bAdjustScrollBar |= bWithScrollBar;
  269. }
  270. void CXTPCalendarControl::EndAdjust(BOOL bWithScrollBar)
  271. {
  272. m_bChanged = TRUE;
  273. m_nLockAdjustCount--;
  274. m_bAdjustScrollBar |= bWithScrollBar;
  275. if (m_nLockAdjustCount == 0)
  276. {
  277. AdjustLayout();
  278. if (m_bAdjustScrollBar)
  279. {
  280. AdjustScrollBar();
  281. }
  282. m_bAdjustScrollBar = FALSE;
  283. }
  284. }
  285. BEGIN_MESSAGE_MAP(CXTPCalendarControl, CWnd)
  286. //{{AFX_MSG_MAP(CXTPCalendarControl)
  287. ON_WM_PAINT()
  288. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  289. ON_WM_ERASEBKGND()
  290. ON_WM_SIZE()
  291. ON_WM_LBUTTONDOWN()
  292. ON_WM_RBUTTONDOWN()
  293. ON_WM_RBUTTONUP()
  294. ON_WM_LBUTTONUP()
  295. ON_WM_LBUTTONDBLCLK()
  296. ON_WM_CONTEXTMENU()
  297. ON_WM_MOUSEMOVE()
  298. ON_WM_MOUSEWHEEL()
  299. ON_WM_CHAR()
  300. ON_WM_KEYDOWN()
  301. ON_WM_SYSKEYDOWN()
  302. ON_WM_CAPTURECHANGED()
  303. ON_WM_VSCROLL()
  304. ON_WM_HSCROLL()
  305. ON_WM_SETCURSOR()
  306. ON_WM_TIMER()
  307. ON_WM_DESTROY()
  308. ON_WM_GETDLGCODE()
  309. ON_WM_ENABLE()
  310. ON_WM_SETFOCUS()
  311. ON_WM_KILLFOCUS()
  312. ON_WM_TIMECHANGE()
  313. ON_REGISTERED_MESSAGE(XTP_WM_TIME_ZONE_CHANGED, OnTimeZoneChanged)
  314. ON_WM_SYSCOLORCHANGE()
  315. ON_REGISTERED_MESSAGE(xtp_wm_SwitchView, OnSwitchView)
  316. ON_REGISTERED_MESSAGE(xtp_wm_UserAction, OnUserAction)
  317. ON_COMMAND(ID_EDIT_UNDO, OnUndo)
  318. ON_COMMAND(ID_EDIT_CUT, OnCut)
  319. ON_COMMAND(ID_EDIT_COPY, OnCopy)
  320. ON_COMMAND(ID_EDIT_PASTE, OnPaste)
  321. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateUndo)
  322. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCut)
  323. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCopy)
  324. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePaste)
  325. //  ON_CONTROL_REFLECT(ID_EDIT_UNDO, OnUndo)
  326. //  ON_UPDATE_COMMAND_UI_REFLECT(OnUpdateUndo)
  327. //}}AFX_MSG_MAP
  328. END_MESSAGE_MAP()
  329. /////////////////////////////////////////////////////////////////////////////
  330. // CXTPCalendarControl message handlers
  331. void CXTPCalendarControl::OnPaint()
  332. {
  333. CPaintDC dc(this); // device context for painting
  334. CRect rc;
  335. GetClientRect(&rc);
  336. if (rc.IsRectEmpty())
  337. return;
  338. // Check cached bitmap
  339. if ((!m_bChanged || m_bDisableRedraw) && m_bmpCache.GetSafeHandle() != 0)
  340. {
  341. CXTPCompatibleDC memDC(&dc, &m_bmpCache);
  342. dc.BitBlt(0, 0, rc.right, rc.bottom, &memDC, 0, 0, SRCCOPY);
  343. }
  344. else
  345. {
  346. CDC memDC;
  347. memDC.CreateCompatibleDC(&dc);
  348. if (!m_bmpCache.m_hObject)
  349. {
  350. m_bmpCache.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
  351. }
  352. CBitmap* pOldBitmap = memDC.SelectObject(&m_bmpCache);
  353. memDC.FillSolidRect(rc, 0xFF);
  354. OnDraw(&memDC);
  355. if (!IsWindowEnabled())
  356. {
  357. XTPImageManager()->DisableBitmap(memDC, rc, XTP_CALENDAR_DISABLED_COLOR_LIGHT, XTP_CALENDAR_DISABLED_COLOR_DARK);
  358. }
  359. dc.BitBlt(0, 0, rc.right, rc.bottom, &memDC, 0, 0, SRCCOPY);
  360. memDC.SelectObject(pOldBitmap);
  361. // update flag
  362. m_bChanged = FALSE;
  363. }
  364. }
  365. LRESULT CXTPCalendarControl::OnPrintClient(WPARAM wParam, LPARAM /*lParam*/)
  366. {
  367. CDC* pDC = CDC::FromHandle((HDC)wParam);
  368. if (pDC)
  369. {
  370. if (m_bmpCache.GetSafeHandle() == 0)
  371. OnDraw(pDC);
  372. else
  373. {
  374. CXTPCompatibleDC memDC(pDC, &m_bmpCache);
  375. CXTPClientRect rc(this);
  376. pDC->BitBlt(0, 0, rc.right, rc.bottom, &memDC, 0, 0, SRCCOPY);
  377. }
  378. }
  379. return TRUE;
  380. }
  381. BOOL CXTPCalendarControl::OnEraseBkgnd(CDC* /*pDC*/)
  382. {
  383. return TRUE;
  384. }
  385. void CXTPCalendarControl::OnSize(UINT nType, int cx, int cy)
  386. {
  387. if (m_bmpCache.m_hObject)
  388. {
  389. m_bmpCache.DeleteObject();
  390. }
  391. CWnd::OnSize(nType, cx, cy);
  392. if (::IsWindow(GetSafeHwnd()) && cx > 0 && cy > 0)
  393. {
  394. AdjustLayout();
  395. AdjustScrollBar();
  396. }
  397. }
  398. void CXTPCalendarControl::AdjustScrollBar(int nSBType)
  399. {
  400. if (!::IsWindow(GetSafeHwnd()) || !m_pActiveView)
  401. return;
  402. BeginUpdate();
  403. if (nSBType == SB_VERT || nSBType == -1)
  404. {
  405. AdjustScrollBarEx(SB_VERT);
  406. }
  407. if (nSBType == SB_HORZ || nSBType == -1)
  408. {
  409. AdjustScrollBarEx(SB_HORZ);
  410. }
  411. AdjustLayout();
  412. EndUpdate();
  413. }
  414. void CXTPCalendarControl::AdjustScrollBarEx(int nSBType)
  415. {
  416. ASSERT(nSBType == SB_VERT || nSBType == SB_HORZ);
  417. if (!m_pActiveView)
  418. {
  419. return;
  420. }
  421. SCROLLINFO  si ;
  422. si.cbSize = sizeof(SCROLLINFO);
  423. si.nMin = 0 ;
  424. si.nMax = 1;
  425. si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
  426. si.nPage = 1;
  427. si.nPos = 0;
  428. BOOL bEnabled = FALSE;
  429. if (nSBType == SB_VERT)
  430. {
  431. bEnabled = m_pActiveView->GetScrollBarInfoV(&si);
  432. }
  433. else if (nSBType == SB_HORZ)
  434. {
  435. bEnabled = m_pActiveView->GetScrollBarInfoH(&si);
  436. }
  437. else
  438. {
  439. ASSERT(FALSE);
  440. return;
  441. }
  442. if (si.nPos > si.nMax + 1 - (int)si.nPage)
  443. {
  444. int nPos_raw = si.nPos;
  445. si.nPos = si.nMax + 1 - (int)si.nPage;
  446. if (nSBType == SB_VERT)
  447. {
  448. m_pActiveView->ScrollV(si.nPos, nPos_raw);
  449. }
  450. else if (nSBType == SB_HORZ)
  451. {
  452. m_pActiveView->ScrollH(si.nPos, nPos_raw);
  453. }
  454. else
  455. {
  456. ASSERT(FALSE);
  457. return;
  458. }
  459. }
  460. if (bEnabled)
  461. {
  462. SetScrollInfo(nSBType, &si) ;
  463. }
  464. EnableScrollBarCtrl(nSBType, bEnabled);
  465. ::EnableScrollBar(m_hWnd, nSBType, (bEnabled && IsWindowEnabled()) ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH);
  466. }
  467. void CXTPCalendarControl::AdjustLayout()
  468. {
  469. if (!::IsWindow(GetSafeHwnd()))
  470. return;
  471. if (m_lcidActiveLocale != CXTPCalendarUtils::GetActiveLCID())
  472. {
  473. m_lcidActiveLocale = CXTPCalendarUtils::GetActiveLCID();
  474. XTP_SAFE_CALL1(m_pPaintManager, RefreshMetrics());
  475. XTP_SAFE_CALL1(m_pTheme, RefreshMetrics());
  476. }
  477. CClientDC dc(this);
  478. CXTPClientRect rcView(this);
  479. // horizontal scrolling support.
  480. SCROLLINFO si;
  481. if (m_pActiveView && m_pActiveView->GetScrollBarInfoH(&si))
  482. {
  483. ASSERT(m_pActiveView == m_pDayView);
  484. if (m_pActiveView == m_pDayView)
  485. {
  486. rcView.left -= si.nPos; //m_pDayView->m_nScrollOffsetX;
  487. rcView.right = rcView.left + si.nMax + 1 + m_pDayView->_GetTimeScaleWith();
  488. }
  489. }
  490. AdjustLayout(&dc, rcView);
  491. }
  492. void CXTPCalendarControl::AdjustLayout(CDC* pDC, const CRect& rcView)
  493. {
  494. if (m_pActiveView && !rcView.IsRectEmpty())
  495. {
  496. if (GetTheme())
  497. {
  498. m_pActiveView->AdjustLayout2(pDC, rcView, TRUE);
  499. }
  500. else
  501. {
  502. m_pActiveView->AdjustLayout(pDC, rcView, TRUE);
  503. }
  504. }
  505. }
  506. void CXTPCalendarControl::RedrawControl(BOOL bForce)
  507. {
  508. m_bChanged = TRUE;
  509. if (GetSafeHwnd() &&
  510. (bForce || (m_nLockUpdateCount == 0)))
  511. {
  512. Invalidate(FALSE);
  513. if (bForce)
  514. UpdateWindow();
  515. }
  516. }
  517. void CXTPCalendarControl::OnLButtonDown(UINT nFlags, CPoint point)
  518. {
  519. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  520. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  521. BOOL bStartEditing = FALSE;
  522. if (IsToolTipVisible())
  523. {
  524. CRect rcTip = m_wndTip.GetHoverRect();
  525. ScreenToClient(&rcTip);
  526. HideToolTip();
  527. bStartEditing = m_wndTip.IsAdvancedMode() && rcTip.PtInRect(point);
  528. }
  529. SetCapture();
  530. SetFocus();
  531. if (m_pActiveView)
  532. {
  533. m_pActiveView->OnLButtonDown(nFlags, point);
  534. if (bStartEditing)
  535. {
  536. m_pActiveView->StartEditNewEventInplace(_T(""));
  537. }
  538. }
  539. CWnd::OnLButtonDown(nFlags, point);
  540. // forward message to subscriber
  541. DWORD dwPoint = MAKELONG(point.x, point.y);
  542. SendNotification(XTP_NC_CALENDARLBUTTONDOWN, dwPoint, 0);
  543. }
  544. void CXTPCalendarControl::OnRButtonDown(UINT nFlags, CPoint point)
  545. {
  546. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  547. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  548. CWnd::OnRButtonDown(nFlags, point);
  549. // forward message to subscriber
  550. DWORD dwPoint = MAKELONG(point.x, point.y);
  551. SendNotification(XTP_NC_CALENDARRBUTTONDOWN, dwPoint, 0);
  552. }
  553. void CXTPCalendarControl::OnRButtonUp(UINT nFlags, CPoint point)
  554. {
  555. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  556. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  557. // forward message to subscriber
  558. DWORD dwPoint = MAKELONG(point.x, point.y);
  559. SendNotification(XTP_NC_CALENDARRBUTTONUP, dwPoint, 0);
  560. CWnd::OnRButtonUp(nFlags, point); // OnContextMenu will be called.
  561. }
  562. void CXTPCalendarControl::OnLButtonUp(UINT nFlags, CPoint point)
  563. {
  564. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  565. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  566. if (GetCapture() == this)
  567. ReleaseCapture();
  568. if (m_pActiveView)
  569. {
  570. m_pActiveView->OnLButtonUp(nFlags, point);
  571. }
  572. CWnd::OnLButtonUp(nFlags, point);
  573. // forward message to subscriber
  574. DWORD dwPoint = MAKELONG(point.x, point.y);
  575. SendNotification(XTP_NC_CALENDARLBUTTONUP, dwPoint, 0);
  576. }
  577. void CXTPCalendarControl::OnLButtonDblClk(UINT nFlags, CPoint point)
  578. {
  579. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  580. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  581. if (m_pActiveView)
  582. {
  583. m_pActiveView->OnLButtonDblClk(nFlags, point);
  584. }
  585. CWnd::OnLButtonDblClk(nFlags, point);
  586. // forward message to subscriber
  587. DWORD dwPoint = MAKELONG(point.x, point.y);
  588. SendNotification(XTP_NC_CALENDARLBUTTONDBLCLICK, dwPoint, 0);
  589. }
  590. void CXTPCalendarControl::OnMouseMove(UINT nFlags, CPoint point)
  591. {
  592. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  593. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  594. m_mouseMode = xtpCalendarMouseNothing;
  595. if (m_pActiveView)
  596. {
  597. m_pActiveView->OnMouseMove(nFlags, point);
  598. }
  599. CWnd::OnMouseMove(nFlags, point);
  600. // forward message to subscriber
  601. DWORD dwPoint = MAKELONG(point.x, point.y);
  602. SendNotification(XTP_NC_CALENDARMOUSEMOVE, dwPoint, 0);
  603. }
  604. void CXTPCalendarControl::OnCaptureChanged(CWnd* pWnd)
  605. {
  606. CWnd::OnCaptureChanged(pWnd);
  607. }
  608. void CXTPCalendarControl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  609. {
  610. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  611. CViewChangedContext viewChanged(this, xtpCalendarViewChangedLock);
  612. if (pScrollBar != NULL)
  613. {
  614. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  615. return;
  616. }
  617. if (!m_pActiveView)
  618. {
  619. return;
  620. }
  621. SCROLLINFO si;
  622. m_pActiveView->GetScrollBarInfoV(&si);
  623. int nCurPos = si.nPos;
  624. int nCurPos_raw = si.nPos;
  625. int nLimit = GetScrollLimit(SB_VERT);
  626. // decide what to do for each different scroll event
  627. switch (nSBCode)
  628. {
  629. case SB_TOP:
  630. nCurPos = nCurPos_raw = 0;
  631. break;
  632. case SB_BOTTOM:
  633. nCurPos = nCurPos_raw = nLimit;
  634. break;
  635. case SB_LINEUP:
  636. nCurPos = max(nCurPos - 1, 0);
  637. nCurPos_raw--;
  638. break;
  639. case SB_LINEDOWN:
  640. nCurPos = min(nCurPos + 1, nLimit);
  641. nCurPos_raw++;
  642. break;
  643. case SB_PAGEUP:
  644. nCurPos = max(nCurPos - (int)si.nPage, 0);
  645. nCurPos_raw -= (int)si.nPage;
  646. break;
  647. case SB_PAGEDOWN:
  648. nCurPos = min(nCurPos + (int)si.nPage, nLimit);
  649. nCurPos_raw += (int)si.nPage;
  650. break;
  651. case SB_THUMBTRACK:
  652. case SB_THUMBPOSITION:
  653. nCurPos = nCurPos_raw = nPos;
  654. break;
  655. }
  656. m_pActiveView->ScrollV(nCurPos, nCurPos_raw);
  657. SetScrollPos(SB_VERT, nCurPos, FALSE);
  658. AdjustScrollBar();
  659. }
  660. void CXTPCalendarControl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  661. {
  662. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  663. CViewChangedContext viewChanged(this, xtpCalendarViewChangedLock);
  664. if (pScrollBar != NULL)
  665. {
  666. CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
  667. return;
  668. }
  669. if (!m_pActiveView)
  670. {
  671. return;
  672. }
  673. SCROLLINFO si;
  674. int nScrollStep = 1;
  675. m_pActiveView->GetScrollBarInfoH(&si, &nScrollStep);
  676. int nCurPos = si.nPos;
  677. int nCurPos_raw = si.nPos;
  678. int nLimit = GetScrollLimit(SB_HORZ);
  679. // decide what to do for each different scroll event
  680. switch (nSBCode)
  681. {
  682. case SB_LEFT:
  683. nCurPos = nCurPos_raw = 0;
  684. break;
  685. case SB_RIGHT:
  686. nCurPos = nCurPos_raw = nLimit;
  687. break;
  688. case SB_LINELEFT:
  689. nCurPos = max(nCurPos - nScrollStep, 0);
  690. nCurPos_raw--;
  691. break;
  692. case SB_LINERIGHT:
  693. nCurPos = min(nCurPos + nScrollStep, nLimit);
  694. nCurPos_raw++;
  695. break;
  696. case SB_PAGELEFT:
  697. nCurPos = max(nCurPos - (int)si.nPage, 0);
  698. nCurPos_raw -= (int)si.nPage;
  699. break;
  700. case SB_PAGERIGHT:
  701. nCurPos = min(nCurPos + (int)si.nPage, nLimit);
  702. nCurPos_raw += (int)si.nPage;
  703. break;
  704. case SB_THUMBTRACK:
  705. case SB_THUMBPOSITION:
  706. nCurPos = nCurPos_raw = nPos;
  707. break;
  708. }
  709. m_pActiveView->ScrollH(nCurPos, nCurPos_raw);
  710. SetScrollPos(SB_HORZ, nCurPos, FALSE);
  711. AdjustScrollBar();
  712. }
  713. void CXTPCalendarControl::OnDraw(CDC* pDC)
  714. {
  715. ASSERT(m_pActiveView && pDC);
  716. if (m_pActiveView && pDC)
  717. m_pActiveView->OnDraw(pDC);
  718. }
  719. void CXTPCalendarControl::Populate()
  720. {
  721. if (IsToolTipVisible())
  722. {
  723. HideToolTip();
  724. }
  725. if (!m_pActiveView)
  726. return;
  727. if (::IsWindow(GetSafeHwnd()))
  728. {
  729. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  730. CViewChangedContext viewChanged(this, xtpCalendarViewChangedLock);
  731. CUpdateContext updateContext2(this, xtpCalendarUpdateAll);
  732. m_pActiveView->Populate();
  733. }
  734. else
  735. {
  736. m_pActiveView->Populate();
  737. }
  738. }
  739. BOOL CXTPCalendarControl::UpdateMouseCursor()
  740. {
  741. if (!AfxGetApp())
  742. {
  743. return FALSE;
  744. }
  745. switch (m_mouseMode)
  746. {
  747. case xtpCalendarMouseEventPreResizeV:
  748. case xtpCalendarMouseEventResizingV:
  749. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  750. TRACE_DRAGGING(_T("UpdateMouseCursor():: ResizingVn"));
  751. break;
  752. case xtpCalendarMouseEventPreResizeH:
  753. case xtpCalendarMouseEventResizingH:
  754. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  755. TRACE_DRAGGING(_T("UpdateMouseCursor():: ResizingHn"));
  756. break;
  757. case xtpCalendarMouseEventPreDrag:
  758. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
  759. TRACE_DRAGGING(_T("UpdateMouseCursor():: PreDragn"));
  760. break;
  761. case xtpCalendarMouseEventDragCopy:
  762. SetCursor(XTPResourceManager()->LoadCursor(XTP_IDC_CALENDAR_DRAGCOPY));
  763. TRACE_DRAGGING(_T("UpdateMouseCursor():: DragCopyn"));
  764. break;
  765. case xtpCalendarMouseEventDragMove:
  766. SetCursor(XTPResourceManager()->LoadCursor(XTP_IDC_CALENDAR_DRAGMOVE));
  767. TRACE_DRAGGING(_T("UpdateMouseCursor():: DragCopyn"));
  768. break;
  769. case xtpCalendarMouseEventDraggingOut:
  770. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_NO));
  771. TRACE_DRAGGING(_T("UpdateMouseCursor():: Dragging OUTn"));
  772. break;
  773. case xtpCalendarMouseNothing:
  774. default:
  775. TRACE_DRAGGING(_T("UpdateMouseCursor():: Nothingn"));
  776. return FALSE;
  777. }
  778. return TRUE;
  779. }
  780. BOOL CXTPCalendarControl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  781. {
  782. if (nHitTest == HTCLIENT)
  783. {
  784. if (UpdateMouseCursor())
  785. return TRUE;
  786. }
  787. return CWnd::OnSetCursor(pWnd, nHitTest, message);
  788. }
  789. BOOL CXTPCalendarControl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  790. {
  791. UINT uiMsg;
  792. int nScrollsCount = 0;
  793. // calculate what should be sent
  794. if (m_nRowsPerWheel == -1)
  795. {
  796. // A m_nRowsPerWheel value less than 0 indicates that the mouse wheel scrolls whole pages, not just lines.
  797. int nPagesScrolled = zDelta / 120;
  798. uiMsg = nPagesScrolled > 0 ? SB_PAGEUP : SB_PAGEDOWN;
  799. nScrollsCount = nPagesScrolled > 0 ? nPagesScrolled : -nPagesScrolled;
  800. }
  801. else
  802. {
  803. int nRowsScrolled = m_nRowsPerWheel * zDelta / 120;
  804. uiMsg = nRowsScrolled > 0 ? SB_LINEUP : SB_LINEDOWN;
  805. nScrollsCount = nRowsScrolled > 0 ? nRowsScrolled : -nRowsScrolled;
  806. }
  807. // send scroll messages
  808. for (int i = 0; i < nScrollsCount; i++)
  809. {
  810. PostMessage(WM_VSCROLL, uiMsg, 0);
  811. }
  812. // prevent parent from scrolling while calendar scroll pos is not min or max.
  813. //
  814. if (m_pActiveView)
  815. {
  816. SCROLLINFO  si;
  817. ::ZeroMemory(&si, sizeof(si));
  818. si.cbSize = sizeof(SCROLLINFO);
  819. BOOL bScrollEnabled = m_pActiveView->GetScrollBarInfoV(&si);
  820. if (bScrollEnabled)
  821. {
  822. int nViewType = m_pActiveView->GetViewType();
  823. if (nViewType == xtpCalendarDayView ||
  824. nViewType == xtpCalendarWorkWeekView)
  825. {
  826. INT nPosMin, nPosMax;
  827. GetScrollRange(SB_VERT, &nPosMin, &nPosMax);
  828. nPosMax = GetScrollLimit(SB_VERT);
  829. int nPos = GetScrollPos(SB_VERT);
  830. if (zDelta > 0 && nPos > nPosMin || zDelta < 0 && nPos < nPosMax)
  831. {
  832. return TRUE;
  833. }
  834. }
  835. else
  836. {
  837. return TRUE;
  838. }
  839. }
  840. }
  841. return CWnd::OnMouseWheel(nFlags, zDelta, pt);
  842. }
  843. //////////////////////////////////////////////////////////////////////////
  844. // View related
  845. //
  846. CXTPCalendarView* CXTPCalendarControl::GetActiveView()
  847. {
  848. return m_pActiveView;
  849. }
  850. CXTPCalendarView* CXTPCalendarControl::GetDayView()
  851. {
  852. if (m_pDayView == 0)
  853. {
  854. m_pDayView = new CXTPCalendarDayView(this);
  855. }
  856. return m_pDayView;
  857. }
  858. CXTPCalendarView* CXTPCalendarControl::GetWeekView()
  859. {
  860. if (m_pWeekView == 0)
  861. {
  862. m_pWeekView = new CXTPCalendarWeekView(this);
  863. }
  864. return m_pWeekView;
  865. }
  866. CXTPCalendarView* CXTPCalendarControl::GetMonthView()
  867. {
  868. if (m_pMonthView == 0)
  869. {
  870. m_pMonthView = new CXTPCalendarMonthView(this);
  871. }
  872. return m_pMonthView;
  873. }
  874. void CXTPCalendarControl::SetActiveView(CXTPCalendarView* pView)
  875. {
  876. CViewChangedContext viewChanged(this);
  877. CMDTARGET_ADDREF(pView);
  878. CXTPCalendarView* pInactiveView = m_pActiveView;
  879. if (pInactiveView)
  880. {
  881. pInactiveView->OnActivateView(FALSE, pView, pInactiveView);
  882. }
  883. m_pActiveView = pView;
  884. if (m_pActiveView)
  885. {
  886. m_pActiveView->OnActivateView(TRUE, m_pActiveView, pInactiveView);
  887. }
  888. CMDTARGET_RELEASE(pInactiveView);
  889. }
  890. void CXTPCalendarControl::SwitchActiveView(XTPCalendarViewType eViewType)
  891. {
  892. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  893. CViewChangedContext viewChanged(this, xtpCalendarViewChangedLock);
  894. CUpdateContext updateContext2(this, xtpCalendarUpdateRedraw | xtpCalendarUpdateLayout);
  895. CXTPCalendarView* pPrevView = GetActiveView();
  896. CXTPCalendarViewEventsPtr ptrSelEvents;
  897. COleDateTime dtSelStartDate, dtSelDay, dtSelDay2, dtSelEvent;
  898. COleDateTimeSpan spSelDayDuration(0.);
  899. BOOL bSelDay = FALSE;
  900. BOOL bSelAllDay = FALSE;
  901. if (pPrevView)
  902. {
  903. bSelDay = pPrevView->GetSelection(&dtSelDay, &dtSelDay2, &bSelAllDay);
  904. if (bSelDay)
  905. {
  906. spSelDayDuration = CXTPCalendarUtils::ResetTime(dtSelDay2) - CXTPCalendarUtils::ResetTime(dtSelDay);
  907. if (bSelAllDay && spSelDayDuration.GetTotalDays() >= 1)
  908. {
  909. spSelDayDuration -= COleDateTimeSpan(1, 0, 0, 0);
  910. }
  911. }
  912. ptrSelEvents = pPrevView->GetSelectedEvents();
  913. dtSelEvent.SetDate(9999, 1, 1);
  914. int nCount = ptrSelEvents ? ptrSelEvents->GetCount() : 0;
  915. for (int i = 0; i < nCount; i++)
  916. {
  917. COleDateTime dtEvent = XTP_SAFE_GET3(ptrSelEvents, GetAt(i), GetEvent(), GetStartTime(), (DATE)0);
  918. dtSelEvent = min(dtSelEvent, dtEvent);
  919. }
  920. dtSelStartDate = nCount ? dtSelEvent : (bSelDay ? dtSelDay : COleDateTime::GetCurrentTime());
  921. }
  922. COleDateTime dtWDStartTime = XTP_SAFE_GET1(GetCalendarOptions(), dtWorkDayStartTime, (DATE)0);
  923. if (eViewType == xtpCalendarDayView)
  924. {
  925. SetActiveView(GetDayView());
  926. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetDayView());
  927. if (!pDayView)
  928. {
  929. return;
  930. }
  931. pDayView->ResetSelection();
  932. pDayView->ShowDay(dtSelStartDate);
  933. COleDateTime dtSelBegin = CXTPCalendarUtils::UpdateTime(dtSelStartDate, dtWDStartTime);
  934. COleDateTime dtSelEnd = dtSelBegin + pDayView->GetCellDuration();
  935. pDayView->SetSelection(dtSelBegin, dtSelEnd, FALSE);
  936. }
  937. else if (eViewType == xtpCalendarWorkWeekView)
  938. {
  939. SetActiveView(GetDayView());
  940. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetDayView());
  941. if (!pDayView)
  942. {
  943. return;
  944. }
  945. pDayView->ShowWorkingDays(dtSelStartDate);
  946. pDayView->ResetSelection();
  947. COleDateTime dtSelBegin = CXTPCalendarUtils::UpdateTime(pDayView->GetViewDayDate(0), dtWDStartTime);
  948. COleDateTime dtSelEnd = dtSelBegin + pDayView->GetCellDuration();
  949. pDayView->SetSelection(dtSelBegin, dtSelEnd, FALSE);
  950. }
  951. else if (eViewType == xtpCalendarFullWeekView)
  952. {
  953. SetActiveView(GetDayView());
  954. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetDayView());
  955. if (!pDayView)
  956. {
  957. return;
  958. }
  959. COleDateTime dtWeekDay(dtSelStartDate);
  960. int nFirstWeekDay = GetFirstDayOfWeek();
  961. // adjust beginning of the week iteration period to the FirstDayOfWeek
  962. while (dtWeekDay.GetDayOfWeek() != nFirstWeekDay)
  963. dtWeekDay -= COleDateTimeSpan(1);
  964. pDayView->ShowDays(dtWeekDay, dtWeekDay + COleDateTimeSpan(6));
  965. pDayView->ResetSelection();
  966. COleDateTime dtSelBegin = CXTPCalendarUtils::UpdateTime(pDayView->GetViewDayDate(0), dtWDStartTime);
  967. COleDateTime dtSelEnd = dtSelBegin + pDayView->GetCellDuration();
  968. pDayView->SetSelection(dtSelBegin, dtSelEnd, FALSE);
  969. }
  970. else if (eViewType == xtpCalendarWeekView)
  971. {
  972. SetActiveView(GetWeekView());
  973. CXTPCalendarWeekView* pWeekView = DYNAMIC_DOWNCAST(CXTPCalendarWeekView, GetWeekView());
  974. if (!pWeekView)
  975. {
  976. return;
  977. }
  978. pWeekView->ResetSelection();
  979. pWeekView->ShowDay(dtSelStartDate);
  980. COleDateTime dtSel = CXTPCalendarUtils::ResetTime(dtSelStartDate);
  981. COleDateTime dtSel2 = dtSel + spSelDayDuration;
  982. pWeekView->SetSelection(dtSel, dtSel2, TRUE);
  983. }
  984. else if (eViewType == xtpCalendarMonthView)
  985. {
  986. SetActiveView(GetMonthView());
  987. CXTPCalendarMonthView* pMonthView = DYNAMIC_DOWNCAST(CXTPCalendarMonthView, GetMonthView());
  988. if (!pMonthView || !pMonthView->GetGrid())
  989. {
  990. return;
  991. }
  992. COleDateTime dtFirstOfMonth(dtSelStartDate.GetYear(), dtSelStartDate.GetMonth(), 1, 0, 0, 0);
  993. pMonthView->ResetSelection();
  994. pMonthView->ShowDay(dtFirstOfMonth);
  995. int nWCount = pMonthView->GetGrid()->GetWeeksCount();
  996. if (nWCount < 5)
  997. {
  998. pMonthView->GetGrid()->SetWeeksCount(5);
  999. }
  1000. COleDateTime dtMaxDate = pMonthView->GetViewDayDate(pMonthView->GetViewDayCount()-1);
  1001. COleDateTime dtSel = CXTPCalendarUtils::ResetTime(dtSelStartDate);
  1002. if (dtSel > dtMaxDate)
  1003. {
  1004. dtSel = pMonthView->GetViewDayDate(0);
  1005. }
  1006. COleDateTime dtSel2 = dtSel + spSelDayDuration;
  1007. pMonthView->SetSelection(dtSel, dtSel2, TRUE);
  1008. }
  1009. else
  1010. {
  1011. ASSERT(FALSE);
  1012. return;
  1013. }
  1014. CXTPCalendarView* pActiveView = GetActiveView();
  1015. if (pActiveView)
  1016. {
  1017. pActiveView->UnselectAllEvents();
  1018. }
  1019. //------------------------------------------------------------------------
  1020. Populate();
  1021. if (::IsWindow(GetSafeHwnd()) && IsWindowVisible())
  1022. {
  1023. AdjustScrollBar();
  1024. }
  1025. //------------------------------------------------------------------------
  1026. if (pActiveView && ptrSelEvents)
  1027. {
  1028. int nCount = ptrSelEvents->GetCount();
  1029. for (int i = 0; i < nCount; i++)
  1030. {
  1031. if (ptrSelEvents->GetAt(i))
  1032. {
  1033. pActiveView->SelectEvent(ptrSelEvents->GetAt(i)->GetEvent());
  1034. }
  1035. }
  1036. }
  1037. }
  1038. UINT CXTPCalendarControl::SetTimer(UINT uTimeOut_ms)
  1039. {
  1040. UINT uTimerID = m_uNextTimerID;
  1041. if (!::IsWindow(GetSafeHwnd()))
  1042. return 0;
  1043. UINT nRes = (UINT)CWnd::SetTimer(uTimerID, uTimeOut_ms, NULL);
  1044. if (!nRes)
  1045. {
  1046. ASSERT(FALSE);
  1047. return 0;
  1048. }
  1049. m_uNextTimerID++;
  1050. if (m_uNextTimerID < XTP_CALENDAR_FIRST_DYN_TIMERID)
  1051. {
  1052. m_uNextTimerID = XTP_CALENDAR_FIRST_DYN_TIMERID;
  1053. }
  1054. return uTimerID;
  1055. }
  1056. void CXTPCalendarControl::OnTimer(UINT_PTR uTimerID)
  1057. {
  1058. ASSERT(m_pActiveView);
  1059. if (uTimerID == m_uPopulateRequest_TimerID)
  1060. {
  1061. KillTimer(m_uPopulateRequest_TimerID);
  1062. m_uPopulateRequest_TimerID = 0;
  1063. Populate();
  1064. return;
  1065. }
  1066. else if (uTimerID == m_uRedrawRequest_TimerID)
  1067. {
  1068. KillTimer(m_uRedrawRequest_TimerID);
  1069. m_uRedrawRequest_TimerID = 0;
  1070. CUpdateContext updateContext(this, xtpCalendarUpdateRedraw);
  1071. return;
  1072. }
  1073. else if (uTimerID == XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID)
  1074. {
  1075. KillTimer(XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID);
  1076. CUpdateContext updateContext(this, xtpCalendarUpdateAll);
  1077. if (GetTheme())
  1078. {
  1079. GetTheme()->RefreshMetrics();
  1080. }
  1081. else if (m_pPaintManager)
  1082. {
  1083. m_pPaintManager->RefreshMetrics();
  1084. }
  1085. return;
  1086. }
  1087. if (m_pActiveView)
  1088. {
  1089. m_pActiveView->OnTimer(uTimerID);
  1090. DBG_TRACE_TIMER(_T("on Timer: ID=%d  n"), uTimerID);
  1091. }
  1092. }
  1093. void CXTPCalendarControl::OnOptionsChanged(int nOptionRelation)
  1094. {
  1095. SendNotification(XTP_NC_CALENDAROPTIONSWASCHANGED, nOptionRelation, 0);
  1096. KillTimer(XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID);
  1097. CWnd::SetTimer(XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID, XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMEOUT, NULL);
  1098. }
  1099. ///////////////////////////////////////////////////////////////////////////
  1100. // Data part
  1101. //
  1102. CString CXTPCalendarControl::DataSourceFromConStr(LPCTSTR lpszConnectionString)
  1103. {
  1104. ASSERT(lpszConnectionString);
  1105. if (!lpszConnectionString || 0 == _tcslen(lpszConnectionString))
  1106. {
  1107. return _T("");
  1108. }
  1109. CString strConnStr_lower = lpszConnectionString;
  1110. strConnStr_lower.MakeLower();
  1111. int nIndex = strConnStr_lower.Find(_T("data source="));
  1112. if (nIndex != -1)
  1113. {
  1114. CString strDataSource = strConnStr_lower.Mid(nIndex + 12);
  1115. if (strDataSource.IsEmpty())
  1116. return _T("");
  1117. if ((strDataSource[0] == _T(''') || strDataSource[0] == _T('"')) && strDataSource.GetLength() > 2)
  1118. {
  1119. TCHAR chQuot = strDataSource[0];
  1120. DELETE_S(strDataSource, 0);
  1121. int nQuot2Idx = FIND_S(strDataSource, chQuot, 0);
  1122. if (nQuot2Idx >= 0)
  1123. {
  1124. DELETE_S(strDataSource, nQuot2Idx, strDataSource.GetLength() - nQuot2Idx);
  1125. }
  1126. }
  1127. return strDataSource;
  1128. }
  1129. return strConnStr_lower;
  1130. }
  1131. XTPCalendarDataProvider CXTPCalendarControl::DataProviderTypeFromConStr(
  1132. LPCTSTR lpszConnectionString,
  1133. XTPCalendarDataProvider eDPDefault)
  1134. {
  1135. ASSERT(lpszConnectionString);
  1136. if (!lpszConnectionString)
  1137. {
  1138. return eDPDefault;
  1139. }
  1140. CString strConnStr_lower(lpszConnectionString);
  1141. strConnStr_lower.MakeLower();
  1142. BOOL bProviderCustom = strConnStr_lower.Find(_T("provider=custom")) != -1;
  1143. if (bProviderCustom)
  1144. {
  1145. return xtpCalendarDataProviderCustom;
  1146. }
  1147. BOOL bProviderMAPI   = strConnStr_lower.Find(_T("provider=mapi"))   != -1;
  1148. if (bProviderMAPI)
  1149. {
  1150. return xtpCalendarDataProviderMAPI;
  1151. }
  1152. BOOL bProviderXML   = strConnStr_lower.Find(_T("provider=xml")) != -1;
  1153. if (bProviderXML)
  1154. {
  1155. return xtpCalendarDataProviderMemory;
  1156. }
  1157. BOOL bProvider = strConnStr_lower.Find(_T("provider=")) != -1;
  1158. BOOL bDSN      = strConnStr_lower.Find(_T("dsn="))      != -1;
  1159. if (bProvider || bDSN)
  1160. {
  1161. return xtpCalendarDataProviderDatabase;
  1162. }
  1163. return eDPDefault;
  1164. }
  1165. CXTPCalendarData* CXTPCalendarControl::CreateDataProvider(LPCTSTR lpszConnectionString)
  1166. {
  1167. ASSERT(lpszConnectionString);
  1168. if (!lpszConnectionString)
  1169. {
  1170. return NULL;
  1171. }
  1172. XTPCalendarDataProvider eDPType = DataProviderTypeFromConStr(lpszConnectionString, xtpCalendarDataProviderMemory);
  1173. CXTPCalendarData* pDataProvider = CreateDataProvider(eDPType);
  1174. if (pDataProvider)
  1175. {
  1176. pDataProvider->SetConnectionString(lpszConnectionString);
  1177. }
  1178. return pDataProvider;
  1179. }
  1180. CXTPCalendarData* CXTPCalendarControl::CreateDataProvider(XTPCalendarDataProvider eDataProvider)
  1181. {
  1182. CXTPCalendarData* pDataProvider = NULL;
  1183. switch (eDataProvider)
  1184. {
  1185. case xtpCalendarDataProviderMemory:
  1186. pDataProvider = new CXTPCalendarMemoryDataProvider();
  1187. break;
  1188. case xtpCalendarDataProviderDatabase:
  1189. pDataProvider = new CXTPCalendarDatabaseDataProvider();
  1190. break;
  1191. case xtpCalendarDataProviderMAPI:
  1192. pDataProvider = new CXTPCalendarMAPIDataProvider();
  1193. break;
  1194. case xtpCalendarDataProviderCustom:
  1195. pDataProvider = new CXTPCalendarCustomDataProvider();
  1196. break;
  1197. default:
  1198. ASSERT(FALSE);
  1199. }
  1200. return pDataProvider;
  1201. }
  1202. void CXTPCalendarControl::_SetDataProvider(CXTPCalendarData* pDataProvider,
  1203.   BOOL bCloseDataProviderWhenDestroy)
  1204. {
  1205. if (m_pRemindersManager)
  1206. {
  1207. VERIFY( m_pRemindersManager->StopMonitoring() );
  1208. }
  1209. CMDTARGET_ADDREF(pDataProvider);
  1210. if (m_pOptions)
  1211. {
  1212. m_pOptions->SetDataProvider(pDataProvider);
  1213. }
  1214. // set current DP
  1215. if (m_pResourcesNf)
  1216. {
  1217. m_pResourcesNf->RemoveAll();
  1218. CXTPCalendarResource* pRC = new CXTPCalendarResource(this);
  1219. if (pRC)
  1220. {
  1221. m_pResourcesNf->Add(pRC);
  1222. pRC->SetDataProvider(pDataProvider, bCloseDataProviderWhenDestroy);
  1223. }
  1224. }
  1225. CMDTARGET_RELEASE(pDataProvider);
  1226. }
  1227. void CXTPCalendarControl::SetDataProvider(CXTPCalendarData* pDataProvider,
  1228.   BOOL bCloseDataProviderWhenDestroy)
  1229. {
  1230. _SetDataProvider(pDataProvider, bCloseDataProviderWhenDestroy);
  1231. AdviseToDataProvider();
  1232. }
  1233. void CXTPCalendarControl::SetDataProvider(LPCTSTR lpszConnectionString)
  1234. {
  1235. ASSERT(lpszConnectionString);
  1236. if (!lpszConnectionString)
  1237. {
  1238. return;
  1239. }
  1240. CXTPCalendarData* pDataProvider = CreateDataProvider(lpszConnectionString);
  1241. if (pDataProvider)
  1242. {
  1243. _SetDataProvider(pDataProvider, TRUE);
  1244. CMDTARGET_RELEASE(pDataProvider);
  1245. }
  1246. AdviseToDataProvider();
  1247. }
  1248. void CXTPCalendarControl::SetDataProvider(
  1249. XTPCalendarDataProvider eDataProvider, LPCTSTR lpszConnectionString)
  1250. {
  1251. CXTPCalendarData* pDataProvider = CreateDataProvider(eDataProvider);
  1252. if (pDataProvider)
  1253. {
  1254. if (lpszConnectionString)
  1255. {
  1256. pDataProvider->SetConnectionString(lpszConnectionString);
  1257. }
  1258. if (eDataProvider == xtpCalendarDataProviderMemory && !lpszConnectionString)
  1259. {
  1260. VERIFY(pDataProvider->Open());
  1261. }
  1262. _SetDataProvider(pDataProvider, TRUE);
  1263. CMDTARGET_RELEASE(pDataProvider);
  1264. }
  1265. AdviseToDataProvider();
  1266. }
  1267. CXTPCalendarData* CXTPCalendarControl::GetDataProvider()
  1268. {
  1269. ASSERT(this);
  1270. if (this && m_pResourcesNf && m_pResourcesNf->GetCount() && m_pResourcesNf->GetAt(0))
  1271. {
  1272. return m_pResourcesNf->GetAt(0)->GetDataProvider();
  1273. }
  1274. return NULL;
  1275. }
  1276. CXTPCalendarResources* CXTPCalendarControl::GetResources()
  1277. {
  1278. ASSERT(this);
  1279. return this ? m_pResourcesNf : NULL;
  1280. }
  1281. void CXTPCalendarControl::SetResources(CXTPCalendarResources* pResources,
  1282.    CXTPCalendarData* pOptionsDataProvider)
  1283. {
  1284. if (!m_pResourcesNf || !pResources || pResources->GetCount() == 0)
  1285. {
  1286. ASSERT(FALSE);
  1287. return;
  1288. }
  1289. if (!pOptionsDataProvider)
  1290. {
  1291. pOptionsDataProvider = XTP_SAFE_GET2(pResources, GetAt(0), GetDataProvider(), NULL);
  1292. }
  1293. if (m_pOptions)
  1294. {
  1295. m_pOptions->SetDataProvider(pOptionsDataProvider);
  1296. }
  1297. // copy data to allow using self as input parameter
  1298. CXTPCalendarResources arRes;
  1299. arRes.Append(pResources);
  1300. m_pResourcesNf->RemoveAll();
  1301. m_pResourcesNf->Append(&arRes);
  1302. // reset view's configurations
  1303. XTP_SAFE_CALL1(m_pDayView,   SetResources(NULL));
  1304. XTP_SAFE_CALL1(m_pMonthView, SetResources(NULL));
  1305. XTP_SAFE_CALL1(m_pWeekView,  SetResources(NULL));
  1306. AdviseToDataProvider();
  1307. }
  1308. void CXTPCalendarControl::AdviseToDataProvider()
  1309. {
  1310. m_Sink_DP.UnadviseAll();
  1311. m_cnidOnReminders = 0;
  1312. if (m_pResourcesNf)
  1313. {
  1314. CXTPNotifyConnection* pDPConn = m_pResourcesNf->GetConnection();
  1315. ASSERT(pDPConn);
  1316. if (pDPConn)
  1317. {
  1318. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAROPTIONSWASCHANGED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1319. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAREVENTWASADDED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1320. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAREVENTWASDELETED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1321. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAREVENTWASCHANGED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1322. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDARPATTERNWASADDED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1323. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDARPATTERNWASDELETED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1324. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDARPATTERNWASCHANGED, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1325. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoRetrieveDayEvents, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1326. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoRemoveAllEvents, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1327. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoRead_Event, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1328. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoRead_RPattern, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1329. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoCreate_Event, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1330. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoUpdate_Event, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1331. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoDelete_Event, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1332. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoCreate_RPattern, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1333. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoUpdate_RPattern, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1334. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoDelete_RPattern, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1335. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoGetAllEvents_raw, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1336. m_Sink_DP.Advise(pDPConn, XTP_NC_CALENDAR_DoGetUpcomingEvents, &CXTPCalendarControl::OnEvent_FromDataProvider);
  1337. }
  1338. m_pResourcesNf->ReBuildInternalData();
  1339. }
  1340. _AdviseToReminders_StartMonitoring();
  1341. SendNotification(XTP_NC_CALENDAR_RESOURCES_WHERE_CHANGED, 0, 0);
  1342. }
  1343. //////////////////////////////////////////////////////////////////////////
  1344. // Reminders
  1345. BOOL CXTPCalendarControl::IsRemindersEnabled() const
  1346. {
  1347. return m_pRemindersManager != NULL;
  1348. }
  1349. void CXTPCalendarControl::EnableReminders(BOOL bEnable)
  1350. {
  1351. if (bEnable && m_pRemindersManager)
  1352. {
  1353. // Already enabled. skip.
  1354. return;
  1355. }
  1356. if (!bEnable && !m_pRemindersManager)
  1357. {
  1358. // Already disabled. skip.
  1359. return;
  1360. }
  1361. // 1. Enable.
  1362. if (bEnable)
  1363. {
  1364. ASSERT(!m_pRemindersManager);
  1365. CMDTARGET_RELEASE(m_pRemindersManager);
  1366. m_pRemindersManager = new CXTPCalendarRemindersManager();
  1367. _AdviseToReminders_StartMonitoring();
  1368. }
  1369. // 2. Disable
  1370. if (!bEnable)
  1371. {
  1372. ASSERT(m_pRemindersManager);
  1373. if (m_pRemindersManager)
  1374. {
  1375. VERIFY( m_pRemindersManager->StopMonitoring() );
  1376. if (m_cnidOnReminders)
  1377. {
  1378. m_Sink_DP.Unadvise(m_cnidOnReminders);
  1379. m_cnidOnReminders = 0;
  1380. }
  1381. }
  1382. CMDTARGET_RELEASE(m_pRemindersManager);
  1383. }
  1384. }
  1385. void CXTPCalendarControl::_AdviseToReminders_StartMonitoring()
  1386. {
  1387. if (m_pRemindersManager && m_pResourcesNf)
  1388. {
  1389. CXTPNotifyConnection* pRMConn = m_pRemindersManager->GetConnection();
  1390. ASSERT(pRMConn);
  1391. if (pRMConn)
  1392. {
  1393. m_cnidOnReminders = m_Sink_DP.Advise(pRMConn, XTP_NC_CALENDAR_ON_REMINDERS, &CXTPCalendarControl::OnEvent_Reminders);
  1394. ASSERT(m_cnidOnReminders);
  1395. VERIFY(m_pRemindersManager->StartMonitoring(m_pResourcesNf,
  1396. m_spRemindersUpdatePeriod) );
  1397. }
  1398. }
  1399. }
  1400. void CXTPCalendarControl::EnableMarkup(BOOL bEnableMarkup)
  1401. {
  1402. if (IsMarkupEnabled() == bEnableMarkup)
  1403. return;
  1404. if (!bEnableMarkup)
  1405. {
  1406. CXTPMarkupContext* pStoredContext = m_pMarkupContext;
  1407. // to disable markup
  1408. m_pMarkupContext = NULL;
  1409. // to destroy all cached markup elements
  1410. Populate();
  1411. XTPMarkupReleaseContext(pStoredContext);
  1412. }
  1413. else
  1414. {
  1415. ASSERT(IsWindow(m_hWnd));
  1416. m_pMarkupContext = XTPMarkupCreateContext(m_hWnd);
  1417. }
  1418. RedrawControl(FALSE);
  1419. }
  1420. void CXTPCalendarControl::OnEnable(BOOL bEnable)
  1421. {
  1422. UNREFERENCED_PARAMETER(bEnable);
  1423. AdjustScrollBar();
  1424. }
  1425. UINT CXTPCalendarControl::OnGetDlgCode()
  1426. {
  1427. return DLGC_WANTARROWS | DLGC_WANTTAB | DLGC_WANTALLKEYS;
  1428. }
  1429. void CXTPCalendarControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  1430. {
  1431. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  1432. CViewChangedContext viewChanged(this, xtpCalendarViewChangedLock);
  1433. if (m_pActiveView)
  1434. {
  1435. m_pActiveView->OnChar(nChar, nRepCnt, nFlags);
  1436. }
  1437. }
  1438. void CXTPCalendarControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1439. {
  1440. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  1441. CUpdateContext updateContext(this, xtpCalendarUpdateRedrawIfNeed);
  1442. CViewChangedContext viewChanged(this, xtpCalendarViewChangedLock);
  1443. #ifdef XTP_CALENDAR_SITENOTIFY_KEY
  1444. if (!XTP_CALENDAR_SITENOTIFY_KEY(this, TRUE, nChar))
  1445. return;
  1446. #endif
  1447. if (nChar == 0)
  1448. {
  1449. return;
  1450. }
  1451. SendNotification(XTP_NC_CALENDARKEYDOWN, (DWORD)nChar, 0);
  1452. if (m_pActiveView)
  1453. {
  1454. m_pActiveView->OnKeyDown(nChar, nRepCnt, nFlags);
  1455. }
  1456. }
  1457. void CXTPCalendarControl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1458. {
  1459. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  1460. #ifdef XTP_CALENDAR_SITENOTIFY_KEY
  1461. if (!XTP_CALENDAR_SITENOTIFY_KEY(this, TRUE, nChar))
  1462. return;
  1463. #endif
  1464. if (nChar == 0)
  1465. {
  1466. return;
  1467. }
  1468. if (m_pActiveView)
  1469. {
  1470. if (m_pActiveView->OnSysKeyDown(nChar, nRepCnt, nFlags))
  1471. {
  1472. return;
  1473. }
  1474. }
  1475. CWnd::OnSysKeyDown(nChar, nRepCnt, nFlags);
  1476. }
  1477. BOOL CXTPCalendarControl::OnWndMsg_Children(UINT message, WPARAM wParam, LPARAM lParam,
  1478. LRESULT* /*pResult*/)
  1479. {
  1480. ASSERT(m_pActiveView);
  1481. if (!m_pActiveView)
  1482. return FALSE;
  1483. if (message == WM_KEYDOWN)
  1484. {
  1485. UINT uRepCnt = LOWORD(lParam);
  1486. UINT uFlags = HIWORD(lParam);
  1487. if (wParam == VK_RETURN || wParam == VK_ESCAPE)
  1488. {
  1489. OnKeyDown((UINT)wParam, uRepCnt, uFlags);
  1490. return TRUE;
  1491. }
  1492. BOOL bEditSubject = m_pActiveView->m_eDraggingMode == xtpCalendaDragModeEditSubject;
  1493. if (bEditSubject && wParam == VK_TAB)
  1494. {
  1495. OnKeyDown((UINT)wParam, uRepCnt, uFlags);
  1496. return TRUE;
  1497. }
  1498. }
  1499. else if (message == WM_MOUSEMOVE)
  1500. {
  1501. if (m_pActiveView->m_eDraggingMode == xtpCalendaDragModeEditSubject)
  1502. {
  1503. m_mouseMode = xtpCalendarMouseNothing;
  1504. m_pActiveView->OnMouseMove((UINT)wParam, CPoint(lParam));
  1505. }
  1506. }
  1507. return FALSE;
  1508. }
  1509. void CXTPCalendarControl::ShowToolTip(const CString& strText, const CRect rcToolTip,
  1510.   CFont* pFont, BOOL bAdvanced)
  1511. {
  1512. if (!m_bEnableToolTips || GetSafeHwnd() == NULL)
  1513. {
  1514. return;
  1515. }
  1516. if (!m_wndTip.GetSafeHwnd())
  1517. {
  1518. m_wndTip.Create(this);
  1519. }
  1520. m_wndTip.SetTheme(GetTheme());
  1521. m_wndTip.SetFont(pFont);
  1522. m_wndTip.SetTooltipText(strText);
  1523. CRect rcTip(rcToolTip);
  1524. if (!bAdvanced)
  1525. {
  1526. rcTip.OffsetRect(7, 0);
  1527. CSize rcNeeded = m_wndTip.CalcToolTipRect();
  1528. rcTip.right = rcTip.left + rcNeeded.cx;
  1529. rcTip.bottom = rcTip.top + rcNeeded.cy;
  1530. }
  1531. else
  1532. {
  1533. rcTip.DeflateRect(0, 0, 7, 0);
  1534. }
  1535. ClientToScreen(rcTip);
  1536. m_wndTip.SetHoverRect(rcTip);
  1537. BOOL bShow = !strText.IsEmpty();
  1538. m_wndTip.Activate(bShow, bAdvanced);
  1539. TRACKMOUSEEVENT tme =
  1540. {
  1541. sizeof(TRACKMOUSEEVENT), TME_LEAVE, GetSafeHwnd(), 0
  1542. };
  1543. _TrackMouseEvent (&tme);
  1544. }
  1545. void CXTPCalendarControl::HideToolTip()
  1546. {
  1547. if (!GetSafeHwnd() || !m_wndTip.GetSafeHwnd())
  1548. {
  1549. return;
  1550. }
  1551. m_wndTip.Activate(FALSE);
  1552. }
  1553. BOOL CXTPCalendarControl::IsToolTipVisible() const
  1554. {
  1555. return (m_wndTip.GetSafeHwnd() != NULL) && m_wndTip.IsWindowVisible();
  1556. }
  1557. void CXTPCalendarControl::SetPaintManager(CXTPCalendarPaintManager* pPaintManager)
  1558. {
  1559. ASSERT(pPaintManager);
  1560. CUpdateContext updateContext(this, xtpCalendarUpdateRedraw);
  1561. CMDTARGET_RELEASE(m_pPaintManager);
  1562. m_pPaintManager = pPaintManager;
  1563. }
  1564. void CXTPCalendarControl::OnSysColorChange()
  1565. {
  1566. CUpdateContext updateContext(this, xtpCalendarUpdateRedraw);
  1567. if (m_pPaintManager)
  1568. {
  1569. m_pPaintManager->RefreshMetrics();
  1570. }
  1571. if (GetTheme())
  1572. {
  1573. GetTheme()->RefreshMetrics();
  1574. }
  1575. AdjustLayout();
  1576. CWnd::OnSysColorChange();
  1577. }
  1578. LRESULT CXTPCalendarControl::OnTimeZoneChanged(WPARAM, LPARAM)
  1579. {
  1580. if (!m_pResourcesNf)
  1581. return 0;
  1582. CXTPCalendarResources* pResByDP = m_pResourcesNf->GetResourcesGroupedByDP();
  1583. ASSERT(pResByDP);
  1584. if (!pResByDP)
  1585. return 0;
  1586. BOOL bDataChanged = FALSE;
  1587. int nCount = pResByDP->GetCount();
  1588. for (int i = 0; i < nCount; i++)
  1589. {
  1590. CXTPCalendarResource* pRC = pResByDP->GetAt(i);
  1591. ASSERT(pRC);
  1592. if (pRC && pRC->GetDataProvider())
  1593. {
  1594. BOOL bChanged = pRC->GetDataProvider()->OnTimeZoneChanged();
  1595. bDataChanged |= bChanged;
  1596. }
  1597. }
  1598. if (bDataChanged)
  1599. {
  1600. CUpdateContext updateContext(this, xtpCalendarUpdateAll);
  1601. AdviseToDataProvider();
  1602. Populate();
  1603. }
  1604. return 0;
  1605. }
  1606. void CXTPCalendarControl::OnTimeChange()
  1607. {
  1608. CUpdateContext updateContext(this, xtpCalendarUpdateAll);
  1609. CWnd::OnTimeChange();
  1610. }
  1611. void CXTPCalendarControl::OnEditCommand(UINT uCommandID)
  1612. {
  1613. if (uCommandID == ID_EDIT_UNDO)
  1614. {
  1615. OnUndo();
  1616. }
  1617. else if (uCommandID == ID_EDIT_CUT)
  1618. {
  1619. OnCut();
  1620. }
  1621. else if (uCommandID == ID_EDIT_COPY)
  1622. {
  1623. OnCopy();
  1624. }
  1625. else if (uCommandID == ID_EDIT_PASTE)
  1626. {
  1627. OnPaste();
  1628. }
  1629. }
  1630. void CXTPCalendarControl::OnUndo()
  1631. {
  1632. if (m_pActiveView)
  1633. {
  1634. if (m_pActiveView->CanUndo())
  1635. {
  1636. m_pActiveView->Undo();
  1637. }
  1638. else if (m_pActiveView->CanRedo())
  1639. {
  1640. m_pActiveView->Redo();
  1641. }
  1642. }
  1643. }
  1644. void CXTPCalendarControl::OnCut()
  1645. {
  1646. if (m_pActiveView)
  1647. {
  1648. CWaitCursor _WC;
  1649. m_pActiveView->Cut();
  1650. }
  1651. }
  1652. void CXTPCalendarControl::OnCopy()
  1653. {
  1654. if (m_pActiveView)
  1655. {
  1656. CWaitCursor _WC;
  1657. m_pActiveView->Copy();
  1658. }
  1659. }
  1660. void CXTPCalendarControl::OnPaste()
  1661. {
  1662. if (m_pActiveView)
  1663. {
  1664. CWaitCursor _WC;
  1665. m_pActiveView->Paste();
  1666. }
  1667. }
  1668. void CXTPCalendarControl::OnUpdateCmdUI(CCmdUI* pCmdUI)
  1669. {
  1670. if (pCmdUI->m_nID == ID_EDIT_UNDO)
  1671. {
  1672. OnUpdateUndo(pCmdUI);
  1673. }
  1674. else if (pCmdUI->m_nID == ID_EDIT_CUT)
  1675. {
  1676. OnUpdateCut(pCmdUI);
  1677. }
  1678. else if (pCmdUI->m_nID == ID_EDIT_COPY)
  1679. {
  1680. OnUpdateCopy(pCmdUI);
  1681. }
  1682. else if (pCmdUI->m_nID == ID_EDIT_PASTE)
  1683. {
  1684. OnUpdatePaste(pCmdUI);
  1685. }
  1686. }
  1687. void CXTPCalendarControl::OnUpdateUndo(CCmdUI* pCmdUI)
  1688. {
  1689. if (pCmdUI->m_nID != ID_EDIT_UNDO || !m_pActiveView)
  1690. {
  1691. ASSERT(FALSE);
  1692. return;
  1693. }
  1694. if (m_pActiveView->CanUndo())
  1695. {
  1696. pCmdUI->Enable(TRUE);
  1697. pCmdUI->SetText(m_strUndoUIText);
  1698. }
  1699. else if (m_pActiveView->CanRedo())
  1700. {
  1701. pCmdUI->Enable(TRUE);
  1702. pCmdUI->SetText(m_strRedoUIText);
  1703. }
  1704. else
  1705. {
  1706. pCmdUI->Enable(FALSE);
  1707. pCmdUI->SetText(m_strUndoUIText);
  1708. }
  1709. }
  1710. void CXTPCalendarControl::OnUpdateCut(CCmdUI* pCmdUI)
  1711. {
  1712. if (pCmdUI->m_nID != ID_EDIT_CUT || !m_pActiveView)
  1713. {
  1714. ASSERT(FALSE);
  1715. return;
  1716. }
  1717. pCmdUI->Enable(m_pActiveView->CanCut());
  1718. }
  1719. void CXTPCalendarControl::OnUpdateCopy(CCmdUI* pCmdUI)
  1720. {
  1721. if (pCmdUI->m_nID != ID_EDIT_COPY || !m_pActiveView)
  1722. {
  1723. ASSERT(FALSE);
  1724. return;
  1725. }
  1726. pCmdUI->Enable(m_pActiveView->CanCopy());
  1727. }
  1728. void CXTPCalendarControl::OnUpdatePaste(CCmdUI* pCmdUI)
  1729. {
  1730. if (pCmdUI->m_nID != ID_EDIT_PASTE || !m_pActiveView)
  1731. {
  1732. ASSERT(FALSE);
  1733. return;
  1734. }
  1735. pCmdUI->Enable(m_pActiveView->CanPaste());
  1736. }
  1737. void CXTPCalendarControl::OnContextMenu(CWnd* /*pWnd*/, CPoint pos)
  1738. {
  1739. if (m_mouseMode != xtpCalendarMouseNothing)
  1740. return;
  1741. CPoint ptClient = pos;
  1742. ScreenToClient(&ptClient);
  1743. // forward message to subscriber
  1744. DWORD dwPoint = MAKELONG(ptClient.x, ptClient.y);
  1745. SendNotification(XTP_NC_CALENDARCONTEXTMENU, dwPoint, 0);
  1746. }
  1747. LRESULT CXTPCalendarControl::OnUserAction(WPARAM dwParam1, LPARAM dwParam2)
  1748. {
  1749. int nButtonMask = xtpCalendarScrollDayButton_DayViewUp | xtpCalendarScrollDayButton_DayViewDown;
  1750. int eButton = (int)(dwParam1 & nButtonMask);
  1751. if ((dwParam1 & xtpCalendarUserAction_OnScrollDay) && eButton && m_pDayView)
  1752. {
  1753. CXTPCalendarDayViewDay* pDVday = m_pDayView->GetViewDay(HIWORD(dwParam2));
  1754. CXTPCalendarDayViewGroup* pDVGroup = pDVday ? pDVday->GetViewGroup(LOWORD(dwParam2)) : NULL;
  1755. ASSERT(pDVGroup);
  1756. if (!pDVGroup || pDVGroup->UserAction_OnScrollDay((XTPCalendarScrollDayButton)eButton))
  1757. return 0;
  1758. CXTPCalendarDayViewEvent* pEVFirst = NULL, *pEVLast = NULL;
  1759. pDVGroup->FindMinMaxGroupDayEvents(pEVFirst, pEVLast);
  1760. if (eButton == xtpCalendarScrollDayButton_DayViewUp)
  1761. {
  1762. ASSERT(pEVFirst);
  1763. if (pEVFirst)
  1764. m_pDayView->EnsureVisible(pEVFirst);
  1765. }
  1766. else if (eButton == xtpCalendarScrollDayButton_DayViewDown)
  1767. {
  1768. ASSERT(pEVLast);
  1769. if (pEVLast)
  1770. m_pDayView->EnsureVisible(pEVLast);
  1771. }
  1772. else {
  1773. ASSERT(FALSE);
  1774. }
  1775. }
  1776. else  if (dwParam1 & xtpCalendarUserAction_OnExpandDay)
  1777. {
  1778. COleDateTime dtDate = (DATE)(LONG)dwParam2;
  1779. nButtonMask = xtpCalendarExpandDayButton_WeekView | xtpCalendarExpandDayButton_MonthView;
  1780. eButton = (int)(dwParam1 & nButtonMask);
  1781. CXTPCalendarViewDay* pActiveDay = XTP_SAFE_GET1(GetActiveView(), _GetViewDay(dtDate), NULL);
  1782. ASSERT(pActiveDay);
  1783. if (!pActiveDay)
  1784. return 0;
  1785. if (pActiveDay->UserAction_OnExpandDay((XTPCalendarExpandDayButton)eButton))
  1786. return 0;
  1787. // default processing
  1788. SwitchActiveView(xtpCalendarDayView);
  1789. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetActiveView());
  1790. if (pDayView)
  1791. {
  1792. pDayView->ResetSelection();
  1793. pDayView->ShowDay(dtDate);
  1794. }
  1795. }
  1796. return 0;
  1797. }
  1798. // for compatibility with previous versions
  1799. LRESULT CXTPCalendarControl::OnSwitchView(WPARAM nDate, LPARAM)
  1800. {
  1801. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  1802. SwitchActiveView(xtpCalendarDayView);
  1803. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, m_pActiveView);
  1804. if (pDayView)
  1805. {
  1806. pDayView->ResetSelection();
  1807. pDayView->ShowDay(COleDateTime((DATE)nDate));
  1808. }
  1809. return 0;
  1810. }
  1811. // for compatibility with previous versions
  1812. void CXTPCalendarControl::QueueDayViewSwitch(DATE dtDate)
  1813. {
  1814. PostMessage(xtp_wm_SwitchView, (UINT)dtDate);
  1815. }
  1816. BOOL CXTPCalendarControl::DoDeleteSelectedEvents(CXTPCalendarViewEvent* pViewEvent)
  1817. {
  1818. CXTPCalendarView* pView = XTP_SAFE_GET3(pViewEvent, GetViewGroup_(), GetViewDay_(), GetView_(), NULL);
  1819. if (!pView)
  1820. {
  1821. ASSERT(FALSE);
  1822. return FALSE;
  1823. }
  1824. //------------------------------------------------------------------------
  1825. if (pView->IsEditingSubject())
  1826. {
  1827. pView->EndEditSubject(xtpCalendarEditSubjectCommit, FALSE);
  1828. }
  1829. //------------------------------------------------------------------------
  1830. CXTPCalendarViewEventsPtr ptrSelEventViews = pView->GetSelectedEvents();
  1831. BOOL bSelExist = ptrSelEventViews && ptrSelEventViews->GetCount();
  1832. BOOL bHandled = FALSE;
  1833. ASSERT(m_pActiveView == pView);
  1834. if (bSelExist && m_pActiveView)
  1835. {
  1836. bHandled = m_pActiveView->OnBeforeEditOperationNotify(xtpCalendarEO_DeleteSelectedEvents, ptrSelEventViews);
  1837. }
  1838. if (bHandled)
  1839. {
  1840. return TRUE;
  1841. }
  1842. //------------------------------------------------------------------------
  1843. if (!bSelExist)
  1844. {
  1845. return DoDeleteEvent(pViewEvent);
  1846. }
  1847. int nCount = ptrSelEventViews ? ptrSelEventViews->GetCount() : 0;
  1848. for (int i = 0; i < nCount; i++)
  1849. {
  1850. CXTPCalendarViewEvent* pEV = ptrSelEventViews->GetAt(i, FALSE);
  1851. if (!DoDeleteEvent(pEV))
  1852. {
  1853. return FALSE;
  1854. }
  1855. }
  1856. return TRUE;
  1857. }
  1858. BOOL CXTPCalendarControl::DoDeleteEvent(CXTPCalendarViewEvent* pViewEvent)
  1859. {
  1860. CXTPCalendarView* pView = XTP_SAFE_GET3(pViewEvent, GetViewGroup_(), GetViewDay_(), GetView_(), m_pActiveView);
  1861. if (!pView)
  1862. {
  1863. ASSERT(FALSE);
  1864. return FALSE;
  1865. }
  1866. CXTPCalendarEvent* pEvent = pViewEvent ? pViewEvent->GetEvent() : NULL;
  1867. CXTPCalendarData* pData = pEvent ? pEvent->GetDataProvider() : NULL;
  1868. if (!pEvent || !pData)
  1869. {
  1870. ASSERT(FALSE);
  1871. return FALSE;
  1872. }
  1873. //------------------------------------------------------------------------
  1874. if (pView->IsEditingSubject())
  1875. {
  1876. pView->EndEditSubject(xtpCalendarEditSubjectCommit, FALSE);
  1877. }
  1878. //- Check is Event Still Exist -------------------------------------------
  1879. if (!::IsEventExists(pData, pEvent))
  1880. {
  1881. return TRUE;
  1882. }
  1883. //------------------------------------------------------------------------
  1884. BOOL bHandled = FALSE;
  1885. if (m_pActiveView)
  1886. {
  1887. bHandled = m_pActiveView->OnBeforeEditOperationNotify(xtpCalendarEO_DeleteEvent, pViewEvent);
  1888. }
  1889. if (bHandled)
  1890. {
  1891. return TRUE;
  1892. }
  1893. //------------------------------------------------------------------------
  1894. CXTPAutoResetValue<BOOL> autoSet_UpdateCtrlNf(m_bUpdateWhenEventChangedNotify);
  1895. autoSet_UpdateCtrlNf = FALSE;
  1896. //------------------------------------------------------------------------
  1897. if (pEvent->GetRecurrenceState() != xtpCalendarRecurrenceNotRecurring)
  1898. {
  1899. CXTPCalendarOccurSeriesChooseDlg dlgOccSer(this, XTP_IDS_CALENDAR_OCURR_SERIES_DELETE);
  1900. dlgOccSer.SetEvent(pEvent);
  1901. if (dlgOccSer.DoModal() != IDOK)
  1902. {
  1903. return TRUE;
  1904. }
  1905. if (!dlgOccSer.m_bOccur)
  1906. {
  1907. // delete series
  1908. CXTPCalendarRecurrencePatternPtr ptrRecPatt = pEvent->GetRecurrencePattern();
  1909. if (!ptrRecPatt)
  1910. {
  1911. ASSERT(FALSE);
  1912. return FALSE;
  1913. }
  1914. CXTPCalendarEventPtr ptrMasterEvent = ptrRecPatt->GetMasterEvent();
  1915. if (ptrMasterEvent)
  1916. {
  1917. return pData->DeleteEvent(ptrMasterEvent);
  1918. }
  1919. ASSERT(FALSE);
  1920. return FALSE;
  1921. }
  1922. }
  1923. return pData->DeleteEvent(pEvent);
  1924. }
  1925. void CXTPCalendarControl::OnSetFocus(CWnd* pOldWnd)
  1926. {
  1927. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  1928. CWnd::OnSetFocus(pOldWnd);
  1929. #ifdef XTP_CALENDAR_SITENOTIFY_ONFOCUS
  1930. XTP_CALENDAR_SITENOTIFY_ONFOCUS(this, this, TRUE)
  1931. #endif
  1932. }
  1933. void CXTPCalendarControl::OnKillFocus (CWnd* pNewWnd)
  1934. {
  1935. CXTPSmartPtrInternalT<CCmdTarget> ptrThisLock(this, TRUE);
  1936. CWnd::OnKillFocus(pNewWnd);
  1937. #ifdef XTP_CALENDAR_SITENOTIFY_ONFOCUS
  1938. XTP_CALENDAR_SITENOTIFY_ONFOCUS(this, this, FALSE)
  1939. #endif
  1940. }
  1941. void CXTPCalendarControl::SetTheme(CXTPCalendarTheme* pTheme)
  1942. {
  1943. if (m_pTheme)
  1944. {
  1945. m_pTheme->SetCalendarControl(NULL);
  1946. CMDTARGET_RELEASE(m_pTheme)
  1947. }
  1948. m_pTheme = pTheme;
  1949. if (m_pTheme)
  1950. {
  1951. m_pTheme->SetCalendarControl(this);
  1952. m_pTheme->RefreshMetrics();
  1953. }
  1954. else
  1955. {
  1956. XTP_SAFE_CALL1(GetPaintManager(), RefreshMetrics());
  1957. }
  1958. SendNotification(XTP_NC_CALENDAR_THEME_CHANGED, 0, 0);
  1959. }
  1960. CXTPCalendarOptions* CXTPCalendarControl::GetCalendarOptions() const
  1961. {
  1962. return m_pOptions;
  1963. }
  1964. // calendar settings
  1965. int CXTPCalendarControl::GetWorkWeekMask() const
  1966. {
  1967. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  1968. ASSERT(pOpt);
  1969. if (pOpt)
  1970. {
  1971. return pOpt->nWorkWeekMask;
  1972. }
  1973. return xtpCalendarDayMo_Fr;
  1974. }
  1975. void CXTPCalendarControl::SetWorkWeekMask(const int nMask)
  1976. {
  1977. if (!nMask) // Invalid mask
  1978. return;
  1979. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  1980. ASSERT(pOpt);
  1981. if (pOpt)
  1982. {
  1983. pOpt->nWorkWeekMask = nMask;
  1984. OnOptionsChanged((int)-1);
  1985. }
  1986. }
  1987. int CXTPCalendarControl::GetFirstDayOfWeek() const
  1988. {
  1989. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  1990. ASSERT(pOpt);
  1991. if (pOpt)
  1992. {
  1993. int nFirstDayOfWeek = pOpt->nFirstDayOfTheWeek;
  1994. ASSERT(nFirstDayOfWeek >= 1 && nFirstDayOfWeek <= 7);
  1995. return max(min(7, nFirstDayOfWeek), 1);
  1996. }
  1997. return 1;
  1998. }
  1999. void CXTPCalendarControl::SetFirstDayOfWeek(const int nFirstDayOfWeek)
  2000. {
  2001. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2002. ASSERT(pOpt);
  2003. if (pOpt)
  2004. {
  2005. ASSERT(nFirstDayOfWeek >= 1 && nFirstDayOfWeek <= 7);
  2006. if (nFirstDayOfWeek >= 1 && nFirstDayOfWeek <= 7)
  2007. {
  2008. pOpt->nFirstDayOfTheWeek = nFirstDayOfWeek;
  2009. }
  2010. OnOptionsChanged((int)-1);
  2011. }
  2012. }
  2013. void CXTPCalendarControl::GetWorkDayStartTime(int& nHour, int& nMin, int& nSec)
  2014. {
  2015. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2016. ASSERT(pOpt);
  2017. if (pOpt)
  2018. {
  2019. nHour = pOpt->dtWorkDayStartTime.GetHour();
  2020. nMin = pOpt->dtWorkDayStartTime.GetMinute();
  2021. nSec = pOpt->dtWorkDayStartTime.GetSecond();
  2022. }
  2023. }
  2024. void CXTPCalendarControl::GetWorkDayStartTime(COleDateTime& dtTime)
  2025. {
  2026. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2027. ASSERT(pOpt);
  2028. if (pOpt)
  2029. {
  2030. dtTime = pOpt->dtWorkDayStartTime;
  2031. }
  2032. }
  2033. void CXTPCalendarControl::GetWorkDayEndTime(int& nHour, int& nMin, int& nSec)
  2034. {
  2035. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2036. ASSERT(pOpt);
  2037. if (pOpt)
  2038. {
  2039. nHour = pOpt->dtWorkDayEndTime.GetHour();
  2040. nMin = pOpt->dtWorkDayEndTime.GetMinute();
  2041. nSec = pOpt->dtWorkDayEndTime.GetSecond();
  2042. }
  2043. }
  2044. void CXTPCalendarControl::GetWorkDayEndTime(COleDateTime& dtTime)
  2045. {
  2046. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2047. ASSERT(pOpt);
  2048. if (pOpt)
  2049. {
  2050. dtTime = pOpt->dtWorkDayEndTime;
  2051. }
  2052. }
  2053. void CXTPCalendarControl::SetWorkDayStartTime(int nHour, int nMin, int nSec)
  2054. {
  2055. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2056. ASSERT(pOpt);
  2057. if (pOpt)
  2058. {
  2059. pOpt->dtWorkDayStartTime.SetTime(nHour, nMin, nSec);
  2060. OnOptionsChanged(xtpCalendarDayView);
  2061. }
  2062. }
  2063. void CXTPCalendarControl::SetWorkDayStartTime(const COleDateTime& dtTime)
  2064. {
  2065. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2066. ASSERT(pOpt);
  2067. if (pOpt)
  2068. {
  2069. pOpt->dtWorkDayStartTime = dtTime;
  2070. OnOptionsChanged(xtpCalendarDayView);
  2071. }
  2072. }
  2073. void CXTPCalendarControl::SetWorkDayEndTime(int nHour, int nMin, int nSec)
  2074. {
  2075. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2076. ASSERT(pOpt);
  2077. if (pOpt)
  2078. {
  2079. pOpt->dtWorkDayEndTime.SetTime(nHour, nMin, nSec);
  2080. OnOptionsChanged(xtpCalendarDayView);
  2081. }
  2082. }
  2083. void CXTPCalendarControl::SetWorkDayEndTime(const COleDateTime& dtTime)
  2084. {
  2085. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2086. ASSERT(pOpt);
  2087. if (pOpt)
  2088. {
  2089. pOpt->dtWorkDayEndTime = dtTime;
  2090. OnOptionsChanged(xtpCalendarDayView);
  2091. }
  2092. }
  2093. BOOL CXTPCalendarControl::DayView_IsAutoResetBusyFlag() const
  2094. {
  2095. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2096. ASSERT(pOpt);
  2097. if (pOpt)
  2098. {
  2099. return pOpt->bDayView_AutoResetBusyFlag;
  2100. }
  2101. return TRUE;
  2102. }
  2103. void CXTPCalendarControl::DayView_SetAutoResetBusyFlag(BOOL bAutoResetBusyFlag)
  2104. {
  2105. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2106. ASSERT(pOpt);
  2107. if (pOpt)
  2108. {
  2109. pOpt->bDayView_AutoResetBusyFlag = bAutoResetBusyFlag;
  2110. OnOptionsChanged(xtpCalendarDayView);
  2111. }
  2112. }
  2113. BOOL CXTPCalendarControl::MonthView_IsCompressWeekendDays() const
  2114. {
  2115. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2116. ASSERT(pOpt);
  2117. if (pOpt)
  2118. {
  2119. return pOpt->bMonthView_CompressWeekendDays;
  2120. }
  2121. return TRUE;
  2122. }
  2123. void CXTPCalendarControl::MonthView_SetCompressWeekendDays(BOOL bCompress)
  2124. {
  2125. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2126. ASSERT(pOpt);
  2127. if (pOpt)
  2128. {
  2129. pOpt->bMonthView_CompressWeekendDays = bCompress;
  2130. OnOptionsChanged(xtpCalendarMonthView);
  2131. }
  2132. }
  2133. BOOL CXTPCalendarControl::MonthView_IsShowEndDate() const
  2134. {
  2135. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2136. ASSERT(pOpt);
  2137. if (pOpt)
  2138. {
  2139. return pOpt->bMonthView_ShowEndDate;
  2140. }
  2141. return FALSE;
  2142. }
  2143. void CXTPCalendarControl::MonthView_SetShowEndDate(BOOL bShowEnd)
  2144. {
  2145. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2146. ASSERT(pOpt);
  2147. if (pOpt)
  2148. {
  2149. pOpt->bMonthView_ShowEndDate = bShowEnd;
  2150. OnOptionsChanged(xtpCalendarMonthView);
  2151. }
  2152. }
  2153. BOOL CXTPCalendarControl::MonthView_IsShowTimeAsClocks() const
  2154. {
  2155. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2156. ASSERT(pOpt);
  2157. if (pOpt)
  2158. {
  2159. return pOpt->bMonthView_ShowTimeAsClocks;
  2160. }
  2161. return FALSE;
  2162. }
  2163. void CXTPCalendarControl::MonthView_SetShowTimeAsClocks(BOOL bShowClocks)
  2164. {
  2165. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2166. ASSERT(pOpt);
  2167. if (pOpt)
  2168. {
  2169. pOpt->bMonthView_ShowTimeAsClocks = bShowClocks;
  2170. OnOptionsChanged(xtpCalendarMonthView);
  2171. }
  2172. }
  2173. BOOL CXTPCalendarControl::WeekView_IsShowEndDate() const
  2174. {
  2175. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2176. ASSERT(pOpt);
  2177. if (pOpt)
  2178. {
  2179. return pOpt->bWeekView_ShowEndDate;
  2180. }
  2181. return FALSE;
  2182. }
  2183. void CXTPCalendarControl::WeekView_SetShowEndDate(BOOL bShowEnd)
  2184. {
  2185. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2186. ASSERT(pOpt);
  2187. if (pOpt)
  2188. {
  2189. pOpt->bWeekView_ShowEndDate = bShowEnd;
  2190. OnOptionsChanged(xtpCalendarWeekView);
  2191. }
  2192. }
  2193. BOOL CXTPCalendarControl::WeekView_IsShowTimeAsClocks() const
  2194. {
  2195. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2196. ASSERT(pOpt);
  2197. if (pOpt)
  2198. {
  2199. return pOpt->bWeekView_ShowTimeAsClocks;
  2200. }
  2201. return FALSE;
  2202. }
  2203. void CXTPCalendarControl::WeekView_SetShowTimeAsClocks(BOOL bShowClocks)
  2204. {
  2205. CXTPCalendarOptions* pOpt = GetCalendarOptions();
  2206. ASSERT(pOpt);
  2207. if (pOpt)
  2208. {
  2209. pOpt->bWeekView_ShowTimeAsClocks = bShowClocks;
  2210. OnOptionsChanged(xtpCalendarWeekView);
  2211. }
  2212. }
  2213. void CXTPCalendarControl::OnEvent_FromDataProvider(XTP_NOTIFY_CODE Event,
  2214. WPARAM wParam, LPARAM lParam)
  2215. {
  2216. ASSERT(Event == XTP_NC_CALENDAROPTIONSWASCHANGED ||
  2217. Event == XTP_NC_CALENDAREVENTWASADDED ||
  2218. Event == XTP_NC_CALENDAREVENTWASDELETED ||
  2219. Event == XTP_NC_CALENDAREVENTWASCHANGED ||
  2220. Event == XTP_NC_CALENDARPATTERNWASADDED ||
  2221. Event == XTP_NC_CALENDARPATTERNWASDELETED ||
  2222. Event == XTP_NC_CALENDARPATTERNWASCHANGED
  2223. ||
  2224. Event == XTP_NC_CALENDAR_DoRetrieveDayEvents ||
  2225. Event == XTP_NC_CALENDAR_DoRemoveAllEvents ||
  2226. Event == XTP_NC_CALENDAR_DoRead_Event ||
  2227. Event == XTP_NC_CALENDAR_DoRead_RPattern ||
  2228. Event == XTP_NC_CALENDAR_DoCreate_Event ||
  2229. Event == XTP_NC_CALENDAR_DoUpdate_Event ||
  2230. Event == XTP_NC_CALENDAR_DoDelete_Event ||
  2231. Event == XTP_NC_CALENDAR_DoCreate_RPattern ||
  2232. Event == XTP_NC_CALENDAR_DoUpdate_RPattern ||
  2233. Event == XTP_NC_CALENDAR_DoDelete_RPattern ||
  2234. Event == XTP_NC_CALENDAR_DoGetUpcomingEvents ||
  2235. Event == XTP_NC_CALENDAR_DoGetAllEvents_raw );
  2236. SendNotification(Event, wParam, lParam);
  2237. if (Event == XTP_NC_CALENDAROPTIONSWASCHANGED)
  2238. {
  2239. KillTimer(XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID);
  2240. CWnd::SetTimer(XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMERID, XTP_CALENDAR_REFRESHMETRICS_REQUEST_TIMEOUT, NULL);
  2241. }
  2242. //-----------------------------------------------------------------------
  2243. if (!m_bUpdateWhenEventChangedNotify)
  2244. {
  2245. return;
  2246. }
  2247. if (Event == XTP_NC_CALENDAREVENTWASADDED ||
  2248. Event == XTP_NC_CALENDAREVENTWASDELETED ||
  2249. Event == XTP_NC_CALENDAREVENTWASCHANGED)
  2250. {
  2251. CXTPCalendarEvent* pEvent = (CXTPCalendarEvent*)lParam;
  2252. if (m_pActiveView)
  2253. {
  2254. int nUpdateType = m_pActiveView->OnEventChanged_InDataProvider(Event, pEvent);
  2255. if (nUpdateType == xtpCalendar_Populate)
  2256. {
  2257. if (m_pActiveView->IsEditingSubject())
  2258. {
  2259. m_pActiveView->EndEditSubject(xtpCalendarEditSubjectCancel);
  2260. }
  2261. if (m_pActiveView->GetDraggingEventNew())
  2262. {
  2263. m_pActiveView->CancelDraggingEvent();
  2264. }
  2265. if (m_uPopulateRequest_TimerID)
  2266. {
  2267. KillTimer(m_uPopulateRequest_TimerID);
  2268. }
  2269. m_uPopulateRequest_TimerID = SetTimer(XTP_CALENDAR_POPULATE_REQUEST_TIMEOUT);
  2270. }
  2271. else if (nUpdateType == xtpCalendar_Redraw)
  2272. {
  2273. if (m_uRedrawRequest_TimerID)
  2274. {
  2275. KillTimer(m_uRedrawRequest_TimerID);
  2276. }
  2277. m_uRedrawRequest_TimerID = SetTimer(XTP_CALENDAR_REDRAW_REQUEST_TIMEOUT);
  2278. }
  2279. }
  2280. }
  2281. }
  2282. void CXTPCalendarControl::OnEvent_Reminders(XTP_NOTIFY_CODE Event, WPARAM wParam , LPARAM lParam)
  2283. {
  2284. ASSERT( Event == XTP_NC_CALENDAR_ON_REMINDERS );
  2285. SendNotification(Event, wParam, lParam);
  2286. }
  2287. void CXTPCalendarControl::SendNotification(XTP_NOTIFY_CODE EventCode, WPARAM wParam , LPARAM lParam)
  2288. {
  2289. if (this && m_pConnect && m_bEnableSendNotifications)
  2290. {
  2291. m_pConnect->SendEvent(EventCode, wParam, lParam);
  2292. }
  2293. }
  2294. void CXTPCalendarControl::SendNotificationAlways(XTP_NOTIFY_CODE EventCode, WPARAM wParam , LPARAM lParam)
  2295. {
  2296. if (this && m_pConnect)
  2297. {
  2298. m_pConnect->SendEvent(EventCode, wParam, lParam);
  2299. }
  2300. }
  2301. void CXTPCalendarControl::OnFinalRelease()
  2302. {
  2303. CWnd::OnFinalRelease();
  2304. if (m_bDeleteOnFinalRelease)
  2305. {
  2306. CCmdTarget::OnFinalRelease();
  2307. }
  2308. }
  2309. void CXTPCalendarControl::SetLayoutRTL(BOOL bRightToLeft)
  2310. {
  2311. if (!XTPSystemVersion()->IsLayoutRTLSupported())
  2312. return;
  2313. if (!m_hWnd)
  2314. return;
  2315. ModifyStyleEx(bRightToLeft ? 0 : WS_EX_LAYOUTRTL, !bRightToLeft ? 0 : WS_EX_LAYOUTRTL);
  2316. RedrawControl();
  2317. }
  2318. DWORD CXTPCalendarControl::GetAskItemTextFlags()
  2319. {
  2320. DWORD dwFlags = 0;
  2321. if (GetTheme())
  2322. {
  2323. dwFlags = GetTheme()->GetAskItemTextFlags();
  2324. }
  2325. else
  2326. {
  2327. dwFlags = XTP_SAFE_GET1(GetPaintManager(), GetAskItemTextFlags(), 0);
  2328. }
  2329. return dwFlags;
  2330. }
  2331. XTPCalendarTheme CXTPCalendarControl::GetPaintTheme() const
  2332. {
  2333. if (m_pTheme)
  2334. return m_pTheme->GetPaintTheme();
  2335. ASSERT(m_pPaintManager);
  2336. if (m_pPaintManager)
  2337. return m_pPaintManager->GetPaintTheme();
  2338. return xtpCalendarThemeUnknown;
  2339. }
  2340. void CXTPCalendarControl::SetPaintTheme(XTPCalendarTheme ePaintTheme)
  2341. {
  2342. if (ePaintTheme == GetPaintTheme())
  2343. return;
  2344. BOOL bSendNotification = TRUE;
  2345. if (ePaintTheme == xtpCalendarThemeOffice2007)
  2346. {
  2347. if (!m_pTheme)
  2348. {
  2349. SetTheme(new CXTPCalendarThemeOffice2007());
  2350. bSendNotification = FALSE;
  2351. }
  2352. }
  2353. else
  2354. {
  2355. ASSERT(GetPaintManager());
  2356. if (GetPaintManager())
  2357. GetPaintManager()->SetPaintTheme(ePaintTheme);
  2358. SetTheme(NULL);
  2359. bSendNotification = FALSE;
  2360. }
  2361. if (bSendNotification)
  2362. SendNotification(XTP_NC_CALENDAR_THEME_CHANGED, 0, 0);
  2363. if (m_hWnd)
  2364. {
  2365. CUpdateContext updateContext(this, xtpCalendarUpdateAll);
  2366. }
  2367. }
  2368. CXTPCalendarControl::CViewChanged_ContextData::CViewChanged_ContextData()
  2369. {
  2370. m_nLockCount = 0;
  2371. m_bRequest = FALSE;
  2372. }
  2373. CXTPCalendarControl::CViewChangedContext::CViewChangedContext(
  2374. CXTPCalendarView* pView, int eType)
  2375. {
  2376. if (!pView)
  2377. {
  2378. ASSERT(FALSE);
  2379. return;
  2380. }
  2381. Init(pView->GetCalendarControl(), eType);
  2382. }
  2383. CXTPCalendarControl::CViewChangedContext::CViewChangedContext(CXTPCalendarControl* pControl, int eType)
  2384. {
  2385. Init(pControl, eType);
  2386. }
  2387. void CXTPCalendarControl::CViewChangedContext::Init(CXTPCalendarControl* pControl, int eType)
  2388. {
  2389. if (!pControl)
  2390. {
  2391. ASSERT(FALSE);
  2392. return;
  2393. }
  2394. m_pControl = pControl;
  2395. m_eType = eType;
  2396. m_pControl->m_cntViewChanged.m_nLockCount++;
  2397. }
  2398. CXTPCalendarControl::CViewChangedContext::~CViewChangedContext()
  2399. {
  2400. if (!m_pControl)
  2401. {
  2402. ASSERT(FALSE);
  2403. return;
  2404. }
  2405. if (m_eType == xtpCalendarViewChangedSend)
  2406. {
  2407. m_pControl->m_cntViewChanged.m_bRequest = TRUE;
  2408. }
  2409. ASSERT(m_pControl->m_cntViewChanged.m_nLockCount > 0);
  2410. m_pControl->m_cntViewChanged.m_nLockCount--;
  2411. if (m_pControl->m_cntViewChanged.m_nLockCount == 0 &&
  2412. m_pControl->m_cntViewChanged.m_bRequest)
  2413. {
  2414. m_pControl->m_cntViewChanged.m_bRequest = FALSE;
  2415. m_pControl->SendNotification(XTP_NC_CALENDARVIEWWASCHANGED, 0, 0);
  2416. }
  2417. }