/// <summary>
 /// Creates a new DockEventArgs object.
 /// </summary>
 /// <param name="point">The point where to dock the window.</param>
 /// <param name="dockType">The needed target container type.</param>
 /// <param name="release">The state of the dock process. True, if dock is finally performed.</param>
 public DockEventArgs(Point point, DockContainerType dockType, bool release)
 {
     this.point = point;
     this.dockType = dockType;
     this.release = release;
     this.target = null;
     this.handled = false;
     this.showDockGuide = false;
 }
        public DockForm()
        {
            InitializeComponent();

            // Create and initialize the root container.
            rootContainer = new DockContainer();
            rootContainer.Dock = DockStyle.Fill;
            this.Controls.Add(rootContainer);

            RegisterToMdiContainer();
        }
        public DockForm(Panel dragObject)
        {
            InitializeComponent();

            this.Opacity = 0;

            if (dragObject is DockContainer)
            {
                DockContainer c = dragObject as DockContainer;

                if (c.panList.Count == 1)
                    this.ClientSize = (c.panList[0] as DockPanel).Form.ClientSize;
                else
                    this.ClientSize = dragObject.Size;

                if (c.removeable)
                    rootContainer = c;
                else
                {
                    rootContainer = new DockContainer();
                    rootContainer.Controls.AddRange((DockPanel[])c.panList.ToArray(typeof(DockPanel)));
                    rootContainer.Controls.AddRange((DockContainer[])c.conList.ToArray(typeof(DockContainer)));

                    ArrayList list = new ArrayList();
                    rootContainer.GetPanels(list);
                    if (list.Count > 0)
                        rootContainer.DockType = (list[0] as DockPanel).Form.DockType;
                }
            }
            else if (dragObject is DockPanel)
            {
                DockPanel p = dragObject as DockPanel;

                this.ClientSize = p.Form.ClientSize;

                rootContainer = new DockContainer();
                p.Form.CopyToDockForm(this);
            }

            if (rootContainer.panList.Count > 0)
            {
                (rootContainer.panList[0] as DockPanel).Form.CopyPropToDockForm(this);
                rootContainer.SetFormSizeBounds(this);
                rootContainer.SelectTab(0);
            }

            rootContainer.Dock = DockStyle.Fill;
            this.Controls.Add(rootContainer);

            RegisterToMdiContainer();
        }
        /// <summary>
        /// The <see cref="DragWindow"/> event handler for dockable windows.
        /// Used to enable a <see cref="DockWindow"/> to send its position changes to this container.
        /// Calls recursively all <see cref="DragWindow"/> event handlers of the child containers.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An <see cref="DockEventArgs"/> that contains the docking data.</param>
        /// <returns>The success of the operation.</returns>
        public bool DragWindow(object sender, DockEventArgs e)
        {
            if (e.Handled)
                return true;

            try
            {
                // First, check if the given point is in the current tree and lots of more cool features.
                if ((e.DockType == DockContainerType.None) |
                    ((e.DockType == DockContainerType.Document) & (dockType == DockContainerType.ToolWindow)) |
                    ((conList.Count > 0) & !e.IgnoreHierarchy) |
                    (sender == this.TopLevelControl) |
                    (autoHide == true) |
                    ((!this.TopLevelControl.Visible) & (sender is DockForm)))
                {
                    //Console.WriteLine(e.invokeCounter + "\t" + HitTest(e.Point).ToString() + "\t" + dockType.ToString() + "\t" + e.DockType.ToString() + "\t" + conList.Count + "\t" + (sender == this.TopLevelControl));
                    return false;
                }

                // Last important question: am I'm moving myself or do I like getting more containers?
                if (this.TopLevelControl is DockForm)
                    if ((this.TopLevelControl as DockForm).Moving | !(this.TopLevelControl as DockForm).AllowDock | !(this.TopLevelControl as DockForm).Visible)
                        return false;

                // Hit test.
                if (!HitTest(e.Point))
                    return false;

                DockForm f = DockManager.GetFormAtPoint(e.Point, 1);
                if ((f != this.TopLevelControl) & (f != null))
                    return false;

                // Update DockGuide.
                DockManager.UpdateDockGuide(this, e);

                if (e.Handled)
                    return false;

                // Get the source object size.
                Size size = Size.Empty;

                if (sender is DockForm)
                    size = (sender as DockForm).Size;
                else if (sender is DockContainer)
                    size = (sender as DockContainer).Size;
                else if (sender is DockWindow)
                    size = (sender as DockWindow).Size;

                // Then check for valid destinations.
                e.Target = GetTarget(size, e.DockType, e.Point);

                if (e.Target == null)
                    return false;

                // The event has finished.
                e.Handled = true;

                // Take the results and add the whole stuff to the own collection.
                if (e.Release)
                {
                    // Transfer all own panels to a higher hierarchy level.
                    if (!conList.Contains(e.Target) & (e.Target != this))
                    {
                        // Create new container and fill it with own panels.
                        DockContainer cont = new DockContainer();
                        cont.removeable = removeable;
                        cont.DockBorder = dockBorder;

                        removeable = true;

                        DockPanel temp = ActivePanel;
                        cont.Controls.AddRange((DockPanel[])panList.ToArray(typeof(DockPanel)));
                        cont.ActivePanel = temp;
                        cont.DockType = dockType;

                        if (conList.Count > 1)
                        {
                            disableOnControlRemove = true;
                            cont.Controls.AddRange((DockContainer[])conList.ToArray(typeof(DockContainer)));
                            disableOnControlRemove = false;
                        }

                        this.Controls.Add(cont);
                        cont.Dock = DockStyle.Fill;
                    }

                    // Add the container to the list object.
                    if (sender is DockWindow)
                    {
                        AddPanel((sender as DockWindow).ControlContainer, e.Target);
                    }
                    else
                    {
                        DockContainer src = null;

                        if (sender is DockForm)
                            src = (sender as DockForm).RootContainer;
                        else if (sender is DockContainer)
                            src = (sender as DockContainer);

                        AddWindowContent(src, e.Target);
                    }

                    // Set focus.
                    this.TopLevelControl.BringToFront();
                    this.TopLevelControl.Invalidate(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("DockContainer.DragWindow: " + ex.Message);
            }

            return true;
        }
        /// <summary>
        /// Recursively resolves the <see cref="DockContainer"/> hierarchy.
        /// </summary>
        /// <param name="type">The <see cref="DockContainerType"/> of the child that is to be retrieved.</param>
        /// <param name="last">The last hit on a suitable <see cref="DockContainer"/>.</param>
        /// <returns>The child <see cref="DockContainer"/> object.</returns>
        public DockContainer GetNextChild(DockContainerType type, DockContainer last)
        {
            DockContainer ret = null;

            foreach (DockContainer cont in conList)
            {
                ret = cont.GetNextChild(type, last);
                if (ret != null)
                    return ret;
            }

            if ((conList.Count == 0) && (dockType == type) && (this != last))
                ret = this;

            return ret;
        }
        /// <summary>
        /// The MouseUp event handler of the drag panel.
        /// Used to handle resizing of the container.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="MouseEventArgs"/> that contains the mouse data.</param>
        private void dragPanel_MouseUp(object sender, MouseEventArgs e)
        {
            // If resizing, release dummy and set new size.
            if (resizing)
            {
                resizing = false;

                // Release dummy.
                Parent.Controls.Remove(dragDummy);
                Parent.Invalidate();
                dragDummy.Dispose();
                dragDummy = null;

                // Set new size according to the actual state.
                ptStart = new Point(e.X + dragPanel.Left, e.Y + dragPanel.Top);

                if (this.Dock == DockStyle.Left)
                {
                    if (ptStart.X < dockBorder * 3)
                        ptStart.X = dockBorder * 3;
                    else if (ptStart.X > this.Parent.Width - dockBorder * 3)
                        ptStart.X = this.Parent.Width - dockBorder * 3;
                }
                else if (this.Dock == DockStyle.Right)
                {
                    if (ptStart.X > this.Width - dockBorder * 3)
                        ptStart.X = this.Width - dockBorder * 3;
                    else if (ptStart.X < this.Width - this.Parent.Width + dockBorder * 3)
                        ptStart.X = this.Width - this.Parent.Width + dockBorder * 3;
                }
                else if (this.Dock == DockStyle.Top)
                {
                    if (ptStart.Y < dockBorder * 3)
                        ptStart.Y = dockBorder * 3;
                    else if (ptStart.Y > this.Parent.Height - dockBorder * 3)
                        ptStart.Y = this.Parent.Height - dockBorder * 3;
                }
                else if (this.Dock == DockStyle.Bottom)
                {
                    if (ptStart.Y > this.Height - dockBorder * 3)
                        ptStart.Y = this.Height - dockBorder * 3;
                    else if (ptStart.Y < this.Height - this.Parent.Height + dockBorder * 3)
                        ptStart.Y = this.Height - this.Parent.Height + dockBorder * 3;
                }

                switch (this.Dock)
                {
                    case DockStyle.Left:
                        if (ptStart.X < 40)
                            this.Width = 40;
                        else
                            this.Width = ptStart.X;
                        break;
                    case DockStyle.Right:
                        int x = 0;

                        if (this.Width - ptStart.X < 40)
                            x = this.Width - 40;
                        else
                            x = ptStart.X;

                        this.Location = new Point(this.Location.X + x, this.Location.Y);
                        this.Width -= x;
                        break;
                    case DockStyle.Top:
                        if (ptStart.Y < 60)
                            this.Height = 60;
                        else
                            this.Height = ptStart.Y;
                        break;
                    case DockStyle.Bottom:
                        int y = 0;

                        if (this.Height - ptStart.Y < 60)
                            y = this.Height - 60;
                        else
                            y = ptStart.Y;

                        this.Location = new Point(this.Location.X, this.Location.Y + y);
                        this.Height -= y;
                        break;
                }
            }
        }
 public AutoHideStorage(DockManager manager, DockContainer parent, DockStyle parentDock, DockStyle toplevelDock)
 {
     this.manager = manager;
     this.parent = parent;
     this.parentDock = parentDock;
     this.toplevelDock = toplevelDock;
 }
        internal static void UnRegisterContainer(DockContainer cont)
        {
            if (!contList.Contains(cont))
                return;

            dragEvent -= cont.dragWindowHandler;
            contList.Remove(cont);
        }
        /// <summary>
        /// The MouseDown event handler of the drag panel.
        /// Used to handle resizing of the container.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="MouseEventArgs"/> that contains the mouse data.</param>
        private void dragPanel_MouseDown(object sender, MouseEventArgs e)
        {
            // Copy last point.
            ptStart = new Point(e.X + dragPanel.Left, e.Y + dragPanel.Top);

            // Create dummy container.
            dragDummy = new DockContainer();
            dragDummy.isDragContainer = true;

            // Set size and location.
            if (this.Dock == DockStyle.Left)
            {
                dragDummy.Location = new Point(this.Location.X + ptStart.X - 2 + this.TopLevelContainer.dockOffsetL, this.Location.Y);
                dragDummy.Size = new Size(4, this.Height);
            }
            else if (this.Dock == DockStyle.Right)
            {
                dragDummy.Location = new Point(this.Location.X + ptStart.X - 2 - this.TopLevelContainer.dockOffsetR, this.Location.Y);
                dragDummy.Size = new Size(4, this.Height);
            }
            else if (this.Dock == DockStyle.Bottom)
            {
                dragDummy.Location = new Point(this.Location.X, this.Location.Y + ptStart.Y - 2 - this.TopLevelContainer.dockOffsetB);
                dragDummy.Size = new Size(this.Width, 4);
            }
            else
            {
                dragDummy.Location = new Point(this.Location.X, this.Location.Y + ptStart.Y - 2 + this.TopLevelContainer.dockOffsetT);
                dragDummy.Size = new Size(this.Width, 4);
            }

            // Add container to parent and resizing flag.
            Parent.Controls.Add(dragDummy);
            dragDummy.BringToFront();
            resizing = true;
        }
        /// <summary>
        /// Retrieves a container that matches a specific mouse location, when a window is dragged.
        /// </summary>
        /// <param name="srcSize">The size of the source object.</param>
        /// <param name="type">The target container type.</param>
        /// <param name="pt">The target position.</param>
        /// <returns>A valid container or null, if no suitable container was found.</returns>*/
        internal DockContainer GetTarget(Size srcSize, DockContainerType type, Point pt)
        {
            // Prepare rectangles.
            Rectangle rcClient = RectangleToScreen(this.ClientRectangle);
            Rectangle rcDock = new Rectangle(rcClient.Left + this.DockPadding.Left,
                rcClient.Top + this.DockPadding.Top,
                rcClient.Width - this.DockPadding.Left - this.DockPadding.Right,
                rcClient.Height - this.DockPadding.Top - this.DockPadding.Bottom);

            // Test on split.
            if (rcDock.Contains(pt))
            {
                DockContainer cont = null;

                if (pt.X - rcDock.Left <= dockBorder)
                {
                    // Split left.
                    cont = new DockContainer();
                    cont.DockType = type;
                    cont.Dock = DockStyle.Left;
                    if (srcSize.Width > this.Width / 2)
                        cont.Width = this.Width / 2;
                    else
                        cont.Width = srcSize.Width;
                    cont.Height = this.Height;
                    cont.Location = new Point(rcClient.X, rcClient.Y);
                }
                else if (rcDock.Right - pt.X <= dockBorder)
                {
                    // Split right.
                    cont = new DockContainer();
                    cont.DockType = type;
                    cont.Dock = DockStyle.Right;
                    if (srcSize.Width > this.Width / 2)
                        cont.Width = this.Width / 2;
                    else
                        cont.Width = srcSize.Width;
                    cont.Height = this.Height;
                    cont.Location = new Point(rcClient.X + this.Width - cont.Width, rcClient.Y);
                }
                else if (pt.Y - rcDock.Top <= dockBorder)
                {
                    // Split top.
                    cont = new DockContainer();
                    cont.DockType = type;
                    cont.Dock = DockStyle.Top;
                    if (srcSize.Height > this.Height / 2)
                        cont.Height = this.Height / 2;
                    else
                        cont.Height = srcSize.Height;
                    cont.Width = this.Width;
                    cont.Location = new Point(rcClient.X, rcClient.Y);
                }
                else if (rcDock.Bottom - pt.Y <= dockBorder)
                {
                    // Split bottom.
                    cont = new DockContainer();
                    cont.DockType = type;
                    cont.Dock = DockStyle.Bottom;
                    if (srcSize.Height > this.Height / 2)
                        cont.Height = this.Height / 2;
                    else
                        cont.Height = srcSize.Height;
                    cont.Width = this.Width;
                    cont.Location = new Point(rcClient.X, rcClient.Y + this.Height - cont.Height);
                }

                return cont;
            }

            // For direct children of DockWindows only:
            if (this.IsRootContainer)
            {
                DockForm wnd = this.Parent as DockForm;
                if (wnd.Bounds.Contains(pt) & (dockType == type))
                    return this;
            }

            // Test on add to own panel list.
            if (rcClient.Contains(pt))
            {
                if ((pt.Y <= rcClient.Top + this.DockPadding.Top) && (dockType == type))
                    return this;
                else if ((dockType == type) && (dockType == DockContainerType.ToolWindow) && (panList.Count > 1) && (pt.Y > rcClient.Top + this.Height - this.DockPadding.Bottom))
                    return this;
            }

            return null;
        }
 internal void ReleaseAutoHideContainer()
 {
     this.Controls.Remove(autoHideContainer);
     autoHideContainer = null;
 }
        internal static void UpdateDockGuide(DockContainer target, DockEventArgs e)
        {
            if ((target == null) | noGuidePlease | (style != DockVisualStyle.VS2005) | fastMoveDraw)
            {
                HideDockGuide();
                return;
            }

            if (dockGuide == null)
                dockGuide = new OverlayForm();

            dockGuide.TargetHost = target;
            dockGuide.Size = target.Size;

            if (!dockGuide.Visible)
                dockGuide.Show();

            if (target.Parent != null)
                dockGuide.Location = target.RectangleToScreen(target.ClientRectangle).Location;
            else
                dockGuide.Location = target.Location;

            dockGuide.BringToFront();

            // Make tests.
            DockStyle dstStyle = dockGuide.HitTest(e.Point);

            if (dstStyle != DockStyle.None)
                e.Point = target.GetVirtualDragDest(dstStyle);
            else
                e.Handled = true;

            e.ShowDockGuide = true;
        }
        /// <summary>
        /// Since there are no non-client area notifications in .NET, this message loop hook is needed.
        /// Captures a window move event and starts own movement procedure with an attached drag window.
        /// </summary>
        /// <param name="m">The Windows Message to process.</param>
        protected override void WndProc(ref Message m)
        {
            if ((m.Msg == (int)Win32.Msgs.WM_NCLBUTTONDOWN) & (m.WParam == (IntPtr)Win32.HitTest.HTCAPTION))
            {
                StartMoving(new Point(MousePosition.X, MousePosition.Y));
                return;
            }
            else if (moving)
            {
                if (m.Msg == (int)Win32.Msgs.WM_MOUSEMOVE)
                {
                    Application.DoEvents();

                    if (this.IsDisposed)
                        return;

                    if (MouseButtons == MouseButtons.None)
                    {
                        EndMoving();
                        Show();
                    }
                    else
                    {
                        if (DockManager.FastMoveDraw & this.Visible)
                            Hide();

                        this.Location = new Point(ptRef.X + MousePosition.X - ptStart.X, ptRef.Y + MousePosition.Y - ptStart.Y);
                        MoveWindow();
                        this.Capture = true;
                    }
                    return;
                }
                else if ((m.Msg == (int)Win32.Msgs.WM_LBUTTONUP) | ((m.Msg == (int)Win32.Msgs.WM_NCMOUSEMOVE) & (MouseButtons == MouseButtons.None)))
                {
                    EndMoving();

                    if (SendDockEvent(true) != null)
                    {
                        rootContainer = null;
                        this.Close();
                        return;
                    }

                    Show();
                }
                else if (m.Msg == (int)Win32.Msgs.WM_MOUSELEAVE)
                {
                    EndMoving();
                    Show();
                }
            }

            base.WndProc(ref m);
        }
        /// <summary>
        /// Invokes the drag event and adjusts the size and location if a valid docking position was received.
        /// This method is only used by explicit drag windows (see flag).
        /// </summary>
        internal void MoveWindow()
        {
            dragTarget = SendDockEvent(false);

            if (dragTarget != null)
            {
                if (dragWindow == null)
                {
                    dragWindow = new OverlayForm();
                    dragWindow.Size = dragTarget.Size;
                    dragWindow.Show();
                    this.BringToFront();
                }
                else
                    dragWindow.Size = dragTarget.Size;

                if (dragTarget.Parent != null)
                    dragWindow.Location = dragTarget.RectangleToScreen(dragTarget.ClientRectangle).Location;
                else
                    dragWindow.Location = dragTarget.Location;
            }
            else if (DockManager.FastMoveDraw)
            {
                if (dragWindow == null)
                {
                    dragWindow = new OverlayForm();
                    dragWindow.Size = this.Size;
                    dragWindow.Show();
                }
                else
                    dragWindow.Size = this.Size;

                dragWindow.Location = this.Location;
            }
            else
                CloseDragWindow();
        }
        private int UpdateAutoHideList(DockContainer c, bool hide, Collection<DockContainer> list)
        {
            if (hide)
            {
                list.Add(c);
            }
            else if (list.Contains(c))
            {
                autoHideContainer = null;
                list.Remove(c);
                this.Controls.Remove(c);
            }

            if (list.Count > 0)
                return 22;
            else
                return 0;
        }
        /// <summary>
        /// Expands the base class function with auto-hide checks.
        /// </summary>
        /// <param name="e">A <see cref="MouseEventArgs"/> that contains the mouse data.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            Rectangle rc;
            Size size;

            if (autoHideContainer != null)
                if (autoHideContainer.fading)
                    return;

            #region AutoHide Left
            foreach (DockContainer c in autoHideL)
            {
                foreach (DockPanel p in c.panList)
                {
                    rc = new Rectangle((int)p.TabRect.Left, (int)p.TabRect.Top, (int)p.TabRect.Width, (int)p.TabRect.Height);

                    if (RectangleToScreen(rc).Contains(MousePosition.X, MousePosition.Y))
                    {
                        c.ActivePanel = p;

                        if (c != autoHideContainer)
                        {
                            disableOnControlAdded = true;
                            disableOnControlRemove = true;

                            this.Controls.Remove(autoHideContainer);
                            autoHideContainer = c;
                            size = c.Size;
                            c.Dock = DockStyle.None;
                            c.Location = new Point(dockOffsetL, dockOffsetT);
                            c.Size = new Size(size.Width, this.Height - dockOffsetT - dockOffsetB);
                            c.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
                            this.Controls.Add(c);
                            c.FadeIn();

                            disableOnControlAdded = false;
                            disableOnControlRemove = false;
                        }

                        return;
                    }
                }
            }
            #endregion

            #region AutoHide Right
            foreach (DockContainer c in autoHideR)
            {
                foreach (DockPanel p in c.panList)
                {
                    rc = new Rectangle((int)p.TabRect.Left, (int)p.TabRect.Top, (int)p.TabRect.Width, (int)p.TabRect.Height);

                    if (RectangleToScreen(rc).Contains(MousePosition.X, MousePosition.Y))
                    {
                        c.ActivePanel = p;

                        if (c != autoHideContainer)
                        {
                            this.Controls.Remove(autoHideContainer);
                            autoHideContainer = c;
                            size = c.Size;
                            c.Dock = DockStyle.None;
                            c.Location = new Point(this.Width - size.Width - dockOffsetR, dockOffsetT);
                            c.Size = new Size(size.Width, this.Height - dockOffsetT - dockOffsetB);
                            c.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                            this.Controls.Add(c);
                            c.FadeIn();
                        }

                        return;
                    }
                }
            }
            #endregion

            #region AutoHide Top
            foreach (DockContainer c in autoHideT)
            {
                foreach (DockPanel p in c.panList)
                {
                    rc = new Rectangle((int)p.TabRect.Left, (int)p.TabRect.Top, (int)p.TabRect.Width, (int)p.TabRect.Height);

                    if (RectangleToScreen(rc).Contains(MousePosition.X, MousePosition.Y))
                    {
                        c.ActivePanel = p;

                        if (c != autoHideContainer)
                        {
                            this.Controls.Remove(autoHideContainer);
                            autoHideContainer = c;
                            size = c.Size;
                            c.Dock = DockStyle.None;
                            c.Location = new Point(dockOffsetL, dockOffsetT);
                            c.Size = new Size(this.Width - dockOffsetL - dockOffsetR, size.Height);
                            c.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left;
                            this.Controls.Add(c);
                            c.FadeIn();
                        }

                        return;
                    }
                }
            }
            #endregion

            #region AutoHide Bottom
            foreach (DockContainer c in autoHideB)
            {
                foreach (DockPanel p in c.panList)
                {
                    rc = new Rectangle((int)p.TabRect.Left, (int)p.TabRect.Top, (int)p.TabRect.Width, (int)p.TabRect.Height);

                    if (RectangleToScreen(rc).Contains(MousePosition.X, MousePosition.Y))
                    {
                        c.ActivePanel = p;

                        if (c != autoHideContainer)
                        {
                            this.Controls.Remove(autoHideContainer);
                            autoHideContainer = c;
                            size = c.Size;
                            c.Dock = DockStyle.None;
                            c.Location = new Point(dockOffsetL, this.Height - size.Height - dockOffsetB);
                            c.Size = new Size(this.Width - dockOffsetL - dockOffsetR, size.Height);
                            c.Anchor = AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
                            this.Controls.Add(c);
                            c.FadeIn();
                        }

                        return;
                    }
                }
            }
            #endregion

            if (autoHideContainer != null)
            {
                if (!autoHideContainer.RectangleToScreen(autoHideContainer.ClientRectangle).Contains(MousePosition.X, MousePosition.Y))
                    autoHideContainer.FadeOut();
            }
        }
        /// <summary>
        /// Adds a <see cref="DockPanel"/> to the container.
        /// </summary>
        /// <param name="src">The source panel.></param>
        /// <param name="dst">The destination container.</param>
        internal void AddPanel(DockPanel src, DockContainer dst)
        {
            if ((src == null) | (dst == null))
                return;

            try
            {
                blockFocusEvents = true;

                if (dst == this)
                {
                    this.Controls.Add(src);
                }
                else
                {
                    dst.Controls.Add(src);
                    this.Controls.Add(dst);
                }

                blockFocusEvents = false;
            }
            catch (Exception e)
            {
                Console.WriteLine("DockContainer.AddPanel: " + e.Message);
            }
        }
        public OverlayForm()
        {
            Init();

            targetHost = null;
        }
        /// <summary>
        /// Adds the content of a <see cref="DockContainer"/> to the container.
        /// </summary>
        /// <param name="src">The source container.></param>
        /// <param name="dst">The destination container.</param>
        internal void AddWindowContent(DockContainer src, DockContainer dst)
        {
            if ((src == null) | (dst == null))
                return;

            try
            {
                blockFocusEvents = true;

                if (dst == this)
                {
                    // Transfer flat hierarchy (all panels).
                    ArrayList list = new ArrayList();
                    src.GetPanels(list);

                    this.Controls.AddRange((DockPanel[])list.ToArray(typeof(DockPanel)));

                    AdjustBorders();
                }
                else
                {
                    // Transfer complete hierarchy.
                    src.Location = dst.Location;
                    src.Size = dst.Size;
                    src.Dock = dst.Dock;

                    this.Controls.Add(src);
                }

                blockFocusEvents = false;
            }
            catch (Exception e)
            {
                Console.WriteLine("DockContainer.AddWindowContent: " + e.Message);
            }
        }
        internal void AutoHideContainer(DockContainer c, DockStyle dst, bool hide)
        {
            if (c == null)
                return;

            switch (dst)
            {
                case DockStyle.Left:
                    dockOffsetL = UpdateAutoHideList(c, hide, autoHideL);
                    break;
                case DockStyle.Top:
                    dockOffsetT = UpdateAutoHideList(c, hide, autoHideT);
                    break;
                case DockStyle.Right:
                    dockOffsetR = UpdateAutoHideList(c, hide, autoHideR);
                    break;
                case DockStyle.Bottom:
                    dockOffsetB = UpdateAutoHideList(c, hide, autoHideB);
                    break;
                default:
                    dockOffsetL = UpdateAutoHideList(c, false, autoHideL);
                    dockOffsetT = UpdateAutoHideList(c, false, autoHideT);
                    dockOffsetR = UpdateAutoHideList(c, false, autoHideR);
                    dockOffsetB = UpdateAutoHideList(c, false, autoHideB);
                    break;
            }

            AdjustBorders();
        }
        /// <summary>
        /// Reads the container data from the window save list.
        /// </summary>
        /// <param name="reader">The <see cref="XmlReader"/> object that reads from the source stream.</param>
        internal virtual void ReadXml(XmlReader reader)
        {
            reader.Read();
            //disableOnControlAdded = true;

            if (!(this is DockManager))
            {
                string s;

                switch (reader.GetAttribute("dock"))
                {
                    case "Fill":
                        this.Dock = DockStyle.Fill;
                        break;
                    case "Top":
                        this.Dock = DockStyle.Top;
                        break;
                    case "Bottom":
                        this.Dock = DockStyle.Bottom;
                        break;
                    case "Left":
                        this.Dock = DockStyle.Left;
                        break;
                    case "Right":
                        this.Dock = DockStyle.Right;
                        break;
                    default:
                        disableOnControlAdded = false;
                        return;
                }

                s = reader.GetAttribute("width");
                if (s != null)
                    this.Width = int.Parse(s);

                s = reader.GetAttribute("height");
                if (s != null)
                    this.Height = int.Parse(s);

                switch (reader.GetAttribute("type"))
                {
                    case "Document":
                        this.DockType = DockContainerType.Document;
                        break;
                    case "ToolWindow":
                        this.DockType = DockContainerType.ToolWindow;
                        break;
                    default:
                        disableOnControlAdded = false;
                        return;
                }
            }

            while (reader.Read())
            {
                if (!reader.IsStartElement())
                    continue;

                if (reader.Name == "container")
                {
                    Console.WriteLine("container");

                    DockContainer c = new DockContainer();
                    c.ReadXml(reader.ReadSubtree());

                    if (!c.IsEmpty)
                    {
                        this.Controls.Add(c);
                        this.DockPadding.All = 0;
                    }
                }
                else if (reader.Name == "panel")
                {
                    Console.WriteLine("panel");

                    DockPanel p = new DockPanel();
                    p.ReadXml(reader);

                    this.Controls.Add(p);
                }
            }

            disableOnControlAdded = false;
        }
 /// <summary>
 /// Removes a child container from the internal list and disposes it.
 /// The other container will be transferred back to the host container at the call of the <see cref="OnControlRemoved"/> method.
 /// </summary>
 /// <param name="cont">The <see cref="DockContainer"/> that is to be removed.</param>
 protected void RemoveContainer(DockContainer cont)
 {
     if (this.Controls.Contains(cont))
     {
         this.Controls.Remove(cont);
         cont.Dispose();
         cont = null;
     }
 }
        public OverlayForm(DockContainer target)
        {
            Init();

            targetHost = target;
        }
        internal static void RegisterContainer(DockContainer cont)
        {
            if (contList.Contains(cont))
                return;

            if (cont == null)
                throw new ArgumentNullException("The container must not be null.");

            cont.Disposed += new EventHandler(ObjectDisposed);
            contList.Add(cont);

            dragEvent += cont.dragWindowHandler;
        }