/// <summary> /// Initialize a new instance of the ViewDrawRibbonGroupsBorderSynch class. /// </summary> /// <param name="ribbon">Reference to owning ribbon control.</param> /// <param name="needPaintDelegate">Delegate for notifying paint/layout changes.</param> public ViewDrawRibbonGroupsBorderSynch(KryptonRibbon ribbon, NeedPaintHandler needPaintDelegate) : base(ribbon, false, needPaintDelegate) { // Create initial lookup table _tabToView = new TabToView(); }
private void SyncChildrenToRibbonTabs() { // Remove all child elements Clear(); // Create a new lookup that reflects any changes in tabs TabToView regenerate = new TabToView(); // Make sure we have a view element to match each tab foreach (KryptonRibbonTab tab in Ribbon.RibbonTabs) { ViewLayoutRibbonScrollPort view = null; // Get the currently cached view for the tab if (_tabToView.ContainsKey(tab)) { view = _tabToView[tab]; } // If a new tab, create a view for it now if (view == null) { ViewLayoutRibbonGroups groups = new ViewLayoutRibbonGroups(Ribbon, tab, NeedPaintDelegate); view = new ViewLayoutRibbonScrollPort(Ribbon, Orientation.Horizontal, groups, false, SCROLL_SPEED, NeedPaintDelegate) { TransparentBackground = true }; groups.NeedPaintDelegate = view.ViewControlPaintDelegate; } // Make sure only the selected tab is visible view.Visible = (Ribbon.SelectedTab == tab); // Add to the lookup for future reference regenerate.Add(tab, view); // Remove no longer needed reference _tabToView.Remove(tab); } // Switch to using the lookup with only the current options inside TabToView redundant = _tabToView; _tabToView = regenerate; // Add the view elements in same order as the tab definitions foreach (KryptonRibbonTab tab in Ribbon.RibbonTabs) { Add(_tabToView[tab]); } // Dispose of all the no longer needed child tabs foreach (ViewBase oldChild in redundant.Values) { oldChild.Dispose(); } }