
/***************************************************************************
**
**    $Header:   D:/PICSLDV/SRC/LOG/VAREDIT.CPP   1.14   09 Jan 1997 14:26:38   ZJRD  $
**
**    $Log:   D:/PICSLDV/SRC/LOG/VAREDIT.CPP  $
** 
**    Rev 1.14   09 Jan 1997 14:26:38   ZJRD
** No change.
** 
**    Rev 1.13   13 Dec 1996 11:21:28   ZJRD
** No change.
** 
**    Rev 1.12   22 Nov 1996 11:02:30   ZJRD
** No change.
** 
**    Rev 1.11   11 Nov 1996 12:49:44   ZJRD
** No change.
** 
**    Rev 1.10   06 Nov 1996 13:01:44   ZJRD
** No change.
** 
**    Rev 1.9   02 Nov 1996 09:48:14   ZJRD
** No change.
** 
**    Rev 1.8   30 Oct 1996 12:50:38   ZJRD
** No change.
** 
**    Rev 1.7   28 Oct 1996 09:43:26   ZJRD
** No change.
** 
**    Rev 1.6   21 Oct 1996 09:17:40   ZJRD
** No change.
** 
**    Rev 1.5   09 Oct 1996 13:47:14   ZJRD
** No change.
** 
**    Rev 1.4   23 Sep 1996 10:36:04   ZJRD
** No change.
** 
**    Rev 1.3   06 Sep 1996 13:50:38   ZJRD
** No change.
** 
**    Rev 1.2   02 Sep 1996 11:31:42   ZJRD
** No change.
** 
**    Rev 1.1   15 Aug 1996 10:08:58   ZJRD
** No change.
** 
**    Rev 1.0   13 Aug 1996 09:19:52   ZJRD
** Initial revision.
** 
****************************************************************************/

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


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

#include "varedit.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// Global variables.
CStringList* pVarEditVariableList;


/////////////////////////////////////////////////////////////////////////////
// External function prototypes.
void VarGetHighlightName(CString& strName);
void VarEditVariable(void);


/////////////////////////////////////////////////////////////////////////////
// CVarEditVariableDialog dialog


CVarEditVariableDialog::CVarEditVariableDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CVarEditVariableDialog::IDD, pParent)
{
    //{{AFX_DATA_INIT(CVarEditVariableDialog)
    m_strVariable = "";
    //}}AFX_DATA_INIT
    
    // Initial.
    m_isDropdown = FALSE;
}

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

BEGIN_MESSAGE_MAP(CVarEditVariableDialog, CDialog)
    //{{AFX_MSG_MAP(CVarEditVariableDialog)
    ON_CBN_DROPDOWN(IDC_COMBO_EDITVARIABLE_VARIABLE, OnDropdownComboVariable)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CVarEditVariableDialog message handlers

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

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

    // Add to combo list box.
    m_comboVariable.GetWindowText(m_strVariable);
    if ( !m_strVariable.IsEmpty() ) {
        ::pVarEditVariableList->AddTail(m_strVariable);
        // Call kernel routine.
        ::VarEditVariable();
    }

    CDialog::OnOK();
}

void CVarEditVariableDialog::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 ( !::pVarEditVariableList->IsEmpty() ) {
            m_comboVariable.ResetContent();
            POSITION posHead = ::pVarEditVariableList->GetHeadPosition();
            while ( posHead ) {
                CString str = 
                    (CString)::pVarEditVariableList->GetNext(posHead);
                m_comboVariable.AddString(str);
            }
        }
    }
        
    // Add the last entered string to the combo box.
    m_comboVariable.SetWindowText(m_strVariable);
}

BOOL CVarEditVariableDialog::OnInitDialog()
{
    CDialog::OnInitDialog();
    
    // TODO: Add extra initialization here
    
    // Central the dialog position.
    CenterWindow();
        
    // Get the current highlight variable name.
    ::VarGetHighlightName(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
}
