Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        internal void OnMouseMove()
        {
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                DockManager.LayoutRootPanel.RootGroupPanel?.HideDropWindow();
                DragTarget = null;
                return;
            }
            bool flag = false;

            _mouseP = DockHelper.GetMousePosition(DockManager);
            foreach (var wnd in DockManager.Windows.Where(w => w is BaseFloatWindow).Cast <BaseFloatWindow>())
            {
                if (wnd != _dragWnd &&
                    wnd.RestoreBounds.Contains(_mouseP) &&
                    !(wnd is DocumentGroupWindow && _dragItem.DragMode == DragMode.Anchor) &&
                    !(wnd is AnchorGroupWindow && _dragItem.DragMode == DragMode.Document))
                {
                    //if (wnd is DocumentGroupWindow)
                    //    if (DockManager.IsBehindToMainWindow(wnd))
                    //        continue;

                    var lflag = false;
                    if (!DockManager.IsAtWindowsIndex(wnd, 1))
                    {
                        //DockManager.MoveFloatTo(wnd);
                        lflag = true;
                    }
                    else if (DockManager.IsBehindToMainWindow(wnd))
                    {
                        lflag = true;
                    }

                    if (lflag)
                    {
                        Win32Helper.BringWindowToTop(wnd.Handle);
                        Win32Helper.BringWindowToTop(_dragWnd.Handle);
                        DockManager.UpdateWindowZOrder();
                    }

                    wnd.HitTest(_mouseP);

                    DockManager.LayoutRootPanel.RootGroupPanel.HideDropWindow();
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                var p = DockHelper.GetMousePositionRelativeTo(DockManager.LayoutRootPanel.RootGroupPanel);
                if (p.X >= 0 && p.Y >= 0 &&
                    p.X <= _rootSize.Width &&
                    p.Y <= _rootSize.Height)
                {
                    if (_dragItem.DragMode != DragMode.Document)
                    {
                        DockManager.LayoutRootPanel.RootGroupPanel?.ShowDropWindow();
                        DockManager.LayoutRootPanel.RootGroupPanel?.Update(_mouseP);
                    }
                    VisualTreeHelper.HitTest(DockManager.LayoutRootPanel.RootGroupPanel, _HitFilter, _HitRessult, new PointHitTestParameters(p));
                }
                else
                {
                    if (_dragItem.DragMode != DragMode.Document)
                    {
                        DockManager.LayoutRootPanel.RootGroupPanel?.HideDropWindow();
                    }
                    DragTarget = null;
                }
            }
        }
Ejemplo n.º 3
0
        internal void OnMouseMove()
        {
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                DockManager.LayoutRootPanel.RootGroupPanel?.HideDropWindow();
                DragTarget = null;
                return;
            }
            bool flag = false;

            _mouseP = DockHelper.GetMousePosition(DockManager);
            foreach (var wnd in DockManager.FloatWindows)
            {
                if (wnd != _dragWnd &&
                    wnd.RestoreBounds.Contains(_mouseP) &&
                    !(wnd is DocumentGroupWindow && _dragItem.DragMode == DragMode.Anchor) &&
                    !(wnd is AnchorGroupWindow && _dragItem.DragMode == DragMode.Document))
                {
                    if (wnd is DocumentGroupWindow)
                    {
                        if (DockManager.IsBehindToMainWindow(wnd))
                        {
                            continue;
                        }
                    }

                    if (wnd != DockManager.FloatWindows.First())
                    {
                        DockManager.MoveFloatTo(wnd);
                        Application.Current.Dispatcher.InvokeAsync(() =>
                        {
                            Win32Helper.BringWindowToTop(wnd.Handle);
                            Win32Helper.BringWindowToTop(_dragWnd.Handle);
                        }, DispatcherPriority.Background);
                    }
                    wnd.HitTest(_mouseP);

                    DockManager.LayoutRootPanel.RootGroupPanel.HideDropWindow();
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                var p = DockHelper.GetMousePositionRelativeTo(DockManager.LayoutRootPanel.RootGroupPanel);
                if (p.X >= 0 && p.Y >= 0 &&
                    p.X <= _rootSize.Width &&
                    p.Y <= _rootSize.Height)
                {
                    if (_dragItem.DragMode != DragMode.Document)
                    {
                        DockManager.LayoutRootPanel.RootGroupPanel?.ShowDropWindow();
                        DockManager.LayoutRootPanel.RootGroupPanel?.Update(_mouseP);
                    }
                    VisualTreeHelper.HitTest(DockManager.LayoutRootPanel.RootGroupPanel, _HitFilter, _HitRessult, new PointHitTestParameters(p));
                }
                else
                {
                    if (_dragItem.DragMode != DragMode.Document)
                    {
                        DockManager.LayoutRootPanel.RootGroupPanel?.HideDropWindow();
                    }
                    DragTarget = null;
                }
            }
        }