/*****************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/


// PropAdvanced.cpp : implementation file
//

#include "stdafx.h"
#include "PropAdvanced.h"

#include "dxbtypes.h"
#include "mgmthlc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPropAdvPRI property page

IMPLEMENT_DYNCREATE(CPropAdvPRI, CPropertyPage)

CPropAdvPRI::CPropAdvPRI() : CPropertyPage(CPropAdvPRI::IDD)
{
	//{{AFX_DATA_INIT(CPropAdvPRI)
	m_fLoopback = FALSE;
	m_nLoopbackMode = 0;
	//}}AFX_DATA_INIT

   m_fShowDChan = TRUE;
   m_fEnableDChan = TRUE;
}

CPropAdvPRI::~CPropAdvPRI()
{
}

void CPropAdvPRI::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropAdvPRI)
	DDX_Control(pDX, IDC_AdvancedTE, m_ctrlAdvancedTE);
	DDX_Control(pDX, IDC_AdvancedNT, m_ctrlAdvancedNT);
	DDX_Control(pDX, IDC_AdvancedLoopbackGroup, m_ctrlAdvancedLoopbackGroup);
	DDX_Control(pDX, IDC_AdvancedLoopback, m_ctrlAdvancedLoopback);
	DDX_Check(pDX, IDC_AdvancedLoopback, m_fLoopback);
	DDX_Radio(pDX, IDC_AdvancedTE, m_nLoopbackMode);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropAdvPRI, CPropertyPage)
	//{{AFX_MSG_MAP(CPropAdvPRI)
	ON_BN_CLICKED(IDC_AdvancedLoopback, OnAdvancedLoopback)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CPropAdvPRI::UpdateDChanModeControls()
{
   try
   {
      int nShow = m_fShowDChan ? SW_SHOW: SW_HIDE;

      m_ctrlAdvancedLoopbackGroup.ShowWindow(nShow);
      m_ctrlAdvancedLoopback.ShowWindow(nShow);
      m_ctrlAdvancedTE.ShowWindow(nShow);
      m_ctrlAdvancedNT.ShowWindow(nShow);

      m_ctrlAdvancedLoopbackGroup.EnableWindow(m_fEnableDChan);
      m_ctrlAdvancedLoopback.EnableWindow(m_fEnableDChan);
      m_ctrlAdvancedTE.EnableWindow(m_fEnableDChan);
      m_ctrlAdvancedNT.EnableWindow(m_fEnableDChan);
   }
   catch (CAffirmException ae)
   {
   }
}

/////////////////////////////////////////////////////////////////////////////
// CPropAdvPRI message handlers

void CPropAdvPRI::OnAdvancedLoopback() 
{
   try
   {
      UpdateData();

      CWnd * cwnd = GetDlgItem(IDC_AdvancedTE);
      AffirmThrow(cwnd != NULL);
      cwnd->EnableWindow(m_fLoopback);

      cwnd = GetDlgItem(IDC_AdvancedNT);
      AffirmThrow(cwnd != NULL);
      cwnd->EnableWindow(m_fLoopback);
   }
   catch (CAffirmException ae)
   {
   }
}

enum
{
   LOOPBACK_TE = 0,
   LOOPBACK_NT,
};

void CPropAdvPRI::OnOK() 
{
   UpdateData();

   m_dwMode = !m_fLoopback ? DCHAN_NORMAL :
               ((m_nLoopbackMode == LOOPBACK_TE) ? DCHAN_LOOPBACK_TE : DCHAN_LOOPBACK_NT);

	CPropertyPage::OnOK();
}

BOOL CPropAdvPRI::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
   m_fLoopback = (m_dwMode != DCHAN_NORMAL);
   m_nLoopbackMode = (m_dwMode == DCHAN_LOOPBACK_NT) ? LOOPBACK_NT : LOOPBACK_TE;

   UpdateData(FALSE);

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