2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / NativeWindow.cs
index ce69abbe0813c8f1e326eab8ce9ff89463317a9e..d1861af1e8faf3575442ab98c9b13088b4171fa0 100644 (file)
 // Authors:
 //     Peter Bartok    pbartok@novell.com
 //
-//
-// $Revision: 1.3 $
-// $Modtime: $
-// $Log: NativeWindow.cs,v $
-// Revision 1.3  2004/10/02 19:06:20  pbartok
-// - Changed access level for the window_collection hash table
-//
-// Revision 1.2  2004/08/11 22:20:59  pbartok
-// - Signature fixes
-//
-// Revision 1.1  2004/07/09 05:21:25  pbartok
-// - Initial check-in
-//
-//
+
 
 // COMPLETE
 
+#undef ExternalExceptionHandler
+
 using System.Runtime.Remoting;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
@@ -74,6 +63,13 @@ namespace System.Windows.Forms
                }
                #endregion      // Public Static Methods
 
+               #region Private and Internal Static Methods
+               internal static NativeWindow FindWindow(IntPtr handle) {
+                       return (NativeWindow)window_collection[handle];
+                       
+               }
+               #endregion
+
                #region Public Instance Methods
                public void AssignHandle(IntPtr handle) {
                        if (window_handle != IntPtr.Zero) {
@@ -86,7 +82,22 @@ namespace System.Windows.Forms
 
                public virtual void CreateHandle(CreateParams create_params) {
                        if (create_params != null) {
-                               window_handle=XplatUI.CreateWindow(create_params);
+                               Control control;
+
+                               control = ((Control.ControlNativeWindow)this).Owner;
+
+                               if ( !(control is Form) && !(control is Form.FormParentWindow)) {
+                                       window_handle=XplatUI.CreateWindow(create_params);
+                               } else {
+                                       CreateParams    cp;
+
+                                       if (control is Form.FormParentWindow) {
+                                               cp = ((Form.FormParentWindow)control).owner.CreateFormParams;
+                                       } else {
+                                               cp = ((Form)control).CreateClientAreaParams;
+                                       }
+                                       window_handle=XplatUI.CreateWindow(cp);
+                               }
 
                                if (window_handle != IntPtr.Zero) {
                                        window_collection.Add(window_handle, this);
@@ -126,16 +137,16 @@ namespace System.Windows.Forms
                }
 
                protected virtual void WndProc(ref Message m) {
-#if debug
-                       Console.WriteLine("NativeWindow.cs: WndProc(ref Message m) called");
-#endif
                        DefWndProc(ref m);
                }
 
                internal static IntPtr WndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
                        Message         m = new Message();
                        NativeWindow    window = null;
+
+                       #if !ExternalExceptionHandler
                        try {
+                       #endif
                                window = (NativeWindow)window_collection[hWnd];
                                m.HWnd=hWnd;
                                m.Msg=(int)msg;
@@ -148,6 +159,7 @@ namespace System.Windows.Forms
                                } else {
                                        m.Result=XplatUI.DefWndProc(ref m);
                                }
+                       #if !ExternalExceptionHandler
                        }
 
                        catch(System.Exception ex) {
@@ -155,10 +167,11 @@ namespace System.Windows.Forms
                                        window.OnThreadException(ex);
                                }
                        }
+                       #endif
 
-#if debug
-                       Console.WriteLine("NativeWindow.cs: Message {0}, result {1}", msg, m.Result);
-#endif
+                       #if debug
+                               Console.WriteLine("NativeWindow.cs: Message {0}, result {1}", msg, m.Result);
+                       #endif
 
                        return m.Result;
                }