2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Input;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-07-23 12:35:18 +08:00
|
|
|
|
public static class DragAndDropProps
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
#region EnabledForDrag
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty EnabledForDragProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("EnabledForDrag", typeof(bool), typeof(DragAndDropProps),
|
|
|
|
|
|
new FrameworkPropertyMetadata((bool)false,
|
|
|
|
|
|
new PropertyChangedCallback(OnEnabledForDragChanged)));
|
|
|
|
|
|
|
|
|
|
|
|
public static bool GetEnabledForDrag(DependencyObject d)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (bool)d.GetValue(EnabledForDragProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void SetEnabledForDrag(DependencyObject d, bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
d.SetValue(EnabledForDragProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void OnEnabledForDragChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
2023-07-23 12:35:18 +08:00
|
|
|
|
FrameworkElement fe = (FrameworkElement)d;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-07-23 12:35:18 +08:00
|
|
|
|
if ((bool)e.NewValue)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
fe.PreviewMouseDown += Fe_PreviewMouseDown;
|
|
|
|
|
|
fe.MouseMove += Fe_MouseMove;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
fe.PreviewMouseDown -= Fe_PreviewMouseDown;
|
|
|
|
|
|
fe.MouseMove -= Fe_MouseMove;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region DragStartPoint
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty DragStartPointProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("DragStartPoint", typeof(Point?), typeof(DragAndDropProps));
|
|
|
|
|
|
|
|
|
|
|
|
public static Point? GetDragStartPoint(DependencyObject d)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (Point?)d.GetValue(DragStartPointProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void SetDragStartPoint(DependencyObject d, Point? value)
|
|
|
|
|
|
{
|
|
|
|
|
|
d.SetValue(DragStartPointProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
static void Fe_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.LeftButton != MouseButtonState.Pressed)
|
2023-07-23 12:35:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Point? dragStartPoint = GetDragStartPoint((DependencyObject)sender);
|
|
|
|
|
|
var point = e.GetPosition((IInputElement)sender);
|
|
|
|
|
|
if (dragStartPoint == point)
|
|
|
|
|
|
return;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2022-12-04 23:07:20 +08:00
|
|
|
|
if (dragStartPoint.HasValue && ((FrameworkElement)sender).DataContext is ToolBoxData toolBoxData)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
DragObject dataObject = new DragObject();
|
2022-12-04 23:07:20 +08:00
|
|
|
|
dataObject.ContentType = toolBoxData.Type;
|
|
|
|
|
|
dataObject.DesiredSize = toolBoxData.DesiredSize;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
dataObject.DesiredMinSize = toolBoxData.DesiredMinSize;
|
2022-12-04 23:07:20 +08:00
|
|
|
|
dataObject.Icon = toolBoxData.Icon;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
dataObject.Text = toolBoxData.Text;
|
2022-12-04 23:07:20 +08:00
|
|
|
|
dataObject.ColorViewModel = toolBoxData.ColorViewModel;
|
2023-07-29 09:45:50 +08:00
|
|
|
|
//if (toolBoxData.Addition is DesignerItemViewModelBase designerItemViewModelBase)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// dataObject.DesignerItem = designerItemViewModelBase.ToSerializableItem();
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
{
|
|
|
|
|
|
dataObject.DesignerItem = toolBoxData.Addition;
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
DragDrop.DoDragDrop((DependencyObject)sender, dataObject, DragDropEffects.Copy);
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Fe_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetDragStartPoint((DependencyObject)sender, e.GetPosition((IInputElement)sender));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|