// 34Document.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "3HeaderInf.h"		// For MC3HeaderInf.
#include "3App.h"				// For MC3App.
#include "3Env.h"				// For MC3Env.
#include "3ToolManager.h"		// For MC3ToolManager.
#include "3LayerManager.h"		// For MC3LayerManager.
#include "3SheetManager.h"		// For MC3SheetManager.
#include "3LinkManager.h"		// For MC3LinkManager.
#include "3Reg.h"				// For MC3Reg.
#include "3CanvasStat.h"		// For MC3CanvasStat.
#include "3Document.h"			// This header.

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

MC3Document* g_pDoc;

/////////////////////////////////////////////////////////////////////////////
// MC3Document

IMPLEMENT_DYNCREATE(MC3Document, COleServerDoc)

/////////////////////////////////////////////////////////////////////////////
// MC3Document _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC3Document::SetFileType
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iPgPjHmNiClHiCoJiDhEiDeAiDeDiDiLiMfOiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	df	:_xZkqqHx_iDhEiDeAiDeDiDiLiMfOiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.06.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void MC3Document::SetFileType (FTDocumentFormat df)
{
	m_headerInf->SetFileType(df);
} // MC3Document::SetFileType.

BOOL MC3Document::InStreamCore (MCARCHIVE& ar)
{
	// _xZkqqHx_iDhHiDgCiDfPiPoOjFpBiCmMjDmHiCnNiNjOiCnNiBeC_xHqqkZx_
	m_headerInf->InStream(ar);
	// _xZkqqHx_jFlGiPjBiDhGiDiNiDhAiDgFiDeCiDfEiDeDiDfJiBeC_xHqqkZx_
	long lDocPropertySize;
	ar >> lDocPropertySize;
//	ASSERT(g_nVersion == 3 && lDocPropertySize == 0);
	if (lDocPropertySize != 0)
	{
		BYTEVector buff(lDocPropertySize);
		ar.Read(&buff.at(0), lDocPropertySize);
	}
	// _xZkqqHx_iDhGiDiKiDjDiDfOiPoOjFpBjDjJiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	m_app->InStream(ar);
	// _xZkqqHx_iKmCiLkLiPoOjFpBiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	m_env->InStream(ar);
	// _xZkqqHx_iDgDiBfLiDiLjAnNjCoIiPoOjFpBiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	m_toolManager->InStream(ar);

	m_sheetManager->InStream(ar);
	// _xZkqqHx_iDiKiDjDiDeOiPoOjFpBiCpAjDpMjHmNiClHiCoJiBeC_xHqqkZx_
	m_linkManager->InStream(ar);
	// _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiPoOjFpBiCpAjDpMjHmNiClHiCoJiBeC_xHqqkZx_
	m_reg->InStream(ar);
	// _xZkqqHx_iDeMiDiDiDjDiDgPiDfIiPoOjFpBiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	m_canvasStat->InStream(ar);

	return TRUE;
} // MC3Document::InStreamCore.

void MC3Document::OutStreamCore (MCARCHIVE& ar)
{
	// _xZkqqHx_iDhHiDgCiDfPiPoOjFpBiCmMiPjBiCkLiPgPiClFiBeC_xHqqkZx_
	m_headerInf->OutStream(ar);
	// _xZkqqHx_jFlGiPjBiDhGiDiNiDhAiDgFiDeCiDfEiDeDiDfJiBeC_xHqqkZx_
	const long lDocPropertySize = 0;
	ar << lDocPropertySize;
	// _xZkqqHx_iDhGiDiKiDjDiDfOiPoOjFpBjDjJiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	m_app->OutStream(ar);
	// _xZkqqHx_iKmCiLkLiPoOjFpBiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	m_env->OutStream(ar);
	// _xZkqqHx_iDgDiBfLiDiLjAnNjCoIiPoOjFpBiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	m_toolManager->OutStream(ar);
	// _xZkqqHx_iDfGiBfLiDgHiBeBjFjEjFgJiPoOjFpBiCpAiPgPjHmNiBeC_xHqqkZx_
	m_sheetManager->OutStream(ar);
	// _xZkqqHx_iDiKiDjDiDeOiPoOjFpBiCpAiPgPjHmNiClHiCoJiBeC_xHqqkZx_
	m_linkManager->OutStream(ar);
	// _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiPoOjFpBiCpAiPgPjHmNiClHiCoJiBeC_xHqqkZx_
	m_reg->OutStream(ar);
	// _xZkqqHx_iDeMiDiDiDjDiDgPiDfIiCmMjFfMiOkGiPpDjBnEiCpAiDfIiDgHiDiKiBfLiDiAiCmJiPgPjHmNiClHiCoJiBeC_xHqqkZx_
	m_canvasStat->OutStream(ar);
} // MC3Document::OutStreamCore.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC3Document::RegisterObject
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jAfGiClFiCkNjAlGjAkMiClDiCoKiClNjFjEjFgJiCpAiOhHjCoIiClFiClN_xHqqkZx_ID_xZkqqHx_iCmFjDgPjIfOiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pObj	: _xZkqqHx_jDgPjIfOiClHiCoJjFjEjFgJ_xHqqkZx_
 *			dwID	: _xZkqqHx_jDgPjIfOiClHiCoJjFjEjFgJiCmM_xHqqkZx_ID
 *
 * <_xZkqqHx_jCiNiInD_xHqqkZx_>	ID_xZkqqHx_iCmMiPgEjFkBiCpAiDgAiDeGiDgCiDeOiClFiCmIiCkCiCmMiCmFiBeB_xHqqkZx_m_obppObjID2P_xZkqqHx_iCkKiClHiCnHiCmEiLpDiCmMiOjOiBeB_xHqqkZx_
 *			_xZkqqHx_iClHiCmIiCoNiClP_xHqqkZx_m_dwObjID2PNext = 0_xZkqqHx_iCmMiOjOiCmMiCnNiOgHjHhAiCmFiCkLiCoJiBeCjAfGiLeLiCmJiDhEiDeAiDeDiDiL_xHqqkZx_
 *			_xZkqqHx_iCpAiDiNiBfLiDgIiClHiCoJiOjOiCmMiCnNiCmGiNgMiCkGiCmEiCoGiCkCiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	98.11.14 Fukushiro M. _xZkqqHx_iDgFiBfLiDhFiDiLiCkK_xHqqkZx_NULL_xZkqqHx_iCmMiPiIjHjNiCpAjCmHiJmB_xHqqkZx_.ChipTbl::InStream_xZkqqHx_iCmMiInH_xHqqkZx_.
 *************************************************************************/
void MC3Document::RegisterObject (MC3ObjBase* pObj, DWORD dwID)
{
	ASSERT(m_mpIdToObj.find(dwID) == m_mpIdToObj.end());
	m_mpIdToObj[dwID] = pObj;
} // MC3Document::RegisterObject.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC3Document::UnregisterObject
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jFjEjFgJiCpA_xHqqkZx_ID_xZkqqHx_jDgPjIfOiCkJiCoHiCmNiClIiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pObj	: _xZkqqHx_jFjEjFgJ_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	98.11.14 Fukushiro M. _xZkqqHx_iDgFiBfLiDhFiDiLiCkK_xHqqkZx_NULL_xZkqqHx_iCmMiPiIjHjNiCpAjCmHiJmB_xHqqkZx_.ChipTbl::InStream_xZkqqHx_iCmMiInH_xHqqkZx_.
 *************************************************************************/
void MC3Document::UnregisterObject (MC3ObjBase* pObj)
{
	// _xZkqqHx_jFjEjFgJ_xHqqkZx_ID_xZkqqHx_iDgFiBfLiDhFiDiLiCkJiCoHjFjEjFgJiCpAiPjMiCkNiBeC_xHqqkZx_
	ASSERT(m_mpIdToObj.find(pObj->GetObjID()) != m_mpIdToObj.end());
	m_mpIdToObj.erase(pObj->GetObjID());
} // MC3Document::UnregisterObject.

/////////////////////////////////////////////////////////////////////////////
// MC3Document


MC3Document::MC3Document ()
{
	// OLE _xZkqqHx_jFkBiNiHiDhEiDeAiDeDiDiLiCpAiOgHjHhAiClFiCnMiClHiBeC_xHqqkZx_
	EnableCompoundFile();

	// _xZkqqHx_iDhHiDgCiDfPiPoOjFpBiBeC_xHqqkZx_
	m_headerInf = new MC3HeaderInf;
	// _xZkqqHx_iDhGiDiKiDjDiDfOiPoOjFpBjDjJiBeC_xHqqkZx_
	m_app = new MC3App;
	// _xZkqqHx_iKmCiLkLiPoOjFpBiBeC_xHqqkZx_
	m_env = new MC3Env;
	// _xZkqqHx_iDgDiBfLiDiLjAnNjCoIiPoOjFpBiBeC_xHqqkZx_
	m_toolManager = new MC3ToolManager;
	// _xZkqqHx_iDfGiBfLiDgHiBeBjFjEjFgJiPoOjFpBiBeC_xHqqkZx_
	m_sheetManager = new MC3SheetManager;
	// _xZkqqHx_iDiKiDjDiDeOiPoOjFpBiBeC_xHqqkZx_
	m_linkManager = new MC3LinkManager;
	// _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiPoOjFpBiBeC_xHqqkZx_
	m_reg = new MC3Reg;
	// _xZkqqHx_iDeMiDiDiDjDiDgPiDfIiPoOjFpBiBeC_xHqqkZx_
	m_canvasStat = new MC3CanvasStat;

	// _xZkqqHx_iDgDiBfLiDiLiDhNiDgMiBfLiDfHiDiDiPiJiKpKiJlLiBeC_xHqqkZx_
	m_toolManager->Initialize(this);

} // MC3Document::MC3Document.

MC3Document::~MC3Document ()
{
	m_sheetManager->DeleteAll();
	// _xZkqqHx_iDgDiBfLiDiLiDhNiDgMiBfLiDfHiDiDiPeJjHlJiJlLiBeC_xHqqkZx_
	m_toolManager->Terminate();

	// _xZkqqHx_iDeMiDiDiDjDiDgPiDfIiPoOjFpBiBeC_xHqqkZx_
	delete m_canvasStat;
	m_canvasStat = NULL;
	// _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiPoOjFpBiBeC_xHqqkZx_
	delete m_reg;
	m_reg = NULL;
	// _xZkqqHx_iDiKiDjDiDeOiPoOjFpBiBeC_xHqqkZx_
	delete m_linkManager;
	m_linkManager = NULL;
	// _xZkqqHx_iDfGiBfLiDgHiBeBjFjEjFgJiPoOjFpBiBeC_xHqqkZx_
	delete m_sheetManager;
	m_sheetManager = NULL;
	// _xZkqqHx_iDgDiBfLiDiLjAnNjCoIiPoOjFpBiBeC_xHqqkZx_
	delete m_toolManager;
	m_toolManager = NULL;
	// _xZkqqHx_iKmCiLkLiPoOjFpBiBeC_xHqqkZx_
	delete m_env;
	m_env = NULL;
	// _xZkqqHx_iDhGiDiKiDjDiDfOiPoOjFpBjDjJiBeC_xHqqkZx_
	delete m_app;
	m_app = NULL;
	// _xZkqqHx_iDhHiDgCiDfPiPoOjFpBiBeC_xHqqkZx_
	delete m_headerInf;
	m_headerInf = NULL;
} // MC3Document::~MC3Document.

BOOL MC3Document::OnNewDocument ()
{
	if (!COleServerDoc::OnNewDocument())
		return FALSE;
	return TRUE;
} // MC3Document::OnNewDocument.

COleServerItem* MC3Document::OnGetEmbeddedItem()
{
	// OnGetEmbeddedItem _xZkqqHx_iCmNiBeBiDgIiDeMiDiFiDiBiDjDiDgHiCmJiKnGjIeBjFhEiCkPiCoHiCoKiClN_xHqqkZx_ COleServerItem _xZkqqHx_iCpA_xHqqkZx_
	// _xZkqqHx_iOoGjDlOiClHiCoJiClNiCnPiCmJiDhEiDiMiBfLiDiAiDiPiBfLiDeOiCkJiCoHjFeLjHhGiCmIiPoKiNiHiCmJiCmMiCnNiMmEiCnBiPgPiClDiCoKiCnMiClHiBeC_xHqqkZx_

	// NULL _xZkqqHx_iCpAjFnEiClHjBoDiCoNiCoIiCmJiBeBiClBiCmMiDgIiDeMiDiFiDiBiDjDiDgHiCmJjIeBiMiLiClDiCoKiClN_xHqqkZx_ COleServerItem _xZkqqHx_iCmM_xHqqkZx_
	// _xZkqqHx_jEgIjAlGiDeOiDiJiDfIiCnGiCmMiDhMiDeDiDjDiDfOiCpAjFnEiClHiCoGiCkEiCmJjFmPiNfIiClFiCmEiJlKiClDiCkCiBeCiClLiCmMiMoDiBeBiImIiJlKiCmM_xHqqkZx_
	// ASSERT(FALSE) _xZkqqHx_iNhDiCpAiNoNiPjMiClFiCmEiJlKiClDiCkCiBeC_xHqqkZx_
	//  (_xZkqqHx_jHoB_xHqqkZx_: return new CMyServerItem)
	ASSERT(FALSE);			// _xZkqqHx_iPiIjHjNiLeMiPhBiMoDiBeBiNoNiPjMiClFiCmEiCkNiClOiClDiCkCiBeC_xHqqkZx_
	return NULL;
}


BEGIN_MESSAGE_MAP(MC3Document, COleServerDoc)
	//{{AFX_MSG_MAP(MC3Document)
		// _xZkqqHx_iDiBiDiC_xHqqkZx_ - ClassWizard _xZkqqHx_iCmNiClBiCmMiImKjChFiCmJiDhNiDgCiDhDiDjDiDePjHhAiCmMiDhNiDeOiDiNiCpAjCmHiJmBiCnMiClNiCmNiNoNiPjMiClFiCnMiClHiBeC_xHqqkZx_
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MC3Document _xZkqqHx_jAgGjCgG_xHqqkZx_

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

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

/////////////////////////////////////////////////////////////////////////////
// MC3Document _xZkqqHx_iDfGiDiKiDeBiDiJiDeDiDfJ_xHqqkZx_

void MC3Document::Serialize (CArchive& ar)
{
	if (ar.IsStoring())
	{
		OutStreamCore(ar);
	}
	else
	{
		InStreamCore(ar);
	}
} // MC3Document::Serialize.

/////////////////////////////////////////////////////////////////////////////
// MC3Document _xZkqqHx_iDfCiDhNiDjDiDgI_xHqqkZx_
