Example #1
0
 internal static void FormatChildSize(ILayoutSize child, Size size)
 {
     if (child == null)
     {
         return;
     }
     child.DesiredWidth  = Math.Min(child.DesiredWidth, size.Width / 2);
     child.DesiredHeight = Math.Min(child.DesiredHeight, size.Height / 2);
 }
        public override void AttachChild(IDockView child, AttachMode mode, int index)
        {
            if (index < 0 || index > Count)
            {
                throw new ArgumentOutOfRangeException("index out of range!");
            }
            if (!_AssertMode(mode))
            {
                throw new ArgumentException("mode is illegal!");
            }

            if (Count == 1 && ActualWidth > 0 && ActualHeight > 0)
            {
                ILayoutSize size = Children[0] as ILayoutSize;
                size.DesiredWidth  = ActualWidth;
                size.DesiredHeight = ActualHeight;
            }

            if (child is LayoutDocumentGroupControl ||
                child is LayoutGroupDocumentPanel ||
                mode == AttachMode.Left_WithSplit ||
                mode == AttachMode.Top_WithSplit ||
                mode == AttachMode.Right_WithSplit ||
                mode == AttachMode.Bottom_WithSplit)
            {
                _AttachWithSplit(child, mode, index);
            }
            else
            {
                if (IsRootPanel)
                {
                    AttachToRootPanel(child, mode);
                }
                else
                {
                    var parent = Parent as LayoutGroupPanel;
                    switch (parent.Direction)
                    {
                    case Direction.LeftToRight:
                        if (mode == AttachMode.Left || mode == AttachMode.Right)
                        {
                            if (child is LayoutGroupPanel)
                            {
                                _AttachSubPanel((child as LayoutGroupPanel), index);
                            }
                            else
                            {
                                _AttachChild(child, index);
                            }
                        }
                        else
                        {
                            int _index = parent.IndexOf(this);
                            parent._DetachChild(this);
                            var pparent = new LayoutGroupPanel()
                            {
                                Direction = Direction.UpToDown
                            };
                            parent._AttachChild(pparent, _index);
                            pparent._AttachChild(this, 0);
                            pparent._AttachChild(child, mode == AttachMode.Top ? 0 : 1);
                        }
                        break;

                    case Direction.UpToDown:
                        if (mode == AttachMode.Top || mode == AttachMode.Bottom)
                        {
                            if (child is LayoutGroupPanel)
                            {
                                _AttachSubPanel((child as LayoutGroupPanel), index);
                            }
                            else
                            {
                                _AttachChild(child, index);
                            }
                        }
                        else
                        {
                            int _index = parent.IndexOf(this);
                            parent._DetachChild(this);
                            var pparent = new LayoutGroupPanel()
                            {
                                Direction = Direction.LeftToRight
                            };
                            parent._AttachChild(pparent, _index);
                            pparent._AttachChild(this, 0);
                            pparent._AttachChild(child, mode == AttachMode.Left ? 0 : 1);
                        }
                        break;
                    }
                }
            }
        }