#include "xmleditbox.h"

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

	m_fontString		= NULL;
	m_letters			= 255;
	m_historyLines		= 0;
	m_isNumeric			= false;
	m_isPassword		= false;
	m_isMultiLine		= false;
	m_isAutoFocus		= true;
}

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

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

	const XMLCh* nodeValue;
	if ( (nodeValue = GetNodeAttribute(nodeMap, "letters")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_letters = atoi(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "historyLines")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_historyLines = atoi(tmpStr);
		XMLString::release(&tmpStr);
	}		
	if ( (nodeValue = GetNodeAttribute(nodeMap, "numeric")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_isNumeric = XmlValueToBoolean(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "password")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_isPassword = XmlValueToBoolean(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "multiLine")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_isMultiLine = XmlValueToBoolean(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "autoFocus")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_isAutoFocus = XmlValueToBoolean(tmpStr);
		XMLString::release(&tmpStr);
	}
}

// ----------------------------------------------------------------------------
void CXmlEditBox::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);
	}
	// Highlight Color
	else if ( XMLString::compareString(nodeName, "HighlightColor") == 0 )
	{
		m_highlightColor.LoadFromDOMNode(node);
	}
	// Text Insets
	else if ( XMLString::compareString(nodeName, "TextInsets") == 0 )
	{
		m_textInsets.LoadFromDOMNode(node);
	}
}

// ----------------------------------------------------------------------------
void CXmlEditBox::Inherit(CXmlLayout* pXmlLayout)
{
	CXmlFrame::Inherit(pXmlLayout);
	CXmlEditBox* pXmlEditBox = dynamic_cast<CXmlEditBox*>(pXmlLayout);
	if (pXmlEditBox)
	{
		if (pXmlEditBox->m_fontString)
		{
			XML_SAFE_DLETE(m_fontString);
			m_fontString = new CXmlFontString(m_pXmlUi, this);
			m_fontString->Inherit(pXmlEditBox->m_fontString);
		}
				
		m_textInsets		= pXmlEditBox->m_textInsets;
		m_highlightColor	= pXmlEditBox->m_highlightColor;
		m_historyLines		= pXmlEditBox->m_historyLines;
		m_letters			= pXmlEditBox->m_letters;
		m_isNumeric			= pXmlEditBox->m_isNumeric;
		m_isPassword		= pXmlEditBox->m_isPassword;
		m_isMultiLine		= pXmlEditBox->m_isMultiLine;
		m_isAutoFocus		= pXmlEditBox->m_isAutoFocus;
	}
}