CheckBoxColumn.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.ComponentModel;
  32. using System.Drawing;
  33. using XPTable.Editors;
  34. using XPTable.Events;
  35. using XPTable.Models.Design;
  36. using XPTable.Renderers;
  37. using XPTable.Sorting;
  38. namespace XPTable.Models
  39. {
  40. /// <summary>
  41. /// Represents a Column whose Cells are displayed as a CheckBox
  42. /// </summary>
  43. [DesignTimeVisible(false),
  44. ToolboxItem(false)]
  45. public class CheckBoxColumn : Column
  46. {
  47. #region Class Data
  48. /// <summary>
  49. /// The size of the checkbox
  50. /// </summary>
  51. private Size checkSize;
  52. /// <summary>
  53. /// Specifies whether any text contained in the Cell should be drawn
  54. /// </summary>
  55. private bool drawText;
  56. /// <summary>
  57. /// The style of the checkboxes
  58. /// </summary>
  59. private CheckBoxColumnStyle checkStyle;
  60. #endregion
  61. #region Constructor
  62. /// <summary>
  63. /// Creates a new CheckBoxColumn with default values
  64. /// </summary>
  65. public CheckBoxColumn() : base()
  66. {
  67. this.Init();
  68. }
  69. /// <summary>
  70. /// Creates a new CheckBoxColumn with the specified header text
  71. /// </summary>
  72. /// <param name="text">The text displayed in the column's header</param>
  73. public CheckBoxColumn(string text) : base(text)
  74. {
  75. this.Init();
  76. }
  77. /// <summary>
  78. /// Creates a new CheckBoxColumn with the specified header text and width
  79. /// </summary>
  80. /// <param name="text">The text displayed in the column's header</param>
  81. /// <param name="width">The column's width</param>
  82. public CheckBoxColumn(string text, int width) : base(text, width)
  83. {
  84. this.Init();
  85. }
  86. /// <summary>
  87. /// Creates a new CheckBoxColumn with the specified header text, width and visibility
  88. /// </summary>
  89. /// <param name="text">The text displayed in the column's header</param>
  90. /// <param name="width">The column's width</param>
  91. /// <param name="visible">Specifies whether the column is visible</param>
  92. public CheckBoxColumn(string text, int width, bool visible) : base(text, width, visible)
  93. {
  94. this.Init();
  95. }
  96. /// <summary>
  97. /// Creates a new CheckBoxColumn with the specified header text and image
  98. /// </summary>
  99. /// <param name="text">The text displayed in the column's header</param>
  100. /// <param name="image">The image displayed on the column's header</param>
  101. public CheckBoxColumn(string text, Image image) : base(text, image)
  102. {
  103. this.Init();
  104. }
  105. /// <summary>
  106. /// Creates a new CheckBoxColumn with the specified header text, image and width
  107. /// </summary>
  108. /// <param name="text">The text displayed in the column's header</param>
  109. /// <param name="image">The image displayed on the column's header</param>
  110. /// <param name="width">The column's width</param>
  111. public CheckBoxColumn(string text, Image image, int width) : base(text, image, width)
  112. {
  113. this.Init();
  114. }
  115. /// <summary>
  116. /// Creates a new CheckBoxColumn with the specified header text, image, width and visibility
  117. /// </summary>
  118. /// <param name="text">The text displayed in the column's header</param>
  119. /// <param name="image">The image displayed on the column's header</param>
  120. /// <param name="width">The column's width</param>
  121. /// <param name="visible">Specifies whether the column is visible</param>
  122. public CheckBoxColumn(string text, Image image, int width, bool visible) : base(text, image, width, visible)
  123. {
  124. this.Init();
  125. }
  126. /// <summary>
  127. /// Initializes the CheckBoxColumn with default values
  128. /// </summary>
  129. private void Init()
  130. {
  131. this.checkSize = new Size(13, 13);
  132. this.drawText = true;
  133. this.checkStyle = CheckBoxColumnStyle.CheckBox;
  134. }
  135. #endregion
  136. #region Methods
  137. /// <summary>
  138. /// Gets a string that specifies the name of the Column's default CellRenderer
  139. /// </summary>
  140. /// <returns>A string that specifies the name of the Column's default
  141. /// CellRenderer</returns>
  142. public override string GetDefaultRendererName()
  143. {
  144. return "CHECKBOX";
  145. }
  146. /// <summary>
  147. /// Gets the Column's default CellRenderer
  148. /// </summary>
  149. /// <returns>The Column's default CellRenderer</returns>
  150. public override ICellRenderer CreateDefaultRenderer()
  151. {
  152. return new CheckBoxCellRenderer();
  153. }
  154. /// <summary>
  155. /// Gets a string that specifies the name of the Column's default CellEditor
  156. /// </summary>
  157. /// <returns>A string that specifies the name of the Column's default
  158. /// CellEditor</returns>
  159. public override string GetDefaultEditorName()
  160. {
  161. return null;
  162. }
  163. /// <summary>
  164. /// Gets the Column's default CellEditor
  165. /// </summary>
  166. /// <returns>The Column's default CellEditor</returns>
  167. public override ICellEditor CreateDefaultEditor()
  168. {
  169. return null;
  170. }
  171. #endregion
  172. #region Properties
  173. /// <summary>
  174. /// Gets or sets the size of the checkboxes
  175. /// </summary>
  176. [Category("Appearance"),
  177. Description("Specifies the size of the checkboxes")]
  178. public Size CheckSize
  179. {
  180. get
  181. {
  182. return this.checkSize;
  183. }
  184. set
  185. {
  186. if (value.Width < 0 || value.Height < 0)
  187. {
  188. value = new Size(13, 13);
  189. }
  190. if (this.checkSize != value)
  191. {
  192. this.checkSize = value;
  193. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.RendererChanged, null));
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// Specifies whether the CheckSize property should be serialized at
  199. /// design time
  200. /// </summary>
  201. /// <returns>true if the CheckSize property should be serialized,
  202. /// false otherwise</returns>
  203. private bool ShouldSerializeCheckSize()
  204. {
  205. return (this.checkSize.Width != 13 || this.checkSize.Height != 13);
  206. }
  207. /// <summary>
  208. /// Gets or sets whether any text contained in the Cell should be drawn
  209. /// </summary>
  210. [Category("Appearance"),
  211. DefaultValue(true),
  212. Description("Specifies whether any text contained in the Cell should be drawn")]
  213. public bool DrawText
  214. {
  215. get
  216. {
  217. return this.drawText;
  218. }
  219. set
  220. {
  221. if (this.drawText != value)
  222. {
  223. this.drawText = value;
  224. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.RendererChanged, null));
  225. }
  226. }
  227. }
  228. /// <summary>
  229. /// Gets or sets whether any text contained in the Cell should be drawn
  230. /// </summary>
  231. [Category("Appearance"),
  232. DefaultValue(CheckBoxColumnStyle.CheckBox),
  233. Description("Specifies the style of the checkboxes")]
  234. public CheckBoxColumnStyle CheckStyle
  235. {
  236. get
  237. {
  238. return this.checkStyle;
  239. }
  240. set
  241. {
  242. if (!Enum.IsDefined(typeof(CheckBoxColumnStyle), value))
  243. {
  244. throw new InvalidEnumArgumentException("value", (int) value, typeof(CheckBoxColumnStyle));
  245. }
  246. if (this.checkStyle != value)
  247. {
  248. this.checkStyle = value;
  249. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.RendererChanged, null));
  250. }
  251. }
  252. }
  253. /// <summary>
  254. /// Gets the Type of the Comparer used to compare the Column's Cells when
  255. /// the Column is sorting
  256. /// </summary>
  257. public override Type DefaultComparerType
  258. {
  259. get
  260. {
  261. return typeof(CheckBoxComparer);
  262. }
  263. }
  264. #endregion
  265. }
  266. }