/*****************************************************************************
* Copyright (c) 1990-2000 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
*
*****************************************************************************/


// PageBRISwitch.cpp : implementation file
//

#include "stdafx.h"
#include "PageBRISwitch.h"

#include "Resource.h"

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

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

/////////////////////////////////////////////////////////////////////////////
// CPageBRISwitch property page

IMPLEMENT_DYNAMIC(CPageBRISwitch, CConfigWizPage)

void CPageBRISwitch::InitData(void)
{
	//{{AFX_DATA_INIT(CPageBRISwitch)
	m_fAutoSpid = FALSE;
	m_iSwitch = -1;
	//}}AFX_DATA_INIT

   try
   {
      AffirmThrow(m_SwitchMap.Init(SValueMap::MAP_BRI_SWITCH));

      m_fMSNPageAdded = FALSE;
      m_pSheet = NULL;
      m_pMSNPage = NULL;
   }
   catch (CAffirmException ae)
   {
   }
}

CPageBRISwitch::CPageBRISwitch() : CConfigWizPage()
{
   InitData();
}

CPageBRISwitch::CPageBRISwitch(int const eMode, CConfigObject const * const pOwner /* = NULL */, int const nState /* = -1 */) : CConfigWizPage()
{
   InitData();
   Construct(eMode, pOwner, nState);
}

void CPageBRISwitch::Construct(int const eMode, CConfigObject const * const pOwner /* = NULL */, int const nState /* = -1 */)
{
   CConfigWizPage::Construct((eMode == WIZARD) ? IDD_WizPageBRISwitch : IDD_PropPageBRISwitch, 0, pOwner, nState);
}

CPageBRISwitch::~CPageBRISwitch()
{
}

void CPageBRISwitch::DoDataExchange(CDataExchange* pDX)
{
	CConfigWizPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageBRISwitch)
	DDX_Control(pDX, IDC_SwitchType, m_ctrlSwitchType);
	DDX_Control(pDX, IDC_AutoSPID, m_ctrlAutoSpid);
	DDX_Check(pDX, IDC_AutoSPID, m_fAutoSpid);
	DDX_CBIndex(pDX, IDC_SwitchType, m_iSwitch);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageBRISwitch, CConfigWizPage)
	//{{AFX_MSG_MAP(CPageBRISwitch)
	ON_CBN_SELCHANGE(IDC_SwitchType, OnSelchangeSwitchType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CPageBRISwitch::SetSwitchType(DWORD const dwSwitch)
{
   try
   {
      m_iSwitch = m_SwitchMap.ToIndex(dwSwitch);
      if (m_hWnd != NULL) UpdateData(FALSE);
   }
   catch (CAffirmException ae)
   {
   }
}

DWORD CPageBRISwitch::GetSwitchType(void)
{
   DWORD dwSwitch = 0;

   try
   {
      if (m_hWnd != NULL) UpdateData();
      dwSwitch = m_SwitchMap.FromIndex(m_iSwitch);
   }
   catch (CAffirmException ae)
   {
   }

   return dwSwitch;
}

void CPageBRISwitch::SetAutoSpid(DWORD const dwAutoSpid)
{
   try
   {
      m_fAutoSpid = (dwAutoSpid == BRI_AUTOSPID_ON);
      if (m_hWnd != NULL) UpdateData(FALSE);
   }
   catch (CAffirmException ae)
   {
   }
}

DWORD CPageBRISwitch::GetAutoSpid(void)
{
   DWORD dwAutoSpid = FALSE;

   try
   {
      if (m_hWnd != NULL) UpdateData();
      dwAutoSpid = m_fAutoSpid ? BRI_AUTOSPID_ON : BRI_AUTOSPID_OFF;
   }
   catch (CAffirmException ae)
   {
   }

   return dwAutoSpid;
}

void CPageBRISwitch::EnableAutoSpid(BOOL const fEnabled)
{
   m_ctrlAutoSpid.EnableWindow(fEnabled);
}

/////////////////////////////////////////////////////////////////////////////
// CPageBRISwitch message handlers

void CPageBRISwitch::OnSelchangeSwitchType() 
{
   // Don't allow auto spid for these switch types
   BOOL fEnableAutoSpid = (GetSwitchType() != BRI_ETSI) && (GetSwitchType() != BRI_JAPAN);
   EnableAutoSpid(fEnableAutoSpid);

   if ((m_pSheet != NULL) && (m_pMSNPage != NULL))
   {
      if (GetSwitchType() == BRI_ETSI)
      {
         if (!m_fMSNPageAdded)
         {
            m_fMSNPageAdded = TRUE;
            m_pSheet->AddPage(m_pMSNPage);
         }
      }
      else
      {
         if (m_fMSNPageAdded)
         {
            m_fMSNPageAdded = FALSE;
            m_pSheet->RemovePage(m_pMSNPage);
         }
      }
   }
}

BOOL CPageBRISwitch::OnInitDialog() 
{
	CConfigWizPage::OnInitDialog();

   for (int i = 0; i < m_SwitchMap.astrDisplayNames.GetSize(); i++)
      m_ctrlSwitchType.AddString(m_SwitchMap.astrDisplayNames[i]);

   UpdateData(FALSE);
   OnSelchangeSwitchType();

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