internal override Rectangle OnGetTextBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            Rectangle r = base.OnGetTextBounds(sMode, bounds);

            r.X = Bounds.Left + 3;

            return r;
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new RibbonPanel
 /// </summary>
 public RibbonPanel()
 {
     _items = new RibbonItemCollection();
     _sizeMode = RibbonElementSizeMode.None;
     _flowsTo = RibbonPanelFlowDirection.Bottom;
     _buttonMoreEnabled = true;
     _buttonMoreVisible = true;
     _items.SetOwnerPanel(this);
     _enabled = true;
 }
        public RibbonButtonList()
        {
            _buttons = new RibbonButtonCollection(this);
            _dropDownItems = new RibbonItemCollection();

            _controlButtonsWidth = 16;
            _itemsInLargeMode = 7;
            _itemsInMediumMode = 3;
            _ItemsInDropwDownMode = new Size(7, 5);
            _buttonsSizeMode = RibbonElementSizeMode.Large;
        }
Esempio n. 4
0
        internal RibbonDropDown(RibbonItem parentItem, IEnumerable<RibbonItem> items, Ribbon ownerRibbon, RibbonElementSizeMode measuringSize)
            : this()
        {
            _items = items;
            _ownerRibbon = ownerRibbon;
            _sizingGripHeight = 12;
            _parentItem = parentItem;
            _sensor = new RibbonMouseSensor(this, OwnerRibbon, items);
            _MeasuringSize = measuringSize;

            if (Items != null)
                foreach (RibbonItem item in Items)
                {
                    item.SetSizeMode(RibbonElementSizeMode.DropDown);
                    item.SetCanvas(this);
                }

            UpdateSize();
        }
Esempio n. 5
0
        /// <summary>
        ///     Sets the bounds of the text of the button when SetBounds is called.
        ///     Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        ///     The measuring occours in the following order:
        ///     <list type="">
        ///         <item>OnSetImageBounds</item>
        ///         <item>OnSetTextBounds</item>
        ///         <item>OnSetDropDownBounds</item>
        ///         <item>OnSetButtonFaceBounds</item>
        ///     </list>
        /// </remarks>
        internal virtual Rectangle OnGetTextBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            var imgw = _imageBounds.Width;
            var imgh = _imageBounds.Height;

            if (sMode == RibbonElementSizeMode.Large)
            {
                return(Rectangle.FromLTRB(
                           Bounds.Left + Owner.ItemMargin.Left,
                           Bounds.Top + Owner.ItemMargin.Top + imgh,
                           Bounds.Right - Owner.ItemMargin.Right,
                           Bounds.Bottom - Owner.ItemMargin.Bottom));
            }
            var ddw = Style != RibbonButtonStyle.Normal ? _dropDownMargin.Horizontal : 0;

            return(Rectangle.FromLTRB(
                       Bounds.Left + imgw + Owner.ItemMargin.Horizontal + Owner.ItemMargin.Left,
                       Bounds.Top + Owner.ItemMargin.Top,
                       Bounds.Right - ddw,
                       Bounds.Bottom - Owner.ItemMargin.Bottom));
        }
Esempio n. 6
0
        /// <summary>
        /// Renders the image of the button
        /// </summary>
        /// <param name="e"></param>
        private void OnPaintImage(RibbonElementPaintEventArgs e)
        {
            RibbonElementSizeMode theSize = GetNearestSize(e.Mode);

            if (_showFlashImage)
            {
                if ((theSize == RibbonElementSizeMode.Large && FlashImage != null) || SmallImage != null)
                {
                    Owner.Renderer.OnRenderRibbonItemImage(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, OnGetImageBounds(theSize, Bounds)));
                }
            }
            else
            {
                if ((theSize == RibbonElementSizeMode.Large && Image != null) || SmallImage != null)
                {
                    Owner.Renderer.OnRenderRibbonItemImage(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, OnGetImageBounds(theSize, Bounds)));
                }
            }
        }
Esempio n. 7
0
        internal RibbonDropDown(RibbonItem parentItem, IEnumerable <RibbonItem> items, Ribbon ownerRibbon, RibbonElementSizeMode measuringSize)
            : this()
        {
            _items            = items;
            _ownerRibbon      = ownerRibbon;
            _sizingGripHeight = 12;
            _parentItem       = parentItem;
            _sensor           = new RibbonMouseSensor(this, OwnerRibbon, items);
            _MeasuringSize    = measuringSize;

            if (Items != null)
            {
                foreach (RibbonItem item in Items)
                {
                    item.SetSizeMode(RibbonElementSizeMode.DropDown);
                    item.SetCanvas(this);
                }
            }

            UpdateSize();
        }
Esempio n. 8
0
        /// <summary>
        /// Updates the bounds of child elements when flow is to bottom
        /// </summary>
        private void UpdateRegionsFlowsToBottom(Graphics g, RibbonElementSizeMode mode)
        {
            int curRight   = ContentBounds.Left + Owner.ItemPadding.Horizontal + 0;
            int curBottom  = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
            int lastRight  = curRight;
            int lastBottom = 0;
            List <RibbonItem> lastColumn = new List <RibbonItem>();

            ///Iterate thru items on panel
            foreach (RibbonItem item in Items)
            {
                ///Gets the last measured size (to avoid re-measuring calculations)
                Size itemSize = item.LastMeasuredSize;

                ///If not enough space available, reset curBottom and advance curRight
                if (curBottom + itemSize.Height > ContentBounds.Bottom)
                {
                    curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                    curRight  = lastRight + Owner.ItemPadding.Horizontal + 0;
                    Items.CenterItemsVerticallyInto(lastColumn, ContentBounds);
                    lastColumn.Clear();
                }

                ///Set the item's bounds
                item.SetBounds(new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height));

                ///save last right and bottom
                lastRight  = Math.Max(item.Bounds.Right, lastRight);
                lastBottom = item.Bounds.Bottom;

                ///update current bottom
                curBottom = item.Bounds.Bottom + Owner.ItemPadding.Vertical + 1;

                ///Add to the collection of items of the last column
                lastColumn.Add(item);
            }

            ///Center the items vertically on the last column
            Items.CenterItemsVerticallyInto(lastColumn, Items.GetItemsBounds());
        }
Esempio n. 9
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            var design = ((Site?.DesignMode ?? false) ||
                          IsOpenInVisualStudioDesigner());

            if (design && (Owner != null))
            {
                var       width  = Convert.ToInt32(e.Graphics.MeasureString(Site.Name, Owner.Font).Width);
                const int height = 20;
                if ((width == LastMeasuredSize.Width) &&
                    (height == LastMeasuredSize.Height))
                {
                    return(LastMeasuredSize);
                }
                SetLastMeasuredSize(new Size(width, height));
            }
            else if ((_ctl == null) || !Visible)
            {
                SetLastMeasuredSize(new Size(0, 0));
            }
            else
            {
                if ((_lastSizeMode == e.SizeMode) &&
                    (_ctl.Size.Width == LastMeasuredSize.Width) &&
                    (_ctl.Size.Height == LastMeasuredSize.Height))
                {
                    return(LastMeasuredSize);
                }
                _ctl.Visible = false;
                if (_lastSizeMode != e.SizeMode)
                {
                    _lastSizeMode = e.SizeMode;
                    var hev = new RibbonHostSizeModeHandledEventArgs(e.Graphics, e.SizeMode);
                    OnSizeModeChanging(ref hev);
                }
                SetLastMeasuredSize(new Size(_ctl.Size.Width, _ctl.Size.Height));
            }
            return(LastMeasuredSize);
        }
Esempio n. 10
0
        /// <summary>
        /// Sets the bounds of the dropdown part of the button when SetBounds is called.
        /// Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        /// The measuring occours in the following order:
        /// <list type="">
        /// <item>OnSetImageBounds</item>
        /// <item>OnSetTextBounds</item>
        /// <item>OnSetDropDownBounds</item>
        /// <item>OnSetButtonFaceBounds</item>
        /// </list>
        /// </remarks>
        internal virtual Rectangle OnGetDropDownBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            Rectangle sideBounds = Rectangle.FromLTRB(
                bounds.Right - _dropDownMargin.Horizontal - 2,
                bounds.Top, bounds.Right, bounds.Bottom);

            switch (SizeMode)
            {
            case RibbonElementSizeMode.Large:
            case RibbonElementSizeMode.Overflow:
                return(Rectangle.FromLTRB(bounds.Left,
                                          bounds.Top + Image.Height + Owner.ItemMargin.Vertical,
                                          bounds.Right, bounds.Bottom));

            case RibbonElementSizeMode.DropDown:
            case RibbonElementSizeMode.Medium:
            case RibbonElementSizeMode.Compact:
                return(sideBounds);
            }


            return(Rectangle.Empty);
        }
Esempio n. 11
0
        /// <summary>
        /// Sets the bounds of the button face part of the button when SetBounds is called.
        /// Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        /// The measuring occours in the following order:
        /// <list type="">
        /// <item>OnSetImageBounds</item>
        /// <item>OnSetTextBounds</item>
        /// <item>OnSetDropDownBounds</item>
        /// <item>OnSetButtonFaceBounds</item>
        /// </list>
        /// </remarks>
        internal virtual Rectangle OnGetButtonFaceBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            Rectangle sideBounds = Rectangle.FromLTRB(
                bounds.Right - _dropDownMargin.Horizontal - 2,
                bounds.Top, bounds.Right, bounds.Bottom);

            switch (sMode)
            {
            case RibbonElementSizeMode.Large:
            case RibbonElementSizeMode.Overflow:
                return(Rectangle.FromLTRB(bounds.Left,
                                          bounds.Top, bounds.Right, _dropDownBounds.Top));

            case RibbonElementSizeMode.DropDown:
            case RibbonElementSizeMode.Medium:
            case RibbonElementSizeMode.Compact:
                return(Rectangle.FromLTRB(bounds.Left, bounds.Top,
                                          _dropDownBounds.Left, bounds.Bottom));
            }


            return(Rectangle.Empty);
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the panel with the larger width and the specified size mode
        /// </summary>
        /// <param name="size">Size mode of panel to search</param>
        /// <returns>Larger panel. Null if none of the specified size mode</returns>
        private RibbonPanel GetLargerPanel(RibbonElementSizeMode size)
        {
            RibbonPanel result = null;

            foreach (RibbonPanel panel in Panels)
            {
                if (panel.SizeMode != size)
                {
                    continue;
                }

                if (result == null)
                {
                    result = panel;
                }

                if (panel.Bounds.Width > result.Bounds.Width)
                {
                    result = panel;
                }
            }

            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// Renders the image of the button
        /// </summary>
        /// <param name="e"></param>
        private void OnPaintImage(RibbonElementPaintEventArgs e)
        {
            RibbonElementSizeMode theSize     = GetNearestSize(e.Mode);
            Rectangle             imageBounds = OnGetImageBounds(theSize, Bounds);

            Rectangle paddedBounds = new Rectangle(imageBounds.X, imageBounds.Y + _padding.Top, imageBounds.Width, imageBounds.Height);

            if (_showFlashImage)
            {
                if ((theSize == RibbonElementSizeMode.Large && FlashImage != null) || FlashSmallImage != null)
                {
                    Owner.Renderer.OnRenderRibbonItemImage(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, paddedBounds));
                }
            }
            else
            {
                if ((theSize == RibbonElementSizeMode.Large && Image != null) || SmallImage != null)
                {
                    Owner.Renderer.OnRenderRibbonItemImage(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, paddedBounds));
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 ///     Sets the bounds of the image of the button when SetBounds is called.
 ///     Override this method to change image bounds
 /// </summary>
 /// <param name="sMode">Mode which is being measured</param>
 /// <param name="bounds">Bounds of the button</param>
 /// <remarks>
 ///     The measuring occours in the following order:
 ///     <list type="">
 ///         <item>OnSetImageBounds</item>
 ///         <item>OnSetTextBounds</item>
 ///         <item>OnSetDropDownBounds</item>
 ///         <item>OnSetButtonFaceBounds</item>
 ///     </list>
 /// </remarks>
 internal virtual Rectangle OnGetImageBounds(RibbonElementSizeMode sMode, Rectangle bounds)
 {
     if (sMode == RibbonElementSizeMode.Large) // || this is RibbonOrbMenuItem)
     {
         if (Image != null)
         {
             return(new Rectangle(
                        Bounds.Left + ((Bounds.Width - Image.Width) / 2),
                        Bounds.Top + Owner.ItemMargin.Top,
                        Image.Width,
                        Image.Height));
         }
         return(new Rectangle(ContentBounds.Location, new Size(32, 32)));
     }
     if (SmallImage != null)
     {
         return(new Rectangle(
                    Bounds.Left + Owner.ItemMargin.Left,
                    Bounds.Top + ((Bounds.Height - SmallImage.Height) / 2),
                    SmallImage.Width,
                    SmallImage.Height));
     }
     return(new Rectangle(ContentBounds.Location, new Size(0, 0)));
 }
Esempio n. 15
0
        /// <summary>
        /// Sets the bounds of the button
        /// </summary>
        /// <param name="bounds"></param>
        public override void SetBounds(System.Drawing.Rectangle bounds)
        {
            base.SetBounds(bounds);

            RibbonElementSizeMode theSize = GetNearestSize(SizeMode);

            if (theSize == RibbonElementSizeMode.Large)
            {
                if (Image != null)
                {
                    _imageBounds = new Rectangle(
                        Bounds.Left + ((Bounds.Width - Image.Width) / 2),
                        Bounds.Top + Owner.ItemMargin.Top,
                        Image.Width,
                        Image.Height);
                }
                else
                {
                    _imageBounds = new Rectangle(ContentBounds.Location, new Size(32, 32));
                }
            }
            else
            {
                if (SmallImage != null)
                {
                    _imageBounds = new Rectangle(
                        Bounds.Left + Owner.ItemMargin.Left,
                        Bounds.Top + ((Bounds.Height - SmallImage.Height) / 2),
                        SmallImage.Width,
                        SmallImage.Height);
                }
                else
                {
                    _imageBounds = new Rectangle(ContentBounds.Location, new Size(16, 16));
                }
            }

            int imgw = _imageBounds.Width;
            int imgh = _imageBounds.Height;

            if (theSize == RibbonElementSizeMode.Large)
            {
                _textBounds = Rectangle.FromLTRB(
                    Bounds.Left + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top + imgh + Owner.ItemMargin.Vertical,
                    Bounds.Right - Owner.ItemMargin.Right,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);
            }
            else
            {
                int ddw = Style != RibbonButtonStyle.Normal ? _dropDownMargin.Horizontal : 0;
                _textBounds = Rectangle.FromLTRB(
                    Bounds.Left + imgw + Owner.ItemMargin.Horizontal + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top,
                    Bounds.Right - ddw,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);
            }


            if (Style == RibbonButtonStyle.SplitDropDown)
            {
                Rectangle sideBounds = Rectangle.FromLTRB(
                    bounds.Right - _dropDownMargin.Horizontal - 2,
                    bounds.Top, bounds.Right, bounds.Bottom);

                switch (SizeMode)
                {
                case RibbonElementSizeMode.Large:
                case RibbonElementSizeMode.Overflow:
                    _dropDownBounds = Rectangle.FromLTRB(bounds.Left,
                                                         bounds.Top + Image.Height + Owner.ItemMargin.Vertical,
                                                         bounds.Right, bounds.Bottom);
                    _buttonFaceBounds = Rectangle.FromLTRB(bounds.Left,
                                                           bounds.Top, bounds.Right, _dropDownBounds.Top);
                    break;

                case RibbonElementSizeMode.DropDown:
                case RibbonElementSizeMode.Medium:
                case RibbonElementSizeMode.Compact:
                    _dropDownBounds   = sideBounds;
                    _buttonFaceBounds = Rectangle.FromLTRB(bounds.Left, bounds.Top,
                                                           _dropDownBounds.Left, bounds.Bottom);
                    break;
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Updates the bounds of child elements when flow is to bottom
        /// </summary>
        private void UpdateRegionsFlowsToRight(Graphics g, RibbonElementSizeMode mode)
        {
            int curLeft   = ContentBounds.Left;
            int curTop    = ContentBounds.Top;
            int padding   = mode == RibbonElementSizeMode.Medium ? 7 : 0;
            int maxBottom = 0;

            #region Sorts from larger to smaller

            RibbonItem[] array = Items.ToArray();

            for (int i = (array.Length - 1); i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (array[j - 1].LastMeasuredSize.Width < array[j].LastMeasuredSize.Width)
                    {
                        RibbonItem temp = array[j - 1];
                        array[j - 1] = array[j];
                        array[j]     = temp;
                    }
                }
            }

            #endregion

            List <RibbonItem> list = new List <RibbonItem>(array);

            ///Attend elements, deleting every attended element from the list
            while (list.Count > 0)
            {
                ///Extract item and delete it
                RibbonItem item = list[0];
                list.Remove(item);

                ///If not enough space left, reset left and advance top
                if (curLeft + item.LastMeasuredSize.Width > ContentBounds.Right)
                {
                    curLeft = ContentBounds.Left;
                    curTop  = maxBottom + Owner.ItemPadding.Vertical + 1 + padding;
                }

                ///Set item's bounds
                item.SetBounds(new Rectangle(new Point(curLeft, curTop), item.LastMeasuredSize));

                ///Increment reminders
                curLeft  += item.Bounds.Width + Owner.ItemPadding.Horizontal;
                maxBottom = Math.Max(maxBottom, item.Bounds.Bottom);

                ///Check available space after placing item
                int spaceAvailable = ContentBounds.Right - curLeft;

                ///Check for elements that fit on available space
                for (int i = 0; i < list.Count; i++)
                {
                    ///If item fits on the available space
                    if (list[i].LastMeasuredSize.Width < spaceAvailable)
                    {
                        ///Place the item there and reset the counter to check for further items
                        list[i].SetBounds(new Rectangle(new Point(curLeft, curTop), list[i].LastMeasuredSize));
                        curLeft       += list[i].Bounds.Width + Owner.ItemPadding.Horizontal;
                        maxBottom      = Math.Max(maxBottom, list[i].Bounds.Bottom);
                        spaceAvailable = ContentBounds.Right - curLeft;
                        list.RemoveAt(i);
                        i = 0;
                    }
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Updates the bounds of child elements when flow is to bottom
        /// </summary>
        private void UpdateRegionsFlowsToRight(Graphics g, RibbonElementSizeMode mode)
        {
            int curLeft = ContentBounds.Left;
            int curTop = ContentBounds.Top;
            int padding = mode == RibbonElementSizeMode.Medium ? 7 : 0;
            int maxBottom = 0;

            #region Sorts from larger to smaller

            RibbonItem[] array = Items.ToArray();

            for (int i = (array.Length - 1); i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (array[j - 1].LastMeasuredSize.Width < array[j].LastMeasuredSize.Width)
                    {
                        RibbonItem temp = array[j - 1];
                        array[j - 1] = array[j];
                        array[j] = temp;
                    }
                }
            }

            #endregion

            List<RibbonItem> list = new List<RibbonItem>(array);

            ///Attend elements, deleting every attended element from the list
            while (list.Count > 0)
            {
                ///Extract item and delete it
                RibbonItem item = list[0];
                list.Remove(item);

                ///If not enough space left, reset left and advance top
                if (curLeft + item.LastMeasuredSize.Width > ContentBounds.Right)
                {
                    curLeft = ContentBounds.Left;
                    curTop = maxBottom + Owner.ItemPadding.Vertical + 1 + padding;
                }

                ///Set item's bounds
                item.SetBounds(new Rectangle(new Point(curLeft, curTop), item.LastMeasuredSize));

                ///Increment reminders
                curLeft += item.Bounds.Width + Owner.ItemPadding.Horizontal;
                maxBottom = Math.Max(maxBottom, item.Bounds.Bottom);

                ///Check available space after placing item
                int spaceAvailable = ContentBounds.Right - curLeft;

                ///Check for elements that fit on available space
                for (int i = 0; i < list.Count; i++)
                {
                    ///If item fits on the available space
                    if (list[i].LastMeasuredSize.Width < spaceAvailable)
                    {
                        ///Place the item there and reset the counter to check for further items
                        list[i].SetBounds(new Rectangle(new Point(curLeft, curTop), list[i].LastMeasuredSize));
                        curLeft += list[i].Bounds.Width + Owner.ItemPadding.Horizontal;
                        maxBottom = Math.Max(maxBottom, list[i].Bounds.Bottom);
                        spaceAvailable = ContentBounds.Right - curLeft;
                        list.RemoveAt(i);
                        i = 0;
                    }
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnPaint(object sender, RibbonElementPaintEventArgs e)
        {
            if (Owner == null)
            {
                return;
            }
            RibbonElementSizeMode theSize = GetNearestSize(e.Mode);

            Owner.Renderer.OnRenderRibbonItem(new RibbonItemRenderEventArgs(Owner, e.Graphics, e.Clip, this));

            Rectangle img = Rectangle.Empty;

            if (theSize == RibbonElementSizeMode.Large)
            {
                if (Image != null)
                {
                    img = new Rectangle(
                        Bounds.Left + ((Bounds.Width - Image.Width) / 2),
                        Bounds.Top + Owner.ItemMargin.Top,
                        Image.Width,
                        Image.Height);

                    Owner.Renderer.OnRenderRibbonItemImage(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, img));
                }
            }
            else
            {
                if (SmallImage != null)
                {
                    img = new Rectangle(
                        Bounds.Left + Owner.ItemMargin.Left,
                        Bounds.Top + ((Bounds.Height - SmallImage.Height) / 2),
                        SmallImage.Width,
                        SmallImage.Height);

                    Owner.Renderer.OnRenderRibbonItemImage(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, img));
                }
            }

            Rectangle t    = Rectangle.Empty;
            int       imgw = SmallImage == null ? 16 : SmallImage.Width;
            int       imgh = Image == null ? 32 : Image.Height;

            if (theSize == RibbonElementSizeMode.Large)
            {
                t = Rectangle.FromLTRB(
                    Bounds.Left + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top + imgh + Owner.ItemMargin.Vertical,
                    Bounds.Right - Owner.ItemMargin.Right,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);

                if (SizeMode != RibbonElementSizeMode.Compact)
                {
                    Owner.Renderer.OnRenderRibbonItemText(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, t));
                }
            }
            else
            {
                int ddw = Style != RibbonButtonStyle.Normal ? _dropDownMargin.Horizontal : 0;
                t = Rectangle.FromLTRB(
                    Bounds.Left + imgw + Owner.ItemMargin.Horizontal + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top,
                    Bounds.Right - ddw,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);

                if (SizeMode != RibbonElementSizeMode.Compact)
                {
                    Owner.Renderer.OnRenderRibbonItemText(
                        new RibbonItemBoundsEventArgs(Owner, e.Graphics, e.Clip, this, t));
                }
            }
        }
Esempio n. 19
0
        internal override void SetSizeMode(RibbonElementSizeMode sizeMode)
        {
            base.SetSizeMode(sizeMode);

            foreach (RibbonItem item in Items)
            {
                item.SetSizeMode(RibbonElementSizeMode.Compact);
            }
        }
 internal override Rectangle OnGetImageBounds(RibbonElementSizeMode sMode, System.Drawing.Rectangle bounds)
 {
     return Rectangle.Empty;
 }
Esempio n. 21
0
 internal override void SetSizeMode(RibbonElementSizeMode sizeMode)
 {
     if (sizeMode == RibbonElementSizeMode.Overflow)
     {
         base.SetSizeMode(RibbonElementSizeMode.Large);
     }
     else
     {
         base.SetSizeMode(sizeMode);
     }
 }
 internal RibbonElementPaintEventArgs(Rectangle clip, Graphics graphics, RibbonElementSizeMode mode, Control control)
     : this(clip, graphics, mode)
 {
     _control = control;
 }
 /// <param name="clip">Rectangle clip</param>
 /// <param name="graphics">Device to draw</param>
 /// <param name="mode">Size mode to draw</param>
 internal RibbonElementPaintEventArgs(Rectangle clip, Graphics graphics, RibbonElementSizeMode mode)
 {
     _clip = clip;
     _graphics = graphics;
     _mode = mode;
 }
 /// <summary>
 ///     Creates a new RibbonElementMeasureSizeEventArgs object
 /// </summary>
 /// <param name="graphics">Device info to draw and measure</param>
 /// <param name="sizeMode">Size mode to measure</param>
 internal RibbonElementMeasureSizeEventArgs(Graphics graphics, RibbonElementSizeMode sizeMode)
 {
     _graphics = graphics;
     _sizeMode = sizeMode;
 }
 /// <summary>
 ///     Creates a new RibbonElementMeasureSizeEventArgs object
 /// </summary>
 /// <param name="graphics">Device info to draw and measure</param>
 /// <param name="sizeMode">Size mode to measure</param>
 internal RibbonHostSizeModeHandledEventArgs(Graphics graphics, RibbonElementSizeMode sizeMode)
 {
     _graphics = graphics;
     _sizeMode = sizeMode;
 }
Esempio n. 26
0
        internal RibbonDropDown(RibbonItem parentItem, IEnumerable <RibbonItem> items, Ribbon ownerRibbon, RibbonElementSizeMode measuringSize)
            : this()
        {
            _items            = items;
            _ownerRibbon      = ownerRibbon;
            _sizingGripHeight = 12;
            _parentItem       = parentItem;
            _sensor           = new RibbonMouseSensor(this, OwnerRibbon, items);
            _MeasuringSize    = measuringSize;
            _scrollBarSize    = 16;

            if (Items != null)
            {
                foreach (RibbonItem item in Items)
                {
                    item.SetSizeMode(RibbonElementSizeMode.DropDown);
                    item.SetCanvas(this);

                    //If item is a RibbonHost, the MouseSensor will not detect the mouse move event, so manually hook into the event.
                    if (item is RibbonHost)
                    {
                        ((RibbonHost)item).ClientMouseMove += new MouseEventHandler(OnRibbonHostMouseMove);
                    }
                }
            }

            UpdateSize();
        }
Esempio n. 27
0
        internal override Rectangle OnGetTextBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            Rectangle r = base.OnGetTextBounds(sMode, bounds);
            DescriptionBounds = r;

            r.Height = 20;

            DescriptionBounds = Rectangle.FromLTRB(DescriptionBounds.Left, r.Bottom, DescriptionBounds.Right, DescriptionBounds.Bottom);

            return r;
        }
Esempio n. 28
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);
            }

            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);
                    //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 = Size.Ceiling(e.Graphics.MeasureString(Text, Owner.Font));
                if (!string.IsNullOrEmpty(Text))
                {
                    widthSum += sz.Width + 1;
                }
                widthSum  += simg.Width + Owner.ItemMargin.Horizontal + Owner.ItemImageToTextSpacing;
                heightSum += Math.Max(sz.Height, simg.Height);
                break;

            case RibbonElementSizeMode.Medium:
                sz = Size.Ceiling(e.Graphics.MeasureString(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;
            //}
            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>
 /// Creates a new RibbonElementMeasureSizeEventArgs object
 /// </summary>
 /// <param name="graphics">Device info to draw and measure</param>
 /// <param name="sizeMode">Size mode to measure</param>
 internal RibbonElementMeasureSizeEventArgs(System.Drawing.Graphics graphics, RibbonElementSizeMode sizeMode)
 {
     _graphics = graphics;
     _sizeMode = sizeMode;
 }
Esempio n. 30
0
        /// <summary>
        /// Sets the bounds of the button face part of the button when SetBounds is called.
        /// Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        /// The measuring occours in the following order:
        /// <list type="">
        /// <item>OnSetImageBounds</item>
        /// <item>OnSetTextBounds</item>
        /// <item>OnSetDropDownBounds</item>
        /// <item>OnSetButtonFaceBounds</item>
        /// </list>
        /// </remarks>
        internal virtual Rectangle OnGetButtonFaceBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            Rectangle sideBounds = Rectangle.FromLTRB(
                bounds.Right - _dropDownMargin.Horizontal - 2,
                bounds.Top, bounds.Right, bounds.Bottom);

            switch (SizeMode)
            {
                case RibbonElementSizeMode.Large:
                case RibbonElementSizeMode.Overflow:
                    return Rectangle.FromLTRB(bounds.Left,
                        bounds.Top, bounds.Right, _dropDownBounds.Top);

                case RibbonElementSizeMode.DropDown:
                case RibbonElementSizeMode.Medium:
                case RibbonElementSizeMode.Compact:
                    return Rectangle.FromLTRB(bounds.Left, bounds.Top,
                        _dropDownBounds.Left, bounds.Bottom);

            }

            return Rectangle.Empty;
        }
Esempio n. 31
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);
        }
Esempio n. 32
0
 /// <summary>
 /// Sets the bounds of the image of the button when SetBounds is called.
 /// Override this method to change image bounds
 /// </summary>
 /// <param name="sMode">Mode which is being measured</param>
 /// <param name="bounds">Bounds of the button</param>
 /// <remarks>
 /// The measuring occours in the following order:
 /// <list type="">
 /// <item>OnSetImageBounds</item>
 /// <item>OnSetTextBounds</item>
 /// <item>OnSetDropDownBounds</item>
 /// <item>OnSetButtonFaceBounds</item>
 /// </list>
 /// </remarks>
 internal virtual Rectangle OnGetImageBounds(RibbonElementSizeMode sMode, Rectangle bounds)
 {
     if (sMode == RibbonElementSizeMode.Large)// || this is RibbonOrbMenuItem)
     {
         if (Image != null)
         {
             return new Rectangle(
             Bounds.Left + ((Bounds.Width - Image.Width) / 2),
             Bounds.Top + Owner.ItemMargin.Top,
             Image.Width,
             Image.Height);
         }
         else
         {
             return new Rectangle(ContentBounds.Location, new Size(32, 32));
         }
     }
     else
     {
         if (SmallImage != null)
         {
             return new Rectangle(
                 Bounds.Left + Owner.ItemMargin.Left,
                 Bounds.Top + ((Bounds.Height - SmallImage.Height) / 2),
                 SmallImage.Width,
                 SmallImage.Height);
         }
         else
         {
             return new Rectangle(ContentBounds.Location, new Size(0, 0));
         }
     }
 }
 /// <param name="clip">Rectangle clip</param>
 /// <param name="graphics">Device to draw</param>
 /// <param name="mode">Size mode to draw</param>
 internal RibbonElementPaintEventArgs(Rectangle clip, Graphics graphics, RibbonElementSizeMode mode)
 {
     Clip     = clip;
     Graphics = graphics;
     Mode     = mode;
 }
Esempio n. 34
0
        private RibbonButton AddButton(RibbonItemCollection collection, RibbonButtonStyle style, string label, string msoImageName,
			string msoCommandName, RibbonElementSizeMode maxSizeMode = RibbonElementSizeMode.None, Action customAction = null)
        {
            RibbonButton button = new RibbonButton();
            button.Style = style;
            button.MaxSizeMode = maxSizeMode;
            button.Text = label;
            AssignImage(button, msoImageName);
            if (customAction == null) {
                AssignAction(button, msoCommandName);
            } else {
                EventHandler handler = new EventHandler(delegate(object sender, EventArgs ea) {
                    RunCommand(customAction);
                });
                button.Click += handler;
                button.DoubleClick += handler;
            }
            collection.Add(button);
            return button;
        }
Esempio n. 35
0
 internal override Rectangle OnGetImageBounds(RibbonElementSizeMode sMode, System.Drawing.Rectangle bounds)
 {
     return Rectangle.Empty;
 }
      internal RibbonDropDown(RibbonItem parentItem, IEnumerable<RibbonItem> items, Ribbon ownerRibbon, RibbonElementSizeMode measuringSize)
         : this()
      {
         _items = items;
         _ownerRibbon = ownerRibbon;
         _sizingGripHeight = 12;
         _parentItem = parentItem;
         _sensor = new RibbonMouseSensor(this, OwnerRibbon, items);
         _MeasuringSize = measuringSize;
         _scrollBarSize = 16;

         if (Items != null)
            foreach (RibbonItem item in Items)
            {
               item.SetSizeMode(RibbonElementSizeMode.DropDown);
               item.SetCanvas(this);

                //If item is a RibbonHost, the MouseSensor will not detect the mouse move event, so manually hook into the event.
               if (item is RibbonHost)
               {
                   ((RibbonHost)item).ClientMouseMove += new MouseEventHandler(OnRibbonHostMouseMove);
               }
            }

         UpdateSize();
      }
Esempio n. 37
0
        /// <summary>
        /// Sets the bounds of the dropdown part of the button when SetBounds is called.
        /// Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        /// The measuring occours in the following order:
        /// <list type="">
        /// <item>OnSetImageBounds</item>
        /// <item>OnSetTextBounds</item>
        /// <item>OnSetDropDownBounds</item>
        /// <item>OnSetButtonFaceBounds</item>
        /// </list>
        /// </remarks>
        internal virtual Rectangle OnGetDropDownBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            Rectangle sideBounds = Rectangle.FromLTRB(
                    bounds.Right - _dropDownMargin.Horizontal - 2,
                    bounds.Top, bounds.Right, bounds.Bottom);

            switch (SizeMode)
            {
                case RibbonElementSizeMode.Large:
                case RibbonElementSizeMode.Overflow:
                    return Rectangle.FromLTRB(bounds.Left,
                        bounds.Top + Image.Height + Owner.ItemMargin.Vertical,
                        bounds.Right, bounds.Bottom);

                case RibbonElementSizeMode.DropDown:
                case RibbonElementSizeMode.Medium:
                case RibbonElementSizeMode.Compact:
                    return sideBounds;
            }

            return Rectangle.Empty;
        }
Esempio n. 38
0
        /// <summary>
        /// Updates the bounds of child elements
        /// </summary>
        internal void UpdateItemsRegions(Graphics g, RibbonElementSizeMode mode)
        {
            switch (FlowsTo)
            {
                case RibbonPanelFlowDirection.Right:
                    UpdateRegionsFlowsToRight(g, mode);
                    break;
                case RibbonPanelFlowDirection.Bottom:
                    UpdateRegionsFlowsToBottom(g, mode);
                    break;
            }

            ///Center items on the panel
            CenterItems();
        }
Esempio n. 39
0
        /// <summary>
        /// Sets the bounds of the text of the button when SetBounds is called.
        /// Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        /// The measuring occours in the following order:
        /// <list type="">
        /// <item>OnSetImageBounds</item>
        /// <item>OnSetTextBounds</item>
        /// <item>OnSetDropDownBounds</item>
        /// <item>OnSetButtonFaceBounds</item>
        /// </list>
        /// </remarks>
        internal virtual Rectangle OnGetTextBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            int imgw = _imageBounds.Width;
            int imgh = _imageBounds.Height;

            if (sMode == RibbonElementSizeMode.Large)
            {
                return Rectangle.FromLTRB(
                    Bounds.Left + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top + imgh,
                    Bounds.Right - Owner.ItemMargin.Right,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);
            }
            else
            {
                int ddw = Style != RibbonButtonStyle.Normal ? _dropDownMargin.Horizontal : 0;
                return Rectangle.FromLTRB(
                    Bounds.Left + imgw + Owner.ItemMargin.Horizontal + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top,
                    Bounds.Right - ddw,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);

            }
        }
 internal override Rectangle OnGetImageBounds(RibbonElementSizeMode sMode, Rectangle bounds)
 {
     return(Rectangle.Empty);
 }
        public Size SwitchToSize(Control ctl, Graphics g, RibbonElementSizeMode size)
        {
            Size s = MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, size));
             Rectangle r = new Rectangle(0, 0, s.Width, s.Height);

             //if (!(ctl is Ribbon))
             //    r = boundsBuffer;
             //else
             //    r = new Rectangle(0, 0, 0, 0);

             SetBounds(r);
             UpdateItemsRegions(g, size);
             return s;
        }
 /// <summary>
 /// Sets the value of the SizeMode property
 /// </summary>
 /// <param name="sizeMode"></param>
 internal virtual void SetSizeMode(RibbonElementSizeMode sizeMode)
 {
     _sizeMode = GetNearestSize(sizeMode);
 }
Esempio n. 43
0
        /// <summary>
        /// Updates the regions of the panels and its contents
        /// </summary>
        internal void UpdatePanelsRegions()
        {
            if (Panels.Count == 0)
            {
                return;
            }

            if (!Owner.IsDesignMode())
            {
                _offset = 0;
            }

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

            using (Graphics g = Owner.CreateGraphics())
            {
                //Check all at full size
                foreach (RibbonPanel panel in Panels)
                {
                    if (panel.Visible && Owner.RightToLeft == RightToLeft.No)
                    {
                        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 bounds 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;
                    }
                    else if (panel.Visible && Owner.RightToLeft == RightToLeft.Yes)
                    {
                        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));

                        curLeft -= size.Width + Owner.PanelSpacing;

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

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

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

                        ///Update curLeft
                        curLeft = bounds.Left - 1 - Owner.PanelSpacing;
                    }
                    else
                    {
                        panel.SetBounds(Rectangle.Empty);
                    }
                }

                if (!Owner.IsDesignMode())
                {
                    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();
        }
        /// <summary>
        /// Gets the size applying the rules of MaxSizeMode and MinSizeMode properties
        /// </summary>
        /// <param name="sizeMode">Suggested sizeMode</param>
        /// <returns>The nearest size to the specified one</returns>
        protected RibbonElementSizeMode GetNearestSize(RibbonElementSizeMode sizeMode)
        {
            int size = (int)sizeMode;
            int max = (int)MaxSizeMode;
            int min = (int)MinSizeMode;
            int result = (int)sizeMode;

            if (max > 0 && size > max) //Max is specified and value exceeds max
            {
                result = max;
            }

            if (min > 0 && size < min) //Min is specified and value exceeds min
            {
                result = min;
            }

            return (RibbonElementSizeMode)result;
        }
 internal RibbonElementPaintEventArgs(Rectangle clip, Graphics graphics, RibbonElementSizeMode mode, Control control)
     : this(clip, graphics, mode)
 {
     Control = control;
 }
 /// <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 override System.Drawing.Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
 {
     if (Site != null && Site.DesignMode && Owner != null)
      {
     //when in design mode just paint the name of this control
     int Width = Convert.ToInt32(e.Graphics.MeasureString(Site.Name, Owner.Font).Width);
     int Height = 20;
     SetLastMeasuredSize(new System.Drawing.Size(Width, Height));
      }
      else if (ctl == null || !Visible)
     SetLastMeasuredSize(new System.Drawing.Size(0, 0));
      else
      {
     ctl.Visible = false;
     if (_lastSizeMode != e.SizeMode)
     {
        _lastSizeMode = e.SizeMode;
        RibbonHostSizeModeHandledEventArgs hev = new RibbonHostSizeModeHandledEventArgs(e.Graphics, e.SizeMode);
        OnSizeModeChanging(ref hev);
     }
     SetLastMeasuredSize(new System.Drawing.Size(ctl.Size.Width + 2, ctl.Size.Height + 2));
      }
      return LastMeasuredSize;
 }
Esempio n. 47
0
        /// <summary>
        /// Sets the value of the SizeMode property
        /// </summary>
        /// <param name="sizeMode"></param>
        internal void SetSizeMode(RibbonElementSizeMode sizeMode)
        {
            _sizeMode = sizeMode;

            foreach (RibbonItem item in Items)
            {
                item.SetSizeMode(sizeMode);
            }
        }
 internal override void SetSizeMode(RibbonElementSizeMode sizeMode)
 {
     base.SetSizeMode(sizeMode);
      if (OwnerPanel != null && OwnerPanel.SizeMode == RibbonElementSizeMode.Overflow)
      {
     ctl.Visible = false;
      }
 }
Esempio n. 49
0
        /// <summary>
        /// Updates the bounds of child elements when flow is to bottom
        /// </summary>
        private void UpdateRegionsFlowsToBottom(Graphics g, RibbonElementSizeMode mode)
        {
            int curRight = ContentBounds.Left + Owner.ItemPadding.Horizontal + 0;
            int curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
            int lastRight = curRight;
            int lastBottom = 0;
            List<RibbonItem> lastColumn = new List<RibbonItem>();

            ///Iterate thru items on panel
            foreach (RibbonItem item in Items)
            {
                ///Gets the last measured size (to avoid re-measuring calculations)
                Size itemSize = item.LastMeasuredSize;

                ///If not enough space available, reset curBottom and advance curRight
                if (curBottom + itemSize.Height > ContentBounds.Bottom)
                {
                    curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                    curRight = lastRight + Owner.ItemPadding.Horizontal + 0;
                    Items.CenterItemsVerticallyInto(lastColumn, ContentBounds);
                    lastColumn.Clear();
                }

                ///Set the item's bounds
                item.SetBounds(new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height));

                ///save last right and bottom
                lastRight = item.Bounds.Right;
                lastBottom = item.Bounds.Bottom;

                ///update current bottom
                curBottom = item.Bounds.Bottom + Owner.ItemPadding.Vertical + 1;

                ///Add to the collection of items of the last column
                lastColumn.Add(item);
            }

            ///Center the items vertically on the last column
            Items.CenterItemsVerticallyInto(lastColumn, Items.GetItemsBounds());
        }
 /// <summary>
 /// Creates a new RibbonElementMeasureSizeEventArgs object
 /// </summary>
 /// <param name="graphics">Device info to draw and measure</param>
 /// <param name="sizeMode">Size mode to measure</param>
 internal RibbonHostSizeModeHandledEventArgs(System.Drawing.Graphics graphics, RibbonElementSizeMode sizeMode)
 {
     _graphics = graphics;
      _sizeMode = sizeMode;
 }
Esempio n. 51
0
 /// <summary>
 /// Sets the value of the SizeMode property
 /// </summary>
 /// <param name="sizeMode"></param>
 internal virtual void SetSizeMode(RibbonElementSizeMode sizeMode)
 {
     _sizeMode = GetNearestSize(sizeMode);
 }
        /// <summary>
        /// Gets the panel with the larger with and the specified size mode
        /// </summary>
        /// <param name="size">Size mode of panel to search</param>
        /// <returns>Larger panel. Null if none of the specified size mode</returns>
        private RibbonPanel GetLargerPanel(RibbonElementSizeMode size)
        {
            RibbonPanel result = null;

            foreach (RibbonPanel panel in Panels)
            {
                if (panel.SizeMode != size) continue;

                if (result == null) result = panel;

                if (panel.Bounds.Width > result.Bounds.Width)
                {
                    result = panel;
                }
            }

            return result;
        }
      internal override void SetSizeMode(RibbonElementSizeMode sizeMode)
      {
         base.SetSizeMode(sizeMode);

         foreach (RibbonItem item in Buttons)
         {
            item.SetSizeMode(ButtonsSizeMode);
         }
      }
        /// <summary>
        /// Sets the bounds of the text of the button when SetBounds is called.
        /// Override this method to change image bounds
        /// </summary>
        /// <param name="sMode">Mode which is being measured</param>
        /// <param name="bounds">Bounds of the button</param>
        /// <remarks>
        /// The measuring occours in the following order:
        /// <list type="">
        /// <item>OnSetImageBounds</item>
        /// <item>OnSetTextBounds</item>
        /// <item>OnSetDropDownBounds</item>
        /// <item>OnSetButtonFaceBounds</item>
        /// </list>
        /// </remarks>
        internal virtual Rectangle OnGetTextBounds(RibbonElementSizeMode sMode, Rectangle bounds)
        {
            int imgw = _imageBounds.Width;
            int imgh = _imageBounds.Height;

            if (sMode == RibbonElementSizeMode.Large)
            {
                return Rectangle.FromLTRB(
                    Bounds.Left + Owner.ItemMargin.Left,
                    Bounds.Top + Owner.ItemMargin.Top + imgh,
                    Bounds.Right - Owner.ItemMargin.Right,
                    Bounds.Bottom - Owner.ItemMargin.Bottom);
            }
            else
            {
                // ddw is the dropdown arrow width
                int ddw = (Style == RibbonButtonStyle.Normal || Style == RibbonButtonStyle.DropDownListItem) ? 0 : _dropDownMargin.Horizontal;
                int imageToTextSpacing = (sMode == RibbonElementSizeMode.DropDown) ? Owner.ItemImageToTextSpacing : 0;
                
                return Rectangle.FromLTRB(
                Bounds.Left + imgw + Owner.ItemMargin.Horizontal + Owner.ItemMargin.Left + imageToTextSpacing,
                Bounds.Top + Owner.ItemMargin.Top,
                Bounds.Right - ddw,
                Bounds.Bottom - Owner.ItemMargin.Bottom);
            }
        }