Esempio n. 1
0
        /// <summary>
        /// Function called when dragged window is moved over already docked window</summary>
        /// <param name="sender">Dockable window being dragged</param>
        /// <param name="e">Drag and drop arguments when window is dropped to be docked to dockpanel</param>
        public void DockDragOver(object sender, DockDragDropEventArgs e)
        {
            Point pos = e.MouseEventArgs.GetPosition(this);
            bool  b   = m_dockTabIcon.HitTest(pos);

            if (b && !m_dockTabIcon.Highlight)
            {
                m_dockTabIcon.Highlight = b;
                DockIconsLayer.RemoveChild(m_dockPreviewShape);
                m_dockPreviewShape = null;
                Window    owner = Window.GetWindow(this);
                Rectangle rect  = new Rectangle();
                rect.Fill          = Brushes.RoyalBlue;
                rect.Opacity       = 0.3;
                m_dockPreviewShape = rect;
                double space = 2;
                Point  p     = PointFromScreen(PointToScreen(new Point(space, space)));
                Canvas c     = new Canvas();
                c.SnapsToDevicePixels = true;
                c.Width  = DockedContent.ActualWidth;
                c.Height = DockedContent.ActualHeight;
                Canvas.SetLeft(c, p.X);
                Canvas.SetTop(c, p.Y);
                m_dockPreviewShape.Width  = DockedContent.ActualWidth - space * 2;
                m_dockPreviewShape.Height = DockedContent.ActualHeight - 20 - space * 2;
                Canvas.SetLeft(m_dockPreviewShape, 0);
                Canvas.SetTop(m_dockPreviewShape, 0);
                c.Children.Add(m_dockPreviewShape);

                rect         = new Rectangle();
                rect.Fill    = Brushes.RoyalBlue;
                rect.Opacity = 0.3;
                rect.Width   = Math.Min(DockedContent.ActualWidth / 4, 50);
                rect.Height  = 20;
                Canvas.SetLeft(rect, 0);
                Canvas.SetTop(rect, DockedContent.ActualHeight - 20 - space * 2);
                c.Children.Add(rect);
                m_dockPreviewShape = c;

                DockIconsLayer.InsertChild(0, m_dockPreviewShape);
            }
            else if (!b)
            {
                if (m_dockPreviewShape != null)
                {
                    DockIconsLayer.RemoveChild(m_dockPreviewShape);
                    m_dockPreviewShape = null;
                }
                m_dockTabIcon.Highlight = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Function called when dragged window is moved over already docked window</summary>
        /// <param name="sender">Dockable window being dragged</param>
        /// <param name="e">Drag and drop arguments when window is dropped to be docked to dockpanel</param>
        public void DockDragOver(object sender, DockDragDropEventArgs e)
        {
            DockTo?previousDockPreview = m_dockPreview;

            m_dockPreview = null;
            Point pos = e.MouseEventArgs.GetPosition(Root);

            m_dockLeftIcon.Highlight   = m_dockLeftIcon.HitTest(pos);
            m_dockRightIcon.Highlight  = m_dockRightIcon.HitTest(pos);
            m_dockTopIcon.Highlight    = m_dockTopIcon.HitTest(pos);
            m_dockBottomIcon.Highlight = m_dockBottomIcon.HitTest(pos);
            m_dockTabIcon.Highlight    = m_dockTabIcon.HitTest(pos);

            m_dockPreview = m_dockLeftIcon.Highlight ? DockTo.Left : m_dockPreview;
            m_dockPreview = m_dockRightIcon.Highlight ? DockTo.Right : m_dockPreview;
            m_dockPreview = m_dockTopIcon.Highlight ? DockTo.Top : m_dockPreview;
            m_dockPreview = m_dockBottomIcon.Highlight ? DockTo.Bottom : m_dockPreview;
            m_dockPreview = m_dockTabIcon.Highlight ? DockTo.Center : m_dockPreview;

            if (m_dockPreview != null)
            {
                if (previousDockPreview != m_dockPreview)
                {
                    Root.DockIconsLayer.RemoveChild(m_dockPreviewShape);
                    m_dockPreviewShape = null;
                    Window    owner = Window.GetWindow(this);
                    Rectangle rect  = new Rectangle();
                    rect.Fill    = Brushes.RoyalBlue;
                    rect.Opacity = 0.3;
                    FrameworkElement fe              = rect;
                    double           space           = 2;
                    Point            p               = Root.PointFromScreen(PointToScreen(new Point(space, space)));
                    ContentSettings  contentSettings = (e.Content is TabLayout) ? ((TabLayout)e.Content).Children[0].Settings : ((DockContent)e.Content).Settings;
                    double           width           = Math.Max(Math.Min(contentSettings.Size.Width, ActualWidth / 2), ActualWidth / 5);
                    double           height          = Math.Max(Math.Min(contentSettings.Size.Height, ActualHeight / 2), ActualHeight / 5);
                    double           ratioWidth      = width / ActualWidth;
                    double           ratioHeight     = height / ActualHeight;
                    switch (m_dockPreview)
                    {
                    case DockTo.Left:
                        fe.Width  = ActualWidth * ratioWidth - space * 2;
                        fe.Height = ActualHeight - space * 2;
                        Canvas.SetLeft(fe, p.X);
                        Canvas.SetTop(fe, p.Y);
                        break;

                    case DockTo.Right:
                        fe.Width  = ActualWidth * ratioWidth - space * 2;
                        fe.Height = ActualHeight - space * 2;
                        Canvas.SetLeft(fe, p.X + ActualWidth * (1 - ratioWidth));
                        Canvas.SetTop(fe, p.Y);
                        break;

                    case DockTo.Top:
                        fe.Width  = ActualWidth - space * 2;
                        fe.Height = ActualHeight * ratioHeight - space * 2;
                        Canvas.SetLeft(fe, p.X);
                        Canvas.SetTop(fe, p.Y);
                        break;

                    case DockTo.Bottom:
                        fe.Width  = ActualWidth - space * 2;
                        fe.Height = ActualHeight * ratioHeight - space * 2;
                        Canvas.SetLeft(fe, p.X);
                        Canvas.SetTop(fe, p.Y + ActualHeight * (1 - ratioHeight));
                        break;

                    case DockTo.Center:
                        Canvas c = new Canvas();
                        c.SnapsToDevicePixels = true;
                        c.Width  = ActualWidth;
                        c.Height = ActualHeight;
                        Canvas.SetLeft(c, p.X);
                        Canvas.SetTop(c, p.Y);
                        fe.Width  = ActualWidth - space * 2;
                        fe.Height = ActualHeight - 20 - space * 2;
                        Canvas.SetLeft(fe, 0);
                        Canvas.SetTop(fe, 0);
                        c.Children.Add(fe);

                        rect         = new Rectangle();
                        rect.Fill    = Brushes.RoyalBlue;
                        rect.Opacity = 0.3;
                        rect.Width   = Math.Min(ActualWidth / 4, 50);
                        rect.Height  = 20;
                        Canvas.SetLeft(rect, 0);
                        Canvas.SetTop(rect, ActualHeight - 20 - space * 2);
                        c.Children.Add(rect);
                        fe = c;
                        break;
                    }
                    Root.DockIconsLayer.InsertChild(0, fe);
                    m_dockPreviewShape = fe;
                }
            }
            else
            {
                if (m_dockPreviewShape != null)
                {
                    Root.DockIconsLayer.RemoveChild(m_dockPreviewShape);
                    m_dockPreviewShape = null;
                }
            }
        }