home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c06 / lab01 / ex01 / diffdoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.8 KB  |  154 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 "splitter.h"
  11. #include "mainfrm.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CDiffDoc
  20.  
  21. IMPLEMENT_DYNCREATE(CDiffDoc, CRichEditDoc)
  22.  
  23. BEGIN_MESSAGE_MAP(CDiffDoc, CRichEditDoc)
  24.     //{{AFX_MSG_MAP(CDiffDoc)
  25.     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CDiffDoc construction/destruction
  31.  
  32. CDiffDoc::CDiffDoc()
  33. {
  34.     m_File1 = "";
  35.     m_File2 = "";
  36.     m_bRTF    = FALSE;
  37. }
  38.  
  39. CDiffDoc::~CDiffDoc()
  40. {
  41. }
  42.  
  43. CRichEditCntrItem* CDiffDoc::CreateClientItem(REOBJECT* preo) const
  44. {
  45.         // cast away constness of this
  46.         return new CRichEditCntrItem();
  47. }
  48.  
  49. BOOL CDiffDoc::OnNewDocument()
  50. {
  51.     if (!CRichEditDoc::OnNewDocument())
  52.         return FALSE;
  53.  
  54.     // TODO: add reinitialization code here
  55.     // (SDI documents will reuse this document)
  56.  
  57.     return TRUE;
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CDiffDoc serialization
  62.  
  63. void CDiffDoc::Serialize(CArchive& ar)
  64. {
  65.     if (ar.IsStoring())
  66.     {
  67.         // TODO: add storing code here
  68.     }
  69.     else
  70.     {
  71.         // TODO: add loading code here
  72.     }
  73. }
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CDiffDoc diagnostics
  77.  
  78. #ifdef _DEBUG
  79. void CDiffDoc::AssertValid() const
  80. {
  81.     CRichEditDoc::AssertValid();
  82. }
  83.  
  84. void CDiffDoc::Dump(CDumpContext& dc) const
  85. {
  86.     CRichEditDoc::Dump(dc);
  87. }
  88. #endif //_DEBUG
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CDiffDoc commands
  92.  
  93. void CDiffDoc::OnFileOpen() 
  94. {
  95.     static char BASED_CODE szFilter[] =
  96.             "All Files (*.*)|*.*|C++ Files (*.cpp, *.h)" \
  97.             "|*.cpp;*.h||";
  98.  
  99.     CFileDialog dlg(TRUE,NULL,NULL,NULL,szFilter);
  100.  
  101.     if(dlg.DoModal() == IDOK)
  102.     {
  103.         m_File1 = m_File2 = dlg.GetPathName();
  104.     }
  105.     RunComparison (m_File1, m_File2);
  106. }
  107.  
  108.  
  109. void CDiffDoc::RunComparison (LPCSTR lpszFile1, LPCSTR lpszFile2)
  110. {
  111.     CMainFrame * pFrame        = CDiffApp::GetApp()->GetMainFrame();
  112.     
  113.     if(pFrame)
  114.     {
  115.         CSplitter * pSplitter    = pFrame->GetSplitter();
  116.  
  117.     
  118.         if(pSplitter)
  119.         {
  120.             CDiffView * pView;
  121.             pView = (CDiffView *)pSplitter->GetPane(0,0);
  122.  
  123.             if (pView)
  124.             {
  125.                 CFile    file(lpszFile1, CFile::modeRead);
  126.                 CArchive ar(&file, CArchive::load);
  127.                 pView->Serialize(ar);
  128.             }
  129.  
  130.             pView = (CDiffView *)pSplitter->GetPane(0,1);
  131.             if (pView)
  132.             {
  133.                 CFile    file(lpszFile2, CFile::modeRead);
  134.                 CArchive ar(&file, CArchive::load);
  135.                 pView->Serialize(ar);
  136.             }
  137.             //      Flag as clean so that we won't get
  138.             //      prompted to save
  139.             SetModifiedFlag(FALSE);
  140.  
  141.         }
  142.     }
  143. }
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.