// Token: 0x06007A0D RID: 31245 RVA: 0x002291F0 File Offset: 0x002273F0 private static void OnCommandPrint(object sender, ExecutedRoutedEventArgs e) { RootBrowserWindow rootBrowserWindow = sender as RootBrowserWindow; Invariant.Assert(rootBrowserWindow != null); if (!rootBrowserWindow._isPrintingFromRBW) { Visual visual = rootBrowserWindow.Content as Visual; if (visual == null) { IInputElement inputElement = rootBrowserWindow.Content as IInputElement; if (inputElement != null) { rootBrowserWindow._isPrintingFromRBW = true; try { if (ApplicationCommands.Print.CanExecute(null, inputElement)) { ApplicationCommands.Print.Execute(null, inputElement); return; } } finally { rootBrowserWindow._isPrintingFromRBW = false; } } } PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { string printJobDescription = RootBrowserWindow.GetPrintJobDescription(RootBrowserWindow.App.MainWindow); if (visual == null) { INavigatorImpl navigatorImpl = rootBrowserWindow; Invariant.Assert(navigatorImpl != null); visual = navigatorImpl.FindRootViewer(); Invariant.Assert(visual != null); } Rect imageableRect = RootBrowserWindow.GetImageableRect(printDialog); VisualBrush visualBrush = new VisualBrush(visual); visualBrush.Stretch = Stretch.None; DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawRectangle(visualBrush, null, new Rect(imageableRect.X, imageableRect.Y, visual.VisualDescendantBounds.Width, visual.VisualDescendantBounds.Height)); drawingContext.Close(); printDialog.PrintVisual(drawingVisual, printJobDescription); } } }
///<summary> /// Prints the content of the App's MainWindow. The logic is that if the content is not visual but IInputElement /// we will try to let it handle the command first. If it does not handle the print command we will get the corresponding /// visual in the visual tree and use that to print. ///</summary> private static void OnCommandPrint(object sender, ExecutedRoutedEventArgs e) { #if !DONOTREFPRINTINGASMMETA RootBrowserWindow rbw = sender as RootBrowserWindow; Invariant.Assert(rbw != null); if (!rbw._isPrintingFromRBW) { Visual vis = rbw.Content as Visual; if (vis == null) { // If the content is not Visual but IInputElement, try to let it handle the command first. // This is for the document scenario. Printing a document is different from printing a visual. // Printing a visual is to print how it is rendered on screen. Printing a doc prints the full // doc inculding the part that is not visible. There might be other functionalities that are // specific for document. FlowDocument's viewer knows how to print the doc. IInputElement target = rbw.Content as IInputElement; if (target != null) { // CanExecute will bubble up. If nobody between the content and rbw can handle it, // It would call back on RBW again. Use _isPrintingFromRBW to prevent the loop. rbw._isPrintingFromRBW = true; try { if (ApplicationCommands.Print.CanExecute(null, target)) { ApplicationCommands.Print.Execute(null, target); return; } } finally { rbw._isPrintingFromRBW = false; } } } // Let the user choose a printer and set print options. PrintDialog printDlg = new PrintDialog(); // If the user pressed the OK button on the print dialog, we proceed if (printDlg.ShowDialog() == true) { string printJobDescription = GetPrintJobDescription(App.MainWindow); // If the root is not visual and does not know how to print itself, we find the // corresponding visual and use that to print. if (vis == null) { INavigatorImpl navigator = rbw as INavigatorImpl; Invariant.Assert(navigator != null); vis = navigator.FindRootViewer(); Invariant.Assert(vis != null); } // Area we can print to for the chosen printer Rect imageableRect = GetImageableRect(printDlg); // We print Visuals aligned with the top/left corner of the printable area. // We do not attempt to print very large Visuals across multiple pages. // Any portion that doesn't fit on a single page will get cropped by the // print system. // Used to draw our visual into another visual for printing purposes VisualBrush visualBrush = new VisualBrush(vis); visualBrush.Stretch = Stretch.None; // Visual we will print - containing a rectangle the size of our // original Visual but offset into the printable area DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext context = drawingVisual.RenderOpen(); context.DrawRectangle(visualBrush, null, new Rect(imageableRect.X, imageableRect.Y, vis.VisualDescendantBounds.Width, vis.VisualDescendantBounds.Height)); context.Close(); printDlg.PrintVisual(drawingVisual, printJobDescription); } } #endif // DONOTREFPRINTINGASMMETA }