// BemSolveView.cpp : implementation of the CBemSolveView class
//

#include "stdafx.h"
#include "BemSolve.h"

#include "BemSolveDoc.h"
#include "BemSolveView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBemSolveView

IMPLEMENT_DYNCREATE(CBemSolveView, CScrollView)

BEGIN_MESSAGE_MAP(CBemSolveView, CScrollView)
	//{{AFX_MSG_MAP(CBemSolveView)
	ON_COMMAND(ID_VIEW_ELEMS, OnViewElems)
	ON_COMMAND(ID_VIEW_RES_EL, OnViewResEl)
	ON_COMMAND(ID_VIEW_RES_INT, OnViewResInt)
	ON_COMMAND(ID_VIEW_RES_WELL, OnViewResWell)
	ON_UPDATE_COMMAND_UI(ID_VIEW_ELEMS, OnUpdateViewElems)
	ON_UPDATE_COMMAND_UI(ID_VIEW_RES_EL, OnUpdateViewResEl)
	ON_UPDATE_COMMAND_UI(ID_VIEW_RES_INT, OnUpdateViewResInt)
	ON_UPDATE_COMMAND_UI(ID_VIEW_RES_WELL, OnUpdateViewResWell)
	ON_COMMAND(ID_VIEW_WELLS, OnViewWells)
	ON_UPDATE_COMMAND_UI(ID_VIEW_WELLS, OnUpdateViewWells)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBemSolveView construction/destruction

CBemSolveView::CBemSolveView()
{
	IsElemI=IsElemO=IsWellI=IsWellO=IsPointO=FALSE;
}

CBemSolveView::~CBemSolveView()
{
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBemSolveView drawing

void CBemSolveView::OnDraw(CDC* pDC)
{
	CBemSolveDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	int iy;
	pDC->SetMapMode(MM_TWIPS);
	iy=-pDoc->bount;
	if (IsElemI)
	{
		iy=pDoc->PrintElem(*pDC,iy);
		iy-=360;
	}
	if (IsWellI)
	{
		iy=pDoc->PrintWell(*pDC,iy);
		iy-=360;
	}
	if (IsElemO)
	{
		iy=pDoc->PrintElemR(*pDC,iy);
		iy-=360;
	}
	if (IsWellO) 
	{
		iy=pDoc->PrintWellR(*pDC,iy);
		iy-=360;
	}
	if (IsPointO) 
	{
		iy=pDoc->PrintIntR(*pDC,iy);
		iy-=360;
	}
	CSize sz;sz.cx=100;sz.cy=-iy;
	SetScrollSizes (MM_TWIPS,sz);
}

void CBemSolveView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CBemSolveView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CBemSolveView diagnostics

#ifdef _DEBUG
void CBemSolveView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CBemSolveView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CBemSolveView message handlers

void CBemSolveView::OnViewElems() 
{
	if (IsElemI) IsElemI=FALSE;	
	else IsElemI=TRUE;
	Invalidate();
}

void CBemSolveView::OnViewResEl() 
{
	if (IsElemO) IsElemO=FALSE;	
	else IsElemO=TRUE;
	Invalidate();
}

void CBemSolveView::OnViewResInt() 
{
	if (IsPointO) IsPointO=FALSE;	
	else IsPointO=TRUE;
	Invalidate();
}

void CBemSolveView::OnViewResWell() 
{
	if (IsWellO) IsWellO=FALSE;	
	else IsWellO=TRUE;
	Invalidate();
}

void CBemSolveView::OnUpdateViewElems(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(IsElemI);	
}

void CBemSolveView::OnUpdateViewResEl(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(IsElemO);	
}

void CBemSolveView::OnUpdateViewResInt(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(IsPointO);	
}

void CBemSolveView::OnUpdateViewResWell(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(IsWellO);	
}

void CBemSolveView::OnViewWells() 
{
	if (IsWellI) IsWellI=FALSE;	
	else IsWellI=TRUE;
	Invalidate();
}

void CBemSolveView::OnUpdateViewWells(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(IsWellI);	
}
