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