2008-10-15 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Wed, 15 Oct 2008 19:30:21 +0000 (19:30 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Wed, 15 Oct 2008 19:30:21 +0000 (19:30 -0000)
* XplatUIX11.cs, XplatUICarbon.cs: Do not Timer.Tick before
MainForm.OnLoad has completed unless DoEvents is forced.
[Fixes bug #412536]

svn path=/trunk/mcs/; revision=115910

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs

index 0490197454e2f0a5e5f6af0f196b2ec943e723c6..3913571ab47fbe90765e7a531f0c3a867bd40196 100644 (file)
@@ -1,3 +1,9 @@
+2008-10-15  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * XplatUIX11.cs, XplatUICarbon.cs: Do not Timer.Tick before 
+       MainForm.OnLoad has completed unless DoEvents is forced.
+       [Fixes bug #412536]
+
 2008-10-15  Jonathan Pobst  <monkey@jpobst.com>
 
        * ToolTip.cs: Ensure that Timer.Internal cannot be set to 0.
index 86e3d3c00e8b73accfa5cf7235d300d6d1b9a04a..f157744f8d672fb6f46baaba96c695bc2f328a61 100644 (file)
@@ -87,6 +87,7 @@ namespace System.Windows.Forms {
 
                // Timers
                private ArrayList TimerList;
+               private static bool in_doevents;
                
                static readonly object instancelock = new object ();
                static readonly object queuelock = new object ();
@@ -100,6 +101,7 @@ namespace System.Windows.Forms {
 
                        RefCount = 0;
                        TimerList = new ArrayList ();
+                       in_doevents = false;
                        MessageQueue = new Queue ();
                        
                        Initialize ();
@@ -486,12 +488,14 @@ namespace System.Windows.Forms {
                                for (int i = 0; i < TimerList.Count; i++) {
                                        Timer timer = (Timer) TimerList [i];
                                        if (timer.Enabled && timer.Expires <= now) {
-                                               // Prevent the Timer from ticking before MainForm.OnLoad has 
-                                               // completed. This seems to be the case with Win32.
+                                               // Timer ticks:
+                                               //  - Before MainForm.OnLoad if DoEvents () is called.
+                                               //  - After MainForm.OnLoad if not.
                                                //
-                                               if (Application.MWFThread.Current.Context != null && 
-                                                   Application.MWFThread.Current.Context.MainForm != null && 
-                                                   Application.MWFThread.Current.Context.MainForm.IsLoaded) {
+                                               if (in_doevents ||
+                                                   (Application.MWFThread.Current.Context != null && 
+                                                    Application.MWFThread.Current.Context.MainForm != null && 
+                                                    Application.MWFThread.Current.Context.MainForm.IsLoaded)) {
                                                        timer.FireTick ();
                                                        timer.Update (now);
                                                }
@@ -1244,10 +1248,12 @@ namespace System.Windows.Forms {
                internal override void DoEvents() {
                         MSG     msg = new MSG ();
 
+                       in_doevents = true;
                        while (PeekMessage (null, ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)) {
                                 TranslateMessage (ref msg);
                                 DispatchMessage (ref msg);
                         }
+                       in_doevents = false;
 
                }
 
index e3d5d7f13d4aea5cd3c72c4495a7226bdfff34a2..e1da6aff97aa21afa45796ff35d535b2c4374333 100644 (file)
@@ -217,7 +217,7 @@ namespace System.Windows.Forms {
                // State
                Point           mouse_position;         // Last position of mouse, in screen coords
                internal static MouseButtons    MouseState;             // Last state of mouse buttons
-
+               internal static bool in_doevents;
                // 'Constants'
                private static int              DoubleClickInterval;    // msec; max interval between clicks to count as double click
 
@@ -240,6 +240,7 @@ namespace System.Windows.Forms {
                private XplatUIX11() {
                        // Handle singleton stuff first
                        RefCount = 0;
+                       in_doevents = false;
 
                        // Now regular initialization
                        XlibLock = new object ();
@@ -1393,12 +1394,14 @@ namespace System.Windows.Forms {
                                timer = (Timer) timers [i];
 
                                if (timer.Enabled && timer.Expires <= now && !timer.Busy) {
-                                       // Prevent the Timer from ticking before MainForm.OnLoad has 
-                                       // completed. This seems to be the case with Win32.
+                                       // Timer ticks:
+                                       //  - Before MainForm.OnLoad if DoEvents () is called.
+                                       //  - After MainForm.OnLoad if not.
                                        //
-                                       if (Application.MWFThread.Current.Context != null && 
-                                           Application.MWFThread.Current.Context.MainForm != null && 
-                                           Application.MWFThread.Current.Context.MainForm.IsLoaded) {
+                                       if (in_doevents ||
+                                           (Application.MWFThread.Current.Context != null && 
+                                            Application.MWFThread.Current.Context.MainForm != null && 
+                                            Application.MWFThread.Current.Context.MainForm.IsLoaded)) {
                                                timer.Busy = true;
                                                timer.Update (now);
                                                timer.FireTick ();
@@ -3494,12 +3497,14 @@ namespace System.Windows.Forms {
                        queue = ThreadQueue(Thread.CurrentThread);
 
                        queue.DispatchIdle = false;
+                       in_doevents = true;
 
                        while (PeekMessage(queue, ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)) {
                                TranslateMessage (ref msg);
                                DispatchMessage (ref msg);
                        }
 
+                       in_doevents = false;
                        queue.DispatchIdle = true;
                }