ColumnModel.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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.Collections;
  32. using System.ComponentModel;
  33. using System.Drawing;
  34. using XPTable.Editors;
  35. using XPTable.Events;
  36. using XPTable.Models.Design;
  37. using XPTable.Renderers;
  38. namespace XPTable.Models
  39. {
  40. /// <summary>
  41. /// Summary description for ColumnModel.
  42. /// </summary>
  43. [DesignTimeVisible(true),
  44. ToolboxItem(true),
  45. ToolboxBitmap(typeof(ColumnModel))]
  46. public class ColumnModel : Component
  47. {
  48. #region EventHandlers
  49. /// <summary>
  50. /// Occurs when a Column has been added to the ColumnModel
  51. /// </summary>
  52. public event ColumnModelEventHandler ColumnAdded;
  53. /// <summary>
  54. /// Occurs when a Column is removed from the ColumnModel
  55. /// </summary>
  56. public event ColumnModelEventHandler ColumnRemoved;
  57. /// <summary>
  58. /// Occurs when the value of the HeaderHeight property changes
  59. /// </summary>
  60. public event EventHandler HeaderHeightChanged;
  61. #endregion
  62. #region Class Data
  63. /// <summary>
  64. /// The default height of a column header
  65. /// </summary>
  66. public static readonly int DefaultHeaderHeight = 20;
  67. /// <summary>
  68. /// The minimum height of a column header
  69. /// </summary>
  70. public static readonly int MinimumHeaderHeight = 16;
  71. /// <summary>
  72. /// The maximum height of a column header
  73. /// </summary>
  74. public static readonly int MaximumHeaderHeight = 128;
  75. /// <summary>
  76. /// The collection of Column's contained in the ColumnModel
  77. /// </summary>
  78. private ColumnCollection columns;
  79. /// <summary>
  80. /// The list of all default CellRenderers used by the Columns in the ColumnModel
  81. /// </summary>
  82. private Hashtable cellRenderers;
  83. /// <summary>
  84. /// The list of all default CellEditors used by the Columns in the ColumnModel
  85. /// </summary>
  86. private Hashtable cellEditors;
  87. /// <summary>
  88. /// The Table that the ColumnModel belongs to
  89. /// </summary>
  90. private Table table;
  91. /// <summary>
  92. /// The height of the column headers
  93. /// </summary>
  94. private int headerHeight;
  95. #endregion
  96. #region Constructor
  97. /// <summary>
  98. /// Initializes a new instance of the ColumnModel class with default settings
  99. /// </summary>
  100. public ColumnModel()
  101. {
  102. this.Init();
  103. }
  104. /// <summary>
  105. /// Initializes a new instance of the ColumnModel class with an array of strings
  106. /// representing TextColumns
  107. /// </summary>
  108. /// <param name="columns">An array of strings that represent the Columns of
  109. /// the ColumnModel</param>
  110. public ColumnModel(string[] columns)
  111. {
  112. if (columns == null)
  113. {
  114. throw new ArgumentNullException("columns", "string[] cannot be null");
  115. }
  116. this.Init();
  117. if (columns.Length > 0)
  118. {
  119. Column[] cols = new Column[columns.Length];
  120. for (int i=0; i<columns.Length; i++)
  121. {
  122. cols[i] = new TextColumn(columns[i]);
  123. }
  124. this.Columns.AddRange(cols);
  125. }
  126. }
  127. /// <summary>
  128. /// Initializes a new instance of the Row class with an array of Column objects
  129. /// </summary>
  130. /// <param name="columns">An array of Cell objects that represent the Columns
  131. /// of the ColumnModel</param>
  132. public ColumnModel(Column[] columns)
  133. {
  134. if (columns == null)
  135. {
  136. throw new ArgumentNullException("columns", "Column[] cannot be null");
  137. }
  138. this.Init();
  139. if (columns.Length > 0)
  140. {
  141. this.Columns.AddRange(columns);
  142. }
  143. }
  144. /// <summary>
  145. /// Initialise default settings
  146. /// </summary>
  147. private void Init()
  148. {
  149. this.columns = null;
  150. this.table = null;
  151. this.headerHeight = ColumnModel.DefaultHeaderHeight;
  152. this.cellRenderers = new Hashtable();
  153. this.SetCellRenderer("TEXT", new TextCellRenderer());
  154. this.cellEditors = new Hashtable();
  155. this.SetCellEditor("TEXT", new TextCellEditor());
  156. }
  157. #endregion
  158. #region Methods
  159. #region Coordinate Translation
  160. /// <summary>
  161. /// Returns the index of the Column that lies on the specified position
  162. /// </summary>
  163. /// <param name="xPosition">The x-coordinate to check</param>
  164. /// <returns>The index of the Column or -1 if no Column is found</returns>
  165. public int ColumnIndexAtX(int xPosition)
  166. {
  167. if (xPosition < 0 || xPosition > this.VisibleColumnsWidth)
  168. {
  169. return -1;
  170. }
  171. for (int i=0; i<this.Columns.Count; i++)
  172. {
  173. if (this.Columns[i].Visible && xPosition < this.Columns[i].Right)
  174. {
  175. return i;
  176. }
  177. }
  178. return -1;
  179. }
  180. /// <summary>
  181. /// Returns the Column that lies on the specified position
  182. /// </summary>
  183. /// <param name="xPosition">The x-coordinate to check</param>
  184. /// <returns>The Column that lies on the specified position,
  185. /// or null if not found</returns>
  186. public Column ColumnAtX(int xPosition)
  187. {
  188. if (xPosition < 0 || xPosition > this.VisibleColumnsWidth)
  189. {
  190. return null;
  191. }
  192. int index = this.ColumnIndexAtX(xPosition);
  193. if (index != -1)
  194. {
  195. return this.Columns[index];
  196. }
  197. return null;
  198. }
  199. /// <summary>
  200. /// Returns a rectangle that countains the header of the column
  201. /// at the specified index in the ColumnModel
  202. /// </summary>
  203. /// <param name="index">The index of the column</param>
  204. /// <returns>that countains the header of the specified column</returns>
  205. public Rectangle ColumnHeaderRect(int index)
  206. {
  207. // make sure the index is valid and the column is not hidden
  208. if (index < 0 || index >= this.Columns.Count || !this.Columns[index].Visible)
  209. {
  210. return Rectangle.Empty;
  211. }
  212. return new Rectangle(this.Columns[index].Left, 0, this.Columns[index].Width, this.HeaderHeight);
  213. }
  214. /// <summary>
  215. /// Returns a rectangle that countains the header of the specified column
  216. /// </summary>
  217. /// <param name="column">The column</param>
  218. /// <returns>A rectangle that countains the header of the specified column</returns>
  219. public Rectangle ColumnHeaderRect(Column column)
  220. {
  221. // check if we actually own the column
  222. int index = this.Columns.IndexOf(column);
  223. if (index == -1)
  224. {
  225. return Rectangle.Empty;
  226. }
  227. return this.ColumnHeaderRect(index);
  228. }
  229. #endregion
  230. #region Dispose
  231. /// <summary>
  232. /// Releases the unmanaged resources used by the ColumnModel and optionally
  233. /// releases the managed resources
  234. /// </summary>
  235. protected override void Dispose(bool disposing)
  236. {
  237. if (disposing)
  238. {
  239. }
  240. base.Dispose(disposing);
  241. }
  242. #endregion
  243. #region Editors
  244. /// <summary>
  245. /// Returns the ICellEditor that is associated with the specified name
  246. /// </summary>
  247. /// <param name="name">The name thst is associated with an ICellEditor</param>
  248. /// <returns>The ICellEditor that is associated with the specified name,
  249. /// or null if the name or ICellEditor do not exist</returns>
  250. public ICellEditor GetCellEditor(string name)
  251. {
  252. if (name == null || name.Length == 0)
  253. {
  254. return null;
  255. }
  256. name = name.ToUpper();
  257. if (!this.cellEditors.ContainsKey(name))
  258. {
  259. if (this.cellEditors.Count == 0)
  260. {
  261. this.SetCellEditor("TEXT", new TextCellEditor());
  262. }
  263. return null;
  264. }
  265. return (ICellEditor) this.cellEditors[name];
  266. }
  267. /// <summary>
  268. /// Gets the ICellEditor for the Column at the specified index in the
  269. /// ColumnModel
  270. /// </summary>
  271. /// <param name="column">The index of the Column in the ColumnModel for
  272. /// which an ICellEditor will be retrieved</param>
  273. /// <returns>The ICellEditor for the Column at the specified index, or
  274. /// null if the editor does not exist</returns>
  275. public ICellEditor GetCellEditor(int column)
  276. {
  277. if (column < 0 || column >= this.Columns.Count)
  278. {
  279. return null;
  280. }
  281. //
  282. if (this.Columns[column].Editor != null)
  283. {
  284. return this.Columns[column].Editor;
  285. }
  286. return this.GetCellEditor(this.Columns[column].GetDefaultEditorName());
  287. }
  288. /// <summary>
  289. /// Associates the specified ICellRenderer with the specified name
  290. /// </summary>
  291. /// <param name="name">The name to be associated with the specified ICellEditor</param>
  292. /// <param name="editor">The ICellEditor to be added to the ColumnModel</param>
  293. public void SetCellEditor(string name, ICellEditor editor)
  294. {
  295. if (name == null || name.Length == 0 || editor == null)
  296. {
  297. return;
  298. }
  299. name = name.ToUpper();
  300. if (this.cellEditors.ContainsKey(name))
  301. {
  302. this.cellEditors.Remove(name);
  303. this.cellEditors[name] = editor;
  304. }
  305. else
  306. {
  307. this.cellEditors.Add(name, editor);
  308. }
  309. }
  310. /// <summary>
  311. /// Gets whether the ColumnModel contains an ICellEditor with the
  312. /// specified name
  313. /// </summary>
  314. /// <param name="name">The name associated with the ICellEditor</param>
  315. /// <returns>true if the ColumnModel contains an ICellEditor with the
  316. /// specified name, false otherwise</returns>
  317. public bool ContainsCellEditor(string name)
  318. {
  319. if (name == null)
  320. {
  321. return false;
  322. }
  323. return this.cellEditors.ContainsKey(name);
  324. }
  325. /// <summary>
  326. /// Gets the number of ICellEditors contained in the ColumnModel
  327. /// </summary>
  328. internal int EditorCount
  329. {
  330. get
  331. {
  332. return this.cellEditors.Count;
  333. }
  334. }
  335. #endregion
  336. #region Renderers
  337. /// <summary>
  338. /// Returns the ICellRenderer that is associated with the specified name
  339. /// </summary>
  340. /// <param name="name">The name thst is associated with an ICellEditor</param>
  341. /// <returns>The ICellRenderer that is associated with the specified name,
  342. /// or null if the name or ICellRenderer do not exist</returns>
  343. public ICellRenderer GetCellRenderer(string name)
  344. {
  345. if (name == null)
  346. {
  347. name = "TEXT";
  348. }
  349. name = name.ToUpper();
  350. if (!this.cellRenderers.ContainsKey(name))
  351. {
  352. if (this.cellRenderers.Count == 0)
  353. {
  354. this.SetCellRenderer("TEXT", new TextCellRenderer());
  355. }
  356. return (ICellRenderer) this.cellRenderers["TEXT"];
  357. }
  358. return (ICellRenderer) this.cellRenderers[name];
  359. }
  360. /// <summary>
  361. /// Gets the ICellRenderer for the Column at the specified index in the
  362. /// ColumnModel
  363. /// </summary>
  364. /// <param name="column">The index of the Column in the ColumnModel for
  365. /// which an ICellRenderer will be retrieved</param>
  366. /// <returns>The ICellRenderer for the Column at the specified index, or
  367. /// null if the renderer does not exist</returns>
  368. public ICellRenderer GetCellRenderer(int column)
  369. {
  370. //
  371. if (column < 0 || column >= this.Columns.Count)
  372. {
  373. return null;
  374. }
  375. //
  376. if (this.Columns[column].Renderer != null)
  377. {
  378. return this.Columns[column].Renderer;
  379. }
  380. //
  381. return this.GetCellRenderer(this.Columns[column].GetDefaultRendererName());
  382. }
  383. /// <summary>
  384. /// Associates the specified ICellRenderer with the specified name
  385. /// </summary>
  386. /// <param name="name">The name to be associated with the specified ICellRenderer</param>
  387. /// <param name="renderer">The ICellRenderer to be added to the ColumnModel</param>
  388. public void SetCellRenderer(string name, ICellRenderer renderer)
  389. {
  390. if (name == null || renderer == null)
  391. {
  392. return;
  393. }
  394. name = name.ToUpper();
  395. if (this.cellRenderers.ContainsKey(name))
  396. {
  397. this.cellRenderers.Remove(name);
  398. this.cellRenderers[name] = renderer;
  399. }
  400. else
  401. {
  402. this.cellRenderers.Add(name, renderer);
  403. }
  404. }
  405. /// <summary>
  406. /// Gets whether the ColumnModel contains an ICellRenderer with the
  407. /// specified name
  408. /// </summary>
  409. /// <param name="name">The name associated with the ICellRenderer</param>
  410. /// <returns>true if the ColumnModel contains an ICellRenderer with the
  411. /// specified name, false otherwise</returns>
  412. public bool ContainsCellRenderer(string name)
  413. {
  414. if (name == null)
  415. {
  416. return false;
  417. }
  418. return this.cellRenderers.ContainsKey(name);
  419. }
  420. /// <summary>
  421. /// Gets the number of ICellRenderers contained in the ColumnModel
  422. /// </summary>
  423. internal int RendererCount
  424. {
  425. get
  426. {
  427. return this.cellRenderers.Count;
  428. }
  429. }
  430. #endregion
  431. #region Utility Methods
  432. /// <summary>
  433. /// Returns the index of the first visible Column that is to the
  434. /// left of the Column at the specified index in the ColumnModel
  435. /// </summary>
  436. /// <param name="index">The index of the Column for which the first
  437. /// visible Column that is to the left of the specified Column is to
  438. /// be found</param>
  439. /// <returns>the index of the first visible Column that is to the
  440. /// left of the Column at the specified index in the ColumnModel, or
  441. /// -1 if the Column at the specified index is the first visible column,
  442. /// or there are no Columns in the Column model</returns>
  443. public int PreviousVisibleColumn(int index)
  444. {
  445. if (this.Columns.Count == 0)
  446. {
  447. return -1;
  448. }
  449. if (index <= 0)
  450. {
  451. return -1;
  452. }
  453. if (index >= this.Columns.Count)
  454. {
  455. if (this.Columns[this.Columns.Count-1].Visible)
  456. {
  457. return this.Columns.Count - 1;
  458. }
  459. index = this.Columns.Count - 1;
  460. }
  461. for (int i=index; i>0; i--)
  462. {
  463. if (this.Columns[i-1].Visible)
  464. {
  465. return i - 1;
  466. }
  467. }
  468. return -1;
  469. }
  470. /// <summary>
  471. /// Returns the index of the first visible Column that is to the
  472. /// right of the Column at the specified index in the ColumnModel
  473. /// </summary>
  474. /// <param name="index">The index of the Column for which the first
  475. /// visible Column that is to the right of the specified Column is to
  476. /// be found</param>
  477. /// <returns>the index of the first visible Column that is to the
  478. /// right of the Column at the specified index in the ColumnModel, or
  479. /// -1 if the Column at the specified index is the last visible column,
  480. /// or there are no Columns in the Column model</returns>
  481. public int NextVisibleColumn(int index)
  482. {
  483. if (this.Columns.Count == 0)
  484. {
  485. return -1;
  486. }
  487. if (index >= this.Columns.Count - 1)
  488. {
  489. return -1;
  490. }
  491. for (int i=index; i<this.Columns.Count-1; i++)
  492. {
  493. if (this.Columns[i+1].Visible)
  494. {
  495. return i + 1;
  496. }
  497. }
  498. return -1;
  499. }
  500. #endregion
  501. #endregion
  502. #region Properties
  503. /// <summary>
  504. /// A ColumnCollection representing the collection of
  505. /// Columns contained within the ColumnModel
  506. /// </summary>
  507. [Category("Behavior"),
  508. Description("Column Collection"),
  509. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  510. Editor(typeof(ColumnCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
  511. public ColumnCollection Columns
  512. {
  513. get
  514. {
  515. if (this.columns == null)
  516. {
  517. this.columns = new ColumnCollection(this);
  518. }
  519. return this.columns;
  520. }
  521. }
  522. /// <summary>
  523. /// Gets or sets the height of the column headers
  524. /// </summary>
  525. [Category("Appearance"),
  526. Description("The height of the column headers")]
  527. public int HeaderHeight
  528. {
  529. get
  530. {
  531. return this.headerHeight;
  532. }
  533. set
  534. {
  535. if (value < ColumnModel.MinimumHeaderHeight)
  536. {
  537. value = ColumnModel.MinimumHeaderHeight;
  538. }
  539. else if (value > ColumnModel.MaximumHeaderHeight)
  540. {
  541. value = ColumnModel.MaximumHeaderHeight;
  542. }
  543. if (this.headerHeight != value)
  544. {
  545. this.headerHeight = value;
  546. this.OnHeaderHeightChanged(EventArgs.Empty);
  547. }
  548. }
  549. }
  550. /// <summary>
  551. /// Specifies whether the HeaderHeight property should be serialized at
  552. /// design time
  553. /// </summary>
  554. /// <returns>true if the HeaderHeight property should be serialized,
  555. /// false otherwise</returns>
  556. private bool ShouldSerializeHeaderHeight()
  557. {
  558. return this.headerHeight != ColumnModel.DefaultHeaderHeight;
  559. }
  560. /// <summary>
  561. /// Gets a rectangle that specifies the width and height of all the
  562. /// visible column headers in the model
  563. /// </summary>
  564. [Browsable(false)]
  565. public Rectangle HeaderRect
  566. {
  567. get
  568. {
  569. if (this.VisibleColumnCount == 0)
  570. {
  571. return Rectangle.Empty;
  572. }
  573. return new Rectangle(0, 0, this.VisibleColumnsWidth, this.HeaderHeight);
  574. }
  575. }
  576. /// <summary>
  577. /// Gets the total width of all the Columns in the model
  578. /// </summary>
  579. [Browsable(false)]
  580. public int TotalColumnWidth
  581. {
  582. get
  583. {
  584. return this.Columns.TotalColumnWidth;
  585. }
  586. }
  587. /// <summary>
  588. /// Gets the total width of all the visible Columns in the model
  589. /// </summary>
  590. [Browsable(false)]
  591. public int VisibleColumnsWidth
  592. {
  593. get
  594. {
  595. return this.Columns.VisibleColumnsWidth;
  596. }
  597. }
  598. /// <summary>
  599. /// Gets the index of the last Column that is not hidden
  600. /// </summary>
  601. [Browsable(false)]
  602. public int LastVisibleColumnIndex
  603. {
  604. get
  605. {
  606. return this.Columns.LastVisibleColumn;
  607. }
  608. }
  609. /// <summary>
  610. /// Gets the number of Columns in the ColumnModel that are visible
  611. /// </summary>
  612. [Browsable(false)]
  613. public int VisibleColumnCount
  614. {
  615. get
  616. {
  617. return this.Columns.VisibleColumnCount;
  618. }
  619. }
  620. /// <summary>
  621. /// Gets the Table the ColumnModel belongs to
  622. /// </summary>
  623. [Browsable(false)]
  624. public Table Table
  625. {
  626. get
  627. {
  628. return this.table;
  629. }
  630. }
  631. /// <summary>
  632. /// Gets or sets the Table the ColumnModel belongs to
  633. /// </summary>
  634. internal Table InternalTable
  635. {
  636. get
  637. {
  638. return this.table;
  639. }
  640. set
  641. {
  642. this.table = value;
  643. }
  644. }
  645. /// <summary>
  646. /// Gets whether the ColumnModel is able to raise events
  647. /// </summary>
  648. protected internal bool CanRaiseEvents
  649. {
  650. get
  651. {
  652. // check if the Table that the ColumModel belongs to is able to
  653. // raise events (if it can't, the ColumModel shouldn't raise
  654. // events either)
  655. if (this.Table != null)
  656. {
  657. return this.Table.CanRaiseEvents;
  658. }
  659. return true;
  660. }
  661. }
  662. /// <summary>
  663. /// Gets whether the ColumnModel is enabled
  664. /// </summary>
  665. internal bool Enabled
  666. {
  667. get
  668. {
  669. if (this.Table == null)
  670. {
  671. return true;
  672. }
  673. return this.Table.Enabled;
  674. }
  675. }
  676. #endregion
  677. #region Events
  678. /// <summary>
  679. /// Raises the ColumnAdded event
  680. /// </summary>
  681. /// <param name="e">A ColumnModelEventArgs that contains the event data</param>
  682. protected internal virtual void OnColumnAdded(ColumnModelEventArgs e)
  683. {
  684. e.Column.ColumnModel = this;
  685. if (!this.ContainsCellRenderer(e.Column.GetDefaultRendererName()))
  686. {
  687. this.SetCellRenderer(e.Column.GetDefaultRendererName(), e.Column.CreateDefaultRenderer());
  688. }
  689. if (!this.ContainsCellEditor(e.Column.GetDefaultEditorName()))
  690. {
  691. this.SetCellEditor(e.Column.GetDefaultEditorName(), e.Column.CreateDefaultEditor());
  692. }
  693. if (this.CanRaiseEvents)
  694. {
  695. if (this.Table != null)
  696. {
  697. this.Table.OnColumnAdded(e);
  698. }
  699. if (ColumnAdded != null)
  700. {
  701. ColumnAdded(this, e);
  702. }
  703. }
  704. }
  705. /// <summary>
  706. /// Raises the ColumnRemoved event
  707. /// </summary>
  708. /// <param name="e">A ColumnModelEventArgs that contains the event data</param>
  709. protected internal virtual void OnColumnRemoved(ColumnModelEventArgs e)
  710. {
  711. if (e.Column != null && e.Column.ColumnModel == this)
  712. {
  713. e.Column.ColumnModel = null;
  714. }
  715. if (this.CanRaiseEvents)
  716. {
  717. if (this.Table != null)
  718. {
  719. this.Table.OnColumnRemoved(e);
  720. }
  721. if (ColumnRemoved != null)
  722. {
  723. ColumnRemoved(this, e);
  724. }
  725. }
  726. }
  727. /// <summary>
  728. /// Raises the HeaderHeightChanged event
  729. /// </summary>
  730. /// <param name="e">An EventArgs that contains the event data</param>
  731. protected virtual void OnHeaderHeightChanged(EventArgs e)
  732. {
  733. if (this.CanRaiseEvents)
  734. {
  735. if (this.Table != null)
  736. {
  737. this.Table.OnHeaderHeightChanged(e);
  738. }
  739. if (HeaderHeightChanged != null)
  740. {
  741. HeaderHeightChanged(this, e);
  742. }
  743. }
  744. }
  745. /// <summary>
  746. /// Raises the ColumnPropertyChanged event
  747. /// </summary>
  748. /// <param name="e">A ColumnEventArgs that contains the event data</param>
  749. internal void OnColumnPropertyChanged(ColumnEventArgs e)
  750. {
  751. if (e.EventType == ColumnEventType.WidthChanged || e.EventType == ColumnEventType.VisibleChanged)
  752. {
  753. this.Columns.RecalcWidthCache();
  754. }
  755. if (this.CanRaiseEvents)
  756. {
  757. if (this.Table != null)
  758. {
  759. this.Table.OnColumnPropertyChanged(e);
  760. }
  761. }
  762. }
  763. #endregion
  764. }
  765. }