ComponentFactory.Krypton.Toolkit.ViewDrawMonthDays.Layout C# (CSharp) Method

Layout() public method

Perform a layout of the elements.
public Layout ( ViewLayoutContext context ) : void
context ViewLayoutContext Layout context.
return void
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Get the current date values
            DateTime minDate = _calendar.MinDate.Date;
            DateTime maxDate = _calendar.MaxDate.Date;
            DateTime selectStart = _calendar.SelectionStart.Date;
            DateTime selectEnd = _calendar.SelectionEnd.Date;

            // We take on all the available display area
            ClientRectangle = context.DisplayRectangle;

            int layoutXCell = ClientLocation.X;
            int layoutXDay = ClientLocation.X + (_months.SizeDays.Width - _months.SizeDay.Width) / 2;
            Rectangle layoutRectCell = new Rectangle(layoutXCell, ClientLocation.Y, _months.SizeDays.Width, _months.SizeDays.Height);
            Rectangle layoutRectDay = new Rectangle(layoutXDay, ClientLocation.Y, _months.SizeDay.Width, _months.SizeDays.Height);

            // Layout each week as a row
            DateTime todayDate = _calendar.TodayDate;
            DateTime displayDate = _firstDay;
            for (int j = 0; j < WEEKS; j++)
            {
                // Layout each day as a column
                for (int i = 0; i < WEEKDAYS; i++)
                {
                    // Memento index
                    int index = j * WEEKDAYS + i;

                    // Define text to be drawn
                    _drawText = displayDate.Day.ToString();

                    if (_dayMementos[index] != null)
                    {
                        _dayMementos[index].Dispose();
                        _dayMementos[index] = null;
                    }

                    bool skip = false;
                    PaletteState paletteState = PaletteState.Normal;
                    IPaletteTriple paletteTriple = _calendar.OverrideNormal;

                    // If the display date is not within the allowed range, do not draw it
                    if ((displayDate < minDate) || (displayDate > maxDate))
                        skip = true;
                    else
                    {
                        _calendar.SetFocusOverride(false);
                        _calendar.SetBoldedOverride(BoldedDate(displayDate));
                        _calendar.SetTodayOverride(_months.ShowTodayCircle && (displayDate == todayDate));

                        // If the day is not actually in the month we are drawing
                        if (displayDate.Month != _month.Month)
                        {
                            // If we need to show this day but disabled
                            if (((j < 3) && _firstMonth) || ((j > 3) && _lastMonth))
                            {
                                paletteState = PaletteState.Disabled;
                                paletteTriple = _calendar.OverrideDisabled;
                            }
                            else
                                skip = true;
                        }
                        else
                        {
                            // Is this day part of the selection?
                            if ((displayDate >= selectStart) && (displayDate <= selectEnd))
                            {
                                _calendar.SetFocusOverride(((_months.FocusDay != null) && (_months.FocusDay.Value == displayDate)));

                                if (_months.TrackingDay.HasValue && (_months.TrackingDay.Value == displayDate))
                                {
                                    paletteState = PaletteState.CheckedTracking;
                                    paletteTriple = _calendar.OverrideCheckedTracking;
                                }
                                else
                                {
                                    paletteState = PaletteState.CheckedNormal;
                                    paletteTriple = _calendar.OverrideCheckedNormal;
                                }
                            }
                            else
                            {
                                if (_months.TrackingDay.HasValue && (_months.TrackingDay.Value == displayDate))
                                {
                                    paletteState = PaletteState.Tracking;
                                    paletteTriple = _calendar.OverrideTracking;
                                }
                            }
                        }
                    }

                    if (!skip)
                    {
                        _dayMementos[index] = context.Renderer.RenderStandardContent.LayoutContent(context, layoutRectDay, paletteTriple.PaletteContent,
                                                                                                   this, VisualOrientation.Top, paletteState, false);

                        // Track the maximum date displayed for this month (exclude disabled days that are shown for
                        // information but cannot actually be selected themselves as part of a multi selection action)
                        if (paletteState != PaletteState.Disabled)
                            _lastDay = displayDate;
                    }

                    _dayRects[index] = layoutRectCell;

                    // Move across to next column
                    layoutRectCell.X += _months.SizeDays.Width;
                    layoutRectDay.X += _months.SizeDays.Width;

                    // Move to next day
                    displayDate += TIMESPAN_1DAY;
                }

                // Move to start of the next row
                layoutRectCell.X = layoutXCell;
                layoutRectCell.Y += _months.SizeDays.Height;
                layoutRectDay.X = layoutXDay;
                layoutRectDay.Y += _months.SizeDays.Height;
            }

            // Put back the original display value now we have finished
            context.DisplayRectangle = ClientRectangle;
        }