private void OnViewAdded(object sender, ViewEventArgs e) { var host = (ViewHost)sender; int i = _tabs.Count - 1; for (; i >= 0; --i) { if (_tabs[i].ViewHost == host) { break; } } var tab = new ViewDockSideTab(this, host, e.View); tab.ResetLength(); var size = tab.Length; _tabs.Insert(i, tab); switch (_orientation) { case Orientation.Vertical: { var space = _grid.VerticalClientSpace; var height = _size + size; _size = height; if (_tabs.Count != 1) { height += Renderer.SideTabSpacing; } if (height > space) { height = space; } Height = height; } break; case Orientation.Horizontal: { var space = _grid.HorizontalClientSpace; var width = _size + size; _size = width; if (_tabs.Count != 1) { width += Renderer.SideTabSpacing; } if (width > space) { width = space; } Width = width; } break; default: throw new ApplicationException(string.Format( CultureInfo.InvariantCulture, "Unexpected {0}.Orientation: {1}", GetType().Name, Orientation)); } e.View.TextChanged += OnViewTextChanged; Invalidate(); }
/// <summary>Adds <see cref="ViewHost"/> to this <see cref="ViewDockSide"/>.</summary> /// <param name="viewHost"><see cref="ViewHost"/> to add.</param> public void AddHost(ViewHost viewHost) { Verify.Argument.IsNotNull(viewHost, nameof(viewHost)); _dockedHosts.Add(viewHost); viewHost.DockSide = this; viewHost.Status = ViewHostStatus.AutoHide; int size = 0; using (var graphics = CreateGraphics()) { if (viewHost.ViewsCount != 0) { foreach (var view in viewHost.Views) { var tab = new ViewDockSideTab(this, viewHost, view); tab.ResetLength(graphics); size += tab.Length; _tabs.Add(tab); view.TextChanged += OnViewTextChanged; } } } switch (Orientation) { case Orientation.Vertical: { var space = _grid.VerticalClientSpace; var height = _size + size; _size = height; height += _tabs.Count * Renderer.SideTabSpacing; if (height > space) { height = space; } Height = height; } break; case Orientation.Horizontal: { var space = _grid.HorizontalClientSpace; var width = _size + size; _size = width; width += _tabs.Count * Renderer.SideTabSpacing; if (width > space) { width = space; } Width = width; } break; default: throw new ApplicationException(string.Format( CultureInfo.InvariantCulture, "Unexpected {0}.Orientation: {1}", GetType().Name, Orientation)); } viewHost.ViewAdded += OnViewAdded; viewHost.ViewRemoved += OnViewRemoved; }