// 初始化窗口控件 void CDuiPanel::InitUI(CRect rcClient, DuiXmlNode pNode) { CRect rcTemp; int nStartX = 0; int nStartY = 0; CControlBase * pControlBase = NULL; // 加载所有窗口控件 if(pNode) { m_nVirtualHeight = 0; m_nVirtualWidth = 0; for (DuiXmlNode pControlElem = pNode.first_child(); pControlElem; pControlElem=pControlElem.next_sibling()) { if(pControlElem != NULL) { CString strControlName = pControlElem.name(); CControlBase* pControl = _CreateControlByName(strControlName); if(pControl) { pControl->Load(pControlElem); if(pControl->IsClass(CArea::GetClassName())) { // Area不能响应鼠标,必须加到Area列表中 m_vecArea.push_back(pControl); }else { m_vecControl.push_back(pControl); } CRect rcCtrl = pControl->GetRect(); if(rcCtrl.bottom > m_nVirtualHeight) { m_nVirtualHeight = rcCtrl.bottom - m_rc.top; } if(rcCtrl.right > m_nVirtualWidth) { m_nVirtualWidth = rcCtrl.right - m_rc.left; } } } } // 需要的总高度大于显示区高度才会显示垂直滚动条 m_pControScrollV->SetVisible(m_nVirtualHeight > m_rc.Height()); ((CDuiScrollVertical*)m_pControScrollV)->SetScrollMaxRange(m_nVirtualHeight); // 需要的总宽度大于显示区宽度才会显示垂直滚动条 m_pControScrollH->SetVisible(m_nVirtualWidth > m_rc.Width()); ((CDuiScrollHorizontal*)m_pControScrollH)->SetScrollMaxRange(m_nVirtualWidth); } m_bInit = true; }
// 加载XML节点 BOOL CSelectBox::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { if(!__super::Load(pXmlElem)) { return FALSE; } // 使用XML节点初始化控件 if(pXmlElem != NULL) { // 加载图片和颜色列表 DuiXmlNode pControlElem; for (DuiXmlNode pControlElem = pXmlElem.child(_T("item")); pControlElem; pControlElem=pControlElem.next_sibling(_T("item"))) { CString strImage = pControlElem.attribute(_T("image")).value(); CString strColor = pControlElem.attribute(_T("color")).value(); if(!strImage.IsEmpty()) { if(strImage.Find(_T("skin:")) == 0) { } if(strImage.Find(_T(".")) != -1) // 加载图片文件 { CString strImgFile = DuiSystem::GetExePath() + strImage; SetBitmap(strImgFile); }else // 加载图片资源 { UINT nResourceID = _wtoi(strImage); if(!SetBitmap(nResourceID, -1, TEXT("PNG"))) { SetBitmap(nResourceID, -1, TEXT("BMP")); } } m_bImage = TRUE; }else if(!strColor.IsEmpty()) { Color color; if(strColor.Find(_T(",")) == -1) { color = HexStringToColor(strColor); }else { color = StringToColor(strColor); } SetColor(color); } } } return TRUE; }
// 加载XML节点,解析节点中的属性信息设置到当前控件的属性中 BOOL CDuiObject::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { // pos属性需要特殊处理,放在最后进行设置,否则有些属性会受到影响,不能正确的初始化 CString strPosValue = _T(""); for (DuiXmlAttribute pAttrib = pXmlElem.first_attribute(); pAttrib; pAttrib = pAttrib.next_attribute()) { CString strName = pAttrib.name(); if(strName == _T("pos")) { strPosValue = pAttrib.value(); }else { SetAttribute(pAttrib.name(), pAttrib.value(), TRUE); } } if(!strPosValue.IsEmpty()) { SetAttribute(_T("pos"), strPosValue, TRUE); } // 初始化 OnInit(); return TRUE; }
// 重载加载XML节点函数,加载下层的div内容 BOOL CDuiLayout::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { __super::Load(pXmlElem); if(pXmlElem == NULL) { return FALSE; } // 加载下层的div节点信息 for (DuiXmlNode pDivElem = pXmlElem.child(_T("layout-div")); pDivElem; pDivElem=pDivElem.next_sibling(_T("layout-div"))) { CString strDivPos = pDivElem.attribute(_T("div-pos")).value(); int nMinPos = _ttoi(pDivElem.attribute(_T("min-pos")).value()); int nMaxPos = _ttoi(pDivElem.attribute(_T("max-pos")).value()); // 创建div CDuiPanel* pControlPanel = (CDuiPanel*)DuiSystem::CreateControlByName(_T("div"), m_hWnd, this); m_vecControl.push_back(pControlPanel); // 加载XML中Tab节点的各个下层控件节点 pControlPanel->Load(pDivElem); LayoutItemInfo itemInfo; itemInfo.pControlPanel = pControlPanel; ParsePosition(strDivPos, itemInfo.pos); // 解析pos信息 itemInfo.nMinPos = nMinPos; itemInfo.nMaxPos = nMaxPos; itemInfo.nPos = -1; // 初始化实际的位置值 itemInfo.rcSplit = CRect(0, 0, 0, 0); // 初始化分割线区域 itemInfo.rcThumb = CRect(0, 0, 0, 0); // 初始化滑块区域 m_vecItemInfo.push_back(itemInfo); } // 初始化div中控件的位置 SetRect(m_rc); m_bInit = TRUE; return TRUE; }
// 初始化窗口控件 void CDlgPopup::InitUI(CRect rcClient, DuiXmlNode pNode) { CRect rcTemp; int nStartX = 0; int nStartY = 0; CControlBase * pControlBase = NULL; // 加载所有窗口控件 if(pNode) { for (DuiXmlNode pControlElem = pNode.first_child(); pControlElem; pControlElem=pControlElem.next_sibling()) { if(pControlElem) { CString strControlName = pControlElem.name(); CControlBase* pControl = _CreateControlByName(strControlName); if(pControl) { if(pControl->Load(pControlElem)) { // 如果Load成功,则添加控件 if(pControl->IsClass(CArea::GetClassName()) || pControl->IsClass(CFrame::GetClassName())) { // Area和Frame不能响应鼠标,必须加到Area列表中 m_vecArea.push_back(pControl); }else { m_vecControl.push_back(pControl); } }else { // 否则直接删除控件对象指针 delete pControl; } } } } } m_bInit = true; }
// 加载XML节点中定义的菜单和其他控件 BOOL CDuiMenu::LoadXmlNode(DuiXmlNode pXmlElem, CString strXmlFile) { if(pXmlElem == NULL) { return FALSE; } for (DuiXmlNode pControlElem = pXmlElem.first_child(); pControlElem; pControlElem=pControlElem.next_sibling()) { CString strControlName = pControlElem.name(); CControlBase* pControl = _CreateControlByName(strControlName); if(pControl) { if(pControl->Load(pControlElem)) { // 如果Load成功,则添加控件 if(pControl->IsClass(CArea::GetClassName()) || pControl->IsClass(CDuiFrame::GetClassName())) { // Area和Frame不能响应鼠标,必须加到Area列表中 m_vecArea.push_back(pControl); }else { m_vecControl.push_back(pControl); } // 如果是菜单项控件,则设置菜单项的菜单XML属性 if(pControl->IsClass(CMenuItem::GetClassName())) { ((CMenuItem*)pControl)->SetMenuXml(strXmlFile); } }else { // 否则直接删除控件对象指针 delete pControl; } } } return TRUE; }
// 加载XML节点 BOOL CPopupList::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { if(!__super::Load(pXmlElem)) { return FALSE; } // 使用XML节点初始化控件 if(pXmlElem != NULL) { // 加载图片和颜色列表 for (DuiXmlNode pControlElem = pXmlElem.child(_T("item")); pControlElem; pControlElem=pControlElem.next_sibling(_T("item"))) { UINT nResourceID = 0; CString strName = pControlElem.attribute(_T("name")).value(); DuiSystem::Instance()->ParseDuiString(strName); CString strDesc = pControlElem.attribute(_T("desc")).value(); DuiSystem::Instance()->ParseDuiString(strDesc); CString strValue = pControlElem.attribute(_T("value")).value(); DuiSystem::Instance()->ParseDuiString(strValue); CString strClrText = pControlElem.attribute(_T("crtext")).value(); Color clrText = CDuiObject::StringToColor(strClrText, Color(255, 0, 20, 35)); CString strClrDesc = pControlElem.attribute(_T("crdesc")).value(); Color clrDesc = CDuiObject::StringToColor(strClrDesc, Color(255, 255, 255, 255)); CString strImage = pControlElem.attribute(_T("image")).value(); if(!strImage.IsEmpty()) { if(strImage.Find(_T("skin:")) == 0) { strImage = DuiSystem::Instance()->GetSkin(strImage); } if(strImage.Find(_T(".")) != -1) // 加载图片文件 { //strImage = DuiSystem::GetExePath() + strImage; }else // 加载图片资源 { nResourceID = _ttoi(strImage); strImage = _T(""); } } AddItem(strName, strDesc, strValue, nResourceID, strImage, clrText, clrDesc); } } return TRUE; }
// 加载指定名字的菜单节点 BOOL CDuiMenu::LoadSubMenu(DuiXmlNode pXmlElem, CString strSubItemName) { if(pXmlElem == NULL) { return FALSE; } // 递归遍历下层节点,看是否有指定名字的节点 for (DuiXmlNode pItemElem = pXmlElem.first_child(); pItemElem; pItemElem=pItemElem.next_sibling()) { CString strName = pItemElem.attribute(_T("name")).value(); if(strSubItemName == strName) { // 加载子菜单 return Load(pItemElem); } if(LoadSubMenu(pItemElem, strSubItemName)) { // 如果递归加载成功则返回,否则继续向下遍历查找 return TRUE; } } return FALSE; }
// 重载加载XML节点函数,加载下层的item内容 BOOL CDuiComboBox::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { __super::Load(pXmlElem); if(pXmlElem == NULL) { return FALSE; } // 加载下层的item节点信息 for (DuiXmlNode pItemElem = pXmlElem.child(_T("item")); pItemElem; pItemElem=pItemElem.next_sibling(_T("item"))) { CString strName = pItemElem.attribute(_T("name")).value(); DuiSystem::Instance()->ParseDuiString(strName); CString strDesc = pItemElem.attribute(_T("desc")).value(); DuiSystem::Instance()->ParseDuiString(strDesc); CString strValue = pItemElem.attribute(_T("value")).value(); DuiSystem::Instance()->ParseDuiString(strValue); UINT nResourceID = 0; CString strImage = pItemElem.attribute(_T("image")).value(); if(!strImage.IsEmpty()) { if(strImage.Find(_T("skin:")) == 0) { strImage = DuiSystem::Instance()->GetSkin(strImage); } if(strImage.Find(_T(".")) == -1) // 加载图片资源 { nResourceID = _wtoi(strImage); strImage = _T(""); } } ComboListItem comboItem; comboItem.nResourceID = nResourceID; comboItem.strImageFile = strImage; comboItem.strName = strName; comboItem.strDesc = strDesc; comboItem.strValue = strValue; m_vecItem.push_back(comboItem); // 如果是当前值,则更新编辑框的显示内容 if(!strValue.IsEmpty() && (strValue == m_strComboValue)) { SetTitle(strName); } } return TRUE; }
// 重载加载XML节点函数,判断是否有子菜单 BOOL CMenuItem::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { BOOL bRet = __super::Load(pXmlElem); // 判断是否有定义子菜单 if(pXmlElem && (pXmlElem.first_child() != NULL)) { m_bIsPopup = TRUE; } // 如果是嵌套菜单(有menu属性),则通过调用父菜单的Load函数将嵌套菜单作为平级菜单加载 CDuiMenu* pParentMenu = GetParentMenu(); if(pParentMenu && !m_strMenuXml.IsEmpty()) { pParentMenu->LoadXmlFile(m_strMenuXml); // 如果是嵌套菜单,则返回FALSE,这样就不会创建此菜单项,只会创建嵌套菜单中定义的菜单项 return FALSE; } return bRet; }
// 重载加载XML节点函数,加载下层的tab页面内容 BOOL CDuiTabCtrl::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { __super::Load(pXmlElem); if(pXmlElem == NULL) { return FALSE; } // 如果没有设置tabctrl高度,则按照hover图片的高度 if((m_pImageHover != NULL) && (m_nTabCtrlHeight == 0)) { m_nTabCtrlHeight = m_sizeHover.cy; } // 如果没有设置tab项的宽度,则按照hover图片的宽度 if((m_pImageHover != NULL) && (m_nTabItemWidth == 0)) { m_nTabItemWidth = m_sizeHover.cx; } BOOL bAllVisible = TRUE; // 加载下层的tab页节点信息 int nIdIndex = m_vecItemInfo.size(); for (DuiXmlNode pTabElem = pXmlElem.child(_T("tab")); pTabElem; pTabElem=pTabElem.next_sibling(_T("tab"))) { CString strId = pTabElem.attribute(_T("id")).value(); int nId = nIdIndex; if(strId != _T("")) { nId = _wtoi(strId); } CString strName = pTabElem.attribute(_T("name")).value(); if(GetItemIndex(strName) != -1) { // 如果已经存在相同名字的tab页,则跳过 continue; } CString strTabXml = pTabElem.attribute(_T("tabxml")).value(); if(!strTabXml.IsEmpty()) { // 从xml文件加载嵌套的tab页 LoadTabXml(strTabXml); nIdIndex = m_vecItemInfo.size(); continue; } CString strAction = pTabElem.attribute(_T("action")).value(); CString strOutLink = pTabElem.attribute(_T("outlink")).value(); BOOL bOutLink = ((strOutLink == _T("1")) || (strOutLink == _T("true"))); CString strImage = pTabElem.attribute(_T("image")).value(); CString strImageIndex = pTabElem.attribute(_T("img-index")).value(); int nImageIndex = -1; if(!strImageIndex.IsEmpty()) { nImageIndex = _wtoi(strImageIndex); } CString strImageCount = pTabElem.attribute(_T("img-count")).value(); int nImageCount = -1; if(!strImageCount.IsEmpty()) { nImageCount = _wtoi(strImageCount); } // visible属性可以用visible或show CString strVisible = pTabElem.attribute(_T("visible")).value(); if(strVisible.IsEmpty()) { strVisible = pTabElem.attribute(_T("show")).value(); } BOOL bVisible = ((strVisible == _T("1")) || (strVisible == _T("true")) || (strVisible == _T(""))); CString strActive = pTabElem.attribute(_T("active")).value(); CString strDivXml = pTabElem.attribute(_T("div")).value(); CString strScroll = pTabElem.attribute(_T("scroll")).value(); BOOL bEnableScroll = (strScroll == _T("1")); // 加载Panel控件,每个Tab页都会自动创建一个Panel控件,即使没有加载子XML节点 CDuiPanel* pControlPanel = (CDuiPanel*)_CreateControlByName(_T("div")); pControlPanel->SetName(strName); // div控件的名字设置为tab的名字 pControlPanel->SetEnableScroll(bEnableScroll); m_vecControl.push_back(pControlPanel); if(!strDivXml.IsEmpty()) { pControlPanel->LoadXmlFile(strDivXml); } // 加载XML中Tab节点的各个下层控件节点 pControlPanel->Load(pTabElem); CString strTitle = pControlPanel->GetTitle(); // 通过Skin读取 CString strSkin = _T(""); if(strImage.Find(_T("skin:")) == 0) { strSkin = DuiSystem::Instance()->GetSkin(strImage); }else { strSkin = strImage; } if(strSkin.Find(_T(".")) != -1) // 加载图片文件 { CString strImgFile = strSkin; if(strSkin.Find(_T(":")) != -1) { strImgFile = strSkin; } InsertItem(-1, nId, strName, strTitle, strAction, strImgFile, pControlPanel, nImageCount, bOutLink); }else if(nImageIndex != -1) // 索引图片 { InsertItem(-1, nId, strName, strTitle, strAction, nImageIndex, pControlPanel, bOutLink); }else if(!strSkin.IsEmpty()) // 图片资源 { UINT uResourceID = _wtoi(strSkin); InsertItem(-1, nId, strName, strTitle, strAction, uResourceID, pControlPanel, nImageCount, bOutLink); }else if(strSkin.IsEmpty()) // 图片为空 { InsertItem(-1, nId, strName, strTitle, strAction, _T(""), pControlPanel, nImageCount, bOutLink); } TabItemInfo &itemInfo = m_vecItemInfo.at(nIdIndex); itemInfo.bVisible = bVisible; if(!bVisible) { bAllVisible = FALSE; } if(strActive == _T("true")) // 设置为当前活动的页面 { m_nHoverItem = nIdIndex; m_nDownItem = nIdIndex; } if(!bVisible && (m_nDownItem == nIdIndex)) { m_nDownItem++; m_nHoverItem = m_nDownItem; } nIdIndex++; } // 如果是用于加载嵌套tab页定义,则不需要下面的流程 if(!bLoadSubControl) { return TRUE; } // 只显示当前活动的tab页对应的Panel对象,其他页面的Panel对象都隐藏 for(size_t i = 0; i < m_vecItemInfo.size(); i++) { TabItemInfo &itemInfo = m_vecItemInfo.at(i); if(itemInfo.pControl != NULL) { if(i == m_nDownItem) { itemInfo.pControl->SetVisible(TRUE); }else { itemInfo.pControl->SetVisible(FALSE); } } } // 如果有页面是隐藏的,则需要刷新所有页面 if(!bAllVisible) { RefreshItems(); } m_bInit = TRUE; return TRUE; }
// 加载XML节点,解析节点中的属性信息设置到当前控件的属性中 BOOL CDuiGridCtrl::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { if(!__super::Load(pXmlElem)) { return FALSE; } // 使用XML节点初始化div控件 if(pXmlElem != NULL) { InitUI(m_rc, pXmlElem); } // 加载下层的cloumn节点信息 for (DuiXmlNode pColumnElem = pXmlElem.child(_T("column")); pColumnElem; pColumnElem=pColumnElem.next_sibling(_T("column"))) { CString strTitle = pColumnElem.attribute(_T("title")).value(); CString strClrText = pColumnElem.attribute(_T("crtext")).value(); CString strWidth = pColumnElem.attribute(_T("width")).value(); CString strAlign = pColumnElem.attribute(_T("align")).value(); CString strVAlign = pColumnElem.attribute(_T("valign")).value(); DuiSystem::Instance()->ParseDuiString(strTitle); Color clrText = Color(0, 0, 0, 0); if(!strClrText.IsEmpty()) { clrText = CDuiObject::StringToColor(strClrText); } int nWidth = -1; if(!strWidth.IsEmpty()) { nWidth = _ttoi(strWidth); } UINT uAlignment = 0xFFFFUL; if(strAlign == _T("left")) { uAlignment = Align_Left; }else if(strAlign ==_T("center")) { uAlignment = Align_Center; }else if(strAlign == _T("right")) { uAlignment = Align_Right; } UINT uVAlignment = 0xFFFFUL; if(strVAlign == _T("top")) { uVAlignment = VAlign_Top; }else if(strVAlign == _T("middle")) { uVAlignment = VAlign_Middle; }else if(strVAlign == _T("bottom")) { uVAlignment = VAlign_Bottom; } InsertColumn(-1, strTitle, nWidth, clrText, uAlignment, uVAlignment); } // 加载下层的row节点信息 for (DuiXmlNode pRowElem = pXmlElem.child(_T("row")); pRowElem; pRowElem=pRowElem.next_sibling(_T("row"))) { CString strId = pRowElem.attribute(_T("id")).value(); CString strCheck = pRowElem.attribute(_T("check")).value(); CString strImage = pRowElem.attribute(_T("image")).value(); CString strRightImage = pRowElem.attribute(_T("right-img")).value(); CString strClrText = pRowElem.attribute(_T("crtext")).value(); int nCheck = -1; if(!strCheck.IsEmpty()) { nCheck = _ttoi(strCheck); } // 左边图片,通过Skin读取 CString strSkin = _T(""); if(strImage.Find(_T("skin:")) == 0) { strSkin = DuiSystem::Instance()->GetSkin(strImage); }else { strSkin = strImage; } int nImageIndex = -1; strImage = _T(""); if(strSkin.Find(_T(".")) != -1) { // 图片文件 strImage = strSkin; }else if(!strSkin.IsEmpty()) { // 图片索引 nImageIndex = _ttoi(strSkin); } // 右边图片,通过Skin读取 CString strRightSkin = _T(""); if(strRightImage.Find(_T("skin:")) == 0) { strRightSkin = DuiSystem::Instance()->GetSkin(strRightImage); }else { strRightSkin = strRightImage; } int nRightImageIndex = -1; strRightImage = _T(""); if(strRightSkin.Find(_T(".")) != -1) { // 图片文件 strRightImage = strRightSkin; }else if(!strRightSkin.IsEmpty()) { // 图片索引 nRightImageIndex = _ttoi(strRightSkin); } Color clrText = CDuiObject::StringToColor(strClrText); InsertRow(-1, strId, nImageIndex, clrText, strImage, nRightImageIndex, strRightImage, nCheck); int nRowIndex = m_vecRowInfo.size()-1; int nItemIndex = 0; // 加载下层的item节点信息 for (DuiXmlNode pItemElem = pRowElem.child(_T("item")); pItemElem; pItemElem=pItemElem.next_sibling(_T("item"))) { CString strTitle = pItemElem.attribute(_T("title")).value(); CString strContent = pItemElem.attribute(_T("content")).value(); CString strClrText = pItemElem.attribute(_T("crtext")).value(); CString strImage = pItemElem.attribute(_T("image")).value(); CString strLink = pItemElem.attribute(_T("link")).value(); CString strLinkAction = pItemElem.attribute(_T("linkaction")).value(); CString strFontTitle = pItemElem.attribute(_T("font-title")).value(); DuiSystem::Instance()->ParseDuiString(strTitle); DuiSystem::Instance()->ParseDuiString(strContent); DuiSystem::Instance()->ParseDuiString(strLink); DuiSystem::Instance()->ParseDuiString(strLinkAction); Color clrText = CDuiObject::StringToColor(strClrText); // 图片,通过Skin读取 CString strSkin = _T(""); if(strImage.Find(_T("skin:")) == 0) { strSkin = DuiSystem::Instance()->GetSkin(strImage); }else { strSkin = strImage; } int nImageIndex = -1; strImage = _T(""); if(strSkin.Find(_T(".")) != -1) { // 图片文件 strImage = strSkin; }else if(!strSkin.IsEmpty()) { // 图片索引 nImageIndex = _ttoi(strSkin); } BOOL bUseTitleFont = (strFontTitle == _T("1")); if(!strLink.IsEmpty()) { SetSubItemLink(nRowIndex, nItemIndex, strLink, strLinkAction, nImageIndex, clrText, strImage); }else { SetSubItem(nRowIndex, nItemIndex, strTitle, strContent, bUseTitleFont, nImageIndex, clrText, strImage); } // 加载下层的控件节点信息 GridItemInfo* pItemInfo = GetItemInfo(nRowIndex, nItemIndex); for (DuiXmlNode pControlElem = pItemElem.first_child(); pControlElem; pControlElem=pControlElem.next_sibling()) { if((pControlElem != NULL) && (pItemInfo != NULL)) { CString strControlName = pControlElem.name(); CControlBase* pControl = _CreateControlByName(strControlName); if(pControl) { pControl->Load(pControlElem); pControl->SetVisible(FALSE); // 将控件指针添加到gridctrl控件的子控件列表中 m_vecControl.push_back(pControl); // 将控件指针添加到单元格的控件列表中(仅用于按照单元格查找子控件) pItemInfo->vecControl.push_back(pControl); } } } nItemIndex++; } } // 计算横向滚动条 CalcColumnsPos(); // 计算每一行的位置和滚动条 CalcRowsPos(); return TRUE; }
// 重载加载XML节点函数,加载下层的Menu item信息 BOOL CDuiMenu::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { SetRect(CRect(0, 0, m_nWidth, m_nHeight)); __super::Load(pXmlElem, bLoadSubControl); if(pXmlElem == NULL) { return FALSE; } if(!bLoadSubControl) { // 不加载子控件 return TRUE; } // 菜单窗口宽度设置为popup窗口的宽度 m_nWidth = m_size.cx; // 创建窗口 Create(m_pParent, m_point, m_uMessageID); // 加载下层的item节点信息(正常情况下都使用DlgPopup的Load控件方式加载菜单项,下面的解析比较少用到) int nIdIndex = 100; for (DuiXmlNode pItemElem = pXmlElem.child(_T("item")); pItemElem; pItemElem=pItemElem.next_sibling()) { CString strId = pItemElem.attribute(_T("id")).value(); int nId = nIdIndex; if(strId != _T("")) { nId = _ttoi(strId); } CString strType = pItemElem.attribute(_T("type")).value(); CString strName = pItemElem.attribute(_T("name")).value(); CString strImage = pItemElem.attribute(_T("image")).value(); CString strTitle = pItemElem.attribute(_T("title")).value(); if(strType == _T("separator")) { // 分隔线也可以用图片的方式 AddSeparator(); continue; } CString strTitleU = strTitle; if(strImage.Find(_T(".")) != -1) // 加载图片文件 { CString strImgFile = strImage; AddMenu(strTitleU, nIdIndex, strImgFile); }else if(!strImage.IsEmpty()) { UINT nResourceID = _ttoi(strImage); AddMenu(strTitleU, nIdIndex, nResourceID); }else { AddMenu(strTitleU, nIdIndex); } nIdIndex++; } // 刷新各菜单控件的位置 SetMenuPoint(); m_bInit = TRUE; return TRUE; }
// 加载XML节点,解析节点中的属性信息设置到当前控件的属性中 BOOL CDuiListCtrl::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl) { if(!__super::Load(pXmlElem)) { return FALSE; } // 使用XML节点初始化div控件 if(pXmlElem != NULL) { InitUI(m_rc, pXmlElem); } // 需要的总高度大于显示区高度才会显示滚动条 m_pControScrollV->SetVisible(((int)m_vecRowInfo.size() * m_nRowHeight) > m_rc.Height()); ((CScrollV*)m_pControScrollV)->SetScrollMaxRange((int)m_vecRowInfo.size() * m_nRowHeight); // 加载下层的row节点信息 for (DuiXmlNode pRowElem = pXmlElem.child(_T("row")); pRowElem; pRowElem=pRowElem.next_sibling(_T("row"))) { CString strId = pRowElem.attribute(_T("id")).value(); CString strTitle = pRowElem.attribute(_T("title")).value(); CString strContent = pRowElem.attribute(_T("content")).value(); CString strTime = pRowElem.attribute(_T("time")).value(); CString strCheck = pRowElem.attribute(_T("check")).value(); CString strImage = pRowElem.attribute(_T("image")).value(); CString strRightImage = pRowElem.attribute(_T("right-img")).value(); CString strClrText = pRowElem.attribute(_T("crtext")).value(); CString strLink1 = pRowElem.attribute(_T("link1")).value(); CString strLinkAction1 = pRowElem.attribute(_T("linkaction1")).value(); CString strLink2 = pRowElem.attribute(_T("link2")).value(); CString strLinkAction2 = pRowElem.attribute(_T("linkaction2")).value(); DuiSystem::Instance()->ParseDuiString(strTitle); DuiSystem::Instance()->ParseDuiString(strContent); int nCheck = -1; if(!strCheck.IsEmpty()) { nCheck = _wtoi(strCheck); } // 左边图片,通过Skin读取 CString strSkin = _T(""); if(strImage.Find(_T("skin:")) == 0) { strSkin = DuiSystem::Instance()->GetSkin(strImage); }else { strSkin = strImage; } int nImageIndex = -1; strImage = _T(""); if(strSkin.Find(_T(".")) != -1) { // 图片文件 strImage = strSkin; }else if(!strSkin.IsEmpty()) { // 图片索引 nImageIndex = _wtoi(strSkin); } // 右边图片,通过Skin读取 CString strRightSkin = _T(""); if(strRightImage.Find(_T("skin:")) == 0) { strRightSkin = DuiSystem::Instance()->GetSkin(strRightImage); }else { strRightSkin = strRightImage; } int nRightImageIndex = -1; strRightImage = _T(""); if(strRightSkin.Find(_T(".")) != -1) { // 图片文件 strRightImage = strRightSkin; }else if(!strRightSkin.IsEmpty()) { // 图片索引 nRightImageIndex = _wtoi(strRightSkin); } Color clrText = CDuiObject::StringToColor(strClrText); InsertItem(-1, strId, strTitle, strContent, strTime, nImageIndex, clrText, strImage, nRightImageIndex, strRightImage, strLink1, strLinkAction1, strLink2, strLinkAction2, nCheck); } return TRUE; }