Beispiel #1
0
        private void InnerSelect(VirtualSnapshotPoint anchorPoint, VirtualSnapshotPoint activePoint)
        {
            bool isEmpty = this.IsEmpty;

            this.ActivationTracksFocus = true;
            this._anchorPoint          = anchorPoint;
            this._activePoint          = activePoint;
            VirtualSnapshotPoint bufferPosition1 = this._anchorPoint;
            VirtualSnapshotPoint bufferPosition2 = this._activePoint;

            if (this._anchorPoint > this._activePoint)
            {
                bufferPosition1 = this._activePoint;
                bufferPosition2 = this._anchorPoint;
            }
            if (this.Mode == TextSelectionMode.Box)
            {
                IWpfTextViewLine containingBufferPosition1 = this._wpfTextView.GetTextViewLineContainingBufferPosition(bufferPosition1.Position);
                IWpfTextViewLine containingBufferPosition2 = this._wpfTextView.GetTextViewLineContainingBufferPosition(bufferPosition2.Position);
                TextBounds       extendedCharacterBounds   = containingBufferPosition1.GetExtendedCharacterBounds(bufferPosition1);
                this._leftX             = extendedCharacterBounds.Leading;
                extendedCharacterBounds = containingBufferPosition2.GetExtendedCharacterBounds(bufferPosition2);
                this._rightX            = extendedCharacterBounds.Leading;
                if (this._rightX < this._leftX)
                {
                    double leftX = this._leftX;
                    this._leftX  = this._rightX;
                    this._rightX = leftX;
                }
            }
            //TODO: this.RaiseChangedEvent(isEmpty, this.IsEmpty, true);
        }
Beispiel #2
0
        public static Rect?GetViewSpanRect(IWpfTextView wpfTextView, SnapshotSpan span)
        {
            var nullable = new Rect?();

            if (span.Length > 0)
            {
                double num1   = double.MaxValue;
                double num2   = double.MaxValue;
                double val1_1 = double.MinValue;
                double val1_2 = double.MinValue;
                foreach (TextBounds textBounds in wpfTextView.TextViewLines.GetNormalizedTextBounds(span))
                {
                    num1   = Math.Min(num1, textBounds.Left);
                    num2   = Math.Min(num2, textBounds.TextTop);
                    val1_1 = Math.Max(val1_1, textBounds.Right);
                    val1_2 = Math.Max(val1_2, textBounds.TextBottom + 1.0);
                }
                IWpfTextViewLine containingBufferPosition = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(span.Start);
                if (containingBufferPosition != null)
                {
                    TextBounds extendedCharacterBounds = containingBufferPosition.GetExtendedCharacterBounds(span.Start);
                    if (extendedCharacterBounds.Left < val1_1 && extendedCharacterBounds.Left >= wpfTextView.ViewportLeft && extendedCharacterBounds.Left < wpfTextView.ViewportRight)
                    {
                        num1 = extendedCharacterBounds.Left;
                    }
                }
                ITextViewLine textViewLine = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(span.End);
                if (textViewLine != null && textViewLine.Start == span.End)
                {
                    val1_2 = Math.Max(val1_2, textViewLine.TextBottom + 1.0);
                }
                if (num1 < val1_1)
                {
                    nullable = new Rect(num1, num2, val1_1 - num1, val1_2 - num2);
                }
            }
            else
            {
                ITextViewLine textViewLine = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(span.Start);
                if (textViewLine != null)
                {
                    TextBounds characterBounds = textViewLine.GetCharacterBounds(span.Start);
                    nullable = new Rect(characterBounds.Left, characterBounds.TextTop, 0.0, characterBounds.TextHeight + 1.0);
                }
            }
            if (!nullable.HasValue || nullable.Value.IsEmpty)
            {
                return(null);
            }
            Rect rect1 = new Rect(wpfTextView.ViewportLeft, wpfTextView.ViewportTop, wpfTextView.ViewportWidth, wpfTextView.ViewportHeight);
            Rect rect2 = nullable.Value;

            rect2.Intersect(rect1);
            var point1 = GetScreenPointFromTextXY(wpfTextView, rect2.Left, rect2.Top);
            var point2 = GetScreenPointFromTextXY(wpfTextView, rect2.Right, rect2.Bottom);

            return(new Rect(point1, point2));
        }