home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c05 / lab06 / baseline / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  5.3 KB  |  229 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "diff.h"
  6.  
  7. #include "progress.h"
  8. #include "splitter.h"
  9. #include "MainFrm.h"
  10. #include "diffdoc.h"
  11. #include "diffview.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMainFrame
  20.  
  21. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  22.  
  23. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  24.     //{{AFX_MSG_MAP(CMainFrame)
  25.     ON_WM_CREATE()
  26.     ON_WM_DROPFILES()
  27.     //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29.  
  30. static UINT indicators[] =
  31. {
  32.     ID_SEPARATOR,           // status line indicator
  33.     ID_INDICATOR_CAPS,
  34.     ID_INDICATOR_NUM,
  35.     ID_INDICATOR_SCRL,
  36. };
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMainFrame construction/destruction
  40.  
  41. CMainFrame::CMainFrame()
  42. {
  43.     // TODO: add member initialization code here
  44.     
  45. }
  46.  
  47. CMainFrame::~CMainFrame()
  48. {
  49. }
  50.  
  51. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  52. {
  53.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  54.         return -1;
  55.     
  56.     if (!m_wndToolBar.Create(this) ||
  57.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  58.     {
  59.         TRACE0("Failed to create toolbar\n");
  60.         return -1;      // fail to create
  61.     }
  62.  
  63.     if (!m_wndStatusBar.Create(this) ||
  64.         !m_wndStatusBar.SetIndicators(indicators,
  65.           sizeof(indicators)/sizeof(UINT)))
  66.     {
  67.         TRACE0("Failed to create status bar\n");
  68.         return -1;      // fail to create
  69.     }
  70.  
  71.     // TODO: Delete these three lines if you don't want the toolbar to
  72.     //  be dockable
  73.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  74.     EnableDocking(CBRS_ALIGN_ANY);
  75.     DockControlBar(&m_wndToolBar);
  76.  
  77.     // TODO: Remove this if you don't want tool tips
  78.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  79.         CBRS_TOOLTIPS | CBRS_FLYBY);
  80.  
  81.     return 0;
  82. }
  83.  
  84. BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
  85.     CCreateContext* pContext)
  86. {
  87.         //
  88.         //    For the difference application, we will create a
  89.         //    static splitter window    with 2 side by side panes.
  90.         //    
  91.     if(!m_wndSplitter.CreateStatic(this,1,2,WS_CHILD))
  92.     {
  93.         return FALSE;
  94.     }
  95.  
  96.     SIZE size;                                  
  97.     CRect rect;     
  98.     GetClientRect(&rect);   
  99.         
  100.         //
  101.         //    Calculate the size of the splitter panes
  102.         //
  103.     size.cx = (rect.right - m_wndSplitter.GetSplitterWidth())/2;
  104.     size.cy = rect.bottom;
  105.  
  106.         //
  107.         //    Provide each pane with its own view, the same in this case
  108.         //    but could be different    
  109.         //
  110.     m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CDiffView),size, pContext);
  111.     m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CDiffView),size, pContext);
  112.     //SetActiveView((CView *)m_wndSplitter.GetPane(0,1));
  113.   
  114.     m_wndSplitter.ShowWindow(SW_SHOWNORMAL);
  115.     m_wndSplitter.UpdateWindow();
  116.  
  117.     return TRUE;
  118. }
  119.  
  120. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  121. {
  122.     // TODO: Modify the Window class or styles here by modifying
  123.     //  the CREATESTRUCT cs
  124.  
  125.     return CFrameWnd::PreCreateWindow(cs);
  126. }
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CMainFrame diagnostics
  130.  
  131. #ifdef _DEBUG
  132. void CMainFrame::AssertValid() const
  133. {
  134.     CFrameWnd::AssertValid();
  135. }
  136.  
  137. void CMainFrame::Dump(CDumpContext& dc) const
  138. {
  139.     CFrameWnd::Dump(dc);
  140. }
  141.  
  142. #endif //_DEBUG
  143.  
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CMainFrame message handlers
  146.  
  147. void CMainFrame::OnDropFiles(HDROP hDropInfo) 
  148. {
  149.     UINT nFileCount = ::DragQueryFile (hDropInfo,
  150.                                         0xFFFFFFFF,
  151.                                         NULL, 0 );
  152.     ASSERT (nFileCount !=0);
  153.  
  154.     // we must have at least two files for this function;
  155.     // we will grab only the first two
  156.  
  157.     if (nFileCount >= 2)
  158.     {
  159.         CString File1;
  160.         CString File2;
  161.  
  162.         ::DragQueryFile (hDropInfo,
  163.                         0,
  164.                         File1.GetBufferSetLength (_MAX_PATH),
  165.                         _MAX_PATH);
  166.         File1.ReleaseBuffer();
  167.  
  168.         ::DragQueryFile (hDropInfo,
  169.                         1,
  170.                         File2.GetBufferSetLength (_MAX_PATH),
  171.                         _MAX_PATH);
  172.         File2.ReleaseBuffer();
  173.  
  174.         ((CDiffDoc *)GetActiveDocument())->
  175.                             RunComparison (File1, File2);
  176.  
  177.         ::DragFinish(hDropInfo);
  178.     }
  179. }
  180.  
  181. void CMainFrame::SetList( int nID, const CString & strFile )
  182. {
  183. #ifndef _BASELINE_CODE_
  184.     //Dialog Bar lab
  185.     AddItem( nID, strFile );
  186.     CComboBox * pCmb = 
  187.         ( CComboBox * ) m_wndDialogBar.GetDlgItem( nID );
  188.     pCmb->SelectString( -1, strFile ); //Start search at top
  189. #endif
  190. }
  191.  
  192. void CMainFrame::AddItem( int nID, const CString & str )
  193. {
  194. #ifndef _BASELINE_CODE_
  195.     //Dialog Bar lab
  196.     CComboBox * pCmb = 
  197.         ( CComboBox * ) m_wndDialogBar.GetDlgItem( nID );
  198.     if ( CB_ERR == pCmb->FindString( -1, str ) )//Search from top
  199.         pCmb->AddString( str );
  200. #endif
  201. }
  202.  
  203. void CMainFrame::ResetFile( int nID, const CString & str )
  204. {
  205.     //Dialog Bar lab
  206.     if ( str.IsEmpty( ) )  //Nothing to do
  207.         return;
  208.     int pane = LEFT == nID ? 0 : 1; //pane 0 is left, pane 1 is right
  209.     
  210.     //Get the appropriate pane, Row 0, Column left or right
  211.     CDiffView * pView = ( CDiffView * ) m_wndSplitter.GetPane( 0, pane );
  212.     
  213.     //Load the pane from the drive using the view's Serialize function
  214.     if ( NULL != pView )
  215.     {
  216.         CFile file( str, CFile::modeRead );
  217.         CArchive ar( & file, CArchive::load );
  218.         pView->Serialize( ar );
  219.  
  220.         //Update the document data member (we're a friend)
  221.         CDiffDoc * pDoc = pView->GetDocument( );
  222.         if ( LEFT == nID )
  223.             pDoc->m_File1 = str;
  224.         else
  225.             pDoc->m_File2 = str;
  226.     }
  227. }
  228.  
  229.