/* 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; namespace WindowsFormsCalendar { /// /// A collection of calendar items /// public class CalendarItemCollection : List { #region Events #endregion #region Fields private Calendar _calendar; #endregion #region Properties /// /// Gets the calendar. /// public Calendar Calendar { get { return _calendar; } } #endregion /// /// Initializes a new instance of the class. /// /// The c. internal CalendarItemCollection( Calendar c ) { _calendar = c; } #region Public Methods /// /// Adds an item to the end of the list /// /// The object to be added to the end of the collection. The value can be null for reference types. public new void Add( CalendarItem item ) { base.Add( item ); CollectionChanged(); } /// /// Adds the items of the specified collection to the end of the list. /// /// The items whose elements should be added to the end of the collection. The collection itself cannont be null, but it can contain elements that are null. public new void AddRange( IEnumerable items ) { base.AddRange( items ); CollectionChanged(); } /// /// Removes all elements from the collection. /// public new void Clear() { base.Clear(); CollectionChanged(); } /// /// Inserts an item into the collection at the specified index. /// /// The zero-based index at which item should be inserted. /// The object to insert. The value can be null for reference types. public new void Insert( int index, CalendarItem item ) { base.Insert( index, item ); CollectionChanged(); } /// /// Inserts the items of a collection into this collection at the specified index. /// /// The zero-based index at which the new elements should be inserted. /// public new void InsertRange( int index, IEnumerable items ) { base.InsertRange( index, items ); CollectionChanged(); } /// /// Removes the first occurrence of a specific object from the collection. /// /// The item to remove from the collection. The value can be null for reference types. /// true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the collection. public new bool Remove( CalendarItem item ) { bool result = base.Remove( item ); CollectionChanged(); return result; } /// /// Removes the item at the specified index of the collection /// /// The zero-based index of the item to remove. /// is less than 0. /// -or- /// is equal to or greater than . /// public new void RemoveAt( int index ) { base.RemoveAt( index ); CollectionChanged(); } /// /// Removes the all the items that match the conditions defined by the specified predicate. /// /// The Predicate delegate that defines the conditions of the items to remove. /// The number of items removed from the collection. public new int RemoveAll( Predicate match ) { int result = base.RemoveAll( match ); CollectionChanged(); return result; } /// /// Removes a range of elements from the collection /// /// The zero-based starting index of the range of items to remove. /// The number of items to remove public new void RemoveRange( int index, int count ) { base.RemoveRange( index, count ); CollectionChanged(); } #endregion #region Private Methods /// /// Handles what to do when this collection changes /// private void CollectionChanged() { Calendar.Renderer.PerformItemsLayout(); Calendar.Invalidate(); } #endregion } }