/// <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, zAllowedDock 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> /// On begin move a positioner using the mouse /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">event arguments</param> private void OnPositionerBeginMoveByMouse(object sender, EventArgs e) { DockableContainer container = sender as DockableContainer; if (container != null) { Debug.Assert(_host.Contains(container), "Only floating forms should have a container as positioner. Docked forms should have their tabbed view."); _host.MoveFirst(container); } else { FormsTabbedView view = sender as FormsTabbedView; Debug.Assert(view != null, "The positioner should wrap either a container for floating forms or a tabbed view for docked forms"); Undock(view); container = view.Parent as DockableContainer; } EventHandler <ControlEventArgs> handler = BeginMoveByMouse; if (handler != null) { ControlEventArgs args = new ControlEventArgs(container); handler(this, args); } }
/// <summary> /// Add sorted floating containers to the list /// </summary> /// <param name="containers">containers</param> private void AddSortedFloatingContainers(List <DockableContainer> containers) { List <DockableContainer> containersToBringInFront = new List <DockableContainer>(); foreach (DockableFormInfo info in _dockableForms) { FormsTabbedView view = HierarchyUtility.GetTabbedView(info.DockableForm); if (view.IsDocked) { continue; } DockableContainer container = HierarchyUtility.GetClosestDockableContainer(info.DockableForm); if (_host.Contains(container) == false) { continue; } if (containersToBringInFront.Contains(container) == false) { containersToBringInFront.Add(container); } } SortContainersBasedOnTheirZOrder(containersToBringInFront); containers.AddRange(containersToBringInFront); }
/// <summary> /// Remove the form /// </summary> /// <param name="info">info about form to remove</param> public void Remove(DockableFormInfo info) { if (info == null) { return; } FormsTabbedView view = HierarchyUtility.GetTabbedView(info.DockableForm); if (view != null) { if (view.Count == 1 && view.IsDocked) { _layout.Undock(view); } if (view.Count == 1) { _host.Remove(view.Parent); DockableContainer container = HierarchyUtility.GetClosestDockableContainer(info.DockableForm); container.SetModeEmpty(); view.Remove(info); } else { if (view.Remove(info) == false) { if (SelectedFormInfo == info) { SelectedFormInfo = null; } return; } } } if (SelectedFormInfo == info) { SelectedFormInfo = null; } _dockableForms.Remove(info); info.SelectedChanged -= OnFormSelectedChanged; info.ShowAutoPanel -= OnShowFormAutoPanel; info.ExplicitDisposing -= OnInfoDisposing; if (info.IsAutoHideMode) { _autohide.ArrangeAutoButtonsPanels(); } info.Dispose(); }
/// <summary> /// Destroy forms tabbed view /// </summary> /// <param name="formTabbedView">form tabbed view</param> private void DestroyFormsTabbedView(FormsTabbedView formTabbedView) { formTabbedView.UndockForm -= OnUndockFormFromView; formTabbedView.ContextMenuClick -= OnViewContextMenuClick; formTabbedView.AutohideClick -= OnViewAutoHideClick; formTabbedView.FormClosing -= OnFormClosing; formTabbedView.FormClosed -= OnFormClosed; formTabbedView.Dispose(); }
/// <summary> /// Undock the view /// </summary> /// <param name="view">view</param> /// <param name="floatingBounds">floating bounds</param> public void Undock(FormsTabbedView view, Rectangle floatingBounds) { DockableContainer container = (DockableContainer)view.Parent; container.SetModeEmpty(); RemoveContainer(container); CreateFloatingContainer(view, floatingBounds); }
/// <summary> /// Split two forms in vertically splitted view /// </summary> /// <param name="topFormTabbedView">view to dock top</param> /// <param name="bottomFormTabbedView">view to dock bottom</param> /// <param name="parentContainer">parent container which will host the two forms</param> private static void SplitVertically(FormsTabbedView topFormTabbedView, FormsTabbedView bottomFormTabbedView, DockableContainer parentContainer) { DockableContainer newBottomFormContainer = new DockableContainer(); DockableContainer newTopFormContainer = new DockableContainer(); parentContainer.SetModeVSplit(newTopFormContainer, newBottomFormContainer); newBottomFormContainer.SetModeSingleChild(bottomFormTabbedView); newTopFormContainer.SetModeSingleChild(topFormTabbedView); }
/// <summary> /// Start showing form /// </summary> /// <param name="form">form to show</param> /// <param name="width">width of the form</param> /// <param name="height">height of the form</param> private void StartShowForm(Form form, int width, int height) { _previewPane.Visible = false; FormsTabbedView view = HierarchyUtility.GetTabbedView(form); view.Size = new Size(width, height); view.SelectPage(form); StartAutoShowPane(view.Parent as AutoHidePanel); }
/// <summary> /// On set logical dock /// </summary> /// <param name="view">view</param> /// <param name="dock">dock</param> private void OnSetHostContainerDock(FormsTabbedView view, DockStyle dock) { EventHandler <DockControlEventArgs> handler = SetHostContainerDock; if (handler != null) { DockControlEventArgs args = new DockControlEventArgs(view, dock, zDockMode.Inner); handler(this, args); } }
/// <summary> /// Split two forms in horizontal splitted view /// </summary> /// <param name="leftFormTabbedView">view to dock left</param> /// <param name="rightFormTabbedView">view to dock right</param> /// <param name="parentContainer">parent container which will host the two forms</param> private static void SplitHorizontally(FormsTabbedView leftFormTabbedView, FormsTabbedView rightFormTabbedView, DockableContainer parentContainer) { DockableContainer newRightFormContainer = new DockableContainer(); DockableContainer newLeftFormContainer = new DockableContainer(); parentContainer.SetModeHSplit(newLeftFormContainer, newRightFormContainer); newRightFormContainer.SetModeSingleChild(rightFormTabbedView); newLeftFormContainer.SetModeSingleChild(leftFormTabbedView); }
/// <summary> /// Destroy forms tabbed view /// </summary> /// <param name="view">tabbed view</param> private void OnDestroyFormsTabbedView(FormsTabbedView view) { EventHandler <ControlEventArgs> handler = DestroyFormsTabbedView; if (handler != null) { ControlEventArgs args = new ControlEventArgs(view); handler(this, args); } }
/// <summary> /// Undock the view /// </summary> /// <param name="view">view</param> public void Undock(FormsTabbedView view) { Point mousePosition = _host.PointToClient(Control.MousePosition); DockableContainer container = (DockableContainer)view.Parent; Rectangle bounds = _host.GetBoundsInHost(container); ComputeFloatingBounds(mousePosition, view.FloatingSize, ref bounds); Undock(view, bounds); }
/// <summary> /// Set mode single child control /// </summary> /// <param name="singleChild">single child</param> public void SetModeSingleChild(FormsTabbedView singleChild) { singleChild.Parent = null; singleChild.Dock = DockStyle.Fill; Reset(); SetModeEmpty(); base.Add(singleChild); SingleChild = singleChild; }
/// <summary> /// Occurs when pages autohide button was clicked /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">event arguments</param> private void OnViewAutoHideClick(object sender, EventArgs e) { FormsTabbedView view = (FormsTabbedView)sender; if (view.PagesPanel.AutoHidden) { _autohide.UnsetAutoHideMode(view); } else { _autohide.SetAutoHideMode(view); } }
/// <summary> /// Move view size info /// </summary> /// <param name="view">view</param> /// <param name="source">source</param> /// <returns>view size</returns> private static Size RemoveViewSizeInfo(FormsTabbedView view, List <ControlSizeInfo> source) { Form form = view.GetPageAt(0); ControlSizeInfo firstInfo = GetInfo(form, source); for (int index = 0; index < view.Count; index++) { ControlSizeInfo info = GetInfo(view.GetPageAt(index), source); source.Remove(info); } return(new Size(firstInfo.Width, firstInfo.Height)); }
/// <summary> /// Update view buttons /// </summary> /// <param name="view">view</param> private static void UpdateViewButtons(FormsTabbedView view) { if (view.HostContainerDock == DockStyle.Fill) { if (view.ButtonsRenderer.GetType() != typeof(TopTabButtonRenderer)) { view.ButtonsRenderer = new TopTabButtonRenderer(); } } else if (view.ButtonsRenderer.GetType() != typeof(BottomTabButtonRenderer)) { view.ButtonsRenderer = new BottomTabButtonRenderer(); } }
/// <summary> /// Checks if this panel contains give panel /// </summary> /// <param name="panel">panel to check</param> /// <returns>true if this panel contains given pane</returns> public bool ContainsPanel(AutoHidePanel panel) { for (int index = ButtonsCount - 1; index >= 0; index--) { TabButton button = GetButtonAt(index); FormsTabbedView view = HierarchyUtility.GetTabbedView((Form)button.Page); if (view.Parent == panel) { return(true); } } return(false); }
/// <summary> /// Show auto form /// </summary> /// <param name="form">form to be shown</param> public void ShowAutoForm(Form form) { FormsTabbedView view = HierarchyUtility.GetTabbedView(form); AutoHidePanel panel = view.Parent as AutoHidePanel; if (panel == null) { return; } if (_leftAutoHideButtons != null) { if (_leftAutoHideButtons.ContainsPanel(panel)) { OnLeftPaneSelectButton(this, new ControlEventArgs(form)); return; } } if (_rightAutoHideButtons != null) { if (_rightAutoHideButtons.ContainsPanel(panel)) { OnRightPaneSelectButton(this, new ControlEventArgs(form)); return; } } if (_topAutoHideButtons != null) { if (_topAutoHideButtons.ContainsPanel(panel)) { OnTopPaneSelectButton(this, new ControlEventArgs(form)); return; } } if (_bottomAutoHideButtons != null) { if (_bottomAutoHideButtons.ContainsPanel(panel)) { OnBottomPaneSelectButton(this, new ControlEventArgs(form)); return; } } }
/// <summary> /// Set view dock /// </summary> /// <param name="view">view</param> /// <param name="hostContainerDock">host container dock</param> /// <param name="dock">dock</param> /// <param name="mode">mode</param> public void SetViewDock(FormsTabbedView view, DockStyle hostContainerDock, DockStyle dock, zDockMode mode) { UpdateViewButtons(view); if (CanMoveByMouseFilledForms == false && hostContainerDock == DockStyle.Fill) { view.CanMoveByMouse = false; } else { view.CanMoveByMouse = true; } if (view.HostContainerDock == dock) { view.SetDock(hostContainerDock, dock, mode); return; } view.SetDock(hostContainerDock, dock, mode); view.Positioner.BeginMoveByMouse -= OnPositionerBeginMoveByMouse; view.Positioner.MoveByMouse -= OnPositionerMoveByMouse; view.Positioner.EndMoveByMouse -= OnPositionerEndMoveByMouse; view.Positioner.Dispose(); if (dock == DockStyle.None) { view.Positioner = new ControlPositioner(view.Parent); view.Positioner.MoveByMouse += OnPositionerMoveByMouse; view.Positioner.EndMoveByMouse += OnPositionerEndMoveByMouse; } else if (dock == Globals.DockAutoHide) { view.Positioner = null; return; } else { view.Positioner = new ControlPositioner(view); } view.Positioner.BeginMoveByMouse += OnPositionerBeginMoveByMouse; }
/// <summary> /// Get the closest dockable container (first parent of given form which is dockable container) /// </summary> /// <param name="form">form</param> /// <returns>dockable container</returns> public static DockableContainer GetClosestDockableContainer(Form form) { if (form == null) { return(null); } FormsTabbedView tabbedView = GetTabbedView(form); if (tabbedView.IsAutoHideMode) { AutoHidePanel panel = (AutoHidePanel)tabbedView.Parent; return(panel.RestoreParent); } return((DockableContainer)tabbedView.Parent); }
/// <summary> /// Undock view /// </summary> /// <param name="view">view to undock</param> /// <param name="hintBounds">hint bounds</param> private void Undock(Form formToUndock, Rectangle hintBounds) { FormsTabbedView view = HierarchyUtility.GetTabbedView(formToUndock); if (view.Count == 1) { _layout.Undock(view, hintBounds); } else { DockableFormInfo info = GetFormInfo(formToUndock); FormsTabbedView newView = CreateFormsTabbedView(info.DockableForm.Size, null); newView.Add(info); _layout.CreateFloatingContainer(newView, hintBounds); } }
/// <summary> /// Create floating container for the view /// </summary> /// <param name="view">view for which to create floating container</param> /// <param name="bounds">bounds of the floating container</param> /// <returns>floating container</returns> public DockableContainer CreateFloatingContainer(FormsTabbedView view, Rectangle bounds) { DockableContainer container = new DockableContainer(); _host.AddFirst(container); container.Bounds = bounds; container.SetModeSingleChild(view); if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.None)) { SetViewDock(view, DockStyle.None, DockStyle.None, zDockMode.None); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Left)) { DockControl(container, null, DockStyle.Left, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Right)) { DockControl(container, null, DockStyle.Right, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Top)) { DockControl(container, null, DockStyle.Top, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Bottom)) { DockControl(container, null, DockStyle.Bottom, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Fill)) { DockControl(container, null, DockStyle.Fill, zDockMode.Inner); } else { _host.Remove(container); throw new NotSupportedException("Err"); // invalid allowed dock } return(container); }
/// <summary> /// Auto-show the given view /// </summary> /// <param name="view">view to show</param> public void UnsetAutoHideMode(FormsTabbedView view) { AutoHidePanel panel = (AutoHidePanel)view.Parent; DockableContainer container = panel.RestoreParent; DockStyle logicalDock = DockStyle.None; if (LeftAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Left; } else if (RightAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Right; } else if (TopAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Top; } else if (BottomAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Bottom; } else { Debug.Fail("Panel not found"); } _host.Remove(panel); container.SetModeSingleChild(view); OnSetHostContainerDock(view, logicalDock); view.IsAutoHideMode = false; view.PagesPanel.AutoHidden = false; ShowRestoreContainers(panel); ArrangeAutoButtonsPanels(); _autoShowPanel = null; }
/// <summary> /// Dock fill in parent container /// </summary> /// <param name="formTabbedView">view to dock</param> /// <param name="parentTabbedView">view where will dock</param> private static void DockFillInParentContainer(FormsTabbedView formTabbedView, FormsTabbedView parentTabbedView) { Form selected = formTabbedView.GetPageAt(formTabbedView.SelectedIndex); DockableFormInfo[] movedPages = formTabbedView.MovePagesTo(parentTabbedView); foreach (DockableFormInfo movedPage in movedPages) { movedPage.Dock = DockStyle.Fill; movedPage.DockMode = zDockMode.Inner; } for (int index = 0; index < parentTabbedView.Count; index++) { if (parentTabbedView.GetPageAt(index) == selected) { parentTabbedView.SelectedIndex = index; break; } } }
/// <summary> /// Move all the pages to given view /// </summary> /// <param name="view">view where to move the pages</param> /// <returns>moved pages</returns> public DockableFormInfo[] MovePagesTo(FormsTabbedView view) { List <DockableFormInfo> movedPages = new List <DockableFormInfo>(); if (view == this) { return(movedPages.ToArray()); } for (int index = _cachedInfos.Count - 1; index >= 0; index--) { DockableFormInfo info = _cachedInfos[index]; Remove(info); view.Add(info); movedPages.Add(info); } return(movedPages.ToArray()); }
/// <summary> /// Removes the panel if is contained here /// </summary> /// <param name="panel">panel to remove</param> /// <returns>true if is removed the panel</returns> public bool Remove(AutoHidePanel panel) { bool removed = false; for (int index = ButtonsCount - 1; index >= 0; index--) { TabButton button = GetButtonAt(index); FormsTabbedView view = HierarchyUtility.GetTabbedView((Form)button.Page); if (view.Parent == panel) { RemoveButton(button); removed = true; } } panel.View.FormAdded -= OnFormAddedToPanel; panel.View.FormRemoved -= OnFormRemovedFromPanel; panel.View.FormSelected -= OnFormSelectedIntoView; return(removed); }
/// <summary> /// Occurs when IsSelected property of a form is changed /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">event argument</param> private void OnFormSelectedChanged(object sender, EventArgs e) { DockableFormInfo info = (DockableFormInfo)sender; if (info.IsSelected) { SelectedFormInfo = info; } FormsTabbedView view = HierarchyUtility.GetTabbedView(info.DockableForm); if (view != null) { if (view.SelectedForm != null) { DockableFormInfo topFormInfo = GetFormInfo(view.SelectedForm); view.PagesPanel.ShowCloseButton = topFormInfo.ShowCloseButton; view.PagesPanel.ShowContextMenuButton = topFormInfo.ShowContextMenuButton; } } }
/// <summary> /// Create forms tabbed view /// </summary> /// <param name="size">initial size of decorator</param> /// <param name="positioner">positioner for control</param> /// <returns>forms tabbed view</returns> private FormsTabbedView CreateFormsTabbedView(Size size, ControlPositioner positioner) { FormsTabbedView view = new FormsTabbedView(); view.ShowOneTabButton = false; view.Size = size; view.PagesPanel.Positioner = positioner; view.PagesPanel.Size = size; view.PagesPanel.BackColor = SystemColors.Control; view.PagesPanel.TextColor = TitleBarTextColor; view.PagesPanel.Color1 = TitleBarGradientColor1; view.PagesPanel.Color2 = TitleBarGradientColor2; view.PagesPanel.SelectedColor1 = TitleBarGradientSelectedColor1; view.PagesPanel.SelectedColor2 = TitleBarGradientSelectedColor2; view.UndockForm += OnUndockFormFromView; view.ContextMenuClick += OnViewContextMenuClick; view.AutohideClick += OnViewAutoHideClick; view.FormClosing += OnFormClosing; view.FormClosed += OnFormClosed; return(view); }
/// <summary> /// Add sorted fill containers to the list /// </summary> /// <param name="containers">containers</param> private void AddSortedFillContainers(List <DockableContainer> containers) { List <DockableContainer> containersToBringInFront = new List <DockableContainer>(); foreach (DockableFormInfo info in _dockableForms) { FormsTabbedView view = HierarchyUtility.GetTabbedView(info.DockableForm); if (view.HostContainerDock != DockStyle.Fill) { continue; } DockableContainer container = HierarchyUtility.GetClosestDockableContainer(info.DockableForm); while (true) { if (container.Parent as DockableContainer != null) { container = (DockableContainer)container.Parent; } else { break; } } Debug.Assert(_host.Contains(container), "Floating form views must have their parent in form"); if (containersToBringInFront.Contains(container) == false) { containersToBringInFront.Add(container); } } SortContainersBasedOnTheirZOrder(containersToBringInFront); containers.AddRange(containersToBringInFront); }
/// <summary> /// Save the view /// </summary> /// <param name="view">view to save</param> /// <param name="viewOwnerId">view owner identifier</param> /// <param name="xmlForms">forms node</param> /// <returns>identifier of the view</returns> private Guid SaveView(FormsTabbedView view, Guid viewOwnerId, XmlNode xmlForms) { Form firstDockedPage = null; for (int childIndex = 0; childIndex < view.Count; childIndex++) { DockableFormInfo childInfo = view.GetPageInfoAt(childIndex); if (childInfo.Dock != DockStyle.Fill) { firstDockedPage = childInfo.DockableForm; break; } } if (firstDockedPage == null) { firstDockedPage = view.GetPageAt(0); } DockableFormInfo info = _container.GetFormInfo(firstDockedPage); Save(info, viewOwnerId, xmlForms); for (int childIndex = 0; childIndex < view.Count; childIndex++) { DockableFormInfo siblingInfo = view.GetPageInfoAt(childIndex); if (siblingInfo == info) { continue; } Save(siblingInfo, info.Id, xmlForms); } return(info.Id); }
/// <summary> /// Undock the view /// </summary> /// <param name="view">view</param> public void Undock(FormsTabbedView view) { Point mousePosition = _host.PointToClient(Control.MousePosition); DockableContainer container = (DockableContainer)view.Parent; Rectangle bounds = _host.GetBoundsInHost(container); ComputeFloatingBounds(mousePosition, view.FloatingSize, ref bounds); Undock(view, bounds); }
/// <summary> /// Set view dock /// </summary> /// <param name="view">view</param> /// <param name="hostContainerDock">host container dock</param> /// <param name="dock">dock</param> /// <param name="mode">mode</param> public void SetViewDock(FormsTabbedView view, DockStyle hostContainerDock, DockStyle dock, zDockMode mode) { UpdateViewButtons(view); if (CanMoveByMouseFilledForms == false && hostContainerDock == DockStyle.Fill) { view.CanMoveByMouse = false; } else { view.CanMoveByMouse = true; } if (view.HostContainerDock == dock) { view.SetDock(hostContainerDock, dock, mode); return; } view.SetDock(hostContainerDock, dock, mode); view.Positioner.BeginMoveByMouse -= OnPositionerBeginMoveByMouse; view.Positioner.MoveByMouse -= OnPositionerMoveByMouse; view.Positioner.EndMoveByMouse -= OnPositionerEndMoveByMouse; view.Positioner.Dispose(); if (dock == DockStyle.None) { view.Positioner = new ControlPositioner(view.Parent); view.Positioner.MoveByMouse += OnPositionerMoveByMouse; view.Positioner.EndMoveByMouse += OnPositionerEndMoveByMouse; } else if (dock == Globals.DockAutoHide) { view.Positioner = null; return; } else { view.Positioner = new ControlPositioner(view); } view.Positioner.BeginMoveByMouse += OnPositionerBeginMoveByMouse; }
/// <summary> /// Undock the view /// </summary> /// <param name="view">view</param> /// <param name="floatingBounds">floating bounds</param> public void Undock(FormsTabbedView view, Rectangle floatingBounds) { DockableContainer container = (DockableContainer)view.Parent; container.SetModeEmpty(); RemoveContainer(container); CreateFloatingContainer(view, floatingBounds); }
/// <summary> /// Move view size info /// </summary> /// <param name="view">view</param> /// <param name="source">source</param> /// <returns>view size</returns> private static Size RemoveViewSizeInfo(FormsTabbedView view, List<ControlSizeInfo> source) { Form form = view.GetPageAt(0); ControlSizeInfo firstInfo = GetInfo(form, source); for(int index = 0; index < view.Count; index++) { ControlSizeInfo info = GetInfo(view.GetPageAt(index), source); source.Remove(info); } return new Size(firstInfo.Width, firstInfo.Height); }
/// <summary> /// Destroy forms tabbed view /// </summary> /// <param name="view">tabbed view</param> private void OnDestroyFormsTabbedView(FormsTabbedView view) { EventHandler<ControlEventArgs> handler = DestroyFormsTabbedView; if (handler != null) { ControlEventArgs args = new ControlEventArgs(view); handler(this, args); } }
/// <summary> /// Split two forms in vertically splitted view /// </summary> /// <param name="topFormTabbedView">view to dock top</param> /// <param name="bottomFormTabbedView">view to dock bottom</param> /// <param name="parentContainer">parent container which will host the two forms</param> private static void SplitVertically(FormsTabbedView topFormTabbedView, FormsTabbedView bottomFormTabbedView, DockableContainer parentContainer) { DockableContainer newBottomFormContainer = new DockableContainer(); DockableContainer newTopFormContainer = new DockableContainer(); parentContainer.SetModeVSplit(newTopFormContainer, newBottomFormContainer); newBottomFormContainer.SetModeSingleChild(bottomFormTabbedView); newTopFormContainer.SetModeSingleChild (topFormTabbedView); }
/// <summary> /// Save the view /// </summary> /// <param name="view">view to save</param> /// <param name="viewOwnerId">view owner identifier</param> /// <param name="xmlForms">forms node</param> /// <returns>identifier of the view</returns> private Guid SaveView(FormsTabbedView view, Guid viewOwnerId, XmlNode xmlForms) { Form firstDockedPage = null; for (int childIndex = 0; childIndex < view.Count; childIndex++) { DockableFormInfo childInfo = view.GetPageInfoAt(childIndex); if (childInfo.Dock != DockStyle.Fill) { firstDockedPage = childInfo.DockableForm; break; } } if (firstDockedPage == null) { firstDockedPage = view.GetPageAt(0); } DockableFormInfo info = _container.GetFormInfo(firstDockedPage); Save(info, viewOwnerId, xmlForms); for (int childIndex = 0; childIndex < view.Count; childIndex++) { DockableFormInfo siblingInfo = view.GetPageInfoAt(childIndex); if (siblingInfo == info) { continue; } Save(siblingInfo, info.Id, xmlForms); } return info.Id; }
/// <summary> /// Update view buttons /// </summary> /// <param name="view">view</param> private static void UpdateViewButtons(FormsTabbedView view) { if (view.HostContainerDock == DockStyle.Fill) { if (view.ButtonsRenderer.GetType() != typeof(TopTabButtonRenderer)) { view.ButtonsRenderer = new TopTabButtonRenderer(); } } else if (view.ButtonsRenderer.GetType() != typeof(BottomTabButtonRenderer)) { view.ButtonsRenderer = new BottomTabButtonRenderer(); } }
/// <summary> /// Create forms tabbed view /// </summary> /// <param name="size">initial size of decorator</param> /// <param name="positioner">positioner for control</param> /// <returns>forms tabbed view</returns> private FormsTabbedView CreateFormsTabbedView(Size size, ControlPositioner positioner) { FormsTabbedView view = new FormsTabbedView(); view.ShowOneTabButton = false; view.Size = size; view.PagesPanel.Positioner = positioner; view.PagesPanel.Size = size; view.PagesPanel.BackColor = SystemColors.Control; view.PagesPanel.TextColor = TitleBarTextColor; view.PagesPanel.Color1 = TitleBarGradientColor1; view.PagesPanel.Color2 = TitleBarGradientColor2; view.PagesPanel.SelectedColor1 = TitleBarGradientSelectedColor1; view.PagesPanel.SelectedColor2 = TitleBarGradientSelectedColor2; view.UndockForm += OnUndockFormFromView; view.ContextMenuClick += OnViewContextMenuClick; view.AutohideClick += OnViewAutoHideClick; view.FormClosing += OnFormClosing; view.FormClosed += OnFormClosed; return view; }
/// <summary> /// Set mode horizontal split /// </summary> /// <param name="leftPane">left pane</param> /// <param name="rightPane">right pane</param> public void SetModeHSplit(DockableContainer leftPane, DockableContainer rightPane) { _linkedView = null; InternalControls.SetModeHSplit(leftPane, rightPane); }
/// <summary> /// Set mode vertical split /// </summary> /// <param name="topPane">left pane</param> /// <param name="bottomPane">right pane</param> public void SetModeVSplit(DockableContainer topPane, DockableContainer bottomPane) { _linkedView = null; InternalControls.SetModeVSplit(topPane, bottomPane); }
/// <summary> /// Set mode single child control /// </summary> /// <param name="singleChild">single child</param> public void SetModeSingleChild(FormsTabbedView singleChild) { _linkedView = null; InternalControls.SetModeSingleChild(singleChild); }
/// <summary> /// Set mode linked /// </summary> /// <param name="link">link</param> public void SetModeLinked(FormsTabbedView link) { InternalControls.SetModeEmpty(); _linkedView = link; }
/// <summary> /// Set mode empty /// </summary> public void SetModeEmpty() { _linkedView = null; InternalControls.SetModeEmpty(); }
/// <summary> /// Create floating container for the view /// </summary> /// <param name="view">view for which to create floating container</param> /// <param name="bounds">bounds of the floating container</param> /// <returns>floating container</returns> public DockableContainer CreateFloatingContainer(FormsTabbedView view, Rectangle bounds) { DockableContainer container = new DockableContainer(); _host.AddFirst(container); container.Bounds = bounds; container.SetModeSingleChild(view); if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.None)) { SetViewDock(view, DockStyle.None, DockStyle.None, zDockMode.None); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Left)) { DockControl(container, null, DockStyle.Left, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Right)) { DockControl(container, null, DockStyle.Right, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Top)) { DockControl(container, null, DockStyle.Top, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Bottom)) { DockControl(container, null, DockStyle.Bottom, zDockMode.Outer); } else if (EnumUtility.Contains(view.AllowedDock, zAllowedDock.Fill)) { DockControl(container, null, DockStyle.Fill, zDockMode.Inner); } else { _host.Remove(container); throw new NotSupportedException("Err"); // invalid allowed dock } return container; }
/// <summary> /// Auto-hide the given view /// </summary> /// <param name="view">view to hide</param> public void SetAutoHideMode(FormsTabbedView view) { AutoHidePanel panel = new AutoHidePanel(); panel.RestoreParent = (DockableContainer)view.Parent; panel.Size = view.Size; panel.Visible = false; HideRestoreContainers(panel); panel.RestoreParent.SetModeLinked(view); view.Parent = panel; DockStyle logicalDock = view.HostContainerDock; OnSetHostContainerDock(view, Globals.DockAutoHide); view.Positioner = new ControlPositioner(panel); view.Positioner.CanMove = false; if (logicalDock == DockStyle.Left) { panel.Bounds = new Rectangle(LeftAutohideButtons.Right, LeftAutohideButtons.Top, view.Width, LeftAutohideButtons.Height); view.Positioner.CanSizeLeft = false; view.Positioner.CanSizeTop = false; view.Positioner.CanSizeBottom = false; panel.AutoHideHandler = AutoHideLeftPane; panel.AutoShowHandler = AutoShowLeftPane; LeftAutohideButtons.Add(panel); } else if (logicalDock == DockStyle.Right) { panel.Bounds = new Rectangle(RightAutohideButtons.Left - view.Width, RightAutohideButtons.Top, view.Width, RightAutohideButtons.Height); view.Positioner.CanSizeRight = false; view.Positioner.CanSizeTop = false; view.Positioner.CanSizeBottom = false; panel.AutoHideHandler = AutoHideRightPane; panel.AutoShowHandler = AutoShowRightPane; RightAutohideButtons.Add(panel); } else if (logicalDock == DockStyle.Top) { panel.Bounds = new Rectangle(TopAutohideButtons.Left, TopAutohideButtons.Bottom, TopAutohideButtons.Width, view.Height); view.Positioner.CanSizeLeft = false; view.Positioner.CanSizeRight = false; view.Positioner.CanSizeTop = false; panel.AutoHideHandler = AutoHideTopPane; panel.AutoShowHandler = AutoShowTopPane; TopAutohideButtons.Add(panel); } else if (logicalDock == DockStyle.Bottom) { panel.Bounds = new Rectangle(BottomAutohideButtons.Left, BottomAutohideButtons.Top - view.Height, BottomAutohideButtons.Width, view.Height); view.Positioner.CanSizeLeft = false; view.Positioner.CanSizeRight = false; view.Positioner.CanSizeBottom = false; panel.AutoHideHandler = AutoHideBottomPane; panel.AutoShowHandler = AutoShowBottomPane; BottomAutohideButtons.Add(panel); } else { Debug.Fail("Autohide should be available only for docked left, right, top or bottom"); return; } _host.AddFirst(panel); view.IsAutoHideMode = true; view.PagesPanel.AutoHidden = true; ArrangeAutoButtonsPanels(); }
/// <summary> /// Create forms tabbed view /// </summary> /// <param name="size">initial size of decorator</param> /// <param name="positioner">positioner for control</param> /// <returns>forms tabbed view</returns> private FormsTabbedView CreateFormsTabbedView(Size size, ControlPositioner positioner) { FormsTabbedView view = new FormsTabbedView(); view.ShowOneTabButton = false; view.Size = size; view.PagesPanel.Positioner = positioner; view.PagesPanel.Size = size; view.PagesPanel.BackColor = SystemColors.Control; view.UndockForm += OnUndockFormFromView; view.ContextMenuClick += OnViewContextMenuClick; view.AutohideClick += OnViewAutoHideClick; view.CloseClick += OnViewCloseClick; return view; }
/// <summary> /// Dock fill in parent container /// </summary> /// <param name="formTabbedView">view to dock</param> /// <param name="parentTabbedView">view where will dock</param> private static void DockFillInParentContainer(FormsTabbedView formTabbedView, FormsTabbedView parentTabbedView) { Form selected = formTabbedView.GetPageAt(formTabbedView.SelectedIndex); DockableFormInfo[] movedPages = formTabbedView.MovePagesTo(parentTabbedView); foreach (DockableFormInfo movedPage in movedPages) { movedPage.Dock = DockStyle.Fill; movedPage.DockMode = zDockMode.Inner; } for (int index = 0; index < parentTabbedView.Count; index++) { if (parentTabbedView.GetPageAt(index) == selected) { parentTabbedView.SelectedIndex = index; break; } } }
/// <summary> /// Destroy forms tabbed view /// </summary> /// <param name="formTabbedView">form tabbed view</param> private void DestroyFormsTabbedView(FormsTabbedView formTabbedView) { formTabbedView.UndockForm -= OnUndockFormFromView; formTabbedView.ContextMenuClick -= OnViewContextMenuClick; formTabbedView.AutohideClick -= OnViewAutoHideClick; formTabbedView.CloseClick -= OnViewCloseClick; formTabbedView.Dispose(); }
/// <summary> /// Split two forms in horizontal splitted view /// </summary> /// <param name="leftFormTabbedView">view to dock left</param> /// <param name="rightFormTabbedView">view to dock right</param> /// <param name="parentContainer">parent container which will host the two forms</param> private static void SplitHorizontally(FormsTabbedView leftFormTabbedView, FormsTabbedView rightFormTabbedView, DockableContainer parentContainer) { DockableContainer newRightFormContainer = new DockableContainer(); DockableContainer newLeftFormContainer = new DockableContainer(); parentContainer.SetModeHSplit(newLeftFormContainer, newRightFormContainer); newRightFormContainer.SetModeSingleChild(rightFormTabbedView); newLeftFormContainer.SetModeSingleChild (leftFormTabbedView); }
/// <summary> /// On set logical dock /// </summary> /// <param name="view">view</param> /// <param name="dock">dock</param> private void OnSetHostContainerDock(FormsTabbedView view, DockStyle dock) { EventHandler<DockControlEventArgs> handler = SetHostContainerDock; if (handler != null) { DockControlEventArgs args = new DockControlEventArgs(view, dock, zDockMode.Inner); handler(this, args); } }
/// <summary> /// Move all the pages to given view /// </summary> /// <param name="view">view where to move the pages</param> /// <returns>moved pages</returns> public DockableFormInfo[] MovePagesTo(FormsTabbedView view) { List<DockableFormInfo> movedPages = new List<DockableFormInfo>(); if (view == this) { return movedPages.ToArray(); } for (int index = _cachedInfos.Count - 1; index >= 0; index--) { DockableFormInfo info = _cachedInfos[index]; Remove(info); view.Add(info); movedPages.Add(info); } return movedPages.ToArray(); }
/// <summary> /// Auto-show the given view /// </summary> /// <param name="view">view to show</param> public void UnsetAutoHideMode(FormsTabbedView view) { AutoHidePanel panel = (AutoHidePanel)view.Parent; DockableContainer container = panel.RestoreParent; DockStyle logicalDock = DockStyle.None; if (LeftAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Left; } else if (RightAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Right; } else if (TopAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Top; } else if (BottomAutohideButtons.Remove(panel)) { logicalDock = DockStyle.Bottom; } else { Debug.Fail("Panel not found"); } _host.Remove(panel); container.SetModeSingleChild(view); OnSetHostContainerDock(view, logicalDock); view.IsAutoHideMode = false; view.PagesPanel.AutoHidden = false; ShowRestoreContainers(panel); ArrangeAutoButtonsPanels(); _autoShowPanel = null; }
/// <summary> /// Set mode single child control /// </summary> /// <param name="singleChild">single child</param> public void SetModeSingleChild(FormsTabbedView singleChild) { singleChild.Parent = null; singleChild.Dock = DockStyle.Fill; Reset(); SetModeEmpty(); base.Add(singleChild); SingleChild = singleChild; }