Exemplo n.º 1
0
        void HandlePositionChanged(object sender, sw.DependencyPropertyChangedEventArgs e)
        {
            if (PositionChangedEnabled > 0)
            {
                return;
            }
            // we use actual width vs. width itself, so we have to use the value passed in
            var old = position;
            var pos = (sw.GridLength)e.NewValue;

            if (pos.GridUnitType == sw.GridUnitType.Pixel)
            {
                var newPosition = (int)pos.Value;
                if (newPosition != Position)
                {
                    var args = new SplitterPositionChangingEventArgs(newPosition);
                    Callback.OnPositionChanging(Widget, args);
                    if (args.Cancel)
                    {
                        return;
                    }
                }
                position = newPosition;
            }
            Callback.OnPositionChanged(Widget, EventArgs.Empty);
            position = old;
        }
Exemplo n.º 2
0
        private void CheckSplitterPos()
        {
            if (splitterMoving > 0)
            {
                return;
            }

            var controlsize = (Orientation == Orientation.Horizontal) ? Control.Width : Control.Height;

            if (controlsize <= panel1MinimumSize)
            {
                return;
            }

            if (Widget.ParentWindow == null || !Widget.Loaded || suppressSplitterMoved > 0)
            {
                return;
            }

            splitterMoving++;
            var originalPosition = Control.SplitterDistance;
            var newPosition      = originalPosition;

            if (newPosition > controlsize - panel2MinimumSize)
            {
                newPosition = controlsize - panel2MinimumSize;
            }

            if (newPosition < panel1MinimumSize)
            {
                newPosition = panel1MinimumSize;
            }

            position = lastPosition;
            var args = new SplitterPositionChangingEventArgs(newPosition);

            Callback.OnPositionChanging(Widget, args);
            position = null;
            if (args.Cancel)
            {
                newPosition = lastPosition;
            }

            if (lastPosition != newPosition)
            {
                if (Control.IsHandleCreated)
                {
                    // keep track of the desired position (for removing/re-adding/resizing the control)
                    UpdateRelative();
                    position = newPosition;
                    Callback.OnPositionChanged(Widget, EventArgs.Empty);
                }

                Control.SplitterDistance = newPosition;
            }
            lastPosition = newPosition;

            splitterMoving--;
        }
Exemplo n.º 3
0
            public override nfloat ConstrainSplitPosition(NSSplitView splitView, nfloat proposedPosition, nint subviewDividerIndex)
            {
                var h = Handler;

                if (h == null)
                {
                    return(proposedPosition);
                }
                var totalSize = splitView.IsVertical ? splitView.Bounds.Width : splitView.Bounds.Height;

                if (h.Panel1?.Visible != true)
                {
                    return(0);
                }

                if (h.Panel2?.Visible != true)
                {
                    return((nfloat)Math.Max(0, totalSize - splitView.DividerThickness));
                }

                if (!h.Enabled)
                {
                    return(h.Position);
                }

                if ((h.Panel1MinimumSize > 0 || h.Panel2MinimumSize > 0))
                {
                    // constrain to panel 2 minimum size
                    proposedPosition = (nfloat)Math.Min(totalSize - h.panel2MinimumSize - splitView.DividerThickness, proposedPosition);
                    // constrain to panel 1 minimum size
                    proposedPosition = (nfloat)Math.Max(proposedPosition, h.Panel1MinimumSize);
                    // constrain to size of control
                    proposedPosition = (nfloat)Math.Min(totalSize, proposedPosition);
                }

                h.TriggerChangeStarted();

                var args = new SplitterPositionChangingEventArgs((int)Math.Round(proposedPosition));

                h.Callback.OnPositionChanging(h.Widget, args);
                if (args.Cancel)
                {
                    return(h.Position);
                }


                return((nfloat)Math.Round(proposedPosition));
            }
Exemplo n.º 4
0
        bool HandlePositionChanging(double horizontal, double vertical)
        {
            var position = DoublePosition;

            if (orientation == Orientation.Horizontal)
            {
                position += horizontal;
            }
            else
            {
                position += vertical;
            }
            // restrict to control size
            position = Math.Max(0, Math.Min(GetAvailableSize(false), position));

            var args = new SplitterPositionChangingEventArgs((int)Math.Round(position));

            Callback.OnPositionChanging(Widget, args);
            return(args.Cancel);
        }
Exemplo n.º 5
0
        bool HandlePositionChanging(double horizontal, double vertical, [System.Runtime.CompilerServices.CallerMemberName] string source = null)
        {
            var position = DoublePosition;

            if (orientation == Orientation.Horizontal)
            {
                position += horizontal;
            }
            else
            {
                position += vertical;
            }

            // restrict to control size
            position = Math.Max(0, Math.Min(GetAvailableSize(false), position));

            var intPosition = (int)Math.Round(position);

            if (intPosition == Position)
            {
                return(false);
            }
            // Console.WriteLine($"Source: {source}, {intPosition}");
            var args = new SplitterPositionChangingEventArgs(intPosition);

            Callback.OnPositionChanging(Widget, args);
            if (args.Cancel)
            {
                return(true);
            }

            if (fixedPanel == SplitterFixedPanel.None)
            {
                Callback.OnPositionChanged(Widget, EventArgs.Empty);
            }

            return(false);
        }
Exemplo n.º 6
0
        void HandlePositionChanged(object sender, sw.DependencyPropertyChangedEventArgs e)
        {
            if (PositionChangedEnabled > 0)
            {
                return;
            }
            // we use actual width vs. width itself, so we have to use the value passed in
            var old = position;
            var pos = (sw.GridLength)e.NewValue;

            if (pos.GridUnitType != sw.GridUnitType.Pixel)
            {
                return;
            }

            var newPosition = (int)Math.Round(pos.Value);

            if (sender is PropertyChangeNotifier notifier &&
                (notifier.PropertySource == Control.ColumnDefinitions[2] || notifier.PropertySource == Control.RowDefinitions[2]))
            {
                // invert position, we are resizing the second pane, not the first
                newPosition = (int)Math.Round(GetAvailableSize() - newPosition);
            }
            if (newPosition != Position)
            {
                var args = new SplitterPositionChangingEventArgs(newPosition);
                // Console.WriteLine($"Source: PositionChanged: {newPosition}");
                Callback.OnPositionChanging(Widget, args);
                if (args.Cancel)
                {
                    return;
                }
            }
            position = newPosition;
            Callback.OnPositionChanged(Widget, EventArgs.Empty);
            position = old;
        }