2 // System.Windows.Forms.ListBox
5 // Joel Basson (jstrike@mweb.co.za)
6 // Alberto Fernandez (infjaf00@yahoo.es)
10 using System
.ComponentModel
;
12 using System
.Collections
;
22 namespace System
.Windows
.Forms
24 public class ListBox
: ListControl
26 private ListBox
.ObjectCollection items
;
27 private ListBox
.SelectedIndexCollection selectedIndices
;
28 private ListBox
.SelectedObjectCollection selectedItems
;
32 public const int DefaultItemHeight
= 13;
33 public const int NoMatches
= -1;
36 public ListBox () : base ()
38 items
= new ListBox
.ObjectCollection (this);
39 selectedIndices
= new ListBox
.SelectedIndexCollection (this);
40 selectedItems
= new ListBox
.SelectedObjectCollection (this);
45 public override Color BackColor
{
46 get { throw new NotImplementedException(); }
50 public override System
.Drawing
.Image BackgroundImage
{
51 get { throw new NotImplementedException (); }
56 public BorderStyle BorderStyle
{
57 get { throw new NotImplementedException (); }
62 public int ColumnWidth
{
63 get{ throw new NotImplementedException (); }
66 throw new ArgumentException ("ColumnWidth must be equal or greather than 0");
75 protected override CreateParams CreateParams
{
76 get { throw new NotImplementedException (); }
78 protected override Size DefaultSize
{
79 get { return new Size (120,96); }
82 // Default = DrawMode.Normal
83 public virtual DrawMode DrawMode
{
84 get { return DrawMode.Normal; }
86 if (! Enum
.IsDefined (typeof (DrawMode
), value))
87 throw new InvalidEnumArgumentException ("");
88 throw new NotImplementedException();
92 public override Color ForeColor
{
93 get { throw new NotImplementedException (); }
98 public int HorizontalExtent
{
99 get { throw new NotImplementedException (); }
100 set { throw new NotImplementedException (); }
103 public bool HorizontalScrollbar
{
104 get { throw new NotImplementedException (); }
108 public bool IntegralHeight
{
109 get { throw new NotImplementedException (); }
113 public virtual int ItemHeight
{
114 get { throw new NotImplementedException (); }
118 public ListBox
.ObjectCollection Items
{
119 get { return items; }
123 public bool MultiColumn
{
124 get { return false; }
128 public int PreferredHeight
{
129 get { throw new NotImplementedException (); }
132 public override RightToLeft RightToLeft
{
133 get { throw new NotImplementedException (); }
137 public bool ScrollAlwaysVisible
{
138 get { throw new NotImplementedException (); }
142 public override int SelectedIndex
{
143 get { throw new NotImplementedException (); }
144 set { throw new NotImplementedException (); }
147 public ListBox
.SelectedIndexCollection SelectedIndices
{
148 get { return selectedIndices; }
151 public object SelectedItem
{
152 get { throw new NotImplementedException (); }
153 set { throw new NotImplementedException (); }
156 public ListBox
.SelectedObjectCollection SelectedItems
{
157 get { return selectedItems; }
160 public virtual SelectionMode SelectionMode
{
161 get { throw new NotImplementedException (); }
166 get { return sorted; }
174 public override string Text
{
175 get { throw new NotImplementedException (); }
176 set { throw new NotImplementedException (); }
179 public int TopIndex
{
180 get { throw new NotImplementedException (); }
181 set { throw new NotImplementedException (); }
184 public bool UseTabStops
{
185 get { throw new NotImplementedException (); }
186 set { throw new NotImplementedException (); }
191 protected virtual void AddItemsCore(object[] value)
195 public void BeginUpdate()
199 public void ClearSelected()
203 protected virtual ObjectCollection
CreateItemCollection()
205 throw new NotImplementedException();
208 public void EndUpdate()
212 public int FindString (string s
)
214 throw new NotImplementedException();
217 public int FindString (string s
, int startIndex
)
219 throw new NotImplementedException();
222 public int FindStringExact (string s
)
224 throw new NotImplementedException ();
227 public int FindStringExact (string s
, int startIndex
)
229 throw new NotImplementedException();
232 public int GetItemHeight(int index
)
234 throw new NotImplementedException ();
237 public Rectangle
GetItemRectangle(int index
)
239 throw new NotImplementedException ();
242 public bool GetSelected(int index
)
244 throw new NotImplementedException ();
247 public int IndexFromPoint(Point p
)
249 throw new NotImplementedException ();
252 public int IndexFromPoint(int x
, int y
)
254 throw new NotImplementedException ();
257 protected override void OnChangeUICues(UICuesEventArgs e
)
259 throw new NotImplementedException ();
262 protected override void OnDataSourceChanged(EventArgs e
)
264 throw new NotImplementedException ();
267 protected override void OnDisplayMemberChanged(EventArgs e
)
271 protected virtual void OnDrawItem(DrawItemEventArgs e
)
275 protected override void OnFontChanged(EventArgs e
)
279 protected override void OnHandleCreated(EventArgs e
)
283 protected override void OnHandleDestroyed(EventArgs e
)
287 protected virtual void OnMeasureItem(MeasureItemEventArgs e
)
291 protected override void OnParentChanged(EventArgs e
)
295 protected override void OnResize(EventArgs e
)
299 protected override void OnSelectedIndexChanged(EventArgs e
)
303 protected override void OnSelectedValueChanged(EventArgs e
)
307 public override void Refresh()
309 ListStore store
= new ListStore (typeof (string));
310 foreach (Object o
in Items
){
311 Value
value = new Value (o
);
312 TreeIter iter
= store
.Append();
313 store
.SetValue (iter
, 0, value);
315 (Widget
as Gtk
.TreeView
).Model
= store
;
318 protected override void RefreshItem(int index
)
322 protected override void SetBoundsCore(int x
,int y
, int width
, int height
, BoundsSpecified specified
)
326 protected override void SetItemCore(int index
, object value)
330 protected override void SetItemsCore(IList
value)
334 public void SetSelected(int index
, bool value)
338 protected virtual void Sort()
342 public override string ToString()
344 return base.ToString();
347 protected virtual void WmReflectCommand(ref Message m
)
351 protected override void WndProc(ref Message m
)
355 public new event EventHandler BackgroundImageChanged
;
356 public new event EventHandler Click
;
357 public event DrawItemEventHandler DrawItem
;
358 public event MeasureItemEventHandler MeasureItem
;
359 public new event PaintEventHandler Paint
;
360 public event EventHandler SelectedIndexChanged
;
361 public new event EventHandler TextChanged
;
368 public class ObjectCollection
: IList
, ICollection
, IEnumerable
370 private ListBox owner
;
371 private ArrayList list
;
373 public ObjectCollection(ListBox owner
)
376 this.list
= new ArrayList();
378 public ObjectCollection(ListBox owner
, object[] value) : this(owner
)
383 public ObjectCollection(ListBox owner
, ObjectCollection
value) : this (owner
)
388 public virtual int Count
{
389 get { return list.Count; }
392 public virtual bool IsReadOnly
{
393 get { return false; }
396 public virtual object this[int index
] {
397 get { return list[index]; }
398 set { throw new NotImplementedException(); }
401 bool ICollection
.IsSynchronized
{
402 get { return list.IsSynchronized; }
405 object ICollection
.SyncRoot
{
406 get { return list.SyncRoot; }
409 bool IList
.IsFixedSize
{
410 get { return list.IsFixedSize; }
414 public int Add(object item
)
416 // FIXME: Implement sorted insert, if ListBox.Sorted == true,
417 int ret
= list
.Add (item
);
422 /*public class ItemCollection {
425 TreeIter iter = new TreeIter ();
427 public ItemCollection (ListBox owner){
429 owner.store = new ListStore (typeof (string));
432 public void Add(String items){
434 Value value = new Value(items);
435 iter = owner.store.Append ();
436 owner.store.SetValue (iter, 0, value);
442 public void AddRange(object[] items
)
444 // FIXME: should stop Control refresh until added finished
445 foreach (object o
in items
)
450 public void AddRange(ListBox
.ObjectCollection
value)
452 list
.AddRange (value);
456 public virtual void Clear()
461 public virtual bool Contains(object value)
463 return list
.Contains (value);
466 public void CopyTo(object[] dest
, int arrayIndex
)
468 list
.CopyTo (dest
, arrayIndex
);
471 public virtual IEnumerator
GetEnumerator()
473 return list
.GetEnumerator();
476 void ICollection
.CopyTo( Array dest
, int index
)
478 list
.CopyTo(dest
, index
);
482 int IList
.Add( object item
)
484 return this.Add (item
);
487 public virtual int IndexOf(object value)
489 return list
.IndexOf(value);
493 public virtual void Insert( int index
, object item
)
495 list
.Insert (index
, item
);
499 public virtual void Remove(object value)
505 public virtual void RemoveAt(int index
)
507 list
.RemoveAt (index
);
512 public class SelectedIndexCollection
: IList
, ICollection
, IEnumerable
515 private ListBox owner
;
516 private ArrayList list
;
517 public bool IsFixedSize
{
518 get { return false; }
521 public bool IsSynchronized
{
522 get { return list.IsSynchronized; }
524 public object SyncRoot
{
525 get { return list.SyncRoot; }
528 public SelectedIndexCollection(ListBox owner
)
531 list
= new ArrayList ();
534 public virtual int Count
{
535 get { return list.Count; }
537 public virtual bool IsReadOnly
{
538 get { return false; }
541 public object this[int index
] {
542 get { return list[index]; }
543 set { throw new NotImplementedException (); }
547 public bool Contains(int selectedIndex
)
549 throw new NotImplementedException ();
553 public virtual void CopyTo(Array dest
, int index
)
555 list
.CopyTo(dest
, index
);
556 //throw new NotImplementedException ();
560 public virtual IEnumerator
GetEnumerator()
562 return list
.GetEnumerator();
563 //throw new NotImplementedException ();
568 int IList
.Add(object value)
571 throw new NotImplementedException ();
578 //throw new NotImplementedException ();
582 bool IList
.Contains(object selectedIndex
)
584 throw new NotImplementedException ();
587 int IList
.IndexOf(object selectedIndex
)
589 return list
.IndexOf (selectedIndex
);
593 void IList
.Insert(int index
, object value)
595 throw new NotImplementedException ();
599 void IList
.Remove(object value)
601 throw new NotImplementedException ();
605 void IList
.RemoveAt(int index
)
607 throw new NotImplementedException ();
611 public int IndexOf(int selectedIndex
)
613 throw new NotImplementedException ();
620 public class SelectedObjectCollection
: IList
, ICollection
, IEnumerable
624 private ListBox owner
;
625 private ArrayList list
;
627 public bool IsFixedSize
{
628 get { return false; }
631 public bool IsSynchronized
{
632 get { return list.IsSynchronized; }
634 public object SyncRoot
{
635 get { return list.SyncRoot; }
638 public SelectedObjectCollection(ListBox owner
)
641 list
= new ArrayList();
644 public virtual int Count
{
645 get { return list.Count; }
648 public virtual bool IsReadOnly
{
649 get { return list.IsReadOnly; }
652 public virtual object this[int index
] {
653 get { return list[index]; }
654 set { throw new NotImplementedException (); }
657 public virtual bool Contains(object selectedObject
)
659 return list
.Contains (selectedObject
);
662 public virtual void CopyTo(Array dest
, int index
)
664 list
.CopyTo(dest
, index
);
667 public virtual IEnumerator
GetEnumerator()
669 return list
.GetEnumerator();
673 int IList
.Add(object value)
675 throw new NotImplementedException ();
682 throw new NotImplementedException ();
687 void IList
.Insert(int index
, object value)
689 throw new NotImplementedException ();
694 void IList
.Remove(object value)
696 throw new NotImplementedException ();
701 void IList
.RemoveAt(int index
)
703 throw new NotImplementedException ();
707 public virtual int IndexOf(object selectedObject
)
709 throw new NotImplementedException ();
714 internal override Gtk
.Widget
CreateWidget () {
716 ListStore store
= new ListStore (typeof (string));
717 TreeView tv
= new TreeView (store
);
718 tv
.HeadersVisible
= false;
719 tv
.HeadersClickable
= false;
720 tv
.EnableSearch
= false;
721 TreeViewColumn NameCol
= new TreeViewColumn ();
722 CellRenderer NameRenderer
= new CellRendererText ();
723 NameCol
.Title
= "Name";
724 NameCol
.PackStart (NameRenderer
, true);
725 NameCol
.AddAttribute (NameRenderer
, "text", 0);
726 tv
.AppendColumn (NameCol
);
733 //ListStore store = null;
734 //TreeIter iter = new TreeIter ();
736 //public ItemCollection Items;
737 //ListStore store = new ListStore ((int)TypeFundamentals.TypeString);
739 /*public class ItemCollection {
742 TreeIter iter = new TreeIter ();
744 public ItemCollection (ListBox owner){
747 owner.store = new ListStore (typeof (string));
751 public void Add(String items){
753 Value value = new Value(items);
754 iter = owner.store.Append ();
755 owner.store.SetValue (iter, 0, value);