/// <summary> /// Gets the size required for all except the contents. /// </summary> /// <param name="context">Layout context.</param> public Size GetNonChildSize(ViewLayoutContext context) { Debug.Assert(context != null); // Remember the original display rectangle provided Rectangle originalRect = context.DisplayRectangle; Rectangle displayRect = context.DisplayRectangle; // Border size that is not applied to preferred size Size borderSize = Size.Empty; // Accumulate the size that must be provided by docking edges and then filler Size preferredSize = Size.Empty; // Track the minimize size needed to satisfy the docking edges only Size minimumSize = Size.Empty; if (!IgnoreAllBorderAndPadding) { // Apply space the border takes up if (IgnoreBorderSpace) { borderSize = CommonHelper.ApplyPadding(Orientation, borderSize, context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation)); } else { Padding padding = context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation); preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, padding); displayRect = CommonHelper.ApplyPadding(Orientation, displayRect, padding); } // Do we have a metric source for additional padding? if ((_paletteMetric != null) && (_metricPadding != PaletteMetricPadding.None)) { // Apply padding needed outside the border of the canvas Padding padding = _paletteMetric.GetMetricPadding(State, _metricPadding); preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, padding); displayRect = CommonHelper.ApplyPadding(Orientation, displayRect, padding); } } // Put back the original display rect context.DisplayRectangle = originalRect; // Enforce the minimum values from the other docking edge sizes preferredSize.Width = Math.Max(preferredSize.Width, minimumSize.Width); preferredSize.Height = Math.Max(preferredSize.Height, minimumSize.Height); // Enforce the border sizing as the minimum preferredSize.Width = Math.Max(preferredSize.Width, borderSize.Width); preferredSize.Height = Math.Max(preferredSize.Height, borderSize.Height); return(preferredSize); }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { // Get size of the contained items Size preferredSize = base.GetPreferredSize(context); // Add on the border padding preferredSize = CommonHelper.ApplyPadding(Orientation.Horizontal, preferredSize, _borderPadding); preferredSize.Height = Math.Max(preferredSize.Height, QAT_HEIGHT_FULL); return(preferredSize); }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // We take on all the available display area and then remove our constant padding ClientRectangle = CommonHelper.ApplyPadding(Orientation.Horizontal, context.DisplayRectangle, _padding); int x = ClientLocation.X; // Are there any children to layout? if (Count > 0) { int y = ClientLocation.Y; int height = ClientHeight; // Position each item from left to right taking up entire height for (int i = 0, j = 0; i < Count; i++) { ViewBase child = this[i]; // We only position visible items if (child.Visible) { Size childSize; if ((_containerWidths != null) && (child is IRibbonViewGroupContainerView)) { childSize = new Size(_containerWidths[j++], _ribbon.CalculatedValues.GroupTripleHeight); } else { childSize = child.GetPreferredSize(context); } // Only interested in items with some width if (childSize.Width > 0) { // Define display rectangle for the group context.DisplayRectangle = new Rectangle(x, y, childSize.Width, height); // Position the element this[i].Layout(context); // Move across to next position (add 1 extra as the spacing gap) x += childSize.Width + 1; } } } } // Update the display rectangle we allocated for use by parent context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> /// <exception cref="ArgumentNullException"></exception> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // Validate incoming reference if (context == null) { throw new ArgumentNullException(nameof(context)); } // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Do we have a metric source for additional padding? if (_paletteMetric != null) { // Get the padding to be applied before the canvas drawing Padding outerPadding = _paletteMetric.GetMetricPadding(State, _metricPadding); // Apply the padding to the client rectangle ClientRectangle = CommonHelper.ApplyPadding(Orientation, ClientRectangle, outerPadding); } // Calculate how much space the border takes up Padding padding = DrawTabBorder ? context.Renderer.RenderTabBorder.GetTabBorderDisplayPadding(context, _paletteBorder, State, Orientation, TabBorderStyle) : context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation); // Apply the padding to the client rectangle context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation, ClientRectangle, padding); // Ensure any content children have correct composition setting foreach (ViewBase child in this) { if (child is ViewDrawContent viewContent) { // Do we need to draw the background? bool drawBackground = DrawCanvas && (_paletteBack.GetBackDraw(State) == InheritBool.True); // Update the content accordingly viewContent.DrawContentOnComposition = DrawCanvasOnComposition && !drawBackground; viewContent.Glowing = viewContent.DrawContentOnComposition; } } // Let child elements layout base.Layout(context); // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // Validate incoming reference if (context == null) { throw new ArgumentNullException(nameof(context)); } // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Ensure that the correct number of children are created SyncChildren(); // Is there anything to layout? if (Count > 0) { // Reduce the client area by the requested padding before the internal children Rectangle displayRect = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, _padding); // Get size of the first child, assume all others are same size Size itemSize = this[0].GetPreferredSize(context); // Starting position for first item Point nextPoint = displayRect.Location; for (int i = 0; i < Count; i++) { // Find rectangle for the child context.DisplayRectangle = new Rectangle(nextPoint, itemSize); // Layout the child this[i].Layout(context); // Move to next position across nextPoint.X += itemSize.Width; // Do we need to move to next line? if (((i + 1) % _lineItems) == 0) { nextPoint.X = displayRect.X; nextPoint.Y += itemSize.Height; } } } // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> public override void RenderBefore(RenderContext context) { // Update the enabled state of the button Enabled = _ribbon.Enabled; IPaletteBack paletteBack = _ribbon.StateCommon.RibbonGroupDialogButton.PaletteBack; IPaletteBorder paletteBorder = _ribbon.StateCommon.RibbonGroupDialogButton.PaletteBorder; IPaletteRibbonGeneral paletteGeneral = _ribbon.StateCommon.RibbonGeneral; // Do we need to draw the background? if (paletteBack.GetBackDraw(State) == InheritBool.True) { // Get the border path which the background is clipped to drawing within using (GraphicsPath borderPath = context.Renderer.RenderStandardBorder.GetBackPath(context, ClientRectangle, paletteBorder, VisualOrientation.Top, State)) { Padding borderPadding = context.Renderer.RenderStandardBorder.GetBorderRawPadding(paletteBorder, State, VisualOrientation.Top); // Apply the padding depending on the orientation Rectangle enclosingRect = CommonHelper.ApplyPadding(VisualOrientation.Top, ClientRectangle, borderPadding); // Render the background inside the border path _mementoBack = context.Renderer.RenderStandardBack.DrawBack(context, enclosingRect, borderPath, paletteBack, VisualOrientation.Top, State, _mementoBack); } } // Do we need to draw the border? if (paletteBorder.GetBorderDraw(State) == InheritBool.True) { context.Renderer.RenderStandardBorder.DrawBorder(context, ClientRectangle, paletteBorder, VisualOrientation.Top, State); } // Find the content area inside the button rectangle Rectangle contentRect = ClientRectangle; contentRect.Inflate(_contentSize); // Decide if we are drawing an overflow or context arrow image if (Overflow) { context.Renderer.RenderGlyph.DrawRibbonOverflow(_ribbon.RibbonShape, context, contentRect, paletteGeneral, State); } else { context.Renderer.RenderGlyph.DrawRibbonContextArrow(_ribbon.RibbonShape, context, contentRect, paletteGeneral, State); } }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { // Sync child elements to the current group items SyncChildrenToRibbonGroupItems(); Size preferredSize = Size.Empty; // Find total width and maximum height across all child elements for (int i = 0, j = 0; i < Count; i++) { ViewBase child = this[i]; // Only interested in visible items if (child.Visible) { Size childSize; if ((_containerWidths != null) && (child is IRibbonViewGroupContainerView)) { childSize = new Size(_containerWidths[j++], _ribbon.CalculatedValues.GroupTripleHeight); } else { childSize = child.GetPreferredSize(context); } // Only need extra processing for children that have some width if (childSize.Width > 0) { // If not the first item positioned if (preferredSize.Width > 0) { // Add on a single pixel spacing gap preferredSize.Width++; } // Always add on to the width preferredSize.Width += childSize.Width; // Find maximum height encountered preferredSize.Height = Math.Max(preferredSize.Height, childSize.Height); } } } // Add on the constant additional padding return(CommonHelper.ApplyPadding(Orientation.Horizontal, preferredSize, _padding)); }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Cache the fill rectangle FillRect = ClientRectangle; // Reduce the fill rectangle to account for the display padding FillRect = CommonHelper.ApplyPadding(Orientation.Horizontal, FillRect, DisplayPadding); // We let the OnLayout override for the control perform the // actually positioning of the fill contents. }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { // Get size of the contained items Size preferredSize = base.GetPreferredSize(context); // Do we need to add on our own border size if (!_borderOutside) { // Add on the border padding preferredSize = CommonHelper.ApplyPadding(Orientation.Horizontal, preferredSize, BorderPadding); } // Override the height to the correct fixed value preferredSize.Height = Ribbon.CalculatedValues.GroupsHeight; return(preferredSize); }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); Rectangle clientRect = context.DisplayRectangle; ClientRectangle = clientRect; // Remove QAT border for positioning children context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, _borderPadding); // Let children be layed out inside border area base.Layout(context); // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { Debug.Assert(context != null); // Validate incoming reference if (context == null) { throw new ArgumentNullException("context"); } // Ensure any content children have correct composition setting foreach (ViewBase child in this) { if (child is ViewDrawContent) { ViewDrawContent viewContent = (ViewDrawContent)child; viewContent.DrawContentOnComposition = DrawCanvasOnComposition; viewContent.Glowing = viewContent.DrawContentOnComposition; } } // Let base class find preferred size of the children Size preferredSize = base.GetPreferredSize(context); // Apply space the border takes up if (DrawTabBorder) { preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, context.Renderer.RenderTabBorder.GetTabBorderDisplayPadding(context, _paletteBorder, State, Orientation, TabBorderStyle)); } else { preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation)); } // Do we have a metric source for additional padding? if ((_paletteMetric != null) && (_metricPadding != PaletteMetricPadding.None)) { // Apply padding needed outside the border of the canvas preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, _paletteMetric.GetMetricPadding(State, _metricPadding)); } return(preferredSize); }
/// <summary> /// Perform a render of the elements. /// </summary> /// <param name="context">Rendering context.</param> public override void Render(RenderContext context) { // Ensure we are using the correct palette CheckPaletteState(context); // Use renderer to draw the tab background int mementoIndex = StateIndex(State); _mementos[mementoIndex] = context.Renderer.RenderRibbon.DrawRibbonBack(_lastRibbonShape, context, CommonHelper.ApplyPadding(_borderBackOrient, ClientRectangle, _drawBorder), State, _currentBack, _borderBackOrient, false, _mementos[mementoIndex]); // Let base class draw the child items base.Render(context); }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { // Validate incoming reference if (context == null) { throw new ArgumentNullException(nameof(context)); } // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Find the rectangle for the child elements by applying padding context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, _preferredPadding); // Let base perform actual layout process of child elements base.Layout(context); // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Do we need to add on our own border size if (!_borderOutside) { // Reduce the display rectangle by the border context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation.Horizontal, context.DisplayRectangle, BorderPadding); } // Let children be layed out inside our space base.Layout(context); // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { // Ensure we are using the correct palette CheckPaletteState(context); // Cache the ribbon shape _lastRibbonShape = (_navigator.Palette == null ? PaletteRibbonShape.Office2007 : _navigator.Palette.GetRibbonShape()); // We take on all the provided size ClientRectangle = context.DisplayRectangle; Padding layoutPadding = Padding.Empty; switch (_borderBackOrient) { case VisualOrientation.Top: layoutPadding = _layoutBorderTop; break; case VisualOrientation.Left: layoutPadding = _layoutBorderLeft; break; case VisualOrientation.Right: layoutPadding = _layoutBorderRight; break; case VisualOrientation.Bottom: layoutPadding = _layoutBorderBottom; break; } // Reduce the display size by our border spacing context.DisplayRectangle = CommonHelper.ApplyPadding(_borderBackOrient, context.DisplayRectangle, layoutPadding); // Layout the content using the reduced size base.Layout(context); // Put back the original size before returning context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> /// <exception cref="ArgumentNullException"></exception> public override void RenderBefore(RenderContext context) { Debug.Assert(context != null); // Validate reference parameter if (context == null) { throw new ArgumentNullException(nameof(context)); } // Ensure we are using the correct palette CheckPaletteState(); // Apply padding needed outside the border of the separator Rectangle rect = CommonHelper.ApplyPadding(Orientation, ClientRectangle, _metric.GetMetricPadding(ElementState, MetricPadding)); // Ask the renderer to perform drawing of the separator glyph context.Renderer.RenderGlyph.DrawSeparator(context, rect, _palette.PaletteBack, _palette.PaletteBorder, Orientation, State, ((Source == null) || Source.SeparatorCanMove)); }
/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> public override void RenderBefore(RenderContext context) { // Make sure we reflect the current enabled state if (!Enabled && _ribbon.InDesignHelperMode) { ElementState = PaletteState.Disabled; } IPaletteBack paletteBack = _ribbon.StateCommon.RibbonQATButton.PaletteBack; IPaletteBorder paletteBorder = _ribbon.StateCommon.RibbonQATButton.PaletteBorder; IPaletteRibbonGeneral paletteGeneral = _ribbon.StateCommon.RibbonGeneral; // Do we need to draw the background? if (paletteBack.GetBackDraw(State) == InheritBool.True) { // Get the border path which the background is clipped to drawing within using (GraphicsPath borderPath = context.Renderer.RenderStandardBorder.GetBackPath(context, ClientRectangle, paletteBorder, VisualOrientation.Top, State)) { Padding borderPadding = context.Renderer.RenderStandardBorder.GetBorderRawPadding(paletteBorder, State, VisualOrientation.Top); // Apply the padding depending on the orientation Rectangle enclosingRect = CommonHelper.ApplyPadding(VisualOrientation.Top, ClientRectangle, borderPadding); // Render the background inside the border path _mementoBack = context.Renderer.RenderStandardBack.DrawBack(context, enclosingRect, borderPath, paletteBack, VisualOrientation.Top, State, _mementoBack); } } // Do we need to draw the border? if (paletteBorder.GetBorderDraw(State) == InheritBool.True) { context.Renderer.RenderStandardBorder.DrawBorder(context, ClientRectangle, paletteBorder, VisualOrientation.Top, State); } base.RenderBefore(context); }
private void DrawBackground(IPaletteBack paletteBack, RenderContext context, Rectangle rect, PaletteState state) { // Do we need to draw the background? if (paletteBack.GetBackDraw(state) == InheritBool.True) { // Get the border path which the background is clipped to drawing within using (GraphicsPath borderPath = context.Renderer.RenderStandardBorder.GetBackPath(context, rect, _paletteBorder, VisualOrientation.Top, state)) { Padding borderPadding = context.Renderer.RenderStandardBorder.GetBorderRawPadding(_paletteBorder, state, VisualOrientation.Top); // Apply the padding depending on the orientation Rectangle enclosingRect = CommonHelper.ApplyPadding(VisualOrientation.Top, rect, borderPadding); // Render the background inside the border path _mementoBack = context.Renderer.RenderStandardBack.DrawBack(context, enclosingRect, borderPath, paletteBack, VisualOrientation.Top, state, _mementoBack); } } }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // Take on the provided space ClientRectangle = context.DisplayRectangle; // Reduce space by the padding value context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, _displayPadding); // Layout each of the children with the new size foreach (ViewBase child in this) { // Only layout visible children if (child.Visible) { child.Layout(context); } } // Restore original display rect we were given context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> public override void RenderBefore(RenderContext context) { IPaletteBack paletteBack = _ribbon.StateCommon.RibbonGroupDialogButton.PaletteBack; IPaletteBorder paletteBorder = _ribbon.StateCommon.RibbonGroupDialogButton.PaletteBorder; IPaletteRibbonGeneral paletteGeneral = _ribbon.StateCommon.RibbonGeneral; // Do we need to draw the background? if (paletteBack.GetBackDraw(State) == InheritBool.True) { // Get the border path which the background is clipped to drawing within using GraphicsPath borderPath = context.Renderer.RenderStandardBorder.GetBackPath(context, ClientRectangle, paletteBorder, VisualOrientation.Top, State); Padding borderPadding = context.Renderer.RenderStandardBorder.GetBorderRawPadding(paletteBorder, State, VisualOrientation.Top); // Apply the padding depending on the orientation Rectangle enclosingRect = CommonHelper.ApplyPadding(VisualOrientation.Top, ClientRectangle, borderPadding); // Render the background inside the border path _mementoBack = context.Renderer.RenderStandardBack.DrawBack(context, enclosingRect, borderPath, paletteBack, VisualOrientation.Top, State, _mementoBack); } // Do we need to draw the border? if (paletteBorder.GetBorderDraw(State) == InheritBool.True) { context.Renderer.RenderStandardBorder.DrawBorder(context, ClientRectangle, paletteBorder, VisualOrientation.Top, State); } // Find the content area inside the button rectangle Rectangle contentRect = ClientRectangle; contentRect.Inflate(_contentSize); // Draw the dialog box launcher glyph in the center context.Renderer.RenderGlyph.DrawRibbonDialogBoxLauncher(_ribbon.RibbonShape, context, contentRect, paletteGeneral, State); }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { // Get size of the contained items Size preferredSize = base.GetPreferredSize(context); // Add on the border padding preferredSize = CommonHelper.ApplyPadding(Orientation.Horizontal, preferredSize, BarPadding); preferredSize.Height = Math.Max(preferredSize.Height, BarHeight); // If we are inside the custom chrome area if (OwnerForm != null) { // Calculate the maximum width allowed int maxWidth = ((OwnerForm.Width - 100) / 3) * 2; // Adjust so the width is a multiple of a button size int buttons = (maxWidth - BarPadding.Horizontal) / QAT_BUTTON_WIDTH; maxWidth = (buttons * QAT_BUTTON_WIDTH) + BarPadding.Horizontal; preferredSize.Width = Math.Min(maxWidth, preferredSize.Width); } return(preferredSize); }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); Rectangle clientRect = context.DisplayRectangle; // For the minibar we have to position ourself at bottom of available area if (_minibar) { clientRect.Y = clientRect.Bottom - 1 - QAT_HEIGHT_MINI; clientRect.Height = QAT_HEIGHT_MINI; } ClientRectangle = clientRect; // Remove QAT border for positioning children context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, BarPadding); // Let children be layed out inside border area base.Layout(context); // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // We take on all the available display area ClientRectangle = context.DisplayRectangle; if (!IgnoreAllBorderAndPadding) { // Do we have a metric source for additional padding? if ((_paletteMetric != null) && (_metricPadding != PaletteMetricPadding.None)) { // Get the padding to be applied before the canvas drawing Padding outerPadding = _paletteMetric.GetMetricPadding(State, _metricPadding); ClientRectangle = CommonHelper.ApplyPadding(Orientation, ClientRectangle, outerPadding); } } // Space available for children begins with our space Rectangle fillerRect = ClientRectangle; context.DisplayRectangle = fillerRect; // By default all the children need to draw all their borders PaletteDrawBorders leftEdges = PaletteDrawBorders.All; PaletteDrawBorders rightEdges = PaletteDrawBorders.All; PaletteDrawBorders topEdges = PaletteDrawBorders.All; PaletteDrawBorders bottomEdges = PaletteDrawBorders.All; PaletteDrawBorders fillEdges = PaletteDrawBorders.All; // Position all except the filler foreach (ViewBase child in Reverse()) { // Only position visible children if (child.Visible && (GetDock(child) != ViewDockStyle.Fill)) { // Prevent children from showing adjacent borders that are not needed UpdateChildBorders(child, context, ref leftEdges, ref rightEdges, ref topEdges, ref bottomEdges, ref fillEdges); // Get the preferred size of the child Size childSize = child.GetPreferredSize(context); // Position the child inside the available space switch (CalculateDock(OrientateDock(GetDock(child)), context.Control)) { case ViewDockStyle.Top: context.DisplayRectangle = new Rectangle(fillerRect.X, fillerRect.Y, fillerRect.Width, childSize.Height); fillerRect.Height -= childSize.Height; fillerRect.Y += childSize.Height; break; case ViewDockStyle.Bottom: context.DisplayRectangle = new Rectangle(fillerRect.X, fillerRect.Bottom - childSize.Height, fillerRect.Width, childSize.Height); fillerRect.Height -= childSize.Height; break; case ViewDockStyle.Left: context.DisplayRectangle = new Rectangle(fillerRect.X, fillerRect.Y, childSize.Width, fillerRect.Height); fillerRect.Width -= childSize.Width; fillerRect.X += childSize.Width; break; case ViewDockStyle.Right: context.DisplayRectangle = new Rectangle(fillerRect.Right - childSize.Width, fillerRect.Y, childSize.Width, fillerRect.Height); fillerRect.Width -= childSize.Width; break; } // Layout child in the provided space child.Layout(context); } } Rectangle borderRect = ClientRectangle; Padding padding = Padding.Empty; if (!IgnoreAllBorderAndPadding) { // Find the actual width of the border as we need to compare this to the calculating border // padding to work out how far from corners we can ignore the calculated border padding and // instead use the actual width only. int borderWidth = _paletteBorder.GetBorderWidth(State); // Update padding to reflect the orientation we are using padding = context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation); padding = CommonHelper.OrientatePadding(Orientation, padding); // If docking content extends beyond the border rounding effects then we can adjust // the padding back so that it lines against the edge and not the rounding edge padding = AdjustPaddingForDockers(padding, fillerRect, borderWidth); } // Apply the padding to the border rectangle borderRect = new Rectangle(borderRect.X + padding.Left, borderRect.Y + padding.Top, borderRect.Width - padding.Horizontal, borderRect.Height - padding.Vertical); // We need to ensure the filler is within the border rectangle if (fillerRect.X < borderRect.X) { fillerRect.Width -= borderRect.X - fillerRect.X; fillerRect.X = borderRect.X; } if (fillerRect.Y < borderRect.Y) { fillerRect.Height -= borderRect.Y - fillerRect.Y; fillerRect.Y = borderRect.Y; } if (fillerRect.Right > borderRect.Right) { fillerRect.Width -= fillerRect.Right - borderRect.Right; } if (fillerRect.Bottom > borderRect.Bottom) { fillerRect.Height -= fillerRect.Bottom - borderRect.Bottom; } // Position any filler last foreach (ViewBase child in Reverse()) { // Only position visible children if (child.Visible && (GetDock(child) == ViewDockStyle.Fill)) { // Prevent children from showing adjacent borders that are not needed UpdateChildBorders(child, context, ref leftEdges, ref rightEdges, ref topEdges, ref bottomEdges, ref fillEdges); // Give the filler the remaining space context.DisplayRectangle = fillerRect; // Layout child in the provided space child.Layout(context); } } // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; // The fill rectangle is the space left over after all children are positioned FillRectangle = fillerRect; }
/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> /// <exception cref="ArgumentNullException"></exception> public override void RenderBefore(RenderContext context) { Debug.Assert(context != null); // Validate incoming reference if (context == null) { throw new ArgumentNullException(nameof(context)); } // Do we need to draw the background? if (DrawCanvas && (_paletteBack.GetBackDraw(State) == InheritBool.True)) { GraphicsPath borderPath; Padding borderPadding; // Ask the border renderer for a path that encloses the border if (DrawTabBorder) { borderPath = context.Renderer.RenderTabBorder.GetTabBackPath(context, ClientRectangle, _paletteBorder, Orientation, State, TabBorderStyle); borderPadding = Padding.Empty; } else { borderPath = context.Renderer.RenderStandardBorder.GetBackPath(context, ClientRectangle, _paletteBorder, Orientation, State); borderPadding = context.Renderer.RenderStandardBorder.GetBorderRawPadding(_paletteBorder, State, Orientation); } // Apply the padding depending on the orientation Rectangle enclosingRect = CommonHelper.ApplyPadding(Orientation, ClientRectangle, borderPadding); // Render the background inside the border path _mementoBack = context.Renderer.RenderStandardBack.DrawBack(context, enclosingRect, borderPath, _paletteBack, Orientation, State, _mementoBack); borderPath.Dispose(); } if (DrawCanvas && (_paletteBorder != null)) { // Do we draw the border before the children? if (!DrawBorderLast) { RenderBorder(context); } else { // Drawing border afterwards, and so clip children to prevent drawing // over the corners if they are rounded. We only clip children if the // border is drawn afterwards. // Remember the current clipping region _clipRegion = context.Graphics.Clip.Clone(); // Restrict the clipping to the area inside the canvas border GraphicsPath borderPath = DrawTabBorder ? context.Renderer.RenderTabBorder.GetTabBorderPath(context, ClientRectangle, _paletteBorder, Orientation, State, TabBorderStyle) : context.Renderer.RenderStandardBorder.GetBorderPath(context, ClientRectangle, _paletteBorder, Orientation, State); if (borderPath == null) { throw new ArgumentNullException(nameof(borderPath)); } // Create a new region the same as the existing clipping region Region combineRegion = new Region(borderPath); // Reduce clipping region down by our border path combineRegion.Intersect(_clipRegion); context.Graphics.Clip = combineRegion; borderPath.Dispose(); } } }
private void RenderCollapsedPressedBefore(RenderContext context) { switch (_lastRibbonShape) { default: case PaletteRibbonShape.Office2007: { IPaletteBack paletteBack = _ribbon.StateCommon.RibbonGroupCollapsedButton.PaletteBack; IPaletteBorder paletteBorder = _ribbon.StateCommon.RibbonGroupCollapsedButton.PaletteBorder; // Do we need to draw the background? if (paletteBack.GetBackDraw(PaletteState.Pressed) == InheritBool.True) { // Get the border path which the background is clipped to drawing within using (GraphicsPath borderPath = context.Renderer.RenderStandardBorder.GetBackPath(context, ClientRectangle, paletteBorder, VisualOrientation.Top, PaletteState.Pressed)) { Padding borderPadding = context.Renderer.RenderStandardBorder.GetBorderRawPadding(paletteBorder, PaletteState.Pressed, VisualOrientation.Top); // Apply the padding depending on the orientation Rectangle enclosingRect = CommonHelper.ApplyPadding(VisualOrientation.Top, ClientRectangle, borderPadding); // Render the background inside the border path _mementoStandardBack = context.Renderer.RenderStandardBack.DrawBack(context, enclosingRect, borderPath, paletteBack, VisualOrientation.Top, PaletteState.Pressed, _mementoStandardBack); } } // Do we need to draw the border? if (paletteBorder.GetBorderDraw(PaletteState.Pressed) == InheritBool.True) { context.Renderer.RenderStandardBorder.DrawBorder(context, ClientRectangle, paletteBorder, VisualOrientation.Top, PaletteState.Pressed); } } break; case PaletteRibbonShape.Office2010: { Rectangle drawRect = ClientRectangle; IPaletteRibbonBack paletteBack = _ribbon.StatePressed.RibbonGroupCollapsedBack; IPaletteRibbonBack paletteBorder = _ribbon.StatePressed.RibbonGroupCollapsedBorder; PaletteState state = PaletteState.Pressed; // Are we a group inside a context tab? if ((_ribbon.SelectedTab != null) && !string.IsNullOrEmpty(_ribbon.SelectedTab.ContextName)) { state = PaletteState.ContextPressed; } // Draw the group border _paletteContextBack.SetInherit(paletteBorder); _mementoRibbonBack1 = context.Renderer.RenderRibbon.DrawRibbonBack(_ribbon.RibbonShape, context, drawRect, state, _paletteContextBack, VisualOrientation.Top, false, _mementoRibbonBack1); Rectangle backRect = drawRect; backRect.Inflate(-2, -2); // Draw the inside background _mementoRibbonBack2 = context.Renderer.RenderRibbon.DrawRibbonBack(_ribbon.RibbonShape, context, backRect, state, paletteBack, VisualOrientation.Top, false, _mementoRibbonBack2); } break; } }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); // Validate incoming reference if (context == null) { throw new ArgumentNullException("context"); } // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Ensure that the correct number of children are created SyncChildren(); // Is there anything to layout? if (Count > 0) { // Reduce the client area by the requested padding before the internal children Rectangle displayRect = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, _gallery.Padding); // Get size of the first child, assume all others are same size _itemSize = this[0].GetPreferredSize(context); // Number of items that can be placed on a single line _lineItems = Math.Max(1, displayRect.Width / _itemSize.Width); // Number of lines needed to show all the items _layoutLines = Math.Max(1, (Count + _lineItems - 1) / _lineItems); // Number of display lines that can be shown at a time _displayLines = Math.Max(1, Math.Min(_layoutLines, displayRect.Height / _itemSize.Height)); // Index of last line that can be the top line _endLine = _layoutLines - _displayLines; // Update topline and offset to reflect any outstanding bring into view request ProcessBringIntoView(); // Limit check the top line is within the valid range _topLine = Math.Max(0, Math.Min(_topLine, _endLine)); // Update the enabled state of the buttons _buttonUp.Enabled = _gallery.Enabled && CanPrevLine; _buttonDown.Enabled = _gallery.Enabled && CanNextLine; _buttonContext.Enabled = _gallery.Enabled && (Count > 0); // Calculate position of first item as the left edge but starting downwards // and equal amount of the spare space after drawing the display lines. Point nextPoint = displayRect.Location; nextPoint.Y += (displayRect.Height - (_displayLines * _itemSize.Height)) / 2; // Stating item is from the top line and last item is number of display items onwards int start = (_topLine * _lineItems); int end = start + (_displayLines * _lineItems); // Do we need to handle scroll offsetting? int offset = _offset; if (offset != 0) { if (offset < 0) { // How many extra full lines needed by the scrolling int extraLines = _topLine - _beginLine; // Limit check the number of previous lines to show if (_topLine - extraLines < 0) { extraLines = _topLine; } // Move start to ensure that the previous lines are visible start -= (extraLines * _lineItems); // Adjust offset to reflect change in start offset += (extraLines * _itemSize.Height); } else { // How many extra full lines needed by the scrolling int extraLines = _beginLine - _topLine; // Move start to ensure that the previous lines are visible end += (extraLines * _lineItems); // Limit check the end item to stop it overflowing number of items if (end > Count) { end = Count; } } } // Add scrolling offset nextPoint.Y -= offset; // Position all children on single line from left to right for (int i = 0; i < Count; i++) { ViewBase childItem = this[i]; // Should this item be visible if ((i < start) || (i >= end)) { childItem.Visible = false; } else { childItem.Visible = true; // Find rectangle for the child context.DisplayRectangle = new Rectangle(nextPoint, _itemSize); // Layout the child childItem.Layout(context); // Move across to next position nextPoint.X += _itemSize.Width; // If there is not enough room for another item on this line if ((nextPoint.X + _itemSize.Width) > displayRect.Right) { // Move down to next line nextPoint.X = displayRect.X; nextPoint.Y += _itemSize.Height; } } } } else { // No children means no items and so need for enabled buttons _buttonUp.Enabled = false; _buttonDown.Enabled = false; _buttonContext.Enabled = false; } // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { Debug.Assert(context != null); // Remember the original display rectangle provided Rectangle originalRect = context.DisplayRectangle; Rectangle displayRect = context.DisplayRectangle; // Border size that is not applied to preferred size Size borderSize = Size.Empty; // Accumulate the size that must be provided by docking edges and then filler Size preferredSize = Size.Empty; // Track the minimize size needed to satisfy the docking edges only Size minimumSize = Size.Empty; if (!IgnoreAllBorderAndPadding) { // Apply space the border takes up if (IgnoreBorderSpace) { borderSize = CommonHelper.ApplyPadding(Orientation, borderSize, context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation)); } else { Padding padding = context.Renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteBorder, State, Orientation); preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, padding); displayRect = CommonHelper.ApplyPadding(Orientation, displayRect, padding); } // Do we have a metric source for additional padding? if ((_paletteMetric != null) && (_metricPadding != PaletteMetricPadding.None)) { // Apply padding needed outside the border of the canvas Padding padding = _paletteMetric.GetMetricPadding(State, _metricPadding); preferredSize = CommonHelper.ApplyPadding(Orientation, preferredSize, padding); displayRect = CommonHelper.ApplyPadding(Orientation, displayRect, padding); } } PaletteDrawBorders leftEdges = PaletteDrawBorders.All; PaletteDrawBorders rightEdges = PaletteDrawBorders.All; PaletteDrawBorders topEdges = PaletteDrawBorders.All; PaletteDrawBorders bottomEdges = PaletteDrawBorders.All; PaletteDrawBorders fillEdges = PaletteDrawBorders.All; // Check for edge docking children foreach (ViewBase child in Reverse()) { // Only position visible children that are not 'fill' if ((child.Visible || PreferredSizeAll) && (GetDock(child) != ViewDockStyle.Fill)) { // Prevent children from showing adjacent borders that are not needed UpdateChildBorders(child, context, ref leftEdges, ref rightEdges, ref topEdges, ref bottomEdges, ref fillEdges); // Update with latest calculated display rectangle context.DisplayRectangle = displayRect; // Get the preferred size of the child Size childSize = child.GetPreferredSize(context); // Apply size requests from edge docking children switch (OrientateDock(GetDock(child))) { case ViewDockStyle.Top: preferredSize.Height += childSize.Height; displayRect.Y += childSize.Height; displayRect.Height -= childSize.Height; if (minimumSize.Width < childSize.Width) { minimumSize.Width = childSize.Width; } break; case ViewDockStyle.Bottom: preferredSize.Height += childSize.Height; displayRect.Height -= childSize.Height; if (minimumSize.Width < childSize.Width) { minimumSize.Width = childSize.Width; } break; case ViewDockStyle.Left: preferredSize.Width += childSize.Width; displayRect.X += childSize.Width; displayRect.Width -= childSize.Width; if (minimumSize.Height < childSize.Height) { minimumSize.Height = childSize.Height; } break; case ViewDockStyle.Right: preferredSize.Width += childSize.Width; displayRect.Width -= childSize.Width; if (minimumSize.Height < childSize.Height) { minimumSize.Height = childSize.Height; } break; } } } // Check for the fill child last foreach (ViewBase child in Reverse()) { // Only interested in a visible 'fill' child if ((child.Visible || PreferredSizeAll) && (GetDock(child) == ViewDockStyle.Fill)) { // Prevent children from showing adjacent borders that are not needed UpdateChildBorders(child, context, ref leftEdges, ref rightEdges, ref topEdges, ref bottomEdges, ref fillEdges); // Update with latest calculated display rectangle context.DisplayRectangle = displayRect; // Get the preferred size of the child Size childSize = child.GetPreferredSize(context); // Add on the preferred size of the filler preferredSize.Width += childSize.Width; preferredSize.Height += childSize.Height; } } // Put back the original display rect context.DisplayRectangle = originalRect; // Enforce the minimum values from the other docking edge sizes preferredSize.Width = Math.Max(preferredSize.Width, minimumSize.Width); preferredSize.Height = Math.Max(preferredSize.Height, minimumSize.Height); // Enforce the border sizing as the minimum preferredSize.Width = Math.Max(preferredSize.Width, borderSize.Width); preferredSize.Height = Math.Max(preferredSize.Height, borderSize.Height); return(preferredSize); }