// EditVWVPg.cpp : インプリメンテーション ファイル
//

#include "stdafx.h"
#include "dm2gded.h"
#include "EditVWVPg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEditVWVPg ダイアログ



void CEditVWVPg::Construction()
{
	//{{AFX_DATA_INIT(CEditVWVPg)
	m_iSel = -1;
	m_strVal = _T("");
	//}}AFX_DATA_INIT
}


void CEditVWVPg::DoDataExchange(CDataExchange* pDX)
{
	CEditVPg::DoDataExchange(pDX);

	if (pDX->m_bSaveAndValidate) {

	} else {
		m_strVal = CWVCF::GetOp(m_wvct).Format(m_nVal);
	}

	//{{AFX_DATA_MAP(CEditVWVPg)
	DDX_Radio(pDX, IDC_RADIO_D10S, m_iSel);
	DDX_Text(pDX, IDC_EDIT_VAL, m_strVal);
	//}}AFX_DATA_MAP

	if (pDX->m_bSaveAndValidate) {
		pDX->PrepareEditCtrl(IDC_EDIT_VAL);
		WORD x;
		if (!CWVCF::GetOp(m_wvct).Parse(m_strVal, x)) {
			AfxMessageBox(IDS_ERR_ILLEGAL_INT);
			pDX->Fail();
		}
		m_nVal = (__int16)x;
	}
}


BEGIN_MESSAGE_MAP(CEditVWVPg, CEditVPg)
	//{{AFX_MSG_MAP(CEditVWVPg)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_RADIO_D10S, OnRadioD10)
	ON_BN_CLICKED(IDC_RADIO_D10U, OnRadioD10)
	ON_BN_CLICKED(IDC_RADIO_D16, OnRadioD10)
	ON_BN_CLICKED(IDC_RADIO_D2, OnRadioD10)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEditVWVPg メッセージ ハンドラ

int CEditVWVPg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	m_nVal = m_nInitVal;

	switch (m_wvct = m_wvcf.GetWvct()) {
	case wvctSigned: m_iSel = 0; break;
	case wvctUnsigned: default: m_iSel = 1; break;
	case wvctHex: m_iSel = 2; break;
	case wvctFlags: m_iSel = 3; break;
	}

	if (CEditVPg::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	return 0;
}

void CEditVWVPg::OnRadioD10() 
{
	if (!UpdateData()) return;

	switch (m_iSel) {
	case 0: m_wvct = wvctSigned; break;
	case 1: m_wvct = wvctUnsigned; break;
	case 2: m_wvct = wvctHex; break;
	case 3: m_wvct = wvctFlags; break;
	}

	UpdateData(FALSE);
}
