Esempio n. 1
0
        void ShowResizerOverlayWindow(Resizer splitter)
        {
            Point ptTopLeftScreen = this.PointToScreenDPI(new Point());

            _resizerGhost = new Border()
            {
                Background = Brushes.Black,
                Opacity = 0.7
            };

            Size actualSize = this.TransformedActualSize();

            if (Orientation == System.Windows.Controls.Orientation.Horizontal)
            {
                _resizerGhost.Width = 5.0;
                _resizerGhost.Height = actualSize.Height;
            }
            else
            {
                _resizerGhost.Height = 5.0;
                _resizerGhost.Width = actualSize.Width;
            }

            _initialStartPoint = splitter.PointToScreenDPI(new Point()) - this.PointToScreenDPI(new Point());

            if (Orientation == System.Windows.Controls.Orientation.Horizontal)
            {
                Canvas.SetLeft(_resizerGhost, _initialStartPoint.X);
            }
            else
            {
                Canvas.SetTop(_resizerGhost, _initialStartPoint.Y);
            }

            Canvas panelHostResizer = new Canvas()
            {
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch
            };

            panelHostResizer.Children.Add(_resizerGhost);

            _resizerWindowHost = new Window()
            {
                ResizeMode = ResizeMode.NoResize,
                WindowStyle = System.Windows.WindowStyle.None,
                ShowInTaskbar = false,
                AllowsTransparency = true,
                Background = null,
                Width = actualSize.Width,
                Height = actualSize.Height,
                Left = ptTopLeftScreen.X,
                Top = ptTopLeftScreen.Y,
                ShowActivated = false,
                Owner = Window.GetWindow(this),
                Content = panelHostResizer
                //,
                //LayoutTransform = (MatrixTransform)this.TansformToAncestor()
            };

            _resizerWindowHost.Show();
        }
Esempio n. 2
0
        void SetupSplitters()
        {
            if (!splitterListIsDirty)
                return;

            if (setupSplitters)
                return;

            setupSplitters = true;

            while (_splitterList.Count > 0)
            {
                Resizer splitter = _splitterList[0];
                splitter.DragStarted -= new DragStartedEventHandler(splitter_DragStarted);
                splitter.DragDelta -= new DragDeltaEventHandler(splitter_DragDelta);
                splitter.DragCompleted -= new DragCompletedEventHandler(splitter_DragCompleted);
                _splitterList.Remove(splitter);
                Children.Remove(splitter);
            }

            int i = 0;//child index
            int j = 0;//splitter index

            while (i < Children.Count - 1)
            {
                if (j == _splitterList.Count)
                {
                    Resizer splitter = new Resizer();
                    splitter.Cursor =  this.Orientation == Orientation.Horizontal ? Cursors.SizeWE : Cursors.SizeNS;
                    _splitterList.Add(splitter);
                    splitter.DragStarted += new DragStartedEventHandler(splitter_DragStarted);
                    splitter.DragDelta += new DragDeltaEventHandler(splitter_DragDelta);
                    splitter.DragCompleted += new DragCompletedEventHandler(splitter_DragCompleted);
                    Children.Insert(i + 1, splitter);
                }

                i += 2;
                j++;
            }

            for (j = 0; j < _splitterList.Count; j++)
            {
                _splitterList[j].Width = (Orientation == Orientation.Horizontal) ? 6 : double.NaN;
                _splitterList[j].Height = (Orientation == Orientation.Vertical) ? 6 : double.NaN;
            }

            #if DEBUG
            Debug.Assert(_splitterList.Count == Children.Count / 2);
            i = 0;
            while (Children.Count > 0)
            {
                Debug.Assert(Children[i] != null);
                Debug.Assert(!(Children[i] is Resizer));
                i++;
                if (i >= Children.Count)
                    break;

                Debug.Assert((Children[i] is Resizer));
                i++;

            }
            #endif
            splitterListIsDirty = false;
            setupSplitters = false;
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Resizer resLeftAnchor   = GetTemplateChild("PART_LeftAnchor") as Resizer;
            Resizer resTopAnchor    = GetTemplateChild("PART_TopAnchor") as Resizer;
            Resizer resBottomAnchor = GetTemplateChild("PART_BottomAnchor") as Resizer;
            Resizer resRightAnchor  = GetTemplateChild("PART_RightAnchor") as Resizer;

            Resizer resLeftTopAnchor    = GetTemplateChild("PART_LeftTopAnchor") as Resizer;
            Resizer resLeftBottomAnchor = GetTemplateChild("PART_LeftBottomAnchor") as Resizer;

            Resizer resRightTopAnchor    = GetTemplateChild("PART_RightTopAnchor") as Resizer;
            Resizer resRightBottomAnchor = GetTemplateChild("PART_RightBottomAnchor") as Resizer;

            //Resizer resMoveAnchor = GetTemplateChild("PART_MoveAnchor") as Resizer;
            Border resMoveAnchor = GetTemplateChild("PART_MoveAnchor") as Border;

            if (resLeftAnchor != null)
            {
                resLeftAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinWidth, Width - e.HorizontalChange) - Width;
                    this.Left  -= delta;
                    this.Width += delta;
                }
            }
            ;
            if (resRightAnchor != null)
            {
                resRightAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinWidth, Width + e.HorizontalChange) - Width;
                    this.Width += delta;
                }
            }
            ;
            if (resTopAnchor != null)
            {
                resTopAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinHeight, Height - e.VerticalChange) - Height;
                    this.Top    -= delta;
                    this.Height += delta;
                }
            }
            ;
            if (resBottomAnchor != null)
            {
                resBottomAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinHeight, Height + e.VerticalChange) - Height;
                    this.Height += delta;
                }
            }
            ;

            if (resLeftTopAnchor != null)
            {
                resLeftTopAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinWidth, Width - e.HorizontalChange) - Width;
                    this.Left  -= delta;
                    this.Width += delta;

                    delta        = Math.Max(MinHeight, Height - e.VerticalChange) - Height;
                    this.Top    -= delta;
                    this.Height += delta;
                }
            }
            ;
            if (resLeftBottomAnchor != null)
            {
                resLeftBottomAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinWidth, Width - e.HorizontalChange) - Width;
                    this.Left  -= delta;
                    this.Width += delta;

                    delta        = Math.Max(MinHeight, Height + e.VerticalChange) - Height;
                    this.Height += delta;
                }
            }
            ;
            if (resRightTopAnchor != null)
            {
                resRightTopAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinWidth, Width + e.HorizontalChange) - Width;
                    this.Width += delta;

                    delta        = Math.Max(MinHeight, Height - e.VerticalChange) - Height;
                    this.Top    -= delta;
                    this.Height += delta;
                }
            }
            ;
            if (resRightBottomAnchor != null)
            {
                resRightBottomAnchor.DragDelta += (s, e) =>
                {
                    double delta = Math.Max(MinWidth, Width + e.HorizontalChange) - Width;
                    this.Width += delta;

                    delta        = Math.Max(MinHeight, Height + e.VerticalChange) - Height;
                    this.Height += delta;
                }
            }
            ;

            if (resMoveAnchor != null)
            {
                bool  isMouseDown = false;
                Point ptStartDrag = new Point();
                resMoveAnchor.MouseLeftButtonDown += (s, e) =>
                {
                    isMouseDown = true;
                    ptStartDrag = e.GetPosition(s as IInputElement);
                    resMoveAnchor.CaptureMouse();
                };

                resMoveAnchor.MouseMove += (s, e) =>
                {
                    if (isMouseDown && resMoveAnchor.IsMouseCaptured)
                    {
                        Point ptMouseMove = e.GetPosition(s as IInputElement);
                        if (Math.Abs(ptMouseMove.X - ptStartDrag.X) > SystemParameters.MinimumHorizontalDragDistance ||
                            Math.Abs(ptMouseMove.Y - ptStartDrag.Y) > SystemParameters.MinimumVerticalDragDistance)
                        {
                            isMouseDown = false;
                            resMoveAnchor.ReleaseMouseCapture();
                            HandleMove();
                        }
                    }
                };

                resMoveAnchor.MouseLeftButtonUp += (s, e) =>
                {
                    isMouseDown = false;
                    resMoveAnchor.ReleaseMouseCapture();
                };
            }

            var pupupButton = GetTemplateChild("PART_ShowContextMenuButton") as FrameworkElement;

            if (pupupButton != null)
            {
                pupupButton.MouseLeftButtonDown += (s, e) =>
                {
                    e.Handled = OpenContextMenu(s as Border, e.GetPosition(s as IInputElement));
                }
            }
            ;

            var titleAnchor = GetTemplateChild("PART_MoveAnchor") as FrameworkElement;

            if (titleAnchor != null)
            {
                titleAnchor.MouseRightButtonDown += (s, e) =>
                {
                    e.Handled = OpenContextMenu(s as Border, e.GetPosition(s as IInputElement));
                }
            }
            ;


            base.OnApplyTemplate();
        }
Esempio n. 4
0
        void ShowResizerOverlayWindow(Resizer splitter)
        {
            _resizerGhost = new Border()
            {
                Background = Brushes.Black,
                Opacity = 0.7
            };

            if (CorrectedAnchor == AnchorStyle.Left || CorrectedAnchor == AnchorStyle.Right)
            {
                _resizerGhost.Width = splitter.Width;
                _resizerGhost.Height = MaxHeight;
            }
            else
            {
                _resizerGhost.Height = splitter.Height;
                _resizerGhost.Width = MaxWidth;
            }

            Canvas panelHostResizer = new Canvas()
            {
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch
            };

            panelHostResizer.Children.Add(_resizerGhost);

            _resizerWindowHost = new Window()
            {
                ResizeMode = ResizeMode.NoResize,
                WindowStyle = System.Windows.WindowStyle.None,
                ShowInTaskbar = false,
                AllowsTransparency = true,
                Background = null,
                Width = MaxWidth,
                Height = MaxHeight,
                Left = Left,
                Top = Top,
                ShowActivated = false,
                Owner = this,
                Content = panelHostResizer
            };

            if (CorrectedAnchor == AnchorStyle.Right)
                _resizerWindowHost.Left = Left - MaxWidth + Width;
            else if (CorrectedAnchor == AnchorStyle.Bottom)
                _resizerWindowHost.Top = Top - MaxHeight + Height;

            if (CorrectedAnchor == AnchorStyle.Left)
            {
                Canvas.SetLeft(_resizerGhost, Width - splitter.Width);
            }
            else if (CorrectedAnchor == AnchorStyle.Right)
            {
                Canvas.SetLeft(_resizerGhost, MaxWidth - Width);
            }
            else if (CorrectedAnchor == AnchorStyle.Top)
            {
                Canvas.SetTop(_resizerGhost, Height - splitter.Height);
            }
            else if (CorrectedAnchor == AnchorStyle.Bottom)
            {
                Canvas.SetTop(_resizerGhost, MaxHeight - Height);
            }

            _initialStartPoint = new Vector(Canvas.GetLeft(_resizerGhost), Canvas.GetTop(_resizerGhost));

            _resizerWindowHost.Show();
        }
Esempio n. 5
0
        void ShowResizerOverlayWindow(Resizer splitter)
        {
            _resizerGhost = new Border()
            {
                Background = Brushes.Black,
                Opacity    = 0.7
            };

            if (CorrectedAnchor == AnchorStyle.Left || CorrectedAnchor == AnchorStyle.Right)
            {
                _resizerGhost.Width  = splitter.Width;
                _resizerGhost.Height = MaxHeight;
            }
            else
            {
                _resizerGhost.Height = splitter.Height;
                _resizerGhost.Width  = MaxWidth;
            }

            Canvas panelHostResizer = new Canvas()
            {
                HorizontalAlignment = Avalonia.HorizontalAlignment.Stretch,
                VerticalAlignment   = Avalonia.VerticalAlignment.Stretch
            };

            panelHostResizer.Children.Add(_resizerGhost);

            _resizerWindowHost = new Window()
            {
                ResizeMode         = ResizeMode.NoResize,
                WindowStyle        = Avalonia.WindowStyle.None,
                ShowInTaskbar      = false,
                AllowsTransparency = true,
                Background         = null,
                Width         = MaxWidth,
                Height        = MaxHeight,
                Left          = Left,
                Top           = Top,
                ShowActivated = false,
                Owner         = this,
                Content       = panelHostResizer
            };

            if (CorrectedAnchor == AnchorStyle.Right)
            {
                _resizerWindowHost.Left = Left - MaxWidth + Width;
            }
            else if (CorrectedAnchor == AnchorStyle.Bottom)
            {
                _resizerWindowHost.Top = Top - MaxHeight + Height;
            }

            if (CorrectedAnchor == AnchorStyle.Left)
            {
                Canvas.SetLeft(_resizerGhost, Width - splitter.Width);
            }
            else if (CorrectedAnchor == AnchorStyle.Right)
            {
                Canvas.SetLeft(_resizerGhost, MaxWidth - Width);
            }
            else if (CorrectedAnchor == AnchorStyle.Top)
            {
                Canvas.SetTop(_resizerGhost, Height - splitter.Height);
            }
            else if (CorrectedAnchor == AnchorStyle.Bottom)
            {
                Canvas.SetTop(_resizerGhost, MaxHeight - Height);
            }

            _initialStartPoint = new Vector(Canvas.GetLeft(_resizerGhost), Canvas.GetTop(_resizerGhost));

            _resizerWindowHost.Show();
        }