2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ScrollableControl.cs
index 23230696486617efd8a4e5ced4e6eeeb96040dca..0f667b99e0b25818049d1d9c29579d7732d1cfe8 100644 (file)
 // Authors:
 //     Peter Bartok    pbartok@novell.com
 //
-//
-// $Revision: 1.3 $
-// $Modtime: $
-// $Log: ScrollableControl.cs,v $
-// Revision 1.3  2004/08/12 15:25:49  jordi
-// calls ctrlbase instead of exeception
-//
-// 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
-//
-//
+
 
 // NOT COMPLETE
 
@@ -45,19 +32,21 @@ using System.Drawing;
 
 namespace System.Windows.Forms {
        public class ScrollableControl : Control {
-               #region Public Constructors
-               public ScrollableControl() {
-               }
-               #endregion      // Public Constructors
-
-               #region Protected Static Fields
-               protected const int ScrollStateAutoScrolling = 1;
-               protected const int ScrollStateFullDrag = 16;
-               protected const int ScrollStateHScrollVisible = 2;
-               protected const int ScrollStateUserHasScrolled = 8;
-               protected const int ScrollStateVScrollVisible= 4;
-               #endregion      // Protected Static Fields
-
+               #region Local Variables
+               private bool                    auto_vscroll;
+               private bool                    auto_hscroll;
+               private bool                    hscroll_visible;
+               private bool                    vscroll_visible;
+               private bool                    auto_scroll;
+               private Size                    auto_scroll_margin;
+               private Size                    auto_scroll_min_size;
+               private Point                   auto_scroll_position;
+               private DockPaddingEdges        dock_padding;
+               private ScrollBar               hscrollbar;
+               private ScrollBar               vscrollbar;
+               #endregion      // Local Variables
+
+               [MonoTODO("Need to use the edge values when performing the layout")]
                #region Subclass DockPaddingEdges
                public class DockPaddingEdges : ICloneable {
                        #region DockPaddingEdges Local Variables
@@ -69,7 +58,12 @@ namespace System.Windows.Forms {
                        #endregion      // DockPaddingEdges Local Variables
 
                        #region DockPaddingEdges Constructor
-                       private DockPaddingEdges() {
+                       internal DockPaddingEdges() {
+                               all = 0;
+                               left = 0;
+                               right = 0;
+                               top = 0;
+                               bottom = 0;
                        }
                        #endregion      // DockPaddingEdges Constructor
 
@@ -80,7 +74,11 @@ namespace System.Windows.Forms {
                                }
 
                                set {
-                                       all=value;
+                                       all = value;
+                                       left = value;
+                                       right = value;
+                                       top = value;
+                                       bottom = value;
                                }
                        }
 
@@ -90,7 +88,8 @@ namespace System.Windows.Forms {
                                }
 
                                set {
-                                       bottom=value;
+                                       bottom = value;
+                                       all = 0;
                                }
                        }
 
@@ -101,6 +100,7 @@ namespace System.Windows.Forms {
 
                                set {
                                        left=value;
+                                       all = 0;
                                }
                        }
 
@@ -111,6 +111,7 @@ namespace System.Windows.Forms {
 
                                set {
                                        right=value;
+                                       all = 0;
                                }
                        }
 
@@ -121,6 +122,7 @@ namespace System.Windows.Forms {
 
                                set {
                                        top=value;
+                                       all = 0;
                                }
                        }
 
@@ -163,7 +165,7 @@ namespace System.Windows.Forms {
                                return padding_edge;
                        }
                }
-               #endregion
+               #endregion      // Subclass DockPaddingEdges
 
                #region Subclass DockPaddingEdgesConverter
                public class DockPaddingEdgesConverter : System.ComponentModel.TypeConverter {
@@ -180,59 +182,116 @@ namespace System.Windows.Forms {
                                throw new NotImplementedException();
                        }
                }
-               #endregion
+               #endregion      // Subclass DockPaddingEdgesConverter
+
+               #region Public Constructors
+               public ScrollableControl() {
+                       SetStyle(ControlStyles.ContainerControl, true);
+                       auto_scroll = false;
+                       auto_hscroll = false;
+                       auto_vscroll = false;
+                       hscroll_visible = false;
+                       vscroll_visible = false;
+                       auto_scroll_margin = new Size(0, 0);
+                       auto_scroll_min_size = new Size(0, 0);
+                       auto_scroll_position = new Point(0, 0);
+                       dock_padding = new DockPaddingEdges();
+               }
+               #endregion      // Public Constructors
+
+               #region Protected Static Fields
+               protected const int ScrollStateAutoScrolling    = 1;
+               protected const int ScrollStateFullDrag         = 16;
+               protected const int ScrollStateHScrollVisible   = 2;
+               protected const int ScrollStateUserHasScrolled  = 8;
+               protected const int ScrollStateVScrollVisible   = 4;
+               #endregion      // Protected Static Fields
 
                #region Public Instance Properties
                public virtual bool AutoScroll {
                        get {
-                               throw new NotImplementedException();
+                               return  auto_scroll;
                        }
 
                        set {
-                               throw new NotImplementedException();
+                               if (auto_scroll == value) {
+                                       return;
+                               }
+
+                               auto_scroll = value;
                        }
                }
 
                public Size AutoScrollMargin {
                        get {
-                               throw new NotImplementedException();
+                               return auto_scroll_margin;
                        }
 
                        set {
-                               throw new NotImplementedException();
+                               if (value.Width < 0) {
+                                       throw new ArgumentException("Width is assigned less than 0", "value.Width");
+                               }
+
+                               if (value.Height < 0) {
+                                       throw new ArgumentException("Height is assigned less than 0", "value.Height");
+                               }
+
+                               auto_scroll_margin = value;
                        }
                }
 
                public Size AutoScrollMinSize {
                        get {
-                               throw new NotImplementedException();
+                               return auto_scroll_min_size;
                        }
 
                        set {
-                               throw new NotImplementedException();
+                               auto_scroll_min_size = value;
                        }
                }
 
                public Point AutoScrollPosition {
                        get {
-                               throw new NotImplementedException();
+                               return auto_scroll_position;
                        }
 
                        set {
-                               throw new NotImplementedException();
+                               auto_scroll_position = value;
                        }
                }
 
                public override Rectangle DisplayRectangle {
                        get {
-                               return base.DisplayRectangle;
-                               throw new NotImplementedException();
+                               Rectangle       rect;
+
+                               rect = base.DisplayRectangle;
+
+                               if (vscroll_visible) {
+                                       rect.Width -= vscrollbar.Width;
+                                       if (rect.Width < 0) {
+                                               rect.Width = 0;
+                                       }
+                               }
+
+                               if (hscroll_visible) {
+                                       rect.Height -= hscrollbar.Height;
+                                       if (rect.Height < 0) {
+                                               rect.Height = 0;
+                                       }
+                               }
+                               return rect;
                        }
                }
 
                public DockPaddingEdges DockPadding {
                        get {
-                               throw new NotImplementedException();
+                               return dock_padding;
+                       }
+
+                       // DockPadding is documented as 'get' only ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsScrollableControlClassAutoScrollTopic.asp )
+                       // but Microsoft's on that pageexamples show 'set' usage
+                       set {
+                               dock_padding = value;
                        }
                }
                #endregion      // Public Instance Properties
@@ -240,27 +299,41 @@ namespace System.Windows.Forms {
                #region Protected Instance Methods
                protected override CreateParams CreateParams {
                        get {
-                               return base.CreateParams;
+                               CreateParams    ret;
+
+                               ret = base.CreateParams;
+
+                               ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
+
+                               return ret;
                        }
                }
 
                protected bool HScroll {
                        get {
-                               throw new NotImplementedException();
+                               return hscroll_visible;
                        }
 
                        set {
-                               throw new NotImplementedException();
+                               if (hscroll_visible != value) {
+                                       hscroll_visible = value;
+                                       if (hscroll_visible && hscrollbar == null)
+                                               hscrollbar = new ScrollBar ();
+                               }
                        }
                }
 
                protected bool VScroll {
                        get {
-                               throw new NotImplementedException();
+                               return vscroll_visible;
                        }
 
                        set {
-                               throw new NotImplementedException();
+                               if (vscroll_visible != value) {
+                                       vscroll_visible = value;
+                                       if (vscroll_visible && vscrollbar == null)
+                                               vscrollbar = new ScrollBar ();
+                               }
                        }
                }
                #endregion      // Protected Instance Methods
@@ -283,22 +356,18 @@ namespace System.Windows.Forms {
 
                protected override void OnLayout(LayoutEventArgs levent) {
                        base.OnLayout(levent);
-                       return;
-                       throw new NotImplementedException();
                }
 
                protected override void OnMouseWheel(MouseEventArgs e) {
-base.OnMouseWheel(e);
-return;
-                       throw new NotImplementedException();
+                       base.OnMouseWheel(e);
                }
 
                protected override void OnVisibleChanged(EventArgs e) {
-                       throw new NotImplementedException();
+                       base.OnVisibleChanged(e);
                }
 
                protected override void ScaleCore(float dx, float dy) {
-                       throw new NotImplementedException();
+                       base.ScaleCore(dx, dy);
                }
 
                protected void SetDisplayRectLocation(int x, int y) {