/// <summary> /// Initialize a new instance of the PaletteBorderInheritForced class. /// </summary> /// <param name="inherit">Border palette to inherit from.</param> public PaletteBorderInheritForced(IPaletteBorder inherit) { // Remember inheritance border _inherit = inherit; // Default values _maxBorderEdges = PaletteDrawBorders.All; _forceGraphicsHint = PaletteGraphicsHint.Inherit; _borderIgnoreNormal = false; }
/// <summary> /// Initialize a new instance of the ViewLayoutDocker class. /// </summary> public ViewLayoutDocker() { // Create child to dock style lookup _childDocking = new ViewDockStyleLookup(); // Default state _fillRectangle = Rectangle.Empty; _orientation = VisualOrientation.Top; _maxBorderEdges = PaletteDrawBorders.All; _preferredSizeAll = false; _removeChildBorders = false; _ignoreRightToLeftLayout = false; _padding = Padding.Empty; }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <param name="context">An ITypeDescriptorContext that provides a format context.</param> /// <param name="culture">The CultureInfo to use as the current culture.</param> /// <param name="value">The Object to convert.</param> /// <returns>An Object that represents the converted value.</returns> public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { // Convert incoming value to a string // We are only interested in adding functionality for converting from strings if (value is string conv) { // Default to returning an empty value PaletteDrawBorders ret = PaletteDrawBorders.None; // If inherit is in the string, we use only that value if (conv.Contains("Inherit")) { ret = PaletteDrawBorders.Inherit; } else { // If the word 'none' is found then no value is needed if (!conv.Contains("None")) { // Get the borders actually specified if (conv.Contains("Top")) { ret |= PaletteDrawBorders.Top; } if (conv.Contains("Bottom")) { ret |= PaletteDrawBorders.Bottom; } if (conv.Contains("Left")) { ret |= PaletteDrawBorders.Left; } if (conv.Contains("Right")) { ret |= PaletteDrawBorders.Right; } } } return(ret); } // Let base class perform default conversion return(base.ConvertFrom(context, culture, value)); }
/// <summary> /// Gets a value indicating which borders to draw. /// </summary> /// <param name="style">Border style.</param> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>PaletteDrawBorders value.</returns> public override PaletteDrawBorders GetBorderDrawBorders(PaletteBorderStyle style, PaletteState state) { PaletteDrawBorders paletteBorder = base.GetBorderDrawBorders(style, state); // The ribbon caption area should only ever draw a bottom border as the maximum if ((paletteBorder & PaletteDrawBorders.Bottom) == PaletteDrawBorders.Bottom) { return(PaletteDrawBorders.Bottom); } else { return(PaletteDrawBorders.None); } }
/// <summary> /// Initialize a new instance of the InternalStorage structure. /// </summary> public InternalStorage() { // Set to default values BorderDraw = InheritBool.Inherit; BorderDrawBorders = PaletteDrawBorders.All; BorderGraphicsHint = PaletteGraphicsHint.Inherit; BorderColor1 = Color.Empty; BorderColor2 = Color.Empty; BorderColorStyle = PaletteColorStyle.Inherit; BorderColorAlign = PaletteRectangleAlign.Inherit; BorderColorAngle = -1; BorderWidth = -1; BorderRounding = -1; BorderImageStyle = PaletteImageStyle.Inherit; BorderImageAlign = PaletteRectangleAlign.Inherit; }
/// <summary> /// Gets a value indicating which borders to draw. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>PaletteDrawBorders value.</returns> public override PaletteDrawBorders GetBorderDrawBorders(PaletteState state) { if (Apply) { PaletteDrawBorders ret = _primary.GetBorderDrawBorders(Override ? OverrideState : state); if (ret == PaletteDrawBorders.Inherit) { ret = _backup.GetBorderDrawBorders(state); } return(ret); } else { return(_backup.GetBorderDrawBorders(state)); } }
/// <summary> /// Gets a value indicating which borders to draw. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>PaletteDrawBorders value.</returns> public override PaletteDrawBorders GetBorderDrawBorders(PaletteState state) { if (_forceBorders) { return(_forceBorderEdges); } else { // If no border edges are allowed then provide none if ((MaxBorderEdges == PaletteDrawBorders.None) || (BorderIgnoreNormal && (state == PaletteState.Normal))) { return(PaletteDrawBorders.None); } else { // Get the requested set of edges PaletteDrawBorders inheritEdges = _inherit.GetBorderDrawBorders(state); // Limit the edges to those allowed return(inheritEdges & MaxBorderEdges); } } }
/// <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); // Create new lookup that only contains entries for current child items ViewDockStyleLookup newChildDocking = new ViewDockStyleLookup(); // Remember the original display rectangle provided Rectangle originalRect = context.DisplayRectangle; Rectangle displayRect = context.DisplayRectangle; // 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; 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()) { // Add into the valid child lookup ViewDockStyle dockStyle = GetDock(child); newChildDocking.Add(child, dockStyle); // 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(dockStyle)) { 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); preferredSize.Width += childSize.Width; preferredSize.Height += childSize.Height; // There can only be one filler! break; } } // Use updated lookup _childDocking = newChildDocking; // 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); // Apply the padding request switch (Orientation) { case VisualOrientation.Top: case VisualOrientation.Bottom: preferredSize.Width += Padding.Horizontal; preferredSize.Height += Padding.Vertical; break; case VisualOrientation.Left: case VisualOrientation.Right: preferredSize.Width += Padding.Vertical; preferredSize.Height += Padding.Horizontal; break; } // Allow the preferred size to be modified before being used return(UpdatePreferredSize(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 ClientRectangle = context.DisplayRectangle; // Space available for children begins with our space Rectangle fillerRect = ClientRectangle; // Apply the padding against the rect switch (Orientation) { case VisualOrientation.Top: fillerRect.X += Padding.Left; fillerRect.Y += Padding.Top; fillerRect.Width -= Padding.Horizontal; fillerRect.Height -= Padding.Vertical; break; case VisualOrientation.Bottom: fillerRect.X += Padding.Right; fillerRect.Y += Padding.Bottom; fillerRect.Width -= Padding.Horizontal; fillerRect.Height -= Padding.Vertical; break; case VisualOrientation.Left: fillerRect.X += Padding.Top; fillerRect.Y += Padding.Right; fillerRect.Width -= Padding.Vertical; fillerRect.Height -= Padding.Horizontal; break; case VisualOrientation.Right: fillerRect.X += Padding.Bottom; fillerRect.Y += Padding.Left; fillerRect.Width -= Padding.Vertical; fillerRect.Height -= Padding.Horizontal; break; } // 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 that are not 'fill' 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); // Provide the available space left over context.DisplayRectangle = fillerRect; // 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); } } // Allow the filler rectangle to be modified before being used fillerRect = UpdateFillerRect(fillerRect, context.Control); // 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; // Remember the filler size FillRectangle = fillerRect; }
public static bool HasRightBorder(PaletteDrawBorders borders) { return ((borders & PaletteDrawBorders.Right) == PaletteDrawBorders.Right); }
public static bool HasTopBorder(PaletteDrawBorders borders) { return ((borders & PaletteDrawBorders.Top) == PaletteDrawBorders.Top); }
private void UpdateChildBorders(ViewBase child, ViewLayoutContext context, ref PaletteDrawBorders leftEdges, ref PaletteDrawBorders rightEdges, ref PaletteDrawBorders topEdges, ref PaletteDrawBorders bottomEdges, ref PaletteDrawBorders fillEdges) { // Do we need to calculate if the child should remove any borders? if (RemoveChildBorders) { // Check if the view is a canvas ViewDrawCanvas childCanvas = child as ViewDrawCanvas; // Docking edge determines calculation switch (CalculateDock(GetDock(child), context.Control)) { case ViewDockStyle.Top: if (childCanvas != null) childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(topEdges, childCanvas.Orientation); // Remove top edges from subsequent children leftEdges &= PaletteDrawBorders.BottomLeftRight; rightEdges &= PaletteDrawBorders.BottomLeftRight; topEdges &= PaletteDrawBorders.BottomLeftRight; break; case ViewDockStyle.Bottom: if (childCanvas != null) childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(bottomEdges, childCanvas.Orientation); // Remove bottom edges from subsequent children leftEdges &= PaletteDrawBorders.TopLeftRight; rightEdges &= PaletteDrawBorders.TopLeftRight; bottomEdges &= PaletteDrawBorders.TopLeftRight; break; case ViewDockStyle.Left: if (childCanvas != null) childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(leftEdges, childCanvas.Orientation); // Remove left edges from subsequent children topEdges &= PaletteDrawBorders.TopBottomRight; bottomEdges &= PaletteDrawBorders.TopBottomRight; leftEdges &= PaletteDrawBorders.TopBottomRight; break; case ViewDockStyle.Right: if (childCanvas != null) childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(rightEdges, childCanvas.Orientation); // Remove right edges from subsequent children topEdges &= PaletteDrawBorders.TopBottomLeft; bottomEdges &= PaletteDrawBorders.TopBottomLeft; rightEdges &= PaletteDrawBorders.TopBottomLeft; break; } } }
private static void CreateBorderBackPathOnlyClosed(bool middle, PaletteDrawBorders borders, GraphicsPath borderPath, Rectangle rect, int arcLength, int variant) { // Reduce the width and height by 1 pixel for drawing into rectangle rect.Width--; rect.Height--; // We create the path using a floating point rectangle RectangleF rectF = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height); // If trying to get the outside edge then perform some offsetting so that // when converted to a region it draws nicely inside the path outline if (!middle) { rectF.X -= 0.25f; rectF.Y -= 0.25f; rectF.Width += 0.75f; rectF.Height += 0.75f; } // Add only the border for drawing switch (borders) { case PaletteDrawBorders.None: break; case PaletteDrawBorders.Top: case PaletteDrawBorders.Bottom: case PaletteDrawBorders.Left: case PaletteDrawBorders.Right: case PaletteDrawBorders.TopBottom: case PaletteDrawBorders.LeftRight: // When using the entire rectangle we do not need to adjust its size rect.Width ++; rect.Height++; borderPath.AddRectangle(rect); break; case PaletteDrawBorders.TopLeft: borderPath.AddLine(rectF.Left, rectF.Bottom + 1, rectF.Left, rectF.Top + arcLength); borderPath.AddArc(rectF.Left, rectF.Top, arcLength, arcLength, 180f, 90f); borderPath.AddLine(rectF.Left + arcLength, rectF.Top, rectF.Right + 1, rectF.Top); borderPath.AddLine(rectF.Right, rectF.Top, rectF.Right, rectF.Bottom); break; case PaletteDrawBorders.TopRight: borderPath.AddLine(rectF.Left - 1, rectF.Top, rectF.Right - arcLength, rectF.Top); borderPath.AddArc(rectF.Right - arcLength, rectF.Top, arcLength, arcLength, -90f, 90f); borderPath.AddLine(rectF.Right, rectF.Top + arcLength, rectF.Right, rectF.Bottom + 1); borderPath.AddLine(rectF.Right, rectF.Bottom, rectF.Left, rectF.Bottom); break; case PaletteDrawBorders.BottomRight: borderPath.AddLine(rectF.Right, rectF.Top - 1, rectF.Right, rectF.Bottom - arcLength); borderPath.AddArc(rectF.Right - arcLength, rectF.Bottom - arcLength, arcLength, arcLength, 0f, 90f); borderPath.AddLine(rectF.Right - arcLength, rectF.Bottom, rectF.Left - 1, rectF.Bottom); borderPath.AddLine(rectF.Left, rectF.Bottom, rectF.Left, rectF.Top); break; case PaletteDrawBorders.BottomLeft: borderPath.AddLine(rectF.Right + 1, rectF.Bottom, rectF.Left + arcLength, rectF.Bottom); borderPath.AddArc(rectF.Left, rectF.Bottom - arcLength, arcLength, arcLength, 90f, 90f); borderPath.AddLine(rectF.Left, rectF.Bottom - arcLength, rectF.Left, rectF.Top - 1); borderPath.AddLine(rectF.Left, rectF.Top, rectF.Right, rectF.Top); break; case PaletteDrawBorders.TopBottomLeft: borderPath.AddLine(rectF.Right + 1, rectF.Bottom, rectF.Left + arcLength, rectF.Bottom); borderPath.AddArc(rectF.Left, rectF.Bottom - arcLength, arcLength, arcLength, 90f, 90f); borderPath.AddArc(rectF.Left, rectF.Top, arcLength, arcLength, 180f, 90f); borderPath.AddLine(rectF.Left + arcLength, rectF.Top, rectF.Right + 1, rectF.Top); break; case PaletteDrawBorders.TopBottomRight: borderPath.AddLine(rectF.Left - 1, rectF.Top, rectF.Right - arcLength, rectF.Top); borderPath.AddArc(rectF.Right - arcLength, rectF.Top, arcLength, arcLength, -90f, 90f); borderPath.AddArc(rectF.Right - arcLength, rectF.Bottom - arcLength, arcLength, arcLength, 0f, 90f); borderPath.AddLine(rectF.Right - arcLength, rectF.Bottom, rectF.Left - 1, rectF.Bottom); break; case PaletteDrawBorders.TopLeftRight: borderPath.AddLine(rectF.Left, rectF.Bottom + 1, rectF.Left, rectF.Top + arcLength); borderPath.AddArc(rectF.Left, rectF.Top, arcLength, arcLength, 180f, 90f); borderPath.AddArc(rectF.Right - arcLength, rectF.Top, arcLength, arcLength, -90f, 90f); borderPath.AddLine(rectF.Right, rectF.Top + arcLength, rectF.Right, rectF.Bottom + 1); break; case PaletteDrawBorders.BottomLeftRight: borderPath.AddLine(rectF.Right, rectF.Top - 1, rectF.Right, rectF.Bottom - arcLength); borderPath.AddArc(rectF.Right - arcLength, rectF.Bottom - arcLength, arcLength, arcLength, 0f, 90f); borderPath.AddArc(rectF.Left, rectF.Bottom - arcLength, arcLength, arcLength, 90f, 90f); borderPath.AddLine(rectF.Left, rectF.Bottom - arcLength, rectF.Left, rectF.Top - 1); break; } }
private static GraphicsPath CreateBorderBackPath(bool forBorder, bool middle, Rectangle rect, PaletteDrawBorders borders, int borderWidth, int borderRounding, bool smoothing, int variant) { Rectangle origRect = rect; GraphicsPath borderPath = new GraphicsPath(); // A zero size rectangle cannot be drawn, so return a null path if ((rect.Width > 0) && (rect.Height > 0)) { // Only use a rounding that will fit inside the rect int rounding = Math.Min(borderRounding, Math.Min(rect.Width / 2, rect.Height / 2) - borderWidth); // Shrink the rect by half the width of the pen, because the pen will // draw half the distance overlapping each side of the centre anyway. // Unless not drawing into the middle in which case give the outside. int halfBorderWidthTL = (middle ? borderWidth / 2 : 0); // Only adjust the edges that are being drawn if (CommonHelper.HasTopBorder(borders)) { rect.Y += halfBorderWidthTL; rect.Height -= halfBorderWidthTL; } if (CommonHelper.HasLeftBorder(borders)) { rect.X += halfBorderWidthTL; rect.Width -= halfBorderWidthTL; } if (CommonHelper.HasBottomBorder(borders)) rect.Height -= halfBorderWidthTL; if (CommonHelper.HasRightBorder(borders)) rect.Width -= halfBorderWidthTL; // Find the width/height of the arc box int arcLength = rounding * 2; int arcLength1 = arcLength + 1; // If drawing all the four borders use a single routine if (CommonHelper.HasAllBorders(borders)) CreateAllBorderBackPath(middle, borderPath, rect, borderWidth, rounding, forBorder, arcLength, arcLength1); else { // Are we calculating just the borders to be drawn? if (forBorder) { // Are we calculating for the outside of the border edge? This is used for a KryptonForm // which needs to create a region that is the outside edge of the borders. if (!middle) { // If rounding is used we need to use a path so that corner rounding is honored but // because this is going to be used as a region we need to close the path as well. if (rounding > 0) CreateBorderBackPathOnlyClosed(middle, borders, borderPath, rect, arcLength, variant); else { // Without rounding we just provide the entire area borderPath.AddRectangle(rect); } } else { // We are calculating the middle of the border as the brush will then draw the entire // border from the middle outwards. if (rounding > 0) CreateBorderBackPathOnly(middle, borders, borderPath, rect, arcLength, variant); else CreateBorderBackPathOnly(borders, borderPath, rect, variant); } } else { // Calculating a complete path for the entire area and not just the specified borders // If there is rounding we need to calculate a path that honors the rounding at corners if (rounding > 0) CreateBorderBackPathComplete(middle, borders, borderPath, rect, arcLength); else { // Without rounding the complete path is always just the entire area borderPath.AddRectangle(rect); } } } } return borderPath; }
/// <summary> /// Apply a reversed orientation so that when orientated again it comes out with the original value. /// </summary> /// <param name="borders">Border edges to be drawn.</param> /// <param name="orientation">How to adjsut the border edges.</param> /// <returns>Border edges adjusted for orientation.</returns> public static PaletteDrawBorders ReverseOrientateDrawBorders(PaletteDrawBorders borders, VisualOrientation orientation) { // No need to perform an change for top orientation if (orientation == VisualOrientation.Top) return borders; // No need to change the All or None values if ((borders == PaletteDrawBorders.All) || (borders == PaletteDrawBorders.None)) return borders; PaletteDrawBorders ret = PaletteDrawBorders.None; // Apply orientation change to each side in turn switch (orientation) { case VisualOrientation.Bottom: // Invert sides if (CommonHelper.HasTopBorder(borders)) ret |= PaletteDrawBorders.Bottom; if (CommonHelper.HasBottomBorder(borders)) ret |= PaletteDrawBorders.Top; if (CommonHelper.HasLeftBorder(borders)) ret |= PaletteDrawBorders.Right; if (CommonHelper.HasRightBorder(borders)) ret |= PaletteDrawBorders.Left; break; case VisualOrientation.Right: // Rotate one anti-clockwise if (CommonHelper.HasTopBorder(borders)) ret |= PaletteDrawBorders.Left; if (CommonHelper.HasBottomBorder(borders)) ret |= PaletteDrawBorders.Right; if (CommonHelper.HasLeftBorder(borders)) ret |= PaletteDrawBorders.Bottom; if (CommonHelper.HasRightBorder(borders)) ret |= PaletteDrawBorders.Top; break; case VisualOrientation.Left: // Rotate sides one clockwise if (CommonHelper.HasTopBorder(borders)) ret |= PaletteDrawBorders.Right; if (CommonHelper.HasBottomBorder(borders)) ret |= PaletteDrawBorders.Left; if (CommonHelper.HasLeftBorder(borders)) ret |= PaletteDrawBorders.Top; if (CommonHelper.HasRightBorder(borders)) ret |= PaletteDrawBorders.Bottom; break; default: // Should never happen! Debug.Assert(false); break; } return ret; }
/// <summary> /// Force the border edges to a particular value. /// </summary> /// <param name="forceBorderEdges">Borders to force.</param> public void ForceBorderEdges(PaletteDrawBorders forceBorderEdges) { _forceBorderEdges = forceBorderEdges; _forceBorders = true; }
/// <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> /// 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); }
private static void CreateBorderBackPathComplete(bool middle, PaletteDrawBorders borders, GraphicsPath borderPath, Rectangle rect, int arcLength) { // We create the path using a floating point rectangle RectangleF rectF = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height); // If trying to get the outside edge then perform some offsetting so that // when converted to a region it draws nicely inside the path outline if (!middle) { rectF.X -= 0.25f; rectF.Y -= 0.25f; rectF.Width += 0.75f; rectF.Height += 0.75f; } // Define area that covers the border and the inside switch (borders) { case PaletteDrawBorders.None: case PaletteDrawBorders.Top: case PaletteDrawBorders.Bottom: case PaletteDrawBorders.Left: case PaletteDrawBorders.Right: case PaletteDrawBorders.TopBottom: case PaletteDrawBorders.LeftRight: // Just add a simple rectangle as a quick way of adding four lines borderPath.AddRectangle(rect); break; case PaletteDrawBorders.TopLeft: borderPath.AddLine(rectF.Left, rectF.Bottom, rectF.Left, rectF.Top + arcLength); borderPath.AddArc(rectF.Left, rectF.Top, arcLength, arcLength, 180f, 90f); borderPath.AddLine(rectF.Left + arcLength, rectF.Top, rectF.Right, rectF.Top); borderPath.AddLine(rectF.Right, rectF.Top, rectF.Right, rectF.Bottom); borderPath.AddLine(rectF.Right, rectF.Bottom, rectF.Left, rectF.Bottom); break; case PaletteDrawBorders.TopRight: borderPath.AddLine(rectF.Left, rectF.Top, rectF.Right - arcLength, rectF.Top); borderPath.AddArc(rectF.Right - arcLength, rectF.Top, arcLength, arcLength, -90f, 90f); borderPath.AddLine(rectF.Right, rectF.Top + arcLength, rectF.Right, rectF.Bottom); borderPath.AddLine(rectF.Right, rectF.Bottom, rectF.Left, rectF.Bottom); borderPath.AddLine(rectF.Left, rectF.Bottom, rectF.Left, rectF.Top); break; case PaletteDrawBorders.BottomRight: // Reduce the width and height by 1 pixel for drawing into rectFangle rectF.Width -= 1; rectF.Height -= 1; borderPath.AddLine(rectF.Right, rectF.Top, rectF.Right, rectF.Bottom - arcLength); borderPath.AddArc(rectF.Right - arcLength, rectF.Bottom - arcLength, arcLength, arcLength, 0f, 90f); borderPath.AddLine(rectF.Right - arcLength, rectF.Bottom, rectF.Left, rectF.Bottom); borderPath.AddLine(rectF.Left, rectF.Bottom, rectF.Left, rectF.Top); borderPath.AddLine(rectF.Left, rectF.Top, rectF.Right, rectF.Top); break; case PaletteDrawBorders.BottomLeft: // Reduce the width and height by 1 pixel for drawing into rectangle rectF.X++; rectF.Width -= 1; rectF.Height -= 1; borderPath.AddLine(rectF.Right, rectF.Bottom, rectF.Left + arcLength, rectF.Bottom); borderPath.AddArc(rectF.Left, rectF.Bottom - arcLength, arcLength, arcLength, 90f, 90f); borderPath.AddLine(rectF.Left, rectF.Bottom - arcLength, rectF.Left, rectF.Top); borderPath.AddLine(rectF.Left, rectF.Top, rectF.Right, rectF.Top); borderPath.AddLine(rectF.Right, rectF.Top, rectF.Right, rectF.Bottom); break; case PaletteDrawBorders.TopBottomLeft: borderPath.AddLine(rectF.Right, rectF.Bottom, rectF.Left + arcLength, rectF.Bottom); borderPath.AddArc(rectF.Left, rectF.Bottom - arcLength, arcLength, arcLength, 90f, 90f); borderPath.AddArc(rectF.Left, rectF.Top, arcLength, arcLength, 180f, 90f); borderPath.AddLine(rectF.Left + arcLength, rectF.Top, rectF.Right, rectF.Top); borderPath.AddLine(rectF.Right, rectF.Top, rectF.Right, rectF.Bottom); break; case PaletteDrawBorders.TopBottomRight: // Reduce the width and height by 1 pixel for drawing into rectangle rectF.Width -= 1; rectF.Height -= 1; borderPath.AddLine(rectF.Left, rectF.Top, rectF.Right - arcLength, rectF.Top); borderPath.AddArc(rectF.Right - arcLength, rectF.Top, arcLength, arcLength, -90f, 90f); borderPath.AddArc(rectF.Right - arcLength, rectF.Bottom - arcLength, arcLength, arcLength, 0f, 90f); borderPath.AddLine(rectF.Right - arcLength, rectF.Bottom, rectF.Left, rectF.Bottom); borderPath.AddLine(rectF.Left, rectF.Bottom, rectF.Left, rectF.Top); break; case PaletteDrawBorders.TopLeftRight: borderPath.AddLine(rectF.Left, rectF.Bottom, rectF.Left, rectF.Top + arcLength); borderPath.AddArc(rectF.Left, rectF.Top, arcLength, arcLength, 180f, 90f); borderPath.AddArc(rectF.Right - arcLength, rectF.Top, arcLength, arcLength, -90f, 90f); borderPath.AddLine(rectF.Right, rectF.Top + arcLength, rectF.Right, rectF.Bottom); borderPath.AddLine(rectF.Right, rectF.Bottom, rectF.Left, rectF.Bottom); break; case PaletteDrawBorders.BottomLeftRight: // Reduce the width and height by 1 pixel for drawing into rectangle rectF.X++; rectF.Width -= 1; rectF.Height -= 1; borderPath.AddLine(rectF.Right, rectF.Top, rectF.Right, rectF.Bottom - arcLength); borderPath.AddArc(rectF.Right - arcLength, rectF.Bottom - arcLength, arcLength, arcLength, 0f, 90f); borderPath.AddArc(rectF.Left, rectF.Bottom - arcLength, arcLength, arcLength, 90f, 90f); borderPath.AddLine(rectF.Left, rectF.Top, rectF.Right, rectF.Top); break; } }
private void UpdateChildBorders(ViewBase child, ViewLayoutContext context, ref PaletteDrawBorders leftEdges, ref PaletteDrawBorders rightEdges, ref PaletteDrawBorders topEdges, ref PaletteDrawBorders bottomEdges, ref PaletteDrawBorders fillEdges) { // Do we need to calculate if the child should remove any borders? if (RemoveChildBorders) { // Check if the view is a canvas ViewDrawCanvas childCanvas = child as ViewDrawCanvas; // Docking edge determines calculation switch (CalculateDock(GetDock(child), context.Control)) { case ViewDockStyle.Fill: if (childCanvas != null) { childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(fillEdges, childCanvas.Orientation); } else { if (child is ViewLayoutDocker layoutDocker) { foreach (ViewBase layoutChild in layoutDocker) { childCanvas = layoutChild as ViewDrawCanvas; if (childCanvas != null) { childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(fillEdges, childCanvas.Orientation); } } } } break; case ViewDockStyle.Top: if (childCanvas != null) { childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(topEdges, childCanvas.Orientation); } // Remove top edges from subsequent children leftEdges &= PaletteDrawBorders.BottomLeftRight; rightEdges &= PaletteDrawBorders.BottomLeftRight; topEdges &= PaletteDrawBorders.BottomLeftRight; fillEdges &= PaletteDrawBorders.BottomLeftRight; break; case ViewDockStyle.Bottom: if (childCanvas != null) { childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(bottomEdges, childCanvas.Orientation); } // Remove bottom edges from subsequent children leftEdges &= PaletteDrawBorders.TopLeftRight; rightEdges &= PaletteDrawBorders.TopLeftRight; bottomEdges &= PaletteDrawBorders.TopLeftRight; fillEdges &= PaletteDrawBorders.TopLeftRight; break; case ViewDockStyle.Left: if (childCanvas != null) { childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(leftEdges, childCanvas.Orientation); } // Remove left edges from subsequent children topEdges &= PaletteDrawBorders.TopBottomRight; bottomEdges &= PaletteDrawBorders.TopBottomRight; leftEdges &= PaletteDrawBorders.TopBottomRight; fillEdges &= PaletteDrawBorders.TopBottomRight; break; case ViewDockStyle.Right: if (childCanvas != null) { childCanvas.MaxBorderEdges = CommonHelper.ReverseOrientateDrawBorders(rightEdges, childCanvas.Orientation); } // Remove right edges from subsequent children topEdges &= PaletteDrawBorders.TopBottomLeft; bottomEdges &= PaletteDrawBorders.TopBottomLeft; rightEdges &= PaletteDrawBorders.TopBottomLeft; fillEdges &= PaletteDrawBorders.TopBottomLeft; break; } } }
public static PaletteDrawBorders ReverseOrientateDrawBorders(PaletteDrawBorders borders, VisualOrientation orientation) { if (orientation == VisualOrientation.Top) { return borders; } if ((borders == PaletteDrawBorders.All) || (borders == PaletteDrawBorders.None)) { return borders; } PaletteDrawBorders none = PaletteDrawBorders.None; switch (orientation) { case VisualOrientation.Bottom: if (HasTopBorder(borders)) { none |= PaletteDrawBorders.Bottom; } if (HasBottomBorder(borders)) { none |= PaletteDrawBorders.Top; } if (HasLeftBorder(borders)) { none |= PaletteDrawBorders.Right; } if (HasRightBorder(borders)) { none |= PaletteDrawBorders.Left; } return none; case VisualOrientation.Left: if (HasTopBorder(borders)) { none |= PaletteDrawBorders.Right; } if (HasBottomBorder(borders)) { none |= PaletteDrawBorders.Left; } if (HasLeftBorder(borders)) { none |= PaletteDrawBorders.Top; } if (HasRightBorder(borders)) { none |= PaletteDrawBorders.Bottom; } return none; case VisualOrientation.Right: if (HasTopBorder(borders)) { none |= PaletteDrawBorders.Left; } if (HasBottomBorder(borders)) { none |= PaletteDrawBorders.Right; } if (HasLeftBorder(borders)) { none |= PaletteDrawBorders.Bottom; } if (HasRightBorder(borders)) { none |= PaletteDrawBorders.Top; } return none; } return none; }
private void SyncChildrenToRibbonGroupItems() { // Grab the shape of the ribbon _lastShape = _ribbon.RibbonShape; bool itemEdgeVisible = (_lastShape != PaletteRibbonShape.Office2010); bool itemEdgeIgnoreNormal = (_lastShape == PaletteRibbonShape.Office2010); bool itemConstantBorder = (_lastShape != PaletteRibbonShape.Office2010); bool itemDrawNonTrackingAreas = (_lastShape != PaletteRibbonShape.Office2010); // Remove all child elements Clear(); // Always add the start separator as the first view element Add(_startSep); // Create new lookups which are up to date ItemToView regenView = new ItemToView(); ViewToEdge regenEdge = new ViewToEdge(); // Cache the first and last visible children ViewBase viewFirst = null; ViewBase viewLast = null; // Add a view element for each group item foreach (IRibbonGroupItem item in _ribbonCluster.Items) { ViewBase itemView; ViewDrawRibbonGroupClusterEdge itemEdge; // Do we already have a view for this item definition if (_itemToView.ContainsKey(item)) { itemView = _itemToView[item]; itemEdge = _viewToEdge[itemView]; // Remove from lookups _itemToView.Remove(item); _viewToEdge.Remove(itemView); } else { // Ask the item definition to return an appropriate view itemView = item.CreateView(_ribbon, _needPaint); // Create a border edge to go with the item view itemEdge = new ViewDrawRibbonGroupClusterEdge(_ribbon, _paletteBorderEdge); } // Update the visible state itemView.Visible = _ribbon.InDesignHelperMode || item.Visible; itemEdge.Visible = itemEdgeVisible && (_ribbon.InDesignHelperMode || item.Visible); // We need to remember associations regenView.Add(item, itemView); regenEdge.Add(itemView, itemEdge); Add(itemView); Add(itemEdge); // Update the cached first/last items if (itemView.Visible && (viewFirst == null)) { viewFirst = itemView; } if (itemView.Visible) { viewLast = itemView; } } // Update the display borders for the visible items foreach (ViewBase item in regenView.Values) { // Only interested in visible items if (item.Visible) { if ((item is ViewDrawRibbonGroupClusterButton) || (item is ViewDrawRibbonGroupClusterColorButton)) { // By default each button shows only the top and bottom PaletteDrawBorders maxBorders = PaletteDrawBorders.TopBottom; switch (_lastShape) { default: case PaletteRibbonShape.Office2007: maxBorders = PaletteDrawBorders.TopBottom; // First and last items have extra borders if (item == viewFirst) { // If first and last, it needs all borders if (item == viewLast) { maxBorders = PaletteDrawBorders.All; } else { maxBorders = PaletteDrawBorders.TopBottomLeft; } } else if (item == viewLast) { maxBorders = PaletteDrawBorders.TopBottomRight; } break; case PaletteRibbonShape.Office2010: maxBorders = PaletteDrawBorders.All; break; } // Remove the border edge after the last button if (item == viewLast) { Remove(regenEdge[item]); } // Cast to correct type ViewDrawRibbonGroupClusterButton clusterButton = item as ViewDrawRibbonGroupClusterButton; ViewDrawRibbonGroupClusterColorButton clusterColorButton = item as ViewDrawRibbonGroupClusterColorButton; if (clusterButton != null) { clusterButton.MaxBorderEdges = maxBorders; clusterButton.BorderIgnoreNormal = itemEdgeIgnoreNormal; clusterButton.ConstantBorder = itemConstantBorder; clusterButton.DrawNonTrackingAreas = itemDrawNonTrackingAreas; } if (clusterColorButton != null) { clusterColorButton.MaxBorderEdges = maxBorders; clusterColorButton.BorderIgnoreNormal = itemEdgeIgnoreNormal; clusterColorButton.ConstantBorder = itemConstantBorder; clusterColorButton.DrawNonTrackingAreas = itemDrawNonTrackingAreas; } } } } // Dispose of all the items no longer needed foreach (ViewBase view in _itemToView.Values) { view.Dispose(); } foreach (ViewBase view in _viewToEdge.Values) { view.Dispose(); } // Always add the end separator as the last view element (excluding any desing time additions) Add(_endSep); // Define visible state of the separators _startSep.Visible = (_lastShape == PaletteRibbonShape.Office2010); _endSep.Visible = (_lastShape == PaletteRibbonShape.Office2010); // When in design time help mode if (_ribbon.InDesignHelperMode) { // Create the design time 'Item' first time it is needed if (_viewAddItem == null) { _viewAddItem = new ViewDrawRibbonDesignCluster(_ribbon, _ribbonCluster, _needPaint); } // Always add at end of the list of items Add(_viewAddItem); } // Use the latest tables _itemToView = regenView; _viewToEdge = regenEdge; }
public static bool HasNoBorders(PaletteDrawBorders borders) { return ((borders & PaletteDrawBorders.All) == PaletteDrawBorders.None); }
/// <summary> /// Converts the given value object to the specified type, using the specified context and culture information. /// </summary> /// <param name="context">An ITypeDescriptorContext that provides a format context.</param> /// <param name="culture">A CultureInfo object. If a null reference the current culture is assumed.</param> /// <param name="value">The Object to convert.</param> /// <param name="destinationType">The Type to convert the value parameter to.</param> /// <returns>An Object that represents the converted value.</returns> public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { // We are only interested in adding functionality for converting to strings if (destinationType == typeof(string)) { // Convert object to expected style PaletteDrawBorders borders = (PaletteDrawBorders)value; // If the inherit flag is set that that is the only flag of interest if ((borders & PaletteDrawBorders.Inherit) == PaletteDrawBorders.Inherit) { return("Inherit"); } else { // Append the names of each border we want StringBuilder sb = new StringBuilder(); if ((borders & PaletteDrawBorders.Top) == PaletteDrawBorders.Top) { sb.Append("Top"); } if ((borders & PaletteDrawBorders.Bottom) == PaletteDrawBorders.Bottom) { if (sb.Length > 0) { sb.Append(","); } sb.Append("Bottom"); } if ((borders & PaletteDrawBorders.Left) == PaletteDrawBorders.Left) { if (sb.Length > 0) { sb.Append(","); } sb.Append("Left"); } if ((borders & PaletteDrawBorders.Right) == PaletteDrawBorders.Right) { if (sb.Length > 0) { sb.Append(","); } sb.Append("Right"); } // If no border is wanted then return a fixed string if (sb.Length == 0) { sb.Append("None"); } return(sb.ToString()); } } // Let base class perform default conversion return(base.ConvertTo(context, culture, value, destinationType)); }
public static bool HasOneBorder(PaletteDrawBorders borders) { PaletteDrawBorders justBorders = (borders & PaletteDrawBorders.All); // If borders value equals just one of the edges return (justBorders == PaletteDrawBorders.Top) || (justBorders == PaletteDrawBorders.Bottom) || (justBorders == PaletteDrawBorders.Left) || (justBorders == PaletteDrawBorders.Right); }
public static bool HasABorder(PaletteDrawBorders borders) { return ((borders & PaletteDrawBorders.All) != PaletteDrawBorders.None); }
private static void CreateBorderBackPathOnly(PaletteDrawBorders borders, GraphicsPath borderPath, Rectangle rect, int variant) { // Reduce the width and height by 1 pixel for drawing into rectangle rect.Width -= 1; rect.Height -= 1; // Add only the border for drawing switch (borders) { case PaletteDrawBorders.None: break; case PaletteDrawBorders.Top: borderPath.AddLine(rect.Left - 1, rect.Top, rect.Right + 1, rect.Top); break; case PaletteDrawBorders.Bottom: borderPath.AddLine(rect.Left - 1, rect.Bottom, rect.Right + 1, rect.Bottom); break; case PaletteDrawBorders.Left: borderPath.AddLine(rect.Left, rect.Top - 1, rect.Left, rect.Bottom + 1); break; case PaletteDrawBorders.Right: borderPath.AddLine(rect.Right, rect.Top - 1, rect.Right, rect.Bottom + 1); break; case PaletteDrawBorders.TopBottom: if (variant == 0) borderPath.AddLine(rect.Left - 1, rect.Top, rect.Right + 1, rect.Top); else borderPath.AddLine(rect.Left - 1, rect.Bottom, rect.Right + 1, rect.Bottom); break; case PaletteDrawBorders.LeftRight: if (variant == 0) borderPath.AddLine(rect.Left, rect.Top - 1, rect.Left, rect.Bottom + 1); else borderPath.AddLine(rect.Right, rect.Top - 1, rect.Right, rect.Bottom + 1); break; case PaletteDrawBorders.TopLeft: borderPath.AddLine(rect.Left, rect.Bottom + 1, rect.Left, rect.Top); borderPath.AddLine(rect.Left, rect.Top, rect.Right + 1, rect.Top); break; case PaletteDrawBorders.TopRight: borderPath.AddLine(rect.Left, rect.Top, rect.Right, rect.Top); borderPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom + 1); break; case PaletteDrawBorders.BottomRight: borderPath.AddLine(rect.Right, rect.Top - 1, rect.Right, rect.Bottom); borderPath.AddLine(rect.Right, rect.Bottom, rect.Left - 1, rect.Bottom); break; case PaletteDrawBorders.BottomLeft: borderPath.AddLine(rect.Right + 1, rect.Bottom, rect.Left, rect.Bottom); borderPath.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top - 1); break; case PaletteDrawBorders.TopBottomLeft: borderPath.AddLine(rect.Right + 1, rect.Bottom, rect.Left, rect.Bottom); borderPath.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top); borderPath.AddLine(rect.Left, rect.Top, rect.Right + 1, rect.Top); break; case PaletteDrawBorders.TopBottomRight: borderPath.AddLine(rect.Left - 1, rect.Top, rect.Right, rect.Top); borderPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom); borderPath.AddLine(rect.Right, rect.Bottom, rect.Left - 1, rect.Bottom); break; case PaletteDrawBorders.TopLeftRight: borderPath.AddLine(rect.Left, rect.Bottom + 1, rect.Left, rect.Top); borderPath.AddLine(rect.Left, rect.Top, rect.Right, rect.Top); borderPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom + 1); break; case PaletteDrawBorders.BottomLeftRight: borderPath.AddLine(rect.Right, rect.Top - 1, rect.Right, rect.Bottom); borderPath.AddLine(rect.Right, rect.Bottom, rect.Left, rect.Bottom); borderPath.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top - 1); break; } }
public static bool HasBottomBorder(PaletteDrawBorders borders) { return ((borders & PaletteDrawBorders.Bottom) == PaletteDrawBorders.Bottom); }
public static bool HasLeftBorder(PaletteDrawBorders borders) { return ((borders & PaletteDrawBorders.Left) == PaletteDrawBorders.Left); }
public static bool HasOneBorder(PaletteDrawBorders borders) { PaletteDrawBorders borders2 = borders & PaletteDrawBorders.All; if (((borders2 != PaletteDrawBorders.Top) && (borders2 != PaletteDrawBorders.Bottom)) && (borders2 != PaletteDrawBorders.Left)) { return (borders2 == PaletteDrawBorders.Right); } return true; }