internal void IntoDragAction(DragItem dragItem, bool _isInvokeByFloatWnd = false) { DockManager.UpdateWindowZOrder(); _dragItem = dragItem; //被浮动窗口调用则不需要调用BeforeDrag() if (_isInvokeByFloatWnd) { IsDragging = true; if (_dragWnd == null) { _dragWnd = _dragItem.RelativeObj as BaseFloatWindow; } } else { BeforeDrag(); } //初始化最外层的_rootTarget _rootSize = DockManager.LayoutRootPanel.RootGroupPanel.TransformActualSizeToAncestor(); if (!_isInvokeByFloatWnd && _dragWnd is DocumentGroupWindow) { _dragWnd.Recreate(); } }
private void _InitDragItem() { LayoutGroup group; IDockElement ele; var mouseP = DockHelper.GetMousePosition(DockManager); switch (_dragItem.DockMode) { case DockMode.Normal: if (_dragItem.RelativeObj is ILayoutGroup) { var _layoutGroup = _dragItem.RelativeObj as LayoutGroup; #region AttachObj var _parent = _layoutGroup.View.DockViewParent as LayoutGroupPanel; var _mode = _parent.Direction == Direction.Horizontal ? AttachMode.Left : AttachMode.Top; if (_parent.Direction == Direction.None) { _mode = AttachMode.None; } var _index = _parent.IndexOf(_layoutGroup.View); if (_parent.Children.Count - 1 > _index) { _layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent.Children[_index + 2] as INotifyDisposable, _index, _mode); } else { _layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent.Children[_index - 2] as INotifyDisposable, _index, _mode); } #endregion //这里移动的一定是AnchorSideGroup,故将其从父级LayoutGroupPanel移走,但不Dispose留着构造浮动窗口 if ((_layoutGroup.View as ILayoutGroupControl).TryDeatchFromParent(false)) { //注意重新设置Mode (_layoutGroup as BaseLayoutGroup).Mode = DockMode.Float; _dragWnd = new AnchorGroupWindow(DockManager) { Left = mouseP.X - _dragItem.ClickPos.X - 1, Top = mouseP.Y - _dragItem.ClickPos.Y - 1 }; _dragWnd.AttachChild(_layoutGroup.View, AttachMode.None, 0); _dragWnd.Show(); } } else if (_dragItem.RelativeObj is IDockElement) { ele = _dragItem.RelativeObj as IDockElement; #region AttachObj var _parent = (ele.Container as LayoutGroup).View as BaseGroupControl; var _index = ele.Container.IndexOf(ele); #endregion if (ele.IsDocument) { group = new LayoutDocumentGroup(DockMode.Float, DockManager); } else { group = new LayoutGroup(ele.Side, DockMode.Float, DockManager); group.AttachObj = new AttachObject(group, _parent, _index); } //先从逻辑父级中移除 ele.Container.Detach(ele); //再加入新的逻辑父级 group.Attach(ele); //创建新的浮动窗口,并初始化位置 if (ele.IsDocument) { _dragWnd = new DocumentGroupWindow(DockManager); _dragWnd.AttachChild(new LayoutDocumentGroupControl(group), AttachMode.None, 0); _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd = new AnchorGroupWindow(DockManager) { NeedReCreate = _dragItem.DragMode == DragMode.Anchor }; _dragWnd.AttachChild(new AnchorSideGroupControl(group) { IsDraggingFromDock = _dragItem.DragMode == DragMode.Anchor }, AttachMode.None, 0); if (!_dragWnd.NeedReCreate) { _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd.Top = mouseP.Y + _dragItem.ClickPos.Y - _dragWnd.Height; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - Constants.DocumentWindowPadding; } } if (_dragWnd is DocumentGroupWindow) { _dragWnd.Recreate(); } _dragWnd.Show(); } break; case DockMode.DockBar: //这里表示从自动隐藏窗口进行的拖动,因此这里移除自动隐藏窗口 ele = _dragItem.RelativeObj as IDockElement; ele.Container.Detach(ele); //创建新的浮动窗口,并初始化位置 group = new LayoutGroup(ele.Side, DockMode.Float, DockManager); group.Attach(ele); _dragWnd = new AnchorGroupWindow(DockManager) { Left = mouseP.X - _dragItem.ClickPos.X - 1, Top = mouseP.Y - _dragItem.ClickPos.Y - 1 }; _dragWnd.AttachChild(new AnchorSideGroupControl(group), AttachMode.None, 0); _dragWnd.Show(); break; case DockMode.Float: if (_dragItem.RelativeObj is IDockElement) { ele = _dragItem.RelativeObj as IDockElement; var ctrl = ele.Container.View as BaseGroupControl; if (ctrl.Items.Count == 1 && ctrl.Parent is BaseFloatWindow) { _dragWnd = ctrl.Parent as BaseFloatWindow; _dragWnd.DetachChild(ctrl); _dragWnd.Close(); _dragWnd = new DocumentGroupWindow(DockManager); _dragWnd.AttachChild(ctrl, AttachMode.None, 0); _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; _dragWnd.Recreate(); _dragWnd.Show(); } else { #region AttachObj var _parent = (ele.Container as LayoutGroup).View as BaseGroupControl; var _index = ele.Container.IndexOf(ele); #endregion if (ele.IsDocument) { group = new LayoutDocumentGroup(DockMode.Float, DockManager); } else { group = new LayoutGroup(ele.Side, DockMode.Float, DockManager); group.AttachObj = new AttachObject(group, _parent, _index); } //先从逻辑父级中移除 ele.Container.Detach(ele); //再加入新的逻辑父级 group.Attach(ele); //创建新的浮动窗口,并初始化位置 //这里可知引起drag的时DragTabItem故这里创建临时的DragTabWindow if (ele.IsDocument) { _dragWnd = new DocumentGroupWindow(DockManager); _dragWnd.AttachChild(new LayoutDocumentGroupControl(group), AttachMode.None, 0); _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd = new AnchorGroupWindow(DockManager) { NeedReCreate = _dragItem.DragMode == DragMode.Anchor }; _dragWnd.AttachChild(new AnchorSideGroupControl(group) { IsDraggingFromDock = _dragItem.DragMode == DragMode.Anchor }, AttachMode.None, 0); if (!_dragWnd.NeedReCreate) { _dragWnd.Top = mouseP.Y - _dragItem.ClickPos.Y; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - _dragItem.ClickRect.Left - Constants.DocumentWindowPadding; } else { _dragWnd.Top = mouseP.Y + _dragItem.ClickPos.Y - _dragWnd.Height; _dragWnd.Left = mouseP.X - _dragItem.ClickPos.X - Constants.DocumentWindowPadding; } } if (_dragWnd is DocumentGroupWindow) { _dragWnd.Recreate(); } _dragWnd.Show(); } } else if (_dragItem.RelativeObj is ILayoutGroup) { group = _dragItem.RelativeObj as LayoutGroup; //表示此时的浮动窗口为IsSingleMode if (group.View.DockViewParent == null) { _dragWnd = (group.View as BaseGroupControl).Parent as BaseFloatWindow; } else { #region AttachObj var _parent = group.View.DockViewParent as LayoutGroupPanel; var _mode = _parent.Direction == Direction.Horizontal ? AttachMode.Left : AttachMode.Top; if (_parent.Direction == Direction.None) { _mode = AttachMode.None; } var _index = _parent.IndexOf(group.View); if (_parent.Children.Count - 1 > _index) { group.AttachObj = new AttachObject(group, _parent.Children[_index + 2] as INotifyDisposable, _index, _mode); } else { group.AttachObj = new AttachObject(group, _parent.Children[_index - 2] as INotifyDisposable, _index, _mode); } #endregion //这里移动的一定是AnchorSideGroup,故将其从父级LayoutGroupPanel移走,但不Dispose留着构造浮动窗口 if ((group.View as ILayoutGroupControl).TryDeatchFromParent(false)) { _dragWnd = new AnchorGroupWindow(DockManager) { Left = mouseP.X - _dragItem.ClickPos.X - 1, Top = mouseP.Y - _dragItem.ClickPos.Y - 1 }; _dragWnd.AttachChild(group.View, AttachMode.None, 0); _dragWnd.Show(); } } } break; } }