/*******************************************************************************
Function Name    : OnInitDialog
Input(s)         :
Output           :
Functionality    : This function will be called during initialization of dialog
                   box. This function will fill respective list controls
Member of        : CSigWatchAddDelDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
*******************************************************************************/
BOOL CSigWatchAddDelDlg::OnInitDialog()
{
    // Call parent's init function
    CDialog::OnInitDialog();
    // Populate the message name combo
    // Clear the content if any
    m_omCombMessage.ResetContent();
    // Create the Image List
    m_omImageList.Create(IDR_BMP_MSG_SIG_WATCH,
                         16,
                         1,
                         defCOLOR_WHITE);

    if (m_podTempCallerList != NULL)
    {
        UINT unNoOfMainEntries = (UINT)m_podTempCallerList->GetCount();

        if ( unNoOfMainEntries > 0 )
        {
            // Add every message name into the message list
            POSITION pos = m_podTempCallerList->GetHeadPosition();

            while (pos != NULL)
            {
                SMAINENTRY& sMainEntry = m_podTempCallerList->GetNext(pos);
                CString omMainEntryName = sMainEntry.m_omMainEntryName;
                CString omMainEntryId;
                omMainEntryId.Format(defSTR_MSG_ID_IN_HEX,sMainEntry.m_unMainEntryID);
                omMainEntryName = omMainEntryId + omMainEntryName;
                m_omCombMessage.AddString(omMainEntryName);
            }

            m_omCombMessage.SetCurSel(0);
            m_omListCtrlSignal.SetImageList(&m_omImageList, LVSIL_SMALL);
            // Create the first column. But this will not be shown
            m_omListCtrlSignal.InsertColumn( 0,
                                             STR_EMPTY,
                                             LVCFMT_LEFT,
                                             0); //Width is zero as this will
            //be updated in vUpdateUnSelSubEntryList
            // Populate the list with signal names
            vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
            m_omCombMessage.SetFocus();
        }
    }

    // Update Signal Watch List
    // Set the same image list to this control
    m_omListCtrlSignalWatch.SetImageList(&m_omImageList,LVSIL_SMALL);
    // Create Column for Signal Watch Lsit
    m_omListCtrlSignalWatch.InsertColumn( 0,
                                          STR_EMPTY,
                                          LVCFMT_LEFT,
                                          0);//Width is zero as this will
    //be updated in vPopulateSelSubEntryList
    vPopulateSelSubEntryList();
    vEnableDisableButtons();
    return FALSE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}
/*******************************************************************************
Function Name    : OnSelChangeMessageName
Input(s)         :
Output           :
Functionality    : This function will be called by framework when the message
                   name combo box selection got changed. This will update the
                   Signal Names List control
Member of        : CWaveformSelectionDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
Modification By  :
Modification on  :
*******************************************************************************/
void CWaveformSelectionDlg::OnSelChangeMessageName()
{
    UINT nMsgID=unGetSelectedMainEntryID();
    m_fDefAmplitude=m_pWaveDataHandler->fGetMsgIDDefaultValue(nMsgID);
    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
    vEnableDisableButtons();
    UpdateData(FALSE);
}
/*******************************************************************************
Function Name    : vDelSelSubEntries
Input(s)         : bAllSignals - Delete All Signals Flag
Output           :
Functionality    : This function will be called to delete the selected signals
                   from the temporary signal list. It will delete all messages
                   if the bool bAllSignals is true.
Member of        : CSigWatchAddDelDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
Modification By  :
Modification on  :
*******************************************************************************/
void CSigWatchAddDelDlg::vDelSelSubEntries(BOOL bAllEntries)
{
    // Get the data from GUI interface
    vUpdateSelSubEntryList(bAllEntries);

    if(bAllEntries == FALSE)
    {
        UINT unSelCount = (UINT)m_omCSAData.GetSize();

        for(UINT index = 0; index < unSelCount; index++)
        {
            CString omSelMainSubEntry, omMainEntry, omSubEntry;
            omSelMainSubEntry = m_omCSAData.GetAt(index);

            if( bGetMainSubName( omSelMainSubEntry, omMainEntry, omSubEntry) == TRUE )
            {
                UINT unMainEntryID = unGetMainEntryIDFromName(omMainEntry);

                if ( bDeleteSubEntry(unMainEntryID, omSubEntry) != TRUE)
                {
                    CString omError;
                    omError.Format(defSTR_SW_DELETE_SIG_ERROR, omSubEntry ,omMainEntry);
                    AfxMessageBox(omError);
                }
            }
            else
            {
                CString omError;
                omError.Format(defSTR_SW_PARSE_ERROR, omSelMainSubEntry);
                AfxMessageBox(omError);
            }
        }
    }
    else
    {
        if (m_podTempCallerList != NULL)
        {
            POSITION pos = m_podTempCallerList->GetHeadPosition();

            while (pos)
            {
                SMAINENTRY& sMainEntry = m_podTempCallerList->GetNext(pos);
                POSITION SubPos = sMainEntry.m_odSelEntryList.GetHeadPosition();

                while (SubPos != NULL)
                {
                    POSITION TempPos = SubPos;
                    SSUBENTRY& sSubEntry = sMainEntry.m_odSelEntryList.GetNext(SubPos);
                    sMainEntry.m_odUnSelEntryList.AddTail(sSubEntry);
                    sMainEntry.m_odSelEntryList.RemoveAt(TempPos);
                }
            }
        }
    }

    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
}
/*******************************************************************************
Function Name    : OnBtnAddSubEntries
Input(s)         :  -
Output           :  -
Functionality    : This function will be called by framework when the user
                   selects "Add" button. This will call "vAddSelSubEntries" to
                   add the selected sub entries
Member of        : CWaveformSelectionDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
Modifications    : Raja N
                 : 14.04.2004. Modifications as per Code Review.
*******************************************************************************/
void CWaveformSelectionDlg::OnBtnAddSubEntries()
{
    sWaveformInfo objWaveInfo;
    m_pWaveDataHandler->vGetDefaultSignalWaveValues(objWaveInfo);
    DefineUpdateWave(&m_omListCtrlSignal, unGetSelectedMainEntryID(),
                     m_omListCtrlSignal.GetItemText(m_omListCtrlSignal.GetSelectionMark() , 0),
                     objWaveInfo);
    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
    vPopulateSelSubEntryList();
    // Update button status
    vEnableDisableButtons();
}
/*******************************************************************************
Function Name    : OnDblclkUnSelSubEntryList
Input(s)         : NMHDR* pNMHDR, LRESULT* pResult - Handler parameter
Output           :  -
Functionality    : This function will be called by framework when the user
                   double clicks on Signal List box. This will call
                   "vAddSelectedSignals" to add the selected entry and will
                   update the button status by calling "vEnableDisableButtons"
Member of        : CWaveformSelectionDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
Modifications    : Raja N
                 : 14.04.2004. Modifications as per Code Review.
*******************************************************************************/
void CWaveformSelectionDlg::OnDblclkUnSelSubEntryList(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
    if(m_omListCtrlSignal.GetSelectedCount() != 0)
    {
        sWaveformInfo objWaveInfo;
        m_pWaveDataHandler->vGetDefaultSignalWaveValues(objWaveInfo);
        DefineUpdateWave(&m_omListCtrlSignal, unGetSelectedMainEntryID(),
                         m_omListCtrlSignal.GetItemText(m_omListCtrlSignal.GetSelectionMark() , 0),
                         objWaveInfo);
        vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
        vPopulateSelSubEntryList();
        // Update button status
        vEnableDisableButtons();
    }
    *pResult = 0;
}
void CWaveformSelectionDlg::OnNMDblclkLstcSignalWatch(NMHDR* /*pNMHDR*/, LRESULT *pResult)
{
    // Get the selected signal Name
    sWaveformInfo objWaveInfo;
    CString strSignalName;
    UINT nMsgID = (UINT)-1;
    vInterPretSignalNameMsgID(m_omListCtrlSignalWatch.GetItemText(
                                  m_omListCtrlSignalWatch.GetSelectionMark() , 0), strSignalName, nMsgID);
    m_pWaveDataHandler->bGetSignalWavePatternDetails(nMsgID, strSignalName, objWaveInfo);

    DefineUpdateWave(&m_omListCtrlSignalWatch, nMsgID, strSignalName, objWaveInfo);

    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
    vPopulateSelSubEntryList();
    // Update button status
    vEnableDisableButtons();

    *pResult = 0;
}
/*******************************************************************************
Function Name    : OnBtnDelSubEntires
Input(s)         :  -
Output           :  -
Functionality    : This function will be called by framework when the user
                   selects "Delete" button. This will call
                   "vDeleteSelectedSignals" to delete the selected signals. If
                   the user selectes all the signals it will do delete all.
Member of        : CWaveformSelectionDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
Modification By  :
Modification on  :
*******************************************************************************/
void CWaveformSelectionDlg::OnBtnDelSubEntires()
{
    BOOL bDeleteAll = FALSE;
    // Check the selection count and if that is equal to total number just
    // all. No need to process the data
    if(static_cast<int>(m_omListCtrlSignalWatch.GetSelectedCount()) ==
            m_omListCtrlSignalWatch.GetItemCount())
    {
        bDeleteAll = TRUE;
    }

    CString strSignalName;
    UINT nMsgID = (UINT)-1;
    vInterPretSignalNameMsgID(m_omListCtrlSignalWatch.GetItemText(
                                  m_omListCtrlSignalWatch.GetSelectionMark() , 0), strSignalName, nMsgID);
    m_pWaveDataHandler->bRemoveSignalFromDefinedWavesList(nMsgID, strSignalName);
    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
    vPopulateSelSubEntryList();
    vEnableDisableButtons();
}
/*******************************************************************************
Function Name    : OnSelChangeMessageName
Input(s)         : 
Output           : 
Functionality    : This function will be called by framework when the message 
                   name combo box selection got changed. This will update the 
                   Signal Names List control
Member of        : CSigWatchAddDelDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
Modification By  : 
Modification on  : 
*******************************************************************************/
void CSigWatchAddDelDlg::OnSelChangeMessageName() 
{

    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
    vEnableDisableButtons();
}
/*******************************************************************************
Function Name    : OnInitDialog
Input(s)         : 
Output           : 
Functionality    : This function will be called during initialization of dialog
                   box. This function will fill respective list controls
Member of        : CMainSubListDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
*******************************************************************************/
BOOL CMainSubListDlg::OnInitDialog() 
{
    // Call parent's init function
    CDialog::OnInitDialog();    

    //Display title name
    SetWindowText((LPCTSTR)m_sGuiParams.m_acTitleName);
    //Dislay Main List name
    CWnd* pWnd = GetDlgItem(IDC_EDIT_MAINLIST_NAME);
    if (pWnd != NULL)
    {
        pWnd->SetWindowText((LPCTSTR)m_sGuiParams.m_acMainListName);
    }
    //Dislay Unselected List name
    pWnd = GetDlgItem(IDC_EDIT_UNSELLIST_NAME);
    if (pWnd != NULL)
    {
        pWnd->SetWindowText((LPCTSTR)m_sGuiParams.m_acUnSelListName);
    }
    //Dislay Selected List name
    pWnd = GetDlgItem(IDC_EDIT_SELLIST_NAME);
    if (pWnd != NULL)
    {
        pWnd->SetWindowText((LPCTSTR)m_sGuiParams.m_acSelListName);
    }
    // Populate the message name combo
    // Clear the content if any
    m_omCombMessage.ResetContent();
    if (m_podTempCallerList != NULL)
    {
        UINT unNoOfMainEntries = (UINT)m_podTempCallerList->GetCount();
    
        if ( unNoOfMainEntries > 0 )
        {		
		    // Add every message name into the message list
            POSITION pos = m_podTempCallerList->GetHeadPosition();
            while (pos != NULL)
            {
                SMAINENTRY& sMainEntry = m_podTempCallerList->GetNext(pos);
                CString omMainEntryName = sMainEntry.m_omMainEntryName;
                CString omMainEntryId = "";

                if (m_sGuiParams.m_bCombine == TRUE)
                {
                    omMainEntryId.Format(defSTR_MSG_ID_IN_HEX,sMainEntry.m_unMainEntryID);
                    omMainEntryName = omMainEntryId + omMainEntryName;
                }
				
				m_omCombMessage.AddString(omMainEntryName);
            }
            m_omCombMessage.SetCurSel(0);
            
            m_omListCtrlSignal.SetImageList(m_sGuiParams.m_pomImageList, LVSIL_SMALL);
            
            // Create the first column. But this will not be shown
            m_omListCtrlSignal.InsertColumn( 0, 
                                                STR_EMPTY, 
                                                LVCFMT_LEFT,
                                                0); //Width is zero as this will 
                                            //be updated in vUpdateUnSelSubEntryList
            
            // Populate the list with signal names
            vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());
            m_omCombMessage.SetFocus();
        }
    }
    
    // Update Signal Watch List
    // Set the same image list to this control
    m_omListCtrlSignalWatch.SetImageList(m_sGuiParams.m_pomImageList,LVSIL_SMALL);
    // Create Column for Signal Watch Lsit
    m_omListCtrlSignalWatch.InsertColumn( 0,
                                     STR_EMPTY,
                                     LVCFMT_LEFT,
                                     0);//Width is zero as this will 
                                        //be updated in vPopulateSelSubEntryList
    vPopulateSelSubEntryList();
    vEnableDisableButtons();

    return FALSE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}
/*******************************************************************************
Function Name    : OnInitDialog
Input(s)         :
Output           :
Functionality    : This function will be called during initialization of dialog
                   box. This function will fill respective list controls
Member of        : CWaveformSelectionDlg
Friend of        :  -
Author(s)        : Raja N
Date Created     : 25.03.2004
*******************************************************************************/
BOOL CWaveformSelectionDlg::OnInitDialog()
{
    // Call parent's init function
    CDialog::OnInitDialog();

    // Populate the message name combo
    // Clear the content if any
    m_omCombMessage.ResetContent();
    // Create the Image List
    m_omImageList.Create(IDR_BMP_MSG_SIG_WATCH,16,1, defCOLOR_WHITE);

    CStringArray arrMsgIDsList;
    m_pWaveDataHandler->vGetCompleteMsgList(arrMsgIDsList);
    for(int i = 0; i<arrMsgIDsList.GetSize(); i++)
    {
        m_omCombMessage.AddString(arrMsgIDsList.GetAt(i));
    }
    m_omCombMessage.SetCurSel(0);
    m_omCombMessage.SetFocus();

    m_omListCtrlSignal.SetImageList(&m_omImageList, LVSIL_SMALL);
    // Create the first column. But this will not be shown
    m_omListCtrlSignal.InsertColumn( 0, STR_EMPTY, LVCFMT_LEFT,
                                     0); //Width is zero as this will
    //be updated in vUpdateUnSelSubEntryList
    // Populate the list with signal names
    vPopulateUnSelSubEntryList(unGetSelectedMainEntryID());

    UINT nMsgID = unGetSelectedMainEntryID();
    m_fDefAmplitude = m_pWaveDataHandler->fGetMsgIDDefaultValue(nMsgID);

    // Update Signal Watch List
    // Set the same image list to this control
    m_omListCtrlSignalWatch.SetImageList(&m_omImageList,LVSIL_SMALL);
    // Create Column for Signal Watch Lsit
    m_omListCtrlSignalWatch.InsertColumn( 0,
                                          STR_EMPTY,
                                          LVCFMT_LEFT,
                                          0);//Width is zero as this will
    //be updated in vPopulateSelSubEntryList
    vPopulateSelSubEntryList();
    vEnableDisableButtons();

    // Channels
    m_omMsgChannel.ResetContent();
    // Add All Channels as first item
    m_omMsgChannel.AddString(defSTR_SELECTION_ALL);
    for (UINT Index = 1; Index <= m_nHardware; Index++)
    {
        CString omStr;
        // Format Channel ID String Say 1,2,...
        omStr.Format(defFORMAT_MSGID_DECIMAL, Index);
        m_omMsgChannel.AddString(omStr);
    }
    m_omMsgChannel.SetCurSel(1); //Make Channel 1 default.

    //Temporarily disable the channel selection feature.
    m_omMsgChannel.EnableWindow(FALSE);
    GetDlgItem(IDC_STATIC_CHANNEL)->EnableWindow(FALSE);

    UpdateData(FALSE);


    return FALSE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}