/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.Collections.ObjectModel; using dnSpy.Contracts.Hex.Tagging; using VST = Microsoft.VisualStudio.Text; using VSTF = Microsoft.VisualStudio.Text.Formatting; namespace dnSpy.Contracts.Hex.Formatting { /// /// Hex view line /// public abstract class HexViewLine { /// /// Constructor /// protected HexViewLine() { } /// /// Gets a tag that can be used to track the instance across layouts /// public abstract object IdentityTag { get; } /// /// true if this line is valid, false if it has been disposed /// public abstract bool IsValid { get; } /// /// Gets the base line /// public abstract double Baseline { get; } /// /// Gets the position of the top edge of this line /// public abstract double Top { get; } /// /// Gets the position of the bottom edge of this line /// public abstract double Bottom { get; } /// /// Gets the position of the left edge of this line /// public abstract double Left { get; } /// /// Gets the position of the right edge of this line /// public abstract double Right { get; } /// /// Gets the width of the line /// public abstract double Width { get; } /// /// Gets the height of the line /// public abstract double Height { get; } /// /// Gets the position of the top edge of the text /// public abstract double TextTop { get; } /// /// Gets the position of the bottom edge of the text /// public abstract double TextBottom { get; } /// /// Gets the position of the left edge of the text /// public abstract double TextLeft { get; } /// /// Gets the position of the right edge of the text /// public abstract double TextRight { get; } /// /// Gets the text width /// public abstract double TextWidth { get; } /// /// Gets the text height /// public abstract double TextHeight { get; } /// /// Get the width of the virtual spaces at the end of this line /// public abstract double VirtualSpaceWidth { get; } /// /// Gets the delta Y between current layout and previous layout /// public abstract double DeltaY { get; } /// /// Gets the width of the end of line character /// public abstract double EndOfLineWidth { get; } /// /// Gets the visibility /// public abstract VSTF.VisibilityState VisibilityState { get; } /// /// Gets the change /// public abstract VSTF.TextViewLineChange Change { get; } /// /// Gets the default line transform /// public abstract VSTF.LineTransform DefaultLineTransform { get; } /// /// Gets the line transform /// public abstract VSTF.LineTransform LineTransform { get; } /// /// Gets the buffer /// public HexBuffer Buffer => BufferLine.Buffer; /// /// Gets the buffer line /// public abstract HexBufferLine BufferLine { get; } /// /// Gets the text shown in this line /// public string Text => BufferLine.Text; /// /// Gets the text span /// public VST.Span TextSpan => BufferLine.TextSpan; /// /// Gets the buffer span /// public HexBufferSpan BufferSpan => BufferLine.BufferSpan; /// /// Gets the start position /// public HexBufferPoint BufferStart => BufferSpan.Start; /// /// Gets the end position /// public HexBufferPoint BufferEnd => BufferSpan.End; /// /// Returns true if lies within this line /// /// Position /// public abstract bool ContainsBufferPosition(HexBufferPoint bufferPosition); /// /// Gets the bounds of an adornment /// /// Identity tag () /// public abstract VSTF.TextBounds? GetAdornmentBounds(object identityTag); /// /// Gets all adornment tags /// /// Provider tag () /// public abstract ReadOnlyCollection GetAdornmentTags(object providerTag); /// /// Gets the line position /// /// x coordinate /// public abstract int? GetLinePositionFromXCoordinate(double xCoordinate); /// /// Gets the line position /// /// x coordinate /// true to return null if it's over an adornment /// public abstract int? GetLinePositionFromXCoordinate(double xCoordinate, bool textOnly); /// /// Gets character bounds /// /// Position /// public abstract VSTF.TextBounds GetCharacterBounds(int linePosition); /// /// Gets extended character bounds, including any adornments /// /// Position /// public abstract VSTF.TextBounds GetExtendedCharacterBounds(int linePosition); /// /// Gets the line position /// /// x coordinate /// public abstract int GetVirtualLinePositionFromXCoordinate(double xCoordinate); /// /// Gets the insertion line position /// /// x coordinate /// public abstract int GetInsertionLinePositionFromXCoordinate(double xCoordinate); /// /// Gets normalized text bounds /// /// Line span /// public Collection GetNormalizedTextBounds(HexLineSpan lineSpan) { if (lineSpan.IsDefault) throw new ArgumentException(); if (lineSpan.IsTextSpan) return GetNormalizedTextBounds(lineSpan.TextSpan!.Value); return GetNormalizedTextBounds(lineSpan.BufferSpan, lineSpan.SelectionFlags!.Value); } /// /// Gets normalized text bounds /// /// Line span /// public abstract Collection GetNormalizedTextBounds(VST.Span lineSpan); /// /// Gets normalized text bounds /// /// Span and selection flags /// public Collection GetNormalizedTextBounds(HexBufferSpanSelection span) => GetNormalizedTextBounds(span.BufferSpan, span.SelectionFlags); /// /// Gets normalized text bounds /// /// Position /// Flags /// public abstract Collection GetNormalizedTextBounds(HexBufferSpan bufferPosition, HexSpanSelectionFlags flags); /// /// Gets the span whose text element index corresponds to the given line position /// /// Position /// public abstract VST.Span GetTextElementSpan(int linePosition); /// /// Returns true if the line intersects with /// /// Span /// public abstract bool IntersectsBufferSpan(HexBufferSpan bufferSpan); } }