// DlgEmfImageModify.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "DynamicDraw.h"
#include "UtilErr.h"			// For FFMessageBox.
#include "UtilDlg.h"			// For SetUnitString.etc.
#include "DlgEmfImageModify.h"	// This header.

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

/////////////////////////////////////////////////////////////////////////////
// CFCDlgEmfImageModify _xZkqqHx_iDfPiDeDiDeBiDiNiDeP_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::CFCDlgEmfImageModify
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	03.06.24 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
CFCDlgEmfImageModify::CFCDlgEmfImageModify (CWnd* pParent /*=NULL*/)
	: BASE_CLASS(CFCDlgEmfImageModify::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFCDlgEmfImageModify)
		// _xZkqqHx_iDiBiDiC_xHqqkZx_ - ClassWizard _xZkqqHx_iCmNiClBiCmMiImKjChFiCmJiDhNiDgCiDhDiDjDiDePjHhAiCmMiDhNiDeOiDiNiCpAjCmHiJmBiCnMiClNiCmNiNoNiPjMiClFiCnMiClHiBeC_xHqqkZx_
	//}}AFX_DATA_INIT
} // CFCDlgEmfImageModify::CFCDlgEmfImageModify.

void CFCDlgEmfImageModify::DoDataExchange(CDataExchange* pDX)
{
	BASE_CLASS::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFCDlgEmfImageModify)
	DDX_Control(pDX, IDC_EMM_STC_EMFIMAGE, m_stcEmfImage);
	//}}AFX_DATA_MAP
} // CFCDlgEmfImageModify::DoDataExchange.

BEGIN_MESSAGE_MAP(CFCDlgEmfImageModify, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCDlgEmfImageModify)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_EMM_BTN_PASTE, OnEmmBtnPaste)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCDlgEmfImageModify _xZkqqHx_iDiGiBfLiDfFiKnGjAjE_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::SetEmfImageRec
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDfCiBfLiDgIiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	rec	:_xZkqqHx_iDiMiDfCiBfLiDgIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgEmfImageModify::SetEmfImageRec (const FCEmfImageRec& rec)
{
	m_regRec = rec;
} // CFCDlgEmfImageModify::SetEmfImageRec.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::GetEmfImageRec
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDfCiBfLiDgIiCpAiOoGjDlOiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDiMiDfCiBfLiDgIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
const FCEmfImageRec& CFCDlgEmfImageModify::GetEmfImageRec () const
{
	return m_regRec;
} // CFCDlgEmfImageModify::GetEmfImageRec.

/////////////////////////////////////////////////////////////////////////////
// CFCDlgEmfImageModify _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::OnInitDialog
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfPiDeDiDeBiDiNiDePiPiJiKpKiJlLiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iJlKiLeMiDfCiDiBiDjDiDgHiCpAiOfBiPmGiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL CFCDlgEmfImageModify::OnInitDialog ()
{
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnInitDialog();
	// _xZkqqHx_jGlMjBePiCpAjAnNjCoIiBeC_xHqqkZx_
	FFSetDlgItemText(this, IDC_EMM_EDT_EMFNAME, m_regRec.m_szName);
	// _xZkqqHx_iDfEiDjDiDhGiDiLiDhCiDiFiBfLiCmJiDiBiDfOiDhEiDeAiDeDiDiLiDeDiDiBiBfLiDfHiCpAjAnNjCoIiBeC_xHqqkZx_
	m_stcEmfImage.SetEmfImage(m_regRec.m_bypEmfBits, m_regRec.m_lEmfBitsSz);
	// _xZkqqHx_iDfPiDeDiDeBiDiNiDePiCmMjCfAiImKjFfMiOkGiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
	::SetUnitString(m_hWnd);
	// _xZkqqHx_jHjIiCkLjIhCjBmOiJjOjFlGiOjKjHpBiCmMjAnNjCoIiCpAiNhDiCkEiBeC_xHqqkZx_
	::RightByLeftHand(m_hWnd);
	// _xZkqqHx_iDfPiDeDiDeBiDiNiDePiCpAiDhNiDeFiDfIiImKjChFiCmJiInKjDkOiBeC_xHqqkZx_
	FFJustifyWindow(m_hWnd);
	return TRUE;  // _xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCmJiDhEiDeIiBfLiDeKiDfIiCpAjAnNjCoIiClFiCmIiCkCiCmGiCkLiBeBjGnPiCoIjCgMiCmN_xHqqkZx_ TRUE _xZkqqHx_iCmGiCmIiCoIiCnMiClH_xHqqkZx_
	              // _xZkqqHx_jHoBiKeP_xHqqkZx_: OCX _xZkqqHx_iDhGiDiNiDhAiDgFiDeC_xHqqkZx_ _xZkqqHx_iDhJiBfLiDfHiCmMjGnPiCoIjCgMiCmN_xHqqkZx_ FALSE _xZkqqHx_iCmGiCmIiCoIiCnMiClH_xHqqkZx_
} // CFCDlgEmfImageModify::OnInitDialog.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::OnDestroy
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCkKiNoNiPjMiClDiCoKiCoJiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgEmfImageModify::OnDestroy ()
{
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnDestroy();
	
	// TODO: _xZkqqHx_iClBiCmMiImKjChFiCmJiDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJjHhAiCmMiDfCiBfLiDgIiCpAjCmHiJmBiClFiCmEiCkNiClOiClDiCkC_xHqqkZx_
	
} // CFCDlgEmfImageModify::OnDestroy.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::OnOK
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	OK_xZkqqHx_iDhLiDfOiDjDiCkKiJjPiClDiCoKiClNiCmGiCkLiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgEmfImageModify::OnOK ()
{
	// _xZkqqHx_jFfMiOkGjCiGiCmMiDiBiDfOiDhEiDeAiDeDiDiLiDgOiDjDiDgIiDiLiCpAiOoGjDlOiBeC_xHqqkZx_
	HENHMETAFILE hEMF = m_stcEmfImage.GetEmfImage();
	// EmfImageRec_xZkqqHx_iCpAiDeOiDiKiDeBiBeCjDoAjFjEiCmMiDiBiDfOiDhEiDeAiDeDiDiLjEhKjHpBiCpAiJpAjFpKiClHiCoJiBeC_xHqqkZx_
	m_regRec.Clear();
	//----- _xZkqqHx_iDiBiDfOiDhEiDeAiDeDiDiLiDgOiDjDiDgIiDiLiCkJiCoHiDhCiDgCiDgHiDgGiBfLiDfOiCpAiOoGjDlO_xHqqkZx_ -----
	if (hEMF == NULL)
	{
		m_regRec.m_lEmfBitsSz = 0;
		m_regRec.m_bypEmfBits = NULL;
	} else
	{
		m_regRec.m_lEmfBitsSz = ::GetEnhMetaFileBits(hEMF, 0, NULL);
		m_regRec.m_bypEmfBits = new BYTE[m_regRec.m_lEmfBitsSz];
		GetEnhMetaFileBits(hEMF, m_regRec.m_lEmfBitsSz, m_regRec.m_bypEmfBits);
	}
	// _xZkqqHx_jGlMjBePiCmMiDfCiDjDiDgHiDiNiBfLiDiLiCkJiCoHjFlGiOjKjHpBiCpAiOoGjDlOiBeC_xHqqkZx_
	WString strName;
	FFGetDlgItemText(this, IDC_EMM_EDT_EMFNAME, strName);
	if (strName.length() < FD_ENV_NAME_LEN)
	{
		wcscpy(m_regRec.m_szName, strName.c_str());
	} else
	{
		wcsncpy(m_regRec.m_szName, strName.c_str(), FD_ENV_NAME_LEN - 1);
		m_regRec.m_szName[FD_ENV_NAME_LEN - 1] = L'\0';
	}
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnOK();
} // CFCDlgEmfImageModify::OnOK.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgEmfImageModify::OnEmmBtnPaste
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jDfMiCoIjFhEiCkPiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgEmfImageModify::OnEmmBtnPaste ()
{
	if (!OpenClipboard())
	{
		// IDS_ERR_MSG_CANNOT_OPEN_CLIPBOARD = "_xZkqqHx_iDeOiDiKiDgCiDhGiDhLiBfLiDgIiCkKiKeKiCkPiCnMiClJiCpB_xHqqkZx_"
		FFErrorBox(IDS_ERR_MSG_CANNOT_OPEN_CLIPBOARD);
		return;
	}
	// _xZkqqHx_iDeKiBfLiDfMiDiLiMgAiPpDiCpAjBnCiClPiPpDjBnEiCmJjFmPiNfIiBeC_xHqqkZx_
	BeginWaitCursor();
	// _xZkqqHx_iDiBiDfOiDhEiDeAiDeDiDiLiCmMiIoKiOjOjDeJiCmIiDgOiDjDiDgIiDiLiCpAiOoGjDlOiBeC_xHqqkZx_
	HENHMETAFILE hEMF = (HENHMETAFILE)::GetClipboardData(CF_ENHMETAFILE);
	// _xZkqqHx_iDeOiDiKiDgCiDhGiDhLiBfLiDgIiCkJiCoHiDiBiDfOiDhEiDeAiDeDiDiLiDgGiBfLiDfOiCkKiOoGjDlOiCmFiCkLiCmIiCkCiPoKiNiHiBeC_xHqqkZx_
	if (hEMF == NULL)
	{
		CloseClipboard();
		EndWaitCursor();
		// IDS_ERR_MSG_CLIPBOARD_IS_EMPTY = "_xZkqqHx_iDeOiDiKiDgCiDhGiDhLiBfLiDgIiCmJiDgGiBfLiDfOiCkKjHeMiCoIiCnMiClJiCpB_xHqqkZx_"
		FFErrorBox(IDS_ERR_MSG_CLIPBOARD_IS_EMPTY);
		return;
	}
	// _xZkqqHx_iIoKiOjOjDeJiCmIiDgOiDjDiDgIiDiLiCpAiDfCiDhDiBfLiClHiCoJiBeC_xHqqkZx_
	hEMF = ::CopyEnhMetaFile(hEMF, NULL);
	CloseClipboard();
	// _xZkqqHx_iDeKiBfLiDfMiDiLiMgAiPpDiCpAjGnPiClHiBeC_xHqqkZx_
	EndWaitCursor();
	// _xZkqqHx_iDfEiDjDiDhGiDiLiDhCiDiFiBfLiCmJiDiBiDfOiDhEiDeAiDeDiDiLiCpAjAnNjCoIiBeC_xHqqkZx_
	m_stcEmfImage.SetEmfImage(hEMF);
	m_stcEmfImage.Invalidate();
} // CFCDlgEmfImageModify::OnEmmBtnPaste.
