// CCppClassDialogGenerator.cpp
//

#include "stdafx.h"
#include "CSharpClassDialogGenerator.h"
#include "XmlClassInfo.h"
#include "XmlMemberInfo.h"
#include "XmlFormInfo.h"
#include "XmlBaseFormItem.h"
#include "XmlFormItem_Static.h"
#include "XmlFormItem_TextBox.h"
#include "XmlFormItem_CheckBox.h"
#include "XmlFormItem_ComboBox.h"
#include "XmlProjectSettings.h"

CCSharpClassDialogGenerator::CCSharpClassDialogGenerator()
{}

CCSharpClassDialogGenerator::~CCSharpClassDialogGenerator()
{}

void CCSharpClassDialogGenerator::Generate()
{
	/***
	cmString fileName;
	cmString pathName;

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

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

	hGeneratedFiles_[fileName] = pathName + fileName;

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

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

	cppGeneratedFiles_[fileName] = pathName + fileName;

  ***/
}

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// HEADER FILE GENERATORS
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
/***
void CCppClassDialogGenerator::Head_generateHeader()
{
	headCode_ += _T("// ") + GetDlgName() + _T(".h : header file") + xCrLf;
	headCode_ += _T("//") + xCrLf + xCrLf;
	headCode_ += GetGenerationTimeStamp();
}

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

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

void CCppClassDialogGenerator::Head_generateForwardDeclarations()
{
	headCode_ += _T("// forward declarations") + xCrLf;
	headCode_ += _T("//") + xCrLf;
	headCode_ += _T("class ") + GetClassName() + _T(";") + xCrLf;
	headCode_ += xCrLf;
}

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

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

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

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

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

void CCppClassDialogGenerator::Head_generateDialogData()
{
	// dialog data section
	//
	headCode_ += _T("// Dialog Data") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_DATA(") +  GetDlgName() + _T(")") + xCrLf;
	//headCode_ += "enum { IDD = IDD_CFG_TEMPLATE };"  + xCrLf;
	headCode_ += _T("enum { IDD = 0 };")  + xCrLf;
	headCode_ += xTab + xTab + _T("// NOTE: the ClassWizard will add data members here")  + xCrLf;
	headCode_ += xTab + _T("//}}AFX_DATA")  + xCrLf + xCrLf;
	
	// inner controls declarations
	//
	CXmlFormInfo* form;
	CXmlMemberInfo* member;
	FormItemList* formItems;
	FormItemList::iterator formItemIt;
	CXmlBaseFormItem* formItem;

	form = classInfo_->GetForm();
	
	formItems = form->GetItemList();
	for (formItemIt = formItems->begin(); formItemIt != formItems->end(); formItemIt++) {
		formItem = formItemIt->second;
		switch (formItem->GetItemType()) {
			case enFormItemType_Static:
				headCode_ += xTab + _T("CStatic ") + GetCamelCase(formItem->GetName()) + _T("_;") + xCrLf;			
				break;

			case enFormItemType_TextBox:
				//if (formItem->GetRelatedClassMemberName() == "") {
				//	headCode_ += xTab + "CEdit " + GetCamelCase(formItem->GetName()) + "_;" + xCrLf;
				//} else {
				member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMember(formItem->GetRelatedClassMemberName()));
				if (member && member->GetDataType() == enDataType_Double) {
					headCode_ += xTab + _T("CAMSNumericEdit ") + GetCamelCase(formItem->GetName()) + _T("_;") + xCrLf;
				} else {
					headCode_ += xTab + _T("CEdit ") + GetCamelCase(formItem->GetName()) + _T("_;") + xCrLf;
				}
				//}
				
				break;

			case enFormItemType_Bevel:
				//headCode_ += xTab + "CStatic " + GetCamelCase(formItem->GetName()) + "_;" + xCrLf;			
				break;

			case enFormItemType_CheckBox:
				headCode_ += xTab + _T("CButton ") + GetCamelCase(formItem->GetName()) + _T("_;") + xCrLf;			
				break;

			case enFormItemType_ComboBox:
				headCode_ += xTab + _T("CComboBox ") + GetCamelCase(formItem->GetName()) + _T("_;") + xCrLf;			
				break;

		}
	}
}

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

void CCppClassDialogGenerator::Head_generateMessageMap()
{
	headCode_ += _T("// Implementation") + xCrLf;
	headCode_ += _T("//") + xCrLf;
	headCode_ += _T("protected:") + xCrLf;
	headCode_ += xCrLf;
	headCode_ += xTab + _T("// Generated message map functions") + xCrLf;
	headCode_ += xTab + _T("//{{AFX_MSG(") + GetDlgName() + _T(")") + xCrLf;
	headCode_ += xTab + _T("virtual BOOL OnInitDialog();") + xCrLf;
	headCode_ += xTab + _T("//}}AFX_MSG") + xCrLf;
	headCode_ += xTab + _T("DECLARE_MESSAGE_MAP()") + xCrLf;
	headCode_ += xCrLf;
}

void CCppClassDialogGenerator::Head_generateProtectedMembers()
{
	headCode_ += xTab + _T("// Implementation") + xCrLf;
	headCode_ += xTab + _T("//") + xCrLf;
	headCode_ += xTab + _T("protected:") + xCrLf;
	headCode_ += xTab + xTab + _T("DECLARE_DYNCREATE(") + GetDlgName() + _T(");") + xCrLf;
	headCode_ += xTab + xTab + _T("virtual void DisplayData();") + xCrLf;
	headCode_ += xTab + xTab + _T("virtual void OnOK();") + xCrLf;
	headCode_ += xTab + xTab + _T("virtual void OnCancel();") + xCrLf;
	headCode_ += xCrLf;
}

void CCppClassDialogGenerator::Head_generateDataMembers()
{
	headCode_ += xTab + _T("// data members") + xCrLf;
	headCode_ += xTab + _T("//") + xCrLf;
	headCode_ += xTab + _T("protected:") + xCrLf;
	headCode_ += xTab + GetClassName() + _T("* ") + GetCamelCase(classInfo_->GetName()) + _T("_;") + xCrLf;
	headCode_ += xTab + _T("bool initialized_;") + xCrLf;
	headCode_ += xCrLf;
}

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

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

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

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

void CCppClassDialogGenerator::Impl_generateIncludeSection()
{
	implCode_ += _T("#include \"stdafx.h\"") + xCrLf;
	implCode_ += _T("#include \"") + GetDlgName() + _T(".h\"") + xCrLf;
	implCode_ += _T("#include \"") + GetClassName() + _T(".h\"") + xCrLf;
	implCode_ += _T("#include \"resource.h\"") + xCrLf;
	implCode_ += xCrLf;
}

void CCppClassDialogGenerator::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;
	// implCode_ += xCrLf;
}

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

	implCode_ += _T("IMPLEMENT_DYNCREATE(") + GetDlgName() + _T(", CDialog)") + xCrLf;
	implCode_ += xCrLf;
}

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

void CCppClassDialogGenerator::Impl_generateDestructor()
{
	implCode_ += GetDlgName() + _T("::~") + GetDlgName() + _T("()") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += _T("}") + xCrLf + xCrLf;
}

void CCppClassDialogGenerator::Impl_generatePublicMethods()
{
	// SetData
	//
	implCode_ += _T("void ") + GetDlgName() + _T("::SetData(") + GetClassName() + _T("* ") + GetCamelCase(classInfo_->GetName()) + _T(")") + xCrLf;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("if (!initialized_)") + xCrLf;
	implCode_ += xTab + xTab + _T("OnInitDialog();") + xCrLf;

	implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("_ = ") + GetCamelCase(classInfo_->GetName()) + _T(";") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("// display data") + xCrLf;
	implCode_ += xTab + _T("//") + xCrLf;
	implCode_ += xTab + _T("DisplayData();") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += _T("}") + xCrLf;
	implCode_ += xCrLf;

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

	//XMLElementMap::iterator it;
	CXmlFormInfo* form;
	CXmlMemberInfo* member;
	FormItemList* formItems;
	FormItemList::iterator formItemIt;
	CXmlBaseFormItem* formItem;
			
	form = classInfo_->GetForm();
		
	formItems = form->GetItemList();
	for (formItemIt = formItems->begin(); formItemIt != formItems->end(); formItemIt++) {
		formItem = formItemIt->second;
		if (formItem->GetRelatedClassMemberName() == _T(""))
			continue;

		member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMember(formItem->GetRelatedClassMemberName()));
		implCode_ += xTab + _T("// get data from ") + formItem->GetRelatedClassMemberName() + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		switch (formItem->GetItemType()) {
			case enFormItemType_Static:
				implCode_ += xTab + _T("CString ") + GetCamelCase(formItem->GetName()) + _T("Value;") + xCrLf;
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.GetWindowText(") + GetCamelCase(formItem->GetName()) + _T("Value);") + xCrLf;
				implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("_->Set") + formItem->GetRelatedClassMemberName() + _T("(") + GetCamelCase(formItem->GetName()) + _T("Value);") + xCrLf;
				break;

			case enFormItemType_TextBox:
				implCode_ += xTab + _T("CString ") + GetCamelCase(formItem->GetName()) + _T("Value;") + xCrLf;
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.GetWindowText(") + GetCamelCase(formItem->GetName()) + _T("Value);") + xCrLf;
				switch (member->GetDataType()) {
					case enDataType_String:
						implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("_->Set") + formItem->GetRelatedClassMemberName() + _T("(") + GetCamelCase(formItem->GetName()) + _T("Value);") + xCrLf;
						break;

					case enDataType_Double:
						implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("_->Set") + formItem->GetRelatedClassMemberName() + _T("((double)") + GetCamelCase(formItem->GetName()) + _T("Value));") + xCrLf;
						break;
				}
				
				break;

			case enFormItemType_Bevel:
				break;

			case enFormItemType_CheckBox:
				implCode_ += xTab + GetCamelCase(classInfo_->GetName()) + _T("_->Set") + formItem->GetRelatedClassMemberName() + _T("(") + GetCamelCase(formItem->GetName()) + _T("_.GetCheck() == TRUE);") + xCrLf;
				break;

			case enFormItemType_ComboBox:
				//implCode_ += xTab + GetCamelCase(formItem->GetName()) + "Value = " + GetCamelCase(classInfo_->GetName()) + "_->Get" + formItem->getRelatedClassMemberName() + "().c_str();" + xCrLf;
				break;
		}
		implCode_ += xCrLf;
	}

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

void CCppClassDialogGenerator::Impl_generateMessageMap()
{
	implCode_ += _T("BEGIN_MESSAGE_MAP(") + GetDlgName() + _T(", CDialog)") + xCrLf;
	implCode_ += _T("	//{{AFX_MSG_MAP(getDlgName())") + xCrLf;
	implCode_ += _T("	ON_WM_CREATE()") + xCrLf;
	implCode_ += _T("	//}}AFX_MSG_MAP") + xCrLf;
	implCode_ += _T("END_MESSAGE_MAP()") + xCrLf + xCrLf;
}

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

	implCode_ += _T("BOOL ") + GetDlgName() + _T("::OnInitDialog()") + xCrLf ;
	implCode_ += _T("{") + xCrLf;
	implCode_ += xTab + _T("initialized_ = true;") + xCrLf;
	implCode_ += xCrLf;
	implCode_ += xTab + _T("CDialog::OnInitDialog();") + xCrLf + xCrLf;
	
	implCode_ += xTab + _T("ModifyStyle(WS_POPUP, WS_CHILD);") + xCrLf + xCrLf;
	
	// inner controls creation
	//
	//XMLElementMap::iterator it;
	CXmlFormInfo* form;
	CXmlMemberInfo* member;
	FormItemList* formItems;
	FormItemList::iterator formItemIt;
	CXmlBaseFormItem* formItem;
	CXmlFormItem_Static* formItemStatic;
	CXmlFormItem_TextBox* formItemTextBox;
	CXmlFormItem_CheckBox* formItemCheckBox;
	CXmlFormItem_ComboBox* formItemComboBox;
	cmString buf;
	cmString rectDecl;
	CRect rc;

	form = classInfo_->GetForm();
		
	formItems = form->GetItemList();
	for (formItemIt = formItems->begin(); formItemIt != formItems->end(); formItemIt++) {
		formItem = formItemIt->second;
		
		rc = formItem->GetItemRect();

		switch (formItem->GetItemType()) {
			case enFormItemType_Static:
				buf.Format(_T("CRect(%d, %d, %d, %d)"), rc.left, rc.top, rc.right,rc.bottom);
				rectDecl = buf;
				formItemStatic = dynamic_cast<CXmlFormItem_Static*>(formItem);
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.Create(\"") + formItemStatic->GetCaption() + _T("\", WS_VISIBLE | WS_CHILD, ") + rectDecl + _T(", this, ") + GetControlId(formItem, classInfo_) +_T(");") + xCrLf;			
				break;

			case enFormItemType_TextBox:
				formItemTextBox = dynamic_cast<CXmlFormItem_TextBox*>(formItem);
				//sprintf(buf, "CRect(%d, %d, %d, %d)", rc.left, rc.top, rc.right,rc.bottom);
				//rectDecl = buf;
				//implCode_ += xTab + GetCamelCase(formItem->GetName()) + "_.Create(WS_VISIBLE | WS_CHILD, " + rectDecl + ", this, " + getControlId(formItem, classInfo_) +");" + xCrLf;			
				buf.Format(_T(", %d, %d, %d, %d"), rc.left, rc.top, rc.Width(), rc.Height());
				rectDecl = buf;
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.CreateEx(WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE, (LPCSTR) \"EDIT\", \"Editbox\",	WS_TABSTOP | WS_CHILD | WS_VISIBLE") + rectDecl + _T(", GetSafeHwnd(), (HMENU) 1);") + xCrLf;
				member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMember(formItem->GetRelatedClassMemberName()));
				if (member && member->GetDataType() == enDataType_Double) {
					buf.Format(_T("%d"), member->GetDecimalPlaces());
					implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.SetMaxDecimalPlaces(") + cmString(buf) + _T(");") + xCrLf;
					implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.SetSeparators('.',',');") + xCrLf;
				}
				break;

			case enFormItemType_Bevel:
				//headCode_ += xTab + "CStatic " + formItem->GetName() + xCrLf;			
				break;

			case enFormItemType_CheckBox:
				buf.Format(_T("CRect(%d, %d, %d, %d)"), rc.left, rc.top, rc.right,rc.bottom);
				rectDecl = buf;
				formItemCheckBox = dynamic_cast<CXmlFormItem_CheckBox*>(formItem);
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.Create(\"") + formItemCheckBox->GetCaption() + _T("\", WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, ") + rectDecl + _T(", this, ") + GetControlId(formItem, classInfo_) + _T(");") + xCrLf;			
				break;

			case enFormItemType_ComboBox:
				buf.Format(_T("CRect(%d, %d, %d, %d)"), rc.left, rc.top, rc.right,rc.bottom);
				rectDecl = buf;
				formItemComboBox = dynamic_cast<CXmlFormItem_ComboBox*>(formItem);
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.Create(CBS_DROPDOWNLIST | WS_VISIBLE | WS_CHILD, ") + rectDecl + _T(", this, ") + GetControlId(formItem, classInfo_) + _T(");") + xCrLf;			
				break;

		}
		implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.SetFont(GetFont());") + xCrLf + xCrLf;

	}

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

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

	// display data
	//
	//XMLElementMap::iterator it;
	CXmlFormInfo* form;
	CXmlMemberInfo* member;
	FormItemList* formItems;
	FormItemList::iterator formItemIt;
	CXmlBaseFormItem* formItem;
	wchar_t buf[10];		
	form = classInfo_->GetForm();
		
	formItems = form->GetItemList();
	for (formItemIt = formItems->begin(); formItemIt != formItems->end(); formItemIt++) {
		formItem = formItemIt->second;
		if (formItem->GetRelatedClassMemberName() == _T(""))
			continue;

		member = dynamic_cast<CXmlMemberInfo*>(classInfo_->GetMember(formItem->GetRelatedClassMemberName()));
		implCode_ += xTab + _T("// set data on ") + formItem->GetRelatedClassMemberName() + xCrLf;
		implCode_ += xTab + _T("//") + xCrLf;
		switch (formItem->GetItemType()) {
			case enFormItemType_Static:
				implCode_ += xTab + _T("CString ") + GetCamelCase(formItem->GetName()) + _T("Value;") + xCrLf;
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("Value = ") + GetCamelCase(classInfo_->GetName()) + _T("_->Get") + formItem->GetRelatedClassMemberName() + _T("().c_str();") + xCrLf;
				
				break;

			case enFormItemType_TextBox:
				implCode_ += xTab + _T("CString ") + GetCamelCase(formItem->GetName()) + _T("Value;") + xCrLf;
				switch (member->GetDataType()) {
					case enDataType_String:
						implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("Value = ") + GetCamelCase(classInfo_->GetName()) + _T("_->Get") + formItem->GetRelatedClassMemberName() + _T("().c_str();") + xCrLf;
						break;

					case enDataType_Double:
						wsprintf(buf, _T("%d"), member->GetDecimalPlaces());
						implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("Value.Format(_T(\"%1.") + cmString(buf) + _T("f\"), ") + GetCamelCase(classInfo_->GetName()) + _T("_->Get") + formItem->GetRelatedClassMemberName() + _T("());") + xCrLf;
						break;
				}

				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.SetWindowText(") + GetCamelCase(formItem->GetName()) + _T("Value);") + xCrLf;
				break;

			case enFormItemType_Bevel:
				
				break;

			case enFormItemType_CheckBox:
				implCode_ += xTab + GetCamelCase(formItem->GetName()) + _T("_.SetCheck(") + GetCamelCase(classInfo_->GetName()) + _T("_->Get") + formItem->GetRelatedClassMemberName() + _T("());") + xCrLf;
				break;

			case enFormItemType_ComboBox:
				//implCode_ += xTab + GetCamelCase(formItem->GetName()) + "Value = " + GetCamelCase(classInfo_->GetName()) + "_->Get" + formItem->getRelatedClassMemberName() + "().c_str();" + xCrLf;
				break;

		}
		implCode_ += xCrLf;
	}

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

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

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

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