// Implementation file for the definition of a characteristic type
/////////////////////////////////////////////////////////////////////
#include "StdAfx.h"

#include "Controls\CTL_CtlB.hpp"

#include "Controls\CTL_BCtl.hpp"
#include "Data\CTL_DatB.hpp"
#include "WControls\CTL_WCkB.hpp"
#include "WControls\CTL_WSta.hpp"
#include "Controls\CTL_Cnst.hpp"

//External Modules
#include "CTL_ErO.hpp"
//End of External Modules

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

//Constructor / Destructor
//**************************************************************************************
CTL_Editor_BooleanControl::CTL_Editor_BooleanControl(BOOL bReadOnly,
																										 CTL_tdeControlSpacingType tdeSpacingType,
																										 BOOL bUserCanChangeAspect,
																										 CTL_Editor_ControlList *_pclParentList,
																										 CString _csControlName,
																										BOOL _bAcceptNameFromData, //ANNECY BBB
//Stefan Dumitrean 20-07-98 ( OAC buttons )
																										unsigned char ucInitialCurrentPair
//End Stefan Dumitrean 20-07-98 ( OAC buttons )
																										 )
													: CTL_Editor_Control(CTL_DATA_TYPE__BOOLEAN, 
																							 bReadOnly, 
																							 tdeSpacingType,
																							 bUserCanChangeAspect,
																							 _pclParentList,
																							 _csControlName,
																						 _bAcceptNameFromData, //ANNECY BBB
//Stefan Dumitrean 20-07-98 ( OAC buttons )
																					 	 ucInitialCurrentPair
//End Stefan Dumitrean 20-07-98 ( OAC buttons )

																						 )
{
	m_pclCheckBox = NULL;
}

//**************************************************************************************
CTL_Editor_BooleanControl::~CTL_Editor_BooleanControl()
{

}


//Member functions

//**************************************************************************************
//Function called to create associated control
BOOL CTL_Editor_BooleanControl::m_fn_bCreateControl(CWnd *pclParentWnd)
{
	BOOL bReturnValue = TRUE;

	m_pclParentWnd = pclParentWnd;

	m_pro_fn_bCreateBaseControls(C_BOOL_NAME_BOX_PERCENT_WIDTH,
															 C_BOOL_NAME_BOX_MIN_WIDTH,
															 C_EDIT_HEIGHT);

	//Creates check box
 	m_pclCheckBox = new CTL_Editor_CheckBox(CTL_CHECK_BOX_TYPE__NORMAL,
																					WS_TABSTOP,
																					this,
																					m_pclParentWnd);

	m_pclCheckBox->m_pub_fn_vSetHasBeenClicked_CallBack(s_m_fn_vCheckBoxHasBeenClicked);
#ifndef CTL_WITH_NO_TUT
	m_pclCheckBox->m_pub_fn_vRegisterWindowsControl(m_pub_fn_csGetControlName() + " - Boolean");
#endif //CTL_WITH_NO_TUT

	CTL_Editor_BaseControl *pclBC;
	pclBC = m_pclListOfBaseControls->m_pub_fn_pclAddControlAtTail(m_pclCheckBox,
																												m_pclCheckBox,
																												this,
																												CTL_BASE_CONTROL_DISPLAY_TYPE__ALWAYS_FIXED,
																												0,
																												C_BUTTON_WIDTH,
																												C_EDIT_HEIGHT);
	pclBC->m_pub_fn_vSetMustBeEnabledCallBack(s_m_fn_bCheckBoxMustBeEnabled);

	m_bControlCreated = bReturnValue;

	return bReturnValue;
}

//************************************************************************************
//Function called to display the associated control(s) of the char.
void CTL_Editor_BooleanControl::m_fn_vDisplay()
{
	m_pro_fn_vDisplayBaseControls();
}

//************************************************************************
//Function called to update Control in case of values changes.
void CTL_Editor_BooleanControl::m_fn_vUpdate(CTL_tdeUpdateReason _eReason /*= E_ur_NoReasonGiven*/,
																						 long _lUserDefinedReason /*= 0*/)
{
  if ( m_pclCheckBox )
	  //CPA2 Stegaru Cristian 98/06/25
//	  m_pclCheckBox->SetCheck(((CTL_Editor_BooleanData *)m_pclData)->m_bCurrentState);	
	  m_pclCheckBox->SetCheck(((CTL_Editor_BooleanData *)m_pclData)->mfn_bGetCurrentState ());	
	  //End CPA2 Stegaru Cristian 98/06/25

	//CallBack
	m_pclData->m_fn_vDataHasBeenChanged(_eReason, _lUserDefinedReason);
}

//************************************************************************
//Function called to update parent window in case of values changes.
void CTL_Editor_BooleanControl::m_fn_vUpdateParent(CTL_tdeUpdateReason eReason,
																									 long _lUserDefinedReason /*= 0*/)
{
	//Updates parent's controls if necessary (Watch Window, ...)
	CTL_Editor_Control::m_fn_vUpdateParent(eReason, _lUserDefinedReason);
}

//************************************************************************
//Function called to make control Read Only
void CTL_Editor_BooleanControl::m_fn_vMakeReadOnly()
{
	if ( !m_fn_bIsReadOnly() )
	{
		if ( m_pclCheckBox )
			m_pclCheckBox->EnableWindow(FALSE);

		m_bIsReadOnly = TRUE;
	}
}

//************************************************************************
//Function called to make control Read-Write
void CTL_Editor_BooleanControl::m_fn_vMakeReadWrite()
{
 	if ( !m_fn_bIsAlwaysReadOnly() )
	{
		if ( m_pclCheckBox )
			m_pclCheckBox->EnableWindow(TRUE);

		m_bIsReadOnly = FALSE;
	}
}

//************************************************************************
BOOL CTL_Editor_BooleanControl::s_m_fn_bCheckBoxMustBeEnabled(class CTL_Editor_BaseControl *_pclSenderBaseControl)
{
	return (!_pclSenderBaseControl->m_pub_fn_pclGetParentControl()->m_fn_bIsReadOnly());
}

//************************************************************************
void CTL_Editor_BooleanControl::s_m_fn_vCheckBoxHasBeenClicked(class CTL_Editor_CheckBox *_pclSenderCheckBox,
																															 class CTL_Editor_Control *_pclParentControl,
																															 enum CTL_eCarCheckBoxType _tdeType,
																															 long _lUserDefinedType,
																															 long _lUserDefinedCode)
{
	ERROR_ASSERT(_pclParentControl != NULL);
	ERROR_ASSERT(_pclParentControl->m_pub_fn_tdeGetDataType() == CTL_DATA_TYPE__BOOLEAN);

	//Updates motor's data
	//CPA2 Stegaru Cristian 98/06/25
//	((CTL_Editor_BooleanData *)_pclParentControl->m_fn_pclGetEditedData())->m_bCurrentState = _pclSenderCheckBox->GetCheck();
	((CTL_Editor_BooleanData *)_pclParentControl->m_fn_pclGetEditedData())->mfn_bSetCurrentState (_pclSenderCheckBox->GetCheck());
	//End CPA2 Stegaru Cristian 98/06/25
	_pclParentControl->m_fn_pclGetEditedData()->m_fn_vUpdateMotorData(CTL_UPDATE_REASON__DATA_MODIFIED_BY_USER, 0);
}
