Ejemplo n.º 1
0
        /// <summary>
        /// Updates the ZOrder of the input component and on all components with the same ZLevel
        /// that have same or bigger Z-order as the  input component on a given adorner layer
        /// </summary>
        /// <param name="component">the component</param>
        public void UpdateComponentZOrder(IAnnotationComponent component)
        {
            Invariant.Assert(component != null, "null component");

            //check Z-order range for this level
            int level = GetComponentLevel(component);
            //get the component's adorner
            AnnotationAdorner adorner = FindAnnotationAdorner(component);

            if (adorner == null)
            {
                return;
            }

            //set the adorner z-order
            _adornerLayer.SetAdornerZOrder(adorner, ComponentToAdorner(component.ZOrder, level));

            List <AnnotationAdorner> adorners = GetTopAnnotationAdorners(level, component);

            if (adorners == null)
            {
                return;
            }

            int lastZOrder = component.ZOrder + 1;

            foreach (AnnotationAdorner topAdorner in adorners)
            {
                topAdorner.AnnotationComponent.ZOrder = lastZOrder;
                _adornerLayer.SetAdornerZOrder(topAdorner, ComponentToAdorner(lastZOrder, level));
                lastZOrder++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Choose an IAnnotationComponent for a given IAttachedAnnotation.  Implementation in AnnotationComponentChooser knows
        /// about all out-of-box IAnnotationComponents.  The default mapping will be stated here later.
        /// Subclasses can overwrite this method to return application specific mapping.
        /// Note: In future release this method should be made virtual.
        /// </summary>
        /// <param name="attachedAnnotation">The IAttachedAnnotation that needs an IAnnotationComponent </param>
        /// <returns></returns>
        public IAnnotationComponent ChooseAnnotationComponent(IAttachedAnnotation attachedAnnotation)
        {
            if (attachedAnnotation == null)
            {
                throw new ArgumentNullException("attachedAnnotation");
            }

            IAnnotationComponent ac = null;

            // Text StickyNote
            if (attachedAnnotation.Annotation.AnnotationType == StickyNoteControl.TextSchemaName)
            {
                ac = new StickyNoteControl(StickyNoteType.Text) as IAnnotationComponent;
            }
            // Ink StickyNote
            else if (attachedAnnotation.Annotation.AnnotationType == StickyNoteControl.InkSchemaName)
            {
                ac = new StickyNoteControl(StickyNoteType.Ink) as IAnnotationComponent;
            }
            // Highlight
            else if (attachedAnnotation.Annotation.AnnotationType == HighlightComponent.TypeName)
            {
                ac = new HighlightComponent() as IAnnotationComponent;
            }

            return(ac);
        }
        // Token: 0x06007C73 RID: 31859 RVA: 0x0022FF34 File Offset: 0x0022E134
        public void UpdateComponentZOrder(IAnnotationComponent component)
        {
            Invariant.Assert(component != null, "null component");
            int componentLevel = AdornerPresentationContext.GetComponentLevel(component);
            AnnotationAdorner annotationAdorner = this.FindAnnotationAdorner(component);

            if (annotationAdorner == null)
            {
                return;
            }
            this._adornerLayer.SetAdornerZOrder(annotationAdorner, AdornerPresentationContext.ComponentToAdorner(component.ZOrder, componentLevel));
            List <AnnotationAdorner> topAnnotationAdorners = this.GetTopAnnotationAdorners(componentLevel, component);

            if (topAnnotationAdorners == null)
            {
                return;
            }
            int num = component.ZOrder + 1;

            foreach (AnnotationAdorner annotationAdorner2 in topAnnotationAdorners)
            {
                annotationAdorner2.AnnotationComponent.ZOrder = num;
                this._adornerLayer.SetAdornerZOrder(annotationAdorner2, AdornerPresentationContext.ComponentToAdorner(num, componentLevel));
                num++;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Finds all AnnotationAddorners from particular Z-level that have the same or bigger z-order as the component
        /// </summary>
        /// <param name="level">the ZLevel of interest</param>
        /// <param name="component">the component</param>
        /// <returns>the AnnotationAdorner children</returns>
        private List <AnnotationAdorner> GetTopAnnotationAdorners(int level, IAnnotationComponent component)
        {
            List <AnnotationAdorner> res = new List <AnnotationAdorner>();

            int count = VisualTreeHelper.GetChildrenCount(_adornerLayer);

            if (count == 0)
            {
                return(res);
            }

            for (int i = 0; i < count; i++)
            {
                DependencyObject  child   = VisualTreeHelper.GetChild(_adornerLayer, i);
                AnnotationAdorner adorner = child as AnnotationAdorner;
                if (adorner != null)
                {
                    IAnnotationComponent childComponent = adorner.AnnotationComponent;
                    if ((childComponent != component) &&
                        (GetComponentLevel(childComponent) == level) &&
                        (childComponent.ZOrder >= component.ZOrder))
                    {
                        AddAdorner(res, adorner);
                    }
                }
            }

            return(res);
        }
Ejemplo n.º 5
0
        // Token: 0x06007C8E RID: 31886 RVA: 0x002306D0 File Offset: 0x0022E8D0
        private void ModifyAttachedAnnotation(IAttachedAnnotation attachedAnnotation, object previousAttachedAnchor, AttachmentLevel previousAttachmentLevel)
        {
            if (!this._attachedAnnotations.ContainsKey(attachedAnnotation))
            {
                this.AddAttachedAnnotation(attachedAnnotation, true);
                return;
            }
            IAnnotationComponent annotationComponent = this.FindComponent(attachedAnnotation);

            if (annotationComponent == null)
            {
                this.RemoveAttachedAnnotation(attachedAnnotation, true);
                return;
            }
            IList <IAnnotationComponent> list = this._attachedAnnotations[attachedAnnotation];

            if (list.Contains(annotationComponent))
            {
                using (IEnumerator <IAnnotationComponent> enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IAnnotationComponent annotationComponent2 = enumerator.Current;
                        annotationComponent2.ModifyAttachedAnnotation(attachedAnnotation, previousAttachedAnchor, previousAttachmentLevel);
                        if (annotationComponent2.AttachedAnnotations.Count == 0)
                        {
                            annotationComponent2.PresentationContext.RemoveFromHost(annotationComponent2, true);
                        }
                    }
                    return;
                }
            }
            this.RemoveAttachedAnnotation(attachedAnnotation, true);
            this.AddComponent(attachedAnnotation, annotationComponent, true);
        }
        // Token: 0x06007C6B RID: 31851 RVA: 0x0022FD94 File Offset: 0x0022DF94
        public override void RemoveFromHost(IAnnotationComponent component, bool reorder)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (this.IsInternalComponent(component))
            {
                this._annotationAdorner.AnnotationComponent.PresentationContext = null;
                this._adornerLayer.Remove(this._annotationAdorner);
                this._annotationAdorner.RemoveChildren();
                this._annotationAdorner = null;
                return;
            }
            AnnotationAdorner annotationAdorner = this.FindAnnotationAdorner(component);

            if (annotationAdorner == null)
            {
                throw new InvalidOperationException(SR.Get("ComponentNotInPresentationContext", new object[]
                {
                    component
                }));
            }
            this._adornerLayer.Remove(annotationAdorner);
            annotationAdorner.RemoveChildren();
            AdornerPresentationContext adornerPresentationContext = component.PresentationContext as AdornerPresentationContext;

            if (adornerPresentationContext != null)
            {
                adornerPresentationContext.ResetInternalAnnotationAdorner();
            }
            component.PresentationContext = null;
        }
Ejemplo n.º 7
0
        // Token: 0x06007C8D RID: 31885 RVA: 0x00230668 File Offset: 0x0022E868
        private void AddComponent(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component, bool reorder)
        {
            UIElement uielement = attachedAnnotation.Parent as UIElement;

            if (component.PresentationContext != null)
            {
                return;
            }
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(uielement);

            if (adornerLayer != null)
            {
                this.AddToAttachedAnnotations(attachedAnnotation, component);
                component.AddAttachedAnnotation(attachedAnnotation);
                AdornerPresentationContext.HostComponent(adornerLayer, component, uielement, reorder);
                return;
            }
            if (PresentationSource.FromVisual(uielement) == null)
            {
                return;
            }
            throw new InvalidOperationException(SR.Get("NoPresentationContextForGivenElement", new object[]
            {
                uielement
            }));
        }
 // Token: 0x06007C6A RID: 31850 RVA: 0x0022FD71 File Offset: 0x0022DF71
 public override void AddToHost(IAnnotationComponent component)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     AdornerPresentationContext.HostComponent(this._adornerLayer, component, component.AnnotatedElement, false);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Service indicates attached annotation has changed.
        /// For now, take all annotation components maped from old attached annotation and map from new.
        /// Then iterate through annotation components to let them know.
        /// Note, this needs to change later.  If modify is radical, existing component might not want it anymore,
        /// and new one might need to be found...
        /// </summary>
        /// <param name="attachedAnnotation">The modified attached annotation</param>
        /// <param name="previousAttachedAnchor">The previous attached anchor for the attached annotation</param>
        /// <param name="previousAttachmentLevel">The previous attachment level for the attached annotation</param>
        private void ModifyAttachedAnnotation(IAttachedAnnotation attachedAnnotation, object previousAttachedAnchor, AttachmentLevel previousAttachmentLevel)
        {
            Debug.Assert(attachedAnnotation != null, "attachedAnnotation should not be null");
            Debug.Assert(previousAttachedAnchor != null, "previousAttachedAnchor should not be null");

            // if there was no component found for this attached annotation
            // then we treat the modify case as an add
            if (!_attachedAnnotations.ContainsKey(attachedAnnotation))
            {
                // this is not necessarily a bug, it can be that the old attached annotation does not have an
                // associated annotation component.
                this.AddAttachedAnnotation(attachedAnnotation, true);
                return;
            }

            // we have a previous component for this attached annotation
            // we find the chooser for the new attached annotation
            // and ask it to choose a component
            // 1- if it returned null then we just remove the attached annotation
            // 2- if it returned a different component, then we treat it as a remove/add
            // 3- if it returned the same component then we call ModifyAttachedAnnotation on the component
            IAnnotationComponent newComponent = FindComponent(attachedAnnotation);

            if (newComponent == null)
            {
                RemoveAttachedAnnotation(attachedAnnotation, true);
            }
            else
            {
                IList <IAnnotationComponent> currentList = _attachedAnnotations[attachedAnnotation]; //save the current list

                // if we found the new component in any of the list of components we already have for this
                // attached annotation
                if (currentList.Contains(newComponent))
                {
                    // ask the components to handle the anchor modification event
                    foreach (IAnnotationComponent component in currentList)
                    {
                        component.ModifyAttachedAnnotation(attachedAnnotation, previousAttachedAnchor, previousAttachmentLevel);  // let the annotation component know
                        if (component.AttachedAnnotations.Count == 0)
                        {
                            // if component decides it can not handle it, remove it
                            component.PresentationContext.RemoveFromHost(component, true);
                        }
                    }
                }
                else
                {
                    // remove all components
                    RemoveAttachedAnnotation(attachedAnnotation, true);

                    // add the new component
                    AddComponent(attachedAnnotation, newComponent, true);
                }
            }
        }
Ejemplo n.º 10
0
        // Token: 0x06007C89 RID: 31881 RVA: 0x00230504 File Offset: 0x0022E704
        internal void AddAttachedAnnotation(IAttachedAnnotation attachedAnnotation, bool reorder)
        {
            IAnnotationComponent annotationComponent = this.FindComponent(attachedAnnotation);

            if (annotationComponent == null)
            {
                return;
            }
            this.AddComponent(attachedAnnotation, annotationComponent, reorder);
        }
 // Token: 0x06007C7E RID: 31870 RVA: 0x002302A8 File Offset: 0x0022E4A8
 public AnnotationAdorner(IAnnotationComponent component, UIElement annotatedElement) : base(annotatedElement)
 {
     if (component is UIElement)
     {
         this._annotationComponent = component;
         base.AddVisualChild((UIElement)this._annotationComponent);
         return;
     }
     throw new ArgumentException(SR.Get("AnnotationAdorner_NotUIElement"), "component");
 }
        // Token: 0x06007C6E RID: 31854 RVA: 0x0022FEB8 File Offset: 0x0022E0B8
        public override void SendToBack(IAnnotationComponent component)
        {
            AnnotationAdorner annotationAdorner = this.GetAnnotationAdorner(component);
            int componentLevel = AdornerPresentationContext.GetComponentLevel(component);

            if (component.ZOrder != 0)
            {
                component.ZOrder = 0;
                this.UpdateComponentZOrder(component);
            }
        }
        // Token: 0x06007C7B RID: 31867 RVA: 0x00230208 File Offset: 0x0022E408
        private static int GetComponentLevel(IAnnotationComponent component)
        {
            int  result = 0;
            Type type   = component.GetType();

            if (AdornerPresentationContext._ZLevel.ContainsKey(type))
            {
                result = (int)AdornerPresentationContext._ZLevel[type];
            }
            return(result);
        }
        // Token: 0x06007C6D RID: 31853 RVA: 0x0022FE64 File Offset: 0x0022E064
        public override void BringToFront(IAnnotationComponent component)
        {
            AnnotationAdorner annotationAdorner = this.GetAnnotationAdorner(component);
            int componentLevel = AdornerPresentationContext.GetComponentLevel(component);
            int nextZOrder     = AdornerPresentationContext.GetNextZOrder(this._adornerLayer, componentLevel);

            if (nextZOrder != component.ZOrder + 1)
            {
                component.ZOrder = nextZOrder;
                this._adornerLayer.SetAdornerZOrder(annotationAdorner, AdornerPresentationContext.ComponentToAdorner(component.ZOrder, componentLevel));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets a component on bttom of its ZLevel
        /// </summary>
        /// <param name="component">Component to change z-order of</param>
        public override void SendToBack(IAnnotationComponent component)
        {
            AnnotationAdorner adorner = GetAnnotationAdorner(component);
            int level = GetComponentLevel(component);

            // Only change the ZOrder if its not already on the bottom
            if (0 != component.ZOrder)
            {
                component.ZOrder = 0;
                UpdateComponentZOrder(component);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns the component ZLevel
        /// </summary>
        /// <param name="component">component</param>
        /// <returns>ZLevel</returns>
        private static int GetComponentLevel(IAnnotationComponent component)
        {
            int  level = 0;
            Type type  = component.GetType();

            if (_ZLevel.ContainsKey(type))
            {
                level = (int)_ZLevel[type];
            }

            return(level);
        }
Ejemplo n.º 17
0
            // Token: 0x06008E68 RID: 36456 RVA: 0x0025C340 File Offset: 0x0025A540
            private int Compare(IAnnotationComponent first, IAnnotationComponent second)
            {
                TextAnchor textAnchor  = ((IAttachedAnnotation)first.AttachedAnnotations[0]).FullyAttachedAnchor as TextAnchor;
                TextAnchor textAnchor2 = ((IAttachedAnnotation)second.AttachedAnnotations[0]).FullyAttachedAnchor as TextAnchor;
                int        num         = textAnchor.Start.CompareTo(textAnchor2.Start);

                if (num == 0)
                {
                    num = textAnchor.End.CompareTo(textAnchor2.End);
                }
                return(num);
            }
Ejemplo n.º 18
0
        /// <summary>
        /// The given attached annotation was added by the annotation service
        /// Find annotation components for the given attached annotation, maintain
        /// mapping from attached annotation to annotation components, and add to the
        /// adorner layer if the annotation component is not already in a presentation context.
        /// </summary>
        /// <param name="attachedAnnotation">Attached annotation to add</param>
        /// <param name="reorder">If true - update components ZOrder after adding the component</param>
        internal void AddAttachedAnnotation(IAttachedAnnotation attachedAnnotation, bool reorder)
        {
            Debug.Assert(attachedAnnotation != null, "AttachedAnnotation should not be null");

            IAnnotationComponent component = FindComponent(attachedAnnotation);

            if (component == null)
            {
                return;
            }
            AddComponent(attachedAnnotation, component, reorder);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Sets a component on top of its ZLevel
        /// </summary>
        /// <param name="component">Component to change z-order of</param>
        public override void BringToFront(IAnnotationComponent component)
        {
            AnnotationAdorner adorner = GetAnnotationAdorner(component);
            int level     = GetComponentLevel(component);
            int nextLevel = GetNextZOrder(_adornerLayer, level);

            // Only change the ZOrder if its not already on the top
            if (nextLevel != component.ZOrder + 1)
            {
                component.ZOrder = nextLevel;
                _adornerLayer.SetAdornerZOrder(adorner, ComponentToAdorner(component.ZOrder, level));
            }
        }
        // Token: 0x06007C65 RID: 31845 RVA: 0x0022FC4C File Offset: 0x0022DE4C
        internal static void HostComponent(AdornerLayer adornerLayer, IAnnotationComponent component, UIElement annotatedElement, bool reorder)
        {
            AnnotationAdorner annotationAdorner = new AnnotationAdorner(component, annotatedElement);

            annotationAdorner.AnnotationComponent.PresentationContext = new AdornerPresentationContext(adornerLayer, annotationAdorner);
            int componentLevel = AdornerPresentationContext.GetComponentLevel(component);

            if (reorder)
            {
                component.ZOrder = AdornerPresentationContext.GetNextZOrder(adornerLayer, componentLevel);
            }
            adornerLayer.Add(annotationAdorner, AdornerPresentationContext.ComponentToAdorner(component.ZOrder, componentLevel));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// given an attachedAnnotation find the chooser attached at its parent
        /// and ask it to choose a component suitable to handle the attachedAnnotation
        /// </summary>
        /// <param name="attachedAnnotation">the attachedAnnotation we are to find a component for</param>
        /// <returns>an IAnnotationComponent that can handle the attachedAnnotation (or null)</returns>
        private IAnnotationComponent FindComponent(IAttachedAnnotation attachedAnnotation)
        {
            Debug.Assert(attachedAnnotation != null, "AttachedAnnotation should not be null");

            UIElement annotatedElement = attachedAnnotation.Parent as UIElement; // casted from DependencyObject

            Debug.Assert(annotatedElement != null, "the annotatedElement should inherit from UIElement");

            AnnotationComponentChooser chooser = AnnotationService.GetChooser(annotatedElement);

            // should we return a list instead?
            IAnnotationComponent component = chooser.ChooseAnnotationComponent(attachedAnnotation);

            return(component);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Return an initialized annotation adorner
 /// </summary>
 /// <param name="component">The annotation component to wrap in the annotation adorner</param>
 /// <param name="annotatedElement">element being annotated</param>
 public AnnotationAdorner(IAnnotationComponent component, UIElement annotatedElement): base(annotatedElement)
 {
     //The summary on top of the file says:-
     //The wrapped component must be at least a UIElement
     if(component is UIElement)
     {
         _annotationComponent = component;                
         // wrapped annotation component is added as visual child
         this.AddVisualChild((UIElement)_annotationComponent);                 
     }
     else
     {
         throw new ArgumentException(SR.Get(SRID.AnnotationAdorner_NotUIElement), "component");            
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Return an initialized annotation adorner
 /// </summary>
 /// <param name="component">The annotation component to wrap in the annotation adorner</param>
 /// <param name="annotatedElement">element being annotated</param>
 public AnnotationAdorner(IAnnotationComponent component, UIElement annotatedElement) : base(annotatedElement)
 {
     //The summary on top of the file says:-
     //The wrapped component must be at least a UIElement
     if (component is UIElement)
     {
         _annotationComponent = component;
         // wrapped annotation component is added as visual child
         this.AddVisualChild((UIElement)_annotationComponent);
     }
     else
     {
         throw new ArgumentException(SR.Get(SRID.AnnotationAdorner_NotUIElement), "component");
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Host a component in an adorner layer.
        /// Wrap the component in an annotation adorner, add that to the adorner layer, create and set presentation context and invalidate to pick up styles.
        /// Note, this is called from two places: (1) component manager to host choosen annotation component, and (2) presentation context when component
        /// adds additional IAnnotationComponent.
        /// </summary>
        /// <param name="adornerLayer">Adorner layer the component is hosted in</param>
        /// <param name="component">Component that is being hosted</param>
        /// <param name="annotatedElement">element being annotated</param>
        /// <param name="reorder">if true - put the component on top and calculate its z-order</param>
        internal static void HostComponent(AdornerLayer adornerLayer, IAnnotationComponent component, UIElement annotatedElement, bool reorder)
        {
            AnnotationAdorner newAdorner = new AnnotationAdorner(component, annotatedElement);

            // Create the context for the layer and adorner, make sure the adorner's component has its context.
            newAdorner.AnnotationComponent.PresentationContext = new AdornerPresentationContext(adornerLayer, newAdorner);

            int level = GetComponentLevel(component);

            if (reorder)
            {
                component.ZOrder = GetNextZOrder(adornerLayer, level);
            }

            adornerLayer.Add(newAdorner, ComponentToAdorner(component.ZOrder, level));
        }
        /// <summary>
        /// Host a component in an adorner layer. 
        /// Wrap the component in an annotation adorner, add that to the adorner layer, create and set presentation context and invalidate to pick up styles.
        /// Note, this is called from two places: (1) component manager to host choosen annotation component, and (2) presentation context when component 
        /// adds additional IAnnotationComponent. 
        /// </summary>
        /// <param name="adornerLayer">Adorner layer the component is hosted in</param> 
        /// <param name="component">Component that is being hosted</param>
        /// <param name="annotatedElement">element being annotated</param>
        /// <param name="reorder">if true - put the component on top and calculate its z-order</param>
        internal static void HostComponent(AdornerLayer adornerLayer, IAnnotationComponent component, UIElement annotatedElement, bool reorder) 
        {
            AnnotationAdorner newAdorner = new AnnotationAdorner(component, annotatedElement); 
            // Create the context for the layer and adorner, make sure the adorner's component has its context. 
            newAdorner.AnnotationComponent.PresentationContext = new AdornerPresentationContext(adornerLayer, newAdorner);
 
            int level = GetComponentLevel(component);

            if (reorder)
            { 
                component.ZOrder = GetNextZOrder(adornerLayer, level);
            } 
 
            adornerLayer.Add(newAdorner, ComponentToAdorner(component.ZOrder, level));
 
        }
 // Token: 0x06007C76 RID: 31862 RVA: 0x00230018 File Offset: 0x0022E218
 private AnnotationAdorner FindAnnotationAdorner(IAnnotationComponent component)
 {
     if (this._adornerLayer == null)
     {
         return(null);
     }
     foreach (Adorner adorner in this._adornerLayer.GetAdorners(component.AnnotatedElement))
     {
         AnnotationAdorner annotationAdorner = adorner as AnnotationAdorner;
         if (annotationAdorner != null && annotationAdorner.AnnotationComponent == component)
         {
             return(annotationAdorner);
         }
     }
     return(null);
 }
        // Token: 0x06007C7A RID: 31866 RVA: 0x002301B4 File Offset: 0x0022E3B4
        private AnnotationAdorner GetAnnotationAdorner(IAnnotationComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            AnnotationAdorner annotationAdorner = this._annotationAdorner;

            if (!this.IsInternalComponent(component))
            {
                annotationAdorner = this.FindAnnotationAdorner(component);
                if (annotationAdorner == null)
                {
                    throw new InvalidOperationException(SR.Get("ComponentNotInPresentationContext", new object[]
                    {
                        component
                    }));
                }
            }
            return(annotationAdorner);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Finds the correct AdornerLayer where a component lives
        /// </summary>
        /// <param name="component">the component</param>
        /// <returns></returns>
        private AnnotationAdorner GetAnnotationAdorner(IAnnotationComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            //find the adornerLayer
            AnnotationAdorner adorner = _annotationAdorner;

            if (!this.IsInternalComponent(component))
            {
                adorner = this.FindAnnotationAdorner(component);

                if (adorner == null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.ComponentNotInPresentationContext, component));
                }
            }

            return(adorner);
        }
Ejemplo n.º 29
0
        // Token: 0x06006288 RID: 25224 RVA: 0x001BA5F8 File Offset: 0x001B87F8
        public IAnnotationComponent ChooseAnnotationComponent(IAttachedAnnotation attachedAnnotation)
        {
            if (attachedAnnotation == null)
            {
                throw new ArgumentNullException("attachedAnnotation");
            }
            IAnnotationComponent result = null;

            if (attachedAnnotation.Annotation.AnnotationType == StickyNoteControl.TextSchemaName)
            {
                result = new StickyNoteControl(StickyNoteType.Text);
            }
            else if (attachedAnnotation.Annotation.AnnotationType == StickyNoteControl.InkSchemaName)
            {
                result = new StickyNoteControl(StickyNoteType.Ink);
            }
            else if (attachedAnnotation.Annotation.AnnotationType == HighlightComponent.TypeName)
            {
                result = new HighlightComponent();
            }
            return(result);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Remove annotation component from host;  in our case: respective annotation adorner from adornerLayer.
        /// If this presentation context does not contain the component search the adorner layer.
        /// Null out the presentation context of the component and set the local annotationAdorner to null if necessary,
        /// ask the annotation adorner to remove all visual children.
        /// </summary>
        /// <param name="component">Component to remove from host</param>
        /// <param name="reorder">if true - recalculate z-order</param>
        public override void RemoveFromHost(IAnnotationComponent component, bool reorder)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            if (IsInternalComponent(component))
            {
                _annotationAdorner.AnnotationComponent.PresentationContext = null;
                _adornerLayer.Remove(_annotationAdorner);
                _annotationAdorner.RemoveChildren();
                _annotationAdorner = null;
            }
            else
            {// need to find annotation adorner in layer, remove it and do house-keeping
                AnnotationAdorner foundAdorner = this.FindAnnotationAdorner(component);

                if (foundAdorner == null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.ComponentNotInPresentationContext, component));
                }

                _adornerLayer.Remove(foundAdorner);
                foundAdorner.RemoveChildren();

                // now get rid of reference from presentation context of annotation component to annotation adorner
                AdornerPresentationContext p = component.PresentationContext as AdornerPresentationContext;

                if (p != null)
                {
                    p.ResetInternalAnnotationAdorner();
                }

                // finally get rid of reference from annotation component to presentation context
                component.PresentationContext = null;
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Add an attached annotation to a component and add the component to the adorner layer
        /// if the annotation component is not already in a presentation context.
        /// </summary>
        /// <param name="attachedAnnotation">the attachedAnnotation we are to add to the component</param>
        /// <param name="component">the component we are to add to the adorner layer</param>
        /// <param name="reorder">if true - the z-order must be reevaluated</param>
        private void AddComponent(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component, bool reorder)
        {
            UIElement annotatedElement = attachedAnnotation.Parent as UIElement; // casted from DependencyObject

            Debug.Assert(annotatedElement != null, "the annotatedElement should inherit from UIElement");

            // if annotation component is already in presentation context, nothing else to do
            if (component.PresentationContext != null)
            {
                return;
            }

            // otherwise host in the appropriate adorner layer
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(annotatedElement); // note, GetAdornerLayer requires UIElement

            if (layer == null)
            {
                if (PresentationSource.FromVisual(annotatedElement) == null)
                {
                    // The annotated element is no longer part of the application tree.
                    // This probably means we are out of [....] - trying to add an annotation
                    // for an element that has already gone away.  Bug # 1580288 tracks
                    // the need to figure this out.
                    return;
                }

                throw new InvalidOperationException(SR.Get(SRID.NoPresentationContextForGivenElement, annotatedElement));
            }

            // add to the attachedAnnotations
            this.AddToAttachedAnnotations(attachedAnnotation, component);

            // let the annotation component know about the attached annotation
            // call add before adding to adorner layer so the component can be initialized
            component.AddAttachedAnnotation(attachedAnnotation); // this might cause recursion in modify if annotation component adds to annotation

            AdornerPresentationContext.HostComponent(layer, component, annotatedElement, reorder);
        }
        // Token: 0x06007C77 RID: 31863 RVA: 0x0023006C File Offset: 0x0022E26C
        private List <AnnotationAdorner> GetTopAnnotationAdorners(int level, IAnnotationComponent component)
        {
            List <AnnotationAdorner> list = new List <AnnotationAdorner>();
            int childrenCount             = VisualTreeHelper.GetChildrenCount(this._adornerLayer);

            if (childrenCount == 0)
            {
                return(list);
            }
            for (int i = 0; i < childrenCount; i++)
            {
                DependencyObject  child             = VisualTreeHelper.GetChild(this._adornerLayer, i);
                AnnotationAdorner annotationAdorner = child as AnnotationAdorner;
                if (annotationAdorner != null)
                {
                    IAnnotationComponent annotationComponent = annotationAdorner.AnnotationComponent;
                    if (annotationComponent != component && AdornerPresentationContext.GetComponentLevel(annotationComponent) == level && annotationComponent.ZOrder >= component.ZOrder)
                    {
                        this.AddAdorner(list, annotationAdorner);
                    }
                }
            }
            return(list);
        }
 /// <summary>
 /// Return true if the given annotation component is the one this presentation context is on. 
 /// </summary>
 /// <param name="component">The component that might be referred to by this presentation context</param> 
 /// <returns>True if the component is internal</returns> 
 private bool IsInternalComponent(IAnnotationComponent component)
 { 
     return _annotationAdorner != null && component == _annotationAdorner.AnnotationComponent;
 }
        /// <summary> 
        /// Add an attached annotation to a component and add the component to the adorner layer
        /// if the annotation component is not already in a presentation context.
        /// </summary>
        /// <param name="attachedAnnotation">the attachedAnnotation we are to add to the component</param> 
        /// <param name="component">the component we are to add to the adorner layer</param>
        /// <param name="reorder">if true - the z-order must be reevaluated</param> 
        private void AddComponent(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component, bool reorder) 
        {
            UIElement annotatedElement = attachedAnnotation.Parent as UIElement; // casted from DependencyObject 
            Debug.Assert(annotatedElement != null, "the annotatedElement should inherit from UIElement");

            // if annotation component is already in presentation context, nothing else to do
            if (component.PresentationContext != null) return; 

            // otherwise host in the appropriate adorner layer 
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(annotatedElement); // note, GetAdornerLayer requires UIElement 
            if (layer == null)
            { 
                if (PresentationSource.FromVisual(annotatedElement) == null)
                {
                    // The annotated element is no longer part of the application tree.
                    // This probably means we are out of [....] - trying to add an annotation 
                    // for an element that has already gone away.  Bug # 1580288 tracks
                    // the need to figure this out. 
                    return; 
                }
 
                throw new InvalidOperationException(SR.Get(SRID.NoPresentationContextForGivenElement, annotatedElement));
            }

            // add to the attachedAnnotations 
            this.AddToAttachedAnnotations(attachedAnnotation, component);
 
            // let the annotation component know about the attached annotation 
            // call add before adding to adorner layer so the component can be initialized
            component.AddAttachedAnnotation(attachedAnnotation); // this might cause recursion in modify if annotation component adds to annotation 

            AdornerPresentationContext.HostComponent(layer, component, annotatedElement, reorder);

        } 
        /// <summary>
        /// Returns the component ZLevel
        /// </summary>
        /// <param name="component">component</param> 
        /// <returns>ZLevel</returns>
        private static int GetComponentLevel(IAnnotationComponent component) 
        { 
            int level = 0;
            Type type = component.GetType(); 
            if (_ZLevel.ContainsKey(type))
                level = (int)_ZLevel[type];

            return level; 
        }
        /// <summary> 
        /// Finds the correct AdornerLayer where a component lives
        /// </summary> 
        /// <param name="component">the component</param>
        /// <returns></returns>
        private AnnotationAdorner GetAnnotationAdorner(IAnnotationComponent component)
        { 
            if (component == null) throw new ArgumentNullException("component");
 
            //find the adornerLayer 
            AnnotationAdorner adorner = _annotationAdorner;
            if (!this.IsInternalComponent(component)) 
            {
                adorner = this.FindAnnotationAdorner(component);

                if (adorner == null) throw new InvalidOperationException(SR.Get(SRID.ComponentNotInPresentationContext, component)); 
            }
 
            return adorner; 
        }
        /// <summary> 
        /// Finds all AnnotationAddorners from particular Z-level that have the same or bigger z-order as the component
        /// </summary> 
        /// <param name="level">the ZLevel of interest</param>
        /// <param name="component">the component</param>
        /// <returns>the AnnotationAdorner children</returns>
        private List<AnnotationAdorner> GetTopAnnotationAdorners(int level, IAnnotationComponent component) 
        {
            List<AnnotationAdorner> res = new List<AnnotationAdorner>(); 
 
            int count = VisualTreeHelper.GetChildrenCount(_adornerLayer);
            if (count == 0) 
                return res;

            for (int i = 0; i < count; i++)
            { 
                DependencyObject child = VisualTreeHelper.GetChild(_adornerLayer, i);
                AnnotationAdorner adorner = child as AnnotationAdorner; 
                if (adorner != null) 
                {
                    IAnnotationComponent childComponent = adorner.AnnotationComponent; 
                    if ((childComponent != component) &&
                       (GetComponentLevel(childComponent) == level) &&
                       (childComponent.ZOrder >= component.ZOrder))
                    { 
                        AddAdorner(res, adorner);
                    } 
                } 
            }
 
            return res;
        }
        /// <summary> 
        /// Add the component to the adornerlayer of this presentation context.
        /// Create a new presentation context which includes the wrapped annotation adorner and the adornerlayer. 
        /// Assign new presentation context into the component.
        /// </summary>
        /// <param name="component">Component to add to host</param>
        public override void AddToHost(IAnnotationComponent component) 
        {
            if (component == null) throw new ArgumentNullException("component"); 
 
            AdornerPresentationContext.HostComponent(_adornerLayer, component, component.AnnotatedElement, false);
        } 
 /// <summary>
 /// Add annotation component to host.
 /// Needed by annotation components which need to add addl. components
 /// </summary>
 /// <param name="component">the component to add to the presentation context.</param>
 public abstract void AddToHost(IAnnotationComponent component);
        /// <summary> 
        /// Updates the ZOrder of the input component and on all components with the same ZLevel
        /// that have same or bigger Z-order as the  input component on a given adorner layer 
        /// </summary> 
        /// <param name="component">the component</param>
        public void UpdateComponentZOrder(IAnnotationComponent component) 
        {
            Invariant.Assert(component != null, "null component");

            //check Z-order range for this level 
            int level = GetComponentLevel(component);
            //get the component's adorner 
            AnnotationAdorner adorner = FindAnnotationAdorner(component); 
            if (adorner == null)
                return; 

            //set the adorner z-order
            _adornerLayer.SetAdornerZOrder(adorner, ComponentToAdorner(component.ZOrder, level));
 
            List<AnnotationAdorner> adorners = GetTopAnnotationAdorners(level, component);
            if (adorners == null) 
                return; 

            int lastZOrder = component.ZOrder + 1; 
            foreach (AnnotationAdorner topAdorner in adorners)
            {
                topAdorner.AnnotationComponent.ZOrder = lastZOrder;
                _adornerLayer.SetAdornerZOrder(topAdorner, ComponentToAdorner(lastZOrder, level)); 
                lastZOrder++;
            } 
        } 
 /// <summary>
 /// to change z-order of annotation component to be the bottom component
 /// </summary>
 /// <param name="component">the component to send to back</param>
 public abstract void SendToBack(IAnnotationComponent component);
        /// <summary> 
        /// Add to the map from attached annotations -> annotation components
        /// </summary>
        /// <param name="attachedAnnotation">The attached annotation to use as key</param>
        /// <param name="component">The component to add to list</param> 
        private void AddToAttachedAnnotations(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component)
        { 
            Debug.Assert(attachedAnnotation != null, "attachedAnnotation should not be null"); 
            Debug.Assert(component != null, "component should not be null");
 
            IList<IAnnotationComponent> currentList;

            if (!_attachedAnnotations.TryGetValue(attachedAnnotation, out currentList))
            { 
                currentList = new List<IAnnotationComponent>();
                _attachedAnnotations[attachedAnnotation] = currentList; 
            } 

            currentList.Add(component); 
        }
 /// <summary>
 /// Removes annotation component from host.  
 /// Will raise exception if annotation component not contained in host
 /// </summary>
 /// <param name="component">the component to remove from the presentation context.</param>
 /// <param name="reorder">if true - recalculate z-order</param>
 public abstract void RemoveFromHost(IAnnotationComponent component, bool reorder);
        /// <summary> 
        /// Return the annotation adorner for the given annotation component.
        /// will not look at local annotation adorner, will always iterate through annotation adorners of adorner layer. 
        /// Return null if none can be found. 
        /// </summary>
        /// <param name="component">The component that is wrapped by an annotation adorner</param> 
        /// <returns>The annotation adorner that wraps the component in the adorner layer associated with this presentation context</returns>
        private AnnotationAdorner FindAnnotationAdorner(IAnnotationComponent component)
        {
            if (_adornerLayer == null) return null; 

            foreach (Adorner adorner in _adornerLayer.GetAdorners(component.AnnotatedElement)) 
            { 
                AnnotationAdorner annotationAdorner = adorner as AnnotationAdorner;
 
                if (annotationAdorner != null && annotationAdorner.AnnotationComponent == component) return annotationAdorner;
            }

            return null; 
        }
 /// <summary>
 /// invalidate the transform for this adorner. called when adorner inside changed aspects of the transform
 /// this might go away if InvalidateMeasure works. Bug # TBD 
 /// </summary>
 /// <param name="component">the component to invalidate the transform on</param>
 public abstract void InvalidateTransform(IAnnotationComponent component);
        /// <summary> 
        /// Sets a component on top of its ZLevel
        /// </summary> 
        /// <param name="component">Component to change z-order of</param>
        public override void BringToFront(IAnnotationComponent component)
        {
            AnnotationAdorner adorner = GetAnnotationAdorner(component); 
            int level = GetComponentLevel(component);
            int nextLevel = GetNextZOrder(_adornerLayer, level); 
 
            // Only change the ZOrder if its not already on the top
            if (nextLevel != component.ZOrder + 1) 
            {
                component.ZOrder = nextLevel;
                _adornerLayer.SetAdornerZOrder(adorner, ComponentToAdorner(component.ZOrder, level));
            } 
        }
        /// <summary> 
        /// Sets a component on bttom of its ZLevel
        /// </summary> 
        /// <param name="component">Component to change z-order of</param>
        public override void SendToBack(IAnnotationComponent component)
        {
            AnnotationAdorner adorner = GetAnnotationAdorner(component); 
            int level = GetComponentLevel(component);
 
            // Only change the ZOrder if its not already on the bottom 
            if (0 != component.ZOrder)
            { 
                component.ZOrder = 0;
                UpdateComponentZOrder(component);
            }
        } 
        /// <summary>
        /// Remove annotation component from host;  in our case: respective annotation adorner from adornerLayer.
        /// If this presentation context does not contain the component search the adorner layer. 
        /// Null out the presentation context of the component and set the local annotationAdorner to null if necessary,
        /// ask the annotation adorner to remove all visual children. 
        /// </summary> 
        /// <param name="component">Component to remove from host</param>
        /// <param name="reorder">if true - recalculate z-order</param> 
        public override void RemoveFromHost(IAnnotationComponent component, bool reorder)
        {
            if (component == null) throw new ArgumentNullException("component");
 
            if (IsInternalComponent(component))
            { 
                _annotationAdorner.AnnotationComponent.PresentationContext = null; 
                _adornerLayer.Remove(_annotationAdorner);
                _annotationAdorner.RemoveChildren(); 
                _annotationAdorner = null;
            }
            else
            {// need to find annotation adorner in layer, remove it and do house-keeping 
                AnnotationAdorner foundAdorner = this.FindAnnotationAdorner(component);
 
                if (foundAdorner == null) throw new InvalidOperationException(SR.Get(SRID.ComponentNotInPresentationContext, component)); 

                _adornerLayer.Remove(foundAdorner); 
                foundAdorner.RemoveChildren();

                // now get rid of reference from presentation context of annotation component to annotation adorner
                AdornerPresentationContext p = component.PresentationContext as AdornerPresentationContext; 

                if (p != null) p.ResetInternalAnnotationAdorner(); 
 
                // finally get rid of reference from annotation component to presentation context
                component.PresentationContext = null; 
            }
        }
 /// <summary>
 /// to change z-order of annotation component to be the top component
 /// </summary>
 /// <param name="component">the component to bring to front</param>
 public abstract void BringToFront(IAnnotationComponent component);
Ejemplo n.º 50
0
            /// <summary> 
            /// Compares the anchors of two AnnotationComponents that have a ITextRange
            /// as attachedAnchor. 
            /// </summary>
            /// <param name="first">first component</param>
            /// <param name="second">second component</param>
            /// <returns> less than 0 - first is before the second; == 0 - equal attached anchors; > 0 first is after the second</returns> 
            /// <remarks>The comparison is based on the comparison of the Start TPs of the two AttachedAnchors
            /// If Start TPs are equal, the end TPs are compared. The result will be 0 only if 
            /// both = Start and End TPs are equal. </remarks> 
            private int Compare(IAnnotationComponent first, IAnnotationComponent second)
            { 
                Debug.Assert(first != null, "first component is null");
                Debug.Assert((first.AttachedAnnotations != null) && (first.AttachedAnnotations.Count > 0), "first AttachedAnchor is null");
                Debug.Assert(second != null, "second component is null");
                Debug.Assert((second.AttachedAnnotations != null) && (second.AttachedAnnotations.Count > 0), "second AttachedAnchor is null"); 

                TextAnchor firstAnchor = ((IAttachedAnnotation)first.AttachedAnnotations[0]).FullyAttachedAnchor as TextAnchor; 
                TextAnchor secondAnchor = ((IAttachedAnnotation)second.AttachedAnnotations[0]).FullyAttachedAnchor as TextAnchor; 

                Debug.Assert(firstAnchor != null, " first TextAnchor is null"); 
                Debug.Assert(secondAnchor != null, " second TextAnchor is null");

                int res = firstAnchor.Start.CompareTo(secondAnchor.Start);
                if (res == 0) 
                    res = firstAnchor.End.CompareTo(secondAnchor.End);
 
                return res; 
            }
 /// <summary> 
 /// Invalidate the transform for this adorner. called when adorner inside changed aspects of the transform.
 /// This might go away if InvalidateMeasure works 
 /// (unclear if Peter means this should work on the adorner or even one down on the annotation component itself) 
 /// </summary>
 /// <param name="component">Component to invalidate transform for</param> 
 public override void InvalidateTransform(IAnnotationComponent component)
 {
     AnnotationAdorner adorner = GetAnnotationAdorner(component);
     adorner.InvalidateTransform(); 
 }