/*=========================================================================
*
* CPAEditB.hpp		- CPA_EditorBase : definition
*
*
* Version			1.0
* Creation date		20.06.97
* Revision date
*
* Shaitan
*=======================================================================*/
 
#ifdef ACTIVE_EDITOR
 
#ifndef __EDITOR_BASE_HPP__
#define __EDITOR_BASE_HPP__
 
/****************************************/
#ifndef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else
#define CPA_EXPORT
#endif
#endif
/****************************************/
 
#include "CPASObj.hpp"
#include "CPAdList.hpp"
#include "FRMGest.hpp"
#include "CPAPopM.hpp"
 
#define C_szReferenceIniFile "CPAPath.ini"
 
class CPA_MainWorld;
class CPA_Interface;
 
class CPA_EditorBase;
class CPA_ObjectDLLBase;
class CPA_ModifiableObject;
 
/*=== OnModif ===*/
typedef enum
{
	C_EDTDo,
	C_EDTRedo,
	C_EDTUndo,
	C_EDTCancel
}
tdeTypeModif;
 
/*=== For BaseObjectList ===*/
typedef enum
{
	E_rc_ValidObjects,
	E_rc_InvalidObjects,
	E_rc_AllObjects
}
tdeResearchCriteria;
 
/*##########################################################################*/
/* Definition of a Context*/
typedef struct tdstEDTContext_
{
	CPA_EditorBase		*pPreviousEditor;
	BOOL				bCurrentEditor;
    FRMBase	*			m_aWinArray [FRM_C_MaxCol+2] [FRM_C_MaxRow+2];
}
tdstEDTContext;
 
/*##########################################################################*/
/* Definition of a Editor Info*/
typedef struct tdstEDTInfo_
{
	CString			csName;
	CString			csAuthor;
	CString			csVersion;
	CString			csFrenchHelpFile;
	CString			csEnglishHelpFile;
}
tdstEDTInfo;
 
/*=== update list ===*/
typedef enum
{
	C_EDTDelete,
	C_EDTInsert,
	C_EDTReinsert
}
tdeUpdate;
 
/*=== permissions ===*/
typedef enum
{
	C_Allow,
	C_Deny,
	C_CloseBefore
}
tdePermission;
 
/* Begin Mircea Dunka 31 August 1998 Editor Buttons on DialogBar*/
#define C_DlgBarMenuEditor		1
 
typedef enum {
    C_DlgBarCategoryEditor
} tde_DlgBarCategory;
 
typedef struct {
    HICON hIcon;
	char szToolTip[30];
	UINT uID;
} tds_DlgBarBtn;
 
/* End Mircea Dunka 31 August 1998 Editor Buttons on DialogBar*/
 
 
/*##########################################################################*/
/**/
 
class CPA_ModifNamesList : public CList<CString,CString>
{
private:
    CString m_csObjectTypeName;
public:
    CPA_ModifNamesList();
    ~CPA_ModifNamesList();
 
    void fn_vSetObjectTypeName          (const CString _csObjectTypeName)       { m_csObjectTypeName = _csObjectTypeName; }
    void fn_vRegisterModificationsType  (CString a_csTypeName[], long lTypeCount);
    CString fn_csGetObjectTypeName      (void)                                  { return m_csObjectTypeName; }
};
 
/*===========================================================================
*		Description:	Class CPA_EditorBase
*		Creation date:
*		Author:			Shaitan
*
*---------------------------------------------------------------------------
*
*---------------------------------------------------------------------------
*		Revision date:                        Author:
*=========================================================================*/
class CPA_EXPORT CPA_EditorBase
{
private:
	CPA_MainWorld	* m_p_oMainWorld;
	BOOL			  m_bIsCurrentEditor;
	tdstEDTInfo		  m_stEditorInfo;
	tdstEDTContext	  m_stContext;
protected:
	/* list of reachable objects*/
    CList<CPA_BaseObjectList*,CPA_BaseObjectList*> m_oListOfBaseObjectList;
    CList<CPA_BaseObjectList*,CPA_BaseObjectList*> m_oListOfInvalidObjectList;
 
    CPA_List<CPA_ModifNamesList>    m_oListOfModifications;
 
public:
	CPA_EditorBase (void);
	virtual ~CPA_EditorBase (void);
 
/*===========================================================================
	Information
=========================================================================*/
 
	tdstEDTInfo		* GetEditorInfo	(void)	{ return &m_stEditorInfo; }
    void              SetEditorInfo (CString csName, CString csAuthor, CString csVersion, CString csFrenchHelpFile, CString csEnglishHelpFile );
 
/*===========================================================================
	MainWorld
=========================================================================*/
 
	CPA_MainWorld	* GetMainWorld	(void)	{ return m_p_oMainWorld; }
	void			  SetMainWorld	(CPA_MainWorld *p_oMainWorld);
 
/*===========================================================================
	Interface
=========================================================================*/
 
	CPA_Interface	* GetInterface	(void);
 
/*===========================================================================
	Context
=========================================================================*/
 
	void fn_vSaveContext	(void);
	void fn_vRestoreContext	(void);
 
/*===========================================================================
	Current Editor
=========================================================================*/
 
	CString GetCurrentEditorName (void)				{ return m_stEditorInfo . csName; }
	BOOL	fn_bIsCurrentEditor  (void)				{ return m_bIsCurrentEditor; }
	void	SetCurrent			 (BOOL bIsCurrent)	{ m_bIsCurrentEditor = bIsCurrent; }
 
/*===========================================================================
	Messages
=========================================================================*/
/* focus*/
    virtual void fn_vHasLostFocus	(void) { };
    virtual BOOL fn_bHasGainedFocus	(void) { return TRUE; };
/* engine - editor*/
	virtual void fn_vBeforeEngine (void)	{ };
	virtual void fn_vBeforeEditor (void)	{ };
/* engine*/
    virtual BOOL fn_bAcceptToRunEngine		(void) { return TRUE; };
    virtual BOOL fn_bAcceptToRunTimerEngine	(void) { return TRUE; };
/* end appli*/
	virtual void fn_vJustBeforeClosing	(void) { };
	virtual BOOL fn_bAcceptToExit		(void) { return TRUE; };
/* save*/
    virtual BOOL fn_bAcceptToSave		(void) { return TRUE; }
	virtual void fn_vBeforeSaveAll      (void) { };
    virtual void fn_vAfterSaveAll       (void) { };
/* keys*/
	virtual BOOL _OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)	{ return FALSE; };
	virtual BOOL _OnKeyUp	(UINT nChar, UINT nRepCnt, UINT nFlags)	{ return FALSE; };
/* mouse*/
	virtual BOOL _OnMouseMove	  (UINT nFlags, tdstMousePos *p_stPos, MTH3D_tdstVector *p_stVect)	{ return FALSE; };
    virtual BOOL _OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)	{ return FALSE; };
    virtual BOOL _OnRButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)	{ return FALSE; };
    virtual BOOL _OnLButtonDown	  (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)	{ return FALSE; };
    virtual BOOL _OnRButtonDown	  (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)	{ return FALSE; };
    virtual BOOL _OnLButtonUp	  (UINT nFlags, tdstMousePos *p_stPos)	{ return FALSE; };
	virtual BOOL _OnRButtonUp	  (UINT nFlags, tdstMousePos *p_stPos)	{ return FALSE; };
/* command*/
	virtual BOOL _OnCommand			(UINT IDCmdMsg)				{ return FALSE; };
	virtual BOOL _OnUpdateCommandUI	(UINT uiID, CCmdUI *pCmdUI)	{ return FALSE; };
/* dragdrop*/
    virtual BOOL _OnDragDropEnd			(WPARAM wParam, LPARAM lParam)	{ return FALSE; };
    virtual BOOL _OnDragDropMove		(WPARAM wParam, LPARAM lParam)	{ return FALSE; };
    virtual BOOL _OnDragDropLooseFocus	(WPARAM wParam, LPARAM lParam)	{ return FALSE; };
    virtual BOOL _OnDragDropGainFocus	(WPARAM wParam, LPARAM lParam)	{ return FALSE; };
/* add objects to draw*/
	virtual void fn_vBeforeDrawingWorld(GLD_tdstViewportAttributes *p1, GLI_tdxHandleToLight p2, DEV_ViewPort* p3) { };
	virtual void fn_vAddObjectsToDraw	(GLD_tdstViewportAttributes *p1, GLI_tdxHandleToLight p2, DEV_ViewPort* p3)	{ };
	virtual void fn_vAddObjectsToDraw2	(GLD_tdstViewportAttributes *p1, GLI_tdxHandleToLight p2)	{ };
 
/*===========================================================================
	Reinit
=========================================================================*/
 
	virtual void fn_vOnChangeDevice (void)	{ };
	virtual void fn_vOnChangeWorld	(void)	{ };
	virtual void fn_vOnChangeRoot	(void)	{ };
 
/*===========================================================================
	Models
=========================================================================*/
 
	virtual BOOL fn_bCanDeleteThisModel	(CString csListName, CString csModelType, CString csModelName) { return TRUE; }
	virtual void fn_vOnAddModelToList	(CPA_ObjectDLLBase *pOwnerDLL, CString csListName, CString csModelName, tdeTypeModif eType) { }
 
/*===========================================================================
	for Dialog List
=========================================================================*/
 
	/* init & select*/
	virtual CPA_BaseObject  * GetDialogSelection		(CPA_DialogList *pDialog, CString csListName, tdeListDrawMode eDrawMode)	{ return NULL; };
	virtual CPA_BaseObject  * GetDialogParentSelection	(CPA_DialogList *pDialog, CString csListName)	{ return NULL; };
	virtual void			  GetListsForDialog			(CPA_DialogList *pDialog)	{ };
	virtual void			  fn_vInitDefaultParameters	(CPA_DialogList *pDialog);
 
	/* main controls*/
	virtual BOOL fn_bOnSelChangeComboList	(CPA_DialogList *pDialog, CString csListName)															{ return FALSE; };
	virtual BOOL fn_bOnButtonTest			(CPA_DialogList *pDialog, CString csListName, tdeListDrawMode eDraw)									{ return FALSE; };
 
	/* test*/
	virtual void fn_vSetANewTest			(CPA_DialogList *pDialog, CString csCurrentList)					{ };
	virtual BOOL fn_bTestFunction			(CString csCurrentType, CString csTestName, CPA_BaseObject *pEdObj)	{ return TRUE; };
	
	/* keys*/
	virtual BOOL fn_bOnKeyDownInDialog	(CPA_DialogList *pDialog, CString csListName, tdeListDrawMode eDraw,
										 CPA_BaseObject *pSelectedObject, UINT nChar, UINT nRepCnt, UINT nFlags)	{ return FALSE; }
	virtual BOOL fn_bOnKeyUpInDialog	(CPA_DialogList *pDialog, CString csListName, tdeListDrawMode eDraw,
										 CPA_BaseObject *pSelectedObject, UINT nChar, UINT nRepCnt, UINT nFlags)	{ return FALSE; }
 
	/* tree control*/
	virtual BOOL fn_bOnSelChangeHierarchyTree		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pSelectedObject, CPA_BaseObject *pSelectedParent)							{ return FALSE; };
	virtual BOOL fn_bOnDblClkHierarchyTree			(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pSelectedObject, CPA_BaseObject *pSelectedParent)							{ return FALSE; };
 
	virtual BOOL fn_bCanDragItemInHierarchyTree		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObjectToDrag)							{ return FALSE; };
	virtual BOOL fn_bCanDropItemInHierarchyTree		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObjectToDrop, CPA_BaseObject *pTarget)	{ return FALSE; };
	virtual BOOL fn_bOnDragDropInHierarchyTree		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject, CPA_BaseObject *pTarget)			{ return FALSE; };
 
	virtual CPA_BaseObject * GetTreeNodeNextChild	(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pParent, CPA_BaseObject *pCurrentChild);
	virtual void		   * GetInfoForTreeItem		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject, CPA_BaseObject *pParent) { return NULL; }
	virtual int				 GetIconForTreeItem		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject) { return 0; }
	virtual int				 GetStateForTreeItem	(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject) { return 0; }
	
	virtual BOOL	fn_bAddEntriesToTreePopup		(CPA_DialogList *pDialog, CString csListName, CMenu *pMenu, UINT uiCustomEntriesStart) { return FALSE; }
	virtual void	fn_vOnCommandInTreePopup		(CPA_DialogList *pDialog, CString csListName, UINT uiCustomEntry) {   }
 
	/* list control*/
	virtual BOOL fn_bOnSelChangeListObjects		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pSelectedObject, BOOL bUnselect)			{ return FALSE; };
	virtual BOOL fn_bOnDblClkListObjects		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pSelectedObject)							{ return FALSE; };
 
	virtual CString GetInfoForListItem			(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject) { return ""; }
	virtual int		GetIconForListItem			(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject) { return 0; }
	virtual int		GetStateForListItem			(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject) { return 0; }
 
	virtual BOOL	fn_bAddEntriesToListPopup	(CPA_DialogList *pDialog, CString csListName, CMenu *pMenu, UINT uiCustomEntriesStart) { return FALSE; }
	virtual void	fn_vOnCommandInListPopup	(CPA_DialogList *pDialog, CString csListName, UINT uiCustomEntry) {  }
 
	virtual BOOL	GetColorsForListItem		(CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject,
												 COLORREF *pRectColor, COLORREF *pTextColor) { return FALSE; }
 
 
/*===========================================================================
	for Sorted ListBox
=========================================================================*/
 
	virtual CString GetInfoForListItem	(CPA_SortedListBox *pListBox, CPA_BaseObjectList *pObjectList, CPA_BaseObject *pObject) { return ""; }
	virtual int		GetIconForListItem	(CPA_SortedListBox *pListBox, CPA_BaseObjectList *pObjectList, CPA_BaseObject *pObject) { return 0; }
	virtual int		GetStateForListItem	(CPA_SortedListBox *pListBox, CPA_BaseObjectList *pObjectList, CPA_BaseObject *pObject) { return 0; }
 
	virtual BOOL	fn_bAddEntriesToListPopup	(CPA_SortedListBox *pListBox, CPA_BaseObjectList *pObjectList, CMenu *pMenu, UINT uiCustomEntriesStart) { return FALSE; }
	virtual void	fn_vOnCommandInListPopup	(CPA_SortedListBox *pListBox, CPA_BaseObjectList *pObjectList, UINT uiCustomEntry) {  }
 
	virtual BOOL	GetColorsForListItem (CPA_SortedListBox *pListBox, CPA_BaseObjectList *pObjectList, CPA_BaseObject *pObject,
										  COLORREF *pRectColor, COLORREF *pTextColor) { return FALSE; }
 
/*===========================================================================
	for Hierarchy Tree
=========================================================================*/
 
	virtual CPA_BaseObject * GetTreeNodeNextChild	(CPA_HierarchyTree *pTreeCtrl, CPA_BaseObject *pRoot, CPA_BaseObject *pParent, CPA_BaseObject *pCurrentChild) { return NULL; }
	virtual void		   * GetInfoForTreeItem		(CPA_HierarchyTree *pTreeCtrl, CPA_BaseObject *pRoot, CPA_BaseObject *pObject, CPA_BaseObject *pParent) { return NULL; }
	virtual int				 GetIconForTreeItem		(CPA_HierarchyTree *pTreeCtrl, CPA_BaseObject *pRoot, CPA_BaseObject *pObject) { return 0; }
	virtual int				 GetStateForTreeItem	(CPA_HierarchyTree *pTreeCtrl, CPA_BaseObject *pRoot, CPA_BaseObject *pObject) { return 0; }
 
	virtual BOOL	fn_bAddEntriesToTreePopup	(CPA_HierarchyTree *pTreeCtrl, CPA_BaseObject *pRoot, CMenu *pMenu, UINT uiCustomEntriesStart) { return FALSE; }
	virtual void	fn_vOnCommandInTreePopup	(CPA_HierarchyTree *pTreeCtrl, CPA_BaseObject *pRoot, UINT uiCustomEntry) {   }
 
/*===========================================================================
	Current Editor
=========================================================================*/
 
	virtual tdePermission fn_eAcceptNewEditor	(CPA_EditorBase *pNewEditor)	 { return C_Allow; }
 
	virtual BOOL fn_bCanActivateEditor	(CPA_List<CPA_BaseObject> *pParams) { return !m_bIsCurrentEditor; }
	virtual void fn_vOnActivateEditor	(CPA_List<CPA_BaseObject> *pParams, BOOL bBackActivated=FALSE) { }
 
	virtual BOOL fn_bCanCloseEditor		(void)		{ return TRUE; }
	virtual void fn_vOnCloseEditor		(void)		{ }
 
	virtual void fn_vBackActiveMe			(void *pMyData) { };
	virtual void fn_vEraseWalkDataStructure (void *pMyData) { };
 
	virtual void fn_vUpdateEditor	(tdeModeChange eMode)	{ }
 
/*===========================================================================
	DialogBar - Mircea Dunka 31 aug 1998
=========================================================================*/
    virtual void fn_vDefineDlgBarBtnIcon (tde_DlgBarCategory wCategory, tds_DlgBarBtn *_pDlgBarBtn)	{ _pDlgBarBtn->hIcon = NULL; };
 
/*===========================================================================
	SubMenus and PopupMenu
=========================================================================*/
 
    virtual BOOL fn_bDefineSubMenu		(EDT_SubMenu *_p_oEDTSubMenu)	{ return FALSE; };
    virtual void _OnSubMenuCommand		(EDT_SubMenu *_p_oEDTSubMenu,UINT uiMsgID)	{ };
 
	virtual BOOL fn_bDefinePopupMenu	(EDT_PopUpMenu *pPopup, CPA_List<CPA_SuperObject> *pSelection, BOOL bAsCurrentEditor)	{ return FALSE; };
	virtual void _OnPopUpMenuCommand	(UINT m_IDCmdMsg)	{ };
 
/*===========================================================================
	Coherence
=========================================================================*/
 
	virtual BOOL fn_bOnInvalidateLink	(CPA_BaseObject *pOwner, CPA_BaseObject *pReferencedObject, BOOL bDestroyed) { return FALSE; }
	virtual void fn_vOnRestoreLink		(CPA_BaseObject *pOwner, CPA_BaseObject *pReferencedObject) { }
	virtual void fn_vOnModifyChild		(CPA_BaseObject *pOwner, CPA_BaseObject *pReferencedObject, unsigned long _ulData) { }
 
/*===========================================================================
	Draw Flag
=========================================================================*/
 
	virtual void fn_vOnModifDrawFlag (CPA_SuperObject *pSuperObject) { }
 
/*===========================================================================
	General Purpose
=========================================================================*/
 
    virtual long OnQueryAction	(CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };
    virtual long OnQueryInfos	(CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };
    virtual long OnQueryOpen	(CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };
    virtual long OnQueryClose	(CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };
 
/*===========================================================================
	Reachable Objects
=========================================================================*/
 
	virtual BOOL fn_bLoadBaseObject	(CPA_BaseObject *p_oObject) { return FALSE; }
 
	void fn_vRegisterObjectsType (CString a_csTypeName[], long lTypeCount);
 
    CPA_BaseObjectList * GetBaseObjectList		(CString csTypeName);
    CPA_BaseObjectList * GetInvalidObjectList	(CString csTypeName);
 
	BOOL fn_bAddObject		(CPA_BaseObject *p_oObject);
	BOOL fn_bRemoveObject	(CPA_BaseObject *p_oObject);
 
 	CPA_BaseObject * GetBaseObject		(CString csObjectName, CString csObjectType = "", CPA_BaseObject *p_oOwner = NO_CRITERIA, tdeResearchCriteria eCriteria = E_rc_ValidObjects);
 	CPA_BaseObject * GetBaseObject		(void *p_oEngineStruct, CString csObjectType = "", CPA_BaseObject *p_oOwner = NO_CRITERIA, tdeResearchCriteria eCriteria = E_rc_ValidObjects);
	long			 fn_lFindObjects	(CPA_List<CPA_BaseObject> *p_oList, CString csObjectName, CString csObjectType = "", CPA_BaseObject *p_oOwner = NO_CRITERIA, tdeResearchCriteria eCriteria = E_rc_ValidObjects);
 
    BOOL fn_bExist	(CPA_BaseObject *p_oObject, tdeResearchCriteria eCriteria = E_rc_ValidObjects);
	BOOL fn_bExist	(CString oObjectName, CString oObjectType = "", CPA_BaseObject *p_oOwner = NO_CRITERIA, tdeResearchCriteria eCriteria = E_rc_ValidObjects);
 
/*===========================================================================
    Modified Reachable Objects
=========================================================================*/
 
    void                            fn_vRegisterModificationsType   (const CString _csObjectTypeName, CString a_csModificationType[], long lTypeCount);
    CPA_ModifNamesList             *fn_p_oGetModifNamesList         (const CString _csObjectTypeName);
    CPA_List<CPA_ModifNamesList>   *fn_p_oGetAllModifNamesList      ()                          { return & m_oListOfModifications; }
    long                            fn_lFillWithModifiedObject      (CPA_List<CPA_ModifiableObject> *_p_oList, const CString _csObjectTypeName, const CString _csModifTypeName);
 
/*===========================================================================
	References
=========================================================================*/
 
	CString GetReferencePath (CString csEntry);
 
};
 
#endif /* __EDITOR_BASE_HPP__*/
#endif /* ACTIVE_EDITOR*/
