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();
            }
        }
        /// <summary>
        /// Gets the view element group that the provided point is inside.
        /// </summary>
        /// <param name="pt">Mouse point.</param>
        /// <returns>Reference if inside a group; otherwise null.</returns>
        public ViewDrawRibbonGroup ViewGroupFromPoint(Point pt)
        {
            // There can only be groups showing for the currently selected tab
            if (Ribbon.SelectedTab != null && (_tabToView.ContainsKey(Ribbon.SelectedTab)))
            {
                // Get the scroll port for this tab
                ViewLayoutRibbonScrollPort viewScrollPort = _tabToView[Ribbon.SelectedTab];

                // The first child of the scroll port is always the view control
                ViewLayoutControl viewControl = viewScrollPort[0] as ViewLayoutControl;

                // The first child of the view control is always the ribbon groups
                ViewLayoutRibbonGroups viewGroups = viewControl.ChildView as ViewLayoutRibbonGroups;

                // Ask the view groups to find a matching group
                return(viewGroups.ViewGroupFromPoint(pt));
            }

            return(null);
        }
コード例 #3
0
        private void CreateViewElements(PaletteRedirect redirect)
        {
            // Layout for individual tabs inside the header
            LayoutTabs = new ViewLayoutRibbonTabs(_ribbon, NeedPaintDelegate);

            // Put inside a viewport so scrollers are used when tabs cannot be shrunk to fill space
            _tabsViewport = new ViewLayoutRibbonScrollPort(_ribbon, System.Windows.Forms.Orientation.Horizontal, LayoutTabs, true, SCROLL_SPEED, NeedPaintDelegate)
            {
                TransparentBackground = true
            };
            _tabsViewport.PaintBackground += OnTabsPaintBackground;
            LayoutTabs.ParentControl       = _tabsViewport.ViewLayoutControl.ChildControl;
            LayoutTabs.NeedPaintDelegate   = _tabsViewport.ViewControlPaintDelegate;

            // We use a layout docker as a child to prevent buttons going to the left of the app button
            ViewLayoutDocker tabsDocker = new ViewLayoutDocker
            {
                // Place the tabs viewport as the fill inside ourself, the button specs will be placed
                // to the left and right of this fill element automatically by the button manager below
                { _tabsViewport, ViewDockStyle.Fill }
            };

            // We need to draw the bottom half of the application button or a full app tab
            LayoutAppButton = new ViewLayoutRibbonAppButton(_ribbon, true);
            LayoutAppTab    = new ViewLayoutRibbonAppTab(_ribbon);

            // Connect up the application button controller to the app button element
            _appButtonController.Target3        = LayoutAppButton.AppButton;
            _appButtonController.Click         += OnAppButtonClicked;
            _appButtonController.MouseReleased += OnAppButtonReleased;
            LayoutAppButton.MouseController     = _appButtonController;
            LayoutAppButton.SourceController    = _appButtonController;
            LayoutAppButton.KeyController       = _appButtonController;

            _appTabController.Target1        = LayoutAppTab.AppTab;
            _appTabController.Click         += OnAppButtonClicked;
            _appTabController.MouseReleased += OnAppButtonReleased;
            LayoutAppTab.MouseController     = _appTabController;
            LayoutAppTab.SourceController    = _appTabController;
            LayoutAppTab.KeyController       = _appTabController;

            // When the app button is not visible we need separator instead before start of first tab
            _layoutAppButtonSep = new ViewLayoutSeparator(5, 0)
            {
                Visible = false
            };

            // Used separators around the tabs and the edge elements
            _rightSeparator = new ViewLayoutRibbonSeparator(FAR_TAB_GAP, true);
            _leftSeparator  = new ViewLayoutRibbonSeparator(BUTTON_TAB_GAP_2007, true);

            // Place application button on left  and tabs as the filler (with some separators for neatness)
            Add(_rightSeparator, ViewDockStyle.Left);
            Add(_leftSeparator, ViewDockStyle.Left);
            Add(LayoutAppButton, ViewDockStyle.Left);
            Add(_layoutAppButtonSep, ViewDockStyle.Left);
            Add(LayoutAppTab, ViewDockStyle.Left);
            Add(tabsDocker, ViewDockStyle.Fill);

            // Create button specification collection manager
            PaletteRedirect aeroOverrideText = new PaletteRedirectRibbonAeroOverride(_ribbon, redirect);

            ButtonSpecManager = new ButtonSpecManagerLayoutRibbon(_ribbon, aeroOverrideText, _ribbon.ButtonSpecs, _buttonSpecsFixed,
                                                                  new ViewLayoutDocker[] { tabsDocker },
                                                                  new IPaletteMetric[] { _ribbon.StateCommon },
                                                                  new PaletteMetricInt[] { PaletteMetricInt.HeaderButtonEdgeInsetPrimary },
                                                                  new PaletteMetricPadding[] { PaletteMetricPadding.RibbonButtonPadding },
                                                                  _ribbon.CreateToolStripRenderer,
                                                                  NeedPaintDelegate);

            // Create the manager for handling tooltips
            ToolTipManager                   = new ToolTipManager();
            ToolTipManager.ShowToolTip      += OnShowToolTip;
            ToolTipManager.CancelToolTip    += OnCancelToolTip;
            ButtonSpecManager.ToolTipManager = ToolTipManager;
        }