diff --git a/Perspex.UnitTests/Perspex.UnitTests.csproj b/Perspex.UnitTests/Perspex.UnitTests.csproj
index 33ff73f5aa..4fe2bb0fa6 100644
--- a/Perspex.UnitTests/Perspex.UnitTests.csproj
+++ b/Perspex.UnitTests/Perspex.UnitTests.csproj
@@ -65,6 +65,7 @@
+
diff --git a/Perspex.UnitTests/Style.cs b/Perspex.UnitTests/Style.cs
new file mode 100644
index 0000000000..653e69defc
--- /dev/null
+++ b/Perspex.UnitTests/Style.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Perspex.Controls;
+
+namespace Perspex
+{
+ public class Style
+ {
+ private bool applied;
+
+ public Style()
+ {
+ this.Setters = new List();
+ }
+
+ public Func Selector
+ {
+ get;
+ set;
+ }
+
+ public IEnumerable Setters
+ {
+ get;
+ set;
+ }
+
+ public void Attach(Control control)
+ {
+ Match match = this.Selector(control);
+
+ if (match != null)
+ {
+ List> o = new List>();
+
+ while (match != null)
+ {
+ if (match.Observable != null)
+ {
+ o.Add(match.Observable);
+ }
+
+ match = match.Previous;
+ }
+
+ Observable.CombineLatest(o).Subscribe(x =>
+ {
+ if (x.All(y => y))
+ {
+ this.Apply(control);
+ }
+ else if (this.applied)
+ {
+ this.Unapply(control);
+ }
+ });
+ }
+ }
+
+ private void Apply(Control control)
+ {
+ if (this.Setters != null)
+ {
+ foreach (Setter setter in this.Setters)
+ {
+ setter.Apply(control);
+ }
+ }
+
+ this.applied = true;
+ }
+
+ private void Unapply(Control control)
+ {
+ if (this.Setters != null)
+ {
+ foreach (Setter setter in this.Setters)
+ {
+ setter.Unapply(control);
+ }
+
+ this.applied = false;
+ }
+ }
+ }
+}
diff --git a/Perspex.Windows/DrawingContext.cs b/Perspex.Windows/DrawingContext.cs
index dec5dac5fe..881a7c58d1 100644
--- a/Perspex.Windows/DrawingContext.cs
+++ b/Perspex.Windows/DrawingContext.cs
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-//
+//
// Copyright 2013 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
diff --git a/Perspex.Windows/Media/TextService.cs b/Perspex.Windows/Media/TextService.cs
index 79d7190f00..c7b9bb3065 100644
--- a/Perspex.Windows/Media/TextService.cs
+++ b/Perspex.Windows/Media/TextService.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Windows.Media
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Windows.Media
{
using Perspex.Media;
using SharpDX.DirectWrite;
diff --git a/Perspex.Windows/Window.cs b/Perspex.Windows/Window.cs
index 4e5d6c8e40..0c831a20b0 100644
--- a/Perspex.Windows/Window.cs
+++ b/Perspex.Windows/Window.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Windows
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Windows
{
using System;
using System.ComponentModel;
@@ -11,7 +17,7 @@
public class Window : ContentControl, ILayoutRoot
{
- public static PerspexProperty FontSizeProperty =
+ public static readonly PerspexProperty FontSizeProperty =
TextBlock.FontSizeProperty.AddOwner();
private UnmanagedMethods.WndProc wndProcDelegate;
@@ -34,11 +40,13 @@
this.LayoutManager.LayoutNeeded.Subscribe(x =>
{
- Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, () =>
- {
- this.LayoutManager.ExecuteLayoutPass();
- this.renderer.Render(this);
- });
+ Dispatcher.CurrentDispatcher.BeginInvoke(
+ DispatcherPriority.Render,
+ () =>
+ {
+ this.LayoutManager.ExecuteLayoutPass();
+ this.renderer.Render(this);
+ });
});
}
@@ -74,7 +82,7 @@
Border border = new Border();
border.Background = new Perspex.Media.SolidColorBrush(0xffffffff);
ContentPresenter contentPresenter = new ContentPresenter();
- contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(ContentProperty));
+ contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(Window.ContentProperty));
border.Content = contentPresenter;
return border;
}
diff --git a/Perspex/Controls/Border.cs b/Perspex/Controls/Border.cs
index 655640ccba..2208ec1b48 100644
--- a/Perspex/Controls/Border.cs
+++ b/Perspex/Controls/Border.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using System;
using System.Reactive.Linq;
@@ -14,10 +20,6 @@
if (background != null)
{
- System.Diagnostics.Debug.WriteLine(
- string.Format("{0} Draw Background={1}",
- this.GetHashCode(),
- background));
context.FillRectange(background, new Rect(this.Bounds.Size));
}
diff --git a/Perspex/Controls/Button.cs b/Perspex/Controls/Button.cs
index f4364becab..8b76c6387b 100644
--- a/Perspex/Controls/Button.cs
+++ b/Perspex/Controls/Button.cs
@@ -13,12 +13,12 @@ namespace Perspex.Controls
protected override Visual DefaultTemplate()
{
Border border = new Border();
- border.Bind(Border.BackgroundProperty, this.GetObservable(BackgroundProperty));
- border.Bind(Border.BorderBrushProperty, this.GetObservable(BorderBrushProperty));
- border.Bind(Border.BorderThicknessProperty, this.GetObservable(BorderThicknessProperty));
+ border.Bind(Border.BackgroundProperty, this.GetObservable(Button.BackgroundProperty));
+ border.Bind(Border.BorderBrushProperty, this.GetObservable(Button.BorderBrushProperty));
+ border.Bind(Border.BorderThicknessProperty, this.GetObservable(Button.BorderThicknessProperty));
border.Padding = new Thickness(3);
ContentPresenter contentPresenter = new ContentPresenter();
- contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(ContentProperty));
+ contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(Button.ContentProperty));
border.Content = contentPresenter;
return border;
}
diff --git a/Perspex/Controls/ContentControl.cs b/Perspex/Controls/ContentControl.cs
index 99999ef4b4..a84daaabcd 100644
--- a/Perspex/Controls/ContentControl.cs
+++ b/Perspex/Controls/ContentControl.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
diff --git a/Perspex/Controls/ContentPresenter.cs b/Perspex/Controls/ContentPresenter.cs
index 8c2a22e709..35d73e991c 100644
--- a/Perspex/Controls/ContentPresenter.cs
+++ b/Perspex/Controls/ContentPresenter.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs
index b7aafef1d9..ffa21dd003 100644
--- a/Perspex/Controls/Control.cs
+++ b/Perspex/Controls/Control.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
@@ -26,9 +32,6 @@
public abstract class Control : Visual, ILayoutable
{
- internal static readonly PerspexProperty ParentPropertyRW =
- PerspexProperty.Register("Parent");
-
public static readonly ReadOnlyPerspexProperty ParentProperty =
new ReadOnlyPerspexProperty(ParentPropertyRW);
@@ -50,6 +53,9 @@
public static readonly PerspexProperty MarginProperty =
PerspexProperty.Register("Margin");
+ internal static readonly PerspexProperty ParentPropertyRW =
+ PerspexProperty.Register("Parent");
+
public Control()
{
this.Classes = new ObservableCollection();
@@ -174,6 +180,8 @@
private void AttachStyles(Control control)
{
+ Contract.Requires(control != null);
+
if (control.Styles != null)
{
foreach (Style style in control.Styles)
@@ -192,9 +200,11 @@
private void ParentChanged(Tuple values)
{
+ Contract.Requires(values != null);
+
if (values.Item1 != null)
{
- //this.DetatchStyles(values.Item1);
+ ////this.DetatchStyles(values.Item1);
}
if (values.Item2 != null)
diff --git a/Perspex/Controls/Decorator.cs b/Perspex/Controls/Decorator.cs
index 35fd73768b..950e23d7e3 100644
--- a/Perspex/Controls/Decorator.cs
+++ b/Perspex/Controls/Decorator.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
diff --git a/Perspex/Controls/TemplatedControl.cs b/Perspex/Controls/TemplatedControl.cs
index 1d96b47c43..3198e6075e 100644
--- a/Perspex/Controls/TemplatedControl.cs
+++ b/Perspex/Controls/TemplatedControl.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
diff --git a/Perspex/Controls/TextBlock.cs b/Perspex/Controls/TextBlock.cs
index a010b6c7d7..5dfbcbc608 100644
--- a/Perspex/Controls/TextBlock.cs
+++ b/Perspex/Controls/TextBlock.cs
@@ -1,12 +1,15 @@
-namespace Perspex.Controls
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
{
using Perspex.Media;
public class TextBlock : Control
{
- public static readonly PerspexProperty BackgroundProperty =
- Border.BackgroundProperty.AddOwner();
-
public static readonly PerspexProperty FontSizeProperty =
PerspexProperty.Register(
"FontSize",
@@ -21,12 +24,6 @@
public static readonly PerspexProperty TextProperty =
PerspexProperty.Register("Text");
- public Brush Background
- {
- get { return this.GetValue(BackgroundProperty); }
- set { this.SetValue(BackgroundProperty, value); }
- }
-
public double FontSize
{
get { return this.GetValue(FontSizeProperty); }
diff --git a/Perspex/Layout/LayoutManager.cs b/Perspex/Layout/LayoutManager.cs
index 0e4ed95f1a..e1111e830d 100644
--- a/Perspex/Layout/LayoutManager.cs
+++ b/Perspex/Layout/LayoutManager.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Layout
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Layout
{
using System;
using System.Collections.Generic;
@@ -24,13 +30,13 @@
public void ExecuteLayoutPass()
{
- if (root != null)
+ if (this.root != null)
{
- root.Measure(root.ClientSize);
- root.Arrange(new Rect(root.ClientSize));
+ this.root.Measure(this.root.ClientSize);
+ this.root.Arrange(new Rect(this.root.ClientSize));
}
- root = null;
+ this.root = null;
}
public void InvalidateMeasure(ILayoutable item)
diff --git a/Perspex/Match.cs b/Perspex/Match.cs
index 4c6932098c..73661f40c5 100644
--- a/Perspex/Match.cs
+++ b/Perspex/Match.cs
@@ -1,12 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Perspex.Controls;
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
namespace Perspex
{
+ using System;
+ using Perspex.Controls;
+
public class Match
{
public Control Control
diff --git a/Perspex/Media/IDrawingContext.cs b/Perspex/Media/IDrawingContext.cs
index d73bf83607..45005f83a3 100644
--- a/Perspex/Media/IDrawingContext.cs
+++ b/Perspex/Media/IDrawingContext.cs
@@ -4,9 +4,10 @@
//
// -----------------------------------------------------------------------
-using System;
namespace Perspex.Media
{
+ using System;
+
///
/// Defines the interface through which drawing occurs.
///
diff --git a/Perspex/Media/ITextService.cs b/Perspex/Media/ITextService.cs
index 0d44ba01b4..d3fe50d7da 100644
--- a/Perspex/Media/ITextService.cs
+++ b/Perspex/Media/ITextService.cs
@@ -1,4 +1,10 @@
-namespace Perspex.Media
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Media
{
public interface ITextService
{
diff --git a/Perspex/PerspexObject.cs b/Perspex/PerspexObject.cs
index b2967e8a03..4c0378f2ed 100644
--- a/Perspex/PerspexObject.cs
+++ b/Perspex/PerspexObject.cs
@@ -159,7 +159,6 @@ namespace Perspex
/// The type of the property.
/// The target property.
/// The observable.
- /// A disposable binding.
public void Bind(PerspexProperty target, IObservable source)
{
Contract.Requires(target != null);
@@ -384,6 +383,8 @@ namespace Perspex
///
private void ParentPropertyChanged(object sender, PerspexPropertyChangedEventArgs e)
{
+ Contract.Requires(e != null);
+
if (e.Property.Inherits && !this.IsSet(e.Property))
{
this.RaisePropertyChanged(e.Property, e.OldValue, e.NewValue);
@@ -408,7 +409,7 @@ namespace Perspex
}
}
- public void SetValueImpl(PerspexProperty property, object value)
+ private void SetValueImpl(PerspexProperty property, object value)
{
Contract.Requires(property != null);
diff --git a/Perspex/PerspexProperty.cs b/Perspex/PerspexProperty.cs
index 5e752708ac..6ec6856ad4 100644
--- a/Perspex/PerspexProperty.cs
+++ b/Perspex/PerspexProperty.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Collections.Generic;
@@ -48,22 +54,22 @@
}
///
- /// The name of the property.
+ /// Gets the name of the property.
///
public string Name { get; private set; }
///
- /// The type of the property's value.
+ /// Gets the type of the property's value.
///
public Type ValueType { get; private set; }
///
- /// The type of the class that registers the property.
+ /// Gets the type of the class that registers the property.
///
public Type OwnerType { get; private set; }
///
- /// Whether the property inherits its value.
+ /// Gets a value indicating whether the property inherits its value.
///
public bool Inherits { get; private set; }
diff --git a/Perspex/Point.cs b/Perspex/Point.cs
index 174c25a9ad..3d71c17427 100644
--- a/Perspex/Point.cs
+++ b/Perspex/Point.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System.Globalization;
@@ -44,6 +50,11 @@
get { return this.y; }
}
+ public static Point operator -(Point a, Point b)
+ {
+ return new Point(a.x - b.x, a.y - b.y);
+ }
+
///
/// Returns the string representation of the point.
///
@@ -52,10 +63,5 @@
{
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", this.x, this.y);
}
-
- public static Point operator-(Point a, Point b)
- {
- return new Point(a.x - b.x, a.y - b.y);
- }
}
}
diff --git a/Perspex/ReadOnlyPerspexProperty.cs b/Perspex/ReadOnlyPerspexProperty.cs
index db50c7b06c..d08eb254ad 100644
--- a/Perspex/ReadOnlyPerspexProperty.cs
+++ b/Perspex/ReadOnlyPerspexProperty.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
public class ReadOnlyPerspexProperty
{
diff --git a/Perspex/Rect.cs b/Perspex/Rect.cs
index b47904ae13..68fec6d443 100644
--- a/Perspex/Rect.cs
+++ b/Perspex/Rect.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Globalization;
diff --git a/Perspex/Selectors.cs b/Perspex/Selectors.cs
index 95f17558db..4317f9bd22 100644
--- a/Perspex/Selectors.cs
+++ b/Perspex/Selectors.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Collections.Generic;
diff --git a/Perspex/ServiceLocator.cs b/Perspex/ServiceLocator.cs
index 225b019d97..e83ddbf1ab 100644
--- a/Perspex/ServiceLocator.cs
+++ b/Perspex/ServiceLocator.cs
@@ -1,11 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
namespace Perspex
{
+ using System;
+ using System.Collections.Generic;
+
public static class ServiceLocator
{
private static Dictionary> services =
diff --git a/Perspex/Setter.cs b/Perspex/Setter.cs
index 409134290a..bcf758c275 100644
--- a/Perspex/Setter.cs
+++ b/Perspex/Setter.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Diagnostics.Contracts;
@@ -26,13 +32,6 @@
this.oldValue = control.GetValue(this.Property);
control.SetValue(this.Property, this.Value);
-
- System.Diagnostics.Debug.WriteLine(
- string.Format("{0} Style Set {1}.{2}={3}",
- control.GetHashCode(),
- control.GetType().Name,
- this.Property.Name,
- this.Value));
}
public void Unapply(Control control)
@@ -40,13 +39,6 @@
Contract.Requires(control != null);
control.SetValue(this.Property, this.oldValue);
-
- System.Diagnostics.Debug.WriteLine(
- string.Format("{0} Style Unset {1}.{2}={3}",
- control.GetHashCode(),
- control.GetType().Name,
- this.Property.Name,
- oldValue));
}
}
}
diff --git a/Perspex/Size.cs b/Perspex/Size.cs
index 35b3ce7ad8..4976967384 100644
--- a/Perspex/Size.cs
+++ b/Perspex/Size.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Globalization;
diff --git a/Perspex/Style.cs b/Perspex/Style.cs
index 653e69defc..fec4a09324 100644
--- a/Perspex/Style.cs
+++ b/Perspex/Style.cs
@@ -1,14 +1,17 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reactive.Disposables;
-using System.Reactive.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Perspex.Controls;
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 Tricycle. All rights reserved.
+//
+// -----------------------------------------------------------------------
namespace Perspex
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reactive.Linq;
+ using Perspex.Controls;
+
public class Style
{
private bool applied;
diff --git a/Perspex/Thickness.cs b/Perspex/Thickness.cs
index 442cfe4e68..b953e6d6dd 100644
--- a/Perspex/Thickness.cs
+++ b/Perspex/Thickness.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Diagnostics.Contracts;
diff --git a/Perspex/Visual.cs b/Perspex/Visual.cs
index 99b9fac5b7..427a3d2a0a 100644
--- a/Perspex/Visual.cs
+++ b/Perspex/Visual.cs
@@ -1,4 +1,10 @@
-namespace Perspex
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex
{
using System;
using System.Collections.Generic;
@@ -11,12 +17,12 @@
public static readonly ReadOnlyPerspexProperty BoundsProperty =
new ReadOnlyPerspexProperty(BoundsPropertyRW);
- private static readonly PerspexProperty BoundsPropertyRW =
- PerspexProperty.Register("Bounds");
-
public static readonly PerspexProperty IsMouseOverProperty =
PerspexProperty.Register("IsMouseOver");
+ private static readonly PerspexProperty BoundsPropertyRW =
+ PerspexProperty.Register("Bounds");
+
private Visual visualParent;
public Rect Bounds