/* 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.Hex.Formatting; namespace dnSpy.Contracts.Hex.Editor { /// /// Hex caret /// public abstract class HexCaret { /// /// Constructor /// protected HexCaret() { } /// /// true if the caret in the values column is present /// public abstract bool IsValuesCaretPresent { get; } /// /// true if the caret in the ASCII column is present /// public abstract bool IsAsciiCaretPresent { get; } /// /// Gets the position of the top edge of the caret in the values column /// public abstract double ValuesTop { get; } /// /// Gets the position of the bottom edge of the caret in the values column /// public abstract double ValuesBottom { get; } /// /// Gets the position of the left edge of the caret in the values column /// public abstract double ValuesLeft { get; } /// /// Gets the position of the right edge of the caret in the values column /// public abstract double ValuesRight { get; } /// /// Gets the width of the caret in the values column /// public abstract double ValuesWidth { get; } /// /// Gets the height of the caret in the values column /// public abstract double ValuesHeight { get; } /// /// Gets the position of the top edge of the caret in the ASCII column /// public abstract double AsciiTop { get; } /// /// Gets the position of the bottom edge of the caret in the ASCII column /// public abstract double AsciiBottom { get; } /// /// Gets the position of the left edge of the caret in the ASCII column /// public abstract double AsciiLeft { get; } /// /// Gets the position of the right edge of the caret in the ASCII column /// public abstract double AsciiRight { get; } /// /// Gets the width of the caret in the ASCII column /// public abstract double AsciiWidth { get; } /// /// Gets the height of the caret in the ASCII column /// public abstract double AsciiHeight { get; } /// /// true if the caret is hidden, false if it's visible /// public abstract bool IsHidden { get; set; } /// /// Gets the containing hex view line /// public abstract HexViewLine ContainingHexViewLine { get; } /// /// true if it's overwrite mode /// public abstract bool OverwriteMode { get; } /// /// Gets the position /// public abstract HexCaretPosition Position { get; } /// /// Raised after the position is changed by calling one of the MoveTo methods /// public abstract event EventHandler? PositionChanged; /// /// Brings the caret into view /// public abstract void EnsureVisible(); /// /// Toggles the active column /// /// public abstract HexCaretPosition ToggleActiveColumn(); /// /// Moves the caret to a new position /// /// Position /// public HexCaretPosition MoveTo(HexBufferPoint position) => MoveTo(Position.Position.ActiveColumn, position); /// /// Moves the caret to a new position /// /// Column /// Position /// public HexCaretPosition MoveTo(HexColumnType column, HexBufferPoint position) => MoveTo(column, position, HexMoveToFlags.CaptureHorizontalPosition); /// /// Moves the caret to a new position /// /// Column /// Position /// Flags /// public abstract HexCaretPosition MoveTo(HexColumnType column, HexBufferPoint position, HexMoveToFlags flags); /// /// Moves the caret to a new position /// /// Position /// public HexCaretPosition MoveTo(HexCellPosition position) => MoveTo(position, HexMoveToFlags.CaptureHorizontalPosition); /// /// Moves the caret to a new position /// /// Position /// Flags /// public abstract HexCaretPosition MoveTo(HexCellPosition position, HexMoveToFlags flags); /// /// Moves the caret to a new position /// /// Position /// public HexCaretPosition MoveTo(HexColumnPosition position) => MoveTo(position, HexMoveToFlags.CaptureHorizontalPosition); /// /// Moves the caret to a new position /// /// Position /// Flags /// public abstract HexCaretPosition MoveTo(HexColumnPosition position, HexMoveToFlags flags); /// /// Moves the caret to a new position /// /// Line /// public abstract HexCaretPosition MoveTo(HexViewLine hexLine); /// /// Moves the caret to a new position /// /// Line /// Flags /// public abstract HexCaretPosition MoveTo(HexViewLine hexLine, HexMoveToFlags flags); /// /// Moves the caret to a new position /// /// Line /// X coordinate /// public abstract HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate); /// /// Moves the caret to a new position /// /// Line /// X coordinate /// Flags /// public abstract HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate, HexMoveToFlags flags); /// /// Moves the caret to the previous position /// /// public abstract HexCaretPosition MoveToPreviousCaretPosition(); /// /// Moves the caret to the next position /// /// public abstract HexCaretPosition MoveToNextCaretPosition(); /// /// Moves the caret to the preferred x and y coordinates /// /// public abstract HexCaretPosition MoveToPreferredCoordinates(); } /// /// Flags passed to eg. /// [Flags] public enum HexMoveToFlags { /// /// No bit is set /// None = 0, /// /// Capture horizontal position /// CaptureHorizontalPosition = 0x00000001, /// /// Get the character position by finding the character closest to the x coordinate /// InsertionPosition = 0x00000002, } /// /// Caret position changed event args /// public sealed class HexCaretPositionChangedEventArgs : EventArgs { /// /// Gets the hex view /// public HexView HexView { get; } /// /// Gets the old position /// public HexCaretPosition OldPosition { get; } /// /// Gets the new position /// public HexCaretPosition NewPosition { get; } /// /// Constructor /// /// Hex view /// Old position /// New position public HexCaretPositionChangedEventArgs(HexView hexView, HexCaretPosition oldPosition, HexCaretPosition newPosition) { if (oldPosition.IsDefault) throw new ArgumentException(); if (newPosition.IsDefault) throw new ArgumentException(); HexView = hexView ?? throw new ArgumentNullException(nameof(hexView)); OldPosition = oldPosition; NewPosition = newPosition; } } }