// TolBrLayer.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "DynamicDraw.h"
//#include "RegData.h"		// For GetRegFontStatic.
#include "FoundDoc.h"		// For g_pDoc.
#include "DynamicDrawView.h"// For g_pView.
#include "LayerManager.h"	// For FCLayerManager.
#include "UtilWin.h"		// For FFAddString.
#include "ToolBase.h"		// For GetCurrentTool.
#include "HiCommandTable.h"		// For FD_CMD_XXXX.
#include "TolBrLayer.h"		// This header.

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

// _xZkqqHx_iDhLiDgCiDeOiDfIiCmMjFjNiBeC_xHqqkZx_
static const int s_nBoxWidth = 150;
// _xZkqqHx_iDgIiDiNiDgCiDhGiDfPiDeFiDjDiCmMjFjNiBeC_xHqqkZx_
static const int s_nDroppedWidth = 250;
// _xZkqqHx_iDgIiDiNiDgCiDhGiDfPiDeFiDjDiCmMiNiCiClDiBeC_xHqqkZx_
static const int s_nDroppedHeight = 500;

/////////////////////////////////////////////////////////////////////////////
// CFCTolBrLayer

CFCTolBrLayer::CFCTolBrLayer ()
{
} // CFCTolBrLayer::CFCTolBrLayer.

CFCTolBrLayer::~CFCTolBrLayer ()
{
} // CFCTolBrLayer::~CFCTolBrLayer.

/////////////////////////////////////////////////////////////////////////////
// CFCTolBrLayer _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::Initialize
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgDiBfLiDiLiDgPiBfLiCpAiPiJiKpKiJlLiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jAlDiPoNiPeJjHlJiCmMiPoKiNiHiCmN_xHqqkZx_ TRUE_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.29 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL CFCTolBrLayer::Initialize ()
{
	// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	if (!BASE_CLASS::Initialize()) return FALSE;
	// _xZkqqHx_jBePiJpBiCmMiNmEjFfMiOkGiImIiNhOiCmJiDfGiBfLiDgHiCkKjFmPiNfIiClDiCoKiClNiCkJiBeI_xHqqkZx_
	m_bIsSheetChanged = FALSE;

	// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmMiDgGiBfLiDfOiCpAiNfIjAfGiBeC_xHqqkZx_
	OnLayerUpdated();
	// _xZkqqHx_jAlDiPoNiPeJjHlJiBeC_xHqqkZx_
	return TRUE;
} // CFCTolBrLayer::Initialize.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::OnLayerUpdated
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDeDiDiEiBfLiCkKiNfIjAfGiClDiCoKiClNiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.29 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCTolBrLayer::OnLayerUpdated ()
{
	// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmMiDgGiBfLiDfOiCpAiNfIjAfGiBeC_xHqqkZx_
	m_cmbCurLayer.ResetContent();
	for (long lC = 0; lC < g_pDoc->CurrentSheet()->GetLayerSize(); lC++)
	{
		long lLayerIndex = g_pDoc->CurrentSheet()->GetLayerSize() - lC - 1;
		WString wstrName;
		g_pDoc->CurrentSheet()->GetLayerInfo(&wstrName, NULL, lLayerIndex);
		WString str;
		str.Format(L"%ld.%s", lLayerIndex, wstrName.c_str());
		FFAddString(&m_cmbCurLayer ,str);
	}
	// _xZkqqHx_iMlLiNnNjCgMiCpAjAnNjCoIiBeC_xHqqkZx_
	m_cmbCurLayer.SetCurSel(g_pDoc->CurrentSheet()->GetLayerSize() -
							g_pDoc->CurrentSheet()->GetCurrentLayerIdx() - 1);
} // CFCTolBrLayer::OnLayerUpdated.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::GetCmbButtonInfo
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiDhLiDfOiDjDiCmMiPoOjFpBiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	lIndex	:_xZkqqHx_iPoOjFpBiCmMiDeDiDjDiDgGiDgCiDeOiDfIiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiDhLiDfOiDjDiCmMiPoOjFpBiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_iClBiCoKiImIiPoDiDhLiDfOiDjDiCmMiPoOjFpBiCkKjGlDiCkCiPoKiNiHiCmNiBeB_xHqqkZx_FCCmbButtonInfo::pCmb = NULL
 *			_xZkqqHx_iCmMiPoOjFpBiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.06.29 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
const CFCTolBrBase::FCCmbButtonInfo& CFCTolBrLayer::GetCmbButtonInfo (long lIndex)
{
	static FCCmbButtonInfo s_info[] =
	{
		{	&m_cmbCurLayer,						// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIjFmPjAjEiBeC_xHqqkZx_
			ID_CMB_CURRENT_LAYER,				// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmM_xHqqkZx_ID_xZkqqHx_iBeC_xHqqkZx_
			CBS_DROPDOWNLIST,					// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmMjCmHiJmBiDfIiDfOiDeDiDiLiBeC_xHqqkZx_WS_VISIBLE|WS_VSCROLL|WS_TABSTOP _xZkqqHx_iCmNjFfHiPiAiBeC_xHqqkZx_
			s_nBoxWidth,						// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmMjFjNiBeC_xHqqkZx_
			s_nDroppedWidth,					// _xZkqqHx_iDgIiDiNiDgCiDhGiDfPiDeFiDjDiCmMjFjNiBeC_xHqqkZx_
			s_nDroppedHeight },					// _xZkqqHx_iDgIiDiNiDgCiDhGiDfPiDeFiDjDiCmMiNiCiClDiBeC_xHqqkZx_
		{	NULL,								// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIjFmPjAjEiBeC_xHqqkZx_
			0,									// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmM_xHqqkZx_ID_xZkqqHx_iBeC_xHqqkZx_
			0,									// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmMjCmHiJmBiDfIiDfOiDeDiDiLiBeC_xHqqkZx_WS_VISIBLE|WS_VSCROLL|WS_TABSTOP _xZkqqHx_iCmNjFfHiPiAiBeC_xHqqkZx_
			0,									// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIiCmMjFjNiBeC_xHqqkZx_
			0,									// _xZkqqHx_iDgIiDiNiDgCiDhGiDfPiDeFiDjDiCmMjFjNiBeC_xHqqkZx_
			0 },								// _xZkqqHx_iDgIiDiNiDgCiDhGiDfPiDeFiDjDiCmMiNiCiClDiBeC_xHqqkZx_
	};
	return s_info[lIndex];
} // CFCTolBrLayer::GetCmbButtonInfo.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::OnCmdSessionEnded
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	CommandGate_xZkqqHx_iCmMiDfKiDgCiDfGiDiHiDjDiPeJjHlJiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.07.02 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCTolBrLayer::OnCmdSessionEnded ()
{
	// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnCmdSessionEnded();
	if (m_bIsSheetChanged)
	{
		OnLayerUpdated();
		// _xZkqqHx_jBePiJpBiCmMiNmEjFfMiOkGiImIiNhOiCmJiDfGiBfLiDgHiCkKjFmPiNfIiClDiCoKiClNiCkJiBeI_xHqqkZx_
		m_bIsSheetChanged = FALSE;
	}
} // CFCTolBrLayer::OnCmdSessionEnded.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::OnCommandCalled
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	CommandGate_xZkqqHx_iCmFiDfCiDhNiDjDiDgIiCkKiPiIjHjNiClDiCoKiClNiCmGiCkLiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	gateCmd	:_xZkqqHx_iDfCiDhNiDjDiDgIiCmMiOoNjHnOiCpAiOhHjCoIiBeC_xHqqkZx_
 *			lParam	:_xZkqqHx_iDfCiDhNiDjDiDgIiCmMiIpIjAjEiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.07.02 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCTolBrLayer::OnCommandCalled (FTGateCmd gateCmd, LPARAM lParam)
{
	// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnCommandCalled(gateCmd, lParam);
	switch (gateCmd)
	{
	case FD_CMD_INSERT1_SHEET:				// _xZkqqHx_iCfAiDfGiBfLiDgHiCpAjCmHiJmBiDfCiDhNiDjDiDgIiBeC_xHqqkZx_
	case FD_CMD_DELETE1_SHEET:				// _xZkqqHx_iCfAiDfGiBfLiDgHiCpAiNoNiPjMiDfCiDhNiDjDiDgIiBeC_xHqqkZx_
	case FD_CMD_MODIFY1_SHEET:				// _xZkqqHx_iCfAiDfGiBfLiDgHiCpAjFmPiNfIiDfCiDhNiDjDiDgIiBeC_xHqqkZx_
	case FD_CMD_RE_ORDER_SHEET:				// _xZkqqHx_iDfGiBfLiDgHiCmMjFmAiCnHjBnGiCkGiDfCiDhNiDjDiDgIiBeC_xHqqkZx_
		// _xZkqqHx_jBePiJpBiCmMiNmEjFfMiOkGiImIiNhOiCmJiDfGiBfLiDgHiCkKjFmPiNfIiClDiCoKiClNiCkJiBeI_xHqqkZx_
		m_bIsSheetChanged = TRUE;
		break;
	}
} // CFCTolBrLayer::OnCommandCalled.

/////////////////////////////////////////////////////////////////////////////
// CFCTolBrLayer _xZkqqHx_iDiGiBfLiDfFiDeJiBfLiDgPiBfLiDiJiDeDiDgIiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::OnUpdateCmdUI
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgDiBfLiDiL_xHqqkZx_ _xZkqqHx_iDgPiBfLiCnMiClNiCmNiDfIiDgFiBfLiDfOiDfI_xHqqkZx_ _xZkqqHx_iDgPiBfLiCmMiPpDjBnEiCpAiNfIjAfGiClHiCoJiClNiCnPiCmJiBeB_xHqqkZx_
 *			_xZkqqHx_iDhEiDiMiBfLiDiAiDiPiBfLiDeOiCkKiMmEiCnBiPgPiClFiCnMiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pTarget	:_xZkqqHx_iDeBiDhGiDiKiDfAiBfLiDfGiDiHiDjDiCmMiDiBiDeDiDjD_xHqqkZx_ _xZkqqHx_iDhEiDiMiBfLiDiAiCnGiCmMiDhMiDeDiDjDiDfOiBeC_xHqqkZx_
 *			bDisableIfNoHndler :_xZkqqHx_iNfIjAfGiDgOiDjDiDgIiDiJiCpAiOjNiCmBiCmEiCkCiCmIiCkCiDfCiDjDiDgHiDiNiBfLiDiLiCpA_xHqqkZx_
 *								_xZkqqHx_iOkJjDkOjDeJiCmJiLnGiOhOiPpDjBnEiCmFjFfMiOkGiClHiCoJiCkJiCmHiCkEiCkJiCpAiOkGiClHiDhEiDiJiDePiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.29 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCTolBrLayer::OnUpdateCmdUI (CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
	if (::IsWindow(m_hWnd))
	{
//----- 05.08.16 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//		m_cmbCurLayer.EnableWindow(g_pView->GetCurrentTool()->CanLayerOrder());
//----- 05.08.16 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
		m_cmbCurLayer.EnableWindow(FFCanEditReadOnlyDocumentEnv());
//----- 05.08.16 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	}
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
} // CFCTolBrLayer::OnUpdateCmdUI.

BEGIN_MESSAGE_MAP(CFCTolBrLayer, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCTolBrLayer)
		// _xZkqqHx_iDiBiDiC_xHqqkZx_ - ClassWizard _xZkqqHx_iCmNiClBiCmMiImKjChFiCmJiDhNiDgCiDhDiDjDiDePjHhAiCmMiDhNiDeOiDiNiCpAjCmHiJmBiCnMiClNiCmNiNoNiPjMiClFiCnMiClHiBeC_xHqqkZx_
	//}}AFX_MSG_MAP
	ON_CBN_SELCHANGE(ID_CMB_CURRENT_LAYER, OnSelchangeCmbCurrentLayer)
	ON_MESSAGE(WM_USER_LAYER_UPDATED, OnUserLayerUpdated)
	ON_MESSAGE(WM_USER_SHEET_CHANGED, OnUserLayerUpdated)
	ON_MESSAGE(WM_USER_CURRENT_SHEET_CHANGED, OnUserLayerUpdated)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCTolBrLayer _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::OnSelchangeCmbCurrentLayer
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgDiBfLiDiLiDgPiBfLiCmMiBeBiDfCiDjDiDhLiDhLiDgCiDeOiDfIiCkKjFmPiNfIiClDiCoKiClNiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.29 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCTolBrLayer::OnSelchangeCmbCurrentLayer ()
{
	// _xZkqqHx_jFmPiNfIiClDiCoKiClNiMoDiCmJjGpAiKiE_xHqqkZx_Id_xZkqqHx_iCpAiOoGjDlOiBeC_xHqqkZx_
	const int iIdx = m_cmbCurLayer.GetCurSel();
	g_pView->GetCurrentTool()->OnMoveCurrentLayer(
								g_pDoc->CurrentSheet()->GetLayerSize() - iIdx - 1);
} // CFCTolBrLayer::OnSelchangeCmbCurrentLayer.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCTolBrLayer::OnUserLayerUpdated
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDeDiDiEiBfLiCkKiNfIjAfGiClDiCoKiClNiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	wParam	:_xZkqqHx_jGkCiOgHjHhAiBeC_xHqqkZx_
 *			lParam	:_xZkqqHx_jGkCiOgHjHhAiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iPoNiCmJiCfAiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.07.02 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
LRESULT CFCTolBrLayer::OnUserLayerUpdated (WPARAM wParam, LPARAM lParam)
{
	OnLayerUpdated();
	return 1;
} // CFCTolBrLayer::OnUserLayerUpdated.

