using System.Windows;
using System.Windows.Controls;
using CopaData.FileInspector.GUI.TilingPanels.Controls.DragAndDrop;
using CopaData.FileInspector.GUI.TilingPanels.Controls.DropArea;
using CopaData.FileInspector.GUI.TilingPanels.Models;
using CopaData.FileInspector.GUI.ViewModels;
namespace CopaData.FileInspector.GUI.TilingPanels.Controls;
///
/// Control that represents the state of a ,
/// with all the necessary interaction logic tied to it.
///
public class TilingHostControl : DragAndDropControl
{
public TilingHost? Host => DataContext as TilingHost;
static TilingHostControl()
{
DefaultStyleKeyProperty.OverrideMetadata(
typeof(TilingHostControl),
new FrameworkPropertyMetadata(typeof(TilingHostControl)));
}
protected override void OnElementDragOver(DragAndDropData data, UIElement targetElement)
{
SetValue(IsDragTargetPropertyKey, true);
}
protected override void OnElementDragLeave(UIElement targetElement)
{
SetValue(IsDragTargetPropertyKey, false);
}
protected override void OnElementDropped(DragAndDropData data, UIElement targetElement)
{
if (data.DataModel is not TilingFrame frame)
{
// not for us
return;
}
DropDecision decision = (DropDecision)targetElement.GetValue(DropArea.DropArea.DropDecisionProperty);
if (decision == DropDecision.Cancel)
return;
TilingDirection direction = (TilingDirection)decision; // simple cast suffices here
if (direction == TilingDirection.None) {
TilingHost.Insert(TilingManagerViewModel.GlobalRoot, Host!, frame);
} else {
TilingPanel.Attach(TilingManagerViewModel.GlobalRoot, Host!, frame, direction);
}
}
#region Dependency Properties
///
private static readonly DependencyPropertyKey IsDragTargetPropertyKey =
DependencyProperty.RegisterReadOnly(
nameof(IsDragTarget),
typeof(bool),
typeof(TilingHostControl),
new PropertyMetadata(false));
///
public static readonly DependencyProperty IsDragTargetProperty = IsDragTargetPropertyKey.DependencyProperty;
///
/// Whether this is being a potential drop target at the moment.
///
public bool IsDragTarget => (bool)GetValue(IsDragTargetProperty);
#endregion
}