/** * @brief Constructor whicch sets up the window procedure. * @param[in | opt] A tab item to add to the window on startup. * @see sulphur.editor.controls.DynamicDockTab */ public TabWindow(DynamicDockTab item = null) { WindowStyle = WindowStyle.ToolWindow; InitializeComponent(); SizeToContent = SizeToContent.WidthAndHeight; Show(); Owner = Application.Current.MainWindow; HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); source.AddHook(new HwndSourceHook(WndProc)); Content = new DynamicDockTabControl(false); (Content as DynamicDockTabControl).items_changed += TabWindow_items_changed; if (item != null) { (Content as DynamicDockTabControl).Items.Add(item); } }
/** * @brief Removes a tab control when it has no more children and ensures that the last child of the dockpanel always takes the remaining space. * @param[in] sender (object) The sulphur.editor.controls.DynamicDockTabControl whose item collection has changed. * @param[in] e (EventArgs) Arguments passes with the event. */ private void TabItemsChanged(object sender, EventArgs e) { DynamicDockTabControl control = sender as DynamicDockTabControl; if (control.Items.Count == 0) { foreach (Pair p in paired_children_) { if (p.element == control) { RemovePair(p); ((FrameworkElement)Children[Children.Count - 1]).Width = double.NaN; ((FrameworkElement)Children[Children.Count - 1]).Height = double.NaN; UpdateSplitters(); break; } } } }
List <Pair> paired_children_; //!< All Children of this dockpanel paired up with a splitter. /** * @brief Runs after WPF initialization of the control is complete. This functions puts all childs in their respective tab controls and dockpanels. */ public override void EndInit() { base.EndInit(); for (int i = 0; i < Children.Count; ++i) { UIElement child = Children[i]; uint group = GetGroup(child); DynamicDockTab item = new DynamicDockTab(); item.Header = ((FrameworkElement)child).Name; item.Content = new DynamicDock(); item.Content = child; if (group != uint.MaxValue) { bool group_found = false; foreach (Pair entry in paired_children_) { if (group == GetGroup(entry.element)) { entry.element.Items.Add(item); group_found = true; break; } } if (group_found == true) { continue; } } Dock dockmode = GetDock(child); DynamicDockTabControl tabs = new DynamicDockTabControl(true); tabs.items_changed += TabItemsChanged; tabs.Items.Add(item); SetGroup(tabs, group); Pair pair = new Pair(); pair.splitter = null; pair.element = tabs; pair.dockmode = dockmode; pair.adorner = new DynamicDockAdorner(pair.element); SetDock(pair.element, pair.dockmode); if (paired_children_.Count != 0) { Pair back = paired_children_[paired_children_.Count - 1]; back.CreateSplitter(); back.splitter.resizing_started += (object sender, EventArgs args) => notify_subscribers_?.Invoke( sender, new NotificationEventArgs( null, (uint)Notifications.kLayoutChangeStarted, id <DynamicDock> .type_id_) ); back.splitter.resizing_stopped += (object sender, EventArgs args) => notify_subscribers_?.Invoke( sender, new NotificationEventArgs( null, (uint)Notifications.kLayoutChangeEnded, id <DynamicDock> .type_id_) ); } paired_children_.Add(pair); } Children.Clear(); foreach (Pair pair in paired_children_) { Children.Add(pair.element); if (pair.splitter != null) { Children.Add(pair.splitter); } } }