Пример #1
0
        void ApplyRegion(Rect wndRect)
        {
            if (!this.CanTransform())
            {
                return;
            }

            wndRect = new Rect(
                this.TransformFromDeviceDPI(wndRect.TopLeft),
                this.TransformFromDeviceDPI(wndRect.Size));

            _lastApplyRect = wndRect;

            if (PresentationSource.FromVisual(this) == null)
            {
                return;
            }


            if (_dockingManager != null)
            {
                List <Rect> otherRects = new List <Rect>();

                foreach (Window fl in Window.GetWindow(_dockingManager).OwnedWindows)
                {
                    //not with myself!
                    if (fl == this)
                    {
                        continue;
                    }

                    if (!fl.IsVisible)
                    {
                        continue;
                    }

                    //Issue 11545, thx to SrdjanPolic
                    Rect flRect = new Rect(
                        PointFromScreen(new Point(fl.Left, fl.Top)),
                        PointFromScreen(new Point(fl.Left + fl.RestoreBounds.Width, fl.Top + fl.RestoreBounds.Height)));

                    if (flRect.IntersectsWith(wndRect) && fl.AllowsTransparency == false)
                    {
                        otherRects.Add(Rect.Intersect(flRect, wndRect));
                    }

                    //Rect flRect = new Rect(
                    //    PointFromScreen(new Point(fl.Left, fl.Top)),
                    //    PointFromScreen(new Point(fl.Left + fl.Width, fl.Top + fl.Height)));

                    //if (flRect.IntersectsWith(wndRect))
                    //    otherRects.Add(Rect.Intersect(flRect, wndRect));
                }

                IntPtr hDestRegn = InteropHelper.CreateRectRgn(
                    (int)wndRect.Left,
                    (int)wndRect.Top,
                    (int)wndRect.Right,
                    (int)wndRect.Bottom);

                foreach (Rect otherRect in otherRects)
                {
                    IntPtr otherWin32Rect = InteropHelper.CreateRectRgn(
                        (int)otherRect.Left,
                        (int)otherRect.Top,
                        (int)otherRect.Right,
                        (int)otherRect.Bottom);

                    InteropHelper.CombineRgn(hDestRegn, hDestRegn, otherWin32Rect, (int)InteropHelper.CombineRgnStyles.RGN_DIFF);
                }


                InteropHelper.SetWindowRgn(new WindowInteropHelper(this).Handle, hDestRegn, true);
            }
        }
Пример #2
0
        /// <summary>
        /// Initiate an opening animation
        /// </summary>
        void OpenWidthAnimation()
        {
            double wnd_Width  = this._targetWidth > 0.0 ? this._targetWidth : this.ActualWidth;
            double wnd_Height = this._targetHeight > 0.0 ? this._targetHeight : this.ActualHeight;
            double wnd_Left   = this.Left;
            double wnd_Top    = this.Top;

            int wnd_TrimWidth  = 0;
            int wnd_TrimHeight = 0;

            int stepWidth  = (int)(wnd_Width / 4);
            int stepHeight = (int)(wnd_Height / 4);

            if (CorrectedAnchor == AnchorStyle.Left)
            {
                InteropHelper.SetWindowRgn(new WindowInteropHelper(this).Handle, InteropHelper.CreateRectRgn(0, 0, 0, (int)wnd_Height - wnd_TrimHeight), true);
                this.Left = wnd_Left - wnd_Width;
            }
            else if (CorrectedAnchor == AnchorStyle.Top)
            {
                InteropHelper.SetWindowRgn(new WindowInteropHelper(this).Handle, InteropHelper.CreateRectRgn(0, 0, (int)wnd_Width - wnd_TrimWidth, 0), true);
                this.Top = wnd_Top - wnd_Height;
            }

            DispatcherTimer animTimer = new DispatcherTimer();

            animTimer.Interval = TimeSpan.FromMilliseconds(1);

            animTimer.Tick += (sender, eventArgs) =>
            {
                bool stopTimer = false;
                switch (CorrectedAnchor)
                {
                case AnchorStyle.Right:
                {
                    double newLeft = this.Left;
                    if (this.Left - stepWidth <= wnd_Left - wnd_Width)
                    {
                        newLeft       = wnd_Left - wnd_Width;
                        wnd_TrimWidth = (int)wnd_Width;
                        stopTimer     = true;
                    }
                    else
                    {
                        newLeft       -= stepWidth;
                        wnd_TrimWidth += stepWidth;
                    }

                    Width     = _targetWidth;
                    this.Left = newLeft;
                    ApplyRegion(new Rect(0, 0, wnd_TrimWidth, (int)wnd_Height - wnd_TrimHeight));
                }
                break;

                case AnchorStyle.Left:
                {
                    double newLeft = this.Left;
                    if (this.Left + stepWidth >= wnd_Left)
                    {
                        newLeft       = wnd_Left;
                        wnd_TrimWidth = (int)wnd_Width;
                        stopTimer     = true;
                    }
                    else
                    {
                        newLeft       += stepWidth;
                        wnd_TrimWidth += stepWidth;
                    }

                    ApplyRegion(
                        new Rect((int)(wnd_Left - this.Left), 0, (int)(wnd_Width), (int)wnd_Height - wnd_TrimHeight));

                    Width     = _targetWidth;
                    this.Left = newLeft;
                }
                break;

                case AnchorStyle.Bottom:
                {
                    double newTop = this.Top;
                    if (this.Top - stepHeight <= wnd_Top - wnd_Height)
                    {
                        newTop         = wnd_Top - wnd_Height;
                        wnd_TrimHeight = (int)wnd_Height;
                        stopTimer      = true;
                    }
                    else
                    {
                        newTop         -= stepHeight;
                        wnd_TrimHeight += stepHeight;
                    }

                    ApplyRegion(
                        new Rect(0, 0, (int)wnd_Width - wnd_TrimWidth, wnd_TrimHeight));

                    Height   = _targetHeight;
                    this.Top = newTop;
                }
                break;

                case AnchorStyle.Top:
                {
                    double newTop = this.Top;
                    if (this.Top + stepHeight >= wnd_Top)
                    {
                        newTop         = wnd_Top;
                        wnd_TrimHeight = (int)wnd_Height;
                        stopTimer      = true;
                    }
                    else
                    {
                        newTop         += stepHeight;
                        wnd_TrimHeight += stepHeight;
                    }

                    ApplyRegion(
                        new Rect(0, (int)(wnd_Top - this.Top), (int)wnd_Width - wnd_TrimWidth, (int)(wnd_Height)));

                    Height   = _targetHeight;
                    this.Top = newTop;
                }
                break;
                }

                if (stopTimer)
                {
                    UpdatePositionAndSize();
                    animTimer.Stop();
                    IsOpening = false;
                }
            };

            IsOpening = true;
            animTimer.Start();
        }