/// <summary> /// Updates the size of the dropdown /// </summary> private void UpdateSize() { int heightSum = OwnerRibbon.DropDownMargin.Vertical; int maxWidth = 0; int scrollableHeight = 0; using (Graphics g = _ownerRibbon.CreateGraphics()) { foreach (RibbonItem item in Items) { Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, MeasuringSize)); heightSum += s.Height; maxWidth = Math.Max(maxWidth, s.Width + OwnerRibbon.DropDownMargin.Horizontal); if (item is IScrollableRibbonItem) { scrollableHeight += s.Height; } } } //This is the initial sizing of the popup window so //we need to add the width of the scrollbar if its needed. if ((_maxHeight > 0 && _maxHeight < heightSum && !_resizing) || (heightSum + (ShowSizingGrip ? SizingGripHeight + 2 : 0) + 1) > Screen.PrimaryScreen.WorkingArea.Height) { if (_maxHeight > 0) { heightSum = _maxHeight; } else { heightSum = Screen.PrimaryScreen.WorkingArea.Height - ((ShowSizingGrip ? SizingGripHeight + 2 : 0) + 1); } maxWidth += _scrollBarSize; _thumbBounds.Width = _scrollBarSize; _scrollBarEnabled = true; } if (!_resizing) { Size sz = new Size(maxWidth, heightSum + (ShowSizingGrip ? SizingGripHeight + 2 : 0)); Size = sz; } if (WrappedDropDown != null) { WrappedDropDown.Size = this.Size; } SetBounds(); }
/// <summary> /// Updates the regions and bounds of items /// </summary> private void UpdateRegions() { int curtop = 0; int curright = 0; int menuItemHeight = 44; int recentHeight = 22; int mbuttons = 1; //margin int mrecent = 1; //margin int buttonsHeight = 0; int recentsHeight = 0; if (AutoSizeContentButtons) { #region important to do the item max width check before the ContentBounds and other stuff is used (internal Property stuff) int itemMaxWidth = 0; using (Graphics g = _ribbon.CreateGraphics()) { foreach (RibbonItem item in MenuItems) { int width = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, RibbonElementSizeMode.DropDown)).Width; if (width > itemMaxWidth) { itemMaxWidth = width; } } } itemMaxWidth = Math.Min(itemMaxWidth, ContentBounds.Width - ContentRecentItemsMinWidth); itemMaxWidth = Math.Max(itemMaxWidth, ContentButtonsMinWidth); _contentButtonsWidth = itemMaxWidth; #endregion } Rectangle rcontent = ContentBounds; Rectangle rbuttons = ContentButtonsBounds; Rectangle rrecent = ContentRecentItemsBounds; foreach (RibbonItem item in AllItems) { item.SetSizeMode(RibbonElementSizeMode.DropDown); item.SetCanvas(this); } #region Menu Items curtop = rcontent.Top + 1; foreach (RibbonItem item in MenuItems) { Rectangle ritem = new Rectangle(rbuttons.Left + mbuttons, curtop, rbuttons.Width - mbuttons * 2, menuItemHeight); if (item is RibbonSeparator) { ritem.Height = SeparatorHeight(item as RibbonSeparator); } item.SetBounds(ritem); curtop += ritem.Height; } buttonsHeight = curtop - rcontent.Top + 1; #endregion #region Recent List //curtop = rbuttons.Top; //Steve - for recent documents curtop = rrecent.Top; //Steve - for recent documents foreach (RibbonItem item in RecentItems) { Rectangle ritem = new Rectangle(rrecent.Left + mrecent, curtop, rrecent.Width - mrecent * 2, recentHeight); if (item is RibbonSeparator) { ritem.Height = SeparatorHeight(item as RibbonSeparator); } item.SetBounds(ritem); curtop += ritem.Height; } recentsHeight = curtop - rbuttons.Top; #endregion #region Set size int actualHeight = Math.Max(buttonsHeight, recentsHeight); if (RibbonDesigner.Current != null) { actualHeight += ButtonsGlyphBounds.Height + glyphGap * 2; } Height = actualHeight + ContentMargin.Vertical; rcontent = ContentBounds; #endregion #region Option buttons curright = ClientSize.Width - ContentMargin.Right; using (Graphics g = _ribbon.CreateGraphics()) { foreach (RibbonItem item in OptionItems) { Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, RibbonElementSizeMode.DropDown)); curtop = rcontent.Bottom + (ContentMargin.Bottom - s.Height) / 2; item.SetBounds(new Rectangle(new Point(curright - s.Width, curtop), s)); curright = item.Bounds.Left - OptionItemsPadding; } } #endregion }