123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- // DataNodeList.cpp : implementation file
- //
- #include "stdafx.h"
- #include "DataManager.h"
- #include "DataNodeList.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDataNodeList
- CDataNodeList::CDataNodeList()
- {
- }
- CDataNodeList::~CDataNodeList()
- {
- }
- BEGIN_MESSAGE_MAP(CDataNodeList, CListView)
- //{{AFX_MSG_MAP(CDataNodeList)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDataNodeList message handlers
- int CDataNodeList::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CListView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
- CDataNodeListCtrl::InitList(GetListCtrl(), m_imageList);
- return 0;
- }
- // 显示单个节点的属性
- void CDataNodeList::ShowProperties(CDataNodeBase *pNode)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, pNode, m_ptrListNodes);
- }
- // 显示多个节点的属性
- void CDataNodeList::ShowProperties(CPtrList &ptrListNodes, BOOL bShowCommonOnly)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, ptrListNodes, m_ptrListNodes, bShowCommonOnly);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDataNodeListCtrl
- CDataNodeListCtrl::CDataNodeListCtrl()
- {
- }
- CDataNodeListCtrl::~CDataNodeListCtrl()
- {
- }
- BEGIN_MESSAGE_MAP(CDataNodeListCtrl, CListCtrl)
- //{{AFX_MSG_MAP(CDataNodeListCtrl)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDataNodeListCtrl message handlers
- int CDataNodeListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CListCtrl::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
- CDataNodeListCtrl::InitList(GetListCtrl(), m_imageList);
- return 0;
- }
- void CDataNodeListCtrl::InitList(CListCtrl &listCtrl, CImageListDyn &imageList)
- {
- listCtrl.ModifyStyle(NULL, listCtrl.GetStyle()|LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SORTASCENDING|LVS_AUTOARRANGE);
- listCtrl.SetExtendedStyle(listCtrl.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
- imageList.Create();
- listCtrl.SetImageList(&imageList, LVSIL_SMALL);
-
- int i = 0;
- listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("Name"), LVCFMT_LEFT, 20);
- listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("FullName"), LVCFMT_LEFT, 300);
- listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("Value"), LVCFMT_LEFT, 380);
- listCtrl.InsertColumn(i++, CLanguage::GetCurLanguage("Attribute"), LVCFMT_LEFT, 0);
- }
- // 显示单个节点的属性
- void CDataNodeListCtrl::ShowProperties(CDataNodeBase *pNode)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, pNode, m_ptrListNodes);
- }
- void CDataNodeListCtrl::ShowPropertiesSt(CListCtrl &listCtrl, CImageListDyn &imageList, CDataNodeBase *pNode, CPtrList &ptrListNodesM)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- listCtrl.DeleteAllItems();
-
- int nImage = imageList.GetImage("Name");
- int nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "Name", nImage);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("Name"));
- listCtrl.SetItemText(nItem, 2, pNode->GetName());
- listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("Name"));
- nImage = imageList.GetImage("ID");
- nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "ID", nImage);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("ID"));
- listCtrl.SetItemText(nItem, 2, GetText(pNode->GetID()));
- listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("ID"));
- nImage = imageList.GetImage("Type");
- nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "Type", nImage);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("Type"));
- listCtrl.SetItemText(nItem, 2, pNode->PV_GetType());
- listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("Type"));
- nImage = imageList.GetImage("AppName");
- nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), "AppName", nImage);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage("AppName"));
- listCtrl.SetItemText(nItem, 2, pNode->PV_GetAppName());
- listCtrl.SetItemText(nItem, 3, pNode->GetAttributes("AppName"));
-
- ptrListNodesM.RemoveAll();
- ptrListNodesM.AddTail(pNode);
- CMapStringToPtr mapProperties;
- pNode->GetPropertyNames(mapProperties);
- POSITION pos = mapProperties.GetStartPosition();
- while (pos)
- {
- CString strItem;
- CVariable* pVar = NULL;
- mapProperties.GetNextAssoc(pos, strItem, (void*&)pVar);
- nImage = imageList.GetImage(strItem);
- nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), strItem, nImage);
- CString strItemTemp = strItem;
- if(strItem.GetLength() > 3 && strItem.GetAt(2) == '_')
- strItemTemp = strItem.Mid(3);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage(strItemTemp));
- listCtrl.SetItemText(nItem, 2, pVar->GetTextValue());
- listCtrl.SetItemText(nItem, 3, pVar->GetAttributesMsg());
- }
- }
- // 显示多个节点的属性
- void CDataNodeListCtrl::ShowProperties(CPtrList &ptrListNodes, BOOL bShowCommonOnly)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- CDataNodeListCtrl::ShowPropertiesSt(GetListCtrl(), m_imageList, ptrListNodes, m_ptrListNodes, bShowCommonOnly);
- }
- void CDataNodeListCtrl::ShowPropertiesSt(CListCtrl &listCtrl, CImageListDyn &imageList, CPtrList &ptrListNodes, CPtrList &ptrListNodesM, BOOL bShowCommonOnly)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- listCtrl.DeleteAllItems();
- ptrListNodesM.RemoveAll();
- if(ptrListNodes.GetCount() > 0)
- {
- if(bShowCommonOnly)
- {
- ptrListNodesM.AddTail(&ptrListNodes);
- CDataNodeBase *pNode = (CDataNodeBase*)ptrListNodes.GetHead();
- CMapStringToPtr mapProperties;
- pNode->GetPropertyNames(mapProperties);
- POSITION posP = mapProperties.GetStartPosition();
- while (posP)
- {
- CString strItem;
- CVariable* pVar = NULL;
- mapProperties.GetNextAssoc(posP, strItem, (void*&)pVar);
- // 判断其他节点是否也有此属性
- BOOL bIsCommonProperty = TRUE;
- CString strCommonValue = pVar->GetTextValue();
- CString strCommonAttr = pVar->GetAttributesMsg();
- POSITION posN = ptrListNodes.GetHeadPosition();
- ptrListNodes.GetNext(posN);
- while(posN)
- {
- CDataNodeBase *pNodeElse = (CDataNodeBase*)ptrListNodes.GetNext(posN);
- CMapStringToPtr mapPropertiesElse;
- pNodeElse->GetPropertyNames(mapPropertiesElse);
- CVariable* pVarElse = NULL;
- if(mapPropertiesElse.Lookup(strItem, (void*&)pVarElse))
- {
- if(strCommonValue != "" && strCommonValue != pVarElse->GetTextValue())
- strCommonValue = "";
- if(strCommonAttr != "" && strCommonAttr != pVarElse->GetAttributesMsg())
- strCommonAttr = "";
- }
- else
- {
- bIsCommonProperty = FALSE;
- break;
- }
- }
- if(bIsCommonProperty)
- {
- int nImage = imageList.GetImage(strItem);
- int nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), strItem, nImage);
- CString strItemTemp = strItem;
- if(strItem.GetLength() > 3 && strItem.GetAt(2) == '_')
- strItemTemp = strItem.Mid(3);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage(strItemTemp));
- listCtrl.SetItemText(nItem, 2, strCommonValue);
- listCtrl.SetItemText(nItem, 3, strCommonAttr);
- }
- }
- }
- else
- {
- CMapStringToString mapProperties;
- CMapStringToString mapPropertiesAttr;
- POSITION posN = ptrListNodes.GetHeadPosition();
- while(posN)
- {
- CDataNodeBase *pNode = (CDataNodeBase*)ptrListNodes.GetNext(posN);
- CMapStringToPtr mapPropertiesOneNode;
- pNode->GetPropertyNames(mapPropertiesOneNode);
- POSITION posOneNode = mapPropertiesOneNode.GetStartPosition();
- while(posOneNode)
- {
- CVariable* pVar = NULL;
- CString strItem;
- mapPropertiesOneNode.GetNextAssoc(posOneNode, strItem, (void*&)pVar);
- CString strTxtValue;
- if(mapProperties.Lookup(strItem, strTxtValue))
- {
- if(strTxtValue != pVar->GetTextValue())
- strTxtValue = "";
- }
- else
- {
- strTxtValue = pVar->GetTextValue();
- mapPropertiesAttr.SetAt(strItem, pVar->GetAttributesMsg());
- }
- mapProperties.SetAt(strItem, strTxtValue);
- }
- }
- POSITION pos = mapProperties.GetStartPosition();
- while (pos)
- {
- CString strItem;
- CString strTxtValue;
- mapProperties.GetNextAssoc(pos, strItem, strTxtValue);
- int nImage = imageList.GetImage(strItem);
- int nItem = listCtrl.InsertItem(listCtrl.GetItemCount(), strItem, nImage);
- CString strItemTemp = strItem;
- if(strItem.GetLength() > 3 && strItem.GetAt(2) == '_')
- strItemTemp = strItem.Mid(3);
- listCtrl.SetItemText(nItem, 1, CLanguage::GetCurLanguage(strItemTemp));
- listCtrl.SetItemText(nItem, 2, strTxtValue);
- CString strCommonAttr;
- mapPropertiesAttr.Lookup(strItem, strCommonAttr);
- listCtrl.SetItemText(nItem, 3, strCommonAttr);
- }
- }
- }
- }
- CListCtrl& CDataNodeListCtrl::GetListCtrl()
- {
- return *this;
- }
|