// XmlMainDialog.cpp: implementation for the CXmlMainDialog class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "XmlMainDialog.h"

CXmlMainDialog::CXmlMainDialog()
{
	SetDefaults();
}

CXmlMainDialog::~CXmlMainDialog()
{}

bool CXmlMainDialog::BuildFromXml(IXMLDOMNode* node)
{
	Clear();
	
	ExtractMemberNode(node, _T("IconFileName"), iconFileName_);
	ExtractMemberNode(node, _T("InitialSize"), (int&)initialSize_);
	ExtractMemberNode(node, _T("Caption"), caption_);
	ExtractMemberNode(node, _T("SplitterPos"), splitterPos_);
	ExtractMemberNode(node, CXmlMainDialogTree::GetXmlNodeName(), treeSettings_);
	
	return true;
}

bool CXmlMainDialog::AppendToDOMDocument(IXMLDOMDocument2* xmlDoc, IXMLDOMElement* parentElement)
{
	IXMLDOMElement* newElement;
	bool ret;
	HRESULT hr;

	hr = xmlDoc->createElement(CComBSTR((const TCHAR*)GetXmlNodeName()), &newElement);

	ret = CXmlBaseElement::AppendToDOMDocument(xmlDoc, newElement);
	if (!ret)
		return false;

	AppendMemberNode(_T("IconFileName"), iconFileName_, newElement, xmlDoc);
	AppendMemberNode(_T("InitialSize"), initialSize_, newElement, xmlDoc);
	AppendMemberNode(_T("Caption"), caption_, newElement, xmlDoc);
	AppendMemberNode(_T("SplitterPos"), splitterPos_, newElement, xmlDoc);
	treeSettings_.AppendToDOMDocument(xmlDoc, newElement);

	// append node to parent element
	//
	IXMLDOMNode* outNewElement;

	if (parentElement)
		hr = parentElement->appendChild(newElement, &outNewElement);
	else
		hr = xmlDoc->appendChild(newElement, &outNewElement);

	return ret;
}

void CXmlMainDialog::Clear()
{
	SetDefaults();
}


void CXmlMainDialog::SetInitialSize(enMainDlgSize initialSize)
{
	initialSize_ = initialSize;
}

enMainDlgSize CXmlMainDialog::GetInitialSize() const
{
	return initialSize_;
}

void CXmlMainDialog::SetCaption(const cmString& caption)
{
	caption_ = caption;
}

cmString CXmlMainDialog::GetCaption() const
{
	return caption_;
}

void CXmlMainDialog::SetSplitterPos(int splitterPos)
{
	splitterPos_ = splitterPos;
}

int CXmlMainDialog::GetSplitterPos() const
{
	return splitterPos_;
}

void CXmlMainDialog::SetDefaults()
{
	splitterPos_ = 30;					// set splitter pos to 30% of the main dialog width
	initialSize_ = enMainDlgSize_Small;	// 640x480
	caption_ = _T("");
	iconFileName_ = _T("");

	treeSettings_.SetDefaults();
}

void CXmlMainDialog::SetIconFileName(const cmString& fileName)
{
	iconFileName_ = fileName;
}

cmString CXmlMainDialog::GetIconFileName() const
{
	return iconFileName_;
}

CXmlMainDialogTree* CXmlMainDialog::GetTreeSettings()
{
	return &treeSettings_;
}

