SelectionEventArgs.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //#########################################################################################
  2. //★★★★★★★ http://www.cnpopsoft.com [华普软件] ★★★★★★★
  3. //★★★★★★★ 华普软件 - VB & C#.NET 专业论文与源码荟萃! ★★★★★★★
  4. //#########################################################################################
  5. /*
  6. * Copyright ?2005, Mathew Hall
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  25. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. * OF SUCH DAMAGE.
  29. */
  30. using System;
  31. using System.Drawing;
  32. using XPTable.Models;
  33. namespace XPTable.Events
  34. {
  35. #region Delegates
  36. /// <summary>
  37. /// Represents the methods that will handle the SelectionChanged event of a TableModel
  38. /// </summary>
  39. public delegate void SelectionEventHandler(object sender, SelectionEventArgs e);
  40. #endregion
  41. #region SelectionEventArgs
  42. /// <summary>
  43. /// Provides data for a TableModel's SelectionChanged event
  44. /// </summary>
  45. public class SelectionEventArgs : EventArgs
  46. {
  47. #region Class Data
  48. /// <summary>
  49. /// The TableModel that Raised the event
  50. /// </summary>
  51. private TableModel source;
  52. /// <summary>
  53. /// The previously selected Row indicies
  54. /// </summary>
  55. private int[] oldSelectedIndicies;
  56. /// <summary>
  57. /// The newly selected Row indicies
  58. /// </summary>
  59. private int[] newSelectedIndicies;
  60. /// <summary>
  61. /// The Rectangle that bounds the previously selected Rows
  62. /// </summary>
  63. private Rectangle oldSelectionBounds;
  64. /// <summary>
  65. /// The Rectangle that bounds the newly selected Rows
  66. /// </summary>
  67. private Rectangle newSelectionBounds;
  68. #endregion
  69. #region Constructor
  70. /// <summary>
  71. /// Initializes a new instance of the SelectionEventArgs class with
  72. /// the specified TableModel source, old selected indicies and new
  73. /// selected indicies
  74. /// </summary>
  75. /// <param name="source">The TableModel that originated the event</param>
  76. /// <param name="oldSelectedIndicies">An array of the previously selected Rows</param>
  77. /// <param name="newSelectedIndicies">An array of the newly selected Rows</param>
  78. public SelectionEventArgs(TableModel source, int[] oldSelectedIndicies, int[] newSelectedIndicies) : base()
  79. {
  80. if (source == null)
  81. {
  82. throw new ArgumentNullException("source", "TableModel cannot be null");
  83. }
  84. this.source = source;
  85. this.oldSelectedIndicies = oldSelectedIndicies;
  86. this.newSelectedIndicies = newSelectedIndicies;
  87. this.oldSelectionBounds = Rectangle.Empty;
  88. this.newSelectionBounds = Rectangle.Empty;
  89. if (oldSelectedIndicies.Length > 0)
  90. {
  91. this.oldSelectionBounds = source.Selections.CalcSelectionBounds(oldSelectedIndicies[0],
  92. oldSelectedIndicies[oldSelectedIndicies.Length-1]);
  93. }
  94. if (newSelectedIndicies.Length > 0)
  95. {
  96. this.newSelectionBounds = source.Selections.CalcSelectionBounds(newSelectedIndicies[0],
  97. newSelectedIndicies[newSelectedIndicies.Length-1]);
  98. }
  99. }
  100. #endregion
  101. #region Properties
  102. /// <summary>
  103. /// Gets the TableModel that Raised the event
  104. /// </summary>
  105. public TableModel TableModel
  106. {
  107. get
  108. {
  109. return this.source;
  110. }
  111. }
  112. /// <summary>
  113. /// Gets the previously selected Row indicies
  114. /// </summary>
  115. public int[] OldSelectedIndicies
  116. {
  117. get
  118. {
  119. return this.oldSelectedIndicies;
  120. }
  121. }
  122. /// <summary>
  123. /// Gets the newly selected Row indicies
  124. /// </summary>
  125. public int[] NewSelectedIndicies
  126. {
  127. get
  128. {
  129. return this.newSelectedIndicies;
  130. }
  131. }
  132. /// <summary>
  133. /// Gets the Rectangle that bounds the previously selected Rows
  134. /// </summary>
  135. internal Rectangle OldSelectionBounds
  136. {
  137. get
  138. {
  139. return this.oldSelectionBounds;
  140. }
  141. }
  142. /// <summary>
  143. /// Gets the Rectangle that bounds the newly selected Rows
  144. /// </summary>
  145. internal Rectangle NewSelectionBounds
  146. {
  147. get
  148. {
  149. return this.newSelectionBounds;
  150. }
  151. }
  152. #endregion
  153. }
  154. #endregion
  155. }