#include "CPxaEditorGrid.h"
#include "resource.h"

IMPLEMENT_DYNAMIC(CPxaEditorGrid, CDialog)

BEGIN_MESSAGE_MAP(CPxaEditorGrid, CDialog)
	ON_BN_CLICKED(IDOK, &CPxaEditorGrid::OnBnClickedOk)
END_MESSAGE_MAP()

CPxaEditorGrid::CPxaEditorGrid(CWnd* pParent)
	: CDialog(IDD_CPXAEDITOR_GRID, pParent)
{
}

CPxaEditorGrid::~CPxaEditorGrid()
{
}

void CPxaEditorGrid::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_GRID_W, edit_grid_w);
	DDX_Control(pDX, IDC_EDIT_GRID_H, edit_grid_h);
	DDX_Control(pDX, IDC_CHECK_INTERAREA, check_interArea);
}

BOOL CPxaEditorGrid::OnInitDialog()
{
	CDialog::OnInitDialog();
	SetDlgItemInt(IDC_EDIT_GRID_W, outGridW);
	SetDlgItemInt(IDC_EDIT_GRID_H, outGridH);
	check_interArea.SetCheck(outInterArea ? 1 : 0);
	return 0;
}

void CPxaEditorGrid::OnBnClickedOk()
{
	int grid_w = GetDlgItemInt(IDC_EDIT_GRID_W);
	if (grid_w < 1)
	{
		MessageBox(L"网格单元尺寸宽度不能小于1", L"填写属性无效");
		return;
	}

	int grid_h = GetDlgItemInt(IDC_EDIT_GRID_H);
	if (grid_h < 1)
	{
		MessageBox(L"网格单元尺寸高度不能小于1", L"填写属性无效");
		return;
	}
	outGridW = grid_w;
	outGridH = grid_h;
	outInterArea = check_interArea.GetCheck();
	CDialog::OnOK();
}
