/// <summary> /// Refreshes or initializes node positions relative to the parent node position. /// Parent node position must already be set. /// </summary> /// <param name="node">Parent Node</param> /// <param name="sideToRefresh">Which side to refresh (left or right). For Undefined or Root, both sides will be refreshed.</param> internal void RefreshNodePositions(MapNode node, NodePosition sideToRefresh) { if (LayoutSuspended) { return; } NodeView nView = this.GetNodeView(node); if (!node.HasChildren || node.Folded) { return; } else { for (int i = 0; i < 2; i++) { IEnumerable <MapNode> childNodes; NodePosition rpos; if (i == 0) { rpos = NodePosition.Left; childNodes = node.ChildLeftNodes; } else { rpos = NodePosition.Right; childNodes = node.ChildRightNodes; } float left = nView.Left + nView.Width + HOR_MARGIN; float top = nView.Top - (int)((this.GetNodeHeight(node, rpos) - nView.Height) / 2) - ((node.Pos == NodePosition.Root) ? (int)(nView.Height / 2) : 0); int topOffset; foreach (MapNode rnode in childNodes) { NodeView tView = this.GetNodeView(rnode); topOffset = (int)((this.GetNodeHeight(rnode, rpos) - tView.Height) / 2); if (i == 0) { left = nView.Left - tView.Width - HOR_MARGIN; } tView.RefreshPosition(left, top + topOffset); top += (topOffset * 2) + tView.Height + VER_MARGIN; if (!rnode.Folded) { // recursive call RefreshNodePositions(rnode, NodePosition.Undefined); } } } } }
/// <summary> /// Refreshes or initializes node positions for the whole tree /// </summary> private void RefreshNodePositions() { if (LayoutSuspended) { return; } NodeView nodeView = this.GetNodeView(Tree.RootNode); //var left = this.rootPosX; var left = this.Canvas.Width / 2; //var top = this.rootPosY; var top = this.Canvas.Height / 2; // add unit string for xhtml nodeView.RefreshPosition(left - (nodeView.Width / 2), top); RefreshNodePositions(Tree.RootNode, NodePosition.Undefined); }
/// <summary> /// Returns true if successfully refreshes all node positions. If canvas is not big enough, the operation is aborted and 'false' is returned. /// </summary> /// <param name="parent"></param> /// <param name="sideToRefresh"></param> /// <returns></returns> private bool RefreshChildNodePositionsRecursive(MapNode parent, NodePosition sideToRefresh) { NodeView nView = this.GetNodeView(parent); if (!parent.HasChildren || parent.Folded) { if (!NodeWithinCanvas(parent, 50)) { return(false); } return(true); } else { for (int i = 0; i < 2; i++) { IEnumerable <MapNode> childNodes; NodePosition rpos; if (i == 0) { rpos = NodePosition.Left; childNodes = parent.ChildLeftNodes; } else { rpos = NodePosition.Right; childNodes = parent.ChildRightNodes; } float left = nView.Left + nView.Width + HOR_MARGIN; float top = nView.Top - (int)((this.GetNodeHeight(parent, rpos) - nView.Height) / 2) - ((parent.Pos == NodePosition.Root) ? (int)(nView.Height / 2) : 0); int topOffset; foreach (MapNode rnode in childNodes) { NodeView tView = this.GetNodeView(rnode); topOffset = (int)((this.GetNodeHeight(rnode, rpos) - tView.Height) / 2); if (i == 0) { left = nView.Left - tView.Width - HOR_MARGIN; } tView.RefreshPosition(left, top + topOffset); top += (topOffset * 2) + tView.Height + VER_MARGIN; if (!rnode.Folded) { // recursive call bool continueProcess = RefreshChildNodePositionsRecursive(rnode, NodePosition.Undefined); if (!continueProcess) { return(false); } } } } } return(true); }