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

对话框与窗口

开发平台:

Visual C++

  1. // CalendarDemoView.cpp : implementation of the CCalendarDemoView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO 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 "CalendarDemo.h"
  22. #include "MainFrm.h"
  23. #include "CalendarDemoDoc.h"
  24. #include "CalendarDemoView.h"
  25. #include "DataProvidersOptions.h"
  26. #include "AdvancedCalendarOptionsDlg.h"
  27. #include "resource.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. //////////////////////////////////////////////////////////////////////////
  34. extern CString GetDPName(int nDPType);
  35. extern int GetDPType(CXTPCalendarData* pData);
  36. //////////////////////////////////////////////////////////////////////////
  37. static CXTPCalendarRemindersDialog* s_pDlgReminders = NULL;
  38. CString cstrMarkupDynamicSample(
  39. _T("<StackPanel Margin='2, 2, 2, 2' VerticalAlignment='Top'")
  40. _T("HorizontalAlignment='Center'>")
  41. _T("<TextBlock Padding='0,10,0,0' TextWrapping='Wrap'>")
  42. _T("<Italic>Dynamically Customized Subject:</Italic><Bold>/Calendar/Events/Event/Subject</Bold></TextBlock>")
  43. _T("<TextBlock Padding='0,10,0,0'>Dynamically Customized Body:</TextBlock>")
  44. _T("<TextBlock Padding='10,10,0,0' TextWrapping='Wrap'>")
  45. _T("/Calendar/Events/Event/Body")
  46. _T("</TextBlock>")
  47. _T("<TextBlock Padding='10,10,0,0'> - Regards</TextBlock>")
  48. _T("</StackPanel>"));
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CCalendarDemoView
  51. IMPLEMENT_DYNCREATE(CCalendarDemoView, CXTPCalendarControlView)
  52. BEGIN_MESSAGE_MAP(CCalendarDemoView, CXTPCalendarControlView)
  53. //{{AFX_MSG_MAP(CCalendarDemoView)
  54. ON_WM_CREATE()
  55. //}}AFX_MSG_MAP
  56. // Standard printing commands
  57. ON_COMMAND(ID_FILE_PAGE_SETUP, CXTPCalendarControlView::OnFilePageSetup)
  58. ON_COMMAND(ID_FILE_PRINT, CXTPCalendarControlView::OnFilePrint)
  59. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CXTPCalendarControlView::OnFilePrintPreview)
  60. ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  61. ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  62. ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
  63. ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
  64. // User commands
  65. ON_COMMAND(ID_VIEW_REMINDERS, OnViewReminders)
  66. ON_UPDATE_COMMAND_UI(ID_VIEW_REMINDERS,  OnUpdateViewReminders)
  67. ON_COMMAND(ID_CALENDAR_VIEW_DAY, OnCalendarViewDay)
  68. ON_COMMAND(ID_CALENDAR_VIEW_WORKWEEK, OnCalendarViewWorkWeek)
  69. ON_COMMAND(ID_CALENDAR_VIEW_WEEK, OnCalendarViewWeek)
  70. ON_COMMAND(ID_CALENDAR_VIEW_MONTH, OnCalendarViewMonth)
  71. ON_UPDATE_COMMAND_UI(ID_CALENDAR_VIEW_DAY, OnUpdateCalendarViewDay)
  72. ON_UPDATE_COMMAND_UI(ID_CALENDAR_VIEW_WORKWEEK, OnUpdateCalendarViewWorkWeek)
  73. ON_UPDATE_COMMAND_UI(ID_CALENDAR_VIEW_WEEK, OnUpdateCalendarViewWeek)
  74. ON_UPDATE_COMMAND_UI(ID_CALENDAR_VIEW_MONTH, OnUpdateCalendarViewMonth)
  75. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_60MINUTES, OnCalendarTimescale60)
  76. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_30MINUTES, OnCalendarTimescale30)
  77. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_15MINUTES, OnCalendarTimescale15)
  78. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_10MINUTES, OnCalendarTimescale10)
  79. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_6MINUTES,  OnCalendarTimescale6)
  80. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_5MINUTES,  OnCalendarTimescale5)
  81. ON_UPDATE_COMMAND_UI(ID_CALENDAR_CHANGETIMESCALE_60MINUTES, OnUpdateCalendarTimescale60)
  82. ON_UPDATE_COMMAND_UI(ID_CALENDAR_CHANGETIMESCALE_30MINUTES, OnUpdateCalendarTimescale30)
  83. ON_UPDATE_COMMAND_UI(ID_CALENDAR_CHANGETIMESCALE_15MINUTES, OnUpdateCalendarTimescale15)
  84. ON_UPDATE_COMMAND_UI(ID_CALENDAR_CHANGETIMESCALE_10MINUTES, OnUpdateCalendarTimescale10)
  85. ON_UPDATE_COMMAND_UI(ID_CALENDAR_CHANGETIMESCALE_6MINUTES,  OnUpdateCalendarTimescale6)
  86. ON_UPDATE_COMMAND_UI(ID_CALENDAR_CHANGETIMESCALE_5MINUTES,  OnUpdateCalendarTimescale5)
  87. ON_COMMAND(ID_CALENDAR_CHANGETIMESCALE_CHANGETIMEZONE,  OnCalendarTimezone)
  88. ON_COMMAND(ID_CALENDAR_ADD_NEW_EVENT, OnAddNewEvent)
  89. // ON_COMMAND(ID_CALENDAR_LANGUAGE_RUSSIAN,  OnCalendarLangRussian)
  90. // ON_COMMAND(ID_CALENDAR_LANGUAGE_DEFAULT,  OnCalendarLangDefault)
  91. ON_BN_CLICKED(IDC_TIME_ZONE_BTN, OnCalendarTimezone)
  92. ON_BN_CLICKED(IDC_ADVANCED_OPT_BTN, OnAdvancedOptions)
  93. END_MESSAGE_MAP()
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CCalendarDemoView construction/destruction
  96. CCalendarDemoView::CCalendarDemoView()
  97. {
  98. m_dsDayViewDays.SetDateTimeSpan(4,0,0,0);
  99. SetCalendarCtrl(&m_wndCalendarEx, FALSE);
  100. // Advise To Notifications
  101. CXTPNotifyConnection* ptrCalendarConn = GetCalendarCtrl().GetConnection();
  102. ASSERT(ptrCalendarConn);
  103. if(!ptrCalendarConn) {
  104. return;
  105. }
  106. m_nScale = -1;
  107. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDARCONTEXTMENU, &CCalendarDemoView::OnEvent_Calendar);
  108. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDARLBUTTONDBLCLICK, &CCalendarDemoView::OnEvent_Calendar);
  109. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDARKEYDOWN, &CCalendarDemoView::OnEvent_Calendar);
  110. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_IS_EVENT_EDIT_OPERATION_DISABLED, &CCalendarDemoView::OnEvent_IsEditActionDisabled);
  111. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION, &CCalendarDemoView::OnEvent_BeforeEditAction);
  112. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_PREPOPULATE, &CCalendarDemoView::OnEvent_PrePopulate);
  113. //m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_SELECTION_CHANGED, &CCalendarDemoView::OnEvent_SelChanged);
  114.     
  115. // Advise to Calendar Data Provider notifications
  116. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAREVENTWASADDED, &CCalendarDemoView::OnEvent_CalendarData);
  117. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAREVENTWASDELETED, &CCalendarDemoView::OnEvent_CalendarData);
  118. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAREVENTWASCHANGED, &CCalendarDemoView::OnEvent_CalendarData);
  119. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDARPATTERNWASADDED, &CCalendarDemoView::OnEvent_CalendarData);
  120. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDARPATTERNWASDELETED, &CCalendarDemoView::OnEvent_CalendarData);
  121. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDARPATTERNWASCHANGED, &CCalendarDemoView::OnEvent_CalendarData);
  122. // m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_ON_REMINDERS, &CCalendarDemoView::OnReminders);
  123. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_BEFORE_DRAW_THEMEOBJECT, &CCalendarDemoView::OnBeforeDrawThemeObject);
  124. m_Sink.Advise(ptrCalendarConn, XTP_NC_CALENDAR_GETITEMTEXT, &CCalendarDemoView::OnEvent_GetItemText);
  125. }
  126. CCalendarDemoView::~CCalendarDemoView()
  127. {
  128. if (s_pDlgReminders)
  129. delete s_pDlgReminders;
  130. s_pDlgReminders = NULL;
  131. }
  132. BOOL CCalendarDemoView::PreCreateWindow(CREATESTRUCT& cs)
  133. {
  134. // TODO: Modify the Window class or styles here by modifying
  135. //  the CREATESTRUCT cs
  136. cs.style &= ~WS_BORDER;
  137. return CXTPCalendarControlView::PreCreateWindow(cs);
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CCalendarDemoView drawing
  141. void CCalendarDemoView::OnDraw(CDC* pDC)
  142. {
  143. UNREFERENCED_PARAMETER(pDC);
  144. CCalendarDemoDoc* pDoc = GetDocument();
  145. ASSERT_VALID(pDoc);
  146. }
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CCalendarDemoView diagnostics
  149. #ifdef _DEBUG
  150. void CCalendarDemoView::AssertValid() const
  151. {
  152. CXTPCalendarControlView::AssertValid();
  153. }
  154. void CCalendarDemoView::Dump(CDumpContext& dc) const
  155. {
  156. CXTPCalendarControlView::Dump(dc);
  157. }
  158. CCalendarDemoDoc* CCalendarDemoView::GetDocument() // non-debug version is inline
  159. {
  160. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCalendarDemoDoc)));
  161. return (CCalendarDemoDoc*)m_pDocument;
  162. }
  163. #endif //_DEBUG
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CCalendarDemoView message handlers
  166. int CCalendarDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  167. {
  168. if (CXTPCalendarControlView::OnCreate(lpCreateStruct) == -1)
  169. return -1;
  170. ((CWnd*)&GetCalendarCtrl())->EnableToolTips(TRUE);
  171. CCalendarDemoDoc* pDoc = GetDocument();
  172. if (pDoc)
  173. {
  174. pDoc->m_pCalendar = &GetCalendarCtrl();
  175. }
  176.     
  177. m_CalendarController.SetCalendar(&GetCalendarCtrl());
  178. m_wndScrollBar.Create(WS_CHILD | WS_VISIBLE | SBS_VERT, CRect(0, 0, 0, 0), this, 100);
  179. m_wndScrollBar.SetScrollBarStyle(xtpScrollStyleOffice2007Dark);
  180. SetScrollBarCtrl(&m_wndScrollBar);
  181. return 0;
  182. }
  183. //////////////////////////////////////////////////////////////////////////
  184. //  User message handlers
  185. //
  186. void CCalendarDemoView::SetView(XTPCalendarViewType viewType)
  187. {
  188. GetCalendarCtrl().SwitchActiveView(viewType);
  189. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatLong(_T("dddd, d MMMM yyyy 'year'"));
  190. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatMiddle(_T("ddd, d MMM yy"));
  191. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatShort(_T("d MMMM"));
  192. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatShortest(_T("d MMM"));
  193. ((CMainFrame*)GetParentFrame())->m_dlgOptions.OnViewChanged(viewType);
  194. }
  195. void CCalendarDemoView::OnCalendarViewDay() 
  196. {
  197. if(GetCalendarCtrl().GetActiveView() && 
  198. GetCalendarCtrl().GetActiveView()->GetViewType() != xtpCalendarDayView) 
  199. {
  200. TRACE(_T("Switch to 1 day view.n"));
  201. SetView(xtpCalendarDayView);
  202. OnUpdateTimeScale();
  203. }
  204. }
  205. void CCalendarDemoView::OnCalendarViewWorkWeek() 
  206. {
  207. if(GetCalendarCtrl().GetActiveView() && 
  208. GetCalendarCtrl().GetActiveView()->GetViewType() != xtpCalendarWorkWeekView) 
  209. {
  210. TRACE(_T("Switch to work week day view.n"));
  211. SetView(xtpCalendarWorkWeekView);
  212. OnUpdateTimeScale();
  213. }
  214. }
  215. void CCalendarDemoView::OnCalendarViewWeek() 
  216. {
  217. if(GetCalendarCtrl().GetActiveView() && 
  218. GetCalendarCtrl().GetActiveView()->GetViewType() != xtpCalendarWeekView) 
  219. {
  220. TRACE(_T("Switch to week view.n"));
  221. SetView(xtpCalendarWeekView);
  222. }
  223. }
  224. void CCalendarDemoView::OnCalendarViewMonth() 
  225. {   
  226. // CXTPCalendarControl::CUpdateContext cnt(&GetCalendarCtrl(), xtpCalendarUpdateLayout);
  227. if(GetCalendarCtrl().GetActiveView() && 
  228. GetCalendarCtrl().GetActiveView()->GetViewType() != xtpCalendarMonthView) 
  229. {
  230. TRACE(_T("Switch to month view.n"));
  231. SetView(xtpCalendarMonthView);
  232. }
  233. // In month view Long, Middle and Short formats are always used for first month day header
  234. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatLong(_T("d MMMM yyy"));
  235. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatMiddle(_T("d MMM yy"));
  236. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatShort(_T("d MMM"));
  237. // // In month view Shortest format is always used for not first month day header
  238. //GetCalendarCtrl().GetActiveView()->SetDayHeaderFormatShortest(_T("d"));
  239. }
  240. void CCalendarDemoView::OnUpdateCalendarViewDay(CCmdUI* pCmdUI) 
  241. {
  242. BOOL bViewDay = FALSE;
  243. CXTPCalendarView* pView = GetCalendarCtrl().GetActiveView();
  244. if (pView && pView->GetViewType() == xtpCalendarDayView) {
  245. bViewDay = TRUE;
  246. }
  247. pCmdUI->SetCheck(bViewDay);
  248. }
  249. void CCalendarDemoView::OnUpdateCalendarViewWorkWeek(CCmdUI* pCmdUI) 
  250. {
  251. BOOL bViewDays = FALSE;
  252. CXTPCalendarView* pView = GetCalendarCtrl().GetActiveView();
  253. if (pView && pView->GetViewType() == xtpCalendarWorkWeekView) {
  254. bViewDays = TRUE;
  255. }
  256. pCmdUI->SetCheck(bViewDays);
  257. }
  258. void CCalendarDemoView::OnUpdateCalendarViewWeek(CCmdUI* pCmdUI) 
  259. {
  260. BOOL bViewWeek = FALSE;
  261. CXTPCalendarView* pView = GetCalendarCtrl().GetActiveView();
  262. if (pView && pView->GetViewType() == xtpCalendarWeekView) 
  263. bViewWeek = TRUE;
  264. pCmdUI->SetCheck(bViewWeek);
  265. }
  266. void CCalendarDemoView::OnUpdateCalendarViewMonth(CCmdUI* pCmdUI) 
  267. {
  268. BOOL bViewMonth = FALSE;
  269. CXTPCalendarView* pView = GetCalendarCtrl().GetActiveView();
  270. if (pView && pView->GetViewType() == xtpCalendarMonthView) 
  271. bViewMonth = TRUE; 
  272. pCmdUI->SetCheck(bViewMonth);
  273. }
  274. //////////////////////////////////////////////////////////////////////////
  275. void CCalendarDemoView::SetCalendarToolTipMode(int nToolTipMode)
  276. {
  277. m_wndCalendarEx.m_nToolTipMode = nToolTipMode;
  278. GetCalendarCtrl().EnableToolTips(nToolTipMode == ctmStandard);
  279. }
  280. void CCalendarDemoView::SetCalendarTimeScale(int nScale)
  281. {
  282. m_nScale = nScale;
  283. OnUpdateTimeScale();
  284. }
  285. void CCalendarDemoView::OnCalendarTimescale60() 
  286. {
  287. SetCalendarTimeScale(60);
  288. }
  289. void CCalendarDemoView::OnCalendarTimescale30() 
  290. {
  291. SetCalendarTimeScale(30);
  292. }
  293. void CCalendarDemoView::OnCalendarTimescale15() 
  294. {
  295. SetCalendarTimeScale(15);
  296. }
  297. void CCalendarDemoView::OnCalendarTimescale10() 
  298. {
  299. SetCalendarTimeScale(10);
  300. }
  301. void CCalendarDemoView::OnCalendarTimescale6() 
  302. {
  303. SetCalendarTimeScale(6);
  304. }
  305. void CCalendarDemoView::OnCalendarTimescale5() 
  306. {
  307. SetCalendarTimeScale(5);
  308. }
  309. void CCalendarDemoView::OnUpdateCalendarTimescale60(CCmdUI* pCmdUI)
  310. {
  311. OnUpdateCalendarTimescale(pCmdUI, 60);
  312. }
  313. void CCalendarDemoView::OnUpdateCalendarTimescale30(CCmdUI* pCmdUI)
  314. {
  315. OnUpdateCalendarTimescale(pCmdUI, 30);
  316. }
  317. void CCalendarDemoView::OnUpdateCalendarTimescale15(CCmdUI* pCmdUI)
  318. {
  319. OnUpdateCalendarTimescale(pCmdUI, 15);
  320. }
  321. void CCalendarDemoView::OnUpdateCalendarTimescale10(CCmdUI* pCmdUI)
  322. {
  323. OnUpdateCalendarTimescale(pCmdUI, 10);
  324. }
  325. void CCalendarDemoView::OnUpdateCalendarTimescale6(CCmdUI* pCmdUI)
  326. {
  327. OnUpdateCalendarTimescale(pCmdUI, 6);
  328. }
  329. void CCalendarDemoView::OnUpdateCalendarTimescale5(CCmdUI* pCmdUI)
  330. {
  331. OnUpdateCalendarTimescale(pCmdUI, 5);
  332. }
  333. void CCalendarDemoView::OnUpdateCalendarTimescale(CCmdUI* pCmdUI, int nScale) 
  334. {
  335. BOOL bEnable = FALSE;
  336. BOOL bChecked = FALSE;
  337. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetActiveView());
  338. if (pDayView) 
  339. {
  340. bEnable = TRUE;
  341. if (pDayView->GetScaleInterval().GetTotalMinutes() == nScale) 
  342. bChecked = TRUE;
  343. }
  344. pCmdUI->Enable(bEnable);
  345. pCmdUI->SetCheck(bChecked);
  346. }
  347. void CCalendarDemoView::OnUpdateViewReminders(CCmdUI* pCmdUI)
  348. {
  349. pCmdUI->Enable(GetCalendarCtrl().IsRemindersEnabled());
  350. }
  351. CString GetModulePath()
  352. {
  353. TCHAR szCurPath[_MAX_PATH + 2];
  354. ::GetModuleFileName(AfxGetInstanceHandle(), szCurPath, _MAX_PATH);
  355. CString strCurPath(szCurPath);
  356. strCurPath = strCurPath.Left(strCurPath.ReverseFind('\')+1);
  357. return strCurPath;
  358. }
  359. //void CCalendarDemoView::OnCalendarLangDefault()
  360. //{
  361. // XTPResourceManager()->SetResourceFile(_T(""));
  362. //
  363. // GetCalendarCtrl().Populate();
  364. //
  365. // m_wndDatePicker.AdjustLayout();
  366. // m_wndDatePicker.RedrawControl();
  367. //}
  368. //void CCalendarDemoView::OnCalendarLangRussian()
  369. //{
  370. // CString strRCpath = GetModulePath();
  371. //
  372. // strRCpath += _T("Translations\ToolkitPro.ResourceRu.dll");
  373. //  
  374. // XTPResourceManager()->SetResourceFile(strRCpath);
  375. //
  376. // GetCalendarCtrl().Populate();
  377. //
  378. // m_wndDatePicker.AdjustLayout();
  379. // m_wndDatePicker.RedrawControl();
  380. //
  381. //}
  382. //////////////////////////////////////////////////////////////////////////
  383. //
  384. void CCalendarDemoView::OnAddNewEvent() 
  385. {
  386. AddNewEvent();
  387. }
  388. void CCalendarDemoView::AddNewEvent(CPoint* /*pPtHitContext*/) 
  389. {
  390. CXTPCalendarEventPropertiesDlg dlg(&GetCalendarCtrl(), TRUE, this);
  391. dlg.DoModal();
  392. }
  393. void CCalendarDemoView::OnCalendarTimezone() 
  394. {
  395. TRACE(_T("Time zone dialog.n"));
  396. CXTPCalendarOptions* pOptions = GetCalendarCtrl().GetCalendarOptions();
  397. ASSERT(pOptions);
  398. if (pOptions) 
  399. {
  400. CXTPCalendarTimeScalePropertiesDlg dlg;
  401. // init parameters
  402. dlg.m_strCaption1 = pOptions->strDayView_ScaleLabel;
  403. dlg.m_strCaption2 = pOptions->strDayView_Scale2Label;
  404. dlg.m_bShowScale2 = pOptions->bDayView_Scale2Visible;
  405. dlg.m_tziScale2   = pOptions->tziDayView_Scale2TimeZone;
  406. // execute and save
  407. if (dlg.DoModal() == IDOK)
  408. {
  409. // first time scale
  410. pOptions->strDayView_ScaleLabel = dlg.m_strCaption1;
  411. // second time scale
  412. pOptions->bDayView_Scale2Visible = dlg.m_bShowScale2;
  413. if (dlg.m_bShowScale2)
  414. {
  415. pOptions->strDayView_Scale2Label = dlg.m_strCaption2;
  416. pOptions->tziDayView_Scale2TimeZone = dlg.m_tziScale2;
  417. }
  418. pOptions->OnOptionsChanged();
  419. // redraw
  420. GetCalendarCtrl().Populate();
  421. }
  422. }
  423. }
  424. void CCalendarDemoView::OnAdvancedOptions()
  425. {
  426. CAdvancedCalendarOptionsDlg dlgOptEx(&GetCalendarCtrl(), this);
  427. dlgOptEx.DoModal();
  428. }
  429. void CCalendarDemoView::OnInitialUpdate() 
  430. {
  431. CXTPCalendarControlView::OnInitialUpdate();
  432. // date picker
  433. CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
  434. //m_CalendarController.SetBoldDaysPerIdleStep(1);
  435. //m_CalendarController.SetBoldDaysIdleStepTime_ms(999);
  436. m_CalendarController.SetDatePicker(&pWnd->m_dlgDatePicker.m_wndDatePicker);
  437.     
  438. //---------------------------------------------------------------------------
  439. m_dtDayViewStart = COleDateTime::GetCurrentTime();
  440. //---------------------------------------------------------------------------
  441. ((CMainFrame*)GetParentFrame())->m_dlgOptions.Init();
  442. m_nScale = GetCalendarCtrl().GetCalendarOptions()->nDayView_ScaleInterval;
  443.     
  444. // initial settings
  445. OnCalendarViewWorkWeek();
  446. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetDayView() );
  447. if(pDayView) {
  448. pDayView->ScrollToWorkDayBegin();
  449. }
  450. //---------------------------------------------------------------------------
  451. OnOfficeThemeChanged(xtpCalendarThemeOffice2007);
  452. CreateRemindersWindow();
  453. ShowCaptionBar(TRUE);
  454. }
  455. void CCalendarDemoView::OnUpdateTimeScale()
  456. {   
  457. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetActiveView());
  458. if (pDayView) 
  459. {
  460. pDayView->SetScaleInterval(COleDateTimeSpan(0, m_nScale/60, m_nScale%60, 0));
  461. else {
  462. GetCalendarCtrl().GetCalendarOptions()->nDayView_ScaleInterval = m_nScale;
  463. GetCalendarCtrl().GetCalendarOptions()->OnOptionsChanged();
  464. }
  465. }
  466. void CCalendarDemoView::OnEvent_Calendar(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  467. {
  468. UNREFERENCED_PARAMETER(lParam);
  469. if (!GetCalendarCtrl().GetActiveView())
  470. return;
  471. CPoint ptHit(wParam);
  472. XTP_CALENDAR_HITTESTINFO hitInfo;
  473. BOOL bHitTest = GetCalendarCtrl().GetActiveView()->HitTest(ptHit, &hitInfo);
  474. if (XTP_NC_CALENDARKEYDOWN == Event)
  475. {
  476. if (wParam == VK_RETURN && !GetCalendarCtrl().GetActiveView()->IsEditingSubject()
  477. && GetCalendarCtrl().GetActiveView()->GetDraggingMode() == xtpCalendaDragModeUnknown)
  478. {
  479. CXTPCalendarViewEvents* selectedEvents = GetCalendarCtrl().GetActiveView()->GetSelectedViewEvents();
  480. if (selectedEvents && selectedEvents->GetCount() > 0)
  481. {
  482. CXTPCalendarEventPtr ptrEvent = selectedEvents->GetAt(0)->GetEvent()->CloneEvent();
  483. CXTPCalendarEventPropertiesDlg dlg(&GetCalendarCtrl(), FALSE, this, ptrEvent);
  484. dlg.DoModal();
  485. }
  486. else
  487. {
  488. AddNewEvent();
  489. }
  490. }
  491. }
  492. else if (XTP_NC_CALENDARCONTEXTMENU == Event)
  493. {
  494. if (bHitTest)
  495. {
  496. CPoint ptMenu = ptHit;
  497. GetCalendarCtrl().ClientToScreen(&ptMenu);
  498. if (hitInfo.pViewEvent)
  499. {
  500. CMenu menu;
  501. VERIFY(menu.LoadMenu(IDR_MENU_CONTEXT_EVENT));
  502. // track menu
  503. int nMenuResult = CXTPCommandBars::TrackPopupMenu(menu.GetSubMenu(0), 
  504. TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTALIGN |TPM_RIGHTBUTTON, 
  505. ptMenu.x, ptMenu.y, this, NULL);
  506. // general items processing
  507. switch (nMenuResult)
  508. {
  509. case ID_POPUP_DELETEEVENT:
  510. {
  511. VERIFY( GetCalendarCtrl().DoDeleteSelectedEvents(hitInfo.pViewEvent) );
  512. GetCalendarCtrl().Populate();
  513. }
  514. break;
  515. case ID_POPUP_PROPERTIES:
  516. {
  517. ASSERT(hitInfo.pViewEvent);
  518. if(hitInfo.pViewEvent)
  519. {
  520. CXTPCalendarEvent* pEvent = hitInfo.pViewEvent->GetEvent();
  521. CXTPCalendarEventPtr ptrEvent = pEvent->CloneEvent();
  522. CXTPCalendarControl::CUpdateContext updateContext(&GetCalendarCtrl(), xtpCalendarUpdateLayout|xtpCalendarUpdateRedraw);
  523. CXTPCalendarEventPropertiesDlg dlg(&GetCalendarCtrl(), FALSE, this, ptrEvent);
  524. dlg.DoModal();
  525. }
  526. }
  527. break;
  528. }
  529. }
  530. else if (GetCalendarCtrl().GetActiveView()->IsKindOf( RUNTIME_CLASS(CXTPCalendarDayView) ))
  531. {
  532. CMenu menu;
  533. VERIFY(menu.LoadMenu(IDR_MENU_CONTEXT_DAY));
  534. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetActiveView());
  535. if (pDayView)
  536. {
  537. int nInterval = (int)pDayView->GetScaleInterval().GetTotalMinutes();
  538. int nMenuItem = nInterval >= 60 ? ID_CALENDAR_CHANGETIMESCALE_60MINUTES :
  539. (nInterval >= 30 ? ID_CALENDAR_CHANGETIMESCALE_30MINUTES :
  540. (nInterval >= 15 ? ID_CALENDAR_CHANGETIMESCALE_15MINUTES :
  541. (nInterval >= 10 ? ID_CALENDAR_CHANGETIMESCALE_10MINUTES :
  542. (nInterval >=  6 ? ID_CALENDAR_CHANGETIMESCALE_6MINUTES :
  543. (nInterval >=  5 ? ID_CALENDAR_CHANGETIMESCALE_5MINUTES : 0)))));
  544. menu.CheckMenuItem(nMenuItem, MF_CHECKED);
  545. }
  546. // track menu
  547. int nMenuResult = CXTPCommandBars::TrackPopupMenu(menu.GetSubMenu(0), 
  548. TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTALIGN |TPM_RIGHTBUTTON, 
  549. ptMenu.x, ptMenu.y, this, NULL);
  550. // general items processing
  551. switch (nMenuResult)
  552. {
  553. case ID_CALENDAR_CHANGETIMESCALE_60MINUTES:
  554. OnCalendarTimescale60();
  555. break;
  556. case ID_CALENDAR_CHANGETIMESCALE_30MINUTES:
  557. OnCalendarTimescale30();
  558. break;
  559. case ID_CALENDAR_CHANGETIMESCALE_15MINUTES:
  560. OnCalendarTimescale15();
  561. break;
  562. case ID_CALENDAR_CHANGETIMESCALE_10MINUTES:
  563. OnCalendarTimescale10();
  564. break;
  565. case ID_CALENDAR_CHANGETIMESCALE_6MINUTES:
  566. OnCalendarTimescale6();
  567. break;
  568. case ID_CALENDAR_CHANGETIMESCALE_5MINUTES:
  569. OnCalendarTimescale5();
  570. break;
  571. case ID_CALENDAR_CHANGETIMESCALE_CHANGETIMEZONE:
  572. OnCalendarTimezone();
  573. break;
  574. case ID_CALENDAR_ADD_NEW_EVENT:
  575. AddNewEvent(&ptHit);
  576. break;
  577. default:
  578. ASSERT(nMenuResult == 0);
  579. }
  580. }
  581. else //if (GetCalendarCtrl().GetActiveView()->IsKindOf( RUNTIME_CLASS(CXTPCalendarWeekView) ))
  582. {
  583. CMenu menu;
  584. VERIFY(menu.LoadMenu(IDR_MENU_CONTEXT_WEEK));
  585. // track menu
  586. int nMenuResult = CXTPCommandBars::TrackPopupMenu(menu.GetSubMenu(0), 
  587. TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTALIGN |TPM_RIGHTBUTTON, 
  588. ptMenu.x, ptMenu.y, this, NULL);
  589. // general items processing
  590. switch (nMenuResult)
  591. {
  592. case ID_POPUP_GOTOTHISDAY:
  593. {
  594. GetCalendarCtrl().SwitchActiveView(xtpCalendarDayView);
  595. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetActiveView());
  596. if (pDayView)
  597. {
  598. COleDateTime dtThisDay(hitInfo.dt);
  599. pDayView->ResetSelection();
  600. pDayView->ShowDay(dtThisDay);
  601. }
  602. }
  603. break;
  604. case ID_CALENDAR_ADD_NEW_EVENT:
  605. AddNewEvent(&ptHit);
  606. break;
  607. }
  608. }
  609. }
  610. }
  611. else if (XTP_NC_CALENDARLBUTTONDBLCLICK == Event)
  612. {
  613. if (bHitTest && hitInfo.pViewEvent)
  614. {
  615. // mouse double clicked - show event edit dialog
  616. CXTPCalendarEvent* pEvent = hitInfo.pViewEvent->GetEvent();
  617. CXTPCalendarEventPtr ptrEvent = pEvent->CloneEvent();
  618.             
  619. if(hitInfo.pViewEvent->IsShowingToolTip()) { 
  620. hitInfo.pViewEvent->HideToolTip(); 
  621. }
  622. CXTPCalendarEventPropertiesDlg dlg(&GetCalendarCtrl(), FALSE, this, ptrEvent);
  623. dlg.DoModal();
  624. }
  625. else if (bHitTest && (hitInfo.uHitCode & (xtpCalendarHitTestDayArea|xtpCalendarHitTestDayHeader)))
  626. {
  627. AddNewEvent(&ptHit);
  628. }
  629. }
  630. }
  631. void CCalendarDemoView::OnFileSave()
  632. {
  633. CXTPCalendarData* pData = GetCalendarCtrl().GetDataProvider();
  634. if(!pData) {
  635. ASSERT(FALSE);
  636. return;
  637. }
  638. if(GetDPType(pData) == xtpCalendarDataProviderMemory) 
  639. {
  640. CString strFileName = AfxGetApp()->GetProfileString(cstrDP_Opt_section, cstrUseDP_Mem_File_opt);
  641. if(!pData->Save()) 
  642. {
  643. CString strDPname = GetDPName(xtpCalendarDataProviderMemory);
  644. CString strMsg;
  645. strMsg.Format(_T("%s cannot create file: n%s"), strDPname, strFileName);
  646. AfxMessageBox(strMsg);
  647. }
  648. }  
  649. }
  650. void CCalendarDemoView::OnFileSaveAs()
  651. {
  652. CXTPCalendarData* pData = GetCalendarCtrl().GetDataProvider();
  653. if(!pData) {
  654. ASSERT(FALSE);
  655. return;
  656. }
  657. if(GetDPType(pData) != xtpCalendarDataProviderMemory) {
  658. ASSERT(FALSE);
  659. return;
  660. }  
  661. CDataProvidersOptions optDlg;
  662. optDlg.m_strTitle = _T("Save calendar data as:");
  663. optDlg.m_bOpenMode = FALSE;
  664. optDlg.m_bWarnIfExist = TRUE;
  665. optDlg.m_eMode = CDataProvidersOptions::modeMemOnly;
  666. int nDlgRes = (int)optDlg.DoModal();
  667. if(nDlgRes != IDOK) {
  668. return;
  669. }
  670. CString strFileName = AfxGetApp()->GetProfileString(cstrDP_Opt_section, cstrUseDP_Mem_File_opt);
  671. if(!pData->Save()) 
  672. {
  673. CString strDPname = GetDPName(xtpCalendarDataProviderMemory);
  674. CString strMsg;
  675. strMsg.Format(_T("%s cannot create file: n%s"), strDPname, strFileName);
  676. AfxMessageBox(strMsg);
  677. }
  678. }
  679. void CCalendarDemoView::OnUpdateFileSave(CCmdUI* pCmdUI)
  680. {
  681. CXTPCalendarData* pData = GetCalendarCtrl().GetDataProvider();
  682. int nDPType = GetDPType(pData);
  683. pCmdUI->Enable(nDPType == xtpCalendarDataProviderMemory);
  684. }
  685. void CCalendarDemoView::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
  686. {
  687. OnUpdateFileSave(pCmdUI);
  688. }
  689. void CCalendarDemoView::OnEvent_IsEditActionDisabled(XTP_NOTIFY_CODE Event, 
  690. WPARAM wParam, LPARAM lParam)
  691. {   
  692. if (XTP_NC_CALENDAR_IS_EVENT_EDIT_OPERATION_DISABLED != Event) {
  693. ASSERT(FALSE);
  694. return;
  695. }
  696. XTP_EVENT_EDIT_OPERATION_PARAMS* pOPparams = (XTP_EVENT_EDIT_OPERATION_PARAMS*)wParam;
  697. BOOL* pbCancel = (BOOL*)lParam;
  698. ASSERT(pbCancel);
  699. // check is already canceled/handled
  700. if(!pOPparams || !pbCancel || *pbCancel) {
  701. return;
  702. }
  703. // Disable dragging for recurrence events
  704. //
  705. // CXTPCalendarEvent* pEvent = pOPparams->pEventViews->GetAt(0)->GetEvent();
  706. // ASSERT(pEvent);
  707. // if((pOPparams->eOperation == xtpCalendarEO_DragCopy || pOPparams->eOperation == xtpCalendarEO_DragMove ||
  708. // pOPparams->eOperation == xtpCalendarEO_DragResizeBegin || pOPparams->eOperation == xtpCalendarEO_DragResizeEnd)
  709. // && pEvent 
  710. // && pEvent->GetRecurrenceState() != xtpCalendarRecurrenceNotRecurring) 
  711. // {
  712. // *pbCancel = TRUE;
  713. // }
  714. }
  715. void CCalendarDemoView::OnEvent_BeforeEditAction(XTP_NOTIFY_CODE Event, 
  716. WPARAM wParam, LPARAM lParam)
  717. {   
  718. if (XTP_NC_CALENDAR_BEFORE_EVENT_EDIT_OPERATION != Event) {
  719. ASSERT(FALSE);
  720. return;
  721. }
  722.     
  723. XTP_EVENT_EDIT_OPERATION_PARAMS* pOPparams = (XTP_EVENT_EDIT_OPERATION_PARAMS*)wParam;
  724. BOOL* pbHandled = (BOOL*)lParam;
  725. ASSERT(pbHandled && pOPparams);
  726. // check is already canceled/handled
  727. if(!pOPparams || !pbHandled || *pbHandled) {
  728. return;
  729. }
  730. if(pOPparams->eOperation == xtpCalendarEO_DeleteEvent)
  731. {
  732. if(!pOPparams->pEventViews || !pOPparams->pEventViews->GetAt(0)) {
  733. ASSERT(FALSE);
  734. return;
  735. }
  736. CXTPCalendarEvent* pEvent = pOPparams->pEventViews->GetAt(0)->GetEvent();
  737. if(!pEvent) {
  738. ASSERT(FALSE);
  739. return;
  740. }
  741. if(pEvent->GetRecurrenceState() == xtpCalendarRecurrenceNotRecurring)
  742. {
  743. CString strMsg;
  744. strMsg.Format(_T("Would you like to delete event: "%s" ?"), pEvent->GetSubject());
  745. int nRes = AfxMessageBox(strMsg, MB_YESNO);
  746. if(nRes == IDNO) 
  747. {
  748. *pbHandled = TRUE;
  749. }
  750. }
  751. }
  752. //**  since ver 9.81
  753. //******************
  754. //if (pOPparams->eOperation == xtpCalendarEO_DragMove ||
  755. // pOPparams->eOperation == xtpCalendarEO_DragCopy )
  756. //{
  757. // XTP_EVENT_DRAG_OPERATION_PARAMS* pOpDrag = (XTP_EVENT_DRAG_OPERATION_PARAMS*)pOPparams;
  758. // ASSERT(pOpDrag->pDraggingEvent && pOpDrag->pDraggingEventNew);
  759. //
  760. // if(pOpDrag->pDraggingEvent && pOpDrag->pDraggingEventNew)
  761. // {
  762. // COleDateTime dtOrigStart = pOpDrag->pDraggingEvent->GetStartTime();
  763. // COleDateTime dtNewStart = pOpDrag->pDraggingEventNew->GetStartTime();;
  764. //
  765. // if (CXTPCalendarUtils::ResetTime(dtOrigStart) != CXTPCalendarUtils::ResetTime(dtNewStart) 
  766. // || pOpDrag->pDraggingEvent->IsAllDayEvent() != pOpDrag->pDraggingEventNew->IsAllDayEvent()) 
  767. // {
  768. // *pbHandled = TRUE;
  769. // }
  770. // }
  771. //}
  772. //**  for ver 9.80
  773. //******************
  774. //if(pOPparams->eOperation == xtpCalendarEO_DragMove &&
  775. // GetCalendarCtrl().GetActiveView()->GetDraggingEventOrig())
  776. //{
  777. // CPoint pt;
  778. // GetCursorPos(&pt);
  779. // GetCalendarCtrl().ScreenToClient(&pt);
  780. // XTP_CALENDAR_HITTESTINFO hitInfo;
  781. // if(GetCalendarCtrl().GetActiveView()->HitTest(pt, &hitInfo)) 
  782. // {
  783. // COleDateTime dtOrigStart = GetCalendarCtrl().GetActiveView()->GetDraggingEventOrig()->GetStartTime(); 
  784. //
  785. // // store previous version to rollback
  786. // CXTPCalendarEventPtr ptrEventPrev = GetCalendarCtrl().GetActiveView()->GetDraggingEventNew()->CloneEvent(); 
  787. //
  788. // if(GetCalendarCtrl().GetActiveView()->OnDragging(pt, &hitInfo))
  789. // {
  790. // CXTPCalendarEvent* pEventNew = GetCalendarCtrl().GetActiveView()->GetDraggingEventNew();
  791. // COleDateTime dtNewStart = pEventNew->GetStartTime();
  792. //
  793. // if(CXTPCalendarUtils::ResetTime(dtOrigStart) !=
  794. // CXTPCalendarUtils::ResetTime(dtNewStart) ) 
  795. // {
  796. // *pbHandled = TRUE;
  797. // }
  798. //
  799. // pEventNew->Update(ptrEventPrev);
  800. //
  801. // //TRACE(_T("orig: %s - point: %s = [%d] n"), dtOrigStart.Format(), hitInfo.dt.Format(),
  802. // // *pbHandled);
  803. // }
  804. // }
  805. //}
  806. }
  807. void CCalendarDemoView::OnEvent_CalendarData(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  808. {
  809. UNREFERENCED_PARAMETER(lParam);
  810. UNREFERENCED_PARAMETER(wParam);
  811. CString strActionText;
  812.     
  813. switch(Event)
  814. {
  815. case XTP_NC_CALENDAREVENTWASADDED:
  816. strActionText = _T("Event_WasAdded");
  817. break;
  818. case XTP_NC_CALENDAREVENTWASDELETED:
  819. strActionText = _T("Event_WasDeleted");
  820. break;
  821. case XTP_NC_CALENDAREVENTWASCHANGED:
  822. strActionText = _T("Event_WasChanged");
  823. break;
  824. case XTP_NC_CALENDARPATTERNWASADDED:
  825. strActionText = _T("Pattern_WasAdded");
  826. break;
  827. case XTP_NC_CALENDARPATTERNWASDELETED:
  828. strActionText = _T("Pattern_WasDeleted");
  829. break;
  830. case XTP_NC_CALENDARPATTERNWASCHANGED:
  831. strActionText = _T("Pattern_WasChanged");
  832. break;
  833. default:
  834. ASSERT(FALSE);
  835. return;
  836. }
  837. //===========================================================================
  838. CXTPCalendarData* pData = GetCalendarCtrl().GetDataProvider();
  839. if(!pData) {
  840. ASSERT(FALSE);
  841. return;
  842. }
  843. if(Event == XTP_NC_CALENDAREVENTWASADDED || Event == XTP_NC_CALENDAREVENTWASDELETED ||
  844. Event == XTP_NC_CALENDAREVENTWASCHANGED)
  845. {
  846. //EVENT:
  847. CXTPCalendarEvent* pEvent = (CXTPCalendarEvent*)lParam;
  848. if(pEvent)
  849. {
  850. COleDateTime dtStart = pEvent->GetStartTime();
  851. COleDateTime dtEnd = pEvent->GetEndTime();
  852. CString strSubject = pEvent->GetSubject();
  853. TRACE(_T("%s (ID=%d): %s-%s, '%s' n"), strActionText, 
  854. pEvent->GetEventID(), dtStart.Format(), dtEnd.Format(), strSubject);
  855. else {
  856. TRACE(_T("%s (pEvent=%x) n"), strActionText, wParam);
  857. }
  858. }
  859. else {
  860. //PATTERN:
  861. CXTPCalendarRecurrencePatternPtr ptrPattern = pData->GetRecurrencePattern((DWORD)wParam);
  862. if(ptrPattern)
  863. {
  864. COleDateTime dtStartPatt = ptrPattern->GetPatternStartDate();
  865. CXTPCalendarEventPtr ptrMasterEvent = ptrPattern->GetMasterEvent();
  866. ASSERT(ptrMasterEvent);
  867. CString strSubject = ptrMasterEvent ? ptrMasterEvent->GetSubject() : _T("");
  868. TRACE(_T("%s (ID=%d): pattern starts at %s, '%s' n"), strActionText, 
  869. wParam, dtStartPatt.Format(), strSubject);
  870. else {
  871. TRACE(_T("%s (ID=%d) n"), strActionText, wParam);
  872. }
  873. }
  874. }
  875. void CCalendarDemoView::CreateRemindersWindow()
  876. {
  877. if(!s_pDlgReminders || !s_pDlgReminders->GetSafeHwnd()) 
  878. {
  879. if(!s_pDlgReminders)
  880. s_pDlgReminders = new CXTPCalendarRemindersDialog();
  881. VERIFY( s_pDlgReminders->Create() );
  882. s_pDlgReminders->CenterWindow();
  883. s_pDlgReminders->SetRemindersManager(&GetCalendarCtrl());
  884. }
  885. }
  886. void CCalendarDemoView::OnViewReminders()
  887. {
  888. s_pDlgReminders->ShowWindow(SW_SHOWNORMAL);
  889. }
  890. //void CCalendarDemoView::OnReminders(XTP_NOTIFY_CODE Event, WPARAM wParam , LPARAM lParam)
  891. //{
  892. // UNREFERENCED_PARAMETER(lParam);
  893. //
  894. // if (Event != XTP_NC_CALENDAR_ON_REMINDERS) {
  895. // ASSERT(FALSE);
  896. // return;
  897. // }
  898. //
  899. // int eAction = (int)wParam;
  900. // if (eAction == xtpCalendarRemindersMonitoringStarted)
  901. // {
  902. // CreateRemindersWindow();
  903. // }
  904. // if (eAction == xtpCalendarRemindersMonitoringStopped)
  905. // {
  906. // if (s_pDlgReminders)
  907. // {
  908. // delete s_pDlgReminders;
  909. // s_pDlgReminders = NULL;
  910. // }
  911. // }
  912. //}
  913. void CCalendarDemoView::OnBeforeDrawThemeObject(XTP_NOTIFY_CODE Event, WPARAM wParam , LPARAM lParam)
  914. {
  915. ASSERT(Event == XTP_NC_CALENDAR_BEFORE_DRAW_THEMEOBJECT);
  916. if (Event != XTP_NC_CALENDAR_BEFORE_DRAW_THEMEOBJECT)
  917. return;
  918. CXTPCalendarThemeOffice2007* pTheme2007 = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetCalendarCtrl().GetTheme());
  919. ASSERT(pTheme2007);
  920. if (!pTheme2007)
  921. return;
  922. static CFont s_fntStriked;
  923. if (s_fntStriked.m_hObject == NULL)
  924. {
  925. LOGFONT lfIcon;
  926. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  927. lfIcon.lfWeight = FW_BOLD;
  928. lfIcon.lfStrikeOut = 1;
  929. s_fntStriked.CreateFontIndirect(&lfIcon);
  930. }
  931. if (wParam == xtpCalendarBeforeDraw_DayViewEvent)
  932. {
  933. CXTPCalendarDayViewEvent* pViewEvent = (CXTPCalendarDayViewEvent*)lParam;
  934. if (pViewEvent && pViewEvent->GetEvent()->GetSubject().Left(1) == _T("*"))
  935. {
  936. pTheme2007->GetDayViewPartX()->GetDayPartX()->GetGroupPartX()->GetSingleDayEventPartX()->m_fcsetNormal.fcsetSubject.fntFont.SetCustomValue(&s_fntStriked);
  937. pTheme2007->GetDayViewPartX()->GetDayPartX()->GetGroupPartX()->GetMultiDayEventPartX()->m_fcsetNormal.fcsetSubject.fntFont.SetCustomValue(&s_fntStriked);
  938. pTheme2007->GetDayViewPartX()->GetDayPartX()->GetGroupPartX()->GetSingleDayEventPartX()->m_fcsetSelected.fcsetSubject.fntFont.SetCustomValue(&s_fntStriked);
  939. pTheme2007->GetDayViewPartX()->GetDayPartX()->GetGroupPartX()->GetMultiDayEventPartX()->m_fcsetSelected.fcsetSubject.fntFont.SetCustomValue(&s_fntStriked);
  940. }
  941. }
  942. if (wParam == xtpCalendarBeforeDraw_MonthViewDay)
  943. {
  944. CXTPCalendarMonthViewDay* pDay = (CXTPCalendarMonthViewDay*)lParam;
  945. if (pDay->GetDayDate().GetDayOfWeek() == 3)
  946. {
  947. pTheme2007->GetMonthViewPartX()->GetDayPartX()->m_clrBackgroundDark = RGB(196, 128, 128);
  948. pTheme2007->GetMonthViewPartX()->GetDayPartX()->m_clrBackgroundLight = RGB(230, 128, 128);
  949. pTheme2007->GetMonthViewPartX()->GetDayPartX()->m_clrBackgroundSelected = RGB(128, 228, 228);
  950. }
  951. }
  952. }
  953. void CCalendarDemoView::OnEvent_GetItemText(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  954. {
  955. UNREFERENCED_PARAMETER(lParam);
  956. XTP_CALENDAR_GETITEMTEXT_PARAMS* pParams = (XTP_CALENDAR_GETITEMTEXT_PARAMS*)wParam ;
  957. if (XTP_NC_CALENDAR_GETITEMTEXT != Event || !pParams)
  958. return;
  959. if (xtpCalendarItemText_EventMarkupTemplate == pParams->nItem)
  960. {
  961. pParams->pstrText->Format(cstrMarkupDynamicSample);
  962. }
  963. if (xtpCalendarItemText_EventSubject == pParams->nItem)
  964. {
  965. // Dynamically customize Location text
  966. pParams->pstrText->MakeReverse();
  967. }
  968. }
  969. CXTPCalendarControl_Custom::CXTPCalendarControl_Custom()
  970. {
  971. m_nToolTipMode = ctmStandard;
  972. }
  973. INT_PTR CXTPCalendarControl_Custom::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
  974. {
  975. if(m_nToolTipMode == ctmCustom)
  976. {
  977. XTP_CALENDAR_HITTESTINFO hitTest;
  978. if( ((CXTPCalendarControl*)this)->GetActiveView()->HitTest(point, &hitTest))
  979. {
  980. if(hitTest.pViewEvent) 
  981. {
  982. pTI->hwnd = m_hWnd; //   Handle to a window 
  983. pTI->uId = (UINT_PTR)m_hWnd; //   Handle to a child window 
  984. pTI->uFlags |= TTF_IDISHWND | TTF_NOTBUTTON; 
  985. CString strToolText;
  986. strToolText.Format(_T("[ID = 0x%08X] (%s - %s) %s"),
  987. hitTest.pViewEvent->GetEvent()->GetEventID(),
  988. hitTest.pViewEvent->FormatEventTime(hitTest.pViewEvent->GetEvent()->GetStartTime()),
  989. hitTest.pViewEvent->FormatEventTime(hitTest.pViewEvent->GetEvent()->GetEndTime()),
  990. hitTest.pViewEvent->GetEvent()->GetSubject()
  991. );
  992. int nBuffSize = strToolText.GetLength()*2 +10;
  993. TCHAR* pBuffer = (TCHAR*)malloc(nBuffSize);
  994. STRCPY_S(pBuffer, nBuffSize, (LPCTSTR)strToolText);
  995. pTI->lpszText = pBuffer;
  996. return 333;
  997. }
  998. }
  999. }
  1000. return CXTPCalendarControl::OnToolHitTest(point, pTI);
  1001. }
  1002. void CCalendarDemoView::OnEvent_PrePopulate(XTP_NOTIFY_CODE Event, 
  1003.  WPARAM wParam, LPARAM lParam)
  1004. {   
  1005. UNREFERENCED_PARAMETER(wParam);
  1006. if (XTP_NC_CALENDAR_PREPOPULATE != Event) {
  1007. ASSERT(FALSE);
  1008. return;
  1009. }
  1010. // Theme 2007.
  1011. CXTPCalendarThemeOffice2007* pTheme2007 = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetCalendarCtrl().GetTheme());
  1012. if (!pTheme2007)
  1013. return;
  1014. // pTheme2007->SetBeforeDrawFlags(pTheme2007->GetBeforeDrawFlags() | xtpCalendarBeforeDraw_MonthViewDay);
  1015. // pTheme2007->SetBeforeDrawFlags(pTheme2007->GetBeforeDrawFlags() | xtpCalendarBeforeDraw_DayViewEvent);
  1016. // add icons for reminder and meting flags as custom icons
  1017. // See Also: 
  1018. // CAdvancedCalendarOptionsDlg::OnOK() 
  1019. // The custom icons images added there and IDs assigned to them. 
  1020. // wParam - [in] CXTPCalendarViewGroup* - A pointer to Group View.
  1021. // lParam - [in/out] CXTPCalendarEvents* - A pointer to events array to draw.
  1022. CXTPCalendarEvents* pEvents = (CXTPCalendarEvents*)lParam;
  1023. ASSERT(pEvents);
  1024. if (!pEvents)
  1025. return;
  1026. int nCount = pEvents->GetCount();
  1027. for (int i = 0; i < nCount; i++)
  1028. {
  1029. CXTPCalendarEvent* pEvent = pEvents->GetAt(i);
  1030. ASSERT(pEvent);
  1031. if (!pEvent)
  1032. continue;
  1033. if (pEvent->IsReminder()) {
  1034. pEvent->GetCustomIcons()->AddIfNeed((UINT)xtpCalendarEventIconIDReminder);
  1035. }
  1036. else {
  1037. pEvent->GetCustomIcons()->RemoveID((UINT)xtpCalendarEventIconIDReminder);
  1038. }
  1039. if (pEvent->IsMeeting()) {
  1040. pEvent->GetCustomIcons()->AddIfNeed((UINT)xtpCalendarEventIconIDMeeting);
  1041. }
  1042. else {
  1043. pEvent->GetCustomIcons()->RemoveID((UINT)xtpCalendarEventIconIDMeeting);
  1044. }
  1045. //-------------------------------------------------------------------
  1046. // There are 3 standard icons for Office2007 theme: 
  1047. //  * recurrence occurrence
  1048. //  * recurrence exception
  1049. //  * private
  1050. // Its IDs are from from XTPCalendarEventIconIDs enum.
  1051. // If custom icons have an icon with the same ID as standard 
  1052. // icon - custom icon will be used instead of standard.
  1053. //-------------------------------------------------------------------
  1054. // this code customize private icon from the standard Office2007 
  1055. // theme set. 
  1056. //
  1057. // uncomment code below to see the customization. 
  1058. //if (pEvent->IsPrivate()) {
  1059. // pEvent->GetCustomIcons()->AddIfNeed((UINT)xtpCalendarEventIconIDPrivate);
  1060. //}
  1061. //else 
  1062. {
  1063. pEvent->GetCustomIcons()->RemoveID((UINT)xtpCalendarEventIconIDPrivate);
  1064. }
  1065. }
  1066. }
  1067. //void CCalendarDemoView::OnEvent_SelChanged(XTP_NOTIFY_CODE Event, 
  1068. //  WPARAM wParam, LPARAM lParam)
  1069. //{   
  1070. // if (XTP_NC_CALENDAR_SELECTION_CHANGED != Event) {
  1071. // ASSERT(FALSE);
  1072. // return;
  1073. // }
  1074. // if(wParam != xtpCalendarSelectionEvents) {
  1075. // return;
  1076. // }
  1077. //
  1078. // static BOOL s_bInProgress = FALSE;
  1079. //
  1080. // CXTPCalendarView* pView = GetCalendarCtrl().GetActiveView();
  1081. //
  1082. // if(!pView || s_bInProgress) {
  1083. // return;
  1084. // }
  1085. //
  1086. // if(pView->GetSelectedEvents()->GetCount() <= 1) {
  1087. // return;
  1088. // }
  1089. //
  1090. // // Protect from processing self sending notifications.
  1091. // //
  1092. // // see lines below:
  1093. // // pView->UnselectAllEvents(); // will send XTP_NC_CALENDAR_SELECTION_CHANGED
  1094. // // pView->SelectEvent(pLastSelEView->GetEvent()); // will send XTP_NC_CALENDAR_SELECTION_CHANGED
  1095. // //
  1096. // s_bInProgress = TRUE;
  1097. //
  1098. // CXTPCalendarViewEvent* pLastSelEView = pView->GetLastSelectedViewEvent();
  1099. // if(pLastSelEView) 
  1100. // {
  1101. // // Lock event view
  1102. // // for case when it can be destroyed in UnselectAllEvents() call.
  1103. // pLastSelEView->InternalAddRef();
  1104. //
  1105. // pView->UnselectAllEvents();
  1106. // pView->SelectEvent(pLastSelEView->GetEvent());
  1107. //
  1108. // // Unlock event view 
  1109. // pLastSelEView->InternalRelease();
  1110. // }
  1111. //
  1112. // s_bInProgress = FALSE;
  1113. //}
  1114. void CCalendarDemoView::OnOfficeThemeChanged(int nCalendarTheme)
  1115. {
  1116. CXTPCalendarControl::CUpdateContext updateContext(&GetCalendarCtrl(), xtpCalendarUpdateAll);
  1117. GetCalendarCtrl().SetPaintTheme((XTPCalendarTheme)nCalendarTheme);
  1118. if (nCalendarTheme == xtpCalendarThemeOffice2007)
  1119. {
  1120. m_wndScrollBar.SetScrollBarStyle(xtpScrollStyleOffice2007Dark);
  1121. }
  1122. else
  1123. {
  1124. m_wndScrollBar.SetScrollBarStyle(xtpScrollStyleDefault);
  1125. }
  1126. }