public Context( Graphics g, RibbonControl ribbonControl, Renderer renderer, History history, Updates updates , Dictionary<Section, Rectangle> mapSectionToRectangle, Dictionary<Item, Rectangle> mapItemToRectangle) { _graphics = g; _renderer = renderer; _history = history; _updates = updates; _ribbonControl = ribbonControl; _mapSectionToRectangle = mapSectionToRectangle; _mapItemToRectangle = mapItemToRectangle; }
public override Size GetLogicalSize( RibbonControl ribbonControl, Graphics g, Size suggestedSize ) { Size size = base.GetLogicalSize( ribbonControl, g, suggestedSize ); ButtonSizeKind buttonSizeKind = base.IdentifyButton( size ); switch( buttonSizeKind ) { case ButtonSizeKind.Single: case ButtonSizeKind.Wide: return new Size( size.Width + TriangleSize, size.Height ); case ButtonSizeKind.Big: return size; default: throw new InvalidOperationException(); } }
protected override Size LayoutItem( RibbonControl ribbonControl, Graphics g, Item item, int itemLevelOfDetail ) { Size maxItemSize; switch( itemLevelOfDetail ) { case 2: case 1: maxItemSize = new Size( RowHeight * 3 + ItemSep * 2, RowHeight ); break; case 0: maxItemSize = new Size( RowHeight, RowHeight ); break; default: throw new InvalidOperationException(); } return item.GetLogicalSize( ribbonControl, g, maxItemSize ); }
public override void PreLayout( RibbonControl ribbonControl, int levelOfDetail ) { base.PreLayout( ribbonControl, levelOfDetail ); bool haveRemovedSections = false; foreach( Section section in ribbonControl.Sections ) { if( section == this ) { continue; } if( levelOfDetail > section.DisplayUntil ) { haveRemovedSections = true; } } Visible = haveRemovedSections; }
public override bool Layout( Graphics g, RibbonControl ribbonControl, Section[] sections, int levelOfDetail, int leftPos, int rightPos , out Dictionary<Section, Rectangle> sectionLogicalBounds, out Dictionary<Item, Rectangle> itemLogicalBounds, out int ribbonHeight, out int widthRequired) { foreach( Section section in sections ) { section.PreLayout( ribbonControl, levelOfDetail ); } sectionLogicalBounds = new Dictionary<Section, Rectangle>(); itemLogicalBounds = new Dictionary<Item, Rectangle>(); ribbonHeight = 0; foreach( Section section in sections ) { if( ribbonControl.IsSectionVisible( section, levelOfDetail ) ) { LayoutSection( g, section, ribbonControl, levelOfDetail, sectionLogicalBounds, itemLogicalBounds, ref leftPos, ref rightPos ); } else { sectionLogicalBounds[section] = Rectangle.Empty; foreach( Item item in section.Items ) { itemLogicalBounds[item] = Rectangle.Empty; } } } foreach( Rectangle rect in sectionLogicalBounds.Values ) { ribbonHeight = Math.Max( ribbonHeight, rect.Height + SectionSep * 2 + 1 ); } widthRequired = leftPos + rightPos + SectionSep * 2; return leftPos + rightPos < ribbonControl.ClientRectangle.Width - SectionSep * 2; }
public override Size GetLogicalSize( RibbonControl ribbonControl, Graphics g, Size suggestedSize ) { return suggestedSize; }
public abstract Size GetLogicalSize( RibbonControl ribbonControl, Graphics g, Size suggestedSize );
protected virtual void LayoutSection( Graphics g, Section section, RibbonControl ribbonControl, int levelOfDetail, Dictionary<Section, Rectangle> sectionLogicalBounds , Dictionary<Item, Rectangle> itemLogicalBounds, ref int leftPos, ref int rightPos) { int width = 0, height = 0; height += SystemFonts.DialogFont.Height + ItemSep; width = (int) WinFormsUtility.Drawing.GdiPlusEx.MeasureString( g, section.Title, SystemFonts.DialogFont, int.MaxValue ).Width + 1; int itemsWidth = 0; int topItemXPos = leftPos + SectionSep, bottomItemXPos = leftPos + SectionSep; Queue<KeyValuePair<int, int>> gaps = new Queue<KeyValuePair<int, int>>(); List<int> itemLevelOfDetails = new List<int>(); int zeroCount = 0, oneCount = 0, twoCount = 0; for( int i = 0; i < section.Items.Length; ++i ) { Item item = section.Items[i]; int itemLevelOfDetail = Math.Max( Math.Min( item.Importance - levelOfDetail, 2 ), 0 ); switch( itemLevelOfDetail ) { case 0: ++zeroCount; break; case 1: ++oneCount; break; case 2: ++twoCount; break; } itemLevelOfDetails.Add( itemLevelOfDetail ); } bool alreadyFixed = false; if( section.Items.Length == 2 && itemLevelOfDetails[0] == 0 && itemLevelOfDetails[1] == 0 ) { itemLevelOfDetails[0] = 1; itemLevelOfDetails[1] = 1; zeroCount -= 2; oneCount += 2; alreadyFixed = true; } else if( oneCount == 0 && zeroCount == 1 ) { for( int i = 0; i < itemLevelOfDetails.Count; ++i ) { if( itemLevelOfDetails[i] == 0 ) { itemLevelOfDetails[i] = 2; --zeroCount; ++twoCount; } } alreadyFixed = true; } else if( section.Items.Length == 3 && itemLevelOfDetails[0] == 0 && itemLevelOfDetails[1] == 0 && itemLevelOfDetails[2] == 0 ) { itemLevelOfDetails[2] = 2; --zeroCount; ++twoCount; alreadyFixed = true; } if( zeroCount == 1 && oneCount == 1 ) { for( int i = 0; i < itemLevelOfDetails.Count; ++i ) { if( itemLevelOfDetails[i] == 1 ) { itemLevelOfDetails[i] = 2; --oneCount; ++twoCount; } } alreadyFixed = true; } if( twoCount == 0 && oneCount == 1 && zeroCount >= 4 && (zeroCount % 2) == 0 ) { for( int i = 0; i < itemLevelOfDetails.Count; ++i ) { if( itemLevelOfDetails[i] == 1 ) { itemLevelOfDetails[i] = 2; --oneCount; ++twoCount; } } alreadyFixed = true; } if( oneCount == 3 && zeroCount == 1 ) { for( int i = 0; i < itemLevelOfDetails.Count; ++i ) { if( itemLevelOfDetails[i] == 0 ) { itemLevelOfDetails[i] = 1; --zeroCount; ++oneCount; } } alreadyFixed = true; } for( int i = 0; i < section.Items.Length; ++i ) { Item item = section.Items[i]; int itemLevelOfDetail = itemLevelOfDetails[i]; int itemXPos, itemYPos; Rectangle irect; bool nextIsFullHeight = false; Item nextItem; int nextItemLevelOfDetail; if( i == section.Items.Length - 1 ) { nextItem = null; nextIsFullHeight = true; nextItemLevelOfDetail = -1; } else { nextItem = section.Items[i + 1]; nextItemLevelOfDetail = itemLevelOfDetails[i + 1]; Size nextItemSize = LayoutItem( ribbonControl, g, nextItem, nextItemLevelOfDetail ); if( nextItemSize.Height > RowHeight ) { nextIsFullHeight = true; } } if( nextIsFullHeight && !alreadyFixed && itemLevelOfDetail == 1 && topItemXPos == bottomItemXPos ) { itemLevelOfDetail = 2; } Size itemSize = LayoutItem( ribbonControl, g, item, itemLevelOfDetail ); bool gapped = false; if( itemLevelOfDetail == 0 && gaps.Count > 0 ) { KeyValuePair<int, int> gap = gaps.Dequeue(); itemXPos = gap.Key; itemYPos = gap.Value; gapped = true; } else if( itemSize.Height > RowHeight ) { if( topItemXPos > bottomItemXPos + RowHeight ) { gaps.Enqueue( new KeyValuePair<int, int>( bottomItemXPos, SectionSep + ItemSep * 2 + RowHeight ) ); } else if( bottomItemXPos > topItemXPos + RowHeight ) { gaps.Enqueue( new KeyValuePair<int, int>( topItemXPos, SectionSep + ItemSep ) ); } itemXPos = Math.Max( topItemXPos, bottomItemXPos ); topItemXPos = bottomItemXPos = itemXPos; itemYPos = SectionSep + ItemSep; } else { itemXPos = Math.Min( topItemXPos, bottomItemXPos ); if( topItemXPos <= bottomItemXPos ) { itemYPos = SectionSep + ItemSep; } else { itemYPos = SectionSep + ItemSep * 2 + RowHeight; } } itemXPos += ItemSep; irect = new Rectangle( itemXPos, itemYPos, itemSize.Width, itemSize.Height ); if( !gapped ) { if( itemSize.Height > RowHeight ) { topItemXPos += itemSize.Width + ItemSep; bottomItemXPos += itemSize.Width + ItemSep; } else { if( topItemXPos <= bottomItemXPos ) { topItemXPos += itemSize.Width + ItemSep; } else { bottomItemXPos += itemSize.Width + ItemSep; } } } itemLogicalBounds[item] = irect; } itemsWidth = Math.Max( topItemXPos - leftPos - SectionSep, bottomItemXPos - leftPos - SectionSep ); height += RowHeight * 2 + 4 + ItemSep * 2; width = Math.Max( width, itemsWidth ); width += ItemSep; int xp; switch( section.Alignment ) { case Alignment.Left: leftPos += SectionSep; xp = leftPos; leftPos += width; break; case Alignment.Right: rightPos += SectionSep; rightPos += width; xp = ribbonControl.ClientRectangle.Width - rightPos; break; default: throw new InvalidOperationException(); } Rectangle rect = new Rectangle( xp, SectionSep, width, height ); sectionLogicalBounds[section] = rect; }
public override Size GetLogicalSize( RibbonControl ribbonControl, Graphics g, Size suggestedSize ) { return new Size( 6, suggestedSize.Height ); }
protected override void LayoutSection( Graphics g, Section section, RibbonControl ribbonControl, int levelOfDetail, Dictionary<Section, Rectangle> sectionLogicalBounds , Dictionary<Item, Rectangle> itemLogicalBounds, ref int leftPos, ref int rightPos) { int width = 0, height = 0; width = (int) WinFormsUtility.Drawing.GdiPlusEx.MeasureString( g, section.Title, SystemFonts.DialogFont, int.MaxValue ).Width + 1; int itemsWidth = 0; int itemXPos = 0; List<int> itemLevelOfDetails = new List<int>(); for( int i = 0; i < section.Items.Length; ++i ) { Item item = section.Items[i]; int itemLevelOfDetail = Math.Max( Math.Min( item.Importance - levelOfDetail, 2 ), 0 ); itemLevelOfDetails.Add( itemLevelOfDetail ); } for( int i = 0; i < section.Items.Length; ++i ) { Item item = section.Items[i]; int itemLevelOfDetail = itemLevelOfDetails[i]; Rectangle irect; if( item.Visible ) { Size itemSize = LayoutItem( ribbonControl, g, item, itemLevelOfDetail ); irect = new Rectangle( itemXPos, SectionSep, itemSize.Width, itemSize.Height ); itemXPos += itemSize.Width + ItemSep; } else { irect = Rectangle.Empty; } itemLogicalBounds[item] = irect; } itemsWidth = itemXPos - SectionSep; height += RowHeight - 1; width = Math.Max( width, itemsWidth ); width += ItemSep; int xp; switch( section.Alignment ) { case Alignment.Left: leftPos += SectionSep; xp = leftPos; leftPos += width; break; case Alignment.Right: rightPos += width; xp = ribbonControl.ClientRectangle.Width + 2 - rightPos; rightPos += SectionSep; break; default: throw new InvalidOperationException(); } for( int i = 0; i < section.Items.Length; ++i ) { Item item = section.Items[i]; Rectangle irect = itemLogicalBounds[item]; if( item.Visible ) { irect.Offset( xp, 0 ); } itemLogicalBounds[item] = irect; } Rectangle rect = new Rectangle( xp, SectionSep, width, height ); sectionLogicalBounds[section] = rect; }
public override System.Drawing.Size GetLogicalSize( RibbonControl ribbonControl, Graphics g, Size suggestedSize ) { return _control.Size; }
public abstract bool Layout( Graphics g, RibbonControl ribbonControl, Section[] sections, int levelOfDetail, int leftPos, int rightPos , out Dictionary<Section, Rectangle> sectionLogicalBounds, out Dictionary<Item, Rectangle> itemLogicalBounds, out int ribbonHeight, out int widthRequired);