// LessonA06View.cpp : implementation of the CLessonA06View class
//

#include "stdafx.h"
#include "LessonA06.h"

#include "LessonA06Doc.h"
#include "LessonA06View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLessonA06View

IMPLEMENT_DYNCREATE(CLessonA06View, CView)

BEGIN_MESSAGE_MAP(CLessonA06View, CView)
	//{{AFX_MSG_MAP(CLessonA06View)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_MOUSEMOVE()
	ON_WM_CONTEXTMENU()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CLessonA06View construction/destruction

CLessonA06View::CLessonA06View()
{
	// TODO: add construction code here

}

CLessonA06View::~CLessonA06View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLessonA06View drawing

void CLessonA06View::OnDraw(CDC* pDC)
{
	CLessonA06Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	m_Chart1.OnDraw(pDC->m_hDC);
	m_Chart2.OnDraw(pDC->m_hDC);
}

/////////////////////////////////////////////////////////////////////////////
// CLessonA06View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLessonA06View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLessonA06View message handlers

int CLessonA06View::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_Chart1.CreateChart(kTypePie);
	m_Chart1.AddPie(4, "Íõ·Æ");
	m_Chart1.AddPie(3, "ÕÅ°ØÖ¥");
	m_Chart1.AddPie(2, "Irene");

	m_Chart2.CreateChart(kTypeContour);
	m_Chart2.SetContourByPoints();
	m_Chart2.AddContourPoint(-1, -1, 5);
	m_Chart2.AddContourPoint(-1, 1, 5);
	m_Chart2.AddContourPoint(1, -1, 5);
	m_Chart2.AddContourPoint(1, 1, 5);
	m_Chart2.AddContourPoint(-1, 0, -5);
	m_Chart2.AddContourPoint(0, -1, -5);
	m_Chart2.AddContourPoint(1, 0, -5);
	m_Chart2.AddContourPoint(0, 1, -5);
	m_Chart2.AddContourPoint(0, 0, 10);
	m_Chart2.SetPlotRange(-1.5, 1.5, -1.5, 1.5);
	m_Chart2.SetContourPrecision(8);
	m_Chart2.SetContourLineNum(10);
	m_Chart2.SetLegendShow(false);
	
	return 0;
}

void CLessonA06View::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	CRect rect;
	GetClientRect(&rect);
	CRect rt1, rt2;
	rt1 = rect;
	rt1.right = (rect.left + rect.right)/2;
	m_Chart1.SetConfineRect(rt1);
	rt2 = rect;
	rt2.left = (rect.left + rect.right)/2;
	m_Chart2.SetConfineRect(rt2);
}

void CLessonA06View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_Chart1.OnLButtonDownR(m_hWnd, point, nFlags);
	m_Chart2.OnLButtonDownR(m_hWnd, point, nFlags);
}

void CLessonA06View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_Chart1.OnLButtonUpR(m_hWnd, point, nFlags);
	m_Chart2.OnLButtonUpR(m_hWnd, point, nFlags);
}

void CLessonA06View::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_Chart1.OnLButtonDblClkR(m_hWnd, point, nFlags);
	m_Chart2.OnLButtonDblClkR(m_hWnd, point, nFlags);
}

void CLessonA06View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_Chart1.OnMouseMoveR(m_hWnd, point, nFlags);
	m_Chart2.OnMouseMoveR(m_hWnd, point, nFlags);
}

void CLessonA06View::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
	m_Chart1.OnContextMenuR(NULL, m_hWnd, point);
	m_Chart2.OnContextMenuR(NULL, m_hWnd, point);
}

BOOL CLessonA06View::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
	//return CView::OnEraseBkgnd(pDC);
}
