Exemple #1
0
        void PositionLineElement()
        {
            if (!selectionIsEmpty || !enabled)
            {
                adornmentLayer?.RemoveAllAdornments();
                return;
            }

            var line = wpfHexView.Caret.ContainingHexViewLine;

            if (line.IsVisible())
            {
                if (adornmentLayer.IsEmpty)
                {
                    adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, currentLineHighlighterElement, null);
                }
                Canvas.SetLeft(currentLineHighlighterElement, wpfHexView.ViewportLeft);
                Canvas.SetTop(currentLineHighlighterElement, line.TextTop);
                currentLineHighlighterElement.SetLine(line, wpfHexView.ViewportWidth);
            }
            else
            {
                adornmentLayer.RemoveAllAdornments();
            }
        }
Exemple #2
0
 public TextLayer(HexAdornmentLayer adornmentLayer)
 {
     if (adornmentLayer == null)
     {
         throw new ArgumentNullException(nameof(adornmentLayer));
     }
     lines = new List <LineInfo>();
     adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, this, null);
 }
 void CreateMarkerElement(HexBufferSpan fullSpan, Geometry geo)
 {
     Debug.Assert(markerElement == null);
     RemoveAllAdornments();
     markerElement = new MarkerElement(geo);
     markerElement.BackgroundBrush = backgroundBrush;
     if (!layer.AddAdornment(VSTE.AdornmentPositioningBehavior.TextRelative, fullSpan, null, markerElement, markerElementRemovedCallBack))
     {
         OnMarkerElementRemoved();
     }
 }
        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);
        }
        void RecreateColumnLines()
        {
            delayRecreateColumnLinesCalled = false;
            if (wpfHexView.IsClosed)
            {
                return;
            }

            RemoveAllLines();
            if (!enabled)
            {
                return;
            }

            if (wpfHexView.ViewportHeight == 0)
            {
                return;
            }

            var line   = wpfHexView.HexViewLines.FirstVisibleLine;
            var top    = wpfHexView.ViewportTop;
            var bottom = wpfHexView.ViewportBottom;

            foreach (var info in GetColumnPositions(line.BufferLine))
            {
                var lineKind = GetColumnLineKind(info.Key);
                if (lineKind == HexColumnLineKind.None)
                {
                    continue;
                }
                var  props    = editorFormatMap.GetProperties(classificationTypeNames[(int)info.Key]);
                var  pen      = GetPen(props, lineKind);
                var  bounds   = line.GetCharacterBounds(info.Value);
                var  x        = Math.Round(bounds.Left + bounds.Width / 2 - PEN_THICKNESS / 2) + 0.5;
                var  lineElem = new LineElement(info.Key, x, top, bottom, pen);
                bool added    = adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, lineElem, null);
                if (added)
                {
                    lineElements.Add(lineElem);
                }
            }

            latestBufferLines = wpfHexView.BufferLines;
        }
Exemple #6
0
        void RecreateRectangles()
        {
            delayRecreateRectanglesCalled = false;
            if (wpfHexView.IsClosed)
            {
                return;
            }

            RemoveAllRectangles();
            if (!enabled)
            {
                return;
            }

            if (wpfHexView.ViewportHeight == 0)
            {
                return;
            }

            var line   = wpfHexView.HexViewLines.FirstVisibleLine;
            var top    = wpfHexView.ViewportTop;
            var bottom = wpfHexView.ViewportBottom;

            foreach (var info in GetRectanglePositions(line))
            {
                var props   = editorFormatMap.GetProperties(GetClassificationTypeName(info.type));
                var bgBrush = GetBackgroundBrush(props);
                if (bgBrush == null || TWPF.BrushComparer.Equals(bgBrush, Brushes.Transparent))
                {
                    continue;
                }
                var  lineElem = new RectangleElement(info.type, info.rect, bgBrush, null);
                bool added    = adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, lineElem, null);
                if (added)
                {
                    rectangleElements.Add(lineElem);
                }
            }

            latestBufferLines = wpfHexView.BufferLines;
        }
Exemple #7
0
 void AddAdornment() => layer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, this, null);
 protected override void AddImageToAdornmentLayerCore(Image image) =>
 adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, image, null);