// CCppMainDialogGenerator.cpp
//

#include "stdafx.h"
#include "CppMainDialogGenerator.h"
#include "XmlProjectSettings.h"
#include "XmlClassInfo.h"
#include "XmlMemberInfo.h"
#include "XmlProject.h"
#include "XmlProjectIcons.h"
#include "enums.h"

CCppMainDialogGenerator::CCppMainDialogGenerator()
{}

CCppMainDialogGenerator::~CCppMainDialogGenerator()
{}


void CCppMainDialogGenerator::GenerateHeader()
{
	cmString fileName;
	cmString pathName;
	vector<CXmlClassInfo*> parentStack;

	// header file generation
	//
	headCode_ = _T("");
	Head_generateHeader();
	Head_generateIfDefBegin();
	Head_generateIncludeSection();
	Head_generateForwardDeclarations();
	Head_generateClassBegin();
	Head_generateConstructor();
	Head_generateDestructor();
	Head_generateInterfaceImplementation();
	Head_generateDialogData();
	Head_generateGetSetData();
	parentStack.clear();
	Head_generateInsertChildNode(classInfo_, parentStack);
	Head_generateDeleteArrayItemNode();
	Head_generateSelectArrayItemNode();
	Head_generateDeleteMapItemNode();
	Head_generateSelectMapItemNode();
	Head_generateReplaceMapKey(classInfo_, parentStack);
	Head_generateOverrides();
	Head_generateMessageMap();
	Head_generateDataMembers();
	Head_generateBuildNode(classInfo_,_T(""));
	parentStack.clear();
	Head_generateGetItem(classInfo_, parentStack);
	Head_generateInitializeTree();
	Head_generateStoreNodeData();
	Head_generateGetNodeInfo();
	Head_generateOnOK();
	//Head_generateUpdateWindowSize();
	Head_generateDisplayPopupMenu();
	Head_generateDeleteNode();
	Head_generateUpdateNodeImages();
	//Head_generateGetChildDialog();
	Head_generateClassEnd();
	Head_generateIfDefEnd();

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

	hGeneratedFiles_[fileName] = pathName + fileName;
}

void CCppMainDialogGenerator::GenerateImplementation()
{
	int count = 0;
	cmString fileName;
	cmString pathName;
	vector<CXmlClassInfo*> parentStack;

	// generate implementation file
	//
	implCode_ = _T("");
	Impl_generateHeader();
	Impl_generateIncludeSection();
	Impl_generateDebugSymbols();
	Impl_generateMainTitle();
	Impl_generateConstructor();
	Impl_generateDestructor();
	Impl_generateMessageMap();
	Impl_generateOnInitDialog();
	Impl_generateInitializeTree();
	Impl_generateStoreNodeData();
	Impl_generateOnOK();
	Impl_generateOnNodeSelection();
	//Impl_generateGetChildDialog();
	Impl_generateGetSetData();
	Impl_generateBuildNode(classInfo_, count, _T(""));
	Impl_generateGetItem(classInfo_, parentStack);
	Impl_generateGetNodeInfo();
	Impl_generateOnSize();
	//Impl_generateUpdateWindowSize();
	Impl_generateDisplayPopupMenu();
	Impl_generateOnMnuAppendItem_Array();
	Impl_generateOnMnuAppendItem_OnMnuInsertItem_ArrayItem(); 
	Impl_generateOnMnuAppendItem_OnMnuAppendItem_ArrayItem(); 
	Impl_generateOnMnuAppendItem_OnMnuRemoveItem_ArrayItem(); 
	Impl_generateOnMnuAppendItem_OnMnuCreateItem_Map();       
	Impl_generateOnMnuAppendItem_OnMnuRemoveItem_MapItem();   
	Impl_generateOnMnuAppendItem_OnMnuCreateItem_MapItem();   
	Impl_generateDeleteNode();
	Impl_generateUpdateNodeImages();
	Impl_generateInterfaceImplementation();
	count = 0;
	parentStack.clear();
	Impl_generateInsertChildNode(classInfo_, count, parentStack);
	Impl_generateDeleteArrayItemNode();
	Impl_generateSelectArrayItemNode();
	Impl_generateDeleteMapItemNode();
	Impl_generateSelectMapItemNode();
	parentStack.clear();
	Impl_generateReplaceMapKey(classInfo_, parentStack);
	// save implementation file
	//
	pathName = BuildGeneratedSourcePath() + _T("src\\");
	fileName = GetMainDlgName() + _T(".cpp");
	SaveFile(pathName + fileName, implCode_);

	cppGeneratedFiles_[fileName] = pathName + fileName;
}

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

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// HEADER FILE GENERATORS
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

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

void CCppMainDialogGenerator::Head_generateIfDefBegin()
{
	headCode_ += _T("#if !defined(") + DefineOf(GetMainDlgName()) + _T(")") + xCrLf;
	headCode_ += _T("#define ") + DefineOf(GetMainDlgName()) + xCrLf;
	headCode_ += xCrLf;

	headCode_ += _T("#ifdef IDD_CFG_MGR_TEMPLATE") + xCrLf;
	headCode_ += xTab + _T("#undef IDD_CFG_MGR_TEMPLATE") + xCrLf;
	headCode_ += _T("#endif") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += _T("#define IDD_CFG_MGR_TEMPLATE                1000") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateIncludeSection()
{
	headCode_ += _T("#include \"stdafx.h\"") + xCrLf;
	headCode_ += _T("#include \"resource.h\"") + xCrLf;
	headCode_ += _T("#include <map>") + xCrLf;
	headCode_ += _T("#include <vector>") + xCrLf;
	headCode_ += _T("#include \"") + GetClassName() + _T(".h\"") + xCrLf;
	headCode_ += _T("#include \"") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo.h\"") + xCrLf;
	headCode_ += _T("#include \"cmSplitDialog.h\"") + xCrLf;
	headCode_ += xCrLf;
	Head_generateDlgInclude(classInfo_);
	headCode_ += xCrLf;	
	
	headCode_ += _T("using namespace std;") + xCrLf;
	headCode_ += xCrLf;	

}

void CCppMainDialogGenerator::Head_generateDlgInclude(CXmlClassInfo* classInfo)
{
	if (classInfo->GetDefinitionInheritance())
		return;

	enRenderingMode r;
	enCardinality c;

	r = classInfo->GetRenderingMode();
	c = classInfo->GetCardinalityInfo()->GetCardinality();

	/*
	if (r == enRenderingMode_Grid) {
		headCode_ += "#include \"" + GetDlgName(classInfo) + ".h\"" + xCrLf;
	} else if (r != enRenderingMode_None) {
		headCode_ += "#include \"" + GetDlgName(classInfo) + ".h\"" + xCrLf;
	
		if(c == enCardinality_Array)
			headCode_ += "#include \"" + GetArrayDialogName(classInfo) + ".h\"" + xCrLf;
		else if (c == enCardinality_Map)
			headCode_ += "#include \"" + GetMapDialogName(classInfo) + ".h\"" + xCrLf;
	}
	*/
	if (r == enRenderingMode_Grid) {
		headCode_ += _T("class ") + GetDlgName(classInfo) + _T(";") + xCrLf;
	} else if (r != enRenderingMode_None) {
		headCode_ += _T("class ") + GetDlgName(classInfo) + _T(";") + xCrLf;
	
		if(c == enCardinality_Array)
			headCode_ += _T("class ") + GetArrayDialogName(classInfo) + _T(";") + xCrLf;
		else if (c == enCardinality_Map)
			headCode_ += _T("class ") + GetMapDialogName(classInfo) + _T(";") + xCrLf;
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Head_generateDlgInclude(dynamic_cast<CXmlClassInfo*>(member));
	}
	
}

void CCppMainDialogGenerator::Impl_generateClassInclude(CXmlClassInfo* classInfo)
{
	if (classInfo->GetDefinitionInheritance())
		return;

	implCode_ += _T("#include \"") + GetClassName(classInfo->GetName()) + _T(".h\"") + xCrLf;

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateClassInclude(dynamic_cast<CXmlClassInfo*>(member));
	}
}

void CCppMainDialogGenerator::Head_generateDlgDeclare(CXmlClassInfo* classInfo)
{
	if(classInfo->GetDefinitionInheritance())
		return;

	enCardinality c;

	c = classInfo->GetCardinalityInfo()->GetCardinality();

	if(classInfo->GetRenderingMode() != enRenderingMode_None) {
		headCode_ += xTab + GetDlgName(classInfo) + _T("* ") + GetCamelCase(GetDlgName(classInfo)) + _T("_;") + xCrLf;
	
		if (c == enCardinality_Array)
			headCode_ += xTab + GetArrayDialogName(classInfo) + _T("* ") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_;") + xCrLf;
		else if (c == enCardinality_Map) 
			headCode_ += xTab + GetMapDialogName(classInfo) + _T("* ") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_;") + xCrLf;
	}
	
	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Head_generateDlgDeclare(dynamic_cast<CXmlClassInfo*>(member));
	}
	
}

void CCppMainDialogGenerator::Head_generateViewIndexDeclare(CXmlClassInfo* classInfo)
{
	if(classInfo->GetDefinitionInheritance())
		return;

	enCardinality c;

	c = classInfo->GetCardinalityInfo()->GetCardinality();
	if(classInfo->GetRenderingMode() != enRenderingMode_None) {
		headCode_ += xTab + _T("int viewIndex_") + GetCamelCase(GetDlgName(classInfo)) + _T("_;") + xCrLf;
	
		if (c == enCardinality_Array)
			headCode_ += xTab + _T("int viewIndex_") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_;") + xCrLf;
		else if (c == enCardinality_Map)
			headCode_ += xTab + _T("int viewIndex_") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_;") + xCrLf;
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Head_generateViewIndexDeclare(dynamic_cast<CXmlClassInfo*>(member));
	}
	
}

void CCppMainDialogGenerator::Head_generateDeclareChildDlg(CXmlClassInfo* classInfo)
{
	if(classInfo->GetDefinitionInheritance())
		return;

	if(classInfo->GetRenderingMode() != enRenderingMode_None) {
		headCode_ += xTab + GetDlgName(classInfo) + _T("* ") + GetCamelCase(GetDlgName(classInfo)) + _T("_;") + xCrLf;
	
		enCardinality c;

		c = classInfo->GetCardinalityInfo()->GetCardinality();
		if (c == enCardinality_Array && classInfo->GetRenderingMode() != enRenderingMode_Grid )
			headCode_ += xTab + GetArrayDialogName(classInfo) + _T("* ") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_;") + xCrLf;
		else if (c == enCardinality_Map)
			headCode_ += xTab + GetMapDialogName(classInfo) + _T("* ") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_;") + xCrLf;
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Head_generateDeclareChildDlg(dynamic_cast<CXmlClassInfo*>(member));
	}
}

void CCppMainDialogGenerator::Impl_generateDlgCreate(CXmlClassInfo* classInfo)
{
	if (classInfo->GetDefinitionInheritance())
		return;

	enCardinality c;

	c = classInfo->GetCardinalityInfo()->GetCardinality();
	if (classInfo->GetRenderingMode() != enRenderingMode_None) {
		implCode_ += xTab + GetCamelCase(GetDlgName(classInfo)) + _T("_ = new ") + GetDlgName(classInfo) + _T(";") + xCrLf;
		implCode_ += xTab + GetCamelCase(GetDlgName(classInfo)) + _T("_->Create(IDD_CFG_TEMPLATE, this);") + xCrLf;
		implCode_ += xTab + GetCamelCase(GetDlgName(classInfo)) + _T("_->ShowWindow(SW_HIDE);") + xCrLf;
		implCode_ += xCrLf;

		if (c == enCardinality_Array && classInfo->GetRenderingMode() != enRenderingMode_Grid) {
			implCode_ += xTab + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_ = new ") + GetArrayDialogName(classInfo) + _T(";") + xCrLf;
			implCode_ += xTab + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_->Create(IDD_CONTAINER_TEMPLATE, this);") + xCrLf;
			implCode_ += xTab + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_->ShowWindow(SW_HIDE);") + xCrLf;
			implCode_ += xCrLf;
		} else if (c == enCardinality_Map) {
			implCode_ += xTab + GetCamelCase(GetMapDialogName(classInfo)) + _T("_ = new ") + GetMapDialogName(classInfo) + _T(";") + xCrLf;
			implCode_ += xTab + GetCamelCase(GetMapDialogName(classInfo)) + _T("_->Create(IDD_CONTAINER_TEMPLATE, this);") + xCrLf;
			implCode_ += xTab + GetCamelCase(GetMapDialogName(classInfo)) + _T("_->ShowWindow(SW_HIDE);") + xCrLf;
			implCode_ += xCrLf;
		}
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateDlgCreate(dynamic_cast<CXmlClassInfo*>(member));
	}
	
}

void CCppMainDialogGenerator::Impl_generateDlgAddView(CXmlClassInfo* classInfo)
{
	if (classInfo->GetDefinitionInheritance())
		return;

	enCardinality c;

	c = classInfo->GetCardinalityInfo()->GetCardinality();

	if (classInfo->GetRenderingMode() != enRenderingMode_None) {
		implCode_ += xTab + _T("viewIndex_") + GetCamelCase(GetDlgName(classInfo)) + _T("_ = AppendChild(") + GetCamelCase(GetDlgName(classInfo)) + _T("_);") + xCrLf;
	
		if (c == enCardinality_Array && classInfo->GetRenderingMode() != enRenderingMode_Grid)
			implCode_ += xTab + _T("viewIndex_") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_ = AppendChild(") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_);") + xCrLf;
		else if (c == enCardinality_Map)
			implCode_ += xTab + _T("viewIndex_") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_ = AppendChild(") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_);") + xCrLf;
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateDlgAddView(dynamic_cast<CXmlClassInfo*>(member));
	}
}


void CCppMainDialogGenerator::Impl_generateDeleteView(CXmlClassInfo* classInfo)
{
/*
	if (classInfo->GetDefinitionInheritance())
		return;

	if (classInfo->GetRenderingMode() != enRenderingMode_None)
		implCode_ += xTab + "delete splitterWnd_.GetView(viewIndex_" + GetCamelCase(GetDlgName(classInfo)) + "_);" + xCrLf;
		
	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateDeleteVIew(dynamic_cast<CXmlClassInfo*>(member));
	}
*/
}

void CCppMainDialogGenerator::Head_generateClassBegin()
{
	headCode_ += _T("/////////////////////////////////////////////////////////////////////////////") + xCrLf;
	headCode_ += _T("// ") + GetMainDlgName() + _T(" dialog") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += _T("class AFX_EXT_CLASS ") + GetMainDlgName() + _T(" : public cmSplitDialog") + xCrLf;
	headCode_ += _T("{")  + xCrLf;
	headCode_ += xCrLf;
}

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

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

void CCppMainDialogGenerator::Head_generateDialogData()
{
	headCode_ += _T("// Dialog Data") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_DATA(") +  GetMainDlgName() + _T(")") + xCrLf;
	//headCode_ += xTab + xTab + "enum { IDD = IDD_SPLITTERDLG};"  + xCrLf;
	headCode_ += xTab + xTab + _T("// NOTE: the ClassWizard will add data members here")  + xCrLf;
	headCode_ += xTab + _T("//}}AFX_DATA") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += xTab + _T("CImageList imageList_;") + xCrLf;
	headCode_ += xCrLf;

	//headCode_ += xTab + "CDialog emptyDlg_;" + xCrLf; 
	//Head_generateDlgDeclare(classInfo_);
	
	headCode_ += xTab + _T("int viewIndex_EmptyDlg_;") + xCrLf;
	Head_generateViewIndexDeclare(classInfo_);
	headCode_ += xCrLf;
	Head_generateDeclareChildDlg(classInfo_);
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateOverrides()
{
	headCode_ += _T("// Overrides") + xCrLf;
	headCode_ += xTab + _T("// ClassWizard generated virtual function overrides") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_VIRTUAL(") + GetMainDlgName() + _T(")") + xCrLf;
	headCode_ += xTab + _T("protected:") + xCrLf;
	headCode_ += xTab + xTab + _T("virtual BOOL PreTranslateMessage(MSG* pMsg);") + xCrLf;
	headCode_ += xTab + _T("//virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support") + xCrLf;
	headCode_ += xTab + _T("//}}AFX_VIRTUAL") + xCrLf + xCrLf;
}

void CCppMainDialogGenerator::Head_generateMessageMap()
{
	headCode_ += _T("// Implementation") + xCrLf;
	headCode_ += _T("protected:") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += xTab + _T("// Generated message map functions") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_MSG(") + GetMainDlgName() + _T(")") + xCrLf;
	headCode_ += xTab + _T("virtual BOOL OnInitDialog();") + xCrLf;
	//headCode_ += xTab + "afx_msg void OnTreeNodeSelectionXXX(NMHDR* pNMHDR, LRESULT* pResult);" + xCrLf;
	headCode_ += xTab + _T("afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);") + xCrLf;
	headCode_ += xTab + _T("afx_msg void OnSize(UINT nType, int cx, int cy);") + xCrLf;
	headCode_ += xTab + _T("afx_msg void OnMnuAppendItem_Array();") + xCrLf;
	headCode_ += xTab + _T("afx_msg void OnMnuInsertItem_ArrayItem();") + xCrLf; 
	headCode_ += xTab + _T("afx_msg void OnMnuAppendItem_ArrayItem();") + xCrLf; 
	headCode_ += xTab + _T("afx_msg void OnMnuRemoveItem_ArrayItem();") + xCrLf; 
	headCode_ += xTab + _T("afx_msg void OnMnuCreateItem_Map();") + xCrLf;       
	headCode_ += xTab + _T("afx_msg void OnMnuRemoveItem_MapItem();") + xCrLf;   
	headCode_ += xTab + _T("afx_msg void OnMnuCreateItem_MapItem();") + xCrLf;   
	headCode_ += xTab + _T("//}}AFX_MSG") + xCrLf;
	headCode_ += xTab + _T("DECLARE_MESSAGE_MAP()") + xCrLf;
	
	headCode_ += xTab + _T("void OnTreeNodeSelection();") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateDataMembers()
{
	headCode_ += _T("// data members") + xCrLf;
	headCode_ += _T("//") + xCrLf;
	headCode_ += _T("protected:") + xCrLf;
	headCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo> node2InfoMap_;") + xCrLf;
	headCode_ += xTab + GetClassName() + _T(" ") + GetCamelCase(classInfo_->GetName()) + _T("_;") + xCrLf;
	headCode_ += xTab + _T("int lastSelectedViewIndex_;") + xCrLf;
	headCode_ += xTab +_T("HTREEITEM lastSelNode_;") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateInitializeTree()
{
	headCode_ += xTab + _T("void InitializeTree();") + xCrLf;
}

void CCppMainDialogGenerator::Head_generateStoreNodeData()
{
	headCode_ += xTab + _T("void StoreNodeData(HTREEITEM node);") + xCrLf;
}

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

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

void CCppMainDialogGenerator::Head_generateGetChildDialog()
{
	//headCode_ += xTab +"CDialog* GetChildDialog(HTREEITEM treeItem);" + xCrLf;
}

void CCppMainDialogGenerator::Head_generateGetSetData()
{
	headCode_ += xTab + _T("void SetData(") + GetClassName() + _T("& ") + GetCamelCase(classInfo_->GetName()) + _T(");") + xCrLf;
	headCode_ += xTab + GetClassName() + _T("& GetData();") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateOnOK()
{
	headCode_ += xTab + _T("void OnOK();") + xCrLf;
}

void CCppMainDialogGenerator::Head_generateGetNodeInfo()
{
	headCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo* GetNodeInfo(HTREEITEM treeNode);") + xCrLf;
}

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

void CCppMainDialogGenerator::Impl_generateHeader()
{
	implCode_ += _T("// ") + GetMainDlgName() + _T(".cpp : implementation file") + xCrLf;
	implCode_ += _T("//") + xCrLf;
	implCode_ += GetGenerationTimeStamp();
	implCode_ += xCrLf;
	implCode_ += _T("#pragma warning(disable:4786)") + xCrLf;
	implCode_ += _T("#pragma warning(disable:4060) // warning C4060: switch statement contains no 'case' or 'default' labels") + xCrLf;
	
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateIncludeSection()
{
	implCode_ += _T("#include \"stdafx.h\"") + xCrLf;
	implCode_ += _T("#include <afxcview.h>") + xCrLf;
	implCode_ += _T("#include \"") + GetMainDlgName() + _T(".h\"") + xCrLf;
	implCode_ += _T("#include \"resource.h\"") + xCrLf;
	implCode_ += _T("#include \"") + GetResourceFileName() + _T(".h\"") + xCrLf;
	implCode_ += _T("#include \"InputBox.h\"") + xCrLf;
	Impl_generateClassInclude(classInfo_);
	
	Impl_generateChildDlgInclude(classInfo_);

	implCode_ += xCrLf;
}

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

void CCppMainDialogGenerator::Impl_generateMainTitle()
{
	implCode_ += _T("/////////////////////////////////////////////////////////////////////////////") + xCrLf;
	implCode_ += _T("// CCfgClass1 dialog") + xCrLf + xCrLf;

}

void CCppMainDialogGenerator::Impl_generateConstructor()
{
	implCode_ += GetMainDlgName() + _T("::") + GetMainDlgName() + _T("(CWnd* pParent /*=NULL*/):") + xCrLf;
	Impl_generateChildDlgInit(classInfo_);
	implCode_ += xTab + xTab + _T("cmSplitDialog(pParent),") + xCrLf;
	implCode_ += xTab + xTab + _T("lastSelectedViewIndex_(-1),") + xCrLf;
	implCode_ += xTab + xTab + _T("lastSelNode_(NULL)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("//{{AFX_DATA_INIT(") + GetMainDlgName() + _T(")") + xCrLf;
	implCode_ += xTab + xTab + _T("// NOTE: the ClassWizard will add member initialization here") + xCrLf;
	implCode_ += xTab + _T("//}}AFX_DATA_INIT") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;	
}

void CCppMainDialogGenerator::Impl_generateDestructor()
{
	implCode_ += GetMainDlgName() + _T("::~") + GetMainDlgName() + _T("()") + xCrLf;
	implCode_ += _T("{") + xCrLf;

	Impl_generateDeleteView	(classInfo_);
	implCode_ += xCrLf;

	Impl_generateChildDlgDelete(classInfo_);

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

void CCppMainDialogGenerator::Impl_generateMessageMap()
{
	implCode_ += _T("BEGIN_MESSAGE_MAP(") + GetMainDlgName() + _T(", cmSplitDialog)") + xCrLf;
	implCode_ += xTab + _T("//{{AFX_MSG_MAP(") + GetMainDlgName() + _T(")") + xCrLf;
	implCode_ += xTab + _T("ON_WM_CREATE()") + xCrLf;
	implCode_ += xTab + _T("ON_WM_SIZE()") + xCrLf;
	//implCode_ += xTab + "ON_NOTIFY(TVN_SELCHANGED, IDC_GLOBAL_CFGHWDOC_TREE, OnTreeNodeSelectionXXX);" + xCrLf;
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITARRAY_APPENDITEM, OnMnuAppendItem_Array)") + xCrLf;     
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITARRAYITEM_INSERTITEM, OnMnuInsertItem_ArrayItem)") + xCrLf; 
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITARRAYITEM_APPENDITEM, OnMnuAppendItem_ArrayItem)") + xCrLf; 
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITARRAYITEM_REMOVEITEM, OnMnuRemoveItem_ArrayItem)") + xCrLf; 
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITMAP_CREATEITEM, OnMnuCreateItem_Map)") + xCrLf;       
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITMAPITEM_REMOVEITEM, OnMnuRemoveItem_MapItem)") + xCrLf;   
	implCode_ += xTab + _T("ON_COMMAND(ID_EDITMAPITEM_CREATEITEM, OnMnuCreateItem_MapItem)") + xCrLf;   
	implCode_ += xTab + _T("//}}AFX_MSG_MAP") + xCrLf;
	implCode_ += _T("END_MESSAGE_MAP()") + xCrLf + xCrLf;
}

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

	implCode_ += _T("BOOL ") + GetMainDlgName() + _T("::OnInitDialog()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("cmSplitDialog::OnInitDialog();") + xCrLf + xCrLf;
	
	implCode_ += xTab + _T("CRect rc;") + xCrLf;
	//implCode_ += xTab + "CRect treeRect;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("GetClientRect(rc);") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab + _T("imageList_.Create(16, 16, ILC_COLOR32 | ILC_MASK, 50, 50);") + xCrLf;
	implCode_ += xTab + _T("tree_.SetImageList(&imageList_, TVSIL_NORMAL);") + xCrLf;

	// tree customization
	//
	cmString stylesToAdd;
	cmString stylesToRemove;
	cmString indent;
	if (project_->GetMainDialog()->GetTreeSettings()->GetFullRowSelect())
		stylesToAdd += "| TVS_FULLROWSELECT ";
	else
		stylesToRemove += "| TVS_FULLROWSELECT ";

	if (project_->GetMainDialog()->GetTreeSettings()->GetHasButtons())
		stylesToAdd += "| TVS_HASBUTTONS ";
	else
		stylesToRemove += "| TVS_HASBUTTONS ";

	if (project_->GetMainDialog()->GetTreeSettings()->GetHasLines())
		stylesToAdd += "| TVS_HASLINES ";
	else
		stylesToRemove += "| TVS_HASLINES ";

	if (project_->GetMainDialog()->GetTreeSettings()->GetLinesAtRoot())
		stylesToAdd += "| TVS_LINESATROOT ";
	else
		stylesToRemove += "| TVS_LINESATROOT ";

	if (project_->GetMainDialog()->GetTreeSettings()->GetShowSelectionAlways())
		stylesToAdd += "| TVS_SHOWSELALWAYS ";
	else
		stylesToRemove += "| TVS_SHOWSELALWAYS ";

	if (project_->GetMainDialog()->GetTreeSettings()->GetSingleNodeExpand())
		stylesToAdd += "| TVS_SINGLEEXPAND ";
	else
		stylesToRemove += "| TVS_SINGLEEXPAND ";

	if (stylesToAdd.GetLength() && stylesToAdd.Mid(0, 2) == _T("| "))
		stylesToAdd = stylesToAdd.Mid(2);
	stylesToAdd.TrimRight(_T(" "));

	if (stylesToRemove.GetLength() && stylesToRemove.Mid(0, 2) == _T("| "))
		stylesToRemove = stylesToRemove.Mid(2);
	stylesToRemove.TrimRight(_T(" "));

	indent.Format(_T("%d"), project_->GetMainDialog()->GetTreeSettings()->GetIndent());
	implCode_ += xTab + _T("tree_.ModifyStyle(") + stylesToRemove + _T(", ") + stylesToAdd + _T(");") + xCrLf;
	implCode_ += xTab + _T("tree_.SetIndent(") + indent + _T(");") + xCrLf;

	//implCode_ += xTab + _T("tree_.ModifyStyle(0, TVS_HASLINES | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_LINESATROOT);") + xCrLf;
	
	implCode_ += xCrLf;
	implCode_ += xTab + _T("InitializeTree();") + xCrLf;
	implCode_ += xCrLf;
	
	implCode_ += xTab + _T("// create dialogs") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	Impl_generateDlgCreate(classInfo_);
	implCode_ += xCrLf;
	
	implCode_ += xTab + _T("// setup child list") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	Impl_generateDlgAddView(classInfo_);
	implCode_ += xCrLf;

	implCode_ += xTab + _T("// select root node") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM rootItem;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("rootItem = tree_.GetRootItem();") + xCrLf;

	//if (classInfo_->GetRenderingMode() != enRenderingMode_None)
	//	implCode_ += xTab + GetCamelCase(GetDlgName(classInfo_)) + "_.SetWindowPos(&CWnd::wndTop, dlgRect_.left, dlgRect_.top, dlgRect_.Width(), dlgRect_.Height(), SWP_SHOWWINDOW);" + xCrLf;
	
	if (classInfo_->GetRenderingMode() != enRenderingMode_None) {
		implCode_ += xTab + _T("SelectChild(viewIndex_") + GetCamelCase(GetDlgName(classInfo_)) + _T("_);") + xCrLf;
	} else
		implCode_ += xTab + _T("SelectChild(viewIndex_EmptyDlg_);") + xCrLf;
	
	implCode_ += xTab + _T("tree_.Select(rootItem, TVGN_CARET);") + xCrLf;
	implCode_ += xCrLf;

	int splitterPos;
	double dialogWidth;
	_TCHAR tmp[100];

	implCode_ += xTab + _T("// position and size") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("int left = 0;") + xCrLf;
	implCode_ += xTab + _T("int top = 0;") + xCrLf;
	implCode_ += xTab + _T("int width;") + xCrLf;
	implCode_ += xTab + _T("int height;") + xCrLf;
	implCode_ += xTab + _T("CWnd* parent;") + xCrLf;
	implCode_ += xCrLf;
	
	switch (project_->GetMainDialog()->GetInitialSize()) {
		case enMainDlgSize_Small:
			implCode_ += xTab + _T("width = 640;") + xCrLf;
			implCode_ += xTab + _T("height = 480;") + xCrLf;
			dialogWidth = 640;
			break;

		case enMainDlgSize_Medium:
			implCode_ += xTab + _T("width = 800;") + xCrLf;
			implCode_ += xTab + _T("height = 600;") + xCrLf;
			dialogWidth = 800;
			break;

		case enMainDlgSize_Large:
			implCode_ += xTab + _T("width = 1024;") + xCrLf;
			implCode_ += xTab + _T("height = 768;") + xCrLf;
			dialogWidth = 1024;
			break;
	}

	implCode_ += xTab + _T("parent = GetParent();") + xCrLf;
	implCode_ += xTab + _T("if (parent) {") + xCrLf;
	implCode_ += xTab + xTab + _T("CRect rc;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + _T("parent->GetWindowRect(rc);") + xCrLf;
	implCode_ += xTab + xTab + _T("left = rc.CenterPoint().x - (width / 2);") + xCrLf;
	implCode_ += xTab + xTab + _T("top = rc.CenterPoint().y - (height / 2);") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;

	implCode_ += xTab + _T("SetWindowPos(&CWnd::wndTop, left, top, width, height, 0);") + xCrLf;		
	splitterPos = dialogWidth * (double)project_->GetMainDialog()->GetSplitterPos() / 100;
	wsprintf(tmp, _T("%d"), splitterPos);
	implCode_ += xTab + _T("splitterPos_ = ") + cmString(tmp) + _T(";") + xCrLf;
	implCode_ += xCrLf;
	if (project_->GetMainDialog()->GetIconFileName().GetLength())
		implCode_ += xTab + _T("SetIcon(AfxGetApp()->LoadIcon(MAIN_DIALOG_ICON), FALSE);") + xCrLf;	
	
	implCode_ += xTab + _T("SetWindowText(_T(\"") + project_->GetMainDialog()->GetCaption() + _T("\"));") + xCrLf;
	implCode_ += xTab + _T("UpdateWindowSize();") + 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;
	implCode_ += xCrLf;

	// generate OnCreate method
	//
	implCode_ += _T("int ") + GetMainDlgName() + _T("::OnCreate(LPCREATESTRUCT lpCreateStruct)") + xCrLf;
	implCode_ += _T("{") + xCrLf;


	implCode_ += xTab + _T("if (cmSplitDialog::OnCreate(lpCreateStruct) == -1)") + xCrLf;
    implCode_ += xTab + xTab + _T("return -1;") + xCrLf;
    implCode_ += xCrLf;

	implCode_ += xCrLf;
	implCode_ += xTab + _T("return 0;") + xCrLf;
	implCode_ += xCrLf;

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

	implCode_ += _T("BOOL ") + GetMainDlgName() + _T("::PreTranslateMessage(MSG* pMsg)") + xCrLf; 
	implCode_ += _T("{") + xCrLf;
	
	
	implCode_ += xTab + _T("switch (pMsg->message) {") + xCrLf;
	/*
	implCode_ += xTab + xTab + "case WM_LBUTTONDOWN:" + xCrLf;
	implCode_ += xTab + xTab + xTab + "if (pMsg->hwnd == splitterWnd_.GetPane(0, 0)->GetSafeHwnd()) {" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "HTREEITEM selNode;" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "CPoint pt(pMsg->pt);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab +"UINT flags;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "ScreenToClient(&pt);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "selNode = tree_->HitTest(pt, &flags);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "if (selNode == NULL)" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab +"return FALSE;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "if (selNode != lastSelNode_) {" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "tree_->Select(selNode, TVGN_CARET);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "OnTreeNodeSelection();" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "UpdateNodeImages(lastSelNode_);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "lastSelNode_ = selNode;" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab +"}" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "UpdateNodeImages(selNode);" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "if (!(flags & TVHT_ONITEM))" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "return FALSE;" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "return TRUE;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + "}" + xCrLf;
	implCode_ += xTab + xTab + xTab + "break;" + xCrLf;
	implCode_ += xCrLf;
	*/
	/*implCode_ += xTab + xTab + "case WM_RBUTTONDOWN:" +xCrLf;
	implCode_ += xTab + xTab + xTab + "if (pMsg->hwnd == tree_.GetSafeHwnd()) {" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "HTREEITEM selNode;" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "CPoint pt(pMsg->pt);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab +"UINT flags;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "ScreenToClient(&pt);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "selNode = tree_.HitTest(pt, &flags);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "if (selNode == NULL)" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab +"return FALSE;" + xCrLf;
	implCode_ += xCrLf;
	
	implCode_ += xTab + xTab + xTab + xTab + "if (selNode != lastSelNode_) {" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "tree_->Select(selNode, TVGN_CARET);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "OnTreeNodeSelection();" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "UpdateNodeImages(lastSelNode_);" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "lastSelNode_ = selNode;" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab +"}" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "UpdateNodeImages(selNode);" + xCrLf;
	
	implCode_ += xTab + xTab + xTab + xTab + "DisplayPopupMenu(selNode);" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "if (!(flags & TVHT_ONITEM))" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + xTab + "return FALSE;" + xCrLf;
	implCode_ += xTab + xTab + xTab + xTab + "return TRUE;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + xTab + "}" + xCrLf;
	implCode_ += xTab + xTab + xTab + "break;" + xCrLf;
	implCode_ += xCrLf;*/    
	implCode_ += xTab + _T("} // end switch") + xCrLf;
	implCode_ += xCrLf;
	
	implCode_ += xTab + _T("return cmSplitDialog::PreTranslateMessage(pMsg);") + xCrLf;

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

void CCppMainDialogGenerator::Impl_generateInitializeTree()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::InitializeTree()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	
	implCode_ += xTab + _T("BuildNode_") + classInfo_->GetName() + _T("(") + GetCamelCase(classInfo_->GetName()) + _T("_, TVI_ROOT);") + xCrLf;
	//Impl_generateNodeInsertion(classInfo_);

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

void CCppMainDialogGenerator::Impl_generateStoreNodeData()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::StoreNodeData(HTREEITEM node)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo>::iterator it;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo nodeInfo;") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab + _T("it = node2InfoMap_.find(node);") + xCrLf;
	
	// generate new dialog show data
	//
	int count = 0;

	implCode_ += xTab + _T("if(it != node2InfoMap_.end()) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nodeInfo = it->second;") + xCrLf;
	implCode_ += xTab + xTab + _T("switch(nodeInfo.GetClassId()) {") + xCrLf;
	Impl_generateDialogStoreDataSwitch(classInfo_, count);
	implCode_ += xTab +  xTab + _T("}") + xCrLf;
	implCode_ += xTab +  _T("}") + xCrLf;
	implCode_ += xCrLf;
	
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateNodeInsertion(CXmlClassInfo* classInfo, CXmlClassInfo* parentClassInfo)
{
	/*
	string nodeName;

	nodeName = GetCamelCase(classInfo->GetName()) + "Node";

	if (parentClassInfo)
		implCode_ += xTab + "HTREEITEM " + nodeName + " = tree_.InsertItem(\"" + classInfo->GetName() + "\", " + GetCamelCase(parentClassInfo->GetName())  + "Node);" + xCrLf; 
	else
		implCode_ += xTab + "HTREEITEM " + nodeName + " = tree_.InsertItem(\"" + classInfo->GetName() + "\");" + xCrLf; 

	implCode_ += xTab + "node2DialogIdMap_[" + nodeName + "] = " + GetDialogId(classInfo) + ";" + xCrLf; 

	// generate insertion code for children
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateNodeInsertion(dynamic_cast<CXmlClassInfo*>(member), classInfo);		
		}
	}*/
}

void CCppMainDialogGenerator::Impl_generateOnNodeSelection()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnTreeNodeSelection()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo>::iterator it;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo nodeInfo;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo parentNodeInfo;")  + xCrLf;
	implCode_ += xTab + _T("HTREEITEM parentNode;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM selNode;") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab +_T("selNode = tree_.GetSelectedItem();") + xCrLf; //pNMTreeView->itemNew.hItem;";
	implCode_ += xCrLf;

	// generate old dialog store data
	//
	implCode_ += xTab + _T("// store data for last selected dialog and hide it") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("if (lastSelNode_)") + xCrLf;
	implCode_ += xTab + xTab + _T("StoreNodeData(lastSelNode_);") + xCrLf;
	implCode_ += xCrLf;
		
	// get parent node info
	//
	implCode_ += xTab + _T("// get parent node info") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("it = node2InfoMap_.find(parentNode);") + xCrLf;
    implCode_ += xTab + _T("if(it != node2InfoMap_.end())") + xCrLf;
    implCode_ += xTab + xTab + _T("parentNodeInfo = it->second;") + xCrLf;
	implCode_ += xCrLf;

	// generate new dialog show data
	//
	vector<CXmlClassInfo*> parentStack;
	int count = 0;

	implCode_ += xTab + _T("it = node2InfoMap_.find(selNode);") + xCrLf;
	implCode_ += xTab + _T("if(it != node2InfoMap_.end()) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nodeInfo = it->second;") + xCrLf;
	implCode_ += xTab + xTab + _T("switch(nodeInfo.GetClassId()) {") + xCrLf;
	Impl_generateDialogSetDataSwitch(classInfo_, parentStack, count);
	implCode_ += xTab +  xTab + _T("}") + xCrLf;
	implCode_ += xTab +  _T("}") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab +  _T("RedrawWindow();") + xCrLf;
	implCode_ += xCrLf;

	// close method
	//
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateDialogSwitch(CXmlClassInfo* classInfo, int& count)
{
	count++;

	implCode_ += xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T(":") + xCrLf;
	
	implCode_ += xTab + xTab + xTab + _T("ret = &") + GetCamelCase(GetDlgName(classInfo)) + _T("_;") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
	implCode_ += xCrLf;

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class)
			Impl_generateDialogSwitch(dynamic_cast<CXmlClassInfo*>(member), count);
	}
}

void CCppMainDialogGenerator::Impl_generateGetChildDialog()
{
	/*
	implCode_ += "CDialog* " + GetMainDlgName() + "::GetChildDialog(HTREEITEM treeItem)" + xCrLf;
	implCode_ += "{" + xCrLf;
	implCode_ += xTab + "CDialog* ret = NULL;" + xCrLf;
	implCode_ += xTab + "map<HTREEITEM, int>::iterator it;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "it = node2DialogIdMap_.find(treeItem);" + xCrLf;
	implCode_ += xTab + "if(it != node2DialogIdMap_.end()) {" + xCrLf;
	implCode_ += xTab +  xTab + "switch(it->second) {" + xCrLf;

	Impl_generateDialogSwitch(classInfo_);

	implCode_ += xTab +  xTab + "}" + xCrLf;
	implCode_ += xTab +  "}" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "return ret;" + xCrLf;
	implCode_ += "}" + xCrLf;
	implCode_ += xCrLf;
	*/
}

void CCppMainDialogGenerator::Impl_generateGetSetData()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::SetData(") + GetClassName() + _T("& ") + GetCamelCase(classInfo_->GetName()) + _T(")") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("_ = ") + GetCamelCase(classInfo_->GetName()) + _T(";") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += GetClassName() + _T("& ") + GetMainDlgName() + _T("::GetData()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("return ") + GetCamelCase(classInfo_->GetName()) + _T("_;") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateDialogSetDataSwitch(CXmlClassInfo* classInfo, 
															   vector<CXmlClassInfo*> parentStack,
															   int& count)
{
	cmString p;
	enCardinality c;
	cmString varPath;
	cmString dlgName;
	cmString arrayDlgName;
	cmString mapDlgName;
	cmString parentPath;
	cmString n;
	enRenderingMode r;
	CXmlClassInfo* tmpClassInfo;

	count++;

	varPath = Impl_generateVarPath(classInfo, parentStack);

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;

	dlgName = GetDlgName(tmpClassInfo);
	arrayDlgName = GetArrayDialogName(tmpClassInfo);
	c = tmpClassInfo->GetCardinalityInfo()->GetCardinality();
	p = GetCardinalityPostfix(tmpClassInfo);
	r = tmpClassInfo->GetRenderingMode();
	n = tmpClassInfo->GetName();

	parentPath = GetParentPath(NULL, parentStack);
	
	if (r != enRenderingMode_None) {
		if (c == enCardinality_Array && r != enRenderingMode_Grid) {
			cmString tmpVarPath;

			tmpVarPath = Impl_generateVarPath(classInfo, parentStack, true);

			implCode_ += xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(p) + _T(":") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("{") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + arrayDlgName + _T("* dlg;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("SelectChild(viewIndex_") + GetCamelCase(arrayDlgName) + _T("_);") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("dlg = (") + arrayDlgName + _T("*)GetChild(viewIndex_") + GetCamelCase(arrayDlgName) + _T("_);") + xCrLf;
			//implCode_ += xTab + xTab + xTab + xTab + "dlg->SetData(&(" + tmpVarPath + "), selNode, this);" + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem") + parentPath + _T("_") + n + p + _T("(selNode), selNode, this);") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("lastSelectedViewIndex_ = viewIndex_") + GetCamelCase(arrayDlgName) + _T("_;") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("}") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
			implCode_ += xCrLf;
		} else if (c == enCardinality_Map) {
			mapDlgName = GetMapDialogName(tmpClassInfo);

			implCode_ += xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(p) + _T(":") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("{") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + mapDlgName + _T("* dlg;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("SelectChild(viewIndex_") + GetCamelCase(mapDlgName) + _T("_);") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("dlg = (") + mapDlgName + _T("*)GetChild(viewIndex_") + GetCamelCase(mapDlgName) + _T("_);") + xCrLf;
			//implCode_ += xTab + xTab + xTab + xTab + "dlg->SetData(&(" + tmpVarPath + "), selNode, this);" + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem") + parentPath + _T("_") + n + p + _T("(selNode), selNode, this);") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("lastSelectedViewIndex_ = viewIndex_") + GetCamelCase(mapDlgName) + _T("_;") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("}") + xCrLf;
			
			//implCode_ += xTab + xTab + xTab + "lastSelectedViewIndex_ = viewIndex_EmptyDlg_;" + xCrLf;
			//implCode_ += xTab + xTab + xTab + "SelectChild(viewIndex_EmptyDlg_);" + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
			implCode_ += xCrLf;
		}
	

		// class dialog switch
		//
		implCode_ += xTab + xTab + _T("case ") + GetDialogId(tmpClassInfo, count) + _T(":") + xCrLf;
		if (r == enRenderingMode_Grid) {
			implCode_ += xTab + xTab + xTab + _T("{") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + dlgName + _T("* dlg;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("SelectChild(viewIndex_") + GetCamelCase(dlgName) + _T("_);") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("dlg = (") + dlgName + _T("*)GetChild(viewIndex_") + GetCamelCase(dlgName) + _T("_);") + xCrLf;
			if (parentPath.GetLength())
				implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem") + parentPath + _T("_") + n + p + _T("(selNode));") + xCrLf;
			else
				implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem_") + n + _T("(selNode));") + xCrLf;
			
			implCode_ += xTab + xTab + xTab + xTab + _T("lastSelectedViewIndex_ = viewIndex_") + GetCamelCase(dlgName) + _T("_;") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("}") + xCrLf;
		} else {
			implCode_ += xTab + xTab + xTab + _T("{") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + dlgName + _T("* dlg;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("SelectChild(viewIndex_") + GetCamelCase(dlgName) + _T("_);") + xCrLf;
			implCode_ += xTab + xTab + xTab + xTab + _T("dlg = (") + dlgName + _T("*)GetChild(viewIndex_") + GetCamelCase(dlgName) + _T("_);") + xCrLf;
			if (c == enCardinality_Map) {
				implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem") + parentPath + _T("_") + n + p + _T("(tree_.GetParentItem(selNode)), GetItem") + parentPath + _T("_") + n + p + _T("_") + n + _T("(selNode), tree_.GetParentItem(selNode), this);") + xCrLf;
			} else if (c == enCardinality_Array && r != enRenderingMode_Grid) {
				implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem") + parentPath + _T("_") + n + p + _T("_") + n + _T("(selNode));") + xCrLf;
			} else {
				if (parentPath.GetLength())
					implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem") + parentPath + _T("_") + n + _T("(selNode));") + xCrLf;
				else
					implCode_ += xTab + xTab + xTab + xTab + _T("dlg->SetData(GetItem_") + n + _T("(selNode));") + xCrLf;
			}
			implCode_ += xTab + xTab + xTab + xTab + _T("lastSelectedViewIndex_ = viewIndex_") + GetCamelCase(dlgName) + _T("_;") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("}") + xCrLf;
		} 
		implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;

	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = tmpClassInfo->GetMembers();
	parentStack.push_back(classInfo);
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateDialogSetDataSwitch(dynamic_cast<CXmlClassInfo*>(member), parentStack, count);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateDialogStoreDataSwitch(CXmlClassInfo* classInfo, int& count)
{
	cmString dlgName;
	enRenderingMode renderingMode;

	count++;
	implCode_ += xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T(":") + xCrLf;
	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		dlgName = GetDlgName(inheritClassInfo);
		renderingMode = inheritClassInfo->GetRenderingMode();
	} else {
		dlgName = GetDlgName(classInfo);
		renderingMode = classInfo->GetRenderingMode();
	}
	
	if (renderingMode != enRenderingMode_None) {
		implCode_ += xTab + xTab + xTab + _T("{") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + dlgName + _T("* dlg;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("dlg = (") + dlgName + _T("*)GetActiveChild();") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("dlg->StoreData();")+ xCrLf;
		implCode_ += xTab + xTab + xTab + _T("}") + xCrLf;
	}
	implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
	implCode_ += xCrLf;

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class)
			Impl_generateDialogStoreDataSwitch(dynamic_cast<CXmlClassInfo*>(member), count);
	}
}

void CCppMainDialogGenerator::Impl_generateOnOK()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnOK()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
    implCode_ += xTab + _T("if (tree_.GetSelectedItem())") + xCrLf;
    implCode_ += xTab + xTab + _T("StoreNodeData(tree_.GetSelectedItem());") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("cmSplitDialog::OnOK();") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateBuildNode(CXmlClassInfo* classInfo, cmString parentPath)
{
	cmString p;
	cmString name;
	cmString tmp;
	cmString prototype;
	enCardinality c;
	enRenderingMode r;
		
	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		name = inheritClassInfo->GetName();
		p = GetCardinalityPostfix(inheritClassInfo);
		c = inheritClassInfo->GetCardinalityInfo()->GetCardinality();
		r = inheritClassInfo->GetRenderingMode();
	} else {
		name = classInfo->GetName();
		p = GetCardinalityPostfix(classInfo);
		c = classInfo->GetCardinalityInfo()->GetCardinality();
		r = classInfo->GetRenderingMode();
	}

	if (classInfo == classInfo_) {
		headCode_ += xCrLf;
		headCode_ += _T("protected:") + xCrLf;
		headCode_ += xCrLf;
	}

	if (parentPath.GetLength())
		tmp = parentPath + _T("_");
	else
		tmp = _T("");
		
	if (r == enRenderingMode_Grid) {
		headCode_ += xTab + _T("HTREEITEM BuildNode_") + tmp + name + _T("(HTREEITEM parentItem);") + xCrLf;
	} else {
		
		switch (c) {
			case enCardinality_Map:
				prototype = xTab + _T("HTREEITEM BuildNode_") + tmp + name + _T("(") + GetClassName(name) + _T("& ") + GetCamelCase(name) + _T(", HTREEITEM parentItem);") + xCrLf;
				
				break;

			case enCardinality_Array:
				prototype = xTab + _T("HTREEITEM BuildNode_") + tmp + name + _T("(") + GetClassName(name) + _T("& ") + GetCamelCase(name) + _T(", HTREEITEM parentItem, int itemIndex);") + xCrLf;
				break;
			
			default:
				prototype = xTab + _T("HTREEITEM BuildNode_") + tmp + name + _T("(") + GetClassName(name) + _T("& ") + GetCamelCase(name) + _T(", HTREEITEM parentItem);") + xCrLf;
		}
		
		headCode_ += prototype;

		if (c != enCardinality_SingleInstance && r != enRenderingMode_Grid) {
			prototype = xTab + _T("HTREEITEM BuildNode_") + tmp + name + p + _T("(") + GetClassName(name) + p + _T("& ") + GetCamelCase(name) + p + _T(", HTREEITEM parentItem);") + xCrLf;
			headCode_ += prototype;
		}

		ClassMemberMap* members;
		ClassMemberMap::iterator it;
		CXmlBaseElement* member;

		members = classInfo->GetMembers();
		if (parentPath.GetLength())
			tmp = parentPath + _T("_") + name;
		else
			tmp = name;

		for (it = members->begin(); it != members->end(); it++) {
			member = it->second;

			if (member->GetDataType() == enDataType_Class)
				Head_generateBuildNode(dynamic_cast<CXmlClassInfo*>(member), tmp);
		}
	}
}

// generate declarations of functions capable to find a configuration item (class instance) given a HTREEITEM
//
void CCppMainDialogGenerator::Head_generateGetItem(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack)
{
	cmString p;
	cmString name;
	cmString className;
	cmString tmp;
	cmString prototype;
	cmString parentPath;
	enCardinality c;
	enRenderingMode r;
	CXmlClassInfo* tmpClassInfo;

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;
	
	name = tmpClassInfo->GetName();
	p = GetCardinalityPostfix(tmpClassInfo);
	c = tmpClassInfo->GetCardinalityInfo()->GetCardinality();
	r = tmpClassInfo->GetRenderingMode();

	if (classInfo == classInfo_) {
		headCode_ += xCrLf;
		headCode_ += _T("protected:") + xCrLf;
		headCode_ += xCrLf;
	}

	className = GetClassName(name);

	parentPath = GetParentPath(NULL, parentStack);

	if (r == enRenderingMode_Grid) {
		headCode_ += xTab + className + p + _T("* GetItem") + parentPath + _T("_") + name + p + _T("(HTREEITEM treeItem);") + xCrLf;
	} else {
		parentPath = GetParentPath(NULL, parentStack);
		if (c != enCardinality_SingleInstance) {
			prototype = xTab + className + p + _T("* GetItem") + parentPath + _T("_") + name + p + _T("(HTREEITEM treeItem);") + xCrLf;
			headCode_ += prototype;
		}
		
		switch (c) {
			case enCardinality_Map:
				tmp = _T("_") + name + p + _T("_") + name;
				prototype = xTab + className + _T("* GetItem") + parentPath + tmp + _T("(HTREEITEM treeItem);") + xCrLf;
				break;

			case enCardinality_Array:
				tmp = _T("_") + name + p + _T("_") + name;
				prototype = xTab + className + _T("* GetItem") + parentPath + tmp + _T("(HTREEITEM treeItem);") + xCrLf;
				break;
			
			default:
				prototype = xTab + className + _T("* GetItem") + parentPath + _T("_") + name + _T("(HTREEITEM treeItem);") + xCrLf;
		}
		
		headCode_ += prototype;

		ClassMemberMap* members;
		ClassMemberMap::iterator it;
		CXmlBaseElement* member;

		members = classInfo->GetMembers();
		
		parentStack.push_back(tmpClassInfo);
		for (it = members->begin(); it != members->end(); it++) {
			member = it->second;

			if (member->GetDataType() == enDataType_Class)
				Head_generateGetItem(dynamic_cast<CXmlClassInfo*>(member), parentStack);
		}
	}
}

void CCppMainDialogGenerator::Head_generateInsertChildNode(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack)
{
	CXmlClassInfo* tmpClassInfo;
	cmString parentPath;
	enCardinality c;
	enRenderingMode r;

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;

	parentPath = GetParentPath(NULL, parentStack);

	//why did I use "classInfo" and not "tmpClassInfo" ? if (classInfo->GetRenderingMode() != enRenderingMode_None && classInfo->GetRenderingMode() != enRenderingMode_Grid) {
	r = tmpClassInfo->GetRenderingMode();
	if ((r != enRenderingMode_None && r != enRenderingMode_Grid) ||
		 tmpClassInfo->GetLockedByInheritance()) {
		
		cmString tmp;

		tmp += _T("_");
		tmp += tmpClassInfo->GetName();
		tmp += GetCardinalityPostfix(tmpClassInfo);

		c = tmpClassInfo->GetCardinalityInfo()->GetCardinality(); // 2004.07.04 (was classInfo-> ...)

		switch (c) {
			case enCardinality_Array:
				if (r != enRenderingMode_Grid)
					headCode_ += xTab + _T("HTREEITEM InsertArrayItem") + parentPath + tmp + _T("(") + GetClassName(/*2004.04.07 was classInfo->GetName()*/tmpClassInfo->GetName()) + _T("& newItem, HTREEITEM parentItem, int itemIndex);") + xCrLf;
				break;

			case enCardinality_Map:
				headCode_ += xTab + _T("HTREEITEM InsertMapItem") + parentPath + tmp + _T("(") + GetClassName(/*2004.04.07 was classInfo->GetName()*/tmpClassInfo->GetName()) + _T("& newItem, HTREEITEM parentItem, const cmString& itemKey);") + xCrLf;
				break;
		}
	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	cmString tmp;

	parentStack.push_back(tmpClassInfo);

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Head_generateInsertChildNode(dynamic_cast<CXmlClassInfo*>(member), parentStack);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateBuildNode(CXmlClassInfo* classInfo, int& count, cmString parentPath)
{
	enCardinality c;
	enRenderingMode r;
	cmString p;
	cmString name;
	cmString tmp;
	cmString caption;
	cmString containerCaption;
	cmString iconExpandedSelected;
	cmString iconExpandedNotSelected;
	cmString iconCollapsedSelected;
	cmString iconCollapsedNotSelected;
	cmString iconName;
	cmString newItemName;
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	CXmlClassInfo* tmpClassInfo;

	count++;

	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		name = inheritClassInfo->GetName();
		caption = inheritClassInfo->GetCaption();
		containerCaption = inheritClassInfo->GetContainerCaption();
		p = GetCardinalityPostfix(inheritClassInfo);
		c = inheritClassInfo->GetCardinalityInfo()->GetCardinality();
		r = inheritClassInfo->GetRenderingMode();

		tmpClassInfo = inheritClassInfo ;
		
	} else {
		name = classInfo->GetName();
		p = GetCardinalityPostfix(classInfo);
		caption = classInfo->GetCaption();
		containerCaption = classInfo->GetContainerCaption();
		c = classInfo->GetCardinalityInfo()->GetCardinality();
		r = classInfo->GetRenderingMode();
	
		tmpClassInfo = classInfo;
	}

	if (parentPath.GetLength())
		tmp = parentPath + _T("_");
	else
		tmp = _T("");

	// BuildNode method is generated by the inherit class if the current class
	// uses "definition inheritance"
	//
	if (r == enRenderingMode_Grid) {
		// array BuildNode
		//
		iconExpandedSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconExpandedSelected();
		iconExpandedNotSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconExpandedNotSelected();
		iconCollapsedSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconCollapsedSelected();
		iconCollapsedNotSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconCollapsedNotSelected();
		
		iconExpandedSelected = iconExpandedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedSelected) : _T("IDI_EMPTY");
		iconExpandedNotSelected = iconExpandedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedNotSelected) : _T("IDI_EMPTY");
		iconCollapsedSelected = iconCollapsedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedSelected) : _T("IDI_EMPTY");
		iconCollapsedNotSelected = iconCollapsedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedNotSelected) : _T("IDI_EMPTY");

		iconExpandedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedSelected + _T("))");
		iconExpandedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedNotSelected + _T("))");
		iconCollapsedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedSelected + _T("))");
		iconCollapsedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedNotSelected + _T("))");

		implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::BuildNode_") + tmp + name + _T("(HTREEITEM parentItem)") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("HTREEITEM newItem;") + xCrLf;
		implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("// insert node for class ") + GetClassName(name) + p + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		implCode_ += xTab + _T("newItem = tree_.InsertItem(_T(\"") + containerCaption + _T("\"), parentItem);") + xCrLf; 
		implCode_ += xTab + _T("newNodeInfo.SetTreeItem(newItem);") + xCrLf;
		implCode_ += xTab + _T("newNodeInfo.SetClassId(") + GetDialogId(classInfo, count) + _T(");") + xCrLf;
		implCode_ += xTab + _T("newNodeInfo.SetIconExpandedSelected(") + iconExpandedSelected + _T(");") + xCrLf; 
		implCode_ += xTab + _T("newNodeInfo.SetIconExpandedNotSelected(") + iconExpandedNotSelected + _T(");") + xCrLf; 
		implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedSelected(") + iconCollapsedSelected + _T(");") + xCrLf; 
		implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedNotSelected(") + iconCollapsedNotSelected + _T(");") + xCrLf; 
		implCode_ += xTab + _T("node2InfoMap_[newItem] = newNodeInfo;") + xCrLf;
		implCode_ += xTab + _T("tree_.SetItemImage(newItem, newNodeInfo.GetIconCollapsedNotSelected(), newNodeInfo.GetIconCollapsedSelected());") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("return newItem;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
		
		return;
	}
	
	// single instance BuildNode
	//
	iconExpandedSelected = tmpClassInfo->GetTreeIcons()->GetIconExpandedSelected();
	iconExpandedNotSelected = tmpClassInfo->GetTreeIcons()->GetIconExpandedNotSelected();
	iconCollapsedSelected = tmpClassInfo->GetTreeIcons()->GetIconCollapsedSelected();
	iconCollapsedNotSelected = tmpClassInfo->GetTreeIcons()->GetIconCollapsedNotSelected();
	
	iconExpandedSelected = iconExpandedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedSelected) : _T("IDI_EMPTY");
	iconExpandedNotSelected = iconExpandedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedNotSelected) : _T("IDI_EMPTY");
	iconCollapsedSelected = iconCollapsedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedSelected) : _T("IDI_EMPTY");
	iconCollapsedNotSelected = iconCollapsedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedNotSelected) : _T("IDI_EMPTY");

	iconExpandedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedSelected +_T("))");
	iconExpandedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedNotSelected + _T("))");
	iconCollapsedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedSelected + _T("))");
	iconCollapsedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedNotSelected + _T("))");

	if (c == enCardinality_Array) {
		implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::BuildNode_") + tmp + name + _T("(") + GetClassName(name) + _T("& ") + GetCamelCase(name) + _T(", HTREEITEM parentItem, int itemIndex)") + xCrLf;
	} else {
		implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::BuildNode_") + tmp + name + _T("(") + GetClassName(name) + _T("& ") + GetCamelCase(name) + _T(", HTREEITEM parentItem)") + xCrLf;
	}
	implCode_ += _T("{") + xCrLf;
	if (r != enRenderingMode_None) {
		// newItem is needed if this node is not hidden
		//
		if (NodeIsVisible(tmpClassInfo)) {
			implCode_ += xTab + _T("HTREEITEM newItem;") + xCrLf;
			implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;

			implCode_ += xCrLf;
			implCode_ += xTab + _T("// insert node for class ") + GetClassName(name) + p + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			switch(c) {
				case enCardinality_Map:
					implCode_ += xTab + _T("newItem = tree_.InsertItem(") + GetCamelCase(name) + _T(".Get") + classInfo->GetCardinalityInfo()->GetMapSortKey() + _T("(), parentItem);") + xCrLf; 
					break;
				
				case enCardinality_Array:
					implCode_ += xTab + _T("cmString buf;") + xCrLf;
					implCode_ += xTab + _T("cmString caption;") + xCrLf;
					implCode_ += xTab + _T("HTREEITEM tmp;") + xCrLf;
					implCode_ += xCrLf;
					implCode_ += xTab + _T("if (itemIndex == 0) {") + xCrLf;
					implCode_ += xTab + xTab + _T("tmp = TVI_FIRST;") + xCrLf;
					implCode_ += xTab + _T("} else {") + xCrLf;
					implCode_ += xTab + xTab + _T("tmp = tree_.GetChildItem(parentItem);") + xCrLf;
					implCode_ += xTab + xTab + _T("for (int i = 1; i < itemIndex; i++)") + xCrLf;
					implCode_ += xTab + xTab + xTab + _T("tmp = tree_.GetNextItem(tmp, TVGN_NEXT);") + xCrLf;
					implCode_ += xTab + _T("}") + xCrLf;
					implCode_ += xTab + _T("buf.Format(_T(\" %d\"), itemIndex + 1);") + xCrLf;
					implCode_ += xTab + _T("caption = _T(\"") + caption + _T("\");") + xCrLf;
					implCode_ += xTab + _T("caption += buf;") + xCrLf;
					implCode_ += xTab + _T("newItem = tree_.InsertItem(caption, parentItem, tmp);") + xCrLf; 
					break;

				default:
					implCode_ += xTab + _T("newItem = tree_.InsertItem(_T(\"") + caption + _T("\"), parentItem);") + xCrLf; 
			}
			
			implCode_ += xTab + _T("newNodeInfo.SetTreeItem(newItem);") + xCrLf;
			implCode_ += xTab + _T("newNodeInfo.SetClassId(") + GetDialogId(classInfo, count) + _T(");") + xCrLf;
			implCode_ += xTab + _T("newNodeInfo.SetIconExpandedSelected(") + iconExpandedSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconExpandedNotSelected(") + iconExpandedNotSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedSelected(") + iconCollapsedSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedNotSelected(") + iconCollapsedNotSelected + _T(");") + xCrLf; 
			
			if (c == enCardinality_Array) {
				implCode_ += xTab + _T("newNodeInfo.SetArrayIndex(itemIndex);") + xCrLf;
			} else if (c== enCardinality_Map) {
				implCode_ += xTab + _T("newNodeInfo.SetMapKey(") + GetCamelCase(name) + _T(".Get") + classInfo->GetCardinalityInfo()->GetMapSortKey() + _T("());") + xCrLf;
			}

			implCode_ += xTab + _T("node2InfoMap_[newItem] = newNodeInfo;") + xCrLf;
			implCode_ += xTab + _T("tree_.SetItemImage(newItem, newNodeInfo.GetIconCollapsedNotSelected(), newNodeInfo.GetIconCollapsedSelected());") + xCrLf;
			implCode_ += xCrLf;

			newItemName = _T("newItem");
		} else {
			newItemName = _T("TVI_ROOT");
		}
		
		// generate calls for BuildNode of each class member child
		//
		members = classInfo->GetMembers();
		for (it = members->begin(); it != members->end(); it++) {
			member = it->second;
			
			if (member->GetDataType() == enDataType_Class) {
				CXmlClassInfo* tmpClassInfo;
				cmString tmpName;
				cmString p1;

				tmpClassInfo = dynamic_cast<CXmlClassInfo*>(member);
				if (tmpClassInfo->GetDefinitionInheritance())
					tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(tmpClassInfo->GetInherithClassId()));
				
				r = tmpClassInfo->GetRenderingMode();

				p1 = GetCardinalityPostfix(tmpClassInfo);

				if (parentPath.GetLength())
					tmp = parentPath + _T("_") + name + _T("_") + tmpClassInfo->GetName();
				else
					tmp = name + _T("_") + tmpClassInfo->GetName();

				if (r == enRenderingMode_Grid) {
					implCode_ += xTab + _T("BuildNode_") + tmp + _T("(") + newItemName +_T(");") + xCrLf;
				} else {
					implCode_ += xTab + _T("BuildNode_") + tmp + p1 + _T("(") + GetCamelCase(classInfo->GetName())  + _T(".Get") + tmpClassInfo->GetName() + p1 + _T("(), ") + newItemName + _T(");") + xCrLf;
				}
			}
		}
		
		if (NodeIsVisible(tmpClassInfo) && classInfo->GetTreeIcons()->GetExpandedAtStartup()) {
			implCode_ += xCrLf;
			implCode_ += xTab + _T("tree_.Expand(newItem, TVE_EXPAND);") + xCrLf;
		}

	} else {
		implCode_ += xTab + _T("HTREEITEM newItem = NULL;") + xCrLf;
		newItemName = _T("newItem");

	}	// close if rendering_None	

	implCode_ += xCrLf;
	implCode_ += xTab + _T("return ") + newItemName + _T(";") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
	
	if (parentPath.GetLength())
		tmp = parentPath + _T("_") + name;
	else
		tmp = name;
	
	r = tmpClassInfo->GetRenderingMode();

	if (c == enCardinality_Array) {
		// array BuildNode
		//
		iconExpandedSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconExpandedSelected();
		iconExpandedNotSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconExpandedNotSelected();
		iconCollapsedSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconCollapsedSelected();
		iconCollapsedNotSelected = tmpClassInfo->GetArrayTreeIcons()->GetIconCollapsedNotSelected();
		
		iconExpandedSelected = iconExpandedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedSelected) : _T("IDI_EMPTY");
		iconExpandedNotSelected = iconExpandedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedNotSelected) : _T("IDI_EMPTY");
		iconCollapsedSelected = iconCollapsedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedSelected) : _T("IDI_EMPTY");
		iconCollapsedNotSelected = iconCollapsedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedNotSelected) : _T("IDI_EMPTY");

		iconExpandedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedSelected + _T("))");
		iconExpandedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedNotSelected + _T("))");
		iconCollapsedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedSelected + _T("))");
		iconCollapsedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedNotSelected + _T("))");

		implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::BuildNode_") + tmp + p + _T("(") + GetClassName(name) + p + _T("& ") + GetCamelCase(name) + p + _T(", HTREEITEM parentItem)") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		if (r != enRenderingMode_None) {
			implCode_ += xTab + _T("HTREEITEM arrayItem;") + xCrLf;
			implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("// insert array node") + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			implCode_ += xTab + _T("arrayItem = tree_.InsertItem(_T(\"") + containerCaption + _T("\"), parentItem);") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetTreeItem(arrayItem);") + xCrLf;
			implCode_ += xTab + _T("newNodeInfo.SetClassId(") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(p) + _T(");") + xCrLf;
			implCode_ += xTab + _T("newNodeInfo.SetIconExpandedSelected(") + iconExpandedSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconExpandedNotSelected(") + iconExpandedNotSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedSelected(") + iconCollapsedSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedNotSelected(") + iconCollapsedNotSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("node2InfoMap_[arrayItem] = newNodeInfo;") + xCrLf;
			implCode_ += xTab + _T("tree_.SetItemImage(arrayItem, newNodeInfo.GetIconCollapsedNotSelected(), newNodeInfo.GetIconCollapsedSelected());") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("// insert node for class + ") + GetClassName(name) + p + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			implCode_ += xTab + _T("for (int i = 0; i < ") + GetCamelCase(name) + p + _T(".GetSize(); i++) {") + xCrLf;
			implCode_ += xTab + xTab + _T("cmString caption;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + xTab + _T("caption.Format(_T(\"") + caption + _T(" %d\"), i);") + xCrLf; 
			
			if (parentPath.GetLength())
				tmp = parentPath + _T("_") + name;
			else
				tmp = name;
			implCode_ += xTab + xTab + _T("BuildNode_") + tmp + _T("(") + GetCamelCase(name) + p + _T("[i], arrayItem, i);") + xCrLf;
			
			implCode_ += xTab + _T("}") + xCrLf;
		}
		if (classInfo->GetArrayTreeIcons()->GetExpandedAtStartup()) {
			implCode_ += xCrLf;
			implCode_ += xTab + _T("tree_.Expand(arrayItem, TVE_EXPAND);") + xCrLf;
		}
		implCode_ += xCrLf;
		implCode_ += xTab + _T("return arrayItem;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
	} else if (c == enCardinality_Map) {
		// map BuildNode
		//
		iconExpandedSelected = tmpClassInfo->GetMapTreeIcons()->GetIconExpandedSelected();
		iconExpandedNotSelected = tmpClassInfo->GetMapTreeIcons()->GetIconExpandedNotSelected();
		iconCollapsedSelected = tmpClassInfo->GetMapTreeIcons()->GetIconCollapsedSelected();
		iconCollapsedNotSelected = tmpClassInfo->GetMapTreeIcons()->GetIconCollapsedNotSelected();
		
		iconExpandedSelected = iconExpandedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedSelected) : _T("IDI_EMPTY");
		iconExpandedNotSelected = iconExpandedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedNotSelected) : _T("IDI_EMPTY");
		iconCollapsedSelected = iconCollapsedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedSelected) : _T("IDI_EMPTY");
		iconCollapsedNotSelected = iconCollapsedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedNotSelected) : _T("IDI_EMPTY");

		iconExpandedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedSelected + _T("))");
		iconExpandedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedNotSelected + _T("))");
		iconCollapsedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedSelected + _T("))");
		iconCollapsedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedNotSelected + _T("))");
		implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::BuildNode_") + tmp + p + _T("(") + GetClassName(name) + p + _T("& ") + GetCamelCase(name) + p + _T(", HTREEITEM parentItem)") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("HTREEITEM newItem = NULL;") + xCrLf;
		implCode_ += xCrLf;
		if(r != enRenderingMode_None) {
			implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("// insert node for class + ") + GetClassName(name) + p + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			//member = classInfo->GetMember(classInfo->GetCardinalityInfo()->GetMapSortKey());
			member = tmpClassInfo->GetMember(tmpClassInfo->GetCardinalityInfo()->GetMapSortKey()); // 2004.11.18
			implCode_ += xTab + TypeOf(member->GetDataType()) + _T(" key;") + xCrLf;
			implCode_ += xTab + GetClassName(classInfo->GetName()) + _T("* value;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("// insert map node") + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			implCode_ += xTab + _T("newItem = tree_.InsertItem(_T(\"") + containerCaption + _T("\"), parentItem);") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetTreeItem(newItem);") + xCrLf;
			implCode_ += xTab + _T("newNodeInfo.SetClassId(") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(GetCardinalityPostfix(classInfo)) + _T(");") + xCrLf;
			implCode_ += xTab + _T("newNodeInfo.SetIconExpandedSelected(") + iconExpandedSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconExpandedNotSelected(") + iconExpandedNotSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedSelected(") + iconCollapsedSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("newNodeInfo.SetIconCollapsedNotSelected(") + iconCollapsedNotSelected + _T(");") + xCrLf; 
			implCode_ += xTab + _T("node2InfoMap_[newItem] = newNodeInfo;")+ xCrLf;
			implCode_ += xTab + _T("tree_.SetItemImage(newItem ,newNodeInfo.GetIconCollapsedNotSelected(), newNodeInfo.GetIconCollapsedSelected());") + xCrLf;
			implCode_ += xTab + GetCamelCase(classInfo->GetName()) + GetCardinalityPostfix(classInfo) + _T(".MoveFirst();") + xCrLf;
			implCode_ += xTab + _T("while (") + GetCamelCase(classInfo->GetName()) + GetCardinalityPostfix(classInfo) + _T(".GetPair(key, &value)) {") + xCrLf;
			if (parentPath.GetLength())
				tmp = parentPath + _T("_") + name;
			else
				tmp = name;

			implCode_ += xTab + xTab + _T("BuildNode_") + tmp + _T("(*value, newItem);") + xCrLf;
			
			implCode_ += xTab + xTab + GetCamelCase(name) + GetCardinalityPostfix(classInfo) + _T(".MoveNext();") + xCrLf;
			implCode_ += xTab + _T("}") + xCrLf;

			if (classInfo->GetArrayTreeIcons()->GetExpandedAtStartup()) {
				implCode_ += xCrLf;
				implCode_ += xTab + _T("tree_.Expand(newItem, TVE_EXPAND);") + xCrLf;
			}
		}		

		implCode_ += xCrLf;
		implCode_ += xTab + _T("return newItem;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
	}

	if (parentPath.GetLength())
		tmp = parentPath + _T("_") + name;
	else
		tmp = name;

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;

		if (member->GetDataType() == enDataType_Class)
			Impl_generateBuildNode(dynamic_cast<CXmlClassInfo*>(member), count, tmp);
	}
}

void CCppMainDialogGenerator::Impl_generateGetItem(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack)
{
	enCardinality c;
	enRenderingMode r;
	cmString p;
	cmString name;
	cmString tmp;
	cmString caption;
	cmString containerCaption;
	cmString className;
	cmString parentPath;
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	CXmlClassInfo* tmpClassInfo;

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;
	
	name = tmpClassInfo->GetName();
	className = GetClassName(name);

	caption = tmpClassInfo->GetCaption();
	containerCaption = tmpClassInfo->GetContainerCaption();
	p = GetCardinalityPostfix(tmpClassInfo);
	c = tmpClassInfo->GetCardinalityInfo()->GetCardinality();
	r = tmpClassInfo->GetRenderingMode();

	parentPath = GetParentPath(NULL, parentStack);
	
	//if (r == enRenderingMode_None)
	//	return;
		
	if (classInfo == classInfo_) {
		
		// GetItem for root class
		//
		implCode_ += className + _T("* ") + GetMainDlgName() + _T("::GetItem") + parentPath + _T("_") + name + _T("(HTREEITEM treeItem)") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("return &") + GetCamelCase(name) + _T("_;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;

	} else if (r != enRenderingMode_Grid) {
		
		// GetItem for single items
		//
		if (c != enCardinality_SingleInstance)
			implCode_ += className + _T("* ") + GetMainDlgName() + _T("::GetItem") + parentPath + _T("_") + name + p + _T("_") + name + _T("(HTREEITEM treeItem)") + xCrLf;
		else
			implCode_ += className + _T("* ") + GetMainDlgName() + _T("::GetItem") + parentPath + _T("_") + name + _T("(HTREEITEM treeItem)") + xCrLf;

		implCode_ += _T("{") + xCrLf;
		
		cmString parentItemClassName;
		cmString itemClassName;

		switch(c) {
			case enCardinality_Map:
				parentItemClassName = className + p;
				break;
			
			case enCardinality_Array:
				parentItemClassName = className + p;
				break;

			default:
				parentItemClassName = GetClassName((*parentStack.rbegin())->GetName());
		}

		implCode_ += xTab + parentItemClassName+ _T("* parentItem;") + xCrLf;
		implCode_ += xTab + className + _T("* ret;") +  xCrLf;

		implCode_ += xCrLf;
		switch(c) {
			case enCardinality_Map:
				implCode_ += xTab + _T("parentItem = GetItem") + parentPath + _T("_") + name + p + _T("(tree_.GetParentItem(treeItem));") + xCrLf;
				implCode_ += xTab + _T("ret = &(*parentItem)[GetNodeInfo(treeItem)->GetMapKey()];") + xCrLf;
				break;
			
			case enCardinality_Array:
				implCode_ += xTab + _T("parentItem = GetItem") + parentPath + _T("_") + name + p + _T("(tree_.GetParentItem(treeItem));") + xCrLf;
				implCode_ += xTab + _T("ret = &(*parentItem)[GetNodeInfo(treeItem)->GetArrayIndex()];") + xCrLf;
				break;

			default:
				implCode_ += xTab + _T("parentItem = GetItem") + parentPath + _T("(tree_.GetParentItem(treeItem));") + xCrLf;
				implCode_ += xTab + _T("ret = &parentItem->Get") + name + _T("();") + xCrLf;
		}
		
		implCode_ += xCrLf;
		implCode_ += xTab + _T("return ret;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;


		// GetItem for container items
		//
		if (c != enCardinality_SingleInstance) {
			implCode_ += className + p + _T("* ") + GetMainDlgName() + _T("::GetItem") + parentPath + _T("_") + name + p + _T("(HTREEITEM treeItem)") + xCrLf;
			implCode_ += _T("{") + xCrLf;
			
			parentItemClassName = GetClassName((*parentStack.rbegin())->GetName());

			implCode_ += xTab + parentItemClassName+ _T("* parentItem;") + xCrLf;
			implCode_ += xTab + className + p + _T("* ret;") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("parentItem = GetItem") + parentPath + _T("(tree_.GetParentItem(treeItem));") + xCrLf;
			implCode_ += xTab + _T("ret = &parentItem->Get") + name + p + _T("();") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("return ret;") + xCrLf;
			implCode_ += _T("}") + xCrLf;
			implCode_ += xCrLf;
		}
	} else if (r == enRenderingMode_Grid) {
		cmString parentItemClassName;

		// GetItem for single items
		//
		implCode_ += className + p + _T("* ") + GetMainDlgName() + _T("::GetItem") + parentPath + _T("_") + name + p + _T("(HTREEITEM treeItem)") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		
		parentItemClassName = GetClassName((*parentStack.rbegin())->GetName());
		
		implCode_ += xTab + parentItemClassName + _T("* parentItem;") + xCrLf;
		implCode_ += xTab + className + p + _T("* ret;") +  xCrLf;

		implCode_ += xCrLf;
		implCode_ += xTab + _T("parentItem = GetItem") + parentPath + _T("(tree_.GetParentItem(treeItem));") + xCrLf;
		implCode_ += xTab + _T("ret = &parentItem->Get") + name + p + _T("();") + xCrLf;
				
		implCode_ += xCrLf;
		implCode_ += xTab + _T("return ret;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
	}
		
	r = tmpClassInfo->GetRenderingMode();

	parentStack.push_back(tmpClassInfo);
	members = tmpClassInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;

		if (member->GetDataType() == enDataType_Class)
			Impl_generateGetItem(dynamic_cast<CXmlClassInfo*>(member), parentStack);
	}
}

void CCppMainDialogGenerator::Impl_generateGetNodeInfo()
{
	implCode_ += cppSettings_->GetClassPrefix() + _T("TreeNodeInfo* ") + GetMainDlgName() + _T("::GetNodeInfo(HTREEITEM treeNode)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("return &(node2InfoMap_.find(treeNode)->second);") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

cmString CCppMainDialogGenerator::Impl_generateVarPath(CXmlClassInfo* classInfo, vector<CXmlClassInfo*>& parentStack, bool containerVarOnly)
{
	cmString varPath;
	CXmlClassInfo* info;

	if (classInfo->GetDefinitionInheritance())
		info = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		info = classInfo;

	if (parentStack.size() == 0) {
		// root node has parentStack empty
		//
		varPath = GetCamelCase(info->GetName()) + GetCardinalityPostfix(info) + _T("_");
		return varPath;		
	} 

	cmString p;
	vector<CXmlClassInfo*>::reverse_iterator it;
	CXmlClassInfo* parentClass;
	enCardinality cardinality;
	cmString buf;

	p = GetCardinalityPostfix(info);
	cardinality = info->GetCardinalityInfo()->GetCardinality();
	buf = _T("selNode");
	switch(cardinality) {
		case enCardinality_SingleInstance:
			varPath = _T("Get") + info->GetName() + _T("()") + varPath;
			break;

		case enCardinality_Array:
			if (info->GetRenderingMode() == enRenderingMode_Grid) {
				varPath = _T("Get") + info->GetName() + p + _T("()");
			} else {
				//varPath += "Get" + classInfo->GetName() + p + "()[nodeInfo.GetArrayIndex()]";
				varPath = _T("Get") + info->GetName() + p + _T("()");
				
				if (!containerVarOnly) {
					varPath += _T("[GetNodeInfo(tree_.GetParentItem(selNode))->GetArrayIndex()]");
					//varPath += "[GetNodeInfo(selNode)->GetArrayIndex()]";
				}
			}
			break;

		case enCardinality_Map:
			//varPath += "Get" + classInfo->GetName() + p + "()[nodeInfo.GetMapKey()]";
			varPath = _T("Get") + info->GetName() + p + _T("()");
				
			if (!containerVarOnly)
				varPath += _T("[GetNodeInfo(selNode)->GetMapKey()]");

			break;
	}

	for (int i = parentStack.size() - 1; i > 0; i--) {
		parentClass = parentStack[i];
		p = GetCardinalityPostfix(parentClass);
		
		cardinality = parentClass->GetCardinalityInfo()->GetCardinality();
		buf = _T("tree_.GetParentItem(") + buf + _T(")");
		switch(cardinality) {
			case enCardinality_SingleInstance:
				varPath = _T("Get") + parentClass->GetName() + _T("().") + varPath;
				break;

			case enCardinality_Array:
				if (parentClass->GetRenderingMode() == enRenderingMode_Grid) {
					varPath = _T("Get") + parentClass->GetName() + p + _T("().") + varPath;
				} else {
					//varPath += "Get" + classInfo->GetName() + p + "()[nodeInfo.GetArrayIndex()]";
					varPath = _T("Get") + parentClass->GetName() + p + _T("()[GetNodeInfo(") + buf + _T(")->GetArrayIndex()].") + varPath;
				}
				break;

			case enCardinality_Map:
				//varPath += "Get" + classInfo->GetName() + p + "()[nodeInfo.GetMapKey()]";
				varPath = _T("Get") + parentClass->GetName() + p + _T("()[GetNodeInfo(") + buf + _T(")->GetMapKey()].") +  varPath;
				break;
		}
	}	

	parentClass = parentStack[0];
	varPath = GetCamelCase(parentClass->GetName()) + GetCardinalityPostfix(parentClass) + _T("_.") + varPath;

	return varPath;
}

void CCppMainDialogGenerator::Impl_generateOnSize()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnSize(UINT nType, int cx, int cy)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("cmSplitDialog::OnSize(nType, cx, cy);") + xCrLf;
	implCode_ += xCrLf;
	//implCode_ += xTab + "UpdateWindowSize();" + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

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

void CCppMainDialogGenerator::Impl_generateUpdateWindowSize()
{
	/*implCode_ += "void " + GetMainDlgName() + "::UpdateWindowSize()" + xCrLf;
	implCode_ += "{" + xCrLf;
	implCode_ += xTab + "if (!GetSafeHwnd())" + xCrLf;
	implCode_ += xTab + xTab + "return;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "CRect rc;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "GetClientRect(rc);" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "if (cmdOk_.GetSafeHwnd()) {" + xCrLf;
	implCode_ += xTab + xTab + "cmdOk_.SetWindowPos(&CWnd::wndTop, rc.right - 160, rc.bottom - 28, 75, 23, SWP_SHOWWINDOW);" + xCrLf;
    implCode_ += xTab + xTab + "cmdOk_.RedrawWindow();" + xCrLf;
	implCode_ += xTab + "}" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "if (cmdCancel_.GetSafeHwnd()) {" + xCrLf;
	implCode_ += xTab + xTab + "cmdCancel_.SetWindowPos(&CWnd::wndTop, rc.right - 80, rc.bottom - 28, 75, 23, SWP_SHOWWINDOW);" + xCrLf;
	implCode_ += xTab + xTab + "cmdCancel_.RedrawWindow();" + xCrLf;
	implCode_ += xTab + "}" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "rc.DeflateRect(0, 0, 0, 35);" + xCrLf;
	implCode_ += xCrLf;
		
	implCode_ += "}" + xCrLf;
	implCode_ += xCrLf;*/
}

void CCppMainDialogGenerator::Head_generateDisplayPopupMenu()
{
	//headCode_ += xTab + "void DisplayPopupMenu(HTREEITEM treeItem);" +  xCrLf;
}

void CCppMainDialogGenerator::Impl_generateDisplayPopupMenu()
{
	/*implCode_ += "void " + GetMainDlgName() + "::DisplayPopupMenu(HTREEITEM treeItem)" +  xCrLf;
	implCode_ += "{" + xCrLf;
	implCode_ += xTab + "CRect rc;" + xCrLf;
	implCode_ += xTab + "CPoint tmpPoint;" + xCrLf;
	implCode_ += xTab + "CMenu mnu;" + xCrLf;
	implCode_ += xTab + "CMenu* subMenu;" + xCrLf;
	implCode_ += xTab + "map<HTREEITEM, " + cppSettings_->GetClassPrefix() + "TreeNodeInfo>::iterator it;" + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + "TreeNodeInfo nodeInfo;" + xCrLf;
	//implCode_ += xTab + cppSettings_->GetClassPrefix() + "TreeNodeInfo parentNodeInfo;"  + xCrLf;
	//implCode_ += xTab + "HTREEITEM parentNode;" + xCrLf;
	//implCode_ += xTab + "HTREEITEM selNode;" + xCrLf;
	implCode_ += xTab + "int menuId = 0;" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + "// get menu top-left point" + xCrLf;
	implCode_ += xTab + "//" + xCrLf;
	implCode_ += xTab + "if (tree_.GetItemRect(treeItem, rc, TRUE)) {" + xCrLf;
	implCode_ += xTab + xTab + "tmpPoint.x = rc.right;" + xCrLf;
	implCode_ += xTab + xTab + "tmpPoint.y = rc.top;" + xCrLf;
	implCode_ += xTab + xTab + "ClientToScreen(&tmpPoint);" + xCrLf;
		
	implCode_ += xCrLf;
			
	// get parent node info
	//
	//implCode_ += xTab + xTab + "// get parent node info" + xCrLf;
	//implCode_ += xTab + xTab + "//" + xCrLf;
	//implCode_ += xTab + xTab + "it = node2InfoMap_.find(parentNode);" + xCrLf;
    //implCode_ += xTab + xTab + "if(it != node2InfoMap_.end())" + xCrLf;
    //implCode_ += xTab + xTab + xTab + "parentNodeInfo = it->second;" + xCrLf;
	//implCode_ += xCrLf; 

	// generate new dialog show data
	//
	int count = 0;

	implCode_ += xTab + xTab + "it = node2InfoMap_.find(treeItem);" + xCrLf;
	implCode_ += xTab + xTab + "if(it != node2InfoMap_.end()) {" + xCrLf;
	implCode_ += xTab + xTab + xTab + "nodeInfo = it->second;" + xCrLf;
	implCode_ += xTab + xTab + xTab + "switch(nodeInfo.GetClassId()) {" + xCrLf;
	Impl_generatePopupMenuDataSwitch(classInfo_, count);
	implCode_ += xTab + xTab + xTab + "}" + xCrLf;
	implCode_ += xTab + xTab + "}" + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + xTab + "if (menuId) {" + xCrLf;
	implCode_ += xTab + xTab + xTab + "mnu.LoadMenu(menuId);" + xCrLf;
	implCode_ += xTab + xTab + xTab + "subMenu = mnu.GetSubMenu(0);" + xCrLf;
	implCode_ += xTab + xTab + xTab + "subMenu->TrackPopupMenu(0, tmpPoint.x, tmpPoint.y, this, NULL);" + xCrLf;
	implCode_ += xTab + xTab + "}" + xCrLf;
	implCode_ += xTab + "}" + xCrLf;
	implCode_ += "}" + xCrLf;*/
}

void CCppMainDialogGenerator::Impl_generatePopupMenuDataSwitch(CXmlClassInfo* classInfo, int& count)
{
	cmString p;
	enCardinality cardinality;
	cmString varPath;
	cmString dlgName;
	enRenderingMode renderingMode;

	count++;

	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		dlgName = GetDlgName(inheritClassInfo);
		cardinality = inheritClassInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(inheritClassInfo);
		renderingMode = inheritClassInfo->GetRenderingMode();
	} else {
		dlgName = GetDlgName(classInfo);
		cardinality = classInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(classInfo);
		dlgName = GetDlgName(classInfo);
		renderingMode = classInfo->GetRenderingMode();
	}

	// container node for array
	//
	if (cardinality == enCardinality_Array && renderingMode != enRenderingMode_Grid) {
		
		implCode_ += xTab + xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(p) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("menuId = IDR_MNU_EDIT_ARRAY;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;

		implCode_ += xTab + xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("menuId = IDR_MNU_EDIT_ARRAY_ITEM;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;

	} else if (cardinality == enCardinality_Map) {
		
		implCode_ += xTab + xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(p) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("menuId = IDR_MNU_EDIT_MAP;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;

		implCode_ += xTab + xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("menuId = IDR_MNU_EDIT_MAP_ITEM;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;
	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generatePopupMenuDataSwitch(dynamic_cast<CXmlClassInfo*>(member), count);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_Array()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuAppendItem_Array()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_OnMnuInsertItem_ArrayItem()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuInsertItem_ArrayItem()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_OnMnuAppendItem_ArrayItem()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuAppendItem_ArrayItem()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_OnMnuRemoveItem_ArrayItem() 
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuRemoveItem_ArrayItem()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_OnMnuCreateItem_Map()
{
	vector<CXmlClassInfo*> parentStack;
	int count = 0;

	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuCreateItem_Map()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo>::iterator it;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo nodeInfo;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM selNode;") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab + _T("selNode = tree_.GetSelectedItem();") + xCrLf;
	implCode_ += xTab + _T("it = node2InfoMap_.find(selNode);") + xCrLf;
	implCode_ += xTab + _T("if(it != node2InfoMap_.end()) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nodeInfo = it->second;") + xCrLf;
	implCode_ += xTab + xTab + _T("switch(nodeInfo.GetClassId()) {") + xCrLf;
	Impl_generateMapCreateItem(classInfo_, parentStack, count, _T(""));
	implCode_ += xTab +  xTab + _T("}") + xCrLf;
	implCode_ += xTab +  _T("}") + xCrLf;
	implCode_ += xCrLf;

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

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_OnMnuRemoveItem_MapItem()
{
		vector<CXmlClassInfo*> parentStack;
	int count = 0;

	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuRemoveItem_MapItem()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo>::iterator it;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo nodeInfo;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM selNode;") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab + _T("selNode = tree_.GetSelectedItem();") + xCrLf;
	implCode_ += xTab + _T("it = node2InfoMap_.find(selNode);") + xCrLf;
	implCode_ += xTab + _T("if(it != node2InfoMap_.end()) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nodeInfo = it->second;") + xCrLf;
	implCode_ += xTab + xTab + _T("switch(nodeInfo.GetClassId()) {") + xCrLf;
	Impl_generateMapItemRemoveItem(classInfo_, parentStack, count, _T(""));
	implCode_ += xTab +  xTab + _T("}") + xCrLf;
	implCode_ += xTab +  _T("}") + xCrLf;
	implCode_ += xCrLf;

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

void CCppMainDialogGenerator::Impl_generateOnMnuAppendItem_OnMnuCreateItem_MapItem()
{
	vector<CXmlClassInfo*> parentStack;
	int count = 0;

	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnMnuCreateItem_MapItem()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo>::iterator it;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo nodeInfo;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM selNode;") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += xTab + _T("selNode = tree_.GetSelectedItem();") + xCrLf;
	implCode_ += xTab + _T("it = node2InfoMap_.find(selNode);") + xCrLf;
	implCode_ += xTab + _T("if(it != node2InfoMap_.end()) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nodeInfo = it->second;") + xCrLf;
	implCode_ += xTab + xTab + _T("switch(nodeInfo.GetClassId()) {") + xCrLf;
	Impl_generateMapItemCreateItem(classInfo_, parentStack, count, _T(""));
	implCode_ += xTab +  xTab + _T("}") + xCrLf;
	implCode_ += xTab +  _T("}") + xCrLf;
	implCode_ += xCrLf;

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

void CCppMainDialogGenerator::Impl_generateMapCreateItem(CXmlClassInfo* classInfo, 
															   vector<CXmlClassInfo*> parentStack,
															   int& count,
															   cmString parentPath)
{
	cmString p;
	enCardinality cardinality;
	cmString varPath;
	cmString className;
	cmString name;
	enRenderingMode renderingMode;
	CXmlMemberInfo* keyMember;
	TCHAR buf[100];

	count++;

	varPath = Impl_generateVarPath(classInfo, parentStack, true);

	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		className = GetClassName(inheritClassInfo->GetName());
		name = inheritClassInfo->GetName();
		cardinality = inheritClassInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(inheritClassInfo);
		renderingMode = inheritClassInfo->GetRenderingMode();
		keyMember = dynamic_cast<CXmlMemberInfo*>(inheritClassInfo->GetMember(inheritClassInfo->GetCardinalityInfo()->GetMapSortKey()));
		
	} else {
		className = GetClassName(classInfo->GetName());
		name = classInfo->GetName();
		cardinality = classInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(classInfo);
		renderingMode = classInfo->GetRenderingMode();
		keyMember = dynamic_cast<CXmlMemberInfo*>(classInfo->GetMember(classInfo->GetCardinalityInfo()->GetMapSortKey()));
	}

	// class dialog switch
	//
	if (cardinality == enCardinality_Map) {
		
		implCode_ += xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T("_") + ToUpperCase(p) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("{") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + className + _T("* newItem;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("CInputBox inputBox;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("BOOL ret;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("bool itemFound;") + xCrLf;
		implCode_ += xCrLf;
		if (keyMember->GetDataType() == enDataType_String)
			implCode_ += xTab + xTab + xTab + xTab + _T("inputBox.Init(_T(\"Create new item\"), _T(\"Please enter '") + keyMember->GetCaption() + _T("'\"), _T(\"\"));") + xCrLf;
		else
			implCode_ += xTab + xTab + xTab + xTab + _T("inputBox.Init(_T(\"Create new item\"), _T(\"Please enter '") + keyMember->GetCaption() + _T("'\"), 0, ") + cmString(_itow(keyMember->GetDecimalPlaces(), buf, 10)) + _T(");") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("ret = inputBox.DoModal();") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("if (!ret)") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xCrLf;
		if (keyMember->GetDataType() == enDataType_String)
			implCode_ += xTab + xTab + xTab + xTab + _T("itemFound = ") + varPath + _T(".Find(inputBox.GetValueString(), &newItem);") + xCrLf;
		else
			implCode_ += xTab + xTab + xTab + xTab + _T("itemFound = ") + varPath + _T(".Find(inputBox.GetValueDouble(), &newItem);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("if (itemFound) {") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("MessageBox(_T(\"Item already exists\"), _T(\"InsertItem\"), MB_OK);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("}") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("newItem = new ") + className + _T(";") + xCrLf;
		if (keyMember->GetDataType() == enDataType_String)
			implCode_ += xTab + xTab + xTab + xTab + _T("newItem->Set") + keyMember->GetName() + _T("(inputBox.GetValueString());") + xCrLf;
		else
			implCode_ += xTab + xTab + xTab + xTab + _T("newItem->Set") + keyMember->GetName() + _T("(inputBox.GetValueDouble());") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + varPath + _T(".Insert(*newItem);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("BuildNode_") + parentPath + _T("_") + name + _T("(*newItem, selNode);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("tree_.SortChildren(selNode);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("delete newItem;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("}") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;
	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	cmString tmp;

	if (parentPath.GetLength())
		tmp = parentPath + _T("_") + name;
	else
		tmp = name;

	members = classInfo->GetMembers();
	parentStack.push_back(classInfo);
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateMapCreateItem(dynamic_cast<CXmlClassInfo*>(member), parentStack, count, tmp);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateMapItemCreateItem(CXmlClassInfo* classInfo, 
															   vector<CXmlClassInfo*> parentStack,
															   int& count,
															   cmString parentPath)
{
	cmString p;
	enCardinality cardinality;
	cmString varPath;
	cmString className;
	cmString name;
	enRenderingMode renderingMode;
	CXmlMemberInfo* keyMember;
	TCHAR buf[100];
	count++;

	varPath = Impl_generateVarPath(classInfo, parentStack, true);

 	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		className = GetClassName(inheritClassInfo->GetName());
		name = inheritClassInfo->GetName();
		cardinality = inheritClassInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(inheritClassInfo);
		renderingMode = inheritClassInfo->GetRenderingMode();
		keyMember = dynamic_cast<CXmlMemberInfo*>(inheritClassInfo->GetMember(inheritClassInfo->GetCardinalityInfo()->GetMapSortKey()));
		
	} else {
		className = GetClassName(classInfo->GetName());
		name = classInfo->GetName();
		cardinality = classInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(classInfo);
		renderingMode = classInfo->GetRenderingMode();
		keyMember = dynamic_cast<CXmlMemberInfo*>(classInfo->GetMember(classInfo->GetCardinalityInfo()->GetMapSortKey()));
	}

	// class dialog switch
	//
	if (cardinality == enCardinality_Map) {
		
		implCode_ += xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("{") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + className + _T(" newItem;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("CInputBox inputBox;") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("BOOL ret;") + xCrLf;
		implCode_ += xCrLf;
		if (keyMember->GetDataType() == enDataType_String)
			implCode_ += xTab + xTab + xTab + xTab + _T("inputBox.Init(_T(\"Create new item\"), _T(\"Please enter '") + keyMember->GetCaption() + _T("'\"), _T(\"\"));") + xCrLf;
		else
			implCode_ += xTab + xTab + xTab + xTab + _T("inputBox.Init(_T(\"Create new item\"), _T(\"Please enter '") + keyMember->GetCaption() + _T("'\"), 0, ") + cmString(_itow(keyMember->GetDecimalPlaces(), buf, 10)) + _T(");") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("ret = inputBox.DoModal();") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("if (!ret)") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + xTab + _T("return;") + xCrLf;
		implCode_ += xCrLf;
		if (keyMember->GetDataType() == enDataType_String)
			implCode_ += xTab + xTab + xTab + xTab + _T("newItem.Set") + keyMember->GetName() + _T("(inputBox.GetValueString());") + xCrLf;
		else
			implCode_ += xTab + xTab + xTab + xTab + _T("newItem.Set") + keyMember->GetName() + _T("(inputBox.GetValueDouble());") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + varPath + _T(".Insert(newItem);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("BuildNode_") + parentPath + _T("_") + name + _T("(newItem, tree_.GetParentItem(selNode));") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("tree_.SortChildren(tree_.GetParentItem(selNode));") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("}") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;
	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	cmString tmp;

	if (parentPath.GetLength())
		tmp = parentPath + _T("_") + name;
	else
		tmp = name;

	members = classInfo->GetMembers();
	parentStack.push_back(classInfo);
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateMapItemCreateItem(dynamic_cast<CXmlClassInfo*>(member), parentStack, count, tmp);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateMapItemRemoveItem(CXmlClassInfo* classInfo, 
															   vector<CXmlClassInfo*> parentStack,
															   int& count,
															   cmString parentPath)
{
	cmString p;
	enCardinality cardinality;
	cmString varPath;
	cmString className;
	cmString name;
	enRenderingMode renderingMode;
	CXmlMemberInfo* keyMember;

	count++;

	varPath = Impl_generateVarPath(classInfo, parentStack, true);

 	if (classInfo->GetDefinitionInheritance()) {
		CXmlClassInfo* inheritClassInfo;

		inheritClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
		className = GetClassName(inheritClassInfo->GetName());
		name = inheritClassInfo->GetName();
		cardinality = inheritClassInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(inheritClassInfo);
		renderingMode = inheritClassInfo->GetRenderingMode();
		keyMember = dynamic_cast<CXmlMemberInfo*>(inheritClassInfo->GetMember(inheritClassInfo->GetCardinalityInfo()->GetMapSortKey()));
		
	} else {
		className = GetClassName(classInfo->GetName());
		name = classInfo->GetName();
		cardinality = classInfo->GetCardinalityInfo()->GetCardinality();
		p = GetCardinalityPostfix(classInfo);
		renderingMode = classInfo->GetRenderingMode();
		keyMember = dynamic_cast<CXmlMemberInfo*>(classInfo->GetMember(classInfo->GetCardinalityInfo()->GetMapSortKey()));
	}

	// class dialog switch
	//
	if (cardinality == enCardinality_Map) {
		
		implCode_ += xTab + xTab + xTab + _T("case ") + GetDialogId(classInfo, count) + _T(":") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("{") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("HTREEITEM parentItem;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("parentItem = tree_.GetParentItem(selNode);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + varPath + _T(".Delete(nodeInfo.GetMapKey());") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("DeleteNode(selNode);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("tree_.SelectItem(parentItem);") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("OnTreeNodeSelection();") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("}") + xCrLf;
		implCode_ += xTab + xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xCrLf;
	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	cmString tmp;

	if (parentPath.GetLength())
		tmp = parentPath + _T("_") + name;
	else
		tmp = name;

	members = classInfo->GetMembers();
	parentStack.push_back(classInfo);
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateMapItemRemoveItem(dynamic_cast<CXmlClassInfo*>(member), parentStack, count, tmp);
		}
	}
}

void CCppMainDialogGenerator::Head_generateDeleteNode()
{
	headCode_ += xTab + _T("void DeleteNode(HTREEITEM treeItem);") + xCrLf;
}

void CCppMainDialogGenerator::Impl_generateDeleteNode()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::DeleteNode(HTREEITEM treeItem)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM nextItem;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM childItem;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("childItem = tree_.GetChildItem(treeItem);") + xCrLf;
	implCode_ += xTab + _T("while (childItem != NULL) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nextItem = tree_.GetNextItem(childItem, TVGN_NEXT);") + xCrLf;
	implCode_ += xTab + xTab + _T("DeleteNode(childItem);") + xCrLf;
	implCode_ += xTab + xTab + _T("childItem = nextItem;") + xCrLf;
	implCode_ += xTab + _T("};") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("node2InfoMap_.erase(treeItem);") + xCrLf;
	implCode_ += xTab + _T("tree_.DeleteItem(treeItem);") + xCrLf;
	implCode_ += _T("}") + xCrLf;
}

void CCppMainDialogGenerator::Head_generateUpdateNodeImages()
{
	headCode_ += xTab + _T("void UpdateNodeImages(HTREEITEM node);") + xCrLf;
}

void CCppMainDialogGenerator::Impl_generateUpdateNodeImages()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::UpdateNodeImages(HTREEITEM node)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("map<HTREEITEM, ") + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo>::iterator it;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo nodeInfo;") + xCrLf;
	implCode_ += xTab + _T("UINT itemState;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("it = node2InfoMap_.find(node);") + xCrLf;
	implCode_ += xTab + _T("if (it != node2InfoMap_.end()) {") + xCrLf;
	implCode_ += xTab + xTab + _T("nodeInfo = it->second;") + xCrLf;
	implCode_ += xTab + xTab + _T("itemState = tree_.GetItemState(node, TVIF_STATE);") + xCrLf;
	implCode_ += xTab + xTab + _T("if (itemState & TVIS_EXPANDED)") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("tree_.SetItemImage(node, nodeInfo.GetIconExpandedNotSelected(), nodeInfo.GetIconExpandedSelected());") + xCrLf;
	implCode_ +=  xTab + xTab + _T("else") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("tree_.SetItemImage(node, nodeInfo.GetIconCollapsedNotSelected(), nodeInfo.GetIconCollapsedSelected());") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += _T("}") + xCrLf;
}

void CCppMainDialogGenerator::Head_generateInterfaceImplementation()
{
	headCode_ += xTab + _T("public:") + xCrLf;
	headCode_ += xTab + xTab + _T("void OnTreeNodeSelection(HTREEITEM oldItem, HTREEITEM newItem);") + xCrLf;
	headCode_ += xTab + xTab + _T("void OnTreeNodeExpansion(HTREEITEM item);") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateInterfaceImplementation()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnTreeNodeSelection(HTREEITEM oldItem, HTREEITEM newItem)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("UpdateNodeImages(oldItem);") + xCrLf;
	implCode_ += xTab + _T("UpdateNodeImages(newItem);") + xCrLf;
	implCode_ += xTab +_T("OnTreeNodeSelection();") + xCrLf;
	implCode_ += xTab + _T("lastSelNode_ = newItem;") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += _T("void ") + GetMainDlgName() + _T("::OnTreeNodeExpansion(HTREEITEM item)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("UpdateNodeImages(item);") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}


void CCppMainDialogGenerator::Impl_generateInsertChildNode(CXmlClassInfo* classInfo, int& count, vector<CXmlClassInfo*> parentStack)
{
	CXmlClassInfo* tmpClassInfo;
	cmString parentPath;
	cmString tmp;
	enCardinality c;
	enRenderingMode r;

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;

	count++;
	//TRACE2(_T("Impl_generateInsertChildNode %s [%d]\n"), classInfo->GetName(), count);

	parentPath = GetParentPath(NULL, parentStack);

	c = tmpClassInfo->GetCardinalityInfo()->GetCardinality();
	r = tmpClassInfo->GetRenderingMode();
	if ((r != enRenderingMode_None && r != enRenderingMode_Grid) ||
		 tmpClassInfo->GetLockedByInheritance()) {
		
		if (c == enCardinality_Array && r != enRenderingMode_Grid) {
		
			cmString iconExpandedSelected;
			cmString iconExpandedNotSelected;
			cmString iconCollapsedSelected;
			cmString iconCollapsedNotSelected;

			iconExpandedSelected = classInfo->GetTreeIcons()->GetIconExpandedSelected();
			iconExpandedNotSelected = classInfo->GetTreeIcons()->GetIconExpandedNotSelected();
			iconCollapsedSelected = classInfo->GetTreeIcons()->GetIconCollapsedSelected();
			iconCollapsedNotSelected = classInfo->GetTreeIcons()->GetIconCollapsedNotSelected();
			
			iconExpandedSelected = iconExpandedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedSelected) : _T("IDI_EMPTY");
			iconExpandedNotSelected = iconExpandedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconExpandedNotSelected) : _T("IDI_EMPTY");
			iconCollapsedSelected = iconCollapsedSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedSelected) : _T("IDI_EMPTY");
			iconCollapsedNotSelected = iconCollapsedNotSelected.GetLength() ? project_->GetProjectIcons()->GetIconKey(iconCollapsedNotSelected) : _T("IDI_EMPTY");

			iconExpandedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedSelected + _T("))");
			iconExpandedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconExpandedNotSelected + _T("))");
			iconCollapsedSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedSelected + _T("))");
			iconCollapsedNotSelected = _T("imageList_.Add(AfxGetApp()->LoadIcon(") + iconCollapsedNotSelected + _T("))");

			tmp = _T("_");
			tmp += tmpClassInfo->GetName();
			tmp += GetCardinalityPostfix(tmpClassInfo);

			implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::InsertArrayItem") + parentPath + tmp + _T("(") + GetClassName(/*2004.04.07 was classInfo->GetName()*/tmpClassInfo->GetName()) + _T("& newItem, HTREEITEM parentItem, int itemIndex)") + xCrLf;
			implCode_ += _T("{") + xCrLf;
			implCode_ += xTab + _T("cmString buf;") + xCrLf;
			implCode_ += xTab + _T("cmString caption;") + xCrLf;
			implCode_ += xTab + _T("HTREEITEM newNode;") + xCrLf;
			implCode_ += xTab + _T("HTREEITEM tmp;") + xCrLf;
			implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;
			implCode_ += xCrLf;

			parentPath = GetParentPath(NULL, parentStack, false);

			implCode_ += xTab + _T("newNode = BuildNode") + parentPath + _T("_") + tmpClassInfo->GetName() + _T("(newItem, parentItem, itemIndex);") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("// renumber items") + xCrLf;
			implCode_ += xTab + _T("//") + xCrLf;
			implCode_ += xTab + _T("tmp = newNode;") + xCrLf;
			implCode_ += xTab + _T("while (true) {") + xCrLf;
			implCode_ += xTab + xTab + _T("itemIndex++;") + xCrLf;
			implCode_ += xTab + xTab + _T("tmp = tree_.GetNextSiblingItem(tmp);") + xCrLf;
			implCode_ += xTab + xTab + _T("if (tmp == NULL)") + xCrLf;
			implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
			implCode_ += xTab + xTab + _T("GetNodeInfo(tmp)->SetArrayIndex(itemIndex);") + xCrLf;
			implCode_ += xTab + xTab +_T("buf.Format(_T(\" %d\"), itemIndex + 1);") + xCrLf;
			implCode_ += xTab + xTab + _T("caption = _T(\"" + tmpClassInfo->GetCaption() + _T("\");")) + xCrLf;
			implCode_ += xTab + xTab + _T("caption += buf;") + xCrLf;
			implCode_ += xTab + xTab + _T("tree_.SetItemText(tmp, caption);") + xCrLf;
			implCode_ += xTab + _T("}") + xCrLf;
			implCode_ += xTab + _T("tree_.RedrawWindow();") + xCrLf;
			implCode_ += xTab + _T("return newNode;") + xCrLf;
			implCode_ += _T("}") + xCrLf;
			implCode_ += xCrLf;
		} else if(c == enCardinality_Map) {
			tmp = _T("_");
			tmp += tmpClassInfo->GetName();
			tmp += GetCardinalityPostfix(tmpClassInfo);

			implCode_ += _T("HTREEITEM ") + GetMainDlgName() + _T("::InsertMapItem") + parentPath + tmp + _T("(") + GetClassName(/*2004.04.07 was classInfo->GetName()*/tmpClassInfo->GetName()) + _T("& newItem, HTREEITEM parentItem, const cmString& itemKey)") + xCrLf;
			implCode_ += _T("{") + xCrLf;

			parentPath = GetParentPath(NULL, parentStack, false);
			implCode_ += xTab + _T("BuildNode") + parentPath + _T("_") + tmpClassInfo->GetName() + _T("(newItem, parentItem);") + xCrLf;
			implCode_ += xTab + _T("tree_.SortChildren(parentItem);") + xCrLf;
			implCode_ += xTab + _T("tree_.RedrawWindow();") + xCrLf;
			implCode_ += xCrLf;
			implCode_ += xTab + _T("return NULL;") + xCrLf;
			implCode_ +=_T("}") + xCrLf;
			implCode_ += xCrLf;
		}
	}

	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;
	
	parentStack.push_back(tmpClassInfo);
	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateInsertChildNode(dynamic_cast<CXmlClassInfo*>(member), count, parentStack);
		}
	}
}

void CCppMainDialogGenerator::Head_generateDeleteArrayItemNode()
{
	headCode_ += _T("public:") + xCrLf;
	headCode_ += xTab + _T("void DeleteArrayItemNode(HTREEITEM parentItem, int itemIndex, const cmString& caption);") + xCrLf;
	headCode_ += xTab + _T("void DeleteArrayItemNode(HTREEITEM parentItem, vector<int>& itemIndexList, const cmString& caption);") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateDeleteMapItemNode()
{
	headCode_ += _T("public:") + xCrLf;
	headCode_ += xTab + _T("void DeleteMapItemNode(HTREEITEM parentItem, const cmString& itemKey);") + xCrLf;
	headCode_ += xTab + _T("void DeleteMapItemNode(HTREEITEM parentItem, vector<cmString>& itemKeyList);") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateSelectArrayItemNode()
{
	headCode_ += _T("public:") + xCrLf;
	headCode_ += xTab + _T("void SelectArrayItemNode(HTREEITEM parentItem, int itemIndex);") + xCrLf;
	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateSelectMapItemNode()
{
	headCode_ += _T("public:") + xCrLf;
	headCode_ += xTab + _T("void SelectMapItemNode(HTREEITEM parentItem, const cmString& itemKey);") + xCrLf;
}

void CCppMainDialogGenerator::Head_generateReplaceMapKey(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack)
{
	CXmlClassInfo* tmpClassInfo;
	cmString parentPath;
	cmString tmp;
	enCardinality c;

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;

	parentPath = GetParentPath(NULL, parentStack);

	c = tmpClassInfo->GetCardinalityInfo()->GetCardinality();

	tmp += _T("_");
	tmp += tmpClassInfo->GetName();
	tmp += GetCardinalityPostfix(tmpClassInfo);
	tmp += _T("_");
	tmp += tmpClassInfo->GetName();

	if (c == enCardinality_Map)
		headCode_ += xTab + _T("bool ReplaceMapKey") + parentPath + tmp + _T("(HTREEITEM parentItem, const cmString& oldKey, const cmString& newKey);") + xCrLf;

	// generate for children
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	parentStack.push_back(tmpClassInfo);

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Head_generateReplaceMapKey(dynamic_cast<CXmlClassInfo*>(member), parentStack);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateDeleteArrayItemNode()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::DeleteArrayItemNode(HTREEITEM parentItem, int itemIndex, const cmString& caption)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("cmString buf;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM toDelete;") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM tmp;") + xCrLf;
	implCode_ += xTab + _T("cmString newCaption;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("toDelete = tree_.GetChildItem(parentItem);") + xCrLf;
	implCode_ += xTab + _T("for (int i = 1; i <= itemIndex; i++)") + xCrLf;
	implCode_ += xTab + xTab + _T("toDelete = tree_.GetNextItem(toDelete, TVGN_NEXT);") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("// renumber items") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("tmp = toDelete;") + xCrLf;
	implCode_ += xTab + _T("while (true) {") + xCrLf;
	implCode_ += xTab + xTab + _T("tmp = tree_.GetNextSiblingItem(tmp);") + xCrLf;
	implCode_ += xTab + xTab + _T("if (tmp == NULL)") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
	implCode_ += xTab + xTab + _T("GetNodeInfo(tmp)->SetArrayIndex(itemIndex);") + xCrLf;
	implCode_ += xTab + xTab + _T("buf.Format(_T(\" %d\"), itemIndex + 1);") + xCrLf;
	implCode_ += xTab + xTab + _T("newCaption = caption;") + xCrLf;
	implCode_ += xTab + xTab + _T("newCaption += buf;") + xCrLf;
	implCode_ += xTab + xTab + _T("tree_.SetItemText(tmp, newCaption);") + xCrLf;
	implCode_ += xTab + xTab + _T("itemIndex++;") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += xCrLf;			
	implCode_ += xTab + _T("node2InfoMap_.erase(toDelete);") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("tree_.DeleteItem(toDelete);") + xCrLf;
	implCode_ += xTab + _T("tree_.RedrawWindow();") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += _T("void ") + GetMainDlgName() + _T("::DeleteArrayItemNode(HTREEITEM parentItem, vector<int>& itemIndexList, const cmString& caption)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("for (int i = 0; i < itemIndexList.size(); i++)") + xCrLf;
	implCode_ += xTab + xTab + _T("DeleteArrayItemNode(parentItem, itemIndexList[i], caption);") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateSelectArrayItemNode()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::SelectArrayItemNode(HTREEITEM parentItem, int itemIndex)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM tmp;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("tmp = tree_.GetChildItem(parentItem);") + xCrLf;
	implCode_ += xTab + _T("for (int i = 1; i <= itemIndex; i++)") + xCrLf;
	implCode_ += xTab + xTab + _T("tmp = tree_.GetNextItem(tmp, TVGN_NEXT);") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("tree_.SelectItem(tmp);") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateForwardDeclarations()
{
	Head_generateForwardDeclarations(project_->GetRootElement());

	headCode_ += xCrLf;
}

void CCppMainDialogGenerator::Head_generateForwardDeclarations(CXmlClassInfo* classInfo)
{
	headCode_ += _T("class ") + GetClassName(classInfo->GetName()) + _T(";") + xCrLf;
	
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* element;

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		element = it->second;
		
		if (element->GetDataType() == enDataType_Class)
			Head_generateForwardDeclarations(dynamic_cast<CXmlClassInfo*>(element));
	}
}

void CCppMainDialogGenerator::Impl_generateDeleteMapItemNode()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::DeleteMapItemNode(HTREEITEM parentItem, const cmString& itemKey)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM childNode;") + xCrLf;
	implCode_ += xTab + _T("cmString newCaption;") + xCrLf;
	implCode_ += xTab + cppSettings_->GetClassPrefix() + _T("TreeNodeInfo newNodeInfo;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("childNode = tree_.GetChildItem(parentItem);") + xCrLf;
	implCode_ += xTab + _T("while (childNode) {") + xCrLf;
	implCode_ += xTab + xTab + _T("if (tree_.GetItemText(childNode) == itemKey) {") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("node2InfoMap_.erase(childNode);") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("tree_.DeleteItem(childNode);") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("tree_.RedrawWindow();") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
	implCode_ += xTab + xTab + _T("}") + xCrLf;
	implCode_ += xTab + xTab + _T("childNode = tree_.GetNextItem(childNode, TVGN_NEXT);") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

	implCode_ += _T("void ") + GetMainDlgName() + _T("::DeleteMapItemNode(HTREEITEM parentItem, vector<cmString>& itemKeyList)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("for (int i = 0; i < itemKeyList.size(); i++)") + xCrLf;
	implCode_ += xTab + xTab + _T("DeleteMapItemNode(parentItem, itemKeyList[i]);") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateSelectMapItemNode()
{
	implCode_ += _T("void ") + GetMainDlgName() + _T("::SelectMapItemNode(HTREEITEM parentItem, const cmString& itemKey)") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("HTREEITEM childNode;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("childNode = tree_.GetChildItem(parentItem);") + xCrLf;
	implCode_ += xTab + _T("while (childNode) {") + xCrLf;
	implCode_ += xTab + xTab + _T("if (tree_.GetItemText(childNode) == itemKey) {") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("tree_.SelectItem(childNode);") + xCrLf;
	implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
	implCode_ += xTab + xTab + _T("}") + xCrLf;
	implCode_ += xCrLf; 
	implCode_ += xTab + xTab + _T("childNode = tree_.GetNextItem(childNode, TVGN_NEXT);") + xCrLf;
	implCode_ += xTab + _T("}") + xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;
}

void CCppMainDialogGenerator::Impl_generateReplaceMapKey(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack)
{
	CXmlClassInfo* tmpClassInfo;
	cmString parentPath;
	cmString tmp;
	enCardinality c;

	if (classInfo->GetDefinitionInheritance())
		tmpClassInfo = dynamic_cast<CXmlClassInfo*>(rootClassInfo_->GetMemberById(classInfo->GetInherithClassId()));
	else
		tmpClassInfo = classInfo;

	parentPath = GetParentPath(NULL, parentStack);

	c = tmpClassInfo->GetCardinalityInfo()->GetCardinality();

	tmp += _T("_");
	tmp += tmpClassInfo->GetName();
	tmp += GetCardinalityPostfix(tmpClassInfo);
	tmp += _T("_");
	tmp += tmpClassInfo->GetName();

	if (c == enCardinality_Map) {
		implCode_ += _T("bool ") + GetMainDlgName() + _T("::ReplaceMapKey") + parentPath + tmp + _T("(HTREEITEM parentItem, const cmString& oldKey, const cmString& newKey)") + xCrLf;
		implCode_ += _T("{") + xCrLf;
		implCode_ += xTab + _T("HTREEITEM childNode;") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("childNode = tree_.GetChildItem(parentItem);") + xCrLf;
		implCode_ += xTab + _T("while (childNode) {") + xCrLf;
		implCode_ += xTab + xTab + _T("if (tree_.GetItemText(childNode) == oldKey) {") + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("tree_.SetItemText(childNode, newKey);") + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("GetNodeInfo(childNode)->SetMapKey(newKey);") + xCrLf;
		implCode_ += xTab + xTab + xTab + _T("break;") + xCrLf;
		implCode_ += xTab + xTab + _T("}") + xCrLf;
		implCode_ += xCrLf; 
		implCode_ += xTab + xTab + _T("childNode = tree_.GetNextItem(childNode, TVGN_NEXT);") + xCrLf;
		implCode_ += xTab + _T("}") + xCrLf;
		implCode_ += xCrLf;
		implCode_ += xTab + _T("return true;") + xCrLf;
		implCode_ += _T("}") + xCrLf;
		implCode_ += xCrLf;
	}
	// generate for children
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	parentStack.push_back(tmpClassInfo);

	members = classInfo->GetMembers();
	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		
		if (member->GetDataType() == enDataType_Class) {
			Impl_generateReplaceMapKey(dynamic_cast<CXmlClassInfo*>(member), parentStack);
		}
	}
}

void CCppMainDialogGenerator::Impl_generateChildDlgInit(CXmlClassInfo* classInfo)
{
	if(classInfo->GetDefinitionInheritance())
		return;

	if(classInfo->GetRenderingMode() != enRenderingMode_None) {
		implCode_ += xTab + GetCamelCase(GetDlgName(classInfo)) + _T("_(NULL),") + xCrLf;
	
		enCardinality c;

		c = classInfo->GetCardinalityInfo()->GetCardinality();
		if (c == enCardinality_Array && classInfo->GetRenderingMode() != enRenderingMode_Grid )
			implCode_ += xTab + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_(NULL),") + xCrLf;
		else if (c == enCardinality_Map)
			implCode_ += xTab + GetCamelCase(GetMapDialogName(classInfo)) + _T("_(NULL),") + xCrLf;
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateChildDlgInit(dynamic_cast<CXmlClassInfo*>(member));
	}
}

void CCppMainDialogGenerator::Impl_generateChildDlgDelete(CXmlClassInfo* classInfo)
{
	if(classInfo->GetDefinitionInheritance())
		return;

	if(classInfo->GetRenderingMode() != enRenderingMode_None) {
		implCode_ += xTab + _T("if (") + GetCamelCase(GetDlgName(classInfo)) + _T("_)") + xCrLf;
		implCode_ += xTab + xTab + _T("delete ") + GetCamelCase(GetDlgName(classInfo)) + _T("_;") + xCrLf;
		implCode_ += xCrLf;
	
		enCardinality c;

		c = classInfo->GetCardinalityInfo()->GetCardinality();
		if (c == enCardinality_Array && classInfo->GetRenderingMode() != enRenderingMode_Grid ) {
			implCode_ += xTab + _T("if (") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_)") + xCrLf;
			implCode_ += xTab + xTab + _T("delete ") + GetCamelCase(GetArrayDialogName(classInfo)) + _T("_;") + xCrLf;
			implCode_ += xCrLf;
		} else if (c == enCardinality_Map) {
			implCode_ += xTab + _T("if (") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_)") + xCrLf;
			implCode_ += xTab + xTab + _T("delete ") + GetCamelCase(GetMapDialogName(classInfo)) + _T("_;") + xCrLf;
			implCode_ += xCrLf;
		}
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateChildDlgDelete(dynamic_cast<CXmlClassInfo*>(member));
	}
}

void CCppMainDialogGenerator::Impl_generateChildDlgInclude(CXmlClassInfo* classInfo)
{
	if(classInfo->GetDefinitionInheritance())
		return;

	if(classInfo->GetRenderingMode() != enRenderingMode_None) {
		implCode_ += _T("#include \"") + GetDlgName(classInfo) + _T(".h\"") + xCrLf;
	
		enCardinality c;

		c = classInfo->GetCardinalityInfo()->GetCardinality();
		if (c == enCardinality_Array && classInfo->GetRenderingMode() != enRenderingMode_Grid )
			implCode_ += _T("#include \"") + GetArrayDialogName(classInfo) + _T(".h\"") + xCrLf;
		else if (c == enCardinality_Map)
			implCode_ += _T("#include \"") + GetMapDialogName(classInfo) + _T(".h\"") + xCrLf;
	}

	// generate include for class dialogs
	//
	ClassMemberMap* members;
	ClassMemberMap::iterator it;
	CXmlBaseElement* member;

	members = classInfo->GetMembers();

	for (it = members->begin(); it != members->end(); it++) {
		member = it->second;
		if (member->GetDataType() == enDataType_Class)
			Impl_generateChildDlgInclude(dynamic_cast<CXmlClassInfo*>(member));
	}
}

bool CCppMainDialogGenerator::NodeIsVisible(CXmlClassInfo* classInfo)
{
	if(classInfo != project_->GetRootElement())
		return true;

	return !(project_->GetMainDialog()->GetTreeSettings()->GetHideRootNode());
}