private static void xLayoutDockedControl(IArrangedElement element, Rectangle newElementBounds, bool measureOnly, ref Size preferredSize, ref Rectangle remainingBounds) { if (measureOnly) { Size proposedSize = new Size(Math.Max(0, newElementBounds.Width - remainingBounds.Width), Math.Max(0, newElementBounds.Height - remainingBounds.Height)); DockStyle dock = GetDock(element); switch (dock) { case DockStyle.Top: case DockStyle.Bottom: proposedSize.Width = 0; break; } if ((dock == DockStyle.Left) || (dock == DockStyle.Right)) { proposedSize.Height = 0; } if (dock != DockStyle.Fill) { preferredSize += proposedSize; remainingBounds.Size += proposedSize; } else if ((dock == DockStyle.Fill) && CommonProperties.GetAutoSize(element)) { Size size2 = element.GetPreferredSize(proposedSize); remainingBounds.Size += size2; preferredSize += size2; } } else { element.SetBounds(newElementBounds, BoundsSpecified.None); } }
private static Size xGetDockedSize(IArrangedElement element, Size remainingSize, Size constraints, bool measureOnly) { if (CommonProperties.GetAutoSize(element)) { return(element.GetPreferredSize(constraints)); } return(element.Bounds.Size); }
private static Size GetControlSize(IArrangedElement c, Size proposedSize) { if (c.AutoSize) { return(c.GetPreferredSize(proposedSize)); } else { return(c.ExplicitBounds.Size); } }
private static void TryCalculatePreferredSizeDockedControl(IArrangedElement element, Rectangle newElementBounds, bool measureOnly, ref Size preferredSize, ref Rectangle remainingBounds) { if (measureOnly) { Size neededSize = new Size( Math.Max(0, newElementBounds.Width - remainingBounds.Width), Math.Max(0, newElementBounds.Height - remainingBounds.Height)); DockStyle dockStyle = GetDock(element); if ((dockStyle == DockStyle.Top) || (dockStyle == DockStyle.Bottom)) { neededSize.Width = 0; } if ((dockStyle == DockStyle.Left) || (dockStyle == DockStyle.Right)) { neededSize.Height = 0; } if (dockStyle != DockStyle.Fill) { preferredSize += neededSize; remainingBounds.Size += neededSize; } else if (dockStyle == DockStyle.Fill && CommonProperties.GetAutoSize(element)) { Size elementPrefSize = element.GetPreferredSize(neededSize); remainingBounds.Size += elementPrefSize; preferredSize += elementPrefSize; } } else { element.SetBounds(newElementBounds, BoundsSpecified.None); #if DEBUG Control control = element as Control; newElementBounds.Size = control.ApplySizeConstraints(newElementBounds.Size); // This usually happens when a Control overrides its SetBoundsCore or sets size during OnResize // to enforce constraints like AutoSize. Generally you can just move this code to Control.GetAdjustedSize // and then PreferredSize will also pick up these constraints. See ComboBox as an example. if (CommonProperties.GetAutoSize(element) && !CommonProperties.GetSelfAutoSizeInDefaultLayout(element)) { Debug.Assert( (newElementBounds.Width < 0 || element.Bounds.Width == newElementBounds.Width) && (newElementBounds.Height < 0 || element.Bounds.Height == newElementBounds.Height), "Element modified its bounds during docking -- PreferredSize will be wrong. See comment near this assert."); } #endif } }
private static void LayoutAutoSizedControls(IArrangedElement container) { ArrangedElementCollection children = container.Children; for (int i = children.Count - 1; i >= 0; i--) { IArrangedElement element = children[i]; if (CommonProperties.xGetAutoSizedAndAnchored(element)) { Rectangle bounds = GetCachedBounds(element); AnchorStyles anchor = GetAnchor(element); Size proposedConstraints = LayoutUtils.MaxSize; if ((anchor & (AnchorStyles.Left | AnchorStyles.Right)) == (AnchorStyles.Left | AnchorStyles.Right)) { proposedConstraints.Width = bounds.Width; } if ((anchor & (AnchorStyles.Top | AnchorStyles.Bottom)) == (AnchorStyles.Top | AnchorStyles.Bottom)) { proposedConstraints.Height = bounds.Height; } Size prefSize = element.GetPreferredSize(proposedConstraints); Rectangle newBounds = bounds; if (CommonProperties.GetAutoSizeMode(element) == AutoSizeMode.GrowAndShrink) { // this is the case for simple things like radio button, checkbox, etc. newBounds = GetGrowthBounds(element, prefSize); } else { // we had whacked this check, but it turns out it causes undesirable // behavior in things like panel. a panel with no elements sizes to 0,0. if (bounds.Width < prefSize.Width || bounds.Height < prefSize.Height) { Size newSize = LayoutUtils.UnionSizes(bounds.Size, prefSize); newBounds = GetGrowthBounds(element, newSize); } } if (newBounds != bounds) { SetCachedBounds(element, newBounds); } } } }
private static void LayoutAutoSizedControls(IArrangedElement container) { ArrangedElementCollection children = container.Children; for (int i = children.Count - 1; i >= 0; i--) { IArrangedElement element = children[i]; if (CommonProperties.xGetAutoSizedAndAnchored(element)) { Rectangle cachedBounds = GetCachedBounds(element); AnchorStyles anchor = GetAnchor(element); Size maxSize = LayoutUtils.MaxSize; if ((anchor & (AnchorStyles.Right | AnchorStyles.Left)) == (AnchorStyles.Right | AnchorStyles.Left)) { maxSize.Width = cachedBounds.Width; } if ((anchor & (AnchorStyles.Bottom | AnchorStyles.Top)) == (AnchorStyles.Bottom | AnchorStyles.Top)) { maxSize.Height = cachedBounds.Height; } Size preferredSize = element.GetPreferredSize(maxSize); Rectangle bounds = cachedBounds; if (CommonProperties.GetAutoSizeMode(element) == AutoSizeMode.GrowAndShrink) { bounds = GetGrowthBounds(element, preferredSize); } else if ((cachedBounds.Width < preferredSize.Width) || (cachedBounds.Height < preferredSize.Height)) { Size newSize = LayoutUtils.UnionSizes(cachedBounds.Size, preferredSize); bounds = GetGrowthBounds(element, newSize); } if (bounds != cachedBounds) { SetCachedBounds(element, bounds); } } } }
//Unused //private static Size GetFillDockedSize(IArrangedElement element, Size remainingSize, bool measureOnly) { // Size newSize = xGetDockedSize(element, remainingSize, /* constraints = */ remainingSize, measureOnly); // newSize = LayoutUtils.UnionSizes(newSize, remainingSize); // if (!measureOnly) { // newSize = LayoutUtils.IntersectSizes(newSize, remainingSize); // } // Debug.Assert(newSize.Width >= remainingSize.Width && newSize.Height >= remainingSize.Height, // "Error detected in GetFillDockedSize: Element did not stretch to remaning size."); // Debug.Assert(measureOnly || (newSize.Width == remainingSize.Width && newSize.Height == remainingSize.Height), // "Error detected in GetFillDockedSize: Dock size computed incorrectly during layout."); // return newSize; //} private static Size xGetDockedSize(IArrangedElement element, Size remainingSize, Size constraints, bool measureOnly) { Size desiredSize; if (CommonProperties.GetAutoSize(element)) { // Ask control for its desired size using the provided constraints. // (e.g., a control docked to top will constrain width to remaining width // and minimize height.) desiredSize = element.GetPreferredSize(constraints); } else { desiredSize = element.Bounds.Size; } Debug.Assert((desiredSize.Width >= 0 && desiredSize.Height >= 0), "Error detected in xGetDockSize: Element size was negative."); return desiredSize; }
// Helper method that either sets the element bounds or does the preferredSize computation based on // the value of measureOnly. private static void xLayoutDockedControl(IArrangedElement element, Rectangle newElementBounds, bool measureOnly, ref Size preferredSize, ref Rectangle remainingBounds) { if (measureOnly) { Size neededSize = new Size( Math.Max(0, newElementBounds.Width - remainingBounds.Width), Math.Max(0, newElementBounds.Height - remainingBounds.Height)); DockStyle dockStyle = GetDock(element); if ((dockStyle == DockStyle.Top) || (dockStyle == DockStyle.Bottom)) { neededSize.Width = 0; } if ((dockStyle == DockStyle.Left) || (dockStyle == DockStyle.Right)) { neededSize.Height = 0; } if (dockStyle != DockStyle.Fill) { preferredSize += neededSize; remainingBounds.Size += neededSize; } else if(dockStyle == DockStyle.Fill && CommonProperties.GetAutoSize(element)) { Size elementPrefSize = element.GetPreferredSize(neededSize); remainingBounds.Size += elementPrefSize; preferredSize += elementPrefSize; } } else { element.SetBounds(newElementBounds, BoundsSpecified.None); #if DEBUG Control control = element as Control; newElementBounds.Size = control.ApplySizeConstraints(newElementBounds.Size); // This usually happens when a Control overrides its SetBoundsCore or sets size during OnResize // to enforce constraints like AutoSize. Generally you can just move this code to Control.GetAdjustedSize // and then PreferredSize will also pick up these constraints. See ComboBox as an example. // if (CommonProperties.GetAutoSize(element) && !CommonProperties.GetSelfAutoSizeInDefaultLayout(element)) { Debug.Assert( (newElementBounds.Width < 0 || element.Bounds.Width == newElementBounds.Width) && (newElementBounds.Height < 0 || element.Bounds.Height == newElementBounds.Height), "Element modified its bounds during docking -- PreferredSize will be wrong. See comment near this assert."); } #endif } }
public virtual Size GetPreferredSize(Size proposedSize) { return(_element.GetPreferredSize(proposedSize)); }
private Size GetElementSize(IArrangedElement element, Size proposedConstraints) { if(CommonProperties.GetAutoSize(element)) { return element.GetPreferredSize(proposedConstraints); } else { return CommonProperties.GetSpecifiedBounds(element).Size; } }
private static Size xGetDockedSize(IArrangedElement element, Size remainingSize, Size constraints, bool measureOnly) { if (CommonProperties.GetAutoSize(element)) { return element.GetPreferredSize(constraints); } return element.Bounds.Size; }