
/***************************************************************************
**
**    $Header:   D:/ECB2S/SRC/LOG/VARADD.CPP   1.2.1.4   17 Apr 1997 16:08:54   ZJRD  $
**
**    $Log:   D:/ECB2S/SRC/LOG/VARADD.CPP  $
** 
**    Rev 1.2.1.4   17 Apr 1997 16:08:54   ZJRD
** No change.
** 
**    Rev 1.2.1.3   16 Apr 1997 10:44:22   ZJRD
** No change.
** 
**    Rev 1.2.1.2   10 Apr 1997 15:48:54   ZJRD
** No change.
** 
**    Rev 1.2.1.1   03 Apr 1997 15:28:00   ZJRD
** No change.
** 
**    Rev 1.2.1.0   28 Mar 1997 10:31:18   ZJRD
** easy pack sld 2.09d
** 
**    Rev 1.1   19 Mar 1997 11:40:30   ZJRD
** No change.
** 
**    Rev 1.0   12 Mar 1997 14:53:24   ZJRD
** Initial revision.
** 
**    Rev 1.7.1.0.1.2   09 Dec 1996 10:16:04   ZJRD
** EasyPack/SLD Version 2.0P
** 
**    Rev 1.7.1.0.1.0   11 Nov 1996 12:59:20   ZJRD
** EasyPack/SLD Version 2.01
** 
**    Rev 1.7.1.4   09 Sep 1996 13:18:02   ZJRD
** No change.
** 
**    Rev 1.7.1.3   05 Sep 1996 11:29:32   ZJRD
** No change.
** 
**    Rev 1.7.1.2   02 Sep 1996 09:56:36   ZJRD
** No change.
** 
**    Rev 1.7.1.1   28 Aug 1996 15:52:26   ZJRD
** No change.
** 
**    Rev 1.7.1.0   12 Aug 1996 10:55:56   ZJRD
** EasyPack/SLD Version 1.98
** 
**    Rev 1.5   05 Jun 1996 14:58:56   ZJRD
** No change.
** 
**    Rev 1.4   29 May 1996 09:31:32   ZJRD
** No change.
** 
**    Rev 1.3   16 May 1996 09:04:46   ZJRD
** No change.
** 
**    Rev 1.2   10 May 1996 09:13:40   ZJRD
** No change.
** 
**    Rev 1.1   02 May 1996 10:24:14   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.31   18 Apr 1996 12:53:26   Shirley
** No change.
** 
**    Rev 1.30   12 Apr 1996 10:40:16   Shirley
** No change.
** 
**    Rev 1.29   02 Apr 1996 09:22:44   Shirley
** No change.
** 
**    Rev 1.28   15 Feb 1996 08:53:54   Shirley
** No change.
** 
**    Rev 1.27   12 Feb 1996 14:09:12   Shirley
** No change.
** 
**    Rev 1.26   06 Feb 1996 15:35:36   Shirley
** No change.
** 
**    Rev 1.25   06 Feb 1996 13:49:52   Shirley
** No change.
** 
**    Rev 1.24   01 Feb 1996 10:14:22   Shirley
** No change.
** 
**    Rev 1.23   26 Jan 1996 09:20:16   Shirley
** No change.
** 
**    Rev 1.22   25 Jan 1996 13:20:10   Shirley
** No change.
** 
**    Rev 1.21   24 Jan 1996 10:39:02   Shirley
** No change.
** 
**    Rev 1.20   23 Jan 1996 11:27:50   Shirley
** No change.
** 
**    Rev 1.19   18 Jan 1996 10:09:46   Shirley
** No change.
** 
**    Rev 1.18   15 Jan 1996 16:16:04   Shirley
** No change.
** 
**    Rev 1.17   04 Jan 1996 11:11:36   Shirley
** No change.
** 
**    Rev 1.16   30 Nov 1995 09:08:14   Shirley
** No change.
** 
**    Rev 1.15   28 Nov 1995 15:34:46   Shirley
** No change.
** 
**    Rev 1.14   21 Nov 1995 11:22:30   Shirley
** No change.
** 
**    Rev 1.13   13 Nov 1995 09:27:50   Shirley
** No change.
** 
**    Rev 1.12   12 Nov 1995 11:31:20   Shirley
** No change.
** 
**    Rev 1.11   08 Nov 1995 16:27:56   Shirley
** No change.
** 
**    Rev 1.10   08 Nov 1995 12:41:10   Shirley
** No change.
** 
**    Rev 1.9   02 Nov 1995 10:06:50   Shirley
** No change.
** 
**    Rev 1.8   27 Oct 1995 16:51:16   Shirley
** No change.
** 
**    Rev 1.7   27 Oct 1995 13:44:04   Shirley
** No change.
** 
**    Rev 1.6   25 Oct 1995 14:25:50   Shirley
** No change.
** 
**    Rev 1.5   18 Oct 1995 14:47:26   Shirley
** No change.
** 
**    Rev 1.4   13 Oct 1995 13:23:36   Shirley
** No change.
** 
**    Rev 1.3   29 Sep 1995 09:50:06   Shirley
** EasyPack/SLD Version 0.1c
** 
**    Rev 1.2   20 Sep 1995 10:56:44   Shirley
** No change.
** 
**    Rev 1.1   15 Sep 1995 09:45:42   Shirley
** No change.
** 
**    Rev 1.0   07 Sep 1995 09:55:46   Shirley
** Initial revision.
**
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name: VARADD.CPP
//
//  Description: The implementation file fore class: CVarAddVariableDialog.
//
//  Author: Chen Jun
//
//  Date: 07/26/95
//
//  Modification:
//      1. 07/26/95, Initial version of the class: CVarAddVariableDialog.
//
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// Include files.
#include "stdafx.h"
#include "resource.h"

#include "varadd.h"


/////////////////////////////////////////////////////////////////////////////
// Debug flags.
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// Global variables.
CStringList* pVarAddVariableList;


/////////////////////////////////////////////////////////////////////////////
// External function prototypes.
void VarAddVariable(void);


/////////////////////////////////////////////////////////////////////////////
// CVarAddVariableDialog dialog


CVarAddVariableDialog::CVarAddVariableDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CVarAddVariableDialog::IDD, pParent)
{
    //{{AFX_DATA_INIT(CVarAddVariableDialog)
    m_strVariable = "";
    //}}AFX_DATA_INIT

    // Initial.
    m_isDropdown = FALSE;
}

void CVarAddVariableDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CVarAddVariableDialog)
    DDX_Control(pDX, IDC_COMBO_ADDVARIABLE_VARIABLE, m_comboVariable);
    DDX_CBString(pDX, IDC_COMBO_ADDVARIABLE_VARIABLE, m_strVariable);
    DDV_MaxChars(pDX, m_strVariable, 80);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CVarAddVariableDialog, CDialog)
    //{{AFX_MSG_MAP(CVarAddVariableDialog)
    ON_CBN_DROPDOWN(IDC_COMBO_ADDVARIABLE_VARIABLE, OnDropdownComboVariable)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CVarAddVariableDialog message handlers

void CVarAddVariableDialog::OnCancel()
{
    // TODO: Add extra cleanup here
    
    CDialog::OnCancel();
}

void CVarAddVariableDialog::OnOK()
{
    // TODO: Add extra validation here

    // Detect if it has been dropdown.
    if ( m_isDropdown ) {
        // Add to the global list.
        ::pVarAddVariableList->RemoveAll();
        CString str;
        for ( int i = 0; i < m_comboVariable.GetCount(); i++ ) {
            m_comboVariable.GetLBText(i, str);
            if ( !str.IsEmpty() ) {
                ::pVarAddVariableList->AddTail(str);
            }
        }
    }

    // Get from the combo edit box.
    m_comboVariable.GetWindowText(m_strVariable);
    if ( !m_strVariable.IsEmpty() ) {
        ::pVarAddVariableList->AddTail(m_strVariable);
        // Call kernel routine.
        ::VarAddVariable();
    }
    
    CDialog::OnOK();
}

void CVarAddVariableDialog::OnDropdownComboVariable()
{
    // TODO: Add your control notification handler code here

    // Get the last entered string from the combo box.
    m_comboVariable.GetWindowText(m_strVariable);
    
    // Detect if it has been dropdown.
    if ( !m_isDropdown ) {
        // Set the dropdown flag.
        m_isDropdown = TRUE;
        // Get the variable name from the global list.
        if ( !::pVarAddVariableList->IsEmpty() ) {
            m_comboVariable.ResetContent();
            POSITION posHead = ::pVarAddVariableList->GetHeadPosition();
            while ( posHead ) {
                CString str=(CString)::pVarAddVariableList->GetNext(posHead);
                m_comboVariable.AddString(str);
            }
        }
    }
        
    // Add the last entered string to the combo box.
    m_comboVariable.SetWindowText(m_strVariable);
}

BOOL CVarAddVariableDialog::OnInitDialog()
{
    CDialog::OnInitDialog();
    
    // TODO: Add extra initialization here

    // Central the dialog position.
    CenterWindow();
        
    // Set the last variable name.
    if ( !::pVarAddVariableList->IsEmpty() ) {
        m_strVariable = (CString)::pVarAddVariableList->GetTail();
    }
    else {
        // Initial value.
        m_strVariable = "";
    }

    // Show the selected variable.
    m_comboVariable.SetWindowText(m_strVariable);

    // Set the initial value.
    UpdateData(FALSE);

    return TRUE;  // return TRUE  unless you set the focus to a control
}
