Esempio n. 1
0
        //-------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //-------------------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Given a ContentElement searches for associated IContentHost, if one exists.
        /// </summary>
        /// <param name="contentElement">Content element</param>
        /// <returns>Associated IContentHost with ContentElement.</returns>
        internal static IContentHost FindContentHost(ContentElement contentElement)
        {
            IContentHost     ich = null;
            DependencyObject parent;
            TextContainer    textContainer;

            if (contentElement == null)
            {
                return(null);
            }

            // If the ContentElement is a TextElement, retrieve IContentHost form the owner
            // of TextContainer.
            if (contentElement is TextElement)
            {
                textContainer = ((TextElement)contentElement).TextContainer;
                parent        = textContainer.Parent;
                if (parent is IContentHost) // TextBlock
                {
                    ich = (IContentHost)parent;
                }
                else if (parent is FlowDocument) // Viewers
                {
                    ich = GetICHFromFlowDocument((TextElement)contentElement, (FlowDocument)parent);
                }
                else if (textContainer.TextView != null && textContainer.TextView.RenderScope is IContentHost)
                {
                    // TextBlock hosted in ControlTemplate
                    ich = (IContentHost)textContainer.TextView.RenderScope;
                }
            }
            // else; cannot retrive IContentHost

            return(ich);
        }
Esempio n. 2
0
        internal void AddHighPriority(IContentHost host)
        {
            lock (_sync)
            {
                if (_manager == null)
                {
                    throw new ObjectDisposedException("this");
                }
                if (host == null)
                {
                    throw new ArgumentNullException();
                }
                if (_nullReferences.Count > 0)
                {
                    WeakReference wr = _nullReferences.Pop();
                    wr.Target = host;
                    _highPriorityItems.Add(wr);
                }
                else
                {
                    _highPriorityItems.Add(new WeakReference(host));
                }

                if (_created)
                {
                    host.LoadContent(this, _manager);
                }

                ProcessDelayed();
            }
        }
Esempio n. 3
0
        public override TextPointer GetPositionFromPoint(Point point, bool snapToText)
        {
            TextRange contentRange = null;


            // Using the IContentHost interface we can quickly narrow down our
            // range to a run within the text block
            IContentHost contentHost = this.ContentHost;

            if (contentHost != null)
            {
                TextElement te = contentHost.InputHitTest(point) as TextElement;
                if (te != null)
                {
                    contentRange = new TextRange(te.ContentStart, te.ContentEnd);
                }
            }

            if (contentRange == null)
            {
                contentRange = new TextRange(Start, End);
            }

            TextPointer result = GetPositionFromPoint(point, contentRange, snapToText);

            Assert.Implies(snapToText, result != null);

            return(result);
        }
Esempio n. 4
0
 /// <summary>
 ///   Unregister an <see cref = "IContentHost" /> instance with this content manager. NOTE: Instances are stored by weak reference and do not need to be manually removed (see remarks)
 /// </summary>
 /// <remarks>
 ///   <para>Instances are stored by weak reference, so this method should only be called when removing the object early is desired.</para>
 ///   <para>Instances will not be kept alive when added, and do not need to be removed to make sure they are garbage collected</para>
 /// </remarks>
 /// <param name = "host"></param>
 public void Remove(IContentHost host)
 {
     if (Monitor.TryEnter(_sync))
     {
         try
         {
             foreach (WeakReference wr in _items.Where(wr => wr.Target == host))
             {
                 if (_items.Count > 1)
                 {
                     wr.Target = _items[_items.Count - 1].Target;
                     _items[_items.Count - 1].Target = null;
                 }
                 else
                 {
                     wr.Target = null;
                 }
                 break;
             }
             _nullReferences.Push(_items[_items.Count - 1]);
             _items.RemoveAt(_items.Count - 1);
         }
         finally
         {
             Monitor.Exit(_sync);
         }
     }
     else
     {
         lock (_delayedRemoveList)
             _delayedRemoveList.Add(host);
     }
 }
        // Token: 0x06006F07 RID: 28423 RVA: 0x001FE3FC File Offset: 0x001FC5FC
        private static IContentHost GetICHFromFlowDocument(TextElement contentElement, FlowDocument flowDocument)
        {
            IContentHost result   = null;
            ITextView    textView = flowDocument.StructuralCache.TextContainer.TextView;

            if (textView != null)
            {
                if (textView.RenderScope is FlowDocumentView)
                {
                    if (VisualTreeHelper.GetChildrenCount(textView.RenderScope) > 0)
                    {
                        result = (VisualTreeHelper.GetChild(textView.RenderScope, 0) as IContentHost);
                    }
                }
                else if (textView.RenderScope is FrameworkElement)
                {
                    List <DocumentPageView> list = new List <DocumentPageView>();
                    ContentHostHelper.FindDocumentPageViews(textView.RenderScope, list);
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].DocumentPage is FlowDocumentPage)
                        {
                            textView = (ITextView)((IServiceProvider)list[i].DocumentPage).GetService(typeof(ITextView));
                            if (textView != null && textView.IsValid && (textView.Contains(contentElement.ContentStart) || textView.Contains(contentElement.ContentEnd)))
                            {
                                result = (list[i].DocumentPage.Visual as IContentHost);
                            }
                        }
                    }
                }
            }
            return(result);
        }
        // Token: 0x06006F06 RID: 28422 RVA: 0x001FE374 File Offset: 0x001FC574
        internal static IContentHost FindContentHost(ContentElement contentElement)
        {
            IContentHost result = null;

            if (contentElement == null)
            {
                return(null);
            }
            if (contentElement is TextElement)
            {
                TextContainer    textContainer = ((TextElement)contentElement).TextContainer;
                DependencyObject parent        = textContainer.Parent;
                if (parent is IContentHost)
                {
                    result = (IContentHost)parent;
                }
                else if (parent is FlowDocument)
                {
                    result = ContentHostHelper.GetICHFromFlowDocument((TextElement)contentElement, (FlowDocument)parent);
                }
                else if (textContainer.TextView != null && textContainer.TextView.RenderScope is IContentHost)
                {
                    result = (IContentHost)textContainer.TextView.RenderScope;
                }
            }
            return(result);
        }
Esempio n. 7
0
        private void SerializeLinkTargetForElement(IInputElement element, IContentHost contentHost, Visual root)
        {
            if (element is FrameworkElement)
            {
                FrameworkElement fe = (FrameworkElement)element;
                string           id = fe.Name;
                if (!String.IsNullOrEmpty(id))
                {
                    // No need to add overlapping path element for named FE element.
                    AddLinkTarget(id);
                }
            }
            else if (element is FrameworkContentElement && contentHost != null)
            {
                FrameworkContentElement fce = (FrameworkContentElement)element;
                string id  = fce.Name;
                Uri    uri = null;

                if (element is Hyperlink)
                {
                    uri = ((Hyperlink)element).NavigateUri;
                }

                if (!String.IsNullOrEmpty(id) || uri != null)
                {
                    Transform transform     = Transform.Identity;
                    Visual    contentVisual = contentHost as Visual;
                    if (contentVisual != null && root != null && root.IsAncestorOf(contentVisual))
                    {
                        GeneralTransform t = contentVisual.TransformToAncestor(root);

                        if (t is Transform)
                        {
                            transform = (Transform)t;
                        }
                    }

                    Transform rootTransform = root.VisualTransform;
                    if (rootTransform != null)
                    {
                        transform = new MatrixTransform(Matrix.Multiply(transform.Value, rootTransform.Value));
                    }
                    transform = new MatrixTransform(
                        Matrix.Multiply(transform.Value,
                                        new TranslateTransform(root.VisualOffset.X, root.VisualOffset.Y).Value
                                        )
                        );


                    PathGeometry geometry = new PathGeometry();
                    System.Collections.ObjectModel.ReadOnlyCollection <Rect> rectangles = contentHost.GetRectangles(fce);
                    foreach (Rect rect in rectangles)
                    {
                        geometry.AddGeometry(new RectangleGeometry(rect, 0, 0, transform));
                    }
                    SerializeHyperlink(geometry, id, uri);
                }
            }
        }
Esempio n. 8
0
        // Token: 0x060068F9 RID: 26873 RVA: 0x001D9C1C File Offset: 0x001D7E1C
        void IContentHost.OnChildDesiredSizeChanged(UIElement child)
        {
            IContentHost contentHost = this._owner.Target as IContentHost;

            if (contentHost != null)
            {
                contentHost.OnChildDesiredSizeChanged(child);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// <see cref="IContentHost.OnChildDesiredSizeChanged"/>
        /// </summary>
        void IContentHost.OnChildDesiredSizeChanged(UIElement child)
        {
            IContentHost host = _owner.Target as IContentHost;

            if (host != null)
            {
                host.OnChildDesiredSizeChanged(child);
            }
        }
Esempio n. 10
0
        //-------------------------------------------------------------------
        //
        //  IContentHost Members
        //
        //-------------------------------------------------------------------

        #region IContentHost Members

        /// <summary>
        /// <see cref="IContentHost.InputHitTest"/>
        /// </summary>
        IInputElement IContentHost.InputHitTest(Point point)
        {
            IContentHost host = _owner.Target as IContentHost;

            if (host != null)
            {
                return(host.InputHitTest(point));
            }
            return(null);
        }
Esempio n. 11
0
        /// <summary>
        /// <see cref="IContentHost.GetRectangles"/>
        /// </summary>
        ReadOnlyCollection <Rect> IContentHost.GetRectangles(ContentElement child)
        {
            IContentHost host = _owner.Target as IContentHost;

            if (host != null)
            {
                return(host.GetRectangles(child));
            }
            return(new ReadOnlyCollection <Rect>(new List <Rect>(0)));
        }
Esempio n. 12
0
 /// <summary>
 ///   Register an <see cref = "IContentHost" /> instance with this content manager
 /// </summary>
 /// <param name = "host"></param>
 public void PreLoad(IContentHost host)
 {
     if (!LoadingComplete && !LoadingInProgress)
     {
         ContentToLoad.Add(host);
     }
     else
     {
         Content.Add(host);
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Gets a set of rectangles suitable for highlighting a TextRange
        /// </summary>
        /// <param name="range">Range to obtain highlight rects for</param>
        /// <param name="contentHost">Optional IContent host used to performance</param>
        /// <returns>A set of rectangles suitable for highlighting a TextRange</returns>
        public static IEnumerable <Rect> GetHighlightRectanglesWithContentHost(
            TextRange range,
            Func <TextRange, IEnumerable <Rect> > getRectanglesCore,
            IContentHost contentHost
            )
        {
            if (getRectanglesCore == null)
            {
                throw new ArgumentNullException("getRectanglesCore");
            }

            IEnumerable <Rect> result;

            if (contentHost == null)
            {
                result = getRectanglesCore(range);
            }
            else
            {
                result = new Rect[] { };
                const LogicalDirection fwd     = LogicalDirection.Forward;
                TextPointer            current = range.Start;

                TextElement te = current.GetAdjacentElement(fwd) as TextElement;
                while (te != null && te.ContentEnd.CompareTo(range.End) >= 0)
                {
                    if (current.CompareTo(te.ElementStart) < 0)
                    {
                        TextRange          leadingRange = new TextRange(current, te.ElementStart);
                        IEnumerable <Rect> leadingRects = getRectanglesCore(leadingRange);
                        result  = result.Concat(leadingRects);
                        current = te.ElementStart;
                    }

                    if (contentHost != null)
                    {
                        result = result.Concat(contentHost.GetRectangles(te));
                    }

                    current = te.ElementEnd;
                    te      = current.GetAdjacentElement(fwd) as TextElement;
                }

                TextRange          trailingRange = new TextRange(current, range.End);
                IEnumerable <Rect> trailingRects = getRectanglesCore(trailingRange);
                result = result.Concat(trailingRects);
            }

            return(result);
        }
Esempio n. 14
0
        //-------------------------------------------------------------------
        //
        //  Private Methods
        //
        //-------------------------------------------------------------------

        #region Private Methods

        /// <summary>
        /// Given a ContentElement within FlowDocument searches for associated IContentHost.
        /// </summary>
        /// <param name="contentElement">Content element</param>
        /// <param name="flowDocument">FlowDocument hosting ContentElement.</param>
        /// <returns>Associated IContentHost with ContentElement.</returns>
        private static IContentHost GetICHFromFlowDocument(TextElement contentElement, FlowDocument flowDocument)
        {
            IContentHost            ich = null;
            List <DocumentPageView> pageViews;
            ITextView textView = flowDocument.StructuralCache.TextContainer.TextView;

            if (textView != null)
            {
                // If FlowDocument is hosted by FlowDocumentScrollViewer, the RenderScope
                // is FlowDocumentView object which hosts PageVisual representing the content.
                // This PageVisual is also IContentHost for the entire content of DocumentPage.
                if (textView.RenderScope is FlowDocumentView) // FlowDocumentScrollViewer
                {
                    if (VisualTreeHelper.GetChildrenCount(textView.RenderScope) > 0)
                    {
                        ich = VisualTreeHelper.GetChild(textView.RenderScope, 0) as IContentHost;
                    }
                }
                // Our best guess is that FlowDocument is hosted by DocumentViewerBase.
                // In this case search the style for all DocumentPageViews.
                // Having collection of DocumentPageViews, find for the one which hosts TextElement.
                else if (textView.RenderScope is FrameworkElement)
                {
                    pageViews = new List <DocumentPageView>();
                    FindDocumentPageViews(textView.RenderScope, pageViews);
                    for (int i = 0; i < pageViews.Count; i++)
                    {
                        if (pageViews[i].DocumentPage is FlowDocumentPage)
                        {
                            textView = (ITextView)((IServiceProvider)pageViews[i].DocumentPage).GetService(typeof(ITextView));
                            if (textView != null && textView.IsValid)
                            {
                                // Check if the page contains ContentElement. Check Start and End
                                // position, which will give desired results in most of the cases.
                                // Having hyperlink spanning more than 2 pages is not very common,
                                // and this code will not work with it correctly.
                                if (textView.Contains(contentElement.ContentStart) ||
                                    textView.Contains(contentElement.ContentEnd))
                                {
                                    ich = pageViews[i].DocumentPage.Visual as IContentHost;
                                }
                            }
                        }
                    }
                }
            }

            return(ich);
        }
Esempio n. 15
0
        internal void SerializeLinksInDocumentPage(DocumentPage page)
        {
            IContentHost contentHost = page as IContentHost;
            Visual       root        = page.Visual;

            if (contentHost != null)
            {
                SerializeLinksForIContentHost(contentHost, root);
            }
            else
            {
                // do logical tree
                SerializeLinksInLogicalTree(root, null, root);
            }
        }
Esempio n. 16
0
        internal static IEnumerable <Rect> GetHighlightRects(TextRange range, IContentHost contentHost)
        {
#if USE_APPROXIMATE_HIGHLIGHT_RECT
            return(TextPointerOperations.GetHighlightRectanglesWithContentHost(
                       range,
                       TextPointerOperations.GetApproximateHighlightRectangles,
                       contentHost
                       ));
#else
            return(TextPointerOperations.GetHighlightRectanglesWithContentHost(
                       range,
                       TextPointerOperations.GetHighlightRectangles,
                       contentHost
                       ));
#endif
        }
Esempio n. 17
0
        /// <summary>
        ///   Register an <see cref = "IContentHost" /> instance with this content manager
        /// </summary>
        /// <param name = "host"></param>
        public void Add(IContentHost host)
        {
            if (Monitor.TryEnter(_sync))
            {
                try
                {
                    if (_manager == null)
                    {
                        throw new ObjectDisposedException("this");
                    }
                    if (host == null)
                    {
                        throw new ArgumentNullException();
                    }
                    if (_nullReferences.Count > 0)
                    {
                        WeakReference wr = _nullReferences.Pop();
                        wr.Target = host;
                        _items.Add(wr);
                    }
                    else
                    {
                        _items.Add(new WeakReference(host));
                    }

                    if (_created)
                    {
                        host.LoadContent(this, _manager);
                    }
                }
                finally
                {
                    Monitor.Exit(_sync);
                }
            }
            else
            {
                lock (_delayedAddList)
                    _delayedAddList.Add(host);
            }
        }
Esempio n. 18
0
        internal void SerializeLinksInVisual(Visual visual)
        {
            // Checks and sees if this element has an ID or is a Hyperlink
            if (visual is IInputElement)
            {
                SerializeLinkTargetForElement((IInputElement)visual, null, visual);
            }

            IContentHost contentHost = visual as IContentHost;

            if (contentHost != null)
            {
                //recursively find links in its elements
                SerializeLinksForIContentHost(contentHost, visual);
            }
            else
            {
                // do logical tree
                SerializeLinksInLogicalTree(visual, null, visual);
            }
        }
Esempio n. 19
0
        private void SerializeLinksForIContentHost(IContentHost contentHost, Visual root)
        {
            System.Collections.Generic.IEnumerator <IInputElement> enumerator = contentHost.HostedElements;
            while (enumerator.MoveNext())
            {
                IInputElement element = enumerator.Current;

                // Checks and sees if this element has an ID or is a Hyperlink
                SerializeLinkTargetForElement(element, contentHost, root);

                if (element is IContentHost)
                {
                    //recursively find links in its elements
                    SerializeLinksForIContentHost((IContentHost)element, root);
                }
                else if (element is FrameworkElement)
                {
                    // do we do this for FrameworkContentElement?  We could...  But do we want to?
                    // do logical tree
                    SerializeLinksInLogicalTree((DependencyObject)element, contentHost, root);
                }
            }
        }
Esempio n. 20
0
        private void SerializeLinksInLogicalTree(DependencyObject dependencyObject, IContentHost contentHost, Visual root)
        {
            System.Collections.IEnumerable enumerable = LogicalTreeHelper.GetChildren(dependencyObject);
            foreach (object element in enumerable)
            {
                // Checks and sees if this element has an ID or is a Hyperlink
                if (element is IInputElement)
                {
                    SerializeLinkTargetForElement((IInputElement)element, contentHost, root);
                }

                if (element is IContentHost)
                {
                    //recursively find links in its elements
                    SerializeLinksForIContentHost((IContentHost)element, root);
                }
                else if (element is FrameworkElement)
                {
                    // do we do this for FrameworkContentElement?  We could...  But do we want to?
                    // do logical tree
                    SerializeLinksInLogicalTree((DependencyObject)element, contentHost, root);
                }
            }
        }
Esempio n. 21
0
            public FocusVisualAdorner(ContentElement adornedElement, UIElement adornedElementParent, IContentHost contentHostParent, Style focusVisualStyle)
                : base(adornedElementParent)
            {
                Debug.Assert(adornedElement != null, "adornedElement should not be null");
                Debug.Assert(adornedElementParent != null, "adornedElementParent should not be null");
                Debug.Assert(contentHostParent != null, "contentHostParent should not be null");
                Debug.Assert(contentHostParent is Visual, "contentHostParent should be Visual");
                Debug.Assert(focusVisualStyle != null, "focusVisual should not be null");

                _contentHostParent = contentHostParent;
                _adornedContentElement = adornedElement;
                _focusVisualStyle = focusVisualStyle;

                Canvas canvas = new Canvas();
                _canvasChildren = canvas.Children;
                _adorderChild = canvas;
                AddVisualChild(_adorderChild);

                IsClipEnabled = true;
                IsHitTestVisible = false;
                IsEnabled = false;
            }
 /// <summary>
 /// New instance.
 /// </summary>
 public IContentHostRunReader(IContentHost host)
 {
     this.contentHost = host;
 }
Esempio n. 23
0
 public ContentCollection(IContentHost <T> host)
 {
     _host = host;
 }
Esempio n. 24
0
         //only one will be returned, whichever found first
        internal void GetUIParentOrICH(out UIElement uiParent, out IContentHost ich)
        {
            ich = null;
            uiParent = null;

            for(Visual v = VisualTreeHelper.GetParent(this) as Visual; v != null; v = VisualTreeHelper.GetParent(v) as Visual)
            {
                ich = v as IContentHost;
                if (ich != null) break;

                if(v.CheckFlagsAnd(VisualFlags.IsUIElement))
                {
                    uiParent = (UIElement)v;
                    break;
                }
            }
        }
Esempio n. 25
0
 /// <summary>
 ///   Register an <see cref = "IContentHost" /> instance with this content manager
 /// </summary>
 /// <param name = "host"></param>
 public void PreLoad(IContentHost host)
 {
     if (!LoadingComplete && !LoadingInProgress)
     {
         ContentToLoad.Add(host);
     }
     else
     {
         Content.Add(host);
     }
 }
Esempio n. 26
0
File: Content.cs Progetto: rc183/igf
        /// <summary>
        ///   Register an <see cref = "IContentHost" /> instance with this content manager
        /// </summary>
        /// <param name = "host"></param>
        public void Add(IContentHost host)
        {
            if (Monitor.TryEnter(_sync))
            {
                try
                {
                    if (_manager == null)
                        throw new ObjectDisposedException("this");
                    if (host == null)
                        throw new ArgumentNullException();
                    if (_nullReferences.Count > 0)
                    {
                        WeakReference wr = _nullReferences.Pop();
                        wr.Target = host;
                        _items.Add(wr);
                    }
                    else
                        _items.Add(new WeakReference(host));

                    if (_created)
                        host.LoadContent(this, _manager);
                }
                finally
                {
                    Monitor.Exit(_sync);
                }
            }
            else
            {
                lock (_delayedAddList)
                    _delayedAddList.Add(host);
            }
        }
Esempio n. 27
0
        private static UIElement GetParentUIElementFromContentElement(ContentElement ce, ref IContentHost ichParent)
        {
            if (ce == null)
                return null;

            IContentHost ich = MS.Internal.Documents.ContentHostHelper.FindContentHost(ce);
            if (ichParent == null)
                ichParent = ich;

            DependencyObject parent =  ich as DependencyObject;
            if(parent != null)
            {
                // Case 1: UIElement
                // return the element
                UIElement eParent = parent as UIElement;
                if(eParent != null)
                    return eParent;

                // Case 2: Visual
                // Walk up the visual tree until we find UIElement
                Visual visualParent = parent as Visual;
                while (visualParent != null)
                {
                    visualParent = VisualTreeHelper.GetParent(visualParent) as Visual;
                    UIElement uielement = visualParent as UIElement;
                    if (uielement != null)
                        return uielement;
                }

                // Case 3: ContentElement
                ContentElement ceParent = parent as ContentElement;
                if(ceParent != null)
                    return GetParentUIElementFromContentElement(ceParent, ref ichParent);
            }

            return null;
        }
Esempio n. 28
0
File: Content.cs Progetto: rc183/igf
 /// <summary>
 ///   Unregister an <see cref = "IContentHost" /> instance with this content manager. NOTE: Instances are stored by weak reference and do not need to be manually removed (see remarks)
 /// </summary>
 /// <remarks>
 ///   <para>Instances are stored by weak reference, so this method should only be called when removing the object early is desired.</para>
 ///   <para>Instances will not be kept alive when added, and do not need to be removed to make sure they are garbage collected</para>
 /// </remarks>
 /// <param name = "host"></param>
 public void Remove(IContentHost host)
 {
     if (Monitor.TryEnter(_sync))
     {
         try
         {
             foreach (WeakReference wr in _items.Where(wr => wr.Target == host))
             {
                 if (_items.Count > 1)
                 {
                     wr.Target = _items[_items.Count - 1].Target;
                     _items[_items.Count - 1].Target = null;
                 }
                 else
                     wr.Target = null;
                 break;
             }
             _nullReferences.Push(_items[_items.Count - 1]);
             _items.RemoveAt(_items.Count - 1);
         }
         finally
         {
             Monitor.Exit(_sync);
         }
     }
     else
     {
         lock (_delayedRemoveList)
             _delayedRemoveList.Add(host);
     }
 }
Esempio n. 29
0
File: Content.cs Progetto: rc183/igf
        internal void AddHighPriority(IContentHost host)
        {
            lock (_sync)
            {
                if (_manager == null)
                    throw new ObjectDisposedException("this");
                if (host == null)
                    throw new ArgumentNullException();
                if (_nullReferences.Count > 0)
                {
                    WeakReference wr = _nullReferences.Pop();
                    wr.Target = host;
                    _highPriorityItems.Add(wr);
                }
                else
                    _highPriorityItems.Add(new WeakReference(host));

                if (_created)
                    host.LoadContent(this, _manager);

                ProcessDelayed();
            }
        }