Пример #1
0
        private static void _OnChromeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // The different design tools handle drawing outside their custom window objects differently.
            // Rather than try to support this concept in the design surface let the designer draw its own
            // chrome anyways.
            // There's certainly room for improvement here.
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(d))
            {
                return;
            }

            var window    = (Window)d;
            var newChrome = (WindowChrome)e.NewValue;

            Assert.IsNotNull(window);

            // Update the ChromeWorker with this new object.

            // If there isn't currently a worker associated with the Window then assign a new one.
            // There can be a many:1 relationship of Window to WindowChrome objects, but a 1:1 for a Window and a WindowChromeWorker.
            WindowChromeWorker chromeWorker = WindowChromeWorker.GetWindowChromeWorker(window);

            if (chromeWorker == null)
            {
                chromeWorker = new WindowChromeWorker();
                WindowChromeWorker.SetWindowChromeWorker(window, chromeWorker);
            }

            chromeWorker.SetWindowChrome(newChrome);
        }
        private static void _OnChromeWorkerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Window             window             = (Window)d;
            WindowChromeWorker windowChromeWorker = (WindowChromeWorker)e.NewValue;

            windowChromeWorker._SetWindow(window);
        }
        // Token: 0x06000ECD RID: 3789 RVA: 0x00038AB8 File Offset: 0x00036CB8
        private static void _OnChromeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(d))
            {
                return;
            }
            Window             window             = (Window)d;
            WindowChrome       windowChrome       = (WindowChrome)e.NewValue;
            WindowChromeWorker windowChromeWorker = WindowChromeWorker.GetWindowChromeWorker(window);

            if (windowChromeWorker == null)
            {
                windowChromeWorker = new WindowChromeWorker();
                WindowChromeWorker.SetWindowChromeWorker(window, windowChromeWorker);
            }
            windowChromeWorker.SetWindowChrome(windowChrome);
        }
        private static void _CreateAndCombineRoundRectRgn(IntPtr hrgnSource, Rect region, double radius)
        {
            IntPtr hrgnSrc = IntPtr.Zero;

            try
            {
                hrgnSrc = WindowChromeWorker._CreateRoundRectRgn(region, radius);
                if (NativeMethods.CombineRgn(hrgnSource, hrgnSource, hrgnSrc, RGN.OR) == CombineRgnResult.ERROR)
                {
                    throw new InvalidOperationException("Unable to combine two HRGNs.");
                }
            }
            catch
            {
                Utility.SafeDeleteObject(ref hrgnSrc);
                throw;
            }
        }
        private void _SetRoundingRegion(WINDOWPOS?wp)
        {
            WINDOWPLACEMENT windowPlacement = NativeMethods.GetWindowPlacement(this._hwnd);

            if (windowPlacement.showCmd == SW.SHOWMAXIMIZED)
            {
                int num;
                int num2;
                if (wp != null)
                {
                    num  = wp.Value.x;
                    num2 = wp.Value.y;
                }
                else
                {
                    Rect rect = this._GetWindowRect();
                    num  = (int)rect.Left;
                    num2 = (int)rect.Top;
                }
                IntPtr      hMonitor    = NativeMethods.MonitorFromWindow(this._hwnd, 2U);
                MONITORINFO monitorInfo = NativeMethods.GetMonitorInfo(hMonitor);
                RECT        rcWork      = monitorInfo.rcWork;
                rcWork.Offset(-num, -num2);
                IntPtr hRgn = IntPtr.Zero;
                try
                {
                    hRgn = NativeMethods.CreateRectRgnIndirect(rcWork);
                    NativeMethods.SetWindowRgn(this._hwnd, hRgn, NativeMethods.IsWindowVisible(this._hwnd));
                    hRgn = IntPtr.Zero;
                    return;
                }
                finally
                {
                    Utility.SafeDeleteObject(ref hRgn);
                }
            }
            Size size;

            if (wp != null && !Utility.IsFlagSet(wp.Value.flags, 1))
            {
                size = new Size((double)wp.Value.cx, (double)wp.Value.cy);
            }
            else
            {
                if (wp != null && this._lastRoundingState == this._window.WindowState)
                {
                    return;
                }
                size = this._GetWindowRect().Size;
            }
            this._lastRoundingState = this._window.WindowState;
            IntPtr intPtr = IntPtr.Zero;

            try
            {
                DpiScale dpi  = this._window.GetDpi();
                double   num3 = Math.Min(size.Width, size.Height);
                double   num4 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopLeft, 0.0), dpi.DpiScaleX, dpi.DpiScaleY).X;
                num4 = Math.Min(num4, num3 / 2.0);
                if (WindowChromeWorker._IsUniform(this._chromeInfo.CornerRadius))
                {
                    intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(size), num4);
                }
                else
                {
                    intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(0.0, 0.0, size.Width / 2.0 + num4, size.Height / 2.0 + num4), num4);
                    double num5 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopRight, 0.0), dpi.DpiScaleX, dpi.DpiScaleY).X;
                    num5 = Math.Min(num5, num3 / 2.0);
                    Rect region = new Rect(0.0, 0.0, size.Width / 2.0 + num5, size.Height / 2.0 + num5);
                    region.Offset(size.Width / 2.0 - num5, 0.0);
                    WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region, num5);
                    double num6 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomLeft, 0.0), dpi.DpiScaleX, dpi.DpiScaleY).X;
                    num6 = Math.Min(num6, num3 / 2.0);
                    Rect region2 = new Rect(0.0, 0.0, size.Width / 2.0 + num6, size.Height / 2.0 + num6);
                    region2.Offset(0.0, size.Height / 2.0 - num6);
                    WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region2, num6);
                    double num7 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomRight, 0.0), dpi.DpiScaleX, dpi.DpiScaleY).X;
                    num7 = Math.Min(num7, num3 / 2.0);
                    Rect region3 = new Rect(0.0, 0.0, size.Width / 2.0 + num7, size.Height / 2.0 + num7);
                    region3.Offset(size.Width / 2.0 - num7, size.Height / 2.0 - num7);
                    WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region3, num7);
                }
                NativeMethods.SetWindowRgn(this._hwnd, intPtr, NativeMethods.IsWindowVisible(this._hwnd));
                intPtr = IntPtr.Zero;
            }
            finally
            {
                Utility.SafeDeleteObject(ref intPtr);
            }
        }
 // Token: 0x06000EF2 RID: 3826 RVA: 0x00039632 File Offset: 0x00037832
 public static void SetWindowChromeWorker(Window window, WindowChromeWorker chrome)
 {
     Verify.IsNotNull <Window>(window, "window");
     window.SetValue(WindowChromeWorker.WindowChromeWorkerProperty, chrome);
 }