// sktchView.cpp : implementation of the CSktchView class
//
#include "stdafx.h"
#include "sktch.h"
#include "sktchDoc.h"
#include "sktchView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSktchView
IMPLEMENT_DYNCREATE(CSktchView, CView)
BEGIN_MESSAGE_MAP(CSktchView, CView)
//{{AFX_MSG_MAP(CSktchView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSktchView construction/destruction
CSktchView::CSktchView()
{
// TODO: add construction code here
m_butdn=FALSE;
}
CSktchView::~CSktchView()
{
}
BOOL CSktchView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSktchView drawing
void CSktchView::OnDraw(CDC* pDC)
{
CSktchDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int numlines=pDoc->GetLineCount();
if(numlines>0)
{
CLine *ptLine;
for (int i=0; i<numlines; i++)
{
ptLine=pDoc->GetLine(i);
ptLine->Draw(pDC);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CSktchView printing
BOOL CSktchView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSktchView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSktchView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSktchView diagnostics
#ifdef _DEBUG
void CSktchView::AssertValid() const
{
CView::AssertValid();
}
void CSktchView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSktchDoc* CSktchView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSktchDoc)));
return (CSktchDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSktchView message handlers
void CSktchView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_butdn=TRUE;
m_ptPrevPos=point;
CView::OnLButtonDown(nFlags, point);
}
void CSktchView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_butdn=FALSE;
CView::OnLButtonUp(nFlags, point);
}
void CSktchView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_butdn)
{
CClientDC dc(this);
CLine* pLine=GetDocument()->AddLine(m_ptPrevPos,point);
pLine->Draw(&dc);
m_ptPrevPos=point;
}
CView::OnMouseMove(nFlags, point);
}