svn path=/branches/mono-1-1-9/mcs/; revision=50439
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ListViewItem.cs
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 (rkumar@novell.com)
24 //
25 // Todo:
26 //     - Drawing of focus rectangle
27
28
29
30 // NOT COMPLETE
31
32
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Drawing;
36 using System.Runtime.Serialization;
37
38 namespace System.Windows.Forms
39 {
40         [DefaultProperty ("Text")]
41         [DesignTimeVisible (false)]
42         [Serializable]
43         [ToolboxItem (false)]
44         [TypeConverter (typeof (ListViewItemConverter))]
45         public class ListViewItem : ICloneable, ISerializable
46         {
47                 #region Instance Variables
48                 private int image_index = -1;
49                 private bool is_checked = false;
50                 private bool is_focused = false;
51                 private int state_image_index = -1;
52                 private ListViewSubItemCollection sub_items;
53                 private object tag;
54                 private bool use_item_style = true;
55
56                 // internal variables
57                 internal Rectangle checkbox_rect;       // calculated by CalcListViewItem method
58                 internal Rectangle entire_rect;
59                 internal Rectangle icon_rect;
60                 internal Rectangle item_rect;
61                 internal Rectangle label_rect;
62                 internal Point location = Point.Empty;  // set by the ListView control
63                 internal ListView owner;
64                 internal bool selected;
65
66                 #endregion Instance Variables
67
68                 #region Public Constructors
69                 public ListViewItem ()
70                 {
71                         this.sub_items = new ListViewSubItemCollection (this);
72                         this.sub_items.Add ("");                        
73                 }
74
75                 public ListViewItem (string text) : this (text, -1)
76                 {
77                 }
78
79                 public ListViewItem (string [] items) : this (items, -1)
80                 {
81                 }
82
83                 public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
84                 {
85                         this.sub_items = new ListViewSubItemCollection (this);
86                         this.sub_items.AddRange (subItems);
87                         this.image_index = imageIndex;
88                 }
89
90                 public ListViewItem (string text, int imageIndex)
91                 {
92                         this.image_index = imageIndex;
93                         this.sub_items = new ListViewSubItemCollection (this);
94                         this.sub_items.Add (text);
95                 }
96
97                 public ListViewItem (string [] items, int imageIndex)
98                 {
99                         this.sub_items = new ListViewSubItemCollection (this);
100                         this.sub_items.AddRange (items);
101                         this.image_index = imageIndex;
102                 }
103
104                 public ListViewItem (string [] items, int imageIndex, Color foreColor, 
105                                      Color backColor, Font font)
106                 {
107                         this.sub_items = new ListViewSubItemCollection (this);
108                         this.sub_items.AddRange (items);
109                         this.image_index = imageIndex;
110                         ForeColor = foreColor;
111                         BackColor = backColor;
112                         Font = font;
113                 }
114                 #endregion      // Public Constructors
115
116                 #region Public Instance Properties
117                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
118                 public Color BackColor {
119                         get {
120                                 if (sub_items.Count > 0)
121                                         return sub_items[0].BackColor;
122
123                                 if (owner != null)
124                                         return owner.BackColor;
125                                 
126                                 return ThemeEngine.Current.ColorWindow;
127                         }
128
129                         set { sub_items[0].BackColor = value; }
130                 }
131
132                 [Browsable (false)]
133                 public Rectangle Bounds {
134                         get {
135                                 return GetBounds (ItemBoundsPortion.Entire);
136                         }
137                 }
138
139                 [DefaultValue (false)]
140                 [RefreshProperties (RefreshProperties.Repaint)]
141                 public bool Checked {
142                         get { return is_checked; }
143                         set { 
144                                 if (is_checked == value)
145                                         return;
146
147                                 is_checked = value;
148                                 if (owner != null)
149                                         owner.Invalidate (Bounds);
150                         }
151                 }
152
153                 [Browsable (false)]
154                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
155                 public bool Focused {
156                         get { return is_focused; }
157                         set {   
158                                 if (is_focused == value)
159                                         return;
160
161                                 is_focused = value; 
162
163                                 if (owner != null)
164                                         owner.Invalidate (Bounds);
165                         }
166                 }
167
168                 [Localizable (true)]
169                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
170                 public Font Font {
171                         get {
172                                 if (sub_items.Count > 0)
173                                         return sub_items[0].Font;
174
175                                 if (owner != null)
176                                         return owner.Font;
177
178                                 return ThemeEngine.Current.DefaultFont;
179                         }
180                         set {   
181                                 if (sub_items[0].Font == value)
182                                         return;
183
184                                 sub_items[0].Font = value; 
185
186                                 if (owner != null)
187                                         owner.Invalidate (Bounds);
188                         }
189                 }
190
191                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
192                 public Color ForeColor {
193                         get {
194                                 if (sub_items.Count > 0)
195                                         return sub_items[0].ForeColor;
196
197                                 if (owner != null)
198                                         return owner.ForeColor;
199
200                                 return ThemeEngine.Current.ColorWindowText;
201                         }
202                         set { sub_items[0].ForeColor = value; }
203                 }
204
205                 [DefaultValue (-1)]
206                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
207                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
208                          typeof (System.Drawing.Design.UITypeEditor))]
209                 [Localizable (true)]
210                 [TypeConverter (typeof (ImageIndexConverter))]
211                 public int ImageIndex {
212                         get { return image_index; }
213                         set {
214                                 if (value < -1)
215                                         throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
216                                 
217                                 image_index = value;
218
219                                 if (owner != null)
220                                         owner.Invalidate (Bounds);      
221                         }
222                 }
223
224                 [Browsable (false)]
225                 public ImageList ImageList {
226                         get {
227                                 if (owner == null)
228                                         return null;
229                                 else if (owner.View == View.LargeIcon)
230                                         return owner.large_image_list;
231                                 else
232                                         return owner.small_image_list;
233                         }
234                 }
235
236                 [Browsable (false)]
237                 public int Index {
238                         get {
239                                 if (owner == null)
240                                         return -1;
241                                 else
242                                         return owner.Items.IndexOf (this);
243                         }
244                 }
245
246                 [Browsable (false)]
247                 public ListView ListView {
248                         get { return owner; }
249                 }
250
251                 [Browsable (false)]
252                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
253                 public bool Selected {
254                         get { return selected; }
255                         set {
256                                 if (owner != null) {
257                                         if (owner.CanMultiselect == false &&
258                                             owner.SelectedItems.Count > 0) {
259                                                 owner.SelectedItems.Clear ();
260                                                 owner.SelectedIndices.list.Clear ();
261                                         }
262
263                                         selected = value;
264                                         if (selected) {
265                                                 //do we need !owner.SelectedItems.Contains (this))
266                                                 owner.SelectedItems.list.Add (this);
267                                                 owner.SelectedIndices.list.Add (this.Index);
268                                         }
269                                         else {
270                                                 owner.SelectedItems.list.Remove (this);
271                                                 owner.SelectedIndices.list.Remove (this.Index);
272                                         }
273                                 }
274                         }
275                 }
276
277                 [DefaultValue (-1)]
278                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
279                          typeof (System.Drawing.Design.UITypeEditor))]
280                 [Localizable (true)]
281                 [TypeConverter (typeof (ImageIndexConverter))]
282                 public int StateImageIndex {
283                         get { return state_image_index; }
284                         set {
285                                 if (value < -1 || value > 14)
286                                         throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
287
288                                 state_image_index = value;
289                         }
290                 }
291
292                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
293                 public ListViewSubItemCollection SubItems {
294                         get { return sub_items; }
295                 }
296
297                 [Bindable (true)]
298                 [DefaultValue (null)]
299                 [Localizable (false)]
300                 [TypeConverter (typeof (StringConverter))]
301                 public object Tag {
302                         get { return tag; }
303                         set { tag = value; }
304                 }
305
306                 [Localizable (true)]
307                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
308                 public string Text {
309                         get {
310                                 if (this.sub_items.Count > 0)
311                                         return this.sub_items [0].Text;
312                                 else
313                                         return "";
314                         }
315                         set { this.sub_items [0].Text = value; }
316                 }
317
318                 [DefaultValue (true)]
319                 public bool UseItemStyleForSubItems {
320                         get { return use_item_style; }
321                         set { use_item_style = value; }
322                 }
323                 #endregion      // Public Instance Properties
324
325                 #region Public Instance Methods
326                 public void BeginEdit ()
327                 {
328                         // FIXME: TODO
329                         // if (owner != null && owner.LabelEdit 
330                         //    && owner.Activation == ItemActivation.Standard)
331                         // allow editing
332                         // else
333                         // throw new InvalidOperationException ();
334                 }
335
336                 public virtual object Clone ()
337                 {
338                         ListViewItem clone = new ListViewItem ();
339                         clone.image_index = this.image_index;
340                         clone.is_checked = this.is_checked;
341                         clone.is_focused = this.is_focused;
342                         clone.selected = this.selected;
343                         clone.state_image_index = this.state_image_index;
344                         clone.sub_items = new ListViewSubItemCollection (this);
345                         
346                         foreach (ListViewSubItem subItem in this.sub_items)
347                                 clone.sub_items.Add (subItem.Text, subItem.ForeColor,
348                                                      subItem.BackColor, subItem.Font);
349                         clone.tag = this.tag;
350                         clone.use_item_style = this.use_item_style;
351                         clone.owner = null;
352
353                         return clone;
354                 }
355
356                 public virtual void EnsureVisible ()
357                 {
358                         if (this.owner != null) {
359                                 owner.EnsureVisible (owner.Items.IndexOf (this));
360                         }
361                 }
362
363                 public Rectangle GetBounds (ItemBoundsPortion portion)
364                 {
365                         if (owner == null)
366                                 return Rectangle.Empty;
367                         
368                         // should we check for dirty flag to optimize this ?
369                         CalcListViewItem ();
370
371                         switch (portion) {
372
373                         case ItemBoundsPortion.Icon:
374                                 return icon_rect;
375
376                         case ItemBoundsPortion.Label:
377                                 return label_rect;
378
379                         case ItemBoundsPortion.ItemOnly:
380                                 return item_rect;
381
382                         case ItemBoundsPortion.Entire:
383                                 return entire_rect;
384
385                         default:
386                                 throw new ArgumentException ("Invalid value for portion.");
387                         }
388                 }
389
390                 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
391                 {
392                         // FIXME: TODO
393                 }
394
395                 public virtual void Remove ()
396                 {
397                         if (owner != null)
398                                 owner.Items.Remove (this);
399                         owner = null;
400                 }
401
402                 public override string ToString ()
403                 {
404                         return string.Format ("ListViewItem: {0}", this.Text);
405                 }
406                 #endregion      // Public Instance Methods
407
408                 #region Protected Methods
409                 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
410                 {
411                         // FIXME: TODO
412                 }
413
414                 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
415                 {
416                         // FIXME: TODO
417                 }
418                 #endregion      // Protected Methods
419
420                 #region Private Internal Methods
421                 internal Rectangle CheckRect {
422                         get { return this.checkbox_rect; }
423                 }
424
425                 internal Rectangle EntireRect {
426                         get { return this.entire_rect; }
427                 }
428
429                 internal Rectangle IconRect {
430                         get { return this.icon_rect; }
431                 }
432
433                 internal Rectangle LabelRect {
434                         get { return this.label_rect; }
435                 }
436
437                 internal void CalcListViewItem ()
438                 {
439                         int item_ht;
440                         Size text_size = owner.text_size;
441                         
442                         if (owner.CheckBoxes)
443                                 checkbox_rect.Size = owner.CheckBoxSize;
444                         else
445                                 checkbox_rect = Rectangle.Empty;
446
447                         checkbox_rect.Location = this.location;
448
449                         switch (owner.View) {
450
451                         case View.Details:
452                                 // LAMESPEC: MSDN says, "In all views except the details
453                                 // view of the ListView, this value specifies the same
454                                 // bounding rectangle as the Entire value." Actually, it
455                                 // returns same bounding rectangles for Item and Entire
456                                 // values in the case of Details view.
457
458                                 icon_rect.X = checkbox_rect.X + checkbox_rect.Width + 2;
459                                 icon_rect.Y = checkbox_rect.Y;
460
461                                 item_ht = Math.Max (owner.CheckBoxSize.Height + 1,
462                                                     text_size.Height);
463
464                                 if (owner.SmallImageList != null) {
465                                         item_ht = Math.Max (item_ht,
466                                                             owner.SmallImageList.ImageSize.Height + 1);
467                                         icon_rect.Width = owner.SmallImageList.ImageSize.Width;
468                                 }
469                                 else
470                                         icon_rect.Width = 0;
471
472                                 label_rect.Height = checkbox_rect.Height = icon_rect.Height = item_ht;
473
474                                 label_rect.X = icon_rect.X + icon_rect.Width;
475                                 label_rect.Y = icon_rect.Y;
476
477                                 if (owner.Columns.Count > 0)
478                                         label_rect.Width = Math.Max (text_size.Width, owner.Columns[0].Wd);
479                                 else
480                                         label_rect.Width = text_size.Width;
481
482                                 item_rect = entire_rect = Rectangle.Union
483                                         (Rectangle.Union (checkbox_rect, icon_rect), label_rect);
484
485                                 // Take into account the rest of columns. First column
486                                 // is already taken into account above.
487                                 for (int i = 1; i < owner.Columns.Count; i++) {
488                                         item_rect.Width += owner.Columns [i].Wd;
489                                         entire_rect.Width += owner.Columns [i].Wd;
490                                 }
491                                 break;
492
493                         case View.LargeIcon:
494                                 if (owner.LargeImageList != null) {
495                                         icon_rect.Width = owner.LargeImageList.ImageSize.Width + 16;
496                                         icon_rect.Height = owner.LargeImageList.ImageSize.Height + 4;
497                                 }
498                                 else {
499                                         icon_rect.Width = 16;
500                                         icon_rect.Height = 4;
501                                 }
502
503                                 if (text_size.Width <= (checkbox_rect.Width + icon_rect.Width)) {
504                                         icon_rect.X = checkbox_rect.X + checkbox_rect.Width;
505                                         icon_rect.Y = checkbox_rect.Y;
506
507                                         label_rect.X = icon_rect.X + (icon_rect.Width 
508                                                                       - text_size.Width) / 2;
509                                         label_rect.Y = Math.Max (checkbox_rect.Bottom,
510                                                                  icon_rect.Bottom) + 2;
511                                         label_rect.Size = text_size;
512                                 }
513                                 else {
514                                         label_rect.X = this.location.X;
515
516                                         int centerX = label_rect.X + text_size.Width / 2;
517                                         icon_rect.X = centerX - icon_rect.Width / 2;
518                                         checkbox_rect.X = (icon_rect.X - checkbox_rect.Width);
519
520                                         icon_rect.Y = checkbox_rect.Y;
521
522                                         label_rect.Y = Math.Max (checkbox_rect.Bottom,
523                                                                  icon_rect.Bottom) + 2;
524                                         label_rect.Size = text_size;
525                                 }
526
527                                 item_rect = Rectangle.Union (icon_rect, label_rect);
528                                 entire_rect = Rectangle.Union (item_rect, checkbox_rect);
529                                 break;
530
531                         case View.List:
532                                         goto case View.SmallIcon;
533
534                         case View.SmallIcon:
535                                 icon_rect.X = checkbox_rect.X + checkbox_rect.Width;
536                                 icon_rect.Y = checkbox_rect.Y;
537
538                                 item_ht = Math.Max (owner.CheckBoxSize.Height, text_size.Height);
539
540                                 if (owner.SmallImageList != null) {
541                                         item_ht = Math.Max (item_ht,
542                                                             owner.SmallImageList.ImageSize.Height + 1);
543                                         icon_rect.Width = owner.SmallImageList.ImageSize.Width;
544                                 }
545                                 else
546                                         icon_rect.Width = 0;
547
548                                 label_rect.Height = checkbox_rect.Height = icon_rect.Height = item_ht;
549
550                                 label_rect.X = icon_rect.X + icon_rect.Width;
551                                 label_rect.Y = icon_rect.Y;
552                                 label_rect.Width = text_size.Width;
553
554                                 item_rect = Rectangle.Union (icon_rect, label_rect);
555                                 entire_rect = Rectangle.Union (item_rect, checkbox_rect);
556                                 break;
557                         }
558                 }
559                 #endregion      // Private Internal Methods
560
561                 #region Subclasses
562
563                 [DefaultProperty ("Text")]
564                 [DesignTimeVisible (false)]
565                 [Serializable]
566                 [ToolboxItem (false)]
567                 [TypeConverter (typeof(ListViewSubItemConverter))]
568                 public class ListViewSubItem
569                 {
570                         private Color back_color;
571                         private Font font;
572                         private Color fore_color;
573                         internal ListViewItem owner;
574                         private string text;
575                         
576                         #region Public Constructors
577                         public ListViewSubItem ()
578                         {
579                         }
580
581                         public ListViewSubItem (ListViewItem owner, string text)
582                                 : this (owner, text, ThemeEngine.Current.ColorWindowText,
583                                         ThemeEngine.Current.ColorWindow,
584                                         ThemeEngine.Current.DefaultFont)
585                         {
586                         }
587
588                         public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
589                                                 Color backColor, Font font)
590                         {
591                                 this.owner = owner;
592                                 this.text = text;
593                                 this.fore_color = foreColor;
594                                 this.back_color = backColor;
595                                 this.font = font;
596                         }
597                         #endregion // Public Constructors
598
599                         #region Public Instance Properties
600                         public Color BackColor {
601                                 get { return back_color; }
602                                 set { 
603                                         back_color = value; 
604                                         Invalidate ();
605                                     }
606                         }
607
608                         [Localizable (true)]
609                         public Font Font {
610                                 get {
611                                         if (font != null)
612                                                 return font;
613                                         else if (owner != null)
614                                                 return owner.Font;
615                                         return font;
616                                 }
617                                 set { 
618                                         font = value; 
619                                         Invalidate ();
620                                     }
621                         }
622
623                         public Color ForeColor {
624                                 get { return fore_color; }
625                                 set { 
626                                         fore_color = value; 
627                                         Invalidate ();
628                                     }
629                         }
630
631                         [Localizable (true)]
632                         public string Text {
633                                 get { return text; }
634                                 set { 
635                                         text = value; 
636                                         Invalidate ();
637                                     }
638                         }
639                         #endregion // Public Instance Properties
640
641                         #region Public Methods
642                         public void ResetStyle ()
643                         {
644                                 font = ThemeEngine.Current.DefaultFont;
645                                 back_color = ThemeEngine.Current.DefaultControlBackColor;
646                                 fore_color = ThemeEngine.Current.DefaultControlForeColor;
647                                 Invalidate ();
648                         }
649
650                         public override string ToString ()
651                         {
652                                 return string.Format ("ListViewSubItem {{0}}", text);
653                         }
654                         #endregion // Public Methods
655
656                         
657                         #region Private Methods
658                         private void Invalidate ()
659                         {
660                                 if (owner == null || owner.owner == null)
661                                         return;
662
663                                 owner.owner.Invalidate ();
664                         }
665                         #endregion // Private Methods
666                 }
667
668                 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
669                 {
670                         private ArrayList list;
671                         internal ListViewItem owner;
672
673                         #region Public Constructors
674                         public ListViewSubItemCollection (ListViewItem owner)
675                         {
676                                 this.owner = owner;
677                                 this.list = new ArrayList ();
678                         }
679                         #endregion // Public Constructors
680
681                         #region Public Properties
682                         [Browsable (false)]
683                         public virtual int Count {
684                                 get { return list.Count; }
685                         }
686
687                         public virtual bool IsReadOnly {
688                                 get { return false; }
689                         }
690
691                         public ListViewSubItem this [int index] {
692                                 get { return (ListViewSubItem) list [index]; }
693                                 set { 
694                                         value.owner = this.owner;
695                                         list [index] = value;
696                                 }
697                         }
698
699                         bool ICollection.IsSynchronized {
700                                 get { return list.IsSynchronized; }
701                         }
702
703                         object ICollection.SyncRoot {
704                                 get { return list.SyncRoot; }
705                         }
706
707                         bool IList.IsFixedSize {
708                                 get { return list.IsFixedSize; }
709                         }
710
711                         object IList.this [int index] {
712                                 get { return this [index]; }
713                                 set {
714                                         if (! (value is ListViewSubItem))
715                                                 throw new ArgumentException ("Not of type ListViewSubItem", "value");
716                                         this [index] = (ListViewSubItem) value;
717                                 }
718                         }
719                         #endregion // Public Properties
720
721                         #region Public Methods
722                         public ListViewSubItem Add (ListViewSubItem item)
723                         {
724                                 item.owner = this.owner;
725                                 list.Add (item);
726                                 return item;
727                         }
728
729                         public ListViewSubItem Add (string text)
730                         {
731                                 ListViewSubItem item = new ListViewSubItem (this.owner, text);
732                                 list.Add (item);
733                                 return item;
734                         }
735
736                         public ListViewSubItem Add (string text, Color foreColor,
737                                                     Color backColor, Font font)
738                         {
739                                 ListViewSubItem item = new ListViewSubItem (this.owner, text,
740                                                                             foreColor, backColor, font);
741                                 list.Add (item);
742                                 return item;
743                         }
744
745                         public void AddRange (ListViewSubItem [] items)
746                         {
747                                 this.Clear ();
748                                 foreach (ListViewSubItem item in items)
749                                         this.Add (item);
750                         }
751
752                         public void AddRange (string [] items)
753                         {
754                                 this.Clear ();
755                                 foreach (string item in items)
756                                         this.Add (item);
757                         }
758
759                         public void AddRange (string [] items, Color foreColor,
760                                               Color backColor, Font font)
761                         {
762                                 this.Clear ();
763                                 foreach (string item in items)
764                                         this.Add (item, foreColor, backColor, font);
765                         }
766
767                         public virtual void Clear ()
768                         {
769                                 list.Clear ();
770                         }
771
772                         public bool Contains (ListViewSubItem item)
773                         {
774                                 return list.Contains (item);
775                         }
776
777                         public virtual IEnumerator GetEnumerator ()
778                         {
779                                 return list.GetEnumerator ();
780                         }
781
782                         void ICollection.CopyTo (Array dest, int index)
783                         {
784                                 list.CopyTo (dest, index);
785                         }
786
787                         int IList.Add (object item)
788                         {
789                                 if (! (item is ListViewSubItem)) {
790                                         throw new ArgumentException ("Not of type ListViewSubItem", "item");
791                                 }
792
793                                 ListViewSubItem sub_item = (ListViewSubItem) item;
794                                 sub_item.owner = this.owner;
795                                 return list.Add (sub_item);
796                         }
797
798                         bool IList.Contains (object subItem)
799                         {
800                                 if (! (subItem is ListViewSubItem)) {
801                                         throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
802                                 }
803
804                                 return this.Contains ((ListViewSubItem) subItem);
805                         }
806
807                         int IList.IndexOf (object subItem)
808                         {
809                                 if (! (subItem is ListViewSubItem)) {
810                                         throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
811                                 }
812
813                                 return this.IndexOf ((ListViewSubItem) subItem);
814                         }
815
816                         void IList.Insert (int index, object item)
817                         {
818                                 if (! (item is ListViewSubItem)) {
819                                         throw new ArgumentException ("Not of type ListViewSubItem", "item");
820                                 }
821
822                                 this.Insert (index, (ListViewSubItem) item);
823                         }
824
825                         void IList.Remove (object item)
826                         {
827                                 if (! (item is ListViewSubItem)) {
828                                         throw new ArgumentException ("Not of type ListViewSubItem", "item");
829                                 }
830
831                                 this.Remove ((ListViewSubItem) item);
832                         }
833
834                         public int IndexOf (ListViewSubItem subItem)
835                         {
836                                 return list.IndexOf (subItem);
837                         }
838
839                         public void Insert (int index, ListViewSubItem item)
840                         {
841                                 item.owner = this.owner;
842                                 list.Insert (index, item);
843                         }
844
845                         public void Remove (ListViewSubItem item)
846                         {
847                                 list.Remove (item);
848                         }
849
850                         public virtual void RemoveAt (int index)
851                         {
852                                 list.RemoveAt (index);
853                         }
854                         #endregion // Public Methods
855                 }
856                 #endregion // Subclasses
857         }
858 }