//=========================================================================
// FRMBSMN.cpp : implementation of the FRMBaseMenu class
// This is a part of the CPA project.
//
// Version                      1.0
// Creation date        11/12/96
// Revision date
//
// (c) Ubi Studios 1996
//
// DO NOT MODIFY THAT FILE. IF SOMETHING NEEDS TO BE CHANGE, PLEASE CONTACT
// VINCENT GRECO OR CHRISTOPHE BEAUDET.
//=========================================================================

#include "stdafx.h"
#include "acp_base.h"
#include "direct.h"
#include "itf/CPARes.h"
#include "errint.h"
#include "mmgint.h"
#include "itf/FRMBase.hpp"
#include "itf/FRMBsMn.hpp"
#include "itf/CPAProj.hpp"
#include "itf/A3dkeyal.hpp"
#include "itf/CustomID.h"
#include "itf/CPASubM.hpp"
#include "itf/CPAMWorl.hpp"
#include "itf/CPAKaCnf.hpp"
#include "itf/CoheMngr.hpp"
#include "itf/CPACont.hpp"
#include "itf/DEVSgl3D.hpp"
#include "itf/stddllid.h"
#include "itf/camdllb.hpp"
#include "itf/cpainter.hpp"
#include "itf/cpaspec.hpp"
#include "SaveMngr.h"
#include "itf/namemngr.hpp"
//nclude "SCR_Lib.h"

#ifdef ACTIVE_EDITOR

#define M_GetObjectDLLList()    (M_GetMainWorld()->GetListOfObjectDLLBase())
#define M_GetToolDLLList()      (M_GetMainWorld()->GetListOfToolDLLBase())
#define M_GetEditorList()       (M_GetMainWorld()->GetListOfEditorBase())
//
#define M_PosMenuFile       0
#define M_PosMenuEdit       1
#define M_PosMenuEditor     2
#define M_PosMenuTool       3
//ANNECY Shaitan NewInterface 24/03/98 {
#define M_PosMenu3DView     4
#define M_PosMenuSpecific   5
#define M_PosMenuPreference 6
//ENDANNECY Shaitan NewInterface }
#define M_PosMenuHelp       (m_oGeneralMenu.GetMenuItemCount() - 1)

#define M_IsGeneralSubMenu(pMenu,Pos)   ( (m_oGeneralMenu.GetSubMenu(Pos)) && (pMenu->m_hMenu == m_oGeneralMenu.GetSubMenu(Pos)->m_hMenu))

tdstEDTInfo g_stInterfaceInfo;



/////////////////////////////////////////////////////////////////////////////
// FRMBaseMenu

IMPLEMENT_DYNCREATE(FRMBaseMenu, FRMBase)

BEGIN_MESSAGE_MAP(FRMBaseMenu, FRMBase)
//{{AFX_MSG_MAP(FRMBaseMenu)
    ON_WM_CREATE()
    ON_WM_INITMENU()
    ON_WM_INITMENUPOPUP()
    ON_COMMAND(CPA_IDM_SAVEALL, OnSaveAll)
	ON_COMMAND(CPA_IDM_INITMAP, OnInitMap)
	ON_COMMAND(CPA_IDCB_UNDO, OnUndo)
	ON_COMMAND(CPA_IDCB_REDO, OnRedo)
	ON_COMMAND(CPA_IDCB_SAVEALL, OnSaveAll)
	ON_COMMAND(CPA_IDCB_OPTIONS, OnOptions)

    ON_WM_SYSCOMMAND()
    ON_WM_NCLBUTTONDBLCLK()
	ON_WM_DRAWITEM()
    ON_WM_ACTIVATE()

	ON_WM_ENTERMENULOOP()
	ON_WM_EXITMENULOOP()

	ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// FRMBaseMenu construction/destruction

FRMBaseMenu::FRMBaseMenu()
{
    //statement
    m_p_oEditSubMenu   = new EDT_SubMenu(C_SubMenuEdit,C_EditMenuIDStart);
    m_p_oEditorSubMenu = new EDT_SubMenu(C_SubMenuEditor,C_EditorMenuIDStart);
    m_p_oToolSubMenu   = new EDT_SubMenu(C_SubMenuTool,C_ToolMenuIDStart);
//ANNECY Shaitan NewInterface 24/03/98 {
    m_p_o3DViewSubMenu = new EDT_SubMenu(C_SubMenu3DView,C_3DViewMenuIDStart);
    m_p_oSpecificSubMenu = new EDT_SubMenu(C_SubMenuSpecific,C_SpecificMenuIDStart);
//ENDANNECY Shaitan NewInterface }
    m_p_oPrefSubMenu   = new EDT_SubMenu(C_SubMenuPreference,C_PrefMenuIDStart);
    m_bEnableEditors = FALSE;
    mbWantSplit = FALSE;
    mbWantNew = FALSE;
    mbWantTile = FALSE;
    mbWantClose = FALSE;

	g_stInterfaceInfo.csName = "Interface";
	g_stInterfaceInfo.csAuthor = "Chantal Oury";
	g_stInterfaceInfo.csVersion = "V 6.0.4   31/03/99";
	g_stInterfaceInfo.csFrenchHelpFile = "General.hlp";
	g_stInterfaceInfo.csEnglishHelpFile = "";

}

FRMBaseMenu::~FRMBaseMenu()
{
    //statement
    delete m_p_oEditSubMenu;
    delete m_p_oEditorSubMenu;
    delete m_p_oToolSubMenu;
//ANNECY Shaitan NewInterface 24/03/98 {
    delete m_p_o3DViewSubMenu;
    delete m_p_oSpecificSubMenu;
//ENDANNECY Shaitan NewInterface }
    delete m_p_oPrefSubMenu;
}

void FRMBaseMenu::OnActivate(UINT State, CWnd *pOther, BOOL bMini)
{
	if(pOther == NULL)
	{
		g_oBaseFrame.OnActivate(State, pOther, bMini);
		if(State != WA_INACTIVE)
			g_oBaseFrame.BringWindowToTop();
	}
	else
		CFrameWnd::OnActivate(State, pOther, bMini);
}

////
CPA_Interface * FRMBaseMenu::GetInterface (void)
{
	return GetMultiDevice()->GetInterface();
}

////
BOOL FRMBaseMenu::CreateBase
(
    LPCTSTR _lpStr, 
    int, 
    int, 
    CPA_MainWorld* _p_oMainWorld
)
{
	BOOL Ret;
    CCreateContext  stContext;
    stContext.m_pNewViewClass = RUNTIME_CLASS(DEV_MultiDevice3D);
	stContext.m_pCurrentDoc = M_GetMainWnd()->GetActiveView()->GetDocument();
    Ret = FRMBase::CreateBase(_lpStr, 2, 2, _p_oMainWorld, &stContext);
	SetParent(&g_oBaseFrame);
	return Ret;
}

////
BOOL FRMBaseMenu::CreateBase(LPCTSTR _lpStr, CPA_MainWorld* _p_oMainWorld)
{
	BOOL Ret;
    CCreateContext  stContext;
    stContext.m_pNewViewClass = RUNTIME_CLASS(DEV_MultiDevice3D);
	stContext.m_pCurrentDoc = M_GetMainWnd()->GetActiveView()->GetDocument();
    Ret = FRMBase::CreateBase(_lpStr, 2, 2, _p_oMainWorld, &stContext);
	SetParent(&g_oBaseFrame);
	return Ret;
}

////
typedef struct tdstUpdateStat_
{
	char	a_szText[500];
	int		iType;
} tdstUpdateStat;
tdstUpdateStat g_a_UpdateStat[20];

afx_msg void FRMBaseMenu::OnDrawItem(int nID, LPDRAWITEMSTRUCT pSt)
{
	if(*g_a_UpdateStat[pSt->itemID].a_szText)
	{
		CDC		*pDC = m_oStatusBar.GetDC();
		CBrush	oBrush;
		CRect	oRect;
		CFont	xFnt, *xFntPrev = NULL;
		PLOGFONT plf = (PLOGFONT) LocalAlloc(LPTR, sizeof(LOGFONT));

		lstrcpy(plf->lfFaceName, "Arial");
		plf->lfWeight = (g_a_UpdateStat[pSt->itemID].iType == C_STATUS_NORMAL) ? FW_NORMAL : FW_BOLD;
		plf->lfHeight = 15;
		plf->lfEscapement = 0;

		if (xFnt.CreateFontIndirect(plf))
			xFntPrev = pDC->SelectObject(&xFnt);

		switch(g_a_UpdateStat[pSt->itemID].iType)
		{
		case C_STATUS_NORMAL:
			pDC->SetTextColor(RGB(0, 0, 0));
			oBrush.CreateSolidBrush(RGB(200, 200, 200));
			break;
		case C_STATUS_WARNING:
			pDC->SetTextColor(RGB(255, 255, 255));
			oBrush.CreateSolidBrush(RGB(0, 0, 100));
			break;
		case C_STATUS_ERROR:
			pDC->SetTextColor(RGB(255, 255, 255));
			oBrush.CreateSolidBrush(RGB(100, 0, 0));
			break;
		}

		pDC->SetBkMode(TRANSPARENT);
		pDC->FillRect(&pSt->rcItem, &oBrush);

		oRect.left = pSt->rcItem.left + 5;
		oRect.top = pSt->rcItem.top - 1;
		oRect.right = pSt->rcItem.right;
		oRect.bottom = pSt->rcItem.bottom;

		pDC->DrawText(g_a_UpdateStat[pSt->itemID].a_szText, strlen(g_a_UpdateStat[pSt->itemID].a_szText), &oRect, DT_LEFT|DT_TOP|DT_EXTERNALLEADING);

		if ( xFntPrev )
		{
			pDC->SelectObject(xFntPrev);
			xFnt.DeleteObject();
		}
		//do not forget to free the memory for the font
		LocalFree(plf);

		// do not forget to release the Device context !!!
		m_oStatusBar . ReleaseDC (pDC);
	}
}

void FRMBaseMenu::UpdateStatus(char *_p_szString, int _iPane, int _iType)
{
	CStatusBarCtrl &Stat = m_oStatusBar.GetStatusBarCtrl();
	BOOL bCanDisplay = ::IsWindow(Stat.m_hWnd);

/*	if(_iType == C_STATUS_NORMAL)
		Stat.SetText(_p_szString, _iPane, 0);
	else
	{
*/		if(_p_szString)
		{
			strcpy(g_a_UpdateStat[_iPane].a_szText, _p_szString);
			g_a_UpdateStat[_iPane].iType = _iType;
		}
		else
			*g_a_UpdateStat[_iPane].a_szText = '\0';
		if ( bCanDisplay )
			Stat.SetText(_p_szString, _iPane, SBT_OWNERDRAW);
//	}
	if((_iType == C_STATUS_ERROR) && (_p_szString) && (*_p_szString))
		::Beep(100, 250);

	if ( bCanDisplay )
		Stat.UpdateWindow();
}

BOOL FRMBaseMenu::fn_bCanClose(void)
{
	//  Ask DLLs if it's ok to close 
	if (M_GetListOfAllDLL()->CallAcceptToExit() == FALSE)
		return FALSE;

	// They are some datas not saved ?
	if(SCR_g_st_Ntfy_Array.uiNumValues)
	{
		if(MessageBox("Some datas have not been saved. Exit anyway ?", NULL, MB_ICONQUESTION|MB_YESNO) == IDNO)
			return FALSE;
	}

	// We can close
	return TRUE;	
}

int FRMBaseMenu::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	//
	// Create status bar (from MFC to avoid size box)
	//
	ModifyStyle(WS_THICKFRAME, 0);
	m_oStatusBar.Create(this, WS_CHILD | CBRS_BOTTOM);
	ModifyStyle(0, WS_THICKFRAME);

	UINT ar[2] = {CPA_IDR_MAINFRAME, CPA_IDR_MAINFRAME};
	m_oStatusBar.SetIndicators(ar, 2);
	m_oStatusBar.SetPaneInfo(0, CPA_IDR_MAINFRAME, SBPS_NORMAL, 170);
	m_oStatusBar.SetPaneInfo(1, CPA_IDR_MAINFRAME, SBPS_NOBORDERS|SBPS_STRETCH, 0);
	UpdateStatus(NULL, 0, C_STATUS_NORMAL);
	UpdateStatus(NULL, 1, C_STATUS_NORMAL);

	//
	// Create general tool bar. By default, init and hide. 
	// 
	if (!m_oGeneralDialogBar.Create(this, CPA_IDD_GENERALDIALOGBAR, CBRS_ALIGN_TOP, 5000)) 
	{
		TRACE0("Failed to create dialog bar m_oGeneralDialogBar\n");
		return -1;              
	}
	
	m_oGeneralMenu.LoadMenu(CPA_IDM_GENERALMENU);

	return 0;
}

////
void FRMBaseMenu::OnNcLButtonDblClk(UINT nID, CPoint point)
{
    if(M_bEditorsActive())
        return;
    CFrameWnd::OnNcLButtonDblClk(nID, point);
}

////
void FRMBaseMenu::OnSysCommand(UINT nID, LPARAM lParam)
{
    if(M_bEditorsActive())
	{
		if ( 
				(nID == SC_CLOSE) ||
				(nID == SC_MAXIMIZE) ||
				(nID == SC_MINIMIZE) ||
				(nID == SC_RESTORE)
			)
			return;
	}
    CFrameWnd::OnSysCommand(nID, lParam);
}

////
void FRMBaseMenu::fn_vOnActivate(void)
{
    m_p_oMainWorld->fn_vSetCurrentFRMBaseMenu(this);
}

////
void FRMBaseMenu::fn_vInitGeneralMenuWithContext(void)
{
    UINT uiSTATE;

    uiSTATE = M_bEditorsActive() ? MF_BYPOSITION|MF_ENABLED : MF_BYPOSITION|MF_GRAYED;

	m_oGeneralMenu.EnableMenuItem(M_PosMenuFile, uiSTATE);
	m_oGeneralMenu.EnableMenuItem(M_PosMenuEdit, uiSTATE);
	m_oGeneralMenu.EnableMenuItem(M_PosMenuEditor, uiSTATE);
	m_oGeneralMenu.EnableMenuItem(M_PosMenuTool, uiSTATE);
//ANNECY Shaitan NewInterface 24/03/98 {
	m_oGeneralMenu.EnableMenuItem(M_PosMenu3DView, uiSTATE);
	m_oGeneralMenu.EnableMenuItem(M_PosMenuSpecific, uiSTATE);
//ENDANNECY Shaitan NewInterface }
	m_oGeneralMenu.EnableMenuItem(M_PosMenuPreference, uiSTATE);
	m_oGeneralMenu.EnableMenuItem(M_PosMenuHelp, uiSTATE);
}

////
void FRMBaseMenu::OnUndo(void)
{
    M_GetEditManager()->Undo();
	fn_vInitGeneralDialogBarWithContext();
}
void FRMBaseMenu::OnRedo(void)
{
    M_GetEditManager()->Redo();
	fn_vInitGeneralDialogBarWithContext();
}

BOOL FRMBaseMenu::OnCommand(WPARAM _wParam, LPARAM _lParam)
{
    UINT			IDCmdMsg = LOWORD(_wParam);
	UINT			IDRealCmdMsg;
	CPA_EditorBase	*pOwner;	

////////////////////
//Begin Mircea Dunka 31 Aug 1998 - DialogBar interface (no notify!)
	UINT			IDNotifyMsg = HIWORD(_wParam);
	if(IDNotifyMsg != 0)
		return TRUE;
	// Editor buttons
	if ((IDCmdMsg >=  C_EditorButtonIDStart) &&
        (IDCmdMsg <	C_EditorButtonIDEnd))
    {
		//I have to re-initialize the "editors" menu in order to use the buttons :)
		m_p_oEditorSubMenu->Clear();
		// call Hierarchy Editor
		M_GetEditor()->fn_bDefineSubMenu(m_p_oEditorSubMenu);
		// call Objects DLLs
		AddItemToPopupMenu(m_p_oEditorSubMenu,(CPA_List<CPA_DLLBase>*)M_GetObjectDLLList());
		// call Tool DLLs
		AddItemToPopupMenu(m_p_oEditorSubMenu,(CPA_List<CPA_DLLBase>*)M_GetToolDLLList());

		//send the same command as the corresponding menu item
		IDCmdMsg = IDCmdMsg - C_EditorButtonIDStart + C_EditorMenuIDStart;
        m_p_oEditorSubMenu->_OnCommand(IDCmdMsg);
		return TRUE;
	}
//end Mircea Dunka 31 Aug 1998 - DialogBar interface

	
	// Edit PopupMenu
	if ((IDCmdMsg >= C_EditMenuIDStart) &&
        (IDCmdMsg <  C_EditMenuIDEnd))
    {
        // undo
		if (IDCmdMsg == C_EditMenuIDUndo )
		{
            M_GetEditManager()->Undo();
			fn_vInitGeneralDialogBarWithContext();
		}
        // redo
		else if (IDCmdMsg == C_EditMenuIDRedo )
		{
            M_GetEditManager()->Redo();
			fn_vInitGeneralDialogBarWithContext();
		}
//ANNECY Shaitan NewInterface 24/03/98 {
 		// Interface commands
		else if ((m_p_oEditSubMenu->fn_bFindCmdID(IDCmdMsg,&pOwner,&IDRealCmdMsg))&&(pOwner == NULL))
			GetInterface()->_OnSubMenuCommand(m_p_oEditSubMenu, IDRealCmdMsg);
        // custom commands
		else
//ENDANNECY Shaitan NewInterface }
           m_p_oEditSubMenu->_OnCommand(IDCmdMsg);
		// message processed
		return TRUE;
    }

    // Editor PopupMenu
	if ((IDCmdMsg >= C_EditorMenuIDStart) &&
        (IDCmdMsg < C_EditorMenuIDEnd))
	{
        m_p_oEditorSubMenu->_OnCommand(IDCmdMsg);
		return TRUE;
	}

	// Tools PopupMenu
	if ((IDCmdMsg >= C_ToolMenuIDStart) &&
        (IDCmdMsg < C_ToolMenuIDEnd))
    {
//ANNECY Shaitan NewInterface 24/03/98 {
		// Interface commands
		if ((m_p_oToolSubMenu->fn_bFindCmdID(IDCmdMsg,&pOwner,&IDRealCmdMsg))&&(pOwner == NULL))
			GetInterface()->_OnSubMenuCommand(m_p_oToolSubMenu, IDRealCmdMsg);
		// Editors commands
		else
//ENDANNECY Shaitan NewInterface }
			m_p_oToolSubMenu->_OnCommand(IDCmdMsg);
		
		return TRUE;
    }

//ANNECY Shaitan NewInterface 24/03/98 {
	// Load PopupMenu
	/*
	if ((IDCmdMsg >= C_LoadMenuIDStart) &&
        (IDCmdMsg < C_LoadMenuIDEnd))
    {
        m_p_oLoadSubMenu->_OnCommand(IDCmdMsg);
		return TRUE;
    }
	*/
	// 3DView PopupMenu
	if ((IDCmdMsg >= C_3DViewMenuIDStart) &&
        (IDCmdMsg < C_3DViewMenuIDEnd))
    {
		// Interface commands
		if ((m_p_o3DViewSubMenu->fn_bFindCmdID(IDCmdMsg,&pOwner,&IDRealCmdMsg))&&(pOwner == NULL))
			GetInterface()->_OnSubMenuCommand(m_p_o3DViewSubMenu, IDRealCmdMsg);
		// Editors commands
        else
			m_p_o3DViewSubMenu->_OnCommand(IDCmdMsg);
		return TRUE;
    }

	// Specific PopupMenu
	if ((IDCmdMsg >= C_SpecificMenuIDStart) &&
        (IDCmdMsg < C_SpecificMenuIDEnd))
    {
		m_p_oSpecificSubMenu->_OnCommand(IDCmdMsg);
		return TRUE;
    }

//ENDANNECY Shaitan NewInterface }

	// Preferences PopupMenu
	if ((IDCmdMsg >= C_PrefMenuIDStart) &&
        (IDCmdMsg < C_PrefMenuIDEnd))
    {
        // undo
		if (IDCmdMsg == C_PrefMenuIDStart )
            GetInterface()->fn_vSaveDisplayMode();
		else
			m_p_oPrefSubMenu->_OnCommand(IDCmdMsg);
		return TRUE;
    }

    // Help PopupMenu
	if ((IDCmdMsg >= C_HelpMenuIDStart) &&
        (IDCmdMsg < C_HelpMenuIDEnd))
    {
        fn_vActivateHelp(IDCmdMsg);
        return TRUE;
    }

    // send message to contact
	if ((GetMultiDevice())&&(GetMultiDevice()->GetContact()))
		GetMultiDevice()->GetContact()->_OnCommand(IDCmdMsg);

	// default handling
	return FRMBase::OnCommand(_wParam,_lParam);
}

////
void FRMBaseMenu::OnInitMenu(CMenu *_pMenu)
{
	CFrameWnd::OnInitMenu(_pMenu);
}


////
void FRMBaseMenu::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
	if( M_IsGeneralSubMenu(pPopupMenu,nIndex) )
    {
        CString			oEntryName;

        switch(nIndex)
        {
        case M_PosMenuEdit:
            m_p_oEditSubMenu->Clear();
            // add Undo entry
            oEntryName = M_GetEditManager()->GetUndoName();
            oEntryName += "\t";
            oEntryName += M_GetMainApp()->mp_oAppKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Undo"));
            m_p_oEditSubMenu->AddAnEntry((CPA_DLLBase*)NULL,(char*)(LPCTSTR)oEntryName,0,FALSE,M_GetEditManager()->CanUndo());
            // add Redo entry
            oEntryName = M_GetEditManager()->GetRedoName();
            oEntryName += "\t";
            oEntryName += M_GetMainApp()->mp_oAppKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Redo"));
            m_p_oEditSubMenu->AddAnEntry((CPA_DLLBase*)NULL,(char*)(LPCTSTR)oEntryName,0,FALSE,M_GetEditManager()->CanRedo());
            m_p_oEditSubMenu->AddASeparator();
//ANNECY Shaitan NewInterface 24/03/98 {
			// interface
			GetInterface()->fn_bDefineSubMenu(m_p_oEditSubMenu);
            // Call  Hierarchy Editor
            M_GetEditor()->fn_bDefineSubMenu(m_p_oEditSubMenu);
//ENDANNECY Shaitan NewInterface }
			// Build menu
            m_p_oEditSubMenu->Build(pPopupMenu);
            break;
  
		case M_PosMenuEditor:
            m_p_oEditorSubMenu->Clear();
            // call Hierarchy Editor
			M_GetEditor()->fn_bDefineSubMenu(m_p_oEditorSubMenu);
            m_p_oEditorSubMenu->AddASeparator();   
			// call Objects DLLs
			if( !AddItemToPopupMenu(m_p_oEditorSubMenu,(CPA_List<CPA_DLLBase>*)M_GetObjectDLLList()) )
                m_p_oEditorSubMenu->AddAnEntry((CPA_DLLBase*)NULL, "No object editor", 0, FALSE, FALSE);
            m_p_oEditorSubMenu->AddASeparator();   
			// call Tool DLLs
            if( !AddItemToPopupMenu(m_p_oEditorSubMenu,(CPA_List<CPA_DLLBase>*)M_GetToolDLLList()) )
                m_p_oEditorSubMenu->AddAnEntry((CPA_DLLBase*)NULL, "No tool editor", 0, FALSE, FALSE);
            m_p_oEditorSubMenu->Build(pPopupMenu);
            break;
 
		case M_PosMenuTool:
            m_p_oToolSubMenu->Clear();
//ANNECY Shaitan NewInterface 24/03/98 {
			// load submenu
			m_p_oLoadSubMenu = m_p_oToolSubMenu->fn_p_oGetNewSubMenu("Load",C_SubMenuLoad);
			// objects DLLs
			AddItemToPopupMenu(m_p_oLoadSubMenu,(CPA_List<CPA_DLLBase>*)M_GetObjectDLLList());
             // tool DLLs
			AddItemToPopupMenu(m_p_oLoadSubMenu,(CPA_List<CPA_DLLBase>*)M_GetToolDLLList());
			m_p_oToolSubMenu->AddASubMenu(m_p_oLoadSubMenu);
            // objects DLLs
			AddItemToPopupMenu(m_p_oToolSubMenu,(CPA_List<CPA_DLLBase>*)M_GetObjectDLLList());
             // tool DLLs
			AddItemToPopupMenu(m_p_oToolSubMenu,(CPA_List<CPA_DLLBase>*)M_GetToolDLLList());
			// interface entries
			GetInterface()->fn_bDefineSubMenu(m_p_oToolSubMenu);
            m_p_oToolSubMenu->Build(pPopupMenu);
            break;
 
		case M_PosMenu3DView:
            m_p_o3DViewSubMenu->Clear();
            // objects DLLs
			AddItemToPopupMenu(m_p_o3DViewSubMenu,(CPA_List<CPA_DLLBase>*)M_GetObjectDLLList());
             // tool DLLs
			AddItemToPopupMenu(m_p_o3DViewSubMenu,(CPA_List<CPA_DLLBase>*)M_GetToolDLLList());
			m_p_o3DViewSubMenu->AddASeparator();
			// hierarchy editor
			M_GetEditor()->fn_bDefineSubMenu(m_p_o3DViewSubMenu);
			// interface
			GetInterface()->fn_bDefineSubMenu(m_p_o3DViewSubMenu);

            m_p_o3DViewSubMenu->Build(pPopupMenu);
            break;
 
		case M_PosMenuSpecific:
            m_p_oSpecificSubMenu->Clear();
			// only current editor
			if (!M_GetCurrentEditor()->fn_bDefineSubMenu(m_p_oSpecificSubMenu))
                m_p_oSpecificSubMenu->AddAnEntry((CPA_DLLBase*)NULL, "No Specific Entry", 0, FALSE, FALSE);
			m_p_oSpecificSubMenu->Build(pPopupMenu);
			break;
//ENDANNECY Shaitan NewInterface }
 
        case M_PosMenuPreference:
			m_p_oPrefSubMenu->Clear();
            // add preference entry
            m_p_oPrefSubMenu->AddAnEntry((CPA_DLLBase*)NULL, "Save Display Mode", 0, FALSE, TRUE);
            m_p_oPrefSubMenu->AddASeparator();   
			// call current editor
			if (!M_GetCurrentEditor()->fn_bDefineSubMenu(m_p_oPrefSubMenu))
                m_p_oPrefSubMenu->AddAnEntry((CPA_DLLBase*)NULL, "No Preferences", 0, FALSE, FALSE);
			m_p_oPrefSubMenu->Build(pPopupMenu);
			break;

/*		case M_PosMenuOption:
			if (M_GetEditor()->GetSpecificEditor()->GetDisplayMode() == E_dm_DrawWorld)
			{
				m_oGeneralMenu.GetSubMenu(M_PosMenuOption)->CheckMenuItem(CPA_IDCB_DISPLAYWORLD, MF_BYCOMMAND|MF_CHECKED);
				m_oGeneralMenu.GetSubMenu(M_PosMenuOption)->CheckMenuItem(CPA_IDCB_DISPLAYSECTOR, MF_BYCOMMAND|MF_UNCHECKED);
			}
			else
			{
				m_oGeneralMenu.GetSubMenu(M_PosMenuOption)->CheckMenuItem(CPA_IDCB_DISPLAYWORLD, MF_BYCOMMAND|MF_UNCHECKED);
				m_oGeneralMenu.GetSubMenu(M_PosMenuOption)->CheckMenuItem(CPA_IDCB_DISPLAYSECTOR, MF_BYCOMMAND|MF_CHECKED);
			}
			CFrameWnd::OnInitMenuPopup(pPopupMenu,nIndex,bSysMenu);
			break;
*/			
		default:
            if( nIndex == M_PosMenuHelp )   // M_PosMenuHelp not constant
                fn_vFillHelpMenu(pPopupMenu);
            else
			{
				CFrameWnd::OnInitMenuPopup(pPopupMenu,nIndex,bSysMenu);
			}

        }
    }
}

////
BOOL FRMBaseMenu::AddItemToPopupMenu(EDT_SubMenu* _pSubMenu,CPA_List<CPA_DLLBase>* _p_oListOfDLL)
{
    BOOL bAddEntries = FALSE;

    POSITION stPos = _p_oListOfDLL->GetHeadPosition();
    while(stPos)
    {
        CPA_DLLBase *p_oDLL = _p_oListOfDLL->GetNext(stPos);
        bAddEntries |= p_oDLL->fn_bDefineSubMenu(_pSubMenu);
    }
    return bAddEntries;
}

////
void FRMBaseMenu::fn_vFillHelpMenu(CMenu *pPopupMenu)
{
    // delete menu
    while( pPopupMenu -> GetMenuItemCount() )
        pPopupMenu -> DeleteMenu( 0, MF_BYPOSITION );

    // add entries
    UINT uiID = C_HelpMenuIDStart ;
    // add about...
    pPopupMenu -> AppendMenu( MF_STRING, uiID++, "About..." );
    pPopupMenu -> AppendMenu( MF_SEPARATOR );
	// add interface help
	UINT nFlags = MF_STRING + ( (g_stInterfaceInfo.csFrenchHelpFile.IsEmpty() &&  g_stInterfaceInfo.csEnglishHelpFile.IsEmpty() ) ? MF_GRAYED : MF_ENABLED );
	pPopupMenu -> AppendMenu( nFlags, uiID++, g_stInterfaceInfo.csName );
    // add context help
    POSITION stPos = M_GetEditorList() -> GetHeadPosition();
    while( stPos )
    {
        tdstEDTInfo *p_stInfo = M_GetEditorList() -> GetNext( stPos ) -> GetEditorInfo();
        UINT nFlags = MF_STRING + ( ( p_stInfo -> csFrenchHelpFile . IsEmpty() && p_stInfo -> csEnglishHelpFile . IsEmpty()) ? MF_GRAYED : MF_ENABLED );
        pPopupMenu -> AppendMenu( nFlags, uiID++, p_stInfo -> csName );
    }
}

////
void FRMBaseMenu::fn_vActivateHelp(UINT IDCmdMsg)
{
    if( IDCmdMsg == C_HelpMenuIDStart )
    {
        // About entry
        M_GetMainApp() -> OnHelpAbout();
    }
	else 
	{
        tdstEDTInfo *p_stInfo;
		CString		csHelpFile;
		
		if (IDCmdMsg == C_HelpMenuIDStart + 1)
			p_stInfo = &g_stInterfaceInfo;
		else
		{
			int iNumEditor = IDCmdMsg - C_HelpMenuIDStart - 2;
			POSITION stPos = M_GetEditorList() -> FindIndex( iNumEditor );
			CPA_EditorBase *p_oEditor = M_GetEditorList() -> GetAt( stPos );
			
			p_stInfo = p_oEditor -> GetEditorInfo();
		}

		if ((GetInterface()->fn_csGetCurrentLanguage() == "French") || (GetInterface()->fn_csGetCurrentLanguage() == "Francais"))
		{
			if (!p_stInfo->csFrenchHelpFile.IsEmpty())
				csHelpFile = CString(M_GetMainApp() -> m_csEditorDataPath) + "EditorHelp\\French\\" + p_stInfo -> csFrenchHelpFile;
			else
				csHelpFile = CString(M_GetMainApp() -> m_csEditorDataPath) + "EditorHelp\\English\\" + p_stInfo -> csEnglishHelpFile;
		}
		else
		{
			if (!p_stInfo->csEnglishHelpFile.IsEmpty())
				csHelpFile = CString(M_GetMainApp() -> m_csEditorDataPath) + "EditorHelp\\English\\" + p_stInfo -> csEnglishHelpFile;
			else
				csHelpFile = CString(M_GetMainApp() -> m_csEditorDataPath) + "EditorHelp\\French\\" + p_stInfo -> csFrenchHelpFile;
		}

        ::WinHelp( M_GetMainWnd()->m_hWnd, csHelpFile, HELP_FINDER, 0 );
	}
}

////
void FRMBaseMenu::OnInitMap(void)
{
	M_GetListOfAllDLL()->CallBeforeEngine();
	M_GetMainApp()->fn_vReinitCurrentMap();
	GetInterface()->SetInitialState(TRUE);
	M_GetListOfAllDLL()->CallBeforeEditor();
}

////-------------------
// Call to options
////-------------------
void FRMBaseMenu::OnOptions(void)
{
	GetInterface()->fn_vDoDialogOptions();
}

////-------------------
// Call to save
////-------------------
void FRMBaseMenu::OnSaveAll(void)
{
	POSITION stPos;

	SetCursor(M_GetMainApp()->LoadStandardCursor(IDC_WAIT));

	//////////////////////////////
	// Generate modification file
	//////////////////////////////
/*
	{
		unsigned int				uiPos;
		SCR_tdst_Ntfy_Description	*p_stNtfy;
		FILE						*p_xFile;
		char						szMdfName[MAX_PATH];
		char						*p_szNotfy;

		// Compute modification file name (last and new)
		strcpy(szMdfName, (LPCTSTR) M_GetMainApp()->m_csEngineDataPath);
		if(szMdfName[strlen(szMdfName) - 1] != '\\')
			strcat(szMdfName, "\\");
		strcat(szMdfName, "modiflst.txt");

		// Append modification list
		p_xFile = fopen(szMdfName, "at");
		if(p_xFile == NULL)
		{
			SetCursor(M_GetMainApp()->LoadStandardCursor(IDC_ARROW));
			MessageBox("Unable to create modification file.");
			return;
		}

		uiPos = 0;
		SCR_M_DyAr_GetNextElement(SCR_tdst_Ntfy_Description, uiPos, p_stNtfy, SCR_g_st_Ntfy_Array);
		while(p_stNtfy)
		{
			p_szNotfy = strchr(p_stNtfy->a_szSectionName, '\\') + 1;
			fputs(p_szNotfy, p_xFile);
			fputc('\n', p_xFile);
			uiPos++;
			SCR_M_DyAr_GetNextElement(SCR_tdst_Ntfy_Description, uiPos, p_stNtfy, SCR_g_st_Ntfy_Array);
		}
		fclose(p_xFile);
	}
	*/

	// call fn_bAcceptToSave msg
	stPos = M_GetEditorList() -> GetHeadPosition();
	while( stPos )
	{
		if (!M_GetEditorList() -> GetNext( stPos ) -> fn_bAcceptToSave())
		{
			SetCursor(M_GetMainApp()->LoadStandardCursor(IDC_ARROW));
			return;
		}
	}

	// call fn_vBeforeSaveAll msg
	stPos = M_GetEditorList() -> GetHeadPosition();
	while( stPos )
	{
		M_GetEditorList() -> GetNext( stPos ) -> fn_vBeforeSaveAll();
	}

	// call saving
	if (GetInterface()->GetNbObjectsRenamed() != 0)
	{
		g_oNameManager.fn_vWriteNameConflicts();
		UpdateStatus("Objects were renamed during loading : your changes cannot be saved", C_STATUSPANE_INFOS, C_STATUS_ERROR);
		MessageBox ("Objects were renamed during loading : \nyour changes in all editors cannot be saved", "PROBLEM !", MB_OK|MB_ICONEXCLAMATION);
		SetCursor(M_GetMainApp()->LoadStandardCursor(IDC_ARROW));
		return;
	}

	/*
	 * save in a directory all file that will be modified
	 * in order to be able to recuperate data that currently work
	*/
	if ( !SAVE_fn_bGenerateACopyOfFilesBeforeModification( ) )
	{
		UpdateStatus("Save canceled", C_STATUSPANE_INFOS, C_STATUS_ERROR);
		SetCursor(M_GetMainApp()->LoadStandardCursor(IDC_ARROW));
		return;
	}


	// save
	SCR_fn_v_SvL1_UpdateAllNotify();

	// call fn_vAfterSaveAll msg
	stPos = M_GetEditorList() -> GetHeadPosition();
	while( stPos )
	{
		M_GetEditorList() -> GetNext( stPos ) -> fn_vAfterSaveAll();
	}

	// RAZ Undos
	M_GetEditManager()->Reset();
	fn_vInitGeneralDialogBarWithContext();
	// warn user
	UpdateStatus("Save complete", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
	SetCursor(M_GetMainApp()->LoadStandardCursor(IDC_ARROW));
}

////
void FRMBaseMenu::fn_vUpdateCurrentEditor (CPA_EditorBase *pNewCurrentEditor)
{	
	if(pNewCurrentEditor)
	{	
		UpdateStatus((char *) (LPCTSTR) (pNewCurrentEditor->GetCurrentEditorName()), C_STATUSPANE_EDITOR, C_STATUS_NORMAL);
		//  Dunka 17.09.1998 - update tool bar (the editor buttons)
		fn_vUpdateEditorButtonsToolbar();
		//end Mircea Dunka 17.09.1998 - update tool bar (the editor buttons)
	}

	else
		UpdateStatus(NULL, C_STATUSPANE_EDITOR, C_STATUS_NORMAL);
}


//===========================================================================
//      Description:    Init dialog bar regardless to context of application.
//                      => Combo box will contain all editors that can be current
//                      one.
//      Creation date:  11 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void FRMBaseMenu::fn_vInitGeneralDialogBarWithContext(void)
{
	CButton				*pBut;

	// For engine
	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SWAPTOEDITORS);
	pBut->SetCheck(0);
	pBut->ShowWindow(SW_HIDE);
    pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_PAUSEENGINE);
	pBut->SetCheck(0);
	pBut->ShowWindow(SW_HIDE);
	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_ONESTEPENGINE);
	pBut->SetCheck(0);
	pBut->ShowWindow(SW_HIDE);
	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULLSCREEN);
	pBut->SetCheck(0);
	pBut->ShowWindow(SW_HIDE);

	// Undo/Redo
	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_UNDO);
	pBut->SetCheck(0);
	pBut->ShowWindow(SW_SHOW);
	pBut->EnableWindow(M_GetEditManager()->CanUndo() ? TRUE : FALSE);

	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_REDO);
	pBut->SetCheck(0);
	pBut->ShowWindow(SW_SHOW);
	pBut->EnableWindow(M_GetEditManager()->CanRedo() ? TRUE : FALSE);

	// Save
	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SAVEALL);
	pBut->ShowWindow(SW_SHOW);
	// Options
	pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_OPTIONS);
	pBut->ShowWindow(SW_SHOW);

	// Device ToolBar
	mfn_vUpdateDeviceToolBar();
}


//===========================================================================
//      Description:    resets all buttons except for the current editor
//      Creation date:  8.09.98
//      Author:         Mircea Dunka
//---------------------------------------------------------------------------
//      Return BOOL		Helps the user to see what he's doing
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void FRMBaseMenu::fn_vUpdateEditorButtonsToolbar()
{
	if(m_oGeneralDialogBar.m_oListOfEditorButtons.IsEmpty())
		return;

	CPA_DLLBase* pEditor = M_GetCurrentEditor();
	POSITION stPos;
	stPos = m_oGeneralDialogBar.m_oListOfEditorButtons.GetHeadPosition();
	while(stPos)
	{
		CButton *pBut = (CButton*)m_oGeneralDialogBar.m_oListOfEditorButtons.GetNext(stPos);
		if( GetWindowLong(pBut->m_hWnd,GWL_USERDATA) == (long)pEditor)			
			pBut->SetCheck(1);
		else
			pBut->SetCheck(0);
	}
	return;
}
//end Mircea Dunka


void FRMBaseMenu::mfn_vUpdateDeviceToolBar(void)
{
	if(!M_bEditorsActive())
	{
//		m_oGeneralDialogBar.m_oDeviceToolbar.ShowWindow(SW_HIDE);
		return;
	}
	
/*	if(!mbWantSplit && !mbWantNew && !mbWantTile)
		m_oGeneralDialogBar.m_oDeviceToolbar.ShowWindow(SW_HIDE);
	else
*/	{
//		m_oGeneralDialogBar.m_oDeviceToolbar.ShowWindow(SW_SHOW);
/*		if(!mbWantNew)
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_OPENDEVICE, FALSE);
		if(!mbWantSplit)
		{
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_SPLITVERT, FALSE);
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_SPLITHORIZ, FALSE);
		}
		else
		{
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_SPLITVERT, TRUE);
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_SPLITHORIZ, TRUE);
			if(m_oSplitter.GetColumnCount() == 2)
				m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_SPLITVERT, FALSE);
			if(m_oSplitter.GetRowCount() == 2)
				m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_SPLITHORIZ, FALSE);
		}
*/
		// Is there an additional active device ?
		BOOL    bActiv = FALSE;
		for(int i = 1; (i < MAX_DEVICE) && (GetActiveView()); i++)
		{
			if(((DEV_MultiDevice *) GetActiveView())->IsActivDevice(i))
			{
				bActiv = TRUE;
				break;
			}
		}

/*		m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_TILE_HORZ, TRUE);
		m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_TILE_VERT, TRUE);
		m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_CASCADE, TRUE);
		if((!mbWantTile) || (!bActiv))
		{
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_TILE_HORZ, FALSE);
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_TILE_VERT, FALSE);
			m_oGeneralDialogBar.m_oDeviceToolbar.SetPermission(CPA_IDB_DEVICE_CASCADE, FALSE);
		}
*/	}
}

//===========================================================================
//      Description:    Show or hide the general interface of application in edit
//                                      mode (toolbar and menu)
//      Creation date:  11 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      BOOL            Not used
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void FRMBaseMenu::fn_vShowGeneralInterface(BOOL bMustShow)
{
    // Menu
	if (bMustShow)
	{
        // Update menu regardless to context
		fn_vInitGeneralMenuWithContext();

		// Menu
		SetMenu(&m_oGeneralMenu);
	}
	else
	{
		SetMenu(NULL);
	}

    // ToolBar
    if (bMustShow)
	{
		// Update menu and toolbar regardless to context
		fn_vInitGeneralDialogBarWithContext();
    }
    m_oGeneralDialogBar.ShowWindow( bMustShow ? SW_SHOWNORMAL : SW_HIDE );
	m_oStatusBar.ShowWindow( bMustShow ? SW_SHOWNORMAL : SW_HIDE );
	RecalcLayout();
}

void FRMBaseMenu::fn_vEnableEditors(BOOL _bCan)
{
    if(!M_bEditorsActive())
    {
	    CButton     *pBut;

		m_bEnableEditors = _bCan;
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SWAPTOEDITORS);
		pBut->SetCheck(0);
        pBut->ShowWindow(m_bEnableEditors ? SW_SHOW : SW_HIDE);
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_PAUSEENGINE);
        pBut->ShowWindow(m_bEnableEditors ? SW_SHOW : SW_HIDE);
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULLSCREEN);
	    pBut->ShowWindow(m_bEnableEditors ? SW_SHOW : SW_HIDE);
    }
}

void FRMBaseMenu::OnEnterMenuLoop(BOOL bIsTrackPopupMenu)
{
	g_bMouseLocked = TRUE;
}

void FRMBaseMenu::OnExitMenuLoop(BOOL bIsTrackPopupMenu)
{
	g_bMouseLocked = FALSE;
}

	
///////////////////////
// For splitter
///////////////////////

IMPLEMENT_DYNCREATE(FRMSplitter, CSplitterWnd)
BEGIN_MESSAGE_MAP(FRMSplitter, CSplitterWnd)
	ON_WM_LBUTTONDOWN()
    ON_WM_PAINT()
	ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()


BOOL FRMBaseMenu::OnCreateClient(LPCREATESTRUCT _p_stStruct, CCreateContext *_p_stContext)
{
    m_oSplitter.Create
    (
        this, 2, 2,
        CSize(10, 10),//chbani
        _p_stContext,
        WS_CHILD|WS_VISIBLE|SPLS_DYNAMIC_SPLIT
    );

    return TRUE;
}

BOOL FRMBaseMenu::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	return FALSE;
}

BOOL FRMSplitter::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	return FALSE;
}

void FRMSplitter::RecalcLayout(void)
{
    if(!M_bEditorsActive() && M_GetMainApp()->m_bFlagTaken == FALSE)
		if (WaitForSingleObject(M_GetMainApp()->m_hDrawSem,10000) == WAIT_TIMEOUT)
			ASSERT(0);
    CSplitterWnd::RecalcLayout();
    if(!M_bEditorsActive() && M_GetMainApp()->m_bFlagTaken == FALSE)
	    ReleaseSemaphore(M_GetMainApp()->m_hDrawSem, 1, NULL);
}

void FRMSplitter::DrawObject(CWnd *_p_stParam)
{
    DEV_MultiDevice3D   *pMulti = (DEV_MultiDevice3D *) GetPane(0, 0);
    DEV_MultiDevice3D   *pInit = (DEV_MultiDevice3D *) _p_stParam;
    DEV_MultiDevice3D   *pSingle;

    pSingle = (DEV_MultiDevice3D *) GetPane(0, 0);
    if(pSingle != pInit)
    {
		if(M_bEditorsActive())
		{
			pSingle->m_p_oMultiToDraw = _p_stParam;
			pSingle->DrawObject();
			pSingle->m_p_oMultiToDraw = NULL;
		}
    }

    if(GetColumnCount() == 2)
    {
        pSingle = (DEV_MultiDevice3D *) GetPane(0, 1);
        if(pSingle != pInit)
        {
            pSingle->m_p_oMultiToDraw = _p_stParam;
            pSingle->DrawObject();
            pSingle->m_p_oMultiToDraw = NULL;
        }
    }

    if(GetRowCount() == 2)
    {
        pSingle = (DEV_MultiDevice3D *) GetPane(1, 0);
        if(pSingle != pInit)
        {
            pSingle->m_p_oMultiToDraw = _p_stParam;
            pSingle->DrawObject();
            pSingle->m_p_oMultiToDraw = NULL;
        }

        if(GetColumnCount() == 2)
        {
            pSingle = (DEV_MultiDevice3D *) GetPane(1, 1);
            if(pSingle != pInit)
            {
                pSingle->m_p_oMultiToDraw = _p_stParam;
                pSingle->DrawObject();
                pSingle->m_p_oMultiToDraw = NULL;
            }
        }
    }
}

BOOL FRMSplitter::CreateView(int row, int col, CRuntimeClass* pViewClass, SIZE sizeInit, CCreateContext* pContext)
{
	CPA_SuperObject		*p_oCameraSO;
	CPA_CameraDLLBase	*p_oCamDLL;
    
	if(row || col)
    {
        CSplitterWnd::CreateView(row, col, pViewClass, sizeInit, pContext);
        ((DEV_MultiDevice3D *) GetPane(row, col))->m_cIsAdditional = 1;

		// create the default camera for the device
		p_oCamDLL = (CPA_CameraDLLBase*) M_GetMainApp()->m_p_oMainWorld->GetObjectDLLWithName(C_szDLLCameraName);
		ASSERT(p_oCamDLL != NULL);
		
		p_oCameraSO = p_oCamDLL->CreateDefaultCamera();
		p_oCamDLL->InsertCameraInHierarchy(p_oCameraSO);
		ASSERT(p_oCameraSO != NULL);
		
		((DEV_ViewPort3D*)(((DEV_MultiDevice3D *)GetPane(row, col))->GetDevice(0)->GetViewPort()))->ChangeCamera(p_oCameraSO);

		GetParentFrame()->mfn_vUpdateDeviceToolBar();
    }
    else
    {
        CSplitterWnd::CreateView(row, col, pViewClass, sizeInit, pContext);
        ((DEV_MultiDevice3D *) GetPane(row, col))->m_cIsAdditional = 0;
    }
    return TRUE;
}

void FRMSplitter::DeleteView(int iRow, int iCol)
{
    CSplitterWnd::DeleteView(iRow, iCol);
}

void FRMSplitter::DeleteRow(int iRow)
{
    CSplitterWnd::DeleteRow(iRow);
	GetParentFrame()->mfn_vUpdateDeviceToolBar();
}

void FRMSplitter::DeleteColumn(int iCol)
{
    CSplitterWnd::DeleteColumn(iCol);
	GetParentFrame()->mfn_vUpdateDeviceToolBar();
}

void FRMSplitter::SetActivePane(int iRow, int iCol, CWnd *pWnd /*= NULL*/)
{
    CSplitterWnd::SetActivePane(iRow, iCol, pWnd);
}

// To disable the deletion of the game view.
void FRMSplitter::OnLButtonDown(UINT nFlags, CPoint pt)
{
	CSplitterWnd::OnLButtonDown(0, pt);

    if(M_GetMainDevice() == (DEV_MultiDevice *) GetPane(0, 0))
    {
	    int hit = HitTest( pt );
	    if ((hit >= 201) && (hit <= 215))
	    {
		    hit -= 201;
		    m_rectLimit.left = 20;
	    }
	    else if ((hit >= 101) && (hit <= 115))
	    {
		    hit -= 101;
		    m_rectLimit.top = 20;
	    }
    }
}

BOOL FRMSplitter::CreateScrollBarCtrl(DWORD dwStyle, UINT nID)
{
    CSplitterWnd::CreateScrollBarCtrl(dwStyle, nID);
    return TRUE;
}

int FRMSplitter::HitTest(CPoint pt) const
{
    return CSplitterWnd::HitTest(pt);
}

void FRMSplitter::OnPaint()
{
    CSplitterWnd::OnPaint();
}

void FRMSplitter::MakeSplit(int ht)
{
	// start tracking
	StartTracking(ht);
	CRect rect;
	rect.left = m_rectTracker.Width() / 2;
	rect.top = m_rectTracker.Height() / 2;
	if (m_ptTrackOffset.y != 0)
		rect.top = m_rectTracker.top;
	if (m_ptTrackOffset.x != 0)
		rect.left = m_bTracking2 ? m_rectTracker2.left :m_rectTracker.left;
	rect.OffsetRect(-m_ptTrackOffset.x, -m_ptTrackOffset.y);
	ClientToScreen(&rect);
	SetCursorPos(rect.left, rect.top);
	GetParentFrame()->mfn_vUpdateDeviceToolBar();
}

#endif //ACTIVE_EDITOR
