home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c06 / lab03 / ex02 / diffview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.6 KB  |  188 lines

  1. // diffView.cpp : implementation of the CDiffView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "diff.h"
  6.  
  7. #include "diffDoc.h"
  8. #include "diffView.h"
  9. #include "progress.h"
  10. #include "splitter.h"
  11. #include "mainfrm.h"
  12. #include "resource.h"
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CDiffView
  20.  
  21. IMPLEMENT_DYNCREATE(CDiffView, CRichEditView)
  22.  
  23. BEGIN_MESSAGE_MAP(CDiffView, CRichEditView)
  24.     ON_WM_CONTEXTMENU()
  25.     //{{AFX_MSG_MAP(CDiffView)
  26.     ON_WM_DROPFILES()
  27.     ON_WM_RBUTTONUP()
  28.     ON_COMMAND(ID_EDIT_FONT, OnEditFont)
  29.     ON_COMMAND(IDC_EDIT_COLOR_BACKGROUND, OnEditColorBackground)
  30.     ON_COMMAND(IDC_EDIT_COLOR_FOREGROUND, OnEditColorForeground)
  31.     //}}AFX_MSG_MAP
  32.     // Standard printing commands
  33.     ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  34.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  35.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  36. END_MESSAGE_MAP()
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CDiffView construction/destruction
  40.  
  41. CDiffView::CDiffView()
  42. {
  43.     m_BackgroundColor = RGB(255, 255, 255);  // white
  44.     m_ForegroundColor = RGB(0, 0, 255);            //black
  45. }
  46.  
  47. CDiffView::~CDiffView()
  48. {
  49. }
  50.  
  51. BOOL CDiffView::PreCreateWindow(CREATESTRUCT& cs)
  52. {
  53.     // TODO: Modify the Window class or styles here by modifying
  54.     //  the CREATESTRUCT cs
  55.  
  56.     return CRichEditView::PreCreateWindow(cs);
  57. }
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CDiffView drawing
  61.  
  62. void CDiffView::OnDraw(CDC* pDC)
  63. {
  64.     CDiffDoc* pDoc = GetDocument();
  65.     ASSERT_VALID(pDoc);
  66.  
  67.     // TODO: add draw code for native data here
  68. }
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CDiffView printing
  72.  
  73. BOOL CDiffView::OnPreparePrinting(CPrintInfo* pInfo)
  74. {
  75.     // default preparation
  76.     return DoPreparePrinting(pInfo);
  77. }
  78.  
  79. void CDiffView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  80. {
  81.     // TODO: add extra initialization before printing
  82. }
  83.  
  84. void CDiffView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  85. {
  86.     // TODO: add cleanup after printing
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CDiffView diagnostics
  91.  
  92. #ifdef _DEBUG
  93. void CDiffView::AssertValid() const
  94. {
  95.     CRichEditView::AssertValid();
  96. }
  97.  
  98. void CDiffView::Dump(CDumpContext& dc) const
  99. {
  100.     CRichEditView::Dump(dc);
  101. }
  102.  
  103. CDiffDoc* CDiffView::GetDocument() // non-debug version is inline
  104. {
  105.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDiffDoc)));
  106.     return (CDiffDoc*)m_pDocument;
  107. }
  108. #endif //_DEBUG
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CDiffView message handlers
  112.  
  113. void CDiffView::OnInitialUpdate() 
  114. {
  115.     CRichEditView::OnInitialUpdate();
  116.     
  117.     GetRichEditCtrl().SetReadOnly();
  118. }
  119.  
  120. void CDiffView::OnDropFiles(HDROP hDropInfo) 
  121. {
  122.     CDiffApp::GetApp()->GetMainFrame()->
  123.         SendMessage ( WM_DROPFILES,
  124.                       (WPARAM)hDropInfo);
  125.     //Don't call the default -- we don't want OLE
  126.     //embedding behavior    
  127.     //CRichEditView::OnDropFiles(hDropInfo);
  128. }
  129.  
  130. void CDiffView::OnContextMenu(CWnd *pWnd, CPoint point)
  131. {
  132.     UNUSED_ALWAYS (pWnd);    CMenu menu;
  133.     VERIFY(menu.LoadMenu(IDR_POPUP_DIFF_VIEW));
  134.  
  135.     CMenu* pPopup = menu.GetSubMenu(0);
  136.     ASSERT(pPopup != NULL);
  137.  
  138.     if (pPopup != NULL)
  139.         pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
  140. }
  141.  
  142. void CDiffView::OnRButtonUp(UINT nFlags, CPoint point) 
  143. {
  144.     //CRichEditView::OnRButtonUp(nFlags, point);
  145.     ClientToScreen (&point);
  146.     OnContextMenu ((CWnd *)NULL, point);
  147. }
  148.  
  149. void CDiffView::OnEditFont() 
  150. {
  151.     GetRichEditCtrl().GetDefaultCharFormat(m_CharacterFormat);
  152.  
  153.     CFontDialog dlg(m_CharacterFormat,CF_SCREENFONTS);
  154.  
  155.     if (dlg.DoModal() == IDOK)
  156.     {
  157.         dlg.GetCharFormat(m_CharacterFormat);
  158.         GetRichEditCtrl().SetDefaultCharFormat(m_CharacterFormat);
  159.     }
  160. }
  161.  
  162. void CDiffView::OnEditColorBackground() 
  163. {
  164.     CColorDialog dlg(m_BackgroundColor);
  165.  
  166.     if (IDOK == dlg.DoModal())
  167.     {
  168.         m_BackgroundColor = dlg.GetColor();
  169.         GetRichEditCtrl().SetBackgroundColor(FALSE, m_BackgroundColor);
  170.     }    
  171. }
  172.  
  173. void CDiffView::OnEditColorForeground() 
  174. {
  175.     GetRichEditCtrl().GetDefaultCharFormat(m_CharacterFormat);
  176.     m_CharacterFormat.crTextColor = m_ForegroundColor;
  177.     CColorDialog dlg(m_CharacterFormat.crTextColor);
  178.  
  179.     if (IDOK == dlg.DoModal())
  180.     {
  181.         m_CharacterFormat.crTextColor = dlg.GetColor();
  182.         m_CharacterFormat.dwEffects = 0;
  183.         m_CharacterFormat.dwMask = CFM_COLOR;
  184.         m_ForegroundColor = m_CharacterFormat.crTextColor;
  185.         GetRichEditCtrl().SetDefaultCharFormat(m_CharacterFormat);
  186.     }    
  187. }
  188.