/*=========================================================================
*
* CPAdPref.cpp :  Selection - Implementation file
*
*
* Version			1.0
* Creation date
* Revision date
*
* Shaitan
*=======================================================================*/

#include "stdafx.h"
#ifdef ACTIVE_EDITOR
#include "acp_base.h"

#include "itf/CPAdPref.hpp"
#include "itf/CPAInter.hpp"

//#################################################################################
// CPA_DialogPrefix dialog
//#################################################################################

/*----------------------------------------
----------------------------------------*/
CPA_DialogPrefix::CPA_DialogPrefix(CWnd* pParent /*=NULL*/)
	: CDialog(CPA_DialogPrefix::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPA_DialogPrefix)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


/*----------------------------------------
----------------------------------------*/
void CPA_DialogPrefix::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPA_DialogPrefix)
	DDX_Control(pDX, CPA_IDC_COMBOUSERS, m_cComboUsers);
	DDX_Control(pDX, CPA_IDC_SAVEPREFIX, m_cSave);
	//}}AFX_DATA_MAP
}


/*----------------------------------------
----------------------------------------*/
BEGIN_MESSAGE_MAP(CPA_DialogPrefix, CDialog)
	//{{AFX_MSG_MAP(CPA_DialogPrefix)
	ON_LBN_SELCHANGE(CPA_IDC_COMBOUSERS, OnSelChangeComboUsers)
	ON_LBN_DBLCLK(CPA_IDC_COMBOUSERS, OnDblClkComboUsers)
	ON_BN_CLICKED(CPA_IDC_SAVEPREFIX, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//#################################################################################
// CPA_DialogPrefix message handlers
//#################################################################################

/*----------------------------------------
----------------------------------------*/
long CPA_DialogPrefix::fn_lDoDialog (CPA_Interface *pEditor, CString a_csUserNames[], long lNbUsers)
{
	long lIndex;

	// init parameters
	m_pEditor = pEditor;
	m_lNbUsers = lNbUsers;
	for (lIndex = 0; lIndex <lNbUsers; lIndex++)
		m_a_csUserNames[lIndex] = a_csUserNames[lIndex];
	// this dialog is modal
	DoModal();

	return m_lUserSelected;
}



/*----------------------------------------
----------------------------------------*/
BOOL CPA_DialogPrefix::OnInitDialog ()
{
	long lIndex;

	// Create the dialog
	CDialog::OnInitDialog();
	// init combo
	m_cComboUsers.ResetContent();
	for (lIndex = 0; lIndex <m_lNbUsers; lIndex++)
		m_cComboUsers.AddString(m_a_csUserNames[lIndex]);
	// set current selection
	m_lUserSelected = -1;

	return TRUE;
}


/*----------------------------------------
----------------------------------------*/
void CPA_DialogPrefix::OnSelChangeComboUsers()
{
	// set the current selection
	m_lUserSelected = m_cComboUsers.GetCurSel();
}


/*----------------------------------------
----------------------------------------*/
void CPA_DialogPrefix::OnDblClkComboUsers()
{
	// set the current selection
	m_lUserSelected = m_cComboUsers.GetCurSel();
	// if selection, close dialog
	if (m_lUserSelected != -1)
		CDialog::OnOK();
}


/*----------------------------------------
----------------------------------------*/
void CPA_DialogPrefix::OnOK()
{
	// set the current selection
	if (m_lUserSelected != -1)
		CDialog::OnOK();
}

/*----------------------------------------
----------------------------------------*/
void CPA_DialogPrefix::OnCancel()
{
	// set the current selection
	if (m_lUserSelected != -1)
		CDialog::OnCancel();
}


/*----------------------------------------
----------------------------------------*/
void CPA_DialogPrefix::OnSave ()
{
	if (m_lUserSelected != -1)
		m_pEditor->fn_vSaveUserPrefix( m_pEditor->GetUserPrefix(m_lUserSelected) );
}

#endif // ACTIVE_EDITOR
