home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c06 / lab05 / baseline / diffdoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.5 KB  |  187 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 "FindDiff.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.         //    For effect, use the progress feedback available
  113.         //    from our status bar class
  114.         //
  115.     CProgressStatusBar *pStatus = CDiffApp::GetApp()->
  116.         GetMainFrame()->GetStatusBar();
  117.     if(pStatus)
  118.     {
  119.         CString    Label;
  120.         Label.LoadString(IDS_COMPARING);
  121.         pStatus->SetProgressLabel(Label);
  122.  
  123.             //    
  124.             //    Flip the StatusBar into Progress Mode
  125.             //
  126.         pStatus->ShowProgressDisplay(TRUE);
  127.  
  128.             //    
  129.             //    Simulate some bogus progress
  130.             //
  131.         CProgressCtrl *pProgress = pStatus->GetProgressCtrl();
  132.         if(pProgress)
  133.         {
  134.             pProgress->SetRange(0, 10);
  135.             pProgress->SetStep(1);
  136.             while(pProgress->StepIt() != 10)
  137.             {
  138.                 for(LONG l = 0; l < 2000000; l++);
  139.             }
  140.         }
  141.         pStatus->ShowProgressDisplay(FALSE);
  142.     }
  143.     
  144.     CMainFrame * pFrame    = CDiffApp::GetApp()->GetMainFrame();
  145.     
  146.     if(pFrame)
  147.     {
  148.         CSplitter * pSplitter    = pFrame->GetSplitter();
  149.  
  150.     
  151.         if(pSplitter)
  152.         {
  153.             CDiffView * pView;
  154.             pView = (CDiffView *)pSplitter->GetPane(0,0);
  155.  
  156.             if (pView)
  157.             {
  158.                 CFile    file(lpszFile1, CFile::modeRead);
  159.                 CArchive ar(&file, CArchive::load);
  160.                 pView->Serialize(ar);
  161.             }
  162.  
  163.             pView = (CDiffView *)pSplitter->GetPane(0,1);
  164.             if (pView)
  165.             {
  166.                 CFile    file(lpszFile2, CFile::modeRead);
  167.                 CArchive ar(&file, CArchive::load);
  168.                 pView->Serialize(ar);
  169.             }
  170.             //      Flag as clean so that we won't get
  171.             //      prompted to save
  172.             SetModifiedFlag(FALSE);
  173.  
  174.         }
  175.     }
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.