Author: jpobst
Date: 2006-12-07 11:24:40 -0500 (Thu, 07 Dec 2006)
New Revision: 69186

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
Log:
2006-12-07  Jonathan Pobst  <[EMAIL PROTECTED]>

        * Control.cs: Remove static ArrayList "controls" which maintained
        a reference to every control created.
        * Application.cs: Create a static FormCollection to maintain a reference
        to every form created.  Use it in places that formerly enumerated 
through
        the controls one looking for forms.
        * Form.cs: Add and remove self from above FormCollection.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs   
2006-12-07 16:19:22 UTC (rev 69185)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs   
2006-12-07 16:24:40 UTC (rev 69186)
@@ -142,6 +142,8 @@
                private static InputLanguage            input_language          
= InputLanguage.CurrentInputLanguage;
                private static string                   safe_caption_format     
= "{1} - {0} - {2}";
                private static ArrayList                message_filters         
= new ArrayList();
+               private static FormCollection           forms                   
= new FormCollection ();
+
 #if NET_2_0
                private static VisualStyleState visual_style_state = 
VisualStyleState.ClientAndNonClientAreasEnabled;
 #endif
@@ -151,7 +153,7 @@
 
                #region Private Methods
                private static void CloseForms(Thread thread) {
-                       Control         c;
+                       Form            f;
                        IEnumerator     control;
                        bool            all;
 
@@ -164,14 +166,15 @@
                                all = false;
                        }
 
-                       control = Control.controls.GetEnumerator();
+                       lock (forms) {
+                               control = forms.GetEnumerator();
 
-                       while (control.MoveNext()) {
-                               c = (Control)control.Current;
-                               if (c is Form) {
-                                       if (all || (thread == 
c.creator_thread)) {
-                                               if (c.IsHandleCreated) {
-                                                       
XplatUI.PostMessage(c.Handle, Msg.WM_CLOSE_INTERNAL, IntPtr.Zero, IntPtr.Zero);
+                               while (control.MoveNext()) {
+                                       f = (Form)control.Current;
+                                       
+                                       if (all || (thread == 
f.creator_thread)) {
+                                               if (f.IsHandleCreated) {
+                                                       
XplatUI.PostMessage(f.Handle, Msg.WM_CLOSE_INTERNAL, IntPtr.Zero, IntPtr.Zero);
                                                }
                                                #if DebugRunLoop
                                                        Console.WriteLine("     
 Closing form {0}", c);
@@ -179,7 +182,6 @@
                                        }
                                }
                        }
-
                }
                #endregion      // Private methods
 
@@ -467,24 +469,28 @@
                        #endif
 
                        if (Modal) {
-                               Control c;
+                               Form f;
 
                                toplevels = new Queue();
-                               control = Control.controls.GetEnumerator();
+                               
+                               lock (forms) {
+                                       control = forms.GetEnumerator();
 
-                               while (control.MoveNext()) {
-
-                                       c = (Control)control.Current;
-                                       if (c is Form && (c != 
context.MainForm)) {
-                                               if (c.IsHandleCreated && 
XplatUI.IsEnabled(c.Handle)) {
-                                                       #if DebugRunLoop
-                                                               
Console.WriteLine("      Disabling form {0}", c);
-                                                       #endif
-                                                       
XplatUI.EnableWindow(c.Handle, false);
-                                                       toplevels.Enqueue(c);
+                                       while (control.MoveNext()) {
+                                               f = (Form)control.Current;
+                                               
+                                               if (f != context.MainForm) {
+                                                       if (f.IsHandleCreated 
&& XplatUI.IsEnabled(f.Handle)) {
+                                                               #if DebugRunLoop
+                                                                       
Console.WriteLine("      Disabling form {0}", c);
+                                                               #endif
+                                                               
XplatUI.EnableWindow(f.Handle, false);
+                                                               
toplevels.Enqueue(f);
+                                                       }
                                                }
                                        }
                                }
+                               
                                // FIXME - need activate?
                                /* make sure the MainForm is enabled */
                                if (context.MainForm != null) {
@@ -617,5 +623,19 @@
                public static event EventHandler        ThreadExit;
                public static event ThreadExceptionEventHandler ThreadException;
                #endregion      // Events
+
+               #region Internal Methods
+               internal static void AddForm (Form f)
+               {
+                       lock (forms)
+                               forms.Add (f);
+               }
+               
+               internal static void RemoveForm (Form f)
+               {
+                       lock (forms)
+                               forms.Remove (f);
+               }
+               #endregion
        }
 }

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-12-07 16:19:22 UTC (rev 69185)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-12-07 16:24:40 UTC (rev 69186)
@@ -1,3 +1,12 @@
+2006-12-07  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * Control.cs: Remove static ArrayList "controls" which maintained
+       a reference to every control created.
+       * Application.cs: Create a static FormCollection to maintain a reference
+       to every form created.  Use it in places that formerly enumerated 
through
+       the controls one looking for forms.
+       * Form.cs: Add and remove self from above FormCollection.
+
 2006-12-07  Alexander Olk  <[EMAIL PROTECTED]>
 
        * MimeIcon.cs: gdk_pixbuf_save_to_buffer is part of libgdk-pixbuf,

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2006-12-07 16:19:22 UTC (rev 69185)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2006-12-07 16:24:40 UTC (rev 69186)
@@ -111,7 +111,6 @@
                internal int                    dist_bottom; // distance to the 
bottom border of the parent
 
                // to be categorized...
-               static internal ArrayList       controls = new ArrayList();  // 
All of the application's controls, in a flat list
                ControlCollection child_controls; // our children
                Control parent; // our parent control
                AccessibleObject accessibility_object; // object that contains 
accessibility information about our control
@@ -800,13 +799,9 @@
                                if (this.InvokeRequired) {
                                        if (Application.MessageLoop) {
                                                this.BeginInvokeInternal(new 
MethodInvoker(DestroyHandle), null, true);
-                                               this.BeginInvokeInternal(new 
RemoveDelegate(controls.Remove), new object[] {this}, true);
                                        }
                                } else {
                                        DestroyHandle();
-                                       lock (Control.controls) {
-                                               Control.controls.Remove(this);
-                                       }
                                }
 
 
@@ -3373,12 +3368,6 @@
                        window.CreateHandle(CreateParams);
 
                        if (window.Handle != IntPtr.Zero) {
-                               lock (Control.controls) {
-                                       if 
(!Control.controls.Contains(window.Handle)) {
-                                               Control.controls.Add(this);
-                                       }
-                               }
-
                                creator_thread = Thread.CurrentThread;
 
                                XplatUI.EnableWindow(window.Handle, is_enabled);

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2006-12-07 16:19:22 UTC (rev 69185)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2006-12-07 16:24:40 UTC (rev 69186)
@@ -1407,6 +1407,8 @@
                protected override void CreateHandle() {
                        base.CreateHandle ();
 
+                       Application.AddForm (this);
+                       
                        UpdateBounds();
 
                        if ((XplatUI.SupportsTransparency() & 
TransparencySupport.Set) != 0) {
@@ -1448,6 +1450,8 @@
                        owned_forms.Clear ();
                        
                        base.Dispose (disposing);
+                       
+                       Application.RemoveForm (this);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to