home *** CD-ROM | disk | FTP | other *** search
- // MiniDrVw.cpp : implementation of the CMiniDrawView class
- //
-
- #include "stdafx.h"
- #include "MiniDraw.h"
-
- #include "MiniDDoc.h"
- #include "MiniDrVw.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView
-
- IMPLEMENT_DYNCREATE(CMiniDrawView, CScrollView)
-
- BEGIN_MESSAGE_MAP(CMiniDrawView, CScrollView)
- //{{AFX_MSG_MAP(CMiniDrawView)
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView construction/destruction
-
- CMiniDrawView::CMiniDrawView()
- {
- // TODO: add construction code here
-
- m_Dragging = 0;
- m_HArrow = AfxGetApp ()->LoadStandardCursor (IDC_ARROW);
- m_HCross = AfxGetApp ()->LoadStandardCursor (IDC_CROSS);
- }
-
- CMiniDrawView::~CMiniDrawView()
- {
- }
-
- BOOL CMiniDrawView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- m_ClassName = AfxRegisterWndClass
- (CS_HREDRAW | CS_VREDRAW, // class styles
- 0, // no cursor
- (HBRUSH)::GetStockObject (WHITE_BRUSH), // assign white background brush
- 0); // no icon
- cs.lpszClass = m_ClassName;
-
- return CScrollView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView drawing
-
- void CMiniDrawView::OnDraw(CDC* pDC)
- {
- CMiniDrawDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
-
- CSize ScrollSize = GetTotalSize ();
- pDC->MoveTo (ScrollSize.cx, 0);
- pDC->LineTo (ScrollSize.cx, ScrollSize.cy);
- pDC->LineTo (0, ScrollSize.cy);
-
- CRect ClipRect;
- CRect DimRect;
- CRect IntRect;
- CLine *PLine;
- pDC->GetClipBox (&ClipRect);
-
- int Index = pDoc->GetNumLines ();
- while (Index--)
- {
- PLine = pDoc->GetLine (Index);
- DimRect = PLine->GetDimRect ();
- if (IntRect.IntersectRect (DimRect, ClipRect))
- PLine->Draw (pDC);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView diagnostics
-
- #ifdef _DEBUG
- void CMiniDrawView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
-
- void CMiniDrawView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
-
- CMiniDrawDoc* CMiniDrawView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMiniDrawDoc)));
- return (CMiniDrawDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView message handlers
-
- void CMiniDrawView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- CClientDC ClientDC (this);
- OnPrepareDC (&ClientDC);
- ClientDC.DPtoLP (&point);
-
- // test whether cursor is within drawing area of view window:
- CSize ScrollSize = GetTotalSize ();
- CRect ScrollRect (0, 0, ScrollSize.cx, ScrollSize.cy);
- if (!ScrollRect.PtInRect (point))
- return;
-
- // save cursor position, capture mouse, & set dragging flag:
- m_PointOrigin = point;
- m_PointOld = point;
- SetCapture ();
- m_Dragging = 1;
-
- // clip mouse cursor:
- ClientDC.LPtoDP (&ScrollRect);
- CRect ViewRect;
- GetClientRect (&ViewRect);
- CRect IntRect;
- IntRect.IntersectRect (&ScrollRect, &ViewRect);
- ClientToScreen (&IntRect);
- ::ClipCursor (&IntRect);
-
- CScrollView::OnLButtonDown(nFlags, point);
- }
-
- void CMiniDrawView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- CClientDC ClientDC (this);
- OnPrepareDC (&ClientDC);
- ClientDC.DPtoLP (&point);
-
- CSize ScrollSize = GetTotalSize ();
- CRect ScrollRect (0, 0, ScrollSize.cx, ScrollSize.cy);
- if (ScrollRect.PtInRect (point))
- ::SetCursor (m_HCross);
- else
- ::SetCursor (m_HArrow);
-
- if (m_Dragging)
- {
- ClientDC.SetROP2 (R2_NOT);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (m_PointOld);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (point);
- m_PointOld = point;
- }
-
- CScrollView::OnMouseMove(nFlags, point);
- }
-
- void CMiniDrawView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- if (m_Dragging)
- {
- m_Dragging = 0;
- ::ReleaseCapture ();
- ::ClipCursor (NULL);
-
- CClientDC ClientDC (this);
- OnPrepareDC (&ClientDC);
- ClientDC.DPtoLP (&point);
-
- ClientDC.SetROP2 (R2_NOT);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (m_PointOld);
- ClientDC.SetROP2 (R2_COPYPEN);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (point);
-
- CMiniDrawDoc* PDoc = GetDocument();
- CLine *PCLine;
- PCLine = PDoc->AddLine (m_PointOrigin.x, m_PointOrigin.y,
- point.x, point.y);
- PDoc->UpdateAllViews (this, 0, PCLine);
- }
-
- CScrollView::OnLButtonUp(nFlags, point);
- }
-
- void CMiniDrawView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
-
- // TODO: Add your specialized code here and/or call the base class
-
- SIZE Size = {640, 480};
- SetScrollSizes (MM_TEXT, Size);
- }
-
- void CMiniDrawView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- if (pHint != 0)
- {
- CRect InvalidRect = ((CLine *)pHint)->GetDimRect ();
- CClientDC ClientDC (this);
- OnPrepareDC (&ClientDC);
- ClientDC.LPtoDP (&InvalidRect);
- InvalidateRect (&InvalidRect);
- }
- else
- CScrollView::OnUpdate (pSender, lHint, pHint);
- }
-