Inheritance: System.Windows.DependencyObject
        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);
        }
Exemple #2
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);
        }
Exemple #3
0
        private static void _OnChromeWorkerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Window             window             = (Window)d;
            WindowChromeWorker windowChromeWorker = (WindowChromeWorker)e.NewValue;

            windowChromeWorker._SetWindow(window);
        }
Exemple #4
0
 private static void _OnChromeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (!DesignerProperties.GetIsInDesignMode(d))
     {
         Window             window             = (Window)d;
         WindowChrome       newValue           = (WindowChrome)e.NewValue;
         WindowChromeWorker windowChromeWorker = WindowChromeWorker.GetWindowChromeWorker(window);
         if (windowChromeWorker == null)
         {
             windowChromeWorker = new WindowChromeWorker();
             WindowChromeWorker.SetWindowChromeWorker(window, windowChromeWorker);
         }
         windowChromeWorker.SetWindowChrome(newValue);
     }
 }
Exemple #5
0
        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;
            }
        }
 public static void SetWindowChromeWorker(Window window, WindowChromeWorker chrome)
 {
     Verify.IsNotNull(window, "window");
     window.SetValue(WindowChromeWorkerProperty, chrome);
 }
 public static void SetWindowChromeWorker(Window window, WindowChromeWorker chrome)
 {
     Verify.IsNotNull(window, "window");
     window.SetValue(WindowChromeWorkerProperty, chrome);
 }
Exemple #8
0
        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
            {
                double num3 = Math.Min(size.Width, size.Height);
                double num4 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopLeft, 0.0)).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)).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)).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)).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);
            }
        }
Exemple #9
0
        private void _SetRoundingRegion(WINDOWPOS?wp)
        {
            int  left;
            int  top;
            Size size;

            if (Standard.NativeMethods.GetWindowPlacement(this._hwnd).showCmd != SW.SHOWMAXIMIZED)
            {
                if (!wp.HasValue || Utility.IsFlagSet(wp.Value.flags, 1))
                {
                    if (wp.HasValue && this._lastRoundingState == this._window.WindowState)
                    {
                        return;
                    }
                    size = this._GetWindowRect().Size;
                }
                else
                {
                    size = new Size((double)wp.Value.cx, (double)wp.Value.cy);
                }
                this._lastRoundingState = this._window.WindowState;
                IntPtr zero = IntPtr.Zero;
                try
                {
                    double       num          = Math.Min(size.Width, size.Height);
                    CornerRadius cornerRadius = this._chromeInfo.CornerRadius;
                    Point        device       = DpiHelper.LogicalPixelsToDevice(new Point(cornerRadius.TopLeft, 0));
                    double       x            = device.X;
                    x = Math.Min(x, num / 2);
                    if (!WindowChromeWorker._IsUniform(this._chromeInfo.CornerRadius))
                    {
                        zero         = WindowChromeWorker._CreateRoundRectRgn(new Rect(0, 0, size.Width / 2 + x, size.Height / 2 + x), x);
                        cornerRadius = this._chromeInfo.CornerRadius;
                        device       = DpiHelper.LogicalPixelsToDevice(new Point(cornerRadius.TopRight, 0));
                        double x1 = device.X;
                        x1 = Math.Min(x1, num / 2);
                        Rect rect = new Rect(0, 0, size.Width / 2 + x1, size.Height / 2 + x1);
                        rect.Offset(size.Width / 2 - x1, 0);
                        WindowChromeWorker._CreateAndCombineRoundRectRgn(zero, rect, x1);
                        cornerRadius = this._chromeInfo.CornerRadius;
                        device       = DpiHelper.LogicalPixelsToDevice(new Point(cornerRadius.BottomLeft, 0));
                        double num1 = device.X;
                        num1 = Math.Min(num1, num / 2);
                        Rect rect1 = new Rect(0, 0, size.Width / 2 + num1, size.Height / 2 + num1);
                        rect1.Offset(0, size.Height / 2 - num1);
                        WindowChromeWorker._CreateAndCombineRoundRectRgn(zero, rect1, num1);
                        cornerRadius = this._chromeInfo.CornerRadius;
                        device       = DpiHelper.LogicalPixelsToDevice(new Point(cornerRadius.BottomRight, 0));
                        double x2 = device.X;
                        x2 = Math.Min(x2, num / 2);
                        Rect rect2 = new Rect(0, 0, size.Width / 2 + x2, size.Height / 2 + x2);
                        rect2.Offset(size.Width / 2 - x2, size.Height / 2 - x2);
                        WindowChromeWorker._CreateAndCombineRoundRectRgn(zero, rect2, x2);
                    }
                    else
                    {
                        zero = WindowChromeWorker._CreateRoundRectRgn(new Rect(size), x);
                    }
                    Standard.NativeMethods.SetWindowRgn(this._hwnd, zero, Standard.NativeMethods.IsWindowVisible(this._hwnd));
                    zero = IntPtr.Zero;
                }
                finally
                {
                    Utility.SafeDeleteObject(ref zero);
                }
            }
            else
            {
                if (!wp.HasValue)
                {
                    Rect rect3 = this._GetWindowRect();
                    left = (int)rect3.Left;
                    top  = (int)rect3.Top;
                }
                else
                {
                    left = wp.Value.x;
                    top  = wp.Value.y;
                }
                RECT monitorInfo = Standard.NativeMethods.GetMonitorInfo(Standard.NativeMethods.MonitorFromWindow(this._hwnd, 2)).rcWork;
                monitorInfo.Offset(-left, -top);
                IntPtr intPtr = IntPtr.Zero;
                try
                {
                    intPtr = Standard.NativeMethods.CreateRectRgnIndirect(monitorInfo);
                    Standard.NativeMethods.SetWindowRgn(this._hwnd, intPtr, Standard.NativeMethods.IsWindowVisible(this._hwnd));
                    intPtr = IntPtr.Zero;
                }
                finally
                {
                    Utility.SafeDeleteObject(ref intPtr);
                }
            }
        }