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

#include "stdafx.h"
#include "XmlMainDialogTree.h"

CXmlMainDialogTree::CXmlMainDialogTree()
{
	SetDefaults();
}

CXmlMainDialogTree::~CXmlMainDialogTree()
{}

bool CXmlMainDialogTree::BuildFromXml(IXMLDOMNode* node)
{
	Clear();
	
	ExtractMemberNode(node, _T("HideRootNode"), hideRootNode_);
	ExtractMemberNode(node, _T("SingleNodeExpand"), singleNodeExpand_);
	ExtractMemberNode(node, _T("HasButtons"), hasButtons_);
	ExtractMemberNode(node, _T("HasLines"), hasLines_);
	ExtractMemberNode(node, _T("FullRowSelect"), fullRowSelect_);
	ExtractMemberNode(node, _T("ShowSelectionAlways"), showSelectionAlways_);
	ExtractMemberNode(node, _T("LinesAtRoot"), linesAtRoot_);
	ExtractMemberNode(node, _T("Indent"), (int&)indent_);
	
	return true;
}

bool CXmlMainDialogTree::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("HideRootNode"), hideRootNode_, newElement, xmlDoc);
	AppendMemberNode(_T("SingleNodeExpand"), singleNodeExpand_, newElement, xmlDoc);
	AppendMemberNode(_T("HasButtons"), hasButtons_, newElement, xmlDoc);
	AppendMemberNode(_T("HasLines"), hasLines_, newElement, xmlDoc);
	AppendMemberNode(_T("FullRowSelect"), fullRowSelect_, newElement, xmlDoc);
	AppendMemberNode(_T("ShowSelectionAlways"), showSelectionAlways_, newElement, xmlDoc);
	AppendMemberNode(_T("LinesAtRoot"), linesAtRoot_, newElement, xmlDoc);
	AppendMemberNode(_T("Indent"), indent_, newElement, xmlDoc);

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

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

	return ret;
}

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

void CXmlMainDialogTree::SetDefaults()
{
	hideRootNode_ = false;
	singleNodeExpand_ = false;
	hasButtons_ = true;
	hasLines_ = true;
	fullRowSelect_= false;
	showSelectionAlways_ = true;
	linesAtRoot_ = true;

	indent_ = 20;
}

void CXmlMainDialogTree::SetHideRootNode(bool hide)
{
	hideRootNode_ = hide;
}

bool CXmlMainDialogTree::GetHideRootNode() const
{
	return hideRootNode_;
}

void CXmlMainDialogTree::SetSingleNodeExpand(bool expand)
{
	singleNodeExpand_ = expand;
}

bool CXmlMainDialogTree::GetSingleNodeExpand() const
{
	return singleNodeExpand_;
}

void CXmlMainDialogTree::SetHasButtons(bool hasButtons)
{
	hasButtons_ = hasButtons;
}

bool CXmlMainDialogTree::GetHasButtons() const
{
	return hasButtons_;
}

void CXmlMainDialogTree::SetHasLines(bool hasLines)
{
	hasLines_ = hasLines;
}

bool CXmlMainDialogTree::GetHasLines() const
{
	return hasLines_;
}

void CXmlMainDialogTree::SetFullRowSelect(bool select)
{
	fullRowSelect_ = select;
}

bool CXmlMainDialogTree::GetFullRowSelect() const
{
	return fullRowSelect_;
}

void CXmlMainDialogTree::SetShowSelectionAlways(bool showSelection)
{
	showSelectionAlways_ = showSelection;
}

bool CXmlMainDialogTree::GetShowSelectionAlways() const
{
	return showSelectionAlways_;
}

void CXmlMainDialogTree::SetIndent(int indent)
{
	indent_ = indent;
}

int CXmlMainDialogTree::GetIndent() const
{
	return indent_;
}

void CXmlMainDialogTree::SetLinesAtRoot(bool value)
{
	linesAtRoot_ = value;
}

bool CXmlMainDialogTree::GetLinesAtRoot() const
{
	return linesAtRoot_;
}


