public override void DrawPageArea(LayoutPageArea pageArea) { Rectangle lineNumberBounds = new Rectangle(new Point(-LineNumberPadding, 0), new Size(LineNumberPadding, pageArea.Bounds.Height)); Canvas.FillRectangle(new RichEditBrush(NumberingHighlightColor), lineNumberBounds); base.DrawPageArea(pageArea); previousColumnIndex = -1; }
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 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); }
private void btnPositionInfo_Click(object sender, EventArgs e) { #region #GetPageForPosition SubDocument subDoc = richEditControl1.Document.CaretPosition.BeginUpdateDocument(); DocumentPosition pos = subDoc.CreatePosition(richEditControl1.Document.CaretPosition.ToInt() == 0 ? 0 : richEditControl1.Document.CaretPosition.ToInt() - 1); LayoutPageArea pageArea = richEditControl1.DocumentLayout.GetElement(pos, LayoutType.PageArea) as LayoutPageArea; LayoutPage page = pageArea.GetParentByType <LayoutPage>(); if (page != null) { string s = String.Format("The caret is on the page with index={0}\r\n" + "The page starts at document position {1},\r\n" + "the range length of the page content is {2}.\r\n", page.Index, page.MainContentRange.Start, page.MainContentRange.Length); lblPageInfo.Text = s; } richEditControl1.Document.CaretPosition.EndUpdateDocument(subDoc); #endregion #GetPageForPosition }
public override void DrawColumn(LayoutColumn column) { LayoutPageArea pageArea = column.GetParentByType <LayoutPageArea>(); if (pageArea != null) { int leftBoundary = 0; if (previousColumnIndex >= 0) { leftBoundary = pageArea.Columns[previousColumnIndex].Bounds.Right; } if (column.LineNumbers.Count > 0) { HighlightLineNumberingArea(column, leftBoundary); } previousColumnIndex++; } base.DrawColumn(column); }
public static PageAreaProperties CaculatePageAreaProperties(LayoutPageArea pageArea, DocumentPosition pos) { PageAreaProperties pageAreaProperties = new PageAreaProperties(); pageAreaProperties.columnCount = pageArea.Columns.Count; pageAreaProperties.currentPageBounds.Location = pageArea.Columns[0].Bounds.Location; for (int i = 0; i < pageArea.Columns.Count; i++) { int currentColumnContentHeight = pageArea.Columns[i].Rows.Last.Bounds.Bottom - pageArea.Columns[i].Rows.First.Bounds.Top; if (pageArea.Columns[i].Range.Contains(pos.ToInt())) { pageAreaProperties.currentColumnIndex = i; pageAreaProperties.currentColumnBounds.Location = pageArea.Columns[i].Bounds.Location; pageAreaProperties.currentColumnBounds.Width = pageArea.Columns[i].Bounds.Width; pageAreaProperties.currentColumnBounds.Height = currentColumnContentHeight; } pageAreaProperties.currentPageBounds.Width += pageArea.Columns[i].Bounds.Width; pageAreaProperties.currentPageBounds.Height = Math.Max(pageAreaProperties.currentPageBounds.Height, currentColumnContentHeight); } return(pageAreaProperties); }
protected override void VisitPageArea(LayoutPageArea pageArea) { TryAddElementToCollection(pageArea, ContentDisplayAction.Select, true); base.VisitPageArea(pageArea); }
public override void DrawPageArea(LayoutPageArea pageArea) { base.DrawPageArea(pageArea); HighlightElement(pageArea); }
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 VisitPageArea(LayoutPageArea pageArea) { AddTreeNode(pageArea, ContentDisplayAction.Select); base.VisitPageArea(pageArea); }