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

对话框与窗口

开发平台:

Visual C++

  1. // PropertiesFrame.cpp : implementation file
  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 "PropertiesView.h"
  23. #include "ReportSampleView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. #define ID_PROPERTY_MULTIPLESELECTION 1
  30. #define ID_PROPERTY_PREVIEWMODE 2
  31. #define ID_PROPERTY_GROUPBOXVISIBLE 3
  32. #define ID_PROPERTY_FOCUSSUBITEMS 4
  33. #define ID_PROPERTY_ALLOWCOLUMNREMOVE 5
  34. #define ID_PROPERTY_ALLOWCOLUMNREORDER 6
  35. #define ID_PROPERTY_ALLOWCOLUMNRESIZE 7
  36. #define ID_PROPERTY_FLATHEADER 8
  37. #define ID_PROPERTY_HIDESELECTION 9
  38. #define ID_PROPERTY_TREEINDENT 10
  39. class CRecordPropertyGroup : public CXTPReportRecord
  40. {
  41. public:
  42. CRecordPropertyGroup(CString strCaption)
  43. {
  44. AddItem(new CXTPReportRecordItemText(strCaption));
  45. CXTPReportRecordItem* pItem = AddItem(new CXTPReportRecordItemText(_T("")));
  46. pItem->SetEditable(FALSE);
  47. AddItem(new CXTPReportRecordItemText(_T("")));
  48. }
  49. };
  50. class CRecordPropertyInt : public CXTPReportRecord
  51. {
  52. public:
  53. CRecordPropertyInt(UINT nID, CString strCaption, int nValue)
  54. {
  55. AddItem(new CXTPReportRecordItemText(strCaption));
  56. CXTPReportRecordItem* pItem = AddItem(new CXTPReportRecordItemNumber(nValue));
  57. pItem->SetItemData(nID);
  58. AddItem(new CXTPReportRecordItemText(_T("int")));
  59. }
  60. static int GetValue(XTP_NM_REPORTRECORDITEM* pItemNotify)
  61. {
  62. return (int)((CXTPReportRecordItemNumber*)pItemNotify->pItem)->GetValue();
  63. }
  64. };
  65. class CRecordPropertyBool : public CXTPReportRecord
  66. {
  67. protected:
  68. class CPropertyItemBool : public CXTPReportRecordItem
  69. {
  70. public:
  71. CPropertyItemBool(BOOL bValue)
  72. {
  73. m_bValue = bValue;
  74. GetEditOptions(NULL)->AddConstraint(_T("True"), TRUE);
  75. GetEditOptions(NULL)->AddConstraint(_T("False"), FALSE);
  76. GetEditOptions(NULL)->m_bConstraintEdit = TRUE;
  77. GetEditOptions(NULL)->AddComboButton();
  78. }
  79. CString GetCaption(CXTPReportColumn* /*pColumn*/)
  80. {
  81. CXTPReportRecordItemConstraint* pConstraint = GetEditOptions(NULL)->FindConstraint(m_bValue);
  82. ASSERT(pConstraint);
  83. return pConstraint->m_strConstraint;
  84. }
  85. void OnConstraintChanged(XTP_REPORTRECORDITEM_ARGS* /*pItemArgs*/, CXTPReportRecordItemConstraint* pConstraint)
  86. {
  87. m_bValue = (BOOL)pConstraint->m_dwData;
  88. }
  89. BOOL GetValue()
  90. {
  91. return m_bValue;
  92. }
  93. protected:
  94. BOOL m_bValue;
  95. };
  96. public:
  97. CRecordPropertyBool(UINT nID, CString strCaption, BOOL bValue)
  98. {
  99. AddItem(new CXTPReportRecordItemText(strCaption));
  100. CXTPReportRecordItem* pItem = AddItem(new CPropertyItemBool(bValue));
  101. pItem->SetItemData(nID);
  102. AddItem(new CXTPReportRecordItemText(_T("bool")));
  103. }
  104. static BOOL GetValue(XTP_NM_REPORTRECORDITEM* pItemNotify)
  105. {
  106. return ((CPropertyItemBool*)pItemNotify->pItem)->GetValue();
  107. }
  108. };
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CPropertiesFrame
  111. CPropertiesFrame::CPropertiesFrame(CView* pOwnerView)
  112. {
  113. m_pOwnerView = pOwnerView;
  114. }
  115. CPropertiesFrame::~CPropertiesFrame()
  116. {
  117. }
  118. BEGIN_MESSAGE_MAP(CPropertiesFrame, CMiniFrameWnd)
  119. //{{AFX_MSG_MAP(CPropertiesFrame)
  120. ON_WM_CREATE()
  121. ON_WM_DESTROY()
  122. //}}AFX_MSG_MAP
  123. END_MESSAGE_MAP()
  124. /////////////////////////////////////////////////////////////////////////////
  125. // CPropertiesFrame message handlers
  126. int CPropertiesFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  127. {
  128. if (CMiniFrameWnd::OnCreate(lpCreateStruct) == -1)
  129. return -1;
  130. if (!InitCommandBars())
  131. return -1;
  132. CXTPCommandBars* pCommandBars = GetCommandBars();
  133. CXTPToolBar* pToolBar = pCommandBars->Add(_T("Options"), xtpBarTop);
  134. pToolBar->LoadToolBar(IDR_MAINFRAME, FALSE);
  135. pToolBar->SetCloseable(FALSE);
  136. return 0;
  137. }
  138. void CPropertiesFrame::OnDestroy()
  139. {
  140. ((CReportSampleView*)m_pOwnerView)->m_pPropertiesFrame = NULL;
  141. CMiniFrameWnd::OnDestroy();
  142. }
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CPropertiesView
  145. IMPLEMENT_DYNCREATE(CPropertiesView, CView)
  146. CPropertiesView::CPropertiesView()
  147. {
  148. }
  149. CPropertiesView::~CPropertiesView()
  150. {
  151. }
  152. #define ID_REPORT_CONTROL 100
  153. BEGIN_MESSAGE_MAP(CPropertiesView, CView)
  154. //{{AFX_MSG_MAP(CPropertiesView)
  155. ON_WM_CREATE()
  156. ON_WM_SIZE()
  157. ON_WM_ERASEBKGND()
  158. ON_WM_SETFOCUS()
  159. //}}AFX_MSG_MAP
  160. ON_NOTIFY(XTP_NM_REPORT_VALUECHANGED, ID_REPORT_CONTROL, OnPropertyChanged)
  161. END_MESSAGE_MAP()
  162. /////////////////////////////////////////////////////////////////////////////
  163. // CPropertiesView drawing
  164. void CPropertiesView::OnDraw(CDC*)
  165. {
  166. }
  167. /////////////////////////////////////////////////////////////////////////////
  168. // CPropertiesView diagnostics
  169. #ifdef _DEBUG
  170. void CPropertiesView::AssertValid() const
  171. {
  172. CView::AssertValid();
  173. }
  174. void CPropertiesView::Dump(CDumpContext& dc) const
  175. {
  176. CView::Dump(dc);
  177. }
  178. #endif //_DEBUG
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CPropertiesView message handlers
  181. CXTPReportControl* CPropertiesView::GetTargetReport()
  182. {
  183. CView* pView = ((CPropertiesFrame*)GetParent())->m_pOwnerView;
  184. return &((CReportSampleView*)pView)->GetReportCtrl();
  185. }
  186. int CPropertiesView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  187. {
  188. if (CView::OnCreate(lpCreateStruct) == -1)
  189. return -1;
  190. if (!m_wndReport.Create(WS_CHILD|WS_TABSTOP|WS_VISIBLE|WM_VSCROLL, CRect(0, 0, 0, 0), this, ID_REPORT_CONTROL))
  191. {
  192. TRACE(_T("Failed to create view windown"));
  193. return -1;
  194. }
  195. m_wndReport.GetReportHeader()->AllowColumnRemove(FALSE);
  196. CXTPReportColumn* pColumn = m_wndReport.AddColumn(new CXTPReportColumn(0, _T("Name"), 200));
  197. pColumn->SetTreeColumn(TRUE);
  198. pColumn->SetEditable(FALSE);
  199. m_wndReport.AddColumn(new CXTPReportColumn(1, _T("Value"), 150));
  200. pColumn = m_wndReport.AddColumn(new CXTPReportColumn(2, _T("Type"), 100));
  201. pColumn->SetEditable(FALSE);
  202. CXTPReportRecord* pRecordControl = m_wndReport.AddRecord(new CRecordPropertyGroup(_T("Report Control")));
  203. pRecordControl->SetExpanded(TRUE);
  204. CXTPReportControl* pTargetReport = GetTargetReport();
  205. pRecordControl->GetChilds()->Add(
  206. new CRecordPropertyBool(ID_PROPERTY_MULTIPLESELECTION, _T("Multiple Selection"), pTargetReport->IsMultipleSelection()));
  207. pRecordControl->GetChilds()->Add(
  208. new CRecordPropertyBool(ID_PROPERTY_PREVIEWMODE, _T("Preview Mode"), pTargetReport->IsPreviewMode()));
  209. pRecordControl->GetChilds()->Add(
  210. new CRecordPropertyBool(ID_PROPERTY_GROUPBOXVISIBLE, _T("Group Box Visible"), pTargetReport->IsGroupByVisible()));
  211. pRecordControl->GetChilds()->Add(
  212. new CRecordPropertyBool(ID_PROPERTY_FOCUSSUBITEMS, _T("Focus Sub Items"), pTargetReport->IsFocusSubItems()));
  213. CXTPReportRecord* pRecordHeader = pRecordControl->GetChilds()->Add(
  214. new CRecordPropertyGroup(_T("Report Header")));
  215. pRecordHeader->GetChilds()->Add(
  216. new CRecordPropertyBool(ID_PROPERTY_ALLOWCOLUMNREMOVE, _T("Allow Column Remove"), pTargetReport->GetReportHeader()->IsAllowColumnRemove()));
  217. pRecordHeader->GetChilds()->Add(
  218. new CRecordPropertyBool(ID_PROPERTY_ALLOWCOLUMNREORDER, _T("Allow Column Reorder"), pTargetReport->GetReportHeader()->IsAllowColumnReorder()));
  219. pRecordHeader->GetChilds()->Add(
  220. new CRecordPropertyBool(ID_PROPERTY_ALLOWCOLUMNRESIZE, _T("Allow Column Resize"), pTargetReport->GetReportHeader()->IsAllowColumnResize()));
  221. CXTPReportRecord* pRecordPaintManager = pRecordControl->GetChilds()->Add(
  222. new CRecordPropertyGroup(_T("Report Paint Manager")));
  223. pRecordPaintManager->GetChilds()->Add(
  224. new CRecordPropertyBool(ID_PROPERTY_FLATHEADER, _T("Flat Header"), pTargetReport->GetPaintManager()->GetColumnStyle() == xtpReportColumnFlat));
  225. pRecordPaintManager->GetChilds()->Add(
  226. new CRecordPropertyBool(ID_PROPERTY_HIDESELECTION, _T("Hide Selection"), pTargetReport->GetPaintManager()->m_bHideSelection));
  227. pRecordPaintManager->GetChilds()->Add(
  228. new CRecordPropertyInt(ID_PROPERTY_TREEINDENT, _T("Tree Indent"), pTargetReport->GetPaintManager()->m_nTreeIndent));
  229. m_wndReport.GetPaintManager()->SetColumnStyle(xtpReportColumnFlat);
  230. m_wndReport.AllowEdit(TRUE);
  231. m_wndReport.EditOnClick(FALSE);
  232. m_wndReport.SetMultipleSelection(FALSE);
  233. m_wndReport.SetTreeIndent(10);
  234. m_wndReport.GetReportHeader()->AllowColumnSort(FALSE);
  235. m_wndReport.Populate();
  236. return 0;
  237. }
  238. void CPropertiesView::OnSize(UINT nType, int cx, int cy)
  239. {
  240. CView::OnSize(nType, cx, cy);
  241. if (m_wndReport.GetSafeHwnd())
  242. {
  243. m_wndReport.MoveWindow(0, 0, cx, cy);
  244. }
  245. }
  246. BOOL CPropertiesView::OnEraseBkgnd(CDC* /*pDC*/)
  247. {
  248. return TRUE;
  249. }
  250. void CPropertiesView::OnSetFocus(CWnd* pOldWnd)
  251. {
  252. CView::OnSetFocus(pOldWnd);
  253. m_wndReport.SetFocus();
  254. }
  255. void CPropertiesView::OnPropertyChanged(NMHDR * pNotifyStruct, LRESULT * /*result*/)
  256. {
  257. XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct;
  258. switch (pItemNotify->pItem->GetItemData())
  259. {
  260. case ID_PROPERTY_MULTIPLESELECTION:
  261. GetTargetReport()->SetMultipleSelection(CRecordPropertyBool::GetValue(pItemNotify));
  262. break;
  263. case ID_PROPERTY_PREVIEWMODE:
  264. GetTargetReport()->EnablePreviewMode(CRecordPropertyBool::GetValue(pItemNotify));
  265. GetTargetReport()->Populate();
  266. break;
  267. case ID_PROPERTY_GROUPBOXVISIBLE:
  268. GetTargetReport()->ShowGroupBy(CRecordPropertyBool::GetValue(pItemNotify));
  269. break;
  270. case ID_PROPERTY_FOCUSSUBITEMS:
  271. GetTargetReport()->FocusSubItems(CRecordPropertyBool::GetValue(pItemNotify));
  272. break;
  273. case ID_PROPERTY_ALLOWCOLUMNREMOVE:
  274. GetTargetReport()->GetReportHeader()->AllowColumnRemove(CRecordPropertyBool::GetValue(pItemNotify));
  275. break;
  276. case ID_PROPERTY_ALLOWCOLUMNREORDER:
  277. GetTargetReport()->GetReportHeader()->AllowColumnReorder(CRecordPropertyBool::GetValue(pItemNotify));
  278. break;
  279. case ID_PROPERTY_ALLOWCOLUMNRESIZE:
  280. GetTargetReport()->GetReportHeader()->AllowColumnResize(CRecordPropertyBool::GetValue(pItemNotify));
  281. break;
  282. case ID_PROPERTY_FLATHEADER:
  283. GetTargetReport()->GetPaintManager()->SetColumnStyle((CRecordPropertyBool::GetValue(pItemNotify))? xtpReportColumnFlat: xtpReportColumnShaded);
  284. break;
  285. case ID_PROPERTY_HIDESELECTION:
  286. GetTargetReport()->GetPaintManager()->m_bHideSelection = (CRecordPropertyBool::GetValue(pItemNotify));
  287. break;
  288. case ID_PROPERTY_TREEINDENT:
  289. GetTargetReport()->GetPaintManager()->m_nTreeIndent = CRecordPropertyInt::GetValue(pItemNotify);
  290. GetTargetReport()->RedrawControl();
  291. break;
  292. }
  293. }