ComponentFactory.Krypton.Toolkit.RenderStandard.GetContentPreferredSize C# (CSharp) Method

GetContentPreferredSize() public method

Get the preferred size for drawing the content.
public GetContentPreferredSize ( ViewLayoutContext context, IPaletteContent palette, IContentValues values, VisualOrientation orientation, PaletteState state, bool composition ) : Size
context ViewLayoutContext Layout context.
palette IPaletteContent Content palette details.
values IContentValues Content values.
orientation VisualOrientation Visual orientation of the content.
state PaletteState State associated with rendering.
composition bool Should draw on a composition element.
return Size
        public override Size GetContentPreferredSize(ViewLayoutContext context,
													 IPaletteContent palette,
													 IContentValues values,
													 VisualOrientation orientation,
                                                     PaletteState state,
                                                     bool composition)
        {
            Debug.Assert(context != null);
            Debug.Assert(palette != null);
            Debug.Assert(values != null);

            // Validate parameter references
            if (context == null) throw new ArgumentNullException("context");
            if (palette == null) throw new ArgumentNullException("palette");

            Debug.Assert(context.Control != null);
            Debug.Assert(!context.Control.IsDisposed);

            // Provide a maximum sized rectangle for placing content into, in
            // order to work out how much of the space is actually allocated
            Rectangle displayRect = new Rectangle(Point.Empty, new Size(int.MaxValue, int.MaxValue));

            // Track the allocated space in each grid position
            Size[,] allocation = new Size[3, 3] { { Size.Empty, Size.Empty, Size.Empty },
                                                  { Size.Empty, Size.Empty, Size.Empty },
                                                  { Size.Empty, Size.Empty, Size.Empty } };

            // Create a memento for storing calculations
            using (StandardContentMemento memento = new StandardContentMemento())
            {
                // Cache the size of a spacing gap
                int spacingGap = palette.GetContentAdjacentGap(state);

                // Is the content intended for a vertical drawing orientation?
                bool vertical = (orientation == VisualOrientation.Left) ||
                                (orientation == VisualOrientation.Right);

                // Drawing vertical means we can ignore right to left, otherwise get value from control
                RightToLeft rtl = (vertical ? RightToLeft.No : context.Control.RightToLeft);

                // Allocate space for each required content in turn
                AllocateImageSpace(memento, palette, values, state, displayRect, rtl, ref allocation);
                AllocateShortTextSpace(context, context.Graphics, memento, palette, values, state, displayRect, rtl, spacingGap, ref allocation, composition);
                AllocateLongTextSpace(context, context.Graphics, memento, palette, values, state, displayRect, rtl, spacingGap, ref allocation, composition);

                // Add up total allocated for rows and columns
                int allocatedWidth = AllocatedTotalWidth(allocation, -1, -1, spacingGap);
                int allocatedHeight = AllocatedTotalHeight(allocation);

                // Grab the padding for the content
                Padding borderPadding = palette.GetContentPadding(state);

                // For the form level buttons we have to calculate the correct padding based on caption area
                PaletteContentStyle contentStyle = palette.GetContentStyle();
                if ((contentStyle == PaletteContentStyle.ButtonForm) ||
                    (contentStyle == PaletteContentStyle.ButtonFormClose))
                    borderPadding = ContentPaddingForButtonForm(borderPadding, context, allocatedHeight);

                // The preferred size needed depends on the orientation.
                switch (orientation)
                {
                    case VisualOrientation.Top:
                    case VisualOrientation.Bottom:
                        // Preferred size is the allocated space for the content plus the border padding
                        return new Size(allocatedWidth + borderPadding.Horizontal,
                                        allocatedHeight + borderPadding.Vertical);
                    case VisualOrientation.Left:
                    case VisualOrientation.Right:
                        // Preferred size is the allocated space for the content plus the border padding
                        return new Size(allocatedHeight + borderPadding.Vertical,
                                        allocatedWidth + borderPadding.Horizontal);
                    default:
                        // Should never happen!
                        Debug.Assert(false);
                        return Size.Empty;
                }
            }
        }
RenderStandard