#include "xmlmessageframe.h"

// ----------------------------------------------------------------------------
CXmlMessageFrame::CXmlMessageFrame(CXmlUi* pXmlUi, CXmlLayout* pParent)
	: CXmlFrame(pXmlUi, pParent)
{
	m_type				= eXmlUiType_MessageFrame;

	m_fontString		= NULL;
	m_isFade			= true;
	m_fadeDuration		= 3.0f;
	m_displayDuration	= 10.0f;
	m_maxLines			= 10;
}

// ----------------------------------------------------------------------------
CXmlMessageFrame::~CXmlMessageFrame()
{
	XML_SAFE_DLETE(m_fontString);
}

// ----------------------------------------------------------------------------
void CXmlMessageFrame::LoadNodeAttribute(const DOMNamedNodeMap* nodeMap)
{
	CXmlFrame::LoadNodeAttribute(nodeMap);

	const XMLCh* nodeValue;
	if ( (nodeValue = GetNodeAttribute(nodeMap, "fade")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_isFade = XmlValueToBoolean(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "fadeDuration")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_fadeDuration = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "displayDuration")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_displayDuration = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "maxLines")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_maxLines = atoi(tmpStr);
		XMLString::release(&tmpStr);
	}
}

// ----------------------------------------------------------------------------
void CXmlMessageFrame::LoadNodeElement(const DOMNode* node, const char* nodeName)
{
	CXmlFrame::LoadNodeElement(node, nodeName);

	// FontString
	if ( XMLString::compareString(nodeName, "FontString") == 0 )
	{
		XML_SAFE_DLETE(m_fontString);
		m_fontString = new CXmlFontString(m_pXmlUi, this);
		m_fontString->LoadFromDOMNode(node);
	}
	// Text Insets
	else if ( XMLString::compareString(nodeName, "TextInsets") == 0 )
	{
		m_textInsets.LoadFromDOMNode(node);
	}
}

// ----------------------------------------------------------------------------
void CXmlMessageFrame::Inherit(CXmlLayout* pXmlLayout)
{
	CXmlFrame::Inherit(pXmlLayout);
	CXmlMessageFrame* pXmlMessageFrame = dynamic_cast<CXmlMessageFrame*>(pXmlLayout);
	if (pXmlMessageFrame)
	{
		if (pXmlMessageFrame->m_fontString)
		{
			XML_SAFE_DLETE(m_fontString);
			m_fontString = new CXmlFontString(m_pXmlUi, this);
			m_fontString->Inherit(pXmlMessageFrame->m_fontString);
		}

		m_textInsets		= pXmlMessageFrame->m_textInsets;
		m_isFade			= pXmlMessageFrame->m_isFade;
		m_fadeDuration		= pXmlMessageFrame->m_fadeDuration;
		m_displayDuration	= pXmlMessageFrame->m_displayDuration;
		m_maxLines			= pXmlMessageFrame->m_maxLines;
	}
}