// mymfc11View.cpp : implementation of the CMymfc11View class
//

#include "stdafx.h"
#include "mymfc11.h"

#include "mymfc11Doc.h"
#include "mymfc11View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMymfc11View

IMPLEMENT_DYNCREATE(CMymfc11View, CView)

BEGIN_MESSAGE_MAP(CMymfc11View, CView)
	//{{AFX_MSG_MAP(CMymfc11View)
	ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
	ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
	ON_COMMAND(ID_DRAW_PATTERN, OnDrawPattern)
	ON_UPDATE_COMMAND_UI(ID_DRAW_PATTERN, OnUpdateDrawPattern)
	ON_COMMAND(ID_DRAW_SQUARE, OnDrawSquare)
	ON_UPDATE_COMMAND_UI(ID_DRAW_SQUARE, OnUpdateDrawSquare)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMymfc11View construction/destruction

CMymfc11View::CMymfc11View() : m_rect(0, 0, 100, 100)
{
	// TODO: add construction code here
	m_bCircle = TRUE;
    m_bPattern = FALSE;
}

CMymfc11View::~CMymfc11View()
{
}

BOOL CMymfc11View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMymfc11View drawing

void CMymfc11View::OnDraw(CDC* pDC)
{
	// TODO: add draw code for native data here
	// brush with diagonal pattern 
    CBrush brush(HS_BDIAGONAL, 0L);

    if (m_bPattern)
    {
        pDC->SelectObject(&brush);
    }
    else
    {
        pDC->SelectStockObject(WHITE_BRUSH);
    }
    if (m_bCircle)
    {
        pDC->Ellipse(m_rect);
    }
    else {
        pDC->Rectangle(m_rect);
    }
    // Deselects brush if selected
    pDC->SelectStockObject(WHITE_BRUSH);
}

/////////////////////////////////////////////////////////////////////////////
// CMymfc11View diagnostics

#ifdef _DEBUG
void CMymfc11View::AssertValid() const
{
	CView::AssertValid();
}

void CMymfc11View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMymfc11Doc* CMymfc11View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMymfc11Doc)));
	return (CMymfc11Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMymfc11View message handlers

void CMymfc11View::OnDrawCircle() 
{
	// TODO: Add your command handler code here
	m_bCircle = TRUE;
    m_rect += CPoint(25, 25);
    InvalidateRect(m_rect);
}

void CMymfc11View::OnUpdateDrawCircle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bCircle);	
}

void CMymfc11View::OnDrawPattern() 
{
	// TODO: Add your command handler code here
	m_bPattern ^= 1;	
}

void CMymfc11View::OnUpdateDrawPattern(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bPattern);
}

void CMymfc11View::OnDrawSquare() 
{
	// TODO: Add your command handler code here
	m_bCircle = FALSE;
    m_rect += CPoint(25, 25);
    InvalidateRect(m_rect);
}

void CMymfc11View::OnUpdateDrawSquare(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_bCircle);	
}

