Example #1
0
        private void window_Loaded(object sender, RoutedEventArgs e)
        {
            doc = new XpsDocument("ch19.xps", FileAccess.ReadWrite);
            docViewer.Document = doc.GetFixedDocumentSequence();

            service = AnnotationService.GetService(docViewer);
            if (service == null)
            {
                Uri annotationUri = PackUriHelper.CreatePartUri(new Uri("AnnotationStream", UriKind.Relative));
                Package package = PackageStore.GetPackage(doc.Uri);
                PackagePart annotationPart = null;
                if (package.PartExists(annotationUri))
                {                    
                    annotationPart = package.GetPart(annotationUri);
                }
                else                
                {                    
                    annotationPart = package.CreatePart(annotationUri, "Annotations/Stream");
                }

                // Load annotations from the package.
                AnnotationStore store = new XmlStreamStore(annotationPart.GetStream());
                service = new AnnotationService(docViewer);
                service.Enable(store);
                
            }
        }
        // Token: 0x060062D4 RID: 25300 RVA: 0x001BBA20 File Offset: 0x001B9C20
        private static IList <IAttachedAnnotation> GetSpannedAnnotationsForFixed(AnnotationService service, int startPage, int endPage)
        {
            Invariant.Assert(service != null, "Need non-null service to get spanned annotations for fixed content.");
            FixedPageProcessor fixedPageProcessor = service.LocatorManager.GetSubTreeProcessorForLocatorPart(FixedPageProcessor.CreateLocatorPart(0)) as FixedPageProcessor;

            Invariant.Assert(fixedPageProcessor != null, "FixedPageProcessor should be available if we are processing fixed content.");
            List <IAttachedAnnotation> result      = null;
            List <Annotation>          annotations = new List <Annotation>();

            try
            {
                fixedPageProcessor.UseLogicalTree = true;
                for (int i = startPage; i <= endPage; i++)
                {
                    ContentLocator contentLocator = new ContentLocator();
                    contentLocator.Parts.Add(FixedPageProcessor.CreateLocatorPart(i));
                    AnnotationHelper.AddRange(annotations, service.Store.GetAnnotations(contentLocator));
                }
                result = AnnotationHelper.ResolveAnnotations(service, annotations);
            }
            finally
            {
                fixedPageProcessor.UseLogicalTree = false;
            }
            return(result);
        }
        // Token: 0x060062DB RID: 25307 RVA: 0x001BBFD4 File Offset: 0x001BA1D4
        private static Annotation ProcessHighlights(AnnotationService service, ITextRange textRange, string author, Color?color, bool create)
        {
            Invariant.Assert(textRange != null, "Parameter 'textRange' is null.");
            IList <IAttachedAnnotation> spannedAnnotations = AnnotationHelper.GetSpannedAnnotations(service);

            foreach (IAttachedAnnotation attachedAnnotation in spannedAnnotations)
            {
                if (HighlightComponent.TypeName.Equals(attachedAnnotation.Annotation.AnnotationType))
                {
                    TextAnchor textAnchor = attachedAnnotation.FullyAttachedAnchor as TextAnchor;
                    Invariant.Assert(textAnchor != null, "FullyAttachedAnchor must not be null.");
                    TextAnchor textAnchor2 = new TextAnchor(textAnchor);
                    textAnchor2 = TextAnchor.TrimToRelativeComplement(textAnchor2, textRange.TextSegments);
                    if (textAnchor2 == null || textAnchor2.IsEmpty)
                    {
                        service.Store.DeleteAnnotation(attachedAnnotation.Annotation.Id);
                    }
                    else
                    {
                        AnnotationHelper.SetAnchor(service, attachedAnnotation.Annotation, textAnchor2);
                    }
                }
            }
            if (create)
            {
                Annotation annotation = AnnotationHelper.CreateHighlight(service, textRange, author, color);
                service.Store.AddAnnotation(annotation);
                return(annotation);
            }
            return(null);
        }
        // Token: 0x060062CF RID: 25295 RVA: 0x001BB61C File Offset: 0x001B981C
        private static Annotation CreateStickyNoteForSelection(AnnotationService service, XmlQualifiedName noteType, string author)
        {
            AnnotationHelper.CheckInputs(service);
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            if (textSelection.IsEmpty)
            {
                throw new InvalidOperationException(SR.Get("EmptySelectionNotSupported"));
            }
            Annotation annotation = null;

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateStickyNoteBegin);
            try
            {
                annotation = AnnotationHelper.CreateAnnotationForSelection(service, textSelection, noteType, author);
                Invariant.Assert(annotation != null, "CreateAnnotationForSelection returned null.");
                service.Store.AddAnnotation(annotation);
                textSelection.SetCaretToPosition(textSelection.MovingPosition, textSelection.MovingPosition.LogicalDirection, true, true);
            }
            finally
            {
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateStickyNoteEnd);
            }
            return(annotation);
        }
        // Token: 0x060062C5 RID: 25285 RVA: 0x001BB4E0 File Offset: 0x001B96E0
        internal static void OnClearHighlightsCommand(object sender, ExecutedRoutedEventArgs e)
        {
            DependencyObject dependencyObject = sender as DependencyObject;

            if (dependencyObject != null)
            {
                AnnotationHelper.ClearHighlightsForSelection(AnnotationService.GetService(dependencyObject));
            }
        }
Example #6
0
        public static Annotation CreateTextStickyNoteForSelection(AnnotationService service, string author)
        {
            Contract.Ensures(!string.IsNullOrEmpty(System.Windows.Controls.StickyNoteControl.TextSchemaName.Name));
            Contract.Ensures(!string.IsNullOrEmpty(System.Windows.Controls.StickyNoteControl.TextSchemaName.Namespace));
            Contract.Ensures(Contract.Result <System.Windows.Annotations.Annotation>() != null);
            Contract.Ensures(System.DateTime.Now.Kind == ((System.DateTimeKind)(2)));

            return(default(Annotation));
        }
        // Token: 0x060062C4 RID: 25284 RVA: 0x001BB4B0 File Offset: 0x001B96B0
        internal static void OnCreateInkStickyNoteCommand(object sender, ExecutedRoutedEventArgs e)
        {
            DependencyObject dependencyObject = sender as DependencyObject;

            if (dependencyObject != null)
            {
                AnnotationHelper.CreateInkStickyNoteForSelection(AnnotationService.GetService(dependencyObject), e.Parameter as string);
            }
        }
        // Token: 0x060062C2 RID: 25282 RVA: 0x001BB444 File Offset: 0x001B9644
        internal static void OnCreateHighlightCommand(object sender, ExecutedRoutedEventArgs e)
        {
            DependencyObject dependencyObject = sender as DependencyObject;

            if (dependencyObject != null)
            {
                AnnotationHelper.CreateHighlightForSelection(AnnotationService.GetService(dependencyObject), null, (e.Parameter != null) ? (e.Parameter as Brush) : null);
            }
        }
    public static Annotation CreateTextStickyNoteForSelection(AnnotationService service, string author)
    {
      Contract.Ensures(!string.IsNullOrEmpty(System.Windows.Controls.StickyNoteControl.TextSchemaName.Name));
      Contract.Ensures(!string.IsNullOrEmpty(System.Windows.Controls.StickyNoteControl.TextSchemaName.Namespace));
      Contract.Ensures(Contract.Result<System.Windows.Annotations.Annotation>() != null);
      Contract.Ensures(System.DateTime.Now.Kind == ((System.DateTimeKind)(2)));

      return default(Annotation);
    }
 /// <summary> 
 /// Return an annotation component manager.  If an annotation service is passed in, manager will
 /// receive notification from the service.  Otherwise it will expect to be called directly. 
 /// </summary>
 /// <param name="service">optional, annotation service the annotation component manager will register on</param>
 internal AnnotationComponentManager(AnnotationService service)
     : base() 
 {
     // Only register if a service was passed in. If no service was passed in, we will not receive events. 
     // This means a client will be calling us directly. 
     if (service != null)
     { 
         service.AttachedAnnotationChanged += new AttachedAnnotationChangedEventHandler(AttachedAnnotationUpdateEventHandler);
     }
 }
        // Token: 0x060062C6 RID: 25286 RVA: 0x001BB504 File Offset: 0x001B9704
        internal static void OnDeleteStickyNotesCommand(object sender, ExecutedRoutedEventArgs e)
        {
            DependencyObject dependencyObject = sender as DependencyObject;

            if (dependencyObject != null)
            {
                AnnotationHelper.DeleteTextStickyNotesForSelection(AnnotationService.GetService(dependencyObject));
                AnnotationHelper.DeleteInkStickyNotesForSelection(AnnotationService.GetService(dependencyObject));
            }
        }
 /// <summary>Clears all highlight annotations from the current selection of the viewer control associated with the given <see cref="T:System.Windows.Annotations.AnnotationService" />.</summary>
 /// <param name="service">The annotation service from which to remove highlight annotations.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///         <paramref name="service" /> is <see langword="null" />.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///         <paramref name="service" /> is not enabled.</exception>
 // Token: 0x060062BE RID: 25278 RVA: 0x001BB204 File Offset: 0x001B9404
 public static void ClearHighlightsForSelection(AnnotationService service)
 {
     EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.ClearHighlightBegin);
     try
     {
         AnnotationHelper.Highlight(service, null, null, false);
     }
     finally
     {
         EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.ClearHighlightEnd);
     }
 }
 /// <summary>Deletes ink sticky note annotations that are wholly contained within the current selection of the viewer control associated with the given <see cref="T:System.Windows.Annotations.AnnotationService" />.</summary>
 /// <param name="service">The annotation service from which to delete ink sticky note annotations.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///         <paramref name="service" /> is <see langword="null" />.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///         <paramref name="service" /> is not enabled.</exception>
 // Token: 0x060062C0 RID: 25280 RVA: 0x001BB28C File Offset: 0x001B948C
 public static void DeleteInkStickyNotesForSelection(AnnotationService service)
 {
     EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeleteInkNoteBegin);
     try
     {
         AnnotationHelper.DeleteSpannedAnnotations(service, StickyNoteControl.InkSchemaName);
     }
     finally
     {
         EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeleteInkNoteEnd);
     }
 }
Example #14
0
 protected void OnInitialized(object sender, EventArgs e)
 {
     // Включить и загрузить комментарии 
     AnnotationService service = AnnotationService.GetService(reader);
     if (service == null)
     {
         stream = new FileStream("storage.xml", FileMode.OpenOrCreate);
         service = new AnnotationService(reader);
         AnnotationStore store = new XmlStreamStore(stream);
         store.AutoFlush = true;
         service.Enable(store);
     }
 }
        // Token: 0x060062D9 RID: 25305 RVA: 0x001BBE0C File Offset: 0x001BA00C
        private static Annotation CreateAnnotationForSelection(AnnotationService service, ITextRange textSelection, XmlQualifiedName annotationType, string author)
        {
            Invariant.Assert(service != null && textSelection != null, "Parameter 'service' or 'textSelection' is null.");
            Invariant.Assert(annotationType != null && (annotationType == HighlightComponent.TypeName || annotationType == StickyNoteControl.TextSchemaName || annotationType == StickyNoteControl.InkSchemaName), "Invalid Annotation Type");
            Annotation annotation = new Annotation(annotationType);

            AnnotationHelper.SetAnchor(service, annotation, textSelection);
            if (author != null)
            {
                annotation.Authors.Add(author);
            }
            return(annotation);
        }
Example #16
0
 private void Window_Initialized(object sender, EventArgs e)
 {
     // Enables and Loads Annotations
     AnnotationService service = AnnotationService.GetService(reader);
     if (service == null)
     {
         stream = new FileStream("storage.xml", FileMode.OpenOrCreate);
         service = new AnnotationService(reader);
         AnnotationStore store = new XmlStreamStore(stream);
         store.AutoFlush = true;
         service.Enable(store);
     }
 }
        // Token: 0x060062DE RID: 25310 RVA: 0x001BC190 File Offset: 0x001BA390
        private static void SetAnchor(AnnotationService service, Annotation annot, object selection)
        {
            Invariant.Assert(annot != null && selection != null, "null input parameter");
            IList <ContentLocatorBase> list = service.LocatorManager.GenerateLocators(selection);

            Invariant.Assert(list != null && list.Count > 0, "No locators generated for selection.");
            AnnotationResource annotationResource = new AnnotationResource();

            foreach (ContentLocatorBase item in list)
            {
                annotationResource.ContentLocators.Add(item);
            }
            annot.Anchors.Clear();
            annot.Anchors.Add(annotationResource);
        }
Example #18
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // Load annotations store
            _stream = new FileStream("storage.xml", FileMode.OpenOrCreate);
            _service = new AnnotationService(flowDocumentReader);
            _store = new XmlStreamStore(_stream) {AutoFlush = true};
            _service.Enable(_store);

            // Detect when annotations are added or deleted
            _service.Store.StoreContentChanged +=
                AnnotationStore_StoreContentChanged;

            // Bind to annotations in store
            BindToAnnotations(_store.GetAnnotations());
        }
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // Use permanent annotation storage
            this.stream = new FileStream("storage.xml", FileMode.OpenOrCreate);
            this.service = new AnnotationService(this.flowDocumentReader);
            this.store = new XmlStreamStore(this.stream);
            this.store.AutoFlush = true;
            this.service.Enable(this.store);

            // Detect when annotations are added or deleted
            this.service.Store.StoreContentChanged += new StoreContentChangedEventHandler(AnnotationStore_StoreContentChanged);

            // Bind to annotations in store
            BindToAnnotations(this.store.GetAnnotations());
        }
        // Token: 0x060062D6 RID: 25302 RVA: 0x001BBB80 File Offset: 0x001B9D80
        private static List <IAttachedAnnotation> ResolveAnnotations(AnnotationService service, IList <Annotation> annotations)
        {
            Invariant.Assert(annotations != null);
            List <IAttachedAnnotation> list = new List <IAttachedAnnotation>(annotations.Count);

            foreach (Annotation annotation in annotations)
            {
                AttachmentLevel attachmentLevel;
                object          obj = service.LocatorManager.ResolveLocator(annotation.Anchors[0].ContentLocators[0], 0, service.Root, out attachmentLevel);
                if (attachmentLevel != AttachmentLevel.Incomplete && attachmentLevel != AttachmentLevel.Unresolved && obj != null)
                {
                    list.Add(new AttachedAnnotation(service.LocatorManager, annotation, annotation.Anchors[0], obj, attachmentLevel));
                }
            }
            return(list);
        }
        /// <summary>Creates a highlight annotation on the current selection of the viewer control associated with the specified <see cref="T:System.Windows.Annotations.AnnotationService" />.</summary>
        /// <param name="service">The annotation service to use to create the highlight annotation.</param>
        /// <param name="author">The author of the annotation.</param>
        /// <param name="highlightBrush">The brush to use to draw the highlight over the selected content.</param>
        /// <returns>The highlight annotation; or <see langword="null" />, if there is no selected content to highlight.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="service" /> is <see langword="null" />.</exception>
        /// <exception cref="T:System.ArgumentException">
        ///         <paramref name="service" /> is not enabled. -or-
        ///         <paramref name="highlightBrush" /> in not a <see cref="T:System.Windows.Media.SolidColorBrush" />.</exception>
        /// <exception cref="T:System.InvalidOperationException">The viewer control contains no content selection.</exception>
        // Token: 0x060062BB RID: 25275 RVA: 0x001BB194 File Offset: 0x001B9394
        public static Annotation CreateHighlightForSelection(AnnotationService service, string author, Brush highlightBrush)
        {
            Annotation annotation = null;

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateHighlightBegin);
            try
            {
                annotation = AnnotationHelper.Highlight(service, author, highlightBrush, true);
                Invariant.Assert(annotation != null, "Highlight not returned from create call.");
            }
            finally
            {
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateHighlightEnd);
            }
            return(annotation);
        }
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();

            XpsDocument xd =
            new XpsDocument("annotation.xps", System.IO.FileAccess.ReadWrite);
            dv.Document = xd.GetFixedDocumentSequence();

            ans = new AnnotationService(dv);

            fs=
            new FileStream(
                         "annotation.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite);

            ans.Enable(new XmlStreamStore(fs));
            ans.Store.AutoFlush = true;
        }
        // Token: 0x060062DC RID: 25308 RVA: 0x001BC0CC File Offset: 0x001BA2CC
        private static Annotation CreateHighlight(AnnotationService service, ITextRange textRange, string author, Color?color)
        {
            Invariant.Assert(textRange != null, "textRange is null");
            Annotation annotation = AnnotationHelper.CreateAnnotationForSelection(service, textRange, HighlightComponent.TypeName, author);

            if (color != null)
            {
                ColorConverter colorConverter = new ColorConverter();
                XmlDocument    xmlDocument    = new XmlDocument();
                XmlElement     xmlElement     = xmlDocument.CreateElement("Colors", "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                xmlElement.SetAttribute("Background", colorConverter.ConvertToInvariantString(color.Value));
                AnnotationResource annotationResource = new AnnotationResource("Highlight");
                annotationResource.Contents.Add(xmlElement);
                annotation.Cargos.Add(annotationResource);
            }
            return(annotation);
        }
Example #24
0
        //----------------------------------------------------- 
        // 
        //  Public Methods
        // 
        //-----------------------------------------------------

        #region Public Methods
 
        /// <summary>
        ///     Creates a highlight annotation for the service.  The anchor used is the 
        ///     current selection in the DocumentViewerBase associated with the service. 
        ///     If the selection length is 0 no highlight is created.
        /// </summary> 
        /// <param name="service">service used to create annotation</param>
        /// <param name="author">annotation author added to new annotation; if null, no author added</param>
        /// <param name="highlightBrush">the brush to use when drawing the highlight; if null, uses default highlight brush</param>
        /// <exception cref="ArgumentNullException">service is null</exception> 
        /// <exception cref="ArgumentException">service is not enabled or highlightBrush is not a SolidColorBrush</exception>
        /// <exception cref="InvalidOperationException">selection is of zero length</exception> 
        /// <returns>the Annotation created</returns> 
        public static Annotation CreateHighlightForSelection(AnnotationService service, string author, Brush highlightBrush)
        { 
            Annotation highlight = null;
            //fire start trace event
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateHighlightBegin);
 
            try
            { 
                highlight = Highlight(service, author, highlightBrush, true); 
                Invariant.Assert(highlight != null, "Highlight not returned from create call.");
            } 
            finally
            {
                //fire end trace event
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateHighlightEnd); 
            }
            return highlight; 
        } 
        // Token: 0x0600629A RID: 25242 RVA: 0x001BA878 File Offset: 0x001B8A78
        private DocumentPage ComposePageWithAnnotationVisuals(int pageNumber, DocumentPage page)
        {
            Size             size             = page.Size;
            AdornerDecorator adornerDecorator = new AdornerDecorator();

            adornerDecorator.FlowDirection = this._flowDirection;
            DocumentPageView documentPageView = new DocumentPageView();

            documentPageView.UseAsynchronousGetPage = false;
            documentPageView.DocumentPaginator      = this._originalPaginator;
            documentPageView.PageNumber             = pageNumber;
            adornerDecorator.Child = documentPageView;
            adornerDecorator.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            adornerDecorator.Arrange(new Rect(adornerDecorator.DesiredSize));
            adornerDecorator.UpdateLayout();
            AnnotationComponentManager annotationComponentManager = new AnnotationComponentManager(null);

            if (this._isFixedContent)
            {
                AnnotationService.SetSubTreeProcessorId(adornerDecorator, FixedPageProcessor.Id);
                this._locatorManager.RegisterSelectionProcessor(new FixedTextSelectionProcessor(), typeof(TextRange));
            }
            else
            {
                AnnotationService.SetDataId(adornerDecorator, "FlowDocument");
                this._locatorManager.RegisterSelectionProcessor(new TextViewSelectionProcessor(), typeof(DocumentPageView));
                TextSelectionProcessor textSelectionProcessor = new TextSelectionProcessor();
                textSelectionProcessor.SetTargetDocumentPageView(documentPageView);
                this._locatorManager.RegisterSelectionProcessor(textSelectionProcessor, typeof(TextRange));
            }
            IList <IAttachedAnnotation> list = this.ProcessAnnotations(documentPageView);

            foreach (IAttachedAnnotation attachedAnnotation in list)
            {
                if (attachedAnnotation.AttachmentLevel != AttachmentLevel.Unresolved && attachedAnnotation.AttachmentLevel != AttachmentLevel.Incomplete)
                {
                    annotationComponentManager.AddAttachedAnnotation(attachedAnnotation, false);
                }
            }
            adornerDecorator.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            adornerDecorator.Arrange(new Rect(adornerDecorator.DesiredSize));
            adornerDecorator.UpdateLayout();
            return(new AnnotationDocumentPaginator.AnnotatedDocumentPage(page, adornerDecorator, size, new Rect(size), new Rect(size)));
        }
        // Token: 0x060062C7 RID: 25287 RVA: 0x001BB534 File Offset: 0x001B9734
        internal static void OnDeleteAnnotationsCommand(object sender, ExecutedRoutedEventArgs e)
        {
            FrameworkElement frameworkElement = sender as FrameworkElement;

            if (frameworkElement != null)
            {
                ITextSelection textSelection = AnnotationHelper.GetTextSelection(frameworkElement);
                if (textSelection != null)
                {
                    AnnotationService service = AnnotationService.GetService(frameworkElement);
                    AnnotationHelper.DeleteTextStickyNotesForSelection(service);
                    AnnotationHelper.DeleteInkStickyNotesForSelection(service);
                    if (!textSelection.IsEmpty)
                    {
                        AnnotationHelper.ClearHighlightsForSelection(service);
                    }
                }
            }
        }
Example #27
0
 // ----------------------------- OnLoaded -----------------------------
 /// <summary>
 ///     Turns Annotations on.
 /// </summary>
 protected void OnLoaded(object sender, RoutedEventArgs e)
 {
     // Make sure that an AnnotationService isn�t already enabled.
     var service = AnnotationService.GetService(Viewer);
     if (service == null)
     {
         // (a) Create a Stream for the annotations to be stored in.
         _annotationStream =
             new FileStream("annotations.xml", FileMode.OpenOrCreate);
         // (b) Create an AnnotationService on our
         // FlowDocumentPageViewer.
         service = new AnnotationService(Viewer);
         // (c) Create an AnnotationStore and give it the stream we
         // created. (Autoflush == false)
         AnnotationStore store = new XmlStreamStore(_annotationStream);
         // (d) "Turn on annotations". Annotations will be persisted in
         // the stream created at (a).
         service.Enable(store);
     }
 } // end:OnLoaded
        // Token: 0x060062E0 RID: 25312 RVA: 0x001BC2C0 File Offset: 0x001BA4C0
        private static bool IsCommandEnabled(object sender, bool checkForEmpty)
        {
            Invariant.Assert(sender != null, "Parameter 'sender' is null.");
            FrameworkElement frameworkElement = sender as FrameworkElement;

            if (frameworkElement != null)
            {
                FrameworkElement  frameworkElement2 = frameworkElement.Parent as FrameworkElement;
                AnnotationService service           = AnnotationService.GetService(frameworkElement);
                if (service != null && service.IsEnabled && (service.Root == frameworkElement || (frameworkElement2 != null && service.Root == frameworkElement2.TemplatedParent)))
                {
                    ITextSelection textSelection = AnnotationHelper.GetTextSelection(frameworkElement);
                    if (textSelection != null)
                    {
                        return(!checkForEmpty || !textSelection.IsEmpty);
                    }
                }
            }
            return(false);
        }
        // Token: 0x060062D7 RID: 25303 RVA: 0x001BBC34 File Offset: 0x001B9E34
        private static void DeleteSpannedAnnotations(AnnotationService service, XmlQualifiedName annotationType)
        {
            AnnotationHelper.CheckInputs(service);
            Invariant.Assert(annotationType != null && (annotationType == HighlightComponent.TypeName || annotationType == StickyNoteControl.TextSchemaName || annotationType == StickyNoteControl.InkSchemaName), "Invalid Annotation Type");
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            IList <IAttachedAnnotation> spannedAnnotations = AnnotationHelper.GetSpannedAnnotations(service);

            foreach (IAttachedAnnotation attachedAnnotation in spannedAnnotations)
            {
                if (annotationType.Equals(attachedAnnotation.Annotation.AnnotationType))
                {
                    TextAnchor textAnchor = attachedAnnotation.AttachedAnchor as TextAnchor;
                    if (textAnchor != null && ((textSelection.Start.CompareTo(textAnchor.Start) > 0 && textSelection.Start.CompareTo(textAnchor.End) < 0) || (textSelection.End.CompareTo(textAnchor.Start) > 0 && textSelection.End.CompareTo(textAnchor.End) < 0) || (textSelection.Start.CompareTo(textAnchor.Start) <= 0 && textSelection.End.CompareTo(textAnchor.End) >= 0) || AnnotationHelper.CheckCaret(textSelection, textAnchor, annotationType)))
                    {
                        service.Store.DeleteAnnotation(attachedAnnotation.Annotation.Id);
                    }
                }
            }
        }
        // Token: 0x060062DA RID: 25306 RVA: 0x001BBE8C File Offset: 0x001BA08C
        private static Annotation Highlight(AnnotationService service, string author, Brush highlightBrush, bool create)
        {
            AnnotationHelper.CheckInputs(service);
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            if (textSelection.IsEmpty)
            {
                throw new InvalidOperationException(SR.Get("EmptySelectionNotSupported"));
            }
            Color?color = null;

            if (highlightBrush != null)
            {
                SolidColorBrush solidColorBrush = highlightBrush as SolidColorBrush;
                if (solidColorBrush == null)
                {
                    throw new ArgumentException(SR.Get("InvalidHighlightColor"), "highlightBrush");
                }
                byte a;
                if (solidColorBrush.Opacity <= 0.0)
                {
                    a = 0;
                }
                else if (solidColorBrush.Opacity >= 1.0)
                {
                    a = solidColorBrush.Color.A;
                }
                else
                {
                    a = (byte)(solidColorBrush.Opacity * (double)solidColorBrush.Color.A);
                }
                color = new Color?(Color.FromArgb(a, solidColorBrush.Color.R, solidColorBrush.Color.G, solidColorBrush.Color.B));
            }
            ITextRange textRange = new TextRange(textSelection.Start, textSelection.End);
            Annotation result    = AnnotationHelper.ProcessHighlights(service, textRange, author, color, create);

            textSelection.SetCaretToPosition(textSelection.MovingPosition, textSelection.MovingPosition.LogicalDirection, true, true);
            return(result);
        }
Example #31
0
        // ------------------------ AddCommandHandlers ------------------------
        private void AddCommandHandlers(FrameworkElement uiScope)
        {
            CommandManager.RegisterClassCommandBinding( typeof(ThumbViewer),
                new CommandBinding( ApplicationCommands.Open,
                            new ExecutedRoutedEventHandler(OnOpen),
                            new CanExecuteRoutedEventHandler(OnNewQuery) ) );

            // Add Command Handlers
            CommandBindingCollection commandBindings = uiScope.CommandBindings;

            commandBindings.Add(
                new CommandBinding( ThumbViewer.Exit,
                            new ExecutedRoutedEventHandler(OnExit),
                            new CanExecuteRoutedEventHandler(OnNewQuery) ) );

            commandBindings.Add(
                new CommandBinding( ThumbViewer.SaveAs,
                            new ExecutedRoutedEventHandler(OnSaveAs),
                            new CanExecuteRoutedEventHandler(OnNewQuery) ) );

            commandBindings.Add(
                new CommandBinding(ThumbViewer.AddBookmark,
                            new ExecutedRoutedEventHandler(OnAddBookmark),
                            new CanExecuteRoutedEventHandler(OnNewQuery) ) );

            commandBindings.Add(
                new CommandBinding(ThumbViewer.AddComment,
                            new ExecutedRoutedEventHandler(OnAddComment),
                            new CanExecuteRoutedEventHandler(OnNewQuery) ) );

            // Enable Annotations
            _annotationBuffer = new MemoryStream();
            _annStore = new XmlStreamStore(_annotationBuffer);
            _annServ  = new AnnotationService(FDPV);
            _annStore.StoreContentChanged +=
                new StoreContentChangedEventHandler(_annStore_StoreContentChanged);
            _annServ.Enable(_annStore);

        }// end:AddCommandHandlers()
        protected void window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
            this.Resources["AuthorName"] = identity.Name;

            service = AnnotationService.GetService(docReader);

            if (service == null)
            {
                // Create a stream for the annotations to be stored in.
                //AnnotationStream =
                 // new FileStream("annotations.xml", FileMode.OpenOrCreate);
                annotationStream = new MemoryStream();

                // Create the on the document container. 
                service = new AnnotationService(docReader);
                
                // Create the AnnotationStore using the stream.
                AnnotationStore store = new XmlStreamStore(annotationStream);

                // Enable annotations.
                service.Enable(store);                
            }
        }
        // Token: 0x060062DF RID: 25311 RVA: 0x001BC234 File Offset: 0x001BA434
        private static void CheckInputs(AnnotationService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (!service.IsEnabled)
            {
                throw new ArgumentException(SR.Get("AnnotationServiceNotEnabled"), "service");
            }
            DocumentViewerBase documentViewerBase = service.Root as DocumentViewerBase;

            if (documentViewerBase == null)
            {
                FlowDocumentScrollViewer flowDocumentScrollViewer = service.Root as FlowDocumentScrollViewer;
                FlowDocumentReader       flowDocumentReader       = service.Root as FlowDocumentReader;
                Invariant.Assert(flowDocumentScrollViewer != null || flowDocumentReader != null, "Service's Root must be either a FlowDocumentReader, DocumentViewerBase or a FlowDocumentScrollViewer.");
                return;
            }
            if (documentViewerBase.Document == null)
            {
                throw new InvalidOperationException(SR.Get("OnlyFlowFixedSupported"));
            }
        }
        // Token: 0x060062D3 RID: 25299 RVA: 0x001BB8C4 File Offset: 0x001B9AC4
        private static IList <IAttachedAnnotation> GetSpannedAnnotationsForFlow(AnnotationService service, ITextSelection selection)
        {
            Invariant.Assert(service != null);
            ITextPointer textPointer  = selection.Start.CreatePointer();
            ITextPointer textPointer2 = selection.End.CreatePointer();

            textPointer.MoveToNextInsertionPosition(LogicalDirection.Backward);
            textPointer2.MoveToNextInsertionPosition(LogicalDirection.Forward);
            ITextRange selection2           = new TextRange(textPointer, textPointer2);
            IList <ContentLocatorBase> list = service.LocatorManager.GenerateLocators(selection2);

            Invariant.Assert(list != null && list.Count > 0);
            TextSelectionProcessor textSelectionProcessor  = service.LocatorManager.GetSelectionProcessor(typeof(TextRange)) as TextSelectionProcessor;
            TextSelectionProcessor textSelectionProcessor2 = service.LocatorManager.GetSelectionProcessor(typeof(TextAnchor)) as TextSelectionProcessor;

            Invariant.Assert(textSelectionProcessor != null, "TextSelectionProcessor should be available for TextRange if we are processing flow content.");
            Invariant.Assert(textSelectionProcessor2 != null, "TextSelectionProcessor should be available for TextAnchor if we are processing flow content.");
            IList <IAttachedAnnotation> result = null;

            try
            {
                textSelectionProcessor.Clamping  = false;
                textSelectionProcessor2.Clamping = false;
                ContentLocator contentLocator = list[0] as ContentLocator;
                Invariant.Assert(contentLocator != null, "Locators for selection in Flow should always be ContentLocators.  ContentLocatorSets not supported.");
                contentLocator.Parts[contentLocator.Parts.Count - 1].NameValuePairs.Add("IncludeOverlaps", bool.TrueString);
                IList <Annotation> annotations = service.Store.GetAnnotations(contentLocator);
                result = AnnotationHelper.ResolveAnnotations(service, annotations);
            }
            finally
            {
                textSelectionProcessor.Clamping  = true;
                textSelectionProcessor2.Clamping = true;
            }
            return(result);
        }
Example #35
0
 private void EnableAnnotations()
 {
     AnnotationService anoService = new AnnotationService(myDocumentReader);
     using (MemoryStream anoStream = new MemoryStream())
     {
         anoService.Enable(new XmlStreamStore(anoStream));
     }
 }
Example #36
0
 public static Annotation CreateHighlightForSelection(AnnotationService service, string author, System.Windows.Media.Brush highlightBrush)
 {
     return(default(Annotation));
 }
 /// <summary>Creates an ink sticky note annotation on the current selection of the viewer control associated with the specified <see cref="T:System.Windows.Annotations.AnnotationService" />..</summary>
 /// <param name="service">The annotation service to use to create the ink sticky note annotation.</param>
 /// <param name="author">The author of the annotation.</param>
 /// <returns>The ink sticky note annotation; or <see langword="null" />, if there is no selected content to annotate.</returns>
 /// <exception cref="T:System.ArgumentNullException">
 ///         <paramref name="service" /> is <see langword="null" />.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///         <paramref name="service" /> is not enabled.</exception>
 /// <exception cref="T:System.InvalidOperationException">The viewer control contains no content selection.</exception>
 // Token: 0x060062BD RID: 25277 RVA: 0x001BB1F6 File Offset: 0x001B93F6
 public static Annotation CreateInkStickyNoteForSelection(AnnotationService service, string author)
 {
     return(AnnotationHelper.CreateStickyNoteForSelection(service, StickyNoteControl.InkSchemaName, author));
 }
Example #38
0
        /// <summary>
        /// Creates a highlight annotation with the specified color and author
        /// </summary> 
        /// <param name="service">the AnnotationService</param>
        /// <param name="textRange">highlight anchor</param> 
        /// <param name="author">highlight author</param> 
        /// <param name="color">highlight brush</param>
        /// <returns>created annotation</returns> 
        private static Annotation CreateHighlight(AnnotationService service, ITextRange textRange, string author, Nullable<Color> color)
        {
            Invariant.Assert(textRange != null, "textRange is null");
 
            Annotation annotation = CreateAnnotationForSelection(service, textRange, HighlightComponent.TypeName, author);
 
            // Set the cargo with highlight color 
            if (color != null)
            { 
                ColorConverter converter = new ColorConverter();
                XmlDocument doc = new XmlDocument();
                XmlElement colorsElement = doc.CreateElement(HighlightComponent.ColorsContentName, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace);
                colorsElement.SetAttribute(HighlightComponent.BackgroundAttributeName, converter.ConvertToInvariantString(color.Value)); 

                AnnotationResource cargo = new AnnotationResource(HighlightComponent.HighlightResourceName); 
                cargo.Contents.Add(colorsElement); 

                annotation.Cargos.Add(cargo); 
            }

            return annotation;
        } 
Example #39
0
        /// <summary>
        ///     Common input checks.  Service must be non-null and enabled. 
        /// </summary> 
        /// <param name="service">service to check</param>
        /// <exception cref="ArgumentNullException">service is null</exception> 
        /// <exception cref="ArgumentException">service is not enabled</exception>
        private static void CheckInputs(AnnotationService service)
        {
            if (service == null) 
            {
                throw new ArgumentNullException("service"); 
            } 

            if (!service.IsEnabled) 
            {
                throw new ArgumentException(SR.Get(SRID.AnnotationServiceNotEnabled), "service");
            }
 
            DocumentViewerBase viewer = service.Root as DocumentViewerBase;
            if (viewer == null) 
            { 
                FlowDocumentScrollViewer scrollViewer = service.Root as FlowDocumentScrollViewer;
                FlowDocumentReader reader = service.Root as FlowDocumentReader; 
                Invariant.Assert((scrollViewer != null) || (reader != null), "Service's Root must be either a FlowDocumentReader, DocumentViewerBase or a FlowDocumentScrollViewer.");
            }
            else
            { 
                if (viewer.Document == null)
                { 
                    throw new InvalidOperationException(SR.Get(SRID.OnlyFlowFixedSupported)); 
                }
            } 
        }
Example #40
0
        private static List<IAttachedAnnotation> ResolveAnnotations(AnnotationService service, IList<Annotation> annotations)
        {
            Invariant.Assert(annotations != null); 
            List<IAttachedAnnotation> attachedAnnotations = new List<IAttachedAnnotation>(annotations.Count);
 
            // Now resolve any that we queried and add them to list of attached annotations 
            foreach (Annotation annot in annotations)
            { 
                AttachmentLevel level;
                object anchor = service.LocatorManager.ResolveLocator(annot.Anchors[0].ContentLocators[0], 0, service.Root, out level);
                if (level != AttachmentLevel.Incomplete && level != AttachmentLevel.Unresolved && anchor != null)
                { 
                    attachedAnnotations.Add(new AttachedAnnotation(service.LocatorManager, annot, annot.Anchors[0], anchor, level));
                } 
            } 

            return attachedAnnotations; 
        }
Example #41
0
        /// <summary> 
        /// Finds and removes all annotations of the specified type that have part or the entire
        /// anchor covered by the start-end range. If the delete range is adjacent to the anchor it 
        /// it will not be deleted 
        /// </summary>
        /// <param name="service">service to use for this operation</param> 
        /// <param name="annotationType">type of the annotations to be removed</param>
        private static void DeleteSpannedAnnotations(AnnotationService service, XmlQualifiedName annotationType)
        {
            CheckInputs(service); 

            // Limited set of annotation types supported in V1 
            Invariant.Assert(annotationType != null && 
                (annotationType == HighlightComponent.TypeName ||
                annotationType == StickyNoteControl.TextSchemaName || 
                annotationType == StickyNoteControl.InkSchemaName), "Invalid Annotation Type");

            // Get the selection from the viewer
            ITextSelection selection = GetTextSelection((FrameworkElement)service.Root); 
            Invariant.Assert(selection != null, "TextSelection is null");
 
            // Get annotations spanned by current selection 
            IList<IAttachedAnnotation> attachedAnnotations = GetSpannedAnnotations(service);
 
            // Find the annotations that overlap with the selection
            foreach (IAttachedAnnotation attachedAnnot in attachedAnnotations)
            {
                if (annotationType.Equals(attachedAnnot.Annotation.AnnotationType)) 
                {
                    // Only annotations with TextRange anchors can be compared to 
                    // the text selection, we ignore others 

                    TextAnchor anchor = attachedAnnot.AttachedAnchor as TextAnchor; 
                    if (anchor == null)
                        continue;

                    // Remove any annotations that overlap in anyway 
                    if (((selection.Start.CompareTo(anchor.Start) > 0) && (selection.Start.CompareTo(anchor.End) < 0)) ||
                        ((selection.End.CompareTo(anchor.Start) > 0) && (selection.End.CompareTo(anchor.End) < 0)) || 
                        ((selection.Start.CompareTo(anchor.Start) <= 0) && (selection.End.CompareTo(anchor.End) >= 0)) || 
                        CheckCaret(selection, anchor, annotationType))
                    { 
                        service.Store.DeleteAnnotation(attachedAnnot.Annotation.Id);
                    }
                }
            } 
        }
Example #42
0
        /// <summary> 
        ///     Creates an annotation of the specified type in the service.  The current
        ///     selection of the DocumentViewerBase is used as the anchor of the new 
        ///     annotation. 
        ///     If the selection is of length 0 no annotation is created.
        ///     If the no locators can be generated for the textAnchor, no annotation is created. 
        /// </summary>
        /// <param name="service">the AnnotationService</param>
        /// <param name="textSelection">text selection for new annotation</param>
        /// <param name="annotationType">the type of the annotation to create</param> 
        /// <param name="author">optional author for new annotation</param>
        /// <returns>the annotation created</returns> 
        /// <exception cref="ArgumentException">service is not enabled</exception> 
        /// <exception cref="InvalidOperationException">selection is of zero length</exception>
        private static Annotation CreateAnnotationForSelection(AnnotationService service, ITextRange textSelection, XmlQualifiedName annotationType, string author) 
        {
            Invariant.Assert(service != null && textSelection != null, "Parameter 'service' or 'textSelection' is null.");

            // Limited set of annotation types supported in V1 
            Invariant.Assert(annotationType != null &&
                (annotationType == HighlightComponent.TypeName || 
                annotationType == StickyNoteControl.TextSchemaName || 
                annotationType == StickyNoteControl.InkSchemaName), "Invalid Annotation Type");
 
            Annotation annotation = new Annotation(annotationType);

            SetAnchor(service, annotation, textSelection);
 
            // Add the author to the annotation
            if (author != null) 
            { 
                annotation.Authors.Add(author);
            } 

            return annotation;
        }
        /// <summary>Returns an <see cref="T:System.Windows.Annotations.IAnchorInfo" /> object that provides anchoring information, such as the anchor location, about the specified annotation.</summary>
        /// <param name="service">The annotation service to use for this operation.</param>
        /// <param name="annotation">The annotation to get anchoring information for.</param>
        /// <returns>An <see cref="T:System.Windows.Annotations.IAnchorInfo" /> object that provides anchoring information about the specified annotation, or <see langword="null" /> if it cannot be resolved.</returns>
        // Token: 0x060062C1 RID: 25281 RVA: 0x001BB2D0 File Offset: 0x001B94D0
        public static IAnchorInfo GetAnchorInfo(AnnotationService service, Annotation annotation)
        {
            AnnotationHelper.CheckInputs(service);
            if (annotation == null)
            {
                throw new ArgumentNullException("annotation");
            }
            bool flag = true;
            DocumentViewerBase documentViewerBase = service.Root as DocumentViewerBase;

            if (documentViewerBase == null)
            {
                FlowDocumentReader flowDocumentReader = service.Root as FlowDocumentReader;
                if (flowDocumentReader != null)
                {
                    documentViewerBase = (AnnotationHelper.GetFdrHost(flowDocumentReader) as DocumentViewerBase);
                }
            }
            else
            {
                flag = (documentViewerBase.Document is FlowDocument);
            }
            IList <IAttachedAnnotation> list = null;

            if (flag)
            {
                TextSelectionProcessor textSelectionProcessor  = service.LocatorManager.GetSelectionProcessor(typeof(TextRange)) as TextSelectionProcessor;
                TextSelectionProcessor textSelectionProcessor2 = service.LocatorManager.GetSelectionProcessor(typeof(TextAnchor)) as TextSelectionProcessor;
                Invariant.Assert(textSelectionProcessor != null, "TextSelectionProcessor should be available for TextRange if we are processing flow content.");
                Invariant.Assert(textSelectionProcessor2 != null, "TextSelectionProcessor should be available for TextAnchor if we are processing flow content.");
                try
                {
                    textSelectionProcessor.Clamping  = false;
                    textSelectionProcessor2.Clamping = false;
                    list = AnnotationHelper.ResolveAnnotations(service, new Annotation[]
                    {
                        annotation
                    });
                    goto IL_12E;
                }
                finally
                {
                    textSelectionProcessor.Clamping  = true;
                    textSelectionProcessor2.Clamping = true;
                }
            }
            FixedPageProcessor fixedPageProcessor = service.LocatorManager.GetSubTreeProcessorForLocatorPart(FixedPageProcessor.CreateLocatorPart(0)) as FixedPageProcessor;

            Invariant.Assert(fixedPageProcessor != null, "FixedPageProcessor should be available if we are processing fixed content.");
            try
            {
                fixedPageProcessor.UseLogicalTree = true;
                list = AnnotationHelper.ResolveAnnotations(service, new Annotation[]
                {
                    annotation
                });
            }
            finally
            {
                fixedPageProcessor.UseLogicalTree = false;
            }
IL_12E:
            Invariant.Assert(list != null);
            if (list.Count > 0)
            {
                return(list[0]);
            }
            return(null);
        }
Example #44
0
 /// <summary> 
 ///     Creates a text sticky note annotation for the service.  The anchor used is
 ///     the current selection in the DocumentViewerBase associated with the service.
 ///     If the selection length is 0 no sticky note is created.
 /// </summary> 
 /// <param name="service">service used to create annotation</param>
 /// <param name="author">annotation author added to new annotation; if null, no author added</param> 
 /// <exception cref="ArgumentNullException">service is null</exception> 
 /// <exception cref="ArgumentException">service is not enabled</exception>
 /// <exception cref="InvalidOperationException">selection is of zero length</exception> 
 /// <returns>the Annotation created</returns>
 public static Annotation CreateTextStickyNoteForSelection(AnnotationService service, string author)
 {
     return CreateStickyNoteForSelection(service, StickyNoteControl.TextSchemaName, author); 
 }
Example #45
0
        ///<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)));
        }
Example #46
0
 /// <summary>
 ///     Deletes ink sticky notes whose anchors are wholly contained by the 
 ///     service's viewer's selection.  If no anchors are wholly contained
 ///     by the selection, then this method is a no-op.
 /// </summary>
 /// <param name="service">service from which to delete annotations</param> 
 /// <exception cref="ArgumentNullException">service is null</exception>
 /// <exception cref="ArgumentException">service is not enabled</exception> 
 public static void DeleteInkStickyNotesForSelection(AnnotationService service) 
 {
     //fire start trace event 
     EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeleteInkNoteBegin);
     try
     {
         DeleteSpannedAnnotations(service, StickyNoteControl.InkSchemaName); 
     }
     finally 
     { 
         //fire end trace event
         EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeleteInkNoteEnd); 
     }
 }
Example #47
0
 /// <summary>
 ///     Clears all highlights that overlap with the service's viewer's selection. 
 ///     If a highlight overlaps the selection only partially, the portion 
 ///     that is overlapping is cleared.  The rest of it remains.
 ///     If no highlights overlap the selection, this method is a no-op. 
 ///     If the selection is of zero length, this method is a no-op.
 /// </summary>
 /// <param name="service">service from which to delete annotations</param>
 /// <exception cref="ArgumentNullException">service is null</exception> 
 /// <exception cref="ArgumentException">service is not enabled</exception>
 public static void ClearHighlightsForSelection(AnnotationService service) 
 { 
     //fire start trace event
     EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.ClearHighlightBegin); 
     try
     {
         Highlight(service, null, null, false);
     } 
     finally
     { 
         //fire end trace event 
         EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.ClearHighlightEnd);
     } 
 }
Example #48
0
        private static IList<IAttachedAnnotation> GetSpannedAnnotationsForFixed(AnnotationService service, int startPage, int endPage) 
        {
            Invariant.Assert(service != null, "Need non-null service to get spanned annotations for fixed content."); 

            FixedPageProcessor processor = service.LocatorManager.GetSubTreeProcessorForLocatorPart(FixedPageProcessor.CreateLocatorPart(0)) as FixedPageProcessor;
            Invariant.Assert(processor != null, "FixedPageProcessor should be available if we are processing fixed content.");
 
            List<IAttachedAnnotation> attachedAnnotations = null;
            List<Annotation> annotations = new List<Annotation>(); 
            try 
            {
                // Turn resolving of non-visible anchors on 
                processor.UseLogicalTree = true;

                // For each non-visible page, query the store for annotations on that page
                for (int pageNumber = startPage; pageNumber <= endPage; pageNumber++) 
                {
                    ContentLocator locator = new ContentLocator(); 
                    locator.Parts.Add(FixedPageProcessor.CreateLocatorPart(pageNumber)); 
                    AddRange(annotations, service.Store.GetAnnotations(locator));
                } 

                attachedAnnotations = ResolveAnnotations(service, annotations);
            }
            finally 
            {
                // Turn resolving of non-visible anchors off again 
                processor.UseLogicalTree = false; 
            }
 
            return attachedAnnotations;
        }
Example #49
0
        private static void SetAnchor(AnnotationService service, Annotation annot, object selection)
        {
            Invariant.Assert(annot != null && selection != null, "null input parameter"); 

            // Generate locators for the selection - add them to the anchor 
            IList<ContentLocatorBase> locators = service.LocatorManager.GenerateLocators(selection); 
            Invariant.Assert(locators != null && locators.Count > 0, "No locators generated for selection.");
 
            // Create an annotation with a single anchor
            AnnotationResource anchor = new AnnotationResource();

            // Add the locators to the anchor 
            foreach (ContentLocatorBase locator in locators)
            { 
                anchor.ContentLocators.Add(locator); 
            }
 
            annot.Anchors.Clear();
            annot.Anchors.Add(anchor);
        }
Example #50
0
        private static IList<IAttachedAnnotation> GetSpannedAnnotationsForFlow(AnnotationService service, ITextSelection selection)
        {
            Invariant.Assert(service != null); 

            // Expand the range to get annotations that sit just outside the selection - important for merging 
            ITextPointer start = selection.Start.CreatePointer(); 
            ITextPointer end = selection.End.CreatePointer();
            start.MoveToNextInsertionPosition(LogicalDirection.Backward); 
            end.MoveToNextInsertionPosition(LogicalDirection.Forward);
            ITextRange textRange = new TextRange(start, end);

            // Create locator that reflects all spanned annotations for the current selection 
            IList<ContentLocatorBase> locators = service.LocatorManager.GenerateLocators(textRange);
            Invariant.Assert(locators != null && locators.Count > 0); 
 
            TextSelectionProcessor rangeProcessor = service.LocatorManager.GetSelectionProcessor(typeof(TextRange)) as TextSelectionProcessor;
            TextSelectionProcessor anchorProcessor = service.LocatorManager.GetSelectionProcessor(typeof(TextAnchor)) as TextSelectionProcessor; 
            Invariant.Assert(rangeProcessor != null, "TextSelectionProcessor should be available for TextRange if we are processing flow content.");
            Invariant.Assert(anchorProcessor != null, "TextSelectionProcessor should be available for TextAnchor if we are processing flow content.");

            IList<IAttachedAnnotation> attachedAnnotations = null; 
            IList<Annotation> annotations = null;
            try 
            { 
                // Turn resolving for non-visible content on
                rangeProcessor.Clamping = false; 
                anchorProcessor.Clamping = false;

                ContentLocator locator = locators[0] as ContentLocator;
                Invariant.Assert(locator != null, "Locators for selection in Flow should always be ContentLocators.  ContentLocatorSets not supported."); 

                // Make sure we get all annotations that overlap with the selection 
                locator.Parts[locator.Parts.Count - 1].NameValuePairs.Add(TextSelectionProcessor.IncludeOverlaps, Boolean.TrueString); 

                // Query for the annotations 
                annotations = service.Store.GetAnnotations(locator);

                //
                attachedAnnotations = ResolveAnnotations(service, annotations); 
            }
            finally 
            { 
                // Turn resolving of non-visible content off again
                rangeProcessor.Clamping = true; 
                anchorProcessor.Clamping = true;
            }

            return attachedAnnotations; 
        }
Example #51
0
        private void EnableAnnotations()
        {
            // Create the AnnotationService object that works
            // with our FlowDocumentReader.
            AnnotationService anoService = new AnnotationService(myDocumentReader);

            // Create a MemoryStream which will hold the annotations.
            MemoryStream anoStream = new MemoryStream();

            // Now, create a XML-based store based on the MemoryStream.
            // You could use this object to programmatically add, delete
            // or find annotations.
            AnnotationStore store = new XmlStreamStore(anoStream);

            // Enable the annotation services.
            anoService.Enable(store);
        }
Example #52
0
        private static IList<IAttachedAnnotation> GetSpannedAnnotations(AnnotationService service)
        { 
            CheckInputs(service);
 
            bool isFlow = true; 

            // Determine if we are using a viewer that supports pagination 
            DocumentViewerBase viewer = service.Root as DocumentViewerBase;
            if (viewer == null)
            {
                FlowDocumentReader fdr = service.Root as FlowDocumentReader; 
                if (fdr != null)
                { 
                    viewer = GetFdrHost(fdr) as DocumentViewerBase; 
                }
            } 
            else
            {
                // Only paginated viewers support non-FlowDocuments, so
                // if we have one, check its content type 
                isFlow = viewer.Document is FlowDocument;
            } 
 
            bool allPagesVisible = true;
 
            ITextSelection selection = GetTextSelection((FrameworkElement)service.Root);
            Invariant.Assert(selection != null, "TextSelection is null");
            int selStartPage = 0, selEndPage = 0;
 
            if(viewer != null)
            { 
                //if this is a DocumentViewerBase check the selection pages 
                TextSelectionHelper.GetPointerPage(selection.Start, out selStartPage);
                TextSelectionHelper.GetPointerPage(selection.End, out selEndPage); 

                // If either page cannot be found, the selection we are trying to anchor to
                // is invalid.  This can happen if the selection was created programmatically
                // for TextPointers that don't have pages because pagination failed. 
                if (selStartPage == -1 || selEndPage == -1)
                    throw new ArgumentException(SR.Get(SRID.InvalidSelectionPages)); 
 
                allPagesVisible = AreAllPagesVisible(viewer, selStartPage, selEndPage);
            } 

            IList<IAttachedAnnotation> attachedAnnotations = null;

            if (allPagesVisible) 
            {
                // If viewer is not a DocumentViewerBase or the selection has 
                // no parts on non-visible pages, just use the attached annotations 
                attachedAnnotations = service.GetAttachedAnnotations();
            } 
            else
            {
                // Use the method specific to the kind of content we are displaying
                if (isFlow) 
                {
                    attachedAnnotations = GetSpannedAnnotationsForFlow(service, selection); 
                } 
                else
                { 
                    attachedAnnotations = GetSpannedAnnotationsForFixed(service, selStartPage, selEndPage);
                }
            }
 
            IList<TextSegment> textSegments = selection.TextSegments;
            Debug.Assert((textSegments != null) && (textSegments.Count > 0), "Invalid selection TextSegments"); 
 
            if ((attachedAnnotations != null) && (attachedAnnotations.Count > 0))
            { 
                if (allPagesVisible || !isFlow)
                {
                    //if the list contains all currently attached annotations or the Annotations
                    // from all visible fixed pages we must remove the annotations that are not 
                    // overlapped by the selection. This is not needed for Flow because
                    // GetSpannedAnnotationsForFlow will retrieve only the annotations covered by the selection 
                    for (int i = attachedAnnotations.Count - 1; i >= 0; i--) 
                    {
                        TextAnchor ta = attachedAnnotations[i].AttachedAnchor as TextAnchor; 
                        if ((ta == null) || !ta.IsOverlapping(textSegments))
                        {
                            //remove this attached annotation - it is out of selection scope
                            attachedAnnotations.RemoveAt(i); 
                        }
                    } 
                } 
            }
            return attachedAnnotations; 
        }
Example #53
0
 public static IAnchorInfo GetAnchorInfo(AnnotationService service, Annotation annotation)
 {
     return(default(IAnchorInfo));
 }
Example #54
0
        //-----------------------------------------------------
        //
        //  Private Methods 
        //
        //----------------------------------------------------- 
 
        #region Private Methods
 
        /// <summary>
        ///     Creates a sticky note annotation of the specified type for the service.  The anchor
        ///     used is the current selection in the DocumentViewerBase associated with the service.
        ///     If the selection length is 0 no sticky note is created. 
        /// </summary>
        /// <param name="service">service in which to create annotation</param> 
        /// <param name="noteType">type of StickyNote to create</param> 
        /// <param name="author">optional author of new annotation</param>
        /// <exception cref="ArgumentNullException">service is null</exception> 
        /// <exception cref="ArgumentException">service is not enabled</exception>
        private static Annotation CreateStickyNoteForSelection(AnnotationService service, XmlQualifiedName noteType, string author)
        {
            CheckInputs(service); 

            // Get the selection for the viewer 
            ITextSelection selection = GetTextSelection((FrameworkElement)service.Root); 
            Invariant.Assert(selection != null, "TextSelection is null");
 
            // Cannot create an annotation with zero length text anchor
            if (selection.IsEmpty)
            {
                throw new InvalidOperationException(SR.Get(SRID.EmptySelectionNotSupported)); 
            }
 
            Annotation annotation = null; 

            //fire start trace event 
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateStickyNoteBegin);
            try
            {
                // Create the annotation 
                annotation = CreateAnnotationForSelection(service, selection, noteType, author);
                Invariant.Assert(annotation != null, "CreateAnnotationForSelection returned null."); 
 
                // Add annotation to the store - causing it to be resolved and displayed, if possible
                service.Store.AddAnnotation(annotation); 

                // Clear the selection
                selection.SetCaretToPosition(selection.MovingPosition, selection.MovingPosition.LogicalDirection, true, true);
            } 
            finally
            { 
                //fire end trace event 
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateStickyNoteEnd);
            } 
            return annotation;
        }
Example #55
0
 public static void DeleteTextStickyNotesForSelection(AnnotationService service)
 {
 }
        // Token: 0x060062D1 RID: 25297 RVA: 0x001BB730 File Offset: 0x001B9930
        private static IList <IAttachedAnnotation> GetSpannedAnnotations(AnnotationService service)
        {
            AnnotationHelper.CheckInputs(service);
            bool flag = true;
            DocumentViewerBase documentViewerBase = service.Root as DocumentViewerBase;

            if (documentViewerBase == null)
            {
                FlowDocumentReader flowDocumentReader = service.Root as FlowDocumentReader;
                if (flowDocumentReader != null)
                {
                    documentViewerBase = (AnnotationHelper.GetFdrHost(flowDocumentReader) as DocumentViewerBase);
                }
            }
            else
            {
                flag = (documentViewerBase.Document is FlowDocument);
            }
            bool           flag2         = true;
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            int num  = 0;
            int num2 = 0;

            if (documentViewerBase != null)
            {
                TextSelectionHelper.GetPointerPage(textSelection.Start, out num);
                TextSelectionHelper.GetPointerPage(textSelection.End, out num2);
                if (num == -1 || num2 == -1)
                {
                    throw new ArgumentException(SR.Get("InvalidSelectionPages"));
                }
                flag2 = AnnotationHelper.AreAllPagesVisible(documentViewerBase, num, num2);
            }
            IList <IAttachedAnnotation> list;

            if (flag2)
            {
                list = service.GetAttachedAnnotations();
            }
            else if (flag)
            {
                list = AnnotationHelper.GetSpannedAnnotationsForFlow(service, textSelection);
            }
            else
            {
                list = AnnotationHelper.GetSpannedAnnotationsForFixed(service, num, num2);
            }
            IList <TextSegment> textSegments = textSelection.TextSegments;

            if (list != null && list.Count > 0 && (flag2 || !flag))
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    TextAnchor textAnchor = list[i].AttachedAnchor as TextAnchor;
                    if (textAnchor == null || !textAnchor.IsOverlapping(textSegments))
                    {
                        list.RemoveAt(i);
                    }
                }
            }
            return(list);
        }
Example #57
0
 public static void ClearHighlightsForSelection(AnnotationService service)
 {
 }
Example #58
0
        /// <summary> 
        ///     Gets the AttachedAnnotation for any annotation, even if its not visible.
        /// </summary> 
        /// <param name="service">service from which to resolve annotations</param> 
        /// <param name="annotation">annotation to get anchor info for</param>
        /// <exception cref="ArgumentNullException">service or annotation is null</exception> 
        /// <exception cref="ArgumentException">service is not enabled</exception>
        public static IAnchorInfo GetAnchorInfo(AnnotationService service, Annotation annotation)
        {
            CheckInputs(service); 

            if (annotation == null) 
                throw new ArgumentNullException("annotation"); 

            bool isFlow = true; 

            // Determine if we are using a viewer that supports pagination
            DocumentViewerBase viewer = service.Root as DocumentViewerBase;
            if (viewer == null) 
            {
                FlowDocumentReader fdr = service.Root as FlowDocumentReader; 
                if (fdr != null) 
                {
                    viewer = GetFdrHost(fdr) as DocumentViewerBase; 
                }
            }
            else
            { 
                // Only paginated viewers support non-FlowDocuments, so
                // if we have one, check its content type 
                isFlow = viewer.Document is FlowDocument; 
            }
 
            IList<IAttachedAnnotation> attachedAnnotations = null;


            // Use the method specific to the kind of content we are displaying 
            if (isFlow)
            { 
                TextSelectionProcessor rangeProcessor = service.LocatorManager.GetSelectionProcessor(typeof(TextRange)) as TextSelectionProcessor; 
                TextSelectionProcessor anchorProcessor = service.LocatorManager.GetSelectionProcessor(typeof(TextAnchor)) as TextSelectionProcessor;
                Invariant.Assert(rangeProcessor != null, "TextSelectionProcessor should be available for TextRange if we are processing flow content."); 
                Invariant.Assert(anchorProcessor != null, "TextSelectionProcessor should be available for TextAnchor if we are processing flow content.");

                try
                { 
                    // Turn resolving for non-visible content on
                    rangeProcessor.Clamping = false; 
                    anchorProcessor.Clamping = false; 

                    attachedAnnotations = ResolveAnnotations(service, new Annotation[] { annotation }); 
                }
                finally
                {
                    // Turn resolving of non-visible content off again 
                    rangeProcessor.Clamping = true;
                    anchorProcessor.Clamping = true; 
                } 
            }
            else 
            {
                FixedPageProcessor processor = service.LocatorManager.GetSubTreeProcessorForLocatorPart(FixedPageProcessor.CreateLocatorPart(0)) as FixedPageProcessor;
                Invariant.Assert(processor != null, "FixedPageProcessor should be available if we are processing fixed content.");
 
                try
                { 
                    // Turn resolving of non-visible anchors on 
                    processor.UseLogicalTree = true;
 
                    attachedAnnotations = ResolveAnnotations(service, new Annotation[] { annotation });
                }
                finally
                { 
                    // Turn resolving of non-visible anchors off again
                    processor.UseLogicalTree = false; 
                } 
            }
 

            Invariant.Assert(attachedAnnotations != null);
            if (attachedAnnotations.Count > 0)
                return attachedAnnotations[0]; 

            return null; 
        } 
Example #59
0
        /// <summary>
        /// Highlights/Unhighlights selection 
        /// </summary> 
        /// <param name="service">annotation servise</param>
        /// <param name="author">annotation author</param> 
        /// <param name="highlightBrush">highlight color</param>
        /// <param name="create">true - highlight, false - clear highlight</param>
        /// <returns>the annotation created, if create flag was true; null otherwise</returns>
        private static Annotation Highlight(AnnotationService service, string author, Brush highlightBrush, bool create) 
        {
            CheckInputs(service); 
 
            // Get the selection for the viewer and wrap it in a TextRange
            ITextSelection selection = GetTextSelection((FrameworkElement)service.Root); 
            Invariant.Assert(selection != null, "TextSelection is null");

            // Cannot create an annotation with zero length text anchor
            if (selection.IsEmpty) 
            {
                throw new InvalidOperationException(SR.Get(SRID.EmptySelectionNotSupported)); 
            } 

            Nullable<Color> color = null; 
            if (highlightBrush != null)
            {
                SolidColorBrush brush = highlightBrush as SolidColorBrush;
                if (brush == null) 
                    throw new ArgumentException(SR.Get(SRID.InvalidHighlightColor), "highlightBrush");
 
                // Opacity less than 0 is treated as 0; greater than 1 is treated a 1. 
                byte alpha;
                if (brush.Opacity <= 0) 
                    alpha = 0;
                else if (brush.Opacity >= 1)
                    alpha = brush.Color.A;
                else 
                    alpha = (byte) (brush.Opacity * brush.Color.A);
 
                color = Color.FromArgb(alpha, brush.Color.R, brush.Color.G, brush.Color.B); 
            }
 
            // Create a range so we can move its ends without changing the selection
            ITextRange anchor = new TextRange(selection.Start, selection.End);

            Annotation highlight = ProcessHighlights(service, anchor, author, color, create); 

            // Clear the selection 
            selection.SetCaretToPosition(selection.MovingPosition, selection.MovingPosition.LogicalDirection, true, true); 

            return highlight; 
        }
Example #60
0
        /// <summary>
        /// Merges highlights with the same color. Splits highlights with different colors 
        /// </summary>
        /// <param name="service">the AnnotationService</param> 
        /// <param name="textRange">TextRange of the new highlight</param> 
        /// <param name="color">highlight color</param>
        /// <param name="author">highlight author</param> 
        /// <param name="create">if true, this is create highlight operation, otherwise it is Clear</param>
        /// <returns>the annotation created, if create flag was true; null otherwise</returns>
        private static Annotation ProcessHighlights(AnnotationService service, ITextRange textRange, string author, Nullable<Color> color, bool create)
        { 
            Invariant.Assert(textRange != null, "Parameter 'textRange' is null.");
 
            IList<IAttachedAnnotation> spannedAnnots = GetSpannedAnnotations(service); 

            // Step one: trim all the spanned annotations so there is no overlap with the new annotation 
            foreach (IAttachedAnnotation attachedAnnotation in spannedAnnots)
            {
                if (HighlightComponent.TypeName.Equals(attachedAnnotation.Annotation.AnnotationType))
                { 
                    TextAnchor textAnchor = attachedAnnotation.FullyAttachedAnchor as TextAnchor;
                    Invariant.Assert(textAnchor != null, "FullyAttachedAnchor must not be null."); 
                    TextAnchor copy = new TextAnchor(textAnchor); 

                    // This modifies the current fully resolved anchor 
                    copy = TextAnchor.TrimToRelativeComplement(copy, textRange.TextSegments);

                    // If the trimming resulting in no more content being in the anchor,
                    // delete the annotation 
                    if (copy == null || copy.IsEmpty)
                    { 
                        service.Store.DeleteAnnotation(attachedAnnotation.Annotation.Id); 
                        continue;
                    } 

                    // If there was some portion of content still in the anchor,
                    // generate new locators representing the modified anchor
                    SetAnchor(service, attachedAnnotation.Annotation, copy); 
                }
            } 
 
            // Step two: create new annotation
            if (create) 
            {
                //create one annotation and return
                Annotation highlight = CreateHighlight(service, textRange, author, color);
                service.Store.AddAnnotation(highlight); 
                return highlight;
            } 
 
            return null;
        }