Beispiel #1
0
        /// <summary>
        /// Method is invoked by the <see cref="LayoutFloatingWindowControl"/> to update the
        /// current mouse position as the user drags the floating window with the mouse cursor.
        /// </summary>
        /// <param name="dragPosition">The screen coordinates of the current mouse cursor position.</param>
        internal void UpdateMouseLocation(Point dragPosition)
        {
            ////var floatingWindowModel = _floatingWindow.Model as LayoutFloatingWindow;
            // TODO - pass in without DPI adjustment, screen co-ords, adjust inside the target window

            var newHost = _overlayWindowHosts.FirstOrDefault(oh => oh.HitTestScreen(dragPosition));

            if (_currentHost != null || _currentHost != newHost)
            {
                //is mouse still inside current overlay window host?
                if ((_currentHost != null && !_currentHost.HitTestScreen(dragPosition)) ||
                    _currentHost != newHost)
                {
                    //esit drop target
                    if (_currentDropTarget != null)
                    {
                        _currentWindow.DragLeave(_currentDropTarget);
                    }

                    _currentDropTarget = null;

                    //exit area
                    _currentWindowAreas.ForEach(a =>
                                                _currentWindow.DragLeave(a));
                    _currentWindowAreas.Clear();

                    //hide current overlay window
                    if (_currentWindow != null)
                    {
                        _currentWindow.DragLeave(_floatingWindow);
                    }
                    if (_currentHost != null)
                    {
                        _currentHost.HideOverlayWindow();
                    }
                    _currentHost = null;
                }

                if (_currentHost != newHost)
                {
                    _currentHost   = newHost;
                    _currentWindow = _currentHost.ShowOverlayWindow(_floatingWindow);
                    _currentWindow.DragEnter(_floatingWindow);
                }
            }

            if (_currentHost == null)
            {
                return;
            }

            if (_currentDropTarget != null &&
                !_currentDropTarget.HitTestScreen(dragPosition))
            {
                _currentWindow.DragLeave(_currentDropTarget);
                _currentDropTarget = null;
            }

            List <IDropArea> areasToRemove = new List <IDropArea>();

            _currentWindowAreas.ForEach(a =>
            {
                //is mouse still inside this area?
                if (!a.DetectionRect.Contains(a.TransformToDeviceDPI(dragPosition)))
                {
                    _currentWindow.DragLeave(a);
                    areasToRemove.Add(a);
                }
            });

            areasToRemove.ForEach(a =>
                                  _currentWindowAreas.Remove(a));

            var areasToAdd =
                _currentHost.GetDropAreas(_floatingWindow).Where(cw => !_currentWindowAreas.Contains(cw) && cw.DetectionRect.Contains(cw.TransformToDeviceDPI(dragPosition))).ToList();

            _currentWindowAreas.AddRange(areasToAdd);

            areasToAdd.ForEach(a =>
                               _currentWindow.DragEnter(a));

            if (_currentDropTarget == null)
            {
                _currentWindowAreas.ForEach(wa =>
                {
                    if (_currentDropTarget != null)
                    {
                        return;
                    }

                    _currentDropTarget = _currentWindow.GetTargets().FirstOrDefault(dt => dt.HitTestScreen(dragPosition));

                    if (_currentDropTarget != null)
                    {
                        _currentWindow.DragEnter(_currentDropTarget);
                        return;
                    }
                });
            }
        }