// XmlMemberGui_Long.cpp: implementation of the CXmlMemberGui_Long class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "XmlMemberGui_Long.h"
#include "XmlBaseElement.h"

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

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

CXmlMemberGui_Long::CXmlMemberGui_Long():
	hexBitCount_(32),
	displayMode_(enLongMemberDisplayMode_None)
{
}

CXmlMemberGui_Long::~CXmlMemberGui_Long()
{
	Clear();
}

void CXmlMemberGui_Long::Clear()
{
	displayMode_ = enLongMemberDisplayMode_None;
}

bool CXmlMemberGui_Long::BuildFromXml(IXMLDOMNode* node)
{
	Clear();
	
	ExtractMemberNode(node, _T("DisplayMode"), (int&)displayMode_);	
	ExtractMemberNode(node, _T("HexBitCount"), hexBitCount_);
		
	return true;
}

bool CXmlMemberGui_Long::AppendToDOMDocument(IXMLDOMDocument2* xmlDoc, IXMLDOMElement* parentElement)
{
	IXMLDOMElement* newElement;
	map<cmString, cmString>::iterator it;
	HRESULT hr;

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

	AppendMemberNode(_T("DisplayModeStr"), CXmlBaseElement::LongMemberDisplayMode2String(displayMode_), newElement, xmlDoc);
	AppendMemberNode(_T("DisplayMode"), (int)displayMode_, newElement, xmlDoc);
	
	if (displayMode_ == enLongMemberDisplayMode_Hex) {
		AppendMemberNode(_T("HexBitCount"), hexBitCount_, newElement, xmlDoc);
	}

	IXMLDOMNode* newOutNode;

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

	return true;
}

void CXmlMemberGui_Long::SetDisplayMode(enLongMemberDisplayMode displayMode)
{
	displayMode_ = displayMode;
}

enLongMemberDisplayMode CXmlMemberGui_Long::GetDisplayMode() const
{
	return displayMode_;
}

void CXmlMemberGui_Long::SetDefaults()
{
	displayMode_ = enLongMemberDisplayMode_None;
}

void CXmlMemberGui_Long::SetHexBitCount(long count)
{
	hexBitCount_ = count;
}

long CXmlMemberGui_Long::GetHexBitCount() const
{
	return hexBitCount_;
}