Sizes and positions a provided view but provides scrolling if too big for area.
Inheritance: ComponentFactory.Krypton.Toolkit.ViewComposite
Ejemplo n.º 1
0
        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)
            {
                // 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;
        }
Ejemplo n.º 3
0
        private void CreateViewElements(PaletteRedirect redirect)
        {
            // Layout for individual tabs inside the header
            _layoutRibbonTabs = 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, _layoutRibbonTabs, true, SCROLL_SPEED, NeedPaintDelegate);
            _tabsViewport.TransparentBackground = true;
            _tabsViewport.PaintBackground      += new PaintEventHandler(OnTabsPaintBackground);
            _layoutRibbonTabs.ParentControl     = _tabsViewport.ViewLayoutControl.ChildControl;
            _layoutRibbonTabs.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
            tabsDocker.Add(_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         += new EventHandler(OnAppButtonClicked);
            _appButtonController.MouseReleased += new EventHandler(OnAppButtonReleased);
            _layoutAppButton.MouseController    = _appButtonController;
            _layoutAppButton.SourceController   = _appButtonController;
            _layoutAppButton.KeyController      = _appButtonController;

            _appTabController.Target1        = _layoutAppTab.AppTab;
            _appTabController.Click         += new EventHandler(OnAppButtonClicked);
            _appTabController.MouseReleased += new EventHandler(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);
            _layoutAppButtonSep.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);

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

            // Create the manager for handling tooltips
            _toolTipManager                = new ToolTipManager();
            _toolTipManager.ShowToolTip   += new EventHandler <ToolTipEventArgs>(OnShowToolTip);
            _toolTipManager.CancelToolTip += new EventHandler(OnCancelToolTip);
            _buttonManager.ToolTipManager  = _toolTipManager;
        }