**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / ListBox.cs
blobc63235c9e207f03ca5433e9032ec5c058f297a32
1 //
2 // System.Windows.Forms.ListBox.cs
3 //
4 // Author:
5 // stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Alexandre Pigolkine (pigolkine@gmx.de)
8 //
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:
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.
32 using System.Collections;
33 using System.Drawing;
34 using System.Runtime.InteropServices;
36 namespace System.Windows.Forms {
38 // <summary>
39 // </summary>
41 public class ListBox : ListControl {
44 // --- Constructor
46 [MonoTODO]
47 public ListBox() {
48 SubClassWndProc_ = true;
49 BorderStyle_ = BorderStyle.Fixed3D;
50 BackColor = SystemColors.Window;
51 controlStyles_ |= ControlStyles.AllPaintingInWmPaint;
55 // --- Protected Fields
57 internal int ColumnWidth_ = 0; // The columns will have default width
58 internal bool IntegralHeight_ = true;
59 internal ListBox.ObjectCollection Items_ = null;
60 internal ListBox.SelectedIndexCollection SelectedIndices_ = null;
61 internal ListBox.SelectedObjectCollection SelectedObjects_ = null;
62 internal DrawMode DrawMode_ = DrawMode.Normal;
63 internal bool UseTabStops_ = false;
64 internal bool MultiColumn_ = false;
65 int selectedIndex = -1;
66 internal bool Sorted_ = false;
67 internal int prevSelectedIndex = -1;
68 internal BorderStyle BorderStyle_;
71 // --- Public Fields
73 public const int DefaultItemHeight = 13;//correct
74 public const int NoMatches = -1 ;//correct
78 // --- Public Properties
80 [MonoTODO]
81 public override Color ForeColor {
82 get {
83 //FIXME:
84 return base.ForeColor;
86 set {
87 //FIXME:
88 base.ForeColor = value;
92 [MonoTODO]
93 public override Color BackColor {
94 get {
95 //FIXME:
96 return base.BackColor;
98 set {
99 //FIXME:
100 base.BackColor = value;
103 [MonoTODO]
104 public override Image BackgroundImage {
105 get {
106 //FIXME:
107 return base.BackgroundImage;
109 set {
110 //FIXME:
111 base.BackgroundImage = value;
115 public BorderStyle BorderStyle {
116 get {
117 return BorderStyle_;
119 set {
120 if( BorderStyle_ != value) {
121 BorderStyle_ = value;
122 if( IsHandleCreated) {
129 [MonoTODO]
130 public int HorizontalExtent {
131 get {
132 throw new NotImplementedException ();
134 set {
135 //Fixme
138 public bool MultiColumn {
139 get {
140 return MultiColumn_;
142 set {
143 if( MultiColumn_ != value) {
144 MultiColumn_ = value;
145 RecreateHandle();
150 [MonoTODO]
151 public override RightToLeft RightToLeft {
152 get {
153 //FIXME:
154 return base.RightToLeft;
156 set {
157 //FIXME:
158 base.RightToLeft = value;
161 [MonoTODO]
162 public bool ScrollAlwaysVisible {
163 get {
164 throw new NotImplementedException ();
166 set {
167 //FIXME:
171 [MonoTODO]
172 public bool HorizontalScrollbar {
173 get {
174 throw new NotImplementedException ();
176 set {
177 // FIXME
181 [MonoTODO]
182 public int PreferredHeight {
183 get {
184 throw new NotImplementedException ();
188 [MonoTODO]
189 public override int SelectedIndex {
190 get {
191 if( IsHandleCreated) {
192 return Win32.SendMessage(Handle, (int)ListBoxMessages.LB_GETCURSEL, 0, 0);
194 else {
195 return selectedIndex;
198 set {
199 prevSelectedIndex = selectedIndex;
200 if( selectedIndex != value) {
201 //FIXME: set exception parameters
202 selectedIndex = value;
203 if( IsHandleCreated) {
204 Win32.SendMessage(Handle, (int)ListBoxMessages.LB_SETCURSEL, selectedIndex, 0);
206 OnSelectedIndexChanged(new EventArgs());
211 [MonoTODO]
212 public ListBox.SelectedIndexCollection SelectedIndices {
213 get {
214 if( SelectedIndices_ == null) {
215 SelectedIndices_ = new ListBox.SelectedIndexCollection(this);
217 return SelectedIndices_;
220 [MonoTODO]
221 public object SelectedItem {
222 get {
223 throw new NotImplementedException ();
225 set {
226 //FIXME:
229 [MonoTODO]
230 public ListBox.SelectedObjectCollection SelectedItems {
231 get {
232 if( SelectedObjects_ == null) {
233 SelectedObjects_ = new ListBox.SelectedObjectCollection(this);
235 return SelectedObjects_;
238 [MonoTODO]
239 public virtual SelectionMode SelectionMode {
240 get {
241 throw new NotImplementedException ();
243 set {
244 //FIXME:
247 [MonoTODO]
248 public bool Sorted {
249 get {
250 return Sorted_;
252 set {
253 if( Sorted_ != value){
254 Sorted_ = value;
255 if( Sorted_) {
256 Items_.SwitchToSortedStyle();
258 object[] items = new object[Items.Count];
259 Items.CopyTo(items, 0);
260 Items.Clear();
261 Items.AddRange(items);
267 [MonoTODO]
268 public override string Text {
269 get {
270 return base.Text;
272 set {
273 base.Text = value;
276 [MonoTODO]
277 public int TopIndex {
278 get {
279 throw new NotImplementedException ();
281 set {
282 //FIXME:
285 [MonoTODO]
286 public bool UseTabStops {
287 get {
288 return UseTabStops_;
290 set {
291 UseTabStops_ = value;
295 [MonoTODO]
296 public virtual DrawMode DrawMode {
297 get {
298 return DrawMode_;
300 set {
301 DrawMode_ = value;
302 // FIXME: change styles of Windows control/ recreate control
306 public int ColumnWidth {
307 get {
308 return ColumnWidth_;
310 set {
311 ColumnWidth_ = value;
315 [MonoTODO]
316 public virtual int ItemHeight {
317 get {
318 throw new NotImplementedException ();
320 set {
321 //FIXME:
324 public bool IntegralHeight {
325 get {
326 return IntegralHeight_;
328 set {
329 IntegralHeight_ = value;
333 public ListBox.ObjectCollection Items {
334 get {
335 if( Items_ == null) {
336 Items_ = CreateItemCollection();
338 return Items_;
342 internal virtual void OnObjectCollectionChanged() {
343 SelectedIndices_ = null;
347 // --- Public Methods
349 [MonoTODO]
350 public void BeginUpdate() {
351 //FIXME:
353 [MonoTODO]
354 public void ClearSelected() {
355 //FIXME:
357 [MonoTODO]
358 public void EndUpdate() {
359 //FIXME:
361 [MonoTODO]
362 public int FindString(string s) {
363 throw new NotImplementedException ();
365 [MonoTODO]
366 public int FindString(string s, int startIndex) {
367 throw new NotImplementedException ();
369 [MonoTODO]
370 public int FindStringExact(string s) {
371 throw new NotImplementedException ();
373 [MonoTODO]
374 public int FindStringExact(string s, int startIndex) {
375 throw new NotImplementedException ();
377 [MonoTODO]
378 public int GetItemHeight(int index) {
379 throw new NotImplementedException ();
381 [MonoTODO]
382 public Rectangle GetItemRectangle(int index) {
383 throw new NotImplementedException ();
385 [MonoTODO]
386 public bool GetSelected(int index) {
387 throw new NotImplementedException ();
389 [MonoTODO]
390 public int IndexFromPoint(Point p) {
391 throw new NotImplementedException ();
393 [MonoTODO]
394 public int IndexFromPoint(int x, int y) {
395 throw new NotImplementedException ();
397 [MonoTODO]
398 public void SetSelected(int index, bool value) {
399 //FIXME:
401 [MonoTODO]
402 public override string ToString() {
403 //FIXME:
404 return base.ToString();
408 // --- Public Events
410 [MonoTODO]
411 public event DrawItemEventHandler DrawItem;
412 [MonoTODO]
413 public event MeasureItemEventHandler MeasureItem;
414 public event EventHandler SelectedIndexChanged;
416 // --- Protected Properties
418 [MonoTODO]
419 protected override CreateParams CreateParams {
420 get {
421 CreateParams createParams = base.CreateParams;
422 createParams.ClassName = "LISTBOX";
423 createParams.ExStyle = (int)WindowExStyles.WS_EX_CLIENTEDGE;
424 createParams.Style = (int) (
425 WindowStyles.WS_CHILD |
426 WindowStyles.WS_VISIBLE |
427 WindowStyles.WS_CLIPSIBLINGS);
428 createParams.Style |= (int) (ListBoxStyles.LBS_NOTIFY |
429 ListBoxStyles.LBS_HASSTRINGS );
430 if( !IntegralHeight_) {
431 createParams.Style |= (int)ListBoxStyles.LBS_NOINTEGRALHEIGHT;
433 if( UseTabStops_ ) {
434 createParams.Style |= (int)ListBoxStyles.LBS_USETABSTOPS;
436 switch( DrawMode_){
437 case DrawMode.OwnerDrawFixed:
438 createParams.Style |= (int)ListBoxStyles.LBS_OWNERDRAWFIXED;
439 break;
440 case DrawMode.OwnerDrawVariable:
441 createParams.Style |= (int)ListBoxStyles.LBS_OWNERDRAWVARIABLE;
442 break;
444 if( MultiColumn_) {
445 createParams.Style |= (int)ListBoxStyles.LBS_MULTICOLUMN | (int)WindowStyles.WS_HSCROLL;
447 else {
448 createParams.Style |= (int)WindowStyles.WS_VSCROLL;
450 return createParams;
454 [MonoTODO]
455 protected override Size DefaultSize {
456 get {
457 return new Size(120,95);
462 // --- Protected Methods
465 [MonoTODO]
466 protected virtual void AddItemsCore(object [] value) {
467 //Fixme
470 [MonoTODO]
471 protected virtual ObjectCollection CreateItemCollection() {
472 return new ListBox.ObjectCollection( this);
475 [MonoTODO]
476 protected override void OnChangeUICues(UICuesEventArgs e) {
477 //FIXME:
478 base.OnChangeUICues(e);
480 [MonoTODO]
481 protected override void OnDataSourceChanged(EventArgs e) {
482 //FIXME:
483 base.OnDataSourceChanged(e);
485 [MonoTODO]
486 protected override void OnDisplayMemberChanged(EventArgs e) {
487 //FIXME:
488 base.OnDisplayMemberChanged(e);
491 [MonoTODO]
492 protected virtual void OnDrawItem(DrawItemEventArgs e) {
493 if( DrawItem != null) {
494 DrawItem(this, e);
498 [MonoTODO]
499 protected override void OnFontChanged(EventArgs e) {
500 //FIXME:
501 base.OnFontChanged(e);
503 [MonoTODO]
504 protected override void OnHandleCreated(EventArgs e) {
505 //FIXME:
506 base.OnHandleCreated(e);
507 if( Items_ != null) {
508 Items_.PopulateControl();
510 if( ColumnWidth_ != 0 && MultiColumn_) {
511 Win32.SendMessage( Handle, (int)ListBoxMessages.LB_SETCOLUMNWIDTH, ColumnWidth_, 0);
515 [MonoTODO]
516 protected override void OnHandleDestroyed(EventArgs e) {
517 //FIXME:
518 base.OnHandleDestroyed(e);
521 [MonoTODO]
522 protected virtual void OnMeasureItem(MeasureItemEventArgs e) {
523 if( MeasureItem != null) {
524 MeasureItem(this, e);
528 [MonoTODO]
529 protected override void OnParentChanged(EventArgs e) {
530 //FIXME:
531 base.OnParentChanged(e);
533 [MonoTODO]
534 protected override void OnResize(EventArgs e) {
535 //FIXME:
536 base.OnResize(e);
538 [MonoTODO]
539 protected override void OnSelectedIndexChanged(EventArgs e) {
540 //FIXME:
541 base.OnSelectedIndexChanged(e);
542 if( SelectedIndexChanged != null) {
543 SelectedIndexChanged(this, e);
547 [MonoTODO]
548 protected override void OnSelectedValueChanged(EventArgs e) {
549 //FIXME:
550 base.OnSelectedValueChanged(e);
553 protected override void RefreshItem(int index) {
554 //FIXME:
557 public override void Refresh() { // .NET V1.1 Beta
558 base.Refresh();
561 [MonoTODO]
562 protected override void SetBoundsCore( int x, int y, int width, int height, BoundsSpecified specified) {
563 //FIXME:
564 base.SetBoundsCore(x, y, width, height, specified);
567 [MonoTODO]
568 protected override void SetItemCore (int index, object value) {
569 //FIXME:
572 protected override void SetItemsCore (IList value){
575 [MonoTODO]
576 protected virtual void Sort() {
577 //FIXME:
580 protected virtual void WmReflectCommand(ref Message m){
581 throw new NotImplementedException ();
584 [MonoTODO]
585 protected override void WndProc(ref Message m) {
586 switch ((Msg) m.Msg) {
587 case Msg.WM_MEASUREITEM: {
588 MEASUREITEMSTRUCT mis = new MEASUREITEMSTRUCT();
589 mis = (MEASUREITEMSTRUCT)Marshal.PtrToStructure(m.LParam, mis.GetType());
590 MeasureItemEventArgs args = new MeasureItemEventArgs(CreateGraphics(),mis.itemID);
591 args.ItemHeight = mis.itemHeight;
592 args.ItemWidth = mis.itemWidth;
593 OnMeasureItem( args);
594 mis.itemHeight = args.ItemHeight;
595 mis.itemWidth = args.ItemWidth;
596 Marshal.StructureToPtr(mis, m.LParam, false);
597 m.Result = (IntPtr)1;
599 break;
600 case Msg.WM_DRAWITEM: {
601 DRAWITEMSTRUCT dis = new DRAWITEMSTRUCT();
602 dis = (DRAWITEMSTRUCT)Marshal.PtrToStructure(m.LParam, dis.GetType());
603 Rectangle rect = new Rectangle(dis.rcItem.left, dis.rcItem.top, dis.rcItem.right - dis.rcItem.left, dis.rcItem.bottom - dis.rcItem.top);
604 DrawItemEventArgs args = new DrawItemEventArgs(Graphics.FromHdc(dis.hDC), Font,
605 rect, dis.itemID, (DrawItemState)dis.itemState);
606 OnDrawItem( args);
607 //Marshal.StructureToPtr(dis, m.LParam, false);
608 m.Result = (IntPtr)1;
610 break;
611 case Msg.WM_COMMAND:
612 switch(m.HiWordWParam) {
613 case (uint)ListBoxNotifications.LBN_SELCHANGE:
614 SelectedIndex = Win32.SendMessage(Handle, (int)ListBoxMessages.LB_GETCURSEL, 0, 0);
615 m.Result = IntPtr.Zero;
616 CallControlWndProc(ref m);
617 break;
618 default:
619 CallControlWndProc(ref m);
620 break;
622 break;
623 default:
624 base.WndProc(ref m);
625 break;
630 // <summary>
631 // This is a subclass
632 // </summary>
634 public class SelectedObjectCollection : IList, ICollection, IEnumerable {
636 ArrayList collection_;
637 ListBox owner_;
639 // --- Constructor
641 [MonoTODO]
642 public SelectedObjectCollection(ListBox owner) {
643 owner_ = owner;
644 collection_ = owner_.Items.CreateSelectedObjectsList();
648 // --- Public Properties
650 [MonoTODO]
651 public int Count {
652 get {
653 return collection_.Count;
656 [MonoTODO]
657 public bool IsReadOnly {
658 get {
659 return true;
662 [MonoTODO]
663 public object this[int index] {
664 get {
665 return collection_[index];
667 set {
668 //FIXME:
673 // --- Public Methods
675 [MonoTODO]
676 public bool Contains(object selectedObject) {
677 return collection_.Contains(selectedObject);;
679 [MonoTODO]
680 public void CopyTo(Array dest, int index) {
681 collection_.CopyTo(dest, index);
683 [MonoTODO]
684 public override bool Equals(object obj) {
685 //FIXME:
686 return base.Equals(obj);
688 [MonoTODO]
689 public override int GetHashCode() {
690 //FIXME add our proprities
691 return base.GetHashCode();
693 [MonoTODO]
694 public IEnumerator GetEnumerator() {
695 return collection_.GetEnumerator();
697 [MonoTODO]
698 public int IndexOf(object selectedObject) {
699 return collection_.IndexOf(selectedObject);
701 /// <summary>
702 /// IList Interface implmentation.
703 /// </summary>
704 bool IList.IsReadOnly{
705 get{
706 // We allow addition, removeal, and editing of items after creation of the list.
707 return false;
710 bool IList.IsFixedSize{
711 get{
712 // We allow addition and removeal of items after creation of the list.
713 return false;
717 //[MonoTODO]
718 #if A
719 object IList.this[int index]{
720 get{
721 throw new NotImplementedException ();
723 set{
724 throw new NotImplementedException ();
727 #endif
729 [MonoTODO]
730 void IList.Clear(){
731 //FIXME:
734 [MonoTODO]
735 int IList.Add( object value){
736 throw new NotImplementedException ();
739 [MonoTODO]
740 bool IList.Contains( object value){
741 throw new NotImplementedException ();
744 [MonoTODO]
745 int IList.IndexOf( object value){
746 throw new NotImplementedException ();
749 [MonoTODO]
750 void IList.Insert(int index, object value){
751 //FIXME:
754 [MonoTODO]
755 void IList.Remove( object value){
756 //FIXME:
759 [MonoTODO]
760 void IList.RemoveAt( int index){
761 //FIXME:
763 // End of IList interface
764 /// <summary>
765 /// ICollection Interface implmentation.
766 /// </summary>
767 int ICollection.Count{
768 get{
769 throw new NotImplementedException ();
772 bool ICollection.IsSynchronized{
773 get{
774 throw new NotImplementedException ();
777 object ICollection.SyncRoot{
778 get{
779 throw new NotImplementedException ();
782 void ICollection.CopyTo(Array array, int index){
783 throw new NotImplementedException ();
785 // End Of ICollection
786 }//End of subclass
788 // <summary>
789 // </summary>
791 public class ObjectCollection : IList, ICollection {
793 internal class ListBoxItem {
794 public object theData_ = null;
795 public string dataRepresentation_ = String.Empty;
796 // FIXME: change those fields to flags
797 //public bool wasSorted_ = false;
798 //public bool wasAddedToControl_ = false;
799 public bool IsAddedToControl_ = false;
800 public bool Selected_ = false;
801 public bool Checked_ = false;
803 public ListBoxItem( object data, string representation) {
804 theData_ = data;
805 dataRepresentation_ = representation;
809 internal class ListItemRepresentationComparer : IComparer {
810 public ListItemRepresentationComparer() {
813 public int Compare(object x, object y) {
814 ListBoxItem left = x as ListBoxItem;
815 ListBoxItem right = y as ListBoxItem;
816 if( left == null || right == null) {
817 throw new ArgumentException();
819 return left.dataRepresentation_.CompareTo(right.dataRepresentation_);
823 internal class ListItemDataComparer : IComparer {
824 public ListItemDataComparer() {
827 public int Compare(object x, object y) {
828 ListBoxItem left = x as ListBoxItem;
829 ListBoxItem right = y as ListBoxItem;
830 if( left == null || right == null) {
831 throw new ArgumentException();
833 return left.theData_.CompareTo(right.dataRepresentation_);
837 internal ArrayList CreateSelectedIndicesList() {
838 ArrayList result = new ArrayList();
839 int ordinalNumber = 0;
840 foreach( ListBoxItem lbi in items_) {
841 if( lbi.Selected_) {
842 result.Add(ordinalNumber);
844 ++ordinalNumber;
846 return result;
849 internal ArrayList CreateSelectedObjectsList() {
850 ArrayList result = new ArrayList();
851 foreach( ListBoxItem lbi in items_) {
852 if( lbi.Selected_) {
853 result.Add(lbi.theData_);
856 return result;
859 internal ArrayList CreateCheckedIndexList() {
860 ArrayList result = new ArrayList();
861 int ordinalNumber = 0;
862 foreach( ListBoxItem lbi in items_) {
863 if( lbi.Checked_) {
864 result.Add(ordinalNumber);
866 ++ordinalNumber;
868 return result;
871 internal ArrayList CreateCheckedItemList() {
872 ArrayList result = new ArrayList();
873 foreach( ListBoxItem lbi in items_) {
874 if( lbi.Checked_) {
875 result.Add(lbi.theData_);
878 return result;
881 internal ListBoxItem getItemAt(int index) {
882 return (ListBoxItem)items_[index];
885 internal void SwitchToSortedStyle() {
886 if( owner_.IsHandleCreated) {
887 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_RESETCONTENT, 0, 0);
889 items_.Sort(new ListItemRepresentationComparer());
890 if( owner_.IsHandleCreated) {
891 foreach( ListBoxItem lbi in items_) {
892 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_ADDSTRING, 0, lbi.dataRepresentation_);
895 owner_.OnObjectCollectionChanged();
898 internal void PopulateControl() {
899 foreach( ListBoxItem lbi in items_) {
900 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_ADDSTRING, 0, lbi.dataRepresentation_);
901 lbi.IsAddedToControl_ = true;
905 internal void DumpItems() {
906 int ordinalNumber = 0;
907 foreach( ListBoxItem lbi in items_) {
908 Console.WriteLine("ListBoxItem {0} order {1} checked {2}", lbi.dataRepresentation_,
909 ordinalNumber, lbi.Checked_);
910 ++ordinalNumber;
914 internal class ListBoxItemEnumerator : IEnumerator {
915 private IEnumerator containerEnum_ = null;
917 public ListBoxItemEnumerator( IEnumerator containerEnum) {
918 containerEnum_ = containerEnum;
921 public object Current {
922 get {
923 return ((ListBoxItem)containerEnum_.Current).theData_;
927 public bool MoveNext() {
928 return containerEnum_.MoveNext();
931 public void Reset() {
932 containerEnum_.Reset();
937 protected ListBox owner_ = null;
938 protected ArrayList items_ = new ArrayList(); // has ListBoxItem
941 // --- Constructor
943 [MonoTODO]
944 public ObjectCollection(ListBox box) {
945 owner_ = box;
947 [MonoTODO]
948 public ObjectCollection(ListBox box, object[] objs) {
949 owner_ = box;
950 AddRange(objs);
954 // --- Public Properties
956 [MonoTODO]
957 public int Count {
958 get {
959 return items_.Count;
962 [MonoTODO]
963 public bool IsReadOnly {
964 get {
965 // FIXME: Is it always not ReadOnly
966 return false;
969 [MonoTODO]
970 public virtual object this[int index] {
971 get {
972 return ((ListBoxItem)items_[index]).theData_;
974 set {
975 ((ListBoxItem)items_[index]).theData_ = value;
976 // FIXME: assing representation and sort if needed
981 // --- Public Methods
983 [MonoTODO]
984 public int Add(object item) {
985 string representation = owner_.getDisplayMemberOfObj(item);
986 ListBoxItem newItem = new ListBoxItem(item, representation);
987 int result = items_.Add(newItem);
988 if( owner_.Sorted) {
989 items_.Sort(new ListItemRepresentationComparer());
990 result = items_.BinarySearch(newItem);
991 if( owner_.IsHandleCreated) {
992 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_INSERTSTRING, result, representation);
994 owner_.OnObjectCollectionChanged();
996 else {
997 if( owner_.IsHandleCreated) {
998 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_ADDSTRING, 0, representation);
1001 newItem.IsAddedToControl_ = true;
1002 return result;
1005 [MonoTODO]
1006 public void AddRange(object[] items) {
1007 if( items == null) throw new ArgumentException();
1008 ListBoxItem[] newItems = new ListBoxItem[items.Length];
1009 int idx = 0;
1010 foreach( object obj in items ) {
1011 newItems[idx] = new ListBoxItem(obj, owner_.getDisplayMemberOfObj(obj));
1012 ++idx;
1014 items_.AddRange(newItems);
1015 if( owner_.Sorted) {
1016 items_.Sort(new ListItemRepresentationComparer());
1017 if( owner_.IsHandleCreated) {
1018 int index = 0;
1019 foreach( ListBoxItem lbi in items_) {
1020 if(!lbi.IsAddedToControl_){
1021 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_INSERTSTRING, index, lbi.dataRepresentation_);
1023 ++index;
1026 owner_.OnObjectCollectionChanged();
1028 else {
1029 if( owner_.IsHandleCreated) {
1030 foreach(ListBoxItem lbi in newItems) {
1031 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_ADDSTRING, 0, lbi.dataRepresentation_);
1032 lbi.IsAddedToControl_ = true;
1036 // FIXME: Add items to control
1038 [MonoTODO]
1039 public void AddRange(ListBox.ObjectCollection collection) {
1040 //FIXME:
1042 [MonoTODO]
1043 public void Clear() {
1044 //FIXME:
1045 items_.Clear();
1046 if( owner_.IsHandleCreated) {
1047 Win32.SendMessage(owner_.Handle, (int)ListBoxMessages.LB_RESETCONTENT, 0, 0);
1049 owner_.OnObjectCollectionChanged();
1051 [MonoTODO]
1052 public bool Contains(object value) {
1053 // FIXME: determine whether some of ListBoxItem has value as theData_
1054 foreach( ListBoxItem lbi in items_) {
1055 if( lbi.theData_ == value) {
1056 return true;
1059 return false;
1061 [MonoTODO]
1062 public void CopyTo(object[] dest, int arrayIndex) {
1063 // FIXME: copy theData_ from ListBoxItem, not the ListBoxItems
1064 items_.CopyTo(dest, arrayIndex);
1066 [MonoTODO]
1067 public override bool Equals(object obj) {
1068 //FIXME:
1069 return base.Equals(obj);
1071 [MonoTODO]
1072 public override int GetHashCode() {
1073 //FIXME add our proprities
1074 return base.GetHashCode();
1076 [MonoTODO]
1077 public IEnumerator GetEnumerator() {
1078 return new ListBoxItemEnumerator(items_.GetEnumerator());
1080 [MonoTODO]
1081 public int IndexOf(object val) {
1082 // FIXME: find ListBoxItem object which has the val as theData_
1083 int result = -1;
1084 int index = 0;
1085 foreach( ListBoxItem lbi in items_) {
1086 if( lbi.theData_ == val) {
1087 result = index;
1088 break;
1090 ++index;
1092 return result;
1094 [MonoTODO]
1095 public void Insert(int index, object item) {
1096 //FIXME:
1098 [MonoTODO]
1099 public void Remove(object val) {
1100 // FIXME: use some sort of Comparer ?
1101 int pos = 0;
1102 foreach(ListBoxItem lbi in items_) {
1103 if( lbi.theData_ == val) {
1104 RemoveAt(pos);
1105 break;
1107 ++pos;
1110 [MonoTODO]
1111 public void RemoveAt(int index) {
1112 if( index < 0 || index >= items_.Count) {
1113 //FIXME: set exception parameters
1114 throw new ArgumentOutOfRangeException();
1116 items_.RemoveAt(index);
1117 if( owner_.IsHandleCreated) {
1118 Win32.SendMessage( owner_.Handle, (int)ListBoxMessages.LB_DELETESTRING, index, 0);
1120 owner_.OnObjectCollectionChanged();
1122 /// <summary>
1123 /// IList Interface implmentation.
1124 /// </summary>
1125 bool IList.IsReadOnly{
1126 get{
1127 // We allow addition, removeal, and editing of items after creation of the list.
1128 return false;
1131 bool IList.IsFixedSize{
1132 get{
1133 // We allow addition and removeal of items after creation of the list.
1134 return false;
1138 #if A
1139 //[MonoTODO]
1140 object IList.this[int index]{
1141 get{
1142 throw new NotImplementedException ();
1144 set{
1145 throw new NotImplementedException ();
1148 #endif
1150 [MonoTODO]
1151 void IList.Clear(){
1152 //FIXME:
1155 [MonoTODO]
1156 int IList.Add( object value){
1157 throw new NotImplementedException ();
1160 [MonoTODO]
1161 bool IList.Contains( object value){
1162 throw new NotImplementedException ();
1165 [MonoTODO]
1166 int IList.IndexOf( object value){
1167 throw new NotImplementedException ();
1170 [MonoTODO]
1171 void IList.Insert(int index, object value){
1172 //FIXME:
1175 [MonoTODO]
1176 void IList.Remove( object value){
1177 //FIXME:
1180 [MonoTODO]
1181 void IList.RemoveAt( int index){
1182 //FIXME:
1184 // End of IList interface
1185 /// <summary>
1186 /// ICollection Interface implmentation.
1187 /// </summary>
1188 int ICollection.Count{
1189 get{
1190 throw new NotImplementedException ();
1193 bool ICollection.IsSynchronized{
1194 get{
1195 throw new NotImplementedException ();
1198 object ICollection.SyncRoot{
1199 get{
1200 throw new NotImplementedException ();
1203 void ICollection.CopyTo(Array array, int index){
1204 throw new NotImplementedException ();
1206 // End Of ICollection
1207 }//end of SubClass
1209 // <summary>
1210 // </summary>
1212 public class SelectedIndexCollection : IList, ICollection, IEnumerable {
1214 ArrayList collection_;
1215 ListBox owner_;
1218 // --- Constructor
1220 [MonoTODO]
1221 public SelectedIndexCollection(ListBox owner) {
1222 owner_ = owner;
1223 collection_ = owner_.Items.CreateSelectedIndicesList();
1227 // --- Public Properties
1229 [MonoTODO]
1230 public int Count {
1231 get {
1232 return collection_.Count;
1235 [MonoTODO]
1236 public bool IsReadOnly {
1237 get {
1238 return true;
1241 [MonoTODO]
1242 public int this[int index] {
1243 get {
1244 return (int)collection_[index];
1249 // --- Public Methods
1251 [MonoTODO]
1252 public bool Contains(int selectedIndex) {
1253 return collection_.Contains(selectedIndex);
1255 [MonoTODO]
1256 public void CopyTo(Array dest, int index) {
1257 collection_.CopyTo(dest, index);
1259 [MonoTODO]
1260 public override bool Equals(object obj) {
1261 //FIXME:
1262 return base.Equals(obj);
1264 [MonoTODO]
1265 public override int GetHashCode() {
1266 //FIXME add our proprities
1267 return base.GetHashCode();
1269 [MonoTODO]
1270 public IEnumerator GetEnumerator() {
1271 return collection_.GetEnumerator();
1273 /// <summary>
1274 /// IList Interface implmentation.
1275 /// </summary>
1276 bool IList.IsReadOnly{
1277 get{
1278 // We allow addition, removeal, and editing of items after creation of the list.
1279 return false;
1282 bool IList.IsFixedSize{
1283 get{
1284 // We allow addition and removeal of items after creation of the list.
1285 return false;
1289 //[MonoTODO]
1290 object IList.this[int index]{
1291 get{
1292 throw new NotImplementedException ();
1294 set{
1295 //FIXME:
1299 [MonoTODO]
1300 void IList.Clear(){
1301 //FIXME:
1304 [MonoTODO]
1305 int IList.Add( object value){
1306 throw new NotImplementedException ();
1309 [MonoTODO]
1310 bool IList.Contains( object value){
1311 throw new NotImplementedException ();
1314 [MonoTODO]
1315 int IList.IndexOf( object value){
1316 throw new NotImplementedException ();
1319 [MonoTODO]
1320 void IList.Insert(int index, object value){
1321 //FIXME:
1324 [MonoTODO]
1325 void IList.Remove( object value){
1326 //FIXME:
1329 [MonoTODO]
1330 void IList.RemoveAt( int index){
1331 throw new NotImplementedException ();
1333 // End of IList interface
1334 /// <summary>
1335 /// ICollection Interface implmentation.
1336 /// </summary>
1337 int ICollection.Count{
1338 get{
1339 throw new NotImplementedException ();
1342 bool ICollection.IsSynchronized{
1343 get{
1344 throw new NotImplementedException ();
1347 object ICollection.SyncRoot{
1348 get{
1349 throw new NotImplementedException ();
1352 void ICollection.CopyTo(Array array, int index){
1353 throw new NotImplementedException ();
1355 // End Of ICollection
1357 }//End of subclass