/*=========================================================================
* 
* SECdEnvs.cpp :  Environments List Dialog - Implementation file
* 
*
* Version			1.0
* Creation date		
* Revision date
*
* Shaitan
*=======================================================================*/

/*
#include "stdafx.h"
#include "acp_base.h"
#include "SECTint.hpp"

#include "SECdEnvs.hpp"

#include "SECmodif.hpp"
#include "SECdEnv.hpp"
#include "SEClEnvs.hpp"

#include "..\Main\Inc\_EditID.h"
#include "TUT.h"

SECT_Environment *g_pClickedEnv;
*/

//#################################################################################
// SECT_DialogEnvElem dialog
//#################################################################################

/*----------------------------------------
----------------------------------------*/
/*
SECT_DialogEnvs::SECT_DialogEnvs(CWnd* pParent)
	: CFormView(SECT_DialogEnvs::IDD)
{
	//{{AFX_DATA_INIT(SECT_DialogEnvs)
	//}}AFX_DATA_INIT
}
*/


/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SECT_DialogEnvs)
	// env elem
	DDX_Control(pDX, SECT_IDC_ENVLISTBOX, m_cEnvListBox);
	DDX_Control(pDX, SECT_IDC_NEWENV, m_cNewEnv);
	DDX_Control(pDX, SECT_IDC_REPLACE, m_cReplace);
	//}}AFX_DATA_MAP
}
*/

/*----------------------------------------
----------------------------------------*/
/*
BEGIN_MESSAGE_MAP(SECT_DialogEnvs, CFormView)
	//{{AFX_MSG_MAP(SECT_DialogEnvs)
	ON_WM_SIZE()
	ON_WM_DESTROY()
	// env elem
	ON_NOTIFY(LVN_ITEMCHANGED, SECT_IDC_ENVLISTBOX, OnSelChangeEnvListBox)
	ON_NOTIFY(NM_DBLCLK, SECT_IDC_ENVLISTBOX, OnDblClkEnvListBox)
	ON_BN_CLICKED(SECT_IDC_NEWENV, OnNewEnv)
	ON_BN_CLICKED(SECT_IDC_REPLACE, OnReplace)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
*/


//#################################################################################
// SECT_DialogEdit Inits
//#################################################################################

/*===========================================================================
*		Description:	Init dialog
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
/*
void SECT_DialogEnvs::fn_vInitDialog (Sector_Interface *p_oDLL, CWnd *pParent)
{
	// create the dialog
	m_bInitialised = FALSE;
	m_pSectorInterface = p_oDLL;
	CFormView::Create(NULL, "", AFX_WS_DEFAULT_VIEW, CRect(0,0,120,180), pParent, AFX_IDW_PANE_FIRST, NULL);

	// init data for dialog
	CFormView::UpdateData(FALSE);

// FOR TUTORIAL
	TUT_M_vGetTutDll();

    TUT_M_vRegisterControl(m_cEnvListBox.m_hWnd,	"OSC_DLISTENV_LIST_ENVS",	TUT_e_ListBox);
    TUT_M_vRegisterControl(m_cNewEnv.m_hWnd,		"OSC_DLISTENV_BUTTON_NEW",	TUT_e_Button);
    TUT_M_vRegisterControl(m_cReplace.m_hWnd,		"OSC_DLISTENV_BUTTON_REP",	TUT_e_Button);
// END TUTORIAL

	// init all controls
	fn_vInitEnvElem(-1);
	m_bInitialised = TRUE;
	// init listbox
	m_cEnvListBox.fn_vInitParameters(this, m_pSectorInterface, E_te_Environment);
}
*/

/*===========================================================================
*		Description:	Reinit dialog
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
/*
void SECT_DialogEnvs::fn_vReinitDialog (void)
{
	fn_vInitEnvListBox();
}
*/

/*===========================================================================
*		Description:	Init controls state
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
/*
void SECT_DialogEnvs::fn_vInitControls (BOOL bEnable)
{
	m_cEnvListBox.EnableWindow(bEnable);
	m_cNewEnv.EnableWindow(bEnable);
}
*/

/*===========================================================================
*		Description:	Reinit environment list
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
/*
void SECT_DialogEnvs::fn_vInitEnvElem (long lEnvElem)
{
	Sector_Object	*pSector;
	
	// find corresponding element
	if (lEnvElem != -1)
		pSector = (Sector_Object *) m_pSectorInterface->GetEditedSector()->GetObject();
	else
		pSector = NULL;

	// update edited element
	m_lEnvElem = lEnvElem;
	m_pEnvElem = (pSector) ? pSector->GetEnvironment(m_lEnvElem) : NULL;

	// update infos
	fn_vSelectEnv((m_pEnvElem) ? m_pEnvElem->GetEnvironment() : NULL);
	m_cEnvListBox.fn_vReinitListObjects();
}
*/
/*===========================================================================
*		Description:	Init listbox with all available environments 
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
/*
void SECT_DialogEnvs::fn_vInitEnvListBox (void)
{
	// set list style
	m_cEnvListBox.SetOrder(E_lo_Alpha, FALSE, FALSE);
	
	// reinit list
	m_cEnvListBox.SetSortedList(m_pSectorInterface->GetBaseObjectList(C_szEnvironmentTypeName));
	// current selection => none
	m_cEnvListBox.SetSelectedItem(-1);
}
*/


/*===========================================================================
*		Description:	update dialog when selection changes  
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                      Author:         
*=========================================================================*/
/*
void SECT_DialogEnvs::fn_vSelectEnv (SECT_Environment *pEnvironment, BOOL bUpdateEnvElem)
{
	SECT_Environment	*pOldSelect, *pOldCurrent = NULL;
	SECT_ModifEnvElem	*pModif;
	int					iInd;
	
	// update current environment
	pOldSelect = m_pEnvironment;
	m_pEnvironment = pEnvironment;
	
	// update corresponding env elem
	if ((bUpdateEnvElem)&&(m_pEnvElem))
	{
		pOldCurrent = m_pEnvElem->GetEnvironment();
		if ((m_pEnvironment)&&(m_pEnvironment != pOldCurrent))
		{
			pModif = new SECT_ModifEnvElem(m_pSectorInterface, E_mt_ChangeEnv, 
											m_pEnvElem, m_pEnvironment, m_lEnvElem);
			m_pSectorInterface->M_GetEditManager()->AskFor(pModif);
		}
	}

	// redraw previous element
	if (pOldSelect != m_pEnvironment)
	{
		iInd = m_cEnvListBox.GetCorrespondingIndex((DWORD) pOldSelect);
		m_cEnvListBox.RedrawItems(iInd, iInd);
	}

	// redraw previous element
	if ((pOldCurrent)&&(pOldCurrent != pOldSelect))
	{
		iInd = m_cEnvListBox.GetCorrespondingIndex((DWORD) pOldCurrent);
		m_cEnvListBox.RedrawItems(iInd, iInd);
	}

	// update selection
	iInd = m_cEnvListBox.GetCorrespondingIndex((DWORD) m_pEnvironment);
	m_cEnvListBox.RedrawItems(iInd, iInd);
	m_cEnvListBox.EnsureVisible(iInd, TRUE);
	m_cEnvListBox.UpdateWindow();

	// update env list
	if ((bUpdateEnvElem)&&(m_pEnvElem))
		m_pSectorInterface->GetDialogEnvList()->fn_vUpdateEnvElem();

	// update env dialog
	if (m_pSectorInterface->GetDialogEnv())
		m_pSectorInterface->GetDialogEnv()->fn_vInitEnvironment(m_pEnvironment, FALSE);
}
*/

//#################################################################################
// SECT_DialogEdit Messages
//#################################################################################

	
/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::OnSize (UINT nFlags, int cx, int cy)
{
	RECT WindowPosition;
	int ecx, ecy;

	if (!m_bInitialised)
		return;
	
	// calculate name position
	GetWindowRect(&WindowPosition);
	ecx = WindowPosition.right - WindowPosition.left;
	ecx = (ecx < 70) ? 70 : ecx;
	ecy = WindowPosition.bottom - WindowPosition.top - 10;
	ecy = (ecy < 100) ? 100 : ecy;

	// mechanic
	GetDlgItem(SECT_IDC_TEXTENVELEM)->MoveWindow(5, 5, ecx-10, ecy);
	m_cEnvListBox.MoveWindow(10, 25, ecx-20, ecy-50);
	m_cNewEnv.MoveWindow(5, ecy-20, 30, 18);
	m_cReplace.MoveWindow(ecx-38, ecy-20, 30, 18);
}
*/

/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::OnDestroy (void)
{
// FOR TUTORIAL
	TUT_M_vGetTutDll();
    // environment
    TUT_M_vUnregisterControl(m_cEnvListBox.m_hWnd);
    TUT_M_vUnregisterControl(m_cNewEnv.m_hWnd);
    TUT_M_vUnregisterControl(m_cReplace.m_hWnd);

// END TUTORIAL

	CFormView::OnDestroy();
}
*/

/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::OnSelChangeEnvListBox (NMHDR* pNMHDR, LRESULT* pResult)
{
	SECT_Environment	*pEnv = NULL;
	LPNM_LISTVIEW		pNMListView = (LPNM_LISTVIEW)pNMHDR;
	BOOL				bOldSelect, bNewSelect;
	int					iIndex;
	
	// update param
	*pResult = 0;

	if ((pNMListView->uChanged != LVIF_STATE)||(m_cEnvListBox.fn_bIsSelecting()))
		return;

	bOldSelect = (pNMListView->uOldState & LVIS_SELECTED);
	bNewSelect = (pNMListView->uNewState & LVIS_SELECTED);

	// get corresponding sector
	iIndex = pNMListView->iItem;
	pEnv = (SECT_Environment *) m_cEnvListBox.GetItemData(iIndex);
	g_pClickedEnv = pEnv;

	m_cEnvListBox.SetSelectedItem(-1);

	if (bOldSelect != bNewSelect)
	{
		// select corresponding environment
		if ((!pEnv)||(!pEnv->fn_bIsAvailable()))
			fn_vSelectEnv((m_pEnvElem) ? m_pEnvElem->GetEnvironment() : NULL, FALSE);
		else 
			fn_vSelectEnv((pEnv != m_pEnvironment) ? pEnv : NULL, FALSE);
	}
}
*/

/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::OnDblClkEnvListBox (NMHDR* pNMHDR, LRESULT* pResult)
{
	SECT_Environment	*pEnv = NULL;

	// update param
	*pResult = 0;

	// get corresponding sector
	pEnv = g_pClickedEnv;
	g_pClickedEnv = NULL;


	// select corresponding environment
	if ((!pEnv)||(!pEnv->fn_bIsAvailable()))
		fn_vSelectEnv((m_pEnvElem) ? m_pEnvElem->GetEnvironment() : NULL);
	else 
		fn_vSelectEnv(pEnv);
}
*/

/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::OnNewEnv (void)
{
	// update env dialog
	fn_vSelectEnv(NULL);
	m_pSectorInterface->GetDialogEnv()->fn_vInitEnvironment(NULL, TRUE);
	// disable dialog
	fn_vInitControls(FALSE);
	m_pSectorInterface->GetDialogEnvList()->fn_vInitControls(FALSE);
}
*/

/*----------------------------------------
----------------------------------------*/
/*
void SECT_DialogEnvs::OnReplace (void)
{
	m_oDialogReplace.fn_vInitSectorInterface(m_pSectorInterface);
	m_oDialogReplace.DoModal();
}
*/

//#################################################################################
// SECT_EnvElemListBox 
//#################################################################################
/*----------------------------------------
----------------------------------------*/
/*
SECT_EnvElemListBox::SECT_EnvElemListBox (void)
{
}
*/

/*----------------------------------------
----------------------------------------*/
/*
SECT_EnvElemListBox::~SECT_EnvElemListBox (void)
{

}
*/

/*----------------------------------------
----------------------------------------*/
/*
BOOL SECT_EnvElemListBox::fn_bIsCurrentElement (CPA_BaseObject *pElem)
{
	SECT_EnvElem  *pEnvElem;
	
	// no dialog => no current element
	if (!m_pDialog)
		return FALSE;
	
	// init parameters
	pEnvElem = ((SECT_DialogEnvs *) m_pDialog)->GetCurrentEnvElem();
	return ((pEnvElem)&&(pElem == pEnvElem->GetEnvironment()));
}
*/

/*----------------------------------------
----------------------------------------*/
/*
BOOL SECT_EnvElemListBox::fn_bIsSelectedElement (CPA_BaseObject *pElem)
{
	// no dialog => no selected element
	if (!m_pDialog)
		return FALSE;
		
	return (pElem == ((SECT_DialogEnvs *) m_pDialog)->GetSelectedEnvironment());
}
*/

/*----------------------------------------
----------------------------------------*/
/*
BOOL SECT_EnvElemListBox::fn_bIsAlreadyUsed (CPA_BaseObject *pElem)
{
	return FALSE;
}
*/
