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

对话框与窗口

开发平台:

Visual C++

  1. // GrepView.cpp : implementation of the CGrepView 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 "Grep.h"
  22. #include "GrepDoc.h"
  23. #include "GrepView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CGrepView
  31. IMPLEMENT_DYNCREATE(CGrepView, CXTPReportView)
  32. BEGIN_MESSAGE_MAP(CGrepView, CXTPReportView)
  33. //{{AFX_MSG_MAP(CGrepView)
  34. ON_WM_CREATE()
  35. //}}AFX_MSG_MAP
  36. // Standard printing commands
  37. ON_NOTIFY(NM_DBLCLK, XTP_ID_REPORT_CONTROL, OnReportItemDblClick)
  38. ON_NOTIFY(NM_KEYDOWN, XTP_ID_REPORT_CONTROL, OnReportKeyDown)
  39. ON_NOTIFY(XTP_NM_REPORT_LBUTTONDOWN, XTP_ID_REPORT_CONTROL, OnReportLButtonDown)
  40. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  41. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  42. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CGrepView construction/destruction
  46. CGrepView::CGrepView()
  47. {
  48. m_bAllowPaste = FALSE;
  49. }
  50. CGrepView::~CGrepView()
  51. {
  52. }
  53. BOOL CGrepView::PreCreateWindow(CREATESTRUCT& cs)
  54. {
  55. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  56. return CXTPReportView::PreCreateWindow(cs);
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CGrepView diagnostics
  60. #ifdef _DEBUG
  61. void CGrepView::AssertValid() const
  62. {
  63. CXTPReportView::AssertValid();
  64. }
  65. void CGrepView::Dump(CDumpContext& dc) const
  66. {
  67. CXTPReportView::Dump(dc);
  68. }
  69. CGrepDoc* CGrepView::GetDocument() // non-debug version is inline
  70. {
  71. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGrepDoc)));
  72. return (CGrepDoc*)m_pDocument;
  73. }
  74. #endif //_DEBUG
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CGrepView message handlers
  77. int CGrepView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  78. {
  79. if (CXTPReportView::OnCreate(lpCreateStruct) == -1)
  80. return -1;
  81. CXTPReportControl& wndReport = GetReportCtrl();
  82. wndReport.AddColumn(new CXTPReportColumn(0, _T("Name"), 80));
  83. wndReport.AddColumn(new CXTPReportColumn(5, _T("Ext"), 18));
  84. wndReport.AddColumn(new CXTPReportColumn(3, _T("Line"), 20));
  85. CXTPReportColumn* pColumnDirectory = wndReport.AddColumn(new CXTPReportColumn(1, _T("Directory"), 180));
  86. pColumnDirectory->SetAlignment(DT_LEFT|DT_PATH_ELLIPSIS);
  87. wndReport.AddColumn(new CXTPReportColumn(2, _T("Match"), 80));
  88. wndReport.AddColumn(new CXTPReportColumn(4, _T("Apply"), 18, FALSE));
  89. wndReport.ShowGroupBy();
  90. wndReport.GetReportHeader()->AllowColumnRemove(FALSE);
  91. wndReport.EnablePreviewMode(TRUE);
  92. wndReport.SetAutoCheckItems(FALSE);
  93. return 0;
  94. }
  95. void CGrepView::OnReportItemDblClick(NMHDR * pNotifyStruct, LRESULT * /*result*/)
  96. {
  97. XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct;
  98. if (pItemNotify->pRow)
  99. {
  100. TRACE(_T("Double Click on row %dn"),
  101. pItemNotify->pRow->GetIndex());
  102. CGrepRecord* pRecord = (CGrepRecord*)pItemNotify->pRow->GetRecord();
  103. if (pRecord)
  104. {
  105. ShellExecute(0, 0, _T("notepad.exe"), (LPTSTR)(LPCTSTR)pRecord->m_strPath, 0, SW_SHOW);
  106. }
  107. }
  108. }
  109. void CGrepView::CheckSelected(BOOL bChecked)
  110. {
  111. CXTPReportSelectedRows* pSelectedRows = GetReportCtrl().GetSelectedRows();
  112. POSITION pos = pSelectedRows->GetFirstSelectedRowPosition();
  113. while (pos)
  114. {
  115. CXTPReportRow* pRow = pSelectedRows->GetNextSelectedRow(pos);
  116. if (pRow->GetRecord())
  117. {
  118. ((CGrepRecord*)pRow->GetRecord())->SetChecked(bChecked);
  119. }
  120. }
  121. GetReportCtrl().RedrawControl();
  122. }
  123. void CGrepView::OnReportKeyDown(NMHDR * pNotifyStruct, LRESULT * /*result*/)
  124. {
  125. LPNMKEY lpNMKey = (LPNMKEY)pNotifyStruct;
  126. if (lpNMKey->nVKey == VK_SPACE)
  127. {
  128. BOOL bChecked = FALSE;
  129. if (GetReportCtrl().GetFocusedRow() && GetReportCtrl().GetFocusedRow()->GetRecord())
  130. bChecked = ! ((CGrepRecord*)(GetReportCtrl().GetFocusedRow()->GetRecord()))->IsChecked();
  131. CheckSelected(bChecked);
  132. }
  133. }
  134. void CGrepView::OnReportLButtonDown(NMHDR * pNotifyStruct, LRESULT * result)
  135. {
  136. XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct;
  137. if (pItemNotify->pRow && pItemNotify->pRow->GetRecord() && pItemNotify->pColumn && pItemNotify->pColumn->GetItemIndex() == 4)
  138. {
  139. BOOL bChecked = ! ((CGrepRecord*)(pItemNotify->pRow->GetRecord()))->IsChecked();
  140. if (pItemNotify->pRow->IsSelected())
  141. {
  142. CheckSelected(bChecked);
  143. *result = TRUE;
  144. }
  145. else
  146. {
  147. ((CGrepRecord*)pItemNotify->pRow->GetRecord())->SetChecked(bChecked);
  148. }
  149. }
  150. }