2 // System.Windows.Forms.ListViewItem.cs
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)
9 // (C) 2002/3 Ximian, Inc
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
32 using System.Runtime.Serialization;
34 using System.Collections;
35 using System.Runtime.InteropServices;
37 namespace System.Windows.Forms
42 public class ListViewItem : ICloneable, ISerializable
44 private ListView container = null;
46 private ListViewSubItemCollection colSubItem = null;
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;
60 protected void CommonConstructor(){
61 colSubItem = new ListViewSubItemCollection(this);
64 public ListViewItem(){
68 public ListViewItem(string str) {
69 Console.WriteLine("ListViewItem.ListViewItem str");
74 public ListViewItem(string[] strings){ // An array of strings that represent the subitems of the new item.
76 Console.WriteLine("ListView.ListView strings");
84 for (int i=1; i<strings.Length; i++)
85 colSubItem.Add(strings[i]);
90 public ListViewItem(ListViewItem.ListViewSubItem[] subItems){
93 for (int i=0; i<subItems.Length; i++)
94 colSubItem.Add(subItems[i]);
98 public ListViewItem(string str, int imageIndex){
105 public ListViewItem(string[] strings, int imageIndex){
109 if (strings.Length>0)
112 if (strings.Length>1)
114 for (int i=1; i<strings.Length; i++)
115 colSubItem.Add(strings[i]);
120 public ListViewItem(string[] strings, int imageIndex, Color fColor, Color bColor, Font font){
125 if (strings.Length>0){
132 if (strings.Length>1){
133 ListViewSubItem subItem;
135 for (int i=1; i<strings.Length; i++){
136 subItem = colSubItem.Add(strings[i]);
137 subItem.BackColor = bColor;
138 subItem.ForeColor = fColor;
145 public ListViewItem (SerializationInfo info, StreamingContext context)
147 throw new NotImplementedException ();
151 public void GetObjectData(SerializationInfo info, StreamingContext context)
153 throw new NotImplementedException ();
158 // --- Public Properties
160 public Color BackColor {
161 get {return backColor;}
162 set {backColor = value;}
166 public Rectangle Bounds {
167 get {return container.GetItemBoundInCtrl(Index);}
170 public bool Checked {
171 get {return bChecked;}
172 set {bChecked = value;}
176 public bool Focused {
177 get {return bFocused;}
178 set {bFocused = value;}
183 get { // see Control.DefaultFont
184 throw new NotImplementedException ();
191 public Color ForeColor {
192 get {return foreColor;}
193 set {foreColor = value;}
196 public int ImageIndex {
198 throw new NotImplementedException ();
205 public ImageList ImageList {
207 throw new NotImplementedException ();
216 public ListView ListView {
217 get {return container;}
220 public bool Selected {
221 get {return bSelected;}
222 set {bSelected=value;}
225 public int StateImageIndex {
227 throw new NotImplementedException ();
234 public ListViewSubItemCollection SubItems {
235 get {return colSubItem;}
250 public bool UseItemStyleForSubItems {
251 get { return useItemStyleForSubItems;}
252 set { useItemStyleForSubItems = value;}
256 // --- Private Methods
258 internal ListView Container {
259 set{container=value;}
262 internal int CtrlIndex{
267 // --- Public Methods
269 public void BeginEdit(){
271 if (!container.LabelEdit)
272 throw new InvalidOperationException("LabelEdit disabled");
274 container.LabelEditInCtrl(Index);
278 public object Clone()
280 throw new NotImplementedException ();
283 public virtual void EnsureVisible()
288 public Rectangle GetBounds(ItemBoundsPortion portion)
290 throw new NotImplementedException ();
298 public override string ToString()
301 return base.ToString();
305 // --- Protected Methods
308 protected virtual void Deserialize(SerializationInfo info, StreamingContext context)
313 protected virtual void Serialize(SerializationInfo info, StreamingContext context)
318 // ISerializable.method:
320 void ISerializable.GetObjectData(SerializationInfo info,StreamingContext context)
322 throw new NotImplementedException ();
326 // System.Windows.Forms.ListViewItem.ListViewSubItemCollection.cs
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)
333 // (C) 2002/3 Ximian, Inc
338 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
341 private ArrayList collection = new ArrayList();
342 private ListViewItem owner = null;
348 public ListViewSubItemCollection(ListViewItem item) {
353 // --- Public Properties
356 get { return collection.Count; }
359 public bool IsReadOnly
361 get { return collection.IsReadOnly; }
364 public ListViewSubItem this[int index]
367 if (index<0 || index>=Count) throw new ArgumentOutOfRangeException();
369 return (ListViewSubItem) collection[index];
372 if (index<0 || index>=Count) throw new ArgumentOutOfRangeException();
373 collection[index] = value;
377 /// --- ICollection properties ---
378 bool IList.IsFixedSize
380 get { return collection.IsFixedSize; }
383 object IList.this[int index]
385 get { return collection[index]; }
386 set { collection[index] = value; }
389 object ICollection.SyncRoot
391 get { return collection.SyncRoot; }
394 bool ICollection.IsSynchronized
396 get { return collection.IsSynchronized; }
400 // --- Public Methods
402 public ListViewSubItem Add(ListViewItem.ListViewSubItem item)
404 if (item.ListViewItem==null) item.ListViewItem = owner;
405 int nIdx = collection.Add(item);
406 return (ListViewSubItem)collection[nIdx];
410 public ListViewSubItem Add(string text)
412 ListViewItem.ListViewSubItem item = new ListViewSubItem(owner, text);
416 public ListViewSubItem Add(string text,Color fColor,Color bColor,Font font)
418 ListViewSubItem item = new ListViewSubItem(owner, text);
419 item.ForeColor = fColor;
420 item.BackColor = bColor;
425 public void AddRange(ListViewItem.ListViewSubItem[] values) {
427 for (int i=0; i<values.Length; i++)
429 if (values[i].ListViewItem==null) values[i].ListViewItem = owner;
434 public void AddRange(string[] values) {
436 for (int i=0; i<values.Length; i++)
441 public void AddRange(string[] items,Color fColor, Color bColor, Font font) {
443 for (int i=0; i<items.Length; i++)
444 Add(items[i], fColor, bColor, font);
453 public bool Contains(ListViewItem.ListViewSubItem subItem) {
455 return collection.Contains(subItem);
458 public IEnumerator GetEnumerator() {
459 return collection.GetEnumerator();
463 void ICollection.CopyTo(Array dest,int index)
465 throw new NotImplementedException ();
469 int IList.Add(object item)
471 throw new NotImplementedException ();
475 bool IList.Contains(object subItem)
477 throw new NotImplementedException ();
481 int IList.IndexOf(object subItem)
483 throw new NotImplementedException ();
487 void IList.Insert(int index,object item)
493 void IList.Remove(object item)
499 public int IndexOf(ListViewItem.ListViewSubItem subItem)
501 throw new NotImplementedException();
505 public void Insert(int index,ListViewItem.ListViewSubItem item)
511 public void Remove(ListViewItem.ListViewSubItem item)
517 public void RemoveAt(int index)
523 // System.Windows.Forms.ListViewItem.ListViewSubItem.cs
526 // stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
528 // (C) 2002 Ximian, Inc
533 public class ListViewSubItem
536 private string sText;
537 private ListViewItem owner = null;
538 private Color backColor = SystemColors.Window;
539 private Color foreColor = SystemColors.WindowText;
543 internal ListViewItem ListViewItem{
552 public ListViewSubItem(){
556 public ListViewSubItem(ListViewItem item, string str){
562 public ListViewSubItem(ListViewItem item, string str, Color foreClr, Color backClr, Font fnt){
572 // --- Public Properties
574 public Color BackColor {
575 get {return backColor;}
576 set {backColor = value;}
585 public Color ForeColor {
586 get {return foreColor;}
587 set {foreColor = value;}
596 // --- Public Methods
599 public override bool Equals(object obj)
602 return base.Equals(obj);
605 public override int GetHashCode() {
606 //FIXME add our proprities
607 return base.GetHashCode();
610 public void ResetStyle()
615 public override string ToString()
618 return base.ToString();