#include "stdafx.h"
#include <olestd.h>			// For CF_EMBEDDEDOBJECT.
#include "UtilVersion.h"	// For FCHeaderInf.

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

/**********************************************************************
 *                      _xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjE_xHqqkZx_
 **********************************************************************/

FCGlobal s_ =
{
	FD_APPMODE_DYNAMICDRAW | FD_RUNMODE_NONE,	// _xZkqqHx_iDeBiDhGiDiKiOmAiNhDiDiCiBfLiDgIiBeC_xHqqkZx_
	0.0,				// Display_xZkqqHx_iCmMjIfPjHjN_xHqqkZx_pixel/mm_xZkqqHx_iCpAjFnLjBlGiBeC_xHqqkZx_
	0.0,				// Display_xZkqqHx_iCmMjIfPjHjN_xHqqkZx_pixel/mm_xZkqqHx_iCpA_xHqqkZx_HORZRES/HORZSIZE_xZkqqHx_iCmFiOoGjDlOiBeC_xHqqkZx_
	0.0,				// Display_xZkqqHx_iCmMjIfPjHjN_xHqqkZx_pixel/mm_xZkqqHx_iCpA_xHqqkZx_VERTRES/VERTSIZE_xZkqqHx_iCmFiOoGjDlOiBeC_xHqqkZx_
	256,				// _xZkqqHx_jEhLjHkGiBeCiPiJiKpKjCgMiCmN_xHqqkZx_256_xZkqqHx_iBeC_xHqqkZx_CFCMainFrame_xZkqqHx_iCmFjAnNjCoIiBeC_xHqqkZx_
	0.0,				// _xZkqqHx_jEhLjHkGiBeCiPiJiKpKjCgMiCmN_xHqqkZx_g_->dDisplayPPM_xZkqqHx_iBeC_xHqqkZx_CFCMainFrame_xZkqqHx_iCmFjAnNjCoIiBeC_xHqqkZx_
	FD_ZOOM256_MAX,		// Zoom256_xZkqqHx_jCgMiCmMiNmFjBoFjCgMiBeCiClBiCmMjCgMiCpAiKnMiCnOiBeC_xHqqkZx_
	0,					// _xZkqqHx_iDfIiDeOiDiNiBfLiDiLiDeJiDhEiDfKiDgCiDgHjCgMiBeC_xHqqkZx_
	0,					// _xZkqqHx_iDfIiDeOiDiNiBfLiDiLiDeJiDhEiDfKiDgCiDgHjCgMiBeC_xHqqkZx_
	FDDR_NONE,			// _xZkqqHx_jFgAiJoGjAoGiDgGiDgPiDeDiDfIjAnNjCoIiBeC_xHqqkZx_
	FD_STD_PRECISION,	// _xZkqqHx_iLmIjApMiMhGiOfKiOjOiCmMjFfHiPiAiCmMjClIjDfPiLjHjHkDiBeC_xHqqkZx_
};

FCGlobal*	g_ = &s_;

static int myBitsPixel ()
{
	// _xZkqqHx_iDgGiDeCiDfIiDhGiDiMiDeDiCmM_xHqqkZx_HDC_xZkqqHx_iCpAiNoMjAkMiBeC_xHqqkZx_
	HDC hAttribDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	// _xZkqqHx_iCfAiDhDiDeOiDfKiDiLiCmMiDhCiDgCiDgHjAjEiCpAiOoGjDlOiBeBiDhCiDgCiDgHiDhNiDgCiDhGiDfEiDeDiDfJiCmMiOfKiPgPiBeC_xHqqkZx_
	int iBitsPixel = GetDeviceCaps(hAttribDC, BITSPIXEL);
	// HDC_xZkqqHx_iCpAiNoNiPjMiBeC_xHqqkZx_
	::DeleteDC(hAttribDC);
	// _xZkqqHx_iCfAiDhDiDeOiDfKiDiLiCmMiDhCiDgCiDgHjAjEiCpAiOoGjDlOiBeBiDhCiDgCiDgHiDhNiDgCiDhGiDfEiDeDiDfJiCmMiOfKiPgPiBeC_xHqqkZx_
	return iBitsPixel;
} // myBitsPixel.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	myClipFormat
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	DDFile_xZkqqHx_iMgAiOkOiCmMiDeOiDiKiDgCiDhGiDhLiBfLiDgIiDhEiDeIiBfLiDhNiDgCiDgHiCpAiNoMjAkMiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	wcpAddText	:_xZkqqHx_jCmHiJmBiDgFiDeMiDfIiDgHiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.07.10 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
static CLIPFORMAT myClipFormat (const wchar_t* wcpAddText)
{
	//----- Molip Draw_xZkqqHx_iCmMiDeOiDiKiDgCiDhGiDhLiBfLiDgIiDfCiDhDiBfLjHhA_xHqqkZx_ Native File Data _xZkqqHx_iCmMiMgAiOkOjGlMiCpAjDgPjIfO_xHqqkZx_ -----
	WString wstrForm;
	wstrForm.Format(L"Dynamic Draw %s %s",
					FCHeaderInf::GetStcFileVersionString(),
					wcpAddText);
	return (CLIPFORMAT)::RegisterClipboardFormat(WStrToTStr(wstrForm));
} // myClipFormat.

// GetDeviceCaps(BITSPIXEL).
const int	g_nBitsPixel = myBitsPixel();
// ChipRec_xZkqqHx_iCmM_xHqqkZx_m_pBits_xZkqqHx_iCmMiDfEiDeDiDfJiBeC_xHqqkZx_
const DWORD	g_dwChipBits = (FD_CHIP_BMP_W * FD_CHIP_BMP_H * g_nBitsPixel) / 8;
// PictArrowRec_xZkqqHx_iCmM_xHqqkZx_m_pBits_xZkqqHx_iCmMiDfEiDeDiDfJiBeC_xHqqkZx_
const DWORD	g_dwPictArrowBits = (FD_PICT_ARROW_BMP_W * FD_PICT_ARROW_BMP_H * g_nBitsPixel) / 8;
// Molip Draw_xZkqqHx_iCmMiDeOiDiKiDgCiDhGiDhLiBfLiDgIiDfCiDhDiBfLjHhA_xHqqkZx_ Native File Data _xZkqqHx_iCmMiMgAiOkOjGlMiBeC_xHqqkZx_
const CLIPFORMAT g_cfDDFile = myClipFormat(L"");
// g_cfDDFile_xZkqqHx_iCmFiBeB_xHqqkZx_ObjFigure_xZkqqHx_iCkKiCfAiCmCiCmMiCnNjDgPjIfOiCmMiPoKiNiHiCmJiBeBiLeMjIfOiClDiCoKiCoJiBeC_xHqqkZx_
const CLIPFORMAT g_cfObjFigure = myClipFormat(L"ObjFigure");
// Dynamic Draw_xZkqqHx_iCmMiDgFiDeMiDfIiDgHiDeOiDiKiDgCiDhGiDhLiBfLiDgIiDfCiDhDiBfLjHhAiBeC_xHqqkZx_
const CLIPFORMAT g_cfDDText = myClipFormat(L"Text");
// RTF_xZkqqHx_iDhEiDeIiBfLiDhNiDgCiDgHiBeC_xHqqkZx_
const CLIPFORMAT g_cfRTF = (CLIPFORMAT)::RegisterClipboardFormat(CF_RTF);
// OLE_xZkqqHx_iDgGiBfLiDfOiBeC_xHqqkZx_
const CLIPFORMAT g_cfEmbeddedObject = (CLIPFORMAT)::RegisterClipboardFormat(CF_EMBEDDEDOBJECT);
// OLE_xZkqqHx_iDfMiBfLiDfIiBeC_xHqqkZx_
const CLIPFORMAT g_cfEmbedSource = (CLIPFORMAT)::RegisterClipboardFormat(CF_EMBEDSOURCE);
// CSV_xZkqqHx_iDgFiDeMiDfIiDgHiBgJ_xHqqkZx_Paste_xZkqqHx_iOjOiCmMiOkPjFmKiCmJiCmMiCnNiOgHjHhAiBgK_xHqqkZx_
extern const CLIPFORMAT g_cfCsvText = myClipFormat(L"CSV");
// CSV Unicode_xZkqqHx_iDgFiDeMiDfIiDgHiBgJ_xHqqkZx_Paste_xZkqqHx_iOjOiCmMiOkPjFmKiCmJiCmMiCnNiOgHjHhAiBgK_xHqqkZx_
extern const CLIPFORMAT g_cfCsvUnicodeText = myClipFormat(L"CSV Unicode");

//--------- _xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEiCmMiDgPiDgCiDeOiDeBiDgCiDhG_xHqqkZx_ ----------
struct FCGlobalBackup
{
	FCEnv*			m_pEnv;				// _xZkqqHx_iKmCiLkLiBeC_xHqqkZx_
	CFCFoundDoc*	m_pDoc;				// _xZkqqHx_iDgIiDeMiDiFiDiBiDjDiDgHiBeC_xHqqkZx_
	CFCMainFrame*		m_pFrame;			// _xZkqqHx_iDhEiDiMiBfLiDiAiBeC_xHqqkZx_
	CFCDynamicDrawView*	m_pView;			// _xZkqqHx_iDhCiDiFiBfLiBeC_xHqqkZx_
	FCRegData*		m_pReg;				// _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiBeC_xHqqkZx_
	FCToolManager*	m_pToolManager;		// _xZkqqHx_iDgDiBfLiDiLiDhNiDgMiBfLiDfHiDiDiBeC_xHqqkZx_
	FCHiProject*		m_pProject;			// _xZkqqHx_iDhGiDiNiDfHiDeGiDeOiDgHiBeC_xHqqkZx_
	FCGlobal*		m_;					// _xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEiBeC_xHqqkZx_
}; // struct FCGlobalBackup.

static vector<FCGlobalBackup> s_globalBackup;

///////////////////////////////////////////////////////////////////////////
// _xZkqqHx_iDePiDiNiBfLiDgPiDiLiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCGlobal::Initialize
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEiCmMiPiJiKpKiJlLiCpAiNhDiCkEiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.09.04 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCGlobal::Initialize ()
{
	// _xZkqqHx_iDgGiDeCiDfIiDhGiDiMiDeDiCmM_xHqqkZx_HDC_xZkqqHx_iCpAiNoMjAkMiBeC_xHqqkZx_
	HDC hAttribDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	if (hAttribDC == NULL) return;

//----- 03.07.06 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
//	// OS_xZkqqHx_iDgPiBfLiDfHiDiHiDjDiPoOjFpBiOoGjDlOiBeC_xHqqkZx_
//	::GetVersionEx(&s_versionInfo);
//----- 03.07.06 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

	//----- _xZkqqHx_iKgF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eviceCaps(LOGPIXELSX)
	// _xZkqqHx_iCmGiCoAiIoBiCkEiClBiCmGiCmJjCiNiInDiBeC_xHqqkZx_
	// GetDeviceCaps(LOGPIXELSX)_xZkqqHx_iCmNiBeBiJoGjGmKiDhGiDiNiDhAiDgFiDeCiCmFiBhFjBoFiCkLiCkCjFlGiOjKiBhGiBeB_xHqqkZx_
	// _xZkqqHx_iBhFiPkMiClDiCkCjFlGiOjKiBhGiCpAjBeJiCpBiClOiOjOiCoAjFmPiJlLiClHiCoJiClBiCmGiCmJjCiNiInDiBeC_xHqqkZx_
	dDisplayPPM = (double)GetDeviceCaps(hAttribDC, LOGPIXELSX) / 25.4;
	// Display_xZkqqHx_iCmMjIfPjHjN_xHqqkZx_mm_xZkqqHx_iCkAiClNiCoIiCmM_xHqqkZx_pixel_xZkqqHx_jAjEiCpAiMhGiOfKiClHiCoJiBeC_xHqqkZx_
	// HORZSIZE	:_xZkqqHx_jFkIjHjNiDgGiDeCiDfIiDhGiDiMiDeDiCmMjFjN_xHqqkZx_ (mm _xZkqqHx_jCfAiImK_xHqqkZx_)_xZkqqHx_iBeC_xHqqkZx_
	// HORZRES	:_xZkqqHx_iDgGiDeCiDfIiDhGiDiMiDeDiCmMjFjN_xHqqkZx_ (_xZkqqHx_iDhDiDeOiDfKiDiLjCfAiImK_xHqqkZx_)_xZkqqHx_iBeC_xHqqkZx_
	dRealDisplayPPMHorz = double(GetDeviceCaps(hAttribDC, HORZRES)) /
												double(GetDeviceCaps(hAttribDC, HORZSIZE));
	dRealDisplayPPMVert = double(GetDeviceCaps(hAttribDC, VERTRES)) /
												double(GetDeviceCaps(hAttribDC, VERTSIZE));
	// _xZkqqHx_iDfJiBfLiDiAjCgMiCmMjAnNjCoIiBeC_xHqqkZx_
	lZoom256 = 256;
	dZoom = ((double)lZoom256 * dDisplayPPM) / 256.0;

	// HDC_xZkqqHx_iCpAiNoNiPjMiBeC_xHqqkZx_
	::DeleteDC(hAttribDC);
} // FCGlobal::Initialize.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FFGlobalBackup
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEiCpAiDgPiDgCiDeOiDeBiDgCiDhGiClFiCmEiBeB_xHqqkZx_NULL_xZkqqHx_iCmFiPiJiKpKiJlLiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	02.12.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FFGlobalBackup ()
{
	// _xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEjHhAiDfIiDfOiDgCiDeOiCmJjAmPiCnOiBeC_xHqqkZx_
	s_globalBackup.push_back(FCGlobalBackup());
	s_globalBackup.back().m_pEnv		= g_pEnv;
	s_globalBackup.back().m_pDoc		= g_pDoc;
	s_globalBackup.back().m_pFrame		= g_pFrame;
	s_globalBackup.back().m_pView		= g_pView;
	s_globalBackup.back().m_pReg		= g_pReg;
	s_globalBackup.back().m_pToolManager= g_pToolManager;
	s_globalBackup.back().m_pProject	= g_pProject;
	s_globalBackup.back().m_			= g_;

	g_pEnv			= NULL;
	g_pDoc			= NULL;
	g_pFrame		= NULL;
	g_pView			= NULL;
	g_pReg			= NULL;
	g_pToolManager	= NULL;
	g_pProject		= NULL;
	g_				= NULL;
} // FFGlobalBackup.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FFGlobalRestore
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEiCmMiDgPiDgCiDeOiDeBiDgCiDhGiCpAjFjMiLeBiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	02.12.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FFGlobalRestore ()
{
	// _xZkqqHx_iDePiDiNiBfLiDgPiDiLjFmPjAjEjHhAiDfIiDfOiDgCiDeOiCkJiCoHiOoGiCoIiPgPiClHiBeC_xHqqkZx_
	g_pEnv		= s_globalBackup.back().m_pEnv;
	g_pDoc		= s_globalBackup.back().m_pDoc;
	g_pFrame	= s_globalBackup.back().m_pFrame;
	g_pView		= s_globalBackup.back().m_pView;
	g_pReg		= s_globalBackup.back().m_pReg;
	g_pToolManager= s_globalBackup.back().m_pToolManager;
	g_pProject	= s_globalBackup.back().m_pProject;
	g_			= s_globalBackup.back().m_;
	s_globalBackup.pop_back();
} // FFGlobalRestore.

