Browse Source

Added IPanel interface.

pull/83/head
Steven Kirk 11 years ago
parent
commit
84924dee3c
  1. 2
      Tests/Perspex.Controls.UnitTests/Presenters/DeckPresenterTests.cs
  2. 6
      Tests/Perspex.Controls.UnitTests/Presenters/ItemsPresenterTests.cs
  3. 4
      src/Perspex.Controls/Deck.cs
  4. 19
      src/Perspex.Controls/IPanel.cs
  5. 10
      src/Perspex.Controls/ItemsControl.cs
  6. 4
      src/Perspex.Controls/Menu.cs
  7. 4
      src/Perspex.Controls/MenuItem.cs
  8. 2
      src/Perspex.Controls/Panel.cs
  9. 1
      src/Perspex.Controls/Perspex.Controls.csproj
  10. 6
      src/Perspex.Controls/Presenters/DeckPresenter.cs
  11. 2
      src/Perspex.Controls/Presenters/IItemsPresenter.cs
  12. 14
      src/Perspex.Controls/Presenters/ItemsPresenter.cs
  13. 4
      src/Perspex.Controls/Primitives/SelectingItemsControl.cs
  14. 4
      src/Perspex.Controls/TreeView.cs
  15. 4
      src/Perspex.Controls/TreeViewItem.cs

2
Tests/Perspex.Controls.UnitTests/Presenters/DeckPresenterTests.cs

@ -18,7 +18,7 @@ namespace Perspex.Controls.UnitTests.Presenters
{
var target = new DeckPresenter
{
ItemsPanel = new FuncTemplate<Panel>(() => new Panel()),
ItemsPanel = new FuncTemplate<IPanel>(() => new Panel()),
};
target.ApplyTemplate();

6
Tests/Perspex.Controls.UnitTests/Presenters/ItemsPresenterTests.cs

@ -137,7 +137,7 @@ namespace Perspex.Controls.UnitTests.Presenters
var panel = new Panel();
var target = new ItemsPresenter
{
ItemsPanel = new FuncTemplate<Panel>(() => panel),
ItemsPanel = new FuncTemplate<IPanel>(() => panel),
};
target.ApplyTemplate();
@ -152,7 +152,7 @@ namespace Perspex.Controls.UnitTests.Presenters
target.ApplyTemplate();
Assert.Equal(KeyboardNavigationMode.Once, KeyboardNavigation.GetTabNavigation(target.Panel));
Assert.Equal(KeyboardNavigationMode.Once, KeyboardNavigation.GetTabNavigation((InputElement)target.Panel));
}
[Fact]
@ -163,7 +163,7 @@ namespace Perspex.Controls.UnitTests.Presenters
KeyboardNavigation.SetTabNavigation(target, KeyboardNavigationMode.Cycle);
target.ApplyTemplate();
Assert.Equal(KeyboardNavigationMode.Cycle, KeyboardNavigation.GetTabNavigation(target.Panel));
Assert.Equal(KeyboardNavigationMode.Cycle, KeyboardNavigation.GetTabNavigation((InputElement)target.Panel));
}
[Fact]

4
src/Perspex.Controls/Deck.cs

@ -26,8 +26,8 @@ namespace Perspex.Controls
/// <summary>
/// The default value of <see cref="IReparentingControl"/> for <see cref="Deck"/>.
/// </summary>
private static readonly ITemplate<Panel> PanelTemplate =
new FuncTemplate<Panel>(() => new Panel());
private static readonly ITemplate<IPanel> PanelTemplate =
new FuncTemplate<IPanel>(() => new Panel());
/// <summary>
/// Initializes static members of the <see cref="Deck"/> class.

19
src/Perspex.Controls/IPanel.cs

@ -0,0 +1,19 @@
// -----------------------------------------------------------------------
// <copyright file="IPanel.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
/// <summary>
/// Interface for controls that can contain multiple children.
/// </summary>
public interface IPanel : IControl
{
/// <summary>
/// Gets or sets the children of the <see cref="Panel"/>.
/// </summary>
Controls Children { get; set; }
}
}

10
src/Perspex.Controls/ItemsControl.cs

@ -29,8 +29,8 @@ namespace Perspex.Controls
/// The default value for the <see cref="ItemsPanel"/> property.
/// </summary>
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "Needs to be before or a NullReferenceException is thrown.")]
private static readonly FuncTemplate<Panel> DefaultPanel =
new FuncTemplate<Panel>(() => new StackPanel());
private static readonly FuncTemplate<IPanel> DefaultPanel =
new FuncTemplate<IPanel>(() => new StackPanel());
/// <summary>
/// Defines the <see cref="Items"/> property.
@ -41,8 +41,8 @@ namespace Perspex.Controls
/// <summary>
/// Defines the <see cref="ItemsPanel"/> property.
/// </summary>
public static readonly PerspexProperty<ITemplate<Panel>> ItemsPanelProperty =
PerspexProperty.Register<ItemsControl, ITemplate<Panel>>("ItemsPanel", defaultValue: DefaultPanel);
public static readonly PerspexProperty<ITemplate<IPanel>> ItemsPanelProperty =
PerspexProperty.Register<ItemsControl, ITemplate<IPanel>>("ItemsPanel", defaultValue: DefaultPanel);
private IItemContainerGenerator itemContainerGenerator;
@ -91,7 +91,7 @@ namespace Perspex.Controls
/// <summary>
/// Gets or sets the panel used to display the items.
/// </summary>
public ITemplate<Panel> ItemsPanel
public ITemplate<IPanel> ItemsPanel
{
get { return this.GetValue(ItemsPanelProperty); }
set { this.SetValue(ItemsPanelProperty, value); }

4
src/Perspex.Controls/Menu.cs

@ -24,8 +24,8 @@ namespace Perspex.Controls
/// <summary>
/// Defines the default items panel used by a <see cref="Menu"/>.
/// </summary>
private static readonly ITemplate<Panel> DefaultPanel =
new FuncTemplate<Panel>(() => new StackPanel { Orientation = Orientation.Horizontal });
private static readonly ITemplate<IPanel> DefaultPanel =
new FuncTemplate<IPanel>(() => new StackPanel { Orientation = Orientation.Horizontal });
/// <summary>
/// Defines the <see cref="IsOpen"/> property.

4
src/Perspex.Controls/MenuItem.cs

@ -77,8 +77,8 @@ namespace Perspex.Controls
/// <summary>
/// The default value for the <see cref="ItemsControl.ItemsPanel"/> property.
/// </summary>
private static readonly ITemplate<Panel> DefaultPanel =
new FuncTemplate<Panel>(() => new StackPanel
private static readonly ITemplate<IPanel> DefaultPanel =
new FuncTemplate<IPanel>(() => new StackPanel
{
[KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Cycle,
});

2
src/Perspex.Controls/Panel.cs

@ -19,7 +19,7 @@ namespace Perspex.Controls
/// Controls can be added to a <see cref="Panel"/> by adding them to its <see cref="Children"/>
/// collection. All children are layed out to fill the panel.
/// </remarks>
public class Panel : Control, IReparentingControl
public class Panel : Control, IReparentingControl, IPanel
{
private Controls children = new Controls();

1
src/Perspex.Controls/Perspex.Controls.csproj

@ -44,6 +44,7 @@
<Compile Include="Generators\ITreeItemContainerGenerator.cs" />
<Compile Include="Generators\ItemContainers.cs" />
<Compile Include="IControl.cs" />
<Compile Include="IPanel.cs" />
<Compile Include="IReparentingHost.cs" />
<Compile Include="ISetLogicalParent.cs" />
<Compile Include="MenuItemAccessKeyHandler.cs" />

6
src/Perspex.Controls/Presenters/DeckPresenter.cs

@ -31,7 +31,7 @@ namespace Perspex.Controls.Presenters
/// <summary>
/// Defines the <see cref="ItemsPanel"/> property.
/// </summary>
public static readonly PerspexProperty<ITemplate<Panel>> ItemsPanelProperty =
public static readonly PerspexProperty<ITemplate<IPanel>> ItemsPanelProperty =
ItemsControl.ItemsPanelProperty.AddOwner<DeckPresenter>();
/// <summary>
@ -98,7 +98,7 @@ namespace Perspex.Controls.Presenters
/// <summary>
/// Gets or sets the panel used to display the pages.
/// </summary>
public ITemplate<Panel> ItemsPanel
public ITemplate<IPanel> ItemsPanel
{
get { return this.GetValue(ItemsPanelProperty); }
set { this.SetValue(ItemsPanelProperty, value); }
@ -116,7 +116,7 @@ namespace Perspex.Controls.Presenters
/// <summary>
/// Gets the panel used to display the pages.
/// </summary>
public Panel Panel
public IPanel Panel
{
get;
private set;

2
src/Perspex.Controls/Presenters/IItemsPresenter.cs

@ -8,6 +8,6 @@ namespace Perspex.Controls.Presenters
{
public interface IItemsPresenter : IPresenter
{
Panel Panel { get; }
IPanel Panel { get; }
}
}

14
src/Perspex.Controls/Presenters/ItemsPresenter.cs

@ -28,7 +28,7 @@ namespace Perspex.Controls.Presenters
/// <summary>
/// Defines the <see cref="ItemsPanel"/> property.
/// </summary>
public static readonly PerspexProperty<ITemplate<Panel>> ItemsPanelProperty =
public static readonly PerspexProperty<ITemplate<IPanel>> ItemsPanelProperty =
ItemsControl.ItemsPanelProperty.AddOwner<ItemsPresenter>();
private bool createdPanel;
@ -93,7 +93,7 @@ namespace Perspex.Controls.Presenters
/// <summary>
/// Gets or sets a template which creates the <see cref="Panel"/> used to display the items.
/// </summary>
public ITemplate<Panel> ItemsPanel
public ITemplate<IPanel> ItemsPanel
{
get { return this.GetValue(ItemsPanelProperty); }
set { this.SetValue(ItemsPanelProperty, value); }
@ -102,7 +102,7 @@ namespace Perspex.Controls.Presenters
/// <summary>
/// Gets the panel used to display the items.
/// </summary>
public Panel Panel
public IPanel Panel
{
get;
private set;
@ -143,7 +143,9 @@ namespace Perspex.Controls.Presenters
if (!this.Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty))
{
KeyboardNavigation.SetDirectionalNavigation(this.Panel, KeyboardNavigationMode.Contained);
KeyboardNavigation.SetDirectionalNavigation(
(InputElement)this.Panel,
KeyboardNavigationMode.Contained);
}
this.AddVisualChild(this.Panel);
@ -157,7 +159,9 @@ namespace Perspex.Controls.Presenters
logicalHost.LogicalChildren);
}
KeyboardNavigation.SetTabNavigation(this.Panel, KeyboardNavigation.GetTabNavigation(this));
KeyboardNavigation.SetTabNavigation(
(InputElement)this.Panel,
KeyboardNavigation.GetTabNavigation(this));
this.createdPanel = true;
this.CreateItemsAndListenForChanges(this.Items);
}

4
src/Perspex.Controls/Primitives/SelectingItemsControl.cs

@ -325,7 +325,9 @@ namespace Perspex.Controls.Primitives
var inputElement = container as IInputElement;
if (inputElement != null && this.Presenter != null && this.Presenter.Panel != null)
{
KeyboardNavigation.SetTabOnceActiveElement(this.Presenter.Panel, inputElement);
KeyboardNavigation.SetTabOnceActiveElement(
(InputElement)this.Presenter.Panel,
inputElement);
}
}
}

4
src/Perspex.Controls/TreeView.cs

@ -69,7 +69,9 @@ namespace Perspex.Controls
if (this.Presenter != null && this.Presenter.Panel != null)
{
KeyboardNavigation.SetTabOnceActiveElement(this.Presenter.Panel, selectedContainer);
KeyboardNavigation.SetTabOnceActiveElement(
(InputElement)this.Presenter.Panel,
selectedContainer);
}
foreach (var item in containers)

4
src/Perspex.Controls/TreeViewItem.cs

@ -33,8 +33,8 @@ namespace Perspex.Controls
public static readonly PerspexProperty<bool> IsSelectedProperty =
ListBoxItem.IsSelectedProperty.AddOwner<TreeViewItem>();
private static readonly ITemplate<Panel> DefaultPanel =
new FuncTemplate<Panel>(() => new StackPanel
private static readonly ITemplate<IPanel> DefaultPanel =
new FuncTemplate<IPanel>(() => new StackPanel
{
[KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
});

Loading…
Cancel
Save