Exemple #1
0
        /// <summary>Get bounding rectangle for docked view.</summary>
        /// <param name="viewHost">Tested <see cref="ViewHost"/>.</param>
        /// <param name="dockResult">Position for docking.</param>
        /// <returns>Bounding rectangle for docked view.</returns>
        public Rectangle GetDockBounds(ViewHost viewHost, DockResult dockResult)
        {
            Verify.Argument.IsNotNull(viewHost, nameof(viewHost));

            var       rootBounds = RootControl.Bounds;
            Rectangle bounds;

            switch (dockResult)
            {
            case DockResult.Left:
            {
                var w1 = viewHost.Width;
                var w2 = rootBounds.Width;
                ViewSplit.OptimalSizes(w2, ViewConstants.MinimumHostWidth, ref w1, ref w2);
                bounds = new Rectangle(0, 0, w1, rootBounds.Height);
            }
            break;

            case DockResult.Top:
            {
                var h1 = viewHost.Height;
                var h2 = rootBounds.Height;
                ViewSplit.OptimalSizes(h2, ViewConstants.MinimumHostHeight, ref h1, ref h2);
                bounds = new Rectangle(0, 0, rootBounds.Width, h1);
            }
            break;

            case DockResult.Right:
            {
                var w1 = rootBounds.Width;
                var w2 = viewHost.Width;
                ViewSplit.OptimalSizes(w1, ViewConstants.MinimumHostWidth, ref w1, ref w2);
                bounds = new Rectangle(rootBounds.Width - w2, 0, w2, rootBounds.Height);
            }
            break;

            case DockResult.Bottom:
            {
                var h1 = rootBounds.Height;
                var h2 = viewHost.Height;
                ViewSplit.OptimalSizes(h1, ViewConstants.MinimumHostHeight, ref h1, ref h2);
                bounds = new Rectangle(0, rootBounds.Height - h2, rootBounds.Width, h2);
            }
            break;

            default:
                throw new ArgumentException(
                          "Unsuported DockResult value: {0}".UseAsFormat(dockResult),
                          "dockResult");
            }
            bounds.Offset(rootBounds.X, rootBounds.Y);
            return(RectangleToScreen(bounds));
        }
Exemple #2
0
        /// <summary>Create <see cref="ViewSplitPositions"/>.</summary>
        /// <param name="viewSplit">Host <see cref="ViewSplit"/>.</param>
        /// <param name="size">Host size.</param>
        /// <param name="position">First splitter position.</param>
        public ViewSplitPositions(ViewSplit viewSplit, int size, double position)
        {
            Verify.Argument.IsNotNull(viewSplit, nameof(viewSplit));
            Verify.Argument.IsNotNegative(size, nameof(size));
            Verify.Argument.IsInRange(0.0, position, 1.0, nameof(position));

            _viewSplit          = viewSplit;
            _size               = size;
            MovingSplitterIndex = -1;
            _positions          = new List <double>()
            {
                position
            };
        }
Exemple #3
0
        /// <summary>Create <see cref="ViewSplitPositions"/>.</summary>
        /// <param name="viewSplit">Host <see cref="ViewSplit"/>.</param>
        /// <param name="size">Host size.</param>
        /// <param name="position">First splitter position.</param>
        public ViewSplitPositions(ViewSplit viewSplit, int size, double position)
        {
            Verify.Argument.IsNotNull(viewSplit, "viewSplit");
            Verify.Argument.IsNotNegative(size, "size");
            Verify.Argument.IsInRange(0.0, position, 1.0, "position");

            _viewSplit           = viewSplit;
            _size                = size;
            _movingSplitterIndex = -1;
            _positions           = new List <double>()
            {
                position
            };
        }
Exemple #4
0
            public SplitEntry(ViewSplit split)
                : this()
            {
                Verify.Argument.IsNotNull(split, nameof(split));

                _orientation = split.Orientation;
                foreach (var control in split)
                {
                    _cells.Add(ToLayout(control));
                }
                foreach (var splitter in split.Positions)
                {
                    _splitters.Add(splitter);
                }
            }
Exemple #5
0
        /// <summary>
        /// Replace <paramref name="origin"/> with a <see cref="ViewSplit"/>, containing
        /// <paramref name="origin"/> and <paramref name="sibling"/> controls.
        /// </summary>
        /// <param name="origin">Original control.</param>
        /// <param name="sibling">Inserted control.</param>
        /// <param name="side"><paramref name="sibling"/> position.</param>
        /// <returns>Created <see cref="ViewSplit"/>.</returns>
        public static ViewSplit Replace(Control origin, Control sibling, AnchorStyles side)
        {
            Control     item1;
            Control     item2;
            Orientation orientation;
            var         bounds = origin.Bounds;
            var         anchor = origin.Anchor;
            var         parent = origin.Parent;

            if (parent == null)
            {
                return(null);
            }
            switch (side)
            {
            case AnchorStyles.Left:
                item1       = sibling;
                item2       = origin;
                orientation = Orientation.Horizontal;
                break;

            case AnchorStyles.Top:
                item1       = sibling;
                item2       = origin;
                orientation = Orientation.Vertical;
                break;

            case AnchorStyles.Right:
                item1       = origin;
                item2       = sibling;
                orientation = Orientation.Horizontal;
                break;

            case AnchorStyles.Bottom:
                item1       = origin;
                item2       = sibling;
                orientation = Orientation.Vertical;
                break;

            default:
                throw new ArgumentException("side");
            }
            parent.DisableRedraw();
            parent.SuspendLayout();
            try
            {
                var split = new ViewSplit(orientation, bounds, item1, item2);
                split.SuspendLayout();
                split.Bounds = bounds;
                split.Parent = parent;

                switch (parent)
                {
                case ViewSplit psplit:
                    split.Anchor = anchor;
                    var index = psplit.IndexOf(origin);
                    psplit[index] = split;
                    break;

                case ViewDockGrid pgrid:
                    split.Anchor      = anchor;
                    pgrid.RootControl = split;
                    break;

                case FloatingViewForm pfloat:
                    pfloat.RootControl = split;
                    split.Dock         = DockStyle.Fill;
                    if (origin is ViewHost vh)
                    {
                        pfloat.EnterMulticontrolMode();
                        vh.Status = ViewHostStatus.DockedOnFloat;
                    }
                    break;

                default:
                    throw new ApplicationException("Unsupported parent control type.");
                }

                item1.Parent = split;
                item2.Parent = split;
                split.ResumeLayout(false);
                return(split);
            }
            finally
            {
                parent.ResumeLayout(false);
                parent.EnableRedraw();
                parent.RedrawWindow();
            }
        }