// get information about a current floating object
        public static string GetInformationAboutCurrentFloatingObject(FloatingObjectAnchorBox currentObjectAnchor, DocumentLayout currentLayout)
        {
            LayoutFloatingObject currentFloatingObject = currentObjectAnchor.FloatingObjectBox;
            string returnedInformation = "";

            if (currentFloatingObject.Type == LayoutType.FloatingPicture)
            {
                returnedInformation = "!A FLOATING PICTURE IS SELECTED!\r\n";
            }
            else if (currentFloatingObject.Type == LayoutType.TextBox)
            {
                returnedInformation = "!A TEXT BOX IS SELECTED!\r\n";
            }

            returnedInformation += String.Format("Anchor location: {0}\r\n", currentObjectAnchor.Bounds.Location);
            returnedInformation += String.Format("Object bounds: {0}\r\n", currentFloatingObject.Bounds);
            returnedInformation += String.Format("Rotation: {0}\r\n", currentFloatingObject.RotationAngle);

            if (currentFloatingObject.Type == LayoutType.TextBox)
            {
                LayoutTextBox currentTextBox = currentFloatingObject as LayoutTextBox;
                returnedInformation += String.Format("\r\n!!Content information:\r\n");
                returnedInformation += TextBoxLayoutHelper.GetInformationAboutCurrentTextBoxContent(currentTextBox, currentLayout);
            }
            else if (currentFloatingObject.Type == LayoutType.FloatingPicture)
            {
                LayoutFloatingPicture currentFloatingPicture = currentFloatingObject as LayoutFloatingPicture;
                returnedInformation += String.Format("\r\n!!Image properties:\r\n");
                returnedInformation += GetInformationAboutOfficeImage(currentFloatingPicture.Image);
            }

            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);
        }
        // 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 override void DrawTextBox(LayoutTextBox textBox)
 {
     if (MainWindow.customDrawTextBox == true)
     {
         Point[] StarPoints =
         {
             new Point(textBox.Bounds.X + textBox.Bounds.Width / 2, textBox.Bounds.Y),
             new Point(textBox.Bounds.X + textBox.Bounds.Width,     textBox.Bounds.Y + textBox.Bounds.Height),
             new Point(textBox.Bounds.X,                            textBox.Bounds.Y + textBox.Bounds.Height / 2),
             new Point(textBox.Bounds.X + textBox.Bounds.Width,     textBox.Bounds.Y + textBox.Bounds.Height / 2),
             new Point(textBox.Bounds.X,                            textBox.Bounds.Y + textBox.Bounds.Height),
             new Point(textBox.Bounds.X + textBox.Bounds.Width / 2, textBox.Bounds.Y)
         };
         Canvas.DrawLines(new RichEditPen(System.Windows.Media.Color.FromRgb(255, 105, 180), 30), StarPoints);
     }
     else
     {
         base.DrawTextBox(textBox);
     }
 }
 public override void DrawTextBox(LayoutTextBox textBox)
 {
     if (Form1.customDrawTextBox == true)
     {
         Point[] StarPoints =
         {
             new Point(textBox.Bounds.X + textBox.Bounds.Width / 2, textBox.Bounds.Y),
             new Point(textBox.Bounds.X + textBox.Bounds.Width,     textBox.Bounds.Y + textBox.Bounds.Height),
             new Point(textBox.Bounds.X,                            textBox.Bounds.Y + textBox.Bounds.Height / 2),
             new Point(textBox.Bounds.X + textBox.Bounds.Width,     textBox.Bounds.Y + textBox.Bounds.Height / 2),
             new Point(textBox.Bounds.X,                            textBox.Bounds.Y + textBox.Bounds.Height),
             new Point(textBox.Bounds.X + textBox.Bounds.Width / 2, textBox.Bounds.Y)
         };
         Canvas.DrawLines(new RichEditPen(Color.HotPink, 30), StarPoints);
     }
     else
     {
         base.DrawTextBox(textBox);
     }
 }
 protected override void VisitTextBox(LayoutTextBox textBox)
 {
     TryAddElementToCollection(textBox, ContentDisplayAction.ScrollTo, true);
     base.VisitTextBox(textBox);
 }
 public override void DrawTextBox(LayoutTextBox textBox)
 {
     base.DrawTextBox(textBox);
     HighlightElement(textBox);
 }
        void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (!(e.Node.IsSelected) || e.Node.Tag == null)
            {
                return;
            }
            // Rebuild the tree if required.
            rebuild = true;

            richEditControl1.Document.ChangeActiveDocument(richEditControl1.Document);
            LayoutElement       element       = layoutTreeDictionary[e.Node];
            RangedLayoutElement rangedElement = element as RangedLayoutElement;

            // Select a range or scroll to a document position, according to the type of the layout element.
            if ((ContentDisplayAction)e.Node.Tag == ContentDisplayAction.ScrollTo)
            {
                LayoutPage     page            = element.GetParentByType <LayoutPage>();
                LayoutPageArea nearestPageArea = page.PageAreas[0];

                if ((element.Type == LayoutType.Header) || (element.GetParentByType <LayoutHeader>() != null))
                {
                    ScrollToPosition(nearestPageArea.Range.Start);
                }
                if ((element.Type == LayoutType.Footer) || (element.GetParentByType <LayoutFooter>() != null))
                {
                    ScrollToPosition(nearestPageArea.Range.Start + nearestPageArea.Range.Length);
                }
                LayoutFloatingObject layoutFloatingObject = element as LayoutFloatingObject;
                if (layoutFloatingObject != null)
                {
                    FloatingObjectAnchorBox anchor = layoutFloatingObject.AnchorBox;
                    ScrollToPosition(anchor.Range.Start);
                    richEditControl1.Document.Selection = richEditControl1.Document.CreateRange(anchor.Range.Start, anchor.Range.Length);
                }
                LayoutComment layoutComment = element as LayoutComment;
                if (layoutComment != null)
                {
                    Comment comment = layoutComment.GetDocumentComment();
                    ScrollToPosition(comment.Range.Start.ToInt());
                }

                LayoutTextBox textBox = element.GetParentByType <LayoutTextBox>();
                if (textBox != null)
                {
                    // Do not rebuild the tree.
                    rebuild = false;
                    ScrollToPosition(textBox.AnchorBox.Range.Start);
                    SubDocument doc = richEditControl1.DocumentLayout.BeginUpdateDocument(textBox);
                    richEditControl1.Document.ChangeActiveDocument(doc);
                    richEditControl1.Document.Selection = doc.CreateRange(rangedElement.Range.Start, rangedElement.Range.Length);
                    richEditControl1.DocumentLayout.EndUpdateDocument(doc);
                }
            }
            else
            {
                if (rangedElement == null)
                {
                    return;
                }
                ScrollToPosition(rangedElement.Range.Start);
                richEditControl1.Document.Selection = richEditControl1.Document.CreateRange(rangedElement.Range.Start, rangedElement.Range.Length);
            }
        }
 protected override void VisitTextBox(LayoutTextBox textBox)
 {
     AddTreeNode(textBox, ContentDisplayAction.ScrollTo);
     base.VisitTextBox(textBox);
 }
Example #10
0
 protected override void VisitTextBox(LayoutTextBox textBox)
 {
     TextBoxesCount++;
     base.VisitTextBox(textBox);
 }