void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 4 "..\..\PrintPreviewDialog.xaml" ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.PreviousClick); #line default #line hidden return; case 2: #line 8 "..\..\PrintPreviewDialog.xaml" ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.NextClick); #line default #line hidden return; case 3: this.pageViewer = ((System.Windows.Controls.Primitives.DocumentPageView)(target)); return; } this._contentLoaded = true; }
//------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- #region Constructors /// <summary> /// Constructor. /// </summary> /// <param name="owner"> /// Root of layout structure visualizing content of a page. /// </param> /// <param name="textContainer"> /// TextContainer representing content. /// </param> internal DocumentPageTextView(DocumentPageView owner, ITextContainer textContainer) { Invariant.Assert(owner != null && textContainer != null); _owner = owner; _page = owner.DocumentPageInternal; _textContainer = textContainer; // Retrive inner TextView if (_page is IServiceProvider) { _pageTextView = ((IServiceProvider)_page).GetService(typeof(ITextView)) as ITextView; } if (_pageTextView != null) { _pageTextView.Updated += new EventHandler(HandlePageTextViewUpdated); } }
//IDocumentPaginatorSource flowDocument, public static FixedDocument ConvertToFixedDocument(DocumentPaginator documentPaginator) { FixedDocument fixeddoc = new FixedDocument(); // DocumentPaginator paginator = documentPaginator; if (!documentPaginator.IsPageCountValid) documentPaginator.ComputePageCount(); int pageindex; for (pageindex = 0; pageindex < documentPaginator.PageCount; pageindex++) { Grid grid = new Grid(); DocumentPageView pageView = new DocumentPageView(); pageView.DocumentPaginator = documentPaginator; pageView.PageNumber = pageindex; grid.Children.Add(new Border() { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Child = pageView }); FixedPage fixedpage = new FixedPage(); fixedpage.Width = documentPaginator.PageSize.Width; fixedpage.Height = documentPaginator.PageSize.Height; fixedpage.Children.Add(grid); PageContent pc = new PageContent(); ((IAddChild)pc).AddChild(fixedpage); fixeddoc.Pages.Add(pc); } return fixeddoc; }
//------------------------------------------------------------------- // // Internal Methods // //------------------------------------------------------------------- #region Internal Methods /// <summary> /// Determines whether DocumentPageView is a master page. /// </summary> /// <param name="pageView">Instance of DocumentPageView.</param> /// <returns>Whether given instance of DocumentPageView is a master page.</returns> internal bool IsMasterPageView(DocumentPageView pageView) { Invariant.Assert(pageView != null); return (pageView == GetMasterPageView()); }
private IList<IAttachedAnnotation> ProcessAnnotations(DocumentPageView dpv) { if (dpv == null) throw new ArgumentNullException("dpv"); IList<IAttachedAnnotation> attachedAnnotations = new List<IAttachedAnnotation>(); IList<ContentLocatorBase> locators = _locatorManager.GenerateLocators(dpv); if (locators.Count > 0) { // LocatorBases for a single node should always be Locators ContentLocator[] lists = new ContentLocator[locators.Count]; locators.CopyTo(lists, 0); IList<Annotation> annotations = _annotationStore.GetAnnotations(lists[0]); foreach (ContentLocator locator in locators) { if (locator.Parts[locator.Parts.Count - 1].NameValuePairs.ContainsKey(TextSelectionProcessor.IncludeOverlaps)) { locator.Parts.RemoveAt(locator.Parts.Count - 1); } } foreach (Annotation annotation in annotations) { foreach (AnnotationResource anchor in annotation.Anchors) { foreach (ContentLocatorBase locator in anchor.ContentLocators) { AttachmentLevel attachmentLevel; object attachedAnchor = _locatorManager.FindAttachedAnchor(dpv, lists, locator, out attachmentLevel); if (attachmentLevel != AttachmentLevel.Unresolved) { Invariant.Assert(VisualTreeHelper.GetChildrenCount(dpv) == 1, "DocumentPageView has no visual children."); DependencyObject firstElement = VisualTreeHelper.GetChild(dpv, 0); attachedAnnotations.Add(new AttachedAnnotation(_locatorManager, annotation, anchor, attachedAnchor, attachmentLevel, firstElement as DocumentPageHost)); // Only process one locator per resource break; } } } } } return attachedAnnotations; }
///<summary> /// For a given page # and a page, returns a page that include the original /// page along with any annotations that are displayed on that page. /// </summary> /// <param name="page"></param> /// <param name="pageNumber"></param> private DocumentPage ComposePageWithAnnotationVisuals(int pageNumber, DocumentPage page) { // Need to store these because our current highlight mechanism // causes the page to be disposed Size tempSize = page.Size; AdornerDecorator decorator = new AdornerDecorator(); decorator.FlowDirection = _flowDirection; DocumentPageView dpv = new DocumentPageView(); dpv.UseAsynchronousGetPage = false; dpv.DocumentPaginator = _originalPaginator; dpv.PageNumber = pageNumber; decorator.Child = dpv; // Arrange the first time to get the DPV setup right decorator.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); decorator.Arrange(new Rect(decorator.DesiredSize)); decorator.UpdateLayout(); // Create a new one for each page because it keeps a cache of annotation components // and we don't want to be holding them in memory once the page is no longer used AnnotationComponentManager manager = new MS.Internal.Annotations.Component.AnnotationComponentManager(null); // Setup DPs and processors for annotation handling. If the service isn't already // enabled the processors will be registered by the service when it is enabled. if (_isFixedContent) { // Setup service to look for FixedPages in the content AnnotationService.SetSubTreeProcessorId(decorator, FixedPageProcessor.Id); // If the service is already registered, set it up for fixed content _locatorManager.RegisterSelectionProcessor(new FixedTextSelectionProcessor(), typeof(TextRange)); } else { // Setup up an initial DataId used to identify the document AnnotationService.SetDataId(decorator, "FlowDocument"); _locatorManager.RegisterSelectionProcessor(new TextViewSelectionProcessor(), typeof(DocumentPageView)); // Setup the selection processor, pre-targeting it at a specific DocumentPageView TextSelectionProcessor textSelectionProcessor = new TextSelectionProcessor(); textSelectionProcessor.SetTargetDocumentPageView(dpv); _locatorManager.RegisterSelectionProcessor(textSelectionProcessor, typeof(TextRange)); } // Get attached annotations for the page IList<IAttachedAnnotation> attachedAnnotations = ProcessAnnotations(dpv); // Now make sure they have a visual component added to the DPV via the component manager foreach (IAttachedAnnotation attachedAnnotation in attachedAnnotations) { if (attachedAnnotation.AttachmentLevel != AttachmentLevel.Unresolved && attachedAnnotation.AttachmentLevel != AttachmentLevel.Incomplete) { manager.AddAttachedAnnotation(attachedAnnotation, false); } } // Update layout a second time to get the annotations layed out correctly decorator.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); decorator.Arrange(new Rect(decorator.DesiredSize)); decorator.UpdateLayout(); /* Look into using the VisualBrush in order to get a dead page instead of a live one... VisualBrush visualBrush = new VisualBrush(decorator); Rectangle rectangle = new Rectangle(); rectangle.Fill = visualBrush; rectangle.Margin = new Thickness(0); */ return new AnnotatedDocumentPage(page, decorator, tempSize, new Rect(tempSize), new Rect(tempSize)); }
/// <summary> /// Set the DocumentPageView this selection processor should use /// when clamping text anchors. If this target is not set then /// the set of DPVs held by the viewer are used. /// </summary> internal void SetTargetDocumentPageView(DocumentPageView target) { Debug.Assert(target != null); _targetPage = target; }
/// <summary> /// The add page body. /// </summary> /// <param name="sourceFlowDocPaginator"> /// The source flow doc paginator. /// </param> /// <param name="pageNo"> /// The page no. /// </param> /// <param name="pageCanvas"> /// The page canvas. /// </param> /// <param name="margins"> /// The margins. /// </param> private void AddPageBody( DocumentPaginator sourceFlowDocPaginator, int pageNo, Canvas pageCanvas, Thickness margins) { using (var dpv = new DocumentPageView()) { dpv.DocumentPaginator = sourceFlowDocPaginator; dpv.PageNumber = pageNo; Canvas.SetTop(dpv, margins.Top); Canvas.SetLeft(dpv, margins.Left); pageCanvas.Children.Add(dpv); } }
//------------------------------------------------------------------- // // Private Methods // //------------------------------------------------------------------- #region Private Methods /// <summary> /// Creates the static members of DocumentGridPage's Visual Tree. /// </summary> private void Init() { //Create the DocumentPageView, which will display our //content. _documentPageView = new DocumentPageView(); _documentPageView.ClipToBounds = true; _documentPageView.StretchDirection = StretchDirection.Both; _documentPageView.PageNumber = int.MaxValue; //Create the border that goes around the page content. _pageBorder = new Border(); _pageBorder.BorderBrush = Brushes.Black; _pageBorder.Child = _documentPageView; //Create the drop shadow that goes behind the page, made //of two rectangles in an "L" shape. _dropShadowRight = new Rectangle(); _dropShadowRight.Fill = Brushes.Black; _dropShadowRight.Opacity = _dropShadowOpacity; _dropShadowBottom = new Rectangle(); _dropShadowBottom.Fill = Brushes.Black; _dropShadowBottom.Opacity = _dropShadowOpacity; _loaded = false; }
/// <summary> /// Constructor. /// </summary> /// <param name="owner">Owner of the AutomationPeer.</param> public DocumentPageViewAutomationPeer(DocumentPageView owner) : base(owner) {}
/// <summary> /// Creates a <see cref="FixedDocument"/> containing the text. /// </summary> /// <param name="pageSize">Size of the page.</param> /// <param name="documentTitle">The document title (can be <see langword="null"/>).</param> /// <returns>A <see cref="FixedDocument"/>.</returns> /// <remarks>This document can be used for printing.</remarks> public FixedDocument CreateFixedDocument(Size pageSize, string documentTitle) { // Create fixed document with the specified page size. var fixedDocument = new FixedDocument(); fixedDocument.DocumentPaginator.PageSize = pageSize; // We add a hardcoded border. var borderPadding = new Thickness(96, 90, 96, 80); // CreateFlowDocument() creates the highlighted, word-wrapped pages for us. var flowDocument = CreateFlowDocument(pageSize, borderPadding); var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator; paginator.ComputePageCount(); // Loop through all pages and add a FixedPage for each page in the FlowDocument. var numberOfPages = paginator.PageCount; for (int pageNumber = 0; pageNumber < numberOfPages; pageNumber++) { var fixedPage = new FixedPage { Width = fixedDocument.DocumentPaginator.PageSize.Width, Height = fixedDocument.DocumentPaginator.PageSize.Height }; // The first child of the FixedPage is a DocumentPageView control that displays // a page of the FlowDocument. var documentPageView = new DocumentPageView { DocumentPaginator = paginator, PageNumber = pageNumber, }; fixedPage.Children.Add(documentPageView); // The second child of the FixedPage is a header with document title and page number. var header = new Grid { Margin = new Thickness(borderPadding.Left, 60, 0, 0), Width = pageSize.Width - borderPadding.Left - borderPadding.Right, }; header.Children.Add(new Border { BorderBrush = Brushes.Black, BorderThickness = new Thickness(0, 0, 0, 0.5), }); header.Children.Add(new TextBlock(new Run($"{pageNumber + 1} / {numberOfPages}")) { FontFamily = new FontFamily("Times New Roman"), FontSize = 10, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 0, 3), }); header.Children.Add(new TextBlock(new Run(documentTitle)) { FontFamily = new FontFamily("Times New Roman"), FontSize = 10, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 0, 0, 3), }); fixedPage.Children.Add(header); // Add the FixedPage to the FixedDocument. PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(fixedPage); fixedDocument.Pages.Add(pageContent); } return fixedDocument; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 7 "..\..\..\PrintPreviewDialog.xaml" ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.PreviousClick); #line default #line hidden return; case 2: #line 11 "..\..\..\PrintPreviewDialog.xaml" ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.NextClick); #line default #line hidden return; case 3: this.pageViewer = ((System.Windows.Controls.Primitives.DocumentPageView)(target)); return; } this._contentLoaded = true; }
/// <summary> /// Adds a page body. /// </summary> /// <param name="sourceFlowDocPaginator">The source flow document paginator.</param> /// <param name="pageNumber">The page number.</param> /// <param name="pageCanvas">The page canvas.</param> /// <param name="margins">The margins.</param> private void AddPageBody(DocumentPaginator sourceFlowDocPaginator, int pageNumber, Canvas pageCanvas, Thickness margins) { var dpv = new DocumentPageView { DocumentPaginator = sourceFlowDocPaginator, PageNumber = pageNumber }; Canvas.SetTop(dpv, margins.Top); Canvas.SetLeft(dpv, margins.Left); pageCanvas.Children.Add(dpv); }
public WhiteDocumentPageViewPeer(DocumentPageView owner) : base(owner) { whitePeer = WhitePeer.Create(this, owner); }