/*****************************************************************************
* 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
*
*****************************************************************************/


// PropPRI.cpp : implementation file
//

#include "stdafx.h"
#include "PropPRI.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPropPRI property page

IMPLEMENT_DYNCREATE(CPropPRI, CPropertyPage)

CPropPRI::CPropPRI(UINT const nIDCaption /* = 0 */) : CPropertyPage(CPropPRI::IDD, nIDCaption)
{
	//{{AFX_DATA_INIT(CPropPRI)
	m_iAddressType = -1;
	m_iNumberingPlan = -1;
	m_iSubaddressType = -1;
	m_iSwitchType = -1;
	//}}AFX_DATA_INIT

   try
   {
      m_AddressTypeMap.Init(SValueMap::MAP_DCHAN_ADDRTYPE);
      m_NumberingPlanMap.Init(SValueMap::MAP_DCHAN_NUMPLAN);
      m_SubaddressTypeMap.Init(SValueMap::MAP_DCHAN_SUBADDRTYPE);
   }
   catch (CAffirmException ae)
   {
   }
}

CPropPRI::~CPropPRI()
{
}

void CPropPRI::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropPRI)
	DDX_Control(pDX, IDC_SwitchType, m_ctrlSwitchType);
	DDX_Control(pDX, IDC_SubaddressType, m_ctrlSubaddressType);
	DDX_Control(pDX, IDC_NumberingPlan, m_ctrlNumberingPlan);
	DDX_Control(pDX, IDC_AddressType, m_ctrlAddressType);
	DDX_CBIndex(pDX, IDC_AddressType, m_iAddressType);
	DDX_CBIndex(pDX, IDC_NumberingPlan, m_iNumberingPlan);
	DDX_CBIndex(pDX, IDC_SubaddressType, m_iSubaddressType);
	DDX_CBIndex(pDX, IDC_SwitchType, m_iSwitchType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropPRI, CPropertyPage)
	//{{AFX_MSG_MAP(CPropPRI)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CPropPRI::SetSwitchType(int const eSwitchMap, DWORD const dwSwitchType)
{
   try
   {
      AffirmThrow((eSwitchMap == SValueMap::MAP_PRI_SWITCH) || (eSwitchMap == SValueMap::MAP_E1_SWITCH));
      m_SwitchMap.Init(eSwitchMap);

      m_iSwitchType = m_SwitchMap.ToIndex(dwSwitchType);
      if (m_hWnd != NULL) UpdateData(FALSE);
   }
   catch (CAffirmException ae)
   {
   }
}

DWORD CPropPRI::GetSwitchType(void)
{
   DWORD dwSwitchType = 0;

   try
   {
      if (m_hWnd != NULL) UpdateData();
#ifdef NT5
	  // since we hide the switch combo box, UpdateData will set m_iSwitch to -1.
	  // which will cause problems.
	  m_iSwitchType = 0;
#endif
      dwSwitchType = m_SwitchMap.FromIndex(m_iSwitchType);
   }
   catch (CAffirmException ae)
   {
   }

   return dwSwitchType;
}

BOOL CPropPRI::SetDChanExtConfig(dchan_ext_config_t const * const pDChanExtConfig)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(pDChanExtConfig != NULL);

      m_iAddressType = m_AddressTypeMap.ToIndex(pDChanExtConfig->address_type);
      m_iNumberingPlan = m_NumberingPlanMap.ToIndex(pDChanExtConfig->numbering_plan);
      m_iSubaddressType = m_SubaddressTypeMap.ToIndex(pDChanExtConfig->subaddress_type);

      if (m_hWnd != NULL) UpdateData(FALSE);

      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

BOOL CPropPRI::GetDChanExtConfig(dchan_ext_config_t * const pDChanExtConfig)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(pDChanExtConfig != NULL);

      if (m_hWnd != NULL) UpdateData();

      pDChanExtConfig->address_type = m_AddressTypeMap.FromIndex(m_iAddressType);
      pDChanExtConfig->numbering_plan = m_NumberingPlanMap.FromIndex(m_iNumberingPlan);
      pDChanExtConfig->subaddress_type = m_SubaddressTypeMap.FromIndex(m_iSubaddressType);

      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

/////////////////////////////////////////////////////////////////////////////
// CPropPRI message handlers

BOOL CPropPRI::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
#ifndef NT5
   FillComboBox(m_ctrlSwitchType, m_SwitchMap.astrDisplayNames, m_iSwitchType);
#else
   // for NT5 we don't ask for switch type
   m_ctrlSwitchType.ShowWindow(SW_HIDE);
   (GetDlgItem(IDC_SwitchTypeLabel))->ShowWindow(SW_HIDE);
#endif 
   FillComboBox(m_ctrlAddressType, m_AddressTypeMap.astrDisplayNames, m_iAddressType);
   FillComboBox(m_ctrlNumberingPlan, m_NumberingPlanMap.astrDisplayNames, m_iNumberingPlan);
   FillComboBox(m_ctrlSubaddressType, m_SubaddressTypeMap.astrDisplayNames, m_iSubaddressType);

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