/*
*******************************************************************************
* Copyright (c) 1996-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 copyright work  Digi   International *
* Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is *
* strictly prohibited.                                                        *
*                                                                             *
* Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc. *
* Confidential  when   combined   with   the   aggregated  modules  for  this *
* product) OBJECT CODE ONLY SOURCE MATERIALS                                  *
*                                                                             *
* (C) COPYRIGHT Digi International Inc. 1996-97                               *
*                                                                             *
* All Rights Reserved                                                         *
*                                                                             *
* US   Government   Users   Restricted   Rights   -   Use,   duplication   or *
* disclosure  restricted by GSA ADP Schedule Contract with Digi International *
* Inc.                                                                        *
*                                                                             *
*******************************************************************************

// Filter.cpp : implementation file

*/

#include "stdafx.h"
#include "Diagnostic.h"
#include "Filter.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFRFilter dialog

CFRFilter::CFRFilter(CWnd* pParent /*=NULL*/)
	: CDialog(CFRFilter::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFRFilter)
	m_AllRadio = -1;
	m_1490Radio = -1;
	//}}AFX_DATA_INIT
}


void CFRFilter::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFRFilter)
	DDX_Radio(pDX, IDC_FRAllAll, m_AllRadio);
	DDX_Radio(pDX, IDC_1490All, m_1490Radio);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFRFilter, CDialog)
	//{{AFX_MSG_MAP(CFRFilter)
	//}}AFX_MSG_MAP
	ON_CONTROL_RANGE(BN_CLICKED, IDC_FRAllAll, IDC_1490, On1490All)
	ON_CONTROL(LBN_SELCHANGE, 1, OnSelchangeCircuit)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFRFilter message handlers

void CFRFilter::OnSelchangeCircuit()
{
	if (m_DLCI.GetCheck(0)) {
		m_DLCI.SetCheck(0, FALSE);
		for (short i = 2; i < m_DLCI.GetCount(); i++)
			m_DLCI.SetCheck(i, TRUE);
		}
	else if (m_DLCI.GetCheck(1)) {
		m_DLCI.SetCheck(1, FALSE);
		for (short i = 2; i < m_DLCI.GetCount(); i++)
			m_DLCI.SetCheck(i, FALSE);
		}
}

BOOL CFRFilter::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rect;

	GetDlgItem(IDC_FilterFrame)->GetWindowRect(rect);
	ScreenToClient(rect);

	m_DLCI.Create(LBS_STANDARD | WS_VISIBLE | WS_TABSTOP | WS_CHILD |
								LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
								rect, this, 1);

	m_DLCI.SetFont(GetFont());
	m_DLCI.SetCheckStyle(BS_AUTOCHECKBOX);

	if (m_FilterCircuit.GetSize() == 0)
		m_FilterCircuit.InsertAt(0, &m_Circuits);

	for (short j = 0, i = 0; i < m_Circuits.GetSize(); i++) {
		CString txt;

		txt.Format("%d", m_Circuits[i]);
		int index = m_DLCI.AddString(txt);
		m_DLCI.SetItemData(index, m_Circuits[i]);

		for (short j = 0; j < m_FilterCircuit.GetSize(); j++)
			if (m_FilterCircuit[j] == m_Circuits[i])
				m_DLCI.SetCheck(index, TRUE);
		}

	m_DLCI.InsertString(0, "None");
	m_DLCI.InsertString(0, "All");

	On1490All(m_AllRadio == 2 ? IDC_1490 : IDC_AllAll);

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

void CFRFilter::On1490All(UINT sel) 
{
	// TODO: Add your control notification handler code here
	BOOL enable = sel == IDC_1490;

	GetDlgItem(IDC_1490All)->EnableWindow(enable);
	GetDlgItem(IDC_IP)->EnableWindow(enable);
	GetDlgItem(IDC_IPX)->EnableWindow(enable);
	GetDlgItem(IDC_8023)->EnableWindow(enable);
	GetDlgItem(IDC_FRF9)->EnableWindow(enable);
	GetDlgItem(IDC_CISCOIP)->EnableWindow(enable);
	m_DLCI.EnableWindow(enable);
}

void CFRFilter::OnOK() 
{
	// TODO: Add extra validation here
	m_FilterCircuit.RemoveAll();

	for (short i = 2; i < m_DLCI.GetCount(); i++)
		if (m_DLCI.GetCheck(i))
			m_FilterCircuit.Add((DWORD)(m_DLCI.GetItemData(i)));

	if (m_FilterCircuit.GetSize() == 0)
		AfxMessageBox(IDP_SELECTCIRCUIT);
	else
		CDialog::OnOK();
}


/////////////////////////////////////////////////////////////////////////////
// CX25Filter dialog


CX25Filter::CX25Filter(CWnd* pParent /*=NULL*/)
	: CDialog(CX25Filter::IDD, pParent)
{
	//{{AFX_DATA_INIT(CX25Filter)
	m_AllRadio = -1;
	m_X25All = -1;
	//}}AFX_DATA_INIT
}


void CX25Filter::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CX25Filter)
	DDX_Radio(pDX, IDC_AllAll, m_AllRadio);
	DDX_Radio(pDX, IDC_X25All, m_X25All);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CX25Filter, CDialog)
	//{{AFX_MSG_MAP(CX25Filter)
	//}}AFX_MSG_MAP
	ON_CONTROL_RANGE(BN_CLICKED, IDC_AllAll, IDC_X25, OnAllAll)
	ON_CONTROL(LBN_SELCHANGE, 1, OnSelchangeCircuit)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CX25Filter message handlers

void CX25Filter::OnSelchangeCircuit()
{
	if (m_Channel.GetCheck(0)) {
		m_Channel.SetCheck(0, FALSE);
		for (short i = 2; i < m_Channel.GetCount(); i++)
			m_Channel.SetCheck(i, TRUE);
		}
	else if (m_Channel.GetCheck(1)) {
		m_Channel.SetCheck(1, FALSE);
		for (short i = 2; i < m_Channel.GetCount(); i++)
			m_Channel.SetCheck(i, FALSE);
		}
}

void CX25Filter::OnOK() 
{
	// TODO: Add extra validation here
	m_FilterCircuit.RemoveAll();

	for (short i = 2; i < m_Channel.GetCount(); i++)
		if (m_Channel.GetCheck(i))
			m_FilterCircuit.Add((DWORD)(m_Channel.GetItemData(i)));

	if (m_FilterCircuit.GetSize() == 0)
		AfxMessageBox(IDP_SELECTCIRCUIT);
	else
		CDialog::OnOK();
}

void CX25Filter::OnAllAll(UINT sel) 
{
	// TODO: Add your control notification handler code here
	BOOL enable = sel == IDC_X25;

	GetDlgItem(IDC_X25All)->EnableWindow(enable);
	GetDlgItem(IDC_X25Proto)->EnableWindow(enable);
	GetDlgItem(IDC_X25Data)->EnableWindow(enable);
	m_Channel.EnableWindow(enable);
}

BOOL CX25Filter::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rect;

	GetDlgItem(IDC_FilterFrame)->GetWindowRect(rect);
	ScreenToClient(rect);

	m_Channel.Create(	LBS_STANDARD | WS_VISIBLE | WS_TABSTOP | WS_CHILD | 
										LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
										rect, this, 1);

	m_Channel.SetFont(GetFont());
	m_Channel.SetCheckStyle(BS_AUTOCHECKBOX);

	if (m_FilterCircuit.GetSize() == 0)
		m_FilterCircuit.InsertAt(0, &m_Circuits);

	for (short i = 0; i < m_Circuits.GetSize(); i++) {
		CString txt;

		txt.Format("%d", m_Circuits[i]);
		int index = m_Channel.AddString(txt);

		m_Channel.SetItemData(index, m_Circuits[i]);
		for (short j = 0; j < m_FilterCircuit.GetSize(); j++)
			if (m_FilterCircuit[j] == m_Circuits[i])
				m_Channel.SetCheck(index, TRUE);
		}

	m_Channel.InsertString(0, "None");
	m_Channel.InsertString(0, "All");

	OnAllAll(m_AllRadio == 2 ? IDC_X25 : IDC_AllAll);

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