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