dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms Control.cs,1.10


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms Control.cs,1.10,1.11
Date: Mon, 16 Jun 2003 21:04:57 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv23887/System.Windows.Forms

Modified Files:
        Control.cs 
Log Message:


Implement docking and anchoring in the "Control" class.


Index: Control.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Control.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** Control.cs  14 Jun 2003 00:36:44 -0000      1.10
--- Control.cs  17 Jun 2003 01:04:55 -0000      1.11
***************
*** 40,43 ****
--- 40,44 ----
        private Control parent;
        private int left, top, width, height;
+       private int prevParentWidth, prevParentHeight;
        private String text;
        private String name;
***************
*** 61,64 ****
--- 62,67 ----
        private bool tabStop;
        private bool disposed;
+       private bool performingLayout;
+       private int layoutSuspended;
        private Object tag;
        private ControlStyles styles;
***************
*** 918,921 ****
--- 921,930 ----
                                                
OnBindingContextChanged(EventArgs.Empty);
                                        }
+ 
+                                       // Create the control if it will be 
visible.
+                                       if(Visible)
+                                       {
+                                               CreateControl();
+                                       }
                                }
                        }
***************
*** 1519,1523 ****
        protected bool GetTopLevel()
                        {
!                               return (parent == null);
                        }
  
--- 1528,1532 ----
        protected bool GetTopLevel()
                        {
!                               return IsTopLevel;
                        }
  
***************
*** 1529,1536 ****
  
        // Initialize layout as this control has just been added to a container.
-       [TODO]
        protected virtual void InitLayout()
                        {
!                               // TODO
                        }
  
--- 1538,1551 ----
  
        // Initialize layout as this control has just been added to a container.
        protected virtual void InitLayout()
                        {
!                               if(Dock == DockStyle.None)
!                               {
!                                       // Record the current width and height 
of the parent
!                                       // control so that we can reposition 
during layout later.
!                                       Rectangle rect = 
parent.DisplayRectangle;
!                                       prevParentWidth = rect.Width;
!                                       prevParentHeight = rect.Height;
!                               }
                        }
  
***************
*** 1644,1657 ****
  
        // Force the child to perform layout.
-       [TODO]
        public void PerformLayout()
                        {
!                               // TODO
                        }
-       [TODO]
        public void PerformLayout
                                (Control affectedControl, String 
affectedProperty)
                        {
!                               // TODO
                        }
  
--- 1659,1855 ----
  
        // Force the child to perform layout.
        public void PerformLayout()
                        {
!                               PerformLayout(null, null);
                        }
        public void PerformLayout
                                (Control affectedControl, String 
affectedProperty)
                        {
!                               // Bail out if layout was suspended.
!                               if(layoutSuspended > 0)
!                               {
!                                       return;
!                               }
! 
!                               // Mark this control as currently being laid 
out.
!                               performingLayout = true;
!                               ++layoutSuspended;
! 
!                               // Lay out this control.  We use a try block to 
make
!                               // sure that the layout control variables are 
reset
!                               // if "OnLayout" throws an exception for some 
reason.
!                               try
!                               {
!                                       OnLayout(new 
LayoutEventArgs(affectedControl,
!                                                                               
                 affectedProperty));
!                               }
!                               finally
!                               {
!                                       // We are finished laying out this 
control.
!                                       --layoutSuspended;
!                                       performingLayout = false;
!                               }
!                       }
! 
!       // Perform actual layout on the control.  Called from "OnLayout".
!       private void PerformActualLayout()
!                       {
!                               Rectangle rect;
!                               int left, right, top, bottom;
!                               int posn, temp;
!                               Control child;
!                               AnchorStyles anchor;
! 
!                               // Start with the display rectangle.
!                               rect = DisplayRectangle;
!                               left = rect.Left;
!                               right = rect.Right;
!                               top = rect.Top;
!                               bottom = rect.Bottom;
! 
!                               // Lay out the docked controls, from last to 
first.
!                               for(posn = numChildren - 1; posn >= 0; --posn)
!                               {
!                                       child = children[posn];
!                                       if(!(child.visible))
!                                       {
!                                               // This child is not visible, 
so skip it.
!                                               continue;
!                                       }
!                                       switch(child.Dock)
!                                       {
!                                               case DockStyle.None: break;
! 
!                                               case DockStyle.Top:
!                                               {
!                                                       child.SetBounds
!                                                               (left, top, 
right - left, child.Height);
!                                                       top += child.Height;
!                                               }
!                                               break;
! 
!                                               case DockStyle.Bottom:
!                                               {
!                                                       temp = child.Height;
!                                                       child.SetBounds
!                                                               (left, bottom - 
temp, right - left, temp);
!                                                       bottom -= child.Height;
!                                               }
!                                               break;
! 
!                                               case DockStyle.Left:
!                                               {
!                                                       child.SetBounds
!                                                               (left, top, 
child.Width, bottom - top);
!                                                       left += child.Width;
!                                               }
!                                               break;
! 
!                                               case DockStyle.Right:
!                                               {
!                                                       temp = child.Width;
!                                                       child.SetBounds
!                                                               (right - temp, 
top, temp, bottom - top);
!                                                       right -= child.Width;
!                                               }
!                                               break;
! 
!                                               case DockStyle.Fill:
!                                               {
!                                                       child.SetBounds
!                                                               (left, top, 
right - left, bottom - top);
!                                               }
!                                               break;
!                                       }
!                                       if(child.Dock != DockStyle.None)
!                                       {
!                                               // Just in case we are switched 
to anchoring later.
!                                               child.prevParentWidth = 
rect.Width;
!                                               child.prevParentHeight = 
rect.Height;
!                                       }
!                               }
! 
!                               // Lay out the anchored controls, from first to 
last.
!                               for(posn = 0; posn < numChildren; ++posn)
!                               {
!                                       child = children[posn];
!                                       if(child.Dock == DockStyle.None)
!                                       {
!                                               // If the anchor style is 
top-left, then bail out as
!                                               // there will be no change to 
the child's position.
!                                               anchor = child.Anchor;
!                                               if(anchor == (AnchorStyles.Top 
| AnchorStyles.Left))
!                                               {
!                                                       child.prevParentWidth = 
rect.Width;
!                                                       child.prevParentHeight 
= rect.Height;
!                                                       continue;
!                                               }
! 
!                                               // Get the previous distance 
from all edges.
!                                               left = child.left - rect.X;
!                                               top = child.top - rect.Y;
!                                               right = child.prevParentWidth - 
(left + child.width);
!                                               bottom = child.prevParentHeight 
- (top + child.height);
! 
!                                               // Anchor the child to each 
specified side.
!                                               if((anchor & AnchorStyles.Top) 
!= 0)
!                                               {
!                                                       if((anchor & 
AnchorStyles.Bottom) == 0)
!                                                       {
!                                                               // Anchor to 
the top, but not the bottom.
!                                                               bottom = 
rect.Height - (top + child.height);
!                                                       }
!                                               }
!                                               else if((anchor & 
AnchorStyles.Bottom) != 0)
!                                               {
!                                                       // Anchor to the 
bottom, but not the top.
!                                                       top = rect.Height - 
(bottom + child.height);
!                                               }
!                                               else
!                                               {
!                                                       // Don't anchor to 
either - default to top.
!                                                       bottom = rect.Height - 
(top + child.height);
!                                               }
!                                               if((anchor & AnchorStyles.Left) 
!= 0)
!                                               {
!                                                       if((anchor & 
AnchorStyles.Right) == 0)
!                                                       {
!                                                               // Anchor to 
the left, but not the right.
!                                                               right = 
rect.Width - (left + child.width);
!                                                       }
!                                               }
!                                               else if((anchor & 
AnchorStyles.Right) != 0)
!                                               {
!                                                       // Anchor to the right, 
but not the left.
!                                                       left = rect.Width - 
(right + child.width);
!                                               }
!                                               else
!                                               {
!                                                       // Don't anchor to 
either - default to left.
!                                                       right = rect.Width - 
(left + child.width);
!                                               }
! 
!                                               // Compute the final client 
rectangle and check it.
!                                               right = rect.Width - right;
!                                               bottom = rect.Height - bottom;
!                                               if(left > right)
!                                               {
!                                                       right = left;
!                                               }
!                                               if(top > bottom)
!                                               {
!                                                       bottom = top;
!                                               }
! 
!                                               // Set the new bounds for the 
child.
!                                               child.SetBounds
!                                                       (rect.X + left, rect.Y 
+ top,
!                                                        right - left, bottom - 
top);
! 
!                                               // Update the parent 
information for the next layout.
!                                               child.prevParentWidth = 
rect.Width;
!                                               child.prevParentHeight = 
rect.Height;
!                                       }
!                               }
                        }
  
***************
*** 1814,1821 ****
                                ResumeLayout(true);
                        }
-       [TODO]
        public void ResumeLayout(bool performLayout)
                        {
!                               // TODO
                        }
  
--- 2012,2024 ----
                                ResumeLayout(true);
                        }
        public void ResumeLayout(bool performLayout)
                        {
!                               if(layoutSuspended <= 0 || (--layoutSuspended) 
== 0)
!                               {
!                                       if(performLayout && !performingLayout)
!                                       {
!                                               PerformLayout();
!                                       }
!                               }
                        }
  
***************
*** 2064,2069 ****
--- 2267,2279 ----
                                if(visible != value)
                                {
+                                       // Update the visible state.
                                        visible = value;
                                        OnVisibleChanged(EventArgs.Empty);
+ 
+                                       // Perform layout on the parent.
+                                       if(parent != null)
+                                       {
+                                               parent.PerformLayout(this, 
"Visible");
+                                       }
                                }
                        }
***************
*** 2076,2083 ****
  
        // Suspend layout for this control.
-       [TODO]
        public void SuspendLayout()
                        {
!                               // TODO
                        }
  
--- 2286,2292 ----
  
        // Suspend layout for this control.
        public void SuspendLayout()
                        {
!                               ++layoutSuspended;
                        }
  
***************
*** 2106,2114 ****
                                if(moved)
                                {
!                                       OnMove(EventArgs.Empty);
                                }
                                if(resized)
                                {
!                                       OnResize(EventArgs.Empty);
                                }
                        }
--- 2315,2323 ----
                                if(moved)
                                {
!                                       OnLocationChanged(EventArgs.Empty);
                                }
                                if(resized)
                                {
!                                       OnSizeChanged(EventArgs.Empty);
                                }
                        }
***************
*** 3242,3245 ****
--- 3451,3455 ----
        protected virtual void OnLayout(LayoutEventArgs e)
                        {
+                               // Invoke the event handler.
                                LayoutEventHandler handler;
                                handler = 
(LayoutEventHandler)(GetHandler(EventId.Layout));
***************
*** 3248,3251 ****
--- 3458,3464 ----
                                        handler(this, e);
                                }
+ 
+                               // Perform layout on this control's contents.
+                               PerformActualLayout();
                        }
        protected virtual void OnLeave(EventArgs e)
***************
*** 3260,3263 ****
--- 3473,3480 ----
        protected virtual void OnLocationChanged(EventArgs e)
                        {
+                               // Raise the "Move" event first.
+                               OnMove(e);
+ 
+                               // Invoke the event handler.
                                EventHandler handler;
                                handler = 
(EventHandler)(GetHandler(EventId.LocationChanged));
***************
*** 3341,3344 ****
--- 3558,3562 ----
        protected virtual void OnMove(EventArgs e)
                        {
+                               // Raise the "Move" event.
                                EventHandler handler;
                                handler = 
(EventHandler)(GetHandler(EventId.Move));
***************
*** 3347,3350 ****
--- 3565,3574 ----
                                        handler(this, e);
                                }
+ 
+                               // If the window is transparent, then 
invalidate.
+                               if((styles & 
ControlStyles.SupportsTransparentBackColor) != 0)
+                               {
+                                       Invalidate();
+                               }
                        }
        protected virtual void OnPaint(PaintEventArgs e)
***************
*** 3460,3463 ****
--- 3684,3690 ----
                                }
  
+                               // Perform layout on this control.
+                               PerformLayout(this, "Bounds");
+ 
                                // Invoke the event handler.
                                EventHandler handler;
***************
*** 3488,3491 ****
--- 3715,3722 ----
        protected virtual void OnSizeChanged(EventArgs e)
                        {
+                               // Raise the "Resize" event first.
+                               OnResize(e);
+ 
+                               // Invoke the event handler.
                                EventHandler handler;
                                handler = 
(EventHandler)(GetHandler(EventId.SizeChanged));
***************
*** 3593,3603 ****
                        }
  
-       // Begin a batch change operation, which suppresses updates until
-       // all controls in the batch have been changed.
-       internal virtual void BeginBatchChange() {}
- 
-       // End a batch change operation.
-       internal virtual void EndBatchChange() {}
- 
        // Move a child to below another.  Does not update "children".
        private static void MoveToBelow(Control after, Control child)
--- 3824,3827 ----
***************
*** 3717,3721 ****
                public virtual void Clear()
                                {
!                                       // TODO
                                }
                bool IList.Contains(Object value)
--- 3941,3958 ----
                public virtual void Clear()
                                {
!                                       owner.SuspendLayout();
!                                       try
!                                       {
!                                               int count = Count;
!                                               while(count > 0)
!                                               {
!                                                       --count;
!                                                       Remove(this[count]);
!                                               }
!                                       }
!                                       finally
!                                       {
!                                               owner.ResumeLayout();
!                                       }
                                }
                bool IList.Contains(Object value)
***************
*** 3795,3803 ****
                                                if(value.Parent == owner)
                                                {
                                                        value.SendToBack();
                                                }
                                                else
                                                {
!                                                       value.Parent = owner;
                                                }
                                        }
--- 4032,4063 ----
                                                if(value.Parent == owner)
                                                {
+                                                       // We are already under 
this owner, so merely
+                                                       // send it to the back 
of its sibling stack.
                                                        value.SendToBack();
                                                }
                                                else
                                                {
!                                                       // Suspend layout on 
the parent while we do this.
!                                                       owner.SuspendLayout();
!                                                       try
!                                                       {
!                                                               // Change the 
parent to the new owner.
!                                                               value.Parent = 
owner;
! 
!                                                               // Initialize 
layout within the new context.
!                                                               
value.InitLayout();
!                                                       }
!                                                       finally
!                                                       {
!                                                               // Resume 
layout, but don't perform it yet.
!                                                               
owner.ResumeLayout(false);
!                                                       }
! 
!                                                       // Now perform layout 
on the control.
!                                                       
owner.PerformLayout(value, "Parent");
! 
!                                                       // Notify the owner 
that the control was added.
!                                                       owner.OnControlAdded
!                                                               (new 
ControlEventArgs(value));
                                                }
                                        }
***************
*** 3841,3845 ****
--- 4101,4112 ----
                                        if(value != null && value.Parent == 
owner)
                                        {
+                                               // Update the parent.
                                                value.Parent = null;
+ 
+                                               // Perform layout on the owner.
+                                               owner.PerformLayout(value, 
"Parent");
+ 
+                                               // Notify the owner that the 
control has been removed.
+                                               owner.OnControlRemoved(new 
ControlEventArgs(value));
                                        }
                                }
***************
*** 3907,3916 ****
                                                throw new 
ArgumentNullException("controls");
                                        }
!                                       owner.BeginBatchChange();
!                                       foreach(Control control in controls)
                                        {
!                                               Add(control);
                                        }
-                                       owner.EndBatchChange();
                                }
  
--- 4174,4189 ----
                                                throw new 
ArgumentNullException("controls");
                                        }
!                                       owner.SuspendLayout();
!                                       try
!                                       {
!                                               foreach(Control control in 
controls)
!                                               {
!                                                       Add(control);
!                                               }
!                                       }
!                                       finally
                                        {
!                                               owner.ResumeLayout();
                                        }
                                }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]