DocumentWalker::StepType DocumentWalker::Step (IDocumentNode **node_return) { DependencyObjectCollection *children = node->GetDocumentChildren(); if (direction == DocumentWalker::Forward) { if (children && children->GetCount() > child_index) { // 1) if node is a container, step into the child node = IDocumentNode::CastToIDocumentNode (children->GetValueAt (child_index)->AsTextElement()); child_index = 0; if (node_return) *node_return = node; return Enter; } else { // 2) if it's not a container, then we walk up a level, step out of this node IDocumentNode *parent_node = node->GetParentDocumentNode(); if (parent_node == NULL) return Done; DependencyObjectCollection *parent_children= parent_node->GetDocumentChildren(); int i = parent_children->IndexOf (node->AsDependencyObject()); if (node_return) *node_return = node; child_index = i + 1; node = parent_node; return Leave; } } else { if (children && children->GetCount() > child_index && child_index >= 0) { // 1) if node is a container, step into the child node = IDocumentNode::CastToIDocumentNode (children->GetValueAt (child_index)->AsTextElement()); children = node->GetDocumentChildren (); child_index = children ? children->GetCount() - 1 : 0; if (node_return) *node_return = node; return Enter; } else { // 2) if it's not a container, then we walk up a level, step out of this node IDocumentNode *parent_node = node->GetParentDocumentNode(); if (parent_node == NULL) return Done; DependencyObjectCollection *parent_children= parent_node->GetDocumentChildren(); int i = parent_children->IndexOf (node->AsDependencyObject()); if (node_return) *node_return = node; child_index = i - 1; node = parent_node; return Leave; } } }