#include "xmlstatusbar.h"

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

	m_barTexture		= NULL;
	m_minValue			= 0;
	m_maxValue			= 0;
	m_defaultValue		= 0;
}

// ----------------------------------------------------------------------------
CXmlStatusBar::~CXmlStatusBar()
{
	XML_SAFE_DLETE(m_barTexture);
}

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

	const XMLCh* nodeValue;
	if ( (nodeValue = GetNodeAttribute(nodeMap, "minValue")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_minValue = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "maxValue")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_maxValue = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "defaultValue")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_defaultValue = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
}

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

	// Bar Texture
	if ( XMLString::compareString(nodeName, "BarTexture") == 0 )
	{
		XML_SAFE_DLETE(m_barTexture);
		m_barTexture = new CXmlTexture(m_pXmlUi, this);
		m_barTexture->LoadFromDOMNode(node);
	}
	// Bar Color
	if ( XMLString::compareString(nodeName, "BarColor") == 0 )
	{
		m_barColor.LoadFromDOMNode(node);
	}
}

// ----------------------------------------------------------------------------
void CXmlStatusBar::Inherit(CXmlLayout* pXmlLayout)
{
	CXmlFrame::Inherit(pXmlLayout);
	CXmlStatusBar* pXmlStatusBar = dynamic_cast<CXmlStatusBar*>(pXmlLayout);
	if (pXmlStatusBar)
	{
		if (pXmlStatusBar->m_barTexture)
		{
			XML_SAFE_DLETE(m_barTexture);
			m_barTexture = new CXmlTexture(m_pXmlUi, this);
			m_barTexture->Inherit(pXmlStatusBar->m_barTexture);
		}

		m_barColor		= pXmlStatusBar->m_barColor;
		m_minValue		= pXmlStatusBar->m_minValue;
		m_maxValue		= pXmlStatusBar->m_maxValue;
		m_defaultValue	= pXmlStatusBar->m_defaultValue;
	}
}