// AtlGridDialogGenerator.cpp: implementation of the CAtlGridDialogGenerator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AtlGridDialogGenerator.h"
#include "XmlClassInfo.h"
#include "XmlMemberInfo.h"
#include "XmlFormInfo.h"
#include "XmlBaseFormItem.h"
#include "XmlFormItem_Static.h"
#include "XmlFormItem_TextBox.h"
#include "XmlFormItem_CheckBox.h"
#include "XmlFormItem_ComboBox.h"
#include "XmlProjectSettings.h"
#include "XmlGuiCategoryInfoList.h"
#include "XmlGuiCategoryInfo.h"
#include "XmlGuiCategoryField.h"
#include "XmlMemberValidation_StaticEnum.h"
#include "XmlMemberValidation_StaticEnumItem.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAtlGridDialogGenerator::CAtlGridDialogGenerator()
{

}

CAtlGridDialogGenerator::~CAtlGridDialogGenerator()
{

}

void CAtlGridDialogGenerator::Generate()
{
	GenerateHeader();
	GenerateImplementation();
}

void CAtlGridDialogGenerator::GenerateHeader()
{
	cmString fileName;
	cmString pathName;

	// header file generation
	//
	headCode_ = _T("");
	Head_generateHeader();
	Head_generateIfDefBegin();
	Head_generateIncludeSection();
	Head_generateForwardDeclarations();
	Head_generateDefineSection();
	Head_generateClassBegin();
	Head_generateConstructor();
	Head_generateDestructor();
	Head_generatePublicMethods();
	Head_generateDialogData();
	Head_generateOverrides();
	Head_generateMessageMap();
	Head_generateProtectedMembers();
	Head_generateUpdateWindowSize();
	Head_generateSetupRow();
	Head_generateDataMembers();
	Head_generateClassEnd();
	Head_generateIfDefEnd();

	// save implementation file
	//
	pathName = BuildGeneratedSourcePath() + _T("include\\");
	fileName = GetDlgName() + _T(".h");
	
	SaveFile(pathName + fileName, headCode_);

	hGeneratedFiles_[fileName] = pathName + fileName;
}

void CAtlGridDialogGenerator::GenerateImplementation()
{
	cmString fileName;
	cmString pathName;

	// generate implementation file
	//
	implCode_ = _T("");
	Impl_generateHeader();
	Impl_generateIncludeSection();
	Impl_generateDebugSymbols();
	Impl_generateMainTitle();
	Impl_generateConstructor();
	Impl_generateDestructor();
	Impl_generatePublicMethods();
	Impl_generateMessageMap();
	Impl_generateOnInitDialog();
	Impl_generateOnSize();
	Impl_generateProtectedMembers();
	Impl_generateUpdateWindowSize();
	Impl_generateUpdateRow();

	// save implementation file
	//
	pathName = BuildGeneratedSourcePath() + _T("src\\");
	fileName = GetDlgName() + _T(".cpp");
	SaveFile(pathName + fileName, implCode_);

	cppGeneratedFiles_[fileName] = pathName + fileName;
}

void CAtlGridDialogGenerator::Head_generateHeader()
{
	headCode_ += _T("// ") + GetDlgName() + _T(".h : header file") + xCrLf;
	headCode_ += _T("//") + xCrLf + xCrLf;
	headCode_ += GetGenerationTimeStamp();
}

void CAtlGridDialogGenerator::Head_generateIfDefBegin()
{
	headCode_ += _T("#if !defined(") + DefineOf(GetDlgName()) + _T(")") + xCrLf;
	headCode_ += _T("#define ") + DefineOf(GetDlgName()) + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Head_generateIncludeSection()
{
	headCode_ += _T("#include \"stdafx.h\"") + xCrLf;
	headCode_ += _T("#include \"resource.h\"") + xCrLf;
	headCode_ += _T("#include \"") + GetResourceFileName() + _T(".h\"") + xCrLf;
	headCode_ += _T("#include \"ProjectConfigAtl.h\"") + xCrLf;
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateForwardDeclarations()
{
	headCode_ += _T("// forward declarations") + xCrLf;
	headCode_ += _T("//") + xCrLf;
	headCode_ += _T("class ") + GetClassName() + GetCardinalityPostfix(classInfo_) + _T(";") + xCrLf;
	headCode_ += _T("class cmTable;") + xCrLf;
	headCode_ += _T("class cmTableRow;") + xCrLf;
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateClassBegin()
{
	headCode_ += _T("/////////////////////////////////////////////////////////////////////////////") + xCrLf;
	headCode_ += _T("// ") + GetDlgName() + _T(" dialog") + xCrLf + xCrLf;

	headCode_ += _T("class ") + GetDlgName() + _T(" : public CDialog")  + xCrLf;
	headCode_ += _T("{")  + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Head_generateConstructor()
{
	headCode_ += _T("public:") + xCrLf;
	headCode_ += xTab + GetDlgName() + _T("(CWnd* pParent = NULL);") + xCrLf;
}

void CAtlGridDialogGenerator::Head_generateDestructor()
{
	headCode_ += xTab + _T("virtual ~") + GetDlgName() + _T("();") + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Head_generatePublicMethods()
{
	headCode_ += xTab + _T("public:") + xCrLf;
	headCode_ += xTab + _T("virtual void SetData(I") + GetClassName() + GetCardinalityPostfix(classInfo_) + _T("* ") + GetCamelCase(classInfo_->GetName()) + _T(");") + xCrLf;
	headCode_ += xTab + _T("virtual void StoreData();") + xCrLf;
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateDialogData()
{
	// dialog data section
	//
	headCode_ += _T("// Dialog Data") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_DATA(") +  GetDlgName() + _T(")") + xCrLf;
	headCode_ += _T("enum { IDD = IDD_CFG_TEMPLATE };")  + xCrLf;
	headCode_ += xTab + xTab + _T("// NOTE: the ClassWizard will add data members here")  + xCrLf;
	headCode_ += xTab + _T("//}}AFX_DATA")  + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Head_generateOverrides()
{
	headCode_ += _T("// Overrides") + xCrLf;
	headCode_ += xTab + _T("// ClassWizard generated virtual function overrides") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_VIRTUAL(") + GetDlgName() + _T(")") + xCrLf;
	headCode_ += xTab + _T("protected:") + xCrLf;
	headCode_ += xTab + _T("//virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support") + xCrLf;
	headCode_ += xTab + _T("//}}AFX_VIRTUAL") + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Head_generateMessageMap()
{
	headCode_ += _T("// Implementation") + xCrLf;
	headCode_ += _T("//") + xCrLf;
	headCode_ += _T("protected:") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += xTab + _T("// Generated message map functions") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_MSG(") + GetDlgName() + _T(")") + xCrLf;
	headCode_ += xTab + _T("virtual BOOL OnInitDialog();") + xCrLf;
	headCode_ += xTab + _T("afx_msg void OnSize(UINT nType, int cx, int cy);") + xCrLf;
	headCode_ += xTab + _T("//}}AFX_MSG") + xCrLf;
	headCode_ += xTab + _T("DECLARE_MESSAGE_MAP()") + xCrLf;
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateProtectedMembers()
{
	headCode_ += xTab + _T("// Implementation") + xCrLf;
	headCode_ += xTab + _T("//") + xCrLf;
	headCode_ += xTab + _T("protected:") + xCrLf;
	headCode_ += xTab + xTab +_T("DECLARE_DYNCREATE(") + GetDlgName() + _T(");") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += xTab + xTab + _T("virtual void DisplayData();") + xCrLf;
	headCode_ += xTab + xTab + _T("virtual void OnOK();") + xCrLf;
	headCode_ += xTab + xTab + _T("virtual void OnCancel();") + xCrLf;
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) { 
		headCode_ += xTab + xTab + _T("virtual void OnAppend();") + xCrLf;
		headCode_ += xTab + xTab + _T("virtual void OnInsert();") + xCrLf;
		headCode_ += xTab + xTab + _T("virtual void OnDelete();") + xCrLf;
	}
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateUpdateWindowSize()
{
	headCode_ += xTab + _T("void UpdateWindowSize();") + xCrLf;
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateDataMembers()
{
	cmString p;
	cmString n;

	n = classInfo_->GetName();
	p = GetCardinalityPostfix(classInfo_);

	headCode_ += xTab + _T("// data members") + xCrLf;
	headCode_ += xTab + _T("//") + xCrLf;
	headCode_ += xTab + _T("protected:") + xCrLf;
	headCode_ += xTab + _T("I") + GetClassName() + p + _T("* ") + GetCamelCase(n) + p + _T("_;") + xCrLf;
	headCode_ += xTab + _T("cmTable* table_;")  + xCrLf;
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		headCode_ += xTab + _T("CButton cmdAppend_;") + xCrLf; 
		headCode_ += xTab + _T("CButton cmdInsert_;") + xCrLf; 
		headCode_ += xTab + _T("CButton cmdDelete_;") + xCrLf; 
	}
	headCode_ += xTab + _T("bool initialized_;") + xCrLf;
	headCode_ += xTab + _T("CFont font_;") + xCrLf;

	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateClassEnd()
{
	headCode_ += _T("};") + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Head_generateIfDefEnd()
{
	headCode_ += _T("#endif // !defined(") + DefineOf(GetDlgName()) + _T(")") + xCrLf + xCrLf;
}

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// IMPLEMENTATION FILE GENERATORS
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

void CAtlGridDialogGenerator::Impl_generateHeader()
{
	implCode_ += _T("// ") + GetDlgName() + _T(".cpp : implementation file") + xCrLf;
	implCode_ += _T("//") + xCrLf;
	implCode_ += GetGenerationTimeStamp();
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateIncludeSection()
{
	implCode_ += _T("#include \"stdafx.h\"") + xCrLf;
	implCode_ += _T("#include \"") + GetDlgName() + _T(".h\"") + xCrLf;
	implCode_ += _T("#include \"") + GetClassName() + GetCardinalityPostfix(classInfo_) + _T(".h\"") + xCrLf;
	implCode_ += _T("#include \"resource.h\"") + xCrLf;
	implCode_ += _T("#include \"cmTable.h\"") + xCrLf;
	implCode_ += _T("#include \"cmTableRow.h\"") + xCrLf;
	implCode_ += _T("#include \"cmBaseCell.h\"") + xCrLf;
	implCode_ += _T("#include \"cmGenericTextCell.h\"") + xCrLf;
	implCode_ += _T("#include \"cmNumericTextCell.h\"") + xCrLf;
	implCode_ += _T("#include \"cmHexadecimalTextCell.h\"") + xCrLf;
	implCode_ += _T("#include \"cmSmartNumericTextCell.h\"") + xCrLf;
	implCode_ += _T("#include \"cmCheckBoxCell.h\"") + xCrLf;
	implCode_ += _T("#include \"cmComboBoxCell.h\"") + xCrLf;
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateDebugSymbols()
{
	/*
	implCode_ += _T("#ifdef _DEBUG") + xCrLf;
	implCode_ += _T("#define new DEBUG_NEW") + xCrLf;
	implCode_ += _T("#undef THIS_FILE") + xCrLf;
	implCode_ += _T("static char THIS_FILE[] = __FILE__;") + xCrLf;
	implCode_ += _T("#endif") + xCrLf + xCrLf;
	*/
}

void CAtlGridDialogGenerator::Impl_generateMainTitle()
{
	implCode_ += _T("/////////////////////////////////////////////////////////////////////////////") + xCrLf;
	implCode_ += _T("// ") + GetClassName() + _T(" dialog") + xCrLf + xCrLf;

	implCode_ += _T("IMPLEMENT_DYNCREATE(") + GetDlgName() + _T(", CDialog)") + xCrLf;
	implCode_ += xCrLf;
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		implCode_ += _T("#ifdef BUTTON_WIDTH") + xCrLf;
		implCode_ += _T("#undef BUTTON_WIDTH") + xCrLf;
		implCode_ += _T("#endif BUTTON_WIDTH") + xCrLf;
		implCode_ += _T("#define BUTTON_WIDTH     75") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += _T("#ifdef BUTTON_HEIGHT") + xCrLf;
		implCode_ += _T("#undef BUTTON_HEIGHT") + xCrLf;
		implCode_ += _T("#endif BUTTON_HEIGHT") + xCrLf;
		implCode_ += _T("#define BUTTON_HEIGHT    23") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += _T("#ifdef BUTTON_DISTANCE") + xCrLf;
		implCode_ += _T("#undef BUTTON_DISTANCE") + xCrLf;
		implCode_ += _T("#endif BUTTON_DISTANCE") + xCrLf;
		implCode_ += _T("#define BUTTON_DISTANCE  5") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += _T("#define IDC_BTN_APPEND    1000") + xCrLf;
		implCode_ += _T("#define IDC_BTN_INSERT    1001") + xCrLf;
		implCode_ += _T("#define IDC_BTN_DELETE    1002") + xCrLf;
	} else {
		implCode_ += _T("#ifdef BUTTON_WIDTH") + xCrLf;
		implCode_ += _T("#undef BUTTON_WIDTH") + xCrLf;
		implCode_ += _T("#endif BUTTON_WIDTH") + xCrLf;
		implCode_ += _T("#define BUTTON_WIDTH     0") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += _T("#ifdef BUTTON_HEIGHT") + xCrLf;
		implCode_ += _T("#undef BUTTON_HEIGHT") + xCrLf;
		implCode_ += _T("#endif BUTTON_HEIGHT") + xCrLf;
		implCode_ += _T("#define BUTTON_HEIGHT    0") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += _T("#ifdef BUTTON_DISTANCE") + xCrLf;
		implCode_ += _T("#undef BUTTON_DISTANCE") + xCrLf;
		implCode_ += _T("#endif BUTTON_DISTANCE") + xCrLf;
		implCode_ += _T("#define BUTTON_DISTANCE  0") + xCrLf;		
	}
	implCode_ += xCrLf;
	implCode_ += _T("#define HEADER_BACK_COLOR ::GetSysColor(COLOR_BTNFACE)") + xCrLf;
	implCode_ += _T("#define HEADER_FORE_COLOR ::GetSysColor(COLOR_BTNTEXT)") + xCrLf;
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateConstructor()
{
	implCode_ += GetDlgName() +_T("::") + GetDlgName() + _T("(CWnd* pParent /*=NULL*/):") + xCrLf;
	implCode_ += xTab + _T("CDialog(") + GetDlgName() + _T("::IDD, pParent),") + xCrLf;
	implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + GetCardinalityPostfix(classInfo_) + _T("_(NULL),") + xCrLf;
	implCode_ += xTab + _T("initialized_(false)") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("//{{AFX_DATA_INIT(") + GetDlgName() + _T(")") + xCrLf;
	implCode_ += xTab + xTab + _T("// NOTE: the ClassWizard will add member initialization here") + xCrLf;
	implCode_ += xTab + _T("//}}AFX_DATA_INIT") + xCrLf;
	implCode_ += xTab + _T("table_ = new cmTable;") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateDestructor()
{
	implCode_ += GetDlgName() +_T("::~") + GetDlgName() + _T("()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("delete table_;") + xCrLf;
	implCode_ += _T("}") + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Impl_generatePublicMethods()
{
	// SetData
	//
	cmString p;
	cmString n;
	cmString arrayMemberName;

	p = GetCardinalityPostfix(classInfo_);
	n = classInfo_->GetName();

	implCode_ += _T("void ") + GetDlgName() + _T("::SetData(I") + GetClassName() + p + _T("* ") + GetCamelCase(n) + p + _T(")") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("if (!initialized_)") + xCrLf;
	implCode_ += xTab + xTab + _T("OnInitDialog();") + xCrLf;
	
	implCode_ += xCrLf;
	implCode_ += xTab + GetCamelCase(n) + p + _T("_ = ") + GetCamelCase(n) + p +_T(";") + xCrLf;
	implCode_ += xTab + GetCamelCase(n) + p + _T("_->AddRef();") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("// display data") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("DisplayData();") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	// StoreData
	//
	implCode_ += _T("void ") + GetDlgName() + _T("::StoreData()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("USES_CONVERSION;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("if (!GetSafeHwnd() || ") + GetCamelCase(n) + p + _T("_ == NULL)") + xCrLf;
	implCode_ += xTab + xTab + _T("return;") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab + _T("CString tmp;") + xCrLf;
	implCode_ += xTab + _T("cmNumericTextCell* numCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmHexadecimalTextCell* hexCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmSmartNumericTextCell* smartCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmCheckBoxCell* chkCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmGenericTextCell* textCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmComboBoxCell* comboCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmTableRow* row;") + xCrLf;
	implCode_ += xTab + _T("int i;") + xCrLf;
	implCode_ += xTab + _T("int arrayIndex = 0;") + xCrLf;
	implCode_ += xTab + _T("I") + GetClassName() + _T("* arrayItem;") + xCrLf;
	implCode_ += xTab + _T("long arraySize;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("for (i = table_->GetFixedRowsNumber(); i < table_->GetRowCount(); i++) {") + xCrLf;
	implCode_ += xTab + xTab + _T("row = table_->GetRow(i);") + xCrLf;
	arrayMemberName = GetCamelCase(classInfo_->GetName()) + p + _T("_");
	implCode_ += xTab + xTab + arrayMemberName + _T("->GetSize(&arraySize);") + xCrLf;
	implCode_ += xTab + xTab + _T("if (arrayIndex < arraySize) {") + xCrLf;
	implCode_ += xTab + xTab + xTab + arrayMemberName + _T("->GetItem(arrayIndex, &arrayItem);") + xCrLf;
	Impl_GenerateRowStore();
	//implCode_ += xTab + xTab + xTab + GetClassName(classInfo_->GetName()) + "& item = (*" + arrayMemberName + ")[arrayIndex];" + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("arrayItem->Release();") + xCrLf;
	implCode_ += xTab + xTab + _T("} else {") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("CComObject<") + GetClassName(n) + _T(">* newItem;") + xCrLf;
	implCode_ += xCrLf;
//	implCode_ += xTab + xTab + xTab + "newItem = new CComObject<" + GetClassName(n) + ">;" + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("CComObject<") + GetClassName(n) + _T(">::CreateInstance(&newItem);") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("newItem->AddRef();") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("newItem->QueryInterface(IID_I") + GetClassName(n) + _T(", (void**)&arrayItem);") + xCrLf;
	implCode_ += xCrLf;
	Impl_GenerateRowStore();
	implCode_ += xTab + xTab + xTab + arrayMemberName + _T("->Insert(arrayIndex, arrayItem);") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("newItem->Release();") + xCrLf;
	implCode_ += xTab + xTab + _T("}") + xCrLf;
	implCode_ += xTab + xTab + _T("arrayIndex++;") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + arrayMemberName + _T("->Release();") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

}

void CAtlGridDialogGenerator::Impl_GenerateRowStore()
{
	cmString className;
	cmString memberName;
	cmString colIndexStr;
	cmString varName;
	CXmlGuiGridInfo* gridInfo;
	CXmlMemberInfo* member;
	GridColumns* columns;
	int firstColIndex = 0;
	int colIndex = 0;
	cmString tmp;

	gridInfo = classInfo_->GetGridInfo();
	columns = gridInfo->GetColumns();

	if (gridInfo->GetColumnCountEnabled())
		firstColIndex++;

	className = _T("(*") + GetCamelCase(classInfo_->GetName()) + GetCardinalityPostfix(classInfo_) + _T("_)[i].") ;
	for (int i = 0; i < columns->size(); i++) {
		member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMemberById((*columns)[i]));
		if (member == NULL)
			continue;
		
		if (member->IsHidden()) {
			implCode_ += xTab + xTab + xTab + _T("// field \"") + member->GetName() + _T("\" is hidden") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("//") + xCrLf;		
			implCode_ += xCrLf;
			continue;
		}
		
		//varName = GetCamelCase(member->GetName()) + "Value";
		implCode_ += xTab + xTab + xTab + _T("// field \"") + member->GetName() + _T("\"") + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("//") + xCrLf;
		//implCode_ += xTab + xTab + xTab + OleTypeOf(member->GetDataType()) + " " + varName + ";" + xCrLf;
		//memberName = "get_" + member->GetName() + "(&" + varName + ")";

		tmp.Format(_T("%d"), colIndex + firstColIndex);
		colIndexStr = (const TCHAR*)tmp;
		if (member->GetValidationInfo()->GetValidationMode() == enValidationMode_StaticEnum) {	
			implCode_ += xTab + xTab + xTab + _T("comboCell = dynamic_cast<cmComboBoxCell*>(row->GetCell(") + colIndexStr + _T("));") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("comboCell->KillFocus();") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("arrayItem->put_") + member->GetName() + _T("((en") + member->GetName() + _T(")comboCell->GetSelectedItemKey());") + xCrLf;
		} else if (member->GetDataType() == enDataType_Long) {
			switch (member->GetLongMemberGuiInfo()->GetDisplayMode()) {
				case enLongMemberDisplayMode_Decimal:
					implCode_ += xTab + xTab + xTab + _T("numCell = dynamic_cast<cmNumericTextCell*>(row->GetCell(") + colIndexStr + _T("));") + xCrLf;
					implCode_ += xTab + xTab + xTab + _T("numCell->KillFocus();") + xCrLf;
					implCode_ += xTab + xTab + xTab + _T("arrayItem->put_") + member->GetName() + _T("(numCell->GetValue());") + xCrLf;
					break;

				case enLongMemberDisplayMode_Hex:
					implCode_ += xTab + xTab + xTab + _T("hexCell = dynamic_cast<cmHexadecimalTextCell*>(row->GetCell(") + colIndexStr + _T("));") + xCrLf;
					implCode_ += xTab + xTab + xTab + _T("hexCell->KillFocus();") + xCrLf;
					implCode_ += xTab + xTab + xTab + _T("arrayItem->put_") + member->GetName() + _T("(hexCell->GetValue());") + xCrLf;
					break;
			}			
		} else if (member->GetDataType() == enDataType_Double) {
			implCode_ += xTab + xTab + xTab + _T("numCell = dynamic_cast<cmNumericTextCell*>(row->GetCell(") + colIndexStr + _T("));") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("numCell->KillFocus();") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("arrayItem->put_") + member->GetName() + _T("(numCell->GetValue());") + xCrLf;
		} else if (member->GetDataType() == enDataType_String) {
			implCode_ += xTab + xTab + xTab + _T("textCell = dynamic_cast<cmGenericTextCell*>(row->GetCell(") + colIndexStr + _T("));") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("textCell->KillFocus();") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("arrayItem->put_") + member->GetName() + _T("(CComBSTR((const TCHAR*)textCell->GetText()));") + xCrLf;
		} else if (member->GetDataType() == enDataType_Boolean) {
			implCode_ += xTab + xTab + xTab + _T("chkCell = dynamic_cast<cmCheckBoxCell*>(row->GetCell(") + colIndexStr + _T("));") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("chkCell->KillFocus();") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("arrayItem->put_") + member->GetName() + _T("(chkCell->GetChecked());") + xCrLf;
		}

		colIndex++;
		implCode_ += xCrLf;
	}

}

void CAtlGridDialogGenerator::Impl_generateMessageMap()
{
	implCode_ += _T("BEGIN_MESSAGE_MAP(") + GetDlgName() + _T(", CDialog)") + xCrLf;
	implCode_ += xTab + _T("//{{AFX_MSG_MAP(getDlgName())") + xCrLf;
	//implCode_ += xTab + "ON_WM_CREATE()" + xCrLf;
	implCode_ += xTab + _T("ON_WM_SIZE()") + xCrLf;
	
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		implCode_ += xTab + _T("ON_BN_CLICKED(IDC_BTN_APPEND, OnAppend)") + xCrLf;
		implCode_ += xTab + _T("ON_BN_CLICKED(IDC_BTN_INSERT, OnInsert)") + xCrLf;
		implCode_ += xTab + _T("ON_BN_CLICKED(IDC_BTN_DELETE, OnDelete)") + xCrLf;
	}
	
	implCode_ += xTab + _T("//}}AFX_MSG_MAP") + xCrLf;
	implCode_ += _T("END_MESSAGE_MAP()") + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateOnInitDialog()
{
	implCode_ += _T("/////////////////////////////////////////////////////////////////////////////") + xCrLf;
	implCode_ += _T("// ") + GetDlgName() + _T(" message handlers") + xCrLf + xCrLf;

	implCode_ += _T("BOOL ") + GetDlgName() + _T("::OnInitDialog()") + xCrLf ;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("initialized_ = true;") + xCrLf;
	implCode_ += xTab + _T("CDialog::OnInitDialog();") + xCrLf + xCrLf;
	
	implCode_ += xTab + _T("CRect rc;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("GetClientRect(rc);") + xCrLf;

	implCode_ += xTab + _T("font_.CreateFont(-11, ") + xCrLf;
	implCode_ += xTab + _T("                 0,                      /* width */ ") + xCrLf;
	implCode_ += xTab + _T("                 0,					  /* escapement */ ") + xCrLf;
	implCode_ += xTab + _T("                 0,					  /* orientation */ ") + xCrLf;
	implCode_ += xTab + _T("                 FW_NORMAL,			  /* weight*/ ") + xCrLf;
	implCode_ += xTab + _T("                 0,					  /* italic*/ ") + xCrLf;
	implCode_ += xTab + _T("                 0,					  /* underline */ ") + xCrLf;
	implCode_ += xTab + _T("                 0,					  /* strikeout */ ") + xCrLf;
	implCode_ += xTab + _T("                 ANSI_CHARSET,			  /* charset */ ") + xCrLf;
	implCode_ += xTab + _T("                 OUT_DEFAULT_PRECIS,	  /* out precision */ ") + xCrLf;
	implCode_ += xTab + _T("                 CLIP_DEFAULT_PRECIS,	  /* clip precision */ ") + xCrLf;
	implCode_ += xTab + _T("                 DEFAULT_QUALITY,		  /* quality */ ") + xCrLf;
	implCode_ += xTab + _T("                 DEFAULT_PITCH,		  /* pitch family */ ") + xCrLf;
	implCode_ += xTab + _T("                 _T(\"tahoma\"));") + xCrLf;


	implCode_ += xTab + _T("ModifyStyle(WS_POPUP, WS_CHILD | WS_CLIPCHILDREN);") + xCrLf;
	implCode_ += xCrLf;

	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		implCode_ += xTab + _T("// create buttons") + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		implCode_ += xTab + _T("cmdAppend_.Create(_T(\"Append\"), WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 0, 0), this, IDC_BTN_APPEND);") + xCrLf;
		implCode_ += xTab + _T("cmdAppend_.SetFont(&font_);") + xCrLf;
		implCode_ += xTab + _T("cmdInsert_.Create(_T(\"Insert\"), WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 0, 0), this, IDC_BTN_INSERT);") + xCrLf;
		implCode_ += xTab + _T("cmdInsert_.SetFont(&font_);") + xCrLf;
		implCode_ += xTab + _T("cmdDelete_.Create(_T(\"Delete\"), WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 0, 0), this, IDC_BTN_DELETE);") + xCrLf;
		implCode_ += xTab + _T("cmdDelete_.SetFont(&font_);") + xCrLf;
	}

	// create table
	//
	GridColumns* columns;
	int columnsCount;
	int firstColumnIndex = 0;
	TCHAR tmp[10];

	columns = classInfo_->GetGridInfo()->GetColumns();
	columnsCount = columns->size();
	if (classInfo_->GetGridInfo()->GetColumnCountEnabled())
		firstColumnIndex = 1;
	columnsCount += firstColumnIndex;

	implCode_ += xTab + _T("// create and configure table") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("cmTableRow* newRow;") + xCrLf;
	implCode_ += xTab + _T("cmBaseCell* baseCell;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("table_->Create(rc, this, WS_CHILD | WS_VISIBLE, -1);") + xCrLf;
	implCode_ += xTab + _T("table_->SetColumnsNumber(") + _itow(columnsCount, tmp, 10) + _T(");") + xCrLf;
	if (classInfo_->GetGridInfo()->GetColumnCountEnabled())
		implCode_ += xTab + _T("table_->SetFixedColumnsNumber(1);") + xCrLf;
	implCode_ += xTab + _T("table_->SetFixedRowsNumber(1);") + xCrLf;
	implCode_ += xCrLf;	
	// set headers name
	//
	implCode_ += xTab + _T("newRow = table_->AppendRow(") + _itow(columnsCount, tmp, 10) + _T(");") + xCrLf;
	if (classInfo_->GetGridInfo()->GetColumnCountEnabled()) {
		implCode_ += xTab + _T("baseCell = newRow->CreateCell(0, enCmTableCellType_Caption);") + xCrLf;
		implCode_ += xTab + _T("baseCell->SetBackColor(HEADER_BACK_COLOR);") + xCrLf;
		implCode_ += xTab + _T("baseCell->SetForeColor(HEADER_FORE_COLOR);") + xCrLf;
		implCode_ += xCrLf;
	}

	for (int i = 0; i < columns->size(); i++) {
		cmString id;
		CXmlMemberInfo* member;

		id = (*columns)[i];
		member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMemberById(id));
		if (member == NULL || member->IsHidden())
			continue;
		
		//implCode_ += xTab + "grid_.GetCell(0, " + itoa(firstColumnIndex + i, tmp, 10) + ")->SetText(\"" + member->GetCaption() + "\");" + xCrLf;

		implCode_ += xTab + _T("baseCell = newRow->CreateCell(") + _itow(i + 1, tmp, 10) + _T(", enCmTableCellType_Caption);") + xCrLf;
		implCode_ += xTab + _T("baseCell->SetBackColor(HEADER_BACK_COLOR);") + xCrLf;
		implCode_ += xTab + _T("baseCell->SetForeColor(HEADER_FORE_COLOR);") + xCrLf;
		implCode_ += xTab + _T("baseCell->SetText(_T(\"") + member->GetCaption() + _T("\"));") + xCrLf;
		implCode_ += xCrLf;
	}

	implCode_ += xTab + _T("UpdateWindowSize();") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("// display data") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("DisplayData();") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("return TRUE;  // return TRUE unless you set the focus to a control") + xCrLf;
	implCode_ += xTab + _T("			   // EXCEPTION: OCX Property Pages should return FALSE")  + xCrLf;
	implCode_ += _T("}") + xCrLf + xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateProtectedMembers()
{
	implCode_ += _T("void ") + GetDlgName() + _T("::DisplayData()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("if (!GetSafeHwnd() || ") + GetCamelCase(classInfo_->GetName()) + GetCardinalityPostfix(classInfo_) + _T("_ == NULL)") + xCrLf;
	implCode_ += xTab + xTab + _T("return;") + xCrLf;
	implCode_ += xCrLf;

	// display data
	//
	CXmlGuiGridInfo* gridInfo;
	GridColumns* columns;
	int firstColIndex = 0;
	CString digits;
	CString decimals;
	cmString memberName;
	cmString className;
	cmString arrayName;
	cmString n;
	cmString p;
	int columnsCount;
	int firstColumnIndex = 0;
	TCHAR tmp[10];

	columns = classInfo_->GetGridInfo()->GetColumns();
	columnsCount = columns->size();
	if (classInfo_->GetGridInfo()->GetColumnCountEnabled())
		firstColumnIndex = 1;
	columnsCount += firstColumnIndex;

	gridInfo = classInfo_->GetGridInfo();
	columns = gridInfo->GetColumns();
		
	n = classInfo_->GetName();
	p = GetCardinalityPostfix(classInfo_);
	arrayName = GetCamelCase(n) + p + _T("_");

	//implCode_ += xTab + "int newRowIndex;" + xCrLf;
	implCode_ += xTab + _T("cmTableRow* row;") + xCrLf;
	implCode_ += xTab + _T("I") + GetClassName(n) + _T("* item;") + xCrLf;
	implCode_ += xTab + _T("long size;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("table_->DeleteNonFixedRows();") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + arrayName + _T("->GetSize(&size);") + xCrLf;
	implCode_ += xTab + _T("for (long i = 0; i < size; i++) {") + xCrLf;
	implCode_ += xTab + xTab + _T("row = table_->GetRow(i + table_->GetFixedRowsNumber());") + xCrLf;
	implCode_ += xTab + xTab + _T("if(row == NULL)") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("row = table_->AppendRow(") + _itow(columnsCount, tmp, 10) + _T(", false);") + xCrLf;
	implCode_ += xTab + xTab + arrayName + _T("->GetItem(i, &item);") + xCrLf;
	implCode_ += xTab + xTab + _T("SetupRow(row, i + table_->GetFixedRowsNumber(), item);") + xCrLf;
	implCode_ += xTab + xTab + _T("item->Release();") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("table_->RedrawWindow();") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

/*** OLD
	
	string arrayName;
	string n;
	string p;

	gridInfo = classInfo_->GetGridInfo();
	columns = gridInfo->GetColumns();
	
	n = classInfo_->GetName();
	p = GetCardinalityPostfix(classInfo_);
	arrayName = GetCamelCase(n) + p + _T("_");

	implCode_ += xTab + _T("int newRowIndex;") + xCrLf;
	implCode_ += xTab + _T("long size;") + xCrLf;
	implCode_ += xTab + _T("I") + GetClassName(n) + _T("* item;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("grid_.DeleteNonFixedRows();") + xCrLf;
	implCode_ += xTab + arrayName + _T("->GetSize(&size);") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("for (int i = 0; i < size; i++) {") + xCrLf;
	
	implCode_ += xTab + xTab + _T("newRowIndex = grid_.InsertRow(\"\");") + xCrLf;
	implCode_ += xTab + xTab + arrayName + _T("->GetItem(i, &item);") + xCrLf;
	implCode_ += xTab + xTab + _T("UpdateRow(newRowIndex, item);") + xCrLf;
	
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("grid_.RedrawWindow();") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
***/
	// OnOK()
	//
	implCode_ += _T("void ") + GetDlgName() + _T("::OnOK()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	// OnCancel()
	//
	implCode_ += _T("void ") + GetDlgName() + _T("::OnCancel()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	// OnAppend()
	//
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		cmString varName;

		varName = GetCamelCase(n) + p + _T("_");
		implCode_ += _T("void ") + GetDlgName() + _T("::OnAppend()") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("CComObject<") + GetClassName() + _T(">* newItem;") + xCrLf;
		implCode_ += xTab + _T("I") + GetClassName() + _T("* newItemInterface;") + xCrLf;		
		implCode_ += xTab + _T("cmTableRow* newRow;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("newRow = table_->AppendRow(") + tmp + _T(", false);") + xCrLf;
//		implCode_ += xTab + "newItem = new CComObject<" + GetClassName() + ">;" + xCrLf;
		implCode_ += xTab + _T("CComObject<") + GetClassName() + _T(">::CreateInstance(&newItem);") + xCrLf;
		implCode_ += xTab + _T("newItem->QueryInterface(IID_I") + GetClassName() + _T(", (void**)&newItemInterface);") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + varName + _T("->Append(newItemInterface);") + xCrLf;
		implCode_ += xTab + _T("SetupRow(newRow, table_->GetRowCount() - 1, newItemInterface);") + xCrLf;
		implCode_ += xTab + _T("table_->RedrawWindow();") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
	}

	// OnInsert()
	//
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		cmString varName;
		int columnsCount;
		int firstColumnIndex = 0;
		TCHAR tmp[10];

		columns = classInfo_->GetGridInfo()->GetColumns();
		columnsCount = columns->size();
		if (classInfo_->GetGridInfo()->GetColumnCountEnabled())
			firstColumnIndex = 1;
		columnsCount += firstColumnIndex;
		wsprintf(tmp, _T("%d"), columnsCount);

		implCode_ += _T("void ") + GetDlgName() + _T("::OnInsert()") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("cmTableRow* newRow;") + xCrLf;
		implCode_ += xTab + _T("cmTableRow* selRow;") + xCrLf;
		implCode_ += xTab + _T("cmBaseCell* selCell;") + xCrLf;
		implCode_ += xTab + _T("int selRowIndex;") + xCrLf;
		implCode_ += xTab + _T("int selColIndex;") + xCrLf;
		implCode_ += xTab + _T("CComObject<") + GetClassName() + _T(">* newItem;") + xCrLf;
		implCode_ += xTab + _T("I") + GetClassName() + _T("* newItemInterface;") + xCrLf;		
		implCode_ += xCrLf;
		implCode_ += xTab + _T("if (!table_->GetSelectedItem(&selRow, &selCell, selRowIndex, selColIndex))") + xCrLf;
		implCode_ += xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("newRow = table_->InsertRow(selRowIndex, ") + tmp + _T(", false);") + xCrLf;
//		implCode_ += xTab + "newItem = new CComObject<" + GetClassName() + ">;" + xCrLf;
		implCode_ += xTab + _T("CComObject<") + GetClassName() + _T(">::CreateInstance(&newItem);") + xCrLf;
		implCode_ += xTab + _T("newItem->QueryInterface(IID_I") + GetClassName() + _T(", (void**)&newItemInterface);") + xCrLf;
		implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("Array_->Insert(selRowIndex, newItem);") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("SetupRow(newRow, selRowIndex, newItem);") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("table_->RedrawWindow();") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;

	}

	// OnDelete()
	//
	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
				implCode_ += _T("void ") + GetDlgName() + _T("::OnDelete()") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("cmTableRow* selRow;") + xCrLf;
		implCode_ += xTab + _T("cmBaseCell* selCell;") + xCrLf;
		implCode_ += xTab + _T("int selRowIndex;") + xCrLf;
		implCode_ += xTab + _T("int selColIndex;") + xCrLf;
		implCode_ += xTab + _T("int ret;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("if (!table_->GetSelectedItem(&selRow, &selCell, selRowIndex, selColIndex))") + xCrLf;
		implCode_ += xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("ret = MessageBox(_T(\"Delete selected row ?\"), _T(\"Delete row\"), MB_OKCANCEL | MB_ICONQUESTION);") + xCrLf;
		implCode_ += xTab + _T("if (ret == IDOK) {") + xCrLf;
		implCode_ += xTab + xTab + _T("table_->DeleteRow(selRowIndex, true);") + xCrLf;
		implCode_ += xTab + xTab + GetCamelCase(classInfo_->GetName()) + _T("Array_->Delete(selRowIndex - 1);") + xCrLf;
		if (classInfo_->GetGridInfo()->GetColumnCountEnabled()) {
			implCode_ += xTab + xTab + _T("// renumber rows") + xCrLf;
			implCode_ += xTab + xTab + _T("//") + xCrLf;
			implCode_ += xTab + xTab + _T("cmString tmp;") + xCrLf;
			implCode_ += xTab + xTab + _T("cmTableRow* row;") + xCrLf;
			implCode_ += xTab + xTab + _T("cmBaseCell* cell;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + xTab + _T("for (int i = 1; i < table_->GetRowCount(); i++) {") + xCrLf;
			if (classInfo_->GetGridInfo()->GetZeroAlignedCount())
				implCode_ += xTab + xTab + xTab + _T("tmp.Format(_T(\"%d\"), i - 1);") + xCrLf;
			else
				implCode_ += xTab + xTab + xTab + _T("tmp.Format(_T(\"%d\"), i);") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("row = table_->GetRow(i);") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("cell = row->GetCell(0);") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("cell->SetText(tmp);") + xCrLf;
			implCode_ += xTab + xTab + _T("}") + xCrLf;
		}
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + _T("table_->RedrawWindow();") + xCrLf;
		implCode_ += xTab + _T("}") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;

		/*** OLD
		implCode_ += _T("void ") + GetDlgName() + _T("::OnDelete()") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("int selCount;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("selCount = grid_.GetSelectedCount();") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("if (selCount == 0)") + xCrLf;
		implCode_ += xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("CCellRange selRange;") + xCrLf;
		implCode_ += xTab + _T("int ret;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("ret = MessageBox(\"Delete selected range ?\", \"Delete rows\", MB_OKCANCEL | MB_ICONQUESTION);") + xCrLf;
		implCode_ += xTab + _T("if (ret == IDOK) {") + xCrLf;
		implCode_ += xTab + xTab + _T("int i;") + xCrLf;
		implCode_ += xTab + xTab + _T("int rowIndex;") + xCrLf;
		implCode_ += xTab + xTab + _T("vector<bool> rows;") + xCrLf;
		implCode_ += xTab + xTab + _T("selRange = grid_.GetSelectedCellRange();") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + _T("for (rowIndex = selRange.GetMinRow(); rowIndex <= selRange.GetMaxRow(); rowIndex++) {") + xCrLf;
		implCode_ += xTab + xTab + xTab +_T("bool isSelected;") + xCrLf;
		//implCode_ += xTab + xTab + xTab +"DWORD itemState;" + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + xTab + _T("isSelected = false;") + xCrLf;
		implCode_ += xTab + xTab + xTab +_T("for (int col = selRange.GetMinCol(); col <= selRange.GetMaxCol(); col++)") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("isSelected |= (grid_.IsCellSelected(rowIndex, col) == TRUE);") + xCrLf;
		//implCode_ += xTab + xTab + xTab + "itemState = grid_.GetItemState(rowIndex, 1);" + xCrLf;
		//implCode_ += xTab + xTab + xTab + "isSelected = ((itemState & GVIS_SELECTED) != 0);" + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("rows.push_back(isSelected);") + xCrLf;
		implCode_ += xTab + xTab + _T("}") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + _T("rowIndex = selRange.GetMinRow();") + xCrLf;
		implCode_ += xTab + xTab + _T("for (i = 0; i < rows.size(); i++) {") + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("if (rows[i])") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("grid_.DeleteRow(rowIndex);") + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("else") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("rowIndex++;") + xCrLf;
		implCode_ += xTab + xTab + _T("}") + xCrLf;
		implCode_ += xCrLf;
		if (classInfo_->GetGridInfo()->GetColumnCountEnabled()) {
			implCode_ += xTab + xTab + _T("// renumber rows") + xCrLf;
			implCode_ += xTab + xTab + _T("//") + xCrLf;
			implCode_ += xTab + xTab + _T("CString tmp;") + xCrLf;
			implCode_ += xTab + xTab + _T("for (i = 1; i < grid_.GetRowCount(); i++) {") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("tmp.Format(\"%d\", i);") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("grid_.GetCell(i, 0)->SetText(tmp);") + xCrLf;
			implCode_ += xTab + xTab + _T("}") + xCrLf;
		}
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + _T("grid_.RedrawWindow();") + xCrLf;
		implCode_ += xTab + _T("}") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
		***/
	}
	
}

void CAtlGridDialogGenerator::Head_generateDefineSection()
{
	headCode_ += _T("#ifdef IDD_CFG_TEMPLATE") + xCrLf;
	headCode_ += xTab + _T("#undef IDD_CFG_TEMPLATE") + xCrLf;
	headCode_ += _T("#endif") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += _T("#define IDD_CFG_TEMPLATE                1001") + xCrLf;
	headCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateOnSize()
{
	implCode_ += _T("void ") + GetDlgName() + _T("::OnSize(UINT nType, int cx, int cy)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("CDialog::OnSize(nType, cx, cy);") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("UpdateWindowSize();") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateUpdateWindowSize()
{
	implCode_ += _T("void ") + GetDlgName() + _T("::UpdateWindowSize()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	
	implCode_ += xTab + _T("if (!GetSafeHwnd())") + xCrLf;
	implCode_ += xTab + xTab + _T("return;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("CRect rc;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("GetClientRect(rc);") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("if (table_->GetSafeHwnd())") + xCrLf;
	implCode_ += xTab + xTab + _T("table_->SetWindowPos(&CWnd::wndTop, rc.left, rc.top, rc.Width(), rc.Height() - BUTTON_HEIGHT - 2 * BUTTON_DISTANCE, SWP_SHOWWINDOW);") + xCrLf;
	implCode_ += xCrLf;

	if (classInfo_->GetGridInfo()->GetButtonBarEnabled()) {
		implCode_ += xTab + _T("if (!cmdAppend_.GetSafeHwnd() || !cmdInsert_.GetSafeHwnd() || !cmdDelete_.GetSafeHwnd())") + xCrLf;
		implCode_ += xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("int buttonBarMinWidth;") + xCrLf;
		implCode_ += xTab + _T("int buttonWidth;") + xCrLf;
		implCode_ += xTab + _T("int buttonLeft;") + xCrLf;
		implCode_ += xTab + _T("int buttonTop;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("buttonBarMinWidth = BUTTON_WIDTH * 3 - BUTTON_DISTANCE * 2;") + xCrLf;
		implCode_ += xTab + _T("if (rc.Width() >= buttonBarMinWidth)") + xCrLf; 
		implCode_ += xTab + xTab + _T("buttonWidth = BUTTON_WIDTH;") + xCrLf;
		implCode_ += xTab + _T("else") + xCrLf;
		implCode_ += xTab + xTab + _T("buttonWidth = (rc.Width() - BUTTON_DISTANCE * 2) / 3;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("buttonTop = rc.bottom - BUTTON_HEIGHT - BUTTON_DISTANCE;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("CPaintDC dc(this);") + xCrLf;
		implCode_ += xTab + _T("CBrush b(::GetSysColor(COLOR_BTNFACE));") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("dc.FillRect(CRect(0, buttonTop - BUTTON_DISTANCE, rc.right, rc.bottom), &b);") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("buttonLeft = rc.right - buttonWidth * 3 - BUTTON_DISTANCE * 2;") + xCrLf;
		implCode_ += xTab + _T("cmdAppend_.SetWindowPos(&CWnd::wndTop, buttonLeft, buttonTop, buttonWidth, BUTTON_HEIGHT, 0);") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("buttonLeft = rc.right - buttonWidth * 2 - BUTTON_DISTANCE;") + xCrLf;
		implCode_ += xTab + _T("cmdInsert_.SetWindowPos(&CWnd::wndTop, buttonLeft, buttonTop, buttonWidth, BUTTON_HEIGHT, 0);") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("buttonLeft = rc.right - buttonWidth;") + xCrLf;
		implCode_ += xTab + _T("cmdDelete_.SetWindowPos(&CWnd::wndTop, buttonLeft, buttonTop, buttonWidth, BUTTON_HEIGHT, 0);") + xCrLf;
	}
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Head_generateSetupRow()
{
	headCode_ += xTab + _T("void SetupRow(cmTableRow* row, int rowIndex, I") + GetClassName() + _T("* item);") + xCrLf;
	implCode_ += xCrLf;
}

void CAtlGridDialogGenerator::Impl_generateUpdateRow()
{
	CXmlMemberInfo* member;
	int firstColIndex = 0;
	CXmlGuiGridInfo* gridInfo;
	GridColumns* columns;
	CString digits;
	CString decimals;
	CString dummy;
	CString tmp;
	cmString memberName;
	cmString className;
	cmString varName;
	cmString colIndexStr;
	
	int colIndex = 0;

	gridInfo = classInfo_->GetGridInfo();
	columns = gridInfo->GetColumns();

	implCode_ += _T("void ") + GetDlgName() + _T("::SetupRow(cmTableRow* row, int rowIndex, I") + GetClassName() + _T("* item)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("USES_CONVERSION;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("cmNumericTextCell* numCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmHexadecimalTextCell* hexCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmSmartNumericTextCell* smartCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmCheckBoxCell* chkCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmGenericTextCell* textCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmComboBoxCell* comboCell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmBaseCell* cell = NULL;") + xCrLf;
	implCode_ += xTab + _T("cmString tmp;") + xCrLf;
	implCode_ += xCrLf;

	// generate header creation
	//
	if (gridInfo->GetColumnCountEnabled()) {
		implCode_ += xTab + _T("// row number \"") + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		if (gridInfo->GetZeroAlignedCount())
			implCode_ += xTab + _T("tmp.Format(_T(\"%d\"), rowIndex - 1);") + xCrLf;
		else
			implCode_ += xTab + _T("tmp.Format(_T(\"%d\"), rowIndex);") + xCrLf;
		implCode_ += xTab + _T("cell = row->GetCell(0);") + xCrLf;
		implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
		implCode_ += xTab + xTab + _T("cell = row->CreateCell(0, enCmTableCellType_Caption);") + xCrLf;
		implCode_ += xTab + _T("cell->SetBackColor(HEADER_BACK_COLOR);") + xCrLf;
		implCode_ += xTab + _T("cell->SetForeColor(HEADER_FORE_COLOR);") + xCrLf;
		implCode_ += xTab + _T("cell->SetText(tmp, false);") + xCrLf;
		implCode_ += xCrLf;
		firstColIndex = 1;
	}

	className = _T("item->"); //"(*" + GetCamelCase(classInfo_->GetName()) + GetCardinalityPostfix(classInfo_) + "_)[i]." ;
	for (int i = 0; i < columns->size(); i++) {
		member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMemberById((*columns)[i]));
		if (member == NULL)
			continue;

		if (member->IsHidden()) {
			implCode_ += xTab + _T("// field \"") + member->GetName() + _T("\" is hidden") + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			continue;
		}

		tmp.Format(_T("%d"), colIndex + firstColIndex);
		colIndexStr = (const TCHAR*)tmp;

		varName = GetCamelCase(member->GetName()) + _T("Value");
		memberName = _T("get_") + member->GetName() + _T("(&") + varName + _T(")");

		implCode_ += xTab + _T("// field \"") + member->GetName() + _T("\"") + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		

		if (member->GetValidationInfo()->GetValidationMode() == enValidationMode_StaticEnum) {
			CXmlMemberValidation_StaticEnum* staticEnum;
			CXmlMemberValidation_StaticEnumItem* item;
			StaticEnumItems* items;
			
			implCode_ += xTab + _T("en") + member->GetName() + _T(" ") + varName + _T(";") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + className + memberName + _T(";") + xCrLf;

			staticEnum = member->GetValidationInfo()->GetStaticEnum();
			items = staticEnum->GetItems();
			
			implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
			implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
			implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_ComboBox);") + xCrLf;
			implCode_ += xTab + _T("comboCell = dynamic_cast<cmComboBoxCell*>(cell);") + xCrLf;
			implCode_ += xTab + _T("comboCell->DeleteAllItems();") + xCrLf;
			for (int i = 0; i < items->size(); i++) {
				item = (*items)[i];
				implCode_ += xTab + _T("comboCell->AddItem(_T(\"") + item->GetItemDescription() + _T("\"), en") + member->GetName() + _T("_") + item->GetItemName() + _T(");") + xCrLf;
			}
			implCode_ += xTab + _T("comboCell->SelectItem(") + className + memberName + _T(");") + xCrLf;
			
		} else if (member->GetDataType() == enDataType_Long) {
			implCode_ += xTab + OleTypeOf(member->GetDataType()) + _T(" ") + varName + _T(";") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + className + memberName + _T(";") + xCrLf;

			switch (member->GetLongMemberGuiInfo()->GetDisplayMode()) {
				case enLongMemberDisplayMode_Decimal:
					implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
					implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
					implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_NumTextBox);") + xCrLf;
					implCode_ += xTab + _T("numCell = dynamic_cast<cmNumericTextCell*>(cell);") + xCrLf;
					implCode_ += xTab + _T("numCell->SetPrecision(0);") + xCrLf;
					implCode_ += xTab + _T("numCell->SetValue(") + varName + _T(", false);") + xCrLf;
					if (member->IsReadOnly())
						implCode_ += xTab + _T("numCell->SetReadOnly(true);") + xCrLf;
					break;

				case enLongMemberDisplayMode_Hex:
					dummy.Format(_T("%d"), member->GetLongMemberGuiInfo()->GetHexBitCount());
					implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
					implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
					implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_HexTextBox);") + xCrLf;
					implCode_ += xTab + _T("hexCell = dynamic_cast<cmHexadecimalTextCell*>(cell);") + xCrLf;
					implCode_ += xTab + _T("hexCell->SetBitCount(") + dummy + _T(");") + xCrLf;
					implCode_ += xTab + _T("hexCell->SetValue(") + varName + _T(", false);") + xCrLf;
					if (member->IsReadOnly())
						implCode_ += xTab + _T("hexCell->SetReadOnly(true);") + xCrLf;
					break;

				case enLongMemberDisplayMode_Smart:
					implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
					implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
					implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_SmartNumTextBox);") + xCrLf;
					implCode_ += xTab + _T("smartCell = dynamic_cast<cmSmartNumericTextCell*>(cell);") + xCrLf;
					implCode_ += xTab + _T("smartCell->SetValue(") + varName + _T(", false);") + xCrLf;
					if (member->IsReadOnly())
						implCode_ += xTab + _T("smartCell->SetReadOnly(true);") + xCrLf;
					break;

			}
		} else if (member->GetDataType() == enDataType_Double) {
			implCode_ += xTab + OleTypeOf(member->GetDataType()) + _T(" ") + varName + _T(";") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + className + memberName + _T(";") + xCrLf;

			decimals.Format(_T("%d"), member->GetDecimalPlaces());
			implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
			implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
			implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_NumTextBox);") + xCrLf;
			implCode_ += xTab + _T("numCell = dynamic_cast<cmNumericTextCell*>(cell);") + xCrLf;
			implCode_ += xTab + _T("numCell->SetPrecision(") + decimals + _T(");") + xCrLf;
			implCode_ += xTab + _T("numCell->SetValue(") + varName + _T(", false);") + xCrLf;
			if (member->IsReadOnly())
				implCode_ += xTab + _T("numCell->SetReadOnly(true);") + xCrLf;

		} else if (member->GetDataType() == enDataType_String) {
			implCode_ += xTab + _T("CComBSTR ") + varName + _T(";") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + className + memberName + _T(";") + xCrLf;

			implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
			implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
			implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_TextBox);") + xCrLf;
			implCode_ += xTab + _T("textCell = dynamic_cast<cmGenericTextCell*>(cell);") + xCrLf;
			implCode_ += xTab + _T("textCell->SetText(W2T(") + varName + _T("), false);") + xCrLf;
			//implCode_ += xTab + "SysFreeString(" + varName + ");" + xCrLf;
			if (member->IsReadOnly())
				implCode_ += xTab + _T("textCell->SetReadOnly(true);") + xCrLf;

		} else if (member->GetDataType() == enDataType_Boolean) {
			implCode_ += xTab + OleTypeOf(member->GetDataType()) + _T(" ") + varName + _T(";") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + className + memberName + _T(";") + xCrLf;

			implCode_ += xTab + _T("cell = row->GetCell(") + colIndexStr + _T(");") + xCrLf;
			implCode_ += xTab + _T("if (cell == NULL)") + xCrLf;
			implCode_ += xTab + xTab + _T("cell = row->CreateCell(") + colIndexStr + _T(", enCmTableCellType_CheckBox);") + xCrLf;
			implCode_ += xTab + _T("chkCell = dynamic_cast<cmCheckBoxCell*>(cell);") + xCrLf;
			implCode_ += xTab + _T("chkCell->SetChecked(") + varName + _T(" == VARIANT_TRUE, false);") + xCrLf;
			if (member->IsReadOnly())
				implCode_ += xTab + _T("chkCell->SetReadOnly(true);") + xCrLf;
		}
		
		colIndex++;
		implCode_ += xCrLf;
	}
/*** OLD
	for (int i = 0; i < columns->size(); i++) {
		member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMemberById((*columns)[i]));
		implCode_ += xTab + _T("// field \"") + member->GetName() + _T("\"") + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		if (member) {
			itoa(i + firstColIndex, colIndexStr, 10);
			switch (member->GetDataType()) {
				case enDataType_Long:
					varName = GetCamelCase(member->GetName()) + _T("Value");
					implCode_ += xTab + _T("long ") + varName + _T(";") + xCrLf;
					implCode_ += xCrLf;
					implCode_ += xTab + _T("grid_.SetCellType(rowIndex , ") + colIndexStr + _T(", RUNTIME_CLASS(CGridCellNumeric));") + xCrLf;
					implCode_ += xTab + _T("numCell = dynamic_cast<CGridCellNumeric*>(grid_.GetCell(rowIndex , ") + colIndexStr + _T("));") + xCrLf;
					implCode_ += xTab + _T("numCell->SetFormat(1,0);") + xCrLf;
					implCode_ += xTab + _T("numCell->SetSeparators('.',',');") + xCrLf;
					implCode_ += xTab + _T("item->get_") + member->GetName() + _T("(&") + varName + _T(");") + xCrLf;
					implCode_ += xTab + _T("tmp.Format(\"%ld\", ") + varName + _T(");") + xCrLf;		
					implCode_ += xTab + _T("grid_.GetCell(rowIndex, ") + colIndexStr + _T(")->SetText(tmp);") + xCrLf;
					break;

				case enDataType_Double:
					varName = GetCamelCase(member->GetName()) + _T("Value");

					digits.Format(_T("%d"), member->GetDigitPlaces());
					decimals.Format(_T("%d"), member->GetDecimalPlaces());
					implCode_ += xTab + _T("double ") + varName + _T(";") + xCrLf;
					implCode_ += xCrLf;
					implCode_ += xTab + _T("grid_.SetCellType(rowIndex , ") + colIndexStr + _T(", RUNTIME_CLASS(CGridCellNumeric));") + xCrLf;
					implCode_ += xTab + _T("numCell = dynamic_cast<CGridCellNumeric*>(grid_.GetCell(rowIndex , ") + colIndexStr + _T("));") + xCrLf;
					implCode_ += xTab + _T("numCell->SetFormat(") + string(digits) + _T(", ")+ string(decimals) + _T(");") + xCrLf;
					implCode_ += xTab + _T("numCell->SetSeparators('.',',');") + xCrLf;
					sprintf(fmt, _T("%%%d.%df"), member->GetDigitPlaces(), member->GetDecimalPlaces());
					implCode_ += xTab + _T("item->get_") + member->GetName() + _T("(&") + varName + _T(");") + xCrLf;
					implCode_ += xTab + _T("tmp.Format(\"") + string(fmt) + _T("\", ") + varName + _T(");") + xCrLf;		
					implCode_ += xTab + _T("grid_.GetCell(rowIndex , ") + colIndexStr + _T(")->SetText(tmp);") + xCrLf;
					break;

				case enDataType_String:
					varName = GetCamelCase(member->GetName()) + _T("Value");
					implCode_ += xTab + _T("BSTR ") + varName + _T(";") + xCrLf;
					implCode_ += xCrLf;
					implCode_ += xTab + _T("item->get_") + member->GetName() + _T("(&") + varName + _T(");") + xCrLf; 
					implCode_ += xTab + _T("tmp = W2A(") + varName + _T(");") + xCrLf;		
					implCode_ += xTab + _T("grid_.GetCell(rowIndex , ") + colIndexStr + _T(")->SetText(tmp);") + xCrLf;
					implCode_ += xTab + _T("SysFreeString(") + varName + _T(");") + xCrLf;
					break;

				case enDataType_Boolean:
					varName = GetCamelCase(member->GetName()) + _T("Value");
					implCode_ += xTab + _T("VARIANT_BOOL ") + varName + _T(";") + xCrLf;
					implCode_ += xCrLf;
					implCode_ += xTab + _T("item->get_") + member->GetName() + _T("(&") + varName + _T(");") + xCrLf;
					implCode_ += xTab + _T("grid_.SetCellType(rowIndex  , ") + colIndexStr + _T(", RUNTIME_CLASS(CGridCellCheck));") + xCrLf;
					implCode_ += xTab + _T("chkCell = dynamic_cast<CGridCellCheck*>(grid_.GetCell(rowIndex , ") + colIndexStr + _T("));") + xCrLf;
					implCode_ += xTab + _T("chkCell->SetCheck(")+ varName + _T(" == VARIANT_TRUE ? TRUE : FALSE);") + xCrLf;
					break;

			}
			
			implCode_ += xCrLf;
		}
	}
***/
	
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}
