2007-02-23 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index 936d24d37fa16fb8e386655b858b979c032e38d2..724b3b2d344c7c8b31e77329621bba8690eeea9c 100644 (file)
@@ -246,6 +246,9 @@ namespace System.Windows.Forms {
                        owned_forms = new Form.ControlCollection(this);
                        transparency_key = Color.Empty;
 
+                       // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
+                       UpdateBounds();
+
                }
                #endregion      // Public Constructor & Destructor
 
@@ -672,8 +675,7 @@ namespace System.Windows.Forms {
                                        mdi_parent.MdiContainer.Controls.Add (this);
                                        mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
 
-                                       if (IsHandleCreated)
-                                               RecreateHandle ();
+                                       RecreateHandle ();
 
                                } else if (mdi_parent != null) {
                                        mdi_parent = null;
@@ -682,8 +684,7 @@ namespace System.Windows.Forms {
                                        window_manager = null;
                                        FormBorderStyle = form_border_style;
 
-                                       if (IsHandleCreated)
-                                               RecreateHandle ();
+                                       RecreateHandle ();
                                }
                        }
                }
@@ -1128,6 +1129,11 @@ namespace System.Windows.Forms {
 
                                cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
 
+                               if (Parent != null) {
+                                       cp.Parent = Parent.Handle;
+                                       cp.Style |= (int) WindowStyles.WS_CHILD;
+                               }
+
                                if (IsMdiChild) {
                                        cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
                                        if (Parent != null) {
@@ -1275,6 +1281,12 @@ namespace System.Windows.Forms {
                                }
                        }
                }
+#if NET_2_0
+               [MonoTODO ("Implemented for Win32, needs X11 implementation")]
+               protected virtual bool ShowWithoutActivation {
+                       get { return false; }
+               }
+#endif
                #endregion      // Protected Instance Properties
 
                #region Public Static Methods
@@ -1588,6 +1600,9 @@ namespace System.Windows.Forms {
                                }
                        }
 
+                       if (this.ShowWithoutActivation)
+                               Hwnd.ObjectFromHandle (this.Handle).no_activate = true;
+
                        XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
                        if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
                                XplatUI.SetIcon(window.Handle, icon);
@@ -1970,8 +1985,7 @@ namespace System.Windows.Forms {
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
-               protected override void SetVisibleCore(bool value)
-               {
+               protected override void SetVisibleCore(bool value) {
                        is_changing_visible_state = true;
                        has_been_visible = value || has_been_visible;
                        base.SetVisibleCore (value);
@@ -2109,7 +2123,25 @@ namespace System.Windows.Forms {
                                }
 
                                // Menu drawing
-                               case Msg.WM_NCLBUTTONDOWN: {
+                case Msg.WM_NCHITTEST: {
+                                       if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
+                                               int x = LowOrder ((int)m.LParam.ToInt32 ());
+                                               int y = HighOrder ((int)m.LParam.ToInt32 ());
+
+                                               XplatUI.ScreenToMenu (ActiveMenu.Wnd.window.Handle, ref x, ref y);
+
+                                               // If point is under menu return HTMENU, it prevents Win32 to return HTMOVE.
+                                               if ((x > 0) && (y > 0) && (x < ActiveMenu.Rect.Width) && (y < ActiveMenu.Rect.Height)) {
+                                                       m.Result = new IntPtr ((int)HitTest.HTMENU);
+                                                       return;
+                                               }
+                                       }
+
+                                       base.WndProc (ref m);
+                                       return;
+                               }
+
+                case Msg.WM_NCLBUTTONDOWN: {
                                        if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
                                                ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
                                        }
@@ -2126,7 +2158,8 @@ namespace System.Windows.Forms {
                                        base.WndProc(ref m);
                                        return;
                                }
-                               case Msg.WM_NCLBUTTONUP: {
+
+                case Msg.WM_NCLBUTTONUP: {
                                        if (ActiveMaximizedMdiChild != null) {
                                                ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
                                                                LowOrder ((int)m.LParam.ToInt32 ()),