/// <summary> /// This method should return a tupple with two nodes without fail (if /// it is called through the root node). The /// first node should be the node in which the topPoint falls, if it /// falls within one of it's tags, after the last tag of its last child, /// if it has no children. The second node should be the node in /// which the bottom point falls, if it falls within one of its tags, /// before the first tag of its first child, or if it has no children. /// </summary> /// <param name="topPoint"> /// The top point. /// </param> /// <param name="bottomPoint"> /// The bottom point. /// </param> /// <returns> /// The first last nodes between points. /// </returns> public Tuple <XamlNode, XamlNode> GetFirstLastNodesBetweenPoints(int topPoint, int bottomPoint) { if (topPoint == bottomPoint) { XamlNode node = this.GetNodeWithOffset(topPoint); return(new Tuple <XamlNode, XamlNode>(node, node)); } PositionAndNode pan1 = this.GetTopPointPositionAndNode(topPoint); PositionAndNode pan2 = this.GetBottomPointPositionAndNode(bottomPoint); if (pan1.Node.Parent != pan2.Node.Parent) { XamlNode parent = pan1.Node.GetCommonAncestor(pan2.Node); XamlNode node1 = parent.GetChildNodeWithOffset(topPoint); XamlNode node2 = parent.GetChildNodeWithOffset(bottomPoint); return(new Tuple <XamlNode, XamlNode>(node1, node2)); } return(new Tuple <XamlNode, XamlNode>(pan1.Node, pan2.Node)); }
private PositionAndNode GetTopPointPositionAndNode(int topPoint) { var pan = new PositionAndNode(this, topPoint); if (pan.Position != NodePosition.Content || !this.HasChildren) { return(pan); } LinkedListNode <XamlNode> childNode = this.ChildrenContainer.First; do { PositionAndNode childPan = childNode.Value.GetTopPointPositionAndNode(topPoint); if (childPan.Position != NodePosition.After) { return(childPan); } }while ((childNode = childNode.Next) != null); return(pan); }
private PositionAndNode GetBottomPointPositionAndNode(int bottomPoint) { var pan = new PositionAndNode(this, bottomPoint); if (pan.Position != NodePosition.Content || !this.HasChildren) { return(pan); } LinkedListNode <XamlNode> childNode = this.ChildrenContainer.Last; do { PositionAndNode childPan = childNode.Value.GetBottomPointPositionAndNode(bottomPoint); if (childPan.Position != NodePosition.Before) { return(childPan); } }while ((childNode = childNode.Previous) != null); return(pan); }