-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubDocumentHelper.vb
52 lines (44 loc) · 2.39 KB
/
SubDocumentHelper.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Runtime.CompilerServices
Namespace SubDocumentIterator
Public Module SubDocumentHelper
Public Delegate Sub SubDocumentDelegate(ByVal subDocument As SubDocument)
<Extension()>
Public Sub ForEachSubDocument(ByVal document As Document, ByVal subDocumentProcessor As SubDocumentDelegate)
subDocumentProcessor(document)
ProcessShapes(document.Shapes, subDocumentProcessor)
ProcessComments(document.Comments, subDocumentProcessor)
For Each section As Section In document.Sections
ProcessSection(section, HeaderFooterType.First, subDocumentProcessor)
ProcessSection(section, HeaderFooterType.Odd, subDocumentProcessor)
ProcessSection(section, HeaderFooterType.Even, subDocumentProcessor)
Next
End Sub
Private Sub ProcessSection(ByVal section As Section, ByVal headerFooterType As HeaderFooterType, ByVal subDocumentProcessor As SubDocumentDelegate)
If section.HasHeader(headerFooterType) Then
Dim header As SubDocument = section.BeginUpdateHeader(headerFooterType)
subDocumentProcessor(header)
ProcessShapes(header.Shapes, subDocumentProcessor)
section.EndUpdateHeader(header)
End If
If section.HasFooter(headerFooterType) Then
Dim footer As SubDocument = section.BeginUpdateFooter(headerFooterType)
subDocumentProcessor(footer)
ProcessShapes(footer.Shapes, subDocumentProcessor)
section.EndUpdateFooter(footer)
End If
End Sub
Private Sub ProcessShapes(ByVal shapes As ShapeCollection, ByVal subDocumentProcessor As SubDocumentDelegate)
For Each shape As Shape In shapes
If shape.TextBox IsNot Nothing Then subDocumentProcessor(shape.TextBox.Document)
Next
End Sub
Private Sub ProcessComments(ByVal comments As CommentCollection, ByVal subDocumentProcessor As SubDocumentDelegate)
For Each comment As Comment In comments
Dim commentSubDocument As SubDocument = comment.BeginUpdate()
subDocumentProcessor(commentSubDocument)
comment.EndUpdate(commentSubDocument)
Next
End Sub
End Module
End Namespace