* Control.cs: We need to reset the is_created flags when the handle is
authorRolf Bjarne Kvinge <RKvinge@novell.com>
Tue, 31 Jul 2007 10:55:20 +0000 (10:55 -0000)
committerRolf Bjarne Kvinge <RKvinge@novell.com>
Tue, 31 Jul 2007 10:55:20 +0000 (10:55 -0000)
  destroyed. Fixes #82187.
* XplatUIWin32.cs: In GetWindowRect don't offset screen coordinates to
  client coordinates if the window doesn't have a parent.
  Win32GetParent returns the parent or the owner, and for top-level
  windows with no parent (but with an owner) we were calculating the
  location from the location of the owner.
* Form.cs: Remove incorrect fix for #82187. Don't raise OnLoad if the
  form has been disposed.
* MdiClient.cs: Add a null-check.

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiClient.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIWin32.cs

index 038459cd01f46acfbec4b530c6c4c6d8af0b7028..be3404bb9a1579dcd4d4b5c84777865cf3a2c778 100644 (file)
@@ -1,3 +1,16 @@
+2007-07-31  Rolf Bjarne Kvinge <RKvinge@novell.com> 
+
+       * Control.cs: We need to reset the is_created flags when the handle is
+         destroyed. Fixes #82187.
+       * XplatUIWin32.cs: In GetWindowRect don't offset screen coordinates to
+         client coordinates if the window doesn't have a parent.
+         Win32GetParent returns the parent or the owner, and for top-level
+         windows with no parent (but with an owner) we were calculating the
+         location from the location of the owner.
+       * Form.cs: Remove incorrect fix for #82187. Don't raise OnLoad if the
+         form has been disposed.
+       * MdiClient.cs: Add a null-check.
+
 2007-07-30  Jonathan Pobst  <monkey@jpobst.com>
 
        * TextBoxBase.cs: TextBoxBase reports itself at AutoSize, but doesn't
index fb925395a99bd3f39ba83f6c09e65f1dba4aebca..97d9cba4755e42418df49c9bd1a324cb589c0bad 100644 (file)
@@ -5115,6 +5115,7 @@ namespace System.Windows.Forms
 #endif
                        window.InvalidateHandle();
 
+                       is_created = false;
                        if (is_recreating) {
 #if DebugRecreate
                                Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
index 189c855a1a8f3022ae3f09dc1e92cd76923c77f2..8c679448b6c0e51f80cde844ddee953befb0ae0a 100644 (file)
@@ -1709,11 +1709,7 @@ namespace System.Windows.Forms {
                        }
                        
                        if (IsHandleCreated) {
-                               // All CommonDialogs assume the form is still alive after a ShowDialog,
-                               // so don't destroy the handle in this case. Fix for #82187.
-                               if (!(this is CommonDialog.DialogForm)) {
-                                       DestroyHandle ();
-                               }
+                               DestroyHandle ();
                        }
 
                        if (DialogResult == DialogResult.None) {
@@ -2821,8 +2817,10 @@ namespace System.Windows.Forms {
                                AutoScale = false;
                        }
 
-                       OnLoad (e);
-
+                       if (!IsDisposed) {
+                               OnLoad (e);
+                       }
+                       
                        if (!IsMdiChild && !IsDisposed) {
                                switch (StartPosition) {
                                        case FormStartPosition.CenterScreen:
index 897bb094712964b763502566d9d7169b0516306b..4a57b97fbf6a4edf0996778b6fd6ca9b83c003c3 100644 (file)
@@ -894,7 +894,7 @@ namespace System.Windows.Forms {
                internal Form ActiveMdiChild {
                        get {
 #if NET_2_0
-                               if (!ParentForm.Visible)
+                               if (ParentForm != null && !ParentForm.Visible)
                                        return null;
 #endif
                                if (Controls.Count < 1)
index 82290a26dc62163a0b3943aeaea9cfbcdfc1ad14..2289fdb3f421bfd8b59f6ab1c41308bd679fc364 100644 (file)
@@ -411,6 +411,12 @@ namespace System.Windows.Forms {
                        Last                            = 32651
                }
 
+               private enum AncestorType {
+                       GA_PARENT = 1,
+                       GA_ROOT = 2, 
+                       GA_ROOTOWNER = 3
+               }
+
                [Flags]
                private enum WindowLong {
                        GWL_WNDPROC                     = -4,
@@ -1812,8 +1818,9 @@ namespace System.Windows.Forms {
                        pt.x=rect.left;
                        pt.y=rect.top;
 
-                       parent = Win32GetParent(handle);
-                       Win32ScreenToClient(parent, ref pt);
+                       parent = Win32GetAncestor (handle, AncestorType.GA_PARENT);
+                       if (parent != IntPtr.Zero && parent != Win32GetDesktopWindow ())
+                               Win32ScreenToClient(parent, ref pt);
 
                        x = pt.x;
                        y = pt.y;
@@ -3272,9 +3279,14 @@ namespace System.Windows.Forms {
                [DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
                private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
 
+               // This function returns the parent OR THE OWNER!
+               // Use GetAncestor to only get the parent.
                [DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
                private extern static IntPtr Win32GetParent(IntPtr hWnd);
 
+               [DllImport ("user32.dll", EntryPoint = "GetAncestor", CallingConvention = CallingConvention.StdCall)]
+               private extern static IntPtr Win32GetAncestor (IntPtr hWnd, AncestorType flags);
+
                [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
                private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);