/*
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.Generic;
using System.Collections.ObjectModel;
using dnSpy.Contracts.Hex.Formatting;
namespace dnSpy.Contracts.Hex.Editor {
///
/// Hex view layout changed event args
///
public sealed class HexViewLayoutChangedEventArgs : EventArgs {
///
/// Gets the old view state
///
public HexViewState OldViewState { get; }
///
/// Gets the new view state
///
public HexViewState NewViewState { get; }
///
/// Gets all new or reformatted lines
///
public ReadOnlyCollection NewOrReformattedLines { get; }
///
/// Gets all translated lines
///
public ReadOnlyCollection TranslatedLines { get; }
///
/// true if the layout was translated vertically
///
public bool VerticalTranslation => OldViewState.ViewportTop != NewViewState.ViewportTop;
///
/// true if the layout was translated horizontally
///
public bool HorizontalTranslation => OldViewState.ViewportLeft != NewViewState.ViewportLeft;
///
/// Gets the old version
///
public HexVersion OldVersion => OldViewState.Version;
///
/// Gets the new version
///
public HexVersion NewVersion => NewViewState.Version;
///
/// Gets all new or reformatted spans
///
public NormalizedHexBufferSpanCollection NewOrReformattedSpans => newOrReformattedSpans ??= CreateSpans(NewOrReformattedLines);
NormalizedHexBufferSpanCollection? newOrReformattedSpans;
///
/// Gets all translated spans
///
public NormalizedHexBufferSpanCollection TranslatedSpans => translatedSpans ??= CreateSpans(TranslatedLines);
NormalizedHexBufferSpanCollection? translatedSpans;
static NormalizedHexBufferSpanCollection CreateSpans(ReadOnlyCollection lines) {
if (lines.Count == 0)
return NormalizedHexBufferSpanCollection.Empty;
if (lines.Count == 1)
return new NormalizedHexBufferSpanCollection(lines[0].BufferSpan);
var array = new HexBufferSpan[lines.Count];
for (int i = 0; i < array.Length; i++)
array[i] = lines[i].BufferSpan;
return new NormalizedHexBufferSpanCollection(array);
}
///
/// Constructor
///
/// Old view state
/// New view state
/// New or reformatted lines
/// Translated lines
public HexViewLayoutChangedEventArgs(HexViewState oldState, HexViewState newState, IList newOrReformattedLines, IList translatedLines) {
if (newOrReformattedLines is null)
throw new ArgumentNullException(nameof(newOrReformattedLines));
if (translatedLines is null)
throw new ArgumentNullException(nameof(translatedLines));
OldViewState = oldState ?? throw new ArgumentNullException(nameof(oldState));
NewViewState = newState ?? throw new ArgumentNullException(nameof(newState));
NewOrReformattedLines = new ReadOnlyCollection(newOrReformattedLines);
TranslatedLines = new ReadOnlyCollection(translatedLines);
}
}
}