// EdIRBNam.cpp : implementation file
//

#include "stdafx.h"

#include "Defines.hpp"

#ifdef D_ED_IR_ACTIVE

#include "EdIRRes.h"

#include "EdIRBNam.hpp"

#include "ai_intf.hpp"

#include "incTUT.h"

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

/////////////////////////////////////////////////////////////////////////////
// class CDlgNewBehaviourName
/////////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(CPA_EdIR_DlgNewBehaviourName, CDialog)
	//{{AFX_MSG_MAP(CPA_EdIR_DlgNewBehaviourName)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/**********************************************************************************/
CPA_EdIR_DlgNewBehaviourName::CPA_EdIR_DlgNewBehaviourName(CString csNewName,CWnd* pParent)
	: CDialog(CPA_EdIR_DlgNewBehaviourName::IDD, &g_oBaseFrame)
{
	//{{AFX_DATA_INIT(CPA_EdIR_DlgNewBehaviourName)
	m_csNewName = csNewName;
	//}}AFX_DATA_INIT

	m_hOldInstance=AfxGetResourceHandle();
	AfxSetResourceHandle(g_stAIIdentity.hModule);
}

/**********************************************************************************/
CPA_EdIR_DlgNewBehaviourName::~CPA_EdIR_DlgNewBehaviourName()
{
	AfxSetResourceHandle(m_hOldInstance);
}

/**********************************************************************************/
void CPA_EdIR_DlgNewBehaviourName::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPA_EdIR_DlgNewBehaviourName)
	DDX_Text(pDX, IDC_EDIT_BEHAVIOUR_NAME, m_csNewName);
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_DlgNewBehaviourName message handlers
/////////////////////////////////////////////////////////////////////////////

/**********************************************************************************/
BOOL CPA_EdIR_DlgNewBehaviourName::OnInitDialog() 
{
	CDialog::OnInitDialog();

	//////////////
	//////////////
	//Registers for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vRegisterControl(m_hWnd,"EdIR_GetBehaviourName_Window",TUT_e_Window);

	TUT_M_vRegisterControlID(IDC_EDIT_BEHAVIOUR_NAME,"EdIR_GetBehaviourName_Name",TUT_e_TextEdit);
	TUT_M_vRegisterControlID(IDOK,"EdIR_GetBehaviourName_IDOK",TUT_e_Button);
	//End of Register for TUT Module
	//////////////
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/**********************************************************************************/
void CPA_EdIR_DlgNewBehaviourName::OnDestroy() 
{
	//////////////
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControl(m_hWnd);
	TUT_M_vUnregisterControlID(IDC_EDIT_BEHAVIOUR_NAME);
	TUT_M_vUnregisterControlID(IDOK);
	//End of UnRegister for TUT Module
	//////////////

	CDialog::OnDestroy();
}

/**********************************************************************************/
BOOL CPA_EdIR_DlgNewBehaviourName::m_fn_bCheckName(CString csName) 
{
	BOOL	bNameIsGood=!(m_csNewName.IsEmpty());

	for(int i=0;i<csName.GetLength() && bNameIsGood;i++)
		bNameIsGood=(
									(csName[i]>='0' && csName[i]<='9')
									||
									(csName[i]>='A' && csName[i]<='Z')
									||
									(csName[i]>='a' && csName[i]<='z')
									||
									(csName[i]=='_')
								);

	return bNameIsGood;
}

/**********************************************************************************/
void CPA_EdIR_DlgNewBehaviourName::OnOK() 
{
	GetDlgItem(IDC_EDIT_BEHAVIOUR_NAME)->GetWindowText(m_csNewName);

	if(m_fn_bCheckName(m_csNewName))
		CDialog::OnOK();
	else
		CDialog::OnCancel();
}

#endif //D_ED_IR_ACTIVE
