//*****************************************************************************
//*  _zWList2.cpp                                                             *
//*****************************************************************************
//*                                                                           *
//* This file contains all the functions for the second list window           *
//*                                                                           *
//*****************************************************************************
//* Author : Alexis Vaisse                                                    *
//*****************************************************************************


// "standard" include
#include "stdafx.h"
#include "ACP_Base.h"
#define HieFriend
#define D_State_Define
#define D_ZdxStuff_StructureDefine
#include "IncGAM.h"
#include "IncITF.h"
#include "..\Main\Inc\_EditID.h"

// personal include
#include "_zRes.h"                                // File created by Microsoft Developer Studio
#include "_zWList1.hpp"
#include "_zWList2.hpp"
#include "_zWEdit.hpp"
#include "_zInterf.hpp"
#include "_zObject.hpp"
#include "_zModif.hpp"

#include "TFA.h"        // Family dll include    
#include "OAC.h"        // Actors dll include
#include "OPD.h"        // Physical Object dll include
#include "TUT.h"        // Tutorial dll include

class EdActors_EditorActorInstance;
class EdActors_EditorActorModel;
class CPA_Family;


#define  C_uiPopupMenuIDSetZdrToItself    3000
#define  C_uiPopupMenuIDSetZdrToAnotherPo 3001
#define  C_uiPopupMenuIDSetZdrToNothing   3002


//*****************************************************************************
// class CList2Window
//
// Window that shows different lists
//*****************************************************************************

#define M_List2GetListElementData(Item)  ((tdstListElementData *) m_List_Ctrl_2 . GetItemData (Item))
#define M_List2GetZDxObject(Item)       (((tdstListElementData *) m_List_Ctrl_2 . GetItemData (Item)) -> pZDxObject)
#define M_List2GetZDxSuperObject(Item)  (((tdstListElementData *) m_List_Ctrl_2 . GetItemData (Item)) -> pZDxSuperObject)

IMPLEMENT_DYNCREATE (CList2Window , CFormView)

#define  C_szNoZDxName   "-----------"
#define  C_szItselfName  "--Itself--"

//-----------------------------------------------------------------------------
// class CList2Window : constructor
//-----------------------------------------------------------------------------
CList2Window::CList2Window (CWnd * pParent)
	: CFormView (CList2Window::IDD)
{
	//{{AFX_DATA_INIT(CList2Window)
	m_bShowZDD = FALSE;
	m_bShowZDE = FALSE;
	m_bShowZDM = FALSE;
	m_bShowZDR = FALSE;
	m_Combo_Box_String_List = _T("");
	//}}AFX_DATA_INIT

    // Init the variables
    m_bIsCreatingList       = FALSE;
    m_bIsSelectingZDx       = FALSE;
    m_bIsInsideOnHasChanged = FALSE;
    m_bMustUpdateDisplay    = FALSE;
    m_bShowZDD              =
    m_bShowZDE              =
    m_bShowZDM              =
    m_bShowZDR              = TRUE;
    m_pListOfZdd            =
    m_pListOfZde            =
    m_pListOfZdm            =
    m_pListOfZdr            = NULL;
    m_pZdd                  =
    m_pZde                  =
    m_pZdm                  =
    m_pZdr                  = NULL;
    m_pActor                = NULL;
    m_pActorSuperObject     = NULL;
    m_pModule               = NULL;
    m_pModuleSuperObject    = NULL;
    m_bRightDragAndDrop     = FALSE;
    m_bIsSelectingPoAsZdr   = FALSE;

    m_pZDxInterface         = NULL;

}

//-----------------------------------------------------------------------------
// class CList2Window : general functions
//-----------------------------------------------------------------------------
void CList2Window::DoDataExchange (CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CList2Window)
	DDX_Control(pDX, IDC_Combo_Box_List, m_Combo_Box_List);
	DDX_Control(pDX, IDC_List_Ctrl_2, m_List_Ctrl_2);
	DDX_Check(pDX, IDC_Check_Box_ZDD, m_bShowZDD);
	DDX_Check(pDX, IDC_Check_Box_ZDE, m_bShowZDE);
	DDX_Check(pDX, IDC_Check_Box_ZDM, m_bShowZDM);
	DDX_Check(pDX, IDC_Check_Box_ZDR, m_bShowZDR);
	DDX_CBString(pDX, IDC_Combo_Box_List, m_Combo_Box_String_List);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP (CList2Window, CFormView)
	//{{AFX_MSG_MAP(CList2Window)
	ON_WM_DRAWITEM()
	ON_BN_CLICKED(IDC_Button_All_ZDx, On_Button_All_ZDx)
    ON_BN_CLICKED(IDC_Button_No_ZDx, On_Button_No_ZDx)
    ON_BN_CLICKED(IDC_Button_New_List, On_Button_New_List)
	ON_BN_CLICKED(IDC_Check_Box_ZDD, On_Check_Boxes_ZDx)
	ON_LBN_SELCHANGE(IDC_List_Ctrl_2, On_Selection_Has_Changed_List_Ctrl_2)
	ON_WM_SIZE()
	ON_WM_MOUSEMOVE()
	ON_CBN_SELCHANGE(IDC_Combo_Box_List, On_Selection_Has_Changed_Combo_Box_List)
	ON_WM_RBUTTONUP()
	ON_BN_CLICKED(IDC_Check_Box_ZDE, On_Check_Boxes_ZDx)
	ON_BN_CLICKED(IDC_Check_Box_ZDM, On_Check_Boxes_ZDx)
	ON_BN_CLICKED(IDC_Check_Box_ZDR, On_Check_Boxes_ZDx)
	//}}AFX_MSG_MAP
    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, SetToolTipText)
END_MESSAGE_MAP ()

//-----------------------------------------------------------------------------
// class CList2Window - Create
// init the window
//-----------------------------------------------------------------------------
BOOL CList2Window::Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
    // Call the standard create. Return TRUE if Ok
	if (CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
    {
        // To call DoDataExchange
        UpdateData (FALSE);

        m_hCursorDragAndDrop   = M_GetMainApp () -> LoadCursor (IDC_Cursor_Drag_And_Drop);
        m_hCursorNoDragAndDrop = M_GetMainApp () -> LoadCursor (IDC_Cursor_No_Drag_And_Drop);

        m_hIconCommon          = M_GetMainApp () -> LoadIcon   (IDI_Icon_Common_Mode);
        m_hIconShared          = M_GetMainApp () -> LoadIcon   (IDI_Icon_Shared_Mode);
        m_hIconVirge           = M_GetMainApp () -> LoadIcon   (IDI_Icon_Virge_Mode );
        m_hIconMotorDisplayOn  = M_GetMainApp () -> LoadIcon   (IDI_Icon_Motor_Display_On);
        m_hIconMotorDisplayOff = M_GetMainApp () -> LoadIcon   (IDI_Icon_Motor_Display_Off);

        // Init icons for the list
        m_stImageList . Create       (16 , 16 , FALSE, 0, 10);
        m_stImageList . Add          (M_GetMainApp () -> LoadIcon (IDI_Icon_Common_Mode    ));
        m_stImageList . Add          (M_GetMainApp () -> LoadIcon (IDI_Icon_Shared_Mode    ));
        m_stImageList . Add          (M_GetMainApp () -> LoadIcon (IDI_Icon_Virge_Mode     ));

        // Init tooltip control
        m_ToolTipCtrl . Create   (this , WS_VISIBLE | TTS_ALWAYSTIP);
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_Check_Box_ZDD  ));
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_Check_Box_ZDE  ));
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_Check_Box_ZDM  ));
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_Check_Box_ZDR  ));
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_Button_All_ZDx ));
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_List_Ctrl_2    ));
        m_ToolTipCtrl . AddTool  (GetDlgItem (IDC_Button_New_List));
        m_ToolTipCtrl . Activate (TRUE);
        EnableToolTips ();

        // Register controls for the tutorial
        TUT_M_vGetTutDll ();
        TUT_M_vRegisterControlID (IDC_Check_Box_ZDD   , "TUT_ZDD"            , TUT_e_Button);
        TUT_M_vRegisterControlID (IDC_Check_Box_ZDE   , "TUT_ZDE"            , TUT_e_Button);
        TUT_M_vRegisterControlID (IDC_Check_Box_ZDM   , "TUT_ZDM"            , TUT_e_Button);
        TUT_M_vRegisterControlID (IDC_Check_Box_ZDR   , "TUT_ZDR"            , TUT_e_Button);
        TUT_M_vRegisterControlID (IDC_Button_All_ZDx  , "TUT_All"            , TUT_e_Button);
        TUT_M_vRegisterControlID (IDC_Combo_Box_List  , "TUT_List2ComboBox"  , TUT_e_ComboBox);
        TUT_M_vRegisterControlID (IDC_Button_New_List , "TUT_New"            , TUT_e_Button);
        TUT_M_vRegisterControlID (IDC_List_Ctrl_2     , "TUT_List2"          , TUT_e_ListBox);

        return TRUE;
    }
    else return FALSE;
}

//-----------------------------------------------------------------------------
// class CList2Window - MoveWindow
// Used to move a control into the CList2Window
//-----------------------------------------------------------------------------
void CList2Window::MoveWindow (CWnd * _pWindow, int _TranslationX , int _TranslationY)
{
    RECT  Pos;
    _pWindow -> GetWindowRect (& Pos);
    ScreenToClient            (& Pos);

    Pos . left   += _TranslationX;
    Pos . right  += _TranslationX;
    Pos . top    += _TranslationY;
    Pos . bottom += _TranslationY;

    _pWindow -> MoveWindow (& Pos);
}

//-----------------------------------------------------------------------------
// class CList2Window - OnSize
// called when the window is resized : we change the size of the elements
//-----------------------------------------------------------------------------
void CList2Window::OnSize (UINT nType, int cx, int cy) 
{
	CFormView::OnSize (nType, cx, cy);

    RECT WindowPos;
    GetClientRect (& WindowPos);

    // Set the size of the list
    if (m_List_Ctrl_2 . m_hWnd)
    {
        RECT ListPos;
        m_List_Ctrl_2 . GetWindowRect (& ListPos);
        ScreenToClient                (& ListPos);
        ListPos . right = WindowPos . right;
        ListPos. bottom = WindowPos . bottom;
        m_List_Ctrl_2 . MoveWindow (& ListPos);
    }

    // Set the position of the New button, if it must be visible
    CWnd * pNewButton = GetDlgItem (IDC_Button_New_List);
    if (pNewButton && pNewButton -> m_hWnd)
    {
// ANNECY AV CLEAN_MEC {
/*
        if (m_pZDxInterface && m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint ())
        {
            pNewButton -> ShowWindow (TRUE);
            RECT ButtonPos;
            pNewButton -> GetWindowRect (& ButtonPos);
            ScreenToClient              (& ButtonPos);
            MoveWindow (pNewButton , WindowPos . right - ButtonPos . right , 0);
        }
        else
*/
        pNewButton -> ShowWindow (FALSE);
// END ANNECY AV }
    }

    // Set the size of the combo box
    if (m_Combo_Box_List . m_hWnd)
    {
        RECT ComboPos;
        m_Combo_Box_List . GetWindowRect (& ComboPos);
        ScreenToClient                   (& ComboPos);

// ANNECY AV CLEAN_MEC {
/*
        if (m_pZDxInterface && m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint ())
        {
            RECT ButtonPos;
            pNewButton -> GetWindowRect (& ButtonPos);
            ScreenToClient              (& ButtonPos);
            ComboPos . right = ButtonPos. left - 5;
        }
        else
*/
        ComboPos . right = WindowPos . right;
// END ANNECY AV }

        m_Combo_Box_List . MoveWindow (& ComboPos);
    }
}

//-----------------------------------------------------------------------------
// class CList1Window - DrawLineInList
// Draw one line of the list
//-----------------------------------------------------------------------------
void CList2Window::DrawLineInList (LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    CDC                 * pDC              = CDC::FromHandle (lpDrawItemStruct -> hDC);               // Get the drawing device
    RECT                  Pos              = lpDrawItemStruct -> rcItem;                              // Get the position to draw
    tdstListElementData * pListElementData = M_List2GetListElementData (lpDrawItemStruct -> itemID);  // Get the tdstListElementData
    if (pListElementData == NULL || (long) pListElementData == -1)  return;
    ZDx_Object          * pZDxObject       = pListElementData -> pZDxObject;
    BOOL                  bSelected        = lpDrawItemStruct -> itemState & ODS_SELECTED;            // Get if the line is selected or not

    pDC -> SetMapMode (MM_TEXT);
    // Select colors
    pDC -> FillSolidRect (& lpDrawItemStruct -> rcItem , 
                          GetSysColor (bSelected ? COLOR_HIGHLIGHT : COLOR_WINDOW));
    pDC -> SetBkMode     (TRANSPARENT);

    // Draw the icon for shared mode
    tdeSharedMode eSharedMode = pListElementData -> eSharedMode;
    if (eSharedMode != eNoSharedMode)
    {
        HICON hIconToDraw;
        switch (eSharedMode)
        {
            case eCommon  : hIconToDraw = m_hIconCommon;    break;
            case eShared  : hIconToDraw = m_hIconShared;    break;
            case eVirge   : hIconToDraw = m_hIconVirge;     break;
            default       : ASSERT (0);
        }
        pDC -> DrawIcon (Pos . left , Pos . top , hIconToDraw);
    }

    // Draw the icon for motor display
    if (pZDxObject && eSharedMode != eNoSharedMode)
    {
        HICON hIconToDraw;
        if (pZDxObject -> GetMotorDisplay ())  hIconToDraw = m_hIconMotorDisplayOn;
                                          else hIconToDraw = m_hIconMotorDisplayOff;
        pDC -> DrawIcon (Pos . right - 16 , Pos . top , hIconToDraw);
    }

    // We compute the position for the type name
    RECT PosType;
    PosType . left   = Pos . left + 20;
    PosType . right  = Pos . left + 50;
    PosType . top    = Pos . top;
    PosType . bottom = Pos . bottom;

    // We compute the position for the first name
    RECT Pos1;
    Pos1 . left   = Pos . left + 50;
    Pos1 . right  = (Pos . left + 50 + Pos . right - 20) / 2 - 3;
    Pos1 . top    = Pos . top;
    Pos1 . bottom = Pos . bottom;

    // We compute the position for the second name
    RECT Pos2;
    Pos2 . left   = (Pos . left + 50 + Pos . right - 20) / 2 + 3;
    Pos2 . right  = Pos . right - 20;
    Pos2 . top    = Pos . top;
    Pos2 . bottom = Pos . bottom;

    // Write the type if we are editing the zones of actor
    pDC -> SetTextColor  (GetSysColor (bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_GRAYTEXT));
    if (m_pActor)
    {
        char * szName;
        switch (pListElementData -> eType)
        {
            case eZddElement             : szName = C_szZddName;    break;
            case eZdeElement             : szName = C_szZdeName;    break;
            case eZdmElement             : szName = C_szZdmName;    break;
            case eZdrElement             : szName = C_szZdrName;    break;
            case eBoundingVolumeElement  : szName = "";             break;
// ANNECY AV CLEAN_MEC {
//            case eTestPointElement       : szName = "";             break;
// END ANNECY AV }
            default                      : return;//???ASSERT (0);
        }
        pDC -> DrawText (szName , -1 , & PosType , DT_SINGLELINE | DT_LEFT | DT_VCENTER);
    }

    // Write the name in the name list
    pDC -> SetTextColor  (GetSysColor (bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
    pDC -> DrawText ((char *) (LPCTSTR) pListElementData -> csNameInNameList , -1 , & Pos1 , DT_SINGLELINE | DT_LEFT |DT_VCENTER);

    // Draw the second name
    char * szName = C_szNoZDxName;
    if (pZDxObject)  szName = (char *) (LPCTSTR) pZDxObject -> GetName ();
    else
    if (pListElementData -> eType == eZdrElement && m_pModule)
    {
        CPA_BaseObject * pZdr = m_pModule -> GetZone (C_ucTypeZdr);
        if (pZdr)
        {
            ASSERT (pZdr -> fn_bIsOfType (C_szPhysicalObjectTypeName));

            if (pZdr == m_pModule)  szName = C_szItselfName;
                              else  szName = (char *) (LPCTSTR) pZdr -> GetName ();
        }
    }
    pDC -> DrawText (szName , -1 , & Pos2 , DT_SINGLELINE | DT_LEFT | DT_VCENTER);
}

//-----------------------------------------------------------------------------
// class CList2Window - OnDrawItem
// Called when something need to be redrawed.
// We used to draw the list
//-----------------------------------------------------------------------------
void CList2Window::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    switch (nIDCtl)
    {
    case IDC_List_Ctrl_2 : if (m_List_Ctrl_2 . IsWindowEnabled ())  DrawLineInList (lpDrawItemStruct);
                                                              else  CFormView::OnDrawItem (nIDCtl , lpDrawItemStruct);
                           break;

    default              : CFormView::OnDrawItem (nIDCtl , lpDrawItemStruct);
                           break;
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - On_Check_Boxes_ZDx
// Called when one clicks on a check box ZDx (ZDD, ZDE, ZDM or ZDR)
//-----------------------------------------------------------------------------
void CList2Window::On_Check_Boxes_ZDx ()
{
    m_pZDxInterface -> IWillRefreshDisplay (C_lOnCheckBoxesZDx);

    // If we were editing the bouding volume, we leave the edition
    if (m_pZDxInterface -> GetList1Window () -> IsEditingBoundingVolume ())
        m_pZDxInterface -> GetList1Window () -> LeaveEditionOfBoundingVolume ();
// ANNECY AV CLEAN_MEC {
/*
    else
    if (m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint      ())
        m_pZDxInterface -> GetList1Window () -> LeaveEditionOfTestPoint      ();
*/
// END ANNECY AV }

    UpdateData        (TRUE);            // Update the variables from screen
    ReCreateListOfZDx (FALSE , FALSE);   // Compute the list of ZDx again

    // Refresh the display of the ZDx object
    ZDx_Object * pSelectedZDxObject = GetSelectedZDx ();
    if (m_pActorSuperObject)  m_pZDxInterface -> ShowZDxOfActor  (m_pActorSuperObject  , GetZDxTypeToShow () , pSelectedZDxObject);
    else
    if (m_pModuleSuperObject) m_pZDxInterface -> ShowZDxOfModule (m_pModuleSuperObject , GetZDxTypeToShow () , pSelectedZDxObject);

    m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());

    FillComboBoxListWithSelection ();    // Fill the combo box

    m_pZDxInterface -> RefreshDisplay (C_lOnCheckBoxesZDx);
}

//-----------------------------------------------------------------------------
// class CList2Window - On_Button_All_ZDx
// Called when one clicks on the All ZDx button
//-----------------------------------------------------------------------------
void CList2Window::On_Button_All_ZDx ()
{
    // We do nothing if there is no ZDx object to edit
    if (m_pActor == NULL)  return;

    m_pZDxInterface -> IWillRefreshDisplay (C_lOnButtonAllZDx);

    // If we were editing the bouding volume, we leave the edition
    if (m_pZDxInterface -> GetList1Window () -> IsEditingBoundingVolume ())
        m_pZDxInterface -> GetList1Window () -> LeaveEditionOfBoundingVolume ();
// ANNECY AV CLEAN_MEC {
/*
    else
    if (m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint      ())
        m_pZDxInterface -> GetList1Window () -> LeaveEditionOfTestPoint      ();
*/
// END ANNECY AV }

    UpdateData        (TRUE);             // Update the variables from screen
    if (GetDlgItem (IDC_Check_Box_ZDD) -> IsWindowEnabled ())  m_bShowZDD = TRUE;
    if (GetDlgItem (IDC_Check_Box_ZDE) -> IsWindowEnabled ())  m_bShowZDE = TRUE;
    if (GetDlgItem (IDC_Check_Box_ZDM) -> IsWindowEnabled ())  m_bShowZDM = TRUE;
    if (GetDlgItem (IDC_Check_Box_ZDR) -> IsWindowEnabled ())  m_bShowZDR = TRUE;
    UpdateData        (FALSE);            // Update the screen
    ReCreateListOfZDx (FALSE , FALSE);    // Compute the list of ZDx again

    // Set the display flag to TRUE for all ZDx object
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        ZDx_Object          * pZDxObject = M_List2GetZDxObject (Item);
        if (pZDxObject)  pZDxObject -> SetMotorDisplay (TRUE);
    }
    ReCreateListOfZDx (FALSE , FALSE);    // Compute the list of ZDx again with correct display flags

    // Refresh the display of the ZDx object
    ZDx_Object * pSelectedZDxObject = GetSelectedZDx ();

    if (m_pActorSuperObject)  m_pZDxInterface -> ShowZDxOfActor  (m_pActorSuperObject  , GetZDxTypeToShow () , pSelectedZDxObject);
    else
    if (m_pModuleSuperObject) m_pZDxInterface -> ShowZDxOfModule (m_pModuleSuperObject , GetZDxTypeToShow () , pSelectedZDxObject);

    m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());

    FillComboBoxListWithSelection ();    // Fill the combo box

    m_pZDxInterface -> RefreshDisplay (C_lOnButtonAllZDx);
}

//-----------------------------------------------------------------------------
// class CList2Window - On_Button_No_ZDx
// Called when one clicks on the No ZDx button
//-----------------------------------------------------------------------------
void CList2Window::On_Button_No_ZDx ()
{
    // We do nothing if there is no ZDx object to edit
    if (m_pActor == NULL)  return;

    m_pZDxInterface -> IWillRefreshDisplay (C_lOnButtonAllZDx);

    // If we were editing the bouding volume, we leave the edition
    if (m_pZDxInterface -> GetList1Window () -> IsEditingBoundingVolume ())
        m_pZDxInterface -> GetList1Window () -> LeaveEditionOfBoundingVolume ();
// ANNECY AV CLEAN_MEC {
/*
    else
    if (m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint      ())
        m_pZDxInterface -> GetList1Window () -> LeaveEditionOfTestPoint      ();
*/
// END ANNECY AV }

    UpdateData        (TRUE);             // Update the variables from screen
    if (GetDlgItem (IDC_Check_Box_ZDD) -> IsWindowEnabled ())  m_bShowZDD = TRUE;
    if (GetDlgItem (IDC_Check_Box_ZDE) -> IsWindowEnabled ())  m_bShowZDE = TRUE;
    if (GetDlgItem (IDC_Check_Box_ZDM) -> IsWindowEnabled ())  m_bShowZDM = TRUE;
    if (GetDlgItem (IDC_Check_Box_ZDR) -> IsWindowEnabled ())  m_bShowZDR = TRUE;
    UpdateData        (FALSE);            // Update the screen
    ReCreateListOfZDx (FALSE , FALSE);    // Compute the list of ZDx again

    // Set the display flag to FALSE for all ZDx object
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        ZDx_Object          * pZDxObject = M_List2GetZDxObject (Item);
        if (pZDxObject)  pZDxObject -> SetMotorDisplay (FALSE);
    }
    ReCreateListOfZDx (FALSE , FALSE);    // Compute the list of ZDx again with correct display flags

    // Refresh the display of the ZDx object
    ZDx_Object * pSelectedZDxObject = GetSelectedZDx ();

    if (m_pActorSuperObject)  m_pZDxInterface -> ShowZDxOfActor  (m_pActorSuperObject  , GetZDxTypeToShow () , pSelectedZDxObject);
    else
    if (m_pModuleSuperObject) m_pZDxInterface -> ShowZDxOfModule (m_pModuleSuperObject , GetZDxTypeToShow () , pSelectedZDxObject);

    m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());

    FillComboBoxListWithSelection ();    // Fill the combo box

    m_pZDxInterface -> RefreshDisplay (C_lOnButtonAllZDx);
}

//-----------------------------------------------------------------------------
// class CList2Window - On_Button_New_List
// Called when one clicks on the New List button
//-----------------------------------------------------------------------------
void CList2Window::On_Button_New_List ()
{
// ANNECY AV CLEAN_MEC {
/*
    // We get the Family tool dll
    CPA_ToolDLLBase * pFamilyDll = m_pZDxInterface -> GetMainWorld () -> GetToolDLLWithName (C_szDLLFamilyName);
    // Ask the Family dll to create a new CPA_TestPointsList
    CPA_TestPointsList * pNewTestPointList =
        (CPA_TestPointsList *) pFamilyDll -> OnQueryAction (m_pZDxInterface , C_uiCreateTPList , (LPARAM) m_pActor -> GetOwner () -> GetOwner ());

    CreateListOfTestPoint (m_pActorSuperObject , pNewTestPointList);
*/
// END ANNECY AV }
}

//-----------------------------------------------------------------------------
// class CList2Window - SetZDxCheckBoxes
// This set the ZDx check boxes
//-----------------------------------------------------------------------------
void CList2Window::SetZDxCheckBoxes (tdeZDxType _eZDxTypeToShow)
{
    m_bShowZDD = _eZDxTypeToShow == eZdd;
    m_bShowZDE = _eZDxTypeToShow == eZde;
    m_bShowZDM = _eZDxTypeToShow == eZdm;
    m_bShowZDR = _eZDxTypeToShow == eZdr;

    GetDlgItem (IDC_Check_Box_ZDD) -> EnableWindow (m_bShowZDD);
    GetDlgItem (IDC_Check_Box_ZDE) -> EnableWindow (m_bShowZDE);
    GetDlgItem (IDC_Check_Box_ZDM) -> EnableWindow (m_bShowZDM);
    GetDlgItem (IDC_Check_Box_ZDR) -> EnableWindow (m_bShowZDR);

    UpdateData (FALSE);
}

//-----------------------------------------------------------------------------
// class CList2Window - SetZDxCheckBoxes
// This set the ZDx check boxes
//-----------------------------------------------------------------------------
void CList2Window::SetZDxCheckBoxes (BOOL _bShowZDD , BOOL _bShowZDE , BOOL _bShowZDM , BOOL _bShowZDR)
{
    m_bShowZDD = _bShowZDD;
    m_bShowZDE = _bShowZDE;
    m_bShowZDM = _bShowZDM;
    m_bShowZDR = _bShowZDR;

    GetDlgItem (IDC_Check_Box_ZDD) -> EnableWindow (m_bShowZDD);
    GetDlgItem (IDC_Check_Box_ZDE) -> EnableWindow (m_bShowZDE);
    GetDlgItem (IDC_Check_Box_ZDM) -> EnableWindow (m_bShowZDM);
    GetDlgItem (IDC_Check_Box_ZDR) -> EnableWindow (m_bShowZDR);

    UpdateData (FALSE);
}

//-----------------------------------------------------------------------------
// class CList2Window - On_Selection_Has_Changed_List_Ctrl_2
// Called when the selection has changed in the tree
//-----------------------------------------------------------------------------
void CList2Window::On_Selection_Has_Changed_List_Ctrl_2 (/*NMHDR * pNMHDR , LRESULT * pResult*/) 
{
    // Accept the selection
	/** pResult = 0;*/

    // If a list is been creating, or if there is a drag and drop, or if it is a recursiv call, we don't do anything
    if (m_bIsCreatingList || m_bRightDragAndDrop || m_bIsInsideOnHasChanged)  return;

    m_pZDxInterface -> IWillRefreshDisplay (C_lOnSelChangeTreeCtrl2);
    m_bIsInsideOnHasChanged = TRUE;

    // Get the selected item
    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();
    if (SelectedItem != -1)
    {
        // Get the element data
        tdstListElementData * pListElementData = M_List2GetListElementData (SelectedItem);
        if (pListElementData)
        {
            // Get the selected ZDx object
            ZDx_Object * pZDxObject = pListElementData -> pZDxObject;

            // Show the ZDx object with the "selected" style
            if (pZDxObject)
            {
                if (pZDxObject -> GetZDxType () == eBoundingVolume) ; // The bounding volume is already displayed : we do nothing
                else
                if (m_pActorSuperObject)
                {
                    m_pZDxInterface -> ShowZDxOfActor  (m_pActorSuperObject  , GetZDxTypeToShow () , pZDxObject);
                    // Put the correct ZDx super object
                    pListElementData -> pZDxSuperObject = m_pZDxInterface -> GetZDxSuperObject (pZDxObject , m_pActorSuperObject);
                }
                else
                if (m_pModuleSuperObject) m_pZDxInterface -> ShowZDxOfModule (m_pModuleSuperObject , GetZDxTypeToShow () , pZDxObject);
                m_bMustUpdateDisplay = TRUE;
            }

            // Select the ZDx object in the edit window
            m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (pListElementData -> pZDxSuperObject);

            SetFocus ();    // To be sure that the list has the focus when one selects a zone into it

// ANNECY AV CLEAN_MEC {
//            if (! m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint ())
// END ANNECY AV }
                FillComboBoxListWithSelection ();    // Fill the combo box list

            // If we are editing a ZDx of module, we select the same ZDx in the list 1
            if (m_pModule && pZDxObject)
            {
                m_bIsSelectingZDx = TRUE;
                m_pZDxInterface -> GetList1Window () -> SelectZDxOfModule (m_pModule , pZDxObject , FALSE);
                m_bIsSelectingZDx = FALSE;
            }
        }
    }

    m_pZDxInterface -> RefreshDisplay (C_lOnSelChangeTreeCtrl2 , m_bMustUpdateDisplay);
    m_bMustUpdateDisplay    = FALSE;

    m_bIsInsideOnHasChanged = FALSE;
}

//-----------------------------------------------------------------------------
// class CList2Window - GetToolTipTexForList
// Get the text that will be shown in a tool tip for the list
//-----------------------------------------------------------------------------
char * CList2Window::GetToolTipTextForList ()
{
    POINT CursorPos;
    GetCursorPos                   (& CursorPos);

    m_List_Ctrl_2 . ScreenToClient (& CursorPos);

    // We get the item under the mouse cursor
    BOOL   bOutside;
    int Item = m_List_Ctrl_2 . ItemFromPoint (CursorPos , bOutside);
    if (bOutside)  return NULL;

    RECT Pos;
    m_List_Ctrl_2 . GetItemRect (Item , & Pos);

    // Is the left icon pointed ?
    if (CursorPos . x < Pos . left + 16)              return "Shared mode";

    // Is the right icon pointed ?
    if (CursorPos . x > Pos . right - 16)
    {
        ZDx_Object * pZDxObject = M_List2GetZDxObject (Item);
        if (pZDxObject)
        {
            if (pZDxObject -> GetMotorDisplay ())  return "Hide zone when playing";
                                              else return "Show zone when playing";
        }
        else return "";
    }

    // Is the ZDx type pointed ?
    if (CursorPos . x < Pos . left + 50)  return "Zone type";

    // Is the name in the name list or the name of the ZDx object pointed ?
    if (CursorPos . x < (Pos . left + 50 + Pos . right - 20) / 2)  return "Name from list for IA";
                                                              else return "Zone name";
}

//-----------------------------------------------------------------------------
// class CList2Window - SetTextForToolTip
// Get the text that will be shown in a tool tip
//-----------------------------------------------------------------------------
BOOL CList2Window::SetToolTipText (UINT uiControlId , NMHDR * pNMHDR , LRESULT * pResult)
{
    LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT) pNMHDR;
	uiControlId                 = ::GetDlgCtrlID ((HWND) pNMHDR -> idFrom);

    switch (uiControlId)
    {
        case IDC_Check_Box_ZDD       : if (m_bShowZDD)  lpToolTipText -> lpszText = "Hide ZDD";
                                                   else lpToolTipText -> lpszText = "Show ZDD";
                                       break;
        case IDC_Check_Box_ZDE       : if (m_bShowZDE)  lpToolTipText -> lpszText = "Hide ZDE";
                                                   else lpToolTipText -> lpszText = "Show ZDE";
                                       break;
        case IDC_Check_Box_ZDM       : if (m_bShowZDM)  lpToolTipText -> lpszText = "Hide ZDM";
                                                   else lpToolTipText -> lpszText = "Show ZDM";
                                       break;
        case IDC_Check_Box_ZDR       : if (m_bShowZDR)  lpToolTipText -> lpszText = "Hide ZDR";
                                                   else lpToolTipText -> lpszText = "Show ZDR";
                                       break;
        case IDC_Button_All_ZDx      : lpToolTipText -> lpszText = "Show all zones";             break;
        case IDC_List_Ctrl_2         : lpToolTipText -> lpszText = GetToolTipTextForList ();     break;
        case IDC_Button_New_List     : lpToolTipText -> lpszText = "Create new test point list"; break;

        default                      : lpToolTipText -> lpszText = "";                           break;
    }

    return TRUE;
}

//-----------------------------------------------------------------------------
// class CList2Window - PreTranslateMessage
// We intercept some messages
//-----------------------------------------------------------------------------
BOOL CList2Window::PreTranslateMessage (MSG * pMsg) 
{
    switch (pMsg -> message)
    {
        case WM_LBUTTONDOWN :
        case WM_MOUSEMOVE   :
        case WM_LBUTTONUP   :
        case WM_RBUTTONDOWN :
        case WM_MBUTTONDOWN :
        case WM_RBUTTONUP   :
        case WM_MBUTTONUP   :  m_ToolTipCtrl . RelayEvent (pMsg);
                               break;

        case WM_KEYDOWN     :  if (pMsg -> wParam == VK_DELETE)
                               {
                                   DeleteZDx ();
                                   return TRUE;    // We have used the message
                               }
                               break;
    }

    switch (pMsg -> message)
    {
         case WM_LBUTTONDOWN : // We intercept the LButtonDown message for the list box
                               if (pMsg -> hwnd == m_List_Ctrl_2 . m_hWnd || m_bIsSelectingPoAsZdr)
                                   OnLButtonDown (0, pMsg->pt);
                               break;

         case WM_RBUTTONDOWN : // We intercept the RButtonDown message for the list box
                               if (pMsg -> hwnd == m_List_Ctrl_2 . m_hWnd)  OnRButtonDown (0, pMsg->pt);
                               break;

         case WM_RBUTTONUP   : // We intercept the RButtonUp   message for the list box
                               if (pMsg -> hwnd == m_List_Ctrl_2 . m_hWnd)  OnRButtonUp   (0, pMsg->pt);
                               break;
    }

    return CFormView::PreTranslateMessage(pMsg);
}

//-----------------------------------------------------------------------------
// class CList2Window - OnLButtonDown
// We check if the user clic on the motor display check box
//-----------------------------------------------------------------------------
void CList2Window::OnLButtonDown (UINT, CPoint pt) 
{
    if (m_bIsSelectingPoAsZdr)
    {
        CPoint PosCursor = pt;
        if (PosCursor . x > 60000)  PosCursor . x -= 65536;
        if (PosCursor . y > 60000)  PosCursor . y -= 65536;
        ClientToScreen (& PosCursor);
        // Coordinate in client coordinate of the 3d view
        m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetFocusDevice () -> ScreenToClient (& PosCursor);

		CRect clientRect;
		m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetFocusDevice () ->GetClientRect(clientRect);
		if((PosCursor.x < 0) || (PosCursor.y < 0) || (PosCursor.x >= clientRect.right) || (PosCursor.y >= clientRect.bottom))
			return;

      	if (GLI_lWhatIsGLI () == GLI_C_VersionGlide)  
            ((DEV_ViewPort3D *) m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetFocusDevice () -> GetViewPort ()) -> ClientToVoodoo (PosCursor);

        tdstMousePos stMousePos;
        stMousePos . stPos          = PosCursor;
        stMousePos . stPos2D . xX   = (float) PosCursor . x;
        stMousePos . stPos2D . xY   = (float) PosCursor . y;
        stMousePos . stPos2D . xOoZ = 0.0;
        MTH3D_M_vNullVector (& stMousePos . stPos3D);
        // Get the T3D tool dll
        CPA_ToolDLLBase * pT3dDll = m_pZDxInterface -> GetMainWorld () -> GetToolDLLWithName (C_szDLLTool3DName);
        ASSERT (pT3dDll);    // It must be there

        // Get the pointed super object
        CPA_SuperObject * pSuperObject = (CPA_SuperObject *) pT3dDll -> OnQueryInfos (m_pZDxInterface , C_wTool3D_QI_GetSOOnGrid , (LPARAM) & stMousePos);
        CPA_BaseObject  * pObject      = pSuperObject ? pSuperObject -> GetObject () : NULL;
        // Check if it is a module
        if (pObject && pObject -> fn_bIsOfType (C_szPhysicalObjectTypeName) == FALSE)  pObject = FALSE;

        if (pObject)
		{
			m_pModule -> SetZone (C_ucTypeZdr , pObject);    // Set the zdr of the module
			ACP_tdxHandleOfObject hObject = (ACP_tdxHandleOfObject)((CPA_BaseObject*)((EditorPO*)pObject) -> m_fnp_oGetGeometricWithDistance(0)) -> GetData();
			GEO_vCreateObjectListOfPointsMaterial( hObject );
			GEO_vComputeObjectListOfPointsMaterial( hObject );

			m_List_Ctrl_2 . Invalidate ();                   // Redraw the list

			ReleaseCapture ();                               // Release the mouse
			m_bIsSelectingPoAsZdr = FALSE;
		}
    }

    // Only ZDx of actor can use display check box
    if (m_pZDxInterface -> GetList1Window () -> IsEditingBoundingVolume ()
// ANNECY AV CLEAN_MEC {
//     || m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint      ()
// END ANNECY AV }
     || m_pZDxInterface -> GetList1Window () -> IsEditingZDxOfModule    ())  return;

    // We get the coordinates of the mouse cursor
    POINT PosCursor = pt;

    // We get the item under the mouse cursor
    BOOL   bOutside;
    int Item = m_List_Ctrl_2 . ItemFromPoint (PosCursor , bOutside);
    if (! bOutside)
    {
        RECT Pos;
        m_List_Ctrl_2 . GetItemRect (Item , & Pos);

        // We compute the position of the check box
        int CheckBoxCenterX = Pos . right - 8;
        int CheckBoxCenterY = Pos . top   + 8;

        // If the user has clicked into the check box, we check the flag of the ZDx
        if (PosCursor . x >= CheckBoxCenterX - 7 && PosCursor . x <= CheckBoxCenterX + 7 &&
            PosCursor . y >= CheckBoxCenterY - 7 && PosCursor . y <= CheckBoxCenterY + 7)
        {
            m_pZDxInterface -> IWillRefreshDisplay (C_lLButtonDown);

            ZDx_Object * pZDxObject = M_List2GetZDxObject (Item);
            if (pZDxObject)  pZDxObject -> SetMotorDisplay (pZDxObject -> GetMotorDisplay () ? FALSE : TRUE);
            m_List_Ctrl_2 . InvalidateRect (& Pos);    // Ask to redraw the line

            // If the zones of other actors are displayed, we must display them again
            CDisplayControlWindow * pDisplayControlWindow = m_pZDxInterface -> GetDisplayControlWindow ();
            if (pDisplayControlWindow -> GetDisplayForAllActors () != eOff)
                pDisplayControlWindow -> DisplayAllActors ();

            m_pZDxInterface -> RefreshDisplay (C_lLButtonDown , FALSE);    // It will be refreshed later
        }
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - OnRButtonDown
// We begin a right drag and drop
//-----------------------------------------------------------------------------
void CList2Window::OnRButtonDown (UINT, CPoint pt) 
{
// ANNECY AV CLEAN_MEC {
    if (m_pZDxInterface -> GetList1Window () -> IsEditingBoundingVolume () /* ||
        m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint      () */)  return;
// END ANNECY AV }

    // We get the coordinates of the mouse cursor
    POINT PosCursor = pt;

    // We get the item under the mouse cursor
    BOOL   bOutside;
    m_DragedItem = m_List_Ctrl_2 . ItemFromPoint (PosCursor , bOutside);
    //kwn if (bOutside)  return;
    
    m_List_Ctrl_2 . SetCurSel (m_DragedItem);
    FillComboBoxListWithSelection ();
    m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (M_List2GetZDxSuperObject (m_DragedItem));

    if (m_pModule == NULL)    // Edition of global zones
    {
        if (! M_List2GetZDxObject (m_DragedItem))  return;
        SetCapture ();
        m_hPreviousCursor   = SetCursor (m_hCursorDragAndDrop);
        m_bRightDragAndDrop = TRUE;
        m_SwitchedItem      = m_DragedItem;
    }
    else                      // Edition of module zones
    {
        // If the selected item is a zdr, if it has no ZDx object, we open a popup menu
        tdstListElementData * pListElementData = M_List2GetListElementData (m_DragedItem);
        if (pListElementData -> eType == eZdrElement && pListElementData -> pZDxObject == NULL)
        {
            POINT Pos;
            GetCursorPos (& Pos);

            CMenu PopMenu;
            PopMenu . CreatePopupMenu ();
            CPA_BaseObject * pZdr = m_pModule -> GetZone (C_ucTypeZdr);
            if (pZdr != m_pModule)
                 PopMenu . AppendMenu (MF_STRING , C_uiPopupMenuIDSetZdrToItself     , "Use module itself as Zdr");
            if (pZdr == NULL || pZdr == m_pModule)
                 PopMenu . AppendMenu (MF_STRING , C_uiPopupMenuIDSetZdrToAnotherPo  , "Use another module as Zdr");
            if (pZdr == m_pModule)
                 PopMenu . AppendMenu (MF_STRING , C_uiPopupMenuIDSetZdrToNothing    , "Do not use module itself as Zdr");
            if (pZdr && pZdr != m_pModule)
                 PopMenu . AppendMenu (MF_STRING , C_uiPopupMenuIDSetZdrToNothing    , "Do not use another module as Zdr");
            PopMenu . TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON , Pos . x , Pos . y , this);
            PopMenu . DestroyMenu    ();
        }
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - OnCommand
// Used for the popup menu
//-----------------------------------------------------------------------------
BOOL CList2Window::OnCommand (WPARAM wParam , LPARAM lParam)
{
	ACP_tdxHandleOfObject hObject;
	switch (LOWORD (wParam))
    {
        case C_uiPopupMenuIDSetZdrToItself    : m_pModule -> SetZone (C_ucTypeZdr , m_pModule);
												hObject = (ACP_tdxHandleOfObject)((CPA_BaseObject*)m_pModule -> m_fnp_oGetGeometricWithDistance(0)) -> GetData();
												GEO_vCreateObjectListOfPointsMaterial( hObject );
												GEO_vComputeObjectListOfPointsMaterial( hObject );
                                                m_List_Ctrl_2 . Invalidate ();    // Redraw the list
                                                return TRUE;

        case C_uiPopupMenuIDSetZdrToAnotherPo : SetCapture ();
                                                m_bIsSelectingPoAsZdr = TRUE;
                                                m_List_Ctrl_2 . Invalidate ();    // Redraw the list
                                                return TRUE;

        case C_uiPopupMenuIDSetZdrToNothing   : m_pModule -> SetZone (C_ucTypeZdr , NULL);
                                                m_List_Ctrl_2 . Invalidate ();    // Redraw the list
                                                return TRUE;

        default                               : return CFormView::OnCommand (wParam , lParam);
    }

}

//-----------------------------------------------------------------------------
// class CList2Window - SwitchItems
// Switch two items
//-----------------------------------------------------------------------------
void CList2Window::SwitchItems (int _Item1 , int _Item2)
{
    if (_Item1 == _Item2)  return;

    tdstListElementData * pListElementData1 = M_List2GetListElementData (_Item1);
    tdstListElementData * pListElementData2 = M_List2GetListElementData (_Item2);

    // Exchange the two ZDx object;
    ZDx_Object * pBackupZDxObject   = pListElementData1 -> pZDxObject;
    pListElementData1 -> pZDxObject = pListElementData2 -> pZDxObject;
    pListElementData2 -> pZDxObject = pBackupZDxObject;

    CPA_SuperObject * pBackupZDxSuperObject = pListElementData1 -> pZDxSuperObject;
    pListElementData1 -> pZDxSuperObject    = pListElementData2 -> pZDxSuperObject;
    pListElementData2 -> pZDxSuperObject    = pBackupZDxSuperObject;
}

//-----------------------------------------------------------------------------
// class CList2Window - GetBigGlobalZone
// Get a big global zone, depending on the given type
//-----------------------------------------------------------------------------
EdtList * CList2Window::GetBigGlobalZone (tdeTreeElementType _eTreeElementType)
{
    switch (_eTreeElementType)
    {
        case eZddElement :   return m_pListOfZdd;
        case eZdeElement :   return m_pListOfZde;
        case eZdmElement :   return m_pListOfZdm;
        case eZdrElement :   return m_pListOfZdr;
        default          :   ASSERT (0);
                             return NULL;
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - GetBigGlobalZone
// Get a big global zone, depending on the given type
//-----------------------------------------------------------------------------
EdtList * CList2Window::GetBigGlobalZone (tdeZDxType _eZDxType)
{
    switch (_eZDxType)
    {
        case eZdd :   return m_pListOfZdd;
        case eZde :   return m_pListOfZde;
        case eZdm :   return m_pListOfZdm;
        case eZdr :   return m_pListOfZdr;
        default   :   ASSERT (0);
                      return NULL;
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - GetIndexInList
// Get the index (zero based) of an item on a specific type in the tree
//-----------------------------------------------------------------------------
long CList2Window::GetIndexInList (int _ItemToFind , tdeTreeElementType eElementType)
{
    long  lIndex = 0;

    for (int Item = 0 ; Item < _ItemToFind ; Item ++ )
        if (M_List2GetListElementData (Item) -> eType == eElementType)  lIndex ++;

    return lIndex;
}

//-----------------------------------------------------------------------------
// class CList2Window - ConvertElementTypeToZDxType
// Convert an element type to a ZDx type
//-----------------------------------------------------------------------------
tdeZDxType CList2Window::ConvertElementTypeToZDxType (tdeTreeElementType _eElementType)
{
    switch (_eElementType)
    {
        case eZddElement            : return eZdd;
        case eZdeElement            : return eZde;
        case eZdmElement            : return eZdm;
        case eZdrElement            : return eZdr;
        case eBoundingVolumeElement : return eBoundingVolume;
// ANNECY AV CLEAN_MEC {
//        case eTestPointElement      : return eTestPoint;
// END ANNECY AV }
        default                     : ASSERT (0);
                                      return eZdd;
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - ConvertZDxTypeToElementType
// Convert a ZDx type to an element type
//-----------------------------------------------------------------------------
tdeTreeElementType CList2Window::ConvertZDxTypeToElementType (tdeZDxType _eZDxType)
{
    switch (_eZDxType)
    {
        case eZdd            : return eZddElement;
        case eZde            : return eZdeElement;
        case eZdm            : return eZdmElement;
        case eZdr            : return eZdrElement;
        case eBoundingVolume : return eBoundingVolumeElement;
// ANNECY AV CLEAN_MEC {
//        case eTestPoint      : return eTestPointElement;
// END ANNECY AV }
        default              : ASSERT (0);
                               return eZddElement;
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - OnMouseMoveRightDragAndDrop
// Called when the mouse is moved during a right drag and drop
//-----------------------------------------------------------------------------
void CList2Window::OnMouseMoveRightDragAndDrop (CPoint Point) 
{
    // We get the item under the mouse cursor
    ClientToScreen                 (& Point);
    m_List_Ctrl_2 . ScreenToClient (& Point);
    BOOL   bOutside;
    int    ItemUnderCursor = m_List_Ctrl_2 . ItemFromPoint (Point , bOutside);

    if (bOutside == FALSE && ItemUnderCursor != m_SwitchedItem)
    {
        SwitchItems (m_DragedItem , m_SwitchedItem);       // Switch m_DragedItem and m_SwitchedItem

        m_SwitchedItem = ItemUnderCursor;                  // Switch m_DragedItem and m_ItemUnderCursor
        SwitchItems (m_DragedItem , m_SwitchedItem);
        
        m_List_Ctrl_2 . SetCurSel    (ItemUnderCursor);    // And select ItemUnderCursor

        m_List_Ctrl_2 . RedrawWindow ();                   // Redraw the tree
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - OnMouseMove
// Called when the mouse is moved. We see if we are inside a drag and drop
//-----------------------------------------------------------------------------
void CList2Window::OnMouseMove (UINT nFlags, CPoint Point)
{
	CFormView::OnMouseMove (nFlags , Point);

    if (m_bRightDragAndDrop)  OnMouseMoveRightDragAndDrop (Point);
	if (m_bIsSelectingPoAsZdr)
		m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetFocusDevice () ->RedrawWindow();
}

//-----------------------------------------------------------------------------
// class CList2Window - OnRButtonUp
// Called when the right button is released. We see if it is the end of a drag and drop
//-----------------------------------------------------------------------------
void CList2Window::OnRButtonUp (UINT, CPoint)
{
    if (m_bRightDragAndDrop)
    {
        ReleaseCapture ();
        SetCursor (m_hPreviousCursor);
        m_bRightDragAndDrop = FALSE;

        SwitchItems (m_DragedItem , m_SwitchedItem);    // Go back to the initial position

        tdstListElementData * pElementData1     = M_List2GetListElementData (m_DragedItem  );
        tdstListElementData * pElementData2     = M_List2GetListElementData (m_SwitchedItem);
        tdeTreeElementType    eElementType1     = pElementData1 -> eType;
        tdeTreeElementType    eElementType2     = pElementData2 -> eType;
        ZDx_Object          * pZDxObject1       = pElementData1 -> pZDxObject;
        ZDx_Object          * pZDxObject2       = pElementData2 -> pZDxObject;
        EdtList             * pBigGlobalZone1   = GetBigGlobalZone (eElementType1);
        EdtList             * pBigGlobalZone2   = GetBigGlobalZone (eElementType2);
        long                  lIndexInList1     = GetIndexInList   (m_DragedItem   , eElementType1);
        long                  lIndexInList2     = GetIndexInList   (m_SwitchedItem , eElementType2);

        // Create a modif for Do/Undo
        m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetEditManager () -> AskFor
            (new ZDx_Modif_Exchange (pZDxObject1 , lIndexInList1 , pBigGlobalZone1 , m_pActorSuperObject ,
                                     pZDxObject2 , lIndexInList2 , pBigGlobalZone2 , m_pActorSuperObject ,
                                     m_pZDxInterface));
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - DeleteZDx
// Called when the user wants to delete a ZDx from the list
//-----------------------------------------------------------------------------
void CList2Window::DeleteZDx ()
{
    // Get the selected ZDx object
    tdeZDxType   eZDxType;
    long         lPosition;
    ZDx_Object * pSelectedZDxObject = GetSelectedZDx (& eZDxType , & lPosition);
    if (! pSelectedZDxObject)  return;

    EdtList * pBigGlobalZone = NULL;
// ANNECY AV CLEAN_MEC {
    if (eZDxType != eBoundingVolume /* && eZDxType != eTestPoint */ && m_pModule == NULL)  pBigGlobalZone = GetBigGlobalZone (eZDxType);
// END ANNECY AV }

    // Create a modif for Do/Undo
    m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetEditManager () -> AskFor
        (new ZDx_Modif_Delete (GetSelectedZDxSuperObject () , lPosition , pBigGlobalZone , 
                               m_pModuleSuperObject , m_pActorSuperObject , m_pZDxInterface));

    // Refresh the list 1 when the list is the list of module
    if (m_pModule)
        m_pZDxInterface -> GetList1Window () -> CreateListOfModule (m_pZDxInterface -> GetList1Window () -> GetSelectedActorSuperObject () ,
                                                                    m_pModule);

    // Reselect the same position
// ANNECY AV CLEAN_MEC {
    /* if (eZDxType != eTestPoint) */ SelectZDx (eZDxType , lPosition);
// END ANNECY AV }
}

//-----------------------------------------------------------------------------
// class CList2Window - GetSelectedZDxSuperObject
// Get the selected ZDx super object
//-----------------------------------------------------------------------------
CPA_SuperObject * CList2Window::GetSelectedZDxSuperObject ()
{
    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();
    return SelectedItem  != -1 ? M_List2GetZDxSuperObject (SelectedItem) : NULL;
}


//-----------------------------------------------------------------------------
// class CList2Window - GetSelectedZDx
// Get the selected ZDx
//-----------------------------------------------------------------------------
ZDx_Object * CList2Window::GetSelectedZDx ()
{
    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();
    return SelectedItem  != -1 ? M_List2GetZDxObject (SelectedItem) : NULL;
}

//-----------------------------------------------------------------------------
// class CList2Window - GetSelectedZDx
// Get the selected ZDx and its position
//-----------------------------------------------------------------------------
ZDx_Object * CList2Window::GetSelectedZDx (tdeZDxType * peZDxType , long * plPosition)
{
    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();
    if (SelectedItem == -1)
    {
        * peZDxType  = eZdd;
        * plPosition = -1;
        return NULL;
    }

    * plPosition = 0;
    tdeTreeElementType eElementTypeOfSelectedItem = M_List2GetListElementData (SelectedItem) -> eType;
    * peZDxType  = ConvertElementTypeToZDxType (eElementTypeOfSelectedItem);

    for (int Item = 0 ; Item < SelectedItem ; Item ++)
        if (M_List2GetListElementData (Item) -> eType == eElementTypeOfSelectedItem)  (* plPosition) ++;

    return M_List2GetZDxObject (SelectedItem);
}

//-----------------------------------------------------------------------------
// class CList2Window - GetFirstZDxOfType
// Get the first ZDx of the given type in the list
//-----------------------------------------------------------------------------
ZDx_Object * CList2Window::GetFirstZDxOfType (tdeZDxType _eZDxType)
{
    tdeTreeElementType eElementType = ConvertZDxTypeToElementType (_eZDxType);

    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        tdstListElementData * pListElementData = M_List2GetListElementData (Item);
        if (pListElementData -> eType = eElementType)  return pListElementData -> pZDxObject;
    }

    return NULL;
}

//-----------------------------------------------------------------------------
// class CList2Window - GetZDxTypeOfSelection
// Get the type of the selected ZDx
//-----------------------------------------------------------------------------
tdeZDxType CList2Window::GetZDxTypeOfSelection ()
{
    // Get the selected item
    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();
    if (SelectedItem == -1)  return eZdd;

    // Get its element type and convert it to a ZDx type
    return ConvertElementTypeToZDxType (M_List2GetListElementData (SelectedItem) -> eType);
}

//-----------------------------------------------------------------------------
// class CList2Window - GetTypeOfTestPoint
// When editing the test points, return the type of the selected test point
//-----------------------------------------------------------------------------
// ANNECY AV CLEAN_MEC {
/*
DNM_tdeKindOfPoint CList2Window::GetTypeOfSelectedTestPoint ()
{
    // Get the selected item
    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();
    if (SelectedItem == -1)  return DNM_Point_Default;

    return M_List2GetListElementData (SelectedItem) -> eKindOfPoint;
}
*/
// END ANNECY AV }

//-----------------------------------------------------------------------------
// class CList2Window - GetListOfTestPoint
// When editing the test points, return the selected list of test points
//-----------------------------------------------------------------------------
// ANNECY AV CLEAN_MEC {
/*
CPA_TestPointsList * CList2Window::GetListOfTestPoint ()
{
    UpdateData (TRUE);              // Update variables from screen

    if (m_Combo_Box_String_List . IsEmpty ())  return NULL;

    // We find the selected CPA_TestPointsList with its name
    return (CPA_TestPointsList *) M_GetMainApp () -> fn_p_oGetMainWorld () -> fn_p_oFindObject (m_Combo_Box_String_List , C_szTestPointsListTypeName);
}
*/
// END ANNECY AV }

//-----------------------------------------------------------------------------
// class CList2Window - GetNumberOfUnusedPosition
// Get the number of unused position into the list
//-----------------------------------------------------------------------------
long CList2Window::GetNumberOfUnusedPosition ()
{
    long Counter = 0;

    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        tdstListElementData * pListElementData = M_List2GetListElementData (Item);
        if (pListElementData -> pZDxObject == NULL)  Counter ++;
    }

    return Counter;
}

//-----------------------------------------------------------------------------
// class CList2Window - InsertZDxObjectInList
// Insert a ZDx object in the list and return the index
//-----------------------------------------------------------------------------
int CList2Window::InsertZDxObjectInList (ZDx_Object * _pZDxObject , tdeTreeElementType _eTreeElementType ,
                                         CString _csNameInNameList , tdeSharedMode _eSharedMode)
{
    int Item = m_List_Ctrl_2 . AddString (_csNameInNameList);

    tdstListElementData * pListElementData = new tdstListElementData;
    pListElementData -> eType            = _eTreeElementType;
    pListElementData -> pZDxObject       = _pZDxObject;
    pListElementData -> pZDxSuperObject  = _pZDxObject ? m_pZDxInterface -> GetZDxSuperObject (_pZDxObject , m_pActorSuperObject ? m_pActorSuperObject : m_pModuleSuperObject)
                                                       : NULL;
    pListElementData -> csNameInNameList = _csNameInNameList;
    pListElementData -> eSharedMode      = _eSharedMode;

    m_List_Ctrl_2 . SetItemDataPtr (Item , pListElementData);

    return Item;
}

//-----------------------------------------------------------------------------
// class CList2Window - FillComboBoxList
// Fill the combo box list with all ZDx lists which belong to the list of names of type _eZDxType
//-----------------------------------------------------------------------------
void CList2Window::FillComboBoxList (tdeZDxType _eZDxType , EdtList * _pEdtList)
{
    m_Combo_Box_List . ResetContent ();

    if (! _pEdtList)
    {
        m_Combo_Box_List . EnableWindow (FALSE);
        return;
    }

    // We get the name list
    CPA_tdoNameList   * pNameList   = m_pZDxInterface -> GetNameList (m_pActor , _eZDxType);
    // We check if there are virged fields
    m_Combo_Box_List . EnableWindow (TRUE);
    for (tdoObjectName * pName = pNameList -> GetHead () ; pName ;
                         pName = pNameList -> GetNextElement (pName))
    {
        // One virged field -> we disable the combo box because one cannot change the list of zones
        if (pName -> m_eGetShareMode () == E_sm_Virge)
        {
            m_Combo_Box_List . EnableWindow (FALSE);
            break;
        }
    }

    // We put all the lists of zones into the combo box
    CPA_List<EdtList> * pListOfList = pNameList -> m_pEdtListHandler -> fn_oGetListOfEdtLists ();
    POSITION Pos;
    for (EdtList * pEdtList = pListOfList -> GetHeadElement (Pos) ; pEdtList ;
                   pEdtList = pListOfList -> GetNextElement (Pos))
    {
        m_Combo_Box_List . AddString (pEdtList -> GetName ());
    }
    // And we select the good one
    m_Combo_Box_List . SelectString (-1 , _pEdtList -> GetName ());
}

//-----------------------------------------------------------------------------
// class CList2Window - FillComboBoxList
// Fill the combo box list with the list of test points of the given family
//-----------------------------------------------------------------------------
// ANNECY AV CLEAN_MEC {
/*
void CList2Window::FillComboBoxList (CPA_Family * _pFamily , CPA_TestPointsList * _pListOfTestPointToSelect)
{
    m_Combo_Box_List . ResetContent ();
    m_Combo_Box_List . EnableWindow (TRUE);

    // We get the list of list of test points of the family
    CPA_List<CPA_TestPointsList> * pListOfListOfTestPoint = & _pFamily -> m_oListOfTPList;

    // We put all the lists of test points into the combo box
    POSITION Pos;
    for (CPA_TestPointsList * pListOfTestPoint = pListOfListOfTestPoint -> GetHeadElement (Pos) ; pListOfTestPoint ;
                              pListOfTestPoint = pListOfListOfTestPoint -> GetNextElement (Pos))
    {
        m_Combo_Box_List . AddString (pListOfTestPoint -> GetName ());
    }

    // And we select the good one
    if (_pListOfTestPointToSelect)  m_Combo_Box_List . SelectString (-1 , _pListOfTestPointToSelect -> GetName ());
}
*/
// END ANNECY AV }

//-----------------------------------------------------------------------------
// class CList2Window - FillComboBoxListWithSelection
// Call the FillComboBoxList function with the list of the selected ZDx
//-----------------------------------------------------------------------------
void CList2Window::FillComboBoxListWithSelection ()
{
	// Edition of test points -> we do nothing
// ANNECY AV CLEAN_MEC {
/*
	if (m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint ())
	{
		FillComboBoxList ((CPA_Family *) m_pActor -> GetOwner () -> GetOwner () , GetListOfTestPoint ());
		return;
	}
*/
// END ANNECY AV }

    EdtList * pListToSelect;
    // Get the selected item
    int       Item = m_List_Ctrl_2 . GetCurSel ();
    // If no selection or edition of the module ZDx, empty the combo box and return
    if (Item == -1 || m_pZDxInterface -> GetList1Window () -> IsEditingZDxOfModule ()
                   || m_pZDxInterface -> GetList1Window () -> IsEditingBoundingVolume ())
    {
        FillComboBoxList (eZdd , NULL);
        return;
    }

    // Get the type of the selected ZDx
    tdeTreeElementType eType         = M_List2GetListElementData (Item) -> eType;
    switch (eType)
    {
        case eZddElement : pListToSelect = m_pListOfZdd;   break;
        case eZdeElement : pListToSelect = m_pListOfZde;   break;
        case eZdmElement : pListToSelect = m_pListOfZdm;   break;
        case eZdrElement : pListToSelect = m_pListOfZdr;   break;
        default          : pListToSelect = NULL;           break;  // Sometimes, the selected item is not correct. So no ASSERT
    }

    FillComboBoxList (ConvertElementTypeToZDxType (eType) , pListToSelect);
}

//-----------------------------------------------------------------------------
// class CList2Window - On_Selection_Has_Changed_Has_Changed_Combo_Box_List
// Called when the selection has changed in the combo box to chose the list of zones
//-----------------------------------------------------------------------------
void CList2Window::On_Selection_Has_Changed_Combo_Box_List ()
{
    UpdateData (TRUE);              // Update variables from screen

// ANNECY AV CLEAN_MEC {
/*
    if (m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint ())
    {
        m_pZDxInterface -> IWillRefreshDisplay (C_lOnSelChangeCombo2);

        // We hide all the previous test points
        m_pZDxInterface -> ShowZDxOfActor (m_pActorSuperObject , C_ucHideAllZDx);

        // We find the selected CPA_TestPointsList with its name
        CPA_TestPointsList * pTestPointList = (CPA_TestPointsList *) M_GetMainApp () -> fn_p_oGetMainWorld () -> fn_p_oFindObject (m_Combo_Box_String_List , C_szTestPointsListTypeName);
        ASSERT (pTestPointList);    // The list must exist

        CreateListOfTestPoint (m_pActorSuperObject , pTestPointList);

        m_pZDxInterface -> RefreshDisplay (C_lOnSelChangeCombo2);
    }
    else
*/
// END ANNECY AV }
    {
        // We find the selected EdtList with its name
	    EdtList * pSelectedList = (EdtList *) M_GetMainApp () -> fn_p_oGetMainWorld () -> fn_p_oFindObject (m_Combo_Box_String_List , C_szEdtListTypeName);
        ASSERT (pSelectedList);    // The list must exist

        // Create a modif for Do/Undo
        m_pZDxInterface -> GetInterface () -> GetMultiDevice () -> GetEditManager () -> AskFor
            (new ZDx_Modif_Change_ZDx_List (m_pZDxInterface , m_pActorSuperObject , m_pZDxInterface ->
             ConvertListTypeToZDxType (pSelectedList -> fn_csGetListType ()) , pSelectedList));
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - CreateOneListOfZDx
// Create one list of ZDx
//-----------------------------------------------------------------------------
void CList2Window::CreateOneListOfZDx (EdtList * _pListOfZDx , CPA_tdoNameList * _pNameList ,
                                       tdeTreeElementType _eTreeElementType)
{
   POSITION      PosName = _pNameList  -> GetHeadPosition ();
   for (POSITION PosZDx  = _pListOfZDx -> GetHeadPosition () ;
        PosZDx && PosName ; )
    {
        ZDx_Object    * pZDxObject = (ZDx_Object *) _pListOfZDx -> GetNext (PosZDx);
        tdoObjectName * pName      = _pNameList -> GetNext (PosName);

        tdeSharedMode eSharedMode;
        switch (pName -> m_eGetShareMode ())
        {
            case E_sm_Common : eSharedMode = eCommon;    break;
            case E_sm_Shared : eSharedMode = eShared;    break;
            case E_sm_Virge  : eSharedMode = eVirge;     break;
            default          : ASSERT (0);
        }
        // Add the ZDx in the list
        InsertZDxObjectInList (pZDxObject , _eTreeElementType , pName -> GetName () , eSharedMode);
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - CreateListOfZDx
// Create the list of the ZDx
// pInstance (if not NULL) is the owner of the ZDx (for showing the ZDx)
//-----------------------------------------------------------------------------
void CList2Window::CreateListOfZDx (CPA_SuperObject * _pActorSuperObject ,
                                    EdtList         * _pListOfZdd ,
                                    EdtList         * _pListOfZde ,
                                    EdtList         * _pListOfZdm ,
                                    EdtList         * _pListOfZdr ,
                                    BOOL              _bUpdateDisplayAndEditWindow ,
                                    BOOL              _bUpdateCheckBox)
{
    // We get the old selected ZDx object, because we will try to select it again
    ZDx_Object * pOldSelectedZDx = GetSelectedZDx ();

    // Empty the combo box list
    FillComboBoxList (eZdd , NULL);

    m_pActorSuperObject  = _pActorSuperObject;
    m_pActor             = _pActorSuperObject ? _pActorSuperObject -> GetObject () : NULL;
    m_pZDxInterface -> GetDisplayControlWindow () -> SetNameOfCurrentActor (m_pActor ? m_pActor -> GetName () : "");
    m_pModuleSuperObject = NULL;
    m_pModule            = NULL;
    m_pListOfZdd         = _pListOfZdd;
    m_pListOfZde         = _pListOfZde;
    m_pListOfZdm         = _pListOfZdm;
    m_pListOfZdr         = _pListOfZdr;

    if (m_pActor)
    {
        tdeDisplayType eDisplayType;
        switch (((CPA_Actor *) m_pActor) -> GetDisplayZone ())
        {
            case FALSE : eDisplayType = eOff;       break;
            case TRUE  : eDisplayType = eOn;        break;
            case 2     : eDisplayType = eSelected;  break;
            default    : ASSERT (0);
        }
         m_pZDxInterface -> GetDisplayControlWindow () -> SetDisplayForCurrentActor (eDisplayType);
    }
    else m_pZDxInterface -> GetDisplayControlWindow () -> SetDisplayForCurrentActor (eNoZone);

    m_bIsCreatingList = TRUE;

    // Delete the previous list
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        delete M_List2GetListElementData (Item);
        m_List_Ctrl_2 . SetItemDataPtr (Item , NULL);
    }
    m_List_Ctrl_2 . ResetContent ();

    if (_bUpdateCheckBox)
    {
        m_bShowZDD = _pListOfZdd != NULL;
        m_bShowZDE = _pListOfZde != NULL;
        m_bShowZDM = _pListOfZdm != NULL;
        m_bShowZDR = _pListOfZdr != NULL;
        UpdateData (FALSE);

        GetDlgItem (IDC_Check_Box_ZDD) -> EnableWindow (m_bShowZDD);
        GetDlgItem (IDC_Check_Box_ZDE) -> EnableWindow (m_bShowZDE);
        GetDlgItem (IDC_Check_Box_ZDM) -> EnableWindow (m_bShowZDM);
        GetDlgItem (IDC_Check_Box_ZDR) -> EnableWindow (m_bShowZDR);
    }

    if (_pActorSuperObject)  m_pZDxInterface -> ShowZDxOfActor (_pActorSuperObject , GetZDxTypeToShow ());

    if (_pListOfZdd && m_bShowZDD)  CreateOneListOfZDx (_pListOfZdd , m_pZDxInterface -> GetNameList (m_pActor , eZdd) , eZddElement);
    if (_pListOfZde && m_bShowZDE)  CreateOneListOfZDx (_pListOfZde , m_pZDxInterface -> GetNameList (m_pActor , eZde) , eZdeElement);
    if (_pListOfZdm && m_bShowZDM)  CreateOneListOfZDx (_pListOfZdm , m_pZDxInterface -> GetNameList (m_pActor , eZdm) , eZdmElement);
    if (_pListOfZdr && m_bShowZDR)  CreateOneListOfZDx (_pListOfZdr , m_pZDxInterface -> GetNameList (m_pActor , eZdr) , eZdrElement);

    if (_bUpdateDisplayAndEditWindow)
    {
        ZDx_Object * pSelectedZDx;
        if (SelectZDx (pOldSelectedZDx))  pSelectedZDx = pOldSelectedZDx;
        else
        if (m_List_Ctrl_2 . GetCount () > 0)
        {
            m_List_Ctrl_2 . SetCurSel (0);
            pSelectedZDx = M_List2GetZDxObject (0);
        }
        else pSelectedZDx = NULL;

        if (m_pActor)
        {
            m_pZDxInterface -> ShowZDxOfActor (m_pActorSuperObject , GetZDxTypeToShow () , pSelectedZDx);
            // Put the correct ZDx super object
            if (m_List_Ctrl_2 . GetCurSel () != -1 && pSelectedZDx != NULL)
            {
                M_List2GetListElementData (m_List_Ctrl_2 . GetCurSel ()) -> pZDxSuperObject =
                    m_pZDxInterface -> GetZDxSuperObject (pSelectedZDx , m_pActorSuperObject);
            }
        }

        m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());
        FillComboBoxListWithSelection ();    // Fill the combo box list
    }

    m_bIsCreatingList = FALSE;

    // Redraw the tree
    m_List_Ctrl_2 . RedrawWindow ();
}

//-----------------------------------------------------------------------------
// class CList2Window - CreateListOfZDxOfModule
// Create the list of the ZDx of a module
// pInstance (if not NULL) is the owner of the ZDx (for showing the ZDx)
//-----------------------------------------------------------------------------
void CList2Window::CreateListOfZDxOfModule (CPA_SuperObject * _pModuleSuperObject ,
                                            BOOL              _bUpdateDisplayAndEditWindow)
{
    // We get the old selected ZDx object, because we will try to select it again
    ZDx_Object * pOldSelectedZDx = GetSelectedZDx ();

    // Empty the combo box list
    FillComboBoxList (eZdd , NULL);

    m_pActorSuperObject  = NULL;
    m_pActor             = NULL;
    m_pZDxInterface -> GetDisplayControlWindow () -> SetNameOfCurrentActor ("");
    m_pModuleSuperObject = _pModuleSuperObject;
    m_pModule            = (EditorPO *) (_pModuleSuperObject ? _pModuleSuperObject -> GetObject () : NULL);
    m_pZdd = m_pModule ? (ZDx_Object *) m_pModule -> GetZone (C_ucTypeZdd) : NULL;
    m_pZde = m_pModule ? (ZDx_Object *) m_pModule -> GetZone (C_ucTypeZde) : NULL;
    m_pZdm = m_pModule ? (ZDx_Object *) m_pModule -> GetZone (C_ucTypeZdm) : NULL;
    m_pZdr = m_pModule ? (ZDx_Object *) m_pModule -> GetZone (C_ucTypeZdr) : NULL;
    if (m_pZdr && m_pZdr -> fn_bIsOfType (C_szZdrName) == FALSE)  m_pZdr = NULL;

    m_bIsCreatingList = TRUE;

    // Delete the previous list
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        delete M_List2GetListElementData (Item);
        m_List_Ctrl_2 . SetItemDataPtr (Item , NULL);
    }
    m_List_Ctrl_2 . ResetContent ();

    if (_pModuleSuperObject)  m_pZDxInterface -> ShowZDxOfModule (_pModuleSuperObject , GetZDxTypeToShow ());

    if (m_bShowZDD)  InsertZDxObjectInList (m_pZdd , eZddElement , "Zdd" , eNoSharedMode);
    if (m_bShowZDE)  InsertZDxObjectInList (m_pZde , eZdeElement , "Zde" , eNoSharedMode);
    if (m_bShowZDM)  InsertZDxObjectInList (m_pZdm , eZdmElement , "Zdm" , eNoSharedMode);
    if (m_bShowZDR)  InsertZDxObjectInList (m_pZdr , eZdrElement , "Zdr" , eNoSharedMode);

    ZDx_Object * pSelectedZDx;
    if (SelectZDx (pOldSelectedZDx , FALSE , _bUpdateDisplayAndEditWindow))                 pSelectedZDx= pOldSelectedZDx;
    else
    if (m_List_Ctrl_2 . GetCount () > 0)
    {
        m_List_Ctrl_2 . SetCurSel          (m_List_Ctrl_2 . GetCount () - 1);
        pSelectedZDx = M_List2GetZDxObject (m_List_Ctrl_2 . GetCount () - 1);
    }
    else pSelectedZDx = NULL;

    if (_bUpdateDisplayAndEditWindow)
    {
        m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());
        FillComboBoxListWithSelection ();    // Fill the combo box list
        if (m_pModule)  m_pZDxInterface -> ShowZDxOfModule (m_pModuleSuperObject , GetZDxTypeToShow () , pSelectedZDx);
    }

    m_bIsCreatingList = FALSE;

    m_List_Ctrl_2 . RedrawWindow ();    // Redraw the list
}

//-----------------------------------------------------------------------------
// class CList2Window - CreateBoundingVolume
// Create a list with only one ZDx : a bounding volume
//-----------------------------------------------------------------------------
void CList2Window::CreateBoundingVolume (CPA_SuperObject * _pActorSuperObject , ZDx_Object * _pBoundingVolume ,
                                         BOOL _bUdateEditWindow /* = TRUE */, BOOL _bShowBdV)
{
    FillComboBoxList (eZdd , NULL);

    m_pActorSuperObject  = _pActorSuperObject;
    m_pActor             = _pActorSuperObject -> GetObject ();
    m_pZDxInterface -> GetDisplayControlWindow () -> SetNameOfCurrentActor (m_pActor -> GetName ());
    m_pModuleSuperObject = NULL;
    m_pModule            = NULL;

    m_bIsCreatingList = TRUE;

    GetDlgItem (IDC_Check_Box_ZDD) -> EnableWindow (FALSE);
    GetDlgItem (IDC_Check_Box_ZDE) -> EnableWindow (FALSE);
    GetDlgItem (IDC_Check_Box_ZDM) -> EnableWindow (FALSE);
    GetDlgItem (IDC_Check_Box_ZDR) -> EnableWindow (FALSE);
    m_bShowZDD = FALSE;
    m_bShowZDE = FALSE;
    m_bShowZDM = FALSE;
    m_bShowZDR = FALSE;
    UpdateData (FALSE);

    // Delete the previous list
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        delete M_List2GetListElementData (Item);
        m_List_Ctrl_2 . SetItemDataPtr (Item , NULL);
    }
    m_List_Ctrl_2 . ResetContent ();

    if (_bShowBdV)
	{
		if (_pActorSuperObject && _pBoundingVolume)  m_pZDxInterface -> ShowBoundingVolume (_pActorSuperObject , _pBoundingVolume , TRUE);

    }
	
	// Insert the bounding volume into the list and select it
    InsertZDxObjectInList (_pBoundingVolume , eBoundingVolumeElement , "BV" , eNoSharedMode);
    m_List_Ctrl_2 . SetCurSel (0);
    if (_bUdateEditWindow)  m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());

    m_bIsCreatingList = FALSE;

    m_List_Ctrl_2 . RedrawWindow ();    // Redraw the list
}

//-----------------------------------------------------------------------------
// class CList2Window - CreateListOfTestPoint
// Create a list with the test points of the family of the given actor
//-----------------------------------------------------------------------------
// ANNECY AV CLEAN_MEC {
/*
void CList2Window::CreateListOfTestPoint (CPA_SuperObject * _pActorSuperObject , CPA_TestPointsList * _pTestPointList ,
                                          BOOL _bUpdateEditWindow)
{
    m_pActorSuperObject  = _pActorSuperObject;
    m_pActor             = _pActorSuperObject -> GetObject ();
    m_pZDxInterface -> GetDisplayControlWindow () -> SetNameOfCurrentActor (m_pActor -> GetName ());
    m_pModuleSuperObject = NULL;
    m_pModule            = NULL;

    m_bIsCreatingList = TRUE;

    GetDlgItem (IDC_Check_Box_ZDD) -> EnableWindow (FALSE);
    GetDlgItem (IDC_Check_Box_ZDE) -> EnableWindow (FALSE);
    GetDlgItem (IDC_Check_Box_ZDM) -> EnableWindow (FALSE);
    GetDlgItem (IDC_Check_Box_ZDR) -> EnableWindow (FALSE);
    m_bShowZDD = FALSE;
    m_bShowZDE = FALSE;
    m_bShowZDM = FALSE;
    m_bShowZDR = FALSE;
    UpdateData (FALSE);

    int SelectedItem = m_List_Ctrl_2 . GetCurSel ();

    // Delete the previous list
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++)
    {
        delete M_List2GetListElementData (Item);
        m_List_Ctrl_2 . SetItemDataPtr (Item , NULL);
    }
    m_List_Ctrl_2 . ResetContent ();

    // Call the OnSize function to show the New button  and the combo box correctly
    RECT WindowPos;
    GetClientRect (& WindowPos);
    OnSize (SIZE_RESTORED , WindowPos . right , WindowPos . bottom);

    // Get the family of the actor
    CPA_Family * pFamily = (CPA_Family *) m_pActor -> GetOwner () -> GetOwner ();
    ASSERT (pFamily);

    if (_pTestPointList == NULL)
    {
        // Get the current state of the actor
        CPA_State * pCurrentState = ((CPA_Actor *) m_pActor) -> m_pub_fn_pclGetCurrentState ();

        // Get the list of test points of this state
        _pTestPointList = pCurrentState ? pCurrentState -> mfn_p_oGetTestPointsList () : NULL;
    }
    if (_pTestPointList == NULL)
    {
        _pTestPointList = pFamily -> m_oListOfTPList . GetHeadElement ();
        if (_pTestPointList == NULL)
        {
            FillComboBoxList (pFamily , _pTestPointList);
            m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (NULL);
            return;
        }
    }

    FillComboBoxList (pFamily , _pTestPointList);

    const int                NumberOfTypeOfTestPoint = 6;
    const DNM_tdeKindOfPoint ListOfType [] = { DNM_Point_Head   , DNM_Point_Clavicle , DNM_Point_Sternum ,
                                               DNM_Point_Coccyx , DNM_Point_Patella  ,  DNM_Point_Feet };

    for (int i = 0 ; i < NumberOfTypeOfTestPoint ; i ++)
    {
        // Get the type of test point
        DNM_tdeKindOfPoint  eKindOfPoint   = ListOfType [i];

        // Ask the list if there is a test point of this type
        CPA_TestPointNode * pTestPoint = _pTestPointList -> mfn_p_oGetNodeByKind (eKindOfPoint);

        ZDx_Object * pZDxObject = pTestPoint ? pTestPoint -> mfn_p_oGetZdxObject () : NULL;

        if (_pActorSuperObject && pZDxObject)
            m_pZDxInterface -> ShowZDxOfActor (_pActorSuperObject , C_ucShowTestPoint , pZDxObject);

        int Item = InsertZDxObjectInList (pZDxObject , eTestPointElement , _pTestPointList -> GetKindOfPointName (eKindOfPoint) , eNoSharedMode);
        tdstListElementData * pListElementData = (tdstListElementData *) m_List_Ctrl_2 . GetItemDataPtr (Item);
        pListElementData -> eKindOfPoint = eKindOfPoint;
        pListElementData -> pTestPoint   = pTestPoint;
    }

    if (m_List_Ctrl_2 . SetCurSel (SelectedItem) == LB_ERR)  m_List_Ctrl_2 . SetCurSel (0);

    if (_bUpdateEditWindow)
    {
        m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());
        m_pZDxInterface -> ShowZDxOfActor (m_pActorSuperObject , C_ucShowTestPoint , GetSelectedZDx ());
    }

    m_bIsCreatingList = FALSE;
}
*/
// END ANNECY AV }

//-----------------------------------------------------------------------------
// class CList2Window - LeaveEditionOfTestPoint
// Leave the edition of test points : refresh the list
//-----------------------------------------------------------------------------
// ANNECY AV CLEAN_MEC {
/*
void CList2Window::LeaveEditionOfTestPoint ()
{
    // Call the OnSize function to show the New button  and the combo box correctly
    RECT WindowPos;
    GetClientRect (& WindowPos);
    OnSize (SIZE_RESTORED , WindowPos . right , WindowPos . bottom);
}
*/
// END ANNECY AV }

//-----------------------------------------------------------------------------
// class CList2Window - ReCreateListOfZDx
// Refresh the showed list
//-----------------------------------------------------------------------------
void CList2Window::ReCreateListOfZDx (BOOL _bUpdateDisplayAndEditWindow ,
                                      BOOL _bUpdateCheckBox)
{
    // One and only one of the two pointers must be defined
    ASSERT ((m_pActorSuperObject != NULL) ^ (m_pModuleSuperObject != NULL));

    if (m_pActorSuperObject)
    {
        m_pZDxInterface -> ShowZDxOfActor (m_pActorSuperObject , GetZDxTypeToShow ());
        CreateListOfZDx (m_pActorSuperObject , m_pListOfZdd , m_pListOfZde , m_pListOfZdm , m_pListOfZdr , _bUpdateDisplayAndEditWindow , _bUpdateCheckBox);
    }
    else
    {
        m_pZDxInterface -> ShowZDxOfModule (m_pModuleSuperObject , GetZDxTypeToShow ());
        CreateListOfZDxOfModule (m_pModuleSuperObject , _bUpdateDisplayAndEditWindow);
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - CreateASpecificListOfZDx
// Create only one list of ZDx
//-----------------------------------------------------------------------------
void CList2Window::CreateASpecificListOfZDx (CPA_SuperObject * _pActorSuperObject ,
                                             EdtList         * _pListOfZDx ,
                                             tdeZDxType        _eZDxType)
{
    if (_pActorSuperObject)  m_pZDxInterface -> ShowZDxOfActor (m_pActorSuperObject , GetZDxTypeToShow ());

    switch (_eZDxType)
    {
    case eZdd :  CreateListOfZDx (_pActorSuperObject , _pListOfZDx , NULL , NULL , NULL);    break;
    case eZde :  CreateListOfZDx (_pActorSuperObject , NULL , _pListOfZDx , NULL , NULL);    break;
    case eZdm :  CreateListOfZDx (_pActorSuperObject , NULL , NULL , _pListOfZDx , NULL);    break;
    case eZdr :  CreateListOfZDx (_pActorSuperObject , NULL , NULL , NULL , _pListOfZDx);    break;
    default   :  ASSERT (0);                                                                 break;
    }
}

//-----------------------------------------------------------------------------
// class CList2Window - SelectZDx
// Select a ZDx in the list. Return FALSE if not found
// If _pZDxObjctToSelect = NULL :
//    If _bSelectEvenIfNull = FALSE, unselect the current select
//    If _bSelectEvenIfNull = TRUE, select the first empty position
//-----------------------------------------------------------------------------
BOOL CList2Window::SelectZDx (ZDx_Object * _pZDxObjectToSelect , BOOL _bSelectEvenIfNull /* = FALSE */ ,
                              BOOL _bUpdateEditWindow /* = TRUE */)
{
    // If we are already selecting a ZDx, we do nothing
    if (m_bIsSelectingZDx)  return FALSE;

    // If _pZDxObjectToSelect is NULL, we unselect the current selection
    if (_pZDxObjectToSelect == NULL && ! _bSelectEvenIfNull)
    {
        m_List_Ctrl_2 . SetCurSel (-1);
        FillComboBoxListWithSelection ();
        m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (NULL);
        return FALSE;
    }

    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++ )
    {
        if (M_List2GetZDxObject (Item) == _pZDxObjectToSelect)
        {
            m_List_Ctrl_2 . SetCurSel (Item);
            FillComboBoxListWithSelection ();
            if (_bUpdateEditWindow)  m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (GetSelectedZDxSuperObject ());
            return TRUE;
        }
    }

    return FALSE;    // Not found
}

//-----------------------------------------------------------------------------
// class CList2Window - SelectZDx
// Select the ZDx which have the given type and the given position in the list
//-----------------------------------------------------------------------------
BOOL CList2Window::SelectZDx (tdeZDxType _eZDxType , long _lPosition)
{
    int i = -1;
    for (int Item = 0 ; Item < m_List_Ctrl_2 . GetCount () ; Item ++ )
    {
        tdeTreeElementType eElementType = M_List2GetListElementData (Item) -> eType;
        tdeZDxType         eZDxType     = ConvertElementTypeToZDxType (eElementType);

        if (eZDxType == _eZDxType)
        {
            if (++i == _lPosition)
            {
                m_List_Ctrl_2 . SetCurSel (Item);
                FillComboBoxListWithSelection ();
                m_pZDxInterface -> GetEditWindow () -> SetZDxObjectToEdit (M_List2GetZDxSuperObject (Item));
                return TRUE;
            }
        }
    }

    return FALSE;    // Not found
}

//-----------------------------------------------------------------------------
// class CList2Window - GetZDxTypeToShow
// Return the type of ZDx to show
//-----------------------------------------------------------------------------
unsigned char CList2Window::GetZDxTypeToShow ()
{
// ANNECY AV CLEAN_MEC {
/*
    if (m_pZDxInterface -> GetList1Window () -> IsEditingTestPoint ())  return C_ucShowTestPoint;
    else */ return (m_bShowZDD ? C_ucShowZDD : 0) +
                (m_bShowZDE ? C_ucShowZDE : 0) +
                (m_bShowZDM ? C_ucShowZDM : 0) +
                (m_bShowZDR ? C_ucShowZDR : 0);
// END ANNECY AV }
}
