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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarControlView.cpp : implementation of the CXTPCalendarControlView class.
  2. //
  3. // This file is a part of the XTREME CALENDAR MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPVC50Helpers.h"
  22. #include "Common/XTPVC80Helpers.h"
  23. #include "Common/XTPResourceManager.h"
  24. #include "Common/XTPImageManager.h"
  25. #include "Common/resource.h"
  26. #include "XTPCalendarControlView.h"
  27. #include "XTPCalendarMonthView.h"
  28. #include "XTPCalendarThemeOffice2007.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. ////////////////////////////////////////////////////////////////////////////
  35. AFX_INLINE void MoveRectToXY(CRect& rc, int nX, int nY)
  36. {
  37. rc.right = nX + rc.Width();
  38. rc.bottom = nY + rc.Height();
  39. rc.left = nX;
  40. rc.top = nY;
  41. }
  42. //////////////////////////////////////////////////////
  43. BEGIN_MESSAGE_MAP(CXTPCalendarPageSetupDialog, CPageSetupDialog)
  44. ON_BN_CLICKED(XTP_IDC_PRINT_DATE_HEADER, OnBnClickedPrintDateHeader)
  45. ON_BN_CLICKED(XTP_IDC_PRINT_DATE_HEADER_FONT_BUTTON, OnBnClickedDateHeaderFont)
  46. ON_BN_CLICKED(XTP_IDC_CALENDAR_HEADER_FORMAT_BTN, OnBnClickedHeaderFormat)
  47. ON_BN_CLICKED(XTP_IDC_CALENDAR_FOOTER_FORMAT_BTN, OnBnClickedFooterFormat)
  48. END_MESSAGE_MAP()
  49. CXTPCalendarPageSetupDialog::CXTPCalendarPageSetupDialog(
  50. CXTPCalendarControlViewPrintOptions* pOptions,
  51. DWORD dwFlags, CWnd* pParentWnd)
  52. : CPageSetupDialog(dwFlags, pParentWnd)
  53. {
  54. ASSERT(pOptions);
  55. m_pOptions = pOptions;
  56. if (m_pOptions)
  57. {
  58. BOOL bIsInches = m_pOptions->IsMarginsMeasureInches();
  59. DWORD dwMeasure = bIsInches ? PSD_INTHOUSANDTHSOFINCHES : PSD_INHUNDREDTHSOFMILLIMETERS;
  60. m_psd.Flags &= ~PSD_INWININIINTLMEASURE;
  61. m_psd.Flags |= dwMeasure;
  62. }
  63. m_psd.Flags |= PSD_ENABLEPAGESETUPTEMPLATEHANDLE;
  64. m_psd.hPageSetupTemplate = XTPResourceManager()->LoadDialogTemplate2(MAKEINTRESOURCE(IDD));
  65. ASSERT(m_psd.hPageSetupTemplate);
  66. if (m_pOptions)
  67. {
  68. m_psd.rtMargin = m_pOptions->m_rcMargins;
  69. }
  70. m_nIDHelp = XTP_IDD_CALENDAR_PRINT_PAGE_SETUP;
  71. VERIFY( ::SystemParametersInfo( SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &m_lfDateHeader, 0 ) );
  72. }
  73. CXTPCalendarPageSetupDialog::~CXTPCalendarPageSetupDialog()
  74. {
  75. }
  76. #ifndef rad1
  77. #define rad1        0x0420
  78. #define rad2        0x0421
  79. #define grp4        0x0433
  80. #endif
  81. BOOL CXTPCalendarPageSetupDialog::OnInitDialog ()
  82. {
  83. CPageSetupDialog::OnInitDialog();
  84. ASSERT(m_pOptions);
  85. VERIFY( m_ctrlPrintFromCmb.SubclassDlgItem(XTP_IDC_PRINT_FROM_COMBO, this) );
  86. VERIFY( m_ctrlPrintToCmb.SubclassDlgItem(XTP_IDC_PRINT_TO_COMBO, this) );
  87. VERIFY( m_ctrlPrintFromTo.SubclassDlgItem(XTP_IDC_PRINT_FROMTO, this) );
  88. VERIFY( m_ctrlPrintDateHeader.SubclassDlgItem(XTP_IDC_PRINT_DATE_HEADER, this) );
  89. VERIFY( m_ctrlDateHeaderFontLabel.SubclassDlgItem(XTP_IDC_PRINT_DATE_HEADER_FONT_LABEL, this) );
  90. VERIFY( m_ctrlDateHeaderFont.SubclassDlgItem(XTP_IDC_PRINT_DATE_HEADER_FONT, this) );
  91. VERIFY( m_ctrlDateHeaderFontButton.SubclassDlgItem(XTP_IDC_PRINT_DATE_HEADER_FONT_BUTTON, this) );
  92. VERIFY( m_ctrlBlackWhitePrinting.SubclassDlgItem(XTP_IDC_PRINT_BLACK_WHITE, this) );
  93. VERIFY( m_ctrlHeaderFormat.SubclassDlgItem(XTP_IDC_CALENDAR_HEADER_FORMAT, this) );
  94. VERIFY( m_ctrlFooterFormat.SubclassDlgItem(XTP_IDC_CALENDAR_FOOTER_FORMAT, this) );
  95. VERIFY( m_ctrlHeaderFormatBtn.SubclassDlgItem(XTP_IDC_CALENDAR_HEADER_FORMAT_BTN, this) );
  96. VERIFY( m_ctrlFooterFormatBtn.SubclassDlgItem(XTP_IDC_CALENDAR_FOOTER_FORMAT_BTN, this) );
  97. CString strTimeFormat_HrMin = CXTPCalendarUtils::GetTimeFormatString_HrMin();
  98. CString strTime;
  99. for (int i = 0; i < 24*60; i += 30)
  100. {
  101. strTime = CXTPCalendarUtils::GetTimeFormat((int)(i / 60), (int)(i % 60), strTimeFormat_HrMin);
  102. m_ctrlPrintFromCmb.AddString(strTime);
  103. m_ctrlPrintToCmb.AddString(strTime);
  104. }
  105. if(m_pOptions)
  106. {
  107. strTime = CXTPCalendarUtils::GetTimeFormat(m_pOptions->m_dtPrintFrom, strTimeFormat_HrMin);
  108. m_ctrlPrintFromCmb.SetWindowText(strTime);
  109. strTime = CXTPCalendarUtils::GetTimeFormat(m_pOptions->m_dtPrintTo, strTimeFormat_HrMin);
  110. m_ctrlPrintToCmb.SetWindowText(strTime);
  111. m_ctrlPrintFromTo.SetCheck(m_pOptions->m_bPrintFromToExactly ? 1 : 0);
  112. m_ctrlPrintDateHeader.SetCheck(m_pOptions->m_bPrintDateHeader ? 1 : 0);
  113. m_ctrlBlackWhitePrinting.SetCheck(m_pOptions->m_bBlackWhitePrinting? 1 : 0);
  114. m_lfDateHeader = m_pOptions->m_lfDateHeaderFont;
  115. CString strFont = FormatFontName(m_lfDateHeader);
  116. m_ctrlDateHeaderFont.SetWindowText(strFont);
  117. if (m_pOptions->GetPageHeader())
  118. m_ctrlHeaderFormat.SetWindowText(m_pOptions->GetPageHeader()->m_strFormatString);
  119. if (m_pOptions->GetPageFooter())
  120. m_ctrlFooterFormat.SetWindowText(m_pOptions->GetPageFooter()->m_strFormatString);
  121. OnBnClickedPrintDateHeader();
  122. }
  123. XTP_SAFE_CALL1(GetDlgItem(rad1), EnableWindow(TRUE)); //1056 Portrait
  124. XTP_SAFE_CALL1(GetDlgItem(rad2), EnableWindow(TRUE)); //1057 Landscape
  125. BOOL bIsInches = m_pOptions ? m_pOptions->IsMarginsMeasureInches() : FALSE;
  126. UINT uStrID = bIsInches ? XTP_IDS_CALENDAR_MARGINS_INCH : XTP_IDS_CALENDAR_MARGINS_MM;
  127. CString strCaption = CXTPCalendarUtils::LoadString(uStrID);
  128. if (!strCaption.IsEmpty() && GetDlgItem(grp4))
  129. {
  130. GetDlgItem(grp4)->SetWindowText(strCaption);
  131. }
  132. HICON hBtnIcon = XTPResourceManager()->LoadIcon(XTP_IDI_BTN_ARROW_R, CSize(0,0));
  133. ASSERT(hBtnIcon);
  134. if (hBtnIcon)
  135. {
  136. m_ctrlHeaderFormatBtn.SetIcon(hBtnIcon);
  137. m_ctrlFooterFormatBtn.SetIcon(hBtnIcon);
  138. }
  139. return FALSE;
  140. }
  141. void CXTPCalendarPageSetupDialog::OnBnClickedPrintDateHeader()
  142. {
  143. int nCheck = m_ctrlPrintDateHeader.GetCheck();
  144. m_ctrlDateHeaderFont.EnableWindow(nCheck != 0);
  145. m_ctrlDateHeaderFontLabel.EnableWindow(nCheck != 0);
  146. m_ctrlDateHeaderFontButton.EnableWindow(nCheck != 0);
  147. }
  148. void CXTPCalendarPageSetupDialog::OnOK()
  149. {
  150. ASSERT(m_pOptions);
  151. if (!m_pOptions)
  152. {
  153. CPageSetupDialog::OnOK();
  154. return;
  155. }
  156. CString strFrom, strTo;
  157. m_ctrlPrintFromCmb.GetWindowText(strFrom);
  158. int nFrom_min = CXTPCalendarUtils::ParceTimeString_min(strFrom);
  159. m_ctrlPrintToCmb.GetWindowText(strTo);
  160. int nTo_min = CXTPCalendarUtils::ParceTimeString_min(strTo);
  161. m_pOptions->m_dtPrintFrom.SetTime(nFrom_min / 60, nFrom_min % 60, 0);
  162. m_pOptions->m_dtPrintTo.SetTime(nTo_min / 60, nTo_min % 60, 0);
  163. m_pOptions->m_bPrintFromToExactly = m_ctrlPrintFromTo.GetCheck() != 0;
  164. m_pOptions->m_bBlackWhitePrinting = m_ctrlBlackWhitePrinting.GetCheck() != 0;
  165. m_pOptions->m_bPrintDateHeader = m_ctrlPrintDateHeader.GetCheck() != 0;
  166. if (m_pOptions->m_bPrintDateHeader)
  167. {
  168. m_pOptions->m_lfDateHeaderFont = m_lfDateHeader;
  169. }
  170. m_pOptions->m_rcMargins = m_psd.rtMargin;
  171. if (m_pOptions->GetPageHeader())
  172. m_ctrlHeaderFormat.GetWindowText(m_pOptions->GetPageHeader()->m_strFormatString);
  173. if (m_pOptions->GetPageFooter())
  174. m_ctrlFooterFormat.GetWindowText(m_pOptions->GetPageFooter()->m_strFormatString);
  175. CPageSetupDialog::OnOK();
  176. }
  177. CString CXTPCalendarPageSetupDialog::FormatFontName(const LOGFONT& lfFont)
  178. {
  179. CClientDC dc(this);
  180. double dLogPixelY = dc.GetDeviceCaps(LOGPIXELSY);
  181. double dPointSize = abs(lfFont.lfHeight) * 72.0 / dLogPixelY;
  182. int nPointSize = (int)(dPointSize + 0.5);
  183. CString strFont;
  184. strFont.Format(_T(" %d pt. %s"), nPointSize, lfFont.lfFaceName);
  185. CString strAttr;
  186. if (lfFont.lfWeight >= FW_BOLD)
  187. {
  188. strAttr += _T(" Bold");
  189. }
  190. if (lfFont.lfItalic)
  191. {
  192. if (!strAttr.IsEmpty())
  193. {
  194. strAttr += _T(",");
  195. }
  196. strAttr += _T(" Italic");;
  197. }
  198. if (!strAttr.IsEmpty())
  199. {
  200. strFont += _T("n");
  201. strFont += strAttr;
  202. }
  203. return strFont;
  204. }
  205. void CXTPCalendarPageSetupDialog::OnBnClickedDateHeaderFont()
  206. {
  207. CFontDialog dlgFont(&m_lfDateHeader);
  208. int nDlgRes = (int)dlgFont.DoModal();
  209. if (nDlgRes == IDOK)
  210. {
  211. dlgFont.GetCurrentFont(&m_lfDateHeader);
  212. CString strFont = FormatFontName(m_lfDateHeader);
  213. m_ctrlDateHeaderFont.SetWindowText(strFont);
  214. }
  215. }
  216. void CXTPCalendarPageSetupDialog::OnBnClickedHeaderFormat()
  217. {
  218. CXTPPrintPageHeaderFooter::DoInsertHFFormatSpecifierViaMenu(
  219. this, &m_ctrlHeaderFormat, &m_ctrlHeaderFormatBtn);
  220. }
  221. void CXTPCalendarPageSetupDialog::OnBnClickedFooterFormat()
  222. {
  223. CXTPPrintPageHeaderFooter::DoInsertHFFormatSpecifierViaMenu(
  224. this, &m_ctrlFooterFormat, &m_ctrlFooterFormatBtn);
  225. }
  226. /////////////////////////////////////////////////////////////////////////////
  227. IMPLEMENT_DYNAMIC(CXTPCalendarControlViewPrintOptions, CXTPPrintOptions)
  228. CXTPCalendarControlViewPrintOptions::CXTPCalendarControlViewPrintOptions()
  229. {
  230. m_dtPrintFrom.SetTime(8, 0, 0);
  231. m_dtPrintTo.SetTime(19, 0, 0);
  232. m_bPrintFromToExactly = TRUE;
  233. LOGFONT lfIcon;
  234. VERIFY( ::SystemParametersInfo( SPI_GETICONTITLELOGFONT, sizeof( lfIcon ), &lfIcon, 0 ) );
  235. m_bPrintDateHeader = TRUE;
  236. m_lfDateHeaderFont = lfIcon;
  237. m_lfDateHeaderFont.lfHeight = -24;
  238. m_lfDateHeaderFont.lfWeight = FW_BOLD;
  239. m_lfDateHeaderWeekDayFont = lfIcon;
  240. m_lfDateHeaderWeekDayFont.lfHeight = -max(abs(lfIcon.lfHeight), abs(m_lfDateHeaderFont.lfHeight*2/3));
  241. m_lfDateHeaderCalendarFont = lfIcon;
  242. }
  243. LCID CXTPCalendarControlViewPrintOptions::GetActiveLCID()
  244. {
  245. return CXTPCalendarUtils::GetActiveLCID();
  246. }
  247. void CXTPCalendarControlViewPrintOptions::Set(const CXTPCalendarControlViewPrintOptions* pSrc)
  248. {
  249. if (!pSrc)
  250. {
  251. return;
  252. }
  253. CXTPPrintOptions::Set(pSrc);
  254. m_dtPrintFrom = pSrc->m_dtPrintFrom;
  255. m_dtPrintTo = pSrc->m_dtPrintTo;
  256. m_bPrintFromToExactly = pSrc->m_bPrintFromToExactly;
  257. m_bPrintDateHeader = pSrc->m_bPrintDateHeader;
  258. m_lfDateHeaderFont = pSrc->m_lfDateHeaderFont;
  259. m_lfDateHeaderCalendarFont = pSrc->m_lfDateHeaderCalendarFont;
  260. }
  261. /////////////////////////////////////////////////////////////////////////////
  262. // CXTPCalendarControlView
  263. IMPLEMENT_DYNCREATE(CXTPCalendarControlView, CView)
  264. CXTPCalendarControlView::CXTPCalendarControlView()
  265. {
  266. m_pCalendar = NULL;
  267. m_pUpdateContect = NULL;
  268. m_bReleaseCalendarWhenDestroy = FALSE;
  269. m_bPrintDirect = FALSE;
  270. m_bResizeControlWithView = TRUE;
  271. m_bShowCaptionBar = FALSE;
  272. m_pScrollBar = NULL;
  273. m_pPrintOptions = new CXTPCalendarControlViewPrintOptions();
  274. }
  275. CXTPCalendarControlView::~CXTPCalendarControlView()
  276. {
  277. if (m_bReleaseCalendarWhenDestroy)
  278. {
  279. CMDTARGET_RELEASE(m_pCalendar);
  280. }
  281. ASSERT(m_pUpdateContect == NULL);
  282. SAFE_DELETE(m_pUpdateContect);
  283. CMDTARGET_RELEASE(m_pPrintOptions);
  284. }
  285. CXTPCalendarControl& CXTPCalendarControlView::GetCalendarCtrl()
  286. {
  287. return m_pCalendar == NULL ? m_wndCalendar : *m_pCalendar;
  288. }
  289. void CXTPCalendarControlView::SetCalendarCtrl(CXTPCalendarControl* pCalendar,
  290.   BOOL bReleaseWhenDestroy)
  291. {
  292. if (::IsWindow(m_wndCalendar.GetSafeHwnd()))
  293. m_wndCalendar.DestroyWindow();
  294. m_pCalendar = pCalendar;
  295. m_bReleaseCalendarWhenDestroy = bReleaseWhenDestroy;
  296. m_Sink.UnadviseAll();
  297. m_Sink.Advise(GetCalendarCtrl().GetConnection(), XTP_NC_CALENDAR_THEME_CHANGED, &CXTPCalendarControlView::OnEvent_CalendarThemeChanged);
  298. _ResizeControls();
  299. }
  300. void CXTPCalendarControlView::SetScrollBarCtrl(CScrollBar* pScrollBar)
  301. {
  302. m_pScrollBar = pScrollBar;
  303. }
  304. BEGIN_MESSAGE_MAP(CXTPCalendarControlView, CView)
  305. //{{AFX_MSG_MAP(CXTPCalendarControlView)
  306. ON_WM_ERASEBKGND()
  307. ON_WM_SIZE()
  308. ON_WM_CREATE()
  309. ON_WM_SETFOCUS()
  310. ON_WM_PAINT()
  311. ON_WM_VSCROLL()
  312. ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  313. ON_BN_CLICKED(ID_EDIT_UNDO, OnUndo)
  314. ON_BN_CLICKED(ID_EDIT_CUT, OnCut)
  315. ON_BN_CLICKED(ID_EDIT_COPY, OnCopy)
  316. ON_BN_CLICKED(ID_EDIT_PASTE, OnPaste)
  317. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateCommand)
  318. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCommand)
  319. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCommand)
  320. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateCommand)
  321. //}}AFX_MSG_MAP
  322. END_MESSAGE_MAP()
  323. /////////////////////////////////////////////////////////////////////////////
  324. // CXTPCalendarControlView drawing
  325. void CXTPCalendarControlView::OnDraw(CDC* /*pDC*/)
  326. {
  327. }
  328. void CXTPCalendarControlView::OnPaint()
  329. {
  330. Default();
  331. }
  332. /////////////////////////////////////////////////////////////////////////////
  333. // CXTPCalendarControlView diagnostics
  334. #ifdef _DEBUG
  335. void CXTPCalendarControlView::AssertValid() const
  336. {
  337. CView::AssertValid();
  338. }
  339. void CXTPCalendarControlView::Dump(CDumpContext& dc) const
  340. {
  341. CView::Dump(dc);
  342. }
  343. #endif //_DEBUG
  344. /////////////////////////////////////////////////////////////////////////////
  345. // CXTPCalendarControlView message handlers
  346. BOOL CXTPCalendarControlView::OnEraseBkgnd(CDC* )
  347. {
  348. return TRUE;
  349. }
  350. CScrollBar* CXTPCalendarControlView::GetScrollBarCtrl(int nBar) const
  351. {
  352. if (nBar == SB_VERT && m_pScrollBar)
  353. return m_pScrollBar;
  354. return CView::GetScrollBarCtrl(nBar);
  355. }
  356. void CXTPCalendarControlView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  357. {
  358. if (m_pScrollBar && pScrollBar == m_pScrollBar)
  359. GetCalendarCtrl().OnVScroll(nSBCode, nPos, 0);
  360. CView::OnVScroll(nSBCode, nPos, pScrollBar);
  361. }
  362. void CXTPCalendarControlView::OnSize(UINT nType, int cx, int cy)
  363. {
  364. CView::OnSize(nType, cx, cy);
  365. if (!m_bResizeControlWithView)
  366. return;
  367. _ResizeControls();
  368. }
  369. void CXTPCalendarControlView::_ResizeControls()
  370. {
  371. if (!m_bResizeControlWithView)
  372. return;
  373. CXTPClientRect rcClient(this);
  374. int cx = rcClient.Width();
  375. int cy = rcClient.Height();
  376. int nCalendarY = 0;
  377. //BOOL bThemeOffice2007 = !!DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, GetCalendarCtrl().GetTheme());
  378. if (m_wndCalendarCaptionBar.GetSafeHwnd())
  379. {
  380. if (m_bShowCaptionBar/* && bThemeOffice2007*/)
  381. {
  382. CRect rcCaptionBar = m_wndCalendarCaptionBar.CalcMinRect(NULL);
  383. nCalendarY = rcCaptionBar.Height();
  384. if ((m_wndCalendarCaptionBar.GetStyle() & WS_VISIBLE) == 0)
  385. {
  386. m_wndCalendarCaptionBar.ShowWindow(SW_SHOW);
  387. m_wndCalendarCaptionBar.GetTheme()->AttachCalendar(&GetCalendarCtrl());
  388. }
  389. }
  390. else
  391. {
  392. if ((m_wndCalendarCaptionBar.GetStyle() & WS_VISIBLE))
  393. {
  394. m_wndCalendarCaptionBar.ShowWindow(SW_HIDE);
  395. m_wndCalendarCaptionBar.GetTheme()->AttachCalendar(NULL);
  396. }
  397. }
  398. m_wndCalendarCaptionBar.MoveWindow(0, 0, cx, nCalendarY);
  399. }
  400. if (m_pScrollBar && m_pScrollBar->GetSafeHwnd())
  401. {
  402. int nScroll = GetSystemMetrics(SM_CXVSCROLL);
  403. m_pScrollBar->MoveWindow(cx - nScroll, nCalendarY, nScroll, cy - nCalendarY);
  404. cx -= nScroll;
  405. }
  406. if (GetCalendarCtrl().GetSafeHwnd())
  407. {
  408. GetCalendarCtrl().MoveWindow(0, nCalendarY, cx, max(0, cy - nCalendarY));
  409. }
  410. }
  411. BOOL CXTPCalendarControlView::IsShowCaptionBar()
  412. {
  413. return m_bShowCaptionBar;
  414. }
  415. void CXTPCalendarControlView::ShowCaptionBar(BOOL bShow)
  416. {
  417. if (m_bShowCaptionBar != bShow)
  418. {
  419. m_bShowCaptionBar = bShow;
  420. _ResizeControls();
  421. if (m_hWnd)
  422. Invalidate(NULL);
  423. }
  424. }
  425. void CXTPCalendarControlView::OnEvent_CalendarThemeChanged(XTP_NOTIFY_CODE Event, WPARAM wParam , LPARAM lParam)
  426. {
  427. UNREFERENCED_PARAMETER(Event);  UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam);
  428. ASSERT(Event == XTP_NC_CALENDAR_THEME_CHANGED);
  429. _ResizeControls();
  430. if (m_hWnd)
  431. Invalidate(NULL);
  432. }
  433. int CXTPCalendarControlView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  434. {
  435. if (CView::OnCreate(lpCreateStruct) == -1)
  436. return -1;
  437. if (!m_wndCalendarCaptionBar.Create(WS_CHILD | WS_TABSTOP/* | WS_VISIBLE*/,
  438.   CRect(0, 0, 0, 0), this, XTP_ID_CALENDARCAPTIONBAR_CONTROL) )
  439. {
  440. TRACE(_T("Failed to create Calendar Caption Bar control windown"));
  441. return -1;
  442. }
  443. if (!GetCalendarCtrl().Create(WS_CHILD | WS_TABSTOP | WS_VISIBLE,
  444.   CRect(0, 0, 0, 0), this, XTP_ID_CALENDAR_CONTROL) )
  445. {
  446. TRACE(_T("Failed to create Calendar control windown"));
  447. return -1;
  448. }
  449. _ResizeControls();
  450. return 0;
  451. }
  452. void CXTPCalendarControlView::OnSetFocus(CWnd* pOldWnd)
  453. {
  454. CView::OnSetFocus(pOldWnd);
  455. GetCalendarCtrl().SetFocus();
  456. }
  457. /////////////////////////////////////////////////////////////////////////////
  458. // CReportSampleView printing
  459. BOOL CXTPCalendarControlView::OnPreparePrinting(CPrintInfo* pInfo)
  460. {
  461. pInfo->m_bDirect = m_bPrintDirect;
  462. pInfo->m_nNumPreviewPages = 1;
  463. pInfo->SetMinPage(1);
  464. pInfo->SetMaxPage(1);
  465. // default preparation
  466. return DoPreparePrinting(pInfo);
  467. }
  468. void CXTPCalendarControlView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  469. {
  470. UNREFERENCED_PARAMETER(pDC);    UNREFERENCED_PARAMETER(pInfo);
  471. m_pritAdjustContext.Reset();
  472. GetCalendarCtrl().EnableSendNotifications(FALSE);
  473. ASSERT(m_pUpdateContect == NULL);
  474. SAFE_DELETE(m_pUpdateContect);
  475. m_pUpdateContect = new CXTPCalendarControl::CUpdateContext(&GetCalendarCtrl(), xtpCalendarUpdateRedraw);
  476. m_beforePrintState.Save(this);
  477. }
  478. void CXTPCalendarControlView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  479. {
  480. m_beforePrintState.Restore(this);
  481. m_beforePrintState.ClearData();
  482. GetCalendarCtrl().AdjustLayout();
  483. GetCalendarCtrl().EnableSendNotifications();
  484. m_pritAdjustContext.Reset();
  485. m_bmpGrayDC.DeleteObject();
  486. ASSERT(m_pUpdateContect);
  487. SAFE_DELETE(m_pUpdateContect);
  488. }
  489. CRect CXTPCalendarControlView::AdjustCalendarForPrint(CDC* pDC, CRect rcCalendar,
  490. CXTPCalendarControlViewPrintOptions* pOptions)
  491. {
  492. //===========================================================================
  493. GetCalendarCtrl().AdjustLayout(pDC, rcCalendar);
  494. //===========================================================================
  495. int nViewType = GetCalendarCtrl().GetActiveView()->GetViewType();
  496. if (nViewType == xtpCalendarDayView || nViewType == xtpCalendarWorkWeekView)
  497. {
  498. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetDayView());
  499. ASSERT(pDayView);
  500. if (!pDayView)
  501. {
  502. return rcCalendar;
  503. }
  504. int dbg_nAdjustSmall = 0;
  505. int dbg_nAdjustScale = 0;
  506. int nHeightNeed_prev = 0;
  507. for (int nLoop = 0; nLoop < 100; nLoop++)
  508. {
  509. int nStartCell = pDayView->GetCellNumber(pOptions->m_dtPrintFrom, FALSE);
  510. int nEndCell = pDayView->GetCellNumber(pOptions->m_dtPrintTo, TRUE);
  511. int nCellCount = nEndCell - nStartCell + 1;
  512. int nCelHeight = pDayView->GetRowHeight();
  513. CRect rcHeader = pDayView->GetDayHeaderRectangle();
  514. CRect rcAllDayArea = pDayView->GetAllDayEventsRectangle();
  515. int nHeightNeed = nCellCount * nCelHeight + rcHeader.Height() +
  516. rcAllDayArea.Height();
  517. if (rcCalendar.Height() >= nHeightNeed)
  518. {
  519. if (!pOptions->m_bPrintFromToExactly)
  520. {
  521. pDayView->_ScrollV(nStartCell, nStartCell);
  522. break;
  523. }
  524. else
  525. {
  526. dbg_nAdjustSmall++;
  527. rcCalendar.bottom = rcCalendar.top + nHeightNeed;
  528. GetCalendarCtrl().AdjustLayout(pDC, rcCalendar);
  529. pDayView->_ScrollV(nStartCell, nStartCell);
  530. if (nHeightNeed_prev == nHeightNeed)
  531. {
  532. //GetCalendarCtrl().AdjustLayout(pDC, rcCalendar);
  533. break;
  534. }
  535. nHeightNeed_prev = nHeightNeed;
  536. }
  537. }
  538. else
  539. {
  540. COleDateTimeSpan spScale = pDayView->GetScaleInterval();
  541. int nScale_min = GETTOTAL_MINUTES_DTS(spScale);
  542. if (nScale_min < 60)
  543. {
  544. dbg_nAdjustScale++;
  545. //int arIntervals[] = {5, 10, 15, 30, 60, 120, 150, 180};
  546. int arIntervals[] = {5, 10, 15, 30, 60};
  547. for (int i = 0; i < _countof(arIntervals); i++)
  548. {
  549. if (arIntervals[i] > nScale_min)
  550. {
  551. spScale = CXTPCalendarUtils::Minutes2Span(arIntervals[i]);
  552. break;
  553. }
  554. }
  555. pDayView->SetScaleInterval(spScale);
  556. GetCalendarCtrl().AdjustLayout(pDC, rcCalendar);
  557. }
  558. else
  559. {
  560. break;
  561. }
  562. }
  563. }
  564. GetCalendarCtrl().AdjustLayout(pDC, rcCalendar);
  565. //TRACE(_T("DBG. Calendar, PrePrintAdjust Counts: Scale = %d, small = %d, All Loops (max 100)= %d n"),
  566. //  dbg_nAdjustScale, dbg_nAdjustSmall, nLoop+1);
  567. }
  568. return rcCalendar;
  569. }
  570. void CXTPCalendarControlView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  571. {
  572. if (!m_pPrintOptions || !pDC || !pInfo)
  573. {
  574. ASSERT(FALSE);
  575. return;
  576. }
  577. CRect rcMargins = m_pPrintOptions->GetMarginsLP(pDC);
  578. CRect rcPrint = pInfo->m_rectDraw;
  579. rcPrint.DeflateRect(rcMargins);
  580. //----------------------------------------------------------
  581. if (!m_pPrintOptions->m_bBlackWhitePrinting)
  582. {
  583. _OnPrint2(pDC, pInfo, rcPrint);
  584. }
  585. else
  586. {
  587. CRect rcPrint00(0, 0, rcPrint.Width(), rcPrint.Height());
  588. CDC memDC;
  589. VERIFY(memDC.CreateCompatibleDC(pDC));
  590. memDC.m_bPrinting = TRUE;
  591. if (!m_bmpGrayDC.m_hObject || m_bmpGrayDC.GetBitmapDimension() != rcPrint00.Size())
  592. {
  593. m_bmpGrayDC.DeleteObject();
  594. m_bmpGrayDC.CreateCompatibleBitmap(pDC, rcPrint00.Width(), rcPrint00.Height());
  595. }
  596. CXTPBitmapDC autpBmp(&memDC, &m_bmpGrayDC);
  597. //----------------------------------------------------
  598. memDC.FillSolidRect(rcPrint00, RGB(255, 255, 255));
  599. _OnPrint2(&memDC, pInfo, rcPrint00);
  600. int nCC = max(0, min(m_pPrintOptions->m_nBlackWhiteContrast, 255));
  601. XTPImageManager()->BlackWhiteBitmap(memDC, rcPrint00, nCC);
  602. pDC->BitBlt(rcPrint.left, rcPrint.top, rcPrint.Width(), rcPrint.Height(),
  603. &memDC, 0, 0, SRCCOPY);
  604. }
  605. }
  606. void CXTPCalendarControlView::_OnPrint2(CDC* pDC, CPrintInfo* pInfo, CRect rcPrint)
  607. {
  608. UNREFERENCED_PARAMETER(pInfo);
  609. m_pritAdjustContext.m_rcHeader = rcPrint;
  610. m_pritAdjustContext.m_rcFooter = rcPrint;
  611. CString strTitle = CXTPPrintPageHeaderFooter::GetParentFrameTitle(this);
  612. m_pPrintOptions->GetPageHeader()->FormatTexts(pInfo, strTitle);
  613. m_pPrintOptions->GetPageFooter()->FormatTexts(pInfo, strTitle);
  614. m_pPrintOptions->GetPageFooter()->Draw(pDC, m_pritAdjustContext.m_rcFooter, TRUE);
  615. m_pPrintOptions->GetPageHeader()->Draw(pDC, m_pritAdjustContext.m_rcHeader);
  616. rcPrint.top += m_pritAdjustContext.m_rcHeader.Height();
  617. rcPrint.bottom -= m_pritAdjustContext.m_rcFooter.Height();
  618. //-----------------------------------------------------------------------
  619. CRect rcCalendar = rcPrint;
  620. if (m_pPrintOptions->m_bPrintDateHeader)
  621. {
  622. m_pritAdjustContext.m_rcDateHeader = rcPrint;
  623. DrawDateHeader(FALSE, pDC, m_pPrintOptions, m_pritAdjustContext.m_rcDateHeader);
  624. rcCalendar.top = m_pritAdjustContext.m_rcDateHeader.bottom + 2;
  625. }
  626. rcCalendar.DeflateRect(2, 2, 2, 2);
  627. if (m_pritAdjustContext.m_bAdjust ||
  628. m_pritAdjustContext.m_rectDraw_prev != rcCalendar)
  629. {
  630. m_pritAdjustContext.m_rcCalendar = AdjustCalendarForPrint(pDC, rcCalendar, m_pPrintOptions);
  631. m_pritAdjustContext.m_rectDraw_prev = rcCalendar;
  632. m_pritAdjustContext.m_bAdjust = FALSE;
  633. }
  634. //===========================================================================
  635. pDC->IntersectClipRect(&m_pritAdjustContext.m_rcCalendar);
  636. //************************************************************************
  637. GetCalendarCtrl().OnDraw(pDC);
  638. //************************************************************************
  639. pDC->SelectClipRgn(NULL);
  640. CRect rcBorder = m_pritAdjustContext.m_rcCalendar;
  641. rcBorder.InflateRect(1, 1, 1, 1);
  642. pDC->Draw3dRect(&rcBorder, 0, 0);
  643. rcBorder.InflateRect(1, 1, 1, 1);
  644. pDC->Draw3dRect(&rcBorder, 0, 0);
  645. m_pPrintOptions->GetPageFooter()->Draw(pDC, m_pritAdjustContext.m_rcFooter);
  646. }
  647. void CXTPCalendarControlView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  648. {
  649. UNREFERENCED_PARAMETER(pInfo);
  650. ASSERT_VALID(this);
  651. ASSERT_VALID(pDC);
  652. ASSERT(pInfo != NULL);  // overriding OnPaint -- never get this.
  653. pDC->SetMapMode(MM_ANISOTROPIC);
  654. pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
  655. pDC->GetDeviceCaps(LOGPIXELSY));
  656. pDC->SetWindowExt(100, 100);
  657. // ptOrg is in logical coordinates
  658. pDC->OffsetWindowOrg(0, 0);
  659. }
  660. void CXTPCalendarControlView::DrawDateHeader(BOOL bCalculate, CDC* pDC,
  661. CXTPCalendarControlViewPrintOptions* pOptions,
  662. CRect& rrcHeader)
  663. {
  664. COleDateTime dtYearMonth1, dtYearMonth2;
  665. CString strHeader1, strHeader2, strHeaderWeekDay;
  666. int nMonths = _GetDateHeaderMonths(dtYearMonth1, dtYearMonth2, strHeader1,
  667.    strHeader2, strHeaderWeekDay);
  668. if (!strHeader2.IsEmpty())
  669. {
  670. strHeader1 += _T(" -");
  671. }
  672. CRect rcCalendar1 = rrcHeader;
  673. CRect rcCalendar2(0, 0, 0, 0);
  674. _DrawDateHeaderCalendar(TRUE, pDC, pOptions, dtYearMonth1, rcCalendar1);
  675. int nCalendar1XPos = rrcHeader.right - rcCalendar1.Width() * 11/10;
  676. int nCalendar2XPos = nCalendar1XPos;
  677. CFont fntDateHeader;
  678. VERIFY( fntDateHeader.CreateFontIndirect(&pOptions->m_lfDateHeaderFont) );
  679. CXTPFontDC fntDC(pDC, &fntDateHeader);
  680. CSize sizeText = pDC->GetTextExtent(strHeader1);
  681. CFont fntDateHeaderWeekDay;
  682. VERIFY( fntDateHeaderWeekDay.CreateFontIndirect(&pOptions->m_lfDateHeaderWeekDayFont) );
  683. fntDC.SetFont(&fntDateHeaderWeekDay);
  684. CSize sizeTextWD = pDC->GetTextExtent(_T("WD"), 2);
  685. int nDatesCaptionHeight = sizeText.cy * 225/100 + sizeTextWD.cy * 125/100;
  686. int nMaxHeight = max(rcCalendar1.Height() * 11/10, nDatesCaptionHeight);
  687. rrcHeader.bottom = rrcHeader.top + nMaxHeight;
  688. int nCalendarYPos = rrcHeader.top + nMaxHeight/2 - rcCalendar1.Height() / 2;
  689. MoveRectToXY(rcCalendar1, nCalendar1XPos, nCalendarYPos);
  690. if (bCalculate)
  691. {
  692. return;
  693. }
  694. //===========================================================================
  695. COLORREF clrPrev = pDC->SetTextColor(0);
  696. int nBkModePrev = pDC->SetBkMode(TRANSPARENT);
  697. //---------------------------------------------------------------------------
  698. if (nMonths > 1)
  699. {
  700. rcCalendar2 = rcCalendar1;
  701. nCalendar2XPos = nCalendar1XPos - rcCalendar1.Width() * 11 / 10;
  702. MoveRectToXY(rcCalendar1, nCalendar2XPos, nCalendarYPos);
  703. }
  704. if (!m_pPrintOptions->m_bBlackWhitePrinting)
  705. pDC->FillSolidRect(&rrcHeader, RGB(229, 229, 229));
  706. pDC->Draw3dRect(&rrcHeader, 0, 0);
  707. _DrawDateHeaderCalendar(FALSE, pDC, pOptions, dtYearMonth1, rcCalendar1);
  708. if (nMonths > 1)
  709. {
  710. _DrawDateHeaderCalendar(FALSE, pDC, pOptions, dtYearMonth2, rcCalendar2);
  711. }
  712. CRect rcHeader1(0, 0, 0, 0);
  713. CRect rcHeader2(0, 0, 0, 0);
  714. CRect rcHeader3(0, 0, 0, 0);
  715. rcHeader1 = rrcHeader;
  716. rcHeader1.DeflateRect(10, 5, 10, 5);
  717. rcHeader1.right = nCalendar2XPos - 20;
  718. rcHeader2 = rcHeader1;
  719. fntDC.SetFont(&fntDateHeader);
  720. UINT uDrawFlags = DT_TOP | DT_LEFT | DT_WORDBREAK | DT_NOPREFIX;
  721. int nHeight1 = pDC->DrawText(strHeader1, &rcHeader1, uDrawFlags);
  722. if (!strHeader2.IsEmpty())
  723. {
  724. rcHeader2.top += nHeight1 + sizeText.cy / 4;
  725. if (rcHeader2.top < rcHeader2.bottom)
  726. {
  727. pDC->DrawText(strHeader2, &rcHeader2, uDrawFlags);
  728. }
  729. }
  730. if (!strHeaderWeekDay.IsEmpty())
  731. {
  732. fntDC.SetFont(&fntDateHeaderWeekDay);
  733. rcHeader3 = rcHeader2;
  734. rcHeader3.top += nHeight1 + sizeTextWD.cy / 5;
  735. if (rcHeader3.top < rcHeader3.bottom)
  736. {
  737. pDC->DrawText(strHeaderWeekDay, &rcHeader3, uDrawFlags);
  738. }
  739. }
  740. //---------------------------------------------------------------------------
  741. pDC->SetTextColor(clrPrev);
  742. pDC->SetBkMode(nBkModePrev);
  743. }
  744. void CXTPCalendarControlView::_DrawDateHeaderCalendar(BOOL bCalculate,
  745. CDC* pDC,
  746. CXTPCalendarControlViewPrintOptions* pOptions,
  747. COleDateTime dtYearMonth,
  748. CRect& rrcHeaderCalendar)
  749. {
  750. LOGFONT lfCalWeek = pOptions->m_lfDateHeaderCalendarFont;
  751. lfCalWeek.lfHeight = lfCalWeek.lfHeight * 8 / 10;
  752. CFont fntCalendarWeek;
  753. VERIFY( fntCalendarWeek.CreateFontIndirect(&lfCalWeek) );
  754. CFont fntCalendar;
  755. VERIFY( fntCalendar.CreateFontIndirect(&pOptions->m_lfDateHeaderCalendarFont) );
  756. CXTPFontDC fntDC(pDC, &fntCalendar);
  757. CSize sizeCellText = pDC->GetTextExtent(_T("88"), 2);
  758. CSize sizeCell = sizeCellText;
  759. sizeCell.cx = sizeCell.cx * 13 / 10;
  760. sizeCell.cy = sizeCell.cy * 11 / 10;
  761. int nMonthRowY = sizeCellText.cy;
  762. int nWSaysRowY = sizeCellText.cy * 13 / 10;
  763. rrcHeaderCalendar.right = rrcHeaderCalendar.left + sizeCell.cx * 9;
  764. rrcHeaderCalendar.bottom = rrcHeaderCalendar.top + nMonthRowY + nWSaysRowY
  765. + sizeCell.cy * 6;
  766. if (bCalculate)
  767. {
  768. return;
  769. }
  770. int nFirstDayOfWeek = GetCalendarCtrl().GetFirstDayOfWeek();
  771. COleDateTime dtMonthFirst = dtYearMonth;
  772. VERIFY( CXTPCalendarUtils::UpdateMonthDay(dtMonthFirst, 1) );
  773. int nMaxMonthDay = CXTPCalendarUtils::GetMaxMonthDay(dtYearMonth);
  774. CStringArray arWDNames;
  775. int i;
  776. for (i = 0; i < 7; i++)
  777. {
  778. CString sWD = CXTPCalendarUtils::GetLocaleString(LOCALE_SABBREVDAYNAME1 + ((i-1+7)%7), 100);
  779. arWDNames.Add(sWD);
  780. }
  781. int nMonth = dtYearMonth.GetMonth();
  782. int nYear = dtYearMonth.GetYear();
  783. CString strMonthName = CXTPCalendarUtils::GetLocaleString(LOCALE_SMONTHNAME1 + nMonth - 1, 100);
  784. CString strMonthYear;
  785. strMonthYear.Format(_T("%s  %d"), (LPCTSTR)strMonthName, nYear);
  786. //===========================================================================
  787. COLORREF clrPrev = pDC->SetTextColor(0);
  788. int nBkModePrev = pDC->SetBkMode(TRANSPARENT);
  789. //---------------------------------------------------------------------------
  790. CRect rcText = rrcHeaderCalendar;
  791. rcText.left += sizeCell.cx;
  792. pDC->DrawText(strMonthYear, &rcText, DT_TOP | DT_CENTER | DT_SINGLELINE);
  793. rcText = rrcHeaderCalendar;
  794. rcText.top += sizeCell.cy;
  795. for (i = 0; i < 7; i++)
  796. {
  797. rcText.left += sizeCell.cx;
  798. rcText.right = rcText.left + sizeCell.cx;
  799. int nMidx = (nFirstDayOfWeek-1+i) % 7;
  800. CString strWD = arWDNames[nMidx];
  801. pDC->DrawText((LPCTSTR)strWD, 1, &rcText, DT_TOP | DT_RIGHT | DT_SINGLELINE);
  802. }
  803. CRect rcLine1 = rrcHeaderCalendar;
  804. rcLine1.left += sizeCell.cx - 0;
  805. rcLine1.top += nMonthRowY + nWSaysRowY - 1;
  806. rcLine1.bottom = rcLine1.top + 1;
  807. CRect rcLine2 = rrcHeaderCalendar;
  808. rcLine2.left = rcLine1.left;
  809. rcLine2.right = rcLine2.left + 1;
  810. rcLine2.top = rcLine1.top;
  811. pDC->FillSolidRect(&rcLine1, 0);
  812. pDC->FillSolidRect(&rcLine2, 0);
  813. int nDay = 1 - (dtMonthFirst.GetDayOfWeek() - nFirstDayOfWeek + 7) % 7;
  814. int nFirstWeekOfYearDays = 1;
  815. COleDateTimeSpan spFWofY(nFirstWeekOfYearDays - 1);
  816. COleDateTime dtWeekLast = dtMonthFirst + COleDateTimeSpan(nDay+6-1);
  817. int nFirstWeekNumber = ((dtWeekLast - spFWofY).GetDayOfYear() - 1) / 7 + 1;
  818. //--------------------------
  819. int nTodayDay_toMark = 0;
  820. COleDateTime dtToday = CXTPCalendarUtils::GetCurrentTime();
  821. if (dtYearMonth.GetYear() == dtToday.GetYear() &&
  822. dtYearMonth.GetMonth() == dtToday.GetMonth())
  823. {
  824. nTodayDay_toMark = dtToday.GetDay();
  825. }
  826. CString strDay, strWeek;
  827. for (int w = 0; w < 6; w++)
  828. {
  829. rcText.top = rrcHeaderCalendar.top + nMonthRowY + nWSaysRowY + sizeCell.cy * w;
  830. if (nDay <= nMaxMonthDay)
  831. {
  832. CRect rcWeek = rcText;
  833. rcWeek.left = rrcHeaderCalendar.left;
  834. rcWeek.right = rcWeek.left + sizeCell.cx - 2;
  835. strWeek.Format(_T("%d"), nFirstWeekNumber + w);
  836. CXTPFontDC fntDCweek(pDC, &fntCalendarWeek);
  837. pDC->DrawText(strWeek, &rcWeek, DT_TOP | DT_RIGHT | DT_SINGLELINE);
  838. }
  839. //--------------------------------------------------------------------
  840. for (i = 0; i < 7; i++)
  841. {
  842. if (nDay > 0 && nDay <= nMaxMonthDay)
  843. {
  844. rcText.left = rrcHeaderCalendar.left + sizeCell.cx * (i + 1);
  845. rcText.right = rcText.left + sizeCell.cx;
  846. strDay.Format(_T("%d"), nDay);
  847. pDC->DrawText(strDay, &rcText, DT_TOP | DT_RIGHT | DT_SINGLELINE);
  848. if (nDay == nTodayDay_toMark)
  849. {
  850. CRect rcToday = rcText;
  851. rcToday.left += max(1, sizeCell.cx/10);
  852. rcToday.right += max(1, sizeCell.cx/10);
  853. rcToday.bottom = rcToday.top + sizeCell.cy;
  854. CBrush brFrame(RGB(82, 82, 82));
  855. pDC->FrameRect(&rcToday, &brFrame);
  856. }
  857. }
  858. nDay++;
  859. }
  860. }
  861. //---------------------------------------------------------------------------
  862. pDC->SetTextColor(clrPrev);
  863. pDC->SetBkMode(nBkModePrev);
  864. }
  865. int CXTPCalendarControlView::_GetDateHeaderMonths(COleDateTime& dtYearMonth1, COleDateTime& dtYearMonth2,
  866.   CString& strHeader1, CString& strHeader2,
  867.   CString& strHeaderWeekDay)
  868. {
  869. strHeader1 = strHeader2 = strHeaderWeekDay = _T("");
  870. dtYearMonth1 = dtYearMonth2 = (DATE)0;
  871. SYSTEMTIME st;
  872. int nViewType = GetCalendarCtrl().GetActiveView()->GetViewType();
  873. if (nViewType == xtpCalendarDayView ||
  874. nViewType == xtpCalendarWorkWeekView || nViewType == xtpCalendarFullWeekView)
  875. {
  876. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl().GetDayView());
  877. ASSERT(pDayView);
  878. if (!pDayView)
  879. {
  880. return 0;
  881. }
  882. dtYearMonth1 = pDayView->GetViewDayDate(0);
  883. GETASSYSTEMTIME_DT(dtYearMonth1, st);
  884. strHeader1 = CXTPCalendarUtils::GetDateFormat(&st, _T("d MMMM"));
  885. int nCount = pDayView->GetViewDayCount();
  886. if (nCount > 1)
  887. {
  888. dtYearMonth2 = pDayView->GetViewDayDate(nCount-1);
  889. GETASSYSTEMTIME_DT(dtYearMonth2, st);
  890. strHeader2 = CXTPCalendarUtils::GetDateFormat(&st, _T("d MMMM"));
  891. if (dtYearMonth1.GetMonth() != dtYearMonth2.GetMonth())
  892. {
  893. return 2;
  894. }
  895. }
  896. if (nCount == 1)
  897. {
  898. COleDateTime dtDay0 = pDayView->GetViewDayDate(0);
  899. int nWd = dtDay0.GetDayOfWeek();
  900. int nWdShift = (nWd-1 + 6)%7;
  901. strHeaderWeekDay = CXTPCalendarUtils::GetLocaleString(LOCALE_SDAYNAME1 + nWdShift, 100);
  902. }
  903. return 1;
  904. }
  905. else if (nViewType == xtpCalendarWeekView)
  906. {
  907. CXTPCalendarView* pView = GetCalendarCtrl().GetActiveView();
  908. ASSERT(pView);
  909. if (!pView)
  910. {
  911. return 0;
  912. }
  913. dtYearMonth1 = pView->GetViewDayDate(0);
  914. dtYearMonth2 = pView->GetViewDayDate(pView->GetViewDayCount()-1);
  915. CString strHeaderFormat = pView->GetDayHeaderFormat();
  916. GETASSYSTEMTIME_DT(dtYearMonth1, st);
  917. strHeader1 = CXTPCalendarUtils::GetDateFormat(&st, strHeaderFormat);
  918. GETASSYSTEMTIME_DT(dtYearMonth2, st);
  919. strHeader2 = CXTPCalendarUtils::GetDateFormat(&st, strHeaderFormat);
  920. return 1;
  921. }
  922. else if (nViewType == xtpCalendarMonthView)
  923. {
  924. CXTPCalendarMonthView* pMonthView = DYNAMIC_DOWNCAST(CXTPCalendarMonthView, GetCalendarCtrl().GetMonthView());
  925. if (!pMonthView || !pMonthView->GetGrid())
  926. {
  927. ASSERT(FALSE);
  928. return 0;
  929. }
  930. int nWeeksCount = pMonthView->GetGrid()->GetWeeksCount();
  931. ASSERT(nWeeksCount);
  932. if (nWeeksCount)
  933. {
  934. CXTPCalendarMonthViewDay* pMVday1 = pMonthView->GetGrid()->GetViewDay(0, 6);
  935. CXTPCalendarMonthViewDay* pMVday2 = pMonthView->GetGrid()->GetViewDay(nWeeksCount-1, 0);
  936. if (pMVday1 && pMVday2)
  937. {
  938. dtYearMonth1 = pMVday1->GetDayDate();
  939. GETASSYSTEMTIME_DT(dtYearMonth1, st);
  940. strHeader1 = CXTPCalendarUtils::GetDateFormat(&st, _T("MMMM yyyy"));
  941. COleDateTime dtLast = pMVday2->GetDayDate();
  942. if (dtYearMonth1.GetMonth() != dtLast.GetMonth())
  943. {
  944. dtYearMonth2 = dtLast;
  945. GETASSYSTEMTIME_DT(dtYearMonth2, st);
  946. strHeader2 = CXTPCalendarUtils::GetDateFormat(&st, _T("MMMM yyyy"));
  947. return 2;
  948. }
  949. return 1;
  950. }
  951. }
  952. }
  953. else
  954. {
  955. ASSERT(FALSE);
  956. }
  957. return 0;
  958. }
  959. CRect CXTPCalendarControlView::_HimetricToLP(CDC* pDC, const CRect rcHimetric)
  960. {
  961. CSize szLT(rcHimetric.left, rcHimetric.top);
  962. CSize szRB(rcHimetric.right, rcHimetric.bottom);
  963. pDC->HIMETRICtoLP(&szLT);
  964. pDC->HIMETRICtoLP(&szRB);
  965. CRect rcLP(szLT.cx, szLT.cy, szRB.cx, szRB.cy);
  966. return rcLP;
  967. }
  968. //////////////////////////////////////////////////////////////////////////
  969. // Clipboard operations
  970. void CXTPCalendarControlView::OnUndo()
  971. {
  972. GetCalendarCtrl().OnUndo();
  973. }
  974. void CXTPCalendarControlView::OnCut()
  975. {
  976. CWnd* pFocusWnd = GetFocus();
  977. if (pFocusWnd)
  978. {
  979. LRESULT lRes = pFocusWnd->SendMessage(WM_COMMAND, ID_EDIT_CUT, NULL);
  980. if (!lRes)
  981. {
  982. pFocusWnd->SendMessage(WM_CUT);
  983. }
  984. }
  985. }
  986. void CXTPCalendarControlView::OnCopy()
  987. {
  988. CWnd* pFocusWnd = GetFocus();
  989. if (pFocusWnd)
  990. {
  991. LRESULT lRes = pFocusWnd->SendMessage(WM_COMMAND, ID_EDIT_COPY, NULL);
  992. if (!lRes)
  993. {
  994. pFocusWnd->SendMessage(WM_COPY);
  995. }
  996. }
  997. }
  998. void CXTPCalendarControlView::OnPaste()
  999. {
  1000. CWnd* pFocusWnd = GetFocus();
  1001. if (pFocusWnd)
  1002. {
  1003. LRESULT lRes = pFocusWnd->SendMessage(WM_COMMAND, ID_EDIT_PASTE, NULL);
  1004. if (!lRes)
  1005. {
  1006. pFocusWnd->SendMessage(WM_PASTE);
  1007. }
  1008. }
  1009. }
  1010. void CXTPCalendarControlView::OnUpdateCommand(CCmdUI* pCmdUI)
  1011. {
  1012. GetCalendarCtrl().OnUpdateCmdUI(pCmdUI);
  1013. }
  1014. void CXTPCalendarControlView::OnFilePageSetup()
  1015. {
  1016. DWORD dwFlags = PSD_MARGINS | PSD_INWININIINTLMEASURE;
  1017. CXTPCalendarPageSetupDialog dlgPageSetup(GetPrintOptions(), dwFlags, this);
  1018. XTPGetPrinterDeviceDefaults(dlgPageSetup.m_psd.hDevMode, dlgPageSetup.m_psd.hDevNames);
  1019. int nDlgRes = (int)dlgPageSetup.DoModal();
  1020. if (nDlgRes == IDOK)
  1021. {
  1022. AfxGetApp()->SelectPrinter(dlgPageSetup.m_psd.hDevNames, dlgPageSetup.m_psd.hDevMode, FALSE);
  1023. }
  1024. }