Exemple #1
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);
        }
Exemple #2
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++;
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the next free Z-order value for the components in this level
        /// </summary>
        /// <param name="adornerLayer">adorner layer</param>
        /// <param name="level">Z-level</param>
        /// <returns>next free Z-order value</returns>
        private static int GetNextZOrder(AdornerLayer adornerLayer, int level)
        {
            Invariant.Assert(adornerLayer != null, "null adornerLayer");

            int res = 0;

            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)
                {
                    if ((GetComponentLevel(adorner.AnnotationComponent) == level) &&
                        (adorner.AnnotationComponent.ZOrder >= res))
                    {
                        res = adorner.AnnotationComponent.ZOrder + 1;
                    }
                }
            }

            return(res);
        }
        // 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++;
            }
        }
        // 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;
        }
        // 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: 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));
            }
        }
Exemple #8
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);
            }
        }
        // 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));
        }
Exemple #10
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));
            }
        }
        /// <summary>
        /// Create an initialized instance of an AdornerPresentationContext. Set the presentation context of the 
        /// component wrapped in the adorner 
        /// </summary>
        /// <param name="adornerLayer">AdornerLayer this presentation context is on, must not be null</param> 
        /// <param name="adorner">AnnotationAdorner that wraps the annotation component.  Will be null in case of creating enclosing context</param>
        private AdornerPresentationContext(AdornerLayer adornerLayer, AnnotationAdorner adorner)
        {
            if (adornerLayer == null) throw new ArgumentNullException("adornerLayer"); 

            _adornerLayer = adornerLayer; 
            if (adorner != null) 
            {
                if (adorner.AnnotationComponent == null) 
                    throw new ArgumentNullException("annotation component");
                if (adorner.AnnotationComponent.PresentationContext != null)
                    throw new InvalidOperationException(SR.Get(SRID.ComponentAlreadyInPresentationContext, adorner.AnnotationComponent));
                _annotationAdorner = adorner; 
            }
        } 
        // Token: 0x06007C78 RID: 31864 RVA: 0x002300E8 File Offset: 0x0022E2E8
        private void AddAdorner(List <AnnotationAdorner> adorners, AnnotationAdorner adorner)
        {
            int num = 0;

            if (adorners.Count > 0)
            {
                num = adorners.Count;
                while (num > 0 && adorners[num - 1].AnnotationComponent.ZOrder > adorner.AnnotationComponent.ZOrder)
                {
                    num--;
                }
            }
            adorners.Insert(num, adorner);
        }
 // 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);
 }
Exemple #14
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));
 
        }
Exemple #16
0
        /// <summary>
        /// Inserts an adorner after the last adorner with ZOrder less or equal of the input one
        /// </summary>
        /// <param name="adorners">adorners list</param>
        /// <param name="adorner">the new adorner</param>
        /// <remarks>In most cases the AnnotationAdorners are already orderd so we expect that the new one
        /// will be added at the end of the list. That is why we start scaning from the end.</remarks>
        private void AddAdorner(List <AnnotationAdorner> adorners, AnnotationAdorner adorner)
        {
            Debug.Assert((adorners != null) && (adorner != null), "null adorners list or adorner");

            int index = 0;

            if (adorners.Count > 0)
            {
                for (index = adorners.Count; index > 0; index--)
                {
                    if (adorners[index - 1].AnnotationComponent.ZOrder <= adorner.AnnotationComponent.ZOrder)
                    {
                        break;
                    }
                }
            }

            adorners.Insert(index, adorner);
        }
        // Token: 0x06007C79 RID: 31865 RVA: 0x0023013C File Offset: 0x0022E33C
        private static int GetNextZOrder(AdornerLayer adornerLayer, int level)
        {
            Invariant.Assert(adornerLayer != null, "null adornerLayer");
            int num           = 0;
            int childrenCount = VisualTreeHelper.GetChildrenCount(adornerLayer);

            if (childrenCount == 0)
            {
                return(num);
            }
            for (int i = 0; i < childrenCount; i++)
            {
                DependencyObject  child             = VisualTreeHelper.GetChild(adornerLayer, i);
                AnnotationAdorner annotationAdorner = child as AnnotationAdorner;
                if (annotationAdorner != null && AdornerPresentationContext.GetComponentLevel(annotationAdorner.AnnotationComponent) == level && annotationAdorner.AnnotationComponent.ZOrder >= num)
                {
                    num = annotationAdorner.AnnotationComponent.ZOrder + 1;
                }
            }
            return(num);
        }
Exemple #18
0
        /// <summary>
        /// Create an initialized instance of an AdornerPresentationContext. Set the presentation context of the
        /// component wrapped in the adorner
        /// </summary>
        /// <param name="adornerLayer">AdornerLayer this presentation context is on, must not be null</param>
        /// <param name="adorner">AnnotationAdorner that wraps the annotation component.  Will be null in case of creating enclosing context</param>
        private AdornerPresentationContext(AdornerLayer adornerLayer, AnnotationAdorner adorner)
        {
            if (adornerLayer == null)
            {
                throw new ArgumentNullException("adornerLayer");
            }

            _adornerLayer = adornerLayer;
            if (adorner != null)
            {
                if (adorner.AnnotationComponent == null)
                {
                    throw new ArgumentNullException("annotation component");
                }
                if (adorner.AnnotationComponent.PresentationContext != null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.ComponentAlreadyInPresentationContext, adorner.AnnotationComponent));
                }
                _annotationAdorner = adorner;
            }
        }
        // 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);
        }
Exemple #20
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);
        }
Exemple #21
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;
            }
        }
        // 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> 
        /// Inserts an adorner after the last adorner with ZOrder less or equal of the input one
        /// </summary> 
        /// <param name="adorners">adorners list</param> 
        /// <param name="adorner">the new adorner</param>
        /// <remarks>In most cases the AnnotationAdorners are already orderd so we expect that the new one 
        /// will be added at the end of the list. That is why we start scaning from the end.</remarks>
        private void AddAdorner(List<AnnotationAdorner> adorners, AnnotationAdorner adorner)
        {
            Debug.Assert((adorners != null) && (adorner != null), "null adorners list or adorner"); 

            int index = 0; 
            if (adorners.Count > 0) 
            {
                for (index = adorners.Count; index > 0; index--) 
                {
                    if (adorners[index-1].AnnotationComponent.ZOrder <= adorner.AnnotationComponent.ZOrder)
                        break;
                } 
            }
 
            adorners.Insert(index, adorner); 
        }
Exemple #24
0
        /// <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();
        }