/// <summary> /// Add form to guider /// </summary> /// <param name="form">form to guide</param> /// <param name="allowedDock">allowed dock</param> /// <param name="formIdentifier">identifier of the form added</param> /// <returns>object that encapsulates relevant information for the guided form</returns> public DockableFormInfo Add(Form form, DockAllowed allowedDock, Guid formIdentifier) { if (GetFormInfo(form) != null) { throw new ArgumentException("Err"); } // Should set the border as None to prevent Microsoft bug in TextBox: // TextBox on Form with TopLevel = False and FormBorderStyle != None doesn't process Click event form.FormBorderStyle = FormBorderStyle.None; Rectangle bounds = form.Bounds; DockableFormInfo info = new DockableFormInfo(form, allowedDock, formIdentifier); info.ExplicitDisposing += OnInfoDisposing; info.SelectedChanged += OnFormSelectedChanged; info.ShowAutoPanel += OnShowFormAutoPanel; _dockableForms.Add(info); FormsTabbedView view = CreateFormsTabbedView(bounds.Size, null); view.Add(info); _layout.CreateFloatingContainer(view, bounds); return(info); }
/// <summary> /// Shows the buttons to dock in the center of the view rectangle /// </summary> /// <param name="allowedDockMode">allowed dock mode</param> /// <param name="viewScreenRectangle">view rectangle in which the buttons to dock will be shown (in screen coordinates)</param> public void Show(DockAllowed allowedDockMode) { UpdateButtonsBounds(); _dockLeftGuider.Location = _leftButtonBounds.Location; _dockRightGuider.Location = _rightButtonBounds.Location; _dockTopGuider.Location = _topButtonBounds.Location; _dockBottomGuider.Location = _bottomButtonBounds.Location; if (EnumUtility.Contains(allowedDockMode, DockAllowed.Left)) { _dockLeftGuider.Visible = true;; } if (EnumUtility.Contains(allowedDockMode, DockAllowed.Right)) { _dockRightGuider.Visible = true; } if (EnumUtility.Contains(allowedDockMode, DockAllowed.Top)) { _dockTopGuider.Visible = true; } if (EnumUtility.Contains(allowedDockMode, DockAllowed.Bottom)) { _dockBottomGuider.Visible = true;; } }
/// <summary> /// End window movement /// </summary> public void EndWindowMovement() { if (_movedWindow == null) { return; } Point screenLocation = Control.MousePosition; DockAllowed allowedDock = _allowedDock; if (GetContainerUnderMouse(screenLocation) != null) { allowedDock = DockAllowed.All; } GuidedDockResult result = _guider.GetDockResult(allowedDock, screenLocation); Control movedControl = _movedWindow; StopMovement(); _movedWindow = null; EventHandler <DockControlEventArgs> handler = ApplyDock; if (handler != null && result.Dock != DockStyle.None) { DockControlEventArgs args = new DockControlEventArgs(movedControl, result.Dock, result.DockMode); handler(this, args); } }
/// <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(); } }
/// <summary> /// Begin the movement of a window /// </summary> /// <param name="window">moved window</param> /// <param name="allowedDock">allowed dock for the window</param> public void BeginWindowMovement(Control window, DockAllowed allowedDock) { if (_movedWindow != null) { throw new InvalidOperationException("Err001"); } _movedWindow = window; _allowedDock = allowedDock; GuideForm(); }
/// <summary> /// Gets the dock result for given screen location /// </summary> /// <param name="allowedDockMode">allowed dock mode</param> /// <param name="screenLocation">screen location</param> /// <returns>dock result</returns> public GuidedDockResult GetDockResult(DockAllowed allowedDockMode, Point screenLocation) { ValidateNotDisposed(); _dockResult.Dock = DockStyle.None; _dockResult.DockMode = DockableMode.Outer; Point clientLocation = _host.PointToClient(screenLocation); if (_marginGuiders.LeftButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Left)) { _dockResult.Dock = DockStyle.Left; } else if (_marginGuiders.RightButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Right)) { _dockResult.Dock = DockStyle.Right; } else if (_marginGuiders.TopButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Top)) { _dockResult.Dock = DockStyle.Top; } else if (_marginGuiders.BottomButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Bottom)) { _dockResult.Dock = DockStyle.Bottom; } else if (_centerGuider.IsVisible) { _dockResult.DockMode = DockableMode.Inner; if (_centerGuider.LeftButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Left)) { _dockResult.Dock = DockStyle.Left; } else if (_centerGuider.TopButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Top)) { _dockResult.Dock = DockStyle.Top; } else if (_centerGuider.RightButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Right)) { _dockResult.Dock = DockStyle.Right; } else if (_centerGuider.BottomButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Bottom)) { _dockResult.Dock = DockStyle.Bottom; } else if (_centerGuider.FillButtonBounds.Contains(clientLocation) && EnumUtility.Contains(allowedDockMode, DockAllowed.Fill)) { _dockResult.Dock = DockStyle.Fill; } } return(_dockResult); }
/// <summary> /// Shows the buttons to dock in the center of the view rectangle /// </summary> /// <param name="allowedDockMode">allowed dock mode</param> /// <param name="viewScreenRectangle">view rectanlge in the center of which the buttons to dock will be shown (in screen coordinates)</param> public void Show(DockAllowed allowedDockMode, Rectangle viewScreenRectangle) { ValidateNotDisposed(); UpdateGuiderBounds(allowedDockMode, viewScreenRectangle); _dockLeftGuider.Visible = EnumUtility.Contains(allowedDockMode, DockAllowed.Left); _dockRightGuider.Visible = EnumUtility.Contains(allowedDockMode, DockAllowed.Right); _dockTopGuider.Visible = EnumUtility.Contains(allowedDockMode, DockAllowed.Top); _dockBottomGuider.Visible = EnumUtility.Contains(allowedDockMode, DockAllowed.Bottom); _dockFillGuider.Visible = true; _dockFillGuider.ShowFillPreview = EnumUtility.Contains(allowedDockMode, DockAllowed.Fill); }
internal DockableFormInfo(Form form, DockAllowed allowedDock, Guid identifier) { if (identifier == Guid.Empty) { throw new ArgumentException("Err"); } _identifier = identifier; _dockableForm = form; _allowedDock = allowedDock; _button = new UnitButton(form); _button.ExplicitDisposing += OnButtonDisposing; form.GotFocus += OnFormGotFocus; }
/// <summary> /// Update the bounds of the buttons /// </summary> /// <param name="allowedDockMode">allowed dock mode</param> /// <param name="viewScreenRectangle">view rectanlge in the center of which the buttons to dock will be shown (in screen coordinates)</param> public void UpdateGuiderBounds(DockAllowed allowedDockMode, Rectangle viewScreenRectangle) { ValidateNotDisposed(); Rectangle viewRectangle = _host.RectangleToClient(viewScreenRectangle); if (_lastAllowedDockMode == allowedDockMode && _lastViewRectangle == viewRectangle) { return; } _lastViewRectangle = viewRectangle; _lastAllowedDockMode = allowedDockMode; int width = viewRectangle.Width; int height = viewRectangle.Height; Point center = new Point(width / 2, height / 2); Point offset = viewRectangle.Location; Point fillPosition = new Point(center.X - _dockFillGuider.Width / 2, center.Y - _dockFillGuider.Height / 2); Point leftPosition = new Point(fillPosition.X - _dockLeftGuider.Width + 7, center.Y - _dockLeftGuider.Height / 2); Point topPosition = new Point(center.X - _dockTopGuider.Width / 2 - 1, fillPosition.Y - _dockTopGuider.Height + 7); Point rightPosition = new Point(fillPosition.X + _dockFillGuider.Width - 7, center.Y - _dockRightGuider.Height / 2); Point bottomPosition = new Point(center.X - _dockBottomGuider.Width / 2, fillPosition.Y + _dockBottomGuider.Height + 7); fillPosition.Offset(offset); leftPosition.Offset(offset); rightPosition.Offset(offset); topPosition.Offset(offset); bottomPosition.Offset(offset); _dockLeftGuider.Location = leftPosition; _dockRightGuider.Location = rightPosition; _dockTopGuider.Location = topPosition; _dockBottomGuider.Location = bottomPosition; _dockFillGuider.Location = fillPosition; bool dockLeftGuiderVisible = EnumUtility.Contains(allowedDockMode, DockAllowed.Left); bool dockRightGuiderVisible = EnumUtility.Contains(allowedDockMode, DockAllowed.Right); bool dockTopGuiderVisible = EnumUtility.Contains(allowedDockMode, DockAllowed.Top); bool dockBottomGuiderVisible = EnumUtility.Contains(allowedDockMode, DockAllowed.Bottom); bool dockFillGuiderShowFillPreview = EnumUtility.Contains(allowedDockMode, DockAllowed.Fill); _guiderBounds.X = _dockFillGuider.Left; if (dockLeftGuiderVisible) { _guiderBounds.X = _dockLeftGuider.Left; } _guiderBounds.Y = _dockFillGuider.Top; if (dockTopGuiderVisible) { _guiderBounds.Y = _dockTopGuider.Top; } int right = _dockFillGuider.Right; if (dockRightGuiderVisible) { right = _dockRightGuider.Right; } _guiderBounds.Width = right - _guiderBounds.Left; int bottom = _dockFillGuider.Bottom; if (dockBottomGuiderVisible) { bottom = _dockBottomGuider.Bottom; } _guiderBounds.Height = bottom - _guiderBounds.Top; _leftButtonBounds.Location = leftPosition; _rightButtonBounds.Location = rightPosition; _topButtonBounds.Location = topPosition; _bottomButtonBounds.Location = bottomPosition; _fillButtonBounds = _dockFillGuider.FillBounds; _fillButtonBounds.X += _dockFillGuider.Left; _fillButtonBounds.Y += _dockFillGuider.Top; }
/// <summary> /// Add form to guider /// </summary> /// <param name="form">form to guide</param> /// <param name="allowedDock">allowed dock</param> /// <param name="formIdentifier">identifier of the form added</param> /// <returns>object that encapsulates relevant information for the guided form</returns> public DockableFormInfo Add(Form form, DockAllowed allowedDock, Guid formIdentifier) { return(_docker.Add(form, allowedDock, formIdentifier)); }
/// <summary> /// Shows the center guider /// </summary> /// <param name="allowedDockMode">allowed dock</param> /// <param name="screenBounds">screen bounds where to center the guider</param> public void ShowCenterGuider(DockAllowed allowedDockMode, Rectangle screenBounds) { ValidateNotDisposed(); _centerGuider.Show(allowedDockMode, screenBounds); }
/// <summary> /// Show margin guider /// </summary> /// <param name="allowedDockMode">allowed dock mode</param> /// <param name="screenBounds">screen bounds where to show the margins guider</param> public void ShowMarginsGuider(DockAllowed allowedDockMode, Rectangle screenBounds) { ValidateNotDisposed(); _marginGuiders.Show(allowedDockMode); }