Column.cs 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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 System.Windows.Forms;
  34. using XPTable.Editors;
  35. using XPTable.Events;
  36. using XPTable.Renderers;
  37. namespace XPTable.Models
  38. {
  39. /// <summary>
  40. /// Summary description for Column.
  41. /// </summary>
  42. [DesignTimeVisible(false),
  43. ToolboxItem(false)]
  44. public abstract class Column : Component
  45. {
  46. #region Event Handlers
  47. /// <summary>
  48. /// Occurs when one of the Column's properties changes
  49. /// </summary>
  50. public event ColumnEventHandler PropertyChanged;
  51. #endregion
  52. #region Class Data
  53. // Column state flags
  54. private readonly static int STATE_EDITABLE = 1;
  55. private readonly static int STATE_ENABLED = 2;
  56. private readonly static int STATE_VISIBLE = 4;
  57. private readonly static int STATE_SELECTABLE = 8;
  58. private readonly static int STATE_SORTABLE = 16;
  59. /// <summary>
  60. /// The amount of space on each side of the Column that can
  61. /// be used as a resizing handle
  62. /// </summary>
  63. public static readonly int ResizePadding = 8;
  64. /// <summary>
  65. /// The default width of a Column
  66. /// </summary>
  67. public static readonly int DefaultWidth = 75;
  68. /// <summary>
  69. /// The maximum width of a Column
  70. /// </summary>
  71. public static readonly int MaximumWidth = 1024;
  72. /// <summary>
  73. /// The minimum width of a Column
  74. /// </summary>
  75. public static readonly int MinimumWidth = ResizePadding * 2;
  76. /// <summary>
  77. /// Contains the current state of the the Column
  78. /// </summary>
  79. public byte state;
  80. /// <summary>
  81. /// The text displayed in the Column's header
  82. /// </summary>
  83. private string text;
  84. /// <summary>
  85. /// A string that specifies how a Column's Cell contents are formatted
  86. /// </summary>
  87. private string format;
  88. /// <summary>
  89. /// The alignment of the text displayed in the Column's Cells
  90. /// </summary>
  91. private ColumnAlignment alignment;
  92. /// <summary>
  93. /// The width of the Column
  94. /// </summary>
  95. private int width;
  96. /// <summary>
  97. /// The Image displayed on the Column's header
  98. /// </summary>
  99. private Image image;
  100. /// <summary>
  101. /// Specifies whether the Image displayed on the Column's header should
  102. /// be draw on the right hand side of the Column
  103. /// </summary>
  104. private bool imageOnRight;
  105. /// <summary>
  106. /// The current state of the Column
  107. /// </summary>
  108. private ColumnState columnState;
  109. /// <summary>
  110. /// The text displayed when a ToolTip is shown for the Column's header
  111. /// </summary>
  112. private string tooltipText;
  113. /// <summary>
  114. /// The ColumnModel that the Column belongs to
  115. /// </summary>
  116. private ColumnModel columnModel;
  117. /// <summary>
  118. /// The x-coordinate of the column's left edge in pixels
  119. /// </summary>
  120. private int x;
  121. /// <summary>
  122. /// The current SortOrder of the Column
  123. /// </summary>
  124. private SortOrder sortOrder;
  125. /// <summary>
  126. /// The CellRenderer used to draw the Column's Cells
  127. /// </summary>
  128. private ICellRenderer renderer;
  129. /// <summary>
  130. /// The CellEditor used to edit the Column's Cells
  131. /// </summary>
  132. private ICellEditor editor;
  133. /// <summary>
  134. /// The Type of the IComparer used to compare the Column's Cells
  135. /// </summary>
  136. private Type comparer;
  137. #endregion
  138. #region Constructor
  139. /// <summary>
  140. /// Creates a new Column with default values
  141. /// </summary>
  142. public Column() : base()
  143. {
  144. this.Init();
  145. }
  146. /// <summary>
  147. /// Creates a new Column with the specified header text
  148. /// </summary>
  149. /// <param name="text">The text displayed in the column's header</param>
  150. public Column(string text) : base()
  151. {
  152. this.Init();
  153. this.text = text;
  154. }
  155. /// <summary>
  156. /// Creates a new Column with the specified header text and width
  157. /// </summary>
  158. /// <param name="text">The text displayed in the column's header</param>
  159. /// <param name="width">The column's width</param>
  160. public Column(string text, int width) : base()
  161. {
  162. this.Init();
  163. this.text = text;
  164. this.width = width;
  165. }
  166. /// <summary>
  167. /// Creates a new Column with the specified header text, width and visibility
  168. /// </summary>
  169. /// <param name="text">The text displayed in the column's header</param>
  170. /// <param name="width">The column's width</param>
  171. /// <param name="visible">Specifies whether the column is visible</param>
  172. public Column(string text, int width, bool visible) : base()
  173. {
  174. this.Init();
  175. this.text = text;
  176. this.width = width;
  177. this.Visible = visible;
  178. }
  179. /// <summary>
  180. /// Creates a new Column with the specified header text and image
  181. /// </summary>
  182. /// <param name="text">The text displayed in the column's header</param>
  183. /// <param name="image">The image displayed on the column's header</param>
  184. public Column(string text, Image image) : base()
  185. {
  186. this.Init();
  187. this.text = text;
  188. this.image = image;
  189. }
  190. /// <summary>
  191. /// Creates a new Column with the specified header text, image and width
  192. /// </summary>
  193. /// <param name="text">The text displayed in the column's header</param>
  194. /// <param name="image">The image displayed on the column's header</param>
  195. /// <param name="width">The column's width</param>
  196. public Column(string text, Image image, int width) : base()
  197. {
  198. this.Init();
  199. this.text = text;
  200. this.image = image;
  201. this.width = width;
  202. }
  203. /// <summary>
  204. /// Creates a new Column with the specified header text, image, width and visibility
  205. /// </summary>
  206. /// <param name="text">The text displayed in the column's header</param>
  207. /// <param name="image">The image displayed on the column's header</param>
  208. /// <param name="width">The column's width</param>
  209. /// <param name="visible">Specifies whether the column is visible</param>
  210. public Column(string text, Image image, int width, bool visible) : base()
  211. {
  212. this.Init();
  213. this.text = text;
  214. this.image = image;
  215. this.width = width;
  216. this.Visible = visible;
  217. }
  218. /// <summary>
  219. /// Initialise default values
  220. /// </summary>
  221. private void Init()
  222. {
  223. this.text = null;
  224. this.width = Column.DefaultWidth;
  225. this.columnState = ColumnState.Normal;
  226. this.alignment = ColumnAlignment.Left;
  227. this.image = null;
  228. this.imageOnRight = false;
  229. this.columnModel = null;
  230. this.x = 0;
  231. this.tooltipText = null;
  232. this.format = "";
  233. this.sortOrder = SortOrder.None;
  234. this.renderer = null;
  235. this.editor = null;
  236. this.comparer = null;
  237. this.state = (byte) (STATE_ENABLED | STATE_EDITABLE | STATE_VISIBLE | STATE_SELECTABLE | STATE_SORTABLE);
  238. }
  239. #endregion
  240. #region Methods
  241. /// <summary>
  242. /// Gets a string that specifies the name of the Column's default CellRenderer
  243. /// </summary>
  244. /// <returns>A string that specifies the name of the Column's default
  245. /// CellRenderer</returns>
  246. public abstract string GetDefaultRendererName();
  247. /// <summary>
  248. /// Gets the Column's default CellRenderer
  249. /// </summary>
  250. /// <returns>The Column's default CellRenderer</returns>
  251. public abstract ICellRenderer CreateDefaultRenderer();
  252. /// <summary>
  253. /// Gets a string that specifies the name of the Column's default CellEditor
  254. /// </summary>
  255. /// <returns>A string that specifies the name of the Column's default
  256. /// CellEditor</returns>
  257. public abstract string GetDefaultEditorName();
  258. /// <summary>
  259. /// Gets the Column's default CellEditor
  260. /// </summary>
  261. /// <returns>The Column's default CellEditor</returns>
  262. public abstract ICellEditor CreateDefaultEditor();
  263. /// <summary>
  264. /// Returns the state represented by the specified state flag
  265. /// </summary>
  266. /// <param name="flag">A flag that represents the state to return</param>
  267. /// <returns>The state represented by the specified state flag</returns>
  268. internal bool GetState(int flag)
  269. {
  270. return ((this.state & flag) != 0);
  271. }
  272. /// <summary>
  273. /// Sets the state represented by the specified state flag to the specified value
  274. /// </summary>
  275. /// <param name="flag">A flag that represents the state to be set</param>
  276. /// <param name="value">The new value of the state</param>
  277. internal void SetState(int flag, bool value)
  278. {
  279. this.state = (byte) (value ? (this.state | flag) : (this.state & ~flag));
  280. }
  281. #endregion
  282. #region Properties
  283. /// <summary>
  284. /// Gets or sets the text displayed on the Column header
  285. /// </summary>
  286. [Category("Appearance"),
  287. DefaultValue(null),
  288. Description("The text displayed in the column's header.")]
  289. public string Text
  290. {
  291. get
  292. {
  293. return this.text;
  294. }
  295. set
  296. {
  297. if (value == null)
  298. {
  299. value = "";
  300. }
  301. if (!value.Equals(this.text))
  302. {
  303. string oldText = this.text;
  304. this.text = value;
  305. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.TextChanged, oldText));
  306. }
  307. }
  308. }
  309. /// <summary>
  310. /// Gets or sets the string that specifies how a Column's Cell contents
  311. /// are formatted
  312. /// </summary>
  313. [Category("Appearance"),
  314. DefaultValue(""),
  315. Description("A string that specifies how a column's cell contents are formatted.")]
  316. public string Format
  317. {
  318. get
  319. {
  320. return this.format;
  321. }
  322. set
  323. {
  324. if (value == null)
  325. {
  326. value = "";
  327. }
  328. if (!value.Equals(this.format))
  329. {
  330. string oldFormat = this.format;
  331. this.format = value;
  332. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.FormatChanged, oldFormat));
  333. }
  334. }
  335. }
  336. /// <summary>
  337. /// Gets or sets the horizontal alignment of the Column's Cell contents
  338. /// </summary>
  339. [Category("Appearance"),
  340. DefaultValue(ColumnAlignment.Left),
  341. Description("The horizontal alignment of the column's cell contents.")]
  342. public virtual ColumnAlignment Alignment
  343. {
  344. get
  345. {
  346. return this.alignment;
  347. }
  348. set
  349. {
  350. if (!Enum.IsDefined(typeof(ColumnAlignment), value))
  351. {
  352. throw new InvalidEnumArgumentException("value", (int) value, typeof(ColumnAlignment));
  353. }
  354. if (this.alignment != value)
  355. {
  356. ColumnAlignment oldAlignment = this.alignment;
  357. this.alignment = value;
  358. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.AlignmentChanged, oldAlignment));
  359. }
  360. }
  361. }
  362. /// <summary>
  363. /// Gets or sets the width of the Column
  364. /// </summary>
  365. [Category("Appearance"),
  366. Description("The width of the column.")]
  367. public int Width
  368. {
  369. get
  370. {
  371. return this.width;
  372. }
  373. set
  374. {
  375. if (this.width != value)
  376. {
  377. int oldWidth = this.Width;
  378. // Set the width, and check min & max
  379. this.width = Math.Min(Math.Max(value, MinimumWidth), MaximumWidth);
  380. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.WidthChanged, oldWidth));
  381. }
  382. }
  383. }
  384. /// <summary>
  385. /// Specifies whether the Width property should be serialized at
  386. /// design time
  387. /// </summary>
  388. /// <returns>true if the Width property should be serialized,
  389. /// false otherwise</returns>
  390. private bool ShouldSerializeWidth()
  391. {
  392. return this.Width != Column.DefaultWidth;
  393. }
  394. /// <summary>
  395. /// Gets or sets the Image displayed in the Column's header
  396. /// </summary>
  397. [Category("Appearance"),
  398. DefaultValue(null),
  399. Description("Ihe image displayed in the column's header")]
  400. public Image Image
  401. {
  402. get
  403. {
  404. return this.image;
  405. }
  406. set
  407. {
  408. if (this.image != value)
  409. {
  410. Image oldImage = this.Image;
  411. this.image = value;
  412. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.ImageChanged, oldImage));
  413. }
  414. }
  415. }
  416. /// <summary>
  417. /// Gets or sets whether the Image displayed on the Column's header should
  418. /// be draw on the right hand side of the Column
  419. /// </summary>
  420. [Category("Appearance"),
  421. DefaultValue(false),
  422. Description("Specifies whether the image displayed on the column's header should be drawn on the right hand side of the column")]
  423. public bool ImageOnRight
  424. {
  425. get
  426. {
  427. return this.imageOnRight;
  428. }
  429. set
  430. {
  431. if (this.imageOnRight != value)
  432. {
  433. this.imageOnRight = value;
  434. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.ImageChanged, null));
  435. }
  436. }
  437. }
  438. /// <summary>
  439. /// Gets the state of the Column
  440. /// </summary>
  441. [Browsable(false),
  442. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  443. public ColumnState ColumnState
  444. {
  445. get
  446. {
  447. return this.columnState;
  448. }
  449. }
  450. /// <summary>
  451. /// Gets or sets the state of the Column
  452. /// </summary>
  453. internal ColumnState InternalColumnState
  454. {
  455. get
  456. {
  457. return this.ColumnState;
  458. }
  459. set
  460. {
  461. if (!Enum.IsDefined(typeof(ColumnState), value))
  462. {
  463. throw new InvalidEnumArgumentException("value", (int) value, typeof(ColumnState));
  464. }
  465. if (this.columnState != value)
  466. {
  467. ColumnState oldState = this.columnState;
  468. this.columnState = value;
  469. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.StateChanged, oldState));
  470. }
  471. }
  472. }
  473. /// <summary>
  474. /// Gets or sets the whether the Column is displayed
  475. /// </summary>
  476. [Category("Appearance"),
  477. DefaultValue(true),
  478. Description("Determines whether the column is visible or hidden.")]
  479. public bool Visible
  480. {
  481. get
  482. {
  483. return this.GetState(STATE_VISIBLE);
  484. }
  485. set
  486. {
  487. bool visible = this.Visible;
  488. this.SetState(STATE_VISIBLE, value);
  489. if (visible != value)
  490. {
  491. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.VisibleChanged, visible));
  492. }
  493. }
  494. }
  495. /// <summary>
  496. /// Gets or sets whether the Column is able to be sorted
  497. /// </summary>
  498. [Category("Appearance"),
  499. DefaultValue(true),
  500. Description("Determines whether the column is able to be sorted.")]
  501. public virtual bool Sortable
  502. {
  503. get
  504. {
  505. return this.GetState(STATE_SORTABLE);
  506. }
  507. set
  508. {
  509. bool sortable = this.Sortable;
  510. this.SetState(STATE_SORTABLE, value);
  511. if (sortable != value)
  512. {
  513. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.SortableChanged, sortable));
  514. }
  515. }
  516. }
  517. /// <summary>
  518. /// Gets or sets the user specified ICellRenderer that is used to draw the
  519. /// Column's Cells
  520. /// </summary>
  521. [Browsable(false),
  522. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  523. public ICellRenderer Renderer
  524. {
  525. get
  526. {
  527. return this.renderer;
  528. }
  529. set
  530. {
  531. if (this.renderer != value)
  532. {
  533. this.renderer = value;
  534. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.RendererChanged, null));
  535. }
  536. }
  537. }
  538. /// <summary>
  539. /// Gets or sets the user specified ICellEditor that is used to edit the
  540. /// Column's Cells
  541. /// </summary>
  542. [Browsable(false),
  543. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  544. public ICellEditor Editor
  545. {
  546. get
  547. {
  548. return this.editor;
  549. }
  550. set
  551. {
  552. if (this.editor != value)
  553. {
  554. this.editor = value;
  555. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.EditorChanged, null));
  556. }
  557. }
  558. }
  559. /// <summary>
  560. /// Gets or sets the user specified Comparer type that is used to edit the
  561. /// Column's Cells
  562. /// </summary>
  563. [Browsable(false),
  564. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  565. public Type Comparer
  566. {
  567. get
  568. {
  569. return this.comparer;
  570. }
  571. set
  572. {
  573. if (this.comparer != value)
  574. {
  575. this.comparer = value;
  576. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.ComparerChanged, null));
  577. }
  578. }
  579. }
  580. /// <summary>
  581. /// Gets the Type of the default Comparer used to compare the Column's Cells when
  582. /// the Column is sorting
  583. /// </summary>
  584. [Browsable(false)]
  585. public abstract Type DefaultComparerType
  586. {
  587. get;
  588. }
  589. /// <summary>
  590. /// Gets the current SortOrder of the Column
  591. /// </summary>
  592. [Browsable(false)]
  593. public SortOrder SortOrder
  594. {
  595. get
  596. {
  597. return this.sortOrder;
  598. }
  599. }
  600. /// <summary>
  601. /// Gets or sets the current SortOrder of the Column
  602. /// </summary>
  603. internal SortOrder InternalSortOrder
  604. {
  605. get
  606. {
  607. return this.SortOrder;
  608. }
  609. set
  610. {
  611. if (!Enum.IsDefined(typeof(SortOrder), value))
  612. {
  613. throw new InvalidEnumArgumentException("value", (int) value, typeof(SortOrder));
  614. }
  615. if (this.sortOrder != value)
  616. {
  617. SortOrder oldOrder = this.sortOrder;
  618. this.sortOrder = value;
  619. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.SortOrderChanged, oldOrder));
  620. }
  621. }
  622. }
  623. /// <summary>
  624. /// Gets or sets a value indicating whether the Column's Cells contents
  625. /// are able to be edited
  626. /// </summary>
  627. [Category("Appearance"),
  628. Description("Controls whether the column's cell contents are able to be changed by the user")]
  629. public virtual bool Editable
  630. {
  631. get
  632. {
  633. if (!this.GetState(STATE_EDITABLE))
  634. {
  635. return false;
  636. }
  637. return this.Visible && this.Enabled;
  638. }
  639. set
  640. {
  641. bool editable = this.GetState(STATE_EDITABLE);
  642. this.SetState(STATE_EDITABLE, value);
  643. if (editable != value)
  644. {
  645. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.EditableChanged, editable));
  646. }
  647. }
  648. }
  649. /// <summary>
  650. /// Specifies whether the Editable property should be serialized at
  651. /// design time
  652. /// </summary>
  653. /// <returns>true if the Editable property should be serialized,
  654. /// false otherwise</returns>
  655. private bool ShouldSerializeEditable()
  656. {
  657. return !this.GetState(STATE_EDITABLE);
  658. }
  659. /// <summary>
  660. /// Gets or sets a value indicating whether the Column's Cells can respond to
  661. /// user interaction
  662. /// </summary>
  663. [Category("Appearance"),
  664. Description("Indicates whether the column's cells can respond to user interaction")]
  665. public bool Enabled
  666. {
  667. get
  668. {
  669. if (!this.GetState(STATE_ENABLED))
  670. {
  671. return false;
  672. }
  673. if (this.ColumnModel == null)
  674. {
  675. return true;
  676. }
  677. return this.ColumnModel.Enabled;
  678. }
  679. set
  680. {
  681. bool enabled = this.GetState(STATE_ENABLED);
  682. this.SetState(STATE_ENABLED, value);
  683. if (enabled != value)
  684. {
  685. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.EnabledChanged, enabled));
  686. }
  687. }
  688. }
  689. /// <summary>
  690. /// Specifies whether the Enabled property should be serialized at
  691. /// design time
  692. /// </summary>
  693. /// <returns>true if the Enabled property should be serialized,
  694. /// false otherwise</returns>
  695. private bool ShouldSerializeEnabled()
  696. {
  697. return !this.GetState(STATE_ENABLED);
  698. }
  699. /// <summary>
  700. /// Gets or sets a value indicating whether the Column's Cells can be selected
  701. /// </summary>
  702. [Category("Appearance"),
  703. DefaultValue(true),
  704. Description("Indicates whether the column's cells can be selected")]
  705. public virtual bool Selectable
  706. {
  707. get
  708. {
  709. return this.GetState(STATE_SELECTABLE);
  710. }
  711. set
  712. {
  713. bool selectable = this.Selectable;
  714. this.SetState(STATE_SELECTABLE, value);
  715. if (selectable != value)
  716. {
  717. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.SelectableChanged, selectable));
  718. }
  719. }
  720. }
  721. /// <summary>
  722. /// Gets or sets the ToolTip text associated with the Column
  723. /// </summary>
  724. [Category("Appearance"),
  725. DefaultValue(null),
  726. Description("The ToolTip text associated with the Column")]
  727. public string ToolTipText
  728. {
  729. get
  730. {
  731. return this.tooltipText;
  732. }
  733. set
  734. {
  735. if (value == null)
  736. {
  737. value = "";
  738. }
  739. if (!value.Equals(this.tooltipText))
  740. {
  741. string oldTip = this.tooltipText;
  742. this.tooltipText = value;
  743. this.OnPropertyChanged(new ColumnEventArgs(this, ColumnEventType.ToolTipTextChanged, oldTip));
  744. }
  745. }
  746. }
  747. /// <summary>
  748. /// Gets the x-coordinate of the column's left edge in pixels
  749. /// </summary>
  750. internal int X
  751. {
  752. get
  753. {
  754. return this.x;
  755. }
  756. set
  757. {
  758. this.x = value;
  759. }
  760. }
  761. /// <summary>
  762. /// Gets the x-coordinate of the column's left edge in pixels
  763. /// </summary>
  764. [Browsable(false)]
  765. public int Left
  766. {
  767. get
  768. {
  769. return this.X;
  770. }
  771. }
  772. /// <summary>
  773. /// Gets the x-coordinate of the column's right edge in pixels
  774. /// </summary>
  775. [Browsable(false)]
  776. public int Right
  777. {
  778. get
  779. {
  780. return this.Left + this.Width;
  781. }
  782. }
  783. /// <summary>
  784. /// Gets or sets the ColumnModel the Column belongs to
  785. /// </summary>
  786. protected internal ColumnModel ColumnModel
  787. {
  788. get
  789. {
  790. return this.columnModel;
  791. }
  792. set
  793. {
  794. this.columnModel = value;
  795. }
  796. }
  797. /// <summary>
  798. /// Gets the ColumnModel the Column belongs to. This member is not
  799. /// intended to be used directly from your code
  800. /// </summary>
  801. [Browsable(false)]
  802. public ColumnModel Parent
  803. {
  804. get
  805. {
  806. return this.ColumnModel;
  807. }
  808. }
  809. /// <summary>
  810. /// Gets whether the Column is able to raise events
  811. /// </summary>
  812. protected bool CanRaiseEvents
  813. {
  814. get
  815. {
  816. // check if the ColumnModel that the Colum belongs to is able to
  817. // raise events (if it can't, the Colum shouldn't raise events either)
  818. if (this.ColumnModel != null)
  819. {
  820. return this.ColumnModel.CanRaiseEvents;
  821. }
  822. return true;
  823. }
  824. }
  825. #endregion
  826. #region Events
  827. /// <summary>
  828. /// Raises the PropertyChanged event
  829. /// </summary>
  830. /// <param name="e">A ColumnEventArgs that contains the event data</param>
  831. protected virtual void OnPropertyChanged(ColumnEventArgs e)
  832. {
  833. if (this.ColumnModel != null)
  834. {
  835. e.SetIndex(this.ColumnModel.Columns.IndexOf(this));
  836. }
  837. if (this.CanRaiseEvents)
  838. {
  839. if (this.ColumnModel != null)
  840. {
  841. this.ColumnModel.OnColumnPropertyChanged(e);
  842. }
  843. if (PropertyChanged != null)
  844. {
  845. PropertyChanged(this, e);
  846. }
  847. }
  848. }
  849. #endregion
  850. }
  851. }