home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c06 / lab04 / ex02 / diffdoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.5 KB  |  186 lines

  1. // diffDoc.cpp : implementation of the CDiffDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "diff.h"
  6.  
  7. #include "diffDoc.h"
  8. #include "diffview.h"
  9.  
  10. #include "progress.h"
  11. #include "splitter.h"
  12. #include "mainfrm.h"
  13. #include "dlgopenf.h"
  14.  
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CDiffDoc
  22.  
  23. IMPLEMENT_DYNCREATE(CDiffDoc, CRichEditDoc)
  24.  
  25. BEGIN_MESSAGE_MAP(CDiffDoc, CRichEditDoc)
  26.     //{{AFX_MSG_MAP(CDiffDoc)
  27.     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  28.     //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CDiffDoc construction/destruction
  33.  
  34. CDiffDoc::CDiffDoc()
  35. {
  36.     m_File1 = "";
  37.     m_File2 = "";
  38.     m_bRTF    = FALSE;
  39. }
  40.  
  41. CDiffDoc::~CDiffDoc()
  42. {
  43. }
  44.  
  45. CRichEditCntrItem* CDiffDoc::CreateClientItem(REOBJECT* preo) const
  46. {
  47.         // cast away constness of this
  48.         return new CRichEditCntrItem();
  49. }
  50.  
  51. BOOL CDiffDoc::OnNewDocument()
  52. {
  53.     if (!CRichEditDoc::OnNewDocument())
  54.         return FALSE;
  55.  
  56.     // TODO: add reinitialization code here
  57.     // (SDI documents will reuse this document)
  58.  
  59.     return TRUE;
  60. }
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CDiffDoc serialization
  64.  
  65. void CDiffDoc::Serialize(CArchive& ar)
  66. {
  67.     if (ar.IsStoring())
  68.     {
  69.         // TODO: add storing code here
  70.     }
  71.     else
  72.     {
  73.         // TODO: add loading code here
  74.     }
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDiffDoc diagnostics
  79.  
  80. #ifdef _DEBUG
  81. void CDiffDoc::AssertValid() const
  82. {
  83.     CRichEditDoc::AssertValid();
  84. }
  85.  
  86. void CDiffDoc::Dump(CDumpContext& dc) const
  87. {
  88.     CRichEditDoc::Dump(dc);
  89. }
  90. #endif //_DEBUG
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CDiffDoc commands
  94.  
  95. void CDiffDoc::OnFileOpen() 
  96. {
  97.  
  98.     CDlgOpenFiles dlg;
  99.  
  100.     if(dlg.DoModal() == IDOK)
  101.     {
  102.         dlg.GetFile1(m_File1);
  103.         dlg.GetFile2(m_File2);
  104.         RunComparison (m_File1, m_File2);
  105.     }
  106. }
  107.  
  108.  
  109. void CDiffDoc::RunComparison (LPCSTR lpszFile1, LPCSTR lpszFile2)
  110. {
  111.         //    For effect, use the progress feedback available
  112.         //    from our status bar class
  113.         //
  114.     CProgressStatusBar *pStatus = CDiffApp::GetApp()->
  115.         GetMainFrame()->GetStatusBar();
  116.     if(pStatus)
  117.     {
  118.         CString    Label;
  119.         Label.LoadString(IDS_COMPARING);
  120.         pStatus->SetProgressLabel(Label);
  121.  
  122.             //    
  123.             //    Flip the StatusBar into Progress Mode
  124.             //
  125.         pStatus->ShowProgressDisplay(TRUE);
  126.  
  127.             //    
  128.             //    Simulate some bogus progress
  129.             //
  130.         CProgressCtrl *pProgress = pStatus->GetProgressCtrl();
  131.         if(pProgress)
  132.         {
  133.             pProgress->SetRange(0, 10);
  134.             pProgress->SetStep(1);
  135.             while(pProgress->StepIt() != 10)
  136.             {
  137.                 for(LONG l = 0; l < 2000000; l++);
  138.             }
  139.         }
  140.         pStatus->ShowProgressDisplay(FALSE);
  141.     }
  142.     
  143.     CMainFrame * pFrame    = CDiffApp::GetApp()->GetMainFrame();
  144.     
  145.     if(pFrame)
  146.     {
  147.         CSplitter * pSplitter    = pFrame->GetSplitter();
  148.  
  149.     
  150.         if(pSplitter)
  151.         {
  152.             CDiffView * pView;
  153.             pView = (CDiffView *)pSplitter->GetPane(0,0);
  154.  
  155.             if (pView)
  156.             {
  157.                 CFile    file(lpszFile1, CFile::modeRead);
  158.                 CArchive ar(&file, CArchive::load);
  159.                 pView->Serialize(ar);
  160.             }
  161.  
  162.             pView = (CDiffView *)pSplitter->GetPane(0,1);
  163.             if (pView)
  164.             {
  165.                 CFile    file(lpszFile2, CFile::modeRead);
  166.                 CArchive ar(&file, CArchive::load);
  167.                 pView->Serialize(ar);
  168.             }
  169.             //      Flag as clean so that we won't get
  170.             //      prompted to save
  171.             SetModifiedFlag(FALSE);
  172.  
  173.         }
  174.     }
  175. }
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.