2005-09-08 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Hwnd.cs
index 5df640eb9fb27aba19fe788a0d16651a39a1a2e4..d323f2b6490c672fa1e30edf788da8938c0fb7aa 100644 (file)
@@ -39,7 +39,7 @@ namespace System.Windows.Forms {
        internal class Hwnd : IDisposable {
                #region Local Variables
                private static Hashtable        windows = new Hashtable(100, 0.5f);
-               private const int       menu_height = 14;                       // FIXME - Read this value from somewhere
+               //private const int     menu_height = 14;                       // FIXME - Read this value from somewhere
                private const int       caption_height = 0;                     // FIXME - Read this value from somewhere
                private const int       tool_caption_height = 0;                // FIXME - Read this value from somewhere
 
@@ -64,6 +64,7 @@ namespace System.Windows.Forms {
                internal Graphics       client_dc;
                internal object         user_data;
                internal Rectangle      client_rectangle;
+               internal ArrayList      marshal_free_list;
                #endregion      // Local Variables
 
                #region Constructors and destructors
@@ -85,12 +86,16 @@ namespace System.Windows.Forms {
                        edge_style = Border3DStyle.Raised;
                        client_rectangle = Rectangle.Empty;
                        erase_pending = true;
+                       marshal_free_list = new ArrayList(2);
                }
 
                public void Dispose() {
                        windows[client_window] = null;
                        windows[whole_window] = null;
-Console.WriteLine("Disposing window {0:X} (whole: {1:X})", client_window.ToInt32(), whole_window.ToInt32());
+                       for (int i = 0; i < marshal_free_list.Count; i++) {
+                               Marshal.FreeHGlobal((IntPtr)marshal_free_list[i]);
+                       }
+                       marshal_free_list.Clear();
                }
                #endregion
 
@@ -133,8 +138,13 @@ Console.WriteLine("Disposing window {0:X} (whole: {1:X})", client_window.ToInt32
                        rect = new Rectangle(client_rect.Location, client_rect.Size);
 
                        if (menu_handle != IntPtr.Zero) {
-                               rect.Y -= menu_height;
-                               rect.Height += menu_height;
+                               MenuAPI.MENU menu = MenuAPI.GetMenuFromID (menu_handle);
+                               if (menu != null) {
+                                       int menu_height = menu.Height;
+                                       rect.Y -= menu_height;
+                                       rect.Height += menu_height;
+                               } else
+                                       Console.WriteLine("Hwnd.GetWindowRectangle: No MENU for menu_handle = {0}", menu_handle);
                        }
 
                        if (border_style == BorderStyle.Fixed3D) {
@@ -166,8 +176,13 @@ Console.WriteLine("Disposing window {0:X} (whole: {1:X})", client_window.ToInt32
                        rect = new Rectangle(0, 0, width, height);
 
                        if (menu_handle != IntPtr.Zero) {
-                               rect.Y += menu_height;
-                               rect.Height -= menu_height;
+                               MenuAPI.MENU menu = MenuAPI.GetMenuFromID (menu_handle);
+                               if (menu != null) {
+                                       int menu_height = menu.Height;
+                                       rect.Y += menu_height;
+                                       rect.Height -= menu_height;
+                               } else
+                                       Console.WriteLine("Hwnd.GetClientRectangle: No MENU for menu_handle = {0}", menu_handle);
                        }
 
                        if (border_style == BorderStyle.Fixed3D) {