//=========================================================================
// CPAFrame.cpp : implementation of the CPA_MainFrame class
// This is a part of the CPA project.
//
// Version                      1.0
// Creation date        06/06/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 <pbt.h>

#include "direct.h"
#include "Itf/CPARes.h"
#include "errint.h"
#include "mmgint.h"
#include "Itf/DEVViewp.hpp"
#include "Itf/DEVMul3D.hpp"
#include "Itf/CPAFrame.hpp"
#include "Itf/CPAProj.hpp"
#include "Itf/CPAConst.hpp"
#include "Itf/A3dkeyal.hpp"
#include "Itf/cpamworl.hpp"
#include "Itf/camdllb.hpp"
#include "Itf/CPAInter.hpp"
#include "incgam.h"

/////////////////////////////////////////////////////////////////////////////
// CPA_MainFrame

    #define M_BaseClass FRMBaseMenu
//	#define M_GetDevice()           ((DEV_MultiDevice*)GetActiveView())
//	#define M_GetEditManager()       (M_GetDevice()->GetEditManager())


IMPLEMENT_DYNCREATE(CPA_MainFrame, M_BaseClass)
BEGIN_MESSAGE_MAP(CPA_MainFrame, M_BaseClass)

//{{AFX_MSG_MAP(CPA_MainFrame)
	ON_MESSAGE(WM_POWERBROADCAST, m_lOnPowerManagement)
    ON_WM_CREATE()
    ON_WM_CLOSE()
//    ON_WM_ACTIVATEAPP()
	ON_WM_MOUSEACTIVATE()
    ON_WM_SYSCOMMAND()
    ON_WM_SIZE()
    ON_WM_GETMINMAXINFO()
    ON_WM_NCLBUTTONDOWN()
    ON_WM_WINDOWPOSCHANGED()
    ON_COMMAND(CPA_ID_APP_EXIT, OnAppExit)
    ON_COMMAND(CPA_IDCB_SWAPTOEDITORS, OnSwapToEditors)
    ON_COMMAND(CPA_IDCB_FULLSCREEN, OnFullScreen)
	ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPA_MainFrame construction/destruction

CPA_MainFrame::CPA_MainFrame()
{
    mbWantSplit = TRUE;
    mbWantNew = TRUE;
    mbWantTile = TRUE;
    mbWantClose = TRUE;

}

CPA_MainFrame::~CPA_MainFrame()
{
}


//###########################################################################
// POWER MANAGEMENT AND SCREEN SAVER
//###########################################################################

// handled WM_POWERBROADCAST
LRESULT CPA_MainFrame::m_lOnPowerManagement(UINT wParam, LONG lParam)
{
	switch ( lParam ) 
	{
	case PBT_APMQUERYSUSPEND: //when system asks apps if they accept to enter low-power mode
	case PBT_APMQUERYSTANDBY:
		return TRUE; //return BROADCAST_QUERY_DENY for refusal to enter low-power mode

	case PBT_APMSTANDBY: //received when all apps granted low-power mode, right before low-power mode is activated
	case PBT_APMSUSPEND:  //these 2 may me received before the two others if some app forces the mode
		if ( !M_GetMainApp()->m_bEngineIsStopped )
		{
			M_GetMainApp()->fn_vStopEngine();
			// if we are in fullscreen, then swap to windowed
			// and tell we were in full screen

			if (M_GetMainDevice()->GetDevice(0)->IsFullScreen())
			{
				M_GetMainDevice()->GetDevice(0)->SwapFullScreen();
				M_GetMainApp()->m_bWasInFullScreenBeforeLooseFocus = TRUE;
				SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
			}
		}
		return TRUE; //accept entry into low-power mode

	case PBT_APMRESUMESUSPEND: //when resuming from low-power mode to normal operation
	case PBT_APMRESUMESTANDBY: //when resuming from low-power mode to normal operation
	case PBT_APMRESUMECRITICAL: //received when power is enough to proceed with normal operations
		OnActivateApp(TRUE, NULL);
		return FALSE;

	case PBT_APMQUERYSUSPENDFAILED: //when an app denied request, others receive this message
	case PBT_APMQUERYSTANDBYFAILED: //when an app denied request, others receive this message
	case PBT_APMPOWERSTATUSCHANGE: //when power supply change is detected (batt<->mains/low, etc...)
	case PBT_APMOEMEVENT: //when bios sends an OEM APM change
	case PBT_APMBATTERYLOW: //when battery is running low
		return FALSE; //return value is irrelevant
	// PBTF_APMRESUMEFROMFAILURE ? 
	}
	return BROADCAST_QUERY_DENY; //any other case is not known, so prevent power management just in case
}
int  g_iMainWindowWidth	= 652; //700
int  g_iMainWindowHeight = 526;//550

BOOL CPA_MainFrame::PreCreateWindow(CREATESTRUCT &cs)
{
    CSize   ss(GetSystemMetrics(SM_CXMAXIMIZED), GetSystemMetrics(SM_CYMAXIMIZED));
	cs.style = WS_CAPTION|WS_CLIPCHILDREN|WS_THICKFRAME|WS_OVERLAPPED;
	cs.hwndParent = g_oBaseFrame.m_hWnd;
	cs.x = (ss.cx - g_iMainWindowWidth) / 2;
	cs.y = (ss.cy - g_iMainWindowHeight) / 2;
	cs.cx = g_iMainWindowWidth;
	cs.cy = g_iMainWindowHeight;
	return CFrameWnd::PreCreateWindow(cs);
}

void CPA_MainFrame::OnSysCommand(UINT nID, LPARAM lParam) //handles WM_SYSCOMMAND message
{
	UINT uiTrueNID = nID & 0xFFFFFFF0;
  if(M_bEditorsActive())
  {
    if(uiTrueNID == SC_MAXIMIZE)
      return;
  }

    if(uiTrueNID == SC_CLOSE)
		TerminateProcess(GetCurrentProcess(),0);

	switch ( uiTrueNID )
	{
	case SC_MONITORPOWER:
	case SC_SCREENSAVE: // screensaver
		// if we are in fullscreen, then swap to windowed
		// and tell we were in full screen
		//(do not do this for MONITORPOWER message, because the resolution change causes the
		//power management counter to reset -> the monitor does not switch off...
		if ( /*uiTrueNID == SC_SCREENSAVE &&*/ M_GetMainDevice()->GetDevice(0)->IsFullScreen() )
		{
			M_GetMainDevice()->GetDevice(0)->SwapFullScreen();
			M_GetMainApp()->m_bWasInFullScreenBeforeLooseFocus = TRUE;
			SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
		}
		M_GetMainApp()->fn_vAppliAskToStopEngine();
		break;

	/*
	case SC_KEYMENU:
	case SC_MAXIMIZE:
		return bRes = FALSE; //message processed -> if we do nothing, no one will */
	}
  CFrameWnd::OnSysCommand(nID, lParam);
}


void CPA_MainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
    if(nHitTest == HTCAPTION)
    {
        if(M_bEditorsActive())
        {
            SetFocus();
            return;
        }
    }
    CFrameWnd::OnNcLButtonDown(nHitTest, point);
}

void CPA_MainFrame::OnWindowPosChanged(WINDOWPOS *lpwndpos)
{
/*    if(!M_bEditorsActive())
        m_oMainPos.SetRect
        (
            lpwndpos->x,
            lpwndpos->y,
            lpwndpos->x + lpwndpos->cx - 1,
            lpwndpos->y + lpwndpos->cy - 1
        );
*/    FRMBaseMenu::OnWindowPosChanged(lpwndpos);
}


void CPA_MainFrame::OnSize(UINT nType, int cx, int cy)
{
    if(!M_bEditorsActive())
    {
        CFrameWnd::OnSize(nType, cx, cy);
        return;
    }
    FRMBaseMenu::OnSize(nType, cx, cy);
}

void CPA_MainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
    CSize   ss(GetSystemMetrics(SM_CXMAXIMIZED), GetSystemMetrics(SM_CYMAXIMIZED));

    if(M_bEditorsActive())
	{
		FRMBaseMenu::OnGetMinMaxInfo(lpMMI);
		return;
	}

	lpMMI->ptMaxSize.x = g_iMainWindowWidth;
	lpMMI->ptMaxSize.y = g_iMainWindowHeight;
	lpMMI->ptMaxPosition.x = (ss.cx - g_iMainWindowWidth) / 2;
	lpMMI->ptMaxPosition.y = (ss.cy - g_iMainWindowHeight) / 2;

    lpMMI->ptMinTrackSize.x = lpMMI->ptMaxSize.x;
    lpMMI->ptMinTrackSize.y = lpMMI->ptMaxSize.y;
    lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
    lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
}

//===========================================================================
//      Description:    That function is called by MFC to update main frame title.
//                      We put project title and actual version of project.     
//      Creation date:  06 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      BOOL            Not used
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void CPA_MainFrame::OnUpdateFrameTitle(BOOL)
{
//    M_GetMainApp()->fn_vUpdateFrameTitle();
//	::SetWindowText(m_hWnd, (LPCTSTR) m_szProjectName);
}

//===========================================================================
//      Description:    Call when application is activate or desactivate.
//      Creation date:  24 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      bActive         Application is activated or not ?
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
int CPA_MainFrame::OnMouseActivate( CWnd* pDesktopWnd, UINT nHitTest, UINT message )
{
	if(!M_bEditorsActive())
		return MA_NOACTIVATEANDEAT;
	else
		return CFrameWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
void CPA_MainFrame::OnActivateApp(BOOL bActive, DWORD)
{
	static BOOL s_bPreventNestedCalls = FALSE;
	if ( s_bPreventNestedCalls )
		return;
	s_bPreventNestedCalls = TRUE;

	if(bActive)
	{
		// Change priority level of main process
		// Warning ! HIGH_PRIORITY_CLASS = same level as windows task manager. So if
		// appli crash, it may causes somes problems.
//		SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
		
		// if we are not in editor mode, check if we were in fullscreen before leaving
		// and resume then engine


		if(!M_bEditorsActive())
		{

			if (M_GetMainApp()->m_bWasInFullScreenBeforeLooseFocus)
			{
				M_GetMainApp()->m_bWasInFullScreenBeforeLooseFocus = FALSE;
				if (M_GetMainDevice()->GetDevice(0)->IsFullScreen() == FALSE)
				{
//					if(M_GetMainWnd()->IsIconic())
//						M_GetMainWnd()->SendMessage(WM_SYSCOMMAND, SC_RESTORE);
					M_GetMainDevice()->GetDevice(0)->SwapFullScreen();
				}
			}
			M_GetMainApp()->m_bAppliAskedToStopEngine = FALSE;
			M_GetMainApp()->fn_vRestartEngine();


		}

		
		// Call a virtual method for a real project
		M_GetMainApp()->fn_vWhenAppGainFocus();
	}
	else
	{

		if(!M_bEditorsActive())
		{
			
			if (M_GetMainApp()->m_bProjectIsClosing == 0)
			{
				if (M_GetMainApp()->m_bLeavingApplication == FALSE)
				{
					
					// Suspend engine thread
					M_GetMainApp()->fn_vAppliAskToStopEngine();
					
					//if we were in full screen, it might be because the screen saver was activated...			
//					if (M_GetMainDevice()->GetDevice(0)->IsFullScreen())
//					{
//						M_GetMainDevice()->GetDevice(0)->SwapFullScreen(FALSE);
//						M_GetMainApp()->m_bWasInFullScreenBeforeLooseFocus = TRUE;
//						SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
//					}
					// Restore a normal priority for actual process
					//			SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
					
					// Call a virtual method for a real project
					M_GetMainApp()->fn_vWhenAppLooseFocus();
				}
			}

		}
	}
/*#ifdef ACTIVE_EDITOR
	if(M_bEditorsActive() && bActive)
	{
        for(int x = 1; x <= FRM_C_MaxCol; x++)
            for(int y = 1; y <= FRM_C_MaxRow; y++)
				if(g_oFrameGest.ma_p_oWinArray[x][y]) g_oFrameGest.ma_p_oWinArray[x][y]->BringWindowToTop();
	}
#endif*/
	s_bPreventNestedCalls = FALSE;
}

//===========================================================================
//      Description:    Call to close main frame.
//                      In editor mode, we ask all editors to close. Editors can
//                      say NO to not close application !
//                      Else we force second thread to close.
//      Creation date:  20 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void CPA_MainFrame::OnClose(void)
{
	// if the engine has finished its closing process, the perform the onclose
	if (M_GetMainApp()->m_bEngineIsOver == FALSE)
	{
		if(fn_bCanClose() == FALSE)
			return;

		// We are in full screen ?
		if(M_GetMainDevice()->GetDevice(0)->IsFullScreen())
			M_GetMainDevice()->GetDevice(0)->SwapFullScreen();
		
		// We indicate that project is closing
		M_GetMainApp()->m_bProjectIsClosing = 1;
		M_GetMainApp()->m_bLeavingApplication = 1;
		
		// Force engine thread to close.
		// we ask engine thread to begin the closing process
		M_GetMainApp()->fn_vAppliAskToEndGame();
	}
	else
	{
		// We close window
		TerminateProcess(GetCurrentProcess(),0);

		CFrameWnd::OnClose();
	}
}

//===========================================================================
//      Description:    Call to create main frame.
//                      In editor mode, we create toolbar and menus.
//      Creation date:  06 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
int CPA_MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (M_BaseClass::OnCreate(lpCreateStruct) == -1)
		return -1;
	SetMenu(NULL);  // No menu at this point of program
	return 0;
}

//###########################################################################
// RESPONSE TO EDIT INTERFACE MESSAGES
//###########################################################################


UINT CPA_MainFrame::OnNcHitTest(CPoint point)
{
	if(M_bEditorsActive())
		return FRMBaseMenu::OnNcHitTest(point);
	return CFrameWnd::OnNcHitTest(point);
}



//###########################################################################
// RESPONSE TO EDIT INTERFACE MESSAGES
//###########################################################################

void CPA_MainFrame::ActivateEditors(void)
{
	M_GetMainApp()->fn_vAfterEngineStops();
	
	
	// Tells the main contact that engine has just been stopped
	g_oFrameGest.mfn_vSetRefresh(FALSE);

	M_GetMainApp()->m_bEditorsAreActive = TRUE;
	M_GetMainApp()->m_bFullScreenInEditor = M_GetMainDevice()->GetDevice(0)->IsFullScreen();
	
	M_GetListOfAllDLL()->CallBeforeEditor();
	g_oFrameGest.mfn_vSetRefresh(TRUE);
		
	M_GetMainDevice()->DrawObject();
//	M_GetMainDevice()->SetFocusDevice(0);	
	M_GetMainWnd()->fn_vShowGeneralInterface(TRUE);
	g_oBaseFrame.SetFocus();
//	M_FocusToDevice(M_GetMainDevice());
	GetInterface()->fn_vDisplayTipOfDay("Interface","ITF",FALSE);
}





void CPA_MainFrame::DisactivateEditors(void)
	{		
		// Ask the main contact if it accepts to run engine
		// Exit if it says NO !
		if (M_GetListOfAllDLL()->CallAcceptToRunEngine() == FALSE)
		{
			M_GetMainApp()->m_bAppliAskedToActivateEditors = TRUE;
			fn_vShowGeneralInterface(TRUE); // For button that is now pressed
			return;
		}
		
		// compute all bounding volumes
//		OnComputeAllBound();

		// erase info in status bar
		M_GetMainWnd()->UpdateStatus(NULL, C_STATUSPANE_INFOS, C_STATUS_NORMAL);

		// tells main contact that engine is about to start
		// 5000 = Special value to force hide in FrmGest.
        g_oFrameGest.m_iCanRefresh = -5000;
		M_GetListOfAllDLL()->CallBeforeEngine();
		M_bEditorsActive() = FALSE;
//        M_GetMainWnd()->MoveWindow(((FRMBase *)M_GetMainWnd())->m_oMainPos);
        M_GetMainWnd()->m_cLock = 0;

        g_oFrameGest.m_iCanRefresh = 0;

		// Go Engine
		M_GetMainApp()->fn_vBeforeEngineStarts();
		if (M_GetMainApp()->m_bAutoReinitTheMap)
		{
			fn_vReinitTheMap();
		}
//		OnComputeAllBound();

		if(M_GetMainDevice()->GetDevice(0)->IsFullScreen())
			M_GetMainWnd()->ShowWindow(FALSE);
		else
		{
			fn_vShowGeneralInterface(FALSE);

			
			CSize   ss(GetSystemMetrics(SM_CXMAXIMIZED), GetSystemMetrics(SM_CYMAXIMIZED));
			CRect	cs;

			//g_iMainWindowWidth = (g_iMainWindowHeight-46)*1.33 + 12;//chbani
			cs.left = (ss.cx - g_iMainWindowWidth) / 2;
			cs.top = (ss.cy - g_iMainWindowHeight) / 2;
			cs.right = cs.left + g_iMainWindowWidth;
			cs.bottom = cs.top + g_iMainWindowHeight;
			M_GetMainWnd()->MoveWindow(cs);
			
			
		}

		M_GetMainApp()->fn_vRestartEngine();
		
//	    fn_vShowGeneralInterface(TRUE);
//	    M_FocusToDevice(M_GetMainDevice());
		g_oBaseFrame.SetFocus();
}

//===========================================================================












//===========================================================================
//      Description:    Call to swap between motor and editors
//      Creation date:  11 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void CPA_MainFrame::OnSwapToEditors(void)
{
	if (M_GetMainApp()->m_bAppliAskedToActivateEditors == TRUE)
	{
		// if editors are not active, don't stop them
		if (M_bEditorsActive())
		{
			M_GetMainApp()->fn_vAppliAskToStopEditors();
		}
	}
	else
	{
		if (!M_bEditorsActive())
		{
			M_GetMainApp()->fn_vAppliAskToStartEditors();
		}
	}
}


//===========================================================================
//      Description:    To pass to full screen when engine runs
//      Creation date:  27 Jun 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void CPA_MainFrame::OnFullScreen(void)
{
	//
	// DO NOT PUT SPECIAL CODE FOR FULL SCREEN HERE, BUT PUT IT IN SWAPFULLSCREEN
	//
	M_GetMainDevice()->GetDevice(0)->SwapFullScreen();
	if (M_bEditorsActive())
		M_FocusToDevice(M_GetMainDevice());
}

//===========================================================================
//      Description:    To exit application
//      Creation date:  20 Sep 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:  3 Dec 97                                                                                          
//      Author:         CPA2-GDumitrascu
//===========================================================================
void CPA_MainFrame::OnAppExit(void)
{
    SendMessage(WM_CLOSE);
}

void CPA_MainFrame::fn_vInitGeneralDialogBarWithContext(void)
{
	CComboBox		*pCombo;
	CButton         *pBut;
	
	// ENABLE OR DISABLE ITEMS
	// Determins if an item of the control must be enabled or disabled. If editors are
	// not active, a lot of things are disabled.
	
	// COMBOBOX :           Not active if engine runs
	// PAUSEENGINE:         Not active  if engine doesn't run
	// ONE/SOMESTEP:        Not active if not in pause or engine doesn't run
	// FULLSCREEN:          Not active if engine doesn't run or engine in pause
	if (M_bEditorsActive() == FALSE)
	{
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SWAPTOEDITORS);
		pBut->SetCheck(0);
//        pBut->ShowWindow(m_bEnableEditors ? SW_SHOW : SW_HIDE);
        pBut->ShowWindow(SW_SHOW);

		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_PAUSEENGINE);
        pBut->ShowWindow(m_bEnableEditors ? SW_SHOW : SW_HIDE);

		if (M_GetMainApp()->m_bAppliAskedToStopEngine)
		{
			pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_ONESTEPENGINE);
			pBut->ShowWindow(SW_SHOW);
			pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULLSCREEN);
			pBut->ShowWindow(SW_HIDE);
		}
		else
		{
			pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_ONESTEPENGINE);
			pBut->ShowWindow(SW_HIDE);
			pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULLSCREEN);
	        pBut->ShowWindow(m_bEnableEditors ? SW_SHOW : SW_HIDE);
		}

		// Undo/Redo
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_UNDO);
		pBut->SetCheck(0);
		pBut->ShowWindow(SW_HIDE);
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_REDO);
		pBut->SetCheck(0);
		pBut->ShowWindow(SW_HIDE);
		// Save
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SAVEALL);
		pBut->ShowWindow(SW_HIDE);
		// Options
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_OPTIONS);
		pBut->ShowWindow(SW_HIDE);
		
		// select mode
		pCombo = (CComboBox *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SELECTMODE);
		pCombo->ShowWindow(SW_HIDE);

		// display mode
		m_oGeneralDialogBar.m_oDisplayToolbar.ShowWindow(SW_HIDE);
		// current sector
		pCombo = (CComboBox *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_CURRENTSECTOR);
		pCombo->ShowWindow(SW_HIDE);

		// auto target
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_AUTOTARGET);
		pBut->ShowWindow(SW_HIDE);
		pBut->EnableWindow(FALSE);


		// CPA_Ed_1 FS begin
		// move camera 
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_MOVECAMERA);
		pBut->ShowWindow(SW_HIDE);
		pBut->EnableWindow(FALSE);
		// CPA_Ed_1 FS end

		// Full button 
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULL);
		pBut->ShowWindow(SW_HIDE);
		pBut->EnableWindow(FALSE);

		// Delta button 
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_DELTA);
		pBut->ShowWindow(SW_HIDE);
		pBut->EnableWindow(FALSE);

//ROMTEAM 3DEdition (Adrian Silvescu 24/02/98)
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_LOCK);
		pBut->ShowWindow(SW_HIDE);
		pBut->EnableWindow(FALSE);
//ENDROMTEAM 3DEdition (Adrian Silvescu)

		m_oGeneralDialogBar.m_oDeviceToolbar.ShowWindow(SW_HIDE);
	}
	
	// Editors active
	
	else
	{
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SWAPTOEDITORS);
		pBut->SetCheck(1);
		
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_PAUSEENGINE);
		pBut->ShowWindow(SW_HIDE);
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_ONESTEPENGINE);
		pBut->ShowWindow(SW_HIDE);
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULLSCREEN);
		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);

		// select mode
		pCombo = (CComboBox *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_SELECTMODE);
		pCombo->ShowWindow(SW_SHOW);

		// display mode
		m_oGeneralDialogBar.m_oDisplayToolbar.ShowWindow(SW_SHOW);
		// current sector
		pCombo = (CComboBox *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_CURRENTSECTOR);
		pCombo->ShowWindow(SW_SHOW);
		// auto target
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_AUTOTARGET);
		pBut->ShowWindow(SW_SHOW);
		pBut->EnableWindow(TRUE);
		pBut->SetCheck(GetInterface()->fn_bAutoTarget());
		
		// CPA_Ed_1 FS begin
		// move camera
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_MOVECAMERA);
		pBut->ShowWindow(SW_SHOW);
		pBut->EnableWindow(TRUE);
		pBut->SetCheck(GetInterface()->fn_bMoveCamera());
		// CPA_Ed_1 FS end

		// Full button 
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_FULL);
		pBut->ShowWindow(SW_SHOW);
		pBut->EnableWindow(TRUE);
		pBut->SetCheck(GetInterface()->fn_bFullSelect());

		// Delta button
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_DELTA);
		pBut->ShowWindow(SW_SHOW);
		pBut->EnableWindow(TRUE);
		pBut->SetCheck(GetInterface()->fn_bDeltaSelect());

//ROMTEAM 3DEdition (Adrian Silvescu 24/02/98)
		pBut = (CButton *) m_oGeneralDialogBar.GetDlgItem(CPA_IDCB_LOCK);
		pBut->ShowWindow(SW_SHOW);
		pBut->EnableWindow(TRUE);
		pBut->SetCheck(GetInterface()->GetLockSelection());
//ENDROMTEAM 3DEdition (Adrian Silvescu)

		m_oGeneralDialogBar.m_oDeviceToolbar.ShowWindow(SW_SHOW);
	}

	// Device toolbar
	mfn_vUpdateDeviceToolBar();

}


#ifdef TEST_CPA_VERSION_3D
//===========================================================================
//      Description:    To load a world id DATA directory.
//      Creation date:  20 Sep 96
//      Author:         CB
//---------------------------------------------------------------------------
//      szName          Name of the world to load
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void fn_vInitCompleteWorld3D(LPCTSTR szName)
{
	// Load an object in main view
	HIE_tdxHandleToSuperObject hRoot/*, hSRoot*/;
//	CPA_SuperObject		*pRoot, *pSRoot;
	DEV_MultiDevice3D	*pDev;
	long				NbTriangles = 0;
    #define				C_MaxTriangles 100000 
    char				temp[MAX_PATH];
	SCR_tdst_Cxt_Values *p_stValues ;
	char				szSectionName[256];

	GLI_xResetMatrixStack();
	Mmg_M_SetModeAlloc4Ch(Int, E_ucDynamic, C_ucMmgDefaultChannel);

	//chdir(M_GetMainApp()->m_csEngineDataPath);
	GMT_fn_vInitLoadGameMaterial();
	strcpy(temp, (char *) (LPCTSTR) (M_GetMainApp()->m_csEngineDataPath));
	strcat(temp, "world\\levels\\");
	SCR_fn_v_RdL0_RegisterPath(temp);

    ::GetCurrentDirectory(255, temp);

	pDev = (DEV_MultiDevice3D *) M_GetMainApp()->fn_p_oGetMainWorld()->GetEditor()->GetDevice();
	// Init des scripts et lecture du fichier
	SCR_M_RdL0_SetContextLong(2, 0,  (long) M_GetMainApp()->fn_p_oGetMainWorld());
	SCR_fn_v_RdL0_ComputeSectionName(szSectionName, "cave\\cave.spo", "SuperObject", "Root");
	p_stValues = SCR_fnp_st_RdL0_AnalyseSection(szSectionName, SCR_CDF_uw_Anl_Normal);
	if (p_stValues)
		hRoot = (HIE_tdxHandleToSuperObject) p_stValues->a_ulValues[0];

	pDev->SetEngineWorld(hRoot);
	chdir(temp);
	//g_b_lLinesOn = 0;
	//g_b_lSurfacesOn = 1;
	//g_b_lBackFaceOn = 0;
}

//===========================================================================
//      Description:    To close current world.
//      Creation date:  20 Sep 96
//      Author:         CB
//---------------------------------------------------------------------------
//      Return void
//---------------------------------------------------------------------------
//      Revision date:                                                                                          
//      Author:         
//===========================================================================
void fn_vCloseCompleteWorld3D(void)
{
}
#endif // TEST_CPA_VERSION_3D
