-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBoxLayoutHelper.cs
More file actions
64 lines (54 loc) · 3.26 KB
/
TextBoxLayoutHelper.cs
File metadata and controls
64 lines (54 loc) · 3.26 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraRichEdit.API.Layout;
using DevExpress.XtraRichEdit.API.Native;
namespace WindowsFormsApplication1.DocumentLayoutHelper {
public static class TextBoxLayoutHelper {
// get information about a current text box layout
public static string GetInformationAboutCurrentTextBox(SubDocument subDocument, DocumentLayout currentLayout, DocumentPosition docPosition) {
string returnedInformation = "!A TEXTBOX CONTENT IS SELECTED!\r\n";
LayoutIterator layoutIterator = new LayoutIterator(currentLayout, subDocument.Range);
LayoutPage currentTextBoxPage = null;
LayoutTextBox currentTextBox = null;
while(layoutIterator.MoveNext()) {
LayoutElement element = layoutIterator.Current;
if(element is LayoutTextBox) {
currentTextBox = (element as LayoutTextBox);
if (currentTextBox.Parent is LayoutPage) currentTextBoxPage = currentTextBox.Parent as LayoutPage;
}
if(element is PlainTextBox) {
PlainTextBox currentPlaintTextBox = element as PlainTextBox;
if(currentPlaintTextBox.Range.Contains(docPosition.ToInt())) {
returnedInformation += String.Format("Selected content: {0}\r\n", currentPlaintTextBox.Text);
LayoutRow currentRow = currentPlaintTextBox.Parent as LayoutRow;
int currentLineIndex = currentTextBox.Rows.ToList().IndexOf(currentRow);
returnedInformation += String.Format("Line index: {0}\r\n", currentLineIndex + 1);
returnedInformation += String.Format("Selected block bounds: {0}\r\n", currentPlaintTextBox.Bounds);
break;
}
}
}
returnedInformation += String.Format("TEXTBOX bounds: {0}\r\n", currentTextBox.Bounds);
returnedInformation += String.Format("\r\n!!Content information:\r\n");
returnedInformation += GetInformationAboutCurrentTextBoxContent(currentTextBox, currentLayout);
if(currentTextBoxPage != null) {
returnedInformation += PageLayoutHelper.GetInformationAboutCurrentPage(currentLayout, currentTextBoxPage, docPosition);
}
return returnedInformation;
}
public static string GetInformationAboutCurrentTextBoxContent(LayoutTextBox currentTextBox, DocumentLayout currentLayout) {
string returnedInformation = "";
CustomDocumentLayoutVisitor visitor = new CustomDocumentLayoutVisitor();
visitor.Visit(currentTextBox);
SubDocument doc = currentLayout.BeginUpdateDocument(currentTextBox);
string plainTextContent = doc.GetText(doc.Range);
currentLayout.EndUpdateDocument(doc);
returnedInformation += String.Format("Lines count: {0}\r\n", visitor.TextLinesCount);
returnedInformation += String.Format("Words count: {0}\r\n", visitor.WordsCount);
returnedInformation += String.Format("Plain text: {0}\r\n", plainTextContent);
return returnedInformation;
}
}
}