コード例 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">host window</param>
        public FormsDocker(IWin32Window host)
        {
            _host     = new FormWrapper(host, 14, 4);
            _guider   = new DockGuider(_host);
            _layout   = new DockLayout(_host);
            _autohide = new Autohide(_host, 9, _animationCommand);

            _layout.BeginMoveByMouse       += OnPositionerBeginMoveByMouse;
            _layout.MoveByMouse            += OnPositionerMoveByMouse;
            _layout.EndMoveByMouse         += OnPositionerEndMoveByMouse;
            _layout.DestroyFormsTabbedView += OnDestroyFormsTabbedView;
            _layout.ShowFloatingWindows    += OnShowFloatingWindows;

            _autohide.SetHostContainerDock += OnSetHostContainerDock;

            _guider.ApplyDock    += OnApplyDock;
            _animationTimer.Tick += OnTimedAnimation;

            _animationTimer.Interval = 50;
            _animationTimer.Enabled  = true;

            _focusDetector.ControlGotFocus += OnControlGotFocus;
            _focusDetector.MessageFiltered += OnMessageFiltered;
            Application.AddMessageFilter(_focusDetector);
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">host</param>
        public MarginDockButtons(FormWrapper host)
        {
            _host = host;

            _leftButtonBounds.Size   = _dockLeftGuider.Size;
            _rightButtonBounds.Size  = _dockRightGuider.Size;
            _topButtonBounds.Size    = _dockTopGuider.Size;
            _bottomButtonBounds.Size = _dockBottomGuider.Size;

            _dockLeftGuider.Visible   = false;
            _dockRightGuider.Visible  = false;
            _dockTopGuider.Visible    = false;
            _dockBottomGuider.Visible = false;

            _dockLeftGuider.Text   = "outer left button";
            _dockRightGuider.Text  = "outer right button";
            _dockTopGuider.Text    = "outer top button";
            _dockBottomGuider.Text = "outer bottom button";

            _host.AddFirst(_dockLeftGuider);
            _host.AddFirst(_dockRightGuider);
            _host.AddFirst(_dockTopGuider);
            _host.AddFirst(_dockBottomGuider);

            _host.KeepFirst[0] = _dockLeftGuider;
            _host.KeepFirst[1] = _dockRightGuider;
            _host.KeepFirst[2] = _dockTopGuider;
            _host.KeepFirst[3] = _dockBottomGuider;

            _host.AddToIgnoreOnGetChildFromPoint(_dockLeftGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockRightGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockTopGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockBottomGuider);
        }
コード例 #3
0
        ///// <summary>
        ///// Gets the child leaf window found at given screen location
        ///// </summary>
        ///// <param name="screenPoint">point in screen coordinates</param>
        ///// <param name="parent">parent inside which the child is searched</param>
        ///// <param name="validate">handler to validate if child is included in search</param>
        ///// <param name="containedExcluded">flag indicating that parent contained excluded</param>
        ///// <returns>rectangle from point</returns>
        //private static Control ChildLeafFromPoint(Point screenPoint, FormWrapper parent, ExtractControlHandler validate, out bool containedExcluded)
        //{
        //   containedExcluded = false;

        //   if (parent == null)
        //   {
        //      return null;
        //   }

        //   for (int childIndex = 0; childIndex < parent.ControlsCount; childIndex++)
        //   {
        //      Control child = parent.GetControlAt(childIndex);
        //      if (IgnoreOnGetFromPoint(parent, child))
        //      {
        //         continue;
        //      }

        //      if (child.RectangleToScreen(child.ClientRectangle).Contains(screenPoint) == false)
        //      {
        //         continue;
        //      }

        //      if (validate(child) == false)
        //      {
        //         containedExcluded = true;
        //         continue;
        //      }

        //      FormWrapper childWrapper    = new FormWrapper(child);
        //      bool childContainedExcluded = false;
        //      Control found = ChildLeafFromPoint(screenPoint, childWrapper, validate, out childContainedExcluded);
        //      if (childContainedExcluded)
        //      {
        //         continue;
        //      }

        //      if (found != null)
        //      {
        //         return found;
        //      }

        //      return child;
        //   }

        //   return null;
        //}

        /// <summary>
        /// Check if should ignore the child on get from point
        /// </summary>
        /// <param name="parent">parent</param>
        /// <param name="child">child</param>
        /// <returns></returns>
        private static bool IgnoreOnGetFromPoint(FormWrapper parent, Control child)
        {
            if (child == null)
            {
                return(true);
            }

            if (child.Visible == false)
            {
                return(true);
            }

            Control control = child;

            while (control != null)
            {
                if (parent._ignoreOnGetFromPoint.Contains(control))
                {
                    return(true);
                }

                control = control.Parent;
            }

            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">host</param>
        public DockGuiderWrapper(FormWrapper host)
        {
            _host = host;

            _marginGuiders = new MarginDockButtons(host);
            _centerGuider  = new CenterDockButtons(host);
        }
コード例 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">host window</param>
        public DockGuider(FormWrapper host)
        {
            _host                 = host;
            _host.SizeChanged    += OnHostSizeChanged;
            _host.Move           += OnHostMoved;
            _host.VisibleChanged += OnHostVisibleChanged;

            _guider = new DockGuiderWrapper(_host);
        }
コード例 #6
0
        /// <summary>
        /// Move a window using mouse
        /// </summary>
        public void MoveWindowByMouse()
        {
            if (_movedWindow == null)
            {
                return;
            }

            DockAllowed      allowedDock         = _allowedDock;
            Point            screenLocation      = Control.MousePosition;
            DockingContainer containerUnderMouse = GetContainerUnderMouse(screenLocation);

            Rectangle fillRectangle = FormWrapper.GetFillRectangleFromPoint(screenLocation, containerUnderMouse, _host);

            if (fillRectangle.IsEmpty)
            {
                _guider.HideCenterGuider();
            }
            else
            {
                if (containerUnderMouse == null)
                {
                    _guider.ShowCenterGuider(allowedDock, fillRectangle);
                }
                else
                {
                    allowedDock = DockAllowed.All;
                    _guider.ShowCenterGuider(allowedDock, fillRectangle);
                }
            }


            GuidedDockResult result = _guider.GetDockResult(allowedDock, screenLocation);

            if (result.DockMode == DockableMode.Outer && result.Dock != DockStyle.None)
            {
                Rectangle bounds = OuterDockPreviewEngine.GetPreviewBounds(result.Dock, _host, _movedWindow);
                _guider.ShowPreviewPanel(bounds);
            }
            else if (result.DockMode == DockableMode.Inner && result.Dock != DockStyle.None)
            {
                Rectangle freeBounds = FormWrapper.GetFillScreenRectangle(_host);
                Rectangle bounds     = InnerDockPreviewEngine.GetPreviewBounds(result.Dock, _movedWindow, containerUnderMouse, freeBounds);
                if (bounds.IsEmpty)
                {
                    _guider.HidePreviewPanel();
                }
                else
                {
                    _guider.ShowPreviewPanel(bounds);
                }
            }
            else
            {
                _guider.HidePreviewPanel();
            }
        }
コード例 #7
0
        /// <summary>
        /// Get outer top preview bounds
        /// </summary>
        /// <param name="host">host</param>
        /// <param name="movedPanel">moved panel</param>
        /// <returns>outer top preview bounds</returns>
        private static Rectangle GetOuterTopPreviewBounds(FormWrapper host, Control movedPanel)
        {
            Rectangle marginBounds = host.ScreenClientRectangle;

            if (marginBounds.IsEmpty == false)
            {
                int size = GetPreviewSize(movedPanel, DockStyle.Top);

                return(new Rectangle(marginBounds.Left, marginBounds.Top, marginBounds.Width, size));
            }

            return(new Rectangle());
        }
コード例 #8
0
        /// <summary>
        /// GEt fill screen rectangle
        /// </summary>
        /// <param name="wrapper">wrapper</param>
        /// <returns></returns>
        public static Rectangle GetFillScreenRectangle(FormWrapper wrapper)
        {
            Rectangle clientArea = wrapper.RectangleToClient(GetScreenClientRectangle(wrapper._host));

            int x1 = clientArea.Left;
            int x2 = clientArea.Right;
            int y1 = clientArea.Top;
            int y2 = clientArea.Bottom;

            for (int index = 0; index < wrapper.ControlsCount; index++)
            {
                Control control = wrapper.GetControlAt(index);
                if (control.Dock == DockStyle.None || control.Visible == false)
                {
                    continue;
                }

                if (control.Dock == DockStyle.Left)
                {
                    x1 = Math.Max(x1, control.Right);
                }
                else if (control.Dock == DockStyle.Right)
                {
                    x2 = Math.Min(x2, control.Left);
                }
                else if (control.Dock == DockStyle.Top)
                {
                    y1 = Math.Max(y1, control.Bottom);
                }
                else if (control.Dock == DockStyle.Bottom)
                {
                    y2 = Math.Min(y2, control.Top);
                }
            }

            if (x2 <= x1 || y2 <= y1)
            {
                return(new Rectangle());
            }

            Rectangle result = new Rectangle(x1, y1, x2 - x1, y2 - y1);

            return(wrapper.RectangleToScreen(result));
        }
コード例 #9
0
        /// <summary>
        /// Get preview bounds
        /// </summary>
        /// <param name="dock">dock for which to get the preview bounds</param>
        /// <param name="host">host</param>
        /// <param name="movedPanel">moved panel</param>
        /// <returns>preview bounds</returns>
        public static Rectangle GetPreviewBounds(DockStyle dock, FormWrapper host, Control movedPanel)
        {
            switch (dock)
            {
            case DockStyle.Left:
                return(GetOuterLeftPreviewBounds(host, movedPanel));

            case DockStyle.Right:
                return(GetOuterRightPreviewBounds(host, movedPanel));

            case DockStyle.Top:
                return(GetOuterTopPreviewBounds(host, movedPanel));

            case DockStyle.Bottom:
                return(GetOuterBottomPreviewBounds(host, movedPanel));

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">host</param>
        /// <param name="firstControlOffset">offset for first control</param>
        /// <param name="animationCommand">animation command</param>
        public Autohide(FormWrapper host, int firstControlOffset, Command animationCommand)
        {
            _host               = host;
            _animationCommand   = animationCommand;
            _firstControlOffset = firstControlOffset;

            _previewPane.Visible = false;
            _host.AddFirst(_previewPane);
            _host.KeepFirst[4 + _firstControlOffset] = _previewPane;

            _previewPane.BackColor = Color.Black;

            _host.SizeChanged    += OnHostSizeChanged;
            _host.VisibleChanged += OnHostVisibleChanged;

            LeftAutohideButtons.Visible   = false;
            RightAutohideButtons.Visible  = false;
            TopAutohideButtons.Visible    = false;
            BottomAutohideButtons.Visible = false;
            ArrangeAutoButtonsPanels();
        }
コード例 #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">host</param>
        public CenterDockButtons(FormWrapper host)
        {
            _host = host;

            _leftButtonBounds.Size   = _dockLeftGuider.Size;
            _rightButtonBounds.Size  = _dockRightGuider.Size;
            _topButtonBounds.Size    = _dockTopGuider.Size;
            _bottomButtonBounds.Size = _dockBottomGuider.Size;
            _fillButtonBounds.Size   = _dockFillGuider.FillSize;

            _dockLeftGuider.Visible   = false;
            _dockRightGuider.Visible  = false;
            _dockTopGuider.Visible    = false;
            _dockBottomGuider.Visible = false;
            _dockFillGuider.Visible   = false;

            _dockLeftGuider.Text   = "inner left button";
            _dockRightGuider.Text  = "inner right button";
            _dockTopGuider.Text    = "inner top button";
            _dockBottomGuider.Text = "inner bottom button";
            _dockFillGuider.Text   = "inner fill button";

            _host.AddFirst(_dockLeftGuider);
            _host.AddFirst(_dockRightGuider);
            _host.AddFirst(_dockTopGuider);
            _host.AddFirst(_dockBottomGuider);
            _host.AddFirst(_dockFillGuider);

            _host.KeepFirst[4] = _dockLeftGuider;
            _host.KeepFirst[5] = _dockRightGuider;
            _host.KeepFirst[6] = _dockTopGuider;
            _host.KeepFirst[7] = _dockBottomGuider;
            _host.KeepFirst[8] = _dockFillGuider;

            _host.AddToIgnoreOnGetChildFromPoint(_dockLeftGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockRightGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockTopGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockBottomGuider);
            _host.AddToIgnoreOnGetChildFromPoint(_dockFillGuider);
        }
コード例 #12
0
        /// <summary>
        /// Dock the form in host
        /// </summary>
        /// <param name="containerToDock">container to dock</param>
        /// <param name="dock">dock</param>
        /// <param name="mode">mode</param>
        private void DockInHost(DockingContainer container, DockStyle dock, DockableMode mode)
        {
            Rectangle availableBounds = FormWrapper.GetFillScreenRectangle(_host);

            container.SingleChild.SaveFloatingSize();
            container.Splitter.Visible = false;

            if (_host.Contains(container.Splitter) == false && dock != DockStyle.Fill)
            {
                _host.AddLast(container.Splitter);
            }

            if (mode == DockableMode.Inner)
            {
                if (dock != DockStyle.Fill)
                {
                    _host.MoveFirst(container);
                    _host.MoveFirst(container.Splitter);
                }
            }
            else
            {
                if (dock != DockStyle.Fill)
                {
                    _host.MoveLast(container.Splitter);
                    _host.MoveLast(container);
                }
            }

            container.Dock = dock;

            if (dock != DockStyle.Fill)
            {
                container.Splitter.Dock    = dock;
                container.Splitter.Visible = true;
            }
            else
            {
                container.SingleChild.ButtonsRenderer = new TopUnitButtonDrawer();
            }

            // Must call this again after splitter is docked and made visible, to have proper splitter.
            // Must have this if/else block also before making the splitter visible to prevent flickering
            if (mode == DockableMode.Inner)
            {
                if (dock != DockStyle.Fill)
                {
                    _host.MoveFirst(container);
                    _host.MoveFirst(container.Splitter);

                    if (availableBounds.IsEmpty == false)
                    {
                        if (dock == DockStyle.Left || dock == DockStyle.Right)
                        {
                            if (container.Width >= availableBounds.Width - MinAvailableSize)
                            {
                                container.Width = availableBounds.Width - MinAvailableSize;
                            }
                        }
                        else if (dock == DockStyle.Top || dock == DockStyle.Bottom)
                        {
                            if (container.Height >= availableBounds.Height - MinAvailableSize)
                            {
                                container.Height = availableBounds.Height - MinAvailableSize;
                            }
                        }
                    }
                }
            }
            else
            {
                if (dock != DockStyle.Fill)
                {
                    _host.MoveLast(container.Splitter);
                    _host.MoveLast(container);
                }
            }

            SetViewDock(container.SingleChild, dock, dock, mode);
        }
コード例 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="host">host window</param>
 public DockLayout(FormWrapper host)
 {
     _host = host;
 }
コード例 #14
0
        /// <summary>
        /// Get the fill rectangle of the control in screen coordinates
        /// </summary>
        /// <param name="window">window</param>
        /// <returns>fill screen rectangle</returns>
        public static Rectangle GetFillScreenRectangle(Control window)
        {
            FormWrapper wrapper = new FormWrapper(window);

            return(GetFillScreenRectangle(wrapper));
        }
コード例 #15
0
        /// <summary>
        /// Gets the fill rectangle based on a point
        /// </summary>
        /// <param name="screenPoint">point in screen coordinates</param>
        /// <returns>rectangle from point</returns>
        public static Rectangle GetFillRectangleFromPoint(Point screenPoint, Control underPoint, FormWrapper host)
        {
            if (underPoint == null)
            {
                if (host != null)
                {
                    return(GetFillScreenRectangle(host));
                }

                return(new Rectangle());
            }

            Rectangle result = GetFillScreenRectangle(underPoint);

            if (result.Contains(screenPoint) == false)
            {
                return(new Rectangle());
            }

            return(result);
        }