Author: toshok
Date: 2006-10-17 21:39:02 -0400 (Tue, 17 Oct 2006)
New Revision: 66777

Modified:
   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
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs
Log:
2006-10-17  Chris Toshok  <[EMAIL PROTECTED]>

        * Form.cs: remove some debug spew, and collapse some duplicate
        code at the end of SetClientSizeCore.

        * XplatUIX11.cs: 
        - add some more debug spew here too wrt Destroy handling.
        - don't call hwnd.Dispose in DestroyWindow, it's effectively done
        in Control's handling of WM_DESTROY.
        - Remove the handling of zombie window DestroyNotifies from the
        event loop - we don't need it.  Now the only DestroyNotifies we
        actually handle are ones generated by X.
        - When sending _NET_ACTIVE_WINDOW, the first param should be 1, to
        match gtk's (functioning) handling of this. This keep metacity
        from leaving droppings in the form of wm borders with no window
        contents all over the place.

        * Control.cs:
        - add a bunch of debug spew wrt control recreation.
        - fix a bug where we weren't tracking Visible properly on
        recreated hwnds.
        - fixed the WM_PAINT double buffer handling to support re-entrant
        calls (yes, i know it's gross, but it's happening to us).



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-10-18 00:01:19 UTC (rev 66776)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-10-18 01:39:02 UTC (rev 66777)
@@ -1,3 +1,27 @@
+2006-10-17  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * Form.cs: remove some debug spew, and collapse some duplicate
+       code at the end of SetClientSizeCore.
+
+       * XplatUIX11.cs: 
+       - add some more debug spew here too wrt Destroy handling.
+       - don't call hwnd.Dispose in DestroyWindow, it's effectively done
+       in Control's handling of WM_DESTROY.
+       - Remove the handling of zombie window DestroyNotifies from the
+       event loop - we don't need it.  Now the only DestroyNotifies we
+       actually handle are ones generated by X.
+       - When sending _NET_ACTIVE_WINDOW, the first param should be 1, to
+       match gtk's (functioning) handling of this. This keep metacity
+       from leaving droppings in the form of wm borders with no window
+       contents all over the place.
+
+       * Control.cs:
+       - add a bunch of debug spew wrt control recreation.
+       - fix a bug where we weren't tracking Visible properly on
+       recreated hwnds.
+       - fixed the WM_PAINT double buffer handling to support re-entrant
+       calls (yes, i know it's gross, but it's happening to us).
+
 2006-10-17  Rolf Bjarne Kvinge  <[EMAIL PROTECTED]>
        * ThemeWin32Classic.cs: changed drawing of selected days
        to make them look better.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2006-10-18 00:01:19 UTC (rev 66776)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2006-10-18 01:39:02 UTC (rev 66777)
@@ -32,6 +32,8 @@
 
 // COMPLETE 
 
+#undef DebugRecreate
+
 using System;
 using System.ComponentModel;
 using System.ComponentModel.Design;
@@ -45,7 +47,6 @@
 using System.Security;
 using System.Threading;
 
-
 namespace System.Windows.Forms
 {
        [Designer("System.Windows.Forms.Design.ControlDesigner, " + 
Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
@@ -116,7 +117,6 @@
                internal ContextMenu            context_menu;           // 
Context menu associated with the control
 
                private Graphics                dc_mem;                 // 
Graphics context for double buffering
-               private GraphicsState           dc_state;               // 
Pristine graphics context to reset after paint code alters dc_mem
                private Bitmap                  bmp_mem;                // 
Bitmap for double buffering control
                private Region                  invalid_region;
 
@@ -914,17 +914,11 @@
                        get { 
                                if (dc_mem == null) {
                                        CreateBuffers(this.Width, this.Height);
-                                       dc_state = dc_mem.Save();
                                }
                                return dc_mem;
                        }
                }
 
-               internal void ResetDeviceContext() {
-                       dc_mem.Restore(dc_state);
-                       dc_state = dc_mem.Save();
-               }
-
                private void ImageBufferNeedsRedraw () {
                        if (invalid_region != null)
                                invalid_region.Dispose();
@@ -941,12 +935,6 @@
                }
 
                internal void CreateBuffers (int width, int height) {
-                       if (dc_mem != null) {
-                               dc_mem.Dispose ();
-                       }
-                       if (bmp_mem != null)
-                               bmp_mem.Dispose ();
-
                        if (width < 1) {
                                width = 1;
                        }
@@ -965,8 +953,6 @@
                        if (dc_mem != null) {
                                dc_mem.Dispose ();
                        }
-                       if (bmp_mem != null)
-                               bmp_mem.Dispose ();
 
                        dc_mem = null;
                        bmp_mem = null;
@@ -3384,6 +3370,7 @@
                                creator_thread = Thread.CurrentThread;
 
                                XplatUI.EnableWindow(window.Handle, is_enabled);
+                               XplatUI.SetVisible(window.Handle, is_visible);
 
                                if (clip_region != null) {
                                        XplatUI.SetClipRegion(Handle, 
clip_region);
@@ -3593,14 +3580,23 @@
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected void RecreateHandle() {
+#if DebugRecreate
+                       Console.WriteLine("Recreating control {0}", 
XplatUI.Window(window.Handle));
+#endif
                        is_recreating=true;
 
                        if (IsHandleCreated) {
+#if DebugRecreate
+                               Console.WriteLine(" + handle is created, 
destroying it.");
+#endif
                                children_to_recreate = new ArrayList();
                                children_to_recreate.AddRange 
(child_controls.GetAllControls ());
                                DestroyHandle();
                                // WM_DESTROY will CreateHandle for us
                        } else {
+#if DebugRecreate
+                               Console.WriteLine(" + handle is not created, 
creating it.");
+#endif
                                if (!is_created) {
                                        CreateControl();
                                } else {
@@ -3608,9 +3604,14 @@
                                }
                                if (parent != null)
                                        parent.RemoveChildFromRecreateList 
(this);
+
+                               is_recreating = false;
+#if DebugRecreate
+                               Console.WriteLine (" + new handle = {0:X}", 
Handle.ToInt32());
+                               Console.WriteLine (" + new parent = {0:X}", 
XplatUIX11.XGetParent (XplatUIX11.XGetParent (Handle)).ToInt32 ());
+#endif
                        }
 
-                       is_recreating = false;
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -3828,6 +3829,12 @@
                                        PerformLayout(this, "visible");
                                }
                        }
+                       else {
+                               Hwnd hwnd = Hwnd.ObjectFromHandle 
(window.Handle);
+                               if (is_visible != hwnd.visible) {
+                                       Console.WriteLine ("oops");
+                               }
+                       }
                }
        
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -3948,12 +3955,26 @@
                        switch((Msg)m.Msg) {
                                case Msg.WM_DESTROY: {
                                        OnHandleDestroyed(EventArgs.Empty);
+#if DebugRecreate
+                                       IntPtr handle = window.Handle;
+#endif
                                        window.InvalidateHandle();
 
                                        if (ParentWaitingOnRecreation (this)) {
+#if DebugRecreate
+                                               Console.WriteLine ("Recreating 
handle for {0:X}, as parent is waiting on us", handle);
+#endif
                                                RecreateHandle();
                                        } else if (is_recreating) {
+#if DebugRecreate
+                                               Console.WriteLine ("Creating 
handle for {0:X}", handle.ToInt32());
+#endif
                                                CreateHandle();
+#if DebugRecreate
+                                               Console.WriteLine (" + new 
handle = {0:X}", Handle.ToInt32());
+                                               Console.WriteLine (" + new 
parent = {0:X}", XplatUIX11.XGetParent (XplatUIX11.XGetParent (Handle)).ToInt32 
());
+#endif
+                                               is_recreating = false;
                                        }
                                        return;
                                }
@@ -3973,10 +3994,8 @@
                                // and here 
http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
                                case Msg.WM_PAINT: {
                                        PaintEventArgs  paint_event;
-                                       bool            reset_context;
 
                                        paint_event = 
XplatUI.PaintEventStart(Handle, true);
-                                       reset_context = false;
 
                                        if (paint_event == null) {
                                                return;
@@ -3990,10 +4009,13 @@
                                        }
 
                                        Graphics dc = null;
+                                       Graphics back_dc = null;
+                                       Bitmap backbuffer = null;
                                        if 
(ThemeEngine.Current.DoubleBufferingSupported) {
                                                if ((control_style & 
ControlStyles.DoubleBuffer) != 0) {
-                                                       dc = 
paint_event.SetGraphics (DeviceContext);
-                                                       reset_context = true;
+                                                       backbuffer = 
ImageBuffer;
+                                                       back_dc = 
Graphics.FromImage (backbuffer);
+                                                       dc = 
paint_event.SetGraphics (back_dc);
                                                }
                                        }
 
@@ -4014,14 +4036,13 @@
                                                        dc.DrawImage 
(ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, 
GraphicsUnit.Pixel);
                                                        paint_event.SetGraphics 
(dc);
                                                        invalid_region.Exclude 
(paint_event.ClipRectangle);
+                                                       back_dc.Dispose ();
+                                                       if (backbuffer != 
bmp_mem)
+                                                               
backbuffer.Dispose();
                                                }
 
                                        XplatUI.PaintEventEnd(Handle, true);
 
-                                       if (reset_context) {
-                                               ResetDeviceContext();
-                                       }
-
                                        return;
                                }
                                        

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2006-10-18 00:01:19 UTC (rev 66776)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2006-10-18 01:39:02 UTC (rev 66777)
@@ -91,7 +91,6 @@
                private void ControlAddedHandler (object sender, 
ControlEventArgs e)
                {
                        if (mdi_container != null) {
-                               Console.WriteLine ("SENDING TO BACK");
                                mdi_container.SendToBack ();
                        }
                }
@@ -1298,7 +1297,6 @@
                                return;
 
                        if (Environment.GetEnvironmentVariable 
("MONO_MWF_SCALING") == "disable"){
-                               Console.WriteLine ("Not scaling");
                                return;
                        }
                        
@@ -1722,14 +1720,8 @@
 
                        clientsize_set = new Size(x, y);
 
-                       if (!IsMdiChild) {
-                               if (XplatUI.CalculateWindowRect(ref ClientRect, 
cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
-                                       SetBounds(bounds.X, bounds.Y, 
WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
-                               }
-                       } else {
-                               if (XplatUI.CalculateWindowRect(ref ClientRect, 
cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
-                                       SetBounds(bounds.X, bounds.Y, 
WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
-                               }
+                       if (XplatUI.CalculateWindowRect(ref ClientRect, 
cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
+                               SetBounds(bounds.X, bounds.Y, WindowRect.Width, 
WindowRect.Height, BoundsSpecified.Size);
                        }
                }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs    
2006-10-18 00:01:19 UTC (rev 66776)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs    
2006-10-18 01:39:02 UTC (rev 66777)
@@ -1581,7 +1581,7 @@
 
                        return (IntPtr)result;
                }
-               private IntPtr XGetParent(IntPtr handle) {
+               internal static IntPtr XGetParent(IntPtr handle) {
                        IntPtr  Root;
                        IntPtr  Parent;
                        IntPtr  Children;
@@ -1616,7 +1616,11 @@
                                if (c.IsHandleCreated && !c.IsDisposed) {
                                        Hwnd hwnd = 
Hwnd.ObjectFromHandle(c.Handle);
 
-                                       list.Add (hwnd.Handle);
+                                       #if DriverDebug || DriverDebugDestroy
+                                       Console.WriteLine (" + adding {0} to 
the list of zombie windows", XplatUI.Window (hwnd.Handle));
+                                       #endif
+
+                                       list.Add (hwnd);
                                        CleanupCachedWindows (hwnd);
                                        hwnd.zombie = true;
                                }
@@ -1628,12 +1632,6 @@
                        
                }
 
-               private void SendWMDestroyMessages(ArrayList handles) {
-                       foreach (IntPtr handle in handles) {
-                               SendMessage(handle, Msg.WM_DESTROY, 
IntPtr.Zero, IntPtr.Zero);
-                       }
-               }
-
                void CleanupCachedWindows (Hwnd hwnd)
                {
                        if (ActiveWindow == hwnd.Handle) {
@@ -2059,11 +2057,16 @@
 
                        hwnd = Hwnd.ObjectFromHandle(handle);
 
-                       if (hwnd != null) lock (XlibLock) {
-                               SendNetWMMessage(hwnd.whole_window, 
_NET_ACTIVE_WINDOW, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
-                               //XRaiseWindow(DisplayHandle, handle);
+                       if (hwnd != null) {
+                               lock (XlibLock) {
+                                       if (true /* the window manager supports 
NET_ACTIVE_WINDOW */) {
+                                               
SendNetWMMessage(hwnd.whole_window, _NET_ACTIVE_WINDOW, (IntPtr)1, IntPtr.Zero, 
IntPtr.Zero);
+                                       }
+                                       else {
+                                               //XRaiseWindow(DisplayHandle, 
handle);
+                                       }
+                               }
                        }
-                       return;
                }
 
                internal override void AudibleAlert() {
@@ -2820,7 +2823,8 @@
                        }
 
                        #if DriverDebug || DriverDebugDestroy
-                               Console.WriteLine("Destroying window {0:X}", 
handle.ToInt32());
+                               Console.WriteLine("Destroying window {0}", 
XplatUI.Window(hwnd.client_window));
+                               Console.WriteLine (Environment.StackTrace);
                        #endif
 
                        CleanupCachedWindows (hwnd);
@@ -2831,17 +2835,23 @@
 
                        lock (XlibLock) {
                                if (hwnd.whole_window != IntPtr.Zero) {
+                                       #if DriverDebug || DriverDebugDestroy
+                                       Console.WriteLine ("XDestroyWindow 
(whole_window = {0:X})", hwnd.whole_window.ToInt32());
+                                       #endif
                                        XDestroyWindow(DisplayHandle, 
hwnd.whole_window);
                                }
                                else if (hwnd.client_window != IntPtr.Zero) {
+                                       #if DriverDebug || DriverDebugDestroy
+                                       Console.WriteLine ("XDestroyWindow 
(client_window = {0:X})", hwnd.client_window.ToInt32());
+                                       #endif
                                        XDestroyWindow(DisplayHandle, 
hwnd.client_window);
                                }
 
                        }
 
-                       SendWMDestroyMessages(windows);
-
-                       hwnd.Dispose();
+                       foreach (Hwnd h in windows) {
+                               SendMessage (h.Handle, Msg.WM_DESTROY, 
IntPtr.Zero, IntPtr.Zero);
+                       }
                }
 
                internal override IntPtr DispatchMessage(ref MSG msg) {
@@ -3118,8 +3128,8 @@
                        // hwnds, since much of the event handling code makes 
requests using the hwnd's
                        // client_window, and that'll result in BadWindow 
errors if there's some lag
                        // between the XDestroyWindow call and the 
DestroyNotify event.
-                       if (hwnd == null || (hwnd.zombie && xevent.type != 
XEventName.DestroyNotify)) {
-                               #if DriverDebug
+                       if (hwnd == null || hwnd.zombie) {
+                               #if DriverDebug || DriverDebugDestroy
                                        Console.WriteLine("GetMessage(): Got 
message {0} for non-existent or already destroyed window {1:X}", xevent.type, 
xevent.AnyEvent.window.ToInt32());
                                #endif
                                goto ProcessNextMessage;
@@ -3613,17 +3623,9 @@
                                                        
Console.WriteLine("Received X11 Destroy Notification for {0}", 
XplatUI.Window(hwnd.client_window));
                                                #endif
 
-                                               if (hwnd.zombie) {
-                                                       /* this window is being 
destroyed via DestroyWindow, so we let that code
-                                                          take care of sending 
the WM_DESTROY message.  Just dispose of it here. */
-                                                       hwnd.Dispose ();
-                                                       goto ProcessNextMessage;
-                                               }
-                                               else {
-                                                       msg.hwnd = 
hwnd.client_window;
-                                                       
msg.message=Msg.WM_DESTROY;
-                                                       hwnd.Dispose();
-                                               }
+                                               msg.hwnd = hwnd.client_window;
+                                               msg.message=Msg.WM_DESTROY;
+                                               hwnd.Dispose();
                                        } else {
                                                goto ProcessNextMessage;
                                        }
@@ -4769,7 +4771,7 @@
                                        XChangeProperty(DisplayHandle, 
hwnd.whole_window, _NET_WM_USER_TIME, (IntPtr)Atom.XA_CARDINAL, 32, 
PropertyMode.Replace, atoms, 1);
 
                                        XRaiseWindow(DisplayHandle, 
hwnd.whole_window);
-                                       SendNetWMMessage(hwnd.whole_window, 
_NET_ACTIVE_WINDOW, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+                                       SendNetWMMessage(hwnd.whole_window, 
_NET_ACTIVE_WINDOW, (IntPtr)1, IntPtr.Zero, IntPtr.Zero);
                                        return true;
                                        //throw new 
ArgumentNullException("after_handle", "Need sibling to adjust z-order");
                                }

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

Reply via email to