Exemplo n.º 1
0
CControlUI* CDialogBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintManagerUI* pManager)
{
	CControlUI* pReturn = NULL;
	for (CMarkupNode node = pRoot->GetChild(); node.IsValid(); node = node.GetSibling())
	{
		LPCTSTR pstrClass = node.GetName();
		CControlUI* pControl = NULL;
		if (strcmp(pstrClass, _T("Include")) == 0) 
		{
			if (!node.HasAttributes()) continue;
		}
		else if (strcmp(pstrClass, _T("TreeNode")) == 0)
		{

		}
		else
		{
			SIZE_T cchLen = strlen(pstrClass);
			switch (cchLen)
			{
			case 5:
				if (strcmp(pstrClass, DUI_CTR_LABEL) == 0)             pControl = new CLabelUI;
				break;
			case 9:
				if (strcmp(pstrClass, DUI_CTR_CONTAINER) == 0)             pControl = new CContainerUI;
				break;
			case 7:
				if (strcmp(pstrClass, DUI_CTR_CONTROL) == 0)               pControl = new CControlUI;
			}
		}
		if (pControl == NULL)
			continue;

		if (node.HasChildren()) 
		{
			_Parse(&node, pControl, pManager);
		}
		if (pParent != NULL)
		{
			if (pParent->GetClass() == DUI_CTR_CONTAINER)
			{
				IContainerUI* pContainer = static_cast<IContainerUI*>(pParent->GetInterface(DUI_CTR_ICONTAINER));
				pContainer->Add(pControl);
			}
		}
		if (node.HasAttributes()) {
			// Set ordinary attributes
			int nAttributes = node.GetAttributeCount();
			for (int i = 0; i < nAttributes; i++) {
				pControl->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i));
			}
		}

		if (pManager) 
		{
			pControl->SetManager(pManager, pParent, false);
		}

		if (pReturn == NULL) pReturn = pControl;
	}
	return pReturn;
}