Copied remotely
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / ListViewItem.cs
1 //
2 // System.Windows.Forms.ListViewItem.cs
3 //
4 // Author:
5 //   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
6 //   Dennis Hayes (dennish@Raytek.com)
7 //       Implemented by Jordi Mas i Hernàndez (jmas@softcatala.org)
8 //
9 // (C) 2002/3 Ximian, Inc
10 //
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32 using System.Runtime.Serialization;
33 using System.Drawing;
34 using System.Collections;
35 using System.Runtime.InteropServices;
36  
37 namespace System.Windows.Forms 
38 {
39         // <summary>
40         // </summary>
41         [Serializable]
42         public class ListViewItem :  ICloneable, ISerializable 
43         {               
44                 private ListView container = null;
45                 private string  text;
46                 private ListViewSubItemCollection       colSubItem = null;
47                 private int index;
48                 private bool bSelected = false;
49                 private bool useItemStyleForSubItems = true;
50                 private bool bChecked = false;
51                 private bool bFocused = false;
52                 private Color backColor = SystemColors.Window;
53                 private Color foreColor = SystemColors.WindowText;
54                 private object tag = null;
55                 
56
57                 //
58                 //  --- Constructor
59                 //                                      
60                 protected void CommonConstructor(){
61                         colSubItem = new        ListViewSubItemCollection(this);
62                 }
63                 
64                 public ListViewItem(){                  
65                         CommonConstructor();                    
66                 }
67                 
68                 public ListViewItem(string str) {
69                         Console.WriteLine("ListViewItem.ListViewItem str");                                     
70                         CommonConstructor();                    
71                         text = str;
72                 }
73                 
74                 public ListViewItem(string[] strings){  // An array of strings that represent the subitems of the new item.
75                 
76                         Console.WriteLine("ListView.ListView strings");                         
77                         CommonConstructor();
78                         
79                         if (strings.Length>0)                   
80                                 text = strings[0];
81                                 
82                         if (strings.Length>1)                   
83                         {
84                                 for (int i=1; i<strings.Length; i++)
85                                         colSubItem.Add(strings[i]);             
86                         }
87                 }
88
89                 
90                 public ListViewItem(ListViewItem.ListViewSubItem[] subItems){
91                         
92                         CommonConstructor();
93                         for (int i=0; i<subItems.Length; i++)
94                                         colSubItem.Add(subItems[i]);            
95                 }
96
97                 
98                 public ListViewItem(string str, int imageIndex){                                                        
99                                 //TODO: Image index
100                                 CommonConstructor();
101                                 text = str;
102                 }
103
104                 
105                 public ListViewItem(string[] strings, int imageIndex){                  
106                         //TODO: Image index
107                         CommonConstructor();
108                         
109                         if (strings.Length>0)                   
110                                 text = strings[0];
111                                 
112                         if (strings.Length>1)                   
113                         {
114                                 for (int i=1; i<strings.Length; i++)
115                                         colSubItem.Add(strings[i]);             
116                         }
117                 }
118
119                 
120                 public ListViewItem(string[] strings, int imageIndex,  Color fColor, Color  bColor, Font font){
121                         
122                         //TODO: Image index
123                         CommonConstructor();
124                         
125                         if (strings.Length>0){
126                                 
127                                 text = strings[0];
128                                 BackColor = bColor;
129                                 ForeColor = fColor;
130                         }
131                                 
132                         if (strings.Length>1){
133                                 ListViewSubItem subItem;
134                                 
135                                 for (int i=1; i<strings.Length; i++){
136                                         subItem = colSubItem.Add(strings[i]);           
137                                         subItem.BackColor = bColor;
138                                         subItem.ForeColor = fColor;
139                                 }
140                         }                       
141                         
142                 }
143
144                 [MonoTODO]
145             public ListViewItem (SerializationInfo info, StreamingContext context)
146                 {
147                         throw new NotImplementedException ();
148                 }
149
150                 [MonoTODO]
151                 public void GetObjectData(SerializationInfo info, StreamingContext context)
152                 {
153                         throw new NotImplementedException ();
154                 }
155                 
156
157                 //
158                 //  --- Public Properties
159                 //              
160                 public Color BackColor {
161                         get {return backColor;}
162                         set {backColor = value;}
163                 }
164
165                 
166                 public Rectangle Bounds {
167                         get {return     container.GetItemBoundInCtrl(Index);}
168                 }
169                 
170                 public bool Checked {
171                         get {return bChecked;}
172                         set {bChecked = value;}
173                 }
174
175                 
176                 public bool Focused {
177                         get {return bFocused;}
178                         set {bFocused = value;}
179                 }
180
181                 [MonoTODO]
182                 public Font Font {
183                         get { // see Control.DefaultFont
184                                 throw new NotImplementedException ();
185                         }
186                         set {
187                                 //FIXME:
188                         }
189                 }
190
191                 public Color ForeColor {
192                         get {return foreColor;}
193                         set {foreColor = value;}
194                 }
195                 [MonoTODO]
196                 public int ImageIndex {
197                         get {
198                                 throw new NotImplementedException ();
199                         }
200                         set {
201                                 //FIXME:
202                         }
203                 }
204                 [MonoTODO]
205                 public ImageList ImageList {
206                         get {
207                                 throw new NotImplementedException ();
208                         }
209                 }
210                 
211                 public int Index {
212                         get {return index;}
213                 }
214                 
215                                                 
216                 public ListView ListView {
217                         get {return container;}                                         
218                 }
219                 
220                 public bool Selected {
221                         get {return bSelected;}                                         
222                         set {bSelected=value;}                                                                  
223                 }
224                 [MonoTODO]
225                 public int StateImageIndex  {
226                         get {
227                                 throw new NotImplementedException ();
228                         }
229                         set {
230                                 //FIXME:
231                         }
232                 }
233                 
234                 public ListViewSubItemCollection SubItems {
235                         get {return colSubItem;}
236                 }
237                 
238
239                 public object Tag {
240                         get {return tag;}
241                         set {tag = value;}
242                 }
243                 
244                 public string Text      {
245                         get { return text;}
246                         set { text = value;}            
247                         
248                 }
249                 
250                 public bool UseItemStyleForSubItems {
251                         get { return useItemStyleForSubItems;}
252                         set { useItemStyleForSubItems = value;}         
253                 }
254                 
255                 //
256                 //  --- Private Methods
257                 //              
258                 internal ListView Container {                   
259                         set{container=value;}
260                 }                               
261                 
262                 internal int CtrlIndex{                                 
263                         set{index=value;}
264                 }               
265                 
266                 //
267                 //  --- Public Methods
268                 //              
269                 public void BeginEdit(){
270                         
271                         if (!container.LabelEdit)
272                                 throw new InvalidOperationException("LabelEdit disabled");
273                         
274                         container.LabelEditInCtrl(Index);
275                         
276                 }
277                 [MonoTODO]
278                 public object Clone()
279                 {
280                         throw new NotImplementedException ();
281                 }
282                 [MonoTODO]
283                 public virtual void EnsureVisible()
284                 {
285                         //FIXME:
286                 }
287                 [MonoTODO]
288                 public Rectangle GetBounds(ItemBoundsPortion portion)
289                 {
290                         throw new NotImplementedException ();
291                 }
292                 [MonoTODO]
293                 public void Remove()
294                 {
295                         //FIXME:
296                 }
297                 [MonoTODO]
298                 public override string ToString()
299                 {
300                         //FIXME:
301                         return base.ToString();
302                 }
303
304                 //
305                 //  --- Protected Methods
306                 //
307                 [MonoTODO]
308                 protected virtual void Deserialize(SerializationInfo info, StreamingContext context)
309                 {
310                         //FIXME:
311                 }
312                 [MonoTODO]
313                 protected virtual void Serialize(SerializationInfo info, StreamingContext context)
314                 {
315                         //FIXME:
316                 }
317                 
318                 // ISerializable.method:
319                 [MonoTODO]
320                 void ISerializable.GetObjectData(SerializationInfo info,StreamingContext context) 
321                 {
322                         throw new NotImplementedException ();
323                 }
324
325                 //
326                 // System.Windows.Forms.ListViewItem.ListViewSubItemCollection.cs
327                 //
328                 // Author:
329                 //   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
330                 //   stub ammended by Jaak Simm (jaaksimm@firm.ee)
331                 //       Implemented by Jordi Mas i Hernàndez (jmas@softcatala.org)
332                 //
333                 // (C) 2002/3 Ximian, Inc
334                 //
335                 // <summary>
336                 // </summary>           
337                 [Serializable]
338                 public class ListViewSubItemCollection :  IList, ICollection, IEnumerable 
339                 {
340                         
341                         private ArrayList collection = new ArrayList();
342                         private ListViewItem owner = null;
343                         
344                         
345                         //
346                         //  --- Constructor
347                         //              
348                         public ListViewSubItemCollection(ListViewItem item) {
349                                 owner = item;
350                         }                       
351                         
352                         //
353                         //  --- Public Properties
354                         //                      
355                         public int Count {
356                                 get { return collection.Count; }
357                         }                       
358                         
359                         public bool IsReadOnly 
360                         {
361                                 get { return collection.IsReadOnly; }
362                         }               
363                         
364                         public ListViewSubItem this[int index] 
365                         {
366                                 get { 
367                                         if (index<0 || index>=Count) throw  new  ArgumentOutOfRangeException();                                 
368                                                 
369                                         return (ListViewSubItem) collection[index];
370                                 }
371                                 set { 
372                                         if (index<0 || index>=Count) throw  new  ArgumentOutOfRangeException();                                 
373                                         collection[index] = value;
374                                 }                               
375                         }       
376                         
377                         /// --- ICollection properties ---
378                         bool IList.IsFixedSize 
379                         {
380                                 get { return collection.IsFixedSize; }
381                         }
382                         
383                         object IList.this[int index] 
384                         {
385                                 get { return collection[index]; }
386                                 set { collection[index] = value; }
387                         }
388         
389                         object ICollection.SyncRoot 
390                         {
391                                 get { return collection.SyncRoot; }
392                         }
393         
394                         bool ICollection.IsSynchronized 
395                         {
396                                 get { return collection.IsSynchronized; }
397                         }
398                         
399                         //
400                         //  --- Public Methods
401                         //                      
402                         public ListViewSubItem Add(ListViewItem.ListViewSubItem item) 
403                         {                                       
404                                 if (item.ListViewItem==null) item.ListViewItem = owner;
405                                 int nIdx = collection.Add(item);                                                                                                
406                                 return (ListViewSubItem)collection[nIdx]; 
407                         } 
408                         
409                         
410                         public ListViewSubItem Add(string text) 
411                         {                               
412                                 ListViewItem.ListViewSubItem item = new ListViewSubItem(owner, text);                                                   
413                                 return Add(item);
414                         }                       
415                         
416                         public ListViewSubItem Add(string text,Color fColor,Color bColor,Font font) 
417                         {
418                                 ListViewSubItem item = new ListViewSubItem(owner, text);
419                                 item.ForeColor = fColor;
420                                 item.BackColor = bColor;
421                                 return Add(item);
422                         }
423                         
424                         
425                         public void AddRange(ListViewItem.ListViewSubItem[] values)     {
426                                 
427                                 for (int i=0; i<values.Length; i++)     
428                                 {
429                                         if (values[i].ListViewItem==null) values[i].ListViewItem = owner;
430                                         Add(values[i]);                                                                         
431                                 }
432                         }                       
433                         
434                         public void AddRange(string[] values) {
435                                 
436                                 for (int i=0; i<values.Length; i++)     
437                                         Add(values[i]);                                                                         
438                         }
439                         
440                         
441                         public void AddRange(string[] items,Color fColor, Color bColor, Font font) {
442                                 
443                                 for (int i=0; i<items.Length; i++)      
444                                         Add(items[i], fColor, bColor, font);                                                                                                            
445                         }
446                         
447                         [MonoTODO]
448                         public void Clear() 
449                         {
450                                 //FIXME:
451                         }                       
452                         
453                         public bool Contains(ListViewItem.ListViewSubItem subItem)      {
454                                 
455                                 return collection.Contains(subItem);
456                         }
457                         
458                         public IEnumerator GetEnumerator()      {                               
459                                 return collection.GetEnumerator();
460                         }
461                         
462                         [MonoTODO]
463                         void ICollection.CopyTo(Array dest,int index) 
464                         {
465                                 throw new NotImplementedException ();
466                         }
467                         
468                         [MonoTODO]
469                         int IList.Add(object item) 
470                         {
471                                 throw new NotImplementedException ();
472                         }
473                         
474                         [MonoTODO]
475                         bool IList.Contains(object subItem) 
476                         {
477                                 throw new NotImplementedException ();
478                         }
479                         
480                         [MonoTODO]
481                         int IList.IndexOf(object subItem) 
482                         {
483                                 throw new NotImplementedException ();
484                         }
485                         
486                         [MonoTODO]
487                         void IList.Insert(int index,object item) 
488                         {
489                                 //FIXME:
490                         }
491                         
492                         [MonoTODO]
493                         void IList.Remove(object item) 
494                         {
495                                 //FIXME:
496                         }
497                         
498                         [MonoTODO]
499                         public int IndexOf(ListViewItem.ListViewSubItem subItem) 
500                         {
501                                 throw new NotImplementedException();
502                         }
503                         
504                         [MonoTODO]
505                         public void Insert(int index,ListViewItem.ListViewSubItem item) 
506                         {
507                                 //FIXME:
508                         }
509                         
510                         [MonoTODO]
511                         public void Remove(ListViewItem.ListViewSubItem item) 
512                         {
513                                 //FIXME:
514                         }
515                         
516                         [MonoTODO]
517                         public void RemoveAt(int index) 
518                         {
519                                 //FIXME:
520                         }
521                 }
522         //
523         // System.Windows.Forms.ListViewItem.ListViewSubItem.cs
524         //
525         // Author:
526         //   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
527         //
528         // (C) 2002 Ximian, Inc
529         //
530         // <summary>
531         // </summary>
532
533         public class ListViewSubItem  
534         {
535                 
536                 private string  sText;
537                 private ListViewItem owner = null;
538                 private Color backColor = SystemColors.Window;
539                 private Color foreColor = SystemColors.WindowText;
540                 private Font font;
541                 
542                         
543                 internal ListViewItem ListViewItem{                             
544                         get{return owner;}
545                         set{owner=value;}
546                 }
547                         
548                         
549                 //
550                 //  --- Constructor
551                 //
552                 public ListViewSubItem(){
553                         
554                 }
555                 
556                 public ListViewSubItem(ListViewItem item, string str){
557                         
558                         owner = item;
559                         sText = str;
560                 }
561                 
562                 public ListViewSubItem(ListViewItem item, string str, Color foreClr, Color backClr, Font fnt){
563                         
564                         owner = item;
565                         sText = str;
566                         BackColor = backClr;
567                         ForeColor = foreClr;                    
568                         font = fnt;
569                 }
570         
571                 //
572                 //  --- Public Properties
573                 //
574                 public Color BackColor {
575                         get {return backColor;}
576                         set {backColor = value;}
577                 }
578
579                 
580                 public Font Font {
581                         get {return font;}
582                         set {font = value;}
583                 }
584                 
585                 public Color ForeColor {
586                         get {return foreColor;}
587                         set {foreColor = value;}
588                 }               
589                 
590                 public string Text {
591                         get {return sText;}
592                         set {sText=value;}
593                 }
594
595                 //
596                 //  --- Public Methods
597                 //
598                 [MonoTODO]
599                 public override bool Equals(object obj)
600                 {
601                         //FIXME:
602                         return base.Equals(obj);
603                 }
604                 [MonoTODO]
605                 public override int GetHashCode() {
606                         //FIXME add our proprities
607                         return base.GetHashCode();
608                 }
609                 [MonoTODO]
610                 public void ResetStyle()
611                 {
612                         //FIXME:
613                 }
614                 [MonoTODO]
615                 public override string ToString()
616                 {
617                         //FIXME:
618                         return base.ToString();
619                 }
620                 }
621         }
622 }
623
624