// DlgLayerOrder.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include <algorithm>		// For reverse.
// 03.05.03 Fukushiro M. 1_xZkqqHx_iNhDiNoNiPjM_xHqqkZx_ ()
//#include <map>				// For map template.
#include "DynamicDraw.h"
// 03.07.18 Fukushiro M. 1_xZkqqHx_iNhDiNoNiPjM_xHqqkZx_ ()
//#include "MainFrame.h"		// For g_pFrame.
#include "FoundDoc.h"		// For g_pDoc.
#include "DynamicDrawView.h"	// For g_pView.
#include "ObjDynabase.h"		// For FCObjDynabase.
#include "UtilStdLib.h"		// For m1_for.
#include "UtilStr.h"		// For GetResString.
#include "UtilDlg.h"		// For FFJustifyWindow.
#include "LinkManager.h"	// For g_pDoc->LinkManager().
#include "LayerManager.h"	// For FCLayerManager.
#include "SheetManager.h"	// For FCSheetManager.
#include "FrameWnd.h"		// For FFGetMainWnd().
#include "DlgLayerOrder.h"	// This header.

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

/////////////////////////////////////////////////////////////////////////////
// CFCDlgLayerOrder _xZkqqHx_iDfPiDeDiDeBiDiNiDeP_xHqqkZx_

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

void CFCDlgLayerOrder::DoDataExchange(CDataExchange* pDX)
{
	BASE_CLASS::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFCDlgLayerOrder)
	DDX_Control(pDX, IDC_LYO_LSV_LAYER, m_layerList);
	//}}AFX_DATA_MAP
} // CFCDlgLayerOrder::DoDataExchange.

BEGIN_MESSAGE_MAP(CFCDlgLayerOrder, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCDlgLayerOrder)
	ON_BN_CLICKED(ID_APPLY_NOW, OnApplyNow)
	ON_BN_CLICKED(IDC_LYO_BTN_LAYER_MERGE, OnLyoBtnLayerMerge)
	ON_BN_CLICKED(IDC_LYO_BTN_LAYER_MODIFY, OnLyoBtnLayerModify)
	ON_BN_CLICKED(IDC_LYO_BTN_LAYER_ADD, OnLyoBtnLayerAdd)
	ON_BN_CLICKED(IDC_LYO_BTN_LAYER_DELETE, OnLyoBtnLayerDelete)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER_MULTICTRL_CHANGED, OnUserMultictrlChanged)
	ON_MESSAGE(WM_USER_LISTCTRL_SELCHANGED, OnUserListctrlSelchanged)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCDlgLayerOrder _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::SetSheetManager
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfGiBfLiDgHiDhNiDgMiBfLiDfHiDiDiCpAjAnNjCoIiBeC_xHqqkZx_DoModal_xZkqqHx_iCmMjBePiCmJjFeLiClIiOmAiNhDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pSheetMgr	:_xZkqqHx_iDfGiBfLiDgHiDhNiDgMiBfLiDfHiDiDiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.20 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::SetSheetManager (const FCSheetManager* pSheetMgr)
{
	m_pSheetMgr = pSheetMgr;
} // CFCDlgLayerOrder::SetSheetManager.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::InitControl
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCpAiPiJiKpKiJlLiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.19 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::InitControl ()
{
	//----- _xZkqqHx_iMiLiJmKjFfMiOkGiDiKiDfIiDgHiDfCiDjDiDgHiDiNiBfLiDiLiCmMjAnNjCoI_xHqqkZx_ -----
	DWORDSet stSelected;
	long lTopPos;
	BOOL bRecorded = (0 < m_layerList.GetItemCount());
	if (bRecorded)
	//----- _xZkqqHx_iKpJiCmJjAnNjCoIiClDiCoKiCmEiCkCiCoJiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_jBeJjBpAiDiKiDfIiDgHiCpAjFnLjBlGiBeC_xHqqkZx_
		POSITION pos = m_layerList.GetFirstSelectedItemPosition();
		while (pos)
			stSelected.insert(m_layerList.GetNextSelectedItem(pos));
		lTopPos = m_layerList.GetItemHeight() * m_layerList.GetTopIndex();
	}
	// _xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCpAiDeOiDiKiDeBiBeC_xHqqkZx_
	m_layerList.ClearContents();
	DWORDVector vOrder;
	for (DWORD dwId = 0; dwId < m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetLayerSize(); dwId++)
	{
		vOrder.push_back(dwId);
		WORD wFlag;
		WString wstrName;
		m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetLayerInfo(&wstrName, &wFlag, dwId);
		FCLayerCtrlRec rec;
		rec.strName = wstrName;
		rec.SetFlag(wFlag);
		m_layerList.AppendRec(dwId, rec);
	}
	// _xZkqqHx_iDiMiDeDiDiEiBfLjBhNjDpMiOjOiCmMiDiMiDeDiDiEiBfL_xHqqkZx_ID_xZkqqHx_iCmMiPiJiKpKjCgMiCpAiOhHjCoIiBeC_xHqqkZx_
	m_layerList.SetNextFreeId(m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetLayerSize());
	// _xZkqqHx_iDiMiDfCiBfLiDgIjFfMiOkGiPiHiCpAjAnNjCoIiBeC_xHqqkZx_
	reverse(vOrder.begin(), vOrder.end());
	m_layerList.SetIdOrder(vOrder.size(), vOrder.begin());
	// _xZkqqHx_iDeKiDiMiDjDiDgHiDiMiDeDiDiEiBfLiCpAjAnNjCoIiBeC_xHqqkZx_
	m_layerList.SetCurrentLayerIdx(
					m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetCurrentLayerIdx());
	if (bRecorded)
	//----- _xZkqqHx_iKpJiCmJjAnNjCoIiClDiCoKiCmEiCkCiClNiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iMlDiCmMjBeJjBpAiDiKiDfIiDgHiCpAjAnNjCoIiBeC_xHqqkZx_
		DWORDSet::iterator iSt;
		for (iSt = stSelected.begin(); iSt != stSelected.end(); iSt++)
			m_layerList.SetItemState(*iSt, LVIS_SELECTED, LVIS_SELECTED);
		m_layerList.Scroll(CSize(0, lTopPos));
	} else
	//----- _xZkqqHx_jAnNjCoIiClDiCoKiCmEiCkCiCmIiCkJiCmBiClNiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCmMjFjNiCmJiNiHiCoNiClJiCmEiDeKiDiJiDiAiCpAjAnNjCoIiBeC_xHqqkZx_
		m_layerList.UpdateColumnWidth();
	}
	// _xZkqqHx_iDhEiDeIiBfLiDeKiDfIiCpAjAnNjCoIiBeC_xHqqkZx_
	m_layerList.SetFocus();
} // CFCDlgLayerOrder::InitControl.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::IsLayerChanged
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDeDiDiEiBfLiPoOjFpBiCkKjFmPiNfIiClDiCoKiCmEiCkCiCoJiCkJiCmHiCkEiCkJiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jFmPiNfIiCmMiPoKiNiHiCmN_xHqqkZx_ TRUE_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.24 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL CFCDlgLayerOrder::IsLayerChanged () const
{
	// _xZkqqHx_iDeKiDiMiDjDiDgHiDiMiDeDiDiEiBfLiCkKjFmPiNfIiClDiCoKiCmEiCkCiCoJiCkJiBeI_xHqqkZx_
	if (m_layerList.GetCurrentLayerIdx() !=
		m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetCurrentLayerIdx())
		return TRUE;
	if (!m_layerList.GetInsertedIdSet().empty()) return TRUE;
	if (!m_layerList.GetRemovedIdSet().empty()) return TRUE;
	if (!m_layerList.GetChangedIdSet().empty()) return TRUE;
	if (!m_layerList.GetMergedIdSet().empty()) return TRUE;
	DWORDVector vdwId;
	m_layerList.GetIdOrder(vdwId);
	if (vdwId.size() != m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetLayerSize()) return TRUE;
	for (DWORD dwId = 0; dwId < vdwId.size(); dwId++)
		if (vdwId[dwId] != vdwId.size() - 1 - dwId) return TRUE;
	return FALSE;
} // CFCDlgLayerOrder::IsLayerChanged.

/////////////////////////////////////////////////////////////////////////////
// CFCDlgLayerOrder _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnInitDialog
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfPiDeDiDeBiDiNiDePiPiJiKpKiJlLiPiIjHjNiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.12 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL CFCDlgLayerOrder::OnInitDialog ()
{
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnInitDialog();
	// _xZkqqHx_iDiMiDeDiDiEiBfLiDiKiDfIiDgHiDfCiDjDiDgHiDiNiBfLiDiLiCmMiPiJiKpKiJlLiBeC_xHqqkZx_
	m_layerList.Initialize();

	// _xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCpAiPiJiKpKiJlLiClHiCoJiBeC_xHqqkZx_
	InitControl();

//----- 00.12.31 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
	// _xZkqqHx_iDfPiDeDiDeBiDiNiDePiCmMjCfAiImKjFfMiOkGiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
	::SetUnitString(m_hWnd);
	// _xZkqqHx_jHjIiCkLjIhCjBmOiJjOjFlGiOjKjHpBiCmMjAnNjCoIiCpAiNhDiCkEiBeC_xHqqkZx_
	::RightByLeftHand(m_hWnd);
	// _xZkqqHx_iDfPiDeDiDeBiDiNiDePiCpAiDhNiDeFiDfIiImKjChFiCmJiInKjDkOiBeC_xHqqkZx_
	FFJustifyWindow(m_hWnd);
//----- 00.12.31 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----

	// _xZkqqHx_iDiMiDeDiDiEiBfLiCmMjFmPiNfIiCpAjCmKjCgNiBeC_xHqqkZx_
	PostMessage(WM_USER_MULTICTRL_CHANGED, 0, 0);
	return TRUE;  // _xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCmJiDhEiDeIiBfLiDeKiDfIiCpAjAnNjCoIiClFiCmIiCkCiCmGiCkLiBeBjGnPiCoIjCgMiCmN_xHqqkZx_ TRUE _xZkqqHx_iCmGiCmIiCoIiCnMiClH_xHqqkZx_
	              // _xZkqqHx_jHoBiKeP_xHqqkZx_: OCX _xZkqqHx_iDhGiDiNiDhAiDgFiDeC_xHqqkZx_ _xZkqqHx_iDhJiBfLiDfHiCmMjGnPiCoIjCgMiCmN_xHqqkZx_ FALSE _xZkqqHx_iCmGiCmIiCoIiCnMiClH_xHqqkZx_
} // CFCDlgLayerOrder::OnInitDialog.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnOK
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iCgOiCgKiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.20 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::OnOK ()
{
	// _xZkqqHx_jFmPiNfIiCkAiCoKiCmOiBeBjFmPiNfIiPiIjHjNiBeC_xHqqkZx_
//----- 05.10.22 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//// 05.08.16 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
////	if (IsLayerChanged() && FFCanEditDocumentEnv()) OnApplyNow();
//	if (IsLayerChanged()) OnApplyNow();
//----- 05.10.22 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
	if (IsLayerChanged() && FFCanEditReadOnlyDocumentEnv()) OnApplyNow();
//----- 05.10.22 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnOK();
} // CFCDlgLayerOrder::OnOK.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnApplyNow
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iBhFjDeLjHhAiDhLiDfOiDjDiBhGiCkKiJjPiClDiCoKiClNiCmGiCkLiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.24 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::OnApplyNow ()
{
	// _xZkqqHx_iDiMiDeDiDiEiBfLiDfCiDjDiDgHiDiNiBfLiDiLiCmFiCmMjFmPiNfIiCmJiCmNiBeBiImIiJlKiCmMiOoNjHnOiCkKiCkAiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iKpJjBlGiDiMiDeDiDiEiBfLiCmMjFmPiNfI_xHqqkZx_
	// _xZkqqHx_iKpJjBlGiDiMiDeDiDiEiBfLiCmMiNoNiPjM_xHqqkZx_
	// _xZkqqHx_jAfGiLeLiDiMiDeDiDiEiBfLiCmMiNoMjAkMiBjFjBhNjDpM_xHqqkZx_
	// _xZkqqHx_iDiMiDeDiDiEiBfLiCmMjFmAiCnHjBnGiCkG_xHqqkZx_
	// _xZkqqHx_iDeKiDiMiDjDiDgHiDiMiDeDiDiEiBfLiCmMjFmPiNfI_xHqqkZx_
	// _xZkqqHx_iClBiCoKiCoHiCmMjBiAiNoMiCkKiOhLiClDiCoKiCoJjBePiCmMiDiMiDeDiDiEiBfLiCmGiMoDiCmMiDiMiDeDiDiEiBfLiCpAjEoEiKhCiClFiCmEiBeB_xHqqkZx_
	// _xZkqqHx_iImIiJlKiCmMiOoIiPiHiCmFiBeBjBiAiNoMiCmMiDfCiDhNiDjDiDgIiCpAiNoMjAkMiClHiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iCfAiBeEiDfCiDjDiDgHiDiNiBfLiDiLiCmFiNoNiPjMiClDiCoKiClNiDiMiDeDiDiEiBfLiCpAiBeBiNoNiPjMiClHiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iCfBiBeEiDfCiDjDiDgHiDiNiBfLiDiLiCmFjAfGiLeLiNoMjAkMiClDiCoKiClNiDiMiDeDiDiEiBfLiCpAiBeBiDiMiDeDiDiEiBfLiDiKiDfIiDgHiNmFiMoDiCmJjBhNjDpMiClHiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iCfCiBeEiDfCiDjDiDgHiDiNiBfLiDiLiCmFjFmPiNfIiClDiCoKiClNiDiMiDeDiDiEiBfLiCpAiBeBiCnMiClIjFmPiNfIiClHiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iCfDiBeEiDfCiDjDiDgHiDiNiBfLiDiLiCmFiCmMjFmAiCnHjBnGiCkGiCpAiOmAiNhDiClHiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iCfEiBeEiDeKiDiMiDjDiDgHiDiMiDeDiDiEiBfLiCmMjFmPiNfIiCpAiOmAiNhDiClHiCoJiBeC_xHqqkZx_
	//

	BOOL bModified = FALSE;

	if (g_pDoc->IsReadOnly())
	//----- ReadOnly_xZkqqHx_iCmMiPoKiNiH_xHqqkZx_ -----
	{
		//----- _xZkqqHx_jFmPiNfIiDeBiDeDiDgFiDiAiDiKiDfIiDgHiCpAiOoGiCoIiPgPiClFiBeBiDeBiDeDiDgFiDiAiCpAjFmPiNfIiClHiCoJ_xHqqkZx_ -----
		DWORDSet::const_iterator iSt;
		for (iSt = m_layerList.GetChangedIdSet().begin();
			 iSt != m_layerList.GetChangedIdSet().end(); iSt++)
		{
			BOOL bViewUpdated;
			g_pDoc->CurrentSheet()->ModifyLayer(bViewUpdated,
												*iSt, m_layerList.GetRec(*iSt)->strName,
												m_layerList.GetRec(*iSt)->GetFlag());
		}
		// _xZkqqHx_iDeKiDiMiDjDiDgHiDiMiDeDiDiEiBfLiCpAjFmPiNfIiBeC_xHqqkZx_
		g_pDoc->CurrentSheet()->SetCurrentLayerIdx(m_layerList.GetCurrentLayerIdx());
		bModified = TRUE;
	} else
	//----- Write_xZkqqHx_iJmCiCmMiPoKiNiH_xHqqkZx_ -----
	{
//----- 06.12.05 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
		// _xZkqqHx_jFjEjFgJiCkKiNoNiPjMiClDiCoKiClNiCkJiBeI_xHqqkZx_
		BOOL bIsDeleted = FALSE;
//----- 06.12.05 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----
		map<DWORD, DWORD> id2idxMap;	// _xZkqqHx_iMlDiCmMiDiMiDeDiDiEiBfL_xHqqkZx_ID_xZkqqHx_iCkJiCoHjFmPiNfIiMoDiCmMiDiMiDeDiDiEiBfL_xHqqkZx_Idx_xZkqqHx_iCnGiBeC_xHqqkZx_
		//----- ID -> Idx_xZkqqHx_jFmPiKlHiDgFiBfLiDhFiDiLiCpAiNoMjAkM_xHqqkZx_ ----
		DWORDVector vdwId;
		// 5, 10, 3, 4, 9 _xZkqqHx_iBgJjHoBiBgKiCpAiOoGjDlOiBeC_xHqqkZx_
		m_layerList.GetIdOrder(vdwId);
		// 5, 10, 3, 4, 9 -> 3, 4, 5, 9, 10 _xZkqqHx_iCmJiDfMiBfLiDgHiBeC_xHqqkZx_
		sort(vdwId.begin(), vdwId.end());
		DWORD dwIdx;
		// [3 -> 0],[4 -> 1],[5 -> 2],[9 -> 3],[10 -> 4]_xZkqqHx_iCpAiNoMjAkMiBeC_xHqqkZx_
		for (dwIdx = 0; dwIdx < vdwId.size(); dwIdx++)
			id2idxMap[vdwId[dwIdx]] = dwIdx;
		// _xZkqqHx_iDfKiDgCiDfGiDiHiDjDiKeKiOgOiPiIjHjNiBeC_xHqqkZx_
		g_pDoc->SessionBegin();
		//----- _xZkqqHx_jBhNjDpMiDeBiDeDiDgFiDiAiDiKiDfIiDgHiCpAiOoGiCoIiPgPiClFiBeBiDeBiDeDiDgFiDiAiCpAjBhNjDpMiClHiCoJ_xHqqkZx_ -----
		DWORDSet::const_iterator iSt;
		for	(iSt = m_layerList.GetInsertedIdSet().begin();
			 iSt != m_layerList.GetInsertedIdSet().end(); iSt++)
		{
			//----- _xZkqqHx_iDiMiDeDiDiEiBfLiCpAjCmHiJmB_xHqqkZx_ -----
			DWORD dwLayerIdx = m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->GetLayerSize();
			g_pDoc->CmdInsert1Layer(m_pSheetMgr->GetCurrentSheetId(),
									dwLayerIdx, m_layerList.GetRec(*iSt)->strName,
									m_layerList.GetRec(*iSt)->GetFlag());
			bModified = TRUE;
		}
		//----- _xZkqqHx_iDiMiDeDiDiEiBfLiDhNiBfLiDfHiPiIjHjN_xHqqkZx_ -----
		IdToIdvMap::const_iterator iMg;
		for (iMg = m_layerList.GetMergedIdSet().begin();
			 iMg != m_layerList.GetMergedIdSet().end(); iMg++)
		{
			DWORDVector::const_iterator iId = (*iMg).second.begin();
			for (iId++; iId != (*iMg).second.end(); iId++)
			{
				// _xZkqqHx_iDhNiBfLiDfHjBmOiPnLiCmMiDiMiDeDiDiEiBfLiCmMjBfDjFjEjFgJiCpAiOoGjDlOiBeC_xHqqkZx_
				ObjDynabaseVector vObj;
				m_pSheetMgr->GetSheet(m_pSheetMgr->GetCurrentSheetId())->
									GetZOrder(vObj, FDOZ_ON_ANY, *iId, *iId);

//----- 06.02.15 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//				// _xZkqqHx_jBfDjFjEjFgJiCpAiDhNiBfLiDfHjAoGiDiMiDeDiDiEiBfLiCmJiInKjDkOiBeC_xHqqkZx_
//				if (g_pDoc->CmdMoveSheetLayerObjs(vObj,
//									m_pSheetMgr->GetCurrentSheetId(), (*iMg).first))
//					bModified = TRUE;
//----- 06.02.15 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
				// _xZkqqHx_jBfDjFjEjFgJiCpAiDhNiBfLiDfHjAoGiDiMiDeDiDiEiBfLiCmJiInKjDkOiBeC_xHqqkZx_
				mdef_const_iterator(ObjDynabaseVector, iObj);
				m1_for (iObj, vObj)
				{
					if (g_pDoc->CmdCross1ObjSheetLayer(*iObj, m_pSheetMgr->GetCurrentSheetId(), (*iMg).first))
						bModified = TRUE;
				}
//----- 06.02.15 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----

			}
		}
		//-----	_xZkqqHx_iNoNiPjMiDeBiDeDiDgFiDiAiDiKiDfIiDgHiCpAiOoGiCoIiPgPiClFiBeBiDeBiDeDiDgFiDiAiCpAiNoNiPjMiClHiCoJ_xHqqkZx_ -----
		DWORDSet::const_reverse_iterator rSt;
		for	(rSt = m_layerList.GetRemovedIdSet().rbegin();
			 rSt != m_layerList.GetRemovedIdSet().rend(); rSt++)
		{
			ObjDynabaseVector vObj;
			g_pDoc->GetZOrder(vObj, FDOZ_ON_ANY, *rSt, *rSt);
			g_pView->RemoveSelectObj(vObj);
			ObjDynabaseVector::const_iterator iObj;
			// _xZkqqHx_iKnGiMfHiClHiCoJiDiKiDjDiDeOiCpAiNoNiPjMiBeCjDoAjFjEiCmFiDiKiDjDiDeOiNoNiPjMiDfCiDhNiDjDiDgIiCmMiLeMjIfOiKnGjAjEiCpAiOmAiNhDiBeC_xHqqkZx_
			for (iObj = vObj.begin(); iObj != vObj.end(); iObj++)
				g_pDoc->LinkManager()->DeleteSoonNotify((*iObj)->GetObjID());
			// _xZkqqHx_jFjEjFgJiCmMiNoNiPjMiDfCiDhNiDjDiDgIiPiIjHjNiBeC_xHqqkZx_
			for (iObj = vObj.begin(); iObj != vObj.end(); iObj++)
				g_pDoc->MulticmdDelete1Obj(*iObj, m_pSheetMgr->GetCurrentSheetId());
//----- 06.12.05 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
			// _xZkqqHx_jFjEjFgJiCkKiNoNiPjMiClDiCoKiClNiCkJiBeI_xHqqkZx_
			if (!vObj.empty()) bIsDeleted = TRUE;
//----- 06.12.05 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----

			g_pDoc->CmdDelete1Layer(m_pSheetMgr->GetCurrentSheetId(), *rSt);
			bModified = TRUE;
		}
		//----- _xZkqqHx_jFmPiNfIiDeBiDeDiDgFiDiAiDiKiDfIiDgHiCpAiOoGiCoIiPgPiClFiBeBiDeBiDeDiDgFiDiAiCpAjFmPiNfIiClHiCoJ_xHqqkZx_ -----
		for	(iSt = m_layerList.GetChangedIdSet().begin();
			 iSt != m_layerList.GetChangedIdSet().end(); iSt++)
		{
			// _xZkqqHx_iDiMiDeDiDiEiBfLiPoOjFpBiCmMjFmPiNfIiCpAiLeMjIfOiBeC_xHqqkZx_
			if (g_pDoc->CmdModify1Layer(m_pSheetMgr->GetCurrentSheetId(),
										id2idxMap[*iSt], m_layerList.GetRec(*iSt)->strName,
										m_layerList.GetRec(*iSt)->GetFlag()))
				bModified = TRUE;
		}
		//----- _xZkqqHx_iDeBiDeDiDgFiDiAjFfMiOkGiPiHiPjIiCpAjFmPiNfIiClHiCoJ_xHqqkZx_ -----
		vdwId.clear();
		m_layerList.GetIdOrder(vdwId);
		reverse(vdwId.begin(), vdwId.end());
		for (dwIdx = 0; dwIdx < vdwId.size(); dwIdx++)
			vdwId[dwIdx] = id2idxMap[vdwId[dwIdx]];
		// _xZkqqHx_iDiMiDeDiDiEiBfLiPiHiPjIiCmMjFmPiNfIiDfCiDhNiDjDiDgIiBeC_xHqqkZx_
		if (g_pDoc->CmdReOrderLayer(m_pSheetMgr->GetCurrentSheetId(), vdwId.begin(), vdwId.size()))
			bModified = TRUE;
		// _xZkqqHx_iDeKiDiMiDjDiDgHiDiMiDeDiDiEiBfLiCmMjFmPiNfIiDfCiDhNiDjDiDgIiBeC_xHqqkZx_
		if (g_pDoc->CmdSetCurrentLayer(m_pSheetMgr->GetCurrentSheetId(), m_layerList.GetCurrentLayerIdx()))
			bModified = TRUE;

//----- 06.12.05 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
		// _xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDhEiDeIiDjDiDgHiCpAjAkOjHjNiBeC_xHqqkZx_
		if (bIsDeleted)
			g_pDoc->MulticmdDeleteUnusedFonts();
//----- 06.12.05 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----
		// _xZkqqHx_iDfKiDgCiDfGiDiHiDjDiPeJjHlJiPiIjHjNiBeC_xHqqkZx_
		g_pDoc->SessionEnd();
	}

	// _xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLiCpAiPiJiKpKiJlLiClHiCoJiBeC_xHqqkZx_
	InitControl();

	if (bModified)
	//----- _xZkqqHx_iDiMiDeDiDiEiBfLiCmJjFmPiNfIiCkKiCkAiCoJiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iDiMiDeDiDiEiBfLjFmPiNfIiCpAiDhCiDiFiBfLiCmJjCmKjCgNiBeCjBeJjBpAjFjEjFgJiCmMjFmPiNfIjDjJiCpAiNhDiCkEiBeC_xHqqkZx_
		g_pView->PostMessage(WM_USER_LAYER_UPDATED);
		// _xZkqqHx_iDhEiDiMiBfLiDiAiCmJiDiMiDeDiDiEiBfLjFmPiNfIiCpAjCmKjCgNiBeC_xHqqkZx_
		FFGetMainWnd()->PostMessage(WM_USER_LAYER_UPDATED);
		// _xZkqqHx_iDhCiDiFiBfLiCpAiNmEjFgAiJoGiBeC_xHqqkZx_
		g_pView->PostRgnRedraw(TRUE);
	}
	// _xZkqqHx_iDiMiDeDiDiEiBfLiCmMjFmPiNfIiCpAjCmKjCgNiBeC_xHqqkZx_
	PostMessage(WM_USER_MULTICTRL_CHANGED, 0, 0);
} // CFCDlgLayerOrder::OnApplyNow.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnUserMultictrlChanged
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDeDiDiEiBfLiDfCiDjDiDgHiDiNiBfLiDiLiCmJjFmPiNfIiCkKiCkAiCmBiClNiCmGiCkLjCmKjCgNiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	wParam	:_xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiL_xHqqkZx_ID_xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *			lParam	:_xZkqqHx_jGkCiOgHjHhAiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iPoNiCmJ_xHqqkZx_1.
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.12.24 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
LRESULT CFCDlgLayerOrder::OnUserMultictrlChanged (WPARAM wParam, LPARAM lParam)
{
//----- 05.10.22 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//// 05.08.16 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
////	GetDlgItem(ID_APPLY_NOW)->EnableWindow(IsLayerChanged() && FFCanEditDocumentEnv());
//	GetDlgItem(ID_APPLY_NOW)->EnableWindow(IsLayerChanged());
//----- 05.10.22 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
	GetDlgItem(ID_APPLY_NOW)->EnableWindow(IsLayerChanged() && FFCanEditReadOnlyDocumentEnv());
//----- 05.10.22 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	GetDlgItem(IDC_LYO_BTN_LAYER_MERGE)->EnableWindow(m_layerList.CanMergeItem());
	GetDlgItem(IDC_LYO_BTN_LAYER_MODIFY)->EnableWindow(m_layerList.CanChangeItem());
	GetDlgItem(IDC_LYO_BTN_LAYER_ADD)->EnableWindow(m_layerList.CanInsertItemNext());
	GetDlgItem(IDC_LYO_BTN_LAYER_DELETE)->EnableWindow(m_layerList.CanDeleteItem());
	return 1;
} // CFCDlgLayerOrder::OnUserMultictrlChanged.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnUserListctrlSelchanged
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDeDiDiEiBfLiDfCiDjDiDgHiDiNiBfLiDiLiCmMjBeJjBpAiCkKjFmPiNfIiClDiCoKiClNiOjOiCmJiOmAiNhDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	wParam	:_xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiL_xHqqkZx_ID_xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *			lParam	:_xZkqqHx_jBeJjBpAiClDiCoKiClNiDeBiDeDiDgFiDiAiDeDiDjDiDgGiDgCiDeOiDfIiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
LRESULT CFCDlgLayerOrder::OnUserListctrlSelchanged (WPARAM wParam, LPARAM lParam)
{
	return OnUserMultictrlChanged(0,0);
} // CFCDlgLayerOrder::OnUserListctrlSelchanged.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnLyoBtnLayerMerge
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhNiBfLiDfHiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::OnLyoBtnLayerMerge ()
{
	m_layerList.PostMessage(WM_COMMAND, ID_RBTN_ITEM_MERGE);
} // CFCDlgLayerOrder::OnLyoBtnLayerMerge.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnLyoBtnLayerModify
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jFmPiNfIiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::OnLyoBtnLayerModify ()
{
	m_layerList.PostMessage(WM_COMMAND, ID_RBTN_ITEM_CHANGE);
} // CFCDlgLayerOrder::OnLyoBtnLayerModify.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnLyoBtnLayerAdd
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jCmHiJmBiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::OnLyoBtnLayerAdd ()
{
	m_layerList.PostMessage(WM_COMMAND, ID_RBTN_ITEM_INSERT_NEXT);
} // CFCDlgLayerOrder::OnLyoBtnLayerAdd.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgLayerOrder::OnLyoBtnLayerDelete
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iNoNiPjMiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.03.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgLayerOrder::OnLyoBtnLayerDelete ()
{
	m_layerList.PostMessage(WM_COMMAND, ID_RBTN_ITEM_DELETE);
} // CFCDlgLayerOrder::OnLyoBtnLayerDelete.
