/*
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 VST = Microsoft.VisualStudio.Text;
using VSTA = Microsoft.VisualStudio.Text.Adornments;
namespace dnSpy.Contracts.Hex.Editor {
///
/// Space reservation manager
///
public abstract class HexSpaceReservationManager {
///
/// Constructor
///
protected HexSpaceReservationManager() { }
///
/// Gets all agents
///
public abstract ReadOnlyCollection Agents { get; }
///
/// true if any of the agents' adornments have keyboard focus
///
public abstract bool HasAggregateFocus { get; }
///
/// true if the mouse is over any of the agents' adornments
///
public abstract bool IsMouseOver { get; }
///
/// Raised after an agent has been added or removed from
///
public abstract event EventHandler? AgentChanged;
///
/// Raised after it got aggregate focus
///
public abstract event EventHandler? GotAggregateFocus;
///
/// Raised after it lost aggregate focus
///
public abstract event EventHandler? LostAggregateFocus;
///
/// Adds an agent
///
/// Agent to add
public abstract void AddAgent(HexSpaceReservationAgent agent);
///
/// Creates a popup agent
///
/// Span and selection flags
/// Popup style
/// Popup content
///
public HexSpaceReservationAgent CreatePopupAgent(HexBufferSpanSelection span, VSTA.PopupStyles style, UIElement content) =>
CreatePopupAgent(span.BufferSpan, span.SelectionFlags, style, content);
///
/// Creates a popup agent
///
/// Buffer span
/// Selection flags
/// Popup style
/// Popup content
///
public HexSpaceReservationAgent CreatePopupAgent(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, VSTA.PopupStyles style, UIElement content) =>
CreatePopupAgent(new HexLineSpan(bufferSpan, flags), style, content);
///
/// Creates a popup agent
///
/// Line
/// Line span
/// Popup style
/// Popup content
///
public HexSpaceReservationAgent CreatePopupAgent(HexBufferLine line, VST.Span span, VSTA.PopupStyles style, UIElement content) =>
CreatePopupAgent(new HexLineSpan(line, span), style, content);
///
/// Creates a popup agent
///
/// Line span
/// Popup style
/// Popup content
///
public abstract HexSpaceReservationAgent CreatePopupAgent(HexLineSpan lineSpan, VSTA.PopupStyles style, UIElement content);
///
/// Removes an agent
///
/// Agent to remove
///
public abstract bool RemoveAgent(HexSpaceReservationAgent agent);
///
/// Updates a popup agent
///
/// Popup agent created by
/// Span and selection flags
/// New popup style
public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferSpanSelection span, VSTA.PopupStyles styles) =>
UpdatePopupAgent(agent, span.BufferSpan, span.SelectionFlags, styles);
///
/// Updates a popup agent
///
/// Popup agent created by
/// New buffer span
/// New selection flags
/// New popup style
public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, VSTA.PopupStyles styles) =>
UpdatePopupAgent(agent, new HexLineSpan(bufferSpan, flags), styles);
///
/// Updates a popup agent
///
/// Popup agent created by
/// Line
/// Line span
/// New popup style
public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferLine line, VST.Span span, VSTA.PopupStyles styles) =>
UpdatePopupAgent(agent, new HexLineSpan(line, span), styles);
///
/// Updates a popup agent
///
/// Popup agent created by
/// New line span
/// New popup style
public abstract void UpdatePopupAgent(HexSpaceReservationAgent agent, HexLineSpan lineSpan, VSTA.PopupStyles styles);
}
///
/// Space reservation agent changed event args
///
public sealed class HexSpaceReservationAgentChangedEventArgs : EventArgs {
///
/// Gets the new agent or null
///
public HexSpaceReservationAgent? NewAgent { get; }
///
/// Gets the old agent or null
///
public HexSpaceReservationAgent? OldAgent { get; }
///
/// Constructor
///
/// Old agent or null
/// New agent or null
public HexSpaceReservationAgentChangedEventArgs(HexSpaceReservationAgent? oldAgent, HexSpaceReservationAgent? newAgent) {
NewAgent = newAgent;
OldAgent = oldAgent;
}
}
}