home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c11 / lab03 / ex01 / ftpview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.8 KB  |  162 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. #include "ftpDlg.h"
  11. #include "ftpGet.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CFtpView
  21.  
  22. IMPLEMENT_DYNCREATE(CFtpView, CScrollView)
  23.  
  24. BEGIN_MESSAGE_MAP(CFtpView, CScrollView)
  25.     //{{AFX_MSG_MAP(CFtpView)
  26.     ON_COMMAND(ID_FILE_FTP_TRANSFER, OnFileFtpTransfer)
  27.     ON_COMMAND(ID_VIEW_CLEAR, OnViewClear)
  28.     //}}AFX_MSG_MAP
  29.     // Standard printing commands
  30.     ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  31.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  32.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  33. END_MESSAGE_MAP()
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CFtpView construction/destruction
  37.  
  38. CFtpView::CFtpView()
  39. {
  40.     // TODO: add construction code here
  41.  
  42. }
  43.  
  44. CFtpView::~CFtpView()
  45. {
  46.     m_strings.RemoveAll();
  47. }
  48.  
  49. BOOL CFtpView::PreCreateWindow(CREATESTRUCT& cs)
  50. {
  51.     // TODO: Modify the Window class or styles here by modifying
  52.     //  the CREATESTRUCT cs
  53.  
  54.     return CScrollView::PreCreateWindow(cs);
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CFtpView drawing
  59.  
  60. void CFtpView::OnDraw(CDC* pDC)
  61. {
  62.     CFtpDoc* pDoc = GetDocument();
  63.     ASSERT_VALID(pDoc);
  64.  
  65.     // TODO: add draw code for native data here
  66.     CSize sizeTotal;
  67.     sizeTotal.cx = 100;
  68.     TEXTMETRIC tm;
  69.     pDC->GetTextMetrics(&tm);
  70.     sizeTotal.cy = tm.tmHeight*m_strings.GetSize();
  71.     SetScrollSizes(MM_TEXT, sizeTotal);
  72.  
  73.     for (int idx=0; idx<m_strings.GetSize(); idx++) {
  74.         CString str;
  75.         str.Format("%s", m_strings.GetAt(idx));
  76.         pDC->TabbedTextOut(0,idx*tm.tmHeight,str,0,NULL,0);
  77.     }
  78.  
  79. }
  80. void CFtpView::OnInitialUpdate()
  81. {
  82.     CScrollView::OnInitialUpdate();
  83.     CSize sizeTotal;
  84.     // TODO: calculate the total size of this view
  85.     sizeTotal.cx = sizeTotal.cy = 100;
  86.     SetScrollSizes(MM_TEXT, sizeTotal);
  87.     AddToView("Select File, then FTP Transfer to begin.");
  88. }
  89. void CFtpView::AddToView(LPCTSTR string)
  90. {
  91.     m_strings.Add(string);
  92.  
  93.     Invalidate();
  94.     // Force an immediate update.
  95.     UpdateWindow();
  96. }
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CFtpView printing
  100.  
  101. BOOL CFtpView::OnPreparePrinting(CPrintInfo* pInfo)
  102. {
  103.     // default preparation
  104.     return DoPreparePrinting(pInfo);
  105. }
  106.  
  107. void CFtpView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  108. {
  109.     // TODO: add extra initialization before printing
  110. }
  111.  
  112. void CFtpView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  113. {
  114.     // TODO: add cleanup after printing
  115. }
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CFtpView diagnostics
  119.  
  120. #ifdef _DEBUG
  121. void CFtpView::AssertValid() const
  122. {
  123.     CScrollView::AssertValid();
  124. }
  125.  
  126. void CFtpView::Dump(CDumpContext& dc) const
  127. {
  128.     CScrollView::Dump(dc);
  129. }
  130.  
  131. CFtpDoc* CFtpView::GetDocument() // non-debug version is inline
  132. {
  133.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFtpDoc)));
  134.     return (CFtpDoc*)m_pDocument;
  135. }
  136. #endif //_DEBUG
  137.  
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CFtpView message handlers
  140. void CFtpView::OnViewClear() 
  141. {
  142.     // TODO: Add your command handler code here
  143.     m_strings.RemoveAll();
  144.     Invalidate();
  145. }
  146.  
  147. void CFtpView::OnFileFtpTransfer() 
  148. {
  149.     OnViewClear();    // Clear the screen.
  150.     // Pop up dialog box to prompt user for FTP transfer parameters.
  151.     CFtpDlg dlg(this);
  152.     if (dlg.DoModal()==IDOK) {
  153.         // Create an instance of the FTP object using dialog values.
  154.         CFtpGet ftpget(this,
  155.             dlg.m_strServer, dlg.m_strFile,
  156.             dlg.m_strPath, dlg.m_strRoot, dlg.m_strGateway, dlg.m_nCopyType);
  157.         // Do the transfer
  158.         ftpget.DoFtpTransfer();
  159.     }
  160. }
  161.  
  162.