// BlockItem_VirtualProps.cpp : implementation file
//

#include "stdafx.h"
#include "xpeluc01.h"
#include "BlockItem_VirtualProps.h"
#include "BlockItem_Virtual.h"
#include "SchemeDoc.h"


// CBlockItem_VirtualProps dialog

IMPLEMENT_DYNAMIC(CBlockItem_VirtualProps, CDialog)

CBlockItem_VirtualProps::CBlockItem_VirtualProps(CWnd* pParent /*=NULL*/, CBlockItem_Virtual *pOwner)
	: CDialog(CBlockItem_VirtualProps::IDD, pParent)
	, m_nInputCount(0)
	, m_nOutputCount(0)
	, m_strName(_T(""))
{
	m_pOwner = pOwner;
}

CBlockItem_VirtualProps::~CBlockItem_VirtualProps()
{
	if ( m_hWnd )
		DestroyWindow();
}

void CBlockItem_VirtualProps::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_INPUTCOUNT, m_nInputCount);
	DDV_MinMaxUInt(pDX, m_nInputCount, 0, 64);
	DDX_Text(pDX, IDC_OUTPUTCOUNT, m_nOutputCount);
	DDV_MinMaxUInt(pDX, m_nOutputCount, 0, 64);
	DDX_Text(pDX, IDC_BLOCKNAME, m_strName);
}


BEGIN_MESSAGE_MAP(CBlockItem_VirtualProps, CDialog)
	ON_BN_CLICKED(ID_APPLY, &CBlockItem_VirtualProps::OnBnClickedApply)
END_MESSAGE_MAP()


// CBlockItem_VirtualProps message handlers

BOOL CBlockItem_VirtualProps::OnInitDialog()
{
	if ( m_pOwner )
	{
		m_nInputCount = m_pOwner->GetInputCount();
		m_nOutputCount = m_pOwner->GetOutputCount();
		m_strName = m_pOwner->GetName();
	}

	CDialog::OnInitDialog();

	CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPININPUT);
	pSpin->SetRange(0, 64);
	pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPINOUTPUT);
	pSpin->SetRange(0, 64);

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

void CBlockItem_VirtualProps::OnOK()
{
	CDialog::OnOK();
	m_pOwner->SetInputCount(m_nInputCount);
	m_pOwner->SetOutputCount(m_nOutputCount);
	m_pOwner->SetName(m_strName);
	m_pOwner->m_pDocument->UpdateAllViews(NULL);
	DestroyWindow();
}

void CBlockItem_VirtualProps::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class

	CDialog::OnCancel();
	DestroyWindow();
}

void CBlockItem_VirtualProps::OnBnClickedApply()
{
	CDataExchange dx(this, TRUE);
	DoDataExchange(&dx);
	if ( m_pOwner )
	{
		m_pOwner->SetInputCount(m_nInputCount);
		m_pOwner->SetOutputCount(m_nOutputCount);
		m_pOwner->SetName(m_strName);
		m_pOwner->m_pDocument->UpdateAllViews(NULL);
	}
}
