/*****************************************************************************
* 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
*
*****************************************************************************/
// ModeSet.cpp : implementation file
// Sets the various LinkService modes as required by IBMSDLC/IBMX25 DLL's
// This module lifted straight from the SDK

#include "stdafx.h"
#include "ModeSet.h"
#include "common.h"

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

//
// Global Variables and Data Structures
//
extern MGSDLCDS	gMgsdlc_data;



/////////////////////////////////////////////////////////////////////////////
// CModeSet property page

IMPLEMENT_DYNCREATE(CModeSet, CPropertyPage)

CModeSet::CModeSet() : CPropertyPage(CModeSet::IDD)
{
	//{{AFX_DATA_INIT(CModeSet)
	m_constantrts = FALSE;
	m_servicetitle = _T("");
	m_servicename = _T("");
	m_distributable = FALSE;
	//}}AFX_DATA_INIT
	m_psp.dwFlags |= PSP_HASHELP;
}

CModeSet::~CModeSet()
{
}

void CModeSet::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CModeSet)
	DDX_Check(pDX, IDC_CONSTANTRTS, m_constantrts);
	DDX_Text(pDX, IDC_SERVICETITLE, m_servicetitle);
	DDX_Text(pDX, IDC_SERVICENAME, m_servicename);
	DDX_Check(pDX, IDC_DISTRIBUTABLE, m_distributable);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CModeSet message handlers


BOOL CModeSet::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
#ifdef SNAX25
	GetDlgItem(IDC_CONSTANTRTS)->ShowWindow(SW_HIDE);
#endif
	
	// TODO: Add extra initialization here
	m_psp.dwFlags |= PSP_HASHELP;

	if (!strcmp(gMgsdlc_data.szLineType, "0"))
	{
		CModeSet::CheckDlgButton(IDC_LEASEDLINE, 1);
	}
	else if (!strcmp(gMgsdlc_data.szRadio4Flag, "1"))
	{
		CModeSet::CheckDlgButton(IDC_SWMD, 1);
	}
	else
	{
		CModeSet::CheckDlgButton(IDC_SWMSN, 1);
	}

	if (!strcmp(gMgsdlc_data.szConstantRTS, "1"))
	{
		m_constantrts = TRUE;
	}

	if (!strcmp(gMgsdlc_data.szDistributable, "1"))
	{
		m_distributable = TRUE;
	}

	m_servicetitle = gMgsdlc_data.szLinkServiceTitle;
	m_servicename = gMgsdlc_data.szLinkServiceName;
	
	CModeSet::UpdateData(FALSE);

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

void CModeSet::OnOK() 
{
	// TODO: Add your specialized code here and/or call the base class
	CModeSet::UpdateData(TRUE);

	strcpy(gMgsdlc_data.szLinkServiceName, m_servicename);

	strcpy(gMgsdlc_data.szLinkServiceServicesRegistryRoot, m_servicename);

	strcpy(gMgsdlc_data.szLinkServiceTitle, m_servicetitle);

	strcpy(gMgsdlc_data.szRadio4Flag, "0");

	strcpy(gMgsdlc_data.szConstantRTS,"0");
	if (m_constantrts)
	{
		strcpy(gMgsdlc_data.szConstantRTS,"1");
	}

	strcpy(gMgsdlc_data.szDistributable, "0");
	if (m_distributable)
	{
		strcpy(gMgsdlc_data.szDistributable, "1");
	}
	
	if (CModeSet::IsDlgButtonChecked(IDC_LEASEDLINE))
	{
		strcpy(gMgsdlc_data.szLineType, "0");
	}
	else if (CModeSet::IsDlgButtonChecked(IDC_SWMSN))
	{
		strcpy(gMgsdlc_data.szLineType, "1");
	}
	else if (CModeSet::IsDlgButtonChecked(IDC_SWMD))
	{
		strcpy(gMgsdlc_data.szLineType, "1");
		strcpy(gMgsdlc_data.szRadio4Flag, "1");
	}

	// CPropertyPage::OnOK();
}

BOOL CModeSet::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	switch (wParam)
	{
		case	ID_HELP:
		{
			::WinHelp(::GetActiveWindow(),"IBMSDLC.HLP",HELP_CONTEXT,111);
			break;
		}
	}

	return CPropertyPage::OnCommand(wParam, lParam);
}
