// CameraConfigDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GigaCam.h"
#include "CameraConfigDlg.h"
#include ".\cameraconfigdlg.h"
#include "VideoWindow.h"


// CCameraConfigDlg dialog

IMPLEMENT_DYNAMIC(CCameraConfigDlg, CDialog)
CCameraConfigDlg::CCameraConfigDlg(
	PCSTR pszCaption, 
	string sXML,
	string sPortName,
	_IPort* pPort,
	BOOL bReadOnly,
	CWnd* pParent /*=NULL*/
	)
	: CDialog(CCameraConfigDlg::IDD, pParent),
	m_pszCaption(pszCaption),
	m_sXML(sXML),
	m_sPortName(sPortName),
	m_pPort(pPort),
	m_bReadOnly(bReadOnly)
{
}

CCameraConfigDlg::~CCameraConfigDlg()
{
}

void CCameraConfigDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_GENICAMEXPLORERCTRL, m_ctlExplorer);
}

const UINT wmNodeChanged = RegisterWindowMessage("GenICamExplorer.WM_NODE_CHANGED");

BEGIN_MESSAGE_MAP(CCameraConfigDlg, CDialog)
	ON_WM_SIZE()
	ON_REGISTERED_MESSAGE(wmNodeChanged, OnNodeChanged)
//	ON_WM_KEYDOWN()
END_MESSAGE_MAP()


// CCameraConfigDlg message handlers

BOOL CCameraConfigDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	CWaitCursor wc;

	SetWindowText( m_pszCaption );

	m_ctlExplorer.SetportName( m_sPortName.c_str() );
	m_ctlExplorer.Setport( m_pPort );
	m_ctlExplorer.SetreadOnly( m_bReadOnly );
	m_ctlExplorer.Setxml( m_sXML.c_str() );

	SetFocus();

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

void CCameraConfigDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);

	//CRect rcDialog;
	//CRect rcExplorer;

	//this->GetClientRect(rcDialog);
	//m_ctlExplorer.GetWindowRect(rcExplorer);

	//m_ctlExplorer.MoveWindow(
	//	10,
	//	15,
	//	rcDialog.Width(),
	//	1500
	//	);
}


LRESULT CCameraConfigDlg::OnNodeChanged(WPARAM wParam, LPARAM lParam)
{
	return GetParent()->SendMessage(WM_NODE_CHANGED, wParam, lParam);
}

//void CCameraConfigDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
//{
//	if(nChar == VK_ESCAPE || nChar == VK_RETURN)
//		return;
//
//	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
//}

BOOL CCameraConfigDlg::PreTranslateMessage(MSG* pMsg)
{
	switch(pMsg->message)
	{
	case WM_KEYDOWN:
		if((pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN) && GetFocus() == this)
			return TRUE;
	}

	return CDialog::PreTranslateMessage(pMsg);
}

void CCameraConfigDlg::OnOK()
{
	if(GetFocus() != this)
		return;

	CDialog::OnOK();
}

void CCameraConfigDlg::OnCancel()
{
	CDialog::OnCancel();
	static_cast<CVideoWindow*>(GetParent())->OnToolsDeviceparameters();
}
