ButtonColumn.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 Button
  42. /// </summary>
  43. [DesignTimeVisible(false),
  44. ToolboxItem(false)]
  45. public class ButtonColumn : Column
  46. {
  47. #region Class Data
  48. /// <summary>
  49. /// Specifies the alignment of the Image displayed on the button
  50. /// </summary>
  51. private ContentAlignment imageAlignment;
  52. #endregion
  53. #region Constructor
  54. /// <summary>
  55. /// Creates a new ButtonColumn with default values
  56. /// </summary>
  57. public ButtonColumn() : base()
  58. {
  59. this.Init();
  60. }
  61. /// <summary>
  62. /// Creates a new ButtonColumn with the specified header text
  63. /// </summary>
  64. /// <param name="text">The text displayed in the column's header</param>
  65. public ButtonColumn(string text) : base(text)
  66. {
  67. this.Init();
  68. }
  69. /// <summary>
  70. /// Creates a new ButtonColumn with the specified header text and width
  71. /// </summary>
  72. /// <param name="text">The text displayed in the column's header</param>
  73. /// <param name="width">The column's width</param>
  74. public ButtonColumn(string text, int width) : base(text, width)
  75. {
  76. this.Init();
  77. }
  78. /// <summary>
  79. /// Creates a new ButtonColumn with the specified header text, width and visibility
  80. /// </summary>
  81. /// <param name="text">The text displayed in the column's header</param>
  82. /// <param name="width">The column's width</param>
  83. /// <param name="visible">Specifies whether the column is visible</param>
  84. public ButtonColumn(string text, int width, bool visible) : base(text, width, visible)
  85. {
  86. this.Init();
  87. }
  88. /// <summary>
  89. /// Creates a new ButtonColumn with the specified header text and image
  90. /// </summary>
  91. /// <param name="text">The text displayed in the column's header</param>
  92. /// <param name="image">The image displayed on the column's header</param>
  93. public ButtonColumn(string text, Image image) : base(text, image)
  94. {
  95. this.Init();
  96. }
  97. /// <summary>
  98. /// Creates a new ButtonColumn with the specified header text, image and width
  99. /// </summary>
  100. /// <param name="text">The text displayed in the column's header</param>
  101. /// <param name="image">The image displayed on the column's header</param>
  102. /// <param name="width">The column's width</param>
  103. public ButtonColumn(string text, Image image, int width) : base(text, image, width)
  104. {
  105. this.Init();
  106. }
  107. /// <summary>
  108. /// Creates a new ButtonColumn with the specified header text, image, width and visibility
  109. /// </summary>
  110. /// <param name="text">The text displayed in the column's header</param>
  111. /// <param name="image">The image displayed on the column's header</param>
  112. /// <param name="width">The column's width</param>
  113. /// <param name="visible">Specifies whether the column is visible</param>
  114. public ButtonColumn(string text, Image image, int width, bool visible) : base(text, image, width, visible)
  115. {
  116. this.Init();
  117. }
  118. /// <summary>
  119. /// Initializes the ButtonColumn with default values
  120. /// </summary>
  121. private void Init()
  122. {
  123. this.Alignment = ColumnAlignment.Center;
  124. this.imageAlignment = ContentAlignment.MiddleCenter;
  125. this.Editable = false;
  126. this.Selectable = false;
  127. }
  128. #endregion
  129. #region Methods
  130. /// <summary>
  131. /// Gets a string that specifies the name of the Column's default CellRenderer
  132. /// </summary>
  133. /// <returns>A string that specifies the name of the Column's default
  134. /// CellRenderer</returns>
  135. public override string GetDefaultRendererName()
  136. {
  137. return "BUTTON";
  138. }
  139. /// <summary>
  140. /// Gets the Column's default CellRenderer
  141. /// </summary>
  142. /// <returns>The Column's default CellRenderer</returns>
  143. public override ICellRenderer CreateDefaultRenderer()
  144. {
  145. return new ButtonCellRenderer();
  146. }
  147. /// <summary>
  148. /// Gets a string that specifies the name of the Column's default CellEditor
  149. /// </summary>
  150. /// <returns>A string that specifies the name of the Column's default
  151. /// CellEditor</returns>
  152. public override string GetDefaultEditorName()
  153. {
  154. return null;
  155. }
  156. /// <summary>
  157. /// Gets the Column's default CellEditor
  158. /// </summary>
  159. /// <returns>The Column's default CellEditor</returns>
  160. public override ICellEditor CreateDefaultEditor()
  161. {
  162. return null;
  163. }
  164. #endregion
  165. #region Properties
  166. /// <summary>
  167. /// Gets or sets the horizontal alignment of the Column's Cell contents
  168. /// </summary>
  169. [Category("Appearance"),
  170. DefaultValue(ColumnAlignment.Center),
  171. Description("The horizontal alignment of the column's cell contents.")]
  172. public override ColumnAlignment Alignment
  173. {
  174. get
  175. {
  176. return base.Alignment;
  177. }
  178. set
  179. {
  180. base.Alignment = value;
  181. }
  182. }
  183. /// <summary>
  184. /// Gets or sets the alignment of the Image displayed on the buttons
  185. /// </summary>
  186. [Category("Appearance"),
  187. DefaultValue(ContentAlignment.MiddleCenter),
  188. Description("The alignment of the Image displayed on the buttons")]
  189. public ContentAlignment ImageAlignment
  190. {
  191. get
  192. {
  193. return this.imageAlignment;
  194. }
  195. set
  196. {
  197. if (!Enum.IsDefined(typeof(ContentAlignment), value))
  198. {
  199. throw new InvalidEnumArgumentException("value", (int) value, typeof(ContentAlignment));
  200. }
  201. if (this.imageAlignment != value)
  202. {
  203. this.imageAlignment = value;
  204. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.RendererChanged, null));
  205. }
  206. }
  207. }
  208. /// <summary>
  209. /// Gets or sets a value indicating whether the Column's Cells contents
  210. /// are able to be edited
  211. /// </summary>
  212. [Category("Appearance"),
  213. DefaultValue(false),
  214. Description("Controls whether the column's cell contents are able to be changed by the user")]
  215. public override bool Editable
  216. {
  217. get
  218. {
  219. return base.Editable;
  220. }
  221. set
  222. {
  223. base.Editable = value;
  224. }
  225. }
  226. /// <summary>
  227. /// Gets or sets a value indicating whether the Column's Cells can be selected
  228. /// </summary>
  229. [Category("Appearance"),
  230. DefaultValue(false),
  231. Description("Indicates whether the column's cells can be selected")]
  232. public override bool Selectable
  233. {
  234. get
  235. {
  236. return base.Selectable;
  237. }
  238. set
  239. {
  240. base.Selectable = value;
  241. }
  242. }
  243. /// <summary>
  244. /// Gets the Type of the Comparer used to compare the Column's Cells when
  245. /// the Column is sorting
  246. /// </summary>
  247. public override Type DefaultComparerType
  248. {
  249. get
  250. {
  251. return typeof(TextComparer);
  252. }
  253. }
  254. #endregion
  255. }
  256. }