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

对话框与窗口

开发平台:

Visual C++

  1. // MessageRecord.cpp: implementation of the CMessageRecord 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 "ReportSample.h"
  22. #include "MessageRecord.h"
  23. #include "ReportSampleView.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. IMPLEMENT_SERIAL(CMessageRecord, CXTPReportRecord, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  30. IMPLEMENT_SERIAL(CMessageRecordItemPrice, CXTPReportRecordItemNumber, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  31. IMPLEMENT_SERIAL(CMessageRecordItemCheck, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  32. IMPLEMENT_SERIAL(CMessageRecordItemImportance, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  33. IMPLEMENT_SERIAL(CMessageRecordItemAttachment, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  34. IMPLEMENT_SERIAL(CMessageRecordItemIcon, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  35. IMPLEMENT_SERIAL(CMessageRecordItemDate, CXTPReportRecordItemDateTime, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  36. //////////////////////////////////////////////////////////////////////////
  37. // CMessageRecordItemPrice
  38. CMessageRecordItemPrice::CMessageRecordItemPrice(double dValue)
  39. : CXTPReportRecordItemNumber(dValue, _T("$ %.2f"))
  40. {
  41. }
  42. CString CMessageRecordItemPrice::GetGroupCaption(CXTPReportColumn* /*pColumn*/)
  43. {
  44. if (m_dValue > 20)
  45. return _T("Record Price > 20");
  46. if (m_dValue > 5)
  47. return _T("Record Price 5 - 20");
  48. return _T("Record Price < 5");
  49. }
  50. int CMessageRecordItemPrice::CompareGroupCaption(CXTPReportColumn* pColumn, CXTPReportRecordItem* pItem)
  51. {
  52. return GetGroupCaption(pColumn).Compare(pItem->GetGroupCaption(pColumn));
  53. }
  54. //////////////////////////////////////////////////////////////////////////
  55. // CMessageRecordItemCheck
  56. CMessageRecordItemCheck::CMessageRecordItemCheck(BOOL bCheck)
  57. {
  58. HasCheckbox(TRUE);
  59. SetChecked(bCheck);
  60. }
  61. int CMessageRecordItemCheck::GetGroupCaptionID(CXTPReportColumn* /*pColumn*/)
  62. {
  63. return IsChecked()? IDS_GROUP_CHECKED_TRUE: IDS_GROUP_CHECKED_FALSE;
  64. }
  65. int CMessageRecordItemCheck::Compare(CXTPReportColumn* /*pColumn*/, CXTPReportRecordItem* pItem)
  66. {
  67. return int(IsChecked()) - int(pItem->IsChecked());
  68. }
  69. //////////////////////////////////////////////////////////////////////////
  70. // CMessageRecordItemImportance
  71. CMessageRecordItemImportance::CMessageRecordItemImportance(MESSAGE_IMPORTANCE eImportance)
  72. : m_eImportance(eImportance)
  73. {
  74. SetIconIndex(eImportance == msgImportanceHigh ? 6 :
  75.  eImportance == msgImportanceLow ? 9: -1);
  76. SetGroupPriority(
  77. m_eImportance == msgImportanceHigh? IDS_GROUP_IMPOPRTANCE_HIGH:
  78. m_eImportance == msgImportanceLow?  IDS_GROUP_IMPOPRTANCE_LOW: IDS_GROUP_IMPOPRTANCE_NORMAL);
  79. SetSortPriority(GetGroupPriority());
  80. CString strToolTip;
  81. strToolTip.LoadString(GetGroupPriority());
  82. SetTooltip(strToolTip);
  83. }
  84. void CMessageRecordItemImportance::DoPropExchange(CXTPPropExchange* pPX)
  85. {
  86. CXTPReportRecordItem::DoPropExchange(pPX);
  87. PX_Enum(pPX, _T("Importance"), m_eImportance, msgImportanceNormal);
  88. }
  89. //////////////////////////////////////////////////////////////////////////
  90. // CMessageRecordItemAttachment
  91. CMessageRecordItemAttachment::CMessageRecordItemAttachment(BOOL bHasAttachment)
  92. : m_bHasAttachment(bHasAttachment)
  93. {
  94. SetIconIndex(bHasAttachment ? 8 : -1);
  95. SetGroupPriority(m_bHasAttachment? IDS_GROUP_ATTACHMENTS_TRUE: IDS_GROUP_ATTACHMENTS_FALSE);
  96. SetSortPriority(GetGroupPriority());
  97. }
  98. void CMessageRecordItemAttachment::DoPropExchange(CXTPPropExchange* pPX)
  99. {
  100. CXTPReportRecordItem::DoPropExchange(pPX);
  101. PX_Bool(pPX, _T("HasAttachment"), m_bHasAttachment);
  102. }
  103. //////////////////////////////////////////////////////////////////////////
  104. // CMessageRecordItemIcon
  105. CMessageRecordItemIcon::CMessageRecordItemIcon(BOOL bRead)
  106. : m_bRead(bRead)
  107. {
  108. UpdateReadIcon();
  109. }
  110. void CMessageRecordItemIcon::UpdateReadIcon()
  111. {
  112. SetIconIndex(m_bRead ? 4 : 3);
  113. }
  114. int CMessageRecordItemIcon::Compare(CXTPReportColumn* /*pColumn*/, CXTPReportRecordItem* pItem)
  115. {
  116. return int(m_bRead) - int(((CMessageRecordItemIcon*)pItem)->m_bRead);
  117. }
  118. CString CMessageRecordItemIcon::GetGroupCaption(CXTPReportColumn* /*pColumn*/)
  119. {
  120. if (m_bRead)
  121. return _T("Message status: Read");
  122. else
  123. return _T("Message status: Unread");
  124. }
  125. int CMessageRecordItemIcon::CompareGroupCaption(CXTPReportColumn* pColumn, CXTPReportRecordItem* pItem)
  126. {
  127. return GetGroupCaption(pColumn).Compare(pItem->GetGroupCaption(pColumn));
  128. }
  129. void CMessageRecordItemIcon::DoPropExchange(CXTPPropExchange* pPX)
  130. {
  131. CXTPReportRecordItem::DoPropExchange(pPX);
  132. PX_Bool(pPX, _T("Read"), m_bRead);
  133. }
  134. //////////////////////////////////////////////////////////////////////////
  135. // CMessageRecordItemSent
  136. CMessageRecordItemDate::CMessageRecordItemDate(COleDateTime odtValue)
  137. : CXTPReportRecordItemDateTime(odtValue)
  138. {
  139. }
  140. int CMessageRecordItemDate::GetGroupCaptionID(CXTPReportColumn* /*pColumn*/)
  141. {
  142. COleDateTime odtNow(COleDateTime::GetCurrentTime());
  143. if (m_odtValue.GetYear() < odtNow.GetYear())
  144. return IDS_GROUP_DATE_OLDER;
  145. if (m_odtValue.GetMonth() < odtNow.GetMonth())
  146. return IDS_GROUP_DATE_THISYEAR;
  147. if (m_odtValue.GetDay() < odtNow.GetDay())
  148. return IDS_GROUP_DATE_THISMONTH;
  149. if (m_odtValue.m_dt <= odtNow.m_dt)
  150. return IDS_GROUP_DATE_TODAY;
  151. return -1;
  152. }
  153. //////////////////////////////////////////////////////////////////////
  154. // CMessageRecord class
  155. //////////////////////////////////////////////////////////////////////
  156. // Construction/Destruction
  157. //////////////////////////////////////////////////////////////////////
  158. CMessageRecord::CMessageRecord()
  159. {
  160. m_pItemIcon = NULL;
  161. m_pItemReceived = NULL;
  162. m_pItemSize = NULL;
  163. CreateItems();
  164. }
  165. CMessageRecord::CMessageRecord(
  166. MESSAGE_IMPORTANCE eImportance, BOOL bChecked, int  nAttachmentBitmap,
  167. CString strFromName, CString strSubject,
  168. COleDateTime odtReceived, int nMessageSize, BOOL bRead,
  169. double dPrice, COleDateTime odtSent, COleDateTime odtCreated,
  170. CString strConversation, CString strContact, CString strMessage,
  171. CString strCC, CString strCategories, CString strAutoforward,
  172. CString strDoNotAutoarch, CString strDueBy,
  173. CString strPreview)
  174. {
  175. AddItem(new CMessageRecordItemImportance(eImportance));
  176. m_pItemIcon = (CMessageRecordItemIcon*)AddItem(new CMessageRecordItemIcon(bRead));
  177. AddItem(new CMessageRecordItemAttachment(nAttachmentBitmap));
  178. AddItem(new CXTPReportRecordItemText(strFromName));
  179. AddItem(new CXTPReportRecordItemText(strSubject));
  180. m_pItemReceived = (CMessageRecordItemDate*)AddItem(new CMessageRecordItemDate(odtReceived));
  181. m_pItemSize = AddItem(new CXTPReportRecordItemNumber(nMessageSize));
  182. AddItem(new CMessageRecordItemCheck(bChecked));
  183. AddItem(new CMessageRecordItemPrice(dPrice));
  184. AddItem(new CMessageRecordItemDate(odtCreated));
  185. AddItem(new CMessageRecordItemDate(odtSent));
  186. AddItem(new CXTPReportRecordItemText(strConversation));
  187. AddItem(new CXTPReportRecordItemText(strContact));
  188. AddItem(new CXTPReportRecordItemText(strMessage));
  189. AddItem(new CXTPReportRecordItemText(strCC));
  190. AddItem(new CXTPReportRecordItemText(strCategories));
  191. AddItem(new CXTPReportRecordItemText(strAutoforward));
  192. AddItem(new CXTPReportRecordItemText(strDoNotAutoarch));
  193. AddItem(new CXTPReportRecordItemText(strDueBy));
  194. SetPreviewItem(new CXTPReportRecordItemPreview(strPreview));
  195. }
  196. void CMessageRecord::CreateItems()
  197. {
  198. // Initialize record items with empty values
  199. COleDateTime dtNow(COleDateTime::GetCurrentTime());
  200. // 0 
  201. AddItem(new CMessageRecordItemImportance(msgImportanceNormal));
  202. // 1 ***
  203. m_pItemIcon = (CMessageRecordItemIcon*)AddItem(new CMessageRecordItemIcon(TRUE));
  204. // 2 
  205. AddItem(new CMessageRecordItemAttachment(0));
  206. // 3 
  207. AddItem(new CXTPReportRecordItemText(_T("")));
  208. // 4 
  209. AddItem(new CXTPReportRecordItemText(_T("")));
  210. // 5 ***
  211. m_pItemReceived = (CMessageRecordItemDate*)AddItem(new CMessageRecordItemDate(dtNow));
  212. // 6 ***
  213. m_pItemSize = AddItem(new CXTPReportRecordItemNumber(0));
  214. AddItem(new CMessageRecordItemCheck(FALSE));
  215. AddItem(new CMessageRecordItemPrice(0));
  216. AddItem(new CMessageRecordItemDate(dtNow));
  217. AddItem(new CMessageRecordItemDate(dtNow));
  218. AddItem(new CXTPReportRecordItemText(_T("")));
  219. AddItem(new CXTPReportRecordItemText(_T("")));
  220. AddItem(new CXTPReportRecordItemText(_T("")));
  221. AddItem(new CXTPReportRecordItemText(_T("")));
  222. AddItem(new CXTPReportRecordItemText(_T("")));
  223. AddItem(new CXTPReportRecordItemText(_T("")));
  224. AddItem(new CXTPReportRecordItemText(_T("")));
  225. AddItem(new CXTPReportRecordItemText(_T("")));
  226. SetPreviewItem(new CXTPReportRecordItemPreview(_T("")));
  227. }
  228. CMessageRecord::~CMessageRecord()
  229. {
  230. }
  231. BOOL CMessageRecord::SetRead()
  232. {
  233. ASSERT(m_pItemIcon);
  234. if (m_pItemIcon->m_bRead)
  235. return FALSE;
  236. m_pItemIcon->m_bRead = TRUE;
  237. m_pItemIcon->UpdateReadIcon();
  238. return TRUE;
  239. }
  240. void CMessageRecord::GetItemMetrics(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pItemMetrics)
  241. {
  242. if (m_pItemIcon && !m_pItemIcon->m_bRead && !pDrawArgs->pItem->IsPreviewItem())
  243. pItemMetrics->pFont = &pDrawArgs->pControl->GetPaintManager()->m_fontBoldText;
  244. CReportSampleView* pView = DYNAMIC_DOWNCAST(CReportSampleView, pDrawArgs->pControl->GetParent());
  245. // If automatic formatting option is enabled, sample code below will be executed.
  246. // There you can see an example of "late" customization for colors, fonts, etc.
  247. if (pView && pView->m_bAutomaticFormating)
  248. {
  249. if ((pDrawArgs->pRow->GetIndex() % 2) && !pDrawArgs->pItem->IsPreviewItem())
  250. {
  251. pItemMetrics->clrBackground = RGB(245, 245, 245);
  252. }
  253. if (m_pItemReceived->GetGroupCaptionID(NULL) <= IDS_GROUP_DATE_THISYEAR  && !pDrawArgs->pItem->IsPreviewItem())
  254. {
  255. static CFont m_fontStriked;
  256. if (!m_fontStriked.GetSafeHandle())
  257. {
  258. LOGFONT lf;
  259. pDrawArgs->pControl->GetPaintManager()->m_fontText.GetLogFont(&lf);
  260. lf.lfStrikeOut = TRUE;
  261. m_fontStriked.CreateFontIndirect(&lf);
  262. }
  263. pItemMetrics->pFont = &m_fontStriked;
  264. }
  265. if (pDrawArgs->pItem->GetCaption(pDrawArgs->pColumn).Find(_T("Undeliverable")) >= 0)
  266. {
  267. pItemMetrics->clrForeground = RGB(0xFF, 0, 0);
  268. }
  269. }
  270. }
  271. void CMessageRecord::DoPropExchange(CXTPPropExchange* pPX)
  272. {
  273. CXTPReportRecord::DoPropExchange(pPX);
  274. if (pPX->IsLoading())
  275. {
  276. // 1 - m_pItemIcon = (CMessageRecordItemIcon*)AddItem(new CMessageRecordItemIcon(TRUE));
  277. ASSERT_KINDOF(CMessageRecordItemIcon, GetItem(1));
  278. m_pItemIcon = DYNAMIC_DOWNCAST(CMessageRecordItemIcon, GetItem(1));
  279. ASSERT(m_pItemIcon);
  280. // 5 - m_pItemReceived = (CMessageRecordItemDate*)AddItem(new CMessageRecordItemDate(dtNow));
  281. ASSERT_KINDOF(CMessageRecordItemDate, GetItem(5));
  282. m_pItemReceived = DYNAMIC_DOWNCAST(CMessageRecordItemDate, GetItem(5));
  283. ASSERT(m_pItemReceived);
  284. // 6 - m_pItemSize = AddItem(new CXTPReportRecordItemNumber(0));
  285. ASSERT_KINDOF(CXTPReportRecordItemNumber, GetItem(6));
  286. m_pItemSize = DYNAMIC_DOWNCAST(CXTPReportRecordItemNumber, GetItem(6));
  287. ASSERT(m_pItemSize);
  288. }
  289. }