void IGlyphTextMarkerListener.OnAdded(IEnumerable <IGlyphTextMarkerImpl> markers)
        {
            // Auto show the marker's popup content when it gets added, eg. the user presses
            // F9 and the breakpoint settings toolbar is auto shown.

            if (!wpfTextViewHost.TextView.HasAggregateFocus)
            {
                return;
            }
            var marker = markers.LastOrDefault();

            if (marker == null)
            {
                return;
            }
            var line = glyphTextViewMarkerService.GetVisibleLine(marker);

            if (line == null)
            {
                return;
            }
            Debug.Assert(line.IsVisible());
            var context      = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
            var popupContent = marker.Handler.GetPopupContent(context, marker);

            if (popupContent != null)
            {
                AddPopupContent(line, marker, popupContent);
            }
        }
        public IEnumerable <GuidObject> GetContextMenuObjects(Point marginRelativePoint)
        {
            var line = GetLine(marginRelativePoint);

            if (line is null)
            {
                yield break;
            }

            var markers = glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line);

            if (markers.Length > 0)
            {
                var glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line, this);
                foreach (var marker in markers)
                {
                    foreach (var o in marker.Handler.GetContextMenuObjects(glyphTextMarkerHandlerContext, marker, marginRelativePoint))
                    {
                        yield return(o);
                    }
                }
            }

            if (glyphTextMarkerMouseProcessors.Length != 0)
            {
                var context = new GlyphTextMarkerMouseProcessorContext(wpfTextViewHost, margin, line, markers, this);
                foreach (var processor in glyphTextMarkerMouseProcessors)
                {
                    foreach (var o in processor.GetContextMenuObjects(context, marginRelativePoint))
                    {
                        yield return(o);
                    }
                }
            }
        }
        void UpdateToolTipContent(IWpfTextViewLine line)
        {
            IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;

            foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line))
            {
                if (glyphTextMarkerHandlerContext == null)
                {
                    glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
                }
                var toolTipContent = marker.Handler.GetToolTipContent(glyphTextMarkerHandlerContext, marker);
                if (toolTipContent != null)
                {
                    Debug.Assert(toolTip == null);
                    toolTipMarker = marker;
                    toolTip       = new ToolTip();
                    toolTip.SetResourceReference(FrameworkElement.StyleProperty, "GlyphTextMarkerToolTipStyle");
                    ToolTipHelper.SetScaleTransform(wpfTextViewHost.TextView, toolTip);
                    toolTip.Content = new TextBlock {
                        Text         = toolTipContent,
                        TextWrapping = TextWrapping.Wrap,
                    };
                    toolTip.Placement        = PlacementMode.Relative;
                    toolTip.PlacementTarget  = margin.VisualElement;
                    toolTip.HorizontalOffset = 0;
                    toolTip.VerticalOffset   = toolTipLine.TextBottom - wpfTextViewHost.TextView.ViewportTop + 1;
                    toolTip.IsOpen           = true;
                    return;
                }
            }
        }
        void UpdateToolTipContent(IWpfTextViewLine line)
        {
            IGlyphTextMarkerHandlerContext?glyphTextMarkerHandlerContext = null;

            foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line))
            {
                if (glyphTextMarkerHandlerContext is null)
                {
                    glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line, this);
                }
                var toolTipInfo = marker.Handler.GetToolTipContent(glyphTextMarkerHandlerContext, marker);
                if (!(toolTipInfo is null))
                {
                    Debug2.Assert(toolTip is null);
                    toolTipMarker = marker;
                    toolTip       = new ToolTip();
                    PopupHelper.SetScaleTransform(wpfTextViewHost.TextView, toolTip);

                    if (toolTipInfo.Content is string toolTipContentString)
                    {
                        toolTip.Content = new TextBlock {
                            Text         = toolTipContentString,
                            TextWrapping = TextWrapping.Wrap,
                        };
                    }
                    else
                    {
                        toolTip.Content = toolTipInfo.Content;
                    }

                    if (toolTipInfo.Style is Style toolTipStyle)
                    {
                        toolTip.Style = toolTipStyle;
                    }
                    else
                    {
                        toolTip.SetResourceReference(FrameworkElement.StyleProperty, toolTipInfo.Style ?? "GlyphTextMarkerToolTipStyle");
                    }

                    toolTip.Placement        = PlacementMode.Relative;
                    toolTip.PlacementTarget  = margin.VisualElement;
                    toolTip.HorizontalOffset = 0;
                    toolTip.VerticalOffset   = toolTipLine !.TextBottom - wpfTextViewHost.TextView.ViewportTop + 1;
                    toolTip.IsOpen           = true;
                    return;
                }
            }
        }
        void UpdatePopupContent(IWpfTextViewLine line)
        {
            IGlyphTextMarkerHandlerContext?glyphTextMarkerHandlerContext = null;

            foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line))
            {
                if (glyphTextMarkerHandlerContext is null)
                {
                    glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line, this);
                }
                var popupContent = marker.Handler.GetPopupContent(glyphTextMarkerHandlerContext, marker);
                if (!(popupContent is null))
                {
                    AddPopupContent(line, marker, popupContent);
                    return;
                }
            }
        }
        public override void PostprocessMouseMove(MouseEventArgs e)
        {
            UpdateLine(e);
            var line = GetLine(e);

            if (line is null)
            {
                return;
            }

            var markers = glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line);

            IGlyphTextMarkerHandlerContext?glyphTextMarkerHandlerContext = null;

            foreach (var marker in markers)
            {
                if (marker.Handler.MouseProcessor is null)
                {
                    continue;
                }
                if (glyphTextMarkerHandlerContext is null)
                {
                    glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line, this);
                }
                marker.Handler.MouseProcessor.OnMouseMove(glyphTextMarkerHandlerContext, marker, e);
                if (e.Handled)
                {
                    return;
                }
            }

            if (glyphTextMarkerMouseProcessors.Length != 0)
            {
                var context = new GlyphTextMarkerMouseProcessorContext(wpfTextViewHost, margin, line, markers, this);
                foreach (var processor in glyphTextMarkerMouseProcessors)
                {
                    processor.OnMouseMove(context, e);
                    if (e.Handled)
                    {
                        return;
                    }
                }
            }
        }
        public override void PostprocessMouseRightButtonUp(MouseButtonEventArgs e)
        {
            CloseToolTip();
            var line = GetLine(e);

            if (line == null)
            {
                return;
            }

            var markers = glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line);

            IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;

            foreach (var marker in markers)
            {
                if (marker.Handler.MouseProcessor == null)
                {
                    continue;
                }
                if (glyphTextMarkerHandlerContext == null)
                {
                    glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
                }
                marker.Handler.MouseProcessor.OnMouseRightButtonUp(glyphTextMarkerHandlerContext, marker, e);
                if (e.Handled)
                {
                    return;
                }
            }

            if (glyphTextMarkerMouseProcessors.Length != 0)
            {
                var context = new GlyphTextMarkerMouseProcessorContext(wpfTextViewHost, margin, line, markers);
                foreach (var processor in glyphTextMarkerMouseProcessors)
                {
                    processor.OnMouseRightButtonUp(context, e);
                    if (e.Handled)
                    {
                        return;
                    }
                }
            }
        }
		void IGlyphTextMarkerListener.OnAdded(IEnumerable<IGlyphTextMarkerImpl> markers) {
			// Auto show the marker's popup content when it gets added, eg. the user presses
			// F9 and the breakpoint settings toolbar is auto shown.

			if (!wpfTextViewHost.TextView.HasAggregateFocus)
				return;
			var marker = markers.LastOrDefault();
			if (marker == null)
				return;
			var line = glyphTextViewMarkerService.GetVisibleLine(marker);
			if (line == null)
				return;
			Debug.Assert(line.IsVisible());
			var context = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
			var popupContent = marker.Handler.GetPopupContent(context, marker);
			if (popupContent != null)
				AddPopupContent(line, marker, popupContent);
		}
		void UpdatePopupContent(IWpfTextViewLine line) {
			IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;
			foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line)) {
				if (glyphTextMarkerHandlerContext == null)
					glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
				var popupContent = marker.Handler.GetPopupContent(glyphTextMarkerHandlerContext, marker);
				if (popupContent != null) {
					AddPopupContent(line, marker, popupContent);
					return;
				}
			}
		}
		void UpdateToolTipContent(IWpfTextViewLine line) {
			IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;
			foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line)) {
				if (glyphTextMarkerHandlerContext == null)
					glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
				var toolTipInfo = marker.Handler.GetToolTipContent(glyphTextMarkerHandlerContext, marker);
				if (toolTipInfo != null) {
					Debug.Assert(toolTip == null);
					toolTipMarker = marker;
					toolTip = new ToolTip();
					PopupHelper.SetScaleTransform(wpfTextViewHost.TextView, toolTip);

					var toolTipContentString = toolTipInfo.Content as string;
					if (toolTipContentString != null) {
						toolTip.Content = new TextBlock {
							Text = toolTipContentString,
							TextWrapping = TextWrapping.Wrap,
						};
					}
					else
						toolTip.Content = toolTipInfo.Content;

					var toolTipStyle = toolTipInfo.Style as Style;
					if (toolTipStyle != null)
						toolTip.Style = toolTipStyle;
					else
						toolTip.SetResourceReference(FrameworkElement.StyleProperty, toolTipInfo.Style ?? "GlyphTextMarkerToolTipStyle");

					toolTip.Placement = PlacementMode.Relative;
					toolTip.PlacementTarget = margin.VisualElement;
					toolTip.HorizontalOffset = 0;
					toolTip.VerticalOffset = toolTipLine.TextBottom - wpfTextViewHost.TextView.ViewportTop + 1;
					toolTip.IsOpen = true;
					return;
				}
			}
		}
		public override void PostprocessMouseMove(MouseEventArgs e) {
			UpdateLine(e);
			var line = GetLine(e);
			if (line == null)
				return;

			var markers = glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line);

			IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;
			foreach (var marker in markers) {
				if (marker.Handler.MouseProcessor == null)
					continue;
				if (glyphTextMarkerHandlerContext == null)
					glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
				marker.Handler.MouseProcessor.OnMouseMove(glyphTextMarkerHandlerContext, marker, e);
				if (e.Handled)
					return;
			}

			if (glyphTextMarkerMouseProcessors.Length != 0) {
				var context = new GlyphTextMarkerMouseProcessorContext(wpfTextViewHost, margin, line, markers);
				foreach (var processor in glyphTextMarkerMouseProcessors) {
					processor.OnMouseMove(context, e);
					if (e.Handled)
						return;
				}
			}
		}
		public IEnumerable<GuidObject> GetContextMenuObjects(Point marginRelativePoint) {
			var line = GetLine(marginRelativePoint);
			if (line == null)
				yield break;

			var markers = glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line);

			if (markers.Length > 0) {
				var glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
				foreach (var marker in markers) {
					foreach (var o in marker.Handler.GetContextMenuObjects(glyphTextMarkerHandlerContext, marker, marginRelativePoint))
						yield return o;
				}
			}

			if (glyphTextMarkerMouseProcessors.Length != 0) {
				var context = new GlyphTextMarkerMouseProcessorContext(wpfTextViewHost, margin, line, markers);
				foreach (var processor in glyphTextMarkerMouseProcessors) {
					foreach (var o in processor.GetContextMenuObjects(context, marginRelativePoint))
						yield return o;
				}
			}
		}