public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            var s = base.MeasureSize(sender, e);

            s.Height = 52;

            SetLastMeasuredSize(s);

            return(s);
        }
Пример #2
0
        /// <summary>
        ///     Measures the size when flow direction is to right
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToRight(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            var widthSum     = Owner.PanelMargin.Horizontal;
            var maxWidth     = 0;
            var maxHeight    = 0;
            var dividedWidth = 0;

            foreach (var item in Items)
            {
                if (item.Visible || Owner.IsDesignMode())
                {
                    var itemSize = item.MeasureSize(this, e);

                    widthSum += itemSize.Width + Owner.ItemPadding.Horizontal + 1;

                    maxWidth  = Math.Max(maxWidth, itemSize.Width);
                    maxHeight = Math.Max(maxHeight, itemSize.Height);
                }
            }

            switch (e.SizeMode)
            {
            case RibbonElementSizeMode.Large:
                dividedWidth = widthSum / 1;   //Show items on one row
                break;

            case RibbonElementSizeMode.Medium:
                dividedWidth = widthSum / 2;   //Show items on two rows
                break;

            case RibbonElementSizeMode.Compact:
                dividedWidth = widthSum / 3;   //Show items on three rows
                break;

            default:
                break;
            }

            //Add padding
            dividedWidth += Owner.PanelMargin.Horizontal;

            return(new Size(Math.Max(maxWidth, dividedWidth) + Owner.PanelMargin.Horizontal, 0)); //Height is provided by MeasureSize
        }
Пример #3
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            ///For RibbonItemGroup, size is always compact, and it's designed to be on an horizontal flow
            ///tab panel.
            ///
            if (!Visible || !Owner.CaptionBarVisible)
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            var widthSum  = Padding.Horizontal;
            var maxHeight = 16;

            foreach (var item in Items)
            {
                if (item.Equals(DropDownButton))
                {
                    continue;
                }
                item.SetSizeMode(RibbonElementSizeMode.Compact);
                var s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, RibbonElementSizeMode.Compact));
                widthSum += s.Width + 1;
                maxHeight = Math.Max(maxHeight, s.Height);
            }

            widthSum -= 1;

            if (Site != null && Site.DesignMode)
            {
                widthSum += 16;
            }

            var result = new Size(widthSum, maxHeight);

            SetLastMeasuredSize(result);
            return(result);
        }
Пример #4
0
        /// <summary>
        ///     Measures the size when flow direction is to bottom
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToBottom(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            var curRight        = Owner.PanelMargin.Left + Owner.ItemPadding.Horizontal;
            var curBottom       = ContentBounds.Top + Owner.ItemPadding.Vertical;
            var lastRight       = 0;
            var lastBottom      = 0;
            var availableHeight = OwnerTab.TabContentBounds.Height - Owner.TabContentMargin.Vertical - Owner.PanelPadding.Vertical - Owner.PanelMargin.Vertical;
            var maxRight        = 0;
            var maxBottom       = 0;

            foreach (var item in Items)
            {
                if (item.Visible || Owner.IsDesignMode() || item.GetType() == typeof(RibbonSeparator))
                {
                    var itemSize = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, e.SizeMode));

                    if (curBottom + itemSize.Height > ContentBounds.Bottom)
                    {
                        curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                        curRight  = maxRight + Owner.ItemPadding.Horizontal + 0;
                    }

                    var bounds = new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height);

                    lastRight  = bounds.Right;
                    lastBottom = bounds.Bottom;

                    curBottom = bounds.Bottom + Owner.ItemPadding.Vertical + 1;

                    maxRight  = Math.Max(maxRight, lastRight);
                    maxBottom = Math.Max(maxBottom, lastBottom);
                }
            }

            return(new Size(maxRight + Owner.ItemPadding.Right + Owner.PanelMargin.Right + 1, 0)); //Height is provided by MeasureSize
        }
Пример #5
0
        /// <summary>
        /// Measures the size of the button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            RibbonElementSizeMode theSize = GetNearestSize(e.SizeMode);
            int widthSum = Owner.ItemMargin.Horizontal;
            int heightSum = Owner.ItemMargin.Vertical;
            int largeHeight = OwnerPanel == null ? 0 : OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical;// -Owner.ItemMargin.Vertical; //58;

            Size simg = SmallImage != null ? SmallImage.Size : Size.Empty;
            Size img = Image != null ? Image.Size : Size.Empty;
            Size sz = Size.Empty;

            switch (theSize)
            {
                case RibbonElementSizeMode.Large:
                case RibbonElementSizeMode.Overflow:
                    sz = MeasureStringLargeSize(e.Graphics, Text, Owner.Font);
                    if (!string.IsNullOrEmpty(Text))
                    {
                        widthSum += Math.Max(sz.Width + 1, img.Width);
                        heightSum = largeHeight;
                    }
                    else
                    {
                        widthSum += img.Width;
                        heightSum += img.Height;
                    }
                    
                    break;
                case RibbonElementSizeMode.DropDown:
                case RibbonElementSizeMode.Medium:
                    sz = TextRenderer.MeasureText(Text, Owner.Font);
                    if(!string.IsNullOrEmpty(Text)) widthSum += sz.Width + 1;
                    widthSum += simg.Width + Owner.ItemMargin.Horizontal;
                    heightSum += Math.Max(sz.Height, simg.Height);
                    break;
                case RibbonElementSizeMode.Compact:
                    widthSum += simg.Width;
                    heightSum += simg.Height;
                    break;
                default:
                    throw new ApplicationException("SizeMode not supported: " + e.SizeMode.ToString());
            }

            if (theSize == RibbonElementSizeMode.DropDown)
            {
                heightSum += 2;
            }

            if (Style == RibbonButtonStyle.DropDown)
            {
                widthSum += arrowWidth + Owner.ItemMargin.Right;
            }
            else if (Style == RibbonButtonStyle.SplitDropDown)
            {
                widthSum += arrowWidth + Owner.ItemMargin.Horizontal;
            }

            SetLastMeasuredSize(new Size(widthSum, heightSum));

            return LastMeasuredSize;
        }
Пример #6
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            #region Determine items

            var itemsWide = 0;

            switch (e.SizeMode)
            {
            case RibbonElementSizeMode.DropDown:
                itemsWide = ItemsSizeInDropwDownMode.Width;
                break;

            case RibbonElementSizeMode.Large:
                itemsWide = ItemsWideInLargeMode;
                break;

            case RibbonElementSizeMode.Medium:
                itemsWide = ItemsWideInMediumMode;
                break;

            case RibbonElementSizeMode.Compact:
                itemsWide = 0;
                break;
            }

            #endregion

            var height       = OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical - 4;
            var scannedItems = 0;
            var widthSum     = 1;
            var buttonHeight = 0;
            var heightSum    = 0;
            var sumWidth     = true;

            foreach (RibbonButton button in Buttons)
            {
                var s = button.MeasureSize(this,
                                           new RibbonElementMeasureSizeEventArgs(e.Graphics, ButtonsSizeMode));

                if (sumWidth)
                {
                    widthSum += s.Width + 1;
                }

                buttonHeight = button.LastMeasuredSize.Height;
                heightSum   += buttonHeight;

                if (++scannedItems == itemsWide)
                {
                    sumWidth = false;
                }
            }

            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                height = buttonHeight * ItemsSizeInDropwDownMode.Height;
            }

            if (ScrollBarRenderer.IsSupported)
            {
                _thumbBounds = new Rectangle(Point.Empty, ScrollBarRenderer.GetSizeBoxSize(e.Graphics, ScrollBarState.Normal));
            }
            else
            {
                _thumbBounds = new Rectangle(Point.Empty, new Size(16, 16));
            }

            //if (height < 0)
            //{
            //    throw new Exception("???");
            //}

            //Got off the patch site from logicalerror
            //SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));
            SetLastMeasuredSize(new Size(Math.Max(0, widthSum + ControlButtonsWidth), Math.Max(0, height)));

            return(LastMeasuredSize);
        }
 public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            ///For RibbonItemGroup, size is always compact, and it's designed to be on an horizontal flow
            ///tab panel.
            ///
            int widthSum = Padding.Horizontal;
            int maxHeight = 16;

            foreach (RibbonItem item in Items)
            {
                if (item.Equals(DropDownButton)) continue;
                Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, RibbonElementSizeMode.Compact));
                widthSum += s.Width + 1;
                maxHeight = Math.Max(maxHeight, s.Height);
            }

            widthSum -= 1;

            if (Site != null && Site.DesignMode) widthSum += 16;

            Size result = new Size(widthSum, maxHeight);
            SetLastMeasuredSize(result);
            return result;
        }
Пример #9
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            #region Determine items

            int itemsWide = 0;

            switch (e.SizeMode)
            {
                case RibbonElementSizeMode.DropDown:
                    itemsWide = ItemsSizeInDropwDownMode.Width;
                    break;
                case RibbonElementSizeMode.Large:
                    itemsWide = ItemsWideInLargeMode;
                    break;
                case RibbonElementSizeMode.Medium:
                    itemsWide = ItemsWideInMediumMode;
                    break;
                case RibbonElementSizeMode.Compact:
                    itemsWide = 0;
                    break;
            }

            #endregion

            int height = OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical - 4;
            int scannedItems = 0;
            int widthSum = 1;
            int buttonHeight = 0;
            int heightSum = 0;
            bool sumWidth = true;

            foreach (RibbonButton button in Buttons)
            {
                Size s = button.MeasureSize(this, 
                    new RibbonElementMeasureSizeEventArgs(e.Graphics, this.ButtonsSizeMode));

                if (sumWidth)
                    widthSum += s.Width + 1;

                buttonHeight = button.LastMeasuredSize.Height;
                heightSum += buttonHeight;

                if (++scannedItems == itemsWide) sumWidth = false;
            }

            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                height = buttonHeight * ItemsSizeInDropwDownMode.Height;
            }

            if (ScrollBarRenderer.IsSupported)
            {
                _thumbBounds = new Rectangle(Point.Empty, ScrollBarRenderer.GetSizeBoxSize(e.Graphics, System.Windows.Forms.VisualStyles.ScrollBarState.Normal));
            }
            else
            {
                _thumbBounds = new Rectangle(Point.Empty, new Size(16, 16));
            }

            //if (height < 0)
            //{
            //    throw new Exception("???");
            //}
            SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));

            return LastMeasuredSize;
        }
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size s = base.MeasureSize(sender, e);

            s.Height = 52;

            SetLastMeasuredSize(s);

            return s;
        }
Пример #11
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size size = Size.Empty;

            int w = 0;
            int iwidth = Image != null ? Image.Width + spacing : 0;
            int lwidth = string.IsNullOrEmpty(Text) ? 0 : e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width + spacing;
            int twidth = TextBoxWidth;

            w += TextBoxWidth;

            switch (e.SizeMode)
            {
                case RibbonElementSizeMode.Large:
                    w += iwidth + lwidth;
                    break;
                case RibbonElementSizeMode.Medium:
                    w += iwidth;
                    break;
            }

            SetLastMeasuredSize(new Size(w, MeasureHeight()));

            return LastMeasuredSize;
        }
Пример #12
0
        /// <summary>
        ///     Measures the size of the button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            var theSize     = GetNearestSize(e.SizeMode);
            var widthSum    = Owner.ItemMargin.Horizontal;
            var heightSum   = Owner.ItemMargin.Vertical;
            var largeHeight = OwnerPanel == null ? 0 : OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical; // -Owner.ItemMargin.Vertical; //58;

            var simg = SmallImage != null ? SmallImage.Size : Size.Empty;
            var img  = Image != null ? Image.Size : Size.Empty;
            var sz   = Size.Empty;

            switch (theSize)
            {
            case RibbonElementSizeMode.Large:
            case RibbonElementSizeMode.Overflow:
                sz = MeasureStringLargeSize(e.Graphics, Text, Owner.Font);
                if (!string.IsNullOrEmpty(Text))
                {
                    widthSum += Math.Max(sz.Width + 1, img.Width);
                    //Got off the patch site from logicalerror
                    //heightSum = largeHeight;
                    heightSum = Math.Max(0, largeHeight);
                }
                else
                {
                    widthSum  += img.Width;
                    heightSum += img.Height;
                }

                break;

            case RibbonElementSizeMode.DropDown:
                sz = TextRenderer.MeasureText(Text, Owner.Font);
                if (!string.IsNullOrEmpty(Text))
                {
                    widthSum += sz.Width + 1;
                }
                widthSum  += simg.Width + Owner.ItemMargin.Horizontal;
                heightSum += Math.Max(sz.Height, simg.Height);
                heightSum += 2;
                break;

            case RibbonElementSizeMode.Medium:
                sz = TextRenderer.MeasureText(Text, Owner.Font);
                if (!string.IsNullOrEmpty(Text))
                {
                    widthSum += sz.Width + 1;
                }
                widthSum  += simg.Width + Owner.ItemMargin.Horizontal;
                heightSum += Math.Max(sz.Height, simg.Height);
                break;

            case RibbonElementSizeMode.Compact:
                widthSum  += simg.Width;
                heightSum += simg.Height;
                break;

            default:
                throw new ApplicationException("SizeMode not supported: " + e.SizeMode);
            }

            //if (theSize == RibbonElementSizeMode.DropDown)
            //{
            //   heightSum += 2;
            //}
            switch (Style)
            {
            case RibbonButtonStyle.DropDown:
            case RibbonButtonStyle.SplitDropDown:     // drawing size calculation for DropDown and SplitDropDown is identical
                widthSum += arrowWidth + _dropDownMargin.Horizontal;
                break;

            case RibbonButtonStyle.DropDownListItem:
                break;
            }

            //check the minimum and mazimum size properties but only in large mode
            if (theSize == RibbonElementSizeMode.Large)
            {
                //Minimum Size
                if (MinimumSize.Height > 0 && heightSum < MinimumSize.Height)
                {
                    heightSum = MinimumSize.Height;
                }
                if (MinimumSize.Width > 0 && widthSum < MinimumSize.Width)
                {
                    widthSum = MinimumSize.Width;
                }

                //Maximum Size
                if (MaximumSize.Height > 0 && heightSum > MaximumSize.Height)
                {
                    heightSum = MaximumSize.Height;
                }
                if (MaximumSize.Width > 0 && widthSum > MaximumSize.Width)
                {
                    widthSum = MaximumSize.Width;
                }
            }

            SetLastMeasuredSize(new Size(widthSum, heightSum));

            return(LastMeasuredSize);
        }
        /// <summary>
        /// Measures the size when flow direction is to right
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToRight(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            int widthSum = Owner.PanelMargin.Horizontal;
            int maxWidth = 0;
            int maxHeight = 0;
            int dividedWidth = 0;

            foreach (RibbonItem item in Items)
            {
                Size itemSize = item.MeasureSize(this, e);

                widthSum += itemSize.Width + Owner.ItemPadding.Horizontal + 1;

                maxWidth = Math.Max(maxWidth, itemSize.Width);
                maxHeight = Math.Max(maxHeight, itemSize.Height);
            }

            switch (e.SizeMode)
            {
                case RibbonElementSizeMode.Large:
                    dividedWidth = widthSum / 1; //Show items on one row
                    break;
                case RibbonElementSizeMode.Medium:
                    dividedWidth = widthSum / 2; //Show items on two rows
                    break;
                case RibbonElementSizeMode.Compact:
                    dividedWidth = widthSum / 3; //Show items on three rows
                    break;
                default:
                    break;
            }

            //Add padding
            dividedWidth += Owner.PanelMargin.Horizontal;

            return new Size(Math.Max(maxWidth, dividedWidth) + Owner.PanelMargin.Horizontal,0); //Height is provided by MeasureSize
        }
        /// <summary>
        /// Measures the size when flow direction is to bottom
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToBottom(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            int curRight = Owner.PanelMargin.Left + Owner.ItemPadding.Horizontal;
            int curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical;
            int lastRight = 0;
            int lastBottom = 0;
            int availableHeight = OwnerTab.TabContentBounds.Height - Owner.TabContentMargin.Vertical - Owner.PanelPadding.Vertical - Owner.PanelMargin.Vertical;
            int maxRight = 0;
            int maxBottom = 0;

            foreach (RibbonItem item in Items)
            {
                Size itemSize = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, e.SizeMode));

                if (curBottom + itemSize.Height > ContentBounds.Bottom)
                {
                    curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                    curRight = maxRight + Owner.ItemPadding.Horizontal + 0;
                }

                Rectangle bounds = new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height);

                lastRight = bounds.Right;
                lastBottom = bounds.Bottom;

                curBottom = bounds.Bottom + Owner.ItemPadding.Vertical + 1;

                maxRight = Math.Max(maxRight, lastRight);
                maxBottom = Math.Max(maxBottom, lastBottom);
            }

            return new Size(maxRight + Owner.ItemPadding.Right + Owner.PanelMargin.Right + 1, 0); //Height is provided by MeasureSize
        }
        /// <summary>
        /// Measures the size of the panel on the mode specified by the event object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size result = Size.Empty;
            Size minSize = Size.Empty;
            int panelHeight = OwnerTab.TabContentBounds.Height - Owner.PanelPadding.Vertical;

            #region Measure width of minSize

            minSize.Width = e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width  + Owner.PanelMargin.Horizontal + 1;

            if (ButtonMoreVisible)
            {
                minSize.Width += ButtonMoreBounds.Width + 3;
            }

            #endregion

            if (e.SizeMode == RibbonElementSizeMode.Overflow)
            {
                Size textSize = RibbonButton.MeasureStringLargeSize(e.Graphics, Text, Owner.Font);

                return new Size(textSize.Width + Owner.PanelMargin.Horizontal, panelHeight);
            }

            switch (FlowsTo)
            {
                case RibbonPanelFlowDirection.Right:
                    result = MeasureSizeFlowsToRight(sender, e);
                    break;
                case RibbonPanelFlowDirection.Bottom:
                    result = MeasureSizeFlowsToBottom(sender, e);
                    break;
                default:
                    result = Size.Empty;
                    break;
            }

            return new Size(Math.Max(result.Width, minSize.Width), panelHeight);
        }
Пример #16
0
 public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);
Пример #17
0
        /// <summary>
        /// Measures the size of the tab. The tab content bounds is measured by the Ribbon control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size textSize = TextRenderer.MeasureText(Text, Owner.Font);

            return textSize;
        }
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            #region Determine items

            int itemsWide = 0;

            switch (e.SizeMode)
            {
                case RibbonElementSizeMode.DropDown:
                    itemsWide = ItemsSizeInDropwDownMode.Width;
                    break;
                case RibbonElementSizeMode.Large:
                    itemsWide = ItemsWideInLargeMode;
                    break;
                case RibbonElementSizeMode.Medium:
                    itemsWide = ItemsWideInMediumMode;
                    break;
                case RibbonElementSizeMode.Compact:
                    itemsWide = 0;
                    break;
            }

            #endregion

            int height = OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical - 4;
            int scannedItems = 0;
            int widthSum = 1;
            int buttonHeight = 0;
            bool sumWidth = true;

            foreach (RibbonButton button in Buttons)
            {
                Size s = button.MeasureSize(this,
                                            new RibbonElementMeasureSizeEventArgs(e.Graphics, ButtonsSizeMode));

                if (sumWidth)
                    widthSum += s.Width + 1;

                buttonHeight = button.LastMeasuredSize.Height;

                if (++scannedItems == itemsWide) sumWidth = false;
            }

            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                height = buttonHeight * ItemsSizeInDropwDownMode.Height;
            }

            SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));

            return LastMeasuredSize;
        }