Beispiel #1
0
        private bool Validate(Point point, DockOperation operation, DragAction dragAction, IVisual relativeTo)
        {
            if (_dragControl == null || _dropControl == null)
            {
                return(false);
            }

            if (_dragControl.DataContext is IDockable sourceDockable && _dropControl.DataContext is IDockable targetDockable)
            {
                DockManager.Position       = DockHelpers.ToDockPoint(point);
                DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));
                return(DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: false));
            }

            return(false);
        }
Beispiel #2
0
        private bool Execute(Point point, DockOperation operation, DragAction dragAction, IVisual relativeTo)
        {
            if (_dragControl == null || _dropControl == null)
            {
                return(false);
            }

            if (_dragControl.DataContext is IDockable sourceDockable && _dropControl.DataContext is IDockable targetDockable)
            {
                Debug.WriteLine($"Execute : {point} : {operation} : {dragAction} : {sourceDockable.Title} -> {targetDockable.Title}");
                _dockManager.Position       = DockHelpers.ToDockPoint(point);
                _dockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));
                return(_dockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: true));
            }

            return(false);
        }
Beispiel #3
0
        private bool Validate(Point point, DockOperation operation, DragAction dragAction, IVisual relativeTo)
        {
            if (_targetDropControl == null)
            {
                return(false);
            }

            var layout = _hostWindow.Window.Layout;

            if (layout?.ActiveDockable is IDockable sourceDockable && _targetDropControl.DataContext is IDockable targetDockable)
            {
                _dockManager.Position       = DockHelpers.ToDockPoint(point);
                _dockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));
                return(_dockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: false));
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Process pointer event.
        /// </summary>
        /// <param name="point">The pointer position.</param>
        /// <param name="eventType">The pointer event type.</param>
        public void Process(Point point, EventType eventType)
        {
            switch (eventType)
            {
            case EventType.Pressed:
            {
                bool isDragEnabled = _hostWindow.GetValue(DockProperties.IsDragEnabledProperty);
                if (isDragEnabled != true)
                {
                    break;
                }
                _dragStartPoint    = point;
                _pointerPressed    = true;
                _doDragDrop        = false;
                _targetDockControl = null;
                _targetPoint       = default;
                _targetDropControl = null;
                _dragAction        = DragAction.Move;
            }
            break;

            case EventType.Released:
            {
                if (_doDragDrop == true)
                {
                    if (_targetDockControl != null && _targetDropControl != null)
                    {
                        bool isDropEnabled = true;

                        if (_targetDockControl is IControl targetControl)
                        {
                            isDropEnabled = targetControl.GetValue(DockProperties.IsDropEnabledProperty);
                        }

                        if (isDropEnabled == true)
                        {
                            Drop(_targetPoint, _dragAction, _targetDockControl);
                        }
                    }
                }
                Leave();
                _dragStartPoint    = default;
                _pointerPressed    = false;
                _doDragDrop        = false;
                _targetDockControl = null;
                _targetPoint       = default;
                _targetDropControl = null;
                _dragAction        = DragAction.Move;
            }
            break;

            case EventType.Moved:
            {
                if (_pointerPressed == false)
                {
                    break;
                }

                if (_doDragDrop == false)
                {
                    Vector diff = _dragStartPoint - point;
                    bool   haveMinimumDragDistance = IsMinimumDragDistance(diff);
                    if (haveMinimumDragDistance == true)
                    {
                        _doDragDrop = true;
                    }
                }

                if (_doDragDrop == true)
                {
                    foreach (var visual in DockControl.s_dockControls)
                    {
                        if (visual is DockControl dockControl)
                        {
                            if (dockControl.Layout != _hostWindow.Window?.Layout)
                            {
                                var position         = point + _dragStartPoint;
                                var screenPoint      = new PixelPoint((int)position.X, (int)position.Y);
                                var dockControlPoint = dockControl.PointToClient(screenPoint);
                                if (dockControlPoint == null)
                                {
                                    continue;
                                }
                                var dropControl = DockHelpers.GetControl(dockControl, dockControlPoint, DockProperties.IsDropAreaProperty);
                                if (dropControl != null)
                                {
                                    bool isDropEnabled = dockControl.GetValue(DockProperties.IsDropEnabledProperty);

                                    Debug.WriteLine($"Drop : {dockControlPoint} : {dropControl.Name} : {dropControl.GetType().Name} : {dropControl.DataContext?.GetType().Name}");

                                    if (isDropEnabled)
                                    {
                                        if (_targetDropControl == dropControl)
                                        {
                                            _targetDockControl = dockControl;
                                            _targetPoint       = dockControlPoint;
                                            _targetDropControl = dropControl;
                                            _dragAction        = DragAction.Move;
                                            Over(_targetPoint, _dragAction, _targetDockControl);
                                            break;
                                        }
                                        else
                                        {
                                            if (_targetDropControl != null)
                                            {
                                                Leave();
                                                _targetDropControl = null;
                                            }
                                            _targetDockControl = dockControl;
                                            _targetPoint       = dockControlPoint;
                                            _targetDropControl = dropControl;
                                            _dragAction        = DragAction.Move;
                                            Enter(_targetPoint, _dragAction, _targetDockControl);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        Leave();
                                        _targetDockControl = null;
                                        _targetPoint       = default;
                                        _targetDropControl = null;
                                    }
                                }
                                else
                                {
                                    Leave();
                                    _targetDockControl = null;
                                    _targetPoint       = default;
                                    _targetDropControl = null;
                                    _dragAction        = DragAction.Move;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            break;

            case EventType.Enter:
            {
            }
            break;

            case EventType.Leave:
            {
            }
            break;

            case EventType.CaptureLost:
            {
                _dragStartPoint    = default;
                _pointerPressed    = false;
                _dragStartPoint    = default;
                _targetDockControl = null;
                _targetPoint       = default;
                _targetDropControl = null;
                _dragAction        = default;
            }
            break;

            case EventType.WheelChanged:
            {
            }
            break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Process pointer event.
        /// </summary>
        /// <param name="point">The pointer position.</param>
        /// <param name="delta">The mouse wheel delta.</param>
        /// <param name="eventType">The pointer event type.</param>
        /// <param name="dragAction">The input drag action.</param>
        /// <param name="activeDockControl">The active dock control.</param>
        /// <param name="dockControls">The dock controls.</param>
        public void Process(Point point, Vector delta, EventType eventType, DragAction dragAction, IVisual activeDockControl, IList <IDockControl> dockControls)
        {
            if (!(activeDockControl is IInputElement inputActiveDockControl))
            {
                return;
            }

            switch (eventType)
            {
            case EventType.Pressed:
            {
                var dragControl = DockHelpers.GetControl(inputActiveDockControl, point, DockProperties.IsDragAreaProperty);
                if (dragControl != null)
                {
                    bool isDragEnabled = dragControl.GetValue(DockProperties.IsDragEnabledProperty);
                    if (isDragEnabled != true)
                    {
                        break;
                    }
                    Debug.WriteLine($"Drag : {point} : {eventType} : {dragControl.Name} : {dragControl.GetType().Name} : {dragControl.DataContext?.GetType().Name}");
                    _dragControl       = dragControl;
                    _dropControl       = null;
                    _dragStartPoint    = point;
                    _pointerPressed    = true;
                    _doDragDrop        = false;
                    _targetPoint       = default;
                    _targetDockControl = null;
                    break;
                }
            }
            break;

            case EventType.Released:
            {
                if (_doDragDrop == true)
                {
                    if (_dropControl != null && _targetDockControl != null)
                    {
                        bool isDropEnabled = true;

                        if (_targetDockControl is IControl targetControl)
                        {
                            isDropEnabled = targetControl.GetValue(DockProperties.IsDropEnabledProperty);
                        }

                        if (isDropEnabled == true)
                        {
                            Drop(_targetPoint, dragAction, _targetDockControl);
                        }
                    }
                    else
                    {
                        // TODO: Create window.
                    }
                }
                Leave();
                _dragControl       = null;
                _dropControl       = null;
                _dragStartPoint    = default;
                _pointerPressed    = false;
                _doDragDrop        = false;
                _targetPoint       = default;
                _targetDockControl = null;
            }
            break;

            case EventType.Moved:
            {
                if (_pointerPressed == false)
                {
                    break;
                }

                if (_doDragDrop == false)
                {
                    Vector diff = _dragStartPoint - point;
                    bool   haveMinimumDragDistance = IsMinimumDragDistance(diff);
                    if (haveMinimumDragDistance == true)
                    {
                        if (_dragControl?.DataContext is IDockable targetDockable)
                        {
                            DockHelpers.ShowWindows(targetDockable);
                        }
                        _doDragDrop = true;
                    }
                }

                if (_doDragDrop == true)
                {
                    Point    targetPoint       = default;
                    IVisual? targetDockControl = null;
                    IControl?dropControl       = null;

                    foreach (var dockControl in dockControls)
                    {
                        if (dockControl is IInputElement inputDockControl && inputDockControl != inputActiveDockControl)
                        {
                            var screenPoint      = inputActiveDockControl.PointToScreen(point);
                            var dockControlPoint = (dockControl as IVisual)?.PointToClient(screenPoint);
                            if (dockControlPoint == null)
                            {
                                continue;
                            }
                            dropControl = DockHelpers.GetControl(inputDockControl, dockControlPoint.Value, DockProperties.IsDropAreaProperty);
                            if (dropControl != null)
                            {
                                targetPoint       = dockControlPoint.Value;
                                targetDockControl = inputDockControl;
                                break;
                            }
                        }
                    }

                    if (dropControl == null)
                    {
                        dropControl = DockHelpers.GetControl(inputActiveDockControl, point, DockProperties.IsDropAreaProperty);
                        if (dropControl != null)
                        {
                            targetPoint       = point;
                            targetDockControl = inputActiveDockControl;
                        }
                    }

                    if (dropControl != null && targetDockControl != null)
                    {
                        bool isDropEnabled = true;

                        if (targetDockControl is IControl targetControl)
                        {
                            isDropEnabled = targetControl.GetValue(DockProperties.IsDropEnabledProperty);
                        }

                        Debug.WriteLine($"Drop : {targetPoint} : {eventType} : {dropControl.Name} : {dropControl.GetType().Name} : {dropControl.DataContext?.GetType().Name}");

                        if (isDropEnabled)
                        {
                            if (_dropControl == dropControl)
                            {
                                _targetPoint       = targetPoint;
                                _targetDockControl = targetDockControl;
                                Over(targetPoint, dragAction, targetDockControl);
                            }
                            else
                            {
                                if (_dropControl != null)
                                {
                                    Leave();
                                    _dropControl = null;
                                }

                                _dropControl       = dropControl;
                                _targetPoint       = targetPoint;
                                _targetDockControl = targetDockControl;

                                Enter(targetPoint, dragAction, targetDockControl);
                            }
                        }
                        else
                        {
                            if (_dropControl != null)
                            {
                                Leave();
                                _dropControl       = null;
                                _targetPoint       = default;
                                _targetDockControl = null;
                            }
                        }
                    }
                    else
                    {
                        Leave();
                        _dropControl       = null;
                        _targetPoint       = default;
                        _targetDockControl = null;
                    }
                }
            }
            break;

            case EventType.Enter:
            {
            }
            break;

            case EventType.Leave:
            {
            }
            break;

            case EventType.CaptureLost:
            {
                Leave();
                _dragControl       = null;
                _dropControl       = null;
                _dragStartPoint    = default;
                _pointerPressed    = false;
                _doDragDrop        = false;
                _targetPoint       = default;
                _targetDockControl = null;
            }
            break;

            case EventType.WheelChanged:
            {
            }
            break;
            }
        }