2007-01-07 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Control.cs
index 7a357734bf9cb6de103a2b7fb3c1d5aa89ab49c4..b32e216b53dda6b9816a5436080b0f2d4f09b358 100644 (file)
@@ -385,15 +385,19 @@ namespace System.Windows.Forms
                                Dispose ();
                        }
                }
+
+               [ListBindable (false)]
 #if NET_2_0
                [ComVisible (false)]
+               public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
 #else
                [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
-#endif
-               [ListBindable(false)]
                public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
+#endif
                        #region ControlCollection Local Variables
+#if !NET_2_0
                        ArrayList list;
+#endif
                        ArrayList impl_list;
                        Control[] all_controls;
                        Control owner;
@@ -402,7 +406,9 @@ namespace System.Windows.Forms
                        #region ControlCollection Public Constructor
                        public ControlCollection(Control owner) {
                                this.owner=owner;
+#if !NET_2_0
                                this.list=new ArrayList();
+#endif
                        }
                        #endregion
 
@@ -412,9 +418,11 @@ namespace System.Windows.Forms
                        }
 
 
+#if !NET_2_0
                        public int Count {
                                get { return list.Count; }
                        }
+#endif
 
 #if NET_2_0
                        bool IList.IsReadOnly
@@ -427,6 +435,22 @@ namespace System.Windows.Forms
                                }
                        }
 
+#if NET_2_0
+                       public Control Owner { get { return this.owner; } }
+                       
+                       public virtual Control this[string key] {
+                               get { 
+                                       int index = IndexOfKey (key);
+                                       
+                                       if (index >= 0)
+                                               return this[index];
+                                               
+                                       return null;
+                               }
+                       }
+                       
+                       new
+#endif
                        public virtual Control this[int index] {
                                get {
                                        if (index < 0 || index >= list.Count) {
@@ -434,10 +458,12 @@ namespace System.Windows.Forms
                                        }
                                        return (Control)list[index];
                                }
+                               
+                               
                        }
                        #endregion // ControlCollection Public Instance Properties
                        
-                       #region ControlCollection Private Instance Methods
+                       #region ControlCollection Instance Methods
                        public virtual void Add (Control value)
                        {
                                if (value == null)
@@ -536,6 +562,9 @@ namespace System.Windows.Forms
                                }
                        }
 
+#if NET_2_0
+                       new
+#endif
                        public virtual void Clear ()
                        {
                                all_controls = null;
@@ -588,17 +617,24 @@ namespace System.Windows.Forms
                                return Contains (value) || ImplicitContains (value);
                        }
 
+#if NET_2_0
+                       public virtual bool ContainsKey (string key)
+                       {
+                               return IndexOfKey (key) >= 0;
+                       }
+#endif
+
                        void ICollection.CopyTo (Array array, int index)
                        {
                                CopyTo (array, index);
                        }
 
+#if !NET_2_0
                        public void CopyTo (Array array, int index)
                        {
                                list.CopyTo(array, index);
                        }
 
-#if !NET_2_0
                        public override bool Equals (object other)
                        {
                                if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
@@ -609,6 +645,27 @@ namespace System.Windows.Forms
                        }
 #endif
 
+#if NET_2_0
+                       // LAMESPEC: MSDN says AE, MS implementation throws ANE
+                       public Control[] Find (string key, bool searchAllChildren)
+                       {
+                               if (string.IsNullOrEmpty (key))
+                                       throw new ArgumentNullException ("key");
+                                       
+                               ArrayList al = new ArrayList ();
+                               
+                               foreach (Control c in list) {
+                                       if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
+                                               al.Add (c);
+                                               
+                                       if (searchAllChildren)
+                                               al.AddRange (c.Controls.Find (key, true));
+                               }
+                               
+                               return (Control[])al.ToArray (typeof (Control));
+                       }
+#endif
+
                        public int GetChildIndex(Control child) {
                                return GetChildIndex(child, false);
                        }
@@ -630,7 +687,7 @@ namespace System.Windows.Forms
                        }
 
 #if NET_2_0
-                       public virtual IEnumerator
+                       public override IEnumerator
 #else
                        public IEnumerator
 #endif
@@ -674,6 +731,20 @@ namespace System.Windows.Forms
                                return list.IndexOf(control);
                        }
 
+#if NET_2_0
+                       public virtual int IndexOfKey (string key)
+                       {
+                               if (string.IsNullOrEmpty (key))
+                                       return -1;
+                                       
+                               for (int i = 0; i < list.Count; i++)
+                                       if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
+                                               return i;
+                                               
+                               return -1;
+                       }
+#endif
+
                        public virtual void Remove(Control value)
                        {
                                if (value == null)
@@ -702,6 +773,9 @@ namespace System.Windows.Forms
                                owner.UpdateChildrenZOrder ();
                        }
 
+#if NET_2_0
+                       new
+#endif
                        public void RemoveAt(int index)
                        {
                                if (index < 0 || index >= list.Count) {
@@ -711,6 +785,14 @@ namespace System.Windows.Forms
                        }
 
 #if NET_2_0
+                       public virtual void RemoveByKey (string key)
+                       {
+                               int index = IndexOfKey (key);
+                               
+                               if (index >= 0)
+                                       RemoveAt (index);
+                       }       
+               
                        public virtual void
 #else
                        public void
@@ -898,7 +980,8 @@ namespace System.Windows.Forms
                        child_controls = CreateControlsInstance();
                        client_size = new Size(DefaultSize.Width, DefaultSize.Height);
                        client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
-                       XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
+                       bounds.Size = SizeFromClientSize (client_size);
+                       
                        if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
                                bounds.X=-1;
                                bounds.Y=-1;
@@ -996,8 +1079,9 @@ namespace System.Windows.Forms
                                        border_style = value;
 
                                        if (IsHandleCreated) {
-                                               XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
-                                               Refresh();
+                                               XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
+                                               RecreateHandle ();
+                                               Refresh ();
                                        }
                                }
                        }
@@ -4039,19 +4123,10 @@ namespace System.Windows.Forms
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void SetClientSizeCore(int x, int y) {
-                       // Calculate the actual window size from the client size (it usually stays the same or grows)
-                       Rectangle       ClientRect;
-                       Rectangle       WindowRect;
-                       CreateParams    cp;
-
-                       ClientRect = new Rectangle(0, 0, x, y);
-                       cp = this.CreateParams;
-
-                       if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
-                               return;
-                       }
-
-                       SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
+                       Size NewSize = SizeFromClientSize (new Size (x, y));
+                       
+                       if (NewSize != Size.Empty)
+                               SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -4119,7 +4194,27 @@ namespace System.Windows.Forms
                                }
                        }
                }
-       
+
+#if NET_2_0
+               protected 
+#else
+               internal
+#endif
+               virtual Size SizeFromClientSize (Size clientSize)
+               {
+                       Rectangle ClientRect;
+                       Rectangle WindowRect;
+                       CreateParams cp;
+
+                       ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
+                       cp = this.CreateParams;
+
+                       if (XplatUI.CalculateWindowRect (ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect))
+                               return new Size (WindowRect.Width, WindowRect.Height);
+                               
+                       return Size.Empty;
+               }
+
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected void UpdateBounds() {
                        int     x;
@@ -4627,7 +4722,6 @@ namespace System.Windows.Forms
 
                #region OnXXX methods
 #if NET_2_0
-               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnAutoSizeChanged (EventArgs e)
                {
                        EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
@@ -4954,7 +5048,6 @@ namespace System.Windows.Forms
                }
 
 #if NET_2_0
-               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnMarginChanged (EventArgs e)
                {
                        EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);