2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / NativeWindow.cs
index edea6ee6cab8ae1a962a70c84356dd70c5c07a40..d1861af1e8faf3575442ab98c9b13088b4171fa0 100644 (file)
 // Authors:
 //     Peter Bartok    pbartok@novell.com
 //
-//
-// $Revision: 1.2 $
-// $Modtime: $
-// $Log: NativeWindow.cs,v $
-// 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;
@@ -46,7 +38,7 @@ namespace System.Windows.Forms
 {
        public class NativeWindow : MarshalByRefObject {
                internal IntPtr                 window_handle;
-               static private Hashtable        window_collection = new Hashtable();
+               static internal Hashtable       window_collection = new Hashtable();
 
                #region Public Constructors
                public NativeWindow() {
@@ -71,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) {
@@ -83,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);
@@ -123,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;
@@ -145,6 +159,7 @@ namespace System.Windows.Forms
                                } else {
                                        m.Result=XplatUI.DefWndProc(ref m);
                                }
+                       #if !ExternalExceptionHandler
                        }
 
                        catch(System.Exception ex) {
@@ -152,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;
                }