public void Drop(Point dropLocation, out bool dropHandled) { dropHandled = false; UpdateMouseLocation(dropLocation); var floatingWindowModel = _floatingWindow.Model as LayoutFloatingWindow; if (floatingWindowModel != null) { var root = floatingWindowModel.Root; _currentHost?.HideOverlayWindow(); if (_currentDropTarget != null) { _currentWindow.DragDrop(_currentDropTarget); root.CollectGarbage(); dropHandled = true; } } _currentWindowAreas.ForEach(a => _currentWindow.DragLeave(a)); if (_currentDropTarget != null) { _currentWindow.DragLeave(_currentDropTarget); } _currentWindow?.DragLeave(_floatingWindow); _currentWindow = null; _currentHost = null; }
public void UpdateMouseLocation(Point dragPosition) { var floatingWindowModel = _floatingWindow.Model as LayoutFloatingWindow; var newHost = _overlayWindowHosts.FirstOrDefault(oh => oh.HitTest(dragPosition)); if (_currentHost != null || _currentHost != newHost) { //is mouse still inside current overlay window host? if ((_currentHost != null && !_currentHost.HitTest(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.HitTest(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(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(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.HitTest(dragPosition)); if (_currentDropTarget != null) { _currentWindow.DragEnter(_currentDropTarget); return; } }); } }