Скачиваний:
11
Добавлен:
01.05.2014
Размер:
5.11 Кб
Скачать
// SketcherDoc.cpp : implementation of the CSketcherDoc class
//////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Sketcher.h"
#include "resource.h"
#include "SketcherDoc.h"

#include "TextRequest.h"
//////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSketcherDoc

IMPLEMENT_DYNCREATE(CSketcherDoc, CDocument)

BEGIN_MESSAGE_MAP(CSketcherDoc, CDocument)
	//{{AFX_MSG_MAP(CSketcherDoc)
	ON_COMMAND(ID_COLOR_BLACK, OnColorBlack)
	ON_COMMAND(ID_COLOR_RED, OnColorRed)
	ON_COMMAND(ID_ELEMENT_LINE, OnElementLine)
	ON_COMMAND(ID_ELEMENT_RECTANGLE, OnElementRectangle)
	ON_UPDATE_COMMAND_UI(ID_COLOR_BLACK, OnUpdateColorBlack)
	ON_UPDATE_COMMAND_UI(ID_COLOR_RED, OnUpdateColorRed)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_LINE, OnUpdateElementLine)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_RECTANGLE, OnUpdateElementRectangle)
	ON_COMMAND(ID_ELEMENT_OVAL, OnElementOval)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_OVAL, OnUpdateElementOval)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_TEXT, OnUpdateElementText)
	ON_COMMAND(ID_ELEMENT_TEXT, OnElementText)
	ON_COMMAND(ID_ELEMENT_TEXT_IN_OVAL, OnElementTextInOval)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_TEXT_IN_OVAL, OnUpdateElementTextInOval)
	ON_COMMAND(ID_ELEMENT_RIBBLE, OnElementRibble)
	ON_UPDATE_COMMAND_UI(ID_ELEMENT_RIBBLE, OnUpdateElementRibble)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSketcherDoc construction/destruction


CSketcherDoc::CSketcherDoc()
{
    m_DocSize = CSize(3000,3000);  // Set initial document size 30x30 inches
	// TODO: add one-time construction code here
    _shapeContainer = new ShapeContainer();
}


CSketcherDoc::~CSketcherDoc()
{
    delete _shapeContainer;
}


BOOL CSketcherDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CSketcherDoc serialization

void CSketcherDoc::Serialize(CArchive& ar)
{
    if (ar.IsStoring())
    {
        ar << m_DocSize;             // and the current document size
        _shapeContainer->serialize(ar);
    }
    else
    {
        ar >> m_DocSize;             // and the current document size
        _shapeContainer->serialize(ar);
    }
}
/////////////////////////////////////////////////////////////////////////////
// CSketcherDoc diagnostics

#ifdef _DEBUG

void CSketcherDoc::AssertValid() const
{
	CDocument::AssertValid();
}


void CSketcherDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSketcherDoc commands


void CSketcherDoc::OnColorBlack() 
{
   _shapeContainer->SetElementColor(BLACK);
}


void CSketcherDoc::OnColorRed() 
{
    _shapeContainer->SetElementColor(RED);
}


void CSketcherDoc::OnElementLine() 
{
   _shapeContainer->SetElementType(RIBBLE);
}


void CSketcherDoc::OnElementRectangle() 
{
   _shapeContainer->SetElementType(RECTANGLE);
}


void CSketcherDoc::OnUpdateColorBlack(CCmdUI* pCmdUI) 
{
   // Set menu item Checked if the current color is black
   pCmdUI->SetCheck(_shapeContainer->GetElementColor()==BLACK);
}


void CSketcherDoc::OnUpdateColorRed(CCmdUI* pCmdUI) 
{
   // Set menu item Checked if the current color is red
   pCmdUI->SetCheck(_shapeContainer->GetElementColor()==RED);
}


void CSketcherDoc::OnUpdateElementLine(CCmdUI* pCmdUI) 
{
   // Set Checked if the current element is a line
   pCmdUI->SetCheck(_shapeContainer->GetElementType()==RIBBLE);
}


void CSketcherDoc::OnUpdateElementRectangle(CCmdUI* pCmdUI) 
{
   pCmdUI->SetCheck(_shapeContainer->GetElementType()==RECTANGLE);
}


void CSketcherDoc::OnElementOval() 
{
	_shapeContainer->SetElementType(OVAL);
}


void CSketcherDoc::OnUpdateElementOval(CCmdUI* pCmdUI) 
{
    pCmdUI->SetCheck(_shapeContainer->GetElementType()==OVAL);
}


void CSketcherDoc::OnUpdateElementText(CCmdUI* pCmdUI) 
{
    pCmdUI->SetCheck(_shapeContainer->GetElementType()==TEXT);
}


void CSketcherDoc::OnElementText() 
{
    TextRequest::getTextToShow();
    _shapeContainer->SetElementType(TEXT);
}


void CSketcherDoc::OnElementTextInOval() 
{
    TextRequest::getTextToShow();
    _shapeContainer->SetElementType(TEXT_IN_OVAL);
}


void CSketcherDoc::OnUpdateElementTextInOval(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(_shapeContainer->GetElementType()==TEXT_IN_OVAL);
}


void CSketcherDoc::OnElementRibble() 
{
    _shapeContainer->SetElementType(RIBBLE);
}


void CSketcherDoc::OnUpdateElementRibble(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(_shapeContainer->GetElementType()==RIBBLE);
}


Соседние файлы в папке Sketcher02