Browse Source

Obsolete protected Logical/VisualChildren properties.

feature/ilogicalvisualchildren
Steven Kirk 4 years ago
parent
commit
007e47a8a3
  1. 2
      src/Avalonia.Base/Input/InputElement.cs
  2. 4
      src/Avalonia.Base/Layout/Layoutable.cs
  3. 9
      src/Avalonia.Base/StyledElement.cs
  4. 5
      src/Avalonia.Base/Visual.cs
  5. 6
      src/Avalonia.Controls/ContentControl.cs
  6. 2
      src/Avalonia.Controls/ContextMenu.cs
  7. 8
      src/Avalonia.Controls/Decorator.cs
  8. 2
      src/Avalonia.Controls/Grid.cs
  9. 10
      src/Avalonia.Controls/ItemsControl.cs
  10. 4
      src/Avalonia.Controls/MenuItem.cs
  11. 4
      src/Avalonia.Controls/Notifications/WindowNotificationManager.cs
  12. 10
      src/Avalonia.Controls/Presenters/ContentPresenter.cs
  13. 8
      src/Avalonia.Controls/Presenters/ItemsPresenterBase.cs
  14. 4
      src/Avalonia.Controls/Primitives/HeaderedContentControl.cs
  15. 6
      src/Avalonia.Controls/Primitives/HeaderedItemsControl.cs
  16. 6
      src/Avalonia.Controls/Primitives/HeaderedSelectingItemsControl.cs
  17. 4
      src/Avalonia.Controls/Primitives/Popup.cs
  18. 23
      src/Avalonia.Controls/Primitives/TemplatedControl.cs
  19. 16
      src/Avalonia.Controls/Primitives/Track.cs
  20. 2
      src/Avalonia.Controls/Primitives/VisualLayerManager.cs
  21. 2
      src/Avalonia.Controls/TabControl.cs
  22. 8
      src/Avalonia.Controls/ToggleSwitch.cs
  23. 6
      tests/Avalonia.Base.UnitTests/Interactivity/InteractiveTests.cs
  24. 12
      tests/Avalonia.Base.UnitTests/TestVisual.cs
  25. 2
      tests/Avalonia.Controls.UnitTests/TestTemplatedControl.cs

2
src/Avalonia.Base/Input/InputElement.cs

@ -682,7 +682,7 @@ namespace Avalonia.Input
// PERF-SENSITIVE: This is called on entire hierarchy and using foreach or LINQ
// will cause extra allocations and overhead.
var children = VisualChildren;
var children = Children.Visual;
// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < children.Count; ++i)

4
src/Avalonia.Base/Layout/Layoutable.cs

@ -613,7 +613,7 @@ namespace Avalonia.Layout
double width = 0;
double height = 0;
var visualChildren = VisualChildren;
var visualChildren = Children.Visual;
var visualCount = visualChildren.Count;
for (var i = 0; i < visualCount; i++)
@ -716,7 +716,7 @@ namespace Avalonia.Layout
{
var arrangeRect = new Rect(finalSize);
var visualChildren = VisualChildren;
var visualChildren = Children.Visual;
var visualCount = visualChildren.Count;
for (var i = 0; i < visualCount; i++)

9
src/Avalonia.Base/StyledElement.cs

@ -235,6 +235,7 @@ namespace Avalonia
/// <summary>
/// Gets the styled element's logical children.
/// </summary>
[Obsolete("Use Children.Logical or Children.LogicalMutable property")]
protected IList<ILogical> LogicalChildren => Children.LogicalMutable;
/// <summary>
@ -589,12 +590,12 @@ namespace Avalonia
element._dataContextUpdating = true;
element.OnDataContextBeginUpdate();
var logicalChildren = element.LogicalChildren;
var logicalChildren = element.Children.Logical;
var logicalChildrenCount = logicalChildren.Count;
for (var i = 0; i < logicalChildrenCount; i++)
{
if (element.LogicalChildren[i] is StyledElement s &&
if (logicalChildren[i] is StyledElement s &&
s.InheritanceParent == element &&
!s.IsSet(DataContextProperty))
{
@ -653,7 +654,7 @@ namespace Avalonia
AttachedToLogicalTree?.Invoke(this, e);
}
var logicalChildren = LogicalChildren;
var logicalChildren = Children.Logical;
var logicalChildrenCount = logicalChildren.Count;
for (var i = 0; i < logicalChildrenCount; i++)
@ -674,7 +675,7 @@ namespace Avalonia
OnDetachedFromLogicalTree(e);
DetachedFromLogicalTree?.Invoke(this, e);
var logicalChildren = LogicalChildren;
var logicalChildren = Children.Logical;
var logicalChildrenCount = logicalChildren.Count;
for (var i = 0; i < logicalChildrenCount; i++)

5
src/Avalonia.Base/Visual.cs

@ -249,6 +249,7 @@ namespace Avalonia
/// <summary>
/// Gets the control's child visuals.
/// </summary>
[Obsolete("Use Children.Visual or Children.VisualMutable property")]
protected IList<IVisual> VisualChildren => Children.VisualMutable;
/// <summary>
@ -421,7 +422,7 @@ namespace Avalonia
AttachedToVisualTree?.Invoke(this, e);
InvalidateVisual();
var visualChildren = VisualChildren;
var visualChildren = Children.Visual;
if (visualChildren != null)
{
@ -458,7 +459,7 @@ namespace Avalonia
DetachedFromVisualTree?.Invoke(this, e);
e.Root?.Renderer?.AddDirty(this);
var visualChildren = VisualChildren;
var visualChildren = Children.Visual;
if (visualChildren != null)
{

6
src/Avalonia.Controls/ContentControl.cs

@ -92,7 +92,7 @@ namespace Avalonia.Controls
}
/// <inheritdoc/>
IList<ILogical> IContentPresenterHost.LogicalChildren => LogicalChildren;
IList<ILogical> IContentPresenterHost.LogicalChildren => Children.LogicalMutable;
/// <inheritdoc/>
bool IContentPresenterHost.RegisterContentPresenter(IContentPresenter presenter)
@ -119,12 +119,12 @@ namespace Avalonia.Controls
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Children.LogicalMutable.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}
}

2
src/Avalonia.Controls/ContextMenu.cs

@ -384,7 +384,7 @@ namespace Avalonia.Controls
private void PopupClosed(object sender, EventArgs e)
{
foreach (var i in LogicalChildren)
foreach (var i in Children.Logical)
{
if (i is MenuItem menuItem)
{

8
src/Avalonia.Controls/Decorator.cs

@ -73,15 +73,15 @@ namespace Avalonia.Controls
if (oldChild != null)
{
((ISetLogicalParent)oldChild).SetParent(null);
LogicalChildren.Clear();
VisualChildren.Remove(oldChild);
Children.LogicalMutable.Clear();
Children.VisualMutable.Remove(oldChild);
}
if (newChild != null)
{
((ISetLogicalParent)newChild).SetParent(this);
VisualChildren.Add(newChild);
LogicalChildren.Add(newChild);
Children.VisualMutable.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}
}

2
src/Avalonia.Controls/Grid.cs

@ -2329,6 +2329,8 @@ namespace Avalonia.Controls
if (ShowGridLines && (_gridLinesRenderer == null))
{
_gridLinesRenderer = new GridLinesRenderer();
// TODO: Grid requires a visual child that isn't in Children.
this.VisualChildren.Add(_gridLinesRenderer);
}

10
src/Avalonia.Controls/ItemsControl.cs

@ -266,7 +266,7 @@ namespace Avalonia.Controls
// it was added to the Items collection.
if (container.ContainerControl != null && container.ContainerControl != container.Item)
{
LogicalChildren.Add(container.ContainerControl);
Children.LogicalMutable.Add(container.ContainerControl);
}
}
}
@ -284,7 +284,7 @@ namespace Avalonia.Controls
// when it is removed from the Items collection.
if (container?.ContainerControl != container?.Item)
{
LogicalChildren.Remove(container.ContainerControl);
Children.LogicalMutable.Remove(container.ContainerControl);
}
}
}
@ -416,14 +416,14 @@ namespace Avalonia.Controls
{
var control = i as IControl;
if (control != null && !LogicalChildren.Contains(control))
if (control != null && !Children.Logical.Contains(control))
{
toAdd.Add(control);
}
}
}
((IAvaloniaList<ILogical>)LogicalChildren).AddRange(toAdd);
((IAvaloniaList<ILogical>)Children.LogicalMutable).AddRange(toAdd);
}
/// <summary>
@ -447,7 +447,7 @@ namespace Avalonia.Controls
}
}
((IAvaloniaList<ILogical>)LogicalChildren).RemoveAll(toRemove);
((IAvaloniaList<ILogical>)Children.LogicalMutable).RemoveAll(toRemove);
}
/// <summary>

4
src/Avalonia.Controls/MenuItem.cs

@ -602,13 +602,13 @@ namespace Avalonia.Controls
if (oldValue != null)
{
LogicalChildren.Remove(oldValue);
Children.LogicalMutable.Remove(oldValue);
PseudoClasses.Remove(":icon");
}
if (newValue != null)
{
LogicalChildren.Add(newValue);
Children.LogicalMutable.Add(newValue);
PseudoClasses.Add(":icon");
}
}

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

@ -56,7 +56,7 @@ namespace Avalonia.Controls.Notifications
/// <param name="host">The window that will host the control.</param>
public WindowNotificationManager(Window host)
{
if (VisualChildren.Count != 0)
if (Children.Visual.Count != 0)
{
Install(host);
}
@ -168,6 +168,6 @@ namespace Avalonia.Controls.Notifications
PseudoClasses.Set(":bottomright", position == NotificationPosition.BottomRight);
}
public bool HitTest(Point point) => VisualChildren.HitTestCustom(point);
public bool HitTest(Point point) => Children.Visual.HitTestCustom(point);
}
}

10
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@ -256,7 +256,7 @@ namespace Avalonia.Controls.Presenters
var content = Content;
var oldChild = Child;
var newChild = CreateChild();
var logicalChildren = Host?.LogicalChildren ?? LogicalChildren;
var logicalChildren = Host?.LogicalChildren ?? Children.LogicalMutable;
// Remove the old child if we're not recycling it.
if (newChild != oldChild)
@ -264,7 +264,7 @@ namespace Avalonia.Controls.Presenters
if (oldChild != null)
{
VisualChildren.Remove(oldChild);
Children.VisualMutable.Remove(oldChild);
logicalChildren.Remove(oldChild);
((ISetInheritanceParent)oldChild).SetParent(oldChild.Parent);
}
@ -295,7 +295,7 @@ namespace Avalonia.Controls.Presenters
logicalChildren.Add(newChild);
}
VisualChildren.Add(newChild);
Children.VisualMutable.Add(newChild);
}
_createdChild = true;
@ -450,8 +450,8 @@ namespace Avalonia.Controls.Presenters
}
else if (Child != null)
{
VisualChildren.Remove(Child);
LogicalChildren.Remove(Child);
Children.VisualMutable.Remove(Child);
Children.LogicalMutable.Remove(Child);
((ISetInheritanceParent)Child).SetParent(Child.Parent);
Child = null;
_recyclingDataTemplate = null;

8
src/Avalonia.Controls/Presenters/ItemsPresenterBase.cs

@ -238,10 +238,10 @@ namespace Avalonia.Controls.Presenters
Panel = ItemsPanel.Build();
Panel.SetValue(TemplatedParentProperty, TemplatedParent);
LogicalChildren.Clear();
VisualChildren.Clear();
LogicalChildren.Add(Panel);
VisualChildren.Add(Panel);
Children.LogicalMutable.Clear();
Children.VisualMutable.Clear();
Children.LogicalMutable.Add(Panel);
Children.VisualMutable.Add(Panel);
_createdPanel = true;

4
src/Avalonia.Controls/Primitives/HeaderedContentControl.cs

@ -76,12 +76,12 @@ namespace Avalonia.Controls.Primitives
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Children.LogicalMutable.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}
}

6
src/Avalonia.Controls/Primitives/HeaderedItemsControl.cs

@ -44,7 +44,7 @@ namespace Avalonia.Controls.Primitives
}
/// <inheritdoc/>
IList<ILogical> IContentPresenterHost.LogicalChildren => LogicalChildren;
IList<ILogical> IContentPresenterHost.LogicalChildren => Children.LogicalMutable;
/// <inheritdoc/>
bool IContentPresenterHost.RegisterContentPresenter(IContentPresenter presenter)
@ -71,12 +71,12 @@ namespace Avalonia.Controls.Primitives
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Children.LogicalMutable.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}
}

6
src/Avalonia.Controls/Primitives/HeaderedSelectingItemsControl.cs

@ -44,7 +44,7 @@ namespace Avalonia.Controls.Primitives
}
/// <inheritdoc/>
IList<ILogical> IContentPresenterHost.LogicalChildren => LogicalChildren;
IList<ILogical> IContentPresenterHost.LogicalChildren => Children.LogicalMutable;
/// <inheritdoc/>
bool IContentPresenterHost.RegisterContentPresenter(IContentPresenter presenter)
@ -71,12 +71,12 @@ namespace Avalonia.Controls.Primitives
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Children.LogicalMutable.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}
}

4
src/Avalonia.Controls/Primitives/Popup.cs

@ -583,14 +583,14 @@ namespace Avalonia.Controls.Primitives
/// <param name="e">The event args.</param>
private void ChildChanged(AvaloniaPropertyChangedEventArgs e)
{
LogicalChildren.Clear();
Children.LogicalMutable.Clear();
((ISetLogicalParent?)e.OldValue)?.SetParent(null);
if (e.NewValue != null)
{
((ISetLogicalParent)e.NewValue).SetParent(this);
LogicalChildren.Add((ILogical)e.NewValue);
Children.LogicalMutable.Add((ILogical)e.NewValue);
}
}

23
src/Avalonia.Controls/Primitives/TemplatedControl.cs

@ -255,7 +255,7 @@ namespace Avalonia.Controls.Primitives
// and we don't need to do anything.
if (_appliedTemplate != template && (template != null || logical.IsAttachedToLogicalTree))
{
if (VisualChildren.Count > 0)
if (Children.Visual.Count > 0)
{
foreach (var child in this.GetTemplateChildren())
{
@ -263,7 +263,7 @@ namespace Avalonia.Controls.Primitives
((ISetLogicalParent)child).SetParent(null);
}
VisualChildren.Clear();
Children.VisualMutable.Clear();
}
if (template != null)
@ -273,7 +273,7 @@ namespace Avalonia.Controls.Primitives
var (child, nameScope) = template.Build(this);
ApplyTemplatedParent(child);
((ISetLogicalParent)child).SetParent(this);
VisualChildren.Add(child);
Children.VisualMutable.Add(child);
// Existing code kinda expect to see a NameScope even if it's empty
if (nameScope == null)
@ -307,11 +307,12 @@ namespace Avalonia.Controls.Primitives
protected sealed override void NotifyChildResourcesChanged(ResourcesChangedEventArgs e)
{
var count = VisualChildren.Count;
var children = Children.Visual;
var count = children.Count;
for (var i = 0; i < count; ++i)
{
if (VisualChildren[i] is ILogical logical)
if (children[i] is ILogical logical)
{
logical.NotifyResourcesChanged(e);
}
@ -323,9 +324,11 @@ namespace Avalonia.Controls.Primitives
/// <inheritdoc/>
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
if (VisualChildren.Count > 0)
var children = Children.Visual;
if (children.Count > 0)
{
((ILogical)VisualChildren[0]).NotifyAttachedToLogicalTree(e);
((ILogical)children[0]).NotifyAttachedToLogicalTree(e);
}
base.OnAttachedToLogicalTree(e);
@ -334,9 +337,11 @@ namespace Avalonia.Controls.Primitives
/// <inheritdoc/>
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
if (VisualChildren.Count > 0)
var children = Children.Visual;
if (children.Count > 0)
{
((ILogical)VisualChildren[0]).NotifyDetachedFromLogicalTree(e);
((ILogical)children[0]).NotifyDetachedFromLogicalTree(e);
}
base.OnDetachedFromLogicalTree(e);

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

@ -410,15 +410,15 @@ namespace Avalonia.Controls.Primitives
{
oldThumb.DragDelta -= ThumbDragged;
LogicalChildren.Remove(oldThumb);
VisualChildren.Remove(oldThumb);
Children.LogicalMutable.Remove(oldThumb);
Children.VisualMutable.Remove(oldThumb);
}
if (newThumb != null)
{
newThumb.DragDelta += ThumbDragged;
LogicalChildren.Add(newThumb);
VisualChildren.Add(newThumb);
Children.LogicalMutable.Add(newThumb);
Children.VisualMutable.Add(newThumb);
}
}
@ -429,14 +429,14 @@ namespace Avalonia.Controls.Primitives
if (oldButton != null)
{
LogicalChildren.Remove(oldButton);
VisualChildren.Remove(oldButton);
Children.LogicalMutable.Remove(oldButton);
Children.VisualMutable.Remove(oldButton);
}
if (newButton != null)
{
LogicalChildren.Add(newButton);
VisualChildren.Add(newButton);
Children.LogicalMutable.Add(newButton);
Children.VisualMutable.Add(newButton);
}
}

2
src/Avalonia.Controls/Primitives/VisualLayerManager.cs

@ -94,7 +94,7 @@ namespace Avalonia.Controls.Primitives
_layers.Add(layer);
((ISetLogicalParent)layer).SetParent(this);
layer.ZIndex = zindex;
VisualChildren.Add(layer);
Children.VisualMutable.Add(layer);
if (((ILogical)this).IsAttachedToLogicalTree)
((ILogical)layer).NotifyAttachedToLogicalTree(
new LogicalTreeAttachmentEventArgs(_logicalRoot, layer, this));

2
src/Avalonia.Controls/TabControl.cs

@ -136,7 +136,7 @@ namespace Avalonia.Controls
internal IContentPresenter ContentPart { get; private set; }
/// <inheritdoc/>
IList<ILogical> IContentPresenterHost.LogicalChildren => LogicalChildren;
IList<ILogical> IContentPresenterHost.LogicalChildren => Children.LogicalMutable;
/// <inheritdoc/>
bool IContentPresenterHost.RegisterContentPresenter(IContentPresenter presenter)

8
src/Avalonia.Controls/ToggleSwitch.cs

@ -116,12 +116,12 @@ namespace Avalonia.Controls
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Children.LogicalMutable.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}
@ -129,12 +129,12 @@ namespace Avalonia.Controls
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Children.LogicalMutable.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
Children.LogicalMutable.Add(newChild);
}
}

6
tests/Avalonia.Base.UnitTests/Interactivity/InteractiveTests.cs

@ -426,7 +426,7 @@ namespace Avalonia.Base.UnitTests.Interactivity
public bool ClassHandlerInvoked { get; private set; }
public new string Name { get; set; }
public IEnumerable<IVisual> Children
public new IEnumerable<IVisual> Children
{
get
{
@ -435,8 +435,8 @@ namespace Avalonia.Base.UnitTests.Interactivity
set
{
VisualChildren.Clear();
((IAvaloniaList<IVisual>)VisualChildren).AddRange(value.Cast<Visual>());
base.Children.VisualMutable.Clear();
((IAvaloniaList<IVisual>)base.Children.VisualMutable).AddRange(value.Cast<Visual>());
}
}

12
tests/Avalonia.Base.UnitTests/TestVisual.cs

@ -29,34 +29,34 @@ namespace Avalonia.Base.UnitTests
{
if (Child != null)
{
VisualChildren.Remove(Child);
Children.VisualMutable.Remove(Child);
}
if (value != null)
{
VisualChildren.Add(value);
Children.VisualMutable.Add(value);
}
}
}
public void AddChild(Visual v)
{
VisualChildren.Add(v);
Children.VisualMutable.Add(v);
}
public void AddChildren(IEnumerable<Visual> v)
{
((IAvaloniaList<IVisual>)VisualChildren).AddRange(v);
((IAvaloniaList<IVisual>)Children.VisualMutable).AddRange(v);
}
public void RemoveChild(Visual v)
{
VisualChildren.Remove(v);
Children.VisualMutable.Remove(v);
}
public void ClearChildren()
{
VisualChildren.Clear();
Children.VisualMutable.Clear();
}
}
}

2
tests/Avalonia.Controls.UnitTests/TestTemplatedControl.cs

@ -9,7 +9,7 @@ namespace Avalonia.Controls.UnitTests
public void AddVisualChild(IVisual visual)
{
VisualChildren.Add(visual);
Children.VisualMutable.Add(visual);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Loading…
Cancel
Save