public static string GetInformationAboutRichEditDocumentLayout(Document currentDocument, DocumentLayout currentDocumentLayout)
        {
            SubDocument      subDocument = currentDocument.CaretPosition.BeginUpdateDocument();
            DocumentPosition docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt() == 0 ? 0 : currentDocument.CaretPosition.ToInt() - 1);

            ReadOnlyShapeCollection         shapes = subDocument.Shapes.Get(subDocument.CreateRange(docPosition, 1));
            ReadOnlyDocumentImageCollection images = subDocument.Images.Get(subDocument.CreateRange(docPosition, 1));

            if (shapes.Count == 0 && images.Count == 0)
            {
                docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt());
            }

            string returnedInformation = "";

            // get infromation about a current document element
            returnedInformation += GetInformationAboutCurrentDocumentElement(currentDocument, currentDocumentLayout, subDocument, docPosition);

            // collect information about CURRENT PAGE
            RangedLayoutElement layoutPosition = currentDocumentLayout.GetElement <RangedLayoutElement>(docPosition);

            if (layoutPosition != null)
            {
                int currentPageIndex = currentDocumentLayout.GetPageIndex(layoutPosition);
                returnedInformation += PageLayoutHelper.GetInformationAboutCurrentPage(currentDocumentLayout, currentDocumentLayout.GetPage(currentPageIndex), docPosition);
            }

            currentDocument.CaretPosition.EndUpdateDocument(subDocument);

            return(returnedInformation);
        }
Пример #2
0
        void OnTreeViewItemSelected(object sender, RoutedEventArgs e)
        {
            RichEditTreeViewItem item = (RichEditTreeViewItem)sender;

            if (!item.IsSelected)
            {
                return;
            }
            CurrentTreeItem = item;
            richEdit.Document.ChangeActiveDocument(richEdit.Document);

            LayoutElement element = CurrentTreeItem.Info.Element;

            if (CurrentTreeItem.Info.DisplayAction == ContentDisplayAction.ScrollTo)
            {
                TryScrollToHeader(element);
                TryScrollToFooter(element);
                TryScrollToFloatingObject(element);
                TryScrollToComment(element);
            }
            else
            {
                RangedLayoutElement rangedElement = element as RangedLayoutElement;
                if (rangedElement == null)
                {
                    return;
                }
                ScrollToPosition(rangedElement.Range.Start);
                richEdit.Document.Selection = richEdit.Document.CreateRange(rangedElement.Range.Start, rangedElement.Range.Length);
            }
        }
Пример #3
0
        void richEdit_SelectionChanged(object sender, EventArgs e)
        {
            RangedLayoutElement element = richEdit.DocumentLayout.GetElement <RangedLayoutElement>(richEdit.Document.CaretPosition);

            if (element != null)
            {
                ActivePageNumber = richEdit.DocumentLayout.GetPageIndex(element) + 1;
            }
        }
        private void UpdateInfoAndSelection()
        {
            LayoutElement element = layoutIterator.Current;

            infoElement.Caption = String.Empty;
            if (element != null)
            {
                RangedLayoutElement rangedElement = element as RangedLayoutElement;
                infoElement.Caption = element.Type.ToString();
                if (rangedElement != null)
                {
                    DocumentRange r = doc.CreateRange(rangedElement.Range.Start, rangedElement.Range.Length);
                    richEditControl1.Document.ChangeActiveDocument(doc);
                    richEditControl1.Document.Selection = r;
                }
            }
        }
        private void btnSetRange_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (coloredRange != null)
            {
                ResetRange(coloredRange);
            }

            coloredRange = richEditControl1.Document.Selection;
            if (coloredRange.Length == 0)
            {
                return;
            }

            // Highlight selected range.
            SubDocument         d  = coloredRange.BeginUpdateDocument();
            CharacterProperties cp = d.BeginUpdateCharacters(coloredRange);

            cp.BackColor = System.Drawing.Color.Yellow;
            d.EndUpdateCharacters(cp);
            coloredRange.EndUpdateDocument(d);

            // Create a new iterator limited to the specified range.
            layoutIterator = new LayoutIterator(richEditControl1.DocumentLayout, coloredRange);

            doc = coloredRange.BeginUpdateDocument();
            richEditControl1.Document.ChangeActiveDocument(doc);
            coloredRange.EndUpdateDocument(doc);

            // Select the first element in the highlighted range.
            RangedLayoutElement el = richEditControl1.DocumentLayout.GetElement(coloredRange.Start, LayoutType.PlainTextBox);

            while (layoutIterator.MoveNext())
            {
                RangedLayoutElement element = layoutIterator.Current as RangedLayoutElement;
                if ((element != null) && (element.Equals(el)))
                {
                    UpdateInfoAndSelection();
                    return;
                }
            }
        }
        public static string GetInformationAboutCurrentDocumentElement(Document currentDocument, DocumentLayout currentDocumentLayout, SubDocument currentSubDocument, DocumentPosition docPosition)
        {
            if (currentSubDocument.GetSubDocumentType() == SubDocumentType.TextBox)
            {
                return(TextBoxLayoutHelper.GetInformationAboutCurrentTextBox(currentSubDocument, currentDocumentLayout, docPosition));
            }
            if (currentSubDocument.GetSubDocumentType() == SubDocumentType.Main)
            {
                RangedLayoutElement tableCell = currentDocumentLayout.GetElement(docPosition, LayoutType.TableCell);
                if (tableCell != null)
                {
                    // collect information about TABLE CELL
                    return(DocumentElementLayoutHelper.GetInformationAboutCurrentTableCell(currentDocument, tableCell as LayoutTableCell));
                }

                RangedLayoutElement imageinline = currentDocumentLayout.GetElement(docPosition, LayoutType.InlinePictureBox);
                if (imageinline != null)
                {
                    // collect information about INLINE PICTURE
                    return(DocumentElementLayoutHelper.GetInformationAboutCurrentInlinePicture(imageinline as InlinePictureBox));
                }


                RangedLayoutElement floatingObjectAnchor = currentDocumentLayout.GetElement(docPosition, LayoutType.FloatingObjectAnchorBox);
                if (floatingObjectAnchor != null)
                {
                    // collect information about FLOATING OBJECT
                    return(DocumentElementLayoutHelper.GetInformationAboutCurrentFloatingObject(floatingObjectAnchor as FloatingObjectAnchorBox, currentDocumentLayout));
                }

                RangedLayoutElement regularTextBlock = currentDocumentLayout.GetElement(docPosition, LayoutType.PlainTextBox);
                if (regularTextBlock != null)
                {
                    // collect information about REGULAR TEXT BLOCK
                    return(DocumentElementLayoutHelper.GetInformationAboutRegularTextBlock(regularTextBlock as PlainTextBox, currentDocument));
                }
            }
            return("");
        }
        private void btnStartHere_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (coloredRange != null)
            {
                ResetRange(coloredRange);
            }

            doc = richEditControl1.Document.CaretPosition.BeginUpdateDocument();
            richEditControl1.Document.ChangeActiveDocument(doc);
            layoutIterator = new LayoutIterator(richEditControl1.DocumentLayout, doc.Range);

            RangedLayoutElement el = richEditControl1.DocumentLayout.GetElement(richEditControl1.Document.CaretPosition, LayoutType.PlainTextBox);

            do
            {
                RangedLayoutElement element = layoutIterator.Current as RangedLayoutElement;
                if ((element != null) && (element.Equals(el)))
                {
                    UpdateInfoAndSelection();
                    return;
                }
            } while (layoutIterator.MoveNext());
        }
        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);
            }
        }