Browse Source

Move more stuff from Control to IControl.

To do this, added the PropertyBag interfaces from ideas branch.
pull/69/head
Steven Kirk 11 years ago
parent
commit
eabf674027
  1. 37
      Perspex.Base/IObservablePropertyBag.cs
  2. 49
      Perspex.Base/IPropertyBag.cs
  3. 2
      Perspex.Base/Perspex.Base.csproj
  4. 2
      Perspex.Base/PerspexObject.cs
  5. 16
      Perspex.Controls/Controls.cs
  6. 11
      Perspex.Controls/INavigablePanel.cs
  7. 4
      Perspex.Controls/Panel.cs
  8. 2
      Perspex.Controls/Primitives/AdornerLayer.cs
  9. 2
      Perspex.Controls/Primitives/SelectingItemsControl.cs
  10. 2
      Perspex.Controls/StackPanel.cs
  11. 8
      Perspex.SceneGraph/Visual.cs
  12. 14
      Perspex.Styling/GlobalSuppressions.cs
  13. 1
      Perspex.Styling/Perspex.Styling.csproj
  14. 36
      Perspex.Styling/Styling/IStyleable.cs
  15. 20
      Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs
  16. 20
      Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs
  17. 15
      Tests/Perspex.Styling.UnitTests/TestControlBase.cs
  18. 15
      Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs

37
Perspex.Base/IObservablePropertyBag.cs

@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// <copyright file="IObservablePropertyBag.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
/// <summary>
/// Interface for getting/setting <see cref="PerspexProperty"/> bindings on an object.
/// </summary>
public interface IObservablePropertyBag : IPropertyBag
{
/// <summary>
/// Binds a <see cref="PerspexProperty"/> to an observable.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
IDisposable Bind(
PerspexProperty property,
IObservable<object> source,
BindingPriority priority = BindingPriority.LocalValue);
/// <summary>
/// Gets an observable for a <see cref="PerspexProperty"/>.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>An observable.</returns>
IObservable<object> GetObservable(PerspexProperty property);
}
}

49
Perspex.Base/IPropertyBag.cs

@ -0,0 +1,49 @@
// -----------------------------------------------------------------------
// <copyright file="IPropertyBag.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
/// <summary>
/// Interface for getting/setting <see cref="PerspexProperty"/> values on an object.
/// </summary>
public interface IPropertyBag
{
/// <summary>
/// Clears a <see cref="PerspexProperty"/>'s local value.
/// </summary>
/// <param name="property">The property.</param>
void ClearValue(PerspexProperty property);
/// <summary>
/// Gets a <see cref="PerspexProperty"/> value.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The value.</returns>
object GetValue(PerspexProperty property);
/// <summary>
/// Checks whether a <see cref="PerspexProperty"/> is registered on this object.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>True if the property is registered, otherwise false.</returns>
bool IsRegistered(PerspexProperty property);
/// <summary>
/// Checks whether a <see cref="PerspexProperty"/> is set on this object.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>True if the property is set, otherwise false.</returns>
bool IsSet(PerspexProperty property);
/// <summary>
/// Sets a <see cref="PerspexProperty"/> value.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
void SetValue(PerspexProperty property, object value, BindingPriority priority = BindingPriority.LocalValue);
}
}

2
Perspex.Base/Perspex.Base.csproj

@ -39,6 +39,8 @@
<Compile Include="Binding.cs" />
<Compile Include="Diagnostics\PerspexObjectExtensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IObservablePropertyBag.cs" />
<Compile Include="IPropertyBag.cs" />
<Compile Include="PerspexObjectExtensions.cs" />
<Compile Include="PerspexProperty`1.cs" />
<Compile Include="PriorityBindingEntry.cs" />

2
Perspex.Base/PerspexObject.cs

@ -66,7 +66,7 @@ namespace Perspex
/// <remarks>
/// This class is analogous to DependencyObject in WPF.
/// </remarks>
public class PerspexObject : INotifyPropertyChanged
public class PerspexObject : IObservablePropertyBag, INotifyPropertyChanged
{
/// <summary>
/// The registered properties by type.

16
Perspex.Controls/Controls.cs

@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="Controls.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information.
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
@ -9,13 +9,23 @@ namespace Perspex.Controls
using System.Collections.Generic;
using Perspex.Collections;
public class Controls : PerspexList<Control>
/// <summary>
/// A collection of <see cref="Control"/>s.
/// </summary>
public class Controls : PerspexList<IControl>
{
/// <summary>
/// Initializes a new instance of the <see cref="Controls"/> class.
/// </summary>
public Controls()
{
}
public Controls(IEnumerable<Control> items)
/// <summary>
/// Initializes a new instance of the <see cref="Controls"/> class.
/// </summary>
/// <param name="items">The initial items in the collection.</param>
public Controls(IEnumerable<IControl> items)
: base(items)
{
}

11
Perspex.Controls/INavigablePanel.cs

@ -8,8 +8,17 @@ namespace Perspex.Controls
{
using Perspex.Input;
/// <summary>
/// Defines a panel in which the child controls can be navigated by keyboard.
/// </summary>
public interface INavigablePanel
{
Control GetControl(FocusNavigationDirection direction, Control from);
/// <summary>
/// Gets the next control in the specified direction.
/// </summary>
/// <param name="direction">The movement direction.</param>
/// <param name="from">The control from which movement begins.</param>
/// <returns>The control.</returns>
IControl GetControl(FocusNavigationDirection direction, IControl from);
}
}

4
Perspex.Controls/Panel.cs

@ -118,7 +118,7 @@ namespace Perspex.Controls
/// Clears <see cref="IControl.Parent"/> for the specified controls.
/// </summary>
/// <param name="controls">The controls.</param>
private void ClearLogicalParent(IEnumerable<Control> controls)
private void ClearLogicalParent(IEnumerable<IControl> controls)
{
foreach (var control in controls)
{
@ -130,7 +130,7 @@ namespace Perspex.Controls
/// Sets <see cref="IControl.Parent"/> for the specified controls.
/// </summary>
/// <param name="controls">The controls.</param>
private void SetLogicalParent(IEnumerable<Control> controls)
private void SetLogicalParent(IEnumerable<IControl> controls)
{
var parent = this.childLogicalParent as Control;

2
Perspex.Controls/Primitives/AdornerLayer.cs

@ -52,7 +52,7 @@ namespace Perspex.Controls.Primitives
foreach (var child in this.Children)
{
var info = child.GetValue(AdornedElementInfoProperty);
var info = (AdornedElementInfo)child.GetValue(AdornedElementInfoProperty);
if (info != null)
{

2
Perspex.Controls/Primitives/SelectingItemsControl.cs

@ -162,7 +162,7 @@ namespace Perspex.Controls.Primitives
if (next != null)
{
this.SelectedItem = this.ItemContainerGenerator.GetItemForContainer(next);
this.SelectedItem = this.ItemContainerGenerator.GetItemForContainer((Control)next);
}
}
else

2
Perspex.Controls/StackPanel.cs

@ -75,7 +75,7 @@ namespace Perspex.Controls
/// <param name="direction">The movement direction.</param>
/// <param name="from">The control from which movement begins.</param>
/// <returns>The control.</returns>
Control INavigablePanel.GetControl(FocusNavigationDirection direction, Control from)
IControl INavigablePanel.GetControl(FocusNavigationDirection direction, IControl from)
{
var horiz = this.Orientation == Orientation.Horizontal;
int index = this.Children.IndexOf(from);

8
Perspex.SceneGraph/Visual.cs

@ -271,7 +271,7 @@ namespace Perspex
/// Adds a visual child to the control.
/// </summary>
/// <param name="visual">The child to add.</param>
protected void AddVisualChild(Visual visual)
protected void AddVisualChild(IVisual visual)
{
Contract.Requires<ArgumentNullException>(visual != null);
@ -282,7 +282,7 @@ namespace Perspex
/// Adds visual children to the control.
/// </summary>
/// <param name="visuals">The children to add.</param>
protected void AddVisualChildren(IEnumerable<Visual> visuals)
protected void AddVisualChildren(IEnumerable<IVisual> visuals)
{
Contract.Requires<ArgumentNullException>(visuals != null);
@ -301,7 +301,7 @@ namespace Perspex
/// Removes a visual child from the control;
/// </summary>
/// <param name="visual">The child to remove.</param>
protected void RemoveVisualChild(Visual visual)
protected void RemoveVisualChild(IVisual visual)
{
Contract.Requires<ArgumentNullException>(visual != null);
@ -312,7 +312,7 @@ namespace Perspex
/// Removes a visual children from the control;
/// </summary>
/// <param name="visuals">The children to remove.</param>
protected void RemoveVisualChildren(IEnumerable<Visual> visuals)
protected void RemoveVisualChildren(IEnumerable<IVisual> visuals)
{
Contract.Requires<ArgumentNullException>(visuals != null);

14
Perspex.Styling/GlobalSuppressions.cs

@ -0,0 +1,14 @@
// -----------------------------------------------------------------------
// <copyright file="GlobalSuppressions.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.MaintainabilityRules",
"SA1401:Fields must be private",
Justification = "PerspexProperty fields should not be private.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.DocumentationRules",
"SA1609:Property documentation must have value",
Justification = "This rule is fscking pointless")]

1
Perspex.Styling/Perspex.Styling.csproj

@ -36,6 +36,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogical.cs" />
<Compile Include="LogicalTree\LogicalExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

36
Perspex.Styling/Styling/IStyleable.cs

@ -11,7 +11,7 @@ namespace Perspex.Styling
/// <summary>
/// Interface for styleable elements.
/// </summary>
public interface IStyleable
public interface IStyleable : IObservablePropertyBag
{
/// <summary>
/// Gets the list of classes for the control.
@ -32,39 +32,5 @@ namespace Perspex.Styling
/// Gets the template parent of this element if the control comes from a template.
/// </summary>
ITemplatedControl TemplatedParent { get; }
/// <summary>
/// Binds a <see cref="PerspexProperty"/> to an observable.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
IDisposable Bind(PerspexProperty property, IObservable<object> source, BindingPriority priority);
/// <summary>
/// Gets an observable for a <see cref="PerspexProperty"/>.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>An observable.</returns>
IObservable<object> GetObservable(PerspexProperty property);
/// <summary>
/// Checks whether a <see cref="PerspexProperty"/> is registered on this class.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>True if the property is registered, otherwise false.</returns>
bool IsRegistered(PerspexProperty property);
/// <summary>
/// Sets a <see cref="PerspexProperty"/> value.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
void SetValue(PerspexProperty property, object value, BindingPriority priority);
}
}

20
Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs

@ -79,10 +79,15 @@ namespace Perspex.Styling.UnitTests
}
public Classes Classes { get; }
public string Name { get; set; }
public IPerspexReadOnlyList<ILogical> LogicalChildren { get; set; }
public ILogical LogicalParent { get; set; }
public Type StyleKey { get; }
public ITemplatedControl TemplatedParent { get; }
public IDisposable Bind(PerspexProperty property, IObservable<object> source, BindingPriority priority)
@ -104,6 +109,21 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public void ClearValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public object GetValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(PerspexProperty property)
{
throw new NotImplementedException();
}
}
public class TestLogical1 : TestLogical

20
Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs

@ -111,10 +111,15 @@ namespace Perspex.Styling.UnitTests
}
public Classes Classes { get; }
public string Name { get; set; }
public IPerspexReadOnlyList<ILogical> LogicalChildren { get; set; }
public ILogical LogicalParent { get; set; }
public Type StyleKey { get; }
public ITemplatedControl TemplatedParent { get; }
public IDisposable Bind(PerspexProperty property, IObservable<object> source, BindingPriority priority)
@ -136,6 +141,21 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public void ClearValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public object GetValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(PerspexProperty property)
{
throw new NotImplementedException();
}
}
public class TestLogical1 : TestLogical

15
Tests/Perspex.Styling.UnitTests/TestControlBase.cs

@ -53,5 +53,20 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public void ClearValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public object GetValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(PerspexProperty property)
{
throw new NotImplementedException();
}
}
}

15
Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs

@ -61,5 +61,20 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public void ClearValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public object GetValue(PerspexProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(PerspexProperty property)
{
throw new NotImplementedException();
}
}
}

Loading…
Cancel
Save