int DocumentIterator::NodeIdx2RecursiveIdx(int nIdx) { int nRecursiveIdx = -1; while(nIdx >= 0) { int nParentID = m_doc.GetNodeByIdx(nIdx).m_nParentID; int nSiblingIdx = m_doc.GetNodeByIdx(nIdx).m_nSiblingIdx; //count the current node nRecursiveIdx ++; //get "previous" node nIdx = -1; if(nSiblingIdx > 0){ nIdx = GetChildIdx(nParentID, nSiblingIdx-1); //previous sibling //recursively go to the last node child int nID = m_doc.GetNodeByIdx(nIdx).m_nID; int nChildCount = GetChildCount(nID); while(nChildCount > 0) { nIdx = GetChildIdx(nID, nChildCount-1); nID = m_doc.GetNodeByIdx(nIdx).m_nID; nChildCount = GetChildCount(nID); } } else nIdx = m_doc.GetIdxFromID(nParentID); // if(nIdx < 0) break; } return nRecursiveIdx; }
int DocumentIterator::RecursiveGetIdx(int nRIdx, int nParentID, int &nCounter) { int nChildCnt = GetChildCount(nParentID); if(nChildCnt > 0) { //recurse into children for(int i=0; i<nChildCnt; i++) { nCounter ++; int nChildIdx = GetChildIdx(nParentID, i); if(nChildIdx >= 0) { if(nCounter == nRIdx) return nChildIdx; int nChildID = m_doc.GetNodeByIdx(nChildIdx).m_nID; int nIdxNode = RecursiveGetIdx(nRIdx, nChildID, nCounter); if(nIdxNode >= 0) return nIdxNode; } } } return -1; //not found at this level }
//---------------------------------------------------------------------------------------------------------------- bool UIObject::RemoveChild(TIUIObjectPtr ip_obj) { size_t idx = GetChildIdx(ip_obj); if(idx != -1) { RemoveChild(idx); return true; } return false; }
//---------------------------------------------------------------------------------------------------------------- TIUIObjectPtr UIObject::RemoveChild( size_t i) { auto child = m_childs[i]; NotificationCenter::Notify(BEFORE_OBJECT_REMOVED, child); if(GetChildIdx(child) != -1) { m_childs.erase(m_childs.begin() + i); child->SetParent(nullptr); NotificationCenter::Notify(OBJECT_REMOVED, child); return child; } return TIUIObjectPtr(); }
//---------------------------------------------------------------------------------------------------------------- void UIObject::DeleteChild( TIUIObjectPtr ip_obj) { size_t idx = GetChildIdx(ip_obj); if(idx != -1) DeleteChild(idx); }