Esempio n. 1
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());
        }
Esempio n. 2
0
        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());
        }
        /// <summary>
        ///     Create an instance of LocatorManager with an optional specific store.
        ///     It manages the processors that are used to create and resolve locators.
        ///     If a store is passed in, its used to query for annotations.  Otherwise
        ///     the service is looked for and the service's store is used.
        /// </summary>
        /// <param name="store">optional, store to use for query of annotations</param>
        public LocatorManager(AnnotationStore store)
        {
            _locatorPartHandlers = new Hashtable();
            _subtreeProcessors = new Hashtable();
            _selectionProcessors = new Hashtable();

            RegisterSubTreeProcessor(new DataIdProcessor(this), DataIdProcessor.Id);
            RegisterSubTreeProcessor(new FixedPageProcessor(this), FixedPageProcessor.Id);
            TreeNodeSelectionProcessor nodeProcessor = new TreeNodeSelectionProcessor();
            RegisterSelectionProcessor(nodeProcessor, typeof(FrameworkElement));
            RegisterSelectionProcessor(nodeProcessor, typeof(FrameworkContentElement));
            TextSelectionProcessor textProcessor = new TextSelectionProcessor();
            RegisterSelectionProcessor(textProcessor, typeof(TextRange));
            RegisterSelectionProcessor(textProcessor, typeof(TextAnchor));

            _internalStore = store;
        }
        /// <summary>
        ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store. 
        /// </summary>
        /// <param name="originalPaginator">document to add annotations to</param> 
        /// <param name="annotationStore">store to retrieve annotations from</param> 
        /// <param name="flowDirection"></param>
        public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, AnnotationStore annotationStore, FlowDirection flowDirection) 
        {
            _isFixedContent = originalPaginator is FixedDocumentPaginator || originalPaginator is FixedDocumentSequencePaginator;

            if (!_isFixedContent && !(originalPaginator is FlowDocumentPaginator)) 
                throw new ArgumentException(SR.Get(SRID.OnlyFlowAndFixedSupported));
 
            _originalPaginator = originalPaginator; 
            _annotationStore = annotationStore;
            _locatorManager = new LocatorManager(_annotationStore); 
            _flowDirection = flowDirection;

            // Register for events
            _originalPaginator.GetPageCompleted += new GetPageCompletedEventHandler(HandleGetPageCompleted); 
            _originalPaginator.ComputePageCountCompleted += new AsyncCompletedEventHandler(HandleComputePageCountCompleted);
            _originalPaginator.PagesChanged += new PagesChangedEventHandler(HandlePagesChanged); 
        } 
 /// <summary>
 ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store. 
 /// </summary>
 /// <param name="originalPaginator">document to add annotations to</param> 
 /// <param name="annotationStore">store to retrieve annotations from</param> 
 public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, AnnotationStore annotationStore) : this(originalPaginator, annotationStore, FlowDirection.LeftToRight)
 { 
 }
Esempio n. 6
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        ///     Enables the service with the given store.
        /// </summary>
        /// <param name="annotationStore">store to use for retreiving and persisting annotations</param>
        /// <exception cref="ArgumentNullException">store is null</exception>
        /// <exception cref="InvalidOperationException">DocumentViewerBase has content which is neither
        /// FlowDocument or FixedDocument; only those two are supported</exception>
        /// <exception cref="InvalidOperationException">this service or another service is already
        /// enabled for the DocumentViewerBase</exception>
        public void Enable(AnnotationStore annotationStore)
        {
            if (annotationStore == null)
                throw new ArgumentNullException("annotationStore");

            VerifyAccess();

            if (_isEnabled)
                throw new InvalidOperationException(SR.Get(SRID.AnnotationServiceIsAlreadyEnabled));

            // Make sure there isn't a service above or below us
            VerifyServiceConfiguration(_root);

            // Post a background work item to load existing annotations.  Do this early in the
            // Enable method in case any later code causes an indirect call to LoadAnnotations,
            // this cached operation will make that LoadAnnotations call a no-op.
            _asyncLoadOperation = _root.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(LoadAnnotationsAsync), this);

            // Enable the store and set it on the tree
            _isEnabled = true;
            _root.SetValue(AnnotationService.ServiceProperty, this);
            _store = annotationStore;

            // If our root is a DocumentViewerBase we need to setup some special processors.
            DocumentViewerBase viewer = _root as DocumentViewerBase;
            if (viewer != null)
            {
                bool isFixed = viewer.Document is FixedDocument || viewer.Document is FixedDocumentSequence;
                bool isFlow = !isFixed && viewer.Document is FlowDocument;

                if (isFixed || isFlow || viewer.Document == null)
                {
                    // Take care of some special processors here
                    if (isFixed)
                    {
                        _locatorManager.RegisterSelectionProcessor(new FixedTextSelectionProcessor(), typeof(TextRange));
                        _locatorManager.RegisterSelectionProcessor(new FixedTextSelectionProcessor(), typeof(TextAnchor));
                    }
                    else if (isFlow)
                    {
                        _locatorManager.RegisterSelectionProcessor(new TextSelectionProcessor(), typeof(TextRange));
                        _locatorManager.RegisterSelectionProcessor(new TextSelectionProcessor(), typeof(TextAnchor));
                        _locatorManager.RegisterSelectionProcessor(new TextViewSelectionProcessor(), typeof(DocumentViewerBase));
                    }
                }
                else
                {
                    throw new InvalidOperationException(SR.Get(SRID.OnlyFlowFixedSupported));
                }
            }

            // Don't register on the store until the service is ready to accept events.
            // Register for content change and anchor change events - we'll need to attach/detach
            // annotations as they are added/removed from the store or their anchors change
            annotationStore.StoreContentChanged += new StoreContentChangedEventHandler(OnStoreContentChanged);
            annotationStore.AnchorChanged += new AnnotationResourceChangedEventHandler(OnAnchorChanged);
        }