/*=========================================================================================
File:			EdtList.hpp
Prupose:		Handle lists in editor
Author:			Yann Le Tensorer
Creation Date:	february 11, 1997 (it's my birthday!!)
Version:		1.0
===========================================================================================
Revisions:		Version		Date				Author
                ----------------------------------------------------------------
 
=========================================================================================*/
 
 
/*=========================================================================================
Notes:
=========================================================================================*/
 
 
#ifndef __EDTLIST_HPP__
#define __EDTLIST_HPP__
 
#if _MSC_VER >= 1000
#pragma once
#endif /* _MSC_VER >= 1000*/
 
class CPA_tdoNameList;
class EdtList;
class EdtListHandler;
class EdActors_EditorActor;
 
/* desolé, on ne peut pas éviter celui-là...*/
#include "cpa_nll.hpp"
 
/* Type of owner (modele or instance)*/
#define C_ucModele		0
#define C_ucInstance	1
 
/* constantes d'erreur */
#define C_ucActorHasNoModel		1
#define C_ucNullPointerError	2
#define C_ucActorHasNoNameList	3
 
/* Enum for SetEdtList*/
typedef enum eConstraintType_ { eNormal , eModifyAllActors , eModifyOneActor } tdeConstraintType;
 
/*=======================================================================
Structure passee en parametres lors des messages onquery pour gérér les listes
editeur
=======================================================================*/
typedef struct stEdtListMess_
{
	CString					csListType;		 /* type de liste à créer (Zdd,Zde,Zdm,Chemin)*/
	CPA_BaseObject*         pActor;			 /* Acteur ou le modele*/
	unsigned long			ulIndexInList;	 /* index de l'objet dans la liste*/
	CPA_BaseObject*         pObject;		 /* objet à inserer*/
	EdtList*		        pList;			 /* liste a obtenir*/
	tdeConstraintType       eConstraintType; /* pour SetEdtList*/
} tdstEdtListMess;
 
/*-----------------------------------------------------------------------------*/
/* class EdtList*/
/*-----------------------------------------------------------------------------*/
class EdtList : public CPA_SaveObject , public CPA_List<CPA_SaveObject>
{
public:
	EdtList(
		CPA_tdoNameList *pNameList,		 /* pointer to the list of names (owner of the edtlist)*/
		CString csListType,              /* type de la liste à créer (Zdd,Zde,Zdm,Chemins)*/
		CString csEdtListName,           /* name of the list to create*/
		BOOL _bSectionExist,	
		BOOL _bForModel = FALSE
	);
 
    /* Pure virtual fonctions*/
    long   GetDataType ();               /* Convert m_csListType to a type used by the engine*/
    void * GetData     ()  { return m_hMotorList; }
 
	unsigned long			fn_ulGetNumberOfActorsUsingThisList();
	CString					fn_csGetListType() { return m_csListType; }
	CPA_tdoNameList			*fn_oGetNameList() {return m_pNameList; }
	BOOL					fn_bMakeActorUseThisList(EdActors_EditorActor* pActor    , BOOL bNotifySave = TRUE);
	BOOL					fn_bMakeActorNotUseThisList(EdActors_EditorActor* pActor , BOOL bNotifySave = TRUE);
	void					fn_vInformEditorForAllActors(
													long ulIndexInList,
													CPA_BaseObject	*OldObject,
													EdActors_EditorActor	*pNotToBeTreatedActor
													);
	CPA_List<EdActors_EditorActor> *fn_oGetListOfActorsUsingThisList();
	void					*fn_hGetMotorList () { return m_hMotorList; }
	void					fn_vSetMotorList (void * _hMotorList)  { fn_vUpdateData(_hMotorList); m_hMotorList = _hMotorList; }
	CPA_BaseObject			*fn_oGetFirstActorUsingThisList ();
	void					fn_vSetDrawObjects ( long lDrawObjects ) { m_lDrawObjects = lDrawObjects; }
	long					fn_lGetDrawObjects ( void ) { return m_lDrawObjects; }
 
private:
	void					*m_hMotorList;				/* handle sur la liste moteur*/
	CString					m_csListType;				/* type de liste (Zdd,Zde,Zdm,Chemins)*/
	CPA_tdoNameList			*m_pNameList;				/* list of names*/
	EdtListHandler			*m_pListHandler;			/* List handler*/
	unsigned long			m_ulNumberOfActorsUsingThisList; /* number of actors using this list*/
	CPA_List<EdActors_EditorActor> *m_p_oListOfReferencingEditorActors; /* list of the actors using this list*/
	long					m_lDrawObjects;				/* The objects of the list must be draw (only used for way) ?*/
	BOOL					m_bForModelOnly;
 
	/* Callback to save an object list*/
	void static CallbackToSaveObjectList(
							SCR_tdst_File_Description *_p_stFile,
							char *_p_szSectionName,
							void *_p_vData,
							SCR_tde_Ntfy_Action _eAction
							);
    /* Callback to the file*/
    void static CallbackToCreateZDxFile (	SCR_tdst_File_Description	* _pFile         ,
											char						* _szSectionName ,
											void						* _pData         ,
											SCR_tde_Ntfy_Action			_eAction);
 
 
public:
	void AddObjectInZoneMotorList(short wInsertIndex);
	void RemoveObjectInZoneMotorList(short wIndex);
	void fn_vNotifyRename ();    /* Called when a fn_eRename is done*/
    void fn_vNotifySave    ();
    tdeMissingCriteria fn_eCheckUnicity (const CString csNewName);
	BOOL fn_bForModelOnly (void) { return m_bForModelOnly; }
};
 
/*-----------------------------------------------------------------------------*/
/* class EdtListHandler*/
/*-----------------------------------------------------------------------------*/
class EdtListHandler
{
public:
    EdtListHandler ();    /* Constructor*/
	EdtList*	    	fn_poCreateEdtList(tdstEdtListMess* p_ListMess);
	EdtList*            fn_poCreateEdtList (CPA_tdoNameList * p_NameList , CString csName , void * p_vEngineList ,
                                            BOOL _bSectionExists);
	EdtList*		    fn_poGetEdtList(tdstEdtListMess* p_ListMess);
	void				fn_vSetEdtList(tdstEdtListMess* p_ListMess);
	unsigned char 		fn_ucDeleteEdtList(tdstEdtListMess* p_ListMess);
	unsigned char		fn_ucModifyEdtList(tdstEdtListMess* p_ListMess);
	CPA_tdoNameList*	fn_oGetNameList()                           {return m_pNameList;}
	void				fn_vSetNameList(CPA_tdoNameList* _NameList) {m_pNameList=_NameList;}
	CPA_List<EdtList>*	fn_oGetListOfEdtLists() {return m_pListOfEdtLists;}
	void				fn_vAddObjectInEdtList(CPA_BaseObject* _pObject);
  void /*CPA_List<CPA_BaseObject>**/m_vRemoveObjectFromAllLists(unsigned long ulIndex);
    void                fn_vAddObjectToAllLists(tdoObjectName *p_oNewObjectName, short wInsertIndex = -1/*, CPA_List<CPA_BaseObject> *p_oReferencesList = NULL*/);
	BOOL				fn_bChangeNameListShareMode(unsigned long	ulIndex,
                                                    tdeShareMode	NewAttribute,
                                                    EdtList   *pModelList);
	BOOL				fn_bSetObjectInAllLists(unsigned long ulIndex,
												CPA_SaveObject *pObject);
	BOOL				fn_bSetObjectInModelListForSharedField(unsigned long ulIndex,
													CPA_SaveObject *pObject,EdtList
													*pModelList);
 
private:
	BOOL				fn_bUserWantsANewList();	/* function that asks to the user if he wants a new list to be created, when modifying a shared field.*/
	CPA_tdoNameList*	m_pNameList;				/* list of names*/
	CPA_List<EdtList>*	m_pListOfEdtLists;			/* list of EdtLists*/
    CString             fn_csConvertNameListTypeToEdtListType (CString csNameListType);
};
 
#endif /* __EDTLIST_HPP__*/
