home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c11 / lab03 / baseline / ftpview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.4 KB  |  155 lines

  1. // ftpView.cpp : implementation of the CFtpView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ftp.h"
  6.  
  7. #include "ftpDoc.h"
  8. #include "ftpView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CFtpView
  18.  
  19. IMPLEMENT_DYNCREATE(CFtpView, CScrollView)
  20.  
  21. BEGIN_MESSAGE_MAP(CFtpView, CScrollView)
  22.     //{{AFX_MSG_MAP(CFtpView)
  23.     ON_COMMAND(ID_FILE_FTP_TRANSFER, OnFileFtpTransfer)
  24.     //}}AFX_MSG_MAP
  25.     // Standard printing commands
  26.     ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  27.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  28.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  29. END_MESSAGE_MAP()
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CFtpView construction/destruction
  33.  
  34. CFtpView::CFtpView()
  35. {
  36.     // TODO: add construction code here
  37.  
  38. }
  39.  
  40. CFtpView::~CFtpView()
  41. {
  42.     m_strings.RemoveAll();
  43. }
  44.  
  45. BOOL CFtpView::PreCreateWindow(CREATESTRUCT& cs)
  46. {
  47.     // TODO: Modify the Window class or styles here by modifying
  48.     //  the CREATESTRUCT cs
  49.  
  50.     return CScrollView::PreCreateWindow(cs);
  51. }
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CFtpView drawing
  55.  
  56. void CFtpView::OnDraw(CDC* pDC)
  57. {
  58.     CFtpDoc* pDoc = GetDocument();
  59.     ASSERT_VALID(pDoc);
  60.  
  61.     // TODO: add draw code for native data here
  62.  
  63.     CSize sizeTotal;
  64.     sizeTotal.cx = 100;
  65.     TEXTMETRIC tm;
  66.     pDC->GetTextMetrics(&tm);
  67.     sizeTotal.cy = tm.tmHeight*m_strings.GetSize();
  68.     SetScrollSizes(MM_TEXT, sizeTotal);
  69.  
  70.     for (int idx=0; idx<m_strings.GetSize(); idx++) {
  71.         CString str;
  72.         str.Format("%s", m_strings.GetAt(idx));
  73.         pDC->TabbedTextOut(0,idx*tm.tmHeight,str,0,NULL,0);
  74.     }
  75.  
  76. }
  77. void CFtpView::OnInitialUpdate()
  78. {
  79.     CScrollView::OnInitialUpdate();
  80.     CSize sizeTotal;
  81.     // TODO: calculate the total size of this view
  82.     sizeTotal.cx = sizeTotal.cy = 100;
  83.     SetScrollSizes(MM_TEXT, sizeTotal);
  84.     AddToView("Select File, then FTP Transfer to begin.");
  85. }
  86. void CFtpView::AddToView(LPCTSTR string)
  87. {
  88.     m_strings.Add(string);
  89.  
  90.     Invalidate();
  91.     // Force an immediate update.
  92.     UpdateWindow();
  93. }
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CFtpView printing
  97.  
  98. BOOL CFtpView::OnPreparePrinting(CPrintInfo* pInfo)
  99. {
  100.     // default preparation
  101.     return DoPreparePrinting(pInfo);
  102. }
  103.  
  104. void CFtpView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  105. {
  106.     // TODO: add extra initialization before printing
  107. }
  108.  
  109. void CFtpView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  110. {
  111.     // TODO: add cleanup after printing
  112. }
  113.  
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CFtpView diagnostics
  116.  
  117. #ifdef _DEBUG
  118. void CFtpView::AssertValid() const
  119. {
  120.     CScrollView::AssertValid();
  121. }
  122.  
  123. void CFtpView::Dump(CDumpContext& dc) const
  124. {
  125.     CScrollView::Dump(dc);
  126. }
  127.  
  128. CFtpDoc* CFtpView::GetDocument() // non-debug version is inline
  129. {
  130.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFtpDoc)));
  131.     return (CFtpDoc*)m_pDocument;
  132. }
  133. #endif //_DEBUG
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CFtpView message handlers
  137. void CFtpView::OnViewClear() 
  138. {
  139.     // TODO: Add your command handler code here
  140.     m_strings.RemoveAll();
  141.  
  142.     Invalidate();
  143.     // Force an immediate update.
  144.     UpdateWindow();
  145.  
  146. }
  147.  
  148. void CFtpView::OnFileFtpTransfer() 
  149. {
  150.     OnViewClear();    // Clear the screen.
  151.  
  152.  
  153. }
  154.  
  155.