HexLinePositionInfo(HexLinePositionInfoType type, int position, HexCell cell) { Type = type; Position = position; CellPosition = position - cell.CellSpan.Start; if (CellPosition < 0) throw new ArgumentOutOfRangeException(nameof(position)); Cell = cell; }
public override PositionAndData? EditValueCell(HexCell cell, int cellPosition, char c) { if (cell == null) throw new ArgumentNullException(nameof(cell)); if (cell.BufferSpan.Buffer != Buffer) throw new ArgumentException(); if ((uint)cellPosition >= (uint)cell.CellSpan.Length) throw new ArgumentOutOfRangeException(nameof(cellPosition)); if (!cell.HasData) return null; return valueFormatter.Edit(cell.BufferStart, cellPosition, c); }
public override HexBufferSpan GetValueBufferSpan(HexCell cell, int cellPosition) { if (cell == null) throw new ArgumentNullException(nameof(cell)); if (cellPosition < 0 || cellPosition >= cell.CellSpan.Length) throw new ArgumentOutOfRangeException(nameof(cellPosition)); return valueFormatter.GetBufferSpan(cell.BufferSpan, cellPosition); }
Rect GetCaretRect(HexViewLine line, bool drawOverwriteMode, HexColumnType column, HexCell cell, int cellPosition) { if (cell == null) return new Rect(); int linePosition = cell.CellSpan.Start + Math.Max(0, Math.Min(cell.CellSpan.Length - 1, cellPosition)); if (hexCaret.CurrentPosition.ActiveColumn != column) { var r = ToRect(line.GetNormalizedTextBounds(cell.CellSpan)); return new Rect(r.X, r.Bottom - INACTIVE_CARET_HEIGHT, r.Width, INACTIVE_CARET_HEIGHT); } else if (drawOverwriteMode) { var textBounds = line.GetExtendedCharacterBounds(linePosition); var left = textBounds.Left; var top = line.TextTop; var width = textBounds.Width; var height = line.TextHeight; return new Rect(left, top, width, height); } else { double left; if (linePosition != 0 && linePosition <= line.BufferLine.Text.Length) left = line.GetExtendedCharacterBounds(linePosition - 1).Trailing; else left = line.GetExtendedCharacterBounds(linePosition).Leading; var top = line.TextTop; var width = SystemParameters.CaretWidth; var height = line.TextHeight; return new Rect(left, top, width, height); } }
static int GetLength(int linePosition, HexCell a) { int sl = Math.Abs(linePosition - a.FullSpan.Start); int el = Math.Abs(linePosition - (a.FullSpan.End - 1)); return Math.Min(sl, el); }
static int Compare(int linePosition, HexCell a, HexCell b) { int da = GetLength(linePosition, a); int db = GetLength(linePosition, b); return da - db; }
static KeyValuePair<HexCell, int>? GetVisible(HexCellCollection collection, HexCell cell) { if (cell.HasData) throw new ArgumentException(); for (int i = cell.Index + 1; i < collection.Count; i++) { var c = collection[i]; if (!c.HasData) continue; return new KeyValuePair<HexCell, int>(c, 0); } for (int i = cell.Index - 1; i >= 0; i--) { var c = collection[i]; if (!c.HasData) continue; return new KeyValuePair<HexCell, int>(c, c.CellSpan.Length - 1); } return null; }
TextAndHexSpan Create(HexCellCollection collection, HexCell first, HexCell last, HexBufferSpan bufferSpan) { var firstCellSpan = first.FullSpan; var lastCellSpan = last.FullSpan; var startPos = HexPosition.MaxEndPosition; var endPos = HexPosition.Zero; for (int i = first.Index; i <= last.Index; i++) { var cell = collection[i]; if (!cell.HasData) continue; startPos = HexPosition.Min(startPos, cell.BufferStart); endPos = HexPosition.Max(endPos, cell.BufferEnd); } var resultBufferSpan = startPos <= endPos ? new HexBufferSpan(new HexBufferPoint(Buffer, startPos), new HexBufferPoint(Buffer, endPos)) : bufferSpan; return new TextAndHexSpan(VST.Span.FromBounds(firstCellSpan.Start, lastCellSpan.End), resultBufferSpan); }
/// <summary> /// Edits a value cell. Returns null if editing isn't supported or if the character /// isn't a valid input character (eg. it's not a hex digit character), else it /// returns the position in the buffer and new value. /// </summary> /// <param name="cell">Cell</param> /// <param name="cellPosition">Position within the cell</param> /// <param name="c">Character</param> /// <returns></returns> public abstract PositionAndData? EditValueCell(HexCell cell, int cellPosition, char c);
/// <summary> /// Gets a buffer span within a cell /// </summary> /// <param name="cell">Cell</param> /// <param name="cellPosition">Position within the cell</param> /// <returns></returns> public abstract HexBufferSpan GetValueBufferSpan(HexCell cell, int cellPosition);
HexLinePositionInfo(HexLinePositionInfoType type, int position, int cellPosition) { Type = type; Position = position; CellPosition = cellPosition; Cell = null; }
/// <summary> /// Creates a position within an ASCII cell /// </summary> /// <param name="linePosition">Line position</param> /// <param name="cell">Cell</param> /// <returns></returns> public static HexLinePositionInfo CreateAscii(int linePosition, HexCell cell) { if (linePosition < 0) throw new ArgumentOutOfRangeException(nameof(linePosition)); if (cell == null) throw new ArgumentNullException(nameof(cell)); return new HexLinePositionInfo(HexLinePositionInfoType.AsciiCell, linePosition, cell); }