reman3/Rayman_X/cpa/tempgrp/OAC/Src/EdActors/EDACVwMS.cpp

499 lines
14 KiB
C++

// cpacvwms.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "_AInterf.hpp"
#include "EDACVwMS.hpp"
#include "EDACFmMn.hpp"
#include "EDACDoc.hpp"
#include "EDACCnst.hpp"
#include "EDACActr.hpp"
#include "EDACWatc.hpp"
#include "help_def.h"
CBrush g_clWhiteBrush(RGB(255,255,255));
CBrush g_clRedBrush(RGB(255,0,0));
CBrush g_clGreenBrush(RGB(0,255,0));
CBrush g_clBackgroundBrush;
CTL_ToolTipTextDatabase g_oToolTipTextDatabase;
#define C_TIMER_COUNTER_MAX 19
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// EdActors_MiniStrucView
IMPLEMENT_DYNCREATE(EdActors_MiniStrucView, CFormView)
BEGIN_MESSAGE_MAP(EdActors_MiniStrucView, CTL_Editor_BaseFormView)
//{{AFX_MSG_MAP(EdActors_MiniStrucView)
ON_WM_TIMER()
ON_WM_HELPINFO()
ON_WM_SIZE()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
END_MESSAGE_MAP()
//***************************************************************************
EdActors_MiniStrucView::EdActors_MiniStrucView()
: CTL_Editor_BaseFormView(EdActors_MiniStrucView::IDD, TRUE)
{
//{{AFX_DATA_INIT(EdActors_MiniStrucView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pclControlTimerSender = NULL;
m_ucTimerCounter = 0;
m_bMustDragData = FALSE;
m_pri_pclDataToDrop = NULL;
m_pri_hDragCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_DRAG);
m_pri_hDisabledDragCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_DRAG_DISABLED);
}
//***************************************************************************
EdActors_MiniStrucView::~EdActors_MiniStrucView()
{
if ( m_pclToolTip != NULL )
delete m_pclToolTip;
}
//Member Functions
////////////////////////////
//*************************************************************************
//Définition des textes pour les Tool Tips
BOOL EdActors_MiniStrucView::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID =pNMHDR->idFrom;
nID = ::GetDlgCtrlID((HWND)nID);
BOOL bReturn = FALSE;
strcpy( pTTT->szText,
g_oToolTipTextDatabase[nID][m_fn_pclGetDocument()->m_pub_fn_bCurrentModeIsModel()]
);
return (TRUE);
}
//***************************************************************************
/*void EdActors_MiniStrucView::OnDraw(CDC* pDC)
{
static s_bFirstPass = TRUE;
if ( s_bFirstPass )
{
g_clBackgroundBrush.CreateSolidBrush(pDC->GetPixel(2,2));
s_bFirstPass = FALSE;
}
/* CRect crClientRect;
GetClientRect(crClientRect);
pDC->FillRect(crClientRect, &g_clWhiteBrush);
*/
//}
//***************************************************************************
void EdActors_MiniStrucView::OnInitialUpdate()
{
HINSTANCE hOldInstance = AfxGetResourceHandle();
AfxSetResourceHandle( g_stActorEditorIdentity.hModule );
//------------------------------------------------------------
CTL_Editor_BaseFormView::OnInitialUpdate();
m_fn_pclGetDocument()->m_pclMiniStrucView = this;
//Creates tool tips
EnableToolTips(TRUE);
m_pclToolTip = new CToolTipCtrl;
m_pclToolTip->Create(this, WS_VISIBLE | TTS_ALWAYSTIP);
//Sets the edition rectangle
GetClientRect(m_crEditionRect);
m_crEditionRect.InflateRect(-C_MAIN_VIEW_SPACING, -C_MAIN_VIEW_SPACING);
m_fn_vCreateAllMS();
//------------------------------------------------------------
AfxSetResourceHandle( hOldInstance );
}
//*********************************************************************************
// Creates the MS controls (and their data controls)
void EdActors_MiniStrucView::m_fn_vCreateAllMS()
{
POSITION pos = m_fn_pclGetDocument()->m_clListOfMSLists.GetHeadPosition();
while ( pos != NULL )
m_fn_vCreateMS(m_fn_pclGetDocument()->m_clListOfMSLists.GetNext(pos));
}
//*********************************************************************************
// Creates the MS controls (and their data controls)
void EdActors_MiniStrucView::m_fn_vCreateMS(EdActors_MiniStructureList *pclList)
{
//Creates the list of MS (non visible action)
CRect crCurrentRect(m_crEditionRect);
crCurrentRect.bottom = crCurrentRect.top + C_MS_LINE_HEIGHT;
EdActors_MiniStructure *pclCurrentMiniStructure;
POSITION MiniStrucPos = pclList->GetHeadPosition();
while ( MiniStrucPos != NULL )
{
pclCurrentMiniStructure = pclList->GetNext(MiniStrucPos);
pclCurrentMiniStructure->m_fn_lCreateMSControls(this, crCurrentRect);
crCurrentRect.OffsetRect(0, C_MS_SPACING + C_MS_LINE_HEIGHT);
}
}
//*********************************************************************************
// Updates editor values with motor values and displays the Actor's charac.
void EdActors_MiniStrucView::m_fn_vDisplayActor(EdActors_EditorActor *pclNewSelectedActor)
{
if ( pclNewSelectedActor != NULL )
{
POSITION AMSpos = pclNewSelectedActor->m_clListOfAMSLists.GetHeadPosition();
POSITION MSpos = m_fn_pclGetDocument()->m_clListOfMSLists.GetHeadPosition();
//Gets all motor datas
while ( MSpos != NULL )
m_fn_vUpdateMSListDatas(m_fn_pclGetDocument()->m_clListOfMSLists.GetNext(MSpos),
pclNewSelectedActor->m_clListOfAMSLists.GetNext(AMSpos));
ASSERT( AMSpos == NULL );
}
else
//only disables buttons
{
EdActors_MiniStructureList *pclEditorMSList = m_fn_pclGetDocument()->m_pclCurrentMiniStructureList;
if ( pclEditorMSList )
{
EdActors_MiniStructure *pclEditorMS;
POSITION EditorMiniStrucPos = pclEditorMSList->GetHeadPosition();
while ( EditorMiniStrucPos != NULL )
{
pclEditorMS = pclEditorMSList->GetNext(EditorMiniStrucPos);
//Sets the pointer onthe Actor MS in the Editor MS
pclEditorMS->m_pclActorMS = NULL;
//Updates button aspect
pclEditorMS->m_fn_vUpdateMSButton();
}
}
}
}
//*********************************************************************************
void EdActors_MiniStrucView::m_fn_vUpdateMSListDatas(EdActors_MiniStructureList *pclEditorMSList,
EdActors_ActorMiniStructureList *pclActorMSList)
{
//Gets all motor datas
EdActors_MiniStructure *pclEditorMS;
EdActors_ActorMiniStructure *pclActorMS;
POSITION EditorMiniStrucPos = pclEditorMSList->GetHeadPosition();
POSITION ActorMiniStrucPos = pclActorMSList->GetHeadPosition();
while ( EditorMiniStrucPos != NULL )
{
pclEditorMS = pclEditorMSList->GetNext(EditorMiniStrucPos);
pclActorMS = pclActorMSList->GetNext(ActorMiniStrucPos);
//Updates button aspect
pclEditorMS->m_fn_vUpdateMSButton();
if ( pclEditorMS->m_pclActorMS->m_fn_bIsAllocated() )
pclEditorMS->m_fn_vGetMotorDatas();
}
}
//*********************************************************************************
void EdActors_MiniStrucView::m_fn_vUpdateTree(EdActors_MiniStructure *pclMS)
{
EdActors_MiniStructureList *pclList = m_fn_pclGetDocument()->m_pclCurrentMiniStructureList;
//ANNECY CB
BOOL hashide = FALSE;
//END
if ( pclList != NULL )
{
//ANNECY CB
if(IsWindowVisible())
{
hashide = TRUE;
ShowWindow(FALSE);
}
//END
EdActors_MiniStructure *pclCurrentMiniStructure;
long lOffsetControls;
CRect crCurrentRect = m_crEditionRect;
crCurrentRect.bottom = crCurrentRect.top + C_MS_LINE_HEIGHT;
//Substracts vertical scroll position
long lOffset = -(GetScrollPosition().y);
crCurrentRect.OffsetRect(0, lOffset);
if ( m_fn_pclGetDocument()->m_pclSelectedActor != NULL )
{
CClientDC dc(this);
long lUpperLimit;
POSITION MiniStrucPos = pclList->GetHeadPosition();
while ( MiniStrucPos != NULL )
{
pclCurrentMiniStructure = pclList->GetNext(MiniStrucPos);
pclCurrentMiniStructure->m_fn_lMove(crCurrentRect);
crCurrentRect.OffsetRect(0, C_MS_LINE_HEIGHT + C_MS_SPACING);
if ( pclCurrentMiniStructure == pclMS )
lUpperLimit = crCurrentRect.top;
if ( pclCurrentMiniStructure->m_pclActorMS->m_fn_bIsOpen() )
{
lOffsetControls = pclCurrentMiniStructure->m_fn_lOpen(crCurrentRect);
crCurrentRect.OffsetRect(0, lOffsetControls + C_MS_SPACING);
}
else
{
if ( m_fn_pclGetDocument()->m_pclSelectedActor->m_fn_bIsAnInstance() )
{
if ( !(pclCurrentMiniStructure->m_pclActorMS->m_fn_bIsAllocated()) )
{
if ( m_fn_pclGetDocument()->m_bMustDisplayUnallocatedMS )
pclCurrentMiniStructure->m_fn_vClose();
else
pclCurrentMiniStructure->m_fn_vHideAllControls();
}
else
pclCurrentMiniStructure->m_fn_vClose();
}
else
pclCurrentMiniStructure->m_fn_vClose();
}
}
//Adjusts zone rectangle for MS according to new vertical scroll position
lOffset = (GetScrollPosition().y) - lOffset;
MiniStrucPos = pclList->GetHeadPosition();
while ( MiniStrucPos != NULL )
(pclList->GetNext(MiniStrucPos))->m_fn_vOffsetZone(lOffset);
//Repaints what is needed
if ( pclMS != NULL )
{
CRect crUpdateRegion;
crUpdateRegion = crCurrentRect;
crUpdateRegion.top = lUpperLimit;
InvalidateRect(crUpdateRegion);
}
else
InvalidateRect(NULL);
}
else
//if no selected actor
{
POSITION MiniStrucPos = pclList->GetHeadPosition();
while ( MiniStrucPos != NULL )
{
pclCurrentMiniStructure = pclList->GetNext(MiniStrucPos);
pclCurrentMiniStructure->m_fn_lMove(crCurrentRect);
crCurrentRect.OffsetRect(0, C_MS_LINE_HEIGHT + C_MS_SPACING);
pclCurrentMiniStructure->m_fn_vClose();
}
lOffsetControls = 0;
}
//Looks if scroll is possible
unsigned short uwNewViewHeigth = (unsigned short)(crCurrentRect.top + GetScrollPosition().y);
m_fn_vSetViewHeight(uwNewViewHeigth);
if(hashide)
ShowWindow(TRUE);
}//end of test 'pclList != NULL'
}
//*******************************************************************************
//Called (during motor for example) to update current data in editor
void EdActors_MiniStrucView::m_fn_vUpdateAllDatas()
{
EdActors_MiniStructureList *pclList = m_fn_pclGetDocument()->m_pclCurrentMiniStructureList;
if (pclList)
{
EdActors_MiniStructure *pclCurrentMiniStructure;
POSITION MiniStrucPos = pclList->GetHeadPosition();
while ( MiniStrucPos != NULL )
{
pclCurrentMiniStructure = pclList->GetNext(MiniStrucPos);
if ( pclCurrentMiniStructure->m_pclActorMS->m_tdeState == MS_STATE_DEVELOPPED )
pclCurrentMiniStructure->m_clControlList.m_pub_fn_vUpdateControlsWithEditedData(FALSE);
}
}
}
//*******************************************************************************
EdActors_MyDocument* EdActors_MiniStrucView::m_fn_pclGetDocument()
{
return &(g_pclInterface->m_clDocument);
}
//*******************************************************************************
void EdActors_MiniStrucView::OnTimer(UINT nIDEvent)
{
if ( m_ucTimerCounter < C_TIMER_COUNTER_MAX )
{
if ( m_ucTimerCounter % 2)
m_fn_vHighliteControl();
else
m_fn_vUnhighliteControl();
m_ucTimerCounter ++;
}
else
{
KillTimer(nIDEvent);
m_pclControlTimerSender = NULL;
m_ucTimerCounter = 0;
CClientDC dc(this);
dc.FrameRect(m_pclControlTimerSender->m_fn_crGetZoneRect(), &g_clBackgroundBrush);
}
CFormView::OnTimer(nIDEvent);
}
//*******************************************************************************
void EdActors_MiniStrucView::m_fn_vUnhighliteControl()
{
CClientDC dc(this);
dc.FrameRect(m_pclControlTimerSender->m_fn_crGetZoneRect(), &g_clRedBrush);
}
//*******************************************************************************
void EdActors_MiniStrucView::m_fn_vHighliteControl()
{
CClientDC dc(this);
dc.FrameRect(m_pclControlTimerSender->m_fn_crGetZoneRect(), &g_clGreenBrush);
}
//***************************************************************************
BOOL EdActors_MiniStrucView::OnHelpInfo(HELPINFO* pHelpInfo)
{
DWORD lHelpId = IDH_MS_VIEW;
UINT uiCommand = HELP_CONTEXT;
//If necessary, searches for the window under mouse
if ( !(g_pclInterface->m_clDocument.m_bMustDisplayHelpOnActiveView) )
{
CWnd *pclWindow = WindowFromPoint(pHelpInfo->MousePos);
if ( pclWindow == (CWnd *)g_pclInterface->m_clDocument.m_pclActorsView )
lHelpId = IDH_ACTORS_VIEW;
else if ( pclWindow == (CWnd *)g_pclInterface->m_clDocument.m_pclMiniStrucView )
lHelpId = IDH_MS_VIEW;
else
{
lHelpId = 0;
uiCommand = HELP_FINDER;
}
}
::WinHelp(m_hWnd,
LPCTSTR(g_pclInterface->m_clDocument.m_csHelpFileNameAndPath),
uiCommand,
lHelpId);
return FALSE;
}
//***************************************************************************
void EdActors_MiniStrucView::OnSize(UINT nType, int cx, int cy)
{
CTL_Editor_BaseFormView::OnSize(nType, cx, cy);
GetClientRect(m_crEditionRect);
m_crEditionRect.InflateRect(-C_MAIN_VIEW_SPACING, -C_MAIN_VIEW_SPACING);
m_fn_vUpdateTree();
}
//***************************************************************************
void EdActors_MiniStrucView::OnMouseMove(UINT nFlags, CPoint point)
{
if ( m_bMustDragData )
{
CPoint cpMyPoint = point;
ClientToScreen(&cpMyPoint);
BOOL bCanDropHere = ( (WindowFromPoint(cpMyPoint)->m_hWnd == WAW_fn_pclGetWatchWindowDialog()->m_hWnd)
|| (WindowFromPoint(cpMyPoint)->m_hWnd == WAW_fn_pclGetWatchWindowTree()->m_hWnd)
);
SetCursor(bCanDropHere ? m_pri_hDragCursor : m_pri_hDisabledDragCursor);
}
CTL_Editor_BaseFormView::OnMouseMove(nFlags, point);
}
//***************************************************************************
void EdActors_MiniStrucView::OnLButtonUp(UINT nFlags, CPoint point)
{
if ( m_bMustDragData )
{
CPoint cpMyPoint = point;
ClientToScreen(&cpMyPoint);
if ( (WindowFromPoint(cpMyPoint)->m_hWnd == WAW_fn_pclGetWatchWindowDialog()->m_hWnd)
|| (WindowFromPoint(cpMyPoint)->m_hWnd == WAW_fn_pclGetWatchWindowTree()->m_hWnd)
)
OAC_AddFieldInWatchWindow(m_pri_pclDataToDrop);
m_bMustDragData = FALSE;
m_pri_pclDataToDrop = NULL;
ReleaseCapture();
}
CTL_Editor_BaseFormView::OnLButtonUp(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
// EdActors_MiniStrucView diagnostics
//***************************************************************************
//***************************************************************************
//***************************************************************************
#ifdef _DEBUG
void EdActors_MiniStrucView::AssertValid() const
{
CTL_Editor_BaseFormView::AssertValid();
}
void EdActors_MiniStrucView::Dump(CDumpContext& dc) const
{
CTL_Editor_BaseFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// EdActors_MiniStrucView message handlers