* XplatUIX11.cs: Removed unused hwnd var in SetBorderStyle.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / SizeGrip.cs
index d399a3cac6ddec09c613119c25b4933a99070abf..a8a2c51d7d44dda0b7c5dc357039c953430cdbeb 100644 (file)
 // Authors:
 //     Jackson Harper (jackson@ximian.com)
 
-// TODO: Eventually we need to handle the cursor and resizing the parent
-
 using System;
 using System.Drawing;
 
 namespace System.Windows.Forms {
 
        internal class SizeGrip : Control {
+               #region Local Variables
+               private bool    redraw;
+               private Point   capture_point;
+               private Control captured_control;
+               private int     window_w;
+               private int     window_h;
+               private bool    show_grip;
+               private bool    hide_pending;
+               #endregion      // Local Variables
 
-               private bool redraw = true;
-               
+               #region Constructors
                public SizeGrip ()
                {
+                       this.Cursor = Cursors.SizeNWSE;
+                       show_grip = true;
+                       redraw = true;
+                       hide_pending = false;
                }
+               #endregion      // Constructors
 
-               protected override void OnPaint (PaintEventArgs pe)
-               {
-                       base.OnPaint (pe);
+               #region Properties
+               
+               public Control CapturedControl {
+                       get {
+                               if (captured_control != null)
+                                       return captured_control;
+                               else
+                                       return Parent;
+                       }
+                       set {
+                               captured_control = value;
+                       }
+               }
+               
+               public bool ShowGrip {
+                       get {
+                               return show_grip;
+                       }
 
-                       if (redraw)
-                               Draw ();
+                       set {
+                               show_grip = value;
+                               redraw = true;
+                       }
+               }
+               #endregion      // Properties
 
-                       pe.Graphics.DrawImage (ImageBuffer, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
+               #region Methods
+               protected override void OnPaint (PaintEventArgs pe) {
+                       if (redraw && show_grip) {
+                               pe.Graphics.FillRectangle (new SolidBrush (ThemeEngine.Current.ColorControl), ClientRectangle);
+                                ControlPaint.DrawSizeGrip (pe.Graphics, BackColor, ClientRectangle);
+                       }
+                       base.OnPaint (pe);
                }
 
-               protected override void OnSizeChanged (EventArgs e)
-               {
+               protected override void OnSizeChanged (EventArgs e) {
                        base.OnSizeChanged (e);
                        redraw = true;
                }
 
-               protected override void OnVisibleChanged (EventArgs e)
-               {
+               protected override void OnVisibleChanged (EventArgs e) {
                        base.OnVisibleChanged (e);
                        redraw = true;
                }
 
-               private void Draw ()
-               {
-                       ControlPaint.DrawSizeGrip (DeviceContext, BackColor, ClientRectangle);
-                       redraw = false;
+               protected override void OnMouseDown(MouseEventArgs e) {
+                       Capture = true;
+                       
+                       capture_point = Control.MousePosition;
+
+                       window_w = CapturedControl.Width;
+                       window_h = CapturedControl.Height;
+               }
+
+               protected override void OnMouseMove(MouseEventArgs e) {
+                       if (Capture) {
+                               int     delta_x;
+                               int     delta_y;
+                               Point   current_point;
+
+                               current_point = Control.MousePosition;
+
+                               delta_x = current_point.X - capture_point.X;
+                               delta_y = current_point.Y - capture_point.Y;
+
+                               CapturedControl.Size = new Size(window_w + delta_x, window_h + delta_y);
+                               XplatUI.DoEvents();
+                       }
                }
-       }
 
+               protected override void OnMouseUp(MouseEventArgs e) {
+                       if (Capture) {
+                               Capture = false;
+                               if (hide_pending) {
+                                       Hide();
+                                       hide_pending = false;
+                               }
+                       }
+               }
+
+
+               protected override void SetVisibleCore(bool value) {
+                       if (Capture) {
+                               if (value == false) {
+                                       hide_pending = true;
+                               } else {
+                                       hide_pending = false;
+                               }
+                               return;
+                       }
+                       base.SetVisibleCore (value);
+               }
+
+               #endregion      // Methods
+       }
 }