// CPA_Box.cpp : implementation file
//

#include "stdafx.h"

#include "Defines.hpp"

#ifdef D_ED_IR_ACTIVE

#include "EdIRRBox.hpp"

#include "ai_intf.hpp"

#include "IncTUT.h"

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

/////////////////////////////////////////////////////////////////////////////
// class CPA_EdIR_ActCondBoxDlg
/////////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(CPA_EdIR_ActCondBoxDlg, CDialog)
	//{{AFX_MSG_MAP(CPA_EdIR_ActCondBoxDlg)
	ON_WM_DESTROY()
	ON_LBN_DBLCLK(IDC_IR_LISTBOX, OnDblclk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
					 
/**********************************************************************************/
CPA_EdIR_ActCondBoxDlg::CPA_EdIR_ActCondBoxDlg(CStringList *p_clListString,CWnd* pParent)
	: CDialog(CPA_EdIR_ActCondBoxDlg::IDD, &g_oBaseFrame)
{
	mp_clListString=p_clListString;
	m_csSelectedString="";

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

	//{{AFX_DATA_INIT(CPA_EdIR_ActCondBoxDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

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

/**********************************************************************************/
void CPA_EdIR_ActCondBoxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPA_EdIR_ActCondBoxDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_ActCondBoxDlg message handlers

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

	CListBox	*p_clListBox=(CListBox *)GetDlgItem(IDC_IR_LISTBOX);

	POSITION	pos=mp_clListString->GetHeadPosition();
	while(pos)
		p_clListBox->AddString(mp_clListString->GetNext(pos));

	p_clListBox->SetCurSel(0);

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

	TUT_M_vRegisterControlID(IDC_IR_LISTBOX,"EdIR_ChooseBox_ListBox",TUT_e_ListBox);
	//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_ActCondBoxDlg::OnDestroy() 
{
	//////////////
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControl(m_hWnd);
	TUT_M_vUnregisterControlID(IDC_IR_LISTBOX);
	//End of UnRegister for TUT Module
	//////////////

	CDialog::OnDestroy();
}

/**********************************************************************************/
void CPA_EdIR_ActCondBoxDlg::OnOK()
{
	CListBox	*p_clListBox=(CListBox *)GetDlgItem(IDC_IR_LISTBOX);

	p_clListBox->GetText(p_clListBox->GetCurSel(),m_csSelectedString);
//ROMTEAM Display Parameter (Ionut Grozea 14/04/98)
	SHORT mShort = GetKeyState(VK_CONTROL);

	if (!(mShort & (1<<15)))
		m_csSelectedString = m_fn_csGetNameOfProcedureWithoutParams(m_csSelectedString);
//ENDROMTEAM Display Parameter (Ionut Grozea 14/04/98)

	CDialog::OnOK();
}

/**********************************************************************************/
void CPA_EdIR_ActCondBoxDlg::OnDblclk() 
{
	CListBox	*p_clListBox=(CListBox *)GetDlgItem(IDC_IR_LISTBOX);

	p_clListBox->GetText(p_clListBox->GetCurSel(),m_csSelectedString);
//ROMTEAM Display Parameter (Ionut Grozea 14/04/98)
	SHORT mShort = GetKeyState(VK_CONTROL);

	if (!(mShort & (1<<15)))
		m_csSelectedString = m_fn_csGetNameOfProcedureWithoutParams(m_csSelectedString);
//ENDROMTEAM Display Parameter (Ionut Grozea 14/04/98)

	CDialog::OnOK();
}
//ROMTEAM Display Parameter (Ionut Grozea 14/04/98)
CString CPA_EdIR_ActCondBoxDlg::m_fn_csGetNameOfProcedureWithoutParams(CString csString)
{
	CString csName;
	long lIndex = csString.Find('(');
	if (lIndex==-1) 
		return csString;
	else
		if (lIndex == 0)
			return "";
		else
			return csString.Left(lIndex);
}
//ENDROMTEAM Display Parameter (Ionut Grozea 14/04/98)
#endif //D_ED_IR_ACTIVE
