internal ResizeControlSplitter(DockCanvas canvas, SplitContainer resizeControl)
        {
            this.canvas   = canvas;
            ResizeControl = resizeControl;

            if (ResizeControl != null)
            {
                UpdateCursor();
            }
        }
        internal void UpdateCursor()
        {
            switch (DockCanvas.GetDock(ResizeControl))
            {
            case Dock.Left:
            case Dock.Right:
                Cursor = Cursors.SizeWE;
                break;

            default:
                Cursor = Cursors.SizeNS;
                break;
            }
        }
        private void OnDragStarted()
        {
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(ResizeControl);

            if (adornerLayer != null)
            {
                resizeData = new ResizeData
                {
                    SplitterDockSide = DockCanvas.GetDock(ResizeControl),
                    Parent           = ResizeControl
                };

                switch (resizeData.SplitterDockSide)
                {
                case Dock.Left:
                    resizeData.MinOffset = 15.0 - ResizeControl.ContentSize;
                    resizeData.MaxOffset = canvas.ClientBounds.Width - 32.0;
                    break;

                case Dock.Top:
                    resizeData.MinOffset = 15.0 - ResizeControl.ContentSize;
                    resizeData.MaxOffset = canvas.ClientBounds.Height - 32.0;
                    break;

                case Dock.Right:
                    resizeData.MaxOffset = ResizeControl.ContentSize - 15.0;
                    resizeData.MinOffset = 32.0 - canvas.ClientBounds.Width;
                    break;

                case Dock.Bottom:
                    resizeData.MaxOffset = ResizeControl.ContentSize - 15.0;
                    resizeData.MinOffset = 32.0 - canvas.ClientBounds.Height;
                    break;
                }

                resizeData.PreviewAdorner = new SplitPreviewAdorner(this);
                adornerLayer.Add(resizeData.PreviewAdorner);
            }
        }
示例#4
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            // Calculate the final rectangle
            Rect final = new Rect(
                0.0,
                0.0,
                finalSize.Width,
                finalSize.Height);

            int index = 0;

            // Iterate through the containers
            foreach (SplitContainer container in parent.SplitContainers)
            {
                // Determine the dock side of each split container
                Dock dockSide = DockCanvas.GetDock(container);

                // Depending on the dock side, we need to arrange the container differently
                switch (dockSide)
                {
                case Dock.Left:
                    container.Arrange(
                        new Rect(
                            final.X,
                            final.Y,
                            container.DesiredSize.Width,
                            final.Height));

                    splitters[index].Arrange(
                        new Rect(
                            final.X + container.DesiredSize.Width,
                            final.Y,
                            splitters[index].DesiredSize.Width,
                            final.Height));

                    final.X     += container.DesiredSize.Width + splitters[index].DesiredSize.Width;
                    final.Width -= container.DesiredSize.Width + splitters[index].DesiredSize.Width;
                    break;

                case Dock.Top:
                    container.Arrange(
                        new Rect(
                            final.X,
                            final.Y,
                            final.Width,
                            container.DesiredSize.Height));

                    splitters[index].Arrange(
                        new Rect(
                            final.X,
                            final.Y + container.DesiredSize.Height,
                            final.Width,
                            splitters[index].DesiredSize.Height));

                    final.Y      += container.DesiredSize.Height + splitters[index].DesiredSize.Height;
                    final.Height -= container.DesiredSize.Height + splitters[index].DesiredSize.Height;
                    break;

                case Dock.Right:
                    container.Arrange(
                        new Rect(
                            final.Right - container.DesiredSize.Width,
                            final.Y,
                            container.DesiredSize.Width,
                            final.Height));

                    splitters[index].Arrange(
                        new Rect(
                            final.Right - container.DesiredSize.Width - splitters[index].DesiredSize.Width,
                            final.Y,
                            splitters[index].DesiredSize.Width,
                            final.Height));

                    final.Width -= container.DesiredSize.Width + splitters[index].DesiredSize.Width;
                    break;

                case Dock.Bottom:
                    container.Arrange(
                        new Rect(
                            final.X,
                            final.Bottom - container.DesiredSize.Height,
                            final.Width,
                            container.DesiredSize.Height));

                    splitters[index].Arrange(
                        new Rect(
                            final.X,
                            final.Bottom - container.DesiredSize.Height - splitters[index].DesiredSize.Height,
                            final.Width,
                            splitters[index].DesiredSize.Height));

                    final.Height -= container.DesiredSize.Height + splitters[index].DesiredSize.Height;
                    break;
                }

                // Handle next splitter
                index++;
            }

            Child?.Arrange(final);

            // Update client bounds (needed for splitter preview)
            ClientBounds = final;

            // The size isn't changed
            return(finalSize);
        }
示例#5
0
 public DockHierarchyPresenter(DockCanvas parent)
 {
     splitters   = new List <ResizeControlSplitter>();
     this.parent = parent ?? throw new ArgumentNullException(nameof(parent));
 }
示例#6
0
        protected override Size MeasureOverride(Size availableSize)
        {
            // This is the size that is taken by the split containers
            Size size = new Size(0.0, 0.0);

            if (splittersInvalid)
            {
                RecreateSplitters();
            }

            int index = 0;

            // Iterate through all split containers
            foreach (SplitContainer container in parent.SplitContainers)
            {
                // Get the dock side
                Dock dockSide = DockCanvas.GetDock(container);

                // Calculate the available size first and measure the container
                Size available = new Size(
                    Math.Max(availableSize.Width - size.Width, 0.0),
                    Math.Max(availableSize.Height - size.Height, 0.0)
                    );
                container.Measure(available);

                double splitterSize = 0.0f;

                // Depending on the dock side, we change the size accordingly
                switch (dockSide)
                {
                case Dock.Top:
                case Dock.Bottom:
                    size.Height += splitterSize = container.DesiredSize.Height;
                    break;

                case Dock.Left:
                case Dock.Right:
                    size.Width += splitterSize = container.DesiredSize.Width;
                    break;
                }

                available = new Size(
                    Math.Max(availableSize.Width - size.Width, 0.0),
                    Math.Max(availableSize.Height - size.Height, 0.0));
                splitters[index].Measure(available);

                if (splitterSize > 0.0)
                {
                    switch (dockSide)
                    {
                    case Dock.Top:
                    case Dock.Bottom:
                        size.Height += splitters[index].DesiredSize.Height;
                        break;

                    case Dock.Left:
                    case Dock.Right:
                        size.Width += splitters[index].DesiredSize.Width;
                        break;
                    }
                }

                index++;
            }

            Child?.Measure(
                new Size(
                    Math.Max(availableSize.Width - size.Width, 0.0),
                    Math.Max(availableSize.Height - size.Height, 0.0)));

            return(size);
        }
 public SplitContainerCollection(DockCanvas parent, Visual visualParent)
 {
     this.parent = parent;
     collection  = new VisualCollection(visualParent);
 }