Exemple #1
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: 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: 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);
 }
Exemple #5
0
        /// <summary>
        ///     Determines if the passed in object is equal to this object.
        ///     Two AdornerPresentationContexts will be equal if they both have the same adorner layer.
        /// </summary>
        /// <param name="o">The object to compare with.</param>
        /// <returns>True if the objects are equal. False otherwise.</returns>
        public override bool Equals(object o)
        {
            AdornerPresentationContext p = o as AdornerPresentationContext;

            if (p != null)
            {
                return(p._adornerLayer == this._adornerLayer);
            }

            return(false);
        }
        // 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));
            }
        }
        // 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));
        }
        // 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 #10
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;
            }
        }
Exemple #11
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);
        }
Exemple #12
0
        // Token: 0x06007CE0 RID: 31968 RVA: 0x00231F28 File Offset: 0x00230128
        private void RegisterAnchor()
        {
            TextAnchor textAnchor = this._attachedAnnotation.AttachedAnchor as TextAnchor;

            if (textAnchor == null)
            {
                throw new ArgumentException(SR.Get("InvalidAttachedAnchor"));
            }
            ITextContainer textContainer = textAnchor.Start.TextContainer;

            this.HighlightAnchor.AddAttachedAnnotation(this._attachedAnnotation);
            this.UpdateGeometry();
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.AnnotatedElement);

            if (adornerLayer == null)
            {
                throw new InvalidOperationException(SR.Get("NoPresentationContextForGivenElement", new object[]
                {
                    this.AnnotatedElement
                }));
            }
            AdornerPresentationContext.HostComponent(adornerLayer, this, this.AnnotatedElement, false);
            this._selection = textContainer.TextSelection;
            if (this._selection != null)
            {
                this._uiParent = (PathNode.GetParent(textContainer.Parent) as UIElement);
                this.RegisterComponent();
                if (this._uiParent != null)
                {
                    this._uiParent.GotKeyboardFocus  += this.OnContainerGotFocus;
                    this._uiParent.LostKeyboardFocus += this.OnContainerLostFocus;
                    if (this.HighlightAnchor.IsSelected(this._selection))
                    {
                        this.SetSelected(true);
                    }
                }
            }
        }
        // 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);
        }
        // Token: 0x06007C6F RID: 31855 RVA: 0x0022FEEC File Offset: 0x0022E0EC
        public override bool Equals(object o)
        {
            AdornerPresentationContext adornerPresentationContext = o as AdornerPresentationContext;

            return(adornerPresentationContext != null && adornerPresentationContext._adornerLayer == this._adornerLayer);
        }