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