ListView.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Ravindra ([email protected])
  24. //
  25. // $Revision: 1.3 $
  26. // $Modtime: $
  27. // $Log: ListView.cs,v $
  28. // Revision 1.3 2004/10/15 15:03:39 ravindra
  29. // Implemented Paint method and fixed coding style.
  30. //
  31. // Revision 1.2 2004/10/02 11:32:01 ravindra
  32. // Added attributes.
  33. //
  34. // Revision 1.1 2004/09/30 13:24:25 ravindra
  35. // Initial implementation.
  36. //
  37. //
  38. // NOT COMPLETE
  39. //
  40. using System.Collections;
  41. using System.ComponentModel;
  42. using System.ComponentModel.Design;
  43. using System.Drawing;
  44. using System.Runtime.InteropServices;
  45. namespace System.Windows.Forms
  46. {
  47. [DefaultEvent ("SelectedIndexChanged")]
  48. [DefaultProperty ("Items")]
  49. [Designer ("System.Windows.Forms.Design.ListViewDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  50. public class ListView : Control
  51. {
  52. private ItemActivation activation = ItemActivation.Standard;
  53. private ListViewAlignment alignment = ListViewAlignment.Top;
  54. private bool allow_column_reorder = false;
  55. private bool auto_arrange = true;
  56. private BorderStyle border_style = BorderStyle.Fixed3D;
  57. private bool check_boxes = false;
  58. private CheckedIndexCollection checked_indices;
  59. private CheckedListViewItemCollection checked_items;
  60. private ColumnHeaderCollection columns;
  61. private ListViewItem focused_item;
  62. private bool full_row_select = false;
  63. private bool grid_lines = false;
  64. private ColumnHeaderStyle header_style = ColumnHeaderStyle.Clickable;
  65. private bool hide_selection = true;
  66. private bool hover_selection = false;
  67. private ListViewItemCollection items;
  68. private bool label_edit = false;
  69. private bool label_wrap = true;
  70. internal ImageList large_image_list;
  71. private IComparer item_sorter;
  72. private bool multiselect = true;
  73. private bool redraw = true;
  74. private bool scrollable = true;
  75. private SelectedIndexCollection selected_indices;
  76. private SelectedListViewItemCollection selected_items;
  77. internal ImageList small_image_list;
  78. private SortOrder sort_order = SortOrder.None;
  79. private ImageList state_image_list;
  80. private bool updating = false;
  81. private View view = View.LargeIcon;
  82. #region Events
  83. public event LabelEditEventHandler AfterLabelEdit;
  84. [Browsable (false)]
  85. [EditorBrowsable (EditorBrowsableState.Never)]
  86. public new event EventHandler BackgroundImageChanged;
  87. public event LabelEditEventHandler BeforeLabelEdit;
  88. public event ColumnClickEventHandler ColumnClick;
  89. public event EventHandler ItemActivate;
  90. public event ItemCheckEventHandler ItemCheck;
  91. public event ItemDragEventHandler ItemDrag;
  92. [Browsable (false)]
  93. [EditorBrowsable (EditorBrowsableState.Never)]
  94. public new event PaintEventHandler Paint;
  95. public event EventHandler SelectedIndexChanged;
  96. [Browsable (false)]
  97. [EditorBrowsable (EditorBrowsableState.Never)]
  98. public new event EventHandler TextChanged;
  99. #endregion // Events
  100. #region Public Constructors
  101. public ListView ()
  102. {
  103. background_color = SystemColors.Window;
  104. checked_indices = new CheckedIndexCollection (this);
  105. checked_items = new CheckedListViewItemCollection (this);
  106. columns = new ColumnHeaderCollection (this);
  107. foreground_color = SystemColors.WindowText;
  108. items = new ListViewItemCollection (this);
  109. selected_indices = new SelectedIndexCollection (this);
  110. selected_items = new SelectedListViewItemCollection (this);
  111. // event handlers
  112. base.Paint += new PaintEventHandler (ListView_Paint);
  113. }
  114. #endregion // Public Constructors
  115. #region Protected Properties
  116. protected override CreateParams CreateParams {
  117. get { return base.CreateParams; }
  118. }
  119. protected override Size DefaultSize {
  120. get { return ThemeEngine.Current.ListViewDefaultSize; }
  121. }
  122. #endregion // Protected Properties
  123. #region Public Instance Properties
  124. [DefaultValue (ItemActivation.Standard)]
  125. public ItemActivation Activation {
  126. get { return activation; }
  127. set { activation = value; }
  128. }
  129. [DefaultValue (ListViewAlignment.Top)]
  130. [Localizable (true)]
  131. public ListViewAlignment Alignment {
  132. get { return alignment; }
  133. set { alignment = value; }
  134. }
  135. [DefaultValue (false)]
  136. public bool AllowColumnReorder {
  137. get { return allow_column_reorder; }
  138. set { allow_column_reorder = value; }
  139. }
  140. [DefaultValue (true)]
  141. public bool AutoArrange {
  142. get { return auto_arrange; }
  143. set { auto_arrange = value; }
  144. }
  145. public override Color BackColor {
  146. get { return base.BackColor; }
  147. set { base.BackColor = value; }
  148. }
  149. [Browsable (false)]
  150. [EditorBrowsable (EditorBrowsableState.Never)]
  151. public override Image BackgroundImage {
  152. get { return background_image; }
  153. set {
  154. if (value == background_image)
  155. return;
  156. background_image = value;
  157. if (BackgroundImageChanged != null)
  158. BackgroundImageChanged (this, new EventArgs ());
  159. }
  160. }
  161. [DefaultValue (BorderStyle.Fixed3D)]
  162. [DispId (-504)]
  163. public BorderStyle BorderStyle {
  164. get { return border_style; }
  165. set { border_style = value; }
  166. }
  167. [DefaultValue (false)]
  168. public bool CheckBoxes {
  169. get { return check_boxes; }
  170. set { check_boxes = value; }
  171. }
  172. [Browsable (false)]
  173. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  174. public CheckedIndexCollection CheckedIndices {
  175. get { return checked_indices; }
  176. }
  177. [Browsable (false)]
  178. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  179. public CheckedListViewItemCollection CheckedItems {
  180. get { return checked_items; }
  181. }
  182. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  183. [Localizable (true)]
  184. [MergableProperty (false)]
  185. public ColumnHeaderCollection Columns {
  186. get { return columns; }
  187. }
  188. [Browsable (false)]
  189. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  190. public ListViewItem FocusedItem {
  191. get { return focused_item; }
  192. }
  193. public override Color ForeColor {
  194. get { return base.ForeColor; }
  195. set { base.ForeColor = value; }
  196. }
  197. [DefaultValue (false)]
  198. public bool FullRowSelect {
  199. get { return full_row_select; }
  200. set { full_row_select = value; }
  201. }
  202. [DefaultValue (false)]
  203. public bool GridLines {
  204. get { return grid_lines; }
  205. set { grid_lines = value; }
  206. }
  207. [DefaultValue (ColumnHeaderStyle.Clickable)]
  208. public ColumnHeaderStyle HeaderStyle {
  209. get { return header_style; }
  210. set { header_style = value; }
  211. }
  212. [DefaultValue (true)]
  213. public bool HideSelection {
  214. get { return hide_selection; }
  215. set { hide_selection = value; }
  216. }
  217. [DefaultValue (false)]
  218. public bool HoverSelection {
  219. get { return hover_selection; }
  220. set { hover_selection = value; }
  221. }
  222. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  223. [Localizable (true)]
  224. [MergableProperty (false)]
  225. public ListViewItemCollection Items {
  226. get { return items; }
  227. }
  228. [DefaultValue (false)]
  229. public bool LabelEdit {
  230. get { return label_edit; }
  231. set { label_edit = value; }
  232. }
  233. [DefaultValue (false)]
  234. [Localizable (true)]
  235. public bool LabelWrap {
  236. get { return label_wrap; }
  237. set { label_wrap = value; }
  238. }
  239. [DefaultValue (null)]
  240. public ImageList LargeImageList {
  241. get { return large_image_list; }
  242. set { large_image_list = value; }
  243. }
  244. [Browsable (false)]
  245. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  246. public IComparer ListViewItemSorter {
  247. get { return item_sorter; }
  248. set { item_sorter = value; }
  249. }
  250. [DefaultValue (true)]
  251. public bool MultiSelect {
  252. get { return multiselect; }
  253. set { multiselect = value; }
  254. }
  255. [DefaultValue (true)]
  256. public bool Scrollable {
  257. get { return scrollable; }
  258. set { scrollable = value; }
  259. }
  260. [Browsable (false)]
  261. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  262. public SelectedIndexCollection SelectedIndices {
  263. get { return selected_indices; }
  264. }
  265. [Browsable (false)]
  266. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  267. public SelectedListViewItemCollection SelectedItems {
  268. get { return selected_items; }
  269. }
  270. [DefaultValue (null)]
  271. public ImageList SmallImageList {
  272. get { return small_image_list; }
  273. set { small_image_list = value; }
  274. }
  275. [DefaultValue (SortOrder.None)]
  276. public SortOrder Sorting {
  277. get { return sort_order; }
  278. set { sort_order = value; }
  279. }
  280. [DefaultValue (null)]
  281. public ImageList StateImageList {
  282. get { return state_image_list; }
  283. set { state_image_list = value; }
  284. }
  285. [Bindable (false)]
  286. [Browsable (false)]
  287. [EditorBrowsable (EditorBrowsableState.Never)]
  288. public override string Text {
  289. get { return text; }
  290. set {
  291. if (value == text)
  292. return;
  293. text = value;
  294. if (TextChanged != null)
  295. TextChanged (this, new EventArgs ());
  296. }
  297. }
  298. [Browsable (false)]
  299. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  300. public ListViewItem TopItem {
  301. get { return items [0]; }
  302. }
  303. [DefaultValue (View.LargeIcon)]
  304. public View View {
  305. get { return view; }
  306. set { view = value; }
  307. }
  308. #endregion // Public Instance Properties
  309. #region Internal Methods
  310. internal void Redraw (bool recalculate)
  311. {
  312. if (recalculate)
  313. CalculateListView ();
  314. redraw = true;
  315. }
  316. private void CalculateListView ()
  317. {
  318. // FIXME: TODO
  319. }
  320. private void ListView_Paint (object sender, PaintEventArgs pe)
  321. {
  322. if (this.Width <= 0 || this.Height <= 0 || this.Visible == false)
  323. return;
  324. if (redraw) {
  325. ThemeEngine.Current.DrawListView (this.DeviceContext, pe.ClipRectangle, this);
  326. redraw = false;
  327. }
  328. // paint on the screen
  329. pe.Graphics.DrawImage (this.ImageBuffer, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
  330. if (Paint != null)
  331. Paint (this, pe);
  332. }
  333. #endregion // Internal Methods
  334. #region Protected Methods
  335. protected override void CreateHandle ()
  336. {
  337. base.CreateHandle ();
  338. }
  339. protected override void Dispose (bool disposing)
  340. {
  341. Clear ();
  342. }
  343. protected override bool IsInputKey (Keys keyData)
  344. {
  345. return base.IsInputKey (keyData);
  346. }
  347. protected virtual void OnAfterLabelEdit (LabelEditEventArgs e)
  348. {
  349. if (AfterLabelEdit != null)
  350. AfterLabelEdit (this, e);
  351. }
  352. protected virtual void OnBeforeLabelEdit (LabelEditEventArgs e)
  353. {
  354. if (BeforeLabelEdit != null)
  355. BeforeLabelEdit (this, e);
  356. }
  357. protected virtual void OnColumnClick (ColumnClickEventArgs e)
  358. {
  359. if (ColumnClick != null)
  360. ColumnClick (this, e);
  361. }
  362. protected override void OnEnabledChanged (EventArgs e)
  363. {
  364. base.OnEnabledChanged (e);
  365. }
  366. protected override void OnFontChanged (EventArgs e)
  367. {
  368. base.OnFontChanged (e);
  369. }
  370. protected override void OnHandleCreated (EventArgs e)
  371. {
  372. base.OnHandleCreated (e);
  373. }
  374. protected override void OnHandleDestroyed (EventArgs e)
  375. {
  376. base.OnHandleDestroyed (e);
  377. }
  378. protected virtual void OnItemActivate (EventArgs e)
  379. {
  380. if (ItemActivate != null)
  381. ItemActivate (this, e);
  382. }
  383. protected virtual void OnItemCheck (ItemCheckEventArgs ice)
  384. {
  385. if (ItemCheck != null)
  386. ItemCheck (this, ice);
  387. }
  388. protected virtual void OnItemDrag (ItemDragEventArgs e)
  389. {
  390. if (ItemDrag != null)
  391. ItemDrag (this, e);
  392. }
  393. protected virtual void OnSelectedIndexChanged (EventArgs e)
  394. {
  395. if (SelectedIndexChanged != null)
  396. SelectedIndexChanged (this, e);
  397. }
  398. protected override void OnSystemColorsChanged (EventArgs e)
  399. {
  400. base.OnSystemColorsChanged (e);
  401. }
  402. protected void RealizeProperties ()
  403. {
  404. // FIXME: TODO
  405. }
  406. protected void UpdateExtendedStyles ()
  407. {
  408. // FIXME: TODO
  409. }
  410. protected override void WndProc (ref Message m)
  411. {
  412. base.WndProc (ref m);
  413. }
  414. #endregion // Protected Methods
  415. #region Public Instance Methods
  416. public void ArrangeIcons ()
  417. {
  418. ArrangeIcons (ListViewAlignment.Default);
  419. }
  420. public void ArrangeIcons (ListViewAlignment alignment)
  421. {
  422. // Icons are arranged only if view is set to LargeIcon or SmallIcon
  423. if (view == View.LargeIcon || view == View.SmallIcon) {
  424. // FIXME: TODO
  425. }
  426. }
  427. public void BeginUpdate ()
  428. {
  429. // flag to avoid painting
  430. updating = true;
  431. }
  432. public void Clear ()
  433. {
  434. columns.Clear ();
  435. items.Clear ();
  436. }
  437. public void EndUpdate ()
  438. {
  439. // flag to avoid painting
  440. updating = false;
  441. }
  442. public void EnsureVisible (int index)
  443. {
  444. // FIXME: TODO
  445. }
  446. public ListViewItem GetItemAt (int x, int y)
  447. {
  448. foreach (ListViewItem item in items) {
  449. if (item.Bounds.Contains (x, y))
  450. return item;
  451. }
  452. return null;
  453. }
  454. public Rectangle GetItemRect (int index)
  455. {
  456. return GetItemRect (index, ItemBoundsPortion.Entire);
  457. }
  458. public Rectangle GetItemRect (int index, ItemBoundsPortion portion)
  459. {
  460. if (index < 0 || index >= items.Count)
  461. throw new IndexOutOfRangeException ("Invalid Index");
  462. return items [index].GetBounds (portion);
  463. }
  464. public void Sort ()
  465. {
  466. if (sort_order != SortOrder.None)
  467. items.list.Sort (item_sorter);
  468. if (sort_order == SortOrder.Descending)
  469. items.list.Reverse ();
  470. }
  471. public override string ToString ()
  472. {
  473. int count = this.Items.Count;
  474. if (count == 0)
  475. return string.Format ("System.Windows.Forms.ListView, Items.Count: 0");
  476. else
  477. return string.Format ("System.Windows.Forms.ListView, Items.Count: {0}, Items[0]: {1}", count, this.Items [0].ToString ());
  478. }
  479. #endregion // Public Instance Methods
  480. #region Subclasses
  481. public class CheckedIndexCollection : IList, ICollection, IEnumerable
  482. {
  483. internal ArrayList list;
  484. private ListView owner;
  485. #region Public Constructor
  486. public CheckedIndexCollection (ListView owner)
  487. {
  488. list = new ArrayList ();
  489. this.owner = owner;
  490. }
  491. #endregion // Public Constructor
  492. #region Public Properties
  493. [Browsable (false)]
  494. public virtual int Count {
  495. get { return list.Count; }
  496. }
  497. public virtual bool IsReadOnly {
  498. get { return true; }
  499. }
  500. public int this [int index] {
  501. get {
  502. if (index < 0 || index >= list.Count)
  503. throw new ArgumentOutOfRangeException ("Index out of range.");
  504. return (int) list [index];
  505. }
  506. }
  507. bool ICollection.IsSynchronized {
  508. get { return list.IsSynchronized; }
  509. }
  510. object ICollection.SyncRoot {
  511. get { return list.SyncRoot; }
  512. }
  513. bool IList.IsFixedSize {
  514. get { return list.IsFixedSize; }
  515. }
  516. object IList.this [int index] {
  517. get { return this [index]; }
  518. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  519. }
  520. #endregion // Public Properties
  521. #region Public Methods
  522. public bool Contains (int checkedIndex)
  523. {
  524. return list.Contains (checkedIndex);
  525. }
  526. public virtual IEnumerator GetEnumerator ()
  527. {
  528. return list.GetEnumerator ();
  529. }
  530. void ICollection.CopyTo (Array dest, int index)
  531. {
  532. list.CopyTo (dest, index);
  533. }
  534. int IList.Add (object value)
  535. {
  536. throw new NotSupportedException ("Add operation is not supported.");
  537. }
  538. void IList.Clear ()
  539. {
  540. throw new NotSupportedException ("Clear operation is not supported.");
  541. }
  542. bool IList.Contains (object checkedIndex)
  543. {
  544. return list.Contains (checkedIndex);
  545. }
  546. int IList.IndexOf (object checkedIndex)
  547. {
  548. return list.IndexOf (checkedIndex);
  549. }
  550. void IList.Insert (int index, object value)
  551. {
  552. throw new NotSupportedException ("Insert operation is not supported.");
  553. }
  554. void IList.Remove (object value)
  555. {
  556. throw new NotSupportedException ("Remove operation is not supported.");
  557. }
  558. void IList.RemoveAt (int index)
  559. {
  560. throw new NotSupportedException ("RemoveAt operation is not supported.");
  561. }
  562. public int IndexOf (int checkedIndex)
  563. {
  564. return list.IndexOf (checkedIndex);
  565. }
  566. #endregion // Public Methods
  567. } // CheckedIndexCollection
  568. public class CheckedListViewItemCollection : IList, ICollection, IEnumerable
  569. {
  570. internal ArrayList list;
  571. private ListView owner;
  572. #region Public Constructor
  573. public CheckedListViewItemCollection (ListView owner)
  574. {
  575. list = new ArrayList ();
  576. this.owner = owner;
  577. }
  578. #endregion // Public Constructor
  579. #region Public Properties
  580. [Browsable (false)]
  581. public virtual int Count {
  582. get { return list.Count; }
  583. }
  584. public virtual bool IsReadOnly {
  585. get { return true; }
  586. }
  587. public ListViewItem this [int index] {
  588. get {
  589. if (index < 0 || index >= list.Count)
  590. throw new ArgumentOutOfRangeException ("Index out of range.");
  591. return (ListViewItem) list [index];
  592. }
  593. }
  594. bool ICollection.IsSynchronized {
  595. get { return list.IsSynchronized; }
  596. }
  597. object ICollection.SyncRoot {
  598. get { return list.SyncRoot; }
  599. }
  600. bool IList.IsFixedSize {
  601. get { return list.IsFixedSize; }
  602. }
  603. object IList.this [int index] {
  604. get { return this [index]; }
  605. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  606. }
  607. #endregion // Public Properties
  608. #region Public Methods
  609. public bool Contains (ListViewItem item)
  610. {
  611. return list.Contains (item);
  612. }
  613. public virtual void CopyTo (Array dest, int index)
  614. {
  615. list.CopyTo (dest, index);
  616. }
  617. public virtual IEnumerator GetEnumerator ()
  618. {
  619. return list.GetEnumerator ();
  620. }
  621. int IList.Add (object value)
  622. {
  623. throw new NotSupportedException ("Add operation is not supported.");
  624. }
  625. void IList.Clear ()
  626. {
  627. throw new NotSupportedException ("Clear operation is not supported.");
  628. }
  629. bool IList.Contains (object item)
  630. {
  631. return list.Contains (item);
  632. }
  633. int IList.IndexOf (object item)
  634. {
  635. return list.IndexOf (item);
  636. }
  637. void IList.Insert (int index, object value)
  638. {
  639. throw new NotSupportedException ("Insert operation is not supported.");
  640. }
  641. void IList.Remove (object value)
  642. {
  643. throw new NotSupportedException ("Remove operation is not supported.");
  644. }
  645. void IList.RemoveAt (int index)
  646. {
  647. throw new NotSupportedException ("RemoveAt operation is not supported.");
  648. }
  649. public int IndexOf (ListViewItem item)
  650. {
  651. return list.IndexOf (item);
  652. }
  653. #endregion // Public Methods
  654. } // CheckedListViewItemCollection
  655. public class ColumnHeaderCollection : IList, ICollection, IEnumerable
  656. {
  657. internal ArrayList list;
  658. private ListView owner;
  659. #region Public Constructor
  660. public ColumnHeaderCollection (ListView owner)
  661. {
  662. list = new ArrayList ();
  663. this.owner = owner;
  664. }
  665. #endregion // Public Constructor
  666. #region Public Properties
  667. [Browsable (false)]
  668. public virtual int Count {
  669. get { return list.Count; }
  670. }
  671. public virtual bool IsReadOnly {
  672. get { return false; }
  673. }
  674. public virtual ColumnHeader this [int index] {
  675. get {
  676. if (index < 0 || index >= list.Count)
  677. throw new ArgumentOutOfRangeException ("Index out of range.");
  678. return (ColumnHeader) list [index];
  679. }
  680. }
  681. bool ICollection.IsSynchronized {
  682. get { return list.IsSynchronized; }
  683. }
  684. object ICollection.SyncRoot {
  685. get { return list.SyncRoot; }
  686. }
  687. bool IList.IsFixedSize {
  688. get { return list.IsFixedSize; }
  689. }
  690. object IList.this [int index] {
  691. get { return this [index]; }
  692. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  693. }
  694. #endregion // Public Properties
  695. #region Public Methods
  696. public virtual int Add (ColumnHeader value)
  697. {
  698. return list.Add (value);
  699. }
  700. public virtual ColumnHeader Add (string str, int width, HorizontalAlignment textAlign)
  701. {
  702. ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
  703. this.Add (colHeader);
  704. return colHeader;
  705. }
  706. public virtual void AddRange (ColumnHeader [] values)
  707. {
  708. foreach (ColumnHeader colHeader in values)
  709. this.Add (colHeader);
  710. }
  711. public virtual void Clear ()
  712. {
  713. list.Clear ();
  714. }
  715. public bool Contains (ColumnHeader value)
  716. {
  717. return list.Contains (value);
  718. }
  719. public virtual IEnumerator GetEnumerator ()
  720. {
  721. return list.GetEnumerator ();
  722. }
  723. void ICollection.CopyTo (Array dest, int index)
  724. {
  725. list.CopyTo (dest, index);
  726. }
  727. int IList.Add (object value)
  728. {
  729. if (! (value is ColumnHeader)) {
  730. throw new ArgumentException("Not of type ColumnHeader", "value");
  731. }
  732. return this.Add ((ColumnHeader) value);
  733. }
  734. bool IList.Contains (object value)
  735. {
  736. if (! (value is ColumnHeader)) {
  737. throw new ArgumentException("Not of type ColumnHeader", "value");
  738. }
  739. return this.Contains ((ColumnHeader) value);
  740. }
  741. int IList.IndexOf (object value)
  742. {
  743. if (! (value is ColumnHeader)) {
  744. throw new ArgumentException("Not of type ColumnHeader", "value");
  745. }
  746. return this.IndexOf ((ColumnHeader) value);
  747. }
  748. void IList.Insert (int index, object value)
  749. {
  750. if (! (value is ColumnHeader)) {
  751. throw new ArgumentException("Not of type ColumnHeader", "value");
  752. }
  753. this.Insert (index, (ColumnHeader) value);
  754. }
  755. void IList.Remove (object value)
  756. {
  757. if (! (value is ColumnHeader)) {
  758. throw new ArgumentException("Not of type ColumnHeader", "value");
  759. }
  760. this.Remove ((ColumnHeader) value);
  761. }
  762. public int IndexOf (ColumnHeader value)
  763. {
  764. return list.IndexOf (value);
  765. }
  766. public void Insert (int index, ColumnHeader value)
  767. {
  768. if (index < 0 || index >= list.Count)
  769. throw new ArgumentOutOfRangeException ("Index out of range.");
  770. list.Insert (index, value);
  771. }
  772. public void Insert (int index, string str, int width, HorizontalAlignment textAlign)
  773. {
  774. ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
  775. this.Insert (index, colHeader);
  776. }
  777. public virtual void Remove (ColumnHeader column)
  778. {
  779. list.Remove (column);
  780. }
  781. public virtual void RemoveAt (int index)
  782. {
  783. if (index < 0 || index >= list.Count)
  784. throw new ArgumentOutOfRangeException ("Index out of range.");
  785. list.RemoveAt (index);
  786. }
  787. #endregion // Public Methods
  788. } // ColumnHeaderCollection
  789. public class ListViewItemCollection : IList, ICollection, IEnumerable
  790. {
  791. internal ArrayList list;
  792. private ListView owner;
  793. #region Public Constructor
  794. public ListViewItemCollection (ListView owner)
  795. {
  796. list = new ArrayList ();
  797. this.owner = owner;
  798. }
  799. #endregion // Public Constructor
  800. #region Public Properties
  801. [Browsable (false)]
  802. public virtual int Count {
  803. get { return list.Count; }
  804. }
  805. public virtual bool IsReadOnly {
  806. get { return false; }
  807. }
  808. public virtual ListViewItem this [int displayIndex] {
  809. get {
  810. if (displayIndex < 0 || displayIndex >= list.Count)
  811. throw new ArgumentOutOfRangeException ("Index out of range.");
  812. return (ListViewItem) list [displayIndex];
  813. }
  814. set {
  815. if (displayIndex < 0 || displayIndex >= list.Count)
  816. throw new ArgumentOutOfRangeException ("Index out of range.");
  817. value.owner = this.owner;
  818. list [displayIndex] = value;
  819. owner.Redraw (true);
  820. }
  821. }
  822. bool ICollection.IsSynchronized {
  823. get { return list.IsSynchronized; }
  824. }
  825. object ICollection.SyncRoot {
  826. get { return list.SyncRoot; }
  827. }
  828. bool IList.IsFixedSize {
  829. get { return list.IsFixedSize; }
  830. }
  831. object IList.this [int index] {
  832. get { return this [index]; }
  833. set {
  834. if (value is ListViewItem)
  835. this [index] = (ListViewItem) value;
  836. else
  837. this [index] = new ListViewItem (value.ToString ());
  838. }
  839. }
  840. #endregion // Public Properties
  841. #region Public Methods
  842. public virtual ListViewItem Add (ListViewItem value)
  843. {
  844. value.owner = this.owner;
  845. list.Add (value);
  846. if (owner.Sorting != SortOrder.None)
  847. owner.Sort ();
  848. owner.Redraw (true);
  849. return value;
  850. }
  851. public virtual ListViewItem Add (string text)
  852. {
  853. ListViewItem item = new ListViewItem (text);
  854. return this.Add (item);
  855. }
  856. public virtual ListViewItem Add (string text, int imageIndex)
  857. {
  858. ListViewItem item = new ListViewItem (text, imageIndex);
  859. return this.Add (item);
  860. }
  861. public void AddRange (ListViewItem [] values)
  862. {
  863. list.Clear ();
  864. foreach (ListViewItem item in values) {
  865. item.owner = this.owner;
  866. list.Add (item);
  867. }
  868. if (owner.Sorting != SortOrder.None)
  869. owner.Sort ();
  870. owner.Redraw (true);
  871. }
  872. public virtual void Clear ()
  873. {
  874. list.Clear ();
  875. owner.Redraw (true);
  876. }
  877. public bool Contains (ListViewItem item)
  878. {
  879. return list.Contains (item);
  880. }
  881. public virtual void CopyTo (Array dest, int index)
  882. {
  883. list.CopyTo (dest, index);
  884. }
  885. public virtual IEnumerator GetEnumerator ()
  886. {
  887. return list.GetEnumerator ();
  888. }
  889. int IList.Add (object item)
  890. {
  891. int result;
  892. ListViewItem li;
  893. if (item is ListViewItem)
  894. li = (ListViewItem) item;
  895. else
  896. li = new ListViewItem (item.ToString ());
  897. li.owner = this.owner;
  898. result = list.Add (li);
  899. owner.Redraw (true);
  900. return result;
  901. }
  902. bool IList.Contains (object item)
  903. {
  904. return list.Contains (item);
  905. }
  906. int IList.IndexOf (object item)
  907. {
  908. return list.IndexOf (item);
  909. }
  910. void IList.Insert (int index, object item)
  911. {
  912. if (item is ListViewItem)
  913. this.Insert (index, (ListViewItem) item);
  914. else
  915. this.Insert (index, item.ToString ());
  916. }
  917. void IList.Remove (object item)
  918. {
  919. if (list.Contains (item)) {
  920. list.Remove (item);
  921. owner.Redraw (true);
  922. }
  923. }
  924. public int IndexOf (ListViewItem item)
  925. {
  926. return list.IndexOf (item);
  927. }
  928. public ListViewItem Insert (int index, ListViewItem item)
  929. {
  930. if (index < 0 || index >= list.Count)
  931. throw new ArgumentOutOfRangeException ("Index out of range.");
  932. item.owner = this.owner;
  933. list.Insert (index, item);
  934. owner.Redraw (true);
  935. return item;
  936. }
  937. public ListViewItem Insert (int index, string text)
  938. {
  939. return this.Insert (index, new ListViewItem (text));
  940. }
  941. public ListViewItem Insert (int index, string text, int imageIndex)
  942. {
  943. return this.Insert (index, new ListViewItem (text, imageIndex));
  944. }
  945. public virtual void Remove (ListViewItem item)
  946. {
  947. if (list.Contains (item)) {
  948. list.Remove (item);
  949. owner.Redraw (true);
  950. }
  951. }
  952. public virtual void RemoveAt (int index)
  953. {
  954. if (index < 0 || index >= list.Count)
  955. throw new ArgumentOutOfRangeException ("Index out of range.");
  956. list.RemoveAt (index);
  957. owner.Redraw (false);
  958. }
  959. #endregion // Public Methods
  960. } // ListViewItemCollection
  961. public class SelectedIndexCollection : IList, ICollection, IEnumerable
  962. {
  963. internal ArrayList list;
  964. private ListView owner;
  965. #region Public Constructor
  966. public SelectedIndexCollection (ListView owner)
  967. {
  968. list = new ArrayList ();
  969. this.owner = owner;
  970. }
  971. #endregion // Public Constructor
  972. #region Public Properties
  973. [Browsable (false)]
  974. public virtual int Count {
  975. get { return list.Count; }
  976. }
  977. public virtual bool IsReadOnly {
  978. get { return true; }
  979. }
  980. public int this [int index] {
  981. get {
  982. if (index < 0 || index >= list.Count)
  983. throw new ArgumentOutOfRangeException ("Index out of range.");
  984. return (int) list [index];
  985. }
  986. }
  987. bool ICollection.IsSynchronized {
  988. get { return list.IsSynchronized; }
  989. }
  990. object ICollection.SyncRoot {
  991. get { return list.SyncRoot; }
  992. }
  993. bool IList.IsFixedSize {
  994. get { return list.IsFixedSize; }
  995. }
  996. object IList.this [int index] {
  997. get { return this [index]; }
  998. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  999. }
  1000. #endregion // Public Properties
  1001. #region Public Methods
  1002. public bool Contains (int selectedIndex)
  1003. {
  1004. return list.Contains (selectedIndex);
  1005. }
  1006. public virtual void CopyTo (Array dest, int index)
  1007. {
  1008. list.CopyTo (dest, index);
  1009. }
  1010. public virtual IEnumerator GetEnumerator ()
  1011. {
  1012. return list.GetEnumerator ();
  1013. }
  1014. int IList.Add (object value)
  1015. {
  1016. throw new NotSupportedException ("Add operation is not supported.");
  1017. }
  1018. void IList.Clear ()
  1019. {
  1020. throw new NotSupportedException ("Clear operation is not supported.");
  1021. }
  1022. bool IList.Contains (object selectedIndex)
  1023. {
  1024. return list.Contains (selectedIndex);
  1025. }
  1026. int IList.IndexOf (object selectedIndex)
  1027. {
  1028. return list.IndexOf (selectedIndex);
  1029. }
  1030. void IList.Insert (int index, object value)
  1031. {
  1032. throw new NotSupportedException ("Insert operation is not supported.");
  1033. }
  1034. void IList.Remove (object value)
  1035. {
  1036. throw new NotSupportedException ("Remove operation is not supported.");
  1037. }
  1038. void IList.RemoveAt (int index)
  1039. {
  1040. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1041. }
  1042. public int IndexOf (int selectedIndex)
  1043. {
  1044. return list.IndexOf (selectedIndex);
  1045. }
  1046. #endregion // Public Methods
  1047. } // SelectedIndexCollection
  1048. public class SelectedListViewItemCollection : IList, ICollection, IEnumerable
  1049. {
  1050. internal ArrayList list;
  1051. private ListView owner;
  1052. #region Public Constructor
  1053. public SelectedListViewItemCollection (ListView owner)
  1054. {
  1055. list = new ArrayList ();
  1056. this.owner = owner;
  1057. }
  1058. #endregion // Public Constructor
  1059. #region Public Properties
  1060. [Browsable (false)]
  1061. public virtual int Count {
  1062. get { return list.Count; }
  1063. }
  1064. public virtual bool IsReadOnly {
  1065. get { return true; }
  1066. }
  1067. public ListViewItem this [int index] {
  1068. get {
  1069. if (index < 0 || index >= list.Count)
  1070. throw new ArgumentOutOfRangeException ("Index out of range.");
  1071. return (ListViewItem) list [index];
  1072. }
  1073. }
  1074. bool ICollection.IsSynchronized {
  1075. get { return list.IsSynchronized; }
  1076. }
  1077. object ICollection.SyncRoot {
  1078. get { return list.SyncRoot; }
  1079. }
  1080. bool IList.IsFixedSize {
  1081. get { return list.IsFixedSize; }
  1082. }
  1083. object IList.this [int index] {
  1084. get { return this [index]; }
  1085. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1086. }
  1087. #endregion // Public Properties
  1088. #region Public Methods
  1089. public virtual void Clear ()
  1090. {
  1091. list.Clear ();
  1092. }
  1093. public bool Contains (ListViewItem item)
  1094. {
  1095. return list.Contains (item);
  1096. }
  1097. public virtual void CopyTo (Array dest, int index)
  1098. {
  1099. list.CopyTo (dest, index);
  1100. }
  1101. public virtual IEnumerator GetEnumerator ()
  1102. {
  1103. return list.GetEnumerator ();
  1104. }
  1105. int IList.Add (object value)
  1106. {
  1107. throw new NotSupportedException ("Add operation is not supported.");
  1108. }
  1109. bool IList.Contains (object item)
  1110. {
  1111. return list.Contains (item);
  1112. }
  1113. int IList.IndexOf (object item)
  1114. {
  1115. return list.IndexOf (item);
  1116. }
  1117. void IList.Insert (int index, object value)
  1118. {
  1119. throw new NotSupportedException ("Insert operation is not supported.");
  1120. }
  1121. void IList.Remove (object value)
  1122. {
  1123. throw new NotSupportedException ("Remove operation is not supported.");
  1124. }
  1125. void IList.RemoveAt (int index)
  1126. {
  1127. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1128. }
  1129. public int IndexOf (ListViewItem item)
  1130. {
  1131. return list.IndexOf (item);
  1132. }
  1133. #endregion // Public Methods
  1134. } // SelectedListViewItemCollection
  1135. #endregion // Subclasses
  1136. }
  1137. }