// RajzoloView.cpp : implementation of the CRajzoloView class
//

#include "stdafx.h"
#include "Rajzolo.h"

#include "RajzoloDoc.h"
#include "RajzoloView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRajzoloView

IMPLEMENT_DYNCREATE(CRajzoloView, CView)

BEGIN_MESSAGE_MAP(CRajzoloView, CView)
	//{{AFX_MSG_MAP(CRajzoloView)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CRajzoloView construction/destruction

CRajzoloView::CRajzoloView()
{
	// TODO: add construction code here
	m_RajzMod = false;
	m_KeresztKurzor = 
		AfxGetApp()->LoadStandardCursor(IDC_CROSS);

}

CRajzoloView::~CRajzoloView()
{
}

BOOL CRajzoloView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CRajzoloView drawing

void CRajzoloView::OnDraw(CDC* pDC)
{
	CRajzoloDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CRajzoloView printing

BOOL CRajzoloView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CRajzoloView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CRajzoloView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CRajzoloView diagnostics

#ifdef _DEBUG
void CRajzoloView::AssertValid() const
{
	CView::AssertValid();
}

void CRajzoloView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CRajzoloDoc* CRajzoloView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRajzoloDoc)));
	return (CRajzoloDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CRajzoloView message handlers

void CRajzoloView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_StartPont = point;
	m_RegiPont = point;
	m_RajzMod = true;
	
	SetCapture();
	RECT Rect;
	GetClientRect(&Rect);
	ClientToScreen(&Rect);
	::ClipCursor(&Rect);
	
	CView::OnLButtonDown(nFlags, point);
}

void CRajzoloView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	::SetCursor(m_KeresztKurzor);
	if (m_RajzMod)
	{
		CClientDC dc(this);
		dc.SetROP2(R2_NOT);
		dc.MoveTo(m_StartPont);
		dc.LineTo(m_RegiPont);
		dc.MoveTo(m_StartPont);
		dc.LineTo(point);
		m_RegiPont = point;
	}
	CView::OnMouseMove(nFlags, point);
}

void CRajzoloView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if (m_RajzMod)
	{
		m_RajzMod = false;
		::ReleaseCapture();
		::ClipCursor(NULL);
		CClientDC dc(this);
		dc.SetROP2(R2_NOT);
		dc.MoveTo(m_StartPont);
		dc.LineTo(m_RegiPont);
		dc.SetROP2(R2_COPYPEN);
		dc.MoveTo(m_StartPont);
		dc.LineTo(point);
	}
	
	CView::OnLButtonUp(nFlags, point);
}
