/*
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 System.Windows;
using VSTE = Microsoft.VisualStudio.Text.Editor;
namespace dnSpy.Contracts.Hex.Editor {
///
/// Adornment layer
///
public abstract class HexAdornmentLayer {
///
/// Constructor
///
protected HexAdornmentLayer() { }
///
/// Gets the UI element
///
public abstract FrameworkElement VisualElement { get; }
///
/// true if the layer is empty
///
public abstract bool IsEmpty { get; }
///
/// Gets/sets the layer opacity
///
public virtual double Opacity {
get => VisualElement.Opacity;
set => VisualElement.Opacity = value;
}
///
/// Gets the hex view
///
public abstract WpfHexView HexView { get; }
///
/// Gets all elements
///
public abstract ReadOnlyCollection Elements { get; }
///
/// Adds an adornment. Returns true if the adornment was added.
///
/// Line
/// Tag
/// Adornment
///
public bool AddAdornment(HexBufferLine line, object? tag, UIElement adornment) =>
AddAdornment(VSTE.AdornmentPositioningBehavior.TextRelative, line, tag, adornment, null);
///
/// Adds an adornment. Returns true if the adornment was added.
///
/// Positioning behavior
/// Line
/// Tag
/// Adornment
/// Called when the adornment is removed
///
public bool AddAdornment(VSTE.AdornmentPositioningBehavior behavior, HexBufferLine line, object? tag, UIElement adornment, VSTE.AdornmentRemovedCallback? removedCallback) {
if (line is null)
throw new ArgumentNullException(nameof(line));
return AddAdornment(behavior, line.BufferSpan, tag, adornment, removedCallback);
}
///
/// Adds an adornment. Returns true if the adornment was added.
///
/// Span
/// Tag
/// Adornment
///
public bool AddAdornment(HexBufferSpan visualSpan, object? tag, UIElement adornment) =>
AddAdornment(VSTE.AdornmentPositioningBehavior.TextRelative, visualSpan, tag, adornment, null);
///
/// Adds an adornment. Returns true if the adornment was added.
///
/// Positioning behavior
/// Span
/// Tag
/// Adornment
/// Called when the adornment is removed
///
public abstract bool AddAdornment(VSTE.AdornmentPositioningBehavior behavior, HexBufferSpan? visualSpan, object? tag, UIElement adornment, VSTE.AdornmentRemovedCallback? removedCallback);
///
/// Removes an adornment
///
/// Adornment to remove
public abstract void RemoveAdornment(UIElement adornment);
///
/// Removes all adornments with the specified tag
///
/// Tag
public abstract void RemoveAdornmentsByTag(object? tag);
///
/// Removes all matching adornments
///
/// Returns true if the adornment should be removed
public abstract void RemoveMatchingAdornments(Predicate match);
///
/// Removes an adornment
///
/// Line
public void RemoveAdornmentsByVisualSpan(HexBufferLine line) =>
RemoveMatchingAdornments(line, returnTruePredicate);
///
/// Removes an adornment
///
/// Span
public void RemoveAdornmentsByVisualSpan(HexBufferSpan visualSpan) =>
RemoveMatchingAdornments(visualSpan, returnTruePredicate);
static readonly Predicate returnTruePredicate = a => true;
///
/// Removes all matching adornments
///
/// Line
/// Returns true if the adornment should be removed
public void RemoveMatchingAdornments(HexBufferLine line, Predicate match) {
if (line is null)
throw new ArgumentNullException(nameof(line));
if (match is null)
throw new ArgumentNullException(nameof(match));
RemoveMatchingAdornments(line.BufferSpan, match);
}
///
/// Removes all matching adornments
///
/// Span
/// Returns true if the adornment should be removed
public abstract void RemoveMatchingAdornments(HexBufferSpan visualSpan, Predicate match);
///
/// Removes all adornments
///
public abstract void RemoveAllAdornments();
}
}