1
0
Эх сурвалжийг харах

Merge branch 'master' into radio

Max Katz 2 жил өмнө
parent
commit
e5bee790bc

+ 3 - 0
.editorconfig

@@ -137,6 +137,9 @@ space_within_single_line_array_initializer_braces = true
 #Net Analyzer
 #Net Analyzer
 dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed.
 dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed.
 
 
+# CS0649: Field 'field' is never assigned to, and will always have its default value 'value'
+dotnet_diagnostic.CS0649.severity = error
+
 # CS1591: Missing XML comment for publicly visible type or member
 # CS1591: Missing XML comment for publicly visible type or member
 dotnet_diagnostic.CS1591.severity = suggestion
 dotnet_diagnostic.CS1591.severity = suggestion
 
 

+ 2 - 2
samples/ControlCatalog/Pages/ExpanderPage.xaml.cs

@@ -14,8 +14,8 @@ namespace ControlCatalog.Pages
             var CollapsingDisabledExpander = this.Get<Expander>("CollapsingDisabledExpander");
             var CollapsingDisabledExpander = this.Get<Expander>("CollapsingDisabledExpander");
             var ExpandingDisabledExpander = this.Get<Expander>("ExpandingDisabledExpander");
             var ExpandingDisabledExpander = this.Get<Expander>("ExpandingDisabledExpander");
 
 
-            CollapsingDisabledExpander.Collapsing += (s, e) => { e.Handled = true; };
-            ExpandingDisabledExpander.Expanding += (s, e) => { e.Handled = true; };
+            CollapsingDisabledExpander.Collapsing += (s, e) => { e.Cancel = true; };
+            ExpandingDisabledExpander.Expanding += (s, e) => { e.Cancel = true; };
         }
         }
 
 
         private void InitializeComponent()
         private void InitializeComponent()

+ 3 - 4
samples/GpuInterop/D3DDemo/D3D11DemoControl.cs

@@ -2,21 +2,17 @@ using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Linq;
 using System.Linq;
 using System.Numerics;
 using System.Numerics;
-using System.Threading.Tasks;
 using Avalonia;
 using Avalonia;
 using Avalonia.Platform;
 using Avalonia.Platform;
 using Avalonia.Rendering.Composition;
 using Avalonia.Rendering.Composition;
 using SharpDX;
 using SharpDX;
-using SharpDX.Direct2D1;
 using SharpDX.Direct3D11;
 using SharpDX.Direct3D11;
 using SharpDX.DXGI;
 using SharpDX.DXGI;
 using SharpDX.Mathematics.Interop;
 using SharpDX.Mathematics.Interop;
 using Buffer = SharpDX.Direct3D11.Buffer;
 using Buffer = SharpDX.Direct3D11.Buffer;
-using DeviceContext = SharpDX.Direct2D1.DeviceContext;
 using DxgiFactory1 = SharpDX.DXGI.Factory1;
 using DxgiFactory1 = SharpDX.DXGI.Factory1;
 using Matrix = SharpDX.Matrix;
 using Matrix = SharpDX.Matrix;
 using D3DDevice = SharpDX.Direct3D11.Device;
 using D3DDevice = SharpDX.Direct3D11.Device;
-using DxgiResource = SharpDX.DXGI.Resource;
 using FeatureLevel = SharpDX.Direct3D.FeatureLevel;
 using FeatureLevel = SharpDX.Direct3D.FeatureLevel;
 using Vector3 = SharpDX.Vector3;
 using Vector3 = SharpDX.Vector3;
 
 
@@ -80,7 +76,10 @@ public class D3D11DemoControl : DrawingSurfaceDemoBase
         if (pixelSize == default)
         if (pixelSize == default)
             return;
             return;
         if (pixelSize != _lastSize)
         if (pixelSize != _lastSize)
+        {
+            _lastSize = pixelSize;
             Resize(pixelSize);
             Resize(pixelSize);
+        }
         using (_swapchain.BeginDraw(pixelSize, out var renderView))
         using (_swapchain.BeginDraw(pixelSize, out var renderView))
         {
         {
             
             

+ 39 - 0
src/Avalonia.Base/Interactivity/CancelRoutedEventArgs.cs

@@ -0,0 +1,39 @@
+namespace Avalonia.Interactivity
+{
+    /// <summary>
+    /// Provides state information and data specific to a cancelable routed event.
+    /// </summary>
+    public class CancelRoutedEventArgs : RoutedEventArgs
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="CancelRoutedEventArgs"/> class.
+        /// </summary>
+        public CancelRoutedEventArgs()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="CancelRoutedEventArgs"/> class.
+        /// </summary>
+        /// <param name="routedEvent">The routed event associated with these event args.</param>
+        public CancelRoutedEventArgs(RoutedEvent? routedEvent)
+            : base(routedEvent)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="CancelRoutedEventArgs"/> class.
+        /// </summary>
+        /// <param name="routedEvent">The routed event associated with these event args.</param>
+        /// <param name="source">The source object that raised the routed event.</param>
+        public CancelRoutedEventArgs(RoutedEvent? routedEvent, object? source)
+            : base(routedEvent, source)
+        {
+        }
+
+        /// <summary>
+        /// Gets or sets a value indicating whether the routed event should be canceled.
+        /// </summary>
+        public bool Cancel { get; set; } = false;
+    }
+}

+ 72 - 58
src/Avalonia.Controls/Expander.cs

@@ -59,12 +59,11 @@ namespace Avalonia.Controls
         /// <summary>
         /// <summary>
         /// Defines the <see cref="IsExpanded"/> property.
         /// Defines the <see cref="IsExpanded"/> property.
         /// </summary>
         /// </summary>
-        public static readonly DirectProperty<Expander, bool> IsExpandedProperty =
-            AvaloniaProperty.RegisterDirect<Expander, bool>(
+        public static readonly StyledProperty<bool> IsExpandedProperty =
+            AvaloniaProperty.Register<Expander, bool>(
                 nameof(IsExpanded),
                 nameof(IsExpanded),
-                o => o.IsExpanded,
-                (o, v) => o.IsExpanded = v,
-                defaultBindingMode: Data.BindingMode.TwoWay);
+                defaultBindingMode: BindingMode.TwoWay,
+                coerce: CoerceIsExpanded);
 
 
         /// <summary>
         /// <summary>
         /// Defines the <see cref="Collapsed"/> event.
         /// Defines the <see cref="Collapsed"/> event.
@@ -77,8 +76,8 @@ namespace Avalonia.Controls
         /// <summary>
         /// <summary>
         /// Defines the <see cref="Collapsing"/> event.
         /// Defines the <see cref="Collapsing"/> event.
         /// </summary>
         /// </summary>
-        public static readonly RoutedEvent<RoutedEventArgs> CollapsingEvent =
-            RoutedEvent.Register<Expander, RoutedEventArgs>(
+        public static readonly RoutedEvent<CancelRoutedEventArgs> CollapsingEvent =
+            RoutedEvent.Register<Expander, CancelRoutedEventArgs>(
                 nameof(Collapsing),
                 nameof(Collapsing),
                 RoutingStrategies.Bubble);
                 RoutingStrategies.Bubble);
 
 
@@ -93,13 +92,12 @@ namespace Avalonia.Controls
         /// <summary>
         /// <summary>
         /// Defines the <see cref="Expanding"/> event.
         /// Defines the <see cref="Expanding"/> event.
         /// </summary>
         /// </summary>
-        public static readonly RoutedEvent<RoutedEventArgs> ExpandingEvent =
-            RoutedEvent.Register<Expander, RoutedEventArgs>(
+        public static readonly RoutedEvent<CancelRoutedEventArgs> ExpandingEvent =
+            RoutedEvent.Register<Expander, CancelRoutedEventArgs>(
                 nameof(Expanding),
                 nameof(Expanding),
                 RoutingStrategies.Bubble);
                 RoutingStrategies.Bubble);
 
 
         private bool _ignorePropertyChanged = false;
         private bool _ignorePropertyChanged = false;
-        private bool _isExpanded;
         private CancellationTokenSource? _lastTransitionCts;
         private CancellationTokenSource? _lastTransitionCts;
 
 
         /// <summary>
         /// <summary>
@@ -134,50 +132,8 @@ namespace Avalonia.Controls
         /// </summary>
         /// </summary>
         public bool IsExpanded
         public bool IsExpanded
         {
         {
-            get => _isExpanded;
-            set
-            {
-                // It is important here that IsExpanded is a direct property so events can be invoked
-                // BEFORE the property system gets notified of updated values. This is because events
-                // may be canceled by external code.
-                if (_isExpanded != value)
-                {
-                    RoutedEventArgs eventArgs;
-
-                    if (value)
-                    {
-                        eventArgs = new RoutedEventArgs(ExpandingEvent, this);
-                        OnExpanding(eventArgs);
-                    }
-                    else
-                    {
-                        eventArgs = new RoutedEventArgs(CollapsingEvent, this);
-                        OnCollapsing(eventArgs);
-                    }
-
-                    if (eventArgs.Handled)
-                    {
-                        // If the event was externally handled (canceled) we must still notify the value has changed.
-                        // This property changed notification will update any external code observing this property that itself may have set the new value.
-                        // We are essentially reverted any external state change along with ignoring the IsExpanded property set.
-                        // Remember IsExpanded is usually controlled by a ToggleButton in the control theme.
-                        _ignorePropertyChanged = true;
-
-                        RaisePropertyChanged(
-                            IsExpandedProperty,
-                            oldValue: value,
-                            newValue: _isExpanded,
-                            BindingPriority.LocalValue,
-                            isEffectiveValue: true);
-
-                        _ignorePropertyChanged = false;
-                    }
-                    else
-                    {
-                        SetAndRaise(IsExpandedProperty, ref _isExpanded, value);
-                    }
-                }
-            }
+            get => GetValue(IsExpandedProperty);
+            set => SetValue(IsExpandedProperty, value);
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -193,10 +149,10 @@ namespace Avalonia.Controls
         /// Occurs as the content area is closing.
         /// Occurs as the content area is closing.
         /// </summary>
         /// </summary>
         /// <remarks>
         /// <remarks>
-        /// The event args <see cref="RoutedEventArgs.Handled"/> property may be set to true to cancel the event
+        /// The event args <see cref="CancelRoutedEventArgs.Cancel"/> property may be set to true to cancel the event
         /// and keep the control open (expanded).
         /// and keep the control open (expanded).
         /// </remarks>
         /// </remarks>
-        public event EventHandler<RoutedEventArgs>? Collapsing
+        public event EventHandler<CancelRoutedEventArgs>? Collapsing
         {
         {
             add => AddHandler(CollapsingEvent, value);
             add => AddHandler(CollapsingEvent, value);
             remove => RemoveHandler(CollapsingEvent, value);
             remove => RemoveHandler(CollapsingEvent, value);
@@ -215,10 +171,10 @@ namespace Avalonia.Controls
         /// Occurs as the content area is opening.
         /// Occurs as the content area is opening.
         /// </summary>
         /// </summary>
         /// <remarks>
         /// <remarks>
-        /// The event args <see cref="RoutedEventArgs.Handled"/> property may be set to true to cancel the event
+        /// The event args <see cref="CancelRoutedEventArgs.Cancel"/> property may be set to true to cancel the event
         /// and keep the control closed (collapsed).
         /// and keep the control closed (collapsed).
         /// </remarks>
         /// </remarks>
-        public event EventHandler<RoutedEventArgs>? Expanding
+        public event EventHandler<CancelRoutedEventArgs>? Expanding
         {
         {
             add => AddHandler(ExpandingEvent, value);
             add => AddHandler(ExpandingEvent, value);
             remove => RemoveHandler(ExpandingEvent, value);
             remove => RemoveHandler(ExpandingEvent, value);
@@ -332,5 +288,63 @@ namespace Avalonia.Controls
 
 
             PseudoClasses.Set(":expanded", IsExpanded);
             PseudoClasses.Set(":expanded", IsExpanded);
         }
         }
+
+        /// <summary>
+        /// Called when the <see cref="IsExpanded"/> property has to be coerced.
+        /// </summary>
+        /// <param name="value">The value to coerce.</param>
+        protected virtual bool OnCoerceIsExpanded(bool value)
+        {
+            CancelRoutedEventArgs eventArgs;
+
+            if (value)
+            {
+                eventArgs = new CancelRoutedEventArgs(ExpandingEvent, this);
+                OnExpanding(eventArgs);
+            }
+            else
+            {
+                eventArgs = new CancelRoutedEventArgs(CollapsingEvent, this);
+                OnCollapsing(eventArgs);
+            }
+
+            if (eventArgs.Cancel)
+            {
+                // If the event was externally canceled we must still notify the value has changed.
+                // This property changed notification will update any external code observing this property that itself may have set the new value.
+                // We are essentially reverted any external state change along with ignoring the IsExpanded property set.
+                // Remember IsExpanded is usually controlled by a ToggleButton in the control theme and is also used for animations.
+                _ignorePropertyChanged = true;
+
+                RaisePropertyChanged(
+                    IsExpandedProperty,
+                    oldValue: value,
+                    newValue: !value,
+                    BindingPriority.LocalValue,
+                    isEffectiveValue: true);
+
+                _ignorePropertyChanged = false;
+
+                return !value;
+            }
+
+            return value;
+        }
+
+        /// <summary>
+        /// Coerces/validates the <see cref="IsExpanded"/> property value.
+        /// </summary>
+        /// <param name="instance">The <see cref="Expander"/> instance.</param>
+        /// <param name="value">The value to coerce.</param>
+        /// <returns>The coerced/validated value.</returns>
+        private static bool CoerceIsExpanded(AvaloniaObject instance, bool value)
+        {
+            if (instance is Expander expander)
+            {
+                return expander.OnCoerceIsExpanded(value);
+            }
+
+            return value;
+        }
     }
     }
 }
 }

+ 2 - 2
src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs

@@ -34,7 +34,7 @@ namespace Avalonia.FreeDesktop.DBusIme
         private bool _connecting;
         private bool _connecting;
         private string? _currentName;
         private string? _currentName;
         private DBusCallQueue _queue;
         private DBusCallQueue _queue;
-        private bool _controlActive, _windowActive;
+        private bool _windowActive;
         private bool? _imeActive;
         private bool? _imeActive;
         private Rect _logicalRect;
         private Rect _logicalRect;
         private PixelRect? _lastReportedRect;
         private PixelRect? _lastReportedRect;
@@ -189,7 +189,7 @@ namespace Avalonia.FreeDesktop.DBusIme
                 if(!IsConnected)
                 if(!IsConnected)
                     return;
                     return;
                 
                 
-                var active = _windowActive && _controlActive;
+                var active = _windowActive && IsActive;
                 if (active != _imeActive)
                 if (active != _imeActive)
                 {
                 {
                     _imeActive = active;
                     _imeActive = active;

+ 2 - 2
src/Avalonia.X11/X11Window.Xim.cs

@@ -13,7 +13,7 @@ namespace Avalonia.X11
         class XimInputMethod : ITextInputMethodImpl, IX11InputMethodControl
         class XimInputMethod : ITextInputMethodImpl, IX11InputMethodControl
         {
         {
             private readonly X11Window _parent;
             private readonly X11Window _parent;
-            private bool _controlActive, _windowActive, _imeActive;
+            private bool _windowActive, _imeActive;
             private Rect? _queuedCursorRect;
             private Rect? _queuedCursorRect;
             private ITextInputMethodClient? _client;
             private ITextInputMethodClient? _client;
 
 
@@ -70,7 +70,7 @@ namespace Avalonia.X11
 
 
             private void UpdateActive()
             private void UpdateActive()
             {
             {
-                var active = _windowActive && _controlActive;
+                var active = _windowActive && IsActive;
                 if(_parent._xic == IntPtr.Zero)
                 if(_parent._xic == IntPtr.Zero)
                     return;
                     return;
                 if (active != _imeActive)
                 if (active != _imeActive)