// Used for Data and Controls customization
//
// YB
//
/////////////////////////////////////////////////////
#include "StdAfx.h"

//ANNECY CHRISTOPHE MODIFICATIONS
#define D_ZdxStuff_StructureDefine
//ANNECY END CHRISTOPHE MODIFICATIONS

#include "EDACCust.hpp"

#include "_AInterf.hpp"
#include "EDACMStA.hpp"
#include "EDACActr.hpp"
#include "EDACModl.hpp"
#include "CPA_DatO.hpp"
#include "CPA_DatS.hpp"
#include "EDACWatc.hpp"
#include "EDACVwMS.hpp"

//CPA2 Stegaru Cristian 98/06/25
#include "..\inc\edactors\dlgselectinstances.h"
//End CPA2 Stegaru Cristian 98/06/25

//External Modules
#include "ErO.h"
#include "IncTUT.h"
#include "WAW.h"
//End of External Modules

#undef CPA_WANTS_IMPORT
#undef CPA_EXPORT
#define CPA_WANTS_EXPORT
    #include "_Actors.hpp"
#undef CPA_WANTS_EXPORT
#define CPA_WANTS_IMPORT

//************************************************************************************
//*****************************########################*******************************
//*****************************# Owner Data Functions #*******************************
//*****************************########################*******************************
//************************************************************************************

//************************************************************************************
//************************************ Data ******************************************
//************************************************************************************

#define OAC_C_szOwnerDataName_Data_ParentActor	"Data_Parent_Actor"
#define OAC_C_szOwnerDataName_Data_ParentAMS		"Data_Parent_AMS"
#define OAC_C_szOwnerDataName_Data_LinkType			"Data_Link_Type"
#define OAC_C_szOwnerDataName_Data_InWatch			"Data_In_Watch"

//************************************************************************************
void OAC_AddOwnerDataToData(CTL_Editor_Data *_pclData,
														EdActors_EditorActor *_pclParentActor,
														EdActors_ActorMiniStructure *_pclParentAMS)
{
	_pclData->m_pub_fn_pclAddOwnerData((void *)_pclParentActor, OAC_C_szOwnerDataName_Data_ParentActor);
	_pclData->m_pub_fn_pclAddOwnerData((void *)_pclParentAMS, OAC_C_szOwnerDataName_Data_ParentAMS);
	_pclData->m_pub_fn_pclAddOwnerData((long)OAC_LINK_MODE__NOT_LINKED, OAC_C_szOwnerDataName_Data_LinkType);
	_pclData->m_pub_fn_pclAddOwnerData((void *)NULL, OAC_C_szOwnerDataName_Data_InWatch);
}

//************************************************************************************
EdActors_EditorActor *OAC_fn_pclGetParentActorOfData(CTL_Editor_Data *_pclData)
{
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_ParentActor);

	if ( pclOD != NULL )
		return (EdActors_EditorActor *)pclOD->m_pub_fn_pvGetDataPtr();
	else
		return NULL;
}

//************************************************************************************
EdActors_ActorMiniStructure *OAC_fn_pclGetParentAMSOfData(CTL_Editor_Data *_pclData)
{
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_ParentAMS);

	if ( pclOD != NULL )
		return (EdActors_ActorMiniStructure *)pclOD->m_pub_fn_pvGetDataPtr();
	else
		return NULL;
}

//************************************************************************************
OAC_eDataLinkMode OAC_fn_tdeGetLink(CTL_Editor_Data *_pclData)
{
	//Sets new link
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_LinkType);
	if ( pclOD != NULL )
		return ((OAC_eDataLinkMode)pclOD->m_pub_fn_lGetData());
	else
		return OAC_LINK_MODE__NOT_LINKED;	//Default value
}

//************************************************************************************
//Returns the previous Link status
OAC_eDataLinkMode OAC_fn_tdeSetLink(CTL_Editor_Data *_pclData,
																		OAC_eDataLinkMode _tdeNewLink)
{
	OAC_eDataLinkMode tdePreviousLink = OAC_fn_tdeGetLink(_pclData);

	//Sets new link
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_LinkType);
	if ( pclOD != NULL )
		pclOD->m_pub_fn_vSetData((long)_tdeNewLink);

	return tdePreviousLink;
}

//************************************************************************************
BOOL OAC_fn_bIsLinked(CTL_Editor_Data *_pclData)
{
	BOOL bIsLinked =	(		( OAC_fn_tdeGetLink(_pclData) == OAC_LINK_MODE__LINKED )
										||	( OAC_fn_tdeGetLink(_pclData) == OAC_LINK_MODE__ALWAYS_LINKED )
										);

	return bIsLinked;
}

//************************************************************************************
OAC_tdeDataLinkMode eNot(OAC_tdeDataLinkMode _eMode)
{
	switch ( _eMode )
	{
		//Can be changed
		case OAC_LINK_MODE__NOT_LINKED:
			return OAC_LINK_MODE__LINKED;
		case OAC_LINK_MODE__LINKED:
			return OAC_LINK_MODE__NOT_LINKED;
		//Cannot be changed !!
		case OAC_LINK_MODE__ALWAYS_LINKED:
		case OAC_LINK_MODE__NEVER_LINKED:
			return _eMode;
		//Default returned value
		default:
			return OAC_LINK_MODE__LINKED;
	};
}

//************************************************************************************
BOOL OAC_fn_bDataIsInWatch(CTL_Editor_Data *_pclData)
{
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_InWatch);

	if ( pclOD != NULL )
		return (pclOD->m_pub_fn_pvGetDataPtr() != NULL );
	else
		return FALSE;
}

//************************************************************************************
WAW_Data *OAC_fn_pclGetAssociatedWatchData(CTL_Editor_Data *_pclData)
{
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_InWatch);

	if ( pclOD != NULL )
		return ( (WAW_Data *)pclOD->m_pub_fn_pvGetDataPtr() );
	else
		return NULL;
}

//************************************************************************************
void OAC_fn_vSetDataInWatch(CTL_Editor_Data *_pclData,
														WAW_Data *_p_clDataInWatch)
{
	CTL_OwnerData *pclOD = _pclData->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Data_InWatch);

	if ( pclOD != NULL )
		pclOD->m_pub_fn_vSetDataPtr((void *)_p_clDataInWatch);
}

//************************************************************************************
//********************************** Controls ****************************************
//************************************************************************************

#define OAC_C_szOwnerDataName_Control_Level					"Control_Level"
#define OAC_C_szOwnerDataName_Control_Visibility		"Control_Visibility"
#define OAC_C_szOwnerDataName_Control_LinkCheckBox	"Control_LinkCheckBox"
#define OAC_C_szOwnerDataName_Control_HelpID				"Control_Help_ID"

//************************************************************************************
void OAC_AddOwnerDataToControl(CTL_Editor_Control *_pclControl,
															 OAC_tdeDataLevel _eLevel,
															 OAC_tdeControlVisibility _eVisibility,
															 DWORD dwHelpID)
{
	_pclControl->m_pub_fn_pclAddOwnerData(_eLevel, OAC_C_szOwnerDataName_Control_Level);
	_pclControl->m_pub_fn_pclAddOwnerData(_eVisibility, OAC_C_szOwnerDataName_Control_Visibility);
	_pclControl->m_pub_fn_pclAddOwnerData(dwHelpID, OAC_C_szOwnerDataName_Control_HelpID);

	_pclControl->m_pub_fn_vSetControlCanBeDisplayedCallBack(OAC_fn_bControlCanBeDisplayed);
}

//************************************************************************************
OAC_tdeControlVisibility OAC_tdeGetVisibilityOfControl(CTL_Editor_Control *_pclControl)
{
	CTL_OwnerData *pclOD = _pclControl->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Control_Visibility);
	if ( pclOD != NULL )
		return (OAC_tdeControlVisibility)pclOD->m_pub_fn_lGetData();
	else
		return EDCAR_DATA_VISI_DUAL;
}

//************************************************************************************
DWORD OAC_fn_tdeGetHelpIDOfControl(CTL_Editor_Control *_pclControl)
{
	CTL_OwnerData *pclOD = _pclControl->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Control_HelpID);
	if ( pclOD != NULL )
		return (DWORD)pclOD->m_pub_fn_lGetData();
	else
		return IDH_FIELD_UNKNOWN;
}

//************************************************************************************
OAC_eDataLevel OAC_fn_tdeGetLevelOfControl(CTL_Editor_Control *_pclControl)
{
	CTL_OwnerData *pclOD = _pclControl->m_pub_fn_pclGetOwnerDataWithName(OAC_C_szOwnerDataName_Control_Level);
	if ( pclOD != NULL )
		return (OAC_eDataLevel)pclOD->m_pub_fn_lGetData();
	else
		return OAC_DATA_LEVEL_1;
}

//************************************************************************************
void OAC_fn_vCustomizeControl(CTL_Editor_Control *_pclControl,
															CWnd *_pclParentWnd)
{
	//Adds a Check Box at Head of control
	ERROR_ASSERT( _pclControl->m_pub_fn_pclGetListOfBaseControls() != NULL );

	//Creates the Check Box
	CTL_Editor_CheckBox *pclCheckBox = new CTL_Editor_CheckBox(CTL_CHECK_BOX_TYPE__USE_USER_DEFINED_TYPE,
																														0,	//Additionnal Style
																														_pclControl,
																														_pclParentWnd,
																														OAC_CHECK_BOX_TYPE__LINK,
																														0);	//Returned code
	//Sets CallBack
	pclCheckBox->m_pub_fn_vSetHasBeenClicked_CallBack(OAC_fn_vCheckBoxHasBeenClicked_CallBack);

	//Adds an owner Data
	_pclControl->m_pub_fn_pclAddOwnerData((void *)pclCheckBox, OAC_C_szOwnerDataName_Control_LinkCheckBox);
	
	CTL_Editor_BaseControl *pclAddedBaseControl;
	pclAddedBaseControl = _pclControl->m_pub_fn_pclGetListOfBaseControls()->m_pub_fn_pclAddControlAtHead(pclCheckBox,
																															pclCheckBox,
																															_pclControl,
																															CTL_BASE_CONTROL_DISPLAY_TYPE__ALWAYS_FIXED,
																															0,
																															15,
																															15,
																															FALSE,
																															FALSE);

	pclAddedBaseControl->m_pub_fn_vSetCanBeDisplayedCallBack(OAC_fn_bLinkCheckBoxCanBeDisplayed_CallBack);
	pclAddedBaseControl->m_pub_fn_vSetMustBeEnabledCallBack(OAC_fn_bLinkCheckBoxMustBeEnabled_CallBack);
}

//************************************************************************************
BOOL OAC_fn_bControlCanBeDisplayed(class CTL_Editor_Control *_pclSenderControl)
{
	BOOL bMustBeDisplayed;

	BOOL bMustNotDisplayBecauseLinkedFieldOfAnInstance;
	BOOL bMustNotDisplayBecauseInstanceOnlyField;
	BOOL bMustNotDisplayBecauseModelOnlyField;
	BOOL bMustDisplayBecauseRightLevel;

// Shaitan FastC {
	if (_pclSenderControl->m_pub_fn_csGetControlName() == "FastC_Index")
		return FALSE;
//End Shaitan FastC }
	//Gets Data
	CTL_Editor_Data *pclData = _pclSenderControl->m_fn_pclGetEditedData();
	//Gets Parent Actor
	EdActors_EditorActor *pclEdActor = OAC_fn_pclGetParentActorOfData(pclData);
	//Gets visibility
	OAC_tdeControlVisibility eVisibility = OAC_tdeGetVisibilityOfControl(_pclSenderControl);
	//Gets Level
	OAC_eDataLevel eLevel = OAC_fn_tdeGetLevelOfControl(_pclSenderControl);

	//Analyses if control must be displayed
	bMustNotDisplayBecauseLinkedFieldOfAnInstance = (
																											pclEdActor->m_fn_bIsAnInstance()
																									&&	(		( OAC_fn_bIsLinked(pclData) )
																											&&	(!g_pclInterface->m_clDocument.m_bMustDisplayModelFieldsInInstance)
																											)
																									);
	
	bMustNotDisplayBecauseInstanceOnlyField =	( 
																								( !pclEdActor->m_fn_bIsAnInstance() )
																						&&	( eVisibility == EDCAR_DATA_VISI_ONLY_INSTANCES )
																						);
	
	bMustNotDisplayBecauseModelOnlyField =	(
																							( pclEdActor->m_fn_bIsAnInstance() )
																					&&	( eVisibility == EDCAR_DATA_VISI_ONLY_MODELS )
																					);
	
//Stefan Dumitrean 14-07-98 ( OAC buttons )
/*
	bMustDisplayBecauseRightLevel = (		(
																					(!g_pclInterface->m_clDocument.m_bExclusiveLevel)
																			&&	(eLevel <= g_pclInterface->m_clDocument.m_tdeCurrentDataLevel)
																			)
																	||	(
																					(g_pclInterface->m_clDocument.m_bExclusiveLevel)
																			&&	(eLevel == g_pclInterface->m_clDocument.m_tdeCurrentDataLevel)
																			)
																	);
*/
	CString csControlName = _pclSenderControl->m_pub_fn_csGetControlName();

/*
	switch( eLevel )
	{
		case OAC_DATA_LEVEL_1:
		case OAC_DATA_LEVEL_2:
			bMustDisplayBecauseRightLevel =
				g_pclInterface->m_clDocument.m_aCurrentOACButtonsPressed[0];
			break;
		case OAC_DATA_LEVEL_3:
			bMustDisplayBecauseRightLevel =
				g_pclInterface->m_clDocument.m_aCurrentOACButtonsPressed[1];
	}

	if( bMustDisplayBecauseRightLevel )
*/		switch( _pclSenderControl->m_ucInitialCurrentPair )
		{
			case 1: //is initial
				bMustDisplayBecauseRightLevel = g_pclInterface->m_clDocument.m_bDisplayInitialValue;
				break;
			case 2: //is current
				bMustDisplayBecauseRightLevel = g_pclInterface->m_clDocument.m_bDisplayCurrentValue;
		}
//End Stefan Dumitrean 14-07-98 ( OAC buttons )

	bMustBeDisplayed =	(		!bMustNotDisplayBecauseLinkedFieldOfAnInstance
											&&	!bMustNotDisplayBecauseInstanceOnlyField
											&&	!bMustNotDisplayBecauseModelOnlyField
											&&	bMustDisplayBecauseRightLevel
											);

	return bMustBeDisplayed;
}


//************************************************************************************
//*******************************######################*******************************
//*******************************# CallBack Functions #*******************************
//*******************************######################*******************************
//************************************************************************************

//************************************************************************************
//************************************** Data ****************************************
//************************************************************************************

//************************************************************************************
void OAC_fn_vDataHasBeenChanged(class CTL_Editor_Data *_pclChangedData,
																enum CTL_eUpdateReason _eReason,
																long _lUserDefinedReason /*= 0*/)
{
	if ( _eReason == CTL_UPDATE_REASON__DATA_MODIFIED_BY_USER )
	{
		EdActors_EditorActor *pclParentActor = OAC_fn_pclGetParentActorOfData(_pclChangedData);
		if ( pclParentActor != NULL )
			pclParentActor->m_pclActor->fn_vNotifySave();

		//CPA2 Stegaru Cristian 98/06/24
		MS_Field modifField;
		EdActors_EditorActor *pclEdActor = g_pclInterface->m_clDocument.m_pclSelectedActor;
		if (pclEdActor && pclEdActor->m_pclActor && pclEdActor->m_pclActor->m_fn_bIsAModel())
		{
			modifField.m_csModelName = pclEdActor->m_pclActor->GetName ();

			CTL_Editor_Control *pParentControl = _pclChangedData->m_pub_fn_pclGetParentControl();	
			if (pParentControl)
			{
				CTL_Editor_Data *pclData = pParentControl->m_fn_pclGetEditedData();
				modifField.m_pModifiedData = pclData;
			}
		}

		g_pclInterface->m_clDocument.mfn_vSetLastModifiedField (modifField);
		//End CPA2 Stegaru Cristian 98/06/24
	}

	BOOL bWatchHasBeenUpdated = FALSE;

	// If a Model has changed
	EdActors_MyDocument *pclDoc = &(g_pclInterface->m_clDocument);
	if ( OAC_fn_pclGetParentActorOfData(_pclChangedData)->m_pclActor->m_fn_bIsAModel() )
	{
		// For Fast_C
		if (_pclChangedData->m_pub_fn_csGetDataName() == "FastC_Run")
			((EdActors_EditorActorModel *) OAC_fn_pclGetParentActorOfData(_pclChangedData))->m_pub_fn_vNotifyBrain();
			
		// If data is an initial value, update the current one
		if (_pclChangedData->m_fn_bHasACurrentData())
			_pclChangedData->m_fn_pclGetAssociatedCurrentData()->m_fn_vUpdateData(_pclChangedData, _eReason, OAC_E_ur_ModelDataChanged);
		
		// If data is linked, update instances
		if ( OAC_fn_bIsLinked(_pclChangedData) && (pclDoc->m_pclSelectedActor == OAC_fn_pclGetParentActorOfData(_pclChangedData)))
		{
			//Updates Instances if a Model has changed
			((EdActors_EditorActorModel *)pclDoc->m_pclSelectedActor)->m_fn_vUpdateAllInstances(_pclChangedData, _eReason, OAC_E_ur_ModelDataChanged);
 			
			//Updates Watch Window
			OAC_fn_vUpdateAllDataInWatchWindow();
			bWatchHasBeenUpdated = TRUE;
		}
	}

	//Updates Watch Window if necessary
	if	( (OAC_fn_bDataIsInWatch(_pclChangedData)) && (!bWatchHasBeenUpdated) )
		OAC_fn_vUpdateDataInWatchWindow(_pclChangedData);
}

//************************************************************************************
BOOL OAC_fn_bVectorDataMustBeRead(CTL_Editor_Data *_pclData)
{
	BOOL bDataMustBeRead = TRUE;
  
	EdActors_EditorActor *pclParentActor = OAC_fn_pclGetParentActorOfData(_pclData);

	bDataMustBeRead =	(		( _pclData->m_fn_pvGetMotorDataPtr() != NULL )  //This is NULL for a Model
										&&	((pclParentActor->m_pclActor == NULL) ? TRUE : !pclParentActor->m_pclActor->m_fn_bIsAnAlways())
										);

	return bDataMustBeRead;
}

//************************************************************************************
BOOL OAC_fn_bVectorDataMustBeWritten(CTL_Editor_Data *_pclData)
{
	BOOL bDataMustBeWritten = TRUE;
  
	EdActors_EditorActor *pclParentActor = OAC_fn_pclGetParentActorOfData(_pclData);

	bDataMustBeWritten =	(		( _pclData->m_fn_pvGetMotorDataPtr() != NULL )  //This is NULL for a Model
												&&	((pclParentActor->m_pclActor == NULL) ? TRUE : !pclParentActor->m_pclActor->m_fn_bIsAnAlways())
												);

	return bDataMustBeWritten;
}

//************************************************************************************
//************************************ Controls **************************************
//************************************************************************************

//************************************************************************************
//******************************** Windows Controls **********************************
//************************************************************************************

//************************************************************************************
void OAC_fn_vFieldNameStaticHasBeenClicked_CallBack(class CTL_Editor_Static *_pclSenderStatic,
																										enum CTL_eClickType _tdeClickType)
{
	switch ( _tdeClickType )
	{
	//CPA2 Stegaru Cristian 98/06/22
	case CTL_CLICK_TYPE__SHIFT_RIGHT_CLICK:
		//show popup
		{
			EdActors_EditorActor *pclEdActor = g_pclInterface->m_clDocument.m_pclSelectedActor;
			if (pclEdActor && pclEdActor->m_pclActor && pclEdActor->m_pclActor->m_fn_bIsAModel())
			{
				const CString csModelName = pclEdActor->m_pclActor->GetName ();
				//get data

				CTL_Editor_Control *pParentControl = _pclSenderStatic->m_pub_fn_pclGetParentControl();	
				CTL_Editor_Data *pclData = pParentControl->m_fn_pclGetEditedData();
				const CString csDataName = pclData->m_pub_fn_csGetDataName();

				MS_Field stLastModifiedField = g_pclInterface->m_clDocument.mfn_stGetLastModifiedField ();

				CStringList lstAllInstances, lstStandardInstances;

				EdActors_EditorActorModel *pEdModel = (EdActors_EditorActorModel *)pclEdActor;
				if (pEdModel)
				{
					pEdModel->mfn_vGetAllInstances (lstAllInstances);
					if (!stLastModifiedField.m_csModelName.IsEmpty () 
						&& csModelName == stLastModifiedField.m_csModelName
						&& stLastModifiedField.m_pModifiedData
						&& csDataName == stLastModifiedField.m_pModifiedData->m_pub_fn_csGetDataName()) 
						pEdModel->mfn_vGetStandardInstances (pclData, stLastModifiedField.m_pModifiedData, lstStandardInstances);

					CDlgSelectInstances dlg (lstAllInstances, lstStandardInstances);	
					if (IDOK == dlg.DoModal ())
					{
						if (dlg.mfn_bProcessAllInstances ())
							pEdModel->mfn_vUpdateInstances (pclData);
						else
							pEdModel->mfn_vUpdateInstances (pclData, REASON_INSTANCES_IN_THE_LIST, &lstAllInstances);
					}
				}
			}
		}
		break;
	//End CPA2 Stegaru Cristian 98/06/22
	case CTL_CLICK_TYPE__RIGHT_CLICK:
		{
			EdActors_EditorActor *pclEdActor = g_pclInterface->m_clDocument.m_pclSelectedActor;
			if ( pclEdActor->m_fn_bIsAnInstance() )
			{
				//Adds/Removes Field in/from Watch
				if ( _pclSenderStatic->m_pub_fn_pclGetParentControl() != NULL )
				{
					CTL_Editor_Data *pclData = _pclSenderStatic->m_pub_fn_pclGetParentControl()->m_fn_pclGetEditedData();
	 				EdActors_EditorActor *pclParentActor = OAC_fn_pclGetParentActorOfData(pclData);

					if	(		(pclParentActor->m_fn_bIsAnInstance())
							&&	(!pclParentActor->m_pclActor->m_fn_bIsAnAlways())
							)
					{
						BOOL bDataIsInWatch = OAC_fn_bDataIsInWatch(pclData);
						
						if ( bDataIsInWatch )
							//Removes from Watch
							OAC_RemoveFieldFromWatchWindow(pclData);
						else
							//Adds in Watch
							OAC_AddFieldInWatchWindow(pclData);

						_pclSenderStatic->m_pub_fn_vSetBackGroundColor(bDataIsInWatch ? g_pclInterface->m_clDocument.m_pub_colref_FieldInstanceBackgroundColor
																																					: g_pclInterface->m_clDocument.m_pub_colref_InWatchFieldBackgroundColor,
																													TRUE);
						_pclSenderStatic->m_pub_fn_vSetTextColor(bDataIsInWatch ? g_pclInterface->m_clDocument.m_pub_colref_FieldInstanceTextColor
																																		: g_pclInterface->m_clDocument.m_pub_colref_InWatchFieldTextColor,
																										TRUE);
					}
				}
			}
		}
		break;
	case CTL_CLICK_TYPE__LEFT_DOUBLE_CLICK:
		break;

	case CTL_CLICK_TYPE__LEFT_BUTTON_DOWN:
		if	( _pclSenderStatic->m_pub_fn_pclGetParentControl() != NULL )
		{
			CTL_Editor_Data *pclData = _pclSenderStatic->m_pub_fn_pclGetParentControl()->m_fn_pclGetEditedData();
			EdActors_EditorActor *pclParentActor = OAC_fn_pclGetParentActorOfData(pclData);
			if	(	pclParentActor->m_fn_bIsAnInstance() )
			{
				//Begins Drag
				g_pclInterface->m_clDocument.m_pclMiniStrucView->m_bMustDragData = TRUE;
				g_pclInterface->m_clDocument.m_pclMiniStrucView->SetCapture();
				g_pclInterface->m_clDocument.m_pclMiniStrucView->m_pri_pclDataToDrop = pclData;
			}
		}

		break;
	};
}

//************************************************************************************
void OAC_fn_vInstanceNameStaticHasBeenClicked_CallBack(class CTL_Editor_Static *_pclSenderStatic,
																											 enum CTL_eClickType _tdeClickType)
{
	switch ( _tdeClickType )
	{
	case CTL_CLICK_TYPE__RIGHT_CLICK:
		{
			//Displays Popup Menu
			////
			//Loads menu
			CMenu clMenu;
			clMenu.LoadMenu(IDR_MENU_CONTEXT);
			
			//Gets submenu
			CMenu *pclSubMenu;

			EdActors_EditorActor *pclEdActor = g_pclInterface->m_clDocument.m_pclSelectedActor;
			ERROR_ASSERT( pclEdActor->m_fn_bIsAnInstance() );

			pclSubMenu = clMenu.GetSubMenu(2);
 		
			//Selects what's needed
			UINT nCheck = pclEdActor->m_pclActor->m_fn_bIsAnAlways() ? MF_CHECKED : MF_UNCHECKED;
			pclSubMenu->CheckMenuItem(ID_ALWAYS, MF_BYCOMMAND | nCheck);
			nCheck = pclEdActor->m_pclActor->m_fn_bIsAGenDoor() ? MF_CHECKED : MF_UNCHECKED;
			pclSubMenu->CheckMenuItem(ID_GENDOOR, MF_BYCOMMAND | nCheck);
			nCheck = pclEdActor->m_pclActor->m_pub_fn_bIsCommon() ? MF_CHECKED : MF_UNCHECKED;
			pclSubMenu->CheckMenuItem(ID_COMMON, MF_BYCOMMAND | nCheck);
			nCheck = pclEdActor->m_pclActor->m_pub_fn_bIsInFix() ? MF_CHECKED : MF_UNCHECKED;
			pclSubMenu->CheckMenuItem(ID_INTO_FIX, MF_BYCOMMAND | nCheck);
			nCheck = pclEdActor->m_pclActor->m_pub_fn_bIsAlwaysActive() ? MF_CHECKED : MF_UNCHECKED;
			pclSubMenu->CheckMenuItem(ID_ALWAYS_ACTIVE, MF_BYCOMMAND | nCheck);
			if ( (pclEdActor->m_pclActor->m_fn_bIsAnAlways()) /*|| (pclEdActor->m_pclActor->m_fn_bIsTheWorldActor())*/ )
				nCheck = MF_GRAYED;
			else
				nCheck = MF_ENABLED;
			pclSubMenu->EnableMenuItem(ID_ALWAYS_ACTIVE, MF_BYCOMMAND | nCheck);
// ANNECY MT - 19/11/98 {
			nCheck = pclEdActor->m_pclActor->m_pub_fn_bIsInAllSubMaps() ? MF_CHECKED : MF_UNCHECKED;
			pclSubMenu->CheckMenuItem(ID_IN_ALL_SUBMAPS, MF_BYCOMMAND | nCheck);
			if ( (pclEdActor->m_pclActor->m_fn_bIsAnAlways()) /*|| (pclEdActor->m_pclActor->m_fn_bIsTheWorldActor())*/ )
				nCheck = MF_GRAYED;
			else
				nCheck = MF_ENABLED;
			pclSubMenu->EnableMenuItem(ID_IN_ALL_SUBMAPS, MF_BYCOMMAND | nCheck);
// END ANNECY MT }

			CPoint crPoint;
			GetCursorPos(&crPoint);
 
			//////////////
			//////////////
			//Registers for TUT Module
			TUT_M_vGetTutDll();
			
			TUT_M_vRegisterMenu(_pclSenderStatic->GetParent()->m_hWnd, pclSubMenu->m_hMenu, crPoint.x, crPoint.y);

			//End of Registers for TUT Module
			//////////////

			pclSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_LEFTBUTTON, crPoint.x, crPoint.y, _pclSenderStatic->GetParent());
			
			pclSubMenu->DestroyMenu();
			clMenu.DestroyMenu();
		}
		break;
	case CTL_CLICK_TYPE__LEFT_DOUBLE_CLICK:
		//Edits Model of this Instance
		break;
	};
}

//************************************************************************************
void OAC_fn_vModelNameStaticHasBeenClicked_CallBack(class CTL_Editor_Static *_pclSenderStatic,
									  																enum CTL_eClickType _tdeClickType)
{
	switch ( _tdeClickType )
	{
/*	case CTL_CLICK_TYPE__RIGHT_CLICK:
		{
			//Displays Popup Menu
			////
			//Loads menu
			CMenu clMenu;
			clMenu.LoadMenu(IDR_MENU_CONTEXT);
			
			//Gets submenu
			CMenu *pclSubMenu;
			EdActors_EditorActor *pclEdActor = g_pclInterface->m_clDocument.m_pclSelectedActor;

			pclSubMenu = clMenu.GetSubMenu(0);
 		
			CPoint crPoint;
			GetCursorPos(&crPoint);
 
			//////////////
			//////////////
			//Registers for TUT Module
			TUT_M_vGetTutDll();
			
			TUT_M_vRegisterMenu(_pclSenderStatic->GetParent()->m_hWnd, pclSubMenu->m_hMenu, crPoint.x, crPoint.y);

			//End of Registers for TUT Module
			//////////////

			pclSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_LEFTBUTTON, crPoint.x, crPoint.y, _pclSenderStatic->GetParent());
			
			pclSubMenu->DestroyMenu();
			clMenu.DestroyMenu();
		}
		break;	*/
	case CTL_CLICK_TYPE__LEFT_DOUBLE_CLICK:
		//Edits Model of the Edited Instance
		//
		break;
	};
}

//************************************************************************************
void OAC_fn_ColRefGetStaticColor_CallBack(class CTL_Editor_Static *_pclSenderStatic,
									  											COLORREF &r_ColRefBackGround,
																					COLORREF &r_ColRefText)
{
	CTL_Editor_Control *pclParentControl = _pclSenderStatic->m_pub_fn_pclGetParentControl();

	if ( pclParentControl != NULL )
	{
		CTL_Editor_Data *pclEditedData = pclParentControl->m_fn_pclGetEditedData();

		if ( pclEditedData != NULL )
		{
			EdActors_EditorActor *pclParentActor = OAC_fn_pclGetParentActorOfData(pclEditedData);

			if ( pclParentActor->m_fn_bIsAnInstance() )
			{
				if ( OAC_fn_bDataIsInWatch(pclEditedData) )
				{
					r_ColRefBackGround = g_pclInterface->m_clDocument.m_pub_colref_InWatchFieldBackgroundColor;
					r_ColRefText = g_pclInterface->m_clDocument.m_pub_colref_InWatchFieldTextColor;
				}
				else
				{
					switch (pclParentControl->m_ucInitialCurrentPair)
					{
						case 2:
							r_ColRefBackGround = g_pclInterface->m_clDocument.m_pub_colref_FieldCurrentBackgroundColor;
							r_ColRefText = g_pclInterface->m_clDocument.m_pub_colref_FieldCurrentTextColor;
							break;
						case 1:
							r_ColRefBackGround = g_pclInterface->m_clDocument.m_pub_colref_FieldInitialBackgroundColor;
							r_ColRefText = g_pclInterface->m_clDocument.m_pub_colref_FieldInitialTextColor;
							break;
						case 0:
						default:
							r_ColRefBackGround = g_pclInterface->m_clDocument.m_pub_colref_FieldInstanceBackgroundColor;
							r_ColRefText = g_pclInterface->m_clDocument.m_pub_colref_FieldInstanceTextColor;
							break;
					}
				}
			}
			else
			{
				r_ColRefBackGround = g_pclInterface->m_clDocument.m_pub_colref_FieldModelBackgroundColor;
				r_ColRefText = g_pclInterface->m_clDocument.m_pub_colref_FieldModelTextColor;
			}
		}
	}
	else
	{
		if ( _pclSenderStatic->m_pub_fn_tdeGetType() == CTL_STATIC_TYPE__NEUTRAL_FIELD )
		{
			r_ColRefBackGround = RGB(190,190,190);
			r_ColRefText = RGB(0,0,0);
		}
	}
}

//************************************************************************************
void OAC_fn_vCheckBoxHasBeenClicked_CallBack(class CTL_Editor_CheckBox *_pclSenderCheckBox,
																						 class CTL_Editor_Control *_pclParentControl,
																						 enum CTL_eCarCheckBoxType _tdeType,
																						 long _lUserDefinedType,
																						 long _lUserDefinedCode)
{

}

//************************************************************************************
BOOL OAC_fn_bLinkCheckBoxCanBeDisplayed_CallBack(class CTL_Editor_BaseControl *_pclSenderBaseControl)
{
	return g_pclInterface->m_clDocument.m_pub_bMustShowLinks;
}

//************************************************************************************
BOOL OAC_fn_bLinkCheckBoxMustBeEnabled_CallBack(class CTL_Editor_BaseControl *_pclSenderBaseControl)
{
	//Gets Link mode of Data
	CTL_Editor_Control *pclControl = _pclSenderBaseControl->m_pub_fn_pclGetParentControl();
	ERROR_ASSERT( pclControl != NULL );
	CTL_Editor_Data *pclData = pclControl->m_fn_pclGetEditedData();
	ERROR_ASSERT( pclData != NULL );

	OAC_eDataLinkMode eLinkMode = OAC_fn_tdeGetLink(pclData);

	return ( ( eLinkMode != OAC_LINK_MODE__ALWAYS_LINKED ) && ( eLinkMode != OAC_LINK_MODE__NEVER_LINKED ) );
}

//************************************************************************************
//********************************####################********************************
//********************************# Global Functions #********************************
//********************************####################********************************
//************************************************************************************

//************************************************************************************
CTL_Editor_Data *OAC_fn_pclAddStateData(CTL_Editor_DataList *_pclDataList,
																				CString _csDataName,
																				CTL_Editor_Data *_pclCurrentAssociatedData /*= NULL*/)
{
	CPA_Editor_StateData *pclData = new CPA_Editor_StateData(_csDataName, _pclDataList, _pclCurrentAssociatedData);
	
	_pclDataList->m_pub_fn_vAddData(pclData);

	return pclData;
}

//************************************************************************************
CTL_Editor_Data *OAC_fn_pclAddObjectListData(CTL_Editor_DataList *_pclDataList,
																						 CString _csDataName,
																						 CTL_Editor_Data *_pclCurrentAssociatedData /*= NULL*/)
{
	CPA_Editor_ObjectListData *pclData = new CPA_Editor_ObjectListData(_csDataName, _pclDataList, _pclCurrentAssociatedData);
	
	_pclDataList->m_pub_fn_vAddData(pclData);

	return pclData;
}

//************************************************************************************
BOOL OAC_fn_bBelongsToAnInstance(CTL_Editor_Data *_pclData)
{
	BOOL bBelongsToAnInstance = FALSE;
	EdActors_EditorActor *pclEditorActor = OAC_fn_pclGetParentActorOfData(_pclData);
	if ( pclEditorActor != NULL )
		bBelongsToAnInstance = pclEditorActor->m_fn_bIsAnInstance();

	return bBelongsToAnInstance;
}

//************************************************************************************
BOOL OAC_fn_bIsEditingAnInstance(CTL_Editor_Control *_pclControl)
{
	return OAC_fn_bBelongsToAnInstance(_pclControl->m_fn_pclGetEditedData());
}


//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method	: OAC_fn_bLinkAllowPropagation 
// Date		: 98/06/24
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description	:
// Author		: Stegaru Cristian - CPA
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification	: 
// Date			:
// By			:
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL OAC_fn_bLinkAllowPropagation (CTL_Editor_Data *pclData)
{
	return OAC_LINK_MODE__NOT_LINKED == OAC_fn_tdeGetLink(pclData);
}

