ImageColumn.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 an Image
  42. /// </summary>
  43. [DesignTimeVisible(false),
  44. ToolboxItem(false)]
  45. public class ImageColumn : Column
  46. {
  47. #region Class Data
  48. /// <summary>
  49. /// Specifies whether any text contained in the Cell should be drawn
  50. /// </summary>
  51. private bool drawText;
  52. #endregion
  53. #region Constructor
  54. /// <summary>
  55. /// Creates a new ImageColumn with default values
  56. /// </summary>
  57. public ImageColumn() : base()
  58. {
  59. this.Init();
  60. }
  61. /// <summary>
  62. /// Creates a new ImageColumn with the specified header text
  63. /// </summary>
  64. /// <param name="text">The text displayed in the column's header</param>
  65. public ImageColumn(string text) : base(text)
  66. {
  67. this.Init();
  68. }
  69. /// <summary>
  70. /// Creates a new ImageColumn 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 ImageColumn(string text, int width) : base(text, width)
  75. {
  76. this.Init();
  77. }
  78. /// <summary>
  79. /// Creates a new ImageColumn 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 ImageColumn(string text, int width, bool visible) : base(text, width, visible)
  85. {
  86. this.Init();
  87. }
  88. /// <summary>
  89. /// Creates a new ImageColumn 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 ImageColumn(string text, Image image) : base(text, image)
  94. {
  95. this.Init();
  96. }
  97. /// <summary>
  98. /// Creates a new ImageColumn 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 ImageColumn(string text, Image image, int width) : base(text, image, width)
  104. {
  105. this.Init();
  106. }
  107. /// <summary>
  108. /// Creates a new ImageColumn with the specified header text, image, width
  109. /// and visibility
  110. /// </summary>
  111. /// <param name="text">The text displayed in the column's header</param>
  112. /// <param name="image">The image displayed on the column's header</param>
  113. /// <param name="width">The column's width</param>
  114. /// <param name="visible">Specifies whether the column is visible</param>
  115. public ImageColumn(string text, Image image, int width, bool visible) : base(text, image, width, visible)
  116. {
  117. this.Init();
  118. }
  119. /// <summary>
  120. /// Initializes the ImageColumn with default values
  121. /// </summary>
  122. private void Init()
  123. {
  124. this.drawText = true;
  125. this.Editable = false;
  126. }
  127. #endregion
  128. #region Methods
  129. /// <summary>
  130. /// Gets a string that specifies the name of the Column's default CellRenderer
  131. /// </summary>
  132. /// <returns>A string that specifies the name of the Column's default
  133. /// CellRenderer</returns>
  134. public override string GetDefaultRendererName()
  135. {
  136. return "IMAGE";
  137. }
  138. /// <summary>
  139. /// Gets the Column's default CellRenderer
  140. /// </summary>
  141. /// <returns>The Column's default CellRenderer</returns>
  142. public override ICellRenderer CreateDefaultRenderer()
  143. {
  144. return new ImageCellRenderer();
  145. }
  146. /// <summary>
  147. /// Gets a string that specifies the name of the Column's default CellEditor
  148. /// </summary>
  149. /// <returns>A string that specifies the name of the Column's default
  150. /// CellEditor</returns>
  151. public override string GetDefaultEditorName()
  152. {
  153. return null;
  154. }
  155. /// <summary>
  156. /// Gets the Column's default CellEditor
  157. /// </summary>
  158. /// <returns>The Column's default CellEditor</returns>
  159. public override ICellEditor CreateDefaultEditor()
  160. {
  161. return null;
  162. }
  163. #endregion
  164. #region Properties
  165. /// <summary>
  166. /// Gets or sets whether any text contained in the Column's Cells should be drawn
  167. /// </summary>
  168. [Category("Appearance"),
  169. DefaultValue(true),
  170. Description("Determines whether any text contained in the Column's Cells should be drawn")]
  171. public bool DrawText
  172. {
  173. get
  174. {
  175. return this.drawText;
  176. }
  177. set
  178. {
  179. if (this.drawText != value)
  180. {
  181. this.drawText = value;
  182. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.RendererChanged, null));
  183. }
  184. }
  185. }
  186. /// <summary>
  187. /// Gets the Type of the Comparer used to compare the Column's Cells when
  188. /// the Column is sorting
  189. /// </summary>
  190. public override Type DefaultComparerType
  191. {
  192. get
  193. {
  194. return typeof(ImageComparer);
  195. }
  196. }
  197. /// <summary>
  198. /// Gets or sets a value indicating whether the Column's Cells contents
  199. /// are able to be edited
  200. /// </summary>
  201. [Category("Appearance"),
  202. DefaultValue(false),
  203. Description("Controls whether the column's cell contents are able to be changed by the user")]
  204. public new bool Editable
  205. {
  206. get
  207. {
  208. return base.Editable;
  209. }
  210. set
  211. {
  212. base.Editable = value;
  213. }
  214. }
  215. #endregion
  216. }
  217. }