2005-06-06 Peter Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / CurrencyManager.cs
index 612118b65320ab6a889307078c22699f91da15db..e30658fdcc9b08dc46d49199504df45f58e880fa 100644 (file)
 //
 
 using System;
+using System.Reflection;
 using System.Collections;
 using System.ComponentModel;
 
 namespace System.Windows.Forms {
-
+       [DefaultMember("Item")]
        public class CurrencyManager : BindingManagerBase {
 
                protected Type finalType;
@@ -50,6 +51,16 @@ namespace System.Windows.Forms {
                                throw new Exception ("Attempted to create currency manager " +
                                        "from invalid type: " + data_source.GetType ());
                        }
+
+                       if (data_source as ArrayList != null) {
+                               finalType = ((ArrayList)data_source).GetType ();
+                       } else {
+                               if (data_source as Array != null) {
+                                       finalType = ((Array) data_source).GetType ();
+                               } else {
+                                       finalType = null;
+                               }
+                       }
                }               
 
                public IList List {
@@ -87,9 +98,30 @@ namespace System.Windows.Forms {
                {
                        ITypedList typed = list as ITypedList;
 
-                       if (typed == null)
-                               return null;
-                       return typed.GetItemProperties (null);
+                       if (list is Array) {
+                               Type element = list.GetType ().GetElementType ();
+                               return TypeDescriptor.GetProperties (element);
+                       }
+
+                       if (typed != null) {
+                               return typed.GetItemProperties (null);
+                       }
+
+                       PropertyInfo [] props = finalType.GetProperties ();
+                       for (int i = 0; i < props.Length; i++) {
+                               if (props [i].Name == "Item") {
+                                       Type t = props [i].PropertyType;
+                                       if (t == typeof (object))
+                                               continue;
+                                       return GetBrowsableProperties (t);
+                               }
+                       }
+
+                       if (list.Count > 0) {
+                               return GetBrowsableProperties (list [0].GetType ());
+                       }
+                       
+                       return new PropertyDescriptorCollection (null);
                }
 
                public override void RemoveAt (int index)
@@ -107,6 +139,10 @@ namespace System.Windows.Forms {
                        binding_suspended = false;
                }
 
+                internal override bool IsSuspended {
+                        get { return binding_suspended; }
+                }
+
                public override void AddNew ()
                {
                        if (binding_list == null)
@@ -182,6 +218,18 @@ namespace System.Windows.Forms {
                        // Probably should be validating or something here
                        EndCurrentEdit ();
                }
+               
+               internal object GetItem (int index)
+               {
+                       return list [index];
+               }
+
+               private PropertyDescriptorCollection GetBrowsableProperties (Type t)
+               {
+                       Attribute [] att = new System.Attribute [1];
+                       att [0] = new BrowsableAttribute (true);
+                       return TypeDescriptor.GetProperties (t, att);
+               }
 
                public event ItemChangedEventHandler ItemChanged;
        }