/*=========================================================================
* 
* SECdMode.cpp :  display mode dialog - Implementation file
* 
*
* Version			1.0
* Creation date		
* Revision date
*
* Shaitan
*=======================================================================*/

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

#include "SECdMode.hpp"

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

//#################################################################################
// SECT_DialogMode dialog
//#################################################################################

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



/*----------------------------------------
----------------------------------------*/
void SECT_DialogMode::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SECT_DialogMode)
	DDX_Control(pDX, SECT_IDC_EDITSECTOR, m_cSector);
	DDX_Control(pDX, SECT_IDC_EDITLIST, m_cList);
//Shaitan Clean Env
//	DDX_Control(pDX, SECT_IDC_EDITENV, m_cEnv);
	DDX_Control(pDX, SECT_IDC_SECTORTEXT, m_cSectorText);
	DDX_Control(pDX, SECT_IDC_LISTTEXT, m_cListText);
//Shaitan Clean Env
//	DDX_Control(pDX, SECT_IDC_ENVTEXT, m_cEnvText);
	DDX_Control(pDX, SECT_IDC_MODESYM, m_cModeSym);
	//}}AFX_DATA_MAP
}


/*----------------------------------------
----------------------------------------*/
BEGIN_MESSAGE_MAP(SECT_DialogMode, CFormView)
	//{{AFX_MSG_MAP(SECT_DialogMode)
	ON_WM_SIZE()
	ON_WM_DESTROY()
	ON_BN_CLICKED(SECT_IDC_EDITSECTOR, OnSectors)
	ON_BN_CLICKED(SECT_IDC_EDITLIST, OnList)
//Shaitan Clean Env
//	ON_BN_CLICKED(SECT_IDC_EDITENV, OnEnv)
	ON_BN_CLICKED(SECT_IDC_MODESYM, OnModeSym)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//#################################################################################
// SECT_DialogMode Inits
//#################################################################################

/*===========================================================================
*		Description:	Init dialog
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
void SECT_DialogMode::fn_vInitDialog (Sector_Interface *pOwnerDLL, CWnd *pParent, BOOL bShowSymetric, const CString csTag)
{
	// create the dialog
	m_bInitialised = FALSE;
	m_pOwnerDLL = pOwnerDLL;
	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_cModeSym.m_hWnd,	"OSC_DMODE" + csTag + "_BUTTON_SYMETRIC",	TUT_e_Button);
    TUT_M_vRegisterControl(m_cSector.m_hWnd,	"OSC_DMODE" + csTag + "_BUTTON_SECTOR",		TUT_e_Button);
    TUT_M_vRegisterControl(m_cList.m_hWnd,		"OSC_DMODE" + csTag + "_BUTTON_LIST",		TUT_e_Button);
//Shaitan Clean Env
//    TUT_M_vRegisterControl(m_cEnv.m_hWnd,		"OSC_DMODE" + csTag + "_BUTTON_ENV",		TUT_e_Button);
// END TUTORIAL

	// update mode
	m_bShowSymetric = bShowSymetric;
	m_cModeSym.EnableWindow(bShowSymetric);
	m_cModeSym.ShowWindow(bShowSymetric);
	m_cModeSym.SetCheck(m_pOwnerDLL->fn_bSymetricMode());
	fn_vUpdateEditMode();
	m_bInitialised = TRUE;
}


/*===========================================================================
*		Description:	update dialog when selection changes  
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		Revision date:                      Author:         
*=========================================================================*/
void SECT_DialogMode::fn_vUpdateEditMode (void)
{
	tdeEditMode eEditMode;
	
	eEditMode = m_pOwnerDLL->GetEditMode();
	
	// reinit buttons
	m_cSector.SetCheck(eEditMode == E_em_EditSector);
	m_cList.SetCheck(eEditMode == E_em_EditList);
//Shaitan Clean Env
//	m_cEnv.SetCheck(eEditMode == E_em_EditEnv);
}

	
//#################################################################################
// SECT_DialogMode Messages
//#################################################################################

/*----------------------------------------
----------------------------------------*/
void SECT_DialogMode::OnSize (UINT nFlags, int cx, int cy)
{
	RECT WindowPosition;
	int wcx, mcx, scx, mpy;

	if (!m_bInitialised)
		return;
	
	GetWindowRect(&WindowPosition);

	// calculate position
	wcx = WindowPosition.right - WindowPosition.left - 20;
//Shaitan Clean Env
	mcx = (wcx > 0) ? wcx / 2/*3*/ : 0;
	scx = (wcx < 20) ? 20 : wcx-20;

	// if necessary, move symetric
	if (m_bShowSymetric)
	{
		m_cModeSym.MoveWindow(20, 2, scx, 18);
		mpy = 20;
	}
	else
		mpy = 0;

	// move text 
	m_cSectorText.MoveWindow(5, mpy+5, mcx, 20);
	m_cListText.MoveWindow(mcx+10, mpy+5, mcx, 20);
//Shaitan Clean Env
//	m_cEnvText.MoveWindow(2*mcx + 15, mpy+5, mcx, 20);
	// move radio buttons
	m_cSector.MoveWindow(mcx/2, mpy+25, 20, 17);
	m_cList.MoveWindow(3*mcx/2 + 5, mpy+25, 20, 17);
//Shaitan Clean Env
//	m_cEnv.MoveWindow(5*mcx/2 + 10, mpy+25, 20, 17);
}

/*----------------------------------------
----------------------------------------*/
void SECT_DialogMode::OnDestroy (void)
{
// FOR TUTORIAL
	TUT_M_vGetTutDll();

	TUT_M_vUnregisterControl(m_cModeSym.m_hWnd);
    TUT_M_vUnregisterControl(m_cSector.m_hWnd);
    TUT_M_vUnregisterControl(m_cList.m_hWnd);
//Shaitan Clean Env
//    TUT_M_vUnregisterControl(m_cEnv.m_hWnd);
// END TUTORIAL

	CFormView::OnDestroy();
}

/*----------------------------------------
----------------------------------------*/
void SECT_DialogMode::OnSectors (void)
{
	if (m_cSector.GetCheck())
		m_pOwnerDLL->SetEditMode(E_em_EditSector);
	else
		m_pOwnerDLL->SetEditMode(E_em_EditList);
}

/*----------------------------------------
----------------------------------------*/
void SECT_DialogMode::OnList (void)
{
	if (m_cList.GetCheck())
		m_pOwnerDLL->SetEditMode(E_em_EditList);
	else
		m_pOwnerDLL->SetEditMode(E_em_EditSector/*E_em_EditEnv*/);
}

/*----------------------------------------
----------------------------------------*/
//Shaitan Clean Env
/*
void SECT_DialogMode::OnEnv (void)
{
	if (m_cEnv.GetCheck())
		m_pOwnerDLL->SetEditMode(E_em_EditEnv);
	else
		m_pOwnerDLL->SetEditMode(E_em_EditSector);
}
*/
/*----------------------------------------
----------------------------------------*/
void SECT_DialogMode::OnModeSym (void)
{
	m_pOwnerDLL->SetSymetricMode(m_cModeSym.GetCheck());
}


