2007-02-23 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index 8663620cdaddfca7bf5a1223ca98c15a98d4a2e8..724b3b2d344c7c8b31e77329621bba8690eeea9c 100644 (file)
@@ -151,7 +151,7 @@ namespace System.Windows.Forms {
                        }
                }
                
-               private void UpdateSizeGripVisible ()
+               private new void UpdateSizeGripVisible ()
                {
                        // Following link explains when to show size grip:
                        // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=138687&SiteID=1
@@ -177,12 +177,10 @@ namespace System.Windows.Forms {
                                        size_grip.Visible = false;
                        } else {
                                if (size_grip == null) {
-                                       size_grip = new SizeGrip ();
-                                       this.Controls.AddImplicit (size_grip);
+                                       size_grip = new SizeGrip (this);
+                                       size_grip.Virtual = true;
+                                       size_grip.FillBackground = false;
                                }
-                               size_grip.Width = SystemInformation.VerticalScrollBarWidth;
-                               size_grip.Height = SystemInformation.HorizontalScrollBarHeight;
-                               size_grip.Location = new Point (ClientSize.Width - size_grip.Width, ClientSize.Height - size_grip.Height);
                                size_grip.Visible = true;
                        }
                }
@@ -1131,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) {
@@ -1278,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
@@ -1400,23 +1409,30 @@ namespace System.Windows.Forms {
                        }
 
                        if (owner == this) {
-                               throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
+                               throw new ArgumentException ("Forms cannot own themselves or their owners.", "owner");
                        }
 
                        if (is_modal) {
-                               throw new InvalidOperationException("The form is already displayed as a modal dialog.");
+                               throw new InvalidOperationException ("The form is already displayed as a modal dialog.");
                        }
 
                        if (Visible) {
-                               throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
+                               throw new InvalidOperationException ("Forms that are already "
+                                       + " visible cannot be displayed as a modal dialog. Set the"
+                                       + " form's visible property to false before calling"
+                                       + " ShowDialog.");
                        }
 
                        if (!Enabled) {
-                               throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
+                               throw new InvalidOperationException ("Forms that are not enabled"
+                                       + " cannot be displayed as a modal dialog. Set the form's"
+                                       + " enabled property to true before calling ShowDialog.");
                        }
 
                        if (TopLevelControl != this) {
-                               throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
+                               throw new InvalidOperationException ("Forms that are not top level"
+                                       + " forms cannot be displayed as a modal dialog. Remove the"
+                                       + " form from any parent form before calling ShowDialog.");
                        }
 
                        #if broken
@@ -1584,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);
@@ -1775,16 +1794,16 @@ namespace System.Windows.Forms {
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void OnPaint (PaintEventArgs pevent) {
                        base.OnPaint (pevent);
+
+                       if (size_grip != null) {
+                               size_grip.HandlePaint (this, pevent);
+                       }
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void OnResize(EventArgs e) {
                        base.OnResize(e);
 
-                       
-                       if (this.size_grip != null && this.size_grip.Visible) {
-                               this.size_grip.Location = new Point (ClientSize.Width - size_grip.Width, ClientSize.Height - size_grip.Height);
-                       }
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -2104,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));
                                        }
@@ -2121,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 ()),
@@ -2223,7 +2261,10 @@ namespace System.Windows.Forms {
                                                active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
                                                return;
                                        }
-                                       base.WndProc(ref m);
+#if NET_2_0
+                                       ToolStripManager.FireAppClicked ();
+#endif
+                                       base.WndProc (ref m);
                                        return;
                                }