in src/Structure/StructureVisualizer/StructureAdornmentManager.cs [423:506]
public override void PreprocessMouseMove(System.Windows.Input.MouseEventArgs e)
{
ITextViewLineCollection textLines = _view.TextViewLines;
if ((textLines != null) && (_visibleBlocks.Count > 0))
{
ITextViewLine firstVisible = textLines.FirstVisibleLine;
Point pt = e.GetPosition(_view.VisualElement);
pt.X += _view.ViewportLeft;
pt.Y += _view.ViewportTop;
//Horrible hack for peek: prevent the tip from showing if the y coordinate is in the space below the bottom of a line's text
//(which is where the peek adornment would be displayed).
var line = textLines.GetTextViewLineContainingYCoordinate(pt.Y);
if ((line != null) && (pt.Y <= line.TextBottom + 1.0))
{
int screenTop = (firstVisible.VisibilityState == VisibilityState.FullyVisible)
? firstVisible.Start
: firstVisible.EndIncludingLineBreak;
foreach (VisibleBlock block in _visibleBlocks)
{
if ((Math.Abs(pt.X - block.x) < 4.0) &&
(pt.Y >= block.yTop) && (pt.Y <= block.yBottom))
{
SnapshotPoint? statementStart = _view.BufferGraph.MapUpToSnapshot(block.tag.StatementStart, PointTrackingMode.Positive, PositionAffinity.Successor, _view.TextSnapshot);
if (statementStart.HasValue && (statementStart.Value < screenTop))
{
if (_tipWindow == null)
{
_tipWindow = new ToolTip();
_tipWindow.ClipToBounds = true;
_tipWindow.Placement = PlacementMode.Top;
_tipWindow.PlacementTarget = _view.VisualElement;
_tipWindow.HorizontalAlignment = HorizontalAlignment.Left;
_tipWindow.HorizontalContentAlignment = HorizontalAlignment.Left;
_tipWindow.VerticalAlignment = VerticalAlignment.Top;
_tipWindow.VerticalContentAlignment = VerticalAlignment.Top;
}
_tipWindow.PlacementRectangle = new Rect(block.x, 0.0, 0.0, 0.0);
if (_tipWindow.IsOpen)
{
var existingContext = _tipWindow.Content as FrameworkElement;
if ((existingContext != null) && (existingContext.Tag == block.tag))
{
// No changes from the last time we opened the tip.
return;
}
}
FrameworkElement context = block.tag.Context(_coloring,
_view.FormattedLineSource.DefaultTextProperties);
context.Tag = block.tag;
//The width of the view is in zoomed coordinates so factor the zoom factor into the tip window width computation.
double zoom = _view.ZoomLevel / 100.0;
_tipWindow.MaxWidth = Math.Max(100.0, _view.ViewportWidth * zoom * 0.5);
_tipWindow.MinHeight = _tipWindow.MaxHeight = context.Height + 12.0;
var rd = _formatMap.GetProperties("TextView Background");
if (rd.Contains(EditorFormatDefinition.BackgroundBrushId))
{
_tipWindow.Background = rd[EditorFormatDefinition.BackgroundBrushId] as Brush;
}
_tipWindow.Content = context;
_tipWindow.IsOpen = true;
StructureMarginElement.LogTipOpened("VS/PPT-Structure/AdornmentTipOpened", context);
return;
}
}
}
}
}
this.CloseTip();
}