home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c05 / lab04 / ex01 / diffview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.1 KB  |  180 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 "splitter.h"
  10. #include "mainfrm.h"
  11. #include "resource.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CDiffView
  19.  
  20. IMPLEMENT_DYNCREATE(CDiffView, CRichEditView)
  21.  
  22. BEGIN_MESSAGE_MAP(CDiffView, CRichEditView)
  23.     ON_WM_CONTEXTMENU()
  24.     //{{AFX_MSG_MAP(CDiffView)
  25.     ON_WM_DROPFILES()
  26.     ON_WM_RBUTTONUP()
  27.     ON_COMMAND(ID_EDIT_FONT, OnEditFont)
  28.     ON_COMMAND(ID_EDIT_COLOR_FOREGROUND, OnEditColorForeground)
  29.     ON_COMMAND(ID_EDIT_COLOR_BACKGROUND, OnEditColorBackground)
  30.     //}}AFX_MSG_MAP
  31.     // Standard printing commands
  32.     ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  33.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  34.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  35. END_MESSAGE_MAP()
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CDiffView construction/destruction
  39.  
  40. CDiffView::CDiffView()
  41. {
  42.     // TODO: add construction code here
  43.  
  44. }
  45.  
  46. CDiffView::~CDiffView()
  47. {
  48. }
  49.  
  50. BOOL CDiffView::PreCreateWindow(CREATESTRUCT& cs)
  51. {
  52.     // TODO: Modify the Window class or styles here by modifying
  53.     //  the CREATESTRUCT cs
  54.  
  55.     return CRichEditView::PreCreateWindow(cs);
  56. }
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CDiffView drawing
  60.  
  61. void CDiffView::OnDraw(CDC* pDC)
  62. {
  63.     CDiffDoc* pDoc = GetDocument();
  64.     ASSERT_VALID(pDoc);
  65.  
  66.     // TODO: add draw code for native data here
  67. }
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CDiffView printing
  71.  
  72. BOOL CDiffView::OnPreparePrinting(CPrintInfo* pInfo)
  73. {
  74.     // default preparation
  75.     return DoPreparePrinting(pInfo);
  76. }
  77.  
  78. void CDiffView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  79. {
  80.     // TODO: add extra initialization before printing
  81. }
  82.  
  83. void CDiffView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  84. {
  85.     // TODO: add cleanup after printing
  86. }
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CDiffView diagnostics
  90.  
  91. #ifdef _DEBUG
  92. void CDiffView::AssertValid() const
  93. {
  94.     CRichEditView::AssertValid();
  95. }
  96.  
  97. void CDiffView::Dump(CDumpContext& dc) const
  98. {
  99.     CRichEditView::Dump(dc);
  100. }
  101.  
  102. CDiffDoc* CDiffView::GetDocument() // non-debug version is inline
  103. {
  104.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDiffDoc)));
  105.     return (CDiffDoc*)m_pDocument;
  106. }
  107. #endif //_DEBUG
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CDiffView message handlers
  111.  
  112. void CDiffView::OnInitialUpdate() 
  113. {
  114.     CRichEditView::OnInitialUpdate();
  115.     
  116.     GetRichEditCtrl().SetReadOnly();
  117.     
  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*, CPoint point)
  131. {
  132.       // CG: This block was added by the Pop-up Menu component
  133.     {
  134.         if (point.x == -1 && point.y == -1){
  135.             //keystroke invocation
  136.             CRect rect;
  137.             GetClientRect(rect);
  138.             ClientToScreen(rect);
  139.  
  140.             point = rect.TopLeft();
  141.             point.Offset(5, 5);
  142.         }
  143.  
  144.         CMenu menu;
  145.         VERIFY(menu.LoadMenu(CG_IDR_POPUP_DIFF_VIEW));
  146.  
  147.         CMenu* pPopup = menu.GetSubMenu(0);
  148.         ASSERT(pPopup != NULL);
  149.         CWnd* pWndPopupOwner = this;
  150.  
  151.         while (pWndPopupOwner->GetStyle() & WS_CHILD)
  152.             pWndPopupOwner = pWndPopupOwner->GetParent();
  153.  
  154.         pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
  155.             pWndPopupOwner);
  156.     }
  157. }
  158.  
  159. void CDiffView::OnRButtonUp(UINT nFlags, CPoint point) 
  160. {
  161.     // CRichEditView::OnRButtonUp(nFlags, point);
  162.     ClientToScreen(&point);
  163.     OnContextMenu((CWnd *)NULL, point);
  164. }
  165.  
  166. void CDiffView::OnEditFont() 
  167. {
  168.     AfxMessageBox("In OnEditFont()");
  169. }
  170.  
  171. void CDiffView::OnEditColorForeground() 
  172. {
  173.     AfxMessageBox("In OnEditColorForeround()");
  174. }
  175.  
  176. void CDiffView::OnEditColorBackground() 
  177. {
  178.     AfxMessageBox("In OnEditColorBackground()");
  179. }
  180.