// Implementation file for the definition of a Text control
//////////////////////////////////////////////////////////////////
#include "StdAfx.h"

#include "Controls\CTL_CtlT.hpp"

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

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

//Constructor / Destructor
//************************************************************************************
CTL_Editor_TextControl::CTL_Editor_TextControl(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__TEXT, 
																					 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_pclCurrentStatic = NULL;
}

//************************************************************************************
CTL_Editor_TextControl::~CTL_Editor_TextControl()
{

}

//Member functions

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

	m_pclParentWnd = pclParentWnd;

	m_pro_fn_bCreateBaseControls(	C_TEXT_NAME_BOX_PERCENT_WIDTH,
																40,
																C_EDIT_HEIGHT);
  	
	//Creates a static box for the current value of the Text (Read Only mode)
	m_pclCurrentStatic = new CTL_Editor_Static(	"",
																							CTL_STATIC_TYPE__FIELD_VALUE,
																							0,
																							NULL,
																							pclParentWnd
																							);
#ifndef CTL_WITH_NO_TUT
	m_pclCurrentStatic->m_pub_fn_vRegisterWindowsControl(m_pub_fn_csGetControlName() + " - Text");
#endif //CTL_WITH_NO_TUT

	m_pclListOfBaseControls->m_pub_fn_pclAddControlAtTail(m_pclCurrentStatic,
																												m_pclCurrentStatic,
																												this,
																												CTL_BASE_CONTROL_DISPLAY_TYPE__NORMAL,
																												C_TEXT_CURRENT_VALUE_PERCENT_WIDTH,
																												C_TEXT_CURRENT_VALUE_MIN_WIDTH, 
																												C_EDIT_HEIGHT,
																												/*TRUE*/FALSE);
	
	m_bControlCreated = bReturnValue;

	return bReturnValue;
}

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

//************************************************************************
//Function called to update controls in case of values changes.
void CTL_Editor_TextControl::m_fn_vUpdate(CTL_tdeUpdateReason _eReason /*= E_ur_NoReasonGiven*/,
																					long _lUserDefinedReason /*= 0*/)
{
	//CPA2 Stegaru Cristian 98/06/26
	m_pclCurrentStatic->m_fn_vSetTextToDisplay(((CTL_Editor_TextData *)m_pclData)->mfn_csGetCurrentString ());
	//End CPA2 Stegaru Cristian 98/06/26

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

//************************************************************************
//Function called to update parent window in case of values changes.
void CTL_Editor_TextControl::m_fn_vUpdateParent(CTL_tdeUpdateReason eReason,
																								long _lUserDefinedReason /*= 0*/)
{
	CTL_Editor_Control::m_fn_vUpdateParent(eReason, _lUserDefinedReason);
}

//************************************************************************
//Function called to make control Read Only
void CTL_Editor_TextControl::m_fn_vMakeReadOnly()
{
	if ( !m_fn_bIsReadOnly() )
	{
		m_bIsReadOnly = TRUE;
		m_fn_vHide();
	}
}

//************************************************************************
//Function called to make control Read-Write
void CTL_Editor_TextControl::m_fn_vMakeReadWrite()
{
	if ( !m_fn_bIsAlwaysReadOnly() )
	{
		if ( m_fn_bIsReadOnly() )
		{
			m_bIsReadOnly = FALSE;
			m_fn_vHide();
		}
	}
}
