/*****************************************************************************
* 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
*
*****************************************************************************/
// PortPage.cpp : implementation file
//

#include "stdafx.h"
#include "DIGICSNT.h"
#include "PortPage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPortPage property page

IMPLEMENT_DYNCREATE(CPortPage, CPropertyPage)

CPortPage::CPortPage() : CPropertyPage(CPortPage::IDD)
{
	//{{AFX_DATA_INIT(CPortPage)
	m_bConstantRTS = FALSE;
	m_bInternalClocking = FALSE;
	m_szPortName = _T("");
	//}}AFX_DATA_INIT
	m_nLineSpeed = -1;
}

CPortPage::~CPortPage()
{
}

void CPortPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPortPage)
	DDX_Control(pDX, IDC_SPEED, m_cLineSpeed);
	DDX_Check(pDX, IDC_CONSTANTRTS, m_bConstantRTS);
	DDX_Check(pDX, IDC_INTERNALCLOCK, m_bInternalClocking);
	DDX_Text(pDX, IDC_PORTNAME, m_szPortName);
	DDV_MaxChars(pDX, m_szPortName, 8);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPortPage, CPropertyPage)
	//{{AFX_MSG_MAP(CPortPage)
	ON_CBN_SELCHANGE(IDC_SPEED, OnSelchangeSpeed)
	ON_WM_HELPINFO()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPortPage message handlers
static	int linespeeds[] = {
		2400,4800,9600,19200,38400,56000,64000,128000,256000,
		512000,1024000,1536000,2048000
		};

void CPortPage::OnOK() 
{
	CPropertyPage::OnOK();

}

BOOL CPortPage::OnInitDialog() 
{
	
	ASSERT(m_nLineSpeed != -1);
	CPropertyPage::OnInitDialog();
	m_cLineSpeed.ResetContent();
	
	int count = sizeof(linespeeds)/sizeof(linespeeds[0]);
	int sel = -1;
	CString strTemp;
	for (int i=0;i<count;i++)
	{
		strTemp.Format("%d",linespeeds[i]);
		m_cLineSpeed.InsertString(i,strTemp);
		if (m_nLineSpeed == linespeeds[i])
			sel = i;

	}
	
	ASSERT(sel != -1);
	m_cLineSpeed.SetCurSel(sel);


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


void CPortPage::OnSelchangeSpeed() 
{
	int index = m_cLineSpeed.GetCurSel();

	if (index != CB_ERR)
		m_nLineSpeed = linespeeds[index];

	
}




BOOL CPortPage::OnHelpInfo(HELPINFO* pHelpInfo) 
{
	// for any control within this property page, WM_HELP will be sent to 
	// to it when user presses F1. We don't provide a help file and so
	// we simply fake handling of the message. 
	// For some reason, running with IBM Comm Server, this message is causing
	// the PCSCFG.EXE (configuration program) to crash.
	return TRUE;

}
