#include "stdafx.h"
// 06.10.11 Fukushiro M. 1_xZkqqHx_iNhDjCmHiJmB_xHqqkZx_ ()
#include "UtilMath.h"		// For mmroundoff.
#include "ObjGroup.h"		// For FCObjGroup.
#include "ObjRect.h"		// For FCObjRect.
#include "ToolTextPut.h"	// This header.

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


// 02.12.05 Fukushiro M. 1_xZkqqHx_iNhDiNoNiPjM_xHqqkZx_ ()
//FCToolTextPut g_toolTextPut;

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::FCToolTextPut
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfO_xHqqkZx_.
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.01.25 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCToolTextPut::FCToolTextPut ()
{
// 05.07.15 Fukushiro M. 1_xZkqqHx_iNhDiNoNiPjM_xHqqkZx_ ()
//	m_objpReference = NULL;		// _xZkqqHx_jDoAjFjEiDgDiBfLiDiLjDoAjFjEjFjEjFgJiBeC_xHqqkZx_
} // FCToolTextPut::FCToolTextPut.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::CreateInsideObject
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jDoAjFjEjFjEjFgJiCpAiNoMjAkMiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jDoAjFjEjFjEjFgJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.07.15 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCObjDynabase* FCToolTextPut::CreateInsideObject ()
{
	// _xZkqqHx_jDoAjFjEiDgDiBfLiDiLjDoAjFjEjFjEjFgJiNoMjAkMiBeC_xHqqkZx_
	FCObjDynabase* pObj = new FCObjRect();
	// _xZkqqHx_iDiKiDfEiDeDiDfJiDhEiDiMiBfLiDiAiCpAiNmEiMhGiOfKiBeC_xHqqkZx_
	pObj->CalcResizeFrame();
	// _xZkqqHx_iDfEiDeDiDfJiCpAiPiJiKpKiJlLiBeC_xHqqkZx_
// 06.10.11 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//	pObj->Resize(TRUE, TRUE, DBLRect(0.0, 0.0, 20.0, 10.0), pObj->GetResizeFrame());
	pObj->Resize(TRUE, TRUE, mmroundoff(DBLRect(0.0, 0.0, 20.0, 10.0)), pObj->GetResizeFrame());
//----- 06.11.26 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
	// _xZkqqHx_jFjEjFgJiCpAjEjCjAeGjDgIiCoIiCmCiCnEiClFiCmFiPiJiKpKiJlLiBeC_xHqqkZx_
	InitInsideObject(pObj);
//----- 06.11.26 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----
	return pObj;
} // FCToolTextPut::CreateInsideObject.

//----- 05.07.15 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
///*************************************************************************
// * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::OnViewCreate
// *
// * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	CFCDynamicDrawView::OnCreate_xZkqqHx_iCkJiCoH_xHqqkZx_Call_xZkqqHx_iBeC_xHqqkZx_Tool_xZkqqHx_iCmMiPiJiKpKiJlLiBeC_xHqqkZx_
// *
// * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.01.25 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
// *************************************************************************/
//void FCToolTextPut::OnViewCreate ()
//{
//	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
//	BASE_CLASS::OnViewCreate();
//	// _xZkqqHx_jDoAjFjEiDgDiBfLiDiLjDoAjFjEjFjEjFgJiNoMjAkMiBeC_xHqqkZx_
//	m_objpReference = new FCObjRect();
//	m_objpReference->CalcResizeFrame();
//// 05.05.02 Fukushiro M. 1_xZkqqHx_iNhDiNoNiPjM_xHqqkZx_ ()
////	m_objpReference->CalcOuterFrame();
//	m_objpReference->Resize(TRUE, TRUE, DBLRect(0.0, 0.0, 20.0, 10.0), m_objpReference->GetResizeFrame());
//} // FCToolTextPut::OnViewCreate.
//----- 05.07.15 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

//----- 05.07.15 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
///*************************************************************************
// * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::OnViewDestroy
// *
// * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	CFCDynamicDrawView::OnDestroy_xZkqqHx_iCkJiCoH_xHqqkZx_Call_xZkqqHx_iBeC_xHqqkZx_Tool_xZkqqHx_iCmMiPeJjHlJiPiIjHjNiBeC_xHqqkZx_
// *
// * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.01.25 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
// *************************************************************************/
//void FCToolTextPut::OnViewDestroy ()
//{
//	// _xZkqqHx_jDoAjFjEiDgDiBfLiDiLjDoAjFjEjFjEjFgJiNoNiPjMiBeC_xHqqkZx_
//	delete m_objpReference;
//	m_objpReference = NULL;
//	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
//	BASE_CLASS::OnViewDestroy();
//} // FCToolTextPut::OnViewDestroy.
//----- 05.07.15 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::GetDefaultIdleCursor
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	StateIdle_xZkqqHx_iCmFiDgGiDhEiDeIiDiLiDgHiCmJiOgHiCoNiCoKiCoJiDeKiBfLiDfMiDiLiDgOiDjDiDgIiDiLiCpAjFnEiClHiBeC_xHqqkZx_
 *			_xZkqqHx_jFfHiPiAiCmMiDeKiBfLiDfMiDiLiCmMiPoKiNiHiCmN_xHqqkZx_ NULL_xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.07.19 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
HCURSOR FCToolTextPut::GetDefaultIdleCursor () const
{
	return FFGetApp()->LoadCursor(IDC_CURSOR_TOOL_TEXT_PUT);
} // FCToolTextPut::GetDefaultIdleCursor.

//----- 05.07.15 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
///*************************************************************************
// * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::GetInsideObject
// *
// * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jFjEjFgJiCmMjAlGjAkMiCmJiOgHjHhAiClDiCoKiCoJjDoAjFjEiDgDiBfLiDiLjDoAjFjEjFjEjFgJiCpAjFnEiClH_xHqqkZx_.
// *
// * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jDoAjFjEiDgDiBfLiDiLjDoAjFjEjFjEjFgJiCmMiDhMiDeDiDjDiDfO_xHqqkZx_.
// *
// * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_iClBiCmMjFjEjFgJiCpAiOgHiCmBiCmEiBeBiDhNiDeFiDfIiInKjDkOiOjOiCmMjFgAiJoGiCoCjFjEjFgJiCmMjAlGjAkMiCpAiNhDiCkE_xHqqkZx_.
// *
// * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.01.25 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
// *************************************************************************/
//FCObjDynabase* FCToolTextPut::GetInsideObject () const
//{
//	return m_objpReference;
//} // FCToolTextPut::GetInsideObject.
//----- 05.07.15 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::CanHandle
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNjFjEjFgJiCkKiClBiCmMiDgDiBfLiDiLiCmFiIlFiCkGiCoJiCkJiCmHiCkEiCkJiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pObj	:_xZkqqHx_jFjEjFgJiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iJmCjEfMiCmMiPoKiNiHiCmN_xHqqkZx_ TRUE_xZkqqHx_iBeBjFhDiJmCjEfMiCmMiPoKiNiHiCmN_xHqqkZx_ FALSE _xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.06.14 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL FCToolTextPut::CanHandle (const FCObjDynabase* pObj) const
{
	// FCToolRichEditTmpl::CanHandle _xZkqqHx_iCkKiOfBiPmGjFjEjFgJiCkKjFnCiPfHiJmCjEfMiCmIiDiMiDeDiDiEiBfLiCmJ_xHqqkZx_
	// _xZkqqHx_iCmIiCkCiPoKiNiHiCmNjFhDiJmCiCmGiClFiCmEiClFiCnMiCkEiClNiCnPiBeBiDeJiBfLiDgPiBfLiDiJiDeDiDgIiClHiCoJiBeC_xHqqkZx_

	// pObj _xZkqqHx_iCkKiBeBjBeJjBpAiJmCjEfMiCmIiDiMiDeDiDiEiBfLiCmJjBkOiClFiCmEiCkCiCoKiCmO_xHqqkZx_TRUE_xZkqqHx_iBeC_xHqqkZx_
	if (g_pDoc->CanDoOnObject(pObj, FDOZ_ON_SELECT)) return TRUE;
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	return BASE_CLASS::CanHandle(pObj);
} // FCToolTextPut::CanHandle.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::IsValidReference
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNjFjEjFgJiCkKiBeBiDiKiDhEiDeAiDiMiDjDiDfIjFjEjFgJiCmGiClFiCmEjAlDiClFiCkCiCkJiCmHiCkEiCkJiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pObj	:_xZkqqHx_iDiKiDhEiDeAiDiMiDjDiDfIjFjEjFgJiMpDjFoCjFjEjFgJiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jAlDiClFiCkCiPoKiNiHiCmN_xHqqkZx_ TRUE_xZkqqHx_iBeBiKnEiIoBiCmBiCmEiCkCiCoJiPoKiNiHiCmN_xHqqkZx_ FALSE _xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.01.26 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL FCToolTextPut::IsValidReference (const FCObjDynabase* pObj) const
{
	if (pObj == NULL) return FALSE;
	// _xZkqqHx_jFjEjFgJiCkKiDhNiDfIiDeOiCmJiOgHiCkGiCoJiPoKiNiHiCmNiJmCiBeC_xHqqkZx_
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//	if (pObj->CanBeTextObject()) return TRUE;
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
	if (pObj->CanBeTextObject() &&
		FD_MIN_AREA_FOR_TEXT <= pObj->CalcArea())
		return TRUE;
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	// _xZkqqHx_iDePiDiLiBfLiDhGjFjEjFgJiCmFiCmIiCkCiCmIiCoHiCmOiBeBjFhDiJmCiBeC_xHqqkZx_
	if (!pObj->IsKindOf(FDOJ_GROUP)) return FALSE;
	//----- _xZkqqHx_iDePiDiLiBfLiDhGjFjEjFgJiCmMiPoKiNiH_xHqqkZx_ -----
	FCObjGroup* pGrp = (FCObjGroup*)pObj;
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//	ObjDynabaseVector vObj;
//	pGrp->GetCanBeTextObject(vObj);
//	if (!vObj.empty()) return TRUE;
//	return FALSE;
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
	return (pGrp->GetFrontEditableTextObj() != NULL);
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
} // FCToolTextPut::IsValidReference.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::StopToEditText
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDeHiDgGiDeCiDfOiCmMjFnCiPfHiPeJjHlJiOjOiCmJiMmEiCmOiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jCiNiInD_xHqqkZx_>	_xZkqqHx_iClBiClBiCmJjHiIiClNiOjOiCmNiLeMjIfOiDfKiDgCiDfGiDiHiDjDiCmMiNmFjCiGiCmFiCkAiCoJiClBiCmGiCmJjCiNiInDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	02.02.16 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCToolTextPut::StopToEditText ()
{
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::StopToEditText();
	// _xZkqqHx_iLeMjIfOiDfKiDgCiDfGiDiHiDjDiCmMiPeJjHlJiBeC_xHqqkZx_StateDoPutText_xZkqqHx_iKnGjAjEiCmFiKeKiOgOiClDiCoKiClNiDfKiDgCiDfGiDiHiDjDiCpAjFmCiClGiCoJiBeC_xHqqkZx_
	g_pDoc->SessionEnd();
} // FCToolTextPut::StopToEditText.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCToolTextPut::StateDoPutText
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgFiDeMiDfIiDgHjAnNjCoIiPiIjHjNiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pDC	:_xZkqqHx_jFgAiJoGjHhAiDgGiDgPiDeDiDfIiDfCiDjDiDgFiDeMiDfIiDgHiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.01.25 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCToolTextPut::StateDoPutText (CDC* pDC)
{
	TRACE(_T("StateDoPutText\r\n"));
	// _xZkqqHx_iLeMjIfOiDfKiDgCiDfGiDiHiDjDiKeKiOgOiBeC_xHqqkZx_BASE_CLASS::StateDoPutText_xZkqqHx_iBeB_xHqqkZx_StartToEditText_xZkqqHx_jCiG_xHqqkZx_
	// _xZkqqHx_iCmFiCoA_xHqqkZx_SessionBegin_xZkqqHx_iCmNiOmAiNhDiClDiCoKiCoJiCkKiBeBiClBiCmMjDpBiCmCiCpAiCfAiDfKiDgCiDfGiDiHiDjDiCmJiKiHiCoJiClNiCnPiBeB_xHqqkZx_
	// _xZkqqHx_iClBiClBiCmFiOmAiNhDiClHiCoJiBeC_xHqqkZx_
	g_pDoc->SessionBegin();
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::StateDoPutText(pDC);
	if (m_pReference != NULL)
	//----- _xZkqqHx_iDiKiDhEiDeAiDiMiDjDiDfIjFjEjFgJiCkKjBlGiNnNiClHiCoJiPoKiNiH_xHqqkZx_ -----
	{
		// BASE_CLASS::StateDoPutText_xZkqqHx_iCmJiCkIiCkCiCmEiBeBiDiKiDhEiDeAiDiMiDjDiDfIjFjEjFgJiCmM_xHqqkZx_
		// _xZkqqHx_jFkBjAlLiCkK_xHqqkZx_SetLastCreateObj_xZkqqHx_iCmFjAnNjCoIiClDiCoKiCmEiCkCiCoJiBeC_xHqqkZx_
		FCObjDynabase* pNewObject = (FCObjDynabase*)GetLastCreateObj();
		// _xZkqqHx_iDgFiDeMiDfIiDgHjFjEjFgJiCpAiDeHiDgGiDeCiDgCiDgHiPpDjBnEiCmJiClHiCoJiBeC_xHqqkZx_
		if (!pNewObject->IsKindOf(FDOJ_GROUP))
		//----- _xZkqqHx_iDePiDiLiBfLiDhGjFjEjFgJiCmFiCmNiCmIiCkCiPoKiNiH_xHqqkZx_ -----
		{
			// _xZkqqHx_iDePiDiLiBfLiDhGjFjEjFgJiCmFiCmIiCkCiCmIiCoHiCmOiBeBiClLiCmMiCnMiCnMjFnCiPfHiBeC_xHqqkZx_
			StartToEditText((FCObjFigure*)pNewObject, NULL, NULL);
		} else
		//----- _xZkqqHx_iDePiDiLiBfLiDhGjFjEjFgJiCmMiPoKiNiH_xHqqkZx_ -----
		{
			FCObjGroup* pGrp = (FCObjGroup*)pNewObject;
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//			ObjDynabaseVector vObj;
//			pGrp->GetCanBeTextObject(vObj);
//			// _xZkqqHx_iNmFiPiJiCmMiDgFiDeMiDfIiDgHjFjEjFgJiCpAiDeHiDgGiDeCiDgCiDgHiPpDjBnEiCmJiClHiCoJiBeC_xHqqkZx_
//			StartToEditText((FCObjFigure*)vObj.front(), pNewObject, NULL);
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
			// _xZkqqHx_iNmFiPiJiCmMiDgFiDeMiDfIiDgHjFjEjFgJiCpAiDeHiDgGiDeCiDgCiDgHiPpDjBnEiCmJiClHiCoJiBeC_xHqqkZx_
			StartToEditText((FCObjFigure*)pGrp->GetFrontEditableTextObj(), pNewObject, NULL);
//----- 06.12.07 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
		}
	}
	// _xZkqqHx_iDgFiDeMiDfIiDgHjFnCiPfHjCiGiCmFjGlDiCkPiCoKiCmOiBeBiLeMjIfOiDfKiDgCiDfGiDiHiDjDiCmMiPeJjHlJiBeC_xHqqkZx_
	// _xZkqqHx_iPoDiLeMiCmFiKeKiOgOiClDiCoKiClNiDfKiDgCiDfGiDiHiDjDiCmNiBeB_xHqqkZx_StopToEditText_xZkqqHx_iKnGjAjEiCmFjFmCiClGiCoJiClNiCnPiBeB_xHqqkZx_
	// StartToEditText _xZkqqHx_iCmFiDgFiDeMiDfIiDgHjFnCiPfHiKeKiOgOiCkKjAkMiMpHiClFiClNiPoKiNiHiCmMiCnNiBeB_xHqqkZx_
	// _xZkqqHx_jHeMiMpIiCmGiClFiCmIiCkPiCoKiCmOiCmIiCoHiCmIiCkCiBeC_xHqqkZx_
	if (!IsEditingText()) g_pDoc->SessionEnd();
} // FCToolTextPut::StateDoPutText.
