void TryAddElementToCollection(LayoutElement element, ContentDisplayAction showingType, bool hasChildNodes) { if (Object.ReferenceEquals(element.Parent, ParentElement.Element)) { ContentDisplayAction type = ParentElement.DisplayAction == ContentDisplayAction.ScrollTo ? ParentElement.DisplayAction : showingType; Collection.Add(new TreeViewItemInfo(element, type, hasChildNodes)); } }
void AddTreeNode(LayoutElement element, ContentDisplayAction displayActionType) { TreeNode item = new TreeNode(); // Store the attribute that determines whether document range selection is allowed for this node. item.Tag = displayActionType; Rectangle bounds = element.Bounds; item.ToolTipText = String.Format("X = {0}\nY = {1}\nWidth = {2}\nHeight = {3}", bounds.X, bounds.Y, bounds.Width, bounds.Height); // Update the layout element / tree node dictionary. Dictionary.Add(element, item); TreeNode parentItem = Dictionary[element.Parent]; if (parentItem != null) { // Add a new node to the tree. int index = parentItem.Nodes.Add(item); // Specify the node caption. string typeName = element.Type.ToString(); switch (element.Type) { case LayoutType.Column: item.Text = String.Format("{0} #{1}", typeName, index); break; case LayoutType.Row: item.Text = String.Format("{0} #{1}", typeName, index + 1); break; case LayoutType.TableRow: item.Text = String.Format("{0} #{1}", typeName, index); break; default: item.Text = typeName; break; } if (parentItem.Tag != null) { // As for the node that does not allow range selection in the document, all its child nodes should have the same attribute. ContentDisplayAction parentDisplayActionType = (ContentDisplayAction)parentItem.Tag; ContentDisplayAction actionType = parentDisplayActionType == ContentDisplayAction.ScrollTo ? parentDisplayActionType : displayActionType; item.Tag = actionType; } } }
public TreeViewItemInfo(LayoutElement element, ContentDisplayAction displayAction, bool hasChildNodes) { this.element = element; this.displayAction = displayAction; this.hasChildNodes = hasChildNodes; }