Esempio n. 1
0
        /// <summary>
        /// Handles mouse move events when the drag operation is in progress.
        /// </summary>
        private void Drag()
        {
            Debug.Assert(IsDragging);

            if (!_dragDeltaExceeded)
            {
                Point  mousePosition = WindowsHelper.GetMousePosition(_dockControl);
                Vector dragDelta     = mousePosition - _initialMousePosition;
                if (Math.Abs(dragDelta.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(dragDelta.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    _dragDeltaExceeded = true;
                }
                else
                {
                    // Do nothing.
                    return;
                }
            }

            if (_targetDockTabPane != null && IsMouseOver(_targetDockTabPane.GetItemsPanel(), VerticalTolerance))
            {
                // Drag items inside a DockTabPanel.
                DragDockTabItems();
                return;
            }

            if (_floatWindow == null)
            {
                // Move the items into a FloatWindow.
                DragDockTabItemsIntoFloatWindow();
            }

            // Move the FloatWindow to the mouse position.
            DragFloatWindow();

            // Show DockIndicators and check possible dock positions.
            UpdateDockIndicators();

            if (!HasResult(_paneDockIndicators) && !HasResult(_borderDockIndicators))
            {
                // Check whether mouse cursor is over other DockTabItem tab and
                // move items into DockTabPane.
                DragFloatWindowIntoDockTabPanel();
            }
        }
        /// <summary>
        /// Gets the <see cref="DockTabItem"/> at the mouse position by testing against the
        /// <see cref="DockTabItem"/> tabs in the specified pane.
        /// </summary>
        /// <param name="dockTabPane">The <see cref="DockTabPane"/>.</param>
        /// <param name="verticalTolerance">
        /// The tolerance (margin at top and bottom) in pixels.
        /// </param>
        /// <returns>The <see cref="DockTabItem"/> under the mouse cursor.</returns>
        private static DockTabItem GetDockTabItemAtMouse(DockTabPane dockTabPane, double verticalTolerance = 0)
        {
            Debug.Assert(dockTabPane != null);

            if (dockTabPane.Items.Count == 0)
            {
                return(null);    // Empty DockTabPane.
            }
            var itemsPanel = dockTabPane.GetItemsPanel();

            if (itemsPanel == null)
            {
                return(null);    // ItemsPanel missing.
            }
            Point mousePosition = WindowsHelper.GetMousePosition(itemsPanel);

            Rect bounds = new Rect(itemsPanel.RenderSize);

            bounds.Inflate(0, verticalTolerance);
            if (!bounds.Contains(mousePosition))
            {
                return(null);    // Mouse position outside ItemsPanel.
            }
            // Test mouse position against DockTabItems bounds.
            double height = itemsPanel.RenderSize.Height;
            double x      = 0;

            for (int i = 0; i < dockTabPane.Items.Count; i++)
            {
                var dockTabItem = dockTabPane.ItemContainerGenerator.ContainerFromIndex(i) as DockTabItem;
                if (dockTabItem == null)
                {
                    break;
                }

                bounds = new Rect(new Point(x, 0), new Size(dockTabItem.RenderSize.Width, height));
                bounds.Inflate(0, verticalTolerance);
                if (bounds.Contains(mousePosition))
                {
                    return(dockTabItem);
                }

                x += bounds.Width;
            }

            return(null);
        }
        /// <summary>
        /// Gets the <see cref="DockTabItem"/> at the mouse position by testing against the
        /// <see cref="DockTabItem"/> tabs in the specified pane.
        /// </summary>
        /// <param name="dockTabPane">The <see cref="DockTabPane"/>.</param>
        /// <param name="verticalTolerance">
        /// The tolerance (margin at top and bottom) in pixels.
        /// </param>
        /// <returns>The <see cref="DockTabItem"/> under the mouse cursor.</returns>
        private static DockTabItem GetDockTabItemAtMouse(DockTabPane dockTabPane, double verticalTolerance = 0)
        {
            Debug.Assert(dockTabPane != null);

            if (dockTabPane.Items.Count == 0)
                return null;    // Empty DockTabPane.

            var itemsPanel = dockTabPane.GetItemsPanel();
            if (itemsPanel == null)
                return null;    // ItemsPanel missing.

            Point mousePosition = WindowsHelper.GetMousePosition(itemsPanel);

            Rect bounds = new Rect(itemsPanel.RenderSize);
            bounds.Inflate(0, verticalTolerance);
            if (!bounds.Contains(mousePosition))
                return null;    // Mouse position outside ItemsPanel.

            // Test mouse position against DockTabItems bounds.
            double height = itemsPanel.RenderSize.Height;
            double x = 0;
            for (int i = 0; i < dockTabPane.Items.Count; i++)
            {
                var dockTabItem = dockTabPane.ItemContainerGenerator.ContainerFromIndex(i) as DockTabItem;
                if (dockTabItem == null)
                    break;

                bounds = new Rect(new Point(x, 0), new Size(dockTabItem.RenderSize.Width, height));
                bounds.Inflate(0, verticalTolerance);
                if (bounds.Contains(mousePosition))
                    return dockTabItem;

                x += bounds.Width;
            }

            return null;
        }