home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c06 / lab05 / baseline / diffview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.6 KB  |  189 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 "FindDiff.h"
  12. #include "mainfrm.h"
  13. #include "resource.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDiffView
  21.  
  22. IMPLEMENT_DYNCREATE(CDiffView, CRichEditView)
  23.  
  24. BEGIN_MESSAGE_MAP(CDiffView, CRichEditView)
  25.     ON_WM_CONTEXTMENU()
  26.     //{{AFX_MSG_MAP(CDiffView)
  27.     ON_WM_DROPFILES()
  28.     ON_WM_RBUTTONUP()
  29.     ON_COMMAND(ID_EDIT_FONT, OnEditFont)
  30.     ON_COMMAND(IDC_EDIT_COLOR_BACKGROUND, OnEditColorBackground)
  31.     ON_COMMAND(IDC_EDIT_COLOR_FOREGROUND, OnEditColorForeground)
  32.     //}}AFX_MSG_MAP
  33.     // Standard printing commands
  34.     ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  35.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  36.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CDiffView construction/destruction
  41.  
  42. CDiffView::CDiffView()
  43. {
  44.     m_BackgroundColor = RGB(255, 255, 255);  // white
  45.     m_ForegroundColor = RGB(0, 0, 255);            //black
  46. }
  47.  
  48. CDiffView::~CDiffView()
  49. {
  50. }
  51.  
  52. BOOL CDiffView::PreCreateWindow(CREATESTRUCT& cs)
  53. {
  54.     // TODO: Modify the Window class or styles here by modifying
  55.     //  the CREATESTRUCT cs
  56.  
  57.     return CRichEditView::PreCreateWindow(cs);
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CDiffView drawing
  62.  
  63. void CDiffView::OnDraw(CDC* pDC)
  64. {
  65.     CDiffDoc* pDoc = GetDocument();
  66.     ASSERT_VALID(pDoc);
  67.  
  68.     // TODO: add draw code for native data here
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CDiffView printing
  73.  
  74. BOOL CDiffView::OnPreparePrinting(CPrintInfo* pInfo)
  75. {
  76.     // default preparation
  77.     return DoPreparePrinting(pInfo);
  78. }
  79.  
  80. void CDiffView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add extra initialization before printing
  83. }
  84.  
  85. void CDiffView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  86. {
  87.     // TODO: add cleanup after printing
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CDiffView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CDiffView::AssertValid() const
  95. {
  96.     CRichEditView::AssertValid();
  97. }
  98.  
  99. void CDiffView::Dump(CDumpContext& dc) const
  100. {
  101.     CRichEditView::Dump(dc);
  102. }
  103.  
  104. CDiffDoc* CDiffView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDiffDoc)));
  107.     return (CDiffDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CDiffView message handlers
  113.  
  114. void CDiffView::OnInitialUpdate() 
  115. {
  116.     CRichEditView::OnInitialUpdate();
  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, 
  140.                                 point.x, point.y, this);
  141. }
  142.  
  143. void CDiffView::OnRButtonUp(UINT nFlags, CPoint point) 
  144. {
  145.     //CRichEditView::OnRButtonUp(nFlags, point);
  146.     ClientToScreen (&point);
  147.     OnContextMenu ((CWnd *)NULL, point);
  148. }
  149.  
  150. void CDiffView::OnEditFont() 
  151. {
  152.     GetRichEditCtrl().GetDefaultCharFormat(m_CharacterFormat);
  153.  
  154.     CFontDialog dlg(m_CharacterFormat,CF_SCREENFONTS);
  155.  
  156.     if (dlg.DoModal() == IDOK)
  157.     {
  158.         dlg.GetCharFormat(m_CharacterFormat);
  159.         GetRichEditCtrl().SetDefaultCharFormat(m_CharacterFormat);
  160.     }
  161. }
  162.  
  163. void CDiffView::OnEditColorBackground() 
  164. {
  165.     CColorDialog dlg(m_BackgroundColor);
  166.  
  167.     if (dlg.DoModal() == IDOK)
  168.     {
  169.         m_BackgroundColor = dlg.GetColor();
  170.         GetRichEditCtrl().SetBackgroundColor(FALSE, m_BackgroundColor);
  171.     }
  172. }
  173.  
  174. void CDiffView::OnEditColorForeground() 
  175. {
  176.     GetRichEditCtrl().GetDefaultCharFormat(m_CharacterFormat);
  177.     m_CharacterFormat.crTextColor = m_ForegroundColor;
  178.     CColorDialog dlg(m_CharacterFormat.crTextColor);
  179.  
  180.     if (dlg.DoModal() == IDOK)
  181.     {
  182.         m_CharacterFormat.crTextColor = dlg.GetColor();
  183.         m_ForegroundColor = m_CharacterFormat.crTextColor;
  184.         m_CharacterFormat.dwEffects = 0;
  185.         m_CharacterFormat.dwMask = CFM_COLOR;
  186.         GetRichEditCtrl().SetDefaultCharFormat(m_CharacterFormat);
  187.     }
  188. }
  189.