コード例 #1
0
 /// <summary>
 /// New instance
 /// </summary>
 /// <param name="handler">Handler for this highlight adorner.</param>
 /// <param name="bodyHighlight">The corresponding highlight adorner in the body of the text.</param>
 public ScrollBarHighlightAdorner(ScrollBarHighlightHandler handler, HighlightAdorner bodyHighlight)
     : base(handler.ScrollViewer)
 {
     this.bodyHighlight = bodyHighlight;
     this.handler       = handler;
     IsHitTestVisible   = false;
 }
コード例 #2
0
 /// <summary>
 /// New instance
 /// </summary>
 public Highlight(int start, int end, HighlightAdorner adorner, System.Windows.Documents.Run run, int runStartIndex)
 {
     this.adorner       = adorner;
     this.s             = start;
     this.e             = end;
     this.run           = run;
     this.runStartIndex = runStartIndex;
 }
コード例 #3
0
 /// <summary>
 /// Removes an adorner when it is no longer used.
 /// </summary>
 /// <param name="adorner"></param>
 public virtual void RemoveAdorner(HighlightAdorner adorner)
 {
     if (adorner != null && AdornerLayer != null)
     {
         AdornerLayer.Remove(adorner);
         adorner.Unregister();
         adorner.RenderImpossible -= new EventHandler(adorner_RenderImpossible);
     }
 }
コード例 #4
0
 /// <summary>
 /// Creates an adorner of type ScrollBarHighlightAdorner.
 /// </summary>
 /// <param name="highlightAdorner"></param>
 /// <returns></returns>
 public ScrollBarHighlightAdorner CreateScrollBarHighlightAdorner(HighlightAdorner highlightAdorner)
 {
     if (!IsUsable)
     {
         return(null);
     }
     else
     {
         return(new ScrollBarHighlightAdorner(this, highlightAdorner));
     }
 }
コード例 #5
0
 /// <summary>
 /// Whether the Y coordinate in the argument is visible in the scroll viewer's viewport.
 /// </summary>
 public bool IsHighlightInViewPort(HighlightAdorner bodyHighlight)
 {
     if (scrollViewerIsChild)
     {
         return(bodyHighlight.IsInViewport);
     }
     else
     {
         return(bodyHighlight.Y >= scrollViewer.ContentVerticalOffset && bodyHighlight.Y <= scrollViewer.ContentVerticalOffset + scrollViewer.ViewportHeight);
     }
 }
コード例 #6
0
        /// <summary>
        /// Gets the position of <c>bodyHighlight</c>.
        /// </summary>
        public Rect GetAdornerPosition(HighlightAdorner bodyHighlight)
        {
            double y = bodyHighlight.Y + (scrollViewerIsChild ? scrollViewer.VerticalOffset : 0);

            return(new Rect(scrollViewer.ActualWidth - track.ActualWidth, scrollButtonSize + ((y / scrollViewer.ExtentHeight) * track.ActualHeight), track.ActualWidth, 3));
        }
コード例 #7
0
 /// <summary>
 /// New instance.
 /// </summary>
 /// <param name="start">Where the highlight starts in <c>run</c></param>
 /// <param name="end">Where the highlight ends in <c>run</c></param>
 /// <param name="adorner">Adorner instance that will actually highlight</param>
 /// <param name="run">The Run where the highlight is</param>
 public TextBoxHighlight(int start, int end, HighlightAdorner adorner, System.Windows.Documents.Run run)
     : base(start, end, adorner, run)
 {
 }
コード例 #8
0
 /// <summary>
 /// New instance.
 /// </summary>
 /// <param name="start">Where the highlight starts in <c>run</c></param>
 /// <param name="end">Where the highlight ends in <c>run</c></param>
 /// <param name="adorner">Adorner instance that will actually highlight</param>
 /// <param name="run">The Run where the highlight is</param>
 public FlowDocumentScrollViewerHighlight(int start, int end, HighlightAdorner adorner, System.Windows.Documents.Run run)
     : base(start, end, adorner, run)
 {
 }
コード例 #9
0
 /// <summary>
 /// New instance, with Run relative to zero index (ie no other Runs in container).
 /// </summary>
 public Highlight(int start, int end, HighlightAdorner adorner, System.Windows.Documents.Run run) : this(start, end, adorner, run, 0)
 {
 }
コード例 #10
0
 /// <summary>
 /// New instance.
 /// </summary>
 /// <param name="start">Where the highlight starts in <c>run</c></param>
 /// <param name="end">Where the highlight ends in <c>run</c></param>
 /// <param name="adorner">Adorner instance that will actually highlight</param>
 /// <param name="run">The Run where the highlight is</param>
 /// <param name="runStartIndex">The character index of the run in the RichTextBox's Document.</param>
 public RichTextBoxHighlight(int start, int end, HighlightAdorner adorner, System.Windows.Documents.Run run, int runStartIndex) : base(start, end, adorner, run)
 {
     this.runStartIndex = runStartIndex;
 }
コード例 #11
0
        /// <summary>
        /// Overrides should call RegisterHighlight to ensure proper registration of the Highlight.
        /// </summary>
        public virtual void AddHighlight(Run run, int index, int length)
        {
            HighlightAdorner adorner = new HighlightAdorner(uiElementToHighlight, run, index, length, scrollBarHighlightHandler.HorizontalScrollBarHeight, BodyHighlightAdornerBrush, BodyHighlightAdornerPen, BodyIterativeHighlightAdornerBrush, BodyIterativeHighlightAdornerPen);

            RegisterHighlight(new Highlight(index, index + length, adorner, run));
        }
コード例 #12
0
        // A common way to implement an adorner's rendering behavior is to override the OnRender
        // method, which is called by the layout system as part of a rendering pass.
        /// <summary>
        /// Paints the highlight.
        /// </summary>
        protected override void OnRender(DrawingContext drawingContext)
        {
            //// Some arbitrary drawing implements.


            /* this is a nice shortcut but it means we can't set yPos, which is used by scroll highlighter
             * int firstline = tb.GetFirstVisibleLineIndex();
             * if (firstline == -1) { OnRenderImpossible(); return; }
             * int lastline = tb.GetLastVisibleLineIndex();
             * if (lastline == -1) { OnRenderImpossible(); return; }
             * try
             * {
             *  int charline = tb.GetLineIndexFromCharacterIndex(start);
             *  if (charline == -1) { OnRenderImpossible(); return; }
             *  if (charline < firstline - 1 || charline > lastline + 1) return;
             * }
             * catch (ArgumentOutOfRangeException) { OnRenderImpossible(); return; }
             */
            //drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.AdornedElement.RenderSize.Width, this.AdornedElement.RenderSize.Height)));

            var leftRectangle  = tb.GetRectFromCharacterIndex(start);
            var rightRectangle = tb.GetRectFromCharacterIndex(start + length);

            if (Double.IsInfinity(leftRectangle.X))
            {
                OnRenderImpossible();
            }

            yPos = leftRectangle.Top;

            AdjustRectanglesToView(ref leftRectangle, ref rightRectangle, this.AdornedElement.RenderSize.Height - horizontalScrollBarHeight);
            //       AdjustRectanglesToView(ref leftRectangle, ref rightRectangle, AdornedElement.RenderSize.Height - SystemParameters.ScrollHeight);

            if (leftRectangle.Top > 1 && rightRectangle.Y > 1 && leftRectangle.Top < (AdornedElement.RenderSize.Height - horizontalScrollBarHeight) &&
                leftRectangle.Left > 1 && rightRectangle.Right > 1 && leftRectangle.Left < (AdornedElement.RenderSize.Width - horizontalScrollBarHeight) //assume vertical scrollbar is as wide as horiz scroll is high


                )
            {
                if (rightRectangle.Left > AdornedElement.RenderSize.Width - horizontalScrollBarHeight - 1)//if it ends to the right
                {
                    rightRectangle.X = AdornedElement.RenderSize.Width - horizontalScrollBarHeight - 1;
                }

                isInViewport = true;
                if (RoughlyTheSame(leftRectangle.Top, rightRectangle.Top))
                {
                    //notsplit over more than 1 line
                    var rect = new Rect(leftRectangle.TopLeft, rightRectangle.BottomRight);

                    rect.Inflate(1, 1);
                    drawingContext.DrawRectangle(renderBrush, null, rect);
                }
                else
                {
                    if (leftRectangle != Rect.Empty && rightRectangle != Rect.Empty)
                    {
                        //paint as 3 rects
                        //r1 is top line from word to end of line
                        //r2 is start of line to end of line, between first line and last line
                        //r3 is last line from start of line to end of word

                        //we need to figure out the X coords of the start of the line and end of the line
                        Rect[] points = FindStartEndOfVisualLineRects(start, leftRectangle);
                        HighlightAdorner.DrawMultiLine(drawingContext, renderBrush, renderPen, ref leftRectangle, ref rightRectangle, points);
                    }
                }
            }
            else
            {
                isInViewport = false;
            }
            //drawingContext.Pop();
        }