// CPACEdBu.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"

#include "WControls\CTL_WBut.hpp"

#include "Controls\CTL_Ctl.hpp"
#include "Others\CTL_Pub.hpp"

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

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

/////////////////////////////////////////////////////////////////////////////
// CTL_Editor_Button

BEGIN_MESSAGE_MAP(CTL_Editor_Button, CButton)
	//{{AFX_MSG_MAP(CTL_Editor_Button)
	ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//**********************************************************************************
CTL_Editor_Button::CTL_Editor_Button(CString _csName,
																		 CTL_tdeButtonType _tdeType,
																		 long _lAdditionnalStyles,
																		 CTL_Editor_Control *_pclParentControl,
																		 CWnd *_pclParentWnd,
																		 long _lUserDefinedType /*= 0*/,
																		 long _lUserDefinedCode /*= 0*/)

											: CTL_BaseWindowsControl(_pclParentControl,
																							 _pclParentWnd,
																							 _lUserDefinedType,
																							 _lUserDefinedCode)
{
	m_tdeType = _tdeType;

	DWORD dwStyle = WS_CHILD;
	dwStyle |= _lAdditionnalStyles;

	if ( Create(_csName, 
							dwStyle, 
							CRect(0,0,0,0), 
							_pclParentWnd, 
							CTL_fn_lGetNextAvailableIDForControl()) )
	{
		SetFont(_pclParentWnd->GetFont());
	}

	m_pri_td_p_fn_vButtonHasBeenClicked_CallBack = NULL;
}

//**********************************************************************************
CTL_Editor_Button::~CTL_Editor_Button()
{

}

/////////////////////////////////////////////////////////////////////////////
// CTL_Editor_Button message handlers

//**********************************************************************************
void CTL_Editor_Button::m_pub_fn_vSetButtonHasBeenClicked_CallBack(CTL_tdp_fn_vButtonHasBeenClicked _p_fn_vCallBack)
{
	ERROR_ASSERT( m_pri_td_p_fn_vButtonHasBeenClicked_CallBack == NULL );

	m_pri_td_p_fn_vButtonHasBeenClicked_CallBack = _p_fn_vCallBack;
}

//**********************************************************************************
void CTL_Editor_Button::OnClicked() 
{
	switch (m_tdeType)
	{
	case CTL_BUTTON_TYPE__EDIT:
		if ( m_pub_fn_pclGetParentControl() != NULL )
			m_pub_fn_pclGetParentControl()->m_fn_vEditData();
		break;
	}

	//Calls CallBack
	if ( m_pri_td_p_fn_vButtonHasBeenClicked_CallBack != NULL )
		m_pri_td_p_fn_vButtonHasBeenClicked_CallBack(this, 
																								 m_pub_fn_pclGetParentControl(),
																								 m_tdeType,
																								 m_pub_fn_lGetUserDefinedType(),
																								 m_pub_fn_lGetUserDefinedCode());
}

//**********************************************************************************
//For TUT registration
void CTL_Editor_Button::m_pub_fn_vRegisterWindowsControl(CString _csAdditionnalInfo)
{
#ifndef CTL_WITH_NO_TUT
	m_pro_fn_vRegisterWindowsControl(_csAdditionnalInfo, TUT_e_Button, "Button", this);
#endif //CTL_WITH_NO_TUT
}

