Example #1
0
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;
}
Example #2
0
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
}
Example #3
0
//----------------------------------------------------------------------------------------------------------------
bool UIObject::RemoveChild(TIUIObjectPtr ip_obj) 
  {
  size_t idx = GetChildIdx(ip_obj);
  if(idx != -1)
    {
    RemoveChild(idx);
    return true;
    }
  return false;
  }
Example #4
0
//----------------------------------------------------------------------------------------------------------------
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();
  }
Example #5
0
//----------------------------------------------------------------------------------------------------------------
void UIObject::DeleteChild( TIUIObjectPtr ip_obj)
  {
  size_t idx = GetChildIdx(ip_obj);
  if(idx != -1)
    DeleteChild(idx);
  }