// IADDgFnd.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#define HieFriend

#include "IADDgFnd.hpp"

#include "IADLnkMt.hpp"
#include "_IADItrf.hpp"

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

/////////////////////////////////////////////////////////////////////////////
// IAD_Dialog_FindInTree dialog

BEGIN_MESSAGE_MAP(IAD_Dialog_FindInTree, CDialog)
	//{{AFX_MSG_MAP(IAD_Dialog_FindInTree)
	ON_CBN_SELCHANGE(IDC_COMBO_FIELD_TYPE, OnSelchangeComboFieldType)
	ON_BN_CLICKED(IDC_RADIO_DEEP_SEARCH, OnRadioDeepSearch)
	ON_BN_CLICKED(IDC_RADIO_SIMPLE_SEARCH, OnRadioSimpleSearch)
	ON_BN_CLICKED(IDC_CHECK_SEARCH_IN_LEVELS, OnCheckSearchInLevels)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//***************************************************************************
IAD_Dialog_FindInTree::IAD_Dialog_FindInTree(CWnd* pParent /*=NULL*/)
											: CDialog(IAD_Dialog_FindInTree::IDD, pParent)
{
	//{{AFX_DATA_INIT(IAD_Dialog_FindInTree)
	m_bOnlyLevels = FALSE;
	//}}AFX_DATA_INIT

	if ( g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch )
	{
		m_iSearchType = 0;

		m_bSimpleSearchCaseSensitive = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch_CaseSensitive;
		m_bSimpleSearchExact = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch_Exact;
		m_csSimpleSearchString = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csSimpleSearchString;
	}
	else
	{
		m_iSearchType = 1;

		m_bName_CaseSensitive = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bName_CaseSensitive;
		m_bName_Exact = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bName_Exact;
		m_bValue_CaseSensitive = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bValue_CaseSensitive;
		m_bValue_Exact = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bValue_Exact;
		m_bRetValue_CaseSensitive = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bRetValue_CaseSensitive;
		m_bRetValue_Exact = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bRetValue_Exact;

		m_csName = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csName;
		m_csValue = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csValue;
		m_csRetValue = g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csRetValue;
	}

	//Depths
	m_bOnlyLevels = !g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bAllLevels;
	if ( g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lBeginningLevel > (-1) )
		m_csBeginningLevel.Format("%ld", g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lBeginningLevel);
	if ( g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lEndLevel > (-1) )
		m_csEndLevel.Format("%ld", g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lEndLevel);
}

//***************************************************************************
void IAD_Dialog_FindInTree::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(IAD_Dialog_FindInTree)
	DDX_Check(pDX, IDC_CHECK_CASE_NAME, m_bName_CaseSensitive);
	DDX_Check(pDX, IDC_CHECK_EXACT_NAME, m_bName_Exact);
	DDX_Check(pDX, IDC_CHECK_CASE_VALUE, m_bValue_CaseSensitive);
	DDX_Check(pDX, IDC_CHECK_CASE_R_VALUE, m_bRetValue_CaseSensitive);
	DDX_Check(pDX, IDC_CHECK_EXACT_VALUE, m_bValue_Exact);
	DDX_Check(pDX, IDC_CHECK_EXACT_R_VALUE, m_bRetValue_Exact);
	DDX_Text(pDX, IDC_EDIT_NAME, m_csName);
	DDX_Text(pDX, IDC_EDIT_RETURNING_VALUE, m_csRetValue);
	DDX_Text(pDX, IDC_EDIT_VALUE, m_csValue);
	DDX_Radio(pDX, IDC_RADIO_SIMPLE_SEARCH, m_iSearchType);
	DDX_Check(pDX, IDC_CHECK_CASE_SIMPLE_SEARCH, m_bSimpleSearchCaseSensitive);
	DDX_Check(pDX, IDC_CHECK_EXACT_SIMPLE_SEARCH, m_bSimpleSearchExact);
	DDX_Text(pDX, IDC_EDIT_SIMPLE_SEARCH, m_csSimpleSearchString);
	DDX_Text(pDX, IDC_EDIT_BEGINNING_LEVEL, m_csBeginningLevel);
	DDX_Text(pDX, IDC_EDIT_END_LEVEL, m_csEndLevel);
	DDX_Check(pDX, IDC_CHECK_SEARCH_IN_LEVELS, m_bOnlyLevels);
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// IAD_Dialog_FindInTree message handlers

//***************************************************************************
BOOL IAD_Dialog_FindInTree::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//Fills Combo
	m_pri_fn_vFillCombo();

	//To initialize default state of controls
	if ( m_iSearchType == 0 )
		OnRadioSimpleSearch();
	else
		OnRadioDeepSearch();

	BOOL bMustCheck = (		(g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lBeginningLevel > (-1)) 
										&&	(g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lEndLevel > (-1))
										);
	((CButton *)GetDlgItem(IDC_CHECK_SEARCH_IN_LEVELS))->SetCheck(bMustCheck);
	OnCheckSearchInLevels();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//***************************************************************************
void IAD_Dialog_FindInTree::OnOK() 
{
	UpdateData(TRUE);
	
	g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch = ( m_iSearchType == 0 );

	if ( g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch )
	{
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csSimpleSearchString		= m_csSimpleSearchString;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch_CaseSensitive	= m_bSimpleSearchCaseSensitive;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bSimpleSearch_Exact					= m_bSimpleSearchExact;
	}
	else
	{

		// CG PB DEBUGGER 23/06/98 {
		#ifdef ACTIVE_AIDEBUG
			g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->eNodeType = AIDebug_E_SecTyp_NbOfSectionType;	//== Invalid value
		#endif // CG PB DEBUGGER }

		CComboBox *pclCombo = (CComboBox *)GetDlgItem(IDC_COMBO_FIELD_TYPE);
		if ( pclCombo != NULL )
		{
			short wIndex = pclCombo->GetCurSel();
			if ( wIndex != CB_ERR )
				g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->eNodeType = (enum AIDebug_tdeSectionType_)pclCombo->GetItemData(wIndex);
		}

		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bName_CaseSensitive		= m_bName_CaseSensitive;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bName_Exact						= m_bName_Exact;
		
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bValue_CaseSensitive	= m_bValue_CaseSensitive;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bValue_Exact					= m_bValue_Exact;
		
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bRetValue_CaseSensitive = m_bRetValue_CaseSensitive;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bRetValue_Exact				= m_bRetValue_Exact;
		
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csName								= m_csName;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csRetValue						= m_csRetValue;
		g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->csValue								= m_csValue;
	}

	g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->bAllLevels					= !m_bOnlyLevels;
	g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lBeginningLevel			= atol(m_csBeginningLevel);
	g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->lEndLevel						= atol(m_csEndLevel);

	CDialog::OnOK();
}

//***************************************************************************
void IAD_Dialog_FindInTree::OnSelchangeComboFieldType() 
{
	// CG PB DEBUGGER 23/06/98 {
	#ifdef ACTIVE_AIDEBUG

		CComboBox *pclCombo = (CComboBox *)GetDlgItem(IDC_COMBO_FIELD_TYPE);
		if ( pclCombo != NULL )
		{
			short wIndex = pclCombo->GetCurSel();

			if ( wIndex != CB_ERR )
			{
				//Gets enum values
				AIDebug_tdeSectionType tdeEnumValue = (AIDebug_tdeSectionType)pclCombo->GetItemData(wIndex);

			}
		}	
	#endif // CG PB DEBUGGER }
}


//***************************************************************************
//***************************************************************************
//***************************************************************************

///////////////////////
// Private Functions //
///////////////////////

//***************************************************************************
void IAD_Dialog_FindInTree::m_pri_fn_vFillCombo()
{
	// CG PB DEBUGGER 23/06/98 {
	#ifdef ACTIVE_AIDEBUG

		CComboBox *pclCombo = (CComboBox *)GetDlgItem(IDC_COMBO_FIELD_TYPE);
		if ( pclCombo != NULL )
		{
			short wIndexToSelect = 0;

			short wIndex = pclCombo->AddString("Engine Loop");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_EngineLoop);
			wIndex = pclCombo->AddString("Reflex Or AI");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_ReflexOrAI);
			wIndex = pclCombo->AddString("Current Comport");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_CurrentComport);
			wIndex = pclCombo->AddString("Field");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Field);
			wIndex = pclCombo->AddString("Constant");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Constant);
			wIndex = pclCombo->AddString("Designer Var Id");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_DsgVarId);
			wIndex = pclCombo->AddString("Designer Var");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_DsgVar);
			wIndex = pclCombo->AddString("Button");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Button);
			wIndex = pclCombo->AddString("Environment Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_EnvRef);
			wIndex = pclCombo->AddString("Sector Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_SectorRef);
			wIndex = pclCombo->AddString("Surface Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_SurfaceRef);
			wIndex = pclCombo->AddString("Perso Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_PersoRef);
			wIndex = pclCombo->AddString("Action Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_ActionRef);
			wIndex = pclCombo->AddString("Real Constant");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Real);
			wIndex = pclCombo->AddString("Vector");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Vector);
			wIndex = pclCombo->AddString("Constant Vector");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_ConstantVector);
			wIndex = pclCombo->AddString("Way");
	//		pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Way);
	//		wIndex = pclCombo->AddString("WayPoint");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_WayPoint);
			wIndex = pclCombo->AddString("Module");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Module);
	//		wIndex = pclCombo->AddString("Channel Number");
	//		pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_ChannelNumber);
			wIndex = pclCombo->AddString("Mask");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Mask);
			wIndex = pclCombo->AddString("String");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_String);
			wIndex = pclCombo->AddString("Lips Synchro");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_LipsSynchroRef);
			wIndex = pclCombo->AddString("Sound Event Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_SoundEventRef);
			wIndex = pclCombo->AddString("Family Ref");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_FamilyRef);
			wIndex = pclCombo->AddString("Begin of Macro");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_BeginMacro);
			wIndex = pclCombo->AddString("End of Macro");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_EndMacro);
			wIndex = pclCombo->AddString("Comport");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Comport);
			wIndex = pclCombo->AddString("KeyWord");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_KeyWord);
			wIndex = pclCombo->AddString("Condition");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Condition);
			wIndex = pclCombo->AddString("Function");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Function);
			wIndex = pclCombo->AddString("Operator");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Operator);
			wIndex = pclCombo->AddString("Procedure");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_Procedure);
			wIndex = pclCombo->AddString("Meta Action");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_MetaAction);
			wIndex = pclCombo->AddString("Begin Meta Action");
			pclCombo->SetItemData(wIndex, AIDebug_E_SecTyp_BeginMetaAction);

			for (wIndex = 0; wIndex < pclCombo->GetCount(); wIndex ++)
			{
				if ( pclCombo->GetItemData(wIndex) == (DWORD)g_pclInterface->m_fn_pclGetDocument()->m_pub_p_tdstGetFindInfo()->eNodeType )
					wIndexToSelect = wIndex;
			}

			pclCombo->SetCurSel(wIndexToSelect);
		}
	#endif // CG PB DEBUGGER }
}


//***************************************************************************
void IAD_Dialog_FindInTree::OnRadioDeepSearch() 
{
	m_pri_fn_vEnableSimpleSearchControls(FALSE);
	m_pri_fn_vEnableDeepSearchControls(TRUE);
}

//***************************************************************************
void IAD_Dialog_FindInTree::OnRadioSimpleSearch() 
{
	m_pri_fn_vEnableSimpleSearchControls(TRUE);
	m_pri_fn_vEnableDeepSearchControls(FALSE);
}

//***************************************************************************
void IAD_Dialog_FindInTree::OnCheckSearchInLevels() 
{
	BOOL bChecked = ((CButton *)GetDlgItem(IDC_CHECK_SEARCH_IN_LEVELS))->GetCheck();

	GetDlgItem(IDC_EDIT_BEGINNING_LEVEL)->EnableWindow(bChecked);	
	GetDlgItem(IDC_EDIT_END_LEVEL)->EnableWindow(bChecked);	
	GetDlgItem(IDC_STATIC_AND_TEXT)->EnableWindow(bChecked);	
}

//***************************************************************************
void IAD_Dialog_FindInTree::m_pri_fn_vEnableSimpleSearchControls(BOOL _bEnable)
{
	GetDlgItem(IDC_STATIC_RECT_SIMPLE_SERACH)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_EDIT_SIMPLE_SEARCH)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_EXACT_SIMPLE_SEARCH)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_CASE_SIMPLE_SEARCH)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_STATIC_SIMPLE_SEARCH_TEXT)->EnableWindow(_bEnable);	
}

//***************************************************************************
void IAD_Dialog_FindInTree::m_pri_fn_vEnableDeepSearchControls(BOOL _bEnable)
{
	GetDlgItem(IDC_STATIC_DEEP_SEARCH_RECT)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_STATIC_DEEP_SEARCH_TEXT)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_COMBO_FIELD_TYPE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_EDIT_NAME)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_EDIT_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_EDIT_RETURNING_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_EXACT_NAME)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_CASE_NAME)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_EXACT_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_CASE_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_EXACT_R_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_CHECK_CASE_R_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_STATIC_RECT_NAME)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_STATIC_RECT_VALUE)->EnableWindow(_bEnable);	
	GetDlgItem(IDC_STATIC_RECT_RET_VALUE)->EnableWindow(_bEnable);	
}
