Пример #1
0
	BUIWidget* BUIWidgetBuilder::create(BUIWidget* parent)
	{
		CMarkupNode& root = m_xml.GetRoot();
		// 解析图片,字体等相关资源属性
		for (CMarkupNode node = root.GetChild(); node.IsValid(); node = node.GetSibling()) {
			itemParse(&node);
		}

		// 解析window相关属性
		itemParse(&root);

		return parse(&root, parent);
	}
Пример #2
0
/*
<MSGTYPE TYPE="NOMALMSG">
	<WHO NAME="ME" />
	<TOWHO NAME="YOU" />
	<MSG CONTEXT="hello,this is a test" />
	<TTIME TIME="2012-06-21 13:26:30" />
</MSGTYPE>
*/
void CMsg::BuildNomal()
{
	CMarkup m_xml(m_strText);
	CMarkupNode root = m_xml.GetRoot(); 
	if( !root.IsValid() ) return ;
	LPCTSTR pstrClass = NULL;
	LPCTSTR pstrName = NULL;
	LPCTSTR pstrValue = NULL;
	for(CMarkupNode node=root.GetChild();node.IsValid();node=node.GetSibling())
	{
		pstrClass = node.GetName();
		if(_tcscmp(pstrClass, _T("WHO")) == 0 )
		{
			pstrName = node.GetAttributeName(0);
			if(_tcscmp(pstrName, _T("NAME")) == 0 )
			{
				pstrValue = node.GetAttributeValue(0);
				m_nomalMsg.who = pstrValue;
			}
		}
		if(_tcscmp(pstrClass, _T("TOWHO")) == 0 )
		{
			pstrName = node.GetAttributeName(0);
			if(_tcscmp(pstrName, _T("NAME")) == 0 )
			{
				pstrValue = node.GetAttributeValue(0);
				m_nomalMsg.toWho = pstrValue;
			}
		}
		if(_tcscmp(pstrClass, _T("MSG")) == 0 )
		{
			pstrName = node.GetAttributeName(0);
			if(_tcscmp(pstrName, _T("CONTEXT")) == 0 )
			{
				pstrValue = node.GetAttributeValue(0);
				m_nomalMsg.msgItem = pstrValue;
			}
		}
		if(_tcscmp(pstrClass, _T("TTIME")) == 0 )
		{
			pstrName = node.GetAttributeName(0);
			if(_tcscmp(pstrName, _T("TIME")) == 0 )
			{
				pstrValue = node.GetAttributeValue(0);
				m_nomalMsg.sndTime = pstrValue;
			}
		}
	}
}
Пример #3
0
	BUIWidget* BUIWidgetBuilder::parse(CMarkupNode* pRoot, BUIWidget* parent)
	{
		BUIWidget* pWidget = NULL;
		for (CMarkupNode node = pRoot->GetChild(); node.IsValid(); node = node.GetSibling()) {
			LPCTSTR nodeName = node.GetName();
			// 资源解析已完成,这里直接跳过
			RESPARSEMAPIT it = s_resoureParseMap.find(nodeName);
			if (it != s_resoureParseMap.end()) {
				continue;
			}

			bstring className = _T("BUI");
			className.append(nodeName);
			BUIWidget* newWidget = BUIWidgetFactory::GetInstance()->CreateWidget(className.c_str());
			assert(newWidget);

			// Init default attributes
			if (m_pWindowManager) {
				newWidget->SetManager(m_pWindowManager, NULL);
				/*LPCTSTR pDefaultAttributes = m_pWindowManager->GetDefaultAttributeList(pstrClass);
				if( pDefaultAttributes ) {
					pControl->ApplyAttributeList(pDefaultAttributes);
				}*/
			}

			if (node.HasAttributes()) {
				int nAttributes = node.GetAttributeCount();
				for (int i = 0; i < nAttributes; i++) 
				{
					newWidget->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i));
				}
			}

			if (node.HasChildren()) {
				parse(&node, newWidget);
			}

			if (parent != NULL ) {
				BUIContainer* pContainer = static_cast<BUIContainer*>(parent->GetInterface(_T("Container")));
				assert(pContainer);
				if (pContainer == NULL)
					return NULL;

				if(!pContainer->Add(newWidget)) {
					delete newWidget;
					continue;
				}
			}

			if (pWidget == NULL) 
				pWidget = newWidget;
		}
		return pWidget;
	}
Пример #4
0
CControlUI* CDialogBuilder::Create(const char* xml, CPaintManagerUI* pManager, CControlUI* pParent)
{
	if (!m_xml.LoadFromFile(xml)) return NULL;
	
	CMarkupNode root = m_xml.GetRoot();
	if (!root.IsValid()) return NULL;
	if (pManager)
	{
		LPCTSTR pstrClass = NULL;
		LPCTSTR pstrName = NULL;
		LPCTSTR pstrValue = NULL;
		pstrClass = root.GetName();
		if (strcmp(pstrClass, _T("Window")) == 0) {
			if (pManager->GetPaintWindow()) {
				int nAttributes = root.GetAttributeCount();
				for (int i = 0; i < nAttributes; i++) {
					pstrName = root.GetAttributeName(i);
					pstrValue = root.GetAttributeValue(i);
					pManager->SetWindowAttribute(pstrName, pstrValue);
				}
			}
		}
	}
	return _Parse(&root, pParent, pManager);
}
Пример #5
0
/*
<MSGTYPE TYPE="SYSTEMMSG">
	<WHO NAME="ME" />
	<TOWHO NAME="YOU" />
	<MSG CONTEXT="hello,this is a test" />
	<TTIME TIME="2012-06-21 13:26:30" />
</MSGTYPE>
*/
CString CMsg::WhatType()
{
//	DUI__Trace(m_strText);
	CMarkup m_xml(m_strText);
	CString preType(MSGTYPE::NULLMSG);
	CMarkupNode root = m_xml.GetRoot(); //tag = <MSGTYPE TYPE="">
	if( !root.IsValid() ) return preType;
	LPCTSTR pstrClass = NULL;
	int nAttributes = 0;
	LPCTSTR pstrName = NULL;
	LPCTSTR pstrValue = NULL;
	LPTSTR pstr = NULL;
	pstrClass = root.GetName();
	if(_tcscmp(pstrClass, _T("MSGTYPE")) != 0 )
		return preType;
	nAttributes = root.GetAttributeCount();
	if(nAttributes==0) return preType;
	pstrName = root.GetAttributeName(0);
	pstrValue = root.GetAttributeValue(0);
	if(_tcscmp(pstrName, _T("TYPE")) == 0 )
		preType = pstrValue;
	return preType;
}
Пример #6
0
	BOOL CResourceManager::LoadResource(CMarkupNode Root)
	{
		if( !Root.IsValid() ) return FALSE;

		LPCTSTR pstrClass = NULL;
		int nAttributes = 0;
		LPCTSTR pstrName = NULL;
		LPCTSTR pstrValue = NULL;
		LPTSTR pstr = NULL;

		//╪стьм╪ф╛вйт╢
		LPCTSTR pstrId = NULL;
		LPCTSTR pstrPath = NULL;
		for( CMarkupNode node = Root.GetChild() ; node.IsValid(); node = node.GetSibling() ) 
		{
			pstrClass = node.GetName();
			CMarkupNode ChildNode = node.GetChild();
			if(ChildNode.IsValid()) LoadResource(node);
			else if ((_tcsicmp(pstrClass,_T("Image")) == 0) && node.HasAttributes())
			{
				//╪стьм╪ф╛вйт╢
				nAttributes = node.GetAttributeCount();
				for( int i = 0; i < nAttributes; i++ ) 
				{
					pstrName = node.GetAttributeName(i);
					pstrValue = node.GetAttributeValue(i);

					if( _tcsicmp(pstrName, _T("id")) == 0 ) 
					{
						pstrId = pstrValue;
					}
					else if( _tcsicmp(pstrName, _T("path")) == 0 ) 
					{
						pstrPath = pstrValue;
					}
				}
				if( pstrId == NULL ||  pstrPath == NULL) continue;
				CDuiString * pstrFind = static_cast<CDuiString *>(m_mImageHashMap.Find(pstrId));
				if(pstrFind != NULL) continue;
				m_mImageHashMap.Insert(pstrId, (LPVOID)new CDuiString(pstrPath));
			}
			else if( _tcsicmp(pstrClass,_T("Xml")) == 0 && node.HasAttributes()) {
				//╪стьXMLеДжцнд╪Ч
				nAttributes = node.GetAttributeCount();
				for( int i = 0; i < nAttributes; i++ ) 
				{
					pstrName = node.GetAttributeName(i);
					pstrValue = node.GetAttributeValue(i);

					if( _tcsicmp(pstrName, _T("id")) == 0 ) 
					{
						pstrId = pstrValue;
					}
					else if( _tcsicmp(pstrName, _T("path")) == 0 ) 
					{
						pstrPath = pstrValue;
					}
				}
				if( pstrId == NULL ||  pstrPath == NULL) continue;
				CDuiString * pstrFind = static_cast<CDuiString *>(m_mXmlHashMap.Find(pstrId));
				if(pstrFind != NULL) continue;
				m_mXmlHashMap.Insert(pstrId, (LPVOID)new CDuiString(pstrPath));
			}
			else continue;
		}
		return TRUE;
	}
Пример #7
0
	BOOL CResourceManager::LoadLanguage(LPCTSTR pstrXml)
	{
		CMarkup xml;
		if( *(pstrXml) == _T('<') ) {
			if( !xml.Load(pstrXml) ) return FALSE;
		}
		else {
			if( !xml.LoadFromFile(pstrXml) ) return FALSE;
		}
		CMarkupNode Root = xml.GetRoot();
		if( !Root.IsValid() ) return FALSE;

		LPCTSTR pstrClass = NULL;
		int nAttributes = 0;
		LPCTSTR pstrName = NULL;
		LPCTSTR pstrValue = NULL;
		LPTSTR pstr = NULL;

		//¼ÓÔØͼƬ×ÊÔ´
		LPCTSTR pstrId = NULL;
		LPCTSTR pstrText = NULL;
		for( CMarkupNode node = Root.GetChild() ; node.IsValid(); node = node.GetSibling() ) 
		{
			pstrClass = node.GetName();
			if ((_tcsicmp(pstrClass,_T("Text")) == 0) && node.HasAttributes())
			{
				//¼ÓÔØͼƬ×ÊÔ´
				nAttributes = node.GetAttributeCount();
				for( int i = 0; i < nAttributes; i++ ) 
				{
					pstrName = node.GetAttributeName(i);
					pstrValue = node.GetAttributeValue(i);

					if( _tcsicmp(pstrName, _T("id")) == 0 ) 
					{
						pstrId = pstrValue;
					}
					else if( _tcsicmp(pstrName, _T("value")) == 0 ) 
					{
						pstrText = pstrValue;
					}
				}
				if( pstrId == NULL ||  pstrText == NULL) continue;

				CDuiString *lpstrFind = static_cast<CDuiString *>(m_mTextResourceHashMap.Find(pstrId));
				if(lpstrFind != NULL) {
					lpstrFind->Assign(pstrText);
				}
				else {
					m_mTextResourceHashMap.Insert(pstrId, (LPVOID)new CDuiString(pstrText));
				}
			}
			else continue;
		}

		return TRUE;
	}
Пример #8
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;
}
Пример #9
0
CControlUI* CDialogBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent)
{
   CDialogLayoutUI* pStretched = NULL;
   IContainerUI* pContainer = NULL;
   CControlUI* pReturn = NULL;
   for( CMarkupNode node = pRoot->GetChild() ; node.IsValid(); node = node.GetSibling() ) {
      LPCTSTR pstrClass = node.GetName();
      SIZE_T cchLen = _tcslen(pstrClass);
      CControlUI* pControl = NULL;
      switch( cchLen ) {
      case 4:
         if( _tcscmp(pstrClass, _T("List")) == 0 )                  pControl = new CListUI;
         break;
      case 6:
         if( _tcscmp(pstrClass, _T("Canvas")) == 0 )                pControl = new CCanvasUI;
         else if( _tcscmp(pstrClass, _T("Button")) == 0 )           pControl = new CButtonUI;
         else if( _tcscmp(pstrClass, _T("Option")) == 0 )           pControl = new COptionUI;
         break;
      case 7:
         if( _tcscmp(pstrClass, _T("Toolbar")) == 0 )               pControl = new CToolbarUI;
         else if( _tcscmp(pstrClass, _T("TabPage")) == 0 )          pControl = new CTabPageUI;
         else if( _tcscmp(pstrClass, _T("ActiveX")) == 0 )          pControl = new CActiveXUI;
         break;
      case 8:
         if( _tcscmp(pstrClass, _T("DropDown")) == 0 )              pControl = new CDropDownUI;
         break;
      case 9:
         if( _tcscmp(pstrClass, _T("FadedLine")) == 0 )             pControl = new CFadedLineUI;      
         else if( _tcscmp(pstrClass, _T("TaskPanel")) == 0 )        pControl = new CTaskPanelUI;
         else if( _tcscmp(pstrClass, _T("Statusbar")) == 0 )        pControl = new CStatusbarUI;
         else if( _tcscmp(pstrClass, _T("TabFolder")) == 0 )        pControl = new CTabFolderUI;
         else if( _tcscmp(pstrClass, _T("TextPanel")) == 0 )        pControl = new CTextPanelUI;
         break;
      case 10:
         if( _tcscmp(pstrClass, _T("ListHeader")) == 0 )            pControl = new CListHeaderUI;
         else if( _tcscmp(pstrClass, _T("ListFooter")) == 0 )       pControl = new CListFooterUI;
         else if( _tcscmp(pstrClass, _T("TileLayout")) == 0 )       pControl = new CTileLayoutUI;
         else if( _tcscmp(pstrClass, _T("ToolButton")) == 0 )       pControl = new CToolButtonUI;
         else if( _tcscmp(pstrClass, _T("ImagePanel")) == 0 )       pControl = new CImagePanelUI;
         else if( _tcscmp(pstrClass, _T("LabelPanel")) == 0 )       pControl = new CLabelPanelUI;
         break;
      case 11:
         if( _tcscmp(pstrClass, _T("ToolGripper")) == 0 )           pControl = new CToolGripperUI;
         else if( _tcscmp(pstrClass, _T("WhiteCanvas")) == 0 )      pControl = new CWhiteCanvasUI;
         else if( _tcscmp(pstrClass, _T("TitleShadow")) == 0 )      pControl = new CTitleShadowUI;
         break;
      case 12:
         if( _tcscmp(pstrClass, _T("WindowCanvas")) == 0 )          pControl = new CWindowCanvasUI;
         else if( _tcscmp(pstrClass, _T("DialogCanvas")) == 0 )     pControl = new CDialogCanvasUI;
         else if( _tcscmp(pstrClass, _T("DialogLayout")) == 0 )     pControl = new CDialogLayoutUI;
         else if( _tcscmp(pstrClass, _T("PaddingPanel")) == 0 )     pControl = new CPaddingPanelUI;
         else if( _tcscmp(pstrClass, _T("WarningPanel")) == 0 )     pControl = new CWarningPanelUI;
         break;
      case 13:
         if( _tcscmp(pstrClass, _T("SeparatorLine")) == 0 )         pControl = new CSeparatorLineUI;
         else if( _tcscmp(pstrClass, _T("ControlCanvas")) == 0 )    pControl = new CControlCanvasUI;
         else if( _tcscmp(pstrClass, _T("MultiLineEdit")) == 0 )    pControl = new CMultiLineEditUI;
         else if( _tcscmp(pstrClass, _T("ToolSeparator")) == 0 )    pControl = new CToolSeparatorUI;
         break;
      case 14:
         if( _tcscmp(pstrClass, _T("VerticalLayout")) == 0 )        pControl = new CVerticalLayoutUI;
         else if( _tcscmp(pstrClass, _T("SingleLineEdit")) == 0 )   pControl = new CSingleLineEditUI;
         else if( _tcscmp(pstrClass, _T("SingleLinePick")) == 0 )   pControl = new CSingleLinePickUI;
         else if( _tcscmp(pstrClass, _T("NavigatorPanel")) == 0 )   pControl = new CNavigatorPanelUI;
         else if( _tcscmp(pstrClass, _T("ListHeaderItem")) == 0 )   pControl = new CListHeaderItemUI;
         else if( _tcscmp(pstrClass, _T("GreyTextHeader")) == 0 )   pControl = new CGreyTextHeaderUI;
         break;
      case 15:
         if( _tcscmp(pstrClass, _T("ListTextElement")) == 0 )       pControl = new CListTextElementUI;
         else if( _tcscmp(pstrClass, _T("NavigatorButton")) == 0 )  pControl = new CNavigatorButtonUI;      
         else if( _tcscmp(pstrClass, _T("TabFolderCanvas")) == 0 )  pControl = new CTabFolderCanvasUI;      
         break;
      case 16:
         if( _tcscmp(pstrClass, _T("ListHeaderShadow")) == 0 )      pControl = new CListHeaderShadowUI; 
         else if( _tcscmp(pstrClass, _T("HorizontalLayout")) == 0 ) pControl = new CHorizontalLayoutUI;
         else if( _tcscmp(pstrClass, _T("ListLabelElement")) == 0 ) pControl = new CListLabelElementUI;
         else if( _tcscmp(pstrClass, _T("SearchTitlePanel")) == 0 ) pControl = new CSearchTitlePanelUI;
         break;
      case 17:
         if( _tcscmp(pstrClass, _T("ToolbarTitlePanel")) == 0 )  pControl = new CToolbarTitlePanelUI;
         else if( _tcscmp(pstrClass, _T("ListExpandElement")) == 0 ) pControl = new CListExpandElementUI;
         break;
      }
      // User-supplied control factory
      if( pControl == NULL && m_pCallback != NULL ) {
         pControl = m_pCallback->CreateControl(pstrClass);
      }
      ASSERT(pControl);
      if( pControl == NULL ) return NULL;
      // Add children
      if( node.HasChildren() ) {
         _Parse(&node, pControl);
      }
      // Attach to parent
      if( pParent != NULL ) {
         if( pContainer == NULL ) pContainer = static_cast<IContainerUI*>(pParent->GetInterface(_T("Container")));
         ASSERT(pContainer);
         if( pContainer == NULL ) return NULL;
         pContainer->Add(pControl);
      }
      // Process attributes
      if( node.HasAttributes() ) {
         TCHAR szValue[500] = { 0 };
         SIZE_T cchLen = lengthof(szValue) - 1;
         // Set ordinary attributes
         int nAttributes = node.GetAttributeCount();
         for( int i = 0; i < nAttributes; i++ ) {
            pControl->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i));
         }
         // Very custom attributes
         if( node.GetAttributeValue(_T("stretch"), szValue, cchLen) ) {
            if( pStretched == NULL ) pStretched = static_cast<CDialogLayoutUI*>(pParent->GetInterface(_T("DialogLayout")));
            ASSERT(pStretched);
            if( pStretched == NULL ) return NULL;
            UINT uMode = 0;
            if( _tcsstr(szValue, _T("move_x")) != NULL ) uMode |= UISTRETCH_MOVE_X;
            if( _tcsstr(szValue, _T("move_y")) != NULL ) uMode |= UISTRETCH_MOVE_Y;
            if( _tcsstr(szValue, _T("move_xy")) != NULL ) uMode |= UISTRETCH_MOVE_X | UISTRETCH_MOVE_Y;
            if( _tcsstr(szValue, _T("size_x")) != NULL ) uMode |= UISTRETCH_SIZE_X;
            if( _tcsstr(szValue, _T("size_y")) != NULL ) uMode |= UISTRETCH_SIZE_Y;
            if( _tcsstr(szValue, _T("size_xy")) != NULL ) uMode |= UISTRETCH_SIZE_X | UISTRETCH_SIZE_Y;
            if( _tcsstr(szValue, _T("group")) != NULL ) uMode |= UISTRETCH_NEWGROUP;
            if( _tcsstr(szValue, _T("line")) != NULL ) uMode |= UISTRETCH_NEWLINE;
            pStretched->SetStretchMode(pControl, uMode);
         }
      }
      // Return first item
      if( pReturn == NULL ) pReturn = pControl;
   }
   return pReturn;
}