private void AddChild(GraphElement child) { // Remove all holes from the sibling index list. Now the max index // number is equal to the size of the children list. this.EnsureSequentialSiblingIndex(); this.needSortChildren = true; // maybe false child.siblingIndex = this.childCount; //this.children.Add(child); if (this.childCount == this.children.Length) { GraphElement[] childs; if (this.childCount == 0) { childs = new GraphElement[4]; } else { childs = new GraphElement[2 * this.childCount]; Array.Copy(this.children, 0, childs, 0, this.childCount); } this.children = childs; } this.children[this.childCount++] = child; this.OnChildAdded(child); System.Drawing.RectangleF invalid = child.ChildrenBoundingBox(); invalid.Offset(child.X, child.Y); this.Invalidate(invalid); }
private void RemoveChild(GraphElement child) { // When removing elements in the middle of the children list, // there will be a "gap" in the list of sibling indexes (0,1,3,4). if (!this.holesInSiblingIndex) { this.holesInSiblingIndex = child.siblingIndex != this.childCount - 1; } if (this.sequentialOrdering && !this.holesInSiblingIndex) { //this.children.RemoveAt(child.siblingIndex); this.childCount--; Array.Copy(this.children, child.siblingIndex + 1, this.children, child.siblingIndex, this.childCount - child.siblingIndex); this.children[this.childCount] = null; } else { //this.children.Remove(child); int i; for (i = 0; i < this.childCount; i++) { if (this.children[i] == child) { break; } } if (i < this.childCount) { this.childCount--; Array.Copy(this.children, i + 1, this.children, i, this.childCount - i); this.children[this.childCount] = null; } } // NB! Do not use children.RemoveAt(child.siblingIndex) because // the child is not guaranteed to be at the index after the list is sorted. // (see ensureSortedChildren()). child.siblingIndex = -1; this.OnChildRemoved(child); System.Drawing.RectangleF invalid = child.ChildrenBoundingBox(); invalid.Offset(child.X, child.Y); this.Invalidate(invalid); }