Скачиваний:
7
Добавлен:
01.05.2014
Размер:
9.15 Кб
Скачать
// part32Doc.cpp : implementation of the CPart32Doc class
//

#include "stdafx.h"
#include "part32.h"

#include "part32Doc.h"
#include "CntrItem.h"
#include "SrvrItem.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPart32Doc

IMPLEMENT_DYNCREATE(CPart32Doc, COleServerDoc)

BEGIN_MESSAGE_MAP(CPart32Doc, COleServerDoc)
	//{{AFX_MSG_MAP(CPart32Doc)
	ON_COMMAND(ID_ELEMENTS_TEXT, OnElementsText)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TEXT, OnUpdateElementsText)
	ON_COMMAND(ID_ELEMENTS_TRAPEZIUM, OnElementsTrapezium)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TRAPEZIUM, OnUpdateElementsTrapezium)
	ON_COMMAND(ID_ELEMENTS_TRAPEZIUMWITHTEXT, OnElementsTrapeziumwithtext)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TRAPEZIUMWITHTEXT, OnUpdateElementsTrapeziumwithtext)
	ON_COMMAND(ID_ELEMENTS_TRIANGLE, OnElementsTriangle)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TRIANGLE, OnUpdateElementsTriangle)
	//}}AFX_MSG_MAP
	// Enable default OLE container implementation
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleServerDoc::OnUpdatePasteMenu)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleServerDoc::OnUpdatePasteLinkMenu)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleServerDoc::OnUpdateObjectVerbMenu)
	ON_COMMAND(ID_OLE_EDIT_CONVERT, COleServerDoc::OnEditConvert)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleServerDoc::OnUpdateEditLinksMenu)
	ON_COMMAND(ID_OLE_EDIT_LINKS, COleServerDoc::OnEditLinks)
	ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, COleServerDoc::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CPart32Doc, COleServerDoc)
	//{{AFX_DISPATCH_MAP(CPart32Doc)
	DISP_FUNCTION(CPart32Doc, "showWnd", showWnd, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CPart32Doc, "getCount", getCount, VT_I2, VTS_I2)
	DISP_FUNCTION(CPart32Doc, "Triangle", Triangle, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2)
	DISP_FUNCTION(CPart32Doc, "Trapezium", Trapezium, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2)
	DISP_FUNCTION(CPart32Doc, "TextTrapezium", TextTrapezium, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_BSTR VTS_I2)
	DISP_FUNCTION(CPart32Doc, "Text", Text, VT_EMPTY, VTS_I2 VTS_I2 VTS_BSTR VTS_I2)
	DISP_FUNCTION(CPart32Doc, "deleteElem", deleteElem, VT_EMPTY, VTS_I2 VTS_I2)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IPart32 to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {73D0D052-E865-4D6F-95EB-41AAF08FDFBF}
static const IID IID_IPart32 =
{ 0x73d0d052, 0xe865, 0x4d6f, { 0x95, 0xeb, 0x41, 0xaa, 0xf0, 0x8f, 0xdf, 0xbf } };

BEGIN_INTERFACE_MAP(CPart32Doc, COleServerDoc)
	INTERFACE_PART(CPart32Doc, IID_IPart32, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPart32Doc construction/destruction

CPart32Doc::CPart32Doc()
{
	// Use OLE compound files
	EnableCompoundFile();

	// TODO: add one-time construction code here

	EnableAutomation();

	AfxOleLockApp();

	c_TypeName=TRIANGLE;
	is_TextEnter=false;
	m_DocSize = CSize(3000,3000);
	index1=1;
	index2=1;
}

CPart32Doc::~CPart32Doc()
{
	AfxOleUnlockApp();
}

BOOL CPart32Doc::OnNewDocument()
{
	if (!COleServerDoc::OnNewDocument())
		return FALSE;

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

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CPart32Doc server implementation

COleServerItem* CPart32Doc::OnGetEmbeddedItem()
{
	// OnGetEmbeddedItem is called by the framework to get the COleServerItem
	//  that is associated with the document.  It is only called when necessary.

	CPart32SrvrItem* pItem = new CPart32SrvrItem(this);
	ASSERT_VALID(pItem);
	return pItem;
}



/////////////////////////////////////////////////////////////////////////////
// CPart32Doc serialization

void CPart32Doc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<set1.count();

		ArSetIterator<Shape*> it(set1);
	
		while(!it.end())
		{
			ar << it.currentItem();

			it.next();
		}

		ar<<set2.count();

		ArSetIterator<Shape*> it2(set2);
	
		while(!it2.end())
		{
			ar << it2.currentItem();

			it2.next();
		}
	}
	else
	{
		// TODO: add loading code here
		int _Cnt;
		int _type;
		Shape* sh;
		ar>>_Cnt;

		for (int i=0;i<_Cnt;i++)
		{
			ar>>_type;
			
			sh=CreateElemByType(_type);

			ar>>sh;

			set1.insertEl(i,sh);
		}

		int _Cnt2;

		ar>>_Cnt2;

		for (i=0;i<_Cnt2;i++)
		{
			ar>>_type;
			
			sh=CreateElemByType(_type);

			ar>>sh;

			set2.insertEl(i,sh);
		}
	}

	// Calling the base class COleServerDoc enables serialization
	//  of the container document's COleClientItem objects.
	COleServerDoc::Serialize(ar);
}

/////////////////////////////////////////////////////////////////////////////
// CPart32Doc diagnostics

#ifdef _DEBUG
void CPart32Doc::AssertValid() const
{
	COleServerDoc::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CPart32Doc commands
WORD CPart32Doc::GetElementType()        // Get the element type
	{
		return c_TypeName;
	}

CSize CPart32Doc::GetDocSize()                        // Retrieve the document size
	  { return m_DocSize; }

Shape* CPart32Doc::CreateElemByType(int type)
	{													//создание фигуры по номеру типа (для сериализации
	 switch(type)
		{
		case 1:
			return new CTriangleEntity(0,0);
     
		case 2:
			return new CTrapeziumEntity(0,0,0);

		case 3:
			return new CTextEntity("");

		case 4:
			return new CTextTrapeziumEntity("",0,0,0);

		default:
			AfxMessageBox("Bad Element code", MB_OK);
			AfxAbort();
			return 0;
		}
	}

void CPart32Doc::OnElementsText() 
{
	// TODO: Add your command handler code here
	c_TypeName=TEXT;
	is_TextEnter=true;	
}

void CPart32Doc::OnUpdateElementsText(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TEXT);	
}

void CPart32Doc::OnElementsTrapezium() 
{
	// TODO: Add your command handler code here
	c_TypeName=TRAPEZ;
	is_TextEnter=false;	
}

void CPart32Doc::OnUpdateElementsTrapezium(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TRAPEZ);	
}

void CPart32Doc::OnElementsTrapeziumwithtext() 
{
	// TODO: Add your command handler code here
	c_TypeName=TRAPEZTEXT;
	is_TextEnter=true;	
}

void CPart32Doc::OnUpdateElementsTrapeziumwithtext(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TRAPEZTEXT);
}

void CPart32Doc::OnElementsTriangle() 
{
	// TODO: Add your command handler code here
	c_TypeName=TRIANGLE;
	is_TextEnter=false;	
}

void CPart32Doc::OnUpdateElementsTriangle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TRIANGLE);	
}

void CPart32Doc::showWnd() 
{
 POSITION pos = GetFirstViewPosition();
 CView* pView = GetNextView(pos);
 if (pView != NULL)
 {
  CFrameWnd* pFrameWnd = pView->GetParentFrame();
  pFrameWnd->ActivateFrame(SW_SHOW);
  pFrameWnd = pFrameWnd->GetParentFrame();
  if (pFrameWnd != NULL)
   pFrameWnd->ActivateFrame(SW_SHOW);
 }
}



short CPart32Doc::getCount(short num) 
{
	// TODO: Add your dispatch handler code here
	if (num==1)
	{ 
		return	set1.count();
	}
	else
	{
		return set2.count();
	}
}

void CPart32Doc::Triangle(short x, short y, short base, short height, short num) 
{
	Shape* sh;
	sh=new CTriangleEntity(base,height,x,y);

	if (num==1)
	{
		set1.insertEl(index1++,sh);
	}
	else
	{
		set2.insertEl(index2++,sh);
	}

	UpdateAllViews(NULL);
}

void CPart32Doc::Trapezium(short x, short y, short base, short height, short cutof, short num) 
{

	Shape* sh;
	sh=new CTrapeziumEntity(10,base,height,x,y);

	if (num==1)
	{
		set1.insertEl(index1++,sh);
	}
	else
	{
		set2.insertEl(index2++,sh);
	}

	UpdateAllViews(NULL);
}

void CPart32Doc::TextTrapezium(short x, short y, short base, short height, short cutof, LPCTSTR Text, short num) 
{
	
	Shape* sh;
	sh=new CTextTrapeziumEntity(Text,10,base,height,x,y);

	if (num==1)
	{
		set1.insertEl(index1++,sh);
	}
	else
	{
		set2.insertEl(index2++,sh);
	}

	UpdateAllViews(NULL);
}

void CPart32Doc::Text(short x, short y, LPCTSTR Text, short num) 
{

	Shape* sh;
	sh=new CTextEntity(Text,x,y);

	if (num==1)
	{
		set1.insertEl(index1++,sh);
	}
	else
	{
		set2.insertEl(index2++,sh);
	}

	UpdateAllViews(NULL);
}

void CPart32Doc::deleteElem(short index, short num) 
{
	if (num==1)
	{ 
		set1.deleteEl(index);
	}
	else
	{
		set2.deleteEl(index);
	}
	UpdateAllViews(NULL);
}
Соседние файлы в папке part32