public AdornmentLayerElement(AdornmentPositioningBehavior behavior, SnapshotSpan? visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback) {
			Adornment = adornment;
			Behavior = behavior;
			RemovedCallback = removedCallback;
			Tag = tag;
			VisualSpan = visualSpan;
		}
 public AdornmentLayerElement(AdornmentPositioningBehavior behavior, SnapshotSpan?visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback)
 {
     Adornment       = adornment;
     Behavior        = behavior;
     RemovedCallback = removedCallback;
     Tag             = tag;
     VisualSpan      = visualSpan;
 }
Exemple #3
0
 public AdornmentAndData(AdornmentPositioningBehavior behavior, SnapshotSpan?visualSpan, object tag, AdornmentElement element, AdornmentRemovedCallback removedCallback)
 {
     _behavior        = behavior;
     _visualSpan      = visualSpan;
     _tag             = tag;
     _element         = element;
     _removedCallback = removedCallback;
 }
Exemple #4
0
 public Marker(IWpfTextView textView, IAdornmentLayer adornmentLayer)
 {
     if (textView == null)
     {
         throw new ArgumentNullException(nameof(textView));
     }
     if (adornmentLayer == null)
     {
         throw new ArgumentNullException(nameof(adornmentLayer));
     }
     this.textView                 = textView;
     this.adornmentLayer           = adornmentLayer;
     this.toMarkedLine             = new Dictionary <object, MarkedLine>();
     this.markedSpans              = NullMarkerSpanCollection.Instance;
     this.adornmentRemovedCallback = OnAdornmentRemoved;
 }
        bool AddAdornment(AdornmentTagInfo adornmentInfo)
        {
            var oldSize = adornmentInfo.TopUIElement.DesiredSize;
            SizeChangedEventHandler sizeChanged = (a, e) => {
                if (e.NewSize == oldSize)
                {
                    return;
                }
                // Sometimes the size just gets changed very little, eg. from 400 to 399.95.....
                const double d = 0.5;
                if (Math.Abs(e.NewSize.Height - oldSize.Height) < d && Math.Abs(e.NewSize.Width - oldSize.Width) < d)
                {
                    return;
                }
                oldSize = e.NewSize;
                tagger?.RefreshSpans(new SnapshotSpanEventArgs(adornmentInfo.Span));
            };

            adornmentInfo.TopUIElement.SizeChanged += sizeChanged;

            AdornmentRemovedCallback removedCallback = (a, b) => {
                adornmentTagInfos.Remove(adornmentInfo);
                adornmentInfo.TopUIElement.SizeChanged -= sizeChanged;
                adornmentInfo.TopUIElement.OnRemoved();
                adornmentInfo.TagSpan.Tag.RemovalCallback?.Invoke(adornmentInfo.TagSpan, 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(AdornmentPositioningBehavior.OwnerControlled, null, adornmentInfo, adornmentInfo.TopUIElement, removedCallback);

            if (!added)
            {
                removedCallback(null, adornmentInfo.TopUIElement);
            }
            return(added);
        }
Exemple #6
0
		public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan? visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback) {
			if (adornment == null)
				throw new ArgumentNullException(nameof(adornment));
			if (visualSpan == null && behavior == AdornmentPositioningBehavior.TextRelative)
				throw new ArgumentNullException(nameof(visualSpan));
			if ((uint)behavior > (uint)AdornmentPositioningBehavior.TextRelative)
				throw new ArgumentOutOfRangeException(nameof(behavior));
			if (layerKind != LayerKind.Normal) {
				if (behavior != AdornmentPositioningBehavior.OwnerControlled)
					throw new ArgumentOutOfRangeException(nameof(behavior), "Special layers must use AdornmentPositioningBehavior.OwnerControlled");
				if (visualSpan != null)
					throw new ArgumentOutOfRangeException(nameof(visualSpan), "Special layers must use a null visual span");
			}
			bool canAdd = visualSpan == null || TextView.TextViewLines.IntersectsBufferSpan(visualSpan.Value);
			if (canAdd) {
				var layerElem = new AdornmentLayerElement(behavior, visualSpan, tag, adornment, removedCallback);
				layerElem.OnLayoutChanged(TextView.TextSnapshot);
				Children.Add(layerElem.Adornment);
				adornmentLayerElements.Add(layerElem);
			}
			return canAdd;
		}
Exemple #7
0
 public LinkViewerLinkTag(UIElement adornment, AdornmentRemovedCallback removalCallback, PositionAffinity?affinity) : base(adornment, removalCallback, affinity)
 {
 }
Exemple #8
0
 public LinkViewerLinkTag(UIElement adornment, AdornmentRemovedCallback removalCallback) : base(adornment, removalCallback)
 {
 }
Exemple #9
0
 public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan?visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback)
 {
     throw new NotImplementedException();
 }
Exemple #10
0
 public LinkViewerLinkTag(UIElement adornment, AdornmentRemovedCallback removalCallback, double?topSpace, double?baseline, double?textHeight, double?bottomSpace, PositionAffinity?affinity) : base(adornment, removalCallback, topSpace, baseline, textHeight, bottomSpace, affinity)
 {
 }
Exemple #11
0
 public static void AddAdornment(this IAdornmentLayer self, object tag, UIElement adornment,
                                 AdornmentRemovedCallback removedCallback = null)
 {
     self.AddAdornment(AdornmentPositioningBehavior.OwnerControlled, null, tag, adornment, null);
 }
Exemple #12
0
        public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan?visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback)
        {
            if (adornment == null)
            {
                throw new ArgumentNullException(nameof(adornment));
            }
            if (visualSpan == null && behavior == AdornmentPositioningBehavior.TextRelative)
            {
                throw new ArgumentNullException(nameof(visualSpan));
            }
            if ((uint)behavior > (uint)AdornmentPositioningBehavior.TextRelative)
            {
                throw new ArgumentOutOfRangeException(nameof(behavior));
            }
            if (layerKind != LayerKind.Normal)
            {
                if (behavior != AdornmentPositioningBehavior.OwnerControlled)
                {
                    throw new ArgumentOutOfRangeException(nameof(behavior), "Special layers must use AdornmentPositioningBehavior.OwnerControlled");
                }
                if (visualSpan != null)
                {
                    throw new ArgumentOutOfRangeException(nameof(visualSpan), "Special layers must use a null visual span");
                }
            }
            bool canAdd = visualSpan == null || TextView.TextViewLines.IntersectsBufferSpan(visualSpan.Value);

            if (canAdd)
            {
                var layerElem = new AdornmentLayerElement(behavior, visualSpan, tag, adornment, removedCallback);
                layerElem.OnLayoutChanged(TextView.TextSnapshot);
                Children.Add(layerElem.Adornment);
                adornmentLayerElements.Add(layerElem);
            }
            return(canAdd);
        }
 public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan? visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback) {
     throw new NotImplementedException();
 }
 public LinkViewerLinkTag(UIElement adornment, AdornmentRemovedCallback removalCallback, double? topSpace, double? baseline, double? textHeight, double? bottomSpace, PositionAffinity? affinity)
     : base(adornment, removalCallback, topSpace, baseline, textHeight, bottomSpace, affinity)
 {
 }
Exemple #15
0
        public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan?visualSpan, object tag, AdornmentElement element, AdornmentRemovedCallback removedCallback)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (_isOverlayLayer && behavior != AdornmentPositioningBehavior.OwnerControlled)
            {
                throw new ArgumentOutOfRangeException("behavior", "Only AdornmentPositioningBehavior.OwnerControlled is supported");
            }
            if (IsTextRelative(behavior) && !visualSpan.HasValue)
            {
                throw new ArgumentNullException("visualSpan");
            }

            bool visible = true;

            if (visualSpan.HasValue)
            {
                //Does the visual span intersect anything visible?
                visible = _view.TextViewLines.IntersectsBufferSpan(visualSpan.Value);
            }

            if (visible)
            {
                AdornmentAndData data = new AdornmentAndData(behavior, visualSpan, tag, element, removedCallback);
                _elements.Add(data);
                Children.Add(element);
            }

            return(visible);
        }
 public LinkViewerLinkTag(UIElement adornment, AdornmentRemovedCallback removalCallback)
     : base(adornment, removalCallback)
 {
 }
 public LinkViewerLinkTag(UIElement adornment, AdornmentRemovedCallback removalCallback, PositionAffinity? affinity)
     : base(adornment, removalCallback, affinity)
 {
 }