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


// PageChannelInfo.cpp : implementation file
//

#include "stdafx.h"
#include "PageChannelInfo.h"

#include "Resource.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPageChannelInfo property page

IMPLEMENT_DYNAMIC(CPageChannelInfo, CConfigWizPage)

CPageChannelInfo::CPageChannelInfo(UINT const nIDTemplate) : CConfigWizPage(nIDTemplate)
{
	//{{AFX_DATA_INIT(CPageChannelInfo)
	m_strPhoneNumber = _T("");
	m_strSpidSubAddress = _T("");
	//}}AFX_DATA_INIT

   m_strSpid = _T("");
   m_fNeedSpid = FALSE;
   m_strSubAddress = _T("");
   m_fNeedSubAddress = FALSE;
}

CPageChannelInfo::~CPageChannelInfo()
{
}

void CPageChannelInfo::DoDataExchange(CDataExchange* pDX)
{
	CConfigWizPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageChannelInfo)
	DDX_Control(pDX, IDC_SpidLabel, m_ctrlSpidLabel);
	DDX_Control(pDX, IDC_SpidEdit, m_ctrlSpid);
	DDX_Text(pDX, IDC_PhoneNumberEdit, m_strPhoneNumber);
	DDV_MaxChars(pDX, m_strPhoneNumber, 20);
	DDX_Text(pDX, IDC_SpidEdit, m_strSpidSubAddress);
	DDV_MaxChars(pDX, m_strSpidSubAddress, 20);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageChannelInfo, CConfigWizPage)
	//{{AFX_MSG_MAP(CPageChannelInfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CPageChannelInfo::EnableSpidSubAddressWindows(BOOL const fSpid, BOOL const fSubAddress)
{
   CString Label = _T("");;
   // This control is named poorly and is used for both SPID and Sub Address
   m_ctrlSpid.EnableWindow(fSpid || fSubAddress);
   m_ctrlSpidLabel.EnableWindow(fSpid || fSubAddress);
   // Set the text according to the value we're interested in
   if (fSpid)
      Label.LoadString(IDS_Spid_Label);
   if (fSubAddress)
      Label.LoadString(IDS_SubAddres_Label);
   m_ctrlSpidLabel.SetWindowText(Label);
}

void CPageChannelInfo::SetChannelInfo(CString const & strPhoneNumber, CString const & strSpid, BOOL const fNeedSpid, CString const & strSubAddress, BOOL const fNeedSubAddress)
{
   try
   {
      m_strPhoneNumber = strPhoneNumber;
      m_strSpid = strSpid;
      m_fNeedSpid = fNeedSpid;
      m_strSubAddress = strSubAddress;
      m_fNeedSubAddress = fNeedSubAddress;

      // Fill in SpidSubAddress edit with Spid or SubAddress
      if (m_fNeedSpid)
         m_strSpidSubAddress = m_strSpid;
      if (m_fNeedSubAddress)
         m_strSpidSubAddress = m_strSubAddress;

      if (m_hWnd != NULL)
      {
         UpdateData(FALSE);
         EnableSpidSubAddressWindows(m_fNeedSpid, m_fNeedSubAddress);
      }
   }
   catch (CAffirmException ae)
   {
   }
}

void CPageChannelInfo::GetChannelInfo(CString & strPhoneNumber, CString & strSpid, CString & strSubAddress)
{
   try
   {
      if (m_hWnd != NULL) UpdateData();

      // We use the same control and member variable to get Spid or SubAddress
      m_strSpid = m_fNeedSpid ? m_strSpidSubAddress : _T("");
      m_strSubAddress = m_fNeedSubAddress ? m_strSpidSubAddress : _T("");

      strPhoneNumber = m_strPhoneNumber;
      strSpid = m_strSpid;
      strSubAddress = m_strSubAddress;
   }
   catch (CAffirmException ae)
   {
   }
}


/////////////////////////////////////////////////////////////////////////////
// CPageChannelInfo message handlers

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

   EnableSpidSubAddressWindows(m_fNeedSpid, m_fNeedSubAddress);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
