* Form.cs: remove the try-catch's around calls to GetWindowState.
authorChris Toshok <toshok@novell.com>
Sun, 29 Oct 2006 16:13:59 +0000 (16:13 -0000)
committerChris Toshok <toshok@novell.com>
Sun, 29 Oct 2006 16:13:59 +0000 (16:13 -0000)
We can just check the return value.

* XplatUIX11.cs: don't throw exceptions from GetWindowState.
Instead return -1.

* XplatUI.cs: Add note about additional return value for
GetWindowState.

2006-10-29  Chris Toshok  <toshok@ximian.com>

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUI.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs

index d7a1c1b5ff231d1aa23ac532777bf72b872d5419..0cbe9de68df14db60f584626adfa84fa5a771838 100644 (file)
@@ -1,3 +1,14 @@
+2006-10-29  Chris Toshok  <toshok@ximian.com>
+
+       * Form.cs: remove the try-catch's around calls to GetWindowState.
+       We can just check the return value.
+
+       * XplatUIX11.cs: don't throw exceptions from GetWindowState.
+       Instead return -1.
+
+       * XplatUI.cs: Add note about additional return value for
+       GetWindowState.
+
 2006-10-29  Chris Toshok  <toshok@ximian.com>
 
        * Control.cs (CreateHandle): when we create our handle, we also
index 8e3f13f101df51619aa28a48e3a010d49763251a..57d78c549546c750c49dfa22744ba6b785bedb34 100644 (file)
@@ -925,12 +925,9 @@ namespace System.Windows.Forms {
                                        if (window_manager != null)
                                                return window_manager.GetWindowState ();
 
-                                       try {
-                                               window_state = XplatUI.GetWindowState(Handle);
-                                       }
-
-                                       catch(NotSupportedException) {
-                                       }
+                                       FormWindowState new_state = XplatUI.GetWindowState(Handle);
+                                       if (new_state != (FormWindowState)(-1))
+                                               window_state = new_state;
                                }
 
                                return window_state;
@@ -946,12 +943,7 @@ namespace System.Windows.Forms {
                                                return;
                                        }
 
-                                       try {
-                                               XplatUI.SetWindowState(Handle, value);
-                                       }
-
-                                       catch(NotSupportedException) {
-                                       }
+                                       XplatUI.SetWindowState(Handle, value);
                                }
                        }
                }
index 4441bdbd638828a9626051ddedc9702e51b8c312..ae24102a28f733dff7e3c3a55bbbc0882a68b565 100644 (file)
@@ -545,6 +545,12 @@ namespace System.Windows.Forms {
                        driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
                }
 
+               /* this method can (and does, on X11) return
+                * (FormWindowState)(-1), when the state of the window
+                * cannot be determined (in the X11 case, when the
+                * window isn't mapped.)  Checking for the additional
+                * return value is less expensive than
+                * throwing/catching an exception. */
                internal static FormWindowState GetWindowState(IntPtr handle) {
                        #if DriverDebug
                                Console.WriteLine("GetWindowState({0}): Called", Window(handle));
index 1692a69c27e69706dc82badab2e86c096259c597..92add2473b7d2a45eb2b6c037bae069d5abb2290 100644 (file)
@@ -858,12 +858,9 @@ namespace System.Windows.Forms {
                        mwmHints.functions = (IntPtr)functions;
                        mwmHints.decorations = (IntPtr)decorations;
 
-                       FormWindowState current_state = FormWindowState.Normal;
-                       try {
-                               current_state = GetWindowState (hwnd.Handle);
-                       }
-                       catch (NotSupportedException) {
-                       }
+                       FormWindowState current_state = GetWindowState (hwnd.Handle);
+                       if (current_state == (FormWindowState)(-1))
+                               current_state = FormWindowState.Normal;
 
                        client_rect = hwnd.ClientRect;
                        lock (XlibLock) {
@@ -3779,7 +3776,7 @@ namespace System.Windows.Forms {
                        attributes = new XWindowAttributes();
                        XGetWindowAttributes(DisplayHandle, hwnd.client_window, ref attributes);
                        if (attributes.map_state == MapState.IsUnmapped) {
-                               throw new NotSupportedException("Cannot retrieve the state of an unmapped window");
+                               return (FormWindowState)(-1);
                        }
 
 
@@ -4667,12 +4664,7 @@ namespace System.Windows.Forms {
 
                        hwnd = Hwnd.ObjectFromHandle(handle);
 
-                       try {
-                               current_state = GetWindowState(handle);
-                       }
-                       catch (NotSupportedException) {
-                               current_state = (FormWindowState)(-1);
-                       }
+                       current_state = GetWindowState(handle);
 
                        if (current_state == state) {
                                return;