/// <summary>
        /// Raises the paint event and draws the
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void OnPaint(object sender, RibbonElementPaintEventArgs e)
        {
            if (Paint != null)
            {
                Paint(this, new PaintEventArgs(e.Graphics, e.Clip));
            }

            if (PopupShowed && e.Control == Owner)
            {
                //Draw a fake collapsed and pressed panel

                #region Create fake panel
                RibbonPanel fakePanel = new RibbonPanel(this.Text);
                fakePanel.Image = this.Image;
                fakePanel.SetSizeMode(RibbonElementSizeMode.Overflow);
                fakePanel.SetBounds(overflowBoundsBuffer);
                fakePanel.SetPressed(true);
                fakePanel.SetOwner(Owner);
                #endregion

                Owner.Renderer.OnRenderRibbonPanelBackground(new RibbonPanelRenderEventArgs(Owner, e.Graphics, e.Clip, fakePanel, e.Control));
                Owner.Renderer.OnRenderRibbonPanelText(new RibbonPanelRenderEventArgs(Owner, e.Graphics, e.Clip, fakePanel, e.Control));
            }
            else
            {
                //Draw normal
                Owner.Renderer.OnRenderRibbonPanelBackground(new RibbonPanelRenderEventArgs(Owner, e.Graphics, e.Clip, this, e.Control));
                Owner.Renderer.OnRenderRibbonPanelText(new RibbonPanelRenderEventArgs(Owner, e.Graphics, e.Clip, this, e.Control));
            }

            if (e.Mode != RibbonElementSizeMode.Overflow ||
                (e.Control != null && e.Control == PopUp))
            {
                foreach (RibbonItem item in Items)
                {
                    item.OnPaint(this, new RibbonElementPaintEventArgs(item.Bounds, e.Graphics, item.SizeMode));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates the regions of the panels and its contents
        /// </summary>
        internal void UpdatePanelsRegions()
        {
            if (Panels.Count == 0)
            {
                return;
            }

            bool dMode = Site != null && Site.DesignMode;

            if (!dMode)
            {
                _offset = 0;
            }

            int curRight  = TabContentBounds.Left + Owner.PanelPadding.Left + _offset;
            int panelsTop = TabContentBounds.Top + Owner.PanelPadding.Top;

            using (Graphics g = Owner.CreateGraphics())
            {
                //Check all at full size
                foreach (RibbonPanel panel in Panels)
                {
                    RibbonElementSizeMode sMode = panel.FlowsTo == RibbonPanelFlowDirection.Right ? RibbonElementSizeMode.Medium : RibbonElementSizeMode.Large;
                    //Set the bounds of the panel to let it know it's height
                    panel.SetBounds(new Rectangle(0, 0, 1, TabContentBounds.Height - Owner.PanelPadding.Vertical));

                    ///Size of the panel
                    Size size = panel.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, sMode));

                    ///Creates the bounds of the panel
                    Rectangle bounds = new Rectangle(
                        curRight, panelsTop,
                        size.Width, size.Height);

                    ///Set the bouns of the panel
                    panel.SetBounds(bounds);

                    ///Let the panel know what size we have decided for it
                    panel.SetSizeMode(sMode);

                    ///Update curLeft
                    curRight = bounds.Right + 1 + Owner.PanelSpacing;
                }


                if (!dMode)
                {
                    while (curRight > TabContentBounds.Right && !AllPanelsOverflow())
                    {
                        #region Down grade the larger panel one position

                        RibbonPanel larger = GetLargerPanel();

                        if (larger.SizeMode == RibbonElementSizeMode.Large)
                        {
                            larger.SetSizeMode(RibbonElementSizeMode.Medium);
                        }
                        else if (larger.SizeMode == RibbonElementSizeMode.Medium)
                        {
                            larger.SetSizeMode(RibbonElementSizeMode.Compact);
                        }
                        else if (larger.SizeMode == RibbonElementSizeMode.Compact)
                        {
                            larger.SetSizeMode(RibbonElementSizeMode.Overflow);
                        }

                        Size size = larger.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, larger.SizeMode));

                        larger.SetBounds(new Rectangle(larger.Bounds.Location, new Size(size.Width + Owner.PanelMargin.Horizontal, size.Height)));

                        #endregion

                        ///Reset x-axis reminder
                        curRight = TabContentBounds.Left + Owner.PanelPadding.Left;

                        ///Re-arrange location because of the new bounds
                        foreach (RibbonPanel panel in Panels)
                        {
                            Size s = panel.Bounds.Size;
                            panel.SetBounds(new Rectangle(new Point(curRight, panelsTop), s));
                            curRight += panel.Bounds.Width + 1 + Owner.PanelSpacing;
                        }
                    }
                }

                ///Update regions of all panels
                foreach (RibbonPanel panel in Panels)
                {
                    panel.UpdateItemsRegions(g, panel.SizeMode);
                }
            }

            UpdateScrollBounds();
        }