/* Copyright 2012 Justin LeCheminant This file is part of WindowsFormsCalendar. indowsFormsCalendar is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. indowsFormsCalendar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with indowsFormsCalendar. If not, see . */ using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace WindowsFormsCalendar { /// /// Represents a month displayed"/> /// public class MonthViewMonth { #region Fields private DateTime _date; private Rectangle monthNameBounds; private Rectangle[] dayNamesBounds; private MonthViewDay[] days; private string[] _dayHeaders; private Size _size = new Size(); private Point _location; private MonthView _monthview; #endregion #region Properties /// /// Gets the bounds. /// public Rectangle Bounds { get { return new Rectangle( Location, Size ); } } /// /// Gets the month view. /// public MonthView MonthView { get { return _monthview; } } /// /// Gets the location. /// public Point Location { get { return _location; } } /// /// Gets the size. /// public Size Size { get { return MonthView.MonthSize; } } /// /// Gets or sets the days. /// /// /// The days. /// public MonthViewDay[] Days { get { return days; } set { days = value; } } /// /// Gets or sets the day names bounds. /// /// /// The day names bounds. /// public Rectangle[] DayNamesBounds { get { return dayNamesBounds; } set { dayNamesBounds = value; } } /// /// Gets or sets the day headers. /// /// /// The day headers. /// public string[] DayHeaders { get { return _dayHeaders; } set { _dayHeaders = value; } } /// /// Gets or sets the month name bounds. /// /// /// The month name bounds. /// public Rectangle MonthNameBounds { get { return monthNameBounds; } set { monthNameBounds = value; } } /// /// Gets or sets the date of the first day of the month /// public DateTime Date { get { return _date; } } #endregion /// /// Initializes a new instance of the class. /// /// The month view. /// The date. internal MonthViewMonth( MonthView monthView, DateTime date ) { if( date.Day != 1 ) { date = new DateTime( date.Year, date.Month, 1 ); } _monthview = monthView; _date = date; int preDays = ( new int[] { 0, 1, 2, 3, 4, 5, 6 } )[(int)date.DayOfWeek] - (int)MonthView.FirstDayOfWeek; days = new MonthViewDay[6 * 7]; DateTime curDate = date.AddDays( -preDays ); DayHeaders = new string[7]; for( int i = 0; i < days.Length; i++ ) { days[i] = new MonthViewDay( this, curDate ); if( i < 7 ) { DayHeaders[i] = curDate.ToString( MonthView.DayNamesFormat ).Substring( 0, MonthView.DayNamesLength ); } curDate = curDate.AddDays( 1 ); } } #region Public Methods #endregion #region Private Methods /// /// Sets the value of the property /// /// internal void SetLocation( Point location ) { int startX = location.X; int startY = location.Y; int curX = startX; int curY = startY; _location = location; monthNameBounds = new Rectangle( location, new Size( Size.Width, MonthView.DaySize.Height ) ); if( MonthView.DayNamesVisible ) { dayNamesBounds = new Rectangle[7]; curY = location.Y + MonthView.DaySize.Height; for( int i = 0; i < dayNamesBounds.Length; i++ ) { DayNamesBounds[i] = new Rectangle( curX, curY, MonthView.DaySize.Width, MonthView.DaySize.Height ); curX += MonthView.DaySize.Width; } } else { dayNamesBounds = new Rectangle[] { }; } curX = startX; curY = startY + MonthView.DaySize.Height * 2; for( int i = 0; i < Days.Length; i++ ) { Days[i].SetBounds( new Rectangle( new Point( curX, curY ), MonthView.DaySize ) ); curX += MonthView.DaySize.Width; if( ( i + 1 ) % 7 == 0 ) { curX = startX; curY += MonthView.DaySize.Height; } } } #endregion } }