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