// CfgItemName.cpp : implementation file
//

#include "stdafx.h"
#include "AsCfgBuilder.h"
#include "CfgItemName.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCfgItemName

CCfgItemName::CCfgItemName()
{
}

CCfgItemName::~CCfgItemName()
{
}


BEGIN_MESSAGE_MAP(CCfgItemName, CEdit)
	//{{AFX_MSG_MAP(CCfgItemName)
	ON_WM_CHAR()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCfgItemName message handlers

void CCfgItemName::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	int i = 0;
	bool charOk = false;
	CString tmp;
	int startChar;
	int endChar;

	TCHAR c = static_cast<TCHAR>(nChar);

	// Check for a non-printable character (such as Ctrl+C)
	if (!_istprint(c))
		charOk = true;

	GetSel(startChar, endChar);
	GetWindowText(tmp);
	if (nChar >= 'a' && nChar <= 'z')
		charOk = true;
	else if (nChar >= 'A' && nChar <= 'Z')
		charOk = true;
	else if (endChar > 0 && (nChar >= '0' && nChar <= '9'))
		charOk = true;
	else if (endChar > 0 && nChar == '_')
		charOk = true;
	else if (nChar == 27 /*escape*/ || 
			 nChar == 8  /*backspace*/)
		charOk = true;

	if (charOk)	
		CEdit::OnChar(nChar, nRepCnt, nFlags);
}

void CCfgItemName::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
