home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / servdemo / servdevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  4.6 KB  |  182 lines

  1. // ServDeVw.cpp : implementation of the CServDemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ServDemo.h"
  6.  
  7. #include "ServDDoc.h"
  8. #include "ServDeVw.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CServDemoView
  18.  
  19. IMPLEMENT_DYNCREATE(CServDemoView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CServDemoView, CView)
  22.    //{{AFX_MSG_MAP(CServDemoView)
  23.    ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
  24.    ON_WM_LBUTTONDOWN()
  25.    ON_WM_MOUSEMOVE()
  26.    ON_WM_LBUTTONUP()
  27.    ON_WM_SIZE()
  28.    //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CServDemoView construction/destruction
  33.  
  34. CServDemoView::CServDemoView()
  35. {
  36.    // TODO: add construction code here
  37.    m_Dragging = 0;
  38.    m_HCross = AfxGetApp ()->LoadStandardCursor (IDC_CROSS);
  39. }
  40.  
  41. CServDemoView::~CServDemoView()
  42. {
  43. }
  44.  
  45. BOOL CServDemoView::PreCreateWindow(CREATESTRUCT& cs)
  46. {
  47.    // TODO: Modify the Window class or styles here by modifying
  48.    //  the CREATESTRUCT cs
  49.  
  50.    m_ClassName = AfxRegisterWndClass
  51.       (CS_HREDRAW | CS_VREDRAW,                // class styles
  52.       0,                                       // no cursor
  53.       (HBRUSH)::GetStockObject (WHITE_BRUSH),  // assign white background brush
  54.       0);                                      // no icon
  55.    cs.lpszClass = m_ClassName;      
  56.  
  57.    return CView::PreCreateWindow(cs);
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CServDemoView drawing
  62.  
  63. void CServDemoView::OnDraw(CDC* pDC)
  64. {
  65.    CServDemoDoc* pDoc = GetDocument();
  66.    ASSERT_VALID(pDoc);
  67.  
  68.    // TODO: add draw code for native data here
  69.  
  70.    int Index = pDoc->GetNumLines ();
  71.    while (Index--)
  72.       pDoc->GetLine (Index)->Draw (pDC);      
  73.  
  74.    pDoc->UpdateAllItems (0);
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // OLE Server support
  79.  
  80. // The following command handler provides the standard keyboard
  81. //  user interface to cancel an in-place editing session.  Here,
  82. //  the server (not the container) causes the deactivation.
  83. void CServDemoView::OnCancelEditSrvr()
  84. {
  85.    GetDocument()->OnDeactivateUI(FALSE);
  86. }
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CServDemoView diagnostics
  90.  
  91. #ifdef _DEBUG
  92. void CServDemoView::AssertValid() const
  93. {
  94.    CView::AssertValid();
  95. }
  96.  
  97. void CServDemoView::Dump(CDumpContext& dc) const
  98. {
  99.    CView::Dump(dc);
  100. }
  101.  
  102. CServDemoDoc* CServDemoView::GetDocument() // non-debug version is inline
  103. {
  104.    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CServDemoDoc)));
  105.    return (CServDemoDoc*)m_pDocument;
  106. }
  107. #endif //_DEBUG
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CServDemoView message handlers
  111.  
  112. void CServDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
  113. {
  114.    // TODO: Add your message handler code here and/or call default
  115.    
  116.    m_PointOrigin = point;
  117.    m_PointOld = point;
  118.    SetCapture ();
  119.    m_Dragging = 1;
  120.    
  121.    RECT Rect;
  122.    GetClientRect (&Rect);
  123.    ClientToScreen (&Rect);
  124.    ::ClipCursor (&Rect);
  125.  
  126.    CView::OnLButtonDown(nFlags, point);
  127. }
  128.  
  129. void CServDemoView::OnMouseMove(UINT nFlags, CPoint point) 
  130. {
  131.    // TODO: Add your message handler code here and/or call default
  132.  
  133.    ::SetCursor (m_HCross);
  134.  
  135.    if (m_Dragging)
  136.       {
  137.       CClientDC ClientDC (this);
  138.       ClientDC.SetROP2 (R2_NOT);
  139.       ClientDC.MoveTo (m_PointOrigin);
  140.       ClientDC.LineTo (m_PointOld);
  141.       ClientDC.MoveTo (m_PointOrigin);
  142.       ClientDC.LineTo (point);
  143.       m_PointOld = point;
  144.       } 
  145.    
  146.    CView::OnMouseMove(nFlags, point);
  147. }
  148.  
  149. void CServDemoView::OnLButtonUp(UINT nFlags, CPoint point) 
  150. {
  151.    // TODO: Add your message handler code here and/or call default
  152.    
  153.    if (m_Dragging)
  154.       {
  155.       m_Dragging = 0;
  156.       ::ReleaseCapture ();
  157.       ::ClipCursor (NULL);
  158.       CClientDC ClientDC (this);
  159.       ClientDC.SetROP2 (R2_NOT);
  160.       ClientDC.MoveTo (m_PointOrigin);
  161.       ClientDC.LineTo (m_PointOld);
  162.       ClientDC.SetROP2 (R2_COPYPEN);
  163.       ClientDC.MoveTo (m_PointOrigin);
  164.       ClientDC.LineTo (point);      
  165.  
  166.       CServDemoDoc* PDoc = GetDocument();
  167.       PDoc->AddLine (m_PointOrigin.x, m_PointOrigin.y, point.x, point.y);
  168.       PDoc->UpdateAllItems (0);
  169.       }   
  170.  
  171.    CView::OnLButtonUp(nFlags, point);
  172. }
  173.  
  174. void CServDemoView::OnSize(UINT nType, int cx, int cy) 
  175. {
  176.    CView::OnSize(nType, cx, cy);
  177.    
  178.    // TODO: Add your message handler code here
  179.    m_ViewSize.cx = cx;
  180.    m_ViewSize.cy = cy;
  181. }
  182.