Ejemplo n.º 1
0
        void TryScrollToComment(LayoutElement element)
        {
            LayoutComment layoutComment = element as LayoutComment;

            if (layoutComment == null)
            {
                layoutComment = element.GetParentByType <LayoutComment>();
            }
            if (layoutComment != null)
            {
                Comment comment = layoutComment.GetDocumentComment();
                ScrollToPosition(comment.Range.Start);
            }
        }
Ejemplo n.º 2
0
        void TryScrollToFloatingObject(LayoutElement element)
        {
            LayoutFloatingObject layoutFloatingObject = element as LayoutFloatingObject;

            if (layoutFloatingObject == null)
            {
                layoutFloatingObject = element.GetParentByType <LayoutTextBox>();
            }
            if (layoutFloatingObject != null)
            {
                FloatingObjectAnchorBox anchor = layoutFloatingObject.AnchorBox;
                ScrollToPosition(anchor.Range.Start);
                richEdit.Document.Selection = richEdit.Document.CreateRange(anchor.Range.Start, anchor.Range.Length);
            }
        }
Ejemplo n.º 3
0
        void TryScrollToHeader(LayoutElement element)
        {
            LayoutHeader header = element as LayoutHeader;

            if (header == null)
            {
                header = element.GetParentByType <LayoutHeader>();
            }
            if (header == null)
            {
                return;
            }
            LayoutPageArea nearestPageArea = ((LayoutPage)header.Parent).PageAreas.First;

            ScrollToPosition(nearestPageArea.Range.Start);
        }
Ejemplo n.º 4
0
        void TryScrollToFooter(LayoutElement element)
        {
            LayoutFooter footer = element as LayoutFooter;

            if (footer == null)
            {
                footer = element.GetParentByType <LayoutFooter>();
            }
            if (footer == null)
            {
                return;
            }
            LayoutPageArea nearestPageArea = ((LayoutPage)footer.Parent).PageAreas.Last;

            ScrollToPosition(nearestPageArea.Range.Start + nearestPageArea.Range.Length - 1);
        }
        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);
            }
        }