示例#1
0
        public void SetLine(HexViewLine line, double width)
        {
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }
            var newRect = new Rect(PEN_THICKNESS / 2, PEN_THICKNESS / 2, Math.Max(0, width - PEN_THICKNESS), Math.Max(0, line.TextHeight + HexFormattedLineImpl.DEFAULT_BOTTOM_SPACE - PEN_THICKNESS));

            if (geometry != null && newRect == geometryRect)
            {
                return;
            }
            geometryRect = newRect;
            if (geometryRect.Height == 0 || geometryRect.Width == 0)
            {
                geometry = null;
            }
            else
            {
                geometry = new RectangleGeometry(geometryRect);
                if (geometry.CanFreeze)
                {
                    geometry.Freeze();
                }
            }
            InvalidateVisual();
        }
 bool IsSelected(AdornmentTagInfo adornmentInfo, HexViewLine line)
 {
     if (line == null)
     {
         return(false);
     }
     if (wpfHexView.Selection.IsEmpty)
     {
         return(false);
     }
     if (adornmentInfo.HexTagSpan != null)
     {
         foreach (var span in wpfHexView.Selection.SelectedSpans)
         {
             if (span.Contains(adornmentInfo.BufferSpan))
             {
                 return(true);
             }
         }
     }
     else
     {
         foreach (var span in wpfHexView.Selection.GetSelectionOnHexViewLine(line))
         {
             if (span.Contains(adornmentInfo.HexTextTagSpan.Span))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 public static bool IsVisible(this HexViewLine line)
 {
     if (line is null)
     {
         throw new ArgumentNullException(nameof(line));
     }
     return(line.VisibilityState == VSTF.VisibilityState.FullyVisible || line.VisibilityState == VSTF.VisibilityState.PartiallyVisible);
 }
 public static bool IsFirstDocumentLine(this HexViewLine line)
 {
     if (line is null)
     {
         throw new ArgumentNullException(nameof(line));
     }
     return(line.BufferLine.LineNumber == 0);
 }
 public static bool IsLastDocumentLine(this HexViewLine line)
 {
     if (line is null)
     {
         throw new ArgumentNullException(nameof(line));
     }
     return(line.BufferLine.LineNumber + 1 == line.BufferLine.LineProvider.LineCount);
 }
        void UpdateAdornmentUIState(HexViewLine line, AdornmentTagInfo adornmentInfo, VSTF.TextBounds bounds)
        {
            double verticalScale = line.LineTransform.VerticalScale;

            adornmentInfo.TopUIElement.SetScale(verticalScale);
            Canvas.SetTop(adornmentInfo.TopUIElement, bounds.TextTop + line.Baseline - verticalScale * adornmentInfo.Tag.Baseline);
            Canvas.SetLeft(adornmentInfo.TopUIElement, bounds.Left);
        }
        void UpdateIsSelected(AdornmentTagInfo adornmentInfo, HexViewLine line)
        {
            if (line == null)
            {
                line = wpfHexView.HexViewLines.GetHexViewLineContainingBufferPosition(adornmentInfo.BufferSpan.Start);
            }
            bool selected = IsSelected(adornmentInfo, line);

            VSTE.IntraTextAdornment.SetIsSelected(adornmentInfo.UserUIElement, selected);
        }
示例#8
0
 HexMouseLocation(HexViewLine hexViewLine, int position, Point point)
 {
     if (hexViewLine == null)
     {
         throw new ArgumentNullException(nameof(hexViewLine));
     }
     HexViewLine = hexViewLine;
     Position    = position;
     Point       = point;
 }
            public override VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement)
            {
                var transform = removeExtraTextLineVerticalPixels ?
                                new VSTF.LineTransform(0, 0, line.DefaultLineTransform.VerticalScale, line.DefaultLineTransform.Right) :
                                line.DefaultLineTransform;

                foreach (var source in lineTransformSources)
                {
                    transform = VSTF.LineTransform.Combine(transform, source.GetLineTransform(line, yPosition, placement));
                }
                return(transform);
            }
示例#10
0
 public LineInfo(HexViewLine hexViewLine, List <IconInfo> icons)
 {
     if (hexViewLine == null)
     {
         throw new ArgumentNullException(nameof(hexViewLine));
     }
     if (icons == null)
     {
         throw new ArgumentNullException(nameof(icons));
     }
     Line  = hexViewLine;
     Icons = icons;
 }
示例#11
0
        void AddLine(Dictionary <object, LineInfo> newInfos, HexViewLine line)
        {
            var wpfLine = line as WpfHexViewLine;

            Debug.Assert(wpfLine != null);
            if (wpfLine == null)
            {
                return;
            }
            var info = new LineInfo(line, CreateIconInfos(wpfLine));

            newInfos.Add(line.IdentityTag, info);
            foreach (var iconInfo in info.Icons)
            {
                childCanvases[iconInfo.Order].Children.Add(iconInfo.Element);
            }
        }
示例#12
0
        IEnumerable <(HexColumnType type, Rect rect)> GetRectanglePositions(HexViewLine line)
        {
            var column = wpfHexView.Caret.Position.Position.ActiveColumn;

            if (!line.BufferLine.IsColumnPresent(column))
            {
                yield break;
            }
            var span = line.BufferLine.GetSpan(column, onlyVisibleCells: false);
            var rect = GetBounds(line.GetNormalizedTextBounds(span));

            if (rect == null || rect.Value.Width <= 0)
            {
                yield break;
            }
            yield return(column, new Rect(rect.Value.X, wpfHexView.ViewportTop, rect.Value.Width, wpfHexView.ViewportHeight));
        }
        bool AddAdornment(AdornmentTagInfo adornmentInfo, HexViewLine line)
        {
            SizeChangedEventHandler sizeChanged = (a, e) => {
                var bounds = line.GetAdornmentBounds(adornmentInfo);
                if (bounds == null)
                {
                    return;
                }
                // Sometimes the size just gets changed very little, eg. from 400 to 399.95.....
                const double d = 0.5;
                if (e.NewSize.Height <= bounds.Value.Height + d && e.NewSize.Width <= bounds.Value.Width + d)
                {
                    return;
                }
                tagger?.RefreshSpans(new HexBufferSpanEventArgs(adornmentInfo.BufferSpan));
            };

            adornmentInfo.TopUIElement.SizeChanged += sizeChanged;

            VSTE.AdornmentRemovedCallback removedCallback = (a, b) => {
                adornmentTagInfos.Remove(adornmentInfo);
                adornmentInfo.TopUIElement.SizeChanged -= sizeChanged;
                adornmentInfo.TopUIElement.OnRemoved();
                if (adornmentInfo.HexTagSpan != null)
                {
                    adornmentInfo.HexTagSpan.Tag.RemovalCallback?.Invoke(adornmentInfo.HexTagSpan, b);
                }
                else
                {
                    adornmentInfo.HexTextTagSpan.Tag.RemovalCallback?.Invoke(adornmentInfo.HexTextTagSpan, b);
                }
            };

            Debug.Assert(!adornmentTagInfos.Contains(adornmentInfo));
            adornmentTagInfos.Add(adornmentInfo);
            // Use OwnerControlled because there are corner cases that the adornment layer can't handle,
            // eg. an adornment with buffer span length == 0 that is shown on its own line (word wrap).
            bool added = layer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, adornmentInfo, adornmentInfo.TopUIElement, removedCallback);

            if (!added)
            {
                removedCallback(null, adornmentInfo.TopUIElement);
            }
            return(added);
        }
示例#14
0
        public override IEnumerable <VST.Span> GetSelectionOnHexViewLine(HexViewLine line)
        {
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }
            if (line.BufferLine.LineProvider != HexView.BufferLines)
            {
                throw new ArgumentException();
            }

            foreach (var info in line.BufferLine.GetSpans(StreamSelectionSpan, SelectionFlags))
            {
                if (info.TextSpan.Length != 0)
                {
                    yield return(info.TextSpan);
                }
            }
        }
示例#15
0
        HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate, HexMoveToFlags flags, bool captureVerticalPosition)
        {
            if (hexLine == null)
            {
                throw new ArgumentNullException(nameof(hexLine));
            }
            if (hexLine.BufferLine.LineProvider != hexView.BufferLines)
            {
                throw new ArgumentException();
            }

            var linePosition = (flags & HexMoveToFlags.InsertionPosition) != 0 ?
                               hexLine.GetInsertionLinePositionFromXCoordinate(xCoordinate) :
                               hexLine.GetVirtualLinePositionFromXCoordinate(xCoordinate);
            var posInfo = hexLine.BufferLine.GetLinePositionInfo(linePosition);

            if (posInfo.IsValueCellSeparator)
            {
                var posInfo2 = hexLine.BufferLine.GetLinePositionInfo(hexLine.GetInsertionLinePositionFromXCoordinate(xCoordinate));
                if (posInfo2.IsValueCell)
                {
                    posInfo = posInfo2;
                }
            }
            var closestPos = hexLine.BufferLine.GetClosestCellPosition(posInfo, onlyVisibleCells: true);

            if (closestPos == null)
            {
                Debug.Assert(hexView.BufferLines.BufferSpan.Length == 0 || (!IsValuesCaretPresent && !IsAsciiCaretPresent));
                closestPos = new HexCellPosition(currentPosition.ActiveColumn, hexLine.BufferStart, 0);
            }
            SetExplicitPosition(CreateColumnPosition(closestPos.Value));
            if ((flags & HexMoveToFlags.CaptureHorizontalPosition) != 0)
            {
                SavePreferredXCoordinate();
            }
            if (captureVerticalPosition)
            {
                SavePreferredYCoordinate();
            }
            return(Position);
        }
示例#16
0
 IList <VSTF.TextBounds> GetTextBounds(HexViewLine line)
 {
     if (lineSpan.IsTextSpan)
     {
         if (lineSpan.TextSpan !.Value.Length == 0)
         {
             if (line.BufferSpan.Contains(lineSpan.BufferSpan))
             {
                 var bounds = line.GetCharacterBounds(lineSpan.TextSpan.Value.Start);
                 // It's just a point, so use zero width
                 bounds = new VSTF.TextBounds(bounds.Leading, bounds.Top, 0, bounds.Height, bounds.TextTop, bounds.TextHeight);
                 return(new VSTF.TextBounds[] { bounds });
             }
             return(Array.Empty <VSTF.TextBounds>());
         }
         else
         {
             return(line.GetNormalizedTextBounds(lineSpan));
         }
     }
示例#17
0
        Rect GetCaretRect(HexViewLine line, bool drawOverwriteMode, HexColumnType column, HexCell cell, int cellPosition)
        {
            if (cell == null)
            {
                return(new Rect());
            }

            int linePosition = cell.CellSpan.Start + Math.Max(0, Math.Min(cell.CellSpan.Length - 1, cellPosition));

            if (hexCaret.CurrentPosition.ActiveColumn != column)
            {
                var r = ToRect(line.GetNormalizedTextBounds(cell.CellSpan));
                return(new Rect(r.X, r.Bottom - INACTIVE_CARET_HEIGHT, r.Width, INACTIVE_CARET_HEIGHT));
            }
            else if (drawOverwriteMode)
            {
                var textBounds = line.GetExtendedCharacterBounds(linePosition);
                var left       = textBounds.Left;
                var top        = line.TextTop;
                var width      = textBounds.Width;
                var height     = line.TextHeight;
                return(new Rect(left, top, width, height));
            }
            else
            {
                double left;
                if (linePosition != 0 && linePosition <= line.BufferLine.Text.Length)
                {
                    left = line.GetExtendedCharacterBounds(linePosition - 1).Trailing;
                }
                else
                {
                    left = line.GetExtendedCharacterBounds(linePosition).Leading;
                }
                var top    = line.TextTop;
                var width  = SystemParameters.CaretWidth;
                var height = line.TextHeight;
                return(new Rect(left, top, width, height));
            }
        }
示例#18
0
 /// <summary>
 /// Selects the line
 /// </summary>
 /// <param name="viewLine">Line</param>
 /// <param name="extendSelection">true to extend the selection</param>
 public abstract void SelectLine(HexViewLine viewLine, bool extendSelection);
示例#19
0
 /// <summary>
 /// Gets the slection on a line
 /// </summary>
 /// <param name="line">Line</param>
 /// <returns></returns>
 public abstract IEnumerable <VST.Span> GetSelectionOnHexViewLine(HexViewLine line);
示例#20
0
 public override HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate, HexMoveToFlags flags) =>
 MoveTo(hexLine, xCoordinate, flags, true);
示例#21
0
 public override HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate) =>
 MoveTo(hexLine, xCoordinate, HexMoveToFlags.CaptureHorizontalPosition, true);
示例#22
0
 public override HexCaretPosition MoveTo(HexViewLine hexLine) =>
 MoveTo(hexLine, preferredXCoordinate, HexMoveToFlags.None, true);
示例#23
0
文件: HexCaret.cs 项目: zquans/dnSpy
 /// <summary>
 /// Moves the caret to a new position
 /// </summary>
 /// <param name="hexLine">Line</param>
 /// <param name="xCoordinate">X coordinate</param>
 /// <returns></returns>
 public abstract HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate);
示例#24
0
 public LineInfo(HexViewLine hexViewLine, List <IconInfo> icons)
 {
     Line  = hexViewLine ?? throw new ArgumentNullException(nameof(hexViewLine));
     Icons = icons ?? throw new ArgumentNullException(nameof(icons));
 }
示例#25
0
文件: HexCaret.cs 项目: zquans/dnSpy
 /// <summary>
 /// Moves the caret to a new position
 /// </summary>
 /// <param name="hexLine">Line</param>
 /// <returns></returns>
 public abstract HexCaretPosition MoveTo(HexViewLine hexLine);
示例#26
0
 /// <summary>
 /// Move caret to a line
 /// </summary>
 /// <param name="hexLine">Line</param>
 /// <param name="horizontalOffset">Horizontal offset</param>
 /// <param name="extendSelection">true to extend the selection</param>
 public void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection) =>
 MoveCaret(hexLine, horizontalOffset, extendSelection, HexMoveToFlags.CaptureHorizontalPosition);
示例#27
0
 /// <summary>
 /// Move caret to a line
 /// </summary>
 /// <param name="hexLine">Line</param>
 /// <param name="horizontalOffset">Horizontal offset</param>
 /// <param name="extendSelection">true to extend the selection</param>
 /// <param name="flags">Flags</param>
 public abstract void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection, HexMoveToFlags flags);
示例#28
0
文件: HexCaret.cs 项目: zquans/dnSpy
 /// <summary>
 /// Moves the caret to a new position
 /// </summary>
 /// <param name="hexLine">Line</param>
 /// <param name="xCoordinate">X coordinate</param>
 /// <param name="flags">Flags</param>
 /// <returns></returns>
 public abstract HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate, HexMoveToFlags flags);