View.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // View.cpp : implementation of the CMDIView class
  2. //
  3. #include "stdafx.h"
  4. #include "MDI.h"
  5. #include "Doc.h"
  6. #include "View.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMDIView
  14. IMPLEMENT_DYNCREATE(CMDIView, CView)
  15. BEGIN_MESSAGE_MAP(CMDIView, CView)
  16. //{{AFX_MSG_MAP(CMDIView)
  17. ON_WM_CREATE()
  18. ON_WM_SIZE()
  19. //}}AFX_MSG_MAP
  20. // Standard printing commands
  21. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMDIView construction/destruction
  27. CMDIView::CMDIView() :
  28. m_pList(0)
  29. {
  30. }
  31. CMDIView::~CMDIView()
  32. {
  33. delete m_pList;
  34. }
  35. BOOL CMDIView::PreCreateWindow(CREATESTRUCT& cs)
  36. {
  37. return CView::PreCreateWindow(cs);
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CMDIView drawing
  41. void CMDIView::OnDraw(CDC* /*pDC*/)
  42. {
  43. CMDIDoc* pDoc = GetDocument();
  44. ASSERT_VALID(pDoc);
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMDIView printing
  48. BOOL CMDIView::OnPreparePrinting(CPrintInfo* pInfo)
  49. {
  50. // default preparation
  51. return DoPreparePrinting(pInfo);
  52. }
  53. void CMDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  54. {
  55. }
  56. void CMDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  57. {
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CMDIView diagnostics
  61. #ifdef _DEBUG
  62. void CMDIView::AssertValid() const
  63. {
  64. CView::AssertValid();
  65. }
  66. void CMDIView::Dump(CDumpContext& dc) const
  67. {
  68. CView::Dump(dc);
  69. }
  70. CMDIDoc* CMDIView::GetDocument() // non-debug version is inline
  71. {
  72. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMDIDoc)));
  73. return (CMDIDoc*)m_pDocument;
  74. }
  75. #endif //_DEBUG
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CMDIView message handlers
  78. int CMDIView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  79. {
  80. if (CView::OnCreate(lpCreateStruct) == -1)
  81. return -1;
  82. DWORD dwStyle = LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS |
  83. WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
  84. CRect rect(0,0,100,100);
  85. m_pList = new CXListCtrl();
  86. ASSERT(m_pList);
  87. //VERIFY(m_pList->CreateEx(WS_EX_CLIENTEDGE, _T("SysListView32"), _T(""),dwStyle, rect, this, 2000, NULL));
  88. VERIFY(m_pList->CreateEx(WS_EX_CLIENTEDGE, dwStyle, rect, GetParent(), 2000));
  89. CFont *pFont = GetFont();
  90. if (pFont)
  91. m_pList->SetFont(pFont);
  92. m_pList->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  93. return 0;
  94. }
  95. void CMDIView::OnInitialUpdate()
  96. {
  97. CView::OnInitialUpdate();
  98. InitListCtrl(m_pList);
  99. FillListCtrl(m_pList);
  100. UpdateWindow();
  101. }
  102. void CMDIView::OnSize(UINT nType, int cx, int cy)
  103. {
  104. CView::OnSize(nType, cx, cy);
  105. if (m_pList && ::IsWindow(m_pList->m_hWnd))
  106. {
  107. m_pList->LockWindowUpdate();
  108. m_pList->MoveWindow(0, 0, cx, cy);
  109. CRect rect;
  110. GetClientRect(&rect);
  111. int w = cx - 2 - ::GetSystemMetrics(SM_CXVSCROLL);
  112. int total_cx = 0;
  113. int n = m_pList->GetColumns();
  114. int nPad = m_pList->GetCellPadding();
  115. // adjust columns
  116. for (int i = 0; i < n; i++)
  117. {
  118. int colwidth = (i == (n - 1)) ? w - total_cx - 2 : (w * m_nColWidths[i]) / 64;
  119. total_cx += colwidth;
  120. m_pList->SetColumnWidth(i, colwidth-2*nPad-2);
  121. }
  122. m_pList->UnlockWindowUpdate();
  123. }
  124. }