// DlgSelectUser.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "DynamicDraw.h"
#include "UtilStr.h"			// For FFLoadWString.
#include "UtilMisc.h"			// For operator < (GUID, GUID)
// 06.11.16 Fukushiro M. 1_xZkqqHx_iNhDjCmHiJmB_xHqqkZx_ ()
#include "UtilDlg.h"			// For SetUnitString.etc.
#include "ProjectCopy.h"		// For FCProjectCopy.
#include "DlgSelectUser.h"		// This header.

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

/////////////////////////////////////////////////////////////////////////////
// CFCDlgSelectUser _xZkqqHx_iDfPiDeDiDeBiDiNiDeP_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::CFCDlgSelectUser
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.23 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
CFCDlgSelectUser::CFCDlgSelectUser (CWnd* pParent /*=NULL*/)
	: BASE_CLASS(CFCDlgSelectUser::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFCDlgSelectUser)
	//}}AFX_DATA_INIT
	// _xZkqqHx_jGkCjAnNjCoIiDiGiBfLiDfFiCkKjBeJjBpAiJmCjEfMiCkJiBeI_xHqqkZx_
	m_bCanSelectUnsetUser = TRUE;
} // CFCDlgSelectUser::CFCDlgSelectUser.

void CFCDlgSelectUser::DoDataExchange(CDataExchange* pDX)
{
	BASE_CLASS::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFCDlgSelectUser)
	DDX_Control(pDX, IDC_SUR_BTN_UNSELECT, m_btnUnselect);
	DDX_Control(pDX, IDC_SUR_BTN_SELECT, m_btnSelect);
	DDX_Control(pDX, IDC_SUR_LSV_UNSELECT_USER, m_lsvUnselectUser);
	DDX_Control(pDX, IDC_SUR_LSV_SELECT_USER, m_lsvSelectUser);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFCDlgSelectUser, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCDlgSelectUser)
	ON_BN_CLICKED(IDC_SUR_BTN_SELECT, OnSurBtnSelect)
	ON_BN_CLICKED(IDC_SUR_BTN_UNSELECT, OnSurBtnUnselect)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCDlgSelectUser _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::Initialize
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfPiDeDiDeBiDiNiDePiCpAiPiJiKpKiJlLiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pProjectCopy	:_xZkqqHx_iDiGiBfLiDfFiPoOjFpBiCkKiLeMjIfOiClDiCoKiClNiDhGiDiNiDfHiDeGiDeOiDgHiCpAiOhHjCoIiBeC_xHqqkZx_
 *			bCanSelectUnsetUser
 *						:_xZkqqHx_jGkCjAnNjCoIiDiGiBfLiDfFiCkKjBeJjBpAiJmCjEfMiCkJiBeI_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.20 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgSelectUser::Initialize (const FCProjectCopy* pProjectCopy, BOOL bCanSelectUnsetUser)
{
	m_pProjectCopy = pProjectCopy;
	// _xZkqqHx_jGkCjAnNjCoIiDiGiBfLiDfFiCkKjBeJjBpAiJmCjEfMiCkJiBeI_xHqqkZx_
	m_bCanSelectUnsetUser = bCanSelectUnsetUser;
} // CFCDlgSelectUser::Initialize.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::GetSelectedUserId
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jBeJjBpAiClDiCoKiClNiDiGiBfLiDfFiCpAiOoGjDlOiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	stGuidUserId	:_xZkqqHx_iDiGiBfLiDfFiDiKiDfIiDgHiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.20 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgSelectUser::GetSelectedUserId (set<GUID>& stGuidUserId) const
{
	stGuidUserId = m_stSelectedUserId;
} // CFCDlgSelectUser::GetSelectedUserId.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::SetSelectedUserId
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jBeJjBpAiClDiCoKiClNiDiGiBfLiDfFiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	stGuidUserId	:_xZkqqHx_iDiGiBfLiDfFiDiKiDfIiDgHiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.20 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgSelectUser::SetSelectedUserId (const set<GUID>& stGuidUserId)
{
	m_stSelectedUserId = stGuidUserId;
} // CFCDlgSelectUser::SetSelectedUserId.

/////////////////////////////////////////////////////////////////////////////
// CFCDlgSelectUser _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::OnInitDialog
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfPiDeDiDeBiDiNiDePiPiJiKpKiJlLiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.20 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL CFCDlgSelectUser::OnInitDialog ()
{
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnInitDialog();
	// _xZkqqHx_jGkCjBeJjBpAiDiGiBfLiDfFiCmMiDiKiDfIiDgHiCpAiPiJiKpKiJlLiBeC_xHqqkZx_
	m_lsvUnselectUser.Initialize();
	// _xZkqqHx_jBeJjBpAiDiGiBfLiDfFiCmMiDiKiDfIiDgHiCpAiPiJiKpKiJlLiBeC_xHqqkZx_
	m_lsvSelectUser.Initialize();

	// _xZkqqHx_jBeJjBpAiDhLiDfOiDjDiCmJiDeBiDeDiDfCiDjDiCpAjAnNjCoIiBeCiDeBiDeDiDfCiDjDiCmNiNlGjBkEiBeCiDgFiDeMiDfIiDgHiCmGiDeBiDeDiDfCiDjDiDeNiDiDiDgCiDhGiCmNiCfDiBeC_xHqqkZx_
//----- 06.03.19 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//	m_btnSelect.SetIcon(FFGetApp()->LoadIcon(IDI_ARROW_UP), 32, 32);
//	m_btnSelect.SetIconTextGap(4);
//----- 06.03.19 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
	m_btnSelect.SetIcon(FFGetApp()->LoadIcon(IDI_ARROW_UP), 32, 32, TRUE, 4);
//----- 06.03.19 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	// _xZkqqHx_jBeJjBpAiJpAiPjMiDhLiDfOiDjDiCmJiDeBiDeDiDfCiDjDiCpAjAnNjCoIiBeCiDeBiDeDiDfCiDjDiCmNiNlGjBkEiBeCiDgFiDeMiDfIiDgHiCmGiDeBiDeDiDfCiDjDiDeNiDiDiDgCiDhGiCmNiCfDiBeC_xHqqkZx_
//----- 06.03.19 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//	m_btnUnselect.SetIcon(FFGetApp()->LoadIcon(IDI_ARROW_DOWN), 32, 32);
//	m_btnUnselect.SetIconTextGap(4);
//----- 06.03.19 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
	m_btnUnselect.SetIcon(FFGetApp()->LoadIcon(IDI_ARROW_DOWN), 32, 32, TRUE, 4);
//----- 06.03.19 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----

	GuidToUserNameMap mpGuidToUserName;
	m_pProjectCopy->GetMemberUserList(mpGuidToUserName);
	GuidToUserNameMap::const_iterator iIn;
	for (iIn = mpGuidToUserName.begin();
		 iIn != mpGuidToUserName.end(); iIn++)
	{
		// _xZkqqHx_iDhGiDiNiDfHiDeGiDeOiDgHiCmJjDgPjIfOiClDiCoKiCmEiCkCiCoJiDiBiDjDiDgPiBfLiCmMiCkEiClPiBeB_xHqqkZx_
		// m_stSelectedUserId _xZkqqHx_iCmJiCkAiCoJiCoAiCmMiCpAjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCmJiBeB_xHqqkZx_
		// _xZkqqHx_jGlDiCkCiCoAiCmMiCpA_xHqqkZx_ _xZkqqHx_jGkCjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCmJjCmHiJmBiClHiCoJiBeC_xHqqkZx_
		// _xZkqqHx_iClBiCoKiCmJiCoGiCmBiCmEiBeB_xHqqkZx_m_stSelectedUserId _xZkqqHx_jCiGiCmJiBeBiDhGiDiNiDfHiDeGiDeOiDgHiCmJ_xHqqkZx_
		// _xZkqqHx_jDgPjIfOiClDiCoKiCmEiCkCiCmIiCkCiDiGiBfLiDfFiCkKiCkAiCmBiCmEiCoAiBeBiDiKiDfIiDgHiDhCiDiFiBfLiCmJ_xHqqkZx_
		// _xZkqqHx_jDgPjIfOiClDiCoKiCoJiClBiCmGiCmNiCmIiCkCiBeC_xHqqkZx_
		if (m_stSelectedUserId.find((*iIn).first) == m_stSelectedUserId.end())
			m_lsvUnselectUser.AddUser((*iIn).first, (*iIn).second.c_str());		// _xZkqqHx_jGkCjBeJjBpAiDiGiBfLiDfFiCpAjCmHiJmBiBeC_xHqqkZx_
		else
			m_lsvSelectUser.AddUser((*iIn).first, (*iIn).second.c_str());		// _xZkqqHx_jBeJjBpAiDiGiBfLiDfFiCpAjCmHiJmBiBeC_xHqqkZx_
	}

	if (m_bCanSelectUnsetUser)
	//----- _xZkqqHx_jGkCjAnNjCoIiDiGiBfLiDfFiCkKjBeJjBpAiJmCjEfMiCmIiPoKiNiH_xHqqkZx_ -----
	{
//----- 06.04.29 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//		if (m_stSelectedUserId.find(GUID_NULL) == m_stSelectedUserId.end())
//			m_lsvUnselectUser.AddUser(GUID_NULL, FFLoadWString(IDS_UNSET));		// _xZkqqHx_jGkCjBeJjBpAiDiGiBfLiDfFiCpAjCmHiJmBiBeC_xHqqkZx_
//		else
//			m_lsvSelectUser.AddUser(GUID_NULL, FFLoadWString(IDS_UNSET));		// _xZkqqHx_jBeJjBpAiDiGiBfLiDfFiCpAjCmHiJmBiBeC_xHqqkZx_
//----- 06.04.29 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
		if (m_stSelectedUserId.find(GUID_NULL) == m_stSelectedUserId.end())
			m_lsvUnselectUser.AddUser(GUID_NULL, FFLoadWString(IDS_GUEST));		// _xZkqqHx_jGkCjBeJjBpAiDiGiBfLiDfFiCpAjCmHiJmBiBeC_xHqqkZx_
		else
			m_lsvSelectUser.AddUser(GUID_NULL, FFLoadWString(IDS_GUEST));		// _xZkqqHx_jBeJjBpAiDiGiBfLiDfFiCpAjCmHiJmBiBeC_xHqqkZx_
//----- 06.04.29 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	}

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

	return TRUE;
} // CFCDlgSelectUser::OnInitDialog.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::OnSurBtnSelect
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jBeJjBpAiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgSelectUser::OnSurBtnSelect ()
{
	// _xZkqqHx_jGkCjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCkJiCoHiBeBjBeJjBpAiClDiCoKiCmEiCkCiCoJiDeBiDeDiDgFiDiAiCmMiDiGiBfLiDfF_xHqqkZx_ID_xZkqqHx_iCpAiOoGjDlOiBeC_xHqqkZx_
	set<GUID> stGuidUserId;
	m_lsvUnselectUser.GetSelectedUserId(stGuidUserId);
	set<GUID>::const_iterator iId;
	for (iId = stGuidUserId.begin(); iId != stGuidUserId.end(); iId++)
	{
		// _xZkqqHx_jGkCjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCkJiCoHiDiGiBfLiDfFiCpAiNoNiPjMiClFiBeBjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCmJjCmHiJmBiClHiCoJiBeC_xHqqkZx_
		m_lsvUnselectUser.DelUser(*iId);
		if (*iId == GUID_NULL)
// 06.04.29 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//			m_lsvSelectUser.AddUser(*iId, FFLoadWString(IDS_UNSET));
			m_lsvSelectUser.AddUser(*iId, FFLoadWString(IDS_GUEST));
		else
			m_lsvSelectUser.AddUser(*iId, m_pProjectCopy->UserIdToUserName(*iId));
	}
} // CFCDlgSelectUser::OnSurBtnSelect.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::OnSurBtnUnselect
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jBeJjBpAiJpAiPjMiDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgSelectUser::OnSurBtnUnselect ()
{
	// _xZkqqHx_jBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCkJiCoHiBeBjBeJjBpAiClDiCoKiCmEiCkCiCoJiDeBiDeDiDgFiDiAiCmMiDiGiBfLiDfF_xHqqkZx_ID_xZkqqHx_iCpAiOoGjDlOiBeC_xHqqkZx_
	set<GUID> stGuidUserId;
	m_lsvSelectUser.GetSelectedUserId(stGuidUserId);
	set<GUID>::const_iterator iId;
	for (iId = stGuidUserId.begin(); iId != stGuidUserId.end(); iId++)
	{
		// _xZkqqHx_jBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCkJiCoHiDiGiBfLiDfFiCpAiNoNiPjMiClFiBeBjGkCjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCmJjCmHiJmBiClHiCoJiBeC_xHqqkZx_
		m_lsvSelectUser.DelUser(*iId);
		if (*iId == GUID_NULL)
// 06.04.29 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//			m_lsvUnselectUser.AddUser(*iId, FFLoadWString(IDS_UNSET));
			m_lsvUnselectUser.AddUser(*iId, FFLoadWString(IDS_GUEST));
		else
			m_lsvUnselectUser.AddUser(*iId, m_pProjectCopy->UserIdToUserName(*iId));
	}
} // CFCDlgSelectUser::OnSurBtnUnselect.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCDlgSelectUser::OnOK
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	OK_xZkqqHx_iDhLiDfOiDjDiCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCDlgSelectUser::OnOK ()
{
	// m_stSelectedUserId _xZkqqHx_iCmJjBeJjBpAiDiKiDfIiDgHiDhCiDiFiBfLiCmMiDiGiBfLiDfFiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
	m_stSelectedUserId.clear();
	for (long lItem = 0; lItem < m_lsvSelectUser.GetItemCount(); lItem++)
		m_stSelectedUserId.insert(m_lsvSelectUser.GetUserId(lItem));
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnOK();
} // CFCDlgSelectUser::OnOK.
