/* 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 dnSpy.Contracts.Command; using dnSpy.Contracts.Hex.Formatting; using VSTE = Microsoft.VisualStudio.Text.Editor; using VSUTIL = Microsoft.VisualStudio.Utilities; namespace dnSpy.Contracts.Hex.Editor { /// /// Hex view /// public abstract class HexView : VSUTIL.IPropertyOwner { /// /// Gets all properties /// public VSUTIL.PropertyCollection Properties { get; } /// /// Gets the hex buffer lines /// public abstract HexBufferLineFormatter BufferLines { get; } /// /// Raised after is changed /// public abstract event EventHandler? BufferLinesChanged; /// /// Gets the command target /// public abstract ICommandTargetCollection CommandTarget { get; } /// /// Gets the caret /// public abstract HexCaret Caret { get; } /// /// Gets the selection /// public abstract HexSelection Selection { get; } /// /// true if the hex view or any of its adornments has focus /// public abstract bool HasAggregateFocus { get; } /// /// true if the mouse is over the view or any of its adornments /// public abstract bool IsMouseOverViewOrAdornments { get; } /// /// Gets the nominal line height /// public abstract double LineHeight { get; } /// /// Gets the x coordinate of the maximum right edge of the text /// public abstract double MaxTextRightCoordinate { get; } /// /// true if the view is in the process of being laid out /// public abstract bool InLayout { get; } /// /// true if the view has closed /// public abstract bool IsClosed { get; } /// /// Gets the editor options /// public abstract VSTE.IEditorOptions Options { get; } /// /// Gets the hex view roles /// public abstract VSTE.ITextViewRoleSet Roles { get; } /// /// Gets the provisional text highlight /// public abstract HexBufferSpan? ProvisionalTextHighlight { get; set; } /// /// Gets the hex buffer /// public abstract HexBuffer Buffer { get; } /// /// Gets viewport top /// public abstract double ViewportTop { get; } /// /// Gets viewport bottom /// public abstract double ViewportBottom { get; } /// /// Gets/sets viewport left /// public abstract double ViewportLeft { get; set; } /// /// Gets viewport right /// public abstract double ViewportRight { get; } /// /// Gets viewport width /// public abstract double ViewportWidth { get; } /// /// Gets viewport height /// public abstract double ViewportHeight { get; } /// /// Gets the view scroller /// public abstract HexViewScroller ViewScroller { get; } /// /// Gets the hex view lines /// public abstract HexViewLineCollection HexViewLines { get; } /// /// Raised after the view is closed /// public abstract event EventHandler? Closed; /// /// Raised when the view or one of its adornments got focus /// public abstract event EventHandler? GotAggregateFocus; /// /// Raised when the view and all its adornments lost focus /// public abstract event EventHandler? LostAggregateFocus; /// /// Raised when the layout is changed /// public abstract event EventHandler? LayoutChanged; /// /// Raised when viewport height is changed /// public abstract event EventHandler? ViewportHeightChanged; /// /// Raised when viewport width is changed /// public abstract event EventHandler? ViewportWidthChanged; /// /// Raised when viewport left is changed /// public abstract event EventHandler? ViewportLeftChanged; /// /// Raised when the mouse has hovered long enough over something in the view /// public abstract event EventHandler? MouseHover; /// /// Constructor /// protected HexView() => Properties = new VSUTIL.PropertyCollection(); /// /// Closes the hex view /// public abstract void Close(); /// /// Displays a line in the view /// /// Position /// Distance relative to the top or bottom of the view /// The public void DisplayHexLineContainingBufferPosition(HexBufferPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo) => DisplayHexLineContainingBufferPosition(bufferPosition, verticalDistance, relativeTo, null, null, DisplayHexLineOptions.None); /// /// Displays a line in the view /// /// Position /// Distance relative to the top or bottom of the view /// The /// Overrides viewport width /// Overrides viewport height public void DisplayHexLineContainingBufferPosition(HexBufferPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo, double? viewportWidthOverride, double? viewportHeightOverride) => DisplayHexLineContainingBufferPosition(bufferPosition, verticalDistance, relativeTo, viewportWidthOverride, viewportHeightOverride, DisplayHexLineOptions.None); /// /// Displays a line in the view /// /// Position /// Distance relative to the top or bottom of the view /// The /// Overrides viewport width /// Overrides viewport height /// Options public abstract void DisplayHexLineContainingBufferPosition(HexBufferPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo, double? viewportWidthOverride, double? viewportHeightOverride, DisplayHexLineOptions options); /// /// Gets a hex view line /// /// Position /// public abstract HexViewLine GetHexViewLineContainingBufferPosition(HexBufferPoint bufferPosition); /// /// Queues a space reservation stack refresh /// public abstract void QueueSpaceReservationStackRefresh(); /// /// Refreshes the screen and clears any read caches /// public abstract void Refresh(); } /// /// changed event args /// public sealed class BufferLinesChangedEventArgs : EventArgs { /// /// Gets the old instance. This value can be null. /// public HexBufferLineFormatter? OldBufferLines { get; } /// /// Gets the new instance. This instance is never null. /// public HexBufferLineFormatter NewBufferLines { get; } /// /// Constructor /// /// Old instance or null /// New instance public BufferLinesChangedEventArgs(HexBufferLineFormatter? oldBufferLines, HexBufferLineFormatter newBufferLines) { OldBufferLines = oldBufferLines; NewBufferLines = newBufferLines ?? throw new ArgumentNullException(nameof(newBufferLines)); } } /// /// Options passed to /// [Flags] public enum DisplayHexLineOptions { /// /// No bit is set /// None = 0, /// /// can be recreated immediately instead of delayed /// CanRecreateBufferLines = 0x00000001, } }