officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-layout-3b3debc3.md
Defines the basic functionality that should be implemented by visitors that traverse the document layout tree.
Namespace : DevExpress.XtraRichEdit.API.Layout
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
public abstract class LayoutVisitor
Public MustInherit Class LayoutVisitor
Refer to the Traversing Layout Tree section for details.
class TreeViewCollector : LayoutVisitor
{
readonly TreeView view;
Dictionary<LayoutElement, TreeNode> dictionary;
RichEditControl richEdit;
public TreeViewCollector(TreeView view, RichEditControl richEdit)
{
this.view = view;
this.dictionary = new Dictionary<LayoutElement, TreeNode>();
this.richEdit = richEdit;
}
public TreeView View { get { return view; } }
public Dictionary<LayoutElement, TreeNode> Dictionary { get { return dictionary; } }
public RichEditControl RichEdit { get { return richEdit; } }
protected override void VisitPage(LayoutPage page)
{
TreeNode item = new TreeNode();
item.Text = String.Format("{0} #{1}", "Page", page.Index + 1); ;
Dictionary.Add(page, item);
base.VisitPage(page);
View.Nodes.Add(item);
}
protected override void VisitHeader(LayoutHeader header)
{
AddTreeNode(header, ContentDisplayAction.ScrollTo);
base.VisitHeader(header);
}
protected override void VisitFooter(LayoutFooter footer)
{
AddTreeNode(footer, ContentDisplayAction.ScrollTo);
base.VisitFooter(footer);
}
protected override void VisitPageArea(LayoutPageArea pageArea)
{
AddTreeNode(pageArea, ContentDisplayAction.Select);
base.VisitPageArea(pageArea);
}
protected override void VisitBookmarkEndBox(BookmarkBox bookmarkEndBox)
{
AddTreeNode(bookmarkEndBox, ContentDisplayAction.Select);
base.VisitBookmarkEndBox(bookmarkEndBox);
}
protected override void VisitBookmarkStartBox(BookmarkBox bookmarkStartBox)
{
AddTreeNode(bookmarkStartBox, ContentDisplayAction.Select);
base.VisitBookmarkStartBox(bookmarkStartBox);
}
protected override void VisitColumn(LayoutColumn column)
{
AddTreeNode(column, ContentDisplayAction.Select);
base.VisitColumn(column);
}
protected override void VisitColumnBreakBox(PlainTextBox columnBreakBox)
{
AddTreeNode(columnBreakBox, ContentDisplayAction.Select);
base.VisitColumnBreakBox(columnBreakBox);
}
protected override void VisitComment(LayoutComment comment)
{
AddTreeNode(comment, ContentDisplayAction.ScrollTo);
base.VisitComment(comment);
}
protected override void VisitCommentEndBox(CommentBox commentEndBox)
{
AddTreeNode(commentEndBox, ContentDisplayAction.Select);
base.VisitCommentEndBox(commentEndBox);
}
protected override void VisitCommentHighlightAreaBox(CommentHighlightAreaBox commentHighlightAreaBox)
{
AddTreeNode(commentHighlightAreaBox, ContentDisplayAction.Select);
base.VisitCommentHighlightAreaBox(commentHighlightAreaBox);
}
protected override void VisitCommentStartBox(CommentBox commentStartBox)
{
AddTreeNode(commentStartBox, ContentDisplayAction.Select);
base.VisitCommentStartBox(commentStartBox);
}
protected override void VisitFieldHighlightAreaBox(FieldHighlightAreaBox fieldHighlightAreaBox)
{
AddTreeNode(fieldHighlightAreaBox, ContentDisplayAction.Select);
base.VisitFieldHighlightAreaBox(fieldHighlightAreaBox);
}
protected override void VisitFloatingObjectAnchorBox(FloatingObjectAnchorBox floatingObjectAnchorBox)
{
AddTreeNode(floatingObjectAnchorBox, ContentDisplayAction.Select);
base.VisitFloatingObjectAnchorBox(floatingObjectAnchorBox);
}
protected override void VisitFloatingPicture(LayoutFloatingPicture floatingPicture)
{
AddTreeNode(floatingPicture, ContentDisplayAction.ScrollTo);
base.VisitFloatingPicture(floatingPicture);
}
protected override void VisitHiddenTextUnderlineBox(HiddenTextUnderlineBox hiddenTextUnderlineBox)
{
AddTreeNode(hiddenTextUnderlineBox, ContentDisplayAction.Select);
base.VisitHiddenTextUnderlineBox(hiddenTextUnderlineBox);
}
protected override void VisitHighlightAreaBox(HighlightAreaBox highlightAreaBox)
{
AddTreeNode(highlightAreaBox, ContentDisplayAction.Select);
base.VisitHighlightAreaBox(highlightAreaBox);
}
protected override void VisitHyphenBox(PlainTextBox hyphen)
{
AddTreeNode(hyphen, ContentDisplayAction.Select);
base.VisitHyphenBox(hyphen);
}
protected override void VisitInlinePictureBox(InlinePictureBox inlinePictureBox)
{
AddTreeNode(inlinePictureBox, ContentDisplayAction.Select);
base.VisitInlinePictureBox(inlinePictureBox);
}
protected override void VisitLineBreakBox(PlainTextBox lineBreakBox)
{
AddTreeNode(lineBreakBox, ContentDisplayAction.Select);
base.VisitLineBreakBox(lineBreakBox);
}
protected override void VisitLineNumberBox(LineNumberBox lineNumberBox)
{
AddTreeNode(lineNumberBox, ContentDisplayAction.Select);
base.VisitLineNumberBox(lineNumberBox);
}
protected override void VisitNumberingListMarkBox(NumberingListMarkBox numberingListMarkBox)
{
AddTreeNode(numberingListMarkBox, ContentDisplayAction.Select);
base.VisitNumberingListMarkBox(numberingListMarkBox);
}
protected override void VisitNumberingListWithSeparatorBox(NumberingListWithSeparatorBox numberingListWithSeparatorBox)
{
AddTreeNode(numberingListWithSeparatorBox, ContentDisplayAction.Select);
base.VisitNumberingListWithSeparatorBox(numberingListWithSeparatorBox);
}
protected override void VisitPageBreakBox(PlainTextBox pageBreakBox)
{
AddTreeNode(pageBreakBox, ContentDisplayAction.Select);
base.VisitPageBreakBox(pageBreakBox);
}
protected override void VisitPageNumberBox(PlainTextBox pageNumberBox)
{
AddTreeNode(pageNumberBox, ContentDisplayAction.Select);
base.VisitPageNumberBox(pageNumberBox);
}
protected override void VisitParagraphMarkBox(PlainTextBox paragraphMarkBox)
{
AddTreeNode(paragraphMarkBox, ContentDisplayAction.Select);
base.VisitParagraphMarkBox(paragraphMarkBox);
}
protected override void VisitPlainTextBox(PlainTextBox plainTextBox)
{
AddTreeNode(plainTextBox, ContentDisplayAction.Select);
base.VisitPlainTextBox(plainTextBox);
}
protected override void VisitRangePermissionEndBox(RangePermissionBox rangePermissionEndBox)
{
AddTreeNode(rangePermissionEndBox, ContentDisplayAction.Select);
base.VisitRangePermissionEndBox(rangePermissionEndBox);
}
protected override void VisitRangePermissionHighlightAreaBox(RangePermissionHighlightAreaBox rangePermissionHighlightAreaBox)
{
AddTreeNode(rangePermissionHighlightAreaBox, ContentDisplayAction.Select);
base.VisitRangePermissionHighlightAreaBox(rangePermissionHighlightAreaBox);
}
protected override void VisitRangePermissionStartBox(RangePermissionBox rangePermissionStartBox)
{
AddTreeNode(rangePermissionStartBox, ContentDisplayAction.Select);
base.VisitRangePermissionStartBox(rangePermissionStartBox);
}
protected override void VisitRow(LayoutRow row)
{
AddTreeNode(row, ContentDisplayAction.Select);
base.VisitRow(row);
}
protected override void VisitSectionBreakBox(PlainTextBox sectionBreakBox)
{
AddTreeNode(sectionBreakBox, ContentDisplayAction.Select);
base.VisitSectionBreakBox(sectionBreakBox);
}
protected override void VisitSpaceBox(PlainTextBox spaceBox)
{
AddTreeNode(spaceBox, ContentDisplayAction.Select);
base.VisitSpaceBox(spaceBox);
}
protected override void VisitSpecialTextBox(PlainTextBox specialTextBox)
{
AddTreeNode(specialTextBox, ContentDisplayAction.Select);
base.VisitSpecialTextBox(specialTextBox);
}
protected override void VisitStrikeoutBox(StrikeoutBox strikeoutBox)
{
AddTreeNode(strikeoutBox, ContentDisplayAction.Select);
base.VisitStrikeoutBox(strikeoutBox);
}
protected override void VisitTable(LayoutTable table)
{
AddTreeNode(table, ContentDisplayAction.Select);
base.VisitTable(table);
}
protected override void VisitTableCell(LayoutTableCell tableCell)
{
AddTreeNode(tableCell, ContentDisplayAction.Select);
base.VisitTableCell(tableCell);
}
protected override void VisitTableRow(LayoutTableRow tableRow)
{
AddTreeNode(tableRow, ContentDisplayAction.Select);
base.VisitTableRow(tableRow);
}
protected override void VisitTabSpaceBox(PlainTextBox tabSpaceBox)
{
AddTreeNode(tabSpaceBox, ContentDisplayAction.Select);
base.VisitTabSpaceBox(tabSpaceBox);
}
protected override void VisitTextBox(LayoutTextBox textBox)
{
AddTreeNode(textBox, ContentDisplayAction.ScrollTo);
base.VisitTextBox(textBox);
}
protected override void VisitUnderlineBox(UnderlineBox underlineBox)
{
AddTreeNode(underlineBox, ContentDisplayAction.Select);
base.VisitUnderlineBox(underlineBox);
}
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 enum ContentDisplayAction { Select, ScrollTo }
Friend Class TreeViewCollector
Inherits LayoutVisitor
Private ReadOnly view_Renamed As TreeView
Private dictionary_Renamed As Dictionary(Of LayoutElement, TreeNode)
Private richEdit_Renamed As RichEditControl
Public Sub New(ByVal view As TreeView, ByVal richEdit As RichEditControl)
Me.view_Renamed = view
Me.dictionary_Renamed = New Dictionary(Of LayoutElement, TreeNode)()
Me.richEdit_Renamed = richEdit
End Sub
Public ReadOnly Property View() As TreeView
Get
Return view_Renamed
End Get
End Property
Public ReadOnly Property Dictionary() As Dictionary(Of LayoutElement, TreeNode)
Get
Return dictionary_Renamed
End Get
End Property
Public ReadOnly Property RichEdit() As RichEditControl
Get
Return richEdit_Renamed
End Get
End Property
Protected Overrides Sub VisitPage(ByVal page As LayoutPage)
Dim item As New TreeNode()
item.Text = String.Format("{0} #{1}", "Page", page.Index + 1)
Dictionary.Add(page, item)
MyBase.VisitPage(page)
View.Nodes.Add(item)
End Sub
Protected Overrides Sub VisitHeader(ByVal header As LayoutHeader)
AddTreeNode(header, ContentDisplayAction.ScrollTo)
MyBase.VisitHeader(header)
End Sub
Protected Overrides Sub VisitFooter(ByVal footer As LayoutFooter)
AddTreeNode(footer, ContentDisplayAction.ScrollTo)
MyBase.VisitFooter(footer)
End Sub
Protected Overrides Sub VisitPageArea(ByVal pageArea As LayoutPageArea)
AddTreeNode(pageArea, ContentDisplayAction.Select)
MyBase.VisitPageArea(pageArea)
End Sub
Protected Overrides Sub VisitBookmarkEndBox(ByVal bookmarkEndBox As BookmarkBox)
AddTreeNode(bookmarkEndBox, ContentDisplayAction.Select)
MyBase.VisitBookmarkEndBox(bookmarkEndBox)
End Sub
Protected Overrides Sub VisitBookmarkStartBox(ByVal bookmarkStartBox As BookmarkBox)
AddTreeNode(bookmarkStartBox, ContentDisplayAction.Select)
MyBase.VisitBookmarkStartBox(bookmarkStartBox)
End Sub
Protected Overrides Sub VisitColumn(ByVal column As LayoutColumn)
AddTreeNode(column, ContentDisplayAction.Select)
MyBase.VisitColumn(column)
End Sub
Protected Overrides Sub VisitColumnBreakBox(ByVal columnBreakBox As PlainTextBox)
AddTreeNode(columnBreakBox, ContentDisplayAction.Select)
MyBase.VisitColumnBreakBox(columnBreakBox)
End Sub
Protected Overrides Sub VisitComment(ByVal comment As LayoutComment)
AddTreeNode(comment, ContentDisplayAction.ScrollTo)
MyBase.VisitComment(comment)
End Sub
Protected Overrides Sub VisitCommentEndBox(ByVal commentEndBox As CommentBox)
AddTreeNode(commentEndBox, ContentDisplayAction.Select)
MyBase.VisitCommentEndBox(commentEndBox)
End Sub
Protected Overrides Sub VisitCommentHighlightAreaBox(ByVal commentHighlightAreaBox As CommentHighlightAreaBox)
AddTreeNode(commentHighlightAreaBox, ContentDisplayAction.Select)
MyBase.VisitCommentHighlightAreaBox(commentHighlightAreaBox)
End Sub
Protected Overrides Sub VisitCommentStartBox(ByVal commentStartBox As CommentBox)
AddTreeNode(commentStartBox, ContentDisplayAction.Select)
MyBase.VisitCommentStartBox(commentStartBox)
End Sub
Protected Overrides Sub VisitFieldHighlightAreaBox(ByVal fieldHighlightAreaBox As FieldHighlightAreaBox)
AddTreeNode(fieldHighlightAreaBox, ContentDisplayAction.Select)
MyBase.VisitFieldHighlightAreaBox(fieldHighlightAreaBox)
End Sub
Protected Overrides Sub VisitFloatingObjectAnchorBox(ByVal floatingObjectAnchorBox As FloatingObjectAnchorBox)
AddTreeNode(floatingObjectAnchorBox, ContentDisplayAction.Select)
MyBase.VisitFloatingObjectAnchorBox(floatingObjectAnchorBox)
End Sub
Protected Overrides Sub VisitFloatingPicture(ByVal floatingPicture As LayoutFloatingPicture)
AddTreeNode(floatingPicture, ContentDisplayAction.ScrollTo)
MyBase.VisitFloatingPicture(floatingPicture)
End Sub
Protected Overrides Sub VisitHiddenTextUnderlineBox(ByVal hiddenTextUnderlineBox As HiddenTextUnderlineBox)
AddTreeNode(hiddenTextUnderlineBox, ContentDisplayAction.Select)
MyBase.VisitHiddenTextUnderlineBox(hiddenTextUnderlineBox)
End Sub
Protected Overrides Sub VisitHighlightAreaBox(ByVal highlightAreaBox As HighlightAreaBox)
AddTreeNode(highlightAreaBox, ContentDisplayAction.Select)
MyBase.VisitHighlightAreaBox(highlightAreaBox)
End Sub
Protected Overrides Sub VisitHyphenBox(ByVal hyphen As PlainTextBox)
AddTreeNode(hyphen, ContentDisplayAction.Select)
MyBase.VisitHyphenBox(hyphen)
End Sub
Protected Overrides Sub VisitInlinePictureBox(ByVal inlinePictureBox As InlinePictureBox)
AddTreeNode(inlinePictureBox, ContentDisplayAction.Select)
MyBase.VisitInlinePictureBox(inlinePictureBox)
End Sub
Protected Overrides Sub VisitLineBreakBox(ByVal lineBreakBox As PlainTextBox)
AddTreeNode(lineBreakBox, ContentDisplayAction.Select)
MyBase.VisitLineBreakBox(lineBreakBox)
End Sub
Protected Overrides Sub VisitLineNumberBox(ByVal lineNumberBox As LineNumberBox)
AddTreeNode(lineNumberBox, ContentDisplayAction.Select)
MyBase.VisitLineNumberBox(lineNumberBox)
End Sub
Protected Overrides Sub VisitNumberingListMarkBox(ByVal numberingListMarkBox As NumberingListMarkBox)
AddTreeNode(numberingListMarkBox, ContentDisplayAction.Select)
MyBase.VisitNumberingListMarkBox(numberingListMarkBox)
End Sub
Protected Overrides Sub VisitNumberingListWithSeparatorBox(ByVal numberingListWithSeparatorBox As NumberingListWithSeparatorBox)
AddTreeNode(numberingListWithSeparatorBox, ContentDisplayAction.Select)
MyBase.VisitNumberingListWithSeparatorBox(numberingListWithSeparatorBox)
End Sub
Protected Overrides Sub VisitPageBreakBox(ByVal pageBreakBox As PlainTextBox)
AddTreeNode(pageBreakBox, ContentDisplayAction.Select)
MyBase.VisitPageBreakBox(pageBreakBox)
End Sub
Protected Overrides Sub VisitPageNumberBox(ByVal pageNumberBox As PlainTextBox)
AddTreeNode(pageNumberBox, ContentDisplayAction.Select)
MyBase.VisitPageNumberBox(pageNumberBox)
End Sub
Protected Overrides Sub VisitParagraphMarkBox(ByVal paragraphMarkBox As PlainTextBox)
AddTreeNode(paragraphMarkBox, ContentDisplayAction.Select)
MyBase.VisitParagraphMarkBox(paragraphMarkBox)
End Sub
Protected Overrides Sub VisitPlainTextBox(ByVal plainTextBox As PlainTextBox)
AddTreeNode(plainTextBox, ContentDisplayAction.Select)
MyBase.VisitPlainTextBox(plainTextBox)
End Sub
Protected Overrides Sub VisitRangePermissionEndBox(ByVal rangePermissionEndBox As RangePermissionBox)
AddTreeNode(rangePermissionEndBox, ContentDisplayAction.Select)
MyBase.VisitRangePermissionEndBox(rangePermissionEndBox)
End Sub
Protected Overrides Sub VisitRangePermissionHighlightAreaBox(ByVal rangePermissionHighlightAreaBox As RangePermissionHighlightAreaBox)
AddTreeNode(rangePermissionHighlightAreaBox, ContentDisplayAction.Select)
MyBase.VisitRangePermissionHighlightAreaBox(rangePermissionHighlightAreaBox)
End Sub
Protected Overrides Sub VisitRangePermissionStartBox(ByVal rangePermissionStartBox As RangePermissionBox)
AddTreeNode(rangePermissionStartBox, ContentDisplayAction.Select)
MyBase.VisitRangePermissionStartBox(rangePermissionStartBox)
End Sub
Protected Overrides Sub VisitRow(ByVal row As LayoutRow)
AddTreeNode(row, ContentDisplayAction.Select)
MyBase.VisitRow(row)
End Sub
Protected Overrides Sub VisitSectionBreakBox(ByVal sectionBreakBox As PlainTextBox)
AddTreeNode(sectionBreakBox, ContentDisplayAction.Select)
MyBase.VisitSectionBreakBox(sectionBreakBox)
End Sub
Protected Overrides Sub VisitSpaceBox(ByVal spaceBox As PlainTextBox)
AddTreeNode(spaceBox, ContentDisplayAction.Select)
MyBase.VisitSpaceBox(spaceBox)
End Sub
Protected Overrides Sub VisitSpecialTextBox(ByVal specialTextBox As PlainTextBox)
AddTreeNode(specialTextBox, ContentDisplayAction.Select)
MyBase.VisitSpecialTextBox(specialTextBox)
End Sub
Protected Overrides Sub VisitStrikeoutBox(ByVal strikeoutBox As StrikeoutBox)
AddTreeNode(strikeoutBox, ContentDisplayAction.Select)
MyBase.VisitStrikeoutBox(strikeoutBox)
End Sub
Protected Overrides Sub VisitTable(ByVal table As LayoutTable)
AddTreeNode(table, ContentDisplayAction.Select)
MyBase.VisitTable(table)
End Sub
Protected Overrides Sub VisitTableCell(ByVal tableCell As LayoutTableCell)
AddTreeNode(tableCell, ContentDisplayAction.Select)
MyBase.VisitTableCell(tableCell)
End Sub
Protected Overrides Sub VisitTableRow(ByVal tableRow As LayoutTableRow)
AddTreeNode(tableRow, ContentDisplayAction.Select)
MyBase.VisitTableRow(tableRow)
End Sub
Protected Overrides Sub VisitTabSpaceBox(ByVal tabSpaceBox As PlainTextBox)
AddTreeNode(tabSpaceBox, ContentDisplayAction.Select)
MyBase.VisitTabSpaceBox(tabSpaceBox)
End Sub
Protected Overrides Sub VisitTextBox(ByVal textBox As LayoutTextBox)
AddTreeNode(textBox, ContentDisplayAction.ScrollTo)
MyBase.VisitTextBox(textBox)
End Sub
Protected Overrides Sub VisitUnderlineBox(ByVal underlineBox As UnderlineBox)
AddTreeNode(underlineBox, ContentDisplayAction.Select)
MyBase.VisitUnderlineBox(underlineBox)
End Sub
Private Sub AddTreeNode(ByVal element As LayoutElement, ByVal displayActionType As ContentDisplayAction)
Dim item As New TreeNode()
' Store the attribute that determines whether document range selection is allowed for this node.
item.Tag = displayActionType
Dim bounds As Rectangle = element.Bounds
item.ToolTipText = String.Format("X = {0}" & ControlChars.Lf & "Y = {1}" & ControlChars.Lf & "Width = {2}" & ControlChars.Lf & "Height = {3}", bounds.X, bounds.Y, bounds.Width, bounds.Height)
' Update the layout element / tree node dictionary.
Dictionary.Add(element, item)
Dim parentItem As TreeNode = Dictionary(element.Parent)
If parentItem IsNot Nothing Then
' Add a new node to the tree.
Dim index As Integer = parentItem.Nodes.Add(item)
' Specify the node caption.
Dim typeName As String = element.Type.ToString()
Select Case element.Type
Case LayoutType.Column
item.Text = String.Format("{0} #{1}", typeName, index)
Case LayoutType.Row
item.Text = String.Format("{0} #{1}", typeName, index + 1)
Case LayoutType.TableRow
item.Text = String.Format("{0} #{1}", typeName, index)
Case Else
item.Text = typeName
End Select
If parentItem.Tag IsNot Nothing Then
' As for the node that does not allow range selection in the document, all its child nodes should have the same attribute.
Dim parentDisplayActionType As ContentDisplayAction = DirectCast(parentItem.Tag, ContentDisplayAction)
Dim actionType As ContentDisplayAction = If(parentDisplayActionType = ContentDisplayAction.ScrollTo, parentDisplayActionType, displayActionType)
item.Tag = actionType
End If
End If
End Sub
End Class
Public Enum ContentDisplayAction
[Select]
ScrollTo
End Enum
Object LayoutVisitor
See Also