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

#include "Controls\CTL_CtlM.hpp"

#include "Controls\CTL_BCtl.hpp"
#include "Data\CTL_DatM.hpp"
#include "WControls\CTL_WBut.hpp"
#include "WControls\CTL_WSta.hpp"
#include "WControls\CTL_WCkB.hpp"
#include "Controls\CTL_Cnst.hpp"
#include "CTL_DgME.hpp"


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

#undef CPA_EXPORT
#define ACTIVE_EDITOR
#define CPA_EXPORT __declspec(dllimport)
#include "ITF\FRMGest.hpp"
CPA_EXPORT BaseFrame	g_oBaseFrame;
#undef CPA_EXPORT

//Constructor / Destructor
//**************************************************************************************
CTL_Editor_MaskedControl::CTL_Editor_MaskedControl(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__MASKED, 
																						 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_pclEditButton = NULL;
}

//**************************************************************************************
CTL_Editor_MaskedControl::~CTL_Editor_MaskedControl()
{
	/*
  if ( m_pclEditButton != NULL )
		delete m_pclEditButton;
    */
}


//Member functions

//**************************************************************************************
//Function called to create associated control
BOOL CTL_Editor_MaskedControl::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_pclEditButton = new CTL_Editor_Button("Edit",
																					CTL_BUTTON_TYPE__EDIT,
																					WS_TABSTOP,
																					this,
																					m_pclParentWnd
																					);
#ifndef CTL_WITH_NO_TUT
	m_pclEditButton->m_pub_fn_vRegisterWindowsControl(m_pub_fn_csGetControlName() + " - MaskedData");
#endif //CTL_WITH_NO_TUT
	m_pclEditButton->EnableWindow(!m_fn_bIsAlwaysReadOnly());

	m_pclListOfBaseControls->m_pub_fn_pclAddControlAtTail(m_pclEditButton,
																												m_pclEditButton,
																												this,
																												CTL_BASE_CONTROL_DISPLAY_TYPE__ALWAYS_FIXED,
																												0,
																												C_BUTTON_WIDTH,	
																												C_EDIT_HEIGHT);
	
	m_bControlCreated = bReturnValue;

	return bReturnValue;
}

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

//************************************************************************
//Function called to update Control in case of values changes.
void CTL_Editor_MaskedControl::m_fn_vUpdate(CTL_tdeUpdateReason _eReason /*= E_ur_NoReasonGiven*/,
																						long _lUserDefinedReason /*= 0*/)
{
	//CallBack
	m_pclData->m_fn_vDataHasBeenChanged(_eReason, _lUserDefinedReason);
}

//************************************************************************
//Function called to update parent window in case of values changes.
void CTL_Editor_MaskedControl::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_MaskedControl::m_fn_vMakeReadOnly()
{
	if ( !m_fn_bIsReadOnly() )
	{
		if ( m_pclEditButton != NULL )
			m_pclEditButton->EnableWindow(FALSE);

		m_bIsReadOnly = TRUE;
	}
}

//************************************************************************
//Function called to make control Read-Write
void CTL_Editor_MaskedControl::m_fn_vMakeReadWrite()
{
 	if ( !m_fn_bIsAlwaysReadOnly() )
	{
		if ( m_pclEditButton != NULL )
			m_pclEditButton->EnableWindow(TRUE);

		m_bIsReadOnly = FALSE;
	}
}

//************************************************************************
void CTL_Editor_MaskedControl::m_fn_vSetCurrentValue(unsigned long _ulNewValue)
{
	//CPA2 Stegaru Cristian 98/06/26
	((CTL_Editor_MaskedData *)m_pclData)->mfn_ulSetCurrentValue (_ulNewValue);
	//End CPA2 Stegaru Cristian 98/06/26

//	if ( m_td_p_fn_vDataHasChangedCallBack != NULL )
//		m_td_p_fn_vDataHasChangedCallBack(m_pclData);

	//Updates motor's data
	m_pclData->m_fn_vUpdateMotorData(CTL_UPDATE_REASON__DATA_MODIFIED_BY_USER);

	//Updates parent's controls if necessary (Watch Window, ...)
	m_fn_vUpdateParent();
}

//************************************************************************
//Specific to this control, overloaded from CTL_Editor_Buttonable
void CTL_Editor_MaskedControl::m_fn_vSetValue(short wAction)
{

}

//************************************************************************
//Called when button is pressed
void CTL_Editor_MaskedControl::m_fn_vEditData()
{
	//Displays the Dialog to Edit the Masked data
//	CTL_DialogMaskedDataEdition EditionDial(this, AfxGetMainWnd());
	CTL_DialogMaskedDataEdition EditionDial(this, &g_oBaseFrame);
	EditionDial.DoModal();
}
