Browse Source

Merge branch 'master' into FixTypeUtilities

pull/3942/head
Steven Kirk 6 years ago
committed by GitHub
parent
commit
742b7ecf81
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Documentation/build.md
  2. 5
      native/Avalonia.Native/inc/avalonia-native.h
  3. 3
      native/Avalonia.Native/src/OSX/window.h
  4. 74
      native/Avalonia.Native/src/OSX/window.mm
  5. 225
      src/Avalonia.Animation/Animatable.cs
  6. 2
      src/Avalonia.Animation/TransitionInstance.cs
  7. 13
      src/Avalonia.Animation/Transitions.cs
  8. 204
      src/Avalonia.Base/AvaloniaObject.cs
  9. 59
      src/Avalonia.Base/AvaloniaObjectExtensions.cs
  10. 7
      src/Avalonia.Base/AvaloniaProperty.cs
  11. 23
      src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs
  12. 24
      src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs
  13. 4
      src/Avalonia.Base/Data/BindingValue.cs
  14. 5
      src/Avalonia.Base/DirectPropertyBase.cs
  15. 13
      src/Avalonia.Base/IAvaloniaObject.cs
  16. 20
      src/Avalonia.Base/PropertyStore/BindingEntry.cs
  17. 14
      src/Avalonia.Base/PropertyStore/ConstantValueEntry.cs
  18. 6
      src/Avalonia.Base/PropertyStore/IValue.cs
  19. 6
      src/Avalonia.Base/PropertyStore/IValueSink.cs
  20. 11
      src/Avalonia.Base/PropertyStore/LocalValueEntry.cs
  21. 161
      src/Avalonia.Base/PropertyStore/PriorityValue.cs
  22. 7
      src/Avalonia.Base/StyledPropertyBase.cs
  23. 69
      src/Avalonia.Base/ValueStore.cs
  24. 5
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  25. 12
      src/Avalonia.Controls/Button.cs
  26. 12
      src/Avalonia.Controls/ButtonSpinner.cs
  27. 12
      src/Avalonia.Controls/Calendar/DatePicker.cs
  28. 12
      src/Avalonia.Controls/Expander.cs
  29. 12
      src/Avalonia.Controls/Notifications/WindowNotificationManager.cs
  30. 16
      src/Avalonia.Controls/Platform/IWindowImpl.cs
  31. 15
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  32. 20
      src/Avalonia.Controls/Primitives/ScrollBar.cs
  33. 8
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  34. 12
      src/Avalonia.Controls/Primitives/Track.cs
  35. 16
      src/Avalonia.Controls/ProgressBar.cs
  36. 56
      src/Avalonia.Controls/Repeater/ItemsRepeater.cs
  37. 36
      src/Avalonia.Controls/Repeater/ViewManager.cs
  38. 34
      src/Avalonia.Controls/Shapes/Path.cs
  39. 111
      src/Avalonia.Controls/Shapes/Shape.cs
  40. 12
      src/Avalonia.Controls/Slider.cs
  41. 8
      src/Avalonia.Controls/TreeView.cs
  42. 121
      src/Avalonia.Controls/Window.cs
  43. 2
      src/Avalonia.Controls/WindowBase.cs
  44. 9
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  45. 10
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
  46. 10
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  47. 12
      src/Avalonia.Input/InputElement.cs
  48. 10
      src/Avalonia.Layout/FlowLayoutAlgorithm.cs
  49. 26
      src/Avalonia.Layout/StackLayout.cs
  50. 2
      src/Avalonia.Layout/StackLayoutState.cs
  51. 36
      src/Avalonia.Layout/UniformGridLayout.cs
  52. 5
      src/Avalonia.Native/PopupImpl.cs
  53. 26
      src/Avalonia.Native/WindowImpl.cs
  54. 24
      src/Avalonia.Remote.Protocol/DesignMessages.cs
  55. 12
      src/Avalonia.Styling/Styling/PropertySetterBindingInstance.cs
  56. 4
      src/Avalonia.Visuals/Media/BoxShadows.cs
  57. 8
      src/Avalonia.Visuals/Media/DrawingContext.cs
  58. 10
      src/Avalonia.Visuals/Media/DrawingImage.cs
  59. 44
      src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
  60. 26
      src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs
  61. 49
      src/Avalonia.Visuals/Rect.cs
  62. 2
      src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs
  63. 3
      src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs
  64. 5
      src/Avalonia.Visuals/Visual.cs
  65. 49
      src/Avalonia.X11/X11Window.cs
  66. 19
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  67. 73
      src/Skia/Avalonia.Skia/ImmutableBitmap.cs
  68. 42
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  69. 18
      src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs
  70. 24
      src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
  71. 66
      src/Windows/Avalonia.Direct2D1/Media/Imaging/WicBitmapImpl.cs
  72. 6
      src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs
  73. 29
      src/Windows/Avalonia.Win32/WindowImpl.cs
  74. 339
      tests/Avalonia.Animation.UnitTests/AnimatableTests.cs
  75. 4
      tests/Avalonia.Animation.UnitTests/TransitionsTests.cs
  76. 51
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_GetValue.cs
  77. 142
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_OnPropertyChanged.cs
  78. 39
      tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs
  79. 98
      tests/Avalonia.Base.UnitTests/PriorityValueTests.cs
  80. 16
      tests/Avalonia.Benchmarks/NullRenderingPlatform.cs
  81. 4
      tests/Avalonia.Controls.UnitTests/Shapes/PathTests.cs
  82. 5
      tests/Avalonia.Controls.UnitTests/WindowTests.cs
  83. 40
      tests/Avalonia.LeakTests/ControlTests.cs
  84. 6
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/InitializationOrderTracker.cs
  85. 45
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
  86. 8
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs
  87. 16
      tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs
  88. 19
      tests/Avalonia.Visuals.UnitTests/RectTests.cs
  89. 8
      tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests.cs
  90. 16
      tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs

2
Documentation/build.md

@ -36,7 +36,7 @@ Avalonia requires [CastXML](https://github.com/CastXML/CastXML) for XML processi
On macOS: On macOS:
``` ```
brew install castxml brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8a004a91a7fcd3f6620d5b01b6541ff0a640ffba/Formula/castxml.rb
``` ```
On Debian based Linux (Debian, Ubuntu, Mint, etc): On Debian based Linux (Debian, Ubuntu, Mint, etc):

5
native/Avalonia.Native/inc/avalonia-native.h

@ -267,7 +267,8 @@ AVNCOM(IAvnPopup, 03) : virtual IAvnWindowBase
AVNCOM(IAvnWindow, 04) : virtual IAvnWindowBase AVNCOM(IAvnWindow, 04) : virtual IAvnWindowBase
{ {
virtual HRESULT ShowDialog (IAvnWindow* parent) = 0; virtual HRESULT SetEnabled (bool enable) = 0;
virtual HRESULT SetParent (IAvnWindow* parent) = 0;
virtual HRESULT SetCanResize(bool value) = 0; virtual HRESULT SetCanResize(bool value) = 0;
virtual HRESULT SetDecorations(SystemDecorations value) = 0; virtual HRESULT SetDecorations(SystemDecorations value) = 0;
virtual HRESULT SetTitle (void* utf8Title) = 0; virtual HRESULT SetTitle (void* utf8Title) = 0;
@ -309,6 +310,8 @@ AVNCOM(IAvnWindowEvents, 06) : IAvnWindowBaseEvents
virtual bool Closing () = 0; virtual bool Closing () = 0;
virtual void WindowStateChanged (AvnWindowState state) = 0; virtual void WindowStateChanged (AvnWindowState state) = 0;
virtual void GotInputWhenDisabled () = 0;
}; };
AVNCOM(IAvnMacOptions, 07) : IUnknown AVNCOM(IAvnMacOptions, 07) : IUnknown

3
native/Avalonia.Native/src/OSX/window.h

@ -19,8 +19,7 @@ class WindowBaseImpl;
-(void) pollModalSession: (NSModalSession _Nonnull) session; -(void) pollModalSession: (NSModalSession _Nonnull) session;
-(void) restoreParentWindow; -(void) restoreParentWindow;
-(bool) shouldTryToHandleEvents; -(bool) shouldTryToHandleEvents;
-(bool) isModal; -(void) setEnabled: (bool) enable;
-(void) setModal: (bool) isModal;
-(void) showAppMenuOnly; -(void) showAppMenuOnly;
-(void) showWindowMenuWithAppMenu; -(void) showWindowMenuWithAppMenu;
-(void) applyMenu:(NSMenu* _Nullable)menu; -(void) applyMenu:(NSMenu* _Nullable)menu;

74
native/Avalonia.Native/src/OSX/window.mm

@ -497,12 +497,7 @@ private:
virtual HRESULT Show () override virtual HRESULT Show () override
{ {
@autoreleasepool @autoreleasepool
{ {
if([Window parentWindow] != nil)
[[Window parentWindow] removeChildWindow:Window];
[Window setModal:FALSE];
WindowBaseImpl::Show(); WindowBaseImpl::Show();
HideOrShowTrafficLights(); HideOrShowTrafficLights();
@ -511,7 +506,16 @@ private:
} }
} }
virtual HRESULT ShowDialog (IAvnWindow* parent) override virtual HRESULT SetEnabled (bool enable) override
{
@autoreleasepool
{
[Window setEnabled:enable];
return S_OK;
}
}
virtual HRESULT SetParent (IAvnWindow* parent) override
{ {
@autoreleasepool @autoreleasepool
{ {
@ -522,12 +526,9 @@ private:
if(cparent == nullptr) if(cparent == nullptr)
return E_INVALIDARG; return E_INVALIDARG;
[Window setModal:TRUE];
[cparent->Window addChildWindow:Window ordered:NSWindowAbove]; [cparent->Window addChildWindow:Window ordered:NSWindowAbove];
WindowBaseImpl::Show();
HideOrShowTrafficLights(); UpdateStyle();
return S_OK; return S_OK;
} }
@ -883,15 +884,15 @@ protected:
switch (_decorations) switch (_decorations)
{ {
case SystemDecorationsNone: case SystemDecorationsNone:
s = s | NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskMiniaturizable; s = s | NSWindowStyleMaskFullSizeContentView;
break; break;
case SystemDecorationsBorderOnly: case SystemDecorationsBorderOnly:
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskMiniaturizable; s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView;
break; break;
case SystemDecorationsFull: case SystemDecorationsFull:
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskBorderless; s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskBorderless;
if(_canResize) if(_canResize)
{ {
@ -900,6 +901,10 @@ protected:
break; break;
} }
if([Window parentWindow] == nullptr)
{
s |= NSWindowStyleMaskMiniaturizable;
}
return s; return s;
} }
}; };
@ -1081,15 +1086,28 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
- (bool) ignoreUserInput - (bool) ignoreUserInput
{ {
auto parentWindow = objc_cast<AvnWindow>([self window]); auto parentWindow = objc_cast<AvnWindow>([self window]);
if(parentWindow == nil || ![parentWindow shouldTryToHandleEvents]) if(parentWindow == nil || ![parentWindow shouldTryToHandleEvents])
{
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw());
if(window != nullptr)
{
window->WindowEvents->GotInputWhenDisabled();
}
return TRUE; return TRUE;
}
return FALSE; return FALSE;
} }
- (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type - (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type
{ {
if([self ignoreUserInput]) if([self ignoreUserInput])
{
return; return;
}
[self becomeFirstResponder]; [self becomeFirstResponder];
auto localPoint = [self convertPoint:[event locationInWindow] toView:self]; auto localPoint = [self convertPoint:[event locationInWindow] toView:self];
@ -1234,7 +1252,10 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
- (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type - (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type
{ {
if([self ignoreUserInput]) if([self ignoreUserInput])
{
return; return;
}
auto key = s_KeyMap[[event keyCode]]; auto key = s_KeyMap[[event keyCode]];
auto timestamp = [event timestamp] * 1000; auto timestamp = [event timestamp] * 1000;
@ -1416,7 +1437,7 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
ComPtr<WindowBaseImpl> _parent; ComPtr<WindowBaseImpl> _parent;
bool _canBecomeKeyAndMain; bool _canBecomeKeyAndMain;
bool _closed; bool _closed;
bool _isModal; bool _isEnabled;
AvnMenu* _menu; AvnMenu* _menu;
double _lastScaling; double _lastScaling;
} }
@ -1538,6 +1559,7 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
_parent = parent; _parent = parent;
[self setDelegate:self]; [self setDelegate:self];
_closed = false; _closed = false;
_isEnabled = true;
_lastScaling = [self backingScaleFactor]; _lastScaling = [self backingScaleFactor];
[self setOpaque:NO]; [self setOpaque:NO];
@ -1604,28 +1626,12 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
-(bool)shouldTryToHandleEvents -(bool)shouldTryToHandleEvents
{ {
for(NSWindow* uch in [self childWindows]) return _isEnabled;
{
auto ch = objc_cast<AvnWindow>(uch);
if(ch == nil)
continue;
if(![ch isModal])
continue;
return FALSE;
}
return TRUE;
}
-(bool) isModal
{
return _isModal;
} }
-(void) setModal: (bool) isModal -(void) setEnabled:(bool)enable
{ {
_isModal = isModal; _isEnabled = enable;
} }
-(void)makeKeyWindow -(void)makeKeyWindow

225
src/Avalonia.Animation/Animatable.cs

@ -1,10 +1,10 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Collections.Specialized;
using System.Reactive.Linq;
using Avalonia.Collections;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Animation.Animators;
#nullable enable
namespace Avalonia.Animation namespace Avalonia.Animation
{ {
@ -13,9 +13,24 @@ namespace Avalonia.Animation
/// </summary> /// </summary>
public class Animatable : AvaloniaObject public class Animatable : AvaloniaObject
{ {
/// <summary>
/// Defines the <see cref="Clock"/> property.
/// </summary>
public static readonly StyledProperty<IClock> ClockProperty = public static readonly StyledProperty<IClock> ClockProperty =
AvaloniaProperty.Register<Animatable, IClock>(nameof(Clock), inherits: true); AvaloniaProperty.Register<Animatable, IClock>(nameof(Clock), inherits: true);
/// <summary>
/// Defines the <see cref="Transitions"/> property.
/// </summary>
public static readonly StyledProperty<Transitions?> TransitionsProperty =
AvaloniaProperty.Register<Animatable, Transitions?>(nameof(Transitions));
private bool _transitionsEnabled = true;
private Dictionary<ITransition, TransitionState>? _transitionState;
/// <summary>
/// Gets or sets the clock which controls the animations on the control.
/// </summary>
public IClock Clock public IClock Clock
{ {
get => GetValue(ClockProperty); get => GetValue(ClockProperty);
@ -23,72 +38,194 @@ namespace Avalonia.Animation
} }
/// <summary> /// <summary>
/// Defines the <see cref="Transitions"/> property. /// Gets or sets the property transitions for the control.
/// </summary> /// </summary>
public static readonly DirectProperty<Animatable, Transitions> TransitionsProperty = public Transitions? Transitions
AvaloniaProperty.RegisterDirect<Animatable, Transitions>( {
nameof(Transitions), get => GetValue(TransitionsProperty);
o => o.Transitions, set => SetValue(TransitionsProperty, value);
(o, v) => o.Transitions = v); }
private Transitions _transitions; /// <summary>
/// Enables transitions for the control.
/// </summary>
/// <remarks>
/// This method should not be called from user code, it will be called automatically by the framework
/// when a control is added to the visual tree.
/// </remarks>
protected void EnableTransitions()
{
if (!_transitionsEnabled)
{
_transitionsEnabled = true;
private Dictionary<AvaloniaProperty, IDisposable> _previousTransitions; if (Transitions is object)
{
AddTransitions(Transitions);
}
}
}
/// <summary> /// <summary>
/// Gets or sets the property transitions for the control. /// Disables transitions for the control.
/// </summary> /// </summary>
public Transitions Transitions /// <remarks>
/// This method should not be called from user code, it will be called automatically by the framework
/// when a control is added to the visual tree.
/// </remarks>
protected void DisableTransitions()
{
if (_transitionsEnabled)
{
_transitionsEnabled = false;
if (Transitions is object)
{
RemoveTransitions(Transitions);
}
}
}
protected sealed override void OnPropertyChangedCore<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
get if (change.Property == TransitionsProperty && change.IsEffectiveValueChange)
{ {
if (_transitions is null) var oldTransitions = change.OldValue.GetValueOrDefault<Transitions>();
_transitions = new Transitions(); var newTransitions = change.NewValue.GetValueOrDefault<Transitions>();
if (_previousTransitions is null) if (oldTransitions is object)
_previousTransitions = new Dictionary<AvaloniaProperty, IDisposable>(); {
oldTransitions.CollectionChanged -= TransitionsCollectionChanged;
RemoveTransitions(oldTransitions);
}
return _transitions; if (newTransitions is object)
{
newTransitions.CollectionChanged += TransitionsCollectionChanged;
AddTransitions(newTransitions);
}
} }
set else if (_transitionsEnabled &&
Transitions is object &&
_transitionState is object &&
!change.Property.IsDirect &&
change.Priority > BindingPriority.Animation)
{ {
if (value is null) foreach (var transition in Transitions)
return; {
if (transition.Property == change.Property)
{
var state = _transitionState[transition];
var oldValue = state.BaseValue;
var newValue = GetAnimationBaseValue(transition.Property);
if (_previousTransitions is null) if (!Equals(oldValue, newValue))
_previousTransitions = new Dictionary<AvaloniaProperty, IDisposable>(); {
state.BaseValue = newValue;
SetAndRaise(TransitionsProperty, ref _transitions, value); // We need to transition from the current animated value if present,
// instead of the old base value.
var animatedValue = GetValue(transition.Property);
if (!Equals(newValue, animatedValue))
{
oldValue = animatedValue;
}
state.Instance?.Dispose();
state.Instance = transition.Apply(
this,
Clock ?? AvaloniaLocator.Current.GetService<IGlobalClock>(),
oldValue,
newValue);
return;
}
}
}
}
base.OnPropertyChangedCore(change);
}
private void TransitionsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (!_transitionsEnabled)
{
return;
}
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
AddTransitions(e.NewItems);
break;
case NotifyCollectionChangedAction.Remove:
RemoveTransitions(e.OldItems);
break;
case NotifyCollectionChangedAction.Replace:
RemoveTransitions(e.OldItems);
AddTransitions(e.NewItems);
break;
case NotifyCollectionChangedAction.Reset:
throw new NotSupportedException("Transitions collection cannot be reset.");
} }
} }
protected override void OnPropertyChanged<T>( private void AddTransitions(IList items)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
if (_transitions is null || _previousTransitions is null || priority == BindingPriority.Animation) if (!_transitionsEnabled)
{
return; return;
}
_transitionState ??= new Dictionary<ITransition, TransitionState>();
// PERF-SENSITIVE: Called on every property change. Don't use LINQ here (too many allocations). for (var i = 0; i < items.Count; ++i)
foreach (var transition in _transitions)
{ {
if (transition.Property == property) var t = (ITransition)items[i];
_transitionState.Add(t, new TransitionState
{ {
if (_previousTransitions.TryGetValue(property, out var dispose)) BaseValue = GetAnimationBaseValue(t.Property),
dispose.Dispose(); });
}
}
var instance = transition.Apply( private void RemoveTransitions(IList items)
this, {
Clock ?? Avalonia.Animation.Clock.GlobalClock, if (_transitionState is null)
oldValue.GetValueOrDefault(), {
newValue.GetValueOrDefault()); return;
}
_previousTransitions[property] = instance; for (var i = 0; i < items.Count; ++i)
return; {
var t = (ITransition)items[i];
if (_transitionState.TryGetValue(t, out var state))
{
state.Instance?.Dispose();
_transitionState.Remove(t);
} }
} }
} }
private object GetAnimationBaseValue(AvaloniaProperty property)
{
var value = this.GetBaseValue(property, BindingPriority.LocalValue);
if (value == AvaloniaProperty.UnsetValue)
{
value = GetValue(property);
}
return value;
}
private class TransitionState
{
public IDisposable? Instance { get; set; }
public object? BaseValue { get; set; }
}
} }
} }

2
src/Avalonia.Animation/TransitionInstance.cs

@ -19,6 +19,8 @@ namespace Avalonia.Animation
public TransitionInstance(IClock clock, TimeSpan Duration) public TransitionInstance(IClock clock, TimeSpan Duration)
{ {
clock = clock ?? throw new ArgumentNullException(nameof(clock));
_duration = Duration; _duration = Duration;
_baseClock = clock; _baseClock = clock;
} }

13
src/Avalonia.Animation/Transitions.cs

@ -1,4 +1,6 @@
using System;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Threading;
namespace Avalonia.Animation namespace Avalonia.Animation
{ {
@ -13,6 +15,17 @@ namespace Avalonia.Animation
public Transitions() public Transitions()
{ {
ResetBehavior = ResetBehavior.Remove; ResetBehavior = ResetBehavior.Remove;
Validate = ValidateTransition;
}
private void ValidateTransition(ITransition obj)
{
Dispatcher.UIThread.VerifyAccess();
if (obj.Property.IsDirect)
{
throw new InvalidOperationException("Cannot animate a direct property.");
}
} }
} }
} }

204
src/Avalonia.Base/AvaloniaObject.cs

@ -259,6 +259,21 @@ namespace Avalonia
return registered.InvokeGetter(this); return registered.InvokeGetter(this);
} }
/// <inheritdoc/>
public Optional<T> GetBaseValue<T>(StyledPropertyBase<T> property, BindingPriority maxPriority)
{
property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess();
if (_values is object &&
_values.TryGetValue(property, maxPriority, out var value))
{
return value;
}
return default;
}
/// <summary> /// <summary>
/// Checks whether a <see cref="AvaloniaProperty"/> is animating. /// Checks whether a <see cref="AvaloniaProperty"/> is animating.
/// </summary> /// </summary>
@ -458,29 +473,43 @@ namespace Avalonia
return _propertyChanged?.GetInvocationList(); return _propertyChanged?.GetInvocationList();
} }
void IValueSink.ValueChanged<T>( void IValueSink.ValueChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
StyledPropertyBase<T> property,
BindingPriority priority,
Optional<T> oldValue,
BindingValue<T> newValue)
{ {
oldValue = oldValue.HasValue ? oldValue : GetInheritedOrDefault(property); var property = (StyledPropertyBase<T>)change.Property;
newValue = newValue.HasValue ? newValue : newValue.WithValue(GetInheritedOrDefault(property));
LogIfError(property, newValue); LogIfError(property, change.NewValue);
if (!EqualityComparer<T>.Default.Equals(oldValue.Value, newValue.Value)) // If the change is to the effective value of the property and no old/new value is set
// then fill in the old/new value from property inheritance/default value. We don't do
// this for non-effective value changes because these are only needed for property
// transitions, where knowing e.g. that an inherited value is active at an arbitrary
// priority isn't of any use and would introduce overhead.
if (change.IsEffectiveValueChange && !change.OldValue.HasValue)
{ {
RaisePropertyChanged(property, oldValue, newValue, priority); change.SetOldValue(GetInheritedOrDefault<T>(property));
}
Logger.TryGet(LogEventLevel.Verbose)?.Log( if (change.IsEffectiveValueChange && !change.NewValue.HasValue)
LogArea.Property, {
this, change.SetNewValue(GetInheritedOrDefault(property));
"{Property} changed from {$Old} to {$Value} with priority {Priority}", }
property,
oldValue, if (!change.IsEffectiveValueChange ||
newValue, !EqualityComparer<T>.Default.Equals(change.OldValue.Value, change.NewValue.Value))
(BindingPriority)priority); {
RaisePropertyChanged(change);
if (change.IsEffectiveValueChange)
{
Logger.TryGet(LogEventLevel.Verbose)?.Log(
LogArea.Property,
this,
"{Property} changed from {$Old} to {$Value} with priority {Priority}",
property,
change.OldValue,
change.NewValue,
change.Priority);
}
} }
} }
@ -489,7 +518,13 @@ namespace Avalonia
IPriorityValueEntry entry, IPriorityValueEntry entry,
Optional<T> oldValue) Optional<T> oldValue)
{ {
((IValueSink)this).ValueChanged(property, BindingPriority.Unset, oldValue, default); var change = new AvaloniaPropertyChangedEventArgs<T>(
this,
property,
oldValue,
default,
BindingPriority.Unset);
((IValueSink)this).ValueChanged(change);
} }
/// <summary> /// <summary>
@ -575,15 +610,20 @@ namespace Avalonia
/// <summary> /// <summary>
/// Called when a avalonia property changes on the object. /// Called when a avalonia property changes on the object.
/// </summary> /// </summary>
/// <param name="property">The property whose value has changed.</param> /// <param name="change">The property change details.</param>
/// <param name="oldValue">The old value of the property.</param> protected virtual void OnPropertyChangedCore<T>(AvaloniaPropertyChangedEventArgs<T> change)
/// <param name="newValue">The new value of the property.</param> {
/// <param name="priority">The priority of the new value.</param> if (change.IsEffectiveValueChange)
protected virtual void OnPropertyChanged<T>( {
AvaloniaProperty<T> property, OnPropertyChanged(change);
Optional<T> oldValue, }
BindingValue<T> newValue, }
BindingPriority priority)
/// <summary>
/// Called when a avalonia property changes on the object.
/// </summary>
/// <param name="change">The property change details.</param>
protected virtual void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
} }
@ -600,57 +640,12 @@ namespace Avalonia
BindingValue<T> newValue, BindingValue<T> newValue,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property)); RaisePropertyChanged(new AvaloniaPropertyChangedEventArgs<T>(
this,
VerifyAccess(); property,
oldValue,
property.Notifying?.Invoke(this, true); newValue,
priority));
try
{
AvaloniaPropertyChangedEventArgs<T> e = null;
var hasChanged = property.HasChangedSubscriptions;
if (hasChanged || _propertyChanged != null)
{
e = new AvaloniaPropertyChangedEventArgs<T>(
this,
property,
oldValue,
newValue,
priority);
}
OnPropertyChanged(property, oldValue, newValue, priority);
if (hasChanged)
{
property.NotifyChanged(e);
}
_propertyChanged?.Invoke(this, e);
if (_inpcChanged != null)
{
var inpce = new PropertyChangedEventArgs(property.Name);
_inpcChanged(this, inpce);
}
if (property.Inherits && _inheritanceChildren != null)
{
foreach (var child in _inheritanceChildren)
{
child.InheritedPropertyChanged(
property,
oldValue,
newValue.ToOptional());
}
}
}
finally
{
property.Notifying?.Invoke(this, false);
}
} }
/// <summary> /// <summary>
@ -689,7 +684,9 @@ namespace Avalonia
return property.GetDefaultValue(GetType()); return property.GetDefaultValue(GetType());
} }
private T GetValueOrInheritedOrDefault<T>(StyledPropertyBase<T> property) private T GetValueOrInheritedOrDefault<T>(
StyledPropertyBase<T> property,
BindingPriority maxPriority = BindingPriority.Animation)
{ {
var o = this; var o = this;
var inherits = property.Inherits; var inherits = property.Inherits;
@ -699,7 +696,7 @@ namespace Avalonia
{ {
var values = o._values; var values = o._values;
if (values?.TryGetValue(property, out value) == true) if (values?.TryGetValue(property, maxPriority, out value) == true)
{ {
return value; return value;
} }
@ -715,6 +712,51 @@ namespace Avalonia
return property.GetDefaultValue(GetType()); return property.GetDefaultValue(GetType());
} }
protected internal void RaisePropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
VerifyAccess();
if (change.IsEffectiveValueChange)
{
change.Property.Notifying?.Invoke(this, true);
}
try
{
OnPropertyChangedCore(change);
if (change.IsEffectiveValueChange)
{
change.Property.NotifyChanged(change);
_propertyChanged?.Invoke(this, change);
if (_inpcChanged != null)
{
var inpce = new PropertyChangedEventArgs(change.Property.Name);
_inpcChanged(this, inpce);
}
if (change.Property.Inherits && _inheritanceChildren != null)
{
foreach (var child in _inheritanceChildren)
{
child.InheritedPropertyChanged(
change.Property,
change.OldValue,
change.NewValue.ToOptional());
}
}
}
}
finally
{
if (change.IsEffectiveValueChange)
{
change.Property.Notifying?.Invoke(this, false);
}
}
}
/// <summary> /// <summary>
/// Sets the value of a direct property. /// Sets the value of a direct property.
/// </summary> /// </summary>

59
src/Avalonia.Base/AvaloniaObjectExtensions.cs

@ -448,6 +448,65 @@ namespace Avalonia
}; };
} }
/// <summary>
/// Gets an <see cref="AvaloniaProperty"/> base value.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <param name="maxPriority">The maximum priority for the value.</param>
/// <remarks>
/// For styled properties, gets the value of the property if set on the object with a
/// priority equal or lower to <paramref name="maxPriority"/>, otherwise
/// <see cref="AvaloniaProperty.UnsetValue"/>. Note that this method does not return
/// property values that come from inherited or default values.
///
/// For direct properties returns <see cref="GetValue(IAvaloniaObject, AvaloniaProperty)"/>.
/// </remarks>
public static object GetBaseValue(
this IAvaloniaObject target,
AvaloniaProperty property,
BindingPriority maxPriority)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
return property.RouteGetBaseValue(target, maxPriority);
}
/// <summary>
/// Gets an <see cref="AvaloniaProperty"/> base value.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <param name="maxPriority">The maximum priority for the value.</param>
/// <remarks>
/// For styled properties, gets the value of the property if set on the object with a
/// priority equal or lower to <paramref name="maxPriority"/>, otherwise
/// <see cref="Optional{T}.Empty"/>. Note that this method does not return property values
/// that come from inherited or default values.
///
/// For direct properties returns
/// <see cref="IAvaloniaObject.GetValue{T}(DirectPropertyBase{T})"/>.
/// </remarks>
public static Optional<T> GetBaseValue<T>(
this IAvaloniaObject target,
AvaloniaProperty<T> property,
BindingPriority maxPriority)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
return property switch
{
StyledPropertyBase<T> styled => target.GetBaseValue(styled, maxPriority),
DirectPropertyBase<T> direct => target.GetValue(direct),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
};
}
/// <summary> /// <summary>
/// Sets a <see cref="AvaloniaProperty"/> value. /// Sets a <see cref="AvaloniaProperty"/> value.
/// </summary> /// </summary>

7
src/Avalonia.Base/AvaloniaProperty.cs

@ -496,6 +496,13 @@ namespace Avalonia
/// <param name="o">The object instance.</param> /// <param name="o">The object instance.</param>
internal abstract object RouteGetValue(IAvaloniaObject o); internal abstract object RouteGetValue(IAvaloniaObject o);
/// <summary>
/// Routes an untyped GetBaseValue call to a typed call.
/// </summary>
/// <param name="o">The object instance.</param>
/// <param name="maxPriority">The maximum priority for the value.</param>
internal abstract object RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority);
/// <summary> /// <summary>
/// Routes an untyped SetValue call to a typed call. /// Routes an untyped SetValue call to a typed call.
/// </summary> /// </summary>

23
src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs

@ -16,6 +16,7 @@ namespace Avalonia
{ {
Sender = sender; Sender = sender;
Priority = priority; Priority = priority;
IsEffectiveValueChange = true;
} }
/// <summary> /// <summary>
@ -35,19 +36,11 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets the old value of the property. /// Gets the old value of the property.
/// </summary> /// </summary>
/// <value>
/// The old value of the property or <see cref="AvaloniaProperty.UnsetValue"/> if the
/// property previously had no value.
/// </value>
public object? OldValue => GetOldValue(); public object? OldValue => GetOldValue();
/// <summary> /// <summary>
/// Gets the new value of the property. /// Gets the new value of the property.
/// </summary> /// </summary>
/// <value>
/// The new value of the property or <see cref="AvaloniaProperty.UnsetValue"/> if the
/// property previously had no value.
/// </value>
public object? NewValue => GetNewValue(); public object? NewValue => GetNewValue();
/// <summary> /// <summary>
@ -58,6 +51,20 @@ namespace Avalonia
/// </value> /// </value>
public BindingPriority Priority { get; private set; } public BindingPriority Priority { get; private set; }
/// <summary>
/// Gets a value indicating whether the change represents a change to the effective value of
/// the property.
/// </summary>
/// <remarks>
/// This will usually be true, except in
/// <see cref="AvaloniaObject.OnPropertyChangedCore{T}(AvaloniaPropertyChangedEventArgs{T})"/>
/// which recieves notifications for all changes to property values, whether a value with a higher
/// priority is present or not. When this property is false, the change that is being signalled
/// has not resulted in a change to the property value on the object.
/// </remarks>
public bool IsEffectiveValueChange { get; private set; }
internal void MarkNonEffectiveValue() => IsEffectiveValueChange = false;
protected abstract AvaloniaProperty GetProperty(); protected abstract AvaloniaProperty GetProperty();
protected abstract object? GetOldValue(); protected abstract object? GetOldValue();
protected abstract object? GetNewValue(); protected abstract object? GetNewValue();

24
src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs

@ -1,4 +1,3 @@
using System;
using Avalonia.Data; using Avalonia.Data;
#nullable enable #nullable enable
@ -6,7 +5,7 @@ using Avalonia.Data;
namespace Avalonia namespace Avalonia
{ {
/// <summary> /// <summary>
/// Provides information for a avalonia property change. /// Provides information for an Avalonia property change.
/// </summary> /// </summary>
public class AvaloniaPropertyChangedEventArgs<T> : AvaloniaPropertyChangedEventArgs public class AvaloniaPropertyChangedEventArgs<T> : AvaloniaPropertyChangedEventArgs
{ {
@ -42,19 +41,28 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets the old value of the property. /// Gets the old value of the property.
/// </summary> /// </summary>
/// <value> /// <remarks>
/// The old value of the property. /// When <see cref="AvaloniaPropertyChangedEventArgs.IsEffectiveValueChange"/> is true, returns the
/// </value> /// old value of the property on the object.
/// When <see cref="AvaloniaPropertyChangedEventArgs.IsEffectiveValueChange"/> is false, returns
/// <see cref="Optional{T}.Empty"/>.
/// </remarks>
public new Optional<T> OldValue { get; private set; } public new Optional<T> OldValue { get; private set; }
/// <summary> /// <summary>
/// Gets the new value of the property. /// Gets the new value of the property.
/// </summary> /// </summary>
/// <value> /// <remarks>
/// The new value of the property. /// When <see cref="AvaloniaPropertyChangedEventArgs.IsEffectiveValueChange"/> is true, returns the
/// </value> /// value of the property on the object.
/// When <see cref="AvaloniaPropertyChangedEventArgs.IsEffectiveValueChange"/> is false returns the
/// changed value, or <see cref="Optional{T}.Empty"/> if the value was removed.
/// </remarks>
public new BindingValue<T> NewValue { get; private set; } public new BindingValue<T> NewValue { get; private set; }
internal void SetOldValue(Optional<T> value) => OldValue = value;
internal void SetNewValue(BindingValue<T> value) => NewValue = value;
protected override AvaloniaProperty GetProperty() => Property; protected override AvaloniaProperty GetProperty() => Property;
protected override object? GetOldValue() => OldValue.GetValueOrDefault(AvaloniaProperty.UnsetValue); protected override object? GetOldValue() => OldValue.GetValueOrDefault(AvaloniaProperty.UnsetValue);

4
src/Avalonia.Base/Data/BindingValue.cs

@ -348,8 +348,8 @@ namespace Avalonia.Data
return new BindingValue<T>( return new BindingValue<T>(
fallbackValue.HasValue ? fallbackValue.HasValue ?
BindingValueType.DataValidationError : BindingValueType.DataValidationErrorWithFallback :
BindingValueType.DataValidationErrorWithFallback, BindingValueType.DataValidationError,
fallbackValue.HasValue ? fallbackValue.Value : default, fallbackValue.HasValue ? fallbackValue.Value : default,
e); e);
} }

5
src/Avalonia.Base/DirectPropertyBase.cs

@ -120,6 +120,11 @@ namespace Avalonia
return o.GetValue<TValue>(this); return o.GetValue<TValue>(this);
} }
internal override object RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority)
{
return o.GetValue<TValue>(this);
}
/// <inheritdoc/> /// <inheritdoc/>
internal override IDisposable? RouteSetValue( internal override IDisposable? RouteSetValue(
IAvaloniaObject o, IAvaloniaObject o,

13
src/Avalonia.Base/IAvaloniaObject.cs

@ -41,6 +41,19 @@ namespace Avalonia
/// <returns>The value.</returns> /// <returns>The value.</returns>
T GetValue<T>(DirectPropertyBase<T> property); T GetValue<T>(DirectPropertyBase<T> property);
/// <summary>
/// Gets an <see cref="AvaloniaProperty"/> base value.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <param name="maxPriority">The maximum priority for the value.</param>
/// <remarks>
/// Gets the value of the property, if set on this object with a priority equal or lower to
/// <paramref name="maxPriority"/>, otherwise <see cref="Optional{T}.Empty"/>. Note that
/// this method does not return property values that come from inherited or default values.
/// </remarks>
Optional<T> GetBaseValue<T>(StyledPropertyBase<T> property, BindingPriority maxPriority);
/// <summary> /// <summary>
/// Checks whether a <see cref="AvaloniaProperty"/> is animating. /// Checks whether a <see cref="AvaloniaProperty"/> is animating.
/// </summary> /// </summary>

20
src/Avalonia.Base/PropertyStore/BindingEntry.cs

@ -22,6 +22,7 @@ namespace Avalonia.PropertyStore
private readonly IAvaloniaObject _owner; private readonly IAvaloniaObject _owner;
private IValueSink _sink; private IValueSink _sink;
private IDisposable? _subscription; private IDisposable? _subscription;
private Optional<T> _value;
public BindingEntry( public BindingEntry(
IAvaloniaObject owner, IAvaloniaObject owner,
@ -40,18 +41,21 @@ namespace Avalonia.PropertyStore
public StyledPropertyBase<T> Property { get; } public StyledPropertyBase<T> Property { get; }
public BindingPriority Priority { get; } public BindingPriority Priority { get; }
public IObservable<BindingValue<T>> Source { get; } public IObservable<BindingValue<T>> Source { get; }
public Optional<T> Value { get; private set; } Optional<object> IValue.GetValue() => _value.ToObject();
Optional<object> IValue.Value => Value.ToObject();
BindingPriority IValue.ValuePriority => Priority; public Optional<T> GetValue(BindingPriority maxPriority)
{
return Priority >= maxPriority ? _value : Optional<T>.Empty;
}
public void Dispose() public void Dispose()
{ {
_subscription?.Dispose(); _subscription?.Dispose();
_subscription = null; _subscription = null;
_sink.Completed(Property, this, Value); _sink.Completed(Property, this, _value);
} }
public void OnCompleted() => _sink.Completed(Property, this, Value); public void OnCompleted() => _sink.Completed(Property, this, _value);
public void OnError(Exception error) public void OnError(Exception error)
{ {
@ -94,14 +98,14 @@ namespace Avalonia.PropertyStore
return; return;
} }
var old = Value; var old = _value;
if (value.Type != BindingValueType.DataValidationError) if (value.Type != BindingValueType.DataValidationError)
{ {
Value = value.ToOptional(); _value = value.ToOptional();
} }
_sink.ValueChanged(Property, Priority, old, value); _sink.ValueChanged(new AvaloniaPropertyChangedEventArgs<T>(_owner, Property, old, value, Priority));
} }
} }
} }

14
src/Avalonia.Base/PropertyStore/ConstantValueEntry.cs

@ -13,6 +13,7 @@ namespace Avalonia.PropertyStore
internal class ConstantValueEntry<T> : IPriorityValueEntry<T>, IDisposable internal class ConstantValueEntry<T> : IPriorityValueEntry<T>, IDisposable
{ {
private IValueSink _sink; private IValueSink _sink;
private Optional<T> _value;
public ConstantValueEntry( public ConstantValueEntry(
StyledPropertyBase<T> property, StyledPropertyBase<T> property,
@ -21,18 +22,21 @@ namespace Avalonia.PropertyStore
IValueSink sink) IValueSink sink)
{ {
Property = property; Property = property;
Value = value; _value = value;
Priority = priority; Priority = priority;
_sink = sink; _sink = sink;
} }
public StyledPropertyBase<T> Property { get; } public StyledPropertyBase<T> Property { get; }
public BindingPriority Priority { get; } public BindingPriority Priority { get; }
public Optional<T> Value { get; } Optional<object> IValue.GetValue() => _value.ToObject();
Optional<object> IValue.Value => Value.ToObject();
BindingPriority IValue.ValuePriority => Priority;
public void Dispose() => _sink.Completed(Property, this, Value); public Optional<T> GetValue(BindingPriority maxPriority = BindingPriority.Animation)
{
return Priority >= maxPriority ? _value : Optional<T>.Empty;
}
public void Dispose() => _sink.Completed(Property, this, _value);
public void Reparent(IValueSink sink) => _sink = sink; public void Reparent(IValueSink sink) => _sink = sink;
} }
} }

6
src/Avalonia.Base/PropertyStore/IValue.cs

@ -9,8 +9,8 @@ namespace Avalonia.PropertyStore
/// </summary> /// </summary>
internal interface IValue internal interface IValue
{ {
Optional<object> Value { get; } Optional<object> GetValue();
BindingPriority ValuePriority { get; } BindingPriority Priority { get; }
} }
/// <summary> /// <summary>
@ -19,6 +19,6 @@ namespace Avalonia.PropertyStore
/// <typeparam name="T">The property type.</typeparam> /// <typeparam name="T">The property type.</typeparam>
internal interface IValue<T> : IValue internal interface IValue<T> : IValue
{ {
new Optional<T> Value { get; } Optional<T> GetValue(BindingPriority maxPriority = BindingPriority.Animation);
} }
} }

6
src/Avalonia.Base/PropertyStore/IValueSink.cs

@ -9,11 +9,7 @@ namespace Avalonia.PropertyStore
/// </summary> /// </summary>
internal interface IValueSink internal interface IValueSink
{ {
void ValueChanged<T>( void ValueChanged<T>(AvaloniaPropertyChangedEventArgs<T> change);
StyledPropertyBase<T> property,
BindingPriority priority,
Optional<T> oldValue,
BindingValue<T> newValue);
void Completed<T>( void Completed<T>(
StyledPropertyBase<T> property, StyledPropertyBase<T> property,

11
src/Avalonia.Base/PropertyStore/LocalValueEntry.cs

@ -14,9 +14,14 @@ namespace Avalonia.PropertyStore
private T _value; private T _value;
public LocalValueEntry(T value) => _value = value; public LocalValueEntry(T value) => _value = value;
public Optional<T> Value => _value; public BindingPriority Priority => BindingPriority.LocalValue;
public BindingPriority ValuePriority => BindingPriority.LocalValue; Optional<object> IValue.GetValue() => new Optional<object>(_value);
Optional<object> IValue.Value => Value.ToObject();
public Optional<T> GetValue(BindingPriority maxPriority)
{
return BindingPriority.LocalValue >= maxPriority ? _value : Optional<T>.Empty;
}
public void SetValue(T value) => _value = value; public void SetValue(T value) => _value = value;
} }
} }

161
src/Avalonia.Base/PropertyStore/PriorityValue.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using Avalonia.Data; using Avalonia.Data;
#nullable enable #nullable enable
@ -24,6 +25,7 @@ namespace Avalonia.PropertyStore
private readonly List<IPriorityValueEntry<T>> _entries = new List<IPriorityValueEntry<T>>(); private readonly List<IPriorityValueEntry<T>> _entries = new List<IPriorityValueEntry<T>>();
private readonly Func<IAvaloniaObject, T, T>? _coerceValue; private readonly Func<IAvaloniaObject, T, T>? _coerceValue;
private Optional<T> _localValue; private Optional<T> _localValue;
private Optional<T> _value;
public PriorityValue( public PriorityValue(
IAvaloniaObject owner, IAvaloniaObject owner,
@ -50,11 +52,13 @@ namespace Avalonia.PropertyStore
{ {
existing.Reparent(this); existing.Reparent(this);
_entries.Add(existing); _entries.Add(existing);
var v = existing.GetValue();
if (existing.Value.HasValue) if (v.HasValue)
{ {
Value = existing.Value; _value = v;
ValuePriority = existing.Priority; Priority = existing.Priority;
} }
} }
@ -65,18 +69,39 @@ namespace Avalonia.PropertyStore
LocalValueEntry<T> existing) LocalValueEntry<T> existing)
: this(owner, property, sink) : this(owner, property, sink)
{ {
_localValue = existing.Value; _value = _localValue = existing.GetValue(BindingPriority.LocalValue);
Value = _localValue; Priority = BindingPriority.LocalValue;
ValuePriority = BindingPriority.LocalValue;
} }
public StyledPropertyBase<T> Property { get; } public StyledPropertyBase<T> Property { get; }
public Optional<T> Value { get; private set; } public BindingPriority Priority { get; private set; } = BindingPriority.Unset;
public BindingPriority ValuePriority { get; private set; }
public IReadOnlyList<IPriorityValueEntry<T>> Entries => _entries; public IReadOnlyList<IPriorityValueEntry<T>> Entries => _entries;
Optional<object> IValue.Value => Value.ToObject(); Optional<object> IValue.GetValue() => _value.ToObject();
public void ClearLocalValue()
{
UpdateEffectiveValue(new AvaloniaPropertyChangedEventArgs<T>(
_owner,
Property,
default,
default,
BindingPriority.LocalValue));
}
public Optional<T> GetValue(BindingPriority maxPriority = BindingPriority.Animation)
{
if (Priority == BindingPriority.Unset)
{
return default;
}
public void ClearLocalValue() => UpdateEffectiveValue(); if (Priority >= maxPriority)
{
return _value;
}
return CalculateValue(maxPriority).Item1;
}
public IDisposable? SetValue(T value, BindingPriority priority) public IDisposable? SetValue(T value, BindingPriority priority)
{ {
@ -94,7 +119,13 @@ namespace Avalonia.PropertyStore
result = entry; result = entry;
} }
UpdateEffectiveValue(); UpdateEffectiveValue(new AvaloniaPropertyChangedEventArgs<T>(
_owner,
Property,
default,
value,
priority));
return result; return result;
} }
@ -106,20 +137,19 @@ namespace Avalonia.PropertyStore
return binding; return binding;
} }
public void CoerceValue() => UpdateEffectiveValue(); public void CoerceValue() => UpdateEffectiveValue(null);
void IValueSink.ValueChanged<TValue>( void IValueSink.ValueChanged<TValue>(AvaloniaPropertyChangedEventArgs<TValue> change)
StyledPropertyBase<TValue> property,
BindingPriority priority,
Optional<TValue> oldValue,
BindingValue<TValue> newValue)
{ {
if (priority == BindingPriority.LocalValue) if (change.Priority == BindingPriority.LocalValue)
{ {
_localValue = default; _localValue = default;
} }
UpdateEffectiveValue(); if (change is AvaloniaPropertyChangedEventArgs<T> c)
{
UpdateEffectiveValue(c);
}
} }
void IValueSink.Completed<TValue>( void IValueSink.Completed<TValue>(
@ -128,7 +158,16 @@ namespace Avalonia.PropertyStore
Optional<TValue> oldValue) Optional<TValue> oldValue)
{ {
_entries.Remove((IPriorityValueEntry<T>)entry); _entries.Remove((IPriorityValueEntry<T>)entry);
UpdateEffectiveValue();
if (oldValue is Optional<T> o)
{
UpdateEffectiveValue(new AvaloniaPropertyChangedEventArgs<T>(
_owner,
Property,
o,
default,
entry.Priority));
}
} }
private int FindInsertPoint(BindingPriority priority) private int FindInsertPoint(BindingPriority priority)
@ -147,53 +186,73 @@ namespace Avalonia.PropertyStore
return result; return result;
} }
private void UpdateEffectiveValue() public (Optional<T>, BindingPriority) CalculateValue(BindingPriority maxPriority)
{ {
var reachedLocalValues = false; var reachedLocalValues = false;
var value = default(Optional<T>);
if (_entries.Count > 0) for (var i = _entries.Count - 1; i >= 0; --i)
{ {
for (var i = _entries.Count - 1; i >= 0; --i) var entry = _entries[i];
if (entry.Priority < maxPriority)
{
continue;
}
if (!reachedLocalValues &&
entry.Priority >= BindingPriority.LocalValue &&
maxPriority <= BindingPriority.LocalValue &&
_localValue.HasValue)
{
return (_localValue, BindingPriority.LocalValue);
}
var entryValue = entry.GetValue();
if (entryValue.HasValue)
{ {
var entry = _entries[i]; return (entryValue, entry.Priority);
if (!reachedLocalValues && entry.Priority >= BindingPriority.LocalValue)
{
reachedLocalValues = true;
if (_localValue.HasValue)
{
value = _localValue;
ValuePriority = BindingPriority.LocalValue;
break;
}
}
if (entry.Value.HasValue)
{
value = entry.Value;
ValuePriority = entry.Priority;
break;
}
} }
} }
else if (_localValue.HasValue)
if (!reachedLocalValues &&
maxPriority <= BindingPriority.LocalValue &&
_localValue.HasValue)
{ {
value = _localValue; return (_localValue, BindingPriority.LocalValue);
ValuePriority = BindingPriority.LocalValue;
} }
return (default, BindingPriority.Unset);
}
private void UpdateEffectiveValue(AvaloniaPropertyChangedEventArgs<T>? change)
{
var (value, priority) = CalculateValue(BindingPriority.Animation);
if (value.HasValue && _coerceValue != null) if (value.HasValue && _coerceValue != null)
{ {
value = _coerceValue(_owner, value.Value); value = _coerceValue(_owner, value.Value);
} }
if (value != Value) Priority = priority;
if (value != _value)
{
var old = _value;
_value = value;
_sink.ValueChanged(new AvaloniaPropertyChangedEventArgs<T>(
_owner,
Property,
old,
value,
Priority));
}
else if (change is object)
{ {
var old = Value; change.MarkNonEffectiveValue();
Value = value; change.SetOldValue(default);
_sink.ValueChanged(Property, ValuePriority, old, value); _sink.ValueChanged(change);
} }
} }
} }

7
src/Avalonia.Base/StyledPropertyBase.cs

@ -197,6 +197,13 @@ namespace Avalonia
return o.GetValue<TValue>(this); return o.GetValue<TValue>(this);
} }
/// <inheritdoc/>
internal override object RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority)
{
var value = o.GetBaseValue<TValue>(this, maxPriority);
return value.HasValue ? value.Value : AvaloniaProperty.UnsetValue;
}
/// <inheritdoc/> /// <inheritdoc/>
internal override IDisposable RouteSetValue( internal override IDisposable RouteSetValue(
IAvaloniaObject o, IAvaloniaObject o,

69
src/Avalonia.Base/ValueStore.cs

@ -37,7 +37,7 @@ namespace Avalonia
{ {
if (_values.TryGetValue(property, out var slot)) if (_values.TryGetValue(property, out var slot))
{ {
return slot.ValuePriority < BindingPriority.LocalValue; return slot.Priority < BindingPriority.LocalValue;
} }
return false; return false;
@ -47,21 +47,24 @@ namespace Avalonia
{ {
if (_values.TryGetValue(property, out var slot)) if (_values.TryGetValue(property, out var slot))
{ {
return slot.Value.HasValue; return slot.GetValue().HasValue;
} }
return false; return false;
} }
public bool TryGetValue<T>(StyledPropertyBase<T> property, out T value) public bool TryGetValue<T>(
StyledPropertyBase<T> property,
BindingPriority maxPriority,
out T value)
{ {
if (_values.TryGetValue(property, out var slot)) if (_values.TryGetValue(property, out var slot))
{ {
var v = (IValue<T>)slot; var v = ((IValue<T>)slot).GetValue(maxPriority);
if (v.Value.HasValue) if (v.HasValue)
{ {
value = v.Value.Value; value = v.Value;
return true; return true;
} }
} }
@ -90,17 +93,22 @@ namespace Avalonia
_values.AddValue(property, entry); _values.AddValue(property, entry);
result = entry.SetValue(value, priority); result = entry.SetValue(value, priority);
} }
else if (priority == BindingPriority.LocalValue)
{
_values.AddValue(property, new LocalValueEntry<T>(value));
_sink.ValueChanged(property, priority, default, value);
}
else else
{ {
var entry = new ConstantValueEntry<T>(property, value, priority, this); var change = new AvaloniaPropertyChangedEventArgs<T>(_owner, property, default, value, priority);
_values.AddValue(property, entry);
_sink.ValueChanged(property, priority, default, value); if (priority == BindingPriority.LocalValue)
result = entry; {
_values.AddValue(property, new LocalValueEntry<T>(value));
_sink.ValueChanged(change);
}
else
{
var entry = new ConstantValueEntry<T>(property, value, priority, this);
_values.AddValue(property, entry);
_sink.ValueChanged(change);
result = entry;
}
} }
return result; return result;
@ -149,13 +157,14 @@ namespace Avalonia
if (remove) if (remove)
{ {
var old = TryGetValue(property, out var value) ? value : default; var old = TryGetValue(property, BindingPriority.LocalValue, out var value) ? value : default;
_values.Remove(property); _values.Remove(property);
_sink.ValueChanged( _sink.ValueChanged(new AvaloniaPropertyChangedEventArgs<T>(
_owner,
property, property,
BindingPriority.Unset,
old, old,
BindingValue<T>.Unset); default,
BindingPriority.Unset));
} }
} }
} }
@ -176,23 +185,20 @@ namespace Avalonia
{ {
if (_values.TryGetValue(property, out var slot)) if (_values.TryGetValue(property, out var slot))
{ {
var slotValue = slot.GetValue();
return new Diagnostics.AvaloniaPropertyValue( return new Diagnostics.AvaloniaPropertyValue(
property, property,
slot.Value.HasValue ? slot.Value.Value : AvaloniaProperty.UnsetValue, slotValue.HasValue ? slotValue.Value : AvaloniaProperty.UnsetValue,
slot.ValuePriority, slot.Priority,
null); null);
} }
return null; return null;
} }
void IValueSink.ValueChanged<T>( void IValueSink.ValueChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
StyledPropertyBase<T> property,
BindingPriority priority,
Optional<T> oldValue,
BindingValue<T> newValue)
{ {
_sink.ValueChanged(property, priority, oldValue, newValue); _sink.ValueChanged(change);
} }
void IValueSink.Completed<T>( void IValueSink.Completed<T>(
@ -232,9 +238,14 @@ namespace Avalonia
{ {
if (priority == BindingPriority.LocalValue) if (priority == BindingPriority.LocalValue)
{ {
var old = l.Value; var old = l.GetValue(BindingPriority.LocalValue);
l.SetValue(value); l.SetValue(value);
_sink.ValueChanged(property, priority, old, value); _sink.ValueChanged(new AvaloniaPropertyChangedEventArgs<T>(
_owner,
property,
old,
value,
priority));
} }
else else
{ {

5
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -1,5 +1,4 @@
// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL).
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved. // All other rights reserved.
@ -767,7 +766,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// ItemsProperty property changed handler. /// ItemsProperty property changed handler.
/// </summary> /// </summary>
/// <param name="e">AvaloniaPropertyChangedEventArgs.</param> /// <param name="e">The event arguments.</param>
private void OnItemsPropertyChanged(AvaloniaPropertyChangedEventArgs e) private void OnItemsPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{ {
if (!_areHandlersSuspended) if (!_areHandlersSuspended)

12
src/Avalonia.Controls/Button.cs

@ -313,17 +313,13 @@ namespace Avalonia.Controls
IsPressed = false; IsPressed = false;
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == IsPressedProperty) if (change.Property == IsPressedProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<bool>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<bool>());
} }
} }

12
src/Avalonia.Controls/ButtonSpinner.cs

@ -205,17 +205,13 @@ namespace Avalonia.Controls
} }
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == ButtonSpinnerLocationProperty) if (change.Property == ButtonSpinnerLocationProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<Location>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<Location>());
} }
} }

12
src/Avalonia.Controls/Calendar/DatePicker.cs

@ -510,17 +510,13 @@ namespace Avalonia.Controls
} }
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == SelectedDateProperty) if (change.Property == SelectedDateProperty)
{ {
DataValidationErrors.SetError(this, newValue.Error); DataValidationErrors.SetError(this, change.NewValue.Error);
} }
} }

12
src/Avalonia.Controls/Expander.cs

@ -78,17 +78,13 @@ namespace Avalonia.Controls
} }
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == ExpandDirectionProperty) if (change.Property == ExpandDirectionProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<ExpandDirection>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<ExpandDirection>());
} }
} }

12
src/Avalonia.Controls/Notifications/WindowNotificationManager.cs

@ -136,17 +136,13 @@ namespace Avalonia.Controls.Notifications
notificationControl.Close(); notificationControl.Close();
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == PositionProperty) if (change.Property == PositionProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<NotificationPosition>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<NotificationPosition>());
} }
} }

16
src/Avalonia.Controls/Platform/IWindowImpl.cs

@ -26,9 +26,21 @@ namespace Avalonia.Platform
void SetTitle(string title); void SetTitle(string title);
/// <summary> /// <summary>
/// Shows the window as a dialog. /// Sets the parent of the window.
/// </summary> /// </summary>
void ShowDialog(IWindowImpl parent); /// <param name="parent">The parent <see cref="IWindowImpl"/>.</param>
void SetParent(IWindowImpl parent);
/// <summary>
/// Disables the window for example when a modal dialog is open.
/// </summary>
/// <param name="enable">true if the window is enabled, or false if it is disabled.</param>
void SetEnabled(bool enable);
/// <summary>
/// Called when a disabled window received input. Can be used to activate child windows.
/// </summary>
Action GotInputWhenDisabled { get; set; }
/// <summary> /// <summary>
/// Enables or disables system window decorations (title bar, buttons, etc) /// Enables or disables system window decorations (title bar, buttons, etc)

15
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -75,6 +75,9 @@ namespace Avalonia.Controls.Presenters
static TextPresenter() static TextPresenter()
{ {
AffectsRender<TextPresenter>(SelectionBrushProperty); AffectsRender<TextPresenter>(SelectionBrushProperty);
AffectsMeasure<TextPresenter>(TextProperty, PasswordCharProperty,
TextAlignmentProperty, TextWrappingProperty, TextBlock.FontSizeProperty,
TextBlock.FontStyleProperty, TextBlock.FontWeightProperty, TextBlock.FontFamilyProperty);
Observable.Merge(TextProperty.Changed, TextBlock.ForegroundProperty.Changed, Observable.Merge(TextProperty.Changed, TextBlock.ForegroundProperty.Changed,
TextAlignmentProperty.Changed, TextWrappingProperty.Changed, TextAlignmentProperty.Changed, TextWrappingProperty.Changed,
@ -284,8 +287,6 @@ namespace Avalonia.Controls.Presenters
protected void InvalidateFormattedText() protected void InvalidateFormattedText()
{ {
_formattedText = null; _formattedText = null;
InvalidateMeasure();
} }
/// <summary> /// <summary>
@ -301,13 +302,15 @@ namespace Avalonia.Controls.Presenters
context.FillRectangle(background, new Rect(Bounds.Size)); context.FillRectangle(background, new Rect(Bounds.Size));
} }
FormattedText.Constraint = Bounds.Size;
context.DrawText(Foreground, new Point(), FormattedText); context.DrawText(Foreground, new Point(), FormattedText);
} }
public override void Render(DrawingContext context) public override void Render(DrawingContext context)
{ {
FormattedText.Constraint = Bounds.Size;
_constraint = Bounds.Size;
var selectionStart = SelectionStart; var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd; var selectionEnd = SelectionEnd;
@ -316,10 +319,6 @@ namespace Avalonia.Controls.Presenters
var start = Math.Min(selectionStart, selectionEnd); var start = Math.Min(selectionStart, selectionEnd);
var length = Math.Max(selectionStart, selectionEnd) - start; var length = Math.Max(selectionStart, selectionEnd) - start;
// issue #600: set constraint before any FormattedText manipulation
// see base.Render(...) implementation
FormattedText.Constraint = _constraint;
var rects = FormattedText.HitTestTextRange(start, length); var rects = FormattedText.HitTestTextRange(start, length);
foreach (var rect in rects) foreach (var rect in rects)

20
src/Avalonia.Controls/Primitives/ScrollBar.cs

@ -123,24 +123,20 @@ namespace Avalonia.Controls.Primitives
} }
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == OrientationProperty) if (change.Property == OrientationProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<Orientation>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<Orientation>());
} }
else else
{ {
if (property == MinimumProperty || if (change.Property == MinimumProperty ||
property == MaximumProperty || change.Property == MaximumProperty ||
property == ViewportSizeProperty || change.Property == ViewportSizeProperty ||
property == VisibilityProperty) change.Property == VisibilityProperty)
{ {
UpdateIsVisible(); UpdateIsVisible();
} }

8
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -455,13 +455,13 @@ namespace Avalonia.Controls.Primitives
InternalEndInit(); InternalEndInit();
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == SelectionModeProperty) if (change.Property == SelectionModeProperty)
{ {
var mode = newValue.GetValueOrDefault<SelectionMode>(); var mode = change.NewValue.GetValueOrDefault<SelectionMode>();
Selection.SingleSelect = !mode.HasFlagCustom(SelectionMode.Multiple); Selection.SingleSelect = !mode.HasFlagCustom(SelectionMode.Multiple);
Selection.AutoSelect = mode.HasFlagCustom(SelectionMode.AlwaysSelected); Selection.AutoSelect = mode.HasFlagCustom(SelectionMode.AlwaysSelected);
} }

12
src/Avalonia.Controls/Primitives/Track.cs

@ -280,17 +280,13 @@ namespace Avalonia.Controls.Primitives
return arrangeSize; return arrangeSize;
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == OrientationProperty) if (change.Property == OrientationProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<Orientation>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<Orientation>());
} }
} }

16
src/Avalonia.Controls/ProgressBar.cs

@ -83,21 +83,17 @@ namespace Avalonia.Controls
return base.ArrangeOverride(finalSize); return base.ArrangeOverride(finalSize);
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == IsIndeterminateProperty) if (change.Property == IsIndeterminateProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<bool>(), null); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<bool>(), null);
} }
else if (property == OrientationProperty) else if (change.Property == OrientationProperty)
{ {
UpdatePseudoClasses(null, newValue.GetValueOrDefault<Orientation>()); UpdatePseudoClasses(null, change.NewValue.GetValueOrDefault<Orientation>());
} }
} }

56
src/Avalonia.Controls/Repeater/ItemsRepeater.cs

@ -10,6 +10,7 @@ using Avalonia.Controls.Templates;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.VisualTree;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
@ -375,37 +376,46 @@ namespace Avalonia.Controls
_viewportManager.ResetScrollers(); _viewportManager.ResetScrollers();
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
if (property == ItemsProperty) if (change.Property == ItemsProperty)
{ {
var newEnumerable = newValue.GetValueOrDefault<IEnumerable>(); var oldEnumerable = change.OldValue.GetValueOrDefault<IEnumerable>();
var newDataSource = newEnumerable as ItemsSourceView; var newEnumerable = change.NewValue.GetValueOrDefault<IEnumerable>();
if (newEnumerable != null && newDataSource == null)
if (oldEnumerable != newEnumerable)
{ {
newDataSource = new ItemsSourceView(newEnumerable); var newDataSource = newEnumerable as ItemsSourceView;
} if (newEnumerable != null && newDataSource == null)
{
newDataSource = new ItemsSourceView(newEnumerable);
}
OnDataSourcePropertyChanged(ItemsSourceView, newDataSource); OnDataSourcePropertyChanged(ItemsSourceView, newDataSource);
}
} }
else if (property == ItemTemplateProperty) else if (change.Property == ItemTemplateProperty)
{ {
OnItemTemplateChanged(oldValue.GetValueOrDefault<IDataTemplate>(), newValue.GetValueOrDefault<IDataTemplate>()); OnItemTemplateChanged(
change.OldValue.GetValueOrDefault<IDataTemplate>(),
change.NewValue.GetValueOrDefault<IDataTemplate>());
} }
else if (property == LayoutProperty) else if (change.Property == LayoutProperty)
{ {
OnLayoutChanged(oldValue.GetValueOrDefault<AttachedLayout>(), newValue.GetValueOrDefault<AttachedLayout>()); OnLayoutChanged(
change.OldValue.GetValueOrDefault<AttachedLayout>(),
change.NewValue.GetValueOrDefault<AttachedLayout>());
} }
else if (property == HorizontalCacheLengthProperty) else if (change.Property == HorizontalCacheLengthProperty)
{ {
_viewportManager.HorizontalCacheLength = newValue.GetValueOrDefault<double>(); _viewportManager.HorizontalCacheLength = change.NewValue.GetValueOrDefault<double>();
} }
else if (property == VerticalCacheLengthProperty) else if (change.Property == VerticalCacheLengthProperty)
{ {
_viewportManager.VerticalCacheLength = newValue.GetValueOrDefault<double>(); _viewportManager.VerticalCacheLength = change.NewValue.GetValueOrDefault<double>();
} }
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
} }
internal IControl GetElementImpl(int index, bool forceCreate, bool supressAutoRecycle) internal IControl GetElementImpl(int index, bool forceCreate, bool supressAutoRecycle)
@ -431,8 +441,16 @@ namespace Avalonia.Controls
private int GetElementIndexImpl(IControl element) private int GetElementIndexImpl(IControl element)
{ {
var virtInfo = TryGetVirtualizationInfo(element); // Verify that element is actually a child of this ItemsRepeater
return _viewManager.GetElementIndex(virtInfo); var parent = element.GetVisualParent();
if (parent == this)
{
var virtInfo = TryGetVirtualizationInfo(element);
return _viewManager.GetElementIndex(virtInfo);
}
return -1;
} }
private IControl GetElementFromIndexImpl(int index) private IControl GetElementFromIndexImpl(int index)

36
src/Avalonia.Controls/Repeater/ViewManager.cs

@ -388,19 +388,24 @@ namespace Avalonia.Controls
} }
case NotifyCollectionChangedAction.Reset: case NotifyCollectionChangedAction.Reset:
if (_owner.ItemsSourceView.HasKeyIndexMapping) // If we get multiple resets back to back before
// running layout, we dont have to clear all the elements again.
if (!_isDataSourceStableResetPending)
{ {
_isDataSourceStableResetPending = true; if (_owner.ItemsSourceView.HasKeyIndexMapping)
} {
_isDataSourceStableResetPending = true;
}
// Walk through all the elements and make sure they are cleared, they will go into // Walk through all the elements and make sure they are cleared, they will go into
// the stable id reset pool. // the stable id reset pool.
foreach (var element in _owner.Children) foreach (var element in _owner.Children)
{
var virtInfo = ItemsRepeater.GetVirtualizationInfo(element);
if (virtInfo.IsRealized && virtInfo.AutoRecycleCandidate)
{ {
_owner.ClearElementImpl(element); var virtInfo = ItemsRepeater.GetVirtualizationInfo(element);
if (virtInfo.IsRealized && virtInfo.AutoRecycleCandidate)
{
_owner.ClearElementImpl(element);
}
} }
} }
@ -441,6 +446,9 @@ namespace Avalonia.Controls
} }
_resetPool.Clear(); _resetPool.Clear();
// Flush the realized indices once the stable reset pool is cleared to start fresh.
InvalidateRealizedIndicesHeldByLayout();
} }
} }
@ -498,6 +506,10 @@ namespace Avalonia.Controls
var virtInfo = ItemsRepeater.GetVirtualizationInfo(element); var virtInfo = ItemsRepeater.GetVirtualizationInfo(element);
virtInfo.MoveOwnershipToLayoutFromUniqueIdResetPool(); virtInfo.MoveOwnershipToLayoutFromUniqueIdResetPool();
UpdateElementIndex(element, virtInfo, index); UpdateElementIndex(element, virtInfo, index);
// Update realized indices
_firstRealizedElementIndexHeldByLayout = Math.Min(_firstRealizedElementIndexHeldByLayout, index);
_lastRealizedElementIndexHeldByLayout = Math.Max(_lastRealizedElementIndexHeldByLayout, index);
} }
} }
@ -519,6 +531,10 @@ namespace Avalonia.Controls
_pinnedPool.RemoveAt(i); _pinnedPool.RemoveAt(i);
element = elementInfo.PinnedElement; element = elementInfo.PinnedElement;
elementInfo.VirtualizationInfo.MoveOwnershipToLayoutFromPinnedPool(); elementInfo.VirtualizationInfo.MoveOwnershipToLayoutFromPinnedPool();
// Update realized indices
_firstRealizedElementIndexHeldByLayout = Math.Min(_firstRealizedElementIndexHeldByLayout, index);
_lastRealizedElementIndexHeldByLayout = Math.Max(_lastRealizedElementIndexHeldByLayout, index);
break; break;
} }
} }

34
src/Avalonia.Controls/Shapes/Path.cs

@ -1,5 +1,4 @@
using System; using System;
using Avalonia.Data;
using Avalonia.Media; using Avalonia.Media;
namespace Avalonia.Controls.Shapes namespace Avalonia.Controls.Shapes
@ -9,6 +8,8 @@ namespace Avalonia.Controls.Shapes
public static readonly StyledProperty<Geometry> DataProperty = public static readonly StyledProperty<Geometry> DataProperty =
AvaloniaProperty.Register<Path, Geometry>(nameof(Data)); AvaloniaProperty.Register<Path, Geometry>(nameof(Data));
private EventHandler _geometryChangedHandler;
static Path() static Path()
{ {
AffectsGeometry<Path>(DataProperty); AffectsGeometry<Path>(DataProperty);
@ -21,21 +22,48 @@ namespace Avalonia.Controls.Shapes
set { SetValue(DataProperty, value); } set { SetValue(DataProperty, value); }
} }
private EventHandler GeometryChangedHandler => _geometryChangedHandler ??= GeometryChanged;
protected override Geometry CreateDefiningGeometry() => Data; protected override Geometry CreateDefiningGeometry() => Data;
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
if (Data is object)
{
Data.Changed += GeometryChangedHandler;
}
}
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
if (Data is object)
{
Data.Changed -= GeometryChangedHandler;
}
}
private void DataChanged(AvaloniaPropertyChangedEventArgs e) private void DataChanged(AvaloniaPropertyChangedEventArgs e)
{ {
if (VisualRoot is null)
{
return;
}
var oldGeometry = (Geometry)e.OldValue; var oldGeometry = (Geometry)e.OldValue;
var newGeometry = (Geometry)e.NewValue; var newGeometry = (Geometry)e.NewValue;
if (oldGeometry is object) if (oldGeometry is object)
{ {
oldGeometry.Changed -= GeometryChanged; oldGeometry.Changed -= GeometryChangedHandler;
} }
if (newGeometry is object) if (newGeometry is object)
{ {
newGeometry.Changed += GeometryChanged; newGeometry.Changed += GeometryChangedHandler;
} }
} }

111
src/Avalonia.Controls/Shapes/Shape.cs

@ -2,38 +2,67 @@ using System;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Media; using Avalonia.Media;
#nullable enable
namespace Avalonia.Controls.Shapes namespace Avalonia.Controls.Shapes
{ {
/// <summary>
/// Provides a base class for shape elements, such as <see cref="Ellipse"/>, <see cref="Polygon"/> and <see cref="Rectangle"/>.
/// </summary>
public abstract class Shape : Control public abstract class Shape : Control
{ {
public static readonly StyledProperty<IBrush> FillProperty = /// <summary>
AvaloniaProperty.Register<Shape, IBrush>(nameof(Fill)); /// Defines the <see cref="Fill"/> property.
/// </summary>
public static readonly StyledProperty<IBrush?> FillProperty =
AvaloniaProperty.Register<Shape, IBrush?>(nameof(Fill));
/// <summary>
/// Defines the <see cref="Stretch"/> property.
/// </summary>
public static readonly StyledProperty<Stretch> StretchProperty = public static readonly StyledProperty<Stretch> StretchProperty =
AvaloniaProperty.Register<Shape, Stretch>(nameof(Stretch)); AvaloniaProperty.Register<Shape, Stretch>(nameof(Stretch));
public static readonly StyledProperty<IBrush> StrokeProperty = /// <summary>
AvaloniaProperty.Register<Shape, IBrush>(nameof(Stroke)); /// Defines the <see cref="Stroke"/> property.
/// </summary>
public static readonly StyledProperty<IBrush?> StrokeProperty =
AvaloniaProperty.Register<Shape, IBrush?>(nameof(Stroke));
public static readonly StyledProperty<AvaloniaList<double>> StrokeDashArrayProperty = /// <summary>
AvaloniaProperty.Register<Shape, AvaloniaList<double>>(nameof(StrokeDashArray)); /// Defines the <see cref="StrokeDashArray"/> property.
/// </summary>
public static readonly StyledProperty<AvaloniaList<double>?> StrokeDashArrayProperty =
AvaloniaProperty.Register<Shape, AvaloniaList<double>?>(nameof(StrokeDashArray));
/// <summary>
/// Defines the <see cref="StrokeDashOffset"/> property.
/// </summary>
public static readonly StyledProperty<double> StrokeDashOffsetProperty = public static readonly StyledProperty<double> StrokeDashOffsetProperty =
AvaloniaProperty.Register<Shape, double>(nameof(StrokeDashOffset)); AvaloniaProperty.Register<Shape, double>(nameof(StrokeDashOffset));
/// <summary>
/// Defines the <see cref="StrokeThickness"/> property.
/// </summary>
public static readonly StyledProperty<double> StrokeThicknessProperty = public static readonly StyledProperty<double> StrokeThicknessProperty =
AvaloniaProperty.Register<Shape, double>(nameof(StrokeThickness)); AvaloniaProperty.Register<Shape, double>(nameof(StrokeThickness));
/// <summary>
/// Defines the <see cref="StrokeLineCap"/> property.
/// </summary>
public static readonly StyledProperty<PenLineCap> StrokeLineCapProperty = public static readonly StyledProperty<PenLineCap> StrokeLineCapProperty =
AvaloniaProperty.Register<Shape, PenLineCap>(nameof(StrokeLineCap), PenLineCap.Flat); AvaloniaProperty.Register<Shape, PenLineCap>(nameof(StrokeLineCap), PenLineCap.Flat);
/// <summary>
/// Defines the <see cref="StrokeJoin"/> property.
/// </summary>
public static readonly StyledProperty<PenLineJoin> StrokeJoinProperty = public static readonly StyledProperty<PenLineJoin> StrokeJoinProperty =
AvaloniaProperty.Register<Shape, PenLineJoin>(nameof(StrokeJoin), PenLineJoin.Miter); AvaloniaProperty.Register<Shape, PenLineJoin>(nameof(StrokeJoin), PenLineJoin.Miter);
private Matrix _transform = Matrix.Identity; private Matrix _transform = Matrix.Identity;
private Geometry _definingGeometry; private Geometry? _definingGeometry;
private Geometry _renderedGeometry; private Geometry? _renderedGeometry;
bool _calculateTransformOnArrange = false; private bool _calculateTransformOnArrange;
static Shape() static Shape()
{ {
@ -43,7 +72,10 @@ namespace Avalonia.Controls.Shapes
StrokeThicknessProperty, StrokeLineCapProperty, StrokeJoinProperty); StrokeThicknessProperty, StrokeLineCapProperty, StrokeJoinProperty);
} }
public Geometry DefiningGeometry /// <summary>
/// Gets a value that represents the <see cref="Geometry"/> of the shape.
/// </summary>
public Geometry? DefiningGeometry
{ {
get get
{ {
@ -56,13 +88,10 @@ namespace Avalonia.Controls.Shapes
} }
} }
public IBrush Fill /// <summary>
{ /// Gets a value that represents the final rendered <see cref="Geometry"/> of the shape.
get { return GetValue(FillProperty); } /// </summary>
set { SetValue(FillProperty, value); } public Geometry? RenderedGeometry
}
public Geometry RenderedGeometry
{ {
get get
{ {
@ -93,42 +122,72 @@ namespace Avalonia.Controls.Shapes
} }
} }
/// <summary>
/// Gets or sets the <see cref="IBrush"/> that specifies how the shape's interior is painted.
/// </summary>
public IBrush? Fill
{
get { return GetValue(FillProperty); }
set { SetValue(FillProperty, value); }
}
/// <summary>
/// Gets or sets a <see cref="Stretch"/> enumeration value that describes how the shape fills its allocated space.
/// </summary>
public Stretch Stretch public Stretch Stretch
{ {
get { return GetValue(StretchProperty); } get { return GetValue(StretchProperty); }
set { SetValue(StretchProperty, value); } set { SetValue(StretchProperty, value); }
} }
public IBrush Stroke /// <summary>
/// Gets or sets the <see cref="IBrush"/> that specifies how the shape's outline is painted.
/// </summary>
public IBrush? Stroke
{ {
get { return GetValue(StrokeProperty); } get { return GetValue(StrokeProperty); }
set { SetValue(StrokeProperty, value); } set { SetValue(StrokeProperty, value); }
} }
public AvaloniaList<double> StrokeDashArray /// <summary>
/// Gets or sets a collection of <see cref="double"/> values that indicate the pattern of dashes and gaps that is used to outline shapes.
/// </summary>
public AvaloniaList<double>? StrokeDashArray
{ {
get { return GetValue(StrokeDashArrayProperty); } get { return GetValue(StrokeDashArrayProperty); }
set { SetValue(StrokeDashArrayProperty, value); } set { SetValue(StrokeDashArrayProperty, value); }
} }
/// <summary>
/// Gets or sets a value that specifies the distance within the dash pattern where a dash begins.
/// </summary>
public double StrokeDashOffset public double StrokeDashOffset
{ {
get { return GetValue(StrokeDashOffsetProperty); } get { return GetValue(StrokeDashOffsetProperty); }
set { SetValue(StrokeDashOffsetProperty, value); } set { SetValue(StrokeDashOffsetProperty, value); }
} }
/// <summary>
/// Gets or sets the width of the shape outline.
/// </summary>
public double StrokeThickness public double StrokeThickness
{ {
get { return GetValue(StrokeThicknessProperty); } get { return GetValue(StrokeThicknessProperty); }
set { SetValue(StrokeThicknessProperty, value); } set { SetValue(StrokeThicknessProperty, value); }
} }
/// <summary>
/// Gets or sets a <see cref="PenLineCap"/> enumeration value that describes the shape at the ends of a line.
/// </summary>
public PenLineCap StrokeLineCap public PenLineCap StrokeLineCap
{ {
get { return GetValue(StrokeLineCapProperty); } get { return GetValue(StrokeLineCapProperty); }
set { SetValue(StrokeLineCapProperty, value); } set { SetValue(StrokeLineCapProperty, value); }
} }
/// <summary>
/// Gets or sets a <see cref="PenLineJoin"/> enumeration value that specifies the type of join that is used at the vertices of a Shape.
/// </summary>
public PenLineJoin StrokeJoin public PenLineJoin StrokeJoin
{ {
get { return GetValue(StrokeJoinProperty); } get { return GetValue(StrokeJoinProperty); }
@ -170,12 +229,20 @@ namespace Avalonia.Controls.Shapes
} }
} }
protected abstract Geometry CreateDefiningGeometry(); /// <summary>
/// Creates the shape's defining geometry.
/// </summary>
/// <returns>Defining <see cref="Geometry"/> of the shape.</returns>
protected abstract Geometry? CreateDefiningGeometry();
/// <summary>
/// Invalidates the geometry of this shape.
/// </summary>
protected void InvalidateGeometry() protected void InvalidateGeometry()
{ {
_renderedGeometry = null; _renderedGeometry = null;
_definingGeometry = null; _definingGeometry = null;
InvalidateMeasure(); InvalidateMeasure();
} }
@ -321,8 +388,8 @@ namespace Avalonia.Controls.Shapes
// portion changes. // portion changes.
if (e.Property == BoundsProperty) if (e.Property == BoundsProperty)
{ {
var oldBounds = (Rect)e.OldValue; var oldBounds = (Rect)e.OldValue!;
var newBounds = (Rect)e.NewValue; var newBounds = (Rect)e.NewValue!;
if (oldBounds.Size == newBounds.Size) if (oldBounds.Size == newBounds.Size)
{ {

12
src/Avalonia.Controls/Slider.cs

@ -134,17 +134,13 @@ namespace Avalonia.Controls
} }
} }
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == OrientationProperty) if (change.Property == OrientationProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<Orientation>()); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<Orientation>());
} }
} }

8
src/Avalonia.Controls/TreeView.cs

@ -486,13 +486,13 @@ namespace Avalonia.Controls
} }
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == SelectionModeProperty) if (change.Property == SelectionModeProperty)
{ {
var mode = newValue.GetValueOrDefault<SelectionMode>(); var mode = change.NewValue.GetValueOrDefault<SelectionMode>();
Selection.SingleSelect = !mode.HasFlagCustom(SelectionMode.Multiple); Selection.SingleSelect = !mode.HasFlagCustom(SelectionMode.Multiple);
Selection.AutoSelect = mode.HasFlagCustom(SelectionMode.AlwaysSelected); Selection.AutoSelect = mode.HasFlagCustom(SelectionMode.AlwaysSelected);
} }

121
src/Avalonia.Controls/Window.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Reactive.Linq; using System.Reactive.Linq;
@ -68,6 +69,8 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
public class Window : WindowBase, IStyleable, IFocusScope, ILayoutRoot public class Window : WindowBase, IStyleable, IFocusScope, ILayoutRoot
{ {
private List<Window> _children = new List<Window>();
/// <summary> /// <summary>
/// Defines the <see cref="SizeToContent"/> property. /// Defines the <see cref="SizeToContent"/> property.
/// </summary> /// </summary>
@ -131,7 +134,7 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
public static readonly RoutedEvent WindowClosedEvent = public static readonly RoutedEvent WindowClosedEvent =
RoutedEvent.Register<Window, RoutedEventArgs>("WindowClosed", RoutingStrategies.Direct); RoutedEvent.Register<Window, RoutedEventArgs>("WindowClosed", RoutingStrategies.Direct);
/// <summary> /// <summary>
/// Routed event that can be used for global tracking of opening windows /// Routed event that can be used for global tracking of opening windows
/// </summary> /// </summary>
@ -183,6 +186,7 @@ namespace Avalonia.Controls
: base(impl) : base(impl)
{ {
impl.Closing = HandleClosing; impl.Closing = HandleClosing;
impl.GotInputWhenDisabled = OnGotInputWhenDisabled;
impl.WindowStateChanged = HandleWindowStateChanged; impl.WindowStateChanged = HandleWindowStateChanged;
_maxPlatformClientSize = PlatformImpl?.MaxClientSize ?? default(Size); _maxPlatformClientSize = PlatformImpl?.MaxClientSize ?? default(Size);
this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl?.Resize(x)); this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl?.Resize(x));
@ -302,7 +306,7 @@ namespace Avalonia.Controls
PlatformImpl?.Move(value); PlatformImpl?.Move(value);
} }
} }
/// <summary> /// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler /// Starts moving a window with left button being held. Should be called from left mouse button press event handler
/// </summary> /// </summary>
@ -323,7 +327,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Fired before a window is closed. /// Fired before a window is closed.
/// </summary> /// </summary>
public event EventHandler<CancelEventArgs> Closing; public event EventHandler<CancelEventArgs> Closing;
/// <summary> /// <summary>
/// Closes the window. /// Closes the window.
@ -365,19 +369,59 @@ namespace Avalonia.Controls
{ {
if (close) if (close)
{ {
PlatformImpl?.Dispose(); CloseInternal();
} }
} }
} }
private void CloseInternal()
{
foreach (var child in _children.ToList())
{
// if we HandleClosing() before then there will be no children.
child.CloseInternal();
}
if (Owner is Window owner)
{
owner.RemoveChild(this);
}
Owner = null;
PlatformImpl?.Dispose();
}
/// <summary> /// <summary>
/// Handles a closing notification from <see cref="IWindowImpl.Closing"/>. /// Handles a closing notification from <see cref="IWindowImpl.Closing"/>.
/// </summary> /// </summary>
protected virtual bool HandleClosing() protected virtual bool HandleClosing()
{ {
var args = new CancelEventArgs(); bool canClose = true;
OnClosing(args);
return args.Cancel; foreach (var child in _children.ToList())
{
if (!child.HandleClosing())
{
child.CloseInternal();
}
else
{
canClose = false;
}
}
if (canClose)
{
var args = new CancelEventArgs();
OnClosing(args);
return args.Cancel;
}
else
{
return !canClose;
}
} }
protected virtual void HandleWindowStateChanged(WindowState state) protected virtual void HandleWindowStateChanged(WindowState state)
@ -407,6 +451,14 @@ namespace Avalonia.Controls
using (BeginAutoSizing()) using (BeginAutoSizing())
{ {
Renderer?.Stop(); Renderer?.Stop();
if (Owner is Window owner)
{
owner.RemoveChild(this);
}
Owner = null;
PlatformImpl?.Hide(); PlatformImpl?.Hide();
} }
@ -519,7 +571,10 @@ namespace Avalonia.Controls
using (BeginAutoSizing()) using (BeginAutoSizing())
{ {
PlatformImpl?.ShowDialog(owner.PlatformImpl); PlatformImpl.SetParent(owner.PlatformImpl);
Owner = owner;
owner.AddChild(this);
PlatformImpl?.Show();
Renderer?.Start(); Renderer?.Start();
@ -541,6 +596,37 @@ namespace Avalonia.Controls
return result.Task; return result.Task;
} }
private void UpdateEnabled()
{
PlatformImpl.SetEnabled(_children.Count == 0);
}
private void AddChild(Window window)
{
_children.Add(window);
UpdateEnabled();
}
private void RemoveChild(Window window)
{
_children.Remove(window);
UpdateEnabled();
}
private void OnGotInputWhenDisabled()
{
var firstChild = _children.FirstOrDefault();
if (firstChild != null)
{
firstChild.OnGotInputWhenDisabled();
}
else
{
Activate();
}
}
private void SetWindowStartupLocation(IWindowBaseImpl owner = null) private void SetWindowStartupLocation(IWindowBaseImpl owner = null)
{ {
var scaling = owner?.Scaling ?? PlatformImpl?.Scaling ?? 1; var scaling = owner?.Scaling ?? PlatformImpl?.Scaling ?? 1;
@ -631,6 +717,13 @@ namespace Avalonia.Controls
RaiseEvent(new RoutedEventArgs(WindowClosedEvent)); RaiseEvent(new RoutedEventArgs(WindowClosedEvent));
base.HandleClosed(); base.HandleClosed();
if (Owner is Window owner)
{
owner.RemoveChild(this);
}
Owner = null;
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -658,19 +751,15 @@ namespace Avalonia.Controls
/// </remarks> /// </remarks>
protected virtual void OnClosing(CancelEventArgs e) => Closing?.Invoke(this, e); protected virtual void OnClosing(CancelEventArgs e) => Closing?.Invoke(this, e);
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
if (property == SystemDecorationsProperty) if (change.Property == SystemDecorationsProperty)
{ {
var typedNewValue = newValue.GetValueOrDefault<SystemDecorations>(); var typedNewValue = change.NewValue.GetValueOrDefault<SystemDecorations>();
PlatformImpl?.SetSystemDecorations(typedNewValue); PlatformImpl?.SetSystemDecorations(typedNewValue);
var o = oldValue.GetValueOrDefault<SystemDecorations>() == SystemDecorations.Full; var o = change.OldValue.GetValueOrDefault<SystemDecorations>() == SystemDecorations.Full;
var n = typedNewValue == SystemDecorations.Full; var n = typedNewValue == SystemDecorations.Full;
if (o != n) if (o != n)

2
src/Avalonia.Controls/WindowBase.cs

@ -109,7 +109,7 @@ namespace Avalonia.Controls
public WindowBase Owner public WindowBase Owner
{ {
get { return _owner; } get { return _owner; }
set { SetAndRaise(OwnerProperty, ref _owner, value); } protected set { SetAndRaise(OwnerProperty, ref _owner, value); }
} }
/// <summary> /// <summary>

9
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@ -83,6 +83,7 @@ namespace Avalonia.DesignerSupport.Remote
} }
public IScreenImpl Screen { get; } = new ScreenStub(); public IScreenImpl Screen { get; } = new ScreenStub();
public Action GotInputWhenDisabled { get; set; }
public void Activate() public void Activate()
{ {
@ -115,5 +116,13 @@ namespace Avalonia.DesignerSupport.Remote
public void SetTopmost(bool value) public void SetTopmost(bool value)
{ {
} }
public void SetParent(IWindowImpl parent)
{
}
public void SetEnabled(bool enable)
{
}
} }
} }

10
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

@ -234,18 +234,10 @@ namespace Avalonia.DesignerSupport.Remote
} }
catch (Exception e) catch (Exception e)
{ {
var xmlException = e as XmlException;
s_transport.Send(new UpdateXamlResultMessage s_transport.Send(new UpdateXamlResultMessage
{ {
Error = e.ToString(), Error = e.ToString(),
Exception = new ExceptionDetails Exception = new ExceptionDetails(e),
{
ExceptionType = e.GetType().FullName,
Message = e.Message.ToString(),
LineNumber = xmlException?.LineNumber,
LinePosition = xmlException?.LinePosition,
}
}); });
} }
} }

10
src/Avalonia.DesignerSupport/Remote/Stubs.cs

@ -130,7 +130,17 @@ namespace Avalonia.DesignerSupport.Remote
{ {
} }
public void SetParent(IWindowImpl parent)
{
}
public void SetEnabled(bool enable)
{
}
public IPopupPositioner PopupPositioner { get; } public IPopupPositioner PopupPositioner { get; }
public Action GotInputWhenDisabled { get; set; }
} }
class ClipboardStub : IClipboard class ClipboardStub : IClipboard

12
src/Avalonia.Input/InputElement.cs

@ -526,17 +526,17 @@ namespace Avalonia.Input
{ {
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == IsFocusedProperty) if (change.Property == IsFocusedProperty)
{ {
UpdatePseudoClasses(newValue.GetValueOrDefault<bool>(), null); UpdatePseudoClasses(change.NewValue.GetValueOrDefault<bool>(), null);
} }
else if (property == IsPointerOverProperty) else if (change.Property == IsPointerOverProperty)
{ {
UpdatePseudoClasses(null, newValue.GetValueOrDefault<bool>()); UpdatePseudoClasses(null, change.NewValue.GetValueOrDefault<bool>());
} }
} }

10
src/Avalonia.Layout/FlowLayoutAlgorithm.cs

@ -74,6 +74,7 @@ namespace Avalonia.Layout
double lineSpacing, double lineSpacing,
int maxItemsPerLine, int maxItemsPerLine,
ScrollOrientation orientation, ScrollOrientation orientation,
bool disableVirtualization,
string layoutId) string layoutId)
{ {
_orientation.ScrollOrientation = orientation; _orientation.ScrollOrientation = orientation;
@ -95,14 +96,14 @@ namespace Avalonia.Layout
_elementManager.OnBeginMeasure(orientation); _elementManager.OnBeginMeasure(orientation);
int anchorIndex = GetAnchorIndex(availableSize, isWrapping, minItemSpacing, layoutId); int anchorIndex = GetAnchorIndex(availableSize, isWrapping, minItemSpacing, layoutId);
Generate(GenerateDirection.Forward, anchorIndex, availableSize, minItemSpacing, lineSpacing, maxItemsPerLine, layoutId); Generate(GenerateDirection.Forward, anchorIndex, availableSize, minItemSpacing, lineSpacing, maxItemsPerLine, disableVirtualization, layoutId);
Generate(GenerateDirection.Backward, anchorIndex, availableSize, minItemSpacing, lineSpacing, maxItemsPerLine, layoutId); Generate(GenerateDirection.Backward, anchorIndex, availableSize, minItemSpacing, lineSpacing, maxItemsPerLine, disableVirtualization, layoutId);
if (isWrapping && IsReflowRequired()) if (isWrapping && IsReflowRequired())
{ {
var firstElementBounds = _elementManager.GetLayoutBoundsForRealizedIndex(0); var firstElementBounds = _elementManager.GetLayoutBoundsForRealizedIndex(0);
_orientation.SetMinorStart(ref firstElementBounds, 0); _orientation.SetMinorStart(ref firstElementBounds, 0);
_elementManager.SetLayoutBoundsForRealizedIndex(0, firstElementBounds); _elementManager.SetLayoutBoundsForRealizedIndex(0, firstElementBounds);
Generate(GenerateDirection.Forward, 0 /*anchorIndex*/, availableSize, minItemSpacing, lineSpacing, maxItemsPerLine, layoutId); Generate(GenerateDirection.Forward, 0 /*anchorIndex*/, availableSize, minItemSpacing, lineSpacing, maxItemsPerLine, disableVirtualization, layoutId);
} }
RaiseLineArranged(); RaiseLineArranged();
@ -273,6 +274,7 @@ namespace Avalonia.Layout
double minItemSpacing, double minItemSpacing,
double lineSpacing, double lineSpacing,
int maxItemsPerLine, int maxItemsPerLine,
bool disableVirtualization,
string layoutId) string layoutId)
{ {
if (anchorIndex != -1) if (anchorIndex != -1)
@ -288,7 +290,7 @@ namespace Avalonia.Layout
bool lineNeedsReposition = false; bool lineNeedsReposition = false;
while (_elementManager.IsIndexValidInData(currentIndex) && while (_elementManager.IsIndexValidInData(currentIndex) &&
ShouldContinueFillingUpSpace(previousIndex, direction)) (disableVirtualization || ShouldContinueFillingUpSpace(previousIndex, direction)))
{ {
// Ensure layout element. // Ensure layout element.
_elementManager.EnsureElementRealized(direction == GenerateDirection.Forward, currentIndex, layoutId); _elementManager.EnsureElementRealized(direction == GenerateDirection.Forward, currentIndex, layoutId);

26
src/Avalonia.Layout/StackLayout.cs

@ -14,6 +14,12 @@ namespace Avalonia.Layout
/// </summary> /// </summary>
public class StackLayout : VirtualizingLayout, IFlowLayoutAlgorithmDelegates public class StackLayout : VirtualizingLayout, IFlowLayoutAlgorithmDelegates
{ {
/// <summary>
/// Defines the <see cref="DisableVirtualization"/> property.
/// </summary>
public static readonly StyledProperty<bool> DisableVirtualizationProperty =
AvaloniaProperty.Register<StackLayout, bool>(nameof(DisableVirtualization));
/// <summary> /// <summary>
/// Defines the <see cref="Orientation"/> property. /// Defines the <see cref="Orientation"/> property.
/// </summary> /// </summary>
@ -36,6 +42,15 @@ namespace Avalonia.Layout
LayoutId = "StackLayout"; LayoutId = "StackLayout";
} }
/// <summary>
/// Gets or sets a value indicating whether virtualization is disabled on the layout.
/// </summary>
public bool DisableVirtualization
{
get => GetValue(DisableVirtualizationProperty);
set => SetValue(DisableVirtualizationProperty, value);
}
/// <summary> /// <summary>
/// Gets or sets the axis along which items are laid out. /// Gets or sets the axis along which items are laid out.
/// </summary> /// </summary>
@ -262,6 +277,8 @@ namespace Avalonia.Layout
protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize) protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{ {
((StackLayoutState)context.LayoutState).OnMeasureStart();
var desiredSize = GetFlowAlgorithm(context).Measure( var desiredSize = GetFlowAlgorithm(context).Measure(
availableSize, availableSize,
context, context,
@ -270,6 +287,7 @@ namespace Avalonia.Layout
Spacing, Spacing,
int.MaxValue, int.MaxValue,
_orientation.ScrollOrientation, _orientation.ScrollOrientation,
DisableVirtualization,
LayoutId); LayoutId);
return new Size(desiredSize.Width, desiredSize.Height); return new Size(desiredSize.Width, desiredSize.Height);
@ -284,8 +302,6 @@ namespace Avalonia.Layout
FlowLayoutAlgorithm.LineAlignment.Start, FlowLayoutAlgorithm.LineAlignment.Start,
LayoutId); LayoutId);
((StackLayoutState)context.LayoutState).OnArrangeLayoutEnd();
return new Size(value.Width, value.Height); return new Size(value.Width, value.Height);
} }
@ -296,11 +312,11 @@ namespace Avalonia.Layout
InvalidateLayout(); InvalidateLayout();
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
if (property == OrientationProperty) if (change.Property == OrientationProperty)
{ {
var orientation = newValue.GetValueOrDefault<Orientation>(); var orientation = change.NewValue.GetValueOrDefault<Orientation>();
//Note: For StackLayout Vertical Orientation means we have a Vertical ScrollOrientation. //Note: For StackLayout Vertical Orientation means we have a Vertical ScrollOrientation.
//Horizontal Orientation means we have a Horizontal ScrollOrientation. //Horizontal Orientation means we have a Horizontal ScrollOrientation.

2
src/Avalonia.Layout/StackLayoutState.cs

@ -56,6 +56,6 @@ namespace Avalonia.Layout
MaxArrangeBounds = Math.Max(MaxArrangeBounds, minorSize); MaxArrangeBounds = Math.Max(MaxArrangeBounds, minorSize);
} }
internal void OnArrangeLayoutEnd() => MaxArrangeBounds = 0; internal void OnMeasureStart() => MaxArrangeBounds = 0;
} }
} }

36
src/Avalonia.Layout/UniformGridLayout.cs

@ -433,6 +433,7 @@ namespace Avalonia.Layout
LineSpacing, LineSpacing,
_maximumRowsOrColumns, _maximumRowsOrColumns,
_orientation.ScrollOrientation, _orientation.ScrollOrientation,
false,
LayoutId); LayoutId);
// If after Measure the first item is in the realization rect, then we revoke grid state's ownership, // If after Measure the first item is in the realization rect, then we revoke grid state's ownership,
@ -463,45 +464,44 @@ namespace Avalonia.Layout
gridState.ClearElementOnDataSourceChange(context, args); gridState.ClearElementOnDataSourceChange(context, args);
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
if (property == OrientationProperty) if (change.Property == OrientationProperty)
{ {
var orientation = newValue.GetValueOrDefault<Orientation>(); var orientation = change.NewValue.GetValueOrDefault<Orientation>();
//Note: For UniformGridLayout Vertical Orientation means we have a Horizontal ScrollOrientation. Horizontal Orientation means we have a Vertical ScrollOrientation. //Note: For UniformGridLayout Vertical Orientation means we have a Horizontal ScrollOrientation. Horizontal Orientation means we have a Vertical ScrollOrientation.
//i.e. the properties are the inverse of each other. //i.e. the properties are the inverse of each other.
var scrollOrientation = (orientation == Orientation.Horizontal) ? ScrollOrientation.Vertical : ScrollOrientation.Horizontal; var scrollOrientation = (orientation == Orientation.Horizontal) ? ScrollOrientation.Vertical : ScrollOrientation.Horizontal;
_orientation.ScrollOrientation = scrollOrientation; _orientation.ScrollOrientation = scrollOrientation;
} }
else if (property == MinColumnSpacingProperty) else if (change.Property == MinColumnSpacingProperty)
{ {
_minColumnSpacing = newValue.GetValueOrDefault<double>(); _minColumnSpacing = change.NewValue.GetValueOrDefault<double>();
} }
else if (property == MinRowSpacingProperty) else if (change.Property == MinRowSpacingProperty)
{ {
_minRowSpacing = newValue.GetValueOrDefault<double>(); _minRowSpacing = change.NewValue.GetValueOrDefault<double>();
} }
else if (property == ItemsJustificationProperty) else if (change.Property == ItemsJustificationProperty)
{ {
_itemsJustification = newValue.GetValueOrDefault<UniformGridLayoutItemsJustification>(); _itemsJustification = change.NewValue.GetValueOrDefault<UniformGridLayoutItemsJustification>();
;
} }
else if (property == ItemsStretchProperty) else if (change.Property == ItemsStretchProperty)
{ {
_itemsStretch = newValue.GetValueOrDefault<UniformGridLayoutItemsStretch>(); _itemsStretch = change.NewValue.GetValueOrDefault<UniformGridLayoutItemsStretch>();
} }
else if (property == MinItemWidthProperty) else if (change.Property == MinItemWidthProperty)
{ {
_minItemWidth = newValue.GetValueOrDefault<double>(); _minItemWidth = change.NewValue.GetValueOrDefault<double>();
} }
else if (property == MinItemHeightProperty) else if (change.Property == MinItemHeightProperty)
{ {
_minItemHeight = newValue.GetValueOrDefault<double>(); _minItemHeight = change.NewValue.GetValueOrDefault<double>();
} }
else if (property == MaximumRowsOrColumnsProperty) else if (change.Property == MaximumRowsOrColumnsProperty)
{ {
_maximumRowsOrColumns = newValue.GetValueOrDefault<int>(); _maximumRowsOrColumns = change.NewValue.GetValueOrDefault<int>();
} }
InvalidateLayout(); InvalidateLayout();

5
src/Avalonia.Native/PopupImpl.cs

@ -43,6 +43,11 @@ namespace Avalonia.Native
_parent = parent; _parent = parent;
} }
public void GotInputWhenDisabled()
{
// NOP on Popup
}
bool IAvnWindowEvents.Closing() bool IAvnWindowEvents.Closing()
{ {
return true; return true;

26
src/Avalonia.Native/WindowImpl.cs

@ -40,7 +40,7 @@ namespace Avalonia.Native
bool IAvnWindowEvents.Closing() bool IAvnWindowEvents.Closing()
{ {
if(_parent.Closing != null) if (_parent.Closing != null)
{ {
return _parent.Closing(); return _parent.Closing();
} }
@ -52,15 +52,15 @@ namespace Avalonia.Native
{ {
_parent.WindowStateChanged?.Invoke((WindowState)state); _parent.WindowStateChanged?.Invoke((WindowState)state);
} }
void IAvnWindowEvents.GotInputWhenDisabled()
{
_parent.GotInputWhenDisabled?.Invoke();
}
} }
public IAvnWindow Native => _native; public IAvnWindow Native => _native;
public void ShowDialog(IWindowImpl window)
{
_native.ShowDialog(((WindowImpl)window).Native);
}
public void CanResize(bool value) public void CanResize(bool value)
{ {
_native.CanResize = value; _native.CanResize = value;
@ -71,7 +71,7 @@ namespace Avalonia.Native
_native.Decorations = (Interop.SystemDecorations)enabled; _native.Decorations = (Interop.SystemDecorations)enabled;
} }
public void SetTitleBarColor (Avalonia.Media.Color color) public void SetTitleBarColor(Avalonia.Media.Color color)
{ {
_native.SetTitleBarColor(new AvnColor { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B }); _native.SetTitleBarColor(new AvnColor { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B });
} }
@ -116,5 +116,17 @@ namespace Avalonia.Native
public override IPopupImpl CreatePopup() => public override IPopupImpl CreatePopup() =>
_opts.OverlayPopups ? null : new PopupImpl(_factory, _opts, _glFeature, this); _opts.OverlayPopups ? null : new PopupImpl(_factory, _opts, _glFeature, this);
public Action GotInputWhenDisabled { get; set; }
public void SetParent(IWindowImpl parent)
{
_native.SetParent(((WindowImpl)parent).Native);
}
public void SetEnabled(bool enable)
{
_native.SetEnabled(enable);
}
} }
} }

24
src/Avalonia.Remote.Protocol/DesignMessages.cs

@ -1,4 +1,7 @@
using System; using System;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Xml;
namespace Avalonia.Remote.Protocol.Designer namespace Avalonia.Remote.Protocol.Designer
{ {
@ -26,6 +29,27 @@ namespace Avalonia.Remote.Protocol.Designer
public class ExceptionDetails public class ExceptionDetails
{ {
public ExceptionDetails()
{
}
public ExceptionDetails(Exception e)
{
if (e is TargetInvocationException)
{
e = e.InnerException;
}
ExceptionType = e.GetType().Name;
Message = e.Message;
if (e is XmlException xml)
{
LineNumber = xml.LineNumber;
LinePosition = xml.LinePosition;
}
}
public string ExceptionType { get; set; } public string ExceptionType { get; set; }
public string Message { get; set; } public string Message { get; set; }
public int? LineNumber { get; set; } public int? LineNumber { get; set; }

12
src/Avalonia.Styling/Styling/PropertySetterBindingInstance.cs

@ -24,6 +24,7 @@ namespace Avalonia.Styling
private BindingValue<T> _value; private BindingValue<T> _value;
private IDisposable? _subscription; private IDisposable? _subscription;
private IDisposable? _subscriptionTwoWay; private IDisposable? _subscriptionTwoWay;
private IDisposable? _innerSubscription;
private bool _isActive; private bool _isActive;
public PropertySetterBindingInstance( public PropertySetterBindingInstance(
@ -121,6 +122,9 @@ namespace Avalonia.Styling
sub.Dispose(); sub.Dispose();
} }
_innerSubscription?.Dispose();
_innerSubscription = null;
base.Dispose(); base.Dispose();
} }
@ -144,13 +148,13 @@ namespace Avalonia.Styling
protected override void Subscribed() protected override void Subscribed()
{ {
_subscription = _binding.Observable.Subscribe(_inner); _innerSubscription = _binding.Observable.Subscribe(_inner);
} }
protected override void Unsubscribed() protected override void Unsubscribed()
{ {
_subscription?.Dispose(); _innerSubscription?.Dispose();
_subscription = null; _innerSubscription = null;
} }
private void PublishNext() private void PublishNext()
@ -160,7 +164,7 @@ namespace Avalonia.Styling
private void ConvertAndPublishNext(object? value) private void ConvertAndPublishNext(object? value)
{ {
_value = value is T v ? v : BindingValue<object>.FromUntyped(value).Convert<T>(); _value = value is T v ? v : BindingValue<T>.FromUntyped(value);
if (_isActive) if (_isActive)
{ {

4
src/Avalonia.Visuals/Media/BoxShadows.cs

@ -21,7 +21,7 @@ namespace Avalonia.Media
{ {
_first = shadow; _first = shadow;
_list = null; _list = null;
Count = 1; Count = _first.IsEmpty ? 0 : 1;
} }
public BoxShadows(BoxShadow first, BoxShadow[] rest) public BoxShadows(BoxShadow first, BoxShadow[] rest)
@ -105,8 +105,6 @@ namespace Avalonia.Media
return false; return false;
} }
} }
public static implicit operator BoxShadows(BoxShadow shadow) => new BoxShadows(shadow);
public bool Equals(BoxShadows other) public bool Equals(BoxShadows other)
{ {

8
src/Avalonia.Visuals/Media/DrawingContext.cs

@ -141,13 +141,13 @@ namespace Avalonia.Media
/// <param name="radiusY">The radius in the Y dimension of the rounded corners. /// <param name="radiusY">The radius in the Y dimension of the rounded corners.
/// This value will be clamped to the range of 0 to Height/2 /// This value will be clamped to the range of 0 to Height/2
/// </param> /// </param>
/// <param name="boxShadow">Box shadow effect parameters</param> /// <param name="boxShadows">Box shadow effect parameters</param>
/// <remarks> /// <remarks>
/// The brush and the pen can both be null. If the brush is null, then no fill is performed. /// The brush and the pen can both be null. If the brush is null, then no fill is performed.
/// If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible. /// If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.
/// </remarks> /// </remarks>
public void DrawRectangle(IBrush brush, IPen pen, Rect rect, double radiusX = 0, double radiusY = 0, public void DrawRectangle(IBrush brush, IPen pen, Rect rect, double radiusX = 0, double radiusY = 0,
BoxShadow boxShadow = default) BoxShadows boxShadows = default)
{ {
if (brush == null && !PenIsVisible(pen)) if (brush == null && !PenIsVisible(pen))
{ {
@ -164,7 +164,7 @@ namespace Avalonia.Media
radiusY = Math.Min(radiusY, rect.Height / 2); radiusY = Math.Min(radiusY, rect.Height / 2);
} }
PlatformImpl.DrawRectangle(brush, pen, new RoundedRect(rect, radiusX, radiusY), boxShadow); PlatformImpl.DrawRectangle(brush, pen, new RoundedRect(rect, radiusX, radiusY), boxShadows);
} }
/// <summary> /// <summary>
@ -350,7 +350,7 @@ namespace Avalonia.Media
/// </summary> /// </summary>
/// <param name="matrix">The matrix</param> /// <param name="matrix">The matrix</param>
/// <returns>A disposable used to undo the transformation.</returns> /// <returns>A disposable used to undo the transformation.</returns>
PushedState PushSetTransform(Matrix matrix) public PushedState PushSetTransform(Matrix matrix)
{ {
var oldMatrix = CurrentTransform; var oldMatrix = CurrentTransform;
CurrentTransform = matrix; CurrentTransform = matrix;

10
src/Avalonia.Visuals/Media/DrawingImage.cs

@ -63,15 +63,11 @@ namespace Avalonia.Media
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnPropertyChanged<T>( protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{ {
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
if (property == DrawingProperty) if (change.Property == DrawingProperty)
{ {
RaiseInvalidated(EventArgs.Empty); RaiseInvalidated(EventArgs.Empty);
} }

44
src/Avalonia.Visuals/Media/Imaging/Bitmap.cs

@ -11,6 +11,46 @@ namespace Avalonia.Media.Imaging
/// </summary> /// </summary>
public class Bitmap : IBitmap public class Bitmap : IBitmap
{ {
/// <summary>
/// Loads a Bitmap from a stream and decodes at the desired width. Aspect ratio is maintained.
/// This is more efficient than loading and then resizing.
/// </summary>
/// <param name="stream">The stream to read the bitmap from. This can be any supported image format.</param>
/// <param name="width">The desired width of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param>
/// <returns>An instance of the <see cref="Bitmap"/> class.</returns>
public static Bitmap DecodeToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
return new Bitmap(factory.LoadBitmapToWidth(stream, width, interpolationMode));
}
/// <summary>
/// Loads a Bitmap from a stream and decodes at the desired height. Aspect ratio is maintained.
/// This is more efficient than loading and then resizing.
/// </summary>
/// <param name="stream">The stream to read the bitmap from. This can be any supported image format.</param>
/// <param name="height">The desired height of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param>
/// <returns>An instance of the <see cref="Bitmap"/> class.</returns>
public static Bitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
return new Bitmap(factory.LoadBitmapToHeight(stream, height, interpolationMode));
}
/// <summary>
/// Creates a Bitmap scaled to a specified size from the current bitmap.
/// </summary>
/// <param name="destinationSize">The destination size.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param>
/// <returns>An instance of the <see cref="Bitmap"/> class.</returns>
public Bitmap CreateScaledBitmap(PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
return new Bitmap(factory.ResizeBitmap(PlatformImpl.Item, destinationSize, interpolationMode));
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Bitmap"/> class. /// Initializes a new instance of the <see cref="Bitmap"/> class.
/// </summary> /// </summary>
@ -39,7 +79,7 @@ namespace Avalonia.Media.Imaging
{ {
PlatformImpl = impl.Clone(); PlatformImpl = impl.Clone();
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Bitmap"/> class. /// Initializes a new instance of the <see cref="Bitmap"/> class.
/// </summary> /// </summary>
@ -48,7 +88,7 @@ namespace Avalonia.Media.Imaging
{ {
PlatformImpl = RefCountable.Create(impl); PlatformImpl = RefCountable.Create(impl);
} }
/// <inheritdoc/> /// <inheritdoc/>
public virtual void Dispose() public virtual void Dispose()
{ {

26
src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs

@ -2,6 +2,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Visuals.Media.Imaging;
namespace Avalonia.Platform namespace Avalonia.Platform
{ {
@ -87,17 +89,37 @@ namespace Avalonia.Platform
/// <summary> /// <summary>
/// Loads a bitmap implementation from a file.. /// Loads a bitmap implementation from a file..
/// </summary> /// </summary>
/// <param name="fileName">The filename of the bitmap.</param> /// <param name="fileName">The filename of the bitmap.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns> /// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmap(string fileName); IBitmapImpl LoadBitmap(string fileName);
/// <summary> /// <summary>
/// Loads a bitmap implementation from a file.. /// Loads a bitmap implementation from a file..
/// </summary> /// </summary>
/// <param name="stream">The stream to read the bitmap from.</param> /// <param name="stream">The stream to read the bitmap from.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns> /// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmap(Stream stream); IBitmapImpl LoadBitmap(Stream stream);
/// <summary>
/// Loads a bitmap implementation from a stream to a specified width maintaining aspect ratio.
/// </summary>
/// <param name="stream">The stream to read the bitmap from.</param>
/// <param name="width">The desired width of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
/// <summary>
/// Loads a bitmap implementation from a stream to a specified height maintaining aspect ratio.
/// </summary>
/// <param name="stream">The stream to read the bitmap from.</param>
/// <param name="height">The desired height of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
/// <summary> /// <summary>
/// Loads a bitmap implementation from a pixels in memory. /// Loads a bitmap implementation from a pixels in memory.
/// </summary> /// </summary>

49
src/Avalonia.Visuals/Rect.cs

@ -421,11 +421,50 @@ namespace Avalonia
} }
/// <summary> /// <summary>
/// Gets the union of two rectangles. /// Normalizes the rectangle so both the <see cref="Width"/> and <see
/// </summary> /// cref="Height"/> are positive, without changing the location of the rectangle
/// <param name="rect">The other rectangle.</param> /// </summary>
/// <returns>The union.</returns> /// <returns>Normalized Rect</returns>
public Rect Union(Rect rect) /// <remarks>
/// Empty rect will be return when Rect contains invalid values. Like NaN.
/// </remarks>
public Rect Normalize()
{
Rect rect = this;
if(double.IsNaN(rect.Right) || double.IsNaN(rect.Bottom) ||
double.IsNaN(rect.X) || double.IsNaN(rect.Y) ||
double.IsNaN(Height) || double.IsNaN(Width))
{
return Rect.Empty;
}
if (rect.Width < 0)
{
var x = X + Width;
var width = X - x;
rect = rect.WithX(x).WithWidth(width);
}
if (rect.Height < 0)
{
var y = Y + Height;
var height = Y - y;
rect = rect.WithY(y).WithHeight(height);
}
return rect;
}
/// <summary>
/// Gets the union of two rectangles.
/// </summary>
/// <param name="rect">The other rectangle.</param>
/// <returns>The union.</returns>
public Rect Union(Rect rect)
{ {
if (IsEmpty) if (IsEmpty)
{ {

2
src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs

@ -364,7 +364,7 @@ namespace Avalonia.Rendering.SceneGraph
public int DrawOperationIndex { get; } public int DrawOperationIndex { get; }
} }
private void Add(IDrawOperation node) private void Add<T>(T node) where T : class, IDrawOperation
{ {
using (var refCounted = RefCountable.Create(node)) using (var refCounted = RefCountable.Create(node))
{ {

3
src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs

@ -11,7 +11,8 @@ namespace Avalonia.Rendering.SceneGraph
{ {
public DrawOperation(Rect bounds, Matrix transform) public DrawOperation(Rect bounds, Matrix transform)
{ {
bounds = bounds.TransformToAABB(transform); bounds = bounds.Normalize().TransformToAABB(transform);
Bounds = new Rect( Bounds = new Rect(
new Point(Math.Floor(bounds.X), Math.Floor(bounds.Y)), new Point(Math.Floor(bounds.X), Math.Floor(bounds.Y)),
new Point(Math.Ceiling(bounds.Right), Math.Ceiling(bounds.Bottom))); new Point(Math.Ceiling(bounds.Right), Math.Ceiling(bounds.Bottom)));

5
src/Avalonia.Visuals/Visual.cs

@ -114,6 +114,9 @@ namespace Avalonia
/// </summary> /// </summary>
public Visual() public Visual()
{ {
// Disable transitions until we're added to the visual tree.
DisableTransitions();
var visualChildren = new AvaloniaList<IVisual>(); var visualChildren = new AvaloniaList<IVisual>();
visualChildren.ResetBehavior = ResetBehavior.Remove; visualChildren.ResetBehavior = ResetBehavior.Remove;
visualChildren.Validate = visual => ValidateVisualChild(visual); visualChildren.Validate = visual => ValidateVisualChild(visual);
@ -393,6 +396,7 @@ namespace Avalonia
RenderTransform.Changed += RenderTransformChanged; RenderTransform.Changed += RenderTransformChanged;
} }
EnableTransitions();
OnAttachedToVisualTree(e); OnAttachedToVisualTree(e);
AttachedToVisualTree?.Invoke(this, e); AttachedToVisualTree?.Invoke(this, e);
InvalidateVisual(); InvalidateVisual();
@ -429,6 +433,7 @@ namespace Avalonia
RenderTransform.Changed -= RenderTransformChanged; RenderTransform.Changed -= RenderTransformChanged;
} }
DisableTransitions();
OnDetachedFromVisualTree(e); OnDetachedFromVisualTree(e);
DetachedFromVisualTree?.Invoke(this, e); DetachedFromVisualTree?.Invoke(this, e);
e.Root?.Renderer?.AddDirty(this); e.Root?.Renderer?.AddDirty(this);

49
src/Avalonia.X11/X11Window.cs

@ -41,9 +41,9 @@ namespace Avalonia.X11
private IntPtr _renderHandle; private IntPtr _renderHandle;
private bool _mapped; private bool _mapped;
private bool _wasMappedAtLeastOnce = false; private bool _wasMappedAtLeastOnce = false;
private HashSet<X11Window> _transientChildren = new HashSet<X11Window>();
private X11Window _transientParent;
private double? _scalingOverride; private double? _scalingOverride;
private bool _disabled;
public object SyncRoot { get; } = new object(); public object SyncRoot { get; } = new object();
class InputEventContainer class InputEventContainer
@ -746,7 +746,6 @@ namespace Avalonia.X11
void Cleanup() void Cleanup()
{ {
SetTransientParent(null, false);
if (_xic != IntPtr.Zero) if (_xic != IntPtr.Zero)
{ {
XDestroyIC(_xic); XDestroyIC(_xic);
@ -773,38 +772,24 @@ namespace Avalonia.X11
bool ActivateTransientChildIfNeeded() bool ActivateTransientChildIfNeeded()
{ {
if (_transientChildren.Count == 0) if (_disabled)
return false; {
var child = _transientChildren.First(); GotInputWhenDisabled?.Invoke();
if (!child.ActivateTransientChildIfNeeded()) return true;
child.Activate(); }
return true;
} return false;
void SetTransientParent(X11Window window, bool informServer = true)
{
_transientParent?._transientChildren.Remove(this);
_transientParent = window;
_transientParent?._transientChildren.Add(this);
if (informServer)
SetTransientForHint(_transientParent?._handle);
} }
void SetTransientForHint(IntPtr? parent) public void SetParent(IWindowImpl parent)
{ {
if (parent == null || parent == IntPtr.Zero) if (parent == null || parent.Handle == null || parent.Handle.Handle == IntPtr.Zero)
XDeleteProperty(_x11.Display, _handle, _x11.Atoms.XA_WM_TRANSIENT_FOR); XDeleteProperty(_x11.Display, _handle, _x11.Atoms.XA_WM_TRANSIENT_FOR);
else else
XSetTransientForHint(_x11.Display, _handle, parent.Value); XSetTransientForHint(_x11.Display, _handle, parent.Handle.Handle);
} }
public void Show() public void Show()
{
SetTransientParent(null);
ShowCore();
}
void ShowCore()
{ {
_wasMappedAtLeastOnce = true; _wasMappedAtLeastOnce = true;
XMapWindow(_x11.Display, _handle); XMapWindow(_x11.Display, _handle);
@ -813,7 +798,6 @@ namespace Avalonia.X11
public void Hide() => XUnmapWindow(_x11.Display, _handle); public void Hide() => XUnmapWindow(_x11.Display, _handle);
public Point PointToClient(PixelPoint point) => new Point((point.X - Position.X) / Scaling, (point.Y - Position.Y) / Scaling); public Point PointToClient(PixelPoint point) => new Point((point.X - Position.X) / Scaling, (point.Y - Position.Y) / Scaling);
public PixelPoint PointToScreen(Point point) => new PixelPoint( public PixelPoint PointToScreen(Point point) => new PixelPoint(
@ -1034,13 +1018,14 @@ namespace Avalonia.X11
{ {
ChangeWMAtoms(value, _x11.Atoms._NET_WM_STATE_ABOVE); ChangeWMAtoms(value, _x11.Atoms._NET_WM_STATE_ABOVE);
} }
public void ShowDialog(IWindowImpl parent) public void SetEnabled(bool enable)
{ {
SetTransientParent((X11Window)parent); _disabled = !enable;
ShowCore();
} }
public Action GotInputWhenDisabled { get; set; }
public void SetIcon(IWindowIconImpl icon) public void SetIcon(IWindowIconImpl icon)
{ {
if (icon != null) if (icon != null)

19
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -124,29 +124,12 @@ namespace Avalonia.Skia
Color = new SKColor(255, 255, 255, (byte)(255 * opacity * _currentOpacity)) Color = new SKColor(255, 255, 255, (byte)(255 * opacity * _currentOpacity))
}) })
{ {
paint.FilterQuality = GetInterpolationMode(bitmapInterpolationMode); paint.FilterQuality = bitmapInterpolationMode.ToSKFilterQuality();
drawableImage.Draw(this, s, d, paint); drawableImage.Draw(this, s, d, paint);
} }
} }
private static SKFilterQuality GetInterpolationMode(BitmapInterpolationMode interpolationMode)
{
switch (interpolationMode)
{
case BitmapInterpolationMode.LowQuality:
return SKFilterQuality.Low;
case BitmapInterpolationMode.MediumQuality:
return SKFilterQuality.Medium;
case BitmapInterpolationMode.HighQuality:
return SKFilterQuality.High;
case BitmapInterpolationMode.Default:
return SKFilterQuality.None;
default:
throw new ArgumentOutOfRangeException(nameof(interpolationMode), interpolationMode, null);
}
}
/// <inheritdoc /> /// <inheritdoc />
public void DrawBitmap(IRef<IBitmapImpl> source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) public void DrawBitmap(IRef<IBitmapImpl> source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
{ {

73
src/Skia/Avalonia.Skia/ImmutableBitmap.cs

@ -1,7 +1,11 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using Avalonia.Media.Imaging;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Skia.Helpers; using Avalonia.Skia.Helpers;
using Avalonia.Visuals.Media.Imaging;
using SkiaSharp; using SkiaSharp;
namespace Avalonia.Skia namespace Avalonia.Skia
@ -36,6 +40,75 @@ namespace Avalonia.Skia
} }
} }
public ImmutableBitmap(ImmutableBitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode)
{
SKImageInfo info = new SKImageInfo(destinationSize.Width, destinationSize.Height, SKColorType.Bgra8888);
SKImage output = SKImage.Create(info);
src._image.ScalePixels(output.PeekPixels(), interpolationMode.ToSKFilterQuality());
_image = output;
PixelSize = new PixelSize(_image.Width, _image.Height);
// TODO: Skia doesn't have an API for DPI.
Dpi = new Vector(96, 96);
}
public ImmutableBitmap(Stream stream, int decodeSize, bool horizontal, BitmapInterpolationMode interpolationMode)
{
using (var skStream = new SKManagedStream(stream))
using (var codec = SKCodec.Create(skStream))
{
var info = codec.Info;
// get the scale that is nearest to what we want (eg: jpg returned 512)
var supportedScale = codec.GetScaledDimensions(horizontal ? ((float)decodeSize / info.Width) : ((float)decodeSize / info.Height));
// decode the bitmap at the nearest size
var nearest = new SKImageInfo(supportedScale.Width, supportedScale.Height);
var bmp = SKBitmap.Decode(codec, nearest);
// now scale that to the size that we want
var realScale = horizontal ? ((double)info.Height / info.Width) : ((double)info.Width / info.Height);
SKImageInfo desired;
if (horizontal)
{
desired = new SKImageInfo(decodeSize, (int)(realScale * decodeSize));
}
else
{
desired = new SKImageInfo((int)(realScale * decodeSize), decodeSize);
}
if (bmp.Width != desired.Width || bmp.Height != desired.Height)
{
if (bmp.Height != bmp.Width)
{
}
var scaledBmp = bmp.Resize(desired, interpolationMode.ToSKFilterQuality());
bmp.Dispose();
bmp = scaledBmp;
}
_image = SKImage.FromBitmap(bmp);
bmp.Dispose();
if (_image == null)
{
throw new ArgumentException("Unable to load bitmap from provided data");
}
PixelSize = new PixelSize(_image.Width, _image.Height);
// TODO: Skia doesn't have an API for DPI.
Dpi = new Vector(96, 96);
}
}
/// <summary> /// <summary>
/// Create immutable bitmap from given pixel data copy. /// Create immutable bitmap from given pixel data copy.
/// </summary> /// </summary>

42
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -1,13 +1,16 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Security.Cryptography;
using System.Linq; using System.Linq;
using Avalonia.Controls.Platform.Surfaces; using Avalonia.Controls.Platform.Surfaces;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.OpenGL; using Avalonia.OpenGL;
using Avalonia.OpenGL.Imaging; using Avalonia.OpenGL.Imaging;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Visuals.Media.Imaging;
using SkiaSharp; using SkiaSharp;
namespace Avalonia.Skia namespace Avalonia.Skia
@ -57,12 +60,6 @@ namespace Avalonia.Skia
return new StreamGeometryImpl(); return new StreamGeometryImpl();
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(Stream stream)
{
return new ImmutableBitmap(stream);
}
/// <inheritdoc /> /// <inheritdoc />
public IBitmapImpl LoadBitmap(string fileName) public IBitmapImpl LoadBitmap(string fileName)
{ {
@ -72,12 +69,43 @@ namespace Avalonia.Skia
} }
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(Stream stream)
{
return new ImmutableBitmap(stream);
}
/// <inheritdoc /> /// <inheritdoc />
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
{ {
return new ImmutableBitmap(size, dpi, stride, format, data); return new ImmutableBitmap(size, dpi, stride, format, data);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return new ImmutableBitmap(stream, width, true, interpolationMode);
}
/// <inheritdoc />
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return new ImmutableBitmap(stream, height, false, interpolationMode);
}
/// <inheritdoc />
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
if (bitmapImpl is ImmutableBitmap ibmp)
{
return new ImmutableBitmap(ibmp, destinationSize, interpolationMode);
}
else
{
throw new Exception("Invalid source bitmap type.");
}
}
/// <inheritdoc /> /// <inheritdoc />
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi) public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi)
{ {

18
src/Skia/Avalonia.Skia/SkiaSharpExtensions.cs

@ -1,12 +1,30 @@
using System; using System;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Visuals.Media.Imaging;
using SkiaSharp; using SkiaSharp;
namespace Avalonia.Skia namespace Avalonia.Skia
{ {
public static class SkiaSharpExtensions public static class SkiaSharpExtensions
{ {
public static SKFilterQuality ToSKFilterQuality(this BitmapInterpolationMode interpolationMode)
{
switch (interpolationMode)
{
case BitmapInterpolationMode.LowQuality:
return SKFilterQuality.Low;
case BitmapInterpolationMode.MediumQuality:
return SKFilterQuality.Medium;
case BitmapInterpolationMode.HighQuality:
return SKFilterQuality.High;
case BitmapInterpolationMode.Default:
return SKFilterQuality.None;
default:
throw new ArgumentOutOfRangeException(nameof(interpolationMode), interpolationMode, null);
}
}
public static SKPoint ToSKPoint(this Point p) public static SKPoint ToSKPoint(this Point p)
{ {
return new SKPoint((float)p.X, (float)p.Y); return new SKPoint((float)p.X, (float)p.Y);

24
src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

@ -7,7 +7,9 @@ using Avalonia.Controls.Platform.Surfaces;
using Avalonia.Direct2D1.Media; using Avalonia.Direct2D1.Media;
using Avalonia.Direct2D1.Media.Imaging; using Avalonia.Direct2D1.Media.Imaging;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Visuals.Media.Imaging;
using SharpDX.DirectWrite; using SharpDX.DirectWrite;
using GlyphRun = Avalonia.Media.GlyphRun; using GlyphRun = Avalonia.Media.GlyphRun;
using TextAlignment = Avalonia.Media.TextAlignment; using TextAlignment = Avalonia.Media.TextAlignment;
@ -179,16 +181,38 @@ namespace Avalonia.Direct2D1
public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect); public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect);
public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl(); public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl();
/// <inheritdoc />
public IBitmapImpl LoadBitmap(string fileName) public IBitmapImpl LoadBitmap(string fileName)
{ {
return new WicBitmapImpl(fileName); return new WicBitmapImpl(fileName);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(Stream stream) public IBitmapImpl LoadBitmap(Stream stream)
{ {
return new WicBitmapImpl(stream); return new WicBitmapImpl(stream);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return new WicBitmapImpl(stream, width, true, interpolationMode);
}
/// <inheritdoc />
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return new WicBitmapImpl(stream, height, false, interpolationMode);
}
/// <inheritdoc />
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
// https://github.com/sharpdx/SharpDX/issues/959 blocks implementation.
throw new NotImplementedException();
}
/// <inheritdoc />
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
{ {
return new WicBitmapImpl(format, data, size, dpi, stride); return new WicBitmapImpl(format, data, size, dpi, stride);

66
src/Windows/Avalonia.Direct2D1/Media/Imaging/WicBitmapImpl.cs

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Security.Cryptography;
using Avalonia.Win32.Interop; using Avalonia.Win32.Interop;
using SharpDX.WIC; using SharpDX.WIC;
using APixelFormat = Avalonia.Platform.PixelFormat; using APixelFormat = Avalonia.Platform.PixelFormat;
@ -14,6 +15,26 @@ namespace Avalonia.Direct2D1.Media
{ {
private BitmapDecoder _decoder; private BitmapDecoder _decoder;
private static BitmapInterpolationMode ConvertInterpolationMode(Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode interpolationMode)
{
switch (interpolationMode)
{
case Visuals.Media.Imaging.BitmapInterpolationMode.Default:
return BitmapInterpolationMode.Fant;
case Visuals.Media.Imaging.BitmapInterpolationMode.LowQuality:
return BitmapInterpolationMode.NearestNeighbor;
case Visuals.Media.Imaging.BitmapInterpolationMode.MediumQuality:
return BitmapInterpolationMode.Fant;
default:
case Visuals.Media.Imaging.BitmapInterpolationMode.HighQuality:
return BitmapInterpolationMode.HighQualityCubic;
}
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WicBitmapImpl"/> class. /// Initializes a new instance of the <see cref="WicBitmapImpl"/> class.
/// </summary> /// </summary>
@ -27,6 +48,12 @@ namespace Avalonia.Direct2D1.Media
} }
} }
private WicBitmapImpl(Bitmap bmp)
{
WicImpl = bmp;
Dpi = new Vector(96, 96);
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WicBitmapImpl"/> class. /// Initializes a new instance of the <see cref="WicBitmapImpl"/> class.
/// </summary> /// </summary>
@ -60,7 +87,7 @@ namespace Avalonia.Direct2D1.Media
size.Height, size.Height,
pixelFormat.Value.ToWic(), pixelFormat.Value.ToWic(),
BitmapCreateCacheOption.CacheOnLoad); BitmapCreateCacheOption.CacheOnLoad);
WicImpl.SetResolution(dpi.X, dpi.Y);
Dpi = dpi; Dpi = dpi;
} }
@ -84,6 +111,43 @@ namespace Avalonia.Direct2D1.Media
} }
} }
public WicBitmapImpl(Stream stream, int decodeSize, bool horizontal, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode interpolationMode)
{
_decoder = new BitmapDecoder(Direct2D1Platform.ImagingFactory, stream, DecodeOptions.CacheOnLoad);
var frame = _decoder.GetFrame(0);
// now scale that to the size that we want
var realScale = horizontal ? ((double)frame.Size.Height / frame.Size.Width) : ((double)frame.Size.Width / frame.Size.Height);
PixelSize desired;
if (horizontal)
{
desired = new PixelSize(decodeSize, (int)(realScale * decodeSize));
}
else
{
desired = new PixelSize((int)(realScale * decodeSize), decodeSize);
}
if (frame.Size.Width != desired.Width || frame.Size.Height != desired.Height)
{
using (var scaler = new BitmapScaler(Direct2D1Platform.ImagingFactory))
{
scaler.Initialize(frame, desired.Width, desired.Height, ConvertInterpolationMode(interpolationMode));
WicImpl = new Bitmap(Direct2D1Platform.ImagingFactory, scaler, BitmapCreateCacheOption.CacheOnLoad);
}
}
else
{
WicImpl = new Bitmap(Direct2D1Platform.ImagingFactory, frame, BitmapCreateCacheOption.CacheOnLoad);
}
Dpi = new Vector(96, 96);
}
public override Vector Dpi { get; } public override Vector Dpi { get; }
public override PixelSize PixelSize => WicImpl.Size.ToAvalonia(); public override PixelSize PixelSize => WicImpl.Size.ToAvalonia();

6
src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs

@ -77,12 +77,6 @@ namespace Avalonia.Win32
s_instances.Remove(this); s_instances.Remove(this);
Closed?.Invoke(); Closed?.Invoke();
if (_parent != null)
{
_parent._disabledBy.Remove(this);
_parent.UpdateEnabled();
}
_mouseDevice.Dispose(); _mouseDevice.Dispose();
_touchDevice?.Dispose(); _touchDevice?.Dispose();
//Free other resources //Free other resources

29
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -45,7 +45,6 @@ namespace Avalonia.Win32
#endif #endif
private const WindowStyles WindowStateMask = (WindowStyles.WS_MAXIMIZE | WindowStyles.WS_MINIMIZE); private const WindowStyles WindowStateMask = (WindowStyles.WS_MAXIMIZE | WindowStyles.WS_MINIMIZE);
private readonly List<WindowImpl> _disabledBy;
private readonly TouchDevice _touchDevice; private readonly TouchDevice _touchDevice;
private readonly MouseDevice _mouseDevice; private readonly MouseDevice _mouseDevice;
private readonly ManagedDeferredRendererLock _rendererLock; private readonly ManagedDeferredRendererLock _rendererLock;
@ -70,7 +69,6 @@ namespace Avalonia.Win32
public WindowImpl() public WindowImpl()
{ {
_disabledBy = new List<WindowImpl>();
_touchDevice = new TouchDevice(); _touchDevice = new TouchDevice();
_mouseDevice = new WindowsMouseDevice(); _mouseDevice = new WindowsMouseDevice();
@ -342,31 +340,25 @@ namespace Avalonia.Win32
public void Hide() public void Hide()
{ {
if (_parent != null)
{
_parent._disabledBy.Remove(this);
_parent.UpdateEnabled();
_parent = null;
}
UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide); UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide);
} }
public virtual void Show() public virtual void Show()
{ {
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, IntPtr.Zero); SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent != null ? _parent._hwnd : IntPtr.Zero);
ShowWindow(_showWindowState); ShowWindow(_showWindowState);
} }
public void ShowDialog(IWindowImpl parent) public Action GotInputWhenDisabled { get; set; }
public void SetParent(IWindowImpl parent)
{ {
_parent = (WindowImpl)parent; _parent = (WindowImpl)parent;
_parent._disabledBy.Add(this); SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent._hwnd);
_parent.UpdateEnabled();
SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, ((WindowImpl)parent)._hwnd);
ShowWindow(_showWindowState);
} }
public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable);
public void BeginMoveDrag(PointerPressedEventArgs e) public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
_mouseDevice.Capture(null); _mouseDevice.Capture(null);
@ -666,7 +658,7 @@ namespace Avalonia.Win32
} }
} }
private WindowStyles GetWindowStateStyles () private WindowStyles GetWindowStateStyles()
{ {
return GetStyle() & WindowStateMask; return GetStyle() & WindowStateMask;
} }
@ -721,11 +713,6 @@ namespace Avalonia.Win32
} }
} }
private void UpdateEnabled()
{
EnableWindow(_hwnd, _disabledBy.Count == 0);
}
private void UpdateWindowProperties(WindowProperties newProperties, bool forceChanges = false) private void UpdateWindowProperties(WindowProperties newProperties, bool forceChanges = false)
{ {
var oldProperties = _windowProperties; var oldProperties = _windowProperties;

339
tests/Avalonia.Animation.UnitTests/AnimatableTests.cs

@ -0,0 +1,339 @@
using System;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Styling;
using Avalonia.UnitTests;
using Moq;
using Xunit;
namespace Avalonia.Animation.UnitTests
{
public class AnimatableTests
{
[Fact]
public void Transition_Is_Not_Applied_When_Not_Attached_To_Visual_Tree()
{
var target = CreateTarget();
var control = new Control
{
Transitions = new Transitions { target.Object },
};
control.Opacity = 0.5;
target.Verify(x => x.Apply(
control,
It.IsAny<IClock>(),
1.0,
0.5),
Times.Never);
}
[Fact]
public void Transition_Is_Not_Applied_To_Initial_Style()
{
using (UnitTestApplication.Start(TestServices.RealStyler))
{
var target = CreateTarget();
var control = new Control
{
Transitions = new Transitions { target.Object },
};
var root = new TestRoot
{
Styles =
{
new Style(x => x.OfType<Control>())
{
Setters =
{
new Setter(Visual.OpacityProperty, 0.8),
}
}
}
};
root.Child = control;
Assert.Equal(0.8, control.Opacity);
target.Verify(x => x.Apply(
It.IsAny<Control>(),
It.IsAny<IClock>(),
It.IsAny<object>(),
It.IsAny<object>()),
Times.Never);
}
}
[Fact]
public void Transition_Is_Applied_When_Local_Value_Changes()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
control.Opacity = 0.5;
target.Verify(x => x.Apply(
control,
It.IsAny<IClock>(),
1.0,
0.5));
}
[Fact]
public void Transition_Is_Not_Applied_When_Animated_Value_Changes()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
control.SetValue(Visual.OpacityProperty, 0.5, BindingPriority.Animation);
target.Verify(x => x.Apply(
control,
It.IsAny<IClock>(),
1.0,
0.5),
Times.Never);
}
[Fact]
public void Transition_Is_Not_Applied_When_StyleTrigger_Changes_With_LocalValue_Present()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
control.SetValue(Visual.OpacityProperty, 0.5);
target.Verify(x => x.Apply(
control,
It.IsAny<IClock>(),
1.0,
0.5));
target.ResetCalls();
control.SetValue(Visual.OpacityProperty, 0.8, BindingPriority.StyleTrigger);
target.Verify(x => x.Apply(
It.IsAny<Control>(),
It.IsAny<IClock>(),
It.IsAny<object>(),
It.IsAny<object>()),
Times.Never);
}
[Fact]
public void Transition_Is_Disposed_When_Local_Value_Changes()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
var sub = new Mock<IDisposable>();
target.Setup(x => x.Apply(control, It.IsAny<IClock>(), 1.0, 0.5)).Returns(sub.Object);
control.Opacity = 0.5;
sub.ResetCalls();
control.Opacity = 0.4;
sub.Verify(x => x.Dispose());
}
[Fact]
public void New_Transition_Is_Applied_When_Local_Value_Changes()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
target.Setup(x => x.Property).Returns(Visual.OpacityProperty);
target.Setup(x => x.Apply(control, It.IsAny<IClock>(), 1.0, 0.5))
.Callback(() =>
{
control.SetValue(Visual.OpacityProperty, 0.9, BindingPriority.Animation);
})
.Returns(Mock.Of<IDisposable>());
control.Opacity = 0.5;
Assert.Equal(0.9, control.Opacity);
target.ResetCalls();
control.Opacity = 0.4;
target.Verify(x => x.Apply(
control,
It.IsAny<IClock>(),
0.9,
0.4));
}
[Fact]
public void Transition_Is_Not_Applied_When_Removed_From_Visual_Tree()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
control.Opacity = 0.5;
target.Verify(x => x.Apply(
control,
It.IsAny<IClock>(),
1.0,
0.5));
target.ResetCalls();
var root = (TestRoot)control.Parent;
root.Child = null;
control.Opacity = 0.8;
target.Verify(x => x.Apply(
It.IsAny<Control>(),
It.IsAny<IClock>(),
It.IsAny<object>(),
It.IsAny<object>()),
Times.Never);
}
[Fact]
public void Animation_Is_Cancelled_When_Transition_Removed()
{
var target = CreateTarget();
var control = CreateControl(target.Object);
var sub = new Mock<IDisposable>();
target.Setup(x => x.Apply(
It.IsAny<Animatable>(),
It.IsAny<IClock>(),
It.IsAny<object>(),
It.IsAny<object>())).Returns(sub.Object);
control.Opacity = 0.5;
control.Transitions.RemoveAt(0);
sub.Verify(x => x.Dispose());
}
[Fact]
public void Animation_Is_Cancelled_When_New_Style_Activates()
{
using (UnitTestApplication.Start(TestServices.RealStyler))
{
var target = CreateTarget();
var control = CreateStyledControl(target.Object);
var sub = new Mock<IDisposable>();
target.Setup(x => x.Apply(
control,
It.IsAny<IClock>(),
1.0,
0.5)).Returns(sub.Object);
control.Opacity = 0.5;
target.Verify(x => x.Apply(
control,
It.IsAny<Clock>(),
1.0,
0.5),
Times.Once);
control.Classes.Add("foo");
sub.Verify(x => x.Dispose());
}
}
[Fact]
public void Transition_From_Style_Trigger_Is_Applied()
{
using (UnitTestApplication.Start(TestServices.RealStyler))
{
var target = CreateTransition(Control.WidthProperty);
var control = CreateStyledControl(transition2: target.Object);
var sub = new Mock<IDisposable>();
control.Classes.Add("foo");
control.Width = 100;
target.Verify(x => x.Apply(
control,
It.IsAny<Clock>(),
double.NaN,
100.0),
Times.Once);
}
}
private static Mock<ITransition> CreateTarget()
{
return CreateTransition(Visual.OpacityProperty);
}
private static Control CreateControl(ITransition transition)
{
var control = new Control
{
Transitions = new Transitions { transition },
};
var root = new TestRoot(control);
return control;
}
private static Control CreateStyledControl(
ITransition transition1 = null,
ITransition transition2 = null)
{
transition1 = transition1 ?? CreateTarget().Object;
transition2 = transition2 ?? CreateTransition(Control.WidthProperty).Object;
var control = new Control
{
Styles =
{
new Style(x => x.OfType<Control>())
{
Setters =
{
new Setter
{
Property = Control.TransitionsProperty,
Value = new Transitions { transition1 },
}
}
},
new Style(x => x.OfType<Control>().Class("foo"))
{
Setters =
{
new Setter
{
Property = Control.TransitionsProperty,
Value = new Transitions { transition2 },
}
}
}
}
};
var root = new TestRoot(control);
return control;
}
private static Mock<ITransition> CreateTransition(AvaloniaProperty property)
{
var target = new Mock<ITransition>();
var sub = new Mock<IDisposable>();
target.Setup(x => x.Property).Returns(property);
target.Setup(x => x.Apply(
It.IsAny<Animatable>(),
It.IsAny<IClock>(),
It.IsAny<object>(),
It.IsAny<object>())).Returns(sub.Object);
return target;
}
}
}

4
tests/Avalonia.Animation.UnitTests/TransitionsTests.cs

@ -16,7 +16,7 @@ namespace Avalonia.Animation.UnitTests
{ {
var border = new Border var border = new Border
{ {
Transitions = Transitions = new Transitions
{ {
new DoubleTransition new DoubleTransition
{ {
@ -44,7 +44,7 @@ namespace Avalonia.Animation.UnitTests
{ {
var border = new Border var border = new Border
{ {
Transitions = Transitions = new Transitions
{ {
new DoubleTransition new DoubleTransition
{ {

51
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_GetValue.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Reactive.Subjects; using System.Reactive.Subjects;
using Avalonia.Data;
using Xunit; using Xunit;
namespace Avalonia.Base.UnitTests namespace Avalonia.Base.UnitTests
@ -63,6 +64,56 @@ namespace Avalonia.Base.UnitTests
Assert.Equal("foodefault", target.GetValue(Class1.FooProperty)); Assert.Equal("foodefault", target.GetValue(Class1.FooProperty));
} }
[Fact]
public void GetBaseValue_LocalValue_Ignores_Default_Value()
{
var target = new Class3();
target.SetValue(Class1.FooProperty, "animated", BindingPriority.Animation);
Assert.False(target.GetBaseValue(Class1.FooProperty, BindingPriority.LocalValue).HasValue);
}
[Fact]
public void GetBaseValue_LocalValue_Returns_Local_Value()
{
var target = new Class3();
target.SetValue(Class1.FooProperty, "local");
target.SetValue(Class1.FooProperty, "animated", BindingPriority.Animation);
Assert.Equal("local", target.GetBaseValue(Class1.FooProperty, BindingPriority.LocalValue).Value);
}
[Fact]
public void GetBaseValue_LocalValue_Returns_Style_Value()
{
var target = new Class3();
target.SetValue(Class1.FooProperty, "style", BindingPriority.Style);
target.SetValue(Class1.FooProperty, "animated", BindingPriority.Animation);
Assert.Equal("style", target.GetBaseValue(Class1.FooProperty, BindingPriority.LocalValue).Value);
}
[Fact]
public void GetBaseValue_Style_Ignores_LocalValue_Animated_Value()
{
var target = new Class3();
target.Bind(Class1.FooProperty, new BehaviorSubject<string>("animated"), BindingPriority.Animation);
target.SetValue(Class1.FooProperty, "local");
Assert.False(target.GetBaseValue(Class1.FooProperty, BindingPriority.Style).HasValue);
}
[Fact]
public void GetBaseValue_Style_Returns_Style_Value()
{
var target = new Class3();
target.SetValue(Class1.FooProperty, "local");
target.SetValue(Class1.FooProperty, "style", BindingPriority.Style);
target.Bind(Class1.FooProperty, new BehaviorSubject<string>("animated"), BindingPriority.Animation);
Assert.Equal("style", target.GetBaseValue(Class1.FooProperty, BindingPriority.Style));
}
private class Class1 : AvaloniaObject private class Class1 : AvaloniaObject
{ {
public static readonly StyledProperty<string> FooProperty = public static readonly StyledProperty<string> FooProperty =

142
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_OnPropertyChanged.cs

@ -0,0 +1,142 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Avalonia.Data;
using Xunit;
namespace Avalonia.Base.UnitTests
{
public class AvaloniaObjectTests_OnPropertyChanged
{
[Fact]
public void OnPropertyChangedCore_Is_Called_On_Property_Change()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "newvalue");
Assert.Equal(1, target.CoreChanges.Count);
var change = (AvaloniaPropertyChangedEventArgs<string>)target.CoreChanges[0];
Assert.Equal("newvalue", change.NewValue.Value);
Assert.Equal("foodefault", change.OldValue.Value);
Assert.Equal(BindingPriority.LocalValue, change.Priority);
Assert.True(change.IsEffectiveValueChange);
}
[Fact]
public void OnPropertyChangedCore_Is_Called_On_Non_Effective_Property_Value_Change()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "newvalue");
target.SetValue(Class1.FooProperty, "styled", BindingPriority.Style);
Assert.Equal(2, target.CoreChanges.Count);
var change = (AvaloniaPropertyChangedEventArgs<string>)target.CoreChanges[1];
Assert.Equal("styled", change.NewValue.Value);
Assert.False(change.OldValue.HasValue);
Assert.Equal(BindingPriority.Style, change.Priority);
Assert.False(change.IsEffectiveValueChange);
}
[Fact]
public void OnPropertyChangedCore_Is_Called_On_All_Binding_Property_Changes()
{
var target = new Class1();
var style = new Subject<BindingValue<string>>();
var animation = new Subject<BindingValue<string>>();
var templatedParent = new Subject<BindingValue<string>>();
target.Bind(Class1.FooProperty, style, BindingPriority.Style);
target.Bind(Class1.FooProperty, animation, BindingPriority.Animation);
target.Bind(Class1.FooProperty, templatedParent, BindingPriority.TemplatedParent);
style.OnNext("style1");
templatedParent.OnNext("tp1");
animation.OnNext("a1");
templatedParent.OnNext("tp2");
templatedParent.OnCompleted();
animation.OnNext("a2");
style.OnNext("style2");
style.OnCompleted();
animation.OnCompleted();
var changes = target.CoreChanges.Cast<AvaloniaPropertyChangedEventArgs<string>>();
Assert.Equal(
new[] { true, true, true, false, false, true, false, false, true },
changes.Select(x => x.IsEffectiveValueChange).ToList());
Assert.Equal(
new[] { "style1", "tp1", "a1", "tp2", "$unset", "a2", "style2", "$unset", "foodefault" },
changes.Select(x => x.NewValue.GetValueOrDefault("$unset")).ToList());
Assert.Equal(
new[] { "foodefault", "style1", "tp1", "$unset", "$unset", "a1", "$unset", "$unset", "a2" },
changes.Select(x => x.OldValue.GetValueOrDefault("$unset")).ToList());
}
[Fact]
public void OnPropertyChanged_Is_Called_Only_For_Effective_Value_Changes()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "newvalue");
target.SetValue(Class1.FooProperty, "styled", BindingPriority.Style);
Assert.Equal(1, target.Changes.Count);
Assert.Equal(2, target.CoreChanges.Count);
}
private class Class1 : AvaloniaObject
{
public static readonly StyledProperty<string> FooProperty =
AvaloniaProperty.Register<Class1, string>("Foo", "foodefault");
public Class1()
{
Changes = new List<AvaloniaPropertyChangedEventArgs>();
CoreChanges = new List<AvaloniaPropertyChangedEventArgs>();
}
public List<AvaloniaPropertyChangedEventArgs> Changes { get; }
public List<AvaloniaPropertyChangedEventArgs> CoreChanges { get; }
protected override void OnPropertyChangedCore<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
CoreChanges.Add(Clone(change));
base.OnPropertyChangedCore(change);
}
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
Changes.Add(Clone(change));
base.OnPropertyChanged(change);
}
private static AvaloniaPropertyChangedEventArgs<T> Clone<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
var result = new AvaloniaPropertyChangedEventArgs<T>(
change.Sender,
change.Property,
change.OldValue,
change.NewValue,
change.Priority);
if (!change.IsEffectiveValueChange)
{
result.MarkNonEffectiveValue();
}
return result;
}
}
}
}

39
tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Utilities; using Avalonia.Utilities;
using Xunit; using Xunit;
@ -88,6 +89,30 @@ namespace Avalonia.Base.UnitTests
Assert.Equal("newvalue", value); Assert.Equal("newvalue", value);
} }
[Fact]
public void Changed_Observable_Fired_Only_On_Effective_Value_Change()
{
var target = new Class1();
var result = new List<string>();
Class1.FooProperty.Changed.Subscribe(x => result.Add((string)x.NewValue));
target.SetValue(Class1.FooProperty, "animated", BindingPriority.Animation);
target.SetValue(Class1.FooProperty, "local");
Assert.Equal(new[] { "animated" }, result);
}
[Fact]
public void Notify_Fired_Only_On_Effective_Value_Change()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "animated", BindingPriority.Animation);
target.SetValue(Class1.FooProperty, "local");
Assert.Equal(2, target.NotifyCount);
}
[Fact] [Fact]
public void Property_Equals_Should_Handle_Null() public void Property_Equals_Should_Handle_Null()
{ {
@ -144,6 +169,11 @@ namespace Avalonia.Base.UnitTests
throw new NotImplementedException(); throw new NotImplementedException();
} }
internal override object RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority)
{
throw new NotImplementedException();
}
internal override void RouteInheritanceParentChanged(AvaloniaObject o, IAvaloniaObject oldParent) internal override void RouteInheritanceParentChanged(AvaloniaObject o, IAvaloniaObject oldParent)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -161,7 +191,14 @@ namespace Avalonia.Base.UnitTests
private class Class1 : AvaloniaObject private class Class1 : AvaloniaObject
{ {
public static readonly StyledProperty<string> FooProperty = public static readonly StyledProperty<string> FooProperty =
AvaloniaProperty.Register<Class1, string>("Foo", "default"); AvaloniaProperty.Register<Class1, string>("Foo", "default", notifying: FooNotifying);
public int NotifyCount { get; private set; }
private static void FooNotifying(IAvaloniaObject o, bool n)
{
++((Class1)o).NotifyCount;
}
} }
private class Class2 : Class1 private class Class2 : Class1

98
tests/Avalonia.Base.UnitTests/PriorityValueTests.cs

@ -10,7 +10,7 @@ namespace Avalonia.Base.UnitTests
{ {
public class PriorityValueTests public class PriorityValueTests
{ {
private static readonly IValueSink NullSink = Mock.Of<IValueSink>(); private static readonly IValueSink NullSink = new MockSink();
private static readonly IAvaloniaObject Owner = Mock.Of<IAvaloniaObject>(); private static readonly IAvaloniaObject Owner = Mock.Of<IAvaloniaObject>();
private static readonly StyledProperty<string> TestProperty = new StyledProperty<string>( private static readonly StyledProperty<string> TestProperty = new StyledProperty<string>(
"Test", "Test",
@ -30,8 +30,28 @@ namespace Avalonia.Base.UnitTests
BindingPriority.StyleTrigger, BindingPriority.StyleTrigger,
NullSink)); NullSink));
Assert.Equal("1", target.Value.Value); Assert.Equal("1", target.GetValue().Value);
Assert.Equal(BindingPriority.StyleTrigger, target.ValuePriority); Assert.Equal(BindingPriority.StyleTrigger, target.Priority);
}
[Fact]
public void GetValue_Should_Respect_MaxPriority()
{
var target = new PriorityValue<string>(
Owner,
TestProperty,
NullSink);
target.SetValue("animation", BindingPriority.Animation);
target.SetValue("local", BindingPriority.LocalValue);
target.SetValue("styletrigger", BindingPriority.StyleTrigger);
target.SetValue("style", BindingPriority.Style);
Assert.Equal("animation", target.GetValue(BindingPriority.Animation));
Assert.Equal("local", target.GetValue(BindingPriority.LocalValue));
Assert.Equal("styletrigger", target.GetValue(BindingPriority.StyleTrigger));
Assert.Equal("style", target.GetValue(BindingPriority.TemplatedParent));
Assert.Equal("style", target.GetValue(BindingPriority.Style));
} }
[Fact] [Fact]
@ -61,12 +81,31 @@ namespace Avalonia.Base.UnitTests
var result = target.Entries var result = target.Entries
.OfType<ConstantValueEntry<string>>() .OfType<ConstantValueEntry<string>>()
.Select(x => x.Value.Value) .Select(x => x.GetValue().Value)
.ToList(); .ToList();
Assert.Equal(new[] { "1", "2" }, result); Assert.Equal(new[] { "1", "2" }, result);
} }
[Fact]
public void Priority_Should_Be_Set()
{
var target = new PriorityValue<string>(
Owner,
TestProperty,
NullSink);
Assert.Equal(BindingPriority.Unset, target.Priority);
target.SetValue("style", BindingPriority.Style);
Assert.Equal(BindingPriority.Style, target.Priority);
target.SetValue("local", BindingPriority.LocalValue);
Assert.Equal(BindingPriority.LocalValue, target.Priority);
target.SetValue("animation", BindingPriority.Animation);
Assert.Equal(BindingPriority.Animation, target.Priority);
target.SetValue("local2", BindingPriority.LocalValue);
Assert.Equal(BindingPriority.Animation, target.Priority);
}
[Fact] [Fact]
public void Binding_With_Same_Priority_Should_Be_Appended() public void Binding_With_Same_Priority_Should_Be_Appended()
{ {
@ -184,7 +223,7 @@ namespace Avalonia.Base.UnitTests
target.AddBinding(source2, BindingPriority.Style).Start(); target.AddBinding(source2, BindingPriority.Style).Start();
target.AddBinding(source3, BindingPriority.Style).Start(); target.AddBinding(source3, BindingPriority.Style).Start();
Assert.Equal("1", target.Value.Value); Assert.Equal("1", target.GetValue().Value);
} }
[Fact] [Fact]
@ -196,7 +235,7 @@ namespace Avalonia.Base.UnitTests
target.AddBinding(source1, BindingPriority.LocalValue).Start(); target.AddBinding(source1, BindingPriority.LocalValue).Start();
target.SetValue("2", BindingPriority.LocalValue); target.SetValue("2", BindingPriority.LocalValue);
Assert.Equal("2", target.Value.Value); Assert.Equal("2", target.GetValue().Value);
} }
[Fact] [Fact]
@ -208,7 +247,7 @@ namespace Avalonia.Base.UnitTests
target.AddBinding(source1, BindingPriority.Style).Start(); target.AddBinding(source1, BindingPriority.Style).Start();
target.SetValue("2", BindingPriority.LocalValue); target.SetValue("2", BindingPriority.LocalValue);
Assert.Equal("2", target.Value.Value); Assert.Equal("2", target.GetValue().Value);
} }
[Fact] [Fact]
@ -220,7 +259,39 @@ namespace Avalonia.Base.UnitTests
target.AddBinding(source1, BindingPriority.Animation).Start(); target.AddBinding(source1, BindingPriority.Animation).Start();
target.SetValue("2", BindingPriority.LocalValue); target.SetValue("2", BindingPriority.LocalValue);
Assert.Equal("1", target.Value.Value); Assert.Equal("1", target.GetValue().Value);
}
[Fact]
public void NonAnimated_Value_Should_Be_Correct_1()
{
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
var source3 = new Source("3");
target.AddBinding(source1, BindingPriority.LocalValue).Start();
target.AddBinding(source2, BindingPriority.Style).Start();
target.AddBinding(source3, BindingPriority.Animation).Start();
Assert.Equal("3", target.GetValue().Value);
Assert.Equal("1", target.GetValue(BindingPriority.LocalValue).Value);
}
[Fact]
public void NonAnimated_Value_Should_Be_Correct_2()
{
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
var source3 = new Source("3");
target.AddBinding(source1, BindingPriority.Animation).Start();
target.AddBinding(source2, BindingPriority.Style).Start();
target.AddBinding(source3, BindingPriority.Style).Start();
Assert.Equal("1", target.GetValue().Value);
Assert.Equal("3", target.GetValue(BindingPriority.LocalValue).Value);
} }
private class Source : IObservable<BindingValue<string>> private class Source : IObservable<BindingValue<string>>
@ -239,5 +310,16 @@ namespace Avalonia.Base.UnitTests
public void OnCompleted() => _observer.OnCompleted(); public void OnCompleted() => _observer.OnCompleted();
} }
private class MockSink : IValueSink
{
public void Completed<T>(StyledPropertyBase<T> property, IPriorityValueEntry entry, Optional<T> oldValue)
{
}
public void ValueChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
}
}
} }
} }

16
tests/Avalonia.Benchmarks/NullRenderingPlatform.cs

@ -4,6 +4,7 @@ using System.IO;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Avalonia.Visuals.Media.Imaging;
namespace Avalonia.Benchmarks namespace Avalonia.Benchmarks
{ {
@ -65,6 +66,21 @@ namespace Avalonia.Benchmarks
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IFontManagerImpl CreateFontManager() public IFontManagerImpl CreateFontManager()
{ {
return new MockFontManagerImpl(); return new MockFontManagerImpl();

4
tests/Avalonia.Controls.UnitTests/Shapes/PathTests.cs

@ -23,12 +23,16 @@ namespace Avalonia.Controls.UnitTests.Shapes
var geometry = new EllipseGeometry { Rect = new Rect(0, 0, 10, 10) }; var geometry = new EllipseGeometry { Rect = new Rect(0, 0, 10, 10) };
var target = new Path { Data = geometry }; var target = new Path { Data = geometry };
var root = new TestRoot(target);
target.Measure(Size.Infinity); target.Measure(Size.Infinity);
Assert.True(target.IsMeasureValid); Assert.True(target.IsMeasureValid);
geometry.Rect = new Rect(0, 0, 20, 20); geometry.Rect = new Rect(0, 0, 20, 20);
Assert.False(target.IsMeasureValid); Assert.False(target.IsMeasureValid);
root.Child = null;
} }
} }
} }

5
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -322,10 +322,9 @@ namespace Avalonia.Controls.UnitTests
{ {
var window = new Window(); var window = new Window();
window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.Position = new PixelPoint(60, 40); window.Position = new PixelPoint(60, 40);
window.Owner = parentWindow;
window.Show(); window.ShowDialog(parentWindow);
var expectedPosition = new PixelPoint( var expectedPosition = new PixelPoint(
(int)(parentWindow.Position.X + parentWindow.ClientSize.Width / 2 - window.ClientSize.Width / 2), (int)(parentWindow.Position.X + parentWindow.ClientSize.Width / 2 - window.ClientSize.Width / 2),

40
tests/Avalonia.LeakTests/ControlTests.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Remoting.Contexts; using System.Runtime.Remoting.Contexts;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Diagnostics; using Avalonia.Diagnostics;
using Avalonia.Input; using Avalonia.Input;
@ -492,6 +493,45 @@ namespace Avalonia.LeakTests
} }
} }
[Fact]
public void Path_Is_Freed()
{
using (Start())
{
var geometry = new EllipseGeometry { Rect = new Rect(0, 0, 10, 10) };
Func<Window> run = () =>
{
var window = new Window
{
Content = new Path
{
Data = geometry
}
};
window.Show();
window.LayoutManager.ExecuteInitialLayoutPass(window);
Assert.IsType<Path>(window.Presenter.Child);
window.Content = null;
window.LayoutManager.ExecuteLayoutPass();
Assert.Null(window.Presenter.Child);
return window;
};
var result = run();
dotMemory.Check(memory =>
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Path>()).ObjectsCount));
// We are keeping geometry alive to simulate a resource that outlives the control.
GC.KeepAlive(geometry);
}
}
private IDisposable Start() private IDisposable Start()
{ {
return UnitTestApplication.Start(TestServices.StyledWindow.With( return UnitTestApplication.Start(TestServices.StyledWindow.With(

6
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/InitializationOrderTracker.cs

@ -18,10 +18,10 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
base.OnAttachedToLogicalTree(e); base.OnAttachedToLogicalTree(e);
} }
protected override void OnPropertyChanged<T>(AvaloniaProperty<T> property, Optional<T> oldValue, BindingValue<T> newValue, BindingPriority priority) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
Order.Add($"Property {property.Name} Changed"); Order.Add($"Property {change.Property.Name} Changed");
base.OnPropertyChanged(property, oldValue, newValue, priority); base.OnPropertyChanged(change);
} }
void ISupportInitialize.BeginInit() void ISupportInitialize.BeginInit()

45
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs

@ -337,5 +337,50 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
Assert.Equal(Brushes.Red, listBox.Background); Assert.Equal(Brushes.Red, listBox.Background);
} }
} }
[Fact]
public void Transitions_Can_Be_Styled()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Styles>
<Style Selector='Border'>
<Setter Property='Transitions'>
<Transitions>
<DoubleTransition Property='Width' Duration='0:0:1'/>
</Transitions>
</Setter>
</Style>
<Style Selector='Border.foo'>
<Setter Property='Transitions'>
<Transitions>
<DoubleTransition Property='Height' Duration='0:0:1'/>
</Transitions>
</Setter>
</Style>
</Window.Styles>
<Border/>
</Window>";
var loader = new AvaloniaXamlLoader();
var window = (Window)loader.Load(xaml);
var border = (Border)window.Content;
Assert.Equal(1, border.Transitions.Count);
Assert.Equal(Border.WidthProperty, border.Transitions[0].Property);
border.Classes.Add("foo");
Assert.Equal(1, border.Transitions.Count);
Assert.Equal(Border.HeightProperty, border.Transitions[0].Property);
border.Classes.Remove("foo");
Assert.Equal(1, border.Transitions.Count);
Assert.Equal(Border.WidthProperty, border.Transitions[0].Property);
}
}
} }
} }

8
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs

@ -34,9 +34,11 @@ namespace Avalonia.Markup.Xaml.UnitTests
var parsed = (Grid)AvaloniaXamlLoader.Parse(@" var parsed = (Grid)AvaloniaXamlLoader.Parse(@"
<Grid xmlns='https://github.com/avaloniaui' > <Grid xmlns='https://github.com/avaloniaui' >
<Grid.Transitions> <Grid.Transitions>
<DoubleTransition Property='Opacity' <Transitions>
Easing='CircularEaseIn' <DoubleTransition Property='Opacity'
Duration='0:0:0.5' /> Easing='CircularEaseIn'
Duration='0:0:0.5' />
</Transitions>
</Grid.Transitions> </Grid.Transitions>
</Grid>"); </Grid>");
Assert.Equal(1, parsed.Transitions.Count); Assert.Equal(1, parsed.Transitions.Count);

16
tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Visuals.Media.Imaging;
using Moq; using Moq;
namespace Avalonia.UnitTests namespace Avalonia.UnitTests
@ -69,6 +70,21 @@ namespace Avalonia.UnitTests
return Mock.Of<IBitmapImpl>(); return Mock.Of<IBitmapImpl>();
} }
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return Mock.Of<IBitmapImpl>();
}
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return Mock.Of<IBitmapImpl>();
}
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return Mock.Of<IBitmapImpl>();
}
public IBitmapImpl LoadBitmap( public IBitmapImpl LoadBitmap(
PixelFormat format, PixelFormat format,
IntPtr data, IntPtr data,

19
tests/Avalonia.Visuals.UnitTests/RectTests.cs

@ -35,5 +35,24 @@ namespace Avalonia.Visuals.UnitTests
Assert.Equal(new Rect(0, 0, 100, 100), result); Assert.Equal(new Rect(0, 0, 100, 100), result);
} }
[Fact]
public void Normalize_Should_Reverse_Negative_Size()
{
var result = new Rect(new Point(100, 100), new Point(0, 0)).Normalize();
Assert.Equal(new Rect(0, 0, 100, 100), result);
}
[Fact]
public void Normalize_Should_Make_Invalid_Rects_Empty()
{
var result = new Rect(
double.NegativeInfinity, double.PositiveInfinity,
double.PositiveInfinity, double.PositiveInfinity)
.Normalize();
Assert.Equal(Rect.Empty, result);
}
} }
} }

8
tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests.cs

@ -36,7 +36,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
} }
} }
[Fact] [Fact(Skip = "https://github.com/moq/moq4/issues/988")]
public void AddDirty_With_RenderTransform_Call_RenderRoot_Invalidate() public void AddDirty_With_RenderTransform_Call_RenderRoot_Invalidate()
{ {
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
@ -59,7 +59,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
} }
} }
[Fact] [Fact(Skip = "https://github.com/moq/moq4/issues/988")]
public void AddDirty_For_Child_Moved_Should_Invalidate_Previous_Bounds() public void AddDirty_For_Child_Moved_Should_Invalidate_Previous_Bounds()
{ {
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
@ -111,7 +111,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
} }
} }
[Fact] [Fact(Skip = "https://github.com/moq/moq4/issues/988")]
public void Should_Render_Child_In_Parent_With_RenderTransform() public void Should_Render_Child_In_Parent_With_RenderTransform()
{ {
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
@ -145,7 +145,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
} }
} }
[Fact] [Fact(Skip = "https://github.com/moq/moq4/issues/988")]
public void Should_Render_Child_In_Parent_With_RenderTransform2() public void Should_Render_Child_In_Parent_With_RenderTransform2()
{ {
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))

16
tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs

@ -4,6 +4,7 @@ using System.IO;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Avalonia.Visuals.Media.Imaging;
namespace Avalonia.Visuals.UnitTests.VisualTree namespace Avalonia.Visuals.UnitTests.VisualTree
{ {
@ -83,6 +84,21 @@ namespace Avalonia.Visuals.UnitTests.VisualTree
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
class MockStreamGeometry : IStreamGeometryImpl class MockStreamGeometry : IStreamGeometryImpl
{ {
private MockStreamGeometryContext _impl = new MockStreamGeometryContext(); private MockStreamGeometryContext _impl = new MockStreamGeometryContext();

Loading…
Cancel
Save