+
+ void LayoutAutoSizedChildren (Control parent, Control[] controls)
+ {
+ for (int i = 0; i < controls.Length; i++) {
+ int left;
+ int top;
+
+ Control child = controls[i];
+ if (!child.VisibleInternal
+ || child.ControlLayoutType == Control.LayoutType.Dock
+ || !child.AutoSize)
+ continue;
+
+ AnchorStyles anchor = child.Anchor;
+ left = child.Left;
+ top = child.Top;
+
+ Size preferredsize = GetPreferredControlSize (child);
+
+ if (((anchor & AnchorStyles.Left) != 0) || ((anchor & AnchorStyles.Right) == 0))
+ child.dist_right += child.Width - preferredsize.Width;
+ if (((anchor & AnchorStyles.Top) != 0) || ((anchor & AnchorStyles.Bottom) == 0))
+ child.dist_bottom += child.Height - preferredsize.Height;
+
+ child.SetBoundsInternal (left, top, preferredsize.Width, preferredsize.Height, BoundsSpecified.None);
+ }
+ }
+
+ void LayoutAutoSizeContainer (Control container)
+ {
+ int left;
+ int top;
+ int width;
+ int height;
+
+ if (!container.VisibleInternal || container.ControlLayoutType == Control.LayoutType.Dock || !container.AutoSize)
+ return;
+
+ left = container.Left;
+ top = container.Top;
+
+ Size preferredsize = container.PreferredSize;
+
+ if (container.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink) {
+ width = preferredsize.Width;
+ height = preferredsize.Height;
+ } else {
+ width = container.ExplicitBounds.Width;
+ height = container.ExplicitBounds.Height;
+ if (preferredsize.Width > width)
+ width = preferredsize.Width;
+ if (preferredsize.Height > height)
+ height = preferredsize.Height;
+ }
+
+ // Sanity
+ if (width < container.MinimumSize.Width)
+ width = container.MinimumSize.Width;
+
+ if (height < container.MinimumSize.Height)
+ height = container.MinimumSize.Height;
+
+ if (container.MaximumSize.Width != 0 && width > container.MaximumSize.Width)
+ width = container.MaximumSize.Width;
+
+ if (container.MaximumSize.Height != 0 && height > container.MaximumSize.Height)
+ height = container.MaximumSize.Height;
+
+ container.SetBoundsInternal (left, top, width, height, BoundsSpecified.None);
+ }