diff --git a/Perspex/Application.cs b/Perspex/Application.cs deleted file mode 100644 index a1e1e39e38..0000000000 --- a/Perspex/Application.cs +++ /dev/null @@ -1,97 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using Perspex.Controls; - using Perspex.Input; - using Perspex.Styling; - using Perspex.Threading; - using Splat; - - public class Application - { - private DataTemplates dataTemplates; - - private Styles styles; - - public Application() - { - Current = this; - this.FocusManager = new FocusManager(); - this.InputManager = new InputManager(); - } - - public static Application Current - { - get; - private set; - } - - public DataTemplates DataTemplates - { - get - { - if (this.dataTemplates == null) - { - this.dataTemplates = new DataTemplates(); - } - - return this.dataTemplates; - } - - set - { - this.dataTemplates = value; - } - } - - public IFocusManager FocusManager - { - get; - private set; - } - - public InputManager InputManager - { - get; - private set; - } - - public Styles Styles - { - get - { - if (this.styles == null) - { - this.styles = new Styles(); - } - - return this.styles; - } - - set - { - this.styles = value; - } - } - - public void RegisterServices() - { - Styler styler = new Styler(); - Locator.CurrentMutable.Register(() => this.FocusManager, typeof(IFocusManager)); - Locator.CurrentMutable.Register(() => this.InputManager, typeof(IInputManager)); - Locator.CurrentMutable.Register(() => styler, typeof(IStyler)); - } - - public void Run(ICloseable closable) - { - DispatcherFrame frame = new DispatcherFrame(); - closable.Closed += (s, e) => frame.Continue = false; - Dispatcher.PushFrame(frame); - } - } -} diff --git a/Perspex/Binding.cs b/Perspex/Binding.cs deleted file mode 100644 index be39daf060..0000000000 --- a/Perspex/Binding.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Perspex -{ - public enum BindingMode - { - Default, - OneWay, - TwoWay, - OneTime, - OneWayToSource, - } - - public struct Binding - { - public BindingMode Mode - { - get; - set; - } - - public BindingPriority Priority - { - get; - set; - } - - public PerspexProperty Property - { - get; - set; - } - - public PerspexObject Source - { - get; - set; - } - - public static Binding operator !(Binding binding) - { - return binding.WithMode(BindingMode.TwoWay); - } - - public static Binding operator ~(Binding binding) - { - return binding.WithMode(BindingMode.TwoWay); - } - - public Binding WithMode(BindingMode mode) - { - this.Mode = mode; - return this; - } - - public Binding WithPriority(BindingPriority priority) - { - this.Priority = priority; - return this; - } - } -} diff --git a/Perspex/BindingExtensions.cs b/Perspex/BindingExtensions.cs deleted file mode 100644 index f739682cac..0000000000 --- a/Perspex/BindingExtensions.cs +++ /dev/null @@ -1,39 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Perspex.Controls; - - /// - /// Provides binding utility extension methods. - /// - public static class BindingExtensions - { - /// - /// Binds a property in a template to the same property in the templated parent. - /// - /// The property type. - /// The control in the template. - /// The templated parent. - /// The property. - /// - /// A disposable which can be used to terminate the binding. - /// - public static IDisposable TemplateBinding( - this PerspexObject o, - ITemplatedControl templatedParent, - PerspexProperty property) - { - return o.Bind(property, templatedParent.GetObservable(property), BindingPriority.TemplatedParent); - } - } -} diff --git a/Perspex/Classes.cs b/Perspex/Classes.cs deleted file mode 100644 index b05446fd0a..0000000000 --- a/Perspex/Classes.cs +++ /dev/null @@ -1,177 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Linq; - using System.Reactive; - using System.Reactive.Subjects; - - public class Classes : ICollection, INotifyCollectionChanged - { - private List inner; - - private Subject beforeChanged - = new Subject(); - - private Subject changed - = new Subject(); - - private Subject afterChanged - = new Subject(); - - public Classes() - { - this.inner = new List(); - } - - public Classes(params string[] classes) - { - this.inner = new List(classes); - } - - public Classes(IEnumerable classes) - { - this.inner = new List(classes); - } - - public event NotifyCollectionChangedEventHandler CollectionChanged; - - public int Count - { - get { return this.inner.Count; } - } - - public bool IsReadOnly - { - get { return false; } - } - - public IObservable BeforeChanged - { - get { return this.beforeChanged; } - } - - public IObservable Changed - { - get { return this.changed; } - } - - public IObservable AfterChanged - { - get { return this.afterChanged; } - } - - public void Add(string item) - { - this.Add(Enumerable.Repeat(item, 1)); - } - - public void Add(params string[] items) - { - this.Add((IEnumerable)items); - } - - public void Add(IEnumerable items) - { - items = items.Except(this.inner); - - NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Add, - items); - - this.beforeChanged.OnNext(e); - this.inner.AddRange(items); - this.RaiseChanged(e); - } - - public void Clear() - { - NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Reset); - - this.beforeChanged.OnNext(e); - this.inner.Clear(); - this.RaiseChanged(e); - } - - public bool Contains(string item) - { - return this.inner.Contains(item); - } - - public void CopyTo(string[] array, int arrayIndex) - { - this.inner.CopyTo(array, arrayIndex); - } - - public IEnumerator GetEnumerator() - { - return this.inner.GetEnumerator(); - } - - public override string ToString() - { - return string.Join(" ", this); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return this.inner.GetEnumerator(); - } - - public bool Remove(string item) - { - return this.Remove(Enumerable.Repeat(item, 1)); - } - - public bool Remove(params string[] items) - { - return this.Remove((IEnumerable)items); - } - - public bool Remove(IEnumerable items) - { - items = items.Intersect(this.inner); - - if (items.Any()) - { - NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Remove, - items); - - this.beforeChanged.OnNext(e); - - foreach (string item in items) - { - this.inner.Remove(item); - } - - this.RaiseChanged(e); - return true; - } - else - { - return false; - } - } - - private void RaiseChanged(NotifyCollectionChangedEventArgs e) - { - if (this.CollectionChanged != null) - { - this.CollectionChanged(this, e); - } - - this.changed.OnNext(e); - this.afterChanged.OnNext(e); - } - } -} diff --git a/Perspex/Contract.cs b/Perspex/Contract.cs deleted file mode 100644 index 18a3f65802..0000000000 --- a/Perspex/Contract.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - - internal static class Contract - { - public static void Requires(bool condition) where TException : Exception, new() - { -#if DEBUG - if (!condition) - { - throw new TException(); - } -#endif - } - } -} diff --git a/Perspex/ControlExtensions.cs b/Perspex/ControlExtensions.cs deleted file mode 100644 index 777aeca917..0000000000 --- a/Perspex/ControlExtensions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Perspex.Controls; - using Perspex.Styling; - - public static class ControlExtensions - { - public static IEnumerable GetTemplateControls(this ITemplatedControl control) - { - return GetTemplateControls(control, (IVisual)control); - } - - public static IEnumerable GetTemplateControls(ITemplatedControl templated, IVisual parent) - { - IVisual visual = parent as IVisual; - - foreach (IVisual child in visual.VisualChildren.OfType().Where(x => x.TemplatedParent == templated)) - { - yield return (Control)child; - - foreach (IVisual grandchild in GetTemplateControls(templated, child)) - { - yield return (Control)grandchild; - } - } - } - } -} diff --git a/Perspex/Controls/Border.cs b/Perspex/Controls/Border.cs deleted file mode 100644 index bd0be84e28..0000000000 --- a/Perspex/Controls/Border.cs +++ /dev/null @@ -1,62 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Reactive.Linq; - using Perspex.Layout; - using Perspex.Media; - - public class Border : Decorator - { - static Border() - { - AffectsRender(BackgroundProperty); - AffectsRender(BorderBrushProperty); - } - - public override void Render(IDrawingContext context) - { - Brush background = this.Background; - Brush borderBrush = this.BorderBrush; - double borderThickness = this.BorderThickness; - Rect rect = new Rect(this.ActualSize).Deflate(BorderThickness / 2); - - if (background != null) - { - context.FillRectange(background, rect); - } - - if (borderBrush != null && borderThickness > 0) - { - context.DrawRectange(new Pen(borderBrush, borderThickness), rect); - } - } - - protected override Size ArrangeOverride(Size finalSize) - { - Control content = this.Content; - - if (content != null) - { - Thickness padding = this.Padding + new Thickness(this.BorderThickness); - content.Arrange(new Rect(finalSize).Deflate(padding)); - } - - return finalSize; - } - - protected override Size MeasureOverride(Size availableSize) - { - return LayoutHelper.MeasureDecorator( - this, - this.Content, - availableSize, - this.Padding + new Thickness(this.BorderThickness)); - } - } -} diff --git a/Perspex/Controls/Button.cs b/Perspex/Controls/Button.cs deleted file mode 100644 index 36452bab3b..0000000000 --- a/Perspex/Controls/Button.cs +++ /dev/null @@ -1,48 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - - public class Button : ContentControl - { - public static readonly RoutedEvent ClickEvent = - RoutedEvent.Register("Click", RoutingStrategy.Bubble); - - static Button() - { - FocusableProperty.OverrideDefaultValue(typeof(Button), true); - } - - public Button() - { - this.PointerPressed += (s, e) => - { - this.Classes.Add(":pressed"); - e.Device.Capture(this); - }; - - this.PointerReleased += (s, e) => - { - e.Device.Capture(null); - this.Classes.Remove(":pressed"); - - if (this.Classes.Contains(":pointerover")) - { - RoutedEventArgs click = new RoutedEventArgs(ClickEvent, this); - this.RaiseEvent(click); - } - }; - } - - public event EventHandler Click - { - add { this.AddHandler(ClickEvent, value); } - remove { this.RemoveHandler(ClickEvent, value); } - } - } -} diff --git a/Perspex/Controls/CheckBox.cs b/Perspex/Controls/CheckBox.cs deleted file mode 100644 index a78e5ab7ae..0000000000 --- a/Perspex/Controls/CheckBox.cs +++ /dev/null @@ -1,12 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class CheckBox : ToggleButton - { - } -} diff --git a/Perspex/Controls/ColumnDefinition.cs b/Perspex/Controls/ColumnDefinition.cs deleted file mode 100644 index a07d2d45e2..0000000000 --- a/Perspex/Controls/ColumnDefinition.cs +++ /dev/null @@ -1,53 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class ColumnDefinition : DefinitionBase - { - public static readonly PerspexProperty MaxWidthProperty = - PerspexProperty.Register("MaxWidth", double.PositiveInfinity); - - public static readonly PerspexProperty MinWidthProperty = - PerspexProperty.Register("MinWidth"); - - public static readonly PerspexProperty WidthProperty = - PerspexProperty.Register("Width", new GridLength(1, GridUnitType.Star)); - - public ColumnDefinition() - { - } - - public ColumnDefinition(GridLength width) - { - this.Width = width; - } - - public double ActualWidth - { - get; - internal set; - } - - public double MaxWidth - { - get { return this.GetValue(MaxWidthProperty); } - set { this.SetValue(MaxWidthProperty, value); } - } - - public double MinWidth - { - get { return this.GetValue(MinWidthProperty); } - set { this.SetValue(MinWidthProperty, value); } - } - - public GridLength Width - { - get { return this.GetValue(WidthProperty); } - set { this.SetValue(WidthProperty, value); } - } - } -} diff --git a/Perspex/Controls/ColumnDefinitions.cs b/Perspex/Controls/ColumnDefinitions.cs deleted file mode 100644 index 73656b8854..0000000000 --- a/Perspex/Controls/ColumnDefinitions.cs +++ /dev/null @@ -1,12 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class ColumnDefinitions : PerspexList - { - } -} diff --git a/Perspex/Controls/ContentControl.cs b/Perspex/Controls/ContentControl.cs deleted file mode 100644 index 54bf329ef8..0000000000 --- a/Perspex/Controls/ContentControl.cs +++ /dev/null @@ -1,51 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - - public class ContentControl : TemplatedControl, ILogical - { - public static readonly PerspexProperty ContentProperty = - PerspexProperty.Register("Content"); - - public ContentControl() - { - this.GetObservableWithHistory(ContentProperty).Subscribe(x => - { - if (x.Item1 is Control) - { - ((IVisual)x.Item1).VisualParent = null; - ((ILogical)x.Item1).LogicalParent = null; - } - - if (x.Item2 is Control) - { - ((IVisual)x.Item2).VisualParent = this; - ((ILogical)x.Item2).LogicalParent = this; - } - }); - } - - public object Content - { - get { return this.GetValue(ContentProperty); } - set { this.SetValue(ContentProperty, value); } - } - - IEnumerable ILogical.LogicalChildren - { - get - { - ILogical logicalChild = this.Content as ILogical; - return Enumerable.Repeat(logicalChild, logicalChild != null ? 1 : 0); - } - } - } -} diff --git a/Perspex/Controls/ContentPresenter.cs b/Perspex/Controls/ContentPresenter.cs deleted file mode 100644 index 54d12fb455..0000000000 --- a/Perspex/Controls/ContentPresenter.cs +++ /dev/null @@ -1,188 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Perspex.Layout; - using Perspex.Media; - - public class ContentPresenter : Control, IVisual - { - public static readonly PerspexProperty ContentProperty = - ContentControl.ContentProperty.AddOwner(); - - public static readonly PerspexProperty> DataTemplateProperty = - PerspexProperty.Register>("DataTemplate"); - - private IVisual visualChild; - - public ContentPresenter() - { - this.GetObservableWithHistory(ContentProperty).Subscribe(this.ContentChanged); - } - - public object Content - { - get { return this.GetValue(ContentProperty); } - set { this.SetValue(ContentProperty, value); } - } - - IEnumerable IVisual.ExistingVisualChildren - { - get { return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0); } - } - - IEnumerable IVisual.VisualChildren - { - get - { - object content = this.Content; - - if (this.visualChild == null && content != null) - { - if (content is Visual) - { - this.visualChild = (Visual)content; - } - else - { - DataTemplate dataTemplate = this.FindDataTemplate(content); - - if (dataTemplate != null) - { - this.visualChild = dataTemplate.Build(content); - } - else - { - this.visualChild = new TextBlock - { - Text = content.ToString(), - }; - } - } - - if (this.visualChild != null) - { - this.visualChild.VisualParent = this; - ((Control)this.visualChild).TemplatedParent = null; - } - } - - return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0); - } - } - - protected override Size ArrangeOverride(Size finalSize) - { - Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control; - - if (child != null) - { - double left; - double top; - double width; - double height; - - switch (child.HorizontalAlignment) - { - case HorizontalAlignment.Left: - left = 0; - width = child.DesiredSize.Value.Width; - break; - case HorizontalAlignment.Center: - left = (finalSize.Width / 2) - (child.DesiredSize.Value.Width / 2); - width = child.DesiredSize.Value.Width; - break; - case HorizontalAlignment.Right: - left = finalSize.Width - child.DesiredSize.Value.Width; - width = child.DesiredSize.Value.Width; - break; - default: - left = 0; - width = finalSize.Width; - break; - } - - switch (child.VerticalAlignment) - { - case VerticalAlignment.Top: - top = 0; - height = child.DesiredSize.Value.Height; - break; - case VerticalAlignment.Center: - top = (finalSize.Height / 2) - (child.DesiredSize.Value.Height / 2); - height = child.DesiredSize.Value.Height; - break; - case VerticalAlignment.Bottom: - top = finalSize.Height - child.DesiredSize.Value.Height; - height = child.DesiredSize.Value.Height; - break; - default: - top = 0; - height = finalSize.Height; - break; - } - - child.Arrange(new Rect(left, top, width, height)); - } - - return finalSize; - } - - protected override Size MeasureOverride(Size availableSize) - { - Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control; - - if (child != null) - { - child.Measure(availableSize); - return child.DesiredSize.Value; - } - - return new Size(); - } - - private void ContentChanged(Tuple content) - { - if (content.Item1 != null) - { - this.visualChild.VisualParent = null; - ILogical logical = content.Item1 as ILogical; - - if (logical != null) - { - logical.LogicalParent = null; - } - } - - if (content.Item2 != null) - { - Control control = content.Item2 as Control; - - if (control == null) - { - control = this.GetDataTemplate(content.Item2).Build(content.Item2); - } - - control.TemplatedParent = null; - ((IVisual)control).VisualParent = this; - this.visualChild = control; - - ILogical logical = content.Item2 as ILogical; - - if (logical != null) - { - logical.LogicalParent = (ILogical)this.TemplatedParent; - } - } - - this.InvalidateMeasure(); - } - } -} diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs deleted file mode 100644 index 9aa60ccdbf..0000000000 --- a/Perspex/Controls/Control.cs +++ /dev/null @@ -1,268 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - using Perspex.Input; - using Perspex.Layout; - using Perspex.Media; - using Perspex.Styling; - using Splat; - - public class Control : InputElement, ILogical, IStyleable, IStyled - { - public static readonly PerspexProperty BackgroundProperty = - PerspexProperty.Register("Background", inherits: true); - - public static readonly PerspexProperty BorderBrushProperty = - PerspexProperty.Register("BorderBrush"); - - public static readonly PerspexProperty BorderThicknessProperty = - PerspexProperty.Register("BorderThickness"); - - public static readonly PerspexProperty FontSizeProperty = - PerspexProperty.Register( - "FontSize", - defaultValue: 12.0, - inherits: true); - - public static readonly PerspexProperty ForegroundProperty = - PerspexProperty.Register("Foreground", new SolidColorBrush(0xff000000), true); - - public static readonly PerspexProperty ParentProperty = - PerspexProperty.Register("Parent"); - - public static readonly PerspexProperty TemplatedParentProperty = - PerspexProperty.Register("TemplatedParent", inherits: true); - - private Classes classes; - - private DataTemplates dataTemplates; - - private string id; - - private Styles styles; - - static Control() - { - AffectsMeasure(IsVisibleProperty); - } - - public Control() - { - this.classes = new Classes(); - this.AddPseudoClass(IsPointerOverProperty, ":pointerover"); - this.AddPseudoClass(IsFocusedProperty, ":focus"); - } - - public Brush Background - { - get { return this.GetValue(BackgroundProperty); } - set { this.SetValue(BackgroundProperty, value); } - } - - public Brush BorderBrush - { - get { return this.GetValue(BorderBrushProperty); } - set { this.SetValue(BorderBrushProperty, value); } - } - - public double BorderThickness - { - get { return this.GetValue(BorderThicknessProperty); } - set { this.SetValue(BorderThicknessProperty, value); } - } - - public Classes Classes - { - get - { - return this.classes; - } - - set - { - if (this.classes != value) - { - this.classes.Clear(); - this.classes.Add(value); - } - } - } - - public DataTemplates DataTemplates - { - get - { - if (this.dataTemplates == null) - { - this.dataTemplates = new DataTemplates(); - } - - return this.dataTemplates; - } - - set - { - this.dataTemplates = value; - } - } - - public double FontSize - { - get { return this.GetValue(FontSizeProperty); } - set { this.SetValue(FontSizeProperty, value); } - } - - public Brush Foreground - { - get { return this.GetValue(ForegroundProperty); } - set { this.SetValue(ForegroundProperty, value); } - } - - public string Id - { - get - { - return this.id; - } - - set - { - if (this.id != null) - { - throw new InvalidOperationException("ID already set."); - } - - if (((IVisual)this).VisualParent != null) - { - throw new InvalidOperationException("Cannot set ID : control already added to tree."); - } - - this.id = value; - } - } - - public Control Parent - { - get { return this.GetValue(ParentProperty); } - protected set { this.SetValue(ParentProperty, value); } - } - - public Styles Styles - { - get - { - if (this.styles == null) - { - this.styles = new Styles(); - } - - return this.styles; - } - - set - { - this.styles = value; - } - } - - public ITemplatedControl TemplatedParent - { - get { return this.GetValue(TemplatedParentProperty); } - internal set { this.SetValue(TemplatedParentProperty, value); } - } - - ILogical ILogical.LogicalParent - { - get { return this.Parent; } - set { this.Parent = (Control)value; } - } - - IEnumerable ILogical.LogicalChildren - { - get { return Enumerable.Empty(); } - } - - protected override void OnAttachedToVisualTree(ILayoutRoot root) - { - IStyler styler = Locator.Current.GetService(); - styler.ApplyStyles(this); - } - - protected void AddPseudoClass(PerspexProperty property, string className) - { - this.GetObservable(property).Subscribe(x => - { - if (x) - { - this.classes.Add(className); - } - else - { - this.classes.Remove(className); - } - }); - } - - protected virtual DataTemplate FindDataTemplate(object content) - { - Control control = content as Control; - - if (control != null) - { - return new DataTemplate(x => control); - } - - ILogical node = this; - - while (node != null) - { - control = node as Control; - - if (control != null) - { - foreach (DataTemplate dt in control.DataTemplates.Reverse()) - { - if (dt.Match(content)) - { - return dt; - } - } - } - - node = node.LogicalParent; - - if (node == null && control != null) - { - node = control.TemplatedParent as ILogical; - } - } - - if (Application.Current != null && Application.Current.DataTemplates != null) - { - foreach (DataTemplate dt in Application.Current.DataTemplates.Reverse()) - { - if (dt.Match(content)) - { - return dt; - } - } - } - - return null; - } - - protected DataTemplate GetDataTemplate(object content) - { - return this.FindDataTemplate(content) ?? DataTemplate.Default; - } - } -} diff --git a/Perspex/Controls/ControlTemplate.cs b/Perspex/Controls/ControlTemplate.cs deleted file mode 100644 index c54833cd35..0000000000 --- a/Perspex/Controls/ControlTemplate.cs +++ /dev/null @@ -1,39 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - - public class ControlTemplate - { - private Func build; - - public ControlTemplate(Func build) - { - Contract.Requires(build != null); - - this.build = build; - } - - public static ControlTemplate Create(Func build) - where TControl : ITemplatedControl - { - Contract.Requires(build != null); - - return new ControlTemplate(c => build((TControl)c)); - } - - public Control Build(ITemplatedControl templatedParent) - { - Contract.Requires(templatedParent != null); - - Control root = this.build(templatedParent); - root.TemplatedParent = templatedParent; - return root; - } - } -} diff --git a/Perspex/Controls/Controls.cs b/Perspex/Controls/Controls.cs deleted file mode 100644 index 3e0667cc17..0000000000 --- a/Perspex/Controls/Controls.cs +++ /dev/null @@ -1,22 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -using System.Collections.Generic; - -namespace Perspex.Controls -{ - public class Controls : PerspexList - { - public Controls() - { - } - - public Controls(IEnumerable items) - : base(items) - { - } - } -} diff --git a/Perspex/Controls/DataTemplate.cs b/Perspex/Controls/DataTemplate.cs deleted file mode 100644 index 9f9de2b477..0000000000 --- a/Perspex/Controls/DataTemplate.cs +++ /dev/null @@ -1,68 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Reflection; - - public class DataTemplate - { - public static readonly DataTemplate Default = - new DataTemplate(typeof(object), o => new TextBlock { Text = o.ToString() }); - - public DataTemplate(Func build) - : this(o => true, build) - { - } - - public DataTemplate(Type type, Func build) - : this(o => IsInstance(o, type), build) - { - } - - public DataTemplate(Func match, Func build) - { - Contract.Requires(match != null); - Contract.Requires(build != null); - - this.Match = match; - this.Build = build; - } - - public static bool IsInstance(object o, Type t) - { - return t.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo()); - } - - public Func Match { get; private set; } - - public Func Build { get; private set; } - } - - public class DataTemplate : DataTemplate - { - public DataTemplate(Func build) - : base(typeof(T), Cast(build)) - { - } - - public DataTemplate(Func match, Func build) - : base(CastMatch(match), Cast(build)) - { - } - - private static Func CastMatch(Func f) - { - return o => (o is T) ? f((T)o) : false; - } - - private static Func Cast(Func f) - { - return o => f((T)o); - } - } -} diff --git a/Perspex/Controls/DataTemplates.cs b/Perspex/Controls/DataTemplates.cs deleted file mode 100644 index 1f81fde90f..0000000000 --- a/Perspex/Controls/DataTemplates.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Linq; - using System.Reactive; - using System.Reactive.Subjects; - - public class DataTemplates : PerspexList - { - } -} diff --git a/Perspex/Controls/Decorator.cs b/Perspex/Controls/Decorator.cs deleted file mode 100644 index 19284479be..0000000000 --- a/Perspex/Controls/Decorator.cs +++ /dev/null @@ -1,84 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - using Perspex.Layout; - - public class Decorator : Control, IVisual - { - public static readonly PerspexProperty ContentProperty = - PerspexProperty.Register("Content"); - - public static readonly PerspexProperty PaddingProperty = - PerspexProperty.Register("Padding"); - - public Decorator() - { - this.GetObservableWithHistory(ContentProperty).Subscribe(x => - { - if (x.Item1 != null) - { - ((IVisual)this).RemoveVisualChild(x.Item1); - ((ILogical)this).RemoveLogicalChild(x.Item1); - } - - if (x.Item2 != null) - { - ((IVisual)this).AddVisualChild(x.Item2); - ((ILogical)this).AddLogicalChild(x.Item2); - } - }); - } - - public Control Content - { - get { return this.GetValue(ContentProperty); } - set { this.SetValue(ContentProperty, value); } - } - - public Thickness Padding - { - get { return this.GetValue(PaddingProperty); } - set { this.SetValue(PaddingProperty, value); } - } - - IEnumerable IVisual.ExistingVisualChildren - { - get { return ((IVisual)this).VisualChildren; } - } - - IEnumerable IVisual.VisualChildren - { - get - { - Control content = this.Content; - return Enumerable.Repeat(content, content != null ? 1 : 0); - } - } - - protected override Size ArrangeOverride(Size finalSize) - { - Control content = this.Content; - - if (content != null) - { - content.Arrange(new Rect(finalSize).Deflate(this.Padding)); - } - - return finalSize; - } - - protected override Size MeasureOverride(Size availableSize) - { - return LayoutHelper.MeasureDecorator(this, this.Content, availableSize, this.Padding); - } - } -} diff --git a/Perspex/Controls/DefinitionBase.cs b/Perspex/Controls/DefinitionBase.cs deleted file mode 100644 index f36cab0052..0000000000 --- a/Perspex/Controls/DefinitionBase.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class DefinitionBase : PerspexObject - { - public static readonly PerspexProperty SharedSizeGroupProperty = - PerspexProperty.Register("SharedSizeGroup", inherits: true); - - public string SharedSizeGroup - { - get { return this.GetValue(SharedSizeGroupProperty); } - set { this.SetValue(SharedSizeGroupProperty, value); } - } - } -} diff --git a/Perspex/Controls/Grid.cs b/Perspex/Controls/Grid.cs deleted file mode 100644 index 4cc626b139..0000000000 --- a/Perspex/Controls/Grid.cs +++ /dev/null @@ -1,805 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - - public class Grid : Panel - { - public static readonly PerspexProperty ColumnProperty = - PerspexProperty.RegisterAttached("Column"); - - public static readonly PerspexProperty ColumnSpanProperty = - PerspexProperty.RegisterAttached("ColumnSpan", 1); - - public static readonly PerspexProperty IsSharedSizeScopeProperty = - PerspexProperty.RegisterAttached("IsSharedSizeScopeProperty"); - - public static readonly PerspexProperty RowProperty = - PerspexProperty.RegisterAttached("Row"); - - public static readonly PerspexProperty RowSpanProperty = - PerspexProperty.RegisterAttached("RowSpan", 1); - - private Segment[,] rowMatrix; - private Segment[,] colMatrix; - - public Grid() - { - this.ColumnDefinitions = new ColumnDefinitions(); - this.RowDefinitions = new RowDefinitions(); - } - - public ColumnDefinitions ColumnDefinitions - { - get; - set; - } - - public RowDefinitions RowDefinitions - { - get; - set; - } - - public static int GetColumn(PerspexObject element) - { - return element.GetValue(ColumnProperty); - } - - public static int GetColumnSpan(PerspexObject element) - { - return element.GetValue(ColumnSpanProperty); - } - - public static int GetRow(PerspexObject element) - { - return element.GetValue(RowProperty); - } - - public static int GetRowSpan(PerspexObject element) - { - return element.GetValue(RowSpanProperty); - } - - public static void SetColumn(PerspexObject element, int value) - { - element.SetValue(ColumnProperty, value); - } - - public static void SetColumnSpan(PerspexObject element, int value) - { - element.SetValue(ColumnSpanProperty, value); - } - - public static void SetRow(PerspexObject element, int value) - { - element.SetValue(RowProperty, value); - } - - public static void SetRowSpan(PerspexObject element, int value) - { - element.SetValue(RowSpanProperty, value); - } - - protected override Size MeasureOverride(Size constraint) - { - Size totalSize = constraint; - int colCount = this.ColumnDefinitions.Count; - int rowCount = this.RowDefinitions.Count; - double totalStarsX = 0; - double totalStarsY = 0; - bool emptyRows = rowCount == 0; - bool emptyCols = colCount == 0; - bool hasChildren = this.Children.Count > 0; - - if (emptyRows) - { - rowCount = 1; - } - - if (emptyCols) - { - colCount = 1; - } - - this.CreateMatrices(rowCount, colCount); - - if (emptyRows) - { - this.rowMatrix[0, 0] = new Segment(0, 0, double.PositiveInfinity, GridUnitType.Star); - this.rowMatrix[0, 0].Stars = 1.0; - totalStarsY += 1.0; - } - else - { - for (int i = 0; i < rowCount; i++) - { - RowDefinition rowdef = this.RowDefinitions[i]; - GridLength height = rowdef.Height; - - rowdef.ActualHeight = double.PositiveInfinity; - this.rowMatrix[i, i] = new Segment(0, rowdef.MinHeight, rowdef.MaxHeight, height.GridUnitType); - - if (height.GridUnitType == GridUnitType.Pixel) - { - this.rowMatrix[i, i].OfferedSize = Clamp(height.Value, this.rowMatrix[i, i].Min, this.rowMatrix[i, i].Max); - this.rowMatrix[i, i].DesiredSize = this.rowMatrix[i, i].OfferedSize; - rowdef.ActualHeight = this.rowMatrix[i, i].OfferedSize; - } - else if (height.GridUnitType == GridUnitType.Star) - { - this.rowMatrix[i, i].Stars = height.Value; - totalStarsY += height.Value; - } - else if (height.GridUnitType == GridUnitType.Auto) - { - this.rowMatrix[i, i].OfferedSize = Clamp(0, this.rowMatrix[i, i].Min, this.rowMatrix[i, i].Max); - this.rowMatrix[i, i].DesiredSize = this.rowMatrix[i, i].OfferedSize; - } - } - } - - if (emptyCols) - { - this.colMatrix[0, 0] = new Segment(0, 0, double.PositiveInfinity, GridUnitType.Star); - this.colMatrix[0, 0].Stars = 1.0; - totalStarsX += 1.0; - } - else - { - for (int i = 0; i < colCount; i++) - { - ColumnDefinition coldef = this.ColumnDefinitions[i]; - GridLength width = coldef.Width; - - coldef.ActualWidth = double.PositiveInfinity; - this.colMatrix[i, i] = new Segment(0, coldef.MinWidth, coldef.MaxWidth, width.GridUnitType); - - if (width.GridUnitType == GridUnitType.Pixel) - { - this.colMatrix[i, i].OfferedSize = Clamp(width.Value, this.colMatrix[i, i].Min, this.colMatrix[i, i].Max); - this.colMatrix[i, i].DesiredSize = this.colMatrix[i, i].OfferedSize; - coldef.ActualWidth = this.colMatrix[i, i].OfferedSize; - } - else if (width.GridUnitType == GridUnitType.Star) - { - this.colMatrix[i, i].Stars = width.Value; - totalStarsX += width.Value; - } - else if (width.GridUnitType == GridUnitType.Auto) - { - this.colMatrix[i, i].OfferedSize = Clamp(0, this.colMatrix[i, i].Min, this.colMatrix[i, i].Max); - this.colMatrix[i, i].DesiredSize = this.colMatrix[i, i].OfferedSize; - } - } - } - - List sizes = new List(); - GridNode node; - GridNode separator = new GridNode(null, 0, 0, 0); - int separatorIndex; - - sizes.Add(separator); - - // Pre-process the grid children so that we know what types of elements we have so - // we can apply our special measuring rules. - GridWalker gridWalker = new GridWalker(this, this.rowMatrix, this.colMatrix); - - for (int i = 0; i < 6; i++) - { - // These bools tell us which grid element type we should be measuring. i.e. - // 'star/auto' means we should measure elements with a star row and auto col - bool autoAuto = i == 0; - bool starAuto = i == 1; - bool autoStar = i == 2; - bool starAutoAgain = i == 3; - bool nonStar = i == 4; - bool remainingStar = i == 5; - - if (hasChildren) - { - this.ExpandStarCols(totalSize); - this.ExpandStarRows(totalSize); - } - - foreach (Control child in this.Children) - { - int col, row; - int colspan, rowspan; - double childSizeX = 0; - double childSizeY = 0; - bool starCol = false; - bool starRow = false; - bool autoCol = false; - bool autoRow = false; - - col = Math.Min(GetColumn(child), colCount - 1); - row = Math.Min(GetRow(child), rowCount - 1); - colspan = Math.Min(GetColumnSpan(child), colCount - col); - rowspan = Math.Min(GetRowSpan(child), rowCount - row); - - for (int r = row; r < row + rowspan; r++) - { - starRow |= this.rowMatrix[r, r].Type == GridUnitType.Star; - autoRow |= this.rowMatrix[r, r].Type == GridUnitType.Auto; - } - - for (int c = col; c < col + colspan; c++) - { - starCol |= this.colMatrix[c, c].Type == GridUnitType.Star; - autoCol |= this.colMatrix[c, c].Type == GridUnitType.Auto; - } - - // This series of if statements checks whether or not we should measure - // the current element and also if we need to override the sizes - // passed to the Measure call. - - // If the element has Auto rows and Auto columns and does not span Star - // rows/cols it should only be measured in the auto_auto phase. - // There are similar rules governing auto/star and star/auto elements. - // NOTE: star/auto elements are measured twice. The first time with - // an override for height, the second time without it. - if (autoRow && autoCol && !starRow && !starCol) - { - if (!autoAuto) - { - continue; - } - - childSizeX = double.PositiveInfinity; - childSizeY = double.PositiveInfinity; - } - else if (starRow && autoCol && !starCol) - { - if (!(starAuto || starAutoAgain)) - { - continue; - } - - if (starAuto && gridWalker.HasAutoStar) - { - childSizeY = double.PositiveInfinity; - } - - childSizeX = double.PositiveInfinity; - } - else if (autoRow && starCol && !starRow) - { - if (!autoStar) - { - continue; - } - - childSizeY = double.PositiveInfinity; - } - else if ((autoRow || autoCol) && !(starRow || starCol)) - { - if (!nonStar) - { - continue; - } - - if (autoRow) - { - childSizeY = double.PositiveInfinity; - } - - if (autoCol) - { - childSizeX = double.PositiveInfinity; - } - } - else if (!(starRow || starCol)) - { - if (!nonStar) - { - continue; - } - } - else - { - if (!remainingStar) - { - continue; - } - } - - for (int r = row; r < row + rowspan; r++) - { - childSizeY += this.rowMatrix[r, r].OfferedSize; - } - - for (int c = col; c < col + colspan; c++) - { - childSizeX += this.colMatrix[c, c].OfferedSize; - } - - child.Measure(new Size(childSizeX, childSizeY)); - Size desired = child.DesiredSize.Value; - - // Elements distribute their height based on two rules: - // 1) Elements with rowspan/colspan == 1 distribute their height first - // 2) Everything else distributes in a LIFO manner. - // As such, add all UIElements with rowspan/colspan == 1 after the separator in - // the list and everything else before it. Then to process, just keep popping - // elements off the end of the list. - if (!starAuto) - { - node = new GridNode(this.rowMatrix, row + rowspan - 1, row, desired.Height); - separatorIndex = sizes.IndexOf(separator); - sizes.Insert(node.Row == node.Column ? separatorIndex + 1 : separatorIndex, node); - } - - node = new GridNode(this.colMatrix, col + colspan - 1, col, desired.Width); - - separatorIndex = sizes.IndexOf(separator); - sizes.Insert(node.Row == node.Column ? separatorIndex + 1 : separatorIndex, node); - } - - sizes.Remove(separator); - - while (sizes.Count > 0) - { - node = sizes.Last(); - node.Matrix[node.Row, node.Column].DesiredSize = Math.Max(node.Matrix[node.Row, node.Column].DesiredSize, node.Size); - this.AllocateDesiredSize(rowCount, colCount); - sizes.Remove(node); - } - - sizes.Add(separator); - } - - // Once we have measured and distributed all sizes, we have to store - // the results. Every time we want to expand the rows/cols, this will - // be used as the baseline. - this.SaveMeasureResults(); - - sizes.Remove(separator); - - double gridSizeX = 0; - double gridSizeY = 0; - - for (int c = 0; c < colCount; c++) - { - gridSizeX += this.colMatrix[c, c].DesiredSize; - } - - for (int r = 0; r < rowCount; r++) - { - gridSizeY += this.rowMatrix[r, r].DesiredSize; - } - - return new Size(gridSizeX, gridSizeY); - } - - protected override Size ArrangeOverride(Size finalSize) - { - int colCount = this.ColumnDefinitions.Count; - int rowCount = this.RowDefinitions.Count; - int colMatrixDim = this.colMatrix.GetUpperBound(0) + 1; - int rowMatrixDim = this.rowMatrix.GetUpperBound(0) + 1; - - this.RestoreMeasureResults(); - - double totalConsumedX = 0; - double totalConsumedY = 0; - - for (int c = 0; c < colMatrixDim; c++) - { - this.colMatrix[c, c].OfferedSize = this.colMatrix[c, c].DesiredSize; - totalConsumedX += this.colMatrix[c, c].OfferedSize; - } - - for (int r = 0; r < rowMatrixDim; r++) - { - this.rowMatrix[r, r].OfferedSize = this.rowMatrix[r, r].DesiredSize; - totalConsumedY += this.rowMatrix[r, r].OfferedSize; - } - - if (totalConsumedX != finalSize.Width) - { - this.ExpandStarCols(finalSize); - } - - if (totalConsumedY != finalSize.Height) - { - this.ExpandStarRows(finalSize); - } - - for (int c = 0; c < colCount; c++) - { - this.ColumnDefinitions[c].ActualWidth = this.colMatrix[c, c].OfferedSize; - } - - for (int r = 0; r < rowCount; r++) - { - this.RowDefinitions[r].ActualHeight = this.rowMatrix[r, r].OfferedSize; - } - - foreach (Control child in this.Children) - { - int col = Math.Min(GetColumn(child), colMatrixDim - 1); - int row = Math.Min(GetRow(child), rowMatrixDim - 1); - int colspan = Math.Min(GetColumnSpan(child), colMatrixDim - col); - int rowspan = Math.Min(GetRowSpan(child), rowMatrixDim - row); - - double childFinalX = 0; - double childFinalY = 0; - double childFinalW = 0; - double childFinalH = 0; - - for (int c = 0; c < col; c++) - { - childFinalX += this.colMatrix[c, c].OfferedSize; - } - - for (int c = col; c < col + colspan; c++) - { - childFinalW += this.colMatrix[c, c].OfferedSize; - } - - for (int r = 0; r < row; r++) - { - childFinalY += this.rowMatrix[r, r].OfferedSize; - } - - for (int r = row; r < row + rowspan; r++) - { - childFinalH += this.rowMatrix[r, r].OfferedSize; - } - - child.Arrange(new Rect(childFinalX, childFinalY, childFinalW, childFinalH)); - } - - return finalSize; - } - - private static double Clamp(double val, double min, double max) - { - if (val < min) - { - return min; - } - else if (val > max) - { - return max; - } - else - { - return val; - } - } - - private void CreateMatrices(int rowCount, int colCount) - { - if (this.rowMatrix == null || this.colMatrix == null || - this.rowMatrix.GetUpperBound(0) != rowCount - 1 || - this.colMatrix.GetUpperBound(0) != colCount - 1) - { - this.rowMatrix = new Segment[rowCount, rowCount]; - this.colMatrix = new Segment[colCount, colCount]; - } - } - - private void ExpandStarCols(Size availableSize) - { - int columnsCount = this.ColumnDefinitions.Count; - double width = availableSize.Width; - - for (int i = 0; i < this.colMatrix.GetUpperBound(0) + 1; i++) - { - if (this.colMatrix[i, i].Type == GridUnitType.Star) - { - this.colMatrix[i, i].OfferedSize = 0; - } - else - { - width = Math.Max(availableSize.Width - this.colMatrix[i, i].OfferedSize, 0); - } - } - - this.AssignSize(this.colMatrix, 0, this.colMatrix.GetUpperBound(0), ref width, GridUnitType.Star, false); - width = Math.Max(0, width); - - if (columnsCount > 0) - { - for (int i = 0; i < this.colMatrix.GetUpperBound(0) + 1; i++) - { - if (this.colMatrix[i, i].Type == GridUnitType.Star) - { - this.ColumnDefinitions[i].ActualWidth = this.colMatrix[i, i].OfferedSize; - } - } - } - } - - private void ExpandStarRows(Size availableSize) - { - int rowCount = this.RowDefinitions.Count; - double height = availableSize.Height; - - // When expanding star rows, we need to zero out their height before - // calling AssignSize. AssignSize takes care of distributing the - // available size when there are Mins and Maxs applied. - for (int i = 0; i < this.rowMatrix.GetUpperBound(0) + 1; i++) - { - if (this.rowMatrix[i, i].Type == GridUnitType.Star) - { - this.rowMatrix[i, i].OfferedSize = 0.0; - } - else - { - height = Math.Max(availableSize.Height - this.rowMatrix[i, i].OfferedSize, 0); - } - } - - this.AssignSize(this.rowMatrix, 0, this.rowMatrix.GetUpperBound(0), ref height, GridUnitType.Star, false); - - if (rowCount > 0) - { - for (int i = 0; i < this.rowMatrix.GetUpperBound(0) + 1; i++) - { - if (this.rowMatrix[i, i].Type == GridUnitType.Star) - { - this.RowDefinitions[i].ActualHeight = this.rowMatrix[i, i].OfferedSize; - } - } - } - } - - private void AssignSize( - Segment[,] matrix, - int start, - int end, - ref double size, - GridUnitType type, - bool desiredSize) - { - double count = 0; - bool assigned; - - // Count how many segments are of the correct type. If we're measuring Star rows/cols - // we need to count the number of stars instead. - for (int i = start; i <= end; i++) - { - double segmentSize = desiredSize ? matrix[i, i].DesiredSize : matrix[i, i].OfferedSize; - if (segmentSize < matrix[i, i].Max) - { - count += type == GridUnitType.Star ? matrix[i, i].Stars : 1; - } - } - - do - { - double contribution = size / count; - - assigned = false; - - for (int i = start; i <= end; i++) - { - double segmentSize = desiredSize ? matrix[i, i].DesiredSize : matrix[i, i].OfferedSize; - - if (!(matrix[i, i].Type == type && segmentSize < matrix[i, i].Max)) - { - continue; - } - - double newsize = segmentSize; - newsize += contribution * (type == GridUnitType.Star ? matrix[i, i].Stars : 1); - newsize = Math.Min(newsize, matrix[i, i].Max); - assigned |= newsize > segmentSize; - size -= newsize - segmentSize; - - if (desiredSize) - { - matrix[i, i].DesiredSize = newsize; - } - else - { - matrix[i, i].OfferedSize = newsize; - } - } - } - while (assigned); - } - - private void AllocateDesiredSize(int rowCount, int colCount) - { - // First allocate the heights of the RowDefinitions, then allocate - // the widths of the ColumnDefinitions. - for (int i = 0; i < 2; i++) - { - Segment[,] matrix = i == 0 ? this.rowMatrix : this.colMatrix; - int count = i == 0 ? rowCount : colCount; - - for (int row = count - 1; row >= 0; row--) - { - for (int col = row; col >= 0; col--) - { - bool spansStar = false; - for (int j = row; j >= col; j--) - { - spansStar |= matrix[j, j].Type == GridUnitType.Star; - } - - // This is the amount of pixels which must be available between the grid rows - // at index 'col' and 'row'. i.e. if 'row' == 0 and 'col' == 2, there must - // be at least 'matrix [row][col].size' pixels of height allocated between - // all the rows in the range col -> row. - double current = matrix[row, col].DesiredSize; - - // Count how many pixels have already been allocated between the grid rows - // in the range col -> row. The amount of pixels allocated to each grid row/column - // is found on the diagonal of the matrix. - double totalAllocated = 0; - - for (int k = row; k >= col; k--) - { - totalAllocated += matrix[k, k].DesiredSize; - } - - // If the size requirement has not been met, allocate the additional required - // size between 'pixel' rows, then 'star' rows, finally 'auto' rows, until all - // height has been assigned. - if (totalAllocated < current) - { - double additional = current - totalAllocated; - - if (spansStar) - { - this.AssignSize(matrix, col, row, ref additional, GridUnitType.Star, true); - } - else - { - this.AssignSize(matrix, col, row, ref additional, GridUnitType.Pixel, true); - this.AssignSize(matrix, col, row, ref additional, GridUnitType.Auto, true); - } - } - } - } - } - - for (int r = 0; r < this.rowMatrix.GetUpperBound(0) + 1; r++) - { - this.rowMatrix[r, r].OfferedSize = this.rowMatrix[r, r].DesiredSize; - } - - for (int c = 0; c < this.colMatrix.GetUpperBound(0) + 1; c++) - { - this.colMatrix[c, c].OfferedSize = this.colMatrix[c, c].DesiredSize; - } - } - - private void SaveMeasureResults() - { - for (int i = 0; i < this.rowMatrix.GetUpperBound(0) + 1; i++) - { - for (int j = 0; j < this.rowMatrix.GetUpperBound(0) + 1; j++) - { - this.rowMatrix[i, j].OriginalSize = this.rowMatrix[i, j].OfferedSize; - } - } - - for (int i = 0; i < this.colMatrix.GetUpperBound(0); i++) - { - for (int j = 0; j < this.colMatrix.GetUpperBound(0); j++) - { - this.colMatrix[i, j].OriginalSize = this.colMatrix[i, j].OfferedSize; - } - } - } - - private void RestoreMeasureResults() - { - for (int i = 0; i < this.rowMatrix.GetUpperBound(0) + 1; i++) - { - for (int j = 0; j < this.rowMatrix.GetUpperBound(0) + 1; j++) - { - this.rowMatrix[i, j].OfferedSize = this.rowMatrix[i, j].OriginalSize; - } - } - - for (int i = 0; i < this.colMatrix.GetUpperBound(0) + 1; i++) - { - for (int j = 0; j < this.colMatrix.GetUpperBound(0) + 1; j++) - { - this.colMatrix[i, j].OfferedSize = this.colMatrix[i, j].OriginalSize; - } - } - } - - private struct Segment - { - public double OriginalSize; - public double Max; - public double Min; - public double DesiredSize; - public double OfferedSize; - public double Stars; - public GridUnitType Type; - - public Segment(double offeredSize, double min, double max, GridUnitType type) - { - this.OriginalSize = 0; - this.Min = min; - this.Max = max; - this.DesiredSize = 0; - this.OfferedSize = offeredSize; - this.Stars = 0; - this.Type = type; - } - - public void Init(double offeredSize, double min, double max, GridUnitType type) - { - this.OfferedSize = offeredSize; - this.Min = min; - this.Max = max; - this.Type = type; - } - } - - private struct GridNode - { - public int Row; - public int Column; - public double Size; - public Segment[,] Matrix; - - public GridNode(Segment[,] matrix, int row, int col, double size) - { - this.Matrix = matrix; - this.Row = row; - this.Column = col; - this.Size = size; - } - } - - private class GridWalker - { - public GridWalker(Grid grid, Segment[,] rowMatrix, Segment[,] colMatrix) - { - foreach (Control child in grid.Children) - { - bool starCol = false; - bool starRow = false; - bool autoCol = false; - bool autoRow = false; - - int col = Math.Min(Grid.GetColumn(child), colMatrix.GetUpperBound(0)); - int row = Math.Min(Grid.GetRow(child), rowMatrix.GetUpperBound(0)); - int colspan = Math.Min(Grid.GetColumnSpan(child), colMatrix.GetUpperBound(0)); - int rowspan = Math.Min(Grid.GetRowSpan(child), rowMatrix.GetUpperBound(0)); - - for (int r = row; r < row + rowspan; r++) - { - starRow |= rowMatrix[r, r].Type == GridUnitType.Star; - autoRow |= rowMatrix[r, r].Type == GridUnitType.Auto; - } - - for (int c = col; c < col + colspan; c++) - { - starCol |= colMatrix[c, c].Type == GridUnitType.Star; - autoCol |= colMatrix[c, c].Type == GridUnitType.Auto; - } - - this.HasAutoAuto |= autoRow && autoCol && !starRow && !starCol; - this.HasStarAuto |= starRow && autoCol; - this.HasAutoStar |= autoRow && starCol; - } - } - - public bool HasAutoAuto { get; private set; } - - public bool HasStarAuto { get; private set; } - - public bool HasAutoStar { get; private set; } - } - } -} diff --git a/Perspex/Controls/GridLength.cs b/Perspex/Controls/GridLength.cs deleted file mode 100644 index 5958b58898..0000000000 --- a/Perspex/Controls/GridLength.cs +++ /dev/null @@ -1,121 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - - public enum GridUnitType - { - Auto = 0, - Pixel = 1, - Star = 2, - } - - public struct GridLength : IEquatable - { - private GridUnitType type; - - private double value; - - public GridLength(double value) - : this(value, GridUnitType.Pixel) - { - } - - public GridLength(double value, GridUnitType type) - { - if (value < 0 || double.IsNaN(value) || double.IsInfinity(value)) - { - throw new ArgumentException("Invalid value", "value"); - } - - if (type < GridUnitType.Auto || type > GridUnitType.Star) - { - throw new ArgumentException("Invalid value", "type"); - } - - this.type = type; - this.value = value; - } - - public static GridLength Auto - { - get { return new GridLength(0, GridUnitType.Auto); } - } - - public GridUnitType GridUnitType - { - get { return this.type; } - } - - public bool IsAbsolute - { - get { return this.type == GridUnitType.Pixel; } - } - - public bool IsAuto - { - get { return this.type == GridUnitType.Auto; } - } - - public bool IsStar - { - get { return this.type == GridUnitType.Star; } - } - - public double Value - { - get { return this.value; } - } - - public static bool operator ==(GridLength a, GridLength b) - { - return (a.IsAuto && b.IsAuto) || (a.value == b.value && a.type == b.type); - } - - public static bool operator !=(GridLength gl1, GridLength gl2) - { - return !(gl1 == gl2); - } - - public override bool Equals(object o) - { - if (o == null) - { - return false; - } - - if (!(o is GridLength)) - { - return false; - } - - return this == (GridLength)o; - } - - public bool Equals(GridLength gridLength) - { - return this == gridLength; - } - - public override int GetHashCode() - { - return this.value.GetHashCode() ^ this.type.GetHashCode(); - } - - public override string ToString() - { - if (this.IsAuto) - { - return "Auto"; - } - - string s = this.value.ToString(); - return this.IsStar ? s + "*" : s; - } - } -} diff --git a/Perspex/Controls/HeaderedContentControl.cs b/Perspex/Controls/HeaderedContentControl.cs deleted file mode 100644 index 047698d62c..0000000000 --- a/Perspex/Controls/HeaderedContentControl.cs +++ /dev/null @@ -1,43 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - - public class HeaderedContentControl : ContentControl, ILogical, IHeadered - { - public static readonly PerspexProperty HeaderProperty = - PerspexProperty.Register("Header"); - - public object Header - { - get { return this.GetValue(HeaderProperty); } - set { this.SetValue(HeaderProperty, value); } - } - - IEnumerable ILogical.LogicalChildren - { - get - { - ILogical logicalContent = this.Content as ILogical; - ILogical logicalHeader = this.Header as ILogical; - - if (logicalContent != null) - { - yield return logicalContent; - } - - if (logicalHeader != null) - { - yield return logicalHeader; - } - } - } - } -} diff --git a/Perspex/Controls/HeaderedItemsControl.cs b/Perspex/Controls/HeaderedItemsControl.cs deleted file mode 100644 index d65d1635b4..0000000000 --- a/Perspex/Controls/HeaderedItemsControl.cs +++ /dev/null @@ -1,25 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - using System.Linq; - using System.Reactive.Linq; - - public class HeaderedItemsControl : ItemsControl - { - public static readonly PerspexProperty HeaderProperty = - HeaderedContentControl.HeaderProperty.AddOwner(); - - public object Header - { - get { return this.GetValue(HeaderProperty); } - set { this.SetValue(HeaderProperty, value); } - } - } -} diff --git a/Perspex/Controls/ITemplatedControl.cs b/Perspex/Controls/ITemplatedControl.cs deleted file mode 100644 index 473ab8c876..0000000000 --- a/Perspex/Controls/ITemplatedControl.cs +++ /dev/null @@ -1,24 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - - public interface ITemplatedControl - { - IEnumerable VisualChildren { get; } - - /// - /// Gets an observable for a . - /// - /// - /// The property to get the observable for. - /// The observable. - IObservable GetObservable(PerspexProperty property); - } -} diff --git a/Perspex/Controls/Image.cs b/Perspex/Controls/Image.cs deleted file mode 100644 index cb594b3340..0000000000 --- a/Perspex/Controls/Image.cs +++ /dev/null @@ -1,115 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using Perspex.Media; - using Perspex.Media.Imaging; - - public class Image : Control - { - public static readonly PerspexProperty SourceProperty = - PerspexProperty.Register("Source"); - - public static readonly PerspexProperty StretchProperty = - PerspexProperty.Register("Stretch", Stretch.Uniform); - - public Bitmap Source - { - get { return this.GetValue(SourceProperty); } - set { this.SetValue(SourceProperty, value); } - } - - public Stretch Stretch - { - get { return (Stretch)this.GetValue(StretchProperty); } - set { this.SetValue(StretchProperty, value); } - } - - public override void Render(IDrawingContext drawingContext) - { - Brush background = this.Background; - Bitmap source = this.Source; - - if (background != null) - { - drawingContext.FillRectange(background, new Rect(this.ActualSize)); - } - - if (source != null) - { - Rect viewPort = new Rect(this.ActualSize); - Size sourceSize = new Size(source.PixelWidth, source.PixelHeight); - Vector scale = CalculateScaling(this.ActualSize, sourceSize, this.Stretch); - Size scaledSize = sourceSize * scale; - Rect destRect = viewPort - .Center(new Rect(scaledSize)) - .Intersect(viewPort); - Rect sourceRect = new Rect(sourceSize) - .Center(new Rect(destRect.Size / scale)); - - drawingContext.DrawImage(source, 1, sourceRect, destRect); - } - } - - private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch) - { - double scaleX = 1; - double scaleY = 1; - - if (stretch != Stretch.None) - { - scaleX = availableSize.Width / imageSize.Width; - scaleY = availableSize.Height / imageSize.Height; - - switch (stretch) - { - case Stretch.Uniform: - scaleX = scaleY = Math.Min(scaleX, scaleY); - break; - case Stretch.UniformToFill: - scaleX = scaleY = Math.Max(scaleX, scaleY); - break; - } - } - - return new Vector(scaleX, scaleY); - } - - protected override Size MeasureOverride(Size availableSize) - { - double width = 0; - double height = 0; - Vector scale = new Vector(); - - if (this.Source != null) - { - width = this.Source.PixelWidth; - height = this.Source.PixelHeight; - - if (this.Width > 0) - { - availableSize = new Size(this.Width, availableSize.Height); - } - - if (this.Height > 0) - { - availableSize = new Size(availableSize.Width, this.Height); - } - - scale = CalculateScaling(availableSize, new Size(width, height), this.Stretch); - } - - return new Size(width * scale.X, height * scale.Y); - } - - protected override Size ArrangeOverride(Size finalSize) - { - return finalSize; - } - } -} diff --git a/Perspex/Controls/ItemsControl.cs b/Perspex/Controls/ItemsControl.cs deleted file mode 100644 index 7b26728be9..0000000000 --- a/Perspex/Controls/ItemsControl.cs +++ /dev/null @@ -1,137 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.ComponentModel; - using System.Linq; - - public class ItemsControl : TemplatedControl - { - private static readonly ItemsPanelTemplate DefaultPanel = - new ItemsPanelTemplate(() => new StackPanel { Orientation = Orientation.Vertical }); - - public static readonly PerspexProperty ItemsProperty = - PerspexProperty.Register("Items"); - - public static readonly PerspexProperty ItemsPanelProperty = - PerspexProperty.Register("ItemsPanel", defaultValue: DefaultPanel); - - private Dictionary controlsByItem = new Dictionary(); - - private Dictionary itemsByControl = new Dictionary(); - - public ItemsControl() - { - this.GetObservableWithHistory(ItemsProperty).Subscribe(this.ItemsChanged); - } - - public IEnumerable Items - { - get { return this.GetValue(ItemsProperty); } - set { this.SetValue(ItemsProperty, value); } - } - - public ItemsPanelTemplate ItemsPanel - { - get { return this.GetValue(ItemsPanelProperty); } - set { this.SetValue(ItemsPanelProperty, value); } - } - - public Control GetControlForItem(object item) - { - Control result; - this.controlsByItem.TryGetValue(item, out result); - return result; - } - - public object GetItemForControl(Control control) - { - object result; - this.itemsByControl.TryGetValue(control, out result); - return result; - } - - public IEnumerable GetAllItemControls() - { - return this.controlsByItem.Values; - } - - internal Control CreateItemControl(object item) - { - Control control = this.CreateItemControlOverride(item); - this.itemsByControl.Add(control, item); - this.controlsByItem.Add(item, control); - return control; - } - - internal void RemoveItemControls(IEnumerable items) - { - foreach (object i in items) - { - Control control = this.GetControlForItem(i); - this.controlsByItem.Remove(i); - this.itemsByControl.Remove(control); - } - } - - internal void ClearItemControls() - { - this.controlsByItem.Clear(); - this.itemsByControl.Clear(); - } - - protected virtual Control CreateItemControlOverride(object item) - { - return (item as Control) ?? this.GetDataTemplate(item).Build(item); - } - - private void ItemsChanged(Tuple value) - { - INotifyPropertyChanged inpc = value.Item1 as INotifyPropertyChanged; - - if (inpc != null) - { - inpc.PropertyChanged -= ItemsPropertyChanged; - } - - if (value.Item2 == null || !value.Item2.OfType().Any()) - { - this.Classes.Add(":empty"); - } - else - { - this.Classes.Remove(":empty"); - } - - inpc = value.Item2 as INotifyPropertyChanged; - - if (inpc != null) - { - inpc.PropertyChanged += ItemsPropertyChanged; - } - } - - private void ItemsPropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == "Count") - { - if (((IList)sender).Count == 0) - { - this.Classes.Add(":empty"); - } - else - { - this.Classes.Remove(":empty"); - } - } - } - } -} diff --git a/Perspex/Controls/ItemsPanelTemplate.cs b/Perspex/Controls/ItemsPanelTemplate.cs deleted file mode 100644 index 1e2375c5b0..0000000000 --- a/Perspex/Controls/ItemsPanelTemplate.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Perspex.Controls -{ - public class ItemsPanelTemplate - { - public ItemsPanelTemplate(Func build) - { - Contract.Requires(build != null); - - this.Build = build; - } - - public Func Build { get; private set; } - } -} diff --git a/Perspex/Controls/ItemsPresenter.cs b/Perspex/Controls/ItemsPresenter.cs deleted file mode 100644 index ac0cbe728e..0000000000 --- a/Perspex/Controls/ItemsPresenter.cs +++ /dev/null @@ -1,190 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Linq; - using Perspex.Layout; - - public class ItemsPresenter : Control, IVisual - { - public static readonly PerspexProperty ItemsProperty = - ItemsControl.ItemsProperty.AddOwner(); - - public static readonly PerspexProperty ItemsPanelProperty = - ItemsControl.ItemsPanelProperty.AddOwner(); - - private Panel panel; - - public ItemsPresenter() - { - this.GetObservableWithHistory(ItemsProperty).Subscribe(this.ItemsChanged); - } - - public IEnumerable Items - { - get { return this.GetValue(ItemsProperty); } - set { this.SetValue(ItemsProperty, value); } - } - - public ItemsPanelTemplate ItemsPanel - { - get { return this.GetValue(ItemsPanelProperty); } - set { this.SetValue(ItemsPanelProperty, value); } - } - - IEnumerable IVisual.ExistingVisualChildren - { - get { return Enumerable.Repeat(this.panel, this.panel != null ? 1 : 0); } - } - - IEnumerable IVisual.VisualChildren - { - get { return Enumerable.Repeat(this.GetPanel(), 1); } - } - - protected override Size MeasureOverride(Size availableSize) - { - Panel panel = this.GetPanel(); - panel.Measure(availableSize); - return panel.DesiredSize.Value; - } - - protected override Size ArrangeOverride(Size finalSize) - { - this.GetPanel().Arrange(new Rect(finalSize)); - return finalSize; - } - - private Control CreateItemControl(object item) - { - ItemsControl i = this.TemplatedParent as ItemsControl; - - if (i != null) - { - return i.CreateItemControl(item); - } - else - { - return this.GetDataTemplate(item).Build(item) as Control; - } - } - - private IEnumerable CreateItemControls(IEnumerable items) - { - if (items != null) - { - return items - .Cast() - .Select(x => this.CreateItemControl(x)) - .OfType(); - } - else - { - return Enumerable.Empty(); - } - } - - private void ClearItemControls() - { - ItemsControl i = this.TemplatedParent as ItemsControl; - - if (i != null) - { - i.ClearItemControls(); - } - } - - private void RemoveItemControls(IEnumerable items) - { - ItemsControl i = this.TemplatedParent as ItemsControl; - - if (i != null) - { - i.RemoveItemControls(items); - } - } - - private Panel GetPanel() - { - if (this.panel == null && this.ItemsPanel != null) - { - this.panel = this.ItemsPanel.Build(); - ((IVisual)this.panel).VisualParent = this; - this.ItemsChanged(Tuple.Create(default(IEnumerable), this.Items)); - } - - return this.panel; - } - - private void ItemsChanged(Tuple value) - { - if (value.Item1 != null) - { - INotifyCollectionChanged incc = value.Item1 as INotifyCollectionChanged; - - if (incc != null) - { - incc.CollectionChanged -= this.ItemsCollectionChanged; - } - } - - this.ClearItemControls(); - - if (this.panel != null) - { - var controls = this.CreateItemControls(value.Item2).ToList(); - - foreach (var control in controls) - { - control.TemplatedParent = null; - } - - this.panel.Children = new Controls(controls); - - INotifyCollectionChanged incc = value.Item2 as INotifyCollectionChanged; - - if (incc != null) - { - incc.CollectionChanged += this.ItemsCollectionChanged; - } - } - } - - private void ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - if (this.panel != null) - { - // TODO: Handle Move and Replace. - switch (e.Action) - { - case NotifyCollectionChangedAction.Add: - var controls = this.CreateItemControls(e.NewItems).ToList(); - - foreach (var control in controls) - { - control.TemplatedParent = null; - } - - this.panel.Children.AddRange(controls); - break; - - case NotifyCollectionChangedAction.Remove: - this.RemoveItemControls(e.OldItems); - break; - - case NotifyCollectionChangedAction.Reset: - this.ItemsChanged(Tuple.Create(this.Items, this.Items)); - break; - } - } - } - } -} diff --git a/Perspex/Controls/LogicalChildren.cs b/Perspex/Controls/LogicalChildren.cs deleted file mode 100644 index 5ea6f97a71..0000000000 --- a/Perspex/Controls/LogicalChildren.cs +++ /dev/null @@ -1,99 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Collections.Specialized; - using System.Linq; - - /// - /// Manages parenting for a collection of logical child controls. - /// - /// The type of the controls. - /// - /// Unfortunately, because of ObservableCollection's handling of clear (the cleared items - /// aren't passed to the CollectionChanged event) we have to hold two lists of child controls: - /// the ones in Panel.Children and the ones here - held in case the ObservableCollection - /// gets cleared. It's either that or write a proper PerspexList which is too much work - /// for now. - /// - internal class LogicalChildren where T : class, ILogical, IVisual - { - private T parent; - - private PerspexList childrenCollection; - - private List inner = new List(); - - public LogicalChildren(T parent, PerspexList childrenCollection) - { - this.parent = parent; - this.childrenCollection = childrenCollection; - this.Add(childrenCollection); - childrenCollection.CollectionChanged += this.CollectionChanged; - } - - public void Change(PerspexList childrenCollection) - { - this.childrenCollection.CollectionChanged -= this.CollectionChanged; - this.Remove(this.inner.ToList()); - this.childrenCollection = childrenCollection; - this.Add(childrenCollection); - childrenCollection.CollectionChanged += this.CollectionChanged; - } - - private void Add(IEnumerable items) - { - foreach (T item in items) - { - this.inner.Add(item); - item.LogicalParent = this.parent; - item.VisualParent = this.parent; - } - } - - private void Remove(IEnumerable items) - { - foreach (T item in items) - { - this.inner.Remove(item); - item.LogicalParent = null; - item.VisualParent = null; - } - } - - private void Reset(IEnumerable newState) - { - this.Add(newState.Except(this.inner)); - this.Remove(this.inner.Except(newState)); - } - - private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - switch (e.Action) - { - case NotifyCollectionChangedAction.Add: - this.Add(e.NewItems.Cast()); - break; - - case NotifyCollectionChangedAction.Remove: - this.Remove(e.OldItems.Cast()); - break; - - case NotifyCollectionChangedAction.Replace: - this.Remove(e.OldItems.Cast()); - this.Add(e.NewItems.Cast()); - break; - - case NotifyCollectionChangedAction.Reset: - this.Reset((IEnumerable)sender); - break; - } - } - } -} diff --git a/Perspex/Controls/Panel.cs b/Perspex/Controls/Panel.cs deleted file mode 100644 index 4c216b5baf..0000000000 --- a/Perspex/Controls/Panel.cs +++ /dev/null @@ -1,64 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Collections.Specialized; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - /// - /// Base class for controls that can contain multiple children. - /// - public class Panel : Control, ILogical, IVisual - { - private Controls children; - - private LogicalChildren logicalChildren; - - public Controls Children - { - get - { - if (this.children == null) - { - this.children = new Controls(); - this.logicalChildren = new LogicalChildren(this, this.children); - } - - return this.children; - } - - set - { - this.children = value; - - if (this.logicalChildren != null) - { - this.logicalChildren.Change(this.children); - } - else - { - this.logicalChildren = new LogicalChildren(this, this.children); - } - } - } - - IEnumerable ILogical.LogicalChildren - { - get { return this.children ?? Enumerable.Empty(); } - } - - IEnumerable IVisual.VisualChildren - { - get { return this.children ?? Enumerable.Empty(); } - } - } -} diff --git a/Perspex/Controls/RowDefinition.cs b/Perspex/Controls/RowDefinition.cs deleted file mode 100644 index 230fb7a14a..0000000000 --- a/Perspex/Controls/RowDefinition.cs +++ /dev/null @@ -1,53 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class RowDefinition : DefinitionBase - { - public static readonly PerspexProperty MaxHeightProperty = - PerspexProperty.Register("MaxHeight", double.PositiveInfinity); - - public static readonly PerspexProperty MinHeightProperty = - PerspexProperty.Register("MinHeight"); - - public static readonly PerspexProperty HeightProperty = - PerspexProperty.Register("Height", new GridLength(1, GridUnitType.Star)); - - public RowDefinition() - { - } - - public RowDefinition(GridLength height) - { - this.Height = height; - } - - public double ActualHeight - { - get; - internal set; - } - - public double MaxHeight - { - get { return this.GetValue(MaxHeightProperty); } - set { this.SetValue(MaxHeightProperty, value); } - } - - public double MinHeight - { - get { return this.GetValue(MinHeightProperty); } - set { this.SetValue(MinHeightProperty, value); } - } - - public GridLength Height - { - get { return this.GetValue(HeightProperty); } - set { this.SetValue(HeightProperty, value); } - } - } -} diff --git a/Perspex/Controls/RowDefinitions.cs b/Perspex/Controls/RowDefinitions.cs deleted file mode 100644 index 60ea0da556..0000000000 --- a/Perspex/Controls/RowDefinitions.cs +++ /dev/null @@ -1,12 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class RowDefinitions : PerspexList - { - } -} diff --git a/Perspex/Controls/SelectingItemsControl.cs b/Perspex/Controls/SelectingItemsControl.cs deleted file mode 100644 index 28ba4ff363..0000000000 --- a/Perspex/Controls/SelectingItemsControl.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class SelectingItemsControl : ItemsControl - { - public static readonly PerspexProperty SelectedItemProperty = - PerspexProperty.Register("SelectedItem"); - - public object SelectedItem - { - get { return this.GetValue(SelectedItemProperty); } - set { this.SetValue(SelectedItemProperty, value); } - } - } -} diff --git a/Perspex/Controls/StackPanel.cs b/Perspex/Controls/StackPanel.cs deleted file mode 100644 index 4ce3d9a9ac..0000000000 --- a/Perspex/Controls/StackPanel.cs +++ /dev/null @@ -1,155 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public enum Orientation - { - Vertical, - Horizontal, - } - - public class StackPanel : Panel - { - public static readonly PerspexProperty GapProperty = - PerspexProperty.Register("Gap"); - - public static readonly PerspexProperty OrientationProperty = - PerspexProperty.Register("Orientation"); - - public double Gap - { - get { return this.GetValue(GapProperty); } - set { this.SetValue(GapProperty, value); } - } - - public Orientation Orientation - { - get { return this.GetValue(OrientationProperty); } - set { this.SetValue(OrientationProperty, value); } - } - - protected override Size MeasureOverride(Size availableSize) - { - double childAvailableWidth = double.PositiveInfinity; - double childAvailableHeight = double.PositiveInfinity; - - if (this.Orientation == Orientation.Vertical) - { - childAvailableWidth = availableSize.Width; - - if (!double.IsNaN(this.Width)) - { - childAvailableWidth = this.Width; - } - - childAvailableWidth = Math.Min(childAvailableWidth, this.MaxWidth); - childAvailableWidth = Math.Max(childAvailableWidth, this.MinWidth); - } - else - { - childAvailableHeight = availableSize.Height; - - if (!double.IsNaN(this.Height)) - { - childAvailableHeight = this.Height; - } - - childAvailableHeight = Math.Min(childAvailableHeight, this.MaxHeight); - childAvailableHeight = Math.Max(childAvailableHeight, this.MinHeight); - } - - double measuredWidth = 0; - double measuredHeight = 0; - double gap = this.Gap; - - foreach (Control child in this.Children) - { - child.Measure(new Size(childAvailableWidth, childAvailableHeight)); - Size size = child.DesiredSize.Value; - - if (Orientation == Orientation.Vertical) - { - measuredHeight += size.Height + gap; - measuredWidth = Math.Max(measuredWidth, size.Width); - } - else - { - measuredWidth += size.Width + gap; - measuredHeight = Math.Max(measuredHeight, size.Height); - } - } - - return new Size(measuredWidth, measuredHeight); - } - - protected override Size ArrangeOverride(Size finalSize) - { - double arrangedWidth = finalSize.Width; - double arrangedHeight = finalSize.Height; - double gap = this.Gap; - - if (Orientation == Orientation.Vertical) - { - arrangedHeight = 0; - } - else - { - arrangedWidth = 0; - } - - foreach (Control child in this.Children.Where(x => x.DesiredSize.HasValue)) - { - double childWidth = child.DesiredSize.Value.Width; - double childHeight = child.DesiredSize.Value.Height; - - if (Orientation == Orientation.Vertical) - { - childWidth = finalSize.Width; - - Rect childFinal = new Rect(0, arrangedHeight, childWidth, childHeight); - - if (childFinal.IsEmpty) - { - child.Arrange(new Rect()); - } - else - { - child.Arrange(childFinal); - } - - arrangedWidth = Math.Max(arrangedWidth, childWidth); - arrangedHeight += childHeight + gap; - } - else - { - childHeight = finalSize.Height; - Rect childFinal = new Rect(arrangedWidth, 0, childWidth, childHeight); - child.Arrange(childFinal); - arrangedWidth += childWidth + gap; - arrangedHeight = Math.Max(arrangedHeight, childHeight); - } - } - - if (Orientation == Orientation.Vertical) - { - arrangedHeight = Math.Max(arrangedHeight - gap, finalSize.Height); - } - else - { - arrangedWidth = Math.Max(arrangedWidth - gap, finalSize.Width); - } - - return new Size(arrangedWidth, arrangedHeight); - } - } -} diff --git a/Perspex/Controls/TabControl.cs b/Perspex/Controls/TabControl.cs deleted file mode 100644 index 0f0ee31607..0000000000 --- a/Perspex/Controls/TabControl.cs +++ /dev/null @@ -1,67 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - - public class TabControl : SelectingItemsControl, ILogical - { - public static readonly PerspexProperty SelectedContentProperty = - PerspexProperty.Register("SelectedContent"); - - private TabStrip tabStrip; - - public TabControl() - { - this.GetObservable(SelectedItemProperty).Skip(1).Subscribe(this.SelectedItemChanged); - } - - IEnumerable ILogical.LogicalChildren - { - get { return this.Items.OfType(); } - } - - protected override void OnTemplateApplied() - { - this.tabStrip = this.GetTemplateControls() - .OfType() - .FirstOrDefault(); - - if (this.tabStrip != null) - { - if (this.IsSet(SelectedItemProperty)) - { - this.SelectedItem = SelectedItem; - } - - this.tabStrip.GetObservable(TabStrip.SelectedItemProperty).Subscribe(x => - { - this.SelectedItem = x; - }); - } - } - - private void SelectedItemChanged(object item) - { - this.SelectedItem = item; - - ContentControl content = item as ContentControl; - - if (content != null) - { - this.SetValue(SelectedContentProperty, content.Content); - } - else - { - this.SetValue(SelectedContentProperty, item); - } - } - } -} diff --git a/Perspex/Controls/TabItem.cs b/Perspex/Controls/TabItem.cs deleted file mode 100644 index 351f4f2941..0000000000 --- a/Perspex/Controls/TabItem.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class TabItem : HeaderedContentControl - { - public static readonly PerspexProperty IsSelectedProperty = - PerspexProperty.Register("IsSelected"); - - public TabItem() - { - this.AddPseudoClass(IsSelectedProperty, ":selected"); - AffectsRender(IsSelectedProperty); - } - - public bool IsSelected - { - get { return this.GetValue(IsSelectedProperty); } - set { this.SetValue(IsSelectedProperty, value); } - } - } -} diff --git a/Perspex/Controls/TabStrip.cs b/Perspex/Controls/TabStrip.cs deleted file mode 100644 index 534fd10948..0000000000 --- a/Perspex/Controls/TabStrip.cs +++ /dev/null @@ -1,86 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - using System.Linq; - using Perspex.Input; - - public class TabStrip : SelectingItemsControl - { - private static readonly ItemsPanelTemplate PanelTemplate = new ItemsPanelTemplate( - () => new StackPanel()); - - static TabStrip() - { - ItemsPanelProperty.OverrideDefaultValue(typeof(TabStrip), PanelTemplate); - } - - public TabStrip() - { - this.PointerPressed += this.OnPointerPressed; - this.GetObservable(ItemsProperty).Subscribe(this.ItemsChanged); - this.GetObservable(SelectedItemProperty).Subscribe(this.SelectedItemChanged); - } - - protected override Control CreateItemControlOverride(object item) - { - TabItem result = item as TabItem; - - if (result == null) - { - result = new TabItem - { - Content = this.GetDataTemplate(item).Build(item), - }; - } - - result.IsSelected = this.SelectedItem == item; - - return result; - } - - private void ItemsChanged(IEnumerable items) - { - if (items != null) - { - this.SelectedItem = - items.OfType().FirstOrDefault(x => x.IsSelected) ?? - items.OfType().FirstOrDefault(); - } - else - { - this.SelectedItem = null; - } - } - - private void OnPointerPressed(object sender, PointerEventArgs e) - { - IVisual source = (IVisual)e.Source; - ContentPresenter presenter = source.GetVisualAncestor(); - - if (presenter != null) - { - TabItem item = presenter.TemplatedParent as TabItem; - - if (item != null) - { - this.SelectedItem = item; - } - } - } - - private void SelectedItemChanged(object selectedItem) - { - foreach (TabItem item in this.GetAllItemControls()) - { - item.IsSelected = item == selectedItem; - } - } - } -} diff --git a/Perspex/Controls/TemplatedControl.cs b/Perspex/Controls/TemplatedControl.cs deleted file mode 100644 index 1b0b0b94ed..0000000000 --- a/Perspex/Controls/TemplatedControl.cs +++ /dev/null @@ -1,94 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Perspex.Media; - using Splat; - - public class TemplatedControl : Control, IVisual, ITemplatedControl - { - public static readonly PerspexProperty TemplateProperty = - PerspexProperty.Register("Template"); - - public ControlTemplate Template - { - get { return this.GetValue(TemplateProperty); } - set { this.SetValue(TemplateProperty, value); } - } - - IEnumerable IVisual.ExistingVisualChildren - { - get { return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0); } - } - - IEnumerable ITemplatedControl.VisualChildren - { - get - { - var template = this.Template; - - if (this.visualChild == null && template != null) - { - this.Log().Debug(string.Format( - "Creating template for {0} (#{1:x8})", - this.GetType().Name, - this.GetHashCode())); - - this.visualChild = template.Build(this); - this.visualChild.VisualParent = this; - this.OnTemplateApplied(); - } - - return Enumerable.Repeat(this.visualChild, this.visualChild != null ? 1 : 0); - } - } - - IEnumerable IVisual.VisualChildren - { - get { return ((ITemplatedControl)this).VisualChildren; } - } - - public sealed override void Render(IDrawingContext context) - { - } - - protected override Size ArrangeOverride(Size finalSize) - { - Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control; - - if (child != null) - { - child.Arrange(new Rect(finalSize)); - return child.ActualSize; - } - else - { - return new Size(); - } - } - - protected override Size MeasureOverride(Size availableSize) - { - Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control; - - if (child != null) - { - child.Measure(availableSize); - return child.DesiredSize.Value; - } - - return new Size(); - } - - protected virtual void OnTemplateApplied() - { - } - } -} diff --git a/Perspex/Controls/TextBlock.cs b/Perspex/Controls/TextBlock.cs deleted file mode 100644 index 8d8d275b64..0000000000 --- a/Perspex/Controls/TextBlock.cs +++ /dev/null @@ -1,65 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using Perspex.Media; - using Perspex.Platform; - using Splat; - - public class TextBlock : Control - { - public static readonly PerspexProperty TextProperty = - PerspexProperty.Register("Text"); - - static TextBlock() - { - AffectsMeasure(TextProperty); - } - - public string Text - { - get { return this.GetValue(TextProperty); } - set { this.SetValue(TextProperty, value); } - } - - private FormattedText FormattedText - { - get - { - return new FormattedText - { - FontFamilyName = "Segoe UI", - FontSize = this.FontSize, - Text = this.Text, - }; - } - } - - public override void Render(IDrawingContext context) - { - Brush background = this.Background; - - if (background != null) - { - context.FillRectange(background, new Rect(this.ActualSize)); - } - - context.DrawText(this.Foreground, new Rect(this.ActualSize), this.FormattedText); - } - - protected override Size MeasureOverride(Size availableSize) - { - if (!string.IsNullOrEmpty(this.Text)) - { - return this.FormattedText.Measure(availableSize); - } - - return new Size(); - } - } -} diff --git a/Perspex/Controls/TextBox.cs b/Perspex/Controls/TextBox.cs deleted file mode 100644 index adf102fdd2..0000000000 --- a/Perspex/Controls/TextBox.cs +++ /dev/null @@ -1,133 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Linq; - using Perspex.Input; - using Perspex.Platform; - using Perspex.Styling; - using Splat; - - public class TextBox : TemplatedControl - { - public static readonly PerspexProperty TextProperty = - TextBlock.TextProperty.AddOwner(); - - private int caretIndex; - - private TextBoxView textBoxView; - - static TextBox() - { - FocusableProperty.OverrideDefaultValue(typeof(TextBox), true); - } - - public TextBox() - { - this.GotFocus += (s, e) => this.textBoxView.GotFocus(); - this.LostFocus += (s, e) => this.textBoxView.LostFocus(); - this.KeyDown += this.OnKeyDown; - this.PointerPressed += this.OnPointerPressed; - } - - public int CaretIndex - { - get - { - return this.caretIndex; - } - - set - { - value = Math.Min(Math.Max(value, 0), this.Text.Length); - - if (this.caretIndex != value) - { - this.caretIndex = value; - this.textBoxView.CaretMoved(); - } - } - } - - public string Text - { - get { return this.GetValue(TextProperty); } - set { this.SetValue(TextProperty, value); } - } - - protected override void OnTemplateApplied() - { - Decorator textContainer = this.GetVisualDescendents() - .OfType() - .FirstOrDefault(x => x.Id == "textContainer"); - - if (textContainer == null) - { - throw new Exception( - "TextBox template doesn't contain a textContainer " + - "or textContainer is not a Decorator."); - } - - textContainer.Content = this.textBoxView = new TextBoxView(this); - this.GetObservable(TextProperty).Subscribe(_ => this.textBoxView.InvalidateText()); - } - - private void OnKeyDown(object sender, KeyEventArgs e) - { - string text = this.Text; - - switch (e.Key) - { - case Key.Left: - --this.CaretIndex; - break; - - case Key.Right: - ++this.CaretIndex; - break; - - case Key.Back: - if (this.caretIndex > 0) - { - this.Text = text.Substring(0, this.caretIndex - 1) + text.Substring(this.caretIndex); - --this.CaretIndex; - } - - break; - - case Key.Delete: - if (this.caretIndex < text.Length) - { - this.Text = text.Substring(0, this.caretIndex) + text.Substring(this.caretIndex + 1); - } - - break; - - default: - if (!string.IsNullOrEmpty(e.Text)) - { - this.Text = text.Substring(0, this.caretIndex) + e.Text + text.Substring(this.caretIndex); - ++this.CaretIndex; - } - - break; - } - - e.Handled = true; - } - - private void OnPointerPressed(object sender, PointerEventArgs e) - { - IPlatformRenderInterface platform = Locator.Current.GetService(); - this.CaretIndex = platform.TextService.GetCaretIndex( - this.textBoxView.FormattedText, - e.GetPosition(this.textBoxView), - this.ActualSize); - } - } -} diff --git a/Perspex/Controls/TextBoxView.cs b/Perspex/Controls/TextBoxView.cs deleted file mode 100644 index 9c452223e8..0000000000 --- a/Perspex/Controls/TextBoxView.cs +++ /dev/null @@ -1,126 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Globalization; - using Perspex.Layout; - using Perspex.Media; - using Perspex.Platform; - using Perspex.Threading; - using Splat; - - internal class TextBoxView : Control - { - private TextBox parent; - - private FormattedText formattedText; - - private DispatcherTimer caretTimer; - - private bool caretBlink; - - public TextBoxView(TextBox parent) - { - this.caretTimer = new DispatcherTimer(); - this.caretTimer.Interval = TimeSpan.FromMilliseconds(500); - this.caretTimer.Tick += this.CaretTimerTick; - this.parent = parent; - } - - public FormattedText FormattedText - { - get - { - if (this.formattedText == null) - { - this.formattedText = this.CreateFormattedText(); - } - - return this.formattedText; - } - } - - public new void GotFocus() - { - this.caretBlink = true; - this.caretTimer.Start(); - } - - public new void LostFocus() - { - this.caretTimer.Stop(); - this.InvalidateVisual(); - } - - public void InvalidateText() - { - this.formattedText = null; - this.InvalidateMeasure(); - } - - internal void CaretMoved() - { - this.caretBlink = true; - this.caretTimer.Stop(); - this.caretTimer.Start(); - this.InvalidateVisual(); - } - - public override void Render(IDrawingContext context) - { - Rect rect = new Rect(this.ActualSize); - - context.DrawText(Brushes.Black, rect, this.FormattedText); - - if (this.parent.IsFocused) - { - IPlatformRenderInterface platform = Locator.Current.GetService(); - Point caretPos = platform.TextService.GetCaretPosition( - this.formattedText, - this.parent.CaretIndex, - this.ActualSize); - double[] lineHeights = platform.TextService.GetLineHeights(this.formattedText, this.ActualSize); - Brush caretBrush = Brushes.Black; - - if (this.caretBlink) - { - context.DrawLine( - new Pen(caretBrush, 1), - caretPos, - new Point(caretPos.X, caretPos.Y + lineHeights[0])); - } - } - } - - protected override Size MeasureOverride(Size constraint) - { - if (!string.IsNullOrEmpty(this.parent.Text)) - { - return this.FormattedText.Measure(constraint); - } - - return new Size(); - } - - private FormattedText CreateFormattedText() - { - return new FormattedText - { - FontFamilyName = "Segoe UI", - FontSize = this.FontSize, - Text = this.parent.Text, - }; - } - - private void CaretTimerTick(object sender, EventArgs e) - { - this.caretBlink = !this.caretBlink; - this.InvalidateVisual(); - } - } -} diff --git a/Perspex/Controls/ToggleButton.cs b/Perspex/Controls/ToggleButton.cs deleted file mode 100644 index 288b826a30..0000000000 --- a/Perspex/Controls/ToggleButton.cs +++ /dev/null @@ -1,28 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - - public class ToggleButton : Button - { - public static readonly PerspexProperty IsCheckedProperty = - PerspexProperty.Register("IsChecked"); - - public ToggleButton() - { - this.Click += (s, e) => this.IsChecked = !this.IsChecked; - this.AddPseudoClass(IsCheckedProperty, ":checked"); - } - - public bool IsChecked - { - get { return this.GetValue(IsCheckedProperty); } - set { this.SetValue(IsCheckedProperty, value); } - } - } -} diff --git a/Perspex/Controls/TreeDataTemplate.cs b/Perspex/Controls/TreeDataTemplate.cs deleted file mode 100644 index 5a78fea93f..0000000000 --- a/Perspex/Controls/TreeDataTemplate.cs +++ /dev/null @@ -1,107 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - - public class TreeDataTemplate : DataTemplate - { - public TreeDataTemplate( - Func build, - Func itemsSelector) - : this(o => true, build, itemsSelector) - { - } - - public TreeDataTemplate( - Type type, - Func build, - Func itemsSelector) - : this(o => IsInstance(o, type), build, itemsSelector) - { - } - - public TreeDataTemplate( - Type type, - Func build, - Func itemsSelector, - Func isExpanded) - : this(o => IsInstance(o, type), build, itemsSelector, isExpanded) - { - } - - public TreeDataTemplate( - Func match, - Func build, - Func itemsSelector) - : this(match, build, itemsSelector, _ => false) - { - this.ItemsSelector = itemsSelector; - } - - public TreeDataTemplate( - Func match, - Func build, - Func itemsSelector, - Func isExpanded) - : base(match, build) - { - this.ItemsSelector = itemsSelector; - this.IsExpanded = isExpanded; - } - - public Func ItemsSelector { get; private set; } - - public Func IsExpanded { get; private set; } - } - - public class TreeDataTemplate : TreeDataTemplate - { - public TreeDataTemplate( - Func build, - Func itemsSelector) - : base(typeof(T), Cast(build), Cast(itemsSelector)) - { - } - - public TreeDataTemplate( - Func build, - Func itemsSelector, - Func isExpanded) - : base(typeof(T), Cast(build), Cast(itemsSelector), Cast(isExpanded)) - { - } - - public TreeDataTemplate( - Func match, - Func build, - Func itemsSelector) - : base(CastMatch(match), Cast(build), Cast(itemsSelector)) - { - } - - public TreeDataTemplate( - Func match, - Func build, - Func itemsSelector, - Func isExpanded) - : base(CastMatch(match), Cast(build), Cast(itemsSelector), Cast(isExpanded)) - { - } - - private static Func CastMatch(Func f) - { - return o => (o is T) ? f((T)o) : false; - } - - private static Func Cast(Func f) - { - return o => f((T)o); - } - } -} diff --git a/Perspex/Controls/TreeView.cs b/Perspex/Controls/TreeView.cs deleted file mode 100644 index 6e2c8446c2..0000000000 --- a/Perspex/Controls/TreeView.cs +++ /dev/null @@ -1,76 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Collections; - using System.Linq; - using System.Reactive.Linq; - using Perspex.Input; - - public class TreeView : SelectingItemsControl - { - public TreeView() - { - this.PointerPressed += this.OnPointerPressed; - } - - protected override Control CreateItemControlOverride(object item) - { - TreeViewItem result = item as TreeViewItem; - - if (result == null) - { - TreeDataTemplate template = this.GetTreeDataTemplate(item); - - result = new TreeViewItem - { - Header = template.Build(item), - Items = template.ItemsSelector(item), - IsExpanded = template.IsExpanded(item), - }; - } - - return result; - } - - private TreeDataTemplate GetTreeDataTemplate(object item) - { - DataTemplate template = this.GetDataTemplate(item); - TreeDataTemplate treeTemplate = template as TreeDataTemplate; - - if (treeTemplate == null) - { - treeTemplate = new TreeDataTemplate(template.Build, x => null); - } - - return treeTemplate; - } - - private void OnPointerPressed(object sender, PointerEventArgs e) - { - IVisual source = (IVisual)e.Source; - ContentPresenter contentPresenter = source.GetVisualAncestor(); - - if (contentPresenter != null) - { - TreeViewItem item = contentPresenter.TemplatedParent as TreeViewItem; - - if (item != null) - { - foreach (var i in this.GetVisualDescendents().OfType()) - { - i.IsSelected = i == item; - } - - this.SelectedItem = this.GetItemForControl(item); - } - } - - } - } -} diff --git a/Perspex/Controls/TreeViewItem.cs b/Perspex/Controls/TreeViewItem.cs deleted file mode 100644 index acaed18b2b..0000000000 --- a/Perspex/Controls/TreeViewItem.cs +++ /dev/null @@ -1,54 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - public class TreeViewItem : HeaderedItemsControl - { - public static readonly PerspexProperty IsExpandedProperty = - PerspexProperty.Register("IsExpanded"); - - public static readonly PerspexProperty IsSelectedProperty = - PerspexProperty.Register("IsSelected"); - - TreeView parent; - - public TreeViewItem() - { - this.AddPseudoClass(IsSelectedProperty, ":selected"); - AffectsRender(IsSelectedProperty); - } - - public bool IsExpanded - { - get { return this.GetValue(IsExpandedProperty); } - set { this.SetValue(IsExpandedProperty, value); } - } - - public bool IsSelected - { - get { return this.GetValue(IsSelectedProperty); } - set { this.SetValue(IsSelectedProperty, value); } - } - - protected override Control CreateItemControlOverride(object item) - { - if (this.parent != null) - { - return this.parent.CreateItemControl(item); - } - else - { - return null; - } - } - - protected override void OnVisualParentChanged(IVisual oldParent) - { - this.parent = this.GetVisualAncestor(); - } - } -} diff --git a/Perspex/Diagnostics/Debug.cs b/Perspex/Diagnostics/Debug.cs deleted file mode 100644 index d656aa6405..0000000000 --- a/Perspex/Diagnostics/Debug.cs +++ /dev/null @@ -1,71 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Diagnostics -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Perspex.Controls; - - public static class Debug - { - public static string PrintVisualTree(IVisual visual) - { - StringBuilder result = new StringBuilder(); - PrintVisualTree(visual, result, 0); - return result.ToString(); - } - - private static void PrintVisualTree(IVisual visual, StringBuilder builder, int indent) - { - Control control = visual as Control; - - builder.Append(Indent(indent - 1)); - - if (indent > 0) - { - builder.Append(" +- "); - } - - builder.Append(visual.GetType().Name); - - if (control != null) - { - builder.Append(" "); - builder.AppendLine(control.Classes.ToString()); - - foreach (var value in control.GetSetValues()) - { - builder.Append(Indent(indent)); - builder.Append(" | "); - builder.Append(value.Item1.Name); - builder.Append(" = "); - builder.Append(value.Item2 ?? "(null)"); - builder.Append(" ["); - builder.Append(value.Item3); - builder.AppendLine("]"); - } - } - else - { - builder.AppendLine(); - } - - foreach (var child in visual.VisualChildren) - { - PrintVisualTree(child, builder, indent + 1); - } - } - - private static string Indent(int indent) - { - return string.Join("", Enumerable.Repeat(" ", Math.Max(indent, 0))); - } - } -} diff --git a/Perspex/Diagnostics/DevTools.cs b/Perspex/Diagnostics/DevTools.cs deleted file mode 100644 index 2e6796dce6..0000000000 --- a/Perspex/Diagnostics/DevTools.cs +++ /dev/null @@ -1,14 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Diagnostics -{ - using Perspex.Controls; - - public class DevTools : Control - { - } -} diff --git a/Perspex/ICloseable.cs b/Perspex/ICloseable.cs deleted file mode 100644 index 23ec938f4f..0000000000 --- a/Perspex/ICloseable.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - - public interface ICloseable - { - event EventHandler Closed; - } -} diff --git a/Perspex/IHeadered.cs b/Perspex/IHeadered.cs deleted file mode 100644 index 38ee042a53..0000000000 --- a/Perspex/IHeadered.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - public interface IHeadered - { - object Header { get; set; } - } -} diff --git a/Perspex/ILogical.cs b/Perspex/ILogical.cs deleted file mode 100644 index 20bbf8b7fe..0000000000 --- a/Perspex/ILogical.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public interface ILogical - { - ILogical LogicalParent { get; set; } - - IEnumerable LogicalChildren { get; } - } -} diff --git a/Perspex/IObservableDescription.cs b/Perspex/IObservableDescription.cs deleted file mode 100644 index fb7fb3e415..0000000000 --- a/Perspex/IObservableDescription.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - public interface IObservableDescription - { - string Description { get; } - } -} diff --git a/Perspex/IVisual.cs b/Perspex/IVisual.cs deleted file mode 100644 index a6119915e9..0000000000 --- a/Perspex/IVisual.cs +++ /dev/null @@ -1,66 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using Perspex.Media; - - /// - /// Represents a node in the visual scene graph. - /// - /// - /// The interface defines the interface required for a renderer to - /// render a scene graph. You should not usually need to reference this interface unless - /// you are writing a renderer; instead use the extension methods defined in - /// to traverse the scene graph. This interface is - /// implemented by . It should not be necessary to implement it - /// anywhere else. - /// - public interface IVisual - { - /// - /// Gets the bounds of the scene graph node. - /// - /// - Rect Bounds { get; } - - /// - /// Gets a value indicating whether this scene graph node is visible. - /// - bool IsVisible { get; } - - /// - /// Gets the opacity of the scene graph node. - /// - double Opacity { get; } - - /// - /// Gets the render transform of the scene graph node. - /// - Transform RenderTransform { get; } - - /// - /// Gets the transform origin of the scene graph node. - /// - Origin TransformOrigin { get; } - - /// - /// Gets the scene graph node's child nodes. - /// - PerspexList VisualChildren { get; } - - /// - /// Gets the scene graph node's parent node. - /// - IVisual VisualParent { get; } - - /// - /// Renders the scene graph node to a . - /// - /// The context. - void Render(IDrawingContext context); - } -} diff --git a/Perspex/Input/FocusManager.cs b/Perspex/Input/FocusManager.cs deleted file mode 100644 index 7008aca02b..0000000000 --- a/Perspex/Input/FocusManager.cs +++ /dev/null @@ -1,47 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -using Perspex.Controls; - -namespace Perspex.Input -{ - public class FocusManager : IFocusManager - { - public IInputElement Current - { - get; - private set; - } - - public void Focus(IInputElement control) - { - Interactive current = this.Current as Interactive; - Interactive next = control as Interactive; - - if (current != null) - { - current.RaiseEvent(new RoutedEventArgs - { - RoutedEvent = Control.LostFocusEvent, - Source = current, - OriginalSource = current, - }); - } - - this.Current = control; - - if (next != null) - { - next.RaiseEvent(new RoutedEventArgs - { - RoutedEvent = Control.GotFocusEvent, - Source = next, - OriginalSource = next, - }); - } - } - } -} diff --git a/Perspex/Input/IFocusManager.cs b/Perspex/Input/IFocusManager.cs deleted file mode 100644 index 3399a950dd..0000000000 --- a/Perspex/Input/IFocusManager.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public interface IFocusManager - { - IInputElement Current { get; } - - void Focus(IInputElement focusable); - } -} diff --git a/Perspex/Input/IInputDevice.cs b/Perspex/Input/IInputDevice.cs deleted file mode 100644 index e2ba98a205..0000000000 --- a/Perspex/Input/IInputDevice.cs +++ /dev/null @@ -1,12 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - public interface IInputDevice - { - } -} diff --git a/Perspex/Input/IInputElement.cs b/Perspex/Input/IInputElement.cs deleted file mode 100644 index 728c23ce91..0000000000 --- a/Perspex/Input/IInputElement.cs +++ /dev/null @@ -1,37 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - - public interface IInputElement - { - event EventHandler GotFocus; - - event EventHandler LostFocus; - - event EventHandler KeyDown; - - event EventHandler PointerEnter; - - event EventHandler PointerLeave; - - event EventHandler PointerPressed; - - event EventHandler PointerReleased; - - bool Focusable { get; } - - bool IsFocused { get; } - - bool IsPointerOver { get; } - - void Focus(); - - void RaiseEvent(RoutedEventArgs e); - } -} diff --git a/Perspex/Input/IInputManager.cs b/Perspex/Input/IInputManager.cs deleted file mode 100644 index 0cddac4e33..0000000000 --- a/Perspex/Input/IInputManager.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - using Perspex.Input.Raw; - using Perspex.Layout; - - public interface IInputManager - { - IObservable RawEventReceived { get; } - - void Process(RawInputEventArgs e); - - void SetPointerOver(IPointerDevice device, IVisual visual, Point p); - } -} diff --git a/Perspex/Input/IKeyboardDevice.cs b/Perspex/Input/IKeyboardDevice.cs deleted file mode 100644 index 53e708a26e..0000000000 --- a/Perspex/Input/IKeyboardDevice.cs +++ /dev/null @@ -1,33 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - - [Flags] - public enum ModifierKeys - { - None = 0, - Alt = 1, - Control = 2, - Shift = 4, - Windows = 8, - } - - [Flags] - public enum KeyStates - { - None = 0, - Down = 1, - Toggled = 2, - } - - public interface IKeyboardDevice : IInputDevice - { - ModifierKeys Modifiers { get; } - } -} diff --git a/Perspex/Input/IMouseDevice.cs b/Perspex/Input/IMouseDevice.cs deleted file mode 100644 index b4b30ee65b..0000000000 --- a/Perspex/Input/IMouseDevice.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - public interface IMouseDevice : IPointerDevice - { - Point Position { get; } - } -} diff --git a/Perspex/Input/IPointerDevice.cs b/Perspex/Input/IPointerDevice.cs deleted file mode 100644 index 338b325c56..0000000000 --- a/Perspex/Input/IPointerDevice.cs +++ /dev/null @@ -1,19 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - - public interface IPointerDevice : IInputDevice - { - Interactive Captured { get; } - - void Capture(Interactive visual); - - Point GetPosition(IVisual relativeTo); - } -} diff --git a/Perspex/Input/InputElement.cs b/Perspex/Input/InputElement.cs deleted file mode 100644 index 0aedd05436..0000000000 --- a/Perspex/Input/InputElement.cs +++ /dev/null @@ -1,128 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Linq; - using System.Reactive.Linq; - using Perspex.Input; - using Perspex.Layout; - using Perspex.Media; - using Perspex.Styling; - using Splat; - - public class InputElement : Interactive, IInputElement - { - public static readonly PerspexProperty FocusableProperty = - PerspexProperty.Register("Focusable"); - - public static readonly PerspexProperty IsFocusedProperty = - PerspexProperty.Register("IsFocused", false); - - public static readonly PerspexProperty IsPointerOverProperty = - PerspexProperty.Register("IsPointerOver"); - - public static readonly RoutedEvent GotFocusEvent = - RoutedEvent.Register("GotFocus", RoutingStrategy.Bubble); - - public static readonly RoutedEvent LostFocusEvent = - RoutedEvent.Register("LostFocus", RoutingStrategy.Bubble); - - public static readonly RoutedEvent KeyDownEvent = - RoutedEvent.Register("KeyDown", RoutingStrategy.Bubble); - - public static readonly RoutedEvent PreviewKeyDownEvent = - RoutedEvent.Register("PreviewKeyDown", RoutingStrategy.Tunnel); - - public static readonly RoutedEvent PointerEnterEvent = - RoutedEvent.Register("PointerEnter", RoutingStrategy.Direct); - - public static readonly RoutedEvent PointerLeaveEvent = - RoutedEvent.Register("PointerLeave", RoutingStrategy.Direct); - - public static readonly RoutedEvent PointerPressedEvent = - RoutedEvent.Register("PointerPressed", RoutingStrategy.Bubble); - - public static readonly RoutedEvent PointerReleasedEvent = - RoutedEvent.Register("PointerReleased", RoutingStrategy.Bubble); - - public InputElement() - { - this.GotFocus += (s, e) => this.IsFocused = true; - this.LostFocus += (s, e) => this.IsFocused = false; - this.PointerEnter += (s, e) => this.IsPointerOver = true; - this.PointerLeave += (s, e) => this.IsPointerOver = false; - } - - public event EventHandler GotFocus - { - add { this.AddHandler(GotFocusEvent, value); } - remove { this.RemoveHandler(GotFocusEvent, value); } - } - - public event EventHandler LostFocus - { - add { this.AddHandler(LostFocusEvent, value); } - remove { this.RemoveHandler(LostFocusEvent, value); } - } - - public event EventHandler KeyDown - { - add { this.AddHandler(KeyDownEvent, value); } - remove { this.RemoveHandler(KeyDownEvent, value); } - } - - public event EventHandler PointerEnter - { - add { this.AddHandler(PointerEnterEvent, value); } - remove { this.RemoveHandler(PointerEnterEvent, value); } - } - - public event EventHandler PointerLeave - { - add { this.AddHandler(PointerLeaveEvent, value); } - remove { this.RemoveHandler(PointerLeaveEvent, value); } - } - - public event EventHandler PointerPressed - { - add { this.AddHandler(PointerPressedEvent, value); } - remove { this.RemoveHandler(PointerPressedEvent, value); } - } - - public event EventHandler PointerReleased - { - add { this.AddHandler(PointerReleasedEvent, value); } - remove { this.RemoveHandler(PointerReleasedEvent, value); } - } - - public bool Focusable - { - get { return this.GetValue(FocusableProperty); } - set { this.SetValue(FocusableProperty, value); } - } - - public bool IsFocused - { - get { return this.GetValue(IsFocusedProperty); } - private set { this.SetValue(IsFocusedProperty, value); } - } - - public bool IsPointerOver - { - get { return this.GetValue(IsPointerOverProperty); } - internal set { this.SetValue(IsPointerOverProperty, value); } - } - - public void Focus() - { - Locator.Current.GetService().Focus(this); - } - } -} diff --git a/Perspex/Input/InputManager.cs b/Perspex/Input/InputManager.cs deleted file mode 100644 index 773d023a48..0000000000 --- a/Perspex/Input/InputManager.cs +++ /dev/null @@ -1,65 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Subjects; - using Perspex.Controls; - using Perspex.Input.Raw; - - public class InputManager : IInputManager - { - private List pointerOvers = new List(); - - private Subject rawEventReceived = new Subject(); - - public IObservable RawEventReceived - { - get { return this.rawEventReceived; } - } - - public void Process(RawInputEventArgs e) - { - this.rawEventReceived.OnNext(e); - } - - public void SetPointerOver(IPointerDevice device, IVisual visual, Point p) - { - IEnumerable hits = visual.GetVisualsAt(p); - - foreach (var control in this.pointerOvers.ToList().Except(hits).Cast()) - { - PointerEventArgs e = new PointerEventArgs - { - RoutedEvent = InputElement.PointerLeaveEvent, - Device = device, - OriginalSource = control, - Source = control, - }; - - this.pointerOvers.Remove(control); - control.RaiseEvent(e); - } - - foreach (var control in hits.Except(this.pointerOvers).Cast()) - { - PointerEventArgs e = new PointerEventArgs - { - RoutedEvent = InputElement.PointerEnterEvent, - Device = device, - OriginalSource = control, - Source = control, - }; - - this.pointerOvers.Add(control); - control.RaiseEvent(e); - } - } - } -} diff --git a/Perspex/Input/Key.cs b/Perspex/Input/Key.cs deleted file mode 100644 index b966f9223f..0000000000 --- a/Perspex/Input/Key.cs +++ /dev/null @@ -1,214 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - public enum Key - { - None = 0, - Cancel = 1, - Back = 2, - Tab = 3, - LineFeed = 4, - Clear = 5, - Return = 6, - Enter = 6, - Pause = 7, - CapsLock = 8, - Capital = 8, - HangulMode = 9, - KanaMode = 9, - JunjaMode = 10, - FinalMode = 11, - KanjiMode = 12, - HanjaMode = 12, - Escape = 13, - ImeConvert = 14, - ImeNonConvert = 15, - ImeAccept = 16, - ImeModeChange = 17, - Space = 18, - PageUp = 19, - Prior = 19, - PageDown = 20, - Next = 20, - End = 21, - Home = 22, - Left = 23, - Up = 24, - Right = 25, - Down = 26, - Select = 27, - Print = 28, - Execute = 29, - Snapshot = 30, - PrintScreen = 30, - Insert = 31, - Delete = 32, - Help = 33, - D0 = 34, - D1 = 35, - D2 = 36, - D3 = 37, - D4 = 38, - D5 = 39, - D6 = 40, - D7 = 41, - D8 = 42, - D9 = 43, - A = 44, - B = 45, - C = 46, - D = 47, - E = 48, - F = 49, - G = 50, - H = 51, - I = 52, - J = 53, - K = 54, - L = 55, - M = 56, - N = 57, - O = 58, - P = 59, - Q = 60, - R = 61, - S = 62, - T = 63, - U = 64, - V = 65, - W = 66, - X = 67, - Y = 68, - Z = 69, - LWin = 70, - RWin = 71, - Apps = 72, - Sleep = 73, - NumPad0 = 74, - NumPad1 = 75, - NumPad2 = 76, - NumPad3 = 77, - NumPad4 = 78, - NumPad5 = 79, - NumPad6 = 80, - NumPad7 = 81, - NumPad8 = 82, - NumPad9 = 83, - Multiply = 84, - Add = 85, - Separator = 86, - Subtract = 87, - Decimal = 88, - Divide = 89, - F1 = 90, - F2 = 91, - F3 = 92, - F4 = 93, - F5 = 94, - F6 = 95, - F7 = 96, - F8 = 97, - F9 = 98, - F10 = 99, - F11 = 100, - F12 = 101, - F13 = 102, - F14 = 103, - F15 = 104, - F16 = 105, - F17 = 106, - F18 = 107, - F19 = 108, - F20 = 109, - F21 = 110, - F22 = 111, - F23 = 112, - F24 = 113, - NumLock = 114, - Scroll = 115, - LeftShift = 116, - RightShift = 117, - LeftCtrl = 118, - RightCtrl = 119, - LeftAlt = 120, - RightAlt = 121, - BrowserBack = 122, - BrowserForward = 123, - BrowserRefresh = 124, - BrowserStop = 125, - BrowserSearch = 126, - BrowserFavorites = 127, - BrowserHome = 128, - VolumeMute = 129, - VolumeDown = 130, - VolumeUp = 131, - MediaNextTrack = 132, - MediaPreviousTrack = 133, - MediaStop = 134, - MediaPlayPause = 135, - LaunchMail = 136, - SelectMedia = 137, - LaunchApplication1 = 138, - LaunchApplication2 = 139, - OemSemicolon = 140, - Oem1 = 140, - OemPlus = 141, - OemComma = 142, - OemMinus = 143, - OemPeriod = 144, - OemQuestion = 145, - Oem2 = 145, - OemTilde = 146, - Oem3 = 146, - AbntC1 = 147, - AbntC2 = 148, - OemOpenBrackets = 149, - Oem4 = 149, - OemPipe = 150, - Oem5 = 150, - OemCloseBrackets = 151, - Oem6 = 151, - OemQuotes = 152, - Oem7 = 152, - Oem8 = 153, - OemBackslash = 154, - Oem102 = 154, - ImeProcessed = 155, - System = 156, - OemAttn = 157, - DbeAlphanumeric = 157, - OemFinish = 158, - DbeKatakana = 158, - DbeHiragana = 159, - OemCopy = 159, - DbeSbcsChar = 160, - OemAuto = 160, - DbeDbcsChar = 161, - OemEnlw = 161, - OemBackTab = 162, - DbeRoman = 162, - DbeNoRoman = 163, - Attn = 163, - CrSel = 164, - DbeEnterWordRegisterMode = 164, - ExSel = 165, - DbeEnterImeConfigureMode = 165, - EraseEof = 166, - DbeFlushString = 166, - Play = 167, - DbeCodeInput = 167, - DbeNoCodeInput = 168, - Zoom = 168, - NoName = 169, - DbeDetermineString = 169, - DbeEnterDialogConversionMode = 170, - Pa1 = 170, - OemClear = 171, - DeadCharProcessed = 172, - } -} diff --git a/Perspex/Input/KeyEventArgs.cs b/Perspex/Input/KeyEventArgs.cs deleted file mode 100644 index a92206c2d5..0000000000 --- a/Perspex/Input/KeyEventArgs.cs +++ /dev/null @@ -1,19 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - - public class KeyEventArgs : RoutedEventArgs - { - public IKeyboardDevice Device { get; set; } - - public Key Key { get; set; } - - public string Text { get; set; } - } -} diff --git a/Perspex/Input/KeyboardDevice.cs b/Perspex/Input/KeyboardDevice.cs deleted file mode 100644 index 4069f60173..0000000000 --- a/Perspex/Input/KeyboardDevice.cs +++ /dev/null @@ -1,76 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - using System.Linq; - using System.Reactive.Linq; - using Perspex.Controls; - using Perspex.Input.Raw; - using Splat; - - public abstract class KeyboardDevice : IKeyboardDevice - { - public KeyboardDevice() - { - this.InputManager.RawEventReceived - .OfType() - .Where(x => x.Device == this) - .Subscribe(this.ProcessRawEvent); - } - - public IInputManager InputManager - { - get { return Locator.Current.GetService(); } - } - - public IFocusManager FocusManager - { - get { return Locator.Current.GetService(); } - } - - public IInputElement FocusedElement - { - get; - protected set; - } - - public abstract ModifierKeys Modifiers { get; } - - private void ProcessRawEvent(RawKeyEventArgs e) - { - IInputElement element = this.FocusedElement; - - if (element != null) - { - switch (e.Type) - { - case RawKeyEventType.KeyDown: - element.RaiseEvent(new KeyEventArgs - { - RoutedEvent = Control.PreviewKeyDownEvent, - Device = this, - Key = e.Key, - Text = e.Text, - Source = element, - OriginalSource = element, - }); - element.RaiseEvent(new KeyEventArgs - { - RoutedEvent = Control.KeyDownEvent, - Device = this, - Key = e.Key, - Text = e.Text, - Source = element, - OriginalSource = element, - }); - break; - } - } - } - } -} diff --git a/Perspex/Input/MouseDevice.cs b/Perspex/Input/MouseDevice.cs deleted file mode 100644 index 62ff04a0e5..0000000000 --- a/Perspex/Input/MouseDevice.cs +++ /dev/null @@ -1,153 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - using System.Linq; - using System.Reactive.Linq; - using Perspex.Controls; - using Perspex.Input.Raw; - using Splat; - - public abstract class MouseDevice : IMouseDevice - { - public MouseDevice() - { - this.InputManager.RawEventReceived - .OfType() - .Where(x => x.Device == this) - .Subscribe(this.ProcessRawEvent); - } - - public Interactive Captured - { - get; - protected set; - } - - public IInputManager InputManager - { - get { return Locator.Current.GetService(); } - } - - public Point Position - { - get; - protected set; - } - - public virtual void Capture(Interactive visual) - { - this.Captured = visual; - } - - public Point GetPosition(IVisual relativeTo) - { - Point p = this.GetClientPosition(); - IVisual v = relativeTo; - - while (v != null) - { - p -= v.Bounds.Position; - v = v.VisualParent; - } - - return p; - } - - protected abstract Point GetClientPosition(); - - private void ProcessRawEvent(RawMouseEventArgs e) - { - this.Position = e.Position; - - switch (e.Type) - { - case RawMouseEventType.Move: - this.MouseMove((IMouseDevice)e.Device, (IVisual)e.Root, e.Position); - break; - case RawMouseEventType.LeftButtonDown: - this.MouseDown((IMouseDevice)e.Device, (IVisual)e.Root, e.Position); - break; - case RawMouseEventType.LeftButtonUp: - this.MouseUp((IMouseDevice)e.Device, (IVisual)e.Root, e.Position); - break; - } - } - - private void MouseMove(IMouseDevice device, IVisual visual, Point p) - { - if (this.Captured == null) - { - this.InputManager.SetPointerOver(this, visual, p); - } - else - { - Point offset = new Point(); - - foreach (IVisual ancestor in this.Captured.GetVisualAncestors()) - { - offset += ancestor.Bounds.Position; - } - - this.InputManager.SetPointerOver(this, this.Captured, p - offset); - } - } - - private void MouseDown(IMouseDevice device, IVisual visual, Point p) - { - IVisual hit = visual.GetVisualAt(p); - - if (hit != null) - { - Interactive interactive = this.Captured ?? (hit as Interactive) ?? hit.GetVisualAncestor(); - IInputElement focusable = - this.Captured as IInputElement ?? - hit.GetVisualAncestorsAndSelf() - .OfType() - .FirstOrDefault(x => x.Focusable); - - if (interactive != null) - { - interactive.RaiseEvent(new PointerEventArgs - { - Device = this, - RoutedEvent = Control.PointerPressedEvent, - OriginalSource = interactive, - Source = interactive, - }); - } - - if (focusable != null && focusable.Focusable) - { - focusable.Focus(); - } - } - } - - private void MouseUp(IMouseDevice device, IVisual visual, Point p) - { - IVisual hit = visual.GetVisualAt(p); - - if (hit != null) - { - Interactive source = this.Captured ?? (hit as Interactive) ?? hit.GetVisualAncestor(); - - if (source != null) - { - source.RaiseEvent(new PointerEventArgs - { - Device = this, - RoutedEvent = Control.PointerReleasedEvent, - OriginalSource = source, - Source = source, - }); - } - } - } - } -} diff --git a/Perspex/Input/PointerEventArgs.cs b/Perspex/Input/PointerEventArgs.cs deleted file mode 100644 index 4417c59949..0000000000 --- a/Perspex/Input/PointerEventArgs.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input -{ - using System; - - public class PointerEventArgs : RoutedEventArgs - { - public IPointerDevice Device { get; set; } - - public Point GetPosition(IVisual relativeTo) - { - return this.Device.GetPosition(relativeTo); - } - } -} diff --git a/Perspex/Input/Raw/RawInputEventArgs.cs b/Perspex/Input/Raw/RawInputEventArgs.cs deleted file mode 100644 index 0e9a08c6fe..0000000000 --- a/Perspex/Input/Raw/RawInputEventArgs.cs +++ /dev/null @@ -1,27 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input.Raw -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Perspex.Layout; - - public class RawInputEventArgs : EventArgs - { - public RawInputEventArgs(IInputDevice device) - { - Contract.Requires(device != null); - - this.Device = device; - } - - public IInputDevice Device { get; private set; } - } -} diff --git a/Perspex/Input/Raw/RawKeyEventArgs.cs b/Perspex/Input/Raw/RawKeyEventArgs.cs deleted file mode 100644 index 887030b375..0000000000 --- a/Perspex/Input/Raw/RawKeyEventArgs.cs +++ /dev/null @@ -1,31 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 Tricycle. All rights reserved. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input.Raw -{ - public enum RawKeyEventType - { - KeyDown, - KeyUp - } - - public class RawKeyEventArgs : RawInputEventArgs - { - public RawKeyEventArgs(KeyboardDevice device, RawKeyEventType type, Key key, string text) - : base(device) - { - this.Key = key; - this.Type = type; - this.Text = text; - } - - public Key Key { get; set; } - - public string Text { get; set; } - - public RawKeyEventType Type { get; set; } - } -} diff --git a/Perspex/Input/Raw/RawMouseEventArgs.cs b/Perspex/Input/Raw/RawMouseEventArgs.cs deleted file mode 100644 index 41da9ec88a..0000000000 --- a/Perspex/Input/Raw/RawMouseEventArgs.cs +++ /dev/null @@ -1,42 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Input.Raw -{ - using System; - using Perspex.Layout; - - public enum RawMouseEventType - { - Move, - LeftButtonDown, - LeftButtonUp, - } - - public class RawMouseEventArgs : RawInputEventArgs - { - public RawMouseEventArgs( - IInputDevice device, - ILayoutRoot root, - RawMouseEventType type, - Point position) - : base(device) - { - Contract.Requires(device != null); - Contract.Requires(root != null); - - this.Root = root; - this.Position = position; - this.Type = type; - } - - public ILayoutRoot Root { get; private set; } - - public Point Position { get; private set; } - - public RawMouseEventType Type { get; private set; } - } -} diff --git a/Perspex/Interactive.cs b/Perspex/Interactive.cs deleted file mode 100644 index 60c57b8b11..0000000000 --- a/Perspex/Interactive.cs +++ /dev/null @@ -1,124 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive; - using System.Reactive.Linq; - using Perspex.Layout; - - public class Interactive : Layoutable - { - private Dictionary> eventHandlers = new Dictionary>(); - - public void AddHandler(RoutedEvent routedEvent, Delegate handler) - { - Contract.Requires(routedEvent != null); - Contract.Requires(handler != null); - - List delegates; - - if (!this.eventHandlers.TryGetValue(routedEvent, out delegates)) - { - delegates = new List(); - this.eventHandlers.Add(routedEvent, delegates); - } - - delegates.Add(handler); - } - - public IObservable> GetObservable(RoutedEvent routedEvent) where T : RoutedEventArgs - { - Contract.Requires(routedEvent != null); - - return Observable.FromEventPattern( - handler => this.AddHandler(routedEvent, handler), - handler => this.RemoveHandler(routedEvent, handler)); - } - - public void RemoveHandler(RoutedEvent routedEvent, Delegate handler) - { - Contract.Requires(routedEvent != null); - Contract.Requires(handler != null); - - List delegates; - - if (this.eventHandlers.TryGetValue(routedEvent, out delegates)) - { - delegates.Remove(handler); - } - } - - public void RaiseEvent(RoutedEventArgs e) - { - Contract.Requires(e != null); - - if (e.RoutedEvent != null) - { - switch (e.RoutedEvent.RoutingStrategy) - { - case RoutingStrategy.Bubble: - this.BubbleEvent(e); - break; - case RoutingStrategy.Direct: - this.RaiseEventImpl(e); - break; - case RoutingStrategy.Tunnel: - this.TunnelEvent(e); - break; - } - } - } - - private void BubbleEvent(RoutedEventArgs e) - { - Contract.Requires(e != null); - - foreach (var target in this.GetVisualAncestorsAndSelf().OfType()) - { - target.RaiseEventImpl(e); - - if (e.Handled) - { - break; - } - } - } - - private void TunnelEvent(RoutedEventArgs e) - { - Contract.Requires(e != null); - - foreach (var target in this.GetVisualAncestorsAndSelf().OfType().Reverse()) - { - target.RaiseEventImpl(e); - - if (e.Handled) - { - break; - } - } - } - - private void RaiseEventImpl(RoutedEventArgs e) - { - Contract.Requires(e != null); - - List delegates; - - if (this.eventHandlers.TryGetValue(e.RoutedEvent, out delegates)) - { - foreach (Delegate handler in delegates) - { - handler.DynamicInvoke(this, e); - } - } - } - } -} diff --git a/Perspex/Layout/ILayoutManager.cs b/Perspex/Layout/ILayoutManager.cs deleted file mode 100644 index 2318c5edbc..0000000000 --- a/Perspex/Layout/ILayoutManager.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Layout -{ - using System; - using System.Reactive; - using Perspex.Controls; - - public interface ILayoutManager - { - IObservable LayoutNeeded { get; } - - void ExecuteLayoutPass(); - - void InvalidateMeasure(ILayoutable item); - - void InvalidateArrange(ILayoutable item); - } -} diff --git a/Perspex/Layout/ILayoutRoot.cs b/Perspex/Layout/ILayoutRoot.cs deleted file mode 100644 index 4962760a21..0000000000 --- a/Perspex/Layout/ILayoutRoot.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Layout -{ - public interface ILayoutRoot : ILayoutable - { - Size ClientSize { get; } - - ILayoutManager LayoutManager { get; } - } -} diff --git a/Perspex/Layout/ILayoutable.cs b/Perspex/Layout/ILayoutable.cs deleted file mode 100644 index 6fd20e309b..0000000000 --- a/Perspex/Layout/ILayoutable.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Layout -{ - public interface ILayoutable - { - Size? DesiredSize { get; } - - void Arrange(Rect rect); - - void Measure(Size availableSize); - - void InvalidateArrange(); - - void InvalidateMeasure(); - } -} diff --git a/Perspex/Layout/LayoutHelper.cs b/Perspex/Layout/LayoutHelper.cs deleted file mode 100644 index cd6f1c1e35..0000000000 --- a/Perspex/Layout/LayoutHelper.cs +++ /dev/null @@ -1,59 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Layout -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Perspex.Controls; - - public static class LayoutHelper - { - public static Size ApplyLayoutConstraints(Layoutable control, Size constraints) - { - double width = (control.Width > 0) ? control.Width : constraints.Width; - double height = (control.Height > 0) ? control.Height : constraints.Height; - width = Math.Min(width, control.MaxWidth); - width = Math.Max(width, control.MinWidth); - height = Math.Min(height, control.MaxHeight); - height = Math.Max(height, control.MinHeight); - return new Size(width, height); - } - - public static Size MeasureDecorator( - Control decorator, - Control content, - Size availableSize, - Thickness padding) - { - double width = 0; - double height = 0; - - if (content != null) - { - content.Measure(availableSize.Deflate(padding)); - Size s = content.DesiredSize.Value.Inflate(padding); - width = s.Width; - height = s.Height; - } - - if (decorator.Width > 0) - { - width = decorator.Width; - } - - if (decorator.Height > 0) - { - height = decorator.Height; - } - - return new Size(width, height); - } - } -} diff --git a/Perspex/Layout/LayoutManager.cs b/Perspex/Layout/LayoutManager.cs deleted file mode 100644 index ea09e628d0..0000000000 --- a/Perspex/Layout/LayoutManager.cs +++ /dev/null @@ -1,56 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Layout -{ - using System; - using System.Collections.Generic; - using System.Reactive; - using System.Reactive.Subjects; - using Perspex.Controls; - - public class LayoutManager : ILayoutManager - { - private ILayoutRoot root; - - private Subject layoutNeeded; - - public LayoutManager() - { - this.layoutNeeded = new Subject(); - } - - public IObservable LayoutNeeded - { - get { return this.layoutNeeded; } - } - - public void ExecuteLayoutPass() - { - if (this.root != null) - { - this.root.Measure(this.root.ClientSize); - this.root.Arrange(new Rect(this.root.ClientSize)); - } - - this.root = null; - } - - public void InvalidateMeasure(ILayoutable item) - { - IVisual visual = item as IVisual; - this.root = visual.GetVisualAncestorOrSelf(); - this.layoutNeeded.OnNext(Unit.Default); - } - - public void InvalidateArrange(ILayoutable item) - { - IVisual visual = item as IVisual; - this.root = visual.GetVisualAncestorOrSelf(); - this.layoutNeeded.OnNext(Unit.Default); - } - } -} diff --git a/Perspex/Layout/Layoutable.cs b/Perspex/Layout/Layoutable.cs deleted file mode 100644 index dd3c7fa4e6..0000000000 --- a/Perspex/Layout/Layoutable.cs +++ /dev/null @@ -1,261 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Layout -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public enum HorizontalAlignment - { - Stretch, - Left, - Center, - Right, - } - - public enum VerticalAlignment - { - Stretch, - Top, - Center, - Bottom, - } - - public class Layoutable : Visual, ILayoutable - { - public static readonly PerspexProperty WidthProperty = - PerspexProperty.Register("Width", double.NaN); - - public static readonly PerspexProperty HeightProperty = - PerspexProperty.Register("Height", double.NaN); - - public static readonly PerspexProperty MinWidthProperty = - PerspexProperty.Register("MinWidth"); - - public static readonly PerspexProperty MaxWidthProperty = - PerspexProperty.Register("MaxWidth", double.PositiveInfinity); - - public static readonly PerspexProperty MinHeightProperty = - PerspexProperty.Register("MinHeight"); - - public static readonly PerspexProperty MaxHeightProperty = - PerspexProperty.Register("MaxHeight", double.PositiveInfinity); - - public static readonly PerspexProperty MarginProperty = - PerspexProperty.Register("Margin"); - - public static readonly PerspexProperty HorizontalAlignmentProperty = - PerspexProperty.Register("HorizontalAlignment"); - - public static readonly PerspexProperty VerticalAlignmentProperty = - PerspexProperty.Register("VerticalAlignment"); - - public double Width - { - get { return this.GetValue(WidthProperty); } - set { this.SetValue(WidthProperty, value); } - } - - public double Height - { - get { return this.GetValue(HeightProperty); } - set { this.SetValue(HeightProperty, value); } - } - - public double MinWidth - { - get { return this.GetValue(MinWidthProperty); } - set { this.SetValue(MinWidthProperty, value); } - } - - public double MaxWidth - { - get { return this.GetValue(MaxWidthProperty); } - set { this.SetValue(MaxWidthProperty, value); } - } - - public double MinHeight - { - get { return this.GetValue(MinHeightProperty); } - set { this.SetValue(MinHeightProperty, value); } - } - - public double MaxHeight - { - get { return this.GetValue(MaxHeightProperty); } - set { this.SetValue(MaxHeightProperty, value); } - } - - public Thickness Margin - { - get { return this.GetValue(MarginProperty); } - set { this.SetValue(MarginProperty, value); } - } - - public HorizontalAlignment HorizontalAlignment - { - get { return this.GetValue(HorizontalAlignmentProperty); } - set { this.SetValue(HorizontalAlignmentProperty, value); } - } - - public VerticalAlignment VerticalAlignment - { - get { return this.GetValue(VerticalAlignmentProperty); } - set { this.SetValue(VerticalAlignmentProperty, value); } - } - - public Size ActualSize - { - get { return ((IVisual)this).Bounds.Size; } - } - - public Size? DesiredSize - { - get; - set; - } - - public void Measure(Size availableSize) - { - availableSize = availableSize.Deflate(this.Margin); - this.DesiredSize = this.MeasureCore(availableSize).Constrain(availableSize); - } - - public void Arrange(Rect rect) - { - if (this.DesiredSize.HasValue) - { - this.ArrangeCore(rect); - } - } - - public void InvalidateMeasure() - { - ILayoutRoot root = this.GetVisualAncestorOrSelf(); - - if (root != null && root.LayoutManager != null) - { - root.LayoutManager.InvalidateMeasure(this); - } - } - - public void InvalidateArrange() - { - ILayoutRoot root = this.GetVisualAncestorOrSelf(); - - if (root != null) - { - root.LayoutManager.InvalidateArrange(this); - } - } - - protected static void AffectsArrange(PerspexProperty property) - { - property.Changed.Subscribe(AffectsArrangeInvalidate); - } - - protected static void AffectsMeasure(PerspexProperty property) - { - property.Changed.Subscribe(AffectsMeasureInvalidate); - } - - protected virtual void ArrangeCore(Rect finalRect) - { - double originX = finalRect.X + this.Margin.Left; - double originY = finalRect.Y + this.Margin.Top; - double sizeX = Math.Max(0, finalRect.Width - this.Margin.Left - this.Margin.Right); - double sizeY = Math.Max(0, finalRect.Height - this.Margin.Top - this.Margin.Bottom); - - if (this.HorizontalAlignment != HorizontalAlignment.Stretch) - { - sizeX = Math.Min(sizeX, this.DesiredSize.Value.Width); - } - - if (this.VerticalAlignment != VerticalAlignment.Stretch) - { - sizeY = Math.Min(sizeY, this.DesiredSize.Value.Height); - } - - Size taken = this.ArrangeOverride(new Size(sizeX, sizeY)); - - sizeX = Math.Min(taken.Width, sizeX); - sizeY = Math.Min(taken.Height, sizeY); - - switch (this.HorizontalAlignment) - { - case HorizontalAlignment.Center: - originX += (finalRect.Width - sizeX) / 2; - break; - case HorizontalAlignment.Right: - originX += finalRect.Width - sizeX; - break; - } - - switch (this.VerticalAlignment) - { - case VerticalAlignment.Center: - originY += (finalRect.Height - sizeY) / 2; - break; - case VerticalAlignment.Bottom: - originY += finalRect.Height - sizeY; - break; - } - - ((IVisual)this).Bounds = new Rect(originX, originY, sizeX, sizeY); - } - - protected virtual Size ArrangeOverride(Size finalSize) - { - return finalSize; - } - - protected virtual Size MeasureCore(Size availableSize) - { - if (this.IsVisible) - { - availableSize = LayoutHelper.ApplyLayoutConstraints(this, availableSize) - .Deflate(this.Margin); - var measured = this.MeasureOverride(availableSize); - - return measured.Inflate(this.Margin); - } - else - { - return new Size(); - } - } - - protected virtual Size MeasureOverride(Size availableSize) - { - return new Size(); - } - - private static void AffectsArrangeInvalidate(PerspexPropertyChangedEventArgs e) - { - ILayoutable control = e.Sender as ILayoutable; - - if (control != null) - { - control.InvalidateArrange(); - } - } - - private static void AffectsMeasureInvalidate(PerspexPropertyChangedEventArgs e) - { - ILayoutable control = e.Sender as ILayoutable; - - if (control != null) - { - control.InvalidateMeasure(); - } - } - - } -} diff --git a/Perspex/LogicalExtensions.cs b/Perspex/LogicalExtensions.cs deleted file mode 100644 index f2ff0953f7..0000000000 --- a/Perspex/LogicalExtensions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Perspex.Controls; - using Perspex.Styling; - - public static class LogicalExtensions - { - public static T FindControl(this ILogical control, string id) where T : Control - { - return control.GetLogicalDescendents() - .OfType() - .FirstOrDefault(x => x.Id == id); - } - - public static IEnumerable GetLogicalDescendents(this ILogical control) - { - foreach (ILogical child in control.LogicalChildren) - { - yield return child; - - foreach (ILogical descendent in child.GetLogicalDescendents()) - { - yield return descendent; - } - } - } - } -} diff --git a/Perspex/Media/Brush.cs b/Perspex/Media/Brush.cs deleted file mode 100644 index 7f6dce63e4..0000000000 --- a/Perspex/Media/Brush.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - /// - /// Describes how an area is painted. - /// - public abstract class Brush - { - } -} diff --git a/Perspex/Media/Brushes.cs b/Perspex/Media/Brushes.cs deleted file mode 100644 index 9463df62fe..0000000000 --- a/Perspex/Media/Brushes.cs +++ /dev/null @@ -1,301 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - /// - /// Predefined brushes. - /// - public static class Brushes - { - static Brushes() - { - AliceBlue = new SolidColorBrush(Colors.AliceBlue); - AntiqueWhite = new SolidColorBrush(Colors.AntiqueWhite); - Aqua = new SolidColorBrush(Colors.Aqua); - Aquamarine = new SolidColorBrush(Colors.Aquamarine); - Azure = new SolidColorBrush(Colors.Azure); - Beige = new SolidColorBrush(Colors.Beige); - Bisque = new SolidColorBrush(Colors.Bisque); - Black = new SolidColorBrush(Colors.Black); - BlanchedAlmond = new SolidColorBrush(Colors.BlanchedAlmond); - Blue = new SolidColorBrush(Colors.Blue); - BlueViolet = new SolidColorBrush(Colors.BlueViolet); - Brown = new SolidColorBrush(Colors.Brown); - BurlyWood = new SolidColorBrush(Colors.BurlyWood); - CadetBlue = new SolidColorBrush(Colors.CadetBlue); - Chartreuse = new SolidColorBrush(Colors.Chartreuse); - Chocolate = new SolidColorBrush(Colors.Chocolate); - Coral = new SolidColorBrush(Colors.Coral); - CornflowerBlue = new SolidColorBrush(Colors.CornflowerBlue); - Cornsilk = new SolidColorBrush(Colors.Cornsilk); - Crimson = new SolidColorBrush(Colors.Crimson); - Cyan = new SolidColorBrush(Colors.Cyan); - DarkBlue = new SolidColorBrush(Colors.DarkBlue); - DarkCyan = new SolidColorBrush(Colors.DarkCyan); - DarkGoldenrod = new SolidColorBrush(Colors.DarkGoldenrod); - DarkGray = new SolidColorBrush(Colors.DarkGray); - DarkGreen = new SolidColorBrush(Colors.DarkGreen); - DarkKhaki = new SolidColorBrush(Colors.DarkKhaki); - DarkMagenta = new SolidColorBrush(Colors.DarkMagenta); - DarkOliveGreen = new SolidColorBrush(Colors.DarkOliveGreen); - DarkOrange = new SolidColorBrush(Colors.DarkOrange); - DarkOrchid = new SolidColorBrush(Colors.DarkOrchid); - DarkRed = new SolidColorBrush(Colors.DarkRed); - DarkSalmon = new SolidColorBrush(Colors.DarkSalmon); - DarkSeaGreen = new SolidColorBrush(Colors.DarkSeaGreen); - DarkSlateBlue = new SolidColorBrush(Colors.DarkSlateBlue); - DarkSlateGray = new SolidColorBrush(Colors.DarkSlateGray); - DarkTurquoise = new SolidColorBrush(Colors.DarkTurquoise); - DarkViolet = new SolidColorBrush(Colors.DarkViolet); - DeepPink = new SolidColorBrush(Colors.DeepPink); - DeepSkyBlue = new SolidColorBrush(Colors.DeepSkyBlue); - DimGray = new SolidColorBrush(Colors.DimGray); - DodgerBlue = new SolidColorBrush(Colors.DodgerBlue); - Firebrick = new SolidColorBrush(Colors.Firebrick); - FloralWhite = new SolidColorBrush(Colors.FloralWhite); - ForestGreen = new SolidColorBrush(Colors.ForestGreen); - Fuchsia = new SolidColorBrush(Colors.Fuchsia); - Gainsboro = new SolidColorBrush(Colors.Gainsboro); - GhostWhite = new SolidColorBrush(Colors.GhostWhite); - Gold = new SolidColorBrush(Colors.Gold); - Goldenrod = new SolidColorBrush(Colors.Goldenrod); - Gray = new SolidColorBrush(Colors.Gray); - Green = new SolidColorBrush(Colors.Green); - GreenYellow = new SolidColorBrush(Colors.GreenYellow); - Honeydew = new SolidColorBrush(Colors.Honeydew); - HotPink = new SolidColorBrush(Colors.HotPink); - IndianRed = new SolidColorBrush(Colors.IndianRed); - Indigo = new SolidColorBrush(Colors.Indigo); - Ivory = new SolidColorBrush(Colors.Ivory); - Khaki = new SolidColorBrush(Colors.Khaki); - Lavender = new SolidColorBrush(Colors.Lavender); - LavenderBlush = new SolidColorBrush(Colors.LavenderBlush); - LawnGreen = new SolidColorBrush(Colors.LawnGreen); - LemonChiffon = new SolidColorBrush(Colors.LemonChiffon); - LightBlue = new SolidColorBrush(Colors.LightBlue); - LightCoral = new SolidColorBrush(Colors.LightCoral); - LightCyan = new SolidColorBrush(Colors.LightCyan); - LightGoldenrodYellow = new SolidColorBrush(Colors.LightGoldenrodYellow); - LightGray = new SolidColorBrush(Colors.LightGray); - LightGreen = new SolidColorBrush(Colors.LightGreen); - LightPink = new SolidColorBrush(Colors.LightPink); - LightSalmon = new SolidColorBrush(Colors.LightSalmon); - LightSeaGreen = new SolidColorBrush(Colors.LightSeaGreen); - LightSkyBlue = new SolidColorBrush(Colors.LightSkyBlue); - LightSlateGray = new SolidColorBrush(Colors.LightSlateGray); - LightSteelBlue = new SolidColorBrush(Colors.LightSteelBlue); - LightYellow = new SolidColorBrush(Colors.LightYellow); - Lime = new SolidColorBrush(Colors.Lime); - LimeGreen = new SolidColorBrush(Colors.LimeGreen); - Linen = new SolidColorBrush(Colors.Linen); - Magenta = new SolidColorBrush(Colors.Magenta); - Maroon = new SolidColorBrush(Colors.Maroon); - MediumAquamarine = new SolidColorBrush(Colors.MediumAquamarine); - MediumBlue = new SolidColorBrush(Colors.MediumBlue); - MediumOrchid = new SolidColorBrush(Colors.MediumOrchid); - MediumPurple = new SolidColorBrush(Colors.MediumPurple); - MediumSeaGreen = new SolidColorBrush(Colors.MediumSeaGreen); - MediumSlateBlue = new SolidColorBrush(Colors.MediumSlateBlue); - MediumSpringGreen = new SolidColorBrush(Colors.MediumSpringGreen); - MediumTurquoise = new SolidColorBrush(Colors.MediumTurquoise); - MediumVioletRed = new SolidColorBrush(Colors.MediumVioletRed); - MidnightBlue = new SolidColorBrush(Colors.MidnightBlue); - MintCream = new SolidColorBrush(Colors.MintCream); - MistyRose = new SolidColorBrush(Colors.MistyRose); - Moccasin = new SolidColorBrush(Colors.Moccasin); - NavajoWhite = new SolidColorBrush(Colors.NavajoWhite); - Navy = new SolidColorBrush(Colors.Navy); - OldLace = new SolidColorBrush(Colors.OldLace); - Olive = new SolidColorBrush(Colors.Olive); - OliveDrab = new SolidColorBrush(Colors.OliveDrab); - Orange = new SolidColorBrush(Colors.Orange); - OrangeRed = new SolidColorBrush(Colors.OrangeRed); - Orchid = new SolidColorBrush(Colors.Orchid); - PaleGoldenrod = new SolidColorBrush(Colors.PaleGoldenrod); - PaleGreen = new SolidColorBrush(Colors.PaleGreen); - PaleTurquoise = new SolidColorBrush(Colors.PaleTurquoise); - PaleVioletRed = new SolidColorBrush(Colors.PaleVioletRed); - PapayaWhip = new SolidColorBrush(Colors.PapayaWhip); - PeachPuff = new SolidColorBrush(Colors.PeachPuff); - Peru = new SolidColorBrush(Colors.Peru); - Pink = new SolidColorBrush(Colors.Pink); - Plum = new SolidColorBrush(Colors.Plum); - PowderBlue = new SolidColorBrush(Colors.PowderBlue); - Purple = new SolidColorBrush(Colors.Purple); - Red = new SolidColorBrush(Colors.Red); - RosyBrown = new SolidColorBrush(Colors.RosyBrown); - RoyalBlue = new SolidColorBrush(Colors.RoyalBlue); - SaddleBrown = new SolidColorBrush(Colors.SaddleBrown); - Salmon = new SolidColorBrush(Colors.Salmon); - SandyBrown = new SolidColorBrush(Colors.SandyBrown); - SeaGreen = new SolidColorBrush(Colors.SeaGreen); - SeaShell = new SolidColorBrush(Colors.SeaShell); - Sienna = new SolidColorBrush(Colors.Sienna); - Silver = new SolidColorBrush(Colors.Silver); - SkyBlue = new SolidColorBrush(Colors.SkyBlue); - SlateBlue = new SolidColorBrush(Colors.SlateBlue); - SlateGray = new SolidColorBrush(Colors.SlateGray); - Snow = new SolidColorBrush(Colors.Snow); - SpringGreen = new SolidColorBrush(Colors.SpringGreen); - SteelBlue = new SolidColorBrush(Colors.SteelBlue); - Tan = new SolidColorBrush(Colors.Tan); - Teal = new SolidColorBrush(Colors.Teal); - Thistle = new SolidColorBrush(Colors.Thistle); - Tomato = new SolidColorBrush(Colors.Tomato); - Transparent = new SolidColorBrush(Colors.Transparent); - Turquoise = new SolidColorBrush(Colors.Turquoise); - Violet = new SolidColorBrush(Colors.Violet); - Wheat = new SolidColorBrush(Colors.Wheat); - White = new SolidColorBrush(Colors.White); - WhiteSmoke = new SolidColorBrush(Colors.WhiteSmoke); - Yellow = new SolidColorBrush(Colors.Yellow); - YellowGreen = new SolidColorBrush(Colors.YellowGreen); - } - - public static SolidColorBrush AliceBlue { get; private set; } - public static SolidColorBrush AntiqueWhite { get; private set; } - public static SolidColorBrush Aqua { get; private set; } - public static SolidColorBrush Aquamarine { get; private set; } - public static SolidColorBrush Azure { get; private set; } - public static SolidColorBrush Beige { get; private set; } - public static SolidColorBrush Bisque { get; private set; } - public static SolidColorBrush Black { get; private set; } - public static SolidColorBrush BlanchedAlmond { get; private set; } - public static SolidColorBrush Blue { get; private set; } - public static SolidColorBrush BlueViolet { get; private set; } - public static SolidColorBrush Brown { get; private set; } - public static SolidColorBrush BurlyWood { get; private set; } - public static SolidColorBrush CadetBlue { get; private set; } - public static SolidColorBrush Chartreuse { get; private set; } - public static SolidColorBrush Chocolate { get; private set; } - public static SolidColorBrush Coral { get; private set; } - public static SolidColorBrush CornflowerBlue { get; private set; } - public static SolidColorBrush Cornsilk { get; private set; } - public static SolidColorBrush Crimson { get; private set; } - public static SolidColorBrush Cyan { get; private set; } - public static SolidColorBrush DarkBlue { get; private set; } - public static SolidColorBrush DarkCyan { get; private set; } - public static SolidColorBrush DarkGoldenrod { get; private set; } - public static SolidColorBrush DarkGray { get; private set; } - public static SolidColorBrush DarkGreen { get; private set; } - public static SolidColorBrush DarkKhaki { get; private set; } - public static SolidColorBrush DarkMagenta { get; private set; } - public static SolidColorBrush DarkOliveGreen { get; private set; } - public static SolidColorBrush DarkOrange { get; private set; } - public static SolidColorBrush DarkOrchid { get; private set; } - public static SolidColorBrush DarkRed { get; private set; } - public static SolidColorBrush DarkSalmon { get; private set; } - public static SolidColorBrush DarkSeaGreen { get; private set; } - public static SolidColorBrush DarkSlateBlue { get; private set; } - public static SolidColorBrush DarkSlateGray { get; private set; } - public static SolidColorBrush DarkTurquoise { get; private set; } - public static SolidColorBrush DarkViolet { get; private set; } - public static SolidColorBrush DeepPink { get; private set; } - public static SolidColorBrush DeepSkyBlue { get; private set; } - public static SolidColorBrush DimGray { get; private set; } - public static SolidColorBrush DodgerBlue { get; private set; } - public static SolidColorBrush Firebrick { get; private set; } - public static SolidColorBrush FloralWhite { get; private set; } - public static SolidColorBrush ForestGreen { get; private set; } - public static SolidColorBrush Fuchsia { get; private set; } - public static SolidColorBrush Gainsboro { get; private set; } - public static SolidColorBrush GhostWhite { get; private set; } - public static SolidColorBrush Gold { get; private set; } - public static SolidColorBrush Goldenrod { get; private set; } - public static SolidColorBrush Gray { get; private set; } - public static SolidColorBrush Green { get; private set; } - public static SolidColorBrush GreenYellow { get; private set; } - public static SolidColorBrush Honeydew { get; private set; } - public static SolidColorBrush HotPink { get; private set; } - public static SolidColorBrush IndianRed { get; private set; } - public static SolidColorBrush Indigo { get; private set; } - public static SolidColorBrush Ivory { get; private set; } - public static SolidColorBrush Khaki { get; private set; } - public static SolidColorBrush Lavender { get; private set; } - public static SolidColorBrush LavenderBlush { get; private set; } - public static SolidColorBrush LawnGreen { get; private set; } - public static SolidColorBrush LemonChiffon { get; private set; } - public static SolidColorBrush LightBlue { get; private set; } - public static SolidColorBrush LightCoral { get; private set; } - public static SolidColorBrush LightCyan { get; private set; } - public static SolidColorBrush LightGoldenrodYellow { get; private set; } - public static SolidColorBrush LightGray { get; private set; } - public static SolidColorBrush LightGreen { get; private set; } - public static SolidColorBrush LightPink { get; private set; } - public static SolidColorBrush LightSalmon { get; private set; } - public static SolidColorBrush LightSeaGreen { get; private set; } - public static SolidColorBrush LightSkyBlue { get; private set; } - public static SolidColorBrush LightSlateGray { get; private set; } - public static SolidColorBrush LightSteelBlue { get; private set; } - public static SolidColorBrush LightYellow { get; private set; } - public static SolidColorBrush Lime { get; private set; } - public static SolidColorBrush LimeGreen { get; private set; } - public static SolidColorBrush Linen { get; private set; } - public static SolidColorBrush Magenta { get; private set; } - public static SolidColorBrush Maroon { get; private set; } - public static SolidColorBrush MediumAquamarine { get; private set; } - public static SolidColorBrush MediumBlue { get; private set; } - public static SolidColorBrush MediumOrchid { get; private set; } - public static SolidColorBrush MediumPurple { get; private set; } - public static SolidColorBrush MediumSeaGreen { get; private set; } - public static SolidColorBrush MediumSlateBlue { get; private set; } - public static SolidColorBrush MediumSpringGreen { get; private set; } - public static SolidColorBrush MediumTurquoise { get; private set; } - public static SolidColorBrush MediumVioletRed { get; private set; } - public static SolidColorBrush MidnightBlue { get; private set; } - public static SolidColorBrush MintCream { get; private set; } - public static SolidColorBrush MistyRose { get; private set; } - public static SolidColorBrush Moccasin { get; private set; } - public static SolidColorBrush NavajoWhite { get; private set; } - public static SolidColorBrush Navy { get; private set; } - public static SolidColorBrush OldLace { get; private set; } - public static SolidColorBrush Olive { get; private set; } - public static SolidColorBrush OliveDrab { get; private set; } - public static SolidColorBrush Orange { get; private set; } - public static SolidColorBrush OrangeRed { get; private set; } - public static SolidColorBrush Orchid { get; private set; } - public static SolidColorBrush PaleGoldenrod { get; private set; } - public static SolidColorBrush PaleGreen { get; private set; } - public static SolidColorBrush PaleTurquoise { get; private set; } - public static SolidColorBrush PaleVioletRed { get; private set; } - public static SolidColorBrush PapayaWhip { get; private set; } - public static SolidColorBrush PeachPuff { get; private set; } - public static SolidColorBrush Peru { get; private set; } - public static SolidColorBrush Pink { get; private set; } - public static SolidColorBrush Plum { get; private set; } - public static SolidColorBrush PowderBlue { get; private set; } - public static SolidColorBrush Purple { get; private set; } - public static SolidColorBrush Red { get; private set; } - public static SolidColorBrush RosyBrown { get; private set; } - public static SolidColorBrush RoyalBlue { get; private set; } - public static SolidColorBrush SaddleBrown { get; private set; } - public static SolidColorBrush Salmon { get; private set; } - public static SolidColorBrush SandyBrown { get; private set; } - public static SolidColorBrush SeaGreen { get; private set; } - public static SolidColorBrush SeaShell { get; private set; } - public static SolidColorBrush Sienna { get; private set; } - public static SolidColorBrush Silver { get; private set; } - public static SolidColorBrush SkyBlue { get; private set; } - public static SolidColorBrush SlateBlue { get; private set; } - public static SolidColorBrush SlateGray { get; private set; } - public static SolidColorBrush Snow { get; private set; } - public static SolidColorBrush SpringGreen { get; private set; } - public static SolidColorBrush SteelBlue { get; private set; } - public static SolidColorBrush Tan { get; private set; } - public static SolidColorBrush Teal { get; private set; } - public static SolidColorBrush Thistle { get; private set; } - public static SolidColorBrush Tomato { get; private set; } - public static SolidColorBrush Transparent { get; private set; } - public static SolidColorBrush Turquoise { get; private set; } - public static SolidColorBrush Violet { get; private set; } - public static SolidColorBrush Wheat { get; private set; } - public static SolidColorBrush White { get; private set; } - public static SolidColorBrush WhiteSmoke { get; private set; } - public static SolidColorBrush Yellow { get; private set; } - public static SolidColorBrush YellowGreen { get; private set; } - } -} diff --git a/Perspex/Media/Color.cs b/Perspex/Media/Color.cs deleted file mode 100644 index cf4a779736..0000000000 --- a/Perspex/Media/Color.cs +++ /dev/null @@ -1,110 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - /// - /// An ARGB color. - /// - public struct Color - { - /// - /// Gets or sets the Alpha component of the color. - /// - public byte A { get; set; } - - /// - /// Gets or sets the Red component of the color. - /// - public byte R { get; set; } - - /// - /// Gets or sets the Green component of the color. - /// - public byte G { get; set; } - - /// - /// Gets or sets the Blue component of the color. - /// - public byte B { get; set; } - - /// - /// Creates a from alpha, red, green and blue components. - /// - /// The alpha component. - /// The red component. - /// The green component. - /// The blue component. - /// The color. - public static Color FromArgb(byte a, byte r, byte g, byte b) - { - return new Color - { - A = a, - R = r, - G = g, - B = b, - }; - } - - /// - /// Creates a from red, green and blue components. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The color. - public static Color FromRgb(byte r, byte g, byte b) - { - return new Color - { - A = 0xff, - R = r, - G = g, - B = b, - }; - } - - /// - /// Creates a from an integer. - /// - /// The integer value. - /// The color. - public static Color FromUInt32(uint value) - { - return new Color - { - A = (byte)((value >> 24) & 0xff), - R = (byte)((value >> 16) & 0xff), - G = (byte)((value >> 8) & 0xff), - B = (byte)(value & 0xff), - }; - } - - /// - /// Returns the string representation of the color. - /// - /// - /// The string representation of the color. - /// - public override string ToString() - { - uint rgb = ((uint)this.A << 24) | ((uint)this.R << 16) | ((uint)this.G << 8) | (uint)this.B; - return string.Format("#{0:x8}", rgb); - } - - /// - /// Returns the integer representation of the color. - /// - /// - /// The integer representation of the color. - /// - public uint ToUint32() - { - return ((uint)this.A << 24) | ((uint)this.R << 16) | ((uint)this.G << 8) | (uint)this.B; - } - } -} diff --git a/Perspex/Media/Colors.cs b/Perspex/Media/Colors.cs deleted file mode 100644 index 6a48e4226c..0000000000 --- a/Perspex/Media/Colors.cs +++ /dev/null @@ -1,716 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - public sealed class Colors - { - public static Color AliceBlue - { - get { return Color.FromUInt32(0xfff0f8ff); } - } - - public static Color AntiqueWhite - { - get { return Color.FromUInt32(0xfffaebd7); } - } - - public static Color Aqua - { - get { return Color.FromUInt32(0xff00ffff); } - } - - public static Color Aquamarine - { - get { return Color.FromUInt32(0xff7fffd4); } - } - - public static Color Azure - { - get { return Color.FromUInt32(0xfff0ffff); } - } - - public static Color Beige - { - get { return Color.FromUInt32(0xfff5f5dc); } - } - - public static Color Bisque - { - get { return Color.FromUInt32(0xffffe4c4); } - } - - public static Color Black - { - get { return Color.FromUInt32(0xff000000); } - } - - public static Color BlanchedAlmond - { - get { return Color.FromUInt32(0xffffebcd); } - } - - public static Color Blue - { - get { return Color.FromUInt32(0xff0000ff); } - } - - public static Color BlueViolet - { - get { return Color.FromUInt32(0xff8a2be2); } - } - - public static Color Brown - { - get { return Color.FromUInt32(0xffa52a2a); } - } - - public static Color BurlyWood - { - get { return Color.FromUInt32(0xffdeb887); } - } - - public static Color CadetBlue - { - get { return Color.FromUInt32(0xff5f9ea0); } - } - - public static Color Chartreuse - { - get { return Color.FromUInt32(0xff7fff00); } - } - - public static Color Chocolate - { - get { return Color.FromUInt32(0xffd2691e); } - } - - public static Color Coral - { - get { return Color.FromUInt32(0xffff7f50); } - } - - public static Color CornflowerBlue - { - get { return Color.FromUInt32(0xff6495ed); } - } - - public static Color Cornsilk - { - get { return Color.FromUInt32(0xfffff8dc); } - } - - public static Color Crimson - { - get { return Color.FromUInt32(0xffdc143c); } - } - - public static Color Cyan - { - get { return Color.FromUInt32(0xff00ffff); } - } - - public static Color DarkBlue - { - get { return Color.FromUInt32(0xff00008b); } - } - - public static Color DarkCyan - { - get { return Color.FromUInt32(0xff008b8b); } - } - - public static Color DarkGoldenrod - { - get { return Color.FromUInt32(0xffb8860b); } - } - - public static Color DarkGray - { - get { return Color.FromUInt32(0xffa9a9a9); } - } - - public static Color DarkGreen - { - get { return Color.FromUInt32(0xff006400); } - } - - public static Color DarkKhaki - { - get { return Color.FromUInt32(0xffbdb76b); } - } - - public static Color DarkMagenta - { - get { return Color.FromUInt32(0xff8b008b); } - } - - public static Color DarkOliveGreen - { - get { return Color.FromUInt32(0xff556b2f); } - } - - public static Color DarkOrange - { - get { return Color.FromUInt32(0xffff8c00); } - } - - public static Color DarkOrchid - { - get { return Color.FromUInt32(0xff9932cc); } - } - - public static Color DarkRed - { - get { return Color.FromUInt32(0xff8b0000); } - } - - public static Color DarkSalmon - { - get { return Color.FromUInt32(0xffe9967a); } - } - - public static Color DarkSeaGreen - { - get { return Color.FromUInt32(0xff8fbc8f); } - } - - public static Color DarkSlateBlue - { - get { return Color.FromUInt32(0xff483d8b); } - } - - public static Color DarkSlateGray - { - get { return Color.FromUInt32(0xff2f4f4f); } - } - - public static Color DarkTurquoise - { - get { return Color.FromUInt32(0xff00ced1); } - } - - public static Color DarkViolet - { - get { return Color.FromUInt32(0xff9400d3); } - } - - public static Color DeepPink - { - get { return Color.FromUInt32(0xffff1493); } - } - - public static Color DeepSkyBlue - { - get { return Color.FromUInt32(0xff00bfff); } - } - - public static Color DimGray - { - get { return Color.FromUInt32(0xff696969); } - } - - public static Color DodgerBlue - { - get { return Color.FromUInt32(0xff1e90ff); } - } - - public static Color Firebrick - { - get { return Color.FromUInt32(0xffb22222); } - } - - public static Color FloralWhite - { - get { return Color.FromUInt32(0xfffffaf0); } - } - - public static Color ForestGreen - { - get { return Color.FromUInt32(0xff228b22); } - } - - public static Color Fuchsia - { - get { return Color.FromUInt32(0xffff00ff); } - } - - public static Color Gainsboro - { - get { return Color.FromUInt32(0xffdcdcdc); } - } - - public static Color GhostWhite - { - get { return Color.FromUInt32(0xfff8f8ff); } - } - - public static Color Gold - { - get { return Color.FromUInt32(0xffffd700); } - } - - public static Color Goldenrod - { - get { return Color.FromUInt32(0xffdaa520); } - } - - public static Color Gray - { - get { return Color.FromUInt32(0xff808080); } - } - - public static Color Green - { - get { return Color.FromUInt32(0xff008000); } - } - - public static Color GreenYellow - { - get { return Color.FromUInt32(0xffadff2f); } - } - - public static Color Honeydew - { - get { return Color.FromUInt32(0xfff0fff0); } - } - - public static Color HotPink - { - get { return Color.FromUInt32(0xffff69b4); } - } - - public static Color IndianRed - { - get { return Color.FromUInt32(0xffcd5c5c); } - } - - public static Color Indigo - { - get { return Color.FromUInt32(0xff4b0082); } - } - - public static Color Ivory - { - get { return Color.FromUInt32(0xfffffff0); } - } - - public static Color Khaki - { - get { return Color.FromUInt32(0xfff0e68c); } - } - - public static Color Lavender - { - get { return Color.FromUInt32(0xffe6e6fa); } - } - - public static Color LavenderBlush - { - get { return Color.FromUInt32(0xfffff0f5); } - } - - public static Color LawnGreen - { - get { return Color.FromUInt32(0xff7cfc00); } - } - - public static Color LemonChiffon - { - get { return Color.FromUInt32(0xfffffacd); } - } - - public static Color LightBlue - { - get { return Color.FromUInt32(0xffadd8e6); } - } - - public static Color LightCoral - { - get { return Color.FromUInt32(0xfff08080); } - } - - public static Color LightCyan - { - get { return Color.FromUInt32(0xffe0ffff); } - } - - public static Color LightGoldenrodYellow - { - get { return Color.FromUInt32(0xfffafad2); } - } - - public static Color LightGray - { - get { return Color.FromUInt32(0xffd3d3d3); } - } - - public static Color LightGreen - { - get { return Color.FromUInt32(0xff90ee90); } - } - - public static Color LightPink - { - get { return Color.FromUInt32(0xffffb6c1); } - } - - public static Color LightSalmon - { - get { return Color.FromUInt32(0xffffa07a); } - } - - public static Color LightSeaGreen - { - get { return Color.FromUInt32(0xff20b2aa); } - } - - public static Color LightSkyBlue - { - get { return Color.FromUInt32(0xff87cefa); } - } - - public static Color LightSlateGray - { - get { return Color.FromUInt32(0xff778899); } - } - - public static Color LightSteelBlue - { - get { return Color.FromUInt32(0xffb0c4de); } - } - - public static Color LightYellow - { - get { return Color.FromUInt32(0xffffffe0); } - } - - public static Color Lime - { - get { return Color.FromUInt32(0xff00ff00); } - } - - public static Color LimeGreen - { - get { return Color.FromUInt32(0xff32cd32); } - } - - public static Color Linen - { - get { return Color.FromUInt32(0xfffaf0e6); } - } - - public static Color Magenta - { - get { return Color.FromUInt32(0xffff00ff); } - } - - public static Color Maroon - { - get { return Color.FromUInt32(0xff800000); } - } - - public static Color MediumAquamarine - { - get { return Color.FromUInt32(0xff66cdaa); } - } - - public static Color MediumBlue - { - get { return Color.FromUInt32(0xff0000cd); } - } - - public static Color MediumOrchid - { - get { return Color.FromUInt32(0xffba55d3); } - } - - public static Color MediumPurple - { - get { return Color.FromUInt32(0xff9370db); } - } - - public static Color MediumSeaGreen - { - get { return Color.FromUInt32(0xff3cb371); } - } - - public static Color MediumSlateBlue - { - get { return Color.FromUInt32(0xff7b68ee); } - } - - public static Color MediumSpringGreen - { - get { return Color.FromUInt32(0xff00fa9a); } - } - - public static Color MediumTurquoise - { - get { return Color.FromUInt32(0xff48d1cc); } - } - - public static Color MediumVioletRed - { - get { return Color.FromUInt32(0xffc71585); } - } - - public static Color MidnightBlue - { - get { return Color.FromUInt32(0xff191970); } - } - - public static Color MintCream - { - get { return Color.FromUInt32(0xfff5fffa); } - } - - public static Color MistyRose - { - get { return Color.FromUInt32(0xffffe4e1); } - } - - public static Color Moccasin - { - get { return Color.FromUInt32(0xffffe4b5); } - } - - public static Color NavajoWhite - { - get { return Color.FromUInt32(0xffffdead); } - } - - public static Color Navy - { - get { return Color.FromUInt32(0xff000080); } - } - - public static Color OldLace - { - get { return Color.FromUInt32(0xfffdf5e6); } - } - - public static Color Olive - { - get { return Color.FromUInt32(0xff808000); } - } - - public static Color OliveDrab - { - get { return Color.FromUInt32(0xff6b8e23); } - } - - public static Color Orange - { - get { return Color.FromUInt32(0xffffa500); } - } - - public static Color OrangeRed - { - get { return Color.FromUInt32(0xffff4500); } - } - - public static Color Orchid - { - get { return Color.FromUInt32(0xffda70d6); } - } - - public static Color PaleGoldenrod - { - get { return Color.FromUInt32(0xffeee8aa); } - } - - public static Color PaleGreen - { - get { return Color.FromUInt32(0xff98fb98); } - } - - public static Color PaleTurquoise - { - get { return Color.FromUInt32(0xffafeeee); } - } - - public static Color PaleVioletRed - { - get { return Color.FromUInt32(0xffdb7093); } - } - - public static Color PapayaWhip - { - get { return Color.FromUInt32(0xffffefd5); } - } - - public static Color PeachPuff - { - get { return Color.FromUInt32(0xffffdab9); } - } - - public static Color Peru - { - get { return Color.FromUInt32(0xffcd853f); } - } - - public static Color Pink - { - get { return Color.FromUInt32(0xffffc0cb); } - } - - public static Color Plum - { - get { return Color.FromUInt32(0xffdda0dd); } - } - - public static Color PowderBlue - { - get { return Color.FromUInt32(0xffb0e0e6); } - } - - public static Color Purple - { - get { return Color.FromUInt32(0xff800080); } - } - - public static Color Red - { - get { return Color.FromUInt32(0xffff0000); } - } - - public static Color RosyBrown - { - get { return Color.FromUInt32(0xffbc8f8f); } - } - - public static Color RoyalBlue - { - get { return Color.FromUInt32(0xff4169e1); } - } - - public static Color SaddleBrown - { - get { return Color.FromUInt32(0xff8b4513); } - } - - public static Color Salmon - { - get { return Color.FromUInt32(0xfffa8072); } - } - - public static Color SandyBrown - { - get { return Color.FromUInt32(0xfff4a460); } - } - - public static Color SeaGreen - { - get { return Color.FromUInt32(0xff2e8b57); } - } - - public static Color SeaShell - { - get { return Color.FromUInt32(0xfffff5ee); } - } - - public static Color Sienna - { - get { return Color.FromUInt32(0xffa0522d); } - } - - public static Color Silver - { - get { return Color.FromUInt32(0xffc0c0c0); } - } - - public static Color SkyBlue - { - get { return Color.FromUInt32(0xff87ceeb); } - } - - public static Color SlateBlue - { - get { return Color.FromUInt32(0xff6a5acd); } - } - - public static Color SlateGray - { - get { return Color.FromUInt32(0xff708090); } - } - - public static Color Snow - { - get { return Color.FromUInt32(0xfffffafa); } - } - - public static Color SpringGreen - { - get { return Color.FromUInt32(0xff00ff7f); } - } - - public static Color SteelBlue - { - get { return Color.FromUInt32(0xff4682b4); } - } - - public static Color Tan - { - get { return Color.FromUInt32(0xffd2b48c); } - } - - public static Color Teal - { - get { return Color.FromUInt32(0xff008080); } - } - - public static Color Thistle - { - get { return Color.FromUInt32(0xffd8bfd8); } - } - - public static Color Tomato - { - get { return Color.FromUInt32(0xffff6347); } - } - - public static Color Transparent - { - get { return Color.FromUInt32(0x00ffffff); } - } - - public static Color Turquoise - { - get { return Color.FromUInt32(0xff40e0d0); } - } - - public static Color Violet - { - get { return Color.FromUInt32(0xffee82ee); } - } - - public static Color Wheat - { - get { return Color.FromUInt32(0xfff5deb3); } - } - - public static Color White - { - get { return Color.FromUInt32(0xffffffff); } - } - - public static Color WhiteSmoke - { - get { return Color.FromUInt32(0xfff5f5f5); } - } - - public static Color Yellow - { - get { return Color.FromUInt32(0xffffff00); } - } - - public static Color YellowGreen - { - get { return Color.FromUInt32(0xff9acd32); } - } - } -} \ No newline at end of file diff --git a/Perspex/Media/FormattedText.cs b/Perspex/Media/FormattedText.cs deleted file mode 100644 index 129e0f1243..0000000000 --- a/Perspex/Media/FormattedText.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using Perspex.Platform; - using Splat; - - public class FormattedText - { - public string FontFamilyName { get; set; } - - public double FontSize { get; set; } - - public string Text { get; set; } - - public double[] GetLineHeights(Size constraint) - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - return factory.TextService.GetLineHeights(this, constraint); - } - - public Size Measure(Size constraint) - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - return factory.TextService.Measure(this, constraint); - } - } -} diff --git a/Perspex/Media/Geometry.cs b/Perspex/Media/Geometry.cs deleted file mode 100644 index 192842aa28..0000000000 --- a/Perspex/Media/Geometry.cs +++ /dev/null @@ -1,29 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using Perspex.Platform; - - public abstract class Geometry - { - public abstract Rect Bounds - { - get; - } - - public IGeometryImpl PlatformImpl - { - get; - protected set; - } - - public Rect GetRenderBounds(double strokeThickness) - { - return this.PlatformImpl.GetRenderBounds(strokeThickness); - } - } -} diff --git a/Perspex/Media/IDrawingContext.cs b/Perspex/Media/IDrawingContext.cs deleted file mode 100644 index b7b81f1568..0000000000 --- a/Perspex/Media/IDrawingContext.cs +++ /dev/null @@ -1,67 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using System; - using Perspex.Media.Imaging; - - - /// - /// Defines the interface through which drawing occurs. - /// - public interface IDrawingContext : IDisposable - { - Matrix CurrentTransform { get; } - - void DrawImage(Bitmap source, double opacity, Rect sourceRect, Rect destRect); - - /// - /// Draws a line. - /// - /// The stroke pen. - /// The first point of the line. - /// The second point of the line. - void DrawLine(Pen pen, Point p1, Point p2); - - /// - /// Draws a geometry. - /// - /// The fill brush. - /// The stroke pen. - /// The geometry. - void DrawGeometry(Brush brush, Pen pen, Geometry geometry); - - /// - /// Draws the outline of a rectangle. - /// - /// The pen. - /// The rectangle bounds. - void DrawRectange(Pen pen, Rect rect); - - /// - /// Draws text. - /// - /// The foreground brush. - /// The bounding rectangle. - /// The text. - void DrawText(Brush foreground, Rect rect, FormattedText text); - - /// - /// Draws a filled rectangle. - /// - /// The brush. - /// The rectangle bounds. - void FillRectange(Brush brush, Rect rect); - - /// - /// Pushes a matrix transformation. - /// - /// The matrix - /// A disposable used to undo the transformation. - IDisposable PushTransform(Matrix matrix); - } -} diff --git a/Perspex/Media/Imaging/Bitmap.cs b/Perspex/Media/Imaging/Bitmap.cs deleted file mode 100644 index 9e98886f0e..0000000000 --- a/Perspex/Media/Imaging/Bitmap.cs +++ /dev/null @@ -1,52 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media.Imaging -{ - using Perspex.Platform; - using Splat; - - public class Bitmap : IBitmap - { - public Bitmap(string fileName) - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - this.PlatformImpl = factory.LoadBitmap(fileName); - } - - public Bitmap(int width, int height) - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - this.PlatformImpl = factory.CreateBitmap(width, height); - } - - protected Bitmap(IBitmapImpl impl) - { - this.PlatformImpl = impl; - } - - public int PixelWidth - { - get { return this.PlatformImpl.PixelWidth; } - } - - public int PixelHeight - { - get { return this.PlatformImpl.PixelHeight; } - } - - public IBitmapImpl PlatformImpl - { - get; - private set; - } - - public void Save(string fileName) - { - this.PlatformImpl.Save(fileName); - } - } -} diff --git a/Perspex/Media/Imaging/IBitmap.cs b/Perspex/Media/Imaging/IBitmap.cs deleted file mode 100644 index c070f0113f..0000000000 --- a/Perspex/Media/Imaging/IBitmap.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media.Imaging -{ - public interface IBitmap - { - int PixelHeight { get; } - - int PixelWidth { get; } - - void Save(string fileName); - } -} \ No newline at end of file diff --git a/Perspex/Media/Imaging/RenderTargetBitmap.cs b/Perspex/Media/Imaging/RenderTargetBitmap.cs deleted file mode 100644 index 3f436941da..0000000000 --- a/Perspex/Media/Imaging/RenderTargetBitmap.cs +++ /dev/null @@ -1,35 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media.Imaging -{ - using Perspex.Platform; - using Splat; - - public class RenderTargetBitmap : Bitmap - { - public RenderTargetBitmap(int width, int height) - : base(CreateImpl(width, height)) - { - } - - public new IRenderTargetBitmapImpl PlatformImpl - { - get { return (IRenderTargetBitmapImpl)base.PlatformImpl; } - } - - public void Render(IVisual visual) - { - this.PlatformImpl.Render(visual); - } - - private static IBitmapImpl CreateImpl(int width, int height) - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - return factory.CreateRenderTargetBitmap(width, height); - } - } -} diff --git a/Perspex/Media/Matrix.cs b/Perspex/Media/Matrix.cs deleted file mode 100644 index 14d302a0bf..0000000000 --- a/Perspex/Media/Matrix.cs +++ /dev/null @@ -1,182 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using System; - - public struct Matrix - { - private double m11; - private double m12; - private double m21; - private double m22; - private double offsetX; - private double offsetY; - - public Matrix( - double m11, - double m12, - double m21, - double m22, - double offsetX, - double offsetY) - { - this.m11 = m11; - this.m12 = m12; - this.m21 = m21; - this.m22 = m22; - this.offsetX = offsetX; - this.offsetY = offsetY; - } - - public static Matrix Identity - { - get { return new Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); } - } - - public double Determinant - { - get { return (this.m11 * this.m22) - (this.m12 * this.m21); } - } - - public bool HasInverse - { - get { return this.Determinant != 0; } - } - - public bool IsIdentity - { - get { return this.Equals(Matrix.Identity); } - } - - public double M11 - { - get { return this.m11; } - } - - public double M12 - { - get { return this.m12; } - } - - public double M21 - { - get { return this.m21; } - } - - public double M22 - { - get { return this.m22; } - } - - public double OffsetX - { - get { return this.offsetX; } - } - - public double OffsetY - { - get { return this.offsetY; } - } - - public static Matrix operator *(Matrix left, Matrix right) - { - return new Matrix( - (left.M11 * right.M11) + (left.M12 * right.M21), - (left.M11 * right.M12) + (left.M12 * right.M22), - (left.M21 * right.M11) + (left.M22 * right.M21), - (left.M21 * right.M12) + (left.M22 * right.M22), - (left.offsetX * right.M11) + (left.offsetY * right.M21) + right.offsetX, - (left.offsetX * right.M12) + (left.offsetY * right.M22) + right.offsetY); - } - - public static bool Equals(Matrix matrix1, Matrix matrix2) - { - return matrix1.Equals(matrix2); - } - - public static Matrix Rotation(double angle) - { - double cos = Math.Cos(angle); - double sin = Math.Sin(angle); - return new Matrix(cos, sin, -sin, cos, 0, 0); - } - - public static Matrix Translation(Vector v) - { - return Translation(v.X, v.Y); - } - - public static Matrix Translation(double x, double y) - { - return new Matrix(1.0, 0.0, 0.0, 1.0, x, y); - } - - public static double ToRadians(double angle) - { - return angle * 0.0174532925; - } - - public static Matrix operator -(Matrix matrix) - { - return matrix.Invert(); - } - - public static bool operator ==(Matrix matrix1, Matrix matrix2) - { - return matrix1.Equals(matrix2); - } - - public static bool operator !=(Matrix matrix1, Matrix matrix2) - { - return !matrix1.Equals(matrix2); - } - - public bool Equals(Matrix value) - { - return this.m11 == value.M11 && - this.m12 == value.M12 && - this.m21 == value.M21 && - this.m22 == value.M22 && - this.offsetX == value.OffsetX && - this.offsetY == value.OffsetY; - } - - public override bool Equals(object o) - { - if (!(o is Matrix)) - { - return false; - } - - return this.Equals((Matrix)o); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - - public Matrix Invert() - { - if (!this.HasInverse) - { - throw new InvalidOperationException("Transform is not invertible."); - } - - double d = this.Determinant; - - return new Matrix( - this.m22 / d, - -this.m12 / d, - -this.m21 / d, - this.m11 / d, - ((this.m21 * this.offsetY) - (this.m22 * this.offsetX)) / d, - ((this.m12 * this.offsetX) - (this.m11 * this.offsetY)) / d); - } - } -} \ No newline at end of file diff --git a/Perspex/Media/PathMarkupParser.cs b/Perspex/Media/PathMarkupParser.cs deleted file mode 100644 index 866160732d..0000000000 --- a/Perspex/Media/PathMarkupParser.cs +++ /dev/null @@ -1,289 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - - public class PathMarkupParser - { - private static readonly Dictionary Commands = new Dictionary - { - { 'F', Command.FillRule }, - { 'f', Command.FillRule }, - { 'M', Command.Move }, - { 'm', Command.MoveRelative }, - { 'L', Command.Line }, - { 'l', Command.LineRelative }, - { 'H', Command.HorizontalLine }, - { 'h', Command.HorizontalLineRelative }, - { 'V', Command.VerticalLine }, - { 'v', Command.VerticalLineRelative }, - { 'C', Command.CubicBezierCurve }, - { 'c', Command.CubicBezierCurveRelative }, - { 'Z', Command.Close }, - { 'z', Command.Close }, - }; - - private StreamGeometry geometry; - - private StreamGeometryContext context; - - public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context) - { - this.geometry = geometry; - this.context = context; - } - - private enum Command - { - None, - FillRule, - Move, - MoveRelative, - Line, - LineRelative, - HorizontalLine, - HorizontalLineRelative, - VerticalLine, - VerticalLineRelative, - CubicBezierCurve, - CubicBezierCurveRelative, - Close, - Eof, - } - - public void Parse(string s) - { - bool openFigure = false; - - using (StringReader reader = new StringReader(s)) - { - Command lastCommand = Command.None; - Command command; - Point point = new Point(); - - while ((command = ReadCommand(reader, lastCommand)) != Command.Eof) - { - switch (command) - { - case Command.FillRule: - // TODO: Implement. - reader.Read(); - break; - - case Command.Move: - case Command.MoveRelative: - if (openFigure) - { - this.context.EndFigure(false); - } - - point = ReadPoint(reader); - this.context.BeginFigure(point, true); - openFigure = true; - break; - - case Command.Line: - point = ReadPoint(reader); - this.context.LineTo(point); - break; - - case Command.LineRelative: - point = ReadRelativePoint(reader, point); - this.context.LineTo(point); - break; - - ////case Command.HorizontalLine: - //// point.X = ReadDouble(reader); - //// this.context.LineTo(point, true, false); - //// break; - - ////case Command.HorizontalLineRelative: - //// point.X += ReadDouble(reader); - //// this.context.LineTo(point, true, false); - //// break; - - ////case Command.VerticalLine: - //// point.Y = ReadDouble(reader); - //// this.context.LineTo(point, true, false); - //// break; - - ////case Command.VerticalLineRelative: - //// point.Y += ReadDouble(reader); - //// this.context.LineTo(point, true, false); - //// break; - - ////case Command.CubicBezierCurve: - ////{ - //// Point point1 = ReadPoint(reader); - //// Point point2 = ReadPoint(reader); - //// point = ReadPoint(reader); - //// this.context.BezierTo(point1, point2, point, true, false); - //// break; - ////} - - case Command.Close: - this.context.EndFigure(true); - openFigure = false; - break; - - default: - throw new NotSupportedException("Unsupported command"); - } - - lastCommand = command; - } - - if (openFigure) - { - this.context.EndFigure(false); - } - } - } - - private static Command ReadCommand(StringReader reader, Command lastCommand) - { - ReadWhitespace(reader); - - int i = reader.Peek(); - - if (i == -1) - { - return Command.Eof; - } - else - { - char c = (char)i; - Command command = Command.None; - - if (!Commands.TryGetValue(c, out command)) - { - if ((char.IsDigit(c) || c == '.' || c == '+' || c == '-') && - (lastCommand != Command.None)) - { - return lastCommand; - } - else - { - throw new InvalidDataException("Unexpected path command '" + c + "'."); - } - } - - reader.Read(); - return command; - } - } - - private static double ReadDouble(TextReader reader) - { - // TODO: Handle Infinity, NaN and scientific notation. - StringBuilder b = new StringBuilder(); - bool readSign = false; - bool readPoint = false; - bool readExponent = false; - int i; - - while ((i = reader.Peek()) != -1) - { - char c = char.ToUpperInvariant((char)i); - - if (((c == '+' || c == '-') && !readSign) || - (c == '.' && !readPoint) || - (c == 'E' && !readExponent) || - char.IsDigit(c)) - { - b.Append(c); - reader.Read(); - readSign = c == '+' || c == '-'; - readPoint = c == '.'; - - if (c == 'E') - { - readSign = false; - readExponent = c == 'E'; - } - } - else - { - break; - } - } - - return double.Parse(b.ToString()); - } - - private static Point ReadPoint(StringReader reader) - { - ReadWhitespace(reader); - double x = ReadDouble(reader); - ReadSeparator(reader); - double y = ReadDouble(reader); - return new Point(x, y); - } - - private static Point ReadRelativePoint(StringReader reader, Point lastPoint) - { - ReadWhitespace(reader); - double x = ReadDouble(reader); - ReadSeparator(reader); - double y = ReadDouble(reader); - return new Point(lastPoint.X + x, lastPoint.Y + y); - } - - private static void ReadSeparator(StringReader reader) - { - int i; - bool readComma = false; - - while ((i = reader.Peek()) != -1) - { - char c = (char)i; - - if (char.IsWhiteSpace(c)) - { - reader.Read(); - } - else if (c == ',') - { - if (readComma) - { - throw new InvalidDataException("Unexpected ','."); - } - - readComma = true; - reader.Read(); - } - else - { - break; - } - } - } - - private static void ReadWhitespace(StringReader reader) - { - int i; - - while ((i = reader.Peek()) != -1) - { - char c = (char)i; - - if (char.IsWhiteSpace(c)) - { - reader.Read(); - } - else - { - break; - } - } - } - } -} diff --git a/Perspex/Media/Pen.cs b/Perspex/Media/Pen.cs deleted file mode 100644 index 5e73c40334..0000000000 --- a/Perspex/Media/Pen.cs +++ /dev/null @@ -1,46 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - /// - /// Describes how a stroke is drawn. - /// - public class Pen - { - /// - /// Initializes a new instance of the class. - /// - /// The brush used to draw. - /// The stroke thickness. - public Pen(Brush brush, double thickness) - { - this.Brush = brush; - this.Thickness = thickness; - } - - /// - /// Initializes a new instance of the class. - /// - /// The stroke color. - /// The stroke thickness. - public Pen(uint color, double thickness) - { - this.Brush = new SolidColorBrush(color); - this.Thickness = thickness; - } - - /// - /// Gets the brush used to draw the stroke. - /// - public Brush Brush { get; private set; } - - /// - /// Gets the stroke thickness. - /// - public double Thickness { get; private set; } - } -} diff --git a/Perspex/Media/RectangleGeometry.cs b/Perspex/Media/RectangleGeometry.cs deleted file mode 100644 index c47478489e..0000000000 --- a/Perspex/Media/RectangleGeometry.cs +++ /dev/null @@ -1,36 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using Perspex.Platform; - using Splat; - - public class RectangleGeometry : Geometry - { - public RectangleGeometry(Rect rect) - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - IStreamGeometryImpl impl = factory.CreateStreamGeometry(); - - using (IStreamGeometryContextImpl context = impl.Open()) - { - context.BeginFigure(rect.TopLeft, true); - context.LineTo(rect.TopRight); - context.LineTo(rect.BottomRight); - context.LineTo(rect.BottomLeft); - context.EndFigure(true); - } - - this.PlatformImpl = impl; - } - - public override Rect Bounds - { - get { return this.PlatformImpl.Bounds; } - } - } -} diff --git a/Perspex/Media/RotateTransform.cs b/Perspex/Media/RotateTransform.cs deleted file mode 100644 index 67fe38b7b8..0000000000 --- a/Perspex/Media/RotateTransform.cs +++ /dev/null @@ -1,34 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - public class RotateTransform : Transform - { - public static readonly PerspexProperty AngleProperty = - PerspexProperty.Register("Angle"); - - public RotateTransform() - { - } - - public RotateTransform(double angle) - { - this.Angle = angle; - } - - public double Angle - { - get { return this.GetValue(AngleProperty); } - set { this.SetValue(AngleProperty, value); } - } - - public override Matrix Value - { - get { return Matrix.Rotation(Matrix.ToRadians(this.Angle)); } - } - } -} diff --git a/Perspex/Media/SolidColorBrush.cs b/Perspex/Media/SolidColorBrush.cs deleted file mode 100644 index 4210cdaa8c..0000000000 --- a/Perspex/Media/SolidColorBrush.cs +++ /dev/null @@ -1,46 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - /// - /// Fills an area with a solid color. - /// - public class SolidColorBrush : Brush - { - /// - /// Initializes a new instance of the class. - /// - /// The color to use. - public SolidColorBrush(Color color) - { - this.Color = color; - } - - /// - /// Initializes a new instance of the class. - /// - /// The color to use. - public SolidColorBrush(uint color) - : this(Color.FromUInt32(color)) - { - } - - /// - /// Gets the color of the brush. - /// - public Color Color - { - get; - private set; - } - - public override string ToString() - { - return this.Color.ToString(); - } - } -} diff --git a/Perspex/Media/StreamGeometry.cs b/Perspex/Media/StreamGeometry.cs deleted file mode 100644 index 79f0934ebb..0000000000 --- a/Perspex/Media/StreamGeometry.cs +++ /dev/null @@ -1,42 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using Perspex.Platform; - using Splat; - - public class StreamGeometry : Geometry - { - public StreamGeometry() - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - this.PlatformImpl = factory.CreateStreamGeometry(); - } - - public override Rect Bounds - { - get { return this.PlatformImpl.Bounds; } - } - - public static StreamGeometry Parse(string s) - { - StreamGeometry result = new StreamGeometry(); - - using (StreamGeometryContext ctx = result.Open()) - { - PathMarkupParser parser = new PathMarkupParser(result, ctx); - parser.Parse(s); - return result; - } - } - - public StreamGeometryContext Open() - { - return new StreamGeometryContext(((IStreamGeometryImpl)this.PlatformImpl).Open()); - } - } -} diff --git a/Perspex/Media/StreamGeometryContext.cs b/Perspex/Media/StreamGeometryContext.cs deleted file mode 100644 index c7641ee4e9..0000000000 --- a/Perspex/Media/StreamGeometryContext.cs +++ /dev/null @@ -1,41 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - using System; - using Perspex.Platform; - - public class StreamGeometryContext : IDisposable - { - private IStreamGeometryContextImpl impl; - - public StreamGeometryContext(IStreamGeometryContextImpl impl) - { - this.impl = impl; - } - - public void BeginFigure(Point startPoint, bool isFilled) - { - this.impl.BeginFigure(startPoint, isFilled); - } - - public void LineTo(Point point) - { - this.impl.LineTo(point); - } - - public void EndFigure(bool isClosed) - { - this.impl.EndFigure(isClosed); - } - - public void Dispose() - { - this.impl.Dispose(); - } - } -} diff --git a/Perspex/Media/Stretch.cs b/Perspex/Media/Stretch.cs deleted file mode 100644 index 354e740f66..0000000000 --- a/Perspex/Media/Stretch.cs +++ /dev/null @@ -1,16 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - public enum Stretch - { - None, - Fill, - Uniform, - UniformToFill, - } -} diff --git a/Perspex/Media/Transform.cs b/Perspex/Media/Transform.cs deleted file mode 100644 index 7608b069b4..0000000000 --- a/Perspex/Media/Transform.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Media -{ - public abstract class Transform : PerspexObject - { - public abstract Matrix Value { get; } - } -} diff --git a/Perspex/Origin.cs b/Perspex/Origin.cs deleted file mode 100644 index b4de4562fb..0000000000 --- a/Perspex/Origin.cs +++ /dev/null @@ -1,54 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Globalization; - - public enum OriginUnit - { - Percent, - Pixels, - } - - public struct Origin - { - public static readonly Origin Default = new Origin(0.5, 0.5, OriginUnit.Percent); - - private Point point; - - private OriginUnit unit; - - public Origin(double x, double y, OriginUnit unit) - : this(new Point(x, y), unit) - { - } - - public Origin(Point point, OriginUnit unit) - { - this.point = point; - this.unit = unit; - } - - public Point Point - { - get { return this.point; } - } - - public OriginUnit Unit - { - get { return this.unit; } - } - - public Point ToPixels(Size size) - { - return this.unit == OriginUnit.Pixels ? - point : - new Point(point.X * size.Width, point.Y * size.Height); - } - } -} diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj deleted file mode 100644 index 9fdb84cc07..0000000000 --- a/Perspex/Perspex.csproj +++ /dev/null @@ -1,255 +0,0 @@ - - - - - 11.0 - Debug - AnyCPU - {3C9F40DA-D2A5-43A1-A272-E965876C6D46} - Library - Properties - Perspex - Perspex - v4.5 - Profile7 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 1 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - True - False - True - False - False - True - True - True - False - False - False - True - True - False - False - False - True - False - True - True - False - False - - - - - - - - True - False - Full - %28none%29 - 0 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ..\packages\Splat.1.3.3\lib\Portable-net45+win+wpa81+wp80\Splat.dll - - - ..\packages\Rx-Core.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Core.dll - - - ..\packages\Rx-Interfaces.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Interfaces.dll - - - ..\packages\Rx-Linq.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Linq.dll - - - - - - - - - \ No newline at end of file diff --git a/Perspex/PerspexList.cs b/Perspex/PerspexList.cs deleted file mode 100644 index 209699a388..0000000000 --- a/Perspex/PerspexList.cs +++ /dev/null @@ -1,50 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Collections.Specialized; - using System.Reactive.Linq; - - public class PerspexList : ObservableCollection - { - public PerspexList() - { - this.Initialize(); - } - - public PerspexList(IEnumerable items) - : base(items) - { - this.Initialize(); - } - - public IObservable Changed - { - get; - private set; - } - - public void AddRange(IEnumerable items) - { - foreach (T item in items) - { - this.Add(item); - } - } - - private void Initialize() - { - this.Changed = Observable.FromEvent( - handler => (sender, e) => handler(e), - handler => this.CollectionChanged += handler, - handler => this.CollectionChanged -= handler); - } - } -} \ No newline at end of file diff --git a/Perspex/PerspexObject.cs b/Perspex/PerspexObject.cs deleted file mode 100644 index 0ea7127f70..0000000000 --- a/Perspex/PerspexObject.cs +++ /dev/null @@ -1,645 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - using System.Reflection; - using Splat; - - /// - /// The priority of a binding. - /// - public enum BindingPriority - { - /// - /// A local value. - /// - LocalValue, - - /// - /// A triggered style binding. - /// - /// - /// A style trigger is a selector such as .class which overrides a - /// binding. In this way, a basic control can have - /// for example a Background from the templated parent which changes when the - /// control has the :pointerover class. - /// - StyleTrigger, - - /// - /// A binding to a property on the templated parent. - /// - TemplatedParent, - - /// - /// A style binding. - /// - Style, - - /// - /// The binding is uninitialized. - /// - Unset = int.MaxValue, - } - - /// - /// An object with support. - /// - /// - /// This class is analogous to DependencyObject in WPF. - /// - public class PerspexObject : IEnableLogger - { - /// - /// The registered properties by type. - /// - private static Dictionary> registered = - new Dictionary>(); - - /// - /// The parent object that inherited values are inherited from. - /// - private PerspexObject inheritanceParent; - - /// - /// The set values/bindings on this object. - /// - private Dictionary values = - new Dictionary(); - - /// - /// Raised when a value changes on this object/ - /// - public event EventHandler PropertyChanged; - - /// - /// Gets or sets the parent object that inherited values - /// are inherited from. - /// - protected PerspexObject InheritanceParent - { - get - { - return this.inheritanceParent; - } - - set - { - if (this.inheritanceParent != value) - { - if (this.inheritanceParent != null) - { - this.inheritanceParent.PropertyChanged -= this.ParentPropertyChanged; - } - - var inherited = (from property in GetProperties(this.GetType()) - where property.Inherits - select new - { - Property = property, - Value = this.GetValue(property), - }).ToList(); - - this.inheritanceParent = value; - - foreach (var i in inherited) - { - object newValue = this.GetValue(i.Property); - - if (!object.Equals(i.Value, newValue)) - { - this.RaisePropertyChanged(i.Property, i.Value, newValue); - } - } - - if (this.inheritanceParent != null) - { - this.inheritanceParent.PropertyChanged += this.ParentPropertyChanged; - } - } - } - } - - - /// - /// Gets or sets the value of a . - /// - /// The property. - public object this[PerspexProperty property] - { - get { return this.GetValue(property); } - set { this.SetValue(property, value); } - } - - /// - /// Gets or sets a binding for a . - /// - /// The binding information. - public Binding this[Binding binding] - { - get - { - return new Binding - { - Mode = binding.Mode, - Priority = binding.Priority, - Property = binding.Property, - Source = this, - }; - } - - set - { - BindingMode mode = (binding.Mode == BindingMode.Default) ? - binding.Property.DefaultBindingMode : - binding.Mode; - - switch (mode) - { - case BindingMode.Default: - case BindingMode.OneWay: - this.Bind(binding.Property, value.Source.GetObservable(value.Property), binding.Priority); - break; - case BindingMode.OneTime: - this.SetValue(binding.Property, value.Source.GetValue(value.Property)); - break; - case BindingMode.OneWayToSource: - value.Source.Bind(value.Property, this.GetObservable(binding.Property), binding.Priority); - break; - case BindingMode.TwoWay: - this.BindTwoWay(binding.Property, value.Source, value.Property); - break; - } - } - } - - /// - /// Gets all s registered on a type. - /// - /// The type. - /// A collection of definitions. - public static IEnumerable GetProperties(Type type) - { - Contract.Requires(type != null); - - TypeInfo i = type.GetTypeInfo(); - - while (type != null) - { - List list; - - if (registered.TryGetValue(type, out list)) - { - foreach (PerspexProperty p in list) - { - yield return p; - } - } - - type = type.GetTypeInfo().BaseType; - } - } - - /// - /// Registers a on a type. - /// - /// The type. - /// The property. - /// - /// You won't usually want to call this method directly, instead use the - /// method. - /// - public static void Register(Type type, PerspexProperty property) - { - Contract.Requires(type != null); - Contract.Requires(property != null); - - List list; - - if (!registered.TryGetValue(type, out list)) - { - list = new List(); - registered.Add(type, list); - } - - if (!list.Contains(property)) - { - list.Add(property); - } - } - - /// - /// Clears a 's local value. - /// - /// The property. - public void ClearValue(PerspexProperty property) - { - Contract.Requires(property != null); - - this.SetValue(property, PerspexProperty.UnsetValue); - } - - /// - /// Gets an observable for a . - /// - /// The property. - /// An observable. - public IObservable GetObservable(PerspexProperty property) - { - Contract.Requires(property != null); - - return Observable.Create(observer => - { - EventHandler handler = (s, e) => - { - if (e.Property == property) - { - observer.OnNext(e.NewValue); - } - }; - - this.PropertyChanged += handler; - observer.OnNext(this.GetValue(property)); - - return () => - { - this.PropertyChanged -= handler; - }; - }); - } - - /// - /// Gets an observable for a . - /// - /// - /// - /// - public IObservable GetObservable(PerspexProperty property) - { - Contract.Requires(property != null); - - return this.GetObservable((PerspexProperty)property).Cast(); - } - - /// - /// Gets an observable for a . - /// - /// - /// - /// - public IObservable> GetObservableWithHistory(PerspexProperty property) - { - return Observable.Create>(observer => - { - EventHandler handler = (s, e) => - { - if (e.Property == property) - { - observer.OnNext(Tuple.Create((T)e.OldValue, (T)e.NewValue)); - } - }; - - this.PropertyChanged += handler; - - return () => - { - this.PropertyChanged -= handler; - }; - }); - } - - /// - /// Gets a value. - /// - /// The property. - /// The value. - public object GetValue(PerspexProperty property) - { - Contract.Requires(property != null); - - object result; - - PriorityValue value; - - if (this.values.TryGetValue(property, out value)) - { - result = value.Value; - } - else - { - result = PerspexProperty.UnsetValue; - } - - if (result == PerspexProperty.UnsetValue) - { - result = this.GetDefaultValue(property); - } - - return result; - } - - /// - /// Gets a value. - /// - /// The property. - /// The value. - public T GetValue(PerspexProperty property) - { - Contract.Requires(property != null); - - return (T)this.GetValue((PerspexProperty)property); - } - - /// - /// Gets all of the values explicitly set on this object. - /// - public IEnumerable> GetSetValues() - { - foreach (var value in this.values) - { - yield return Tuple.Create( - value.Key, - value.Value.Value, - (BindingPriority)value.Value.ValuePriority); - } - } - - /// - /// Checks whether a is set on this object. - /// - /// The property. - /// True if the property is set, otherwise false. - public bool IsSet(PerspexProperty property) - { - Contract.Requires(property != null); - - return this.values.ContainsKey(property); - } - - /// - /// Checks whether a is registered on this class. - /// - /// The property. - /// True if the property is registered, otherwise false. - private bool IsRegistered(PerspexProperty property) - { - Type type = this.GetType(); - - while (type != null) - { - List list; - - if (registered.TryGetValue(type, out list)) - { - if (list.Contains(property)) - { - return true; - } - } - - type = type.GetTypeInfo().BaseType; - } - - return false; - } - - /// - /// Sets a value. - /// - /// The property. - /// The value. - public void SetValue(PerspexProperty property, object value) - { - Contract.Requires(property != null); - - const int Priority = (int)BindingPriority.LocalValue; - PriorityValue v; - - if (!this.IsRegistered(property)) - { - throw new InvalidOperationException(string.Format( - "Property '{0}' not registered on '{1}'", - property.Name, - this.GetType())); - } - - if (!PriorityValue.IsValidValue(value, property.PropertyType)) - { - throw new InvalidOperationException(string.Format( - "Invalid value for Property '{0}': {1} ({2})", - property.Name, - value, - value.GetType().FullName)); - } - - if (!this.values.TryGetValue(property, out v)) - { - if (value == PerspexProperty.UnsetValue) - { - return; - } - - v = this.CreatePriorityValue(property); - this.values.Add(property, v); - } - - this.Log().Debug(string.Format( - "Set local value of {0}.{1} (#{2:x8}) to {3}", - this.GetType().Name, - property.Name, - this.GetHashCode(), - value)); - - v.Replace(Observable.Never().StartWith(value), Priority); - } - - /// - /// Sets a value. - /// - /// The type of the property. - /// The property. - /// The value. - public void SetValue(PerspexProperty property, T value) - { - Contract.Requires(property != null); - - this.SetValue((PerspexProperty)property, value); - } - - /// - /// Binds a to an observable. - /// - /// The type of the property. - /// The property. - /// The observable. - /// The priority of the binding. - /// - /// A disposable which can be used to terminate the binding. - /// - public IDisposable Bind( - PerspexProperty property, - IObservable source, - BindingPriority priority = BindingPriority.LocalValue) - { - Contract.Requires(property != null); - - PriorityValue v; - IObservableDescription description = source as IObservableDescription; - - if (!this.values.TryGetValue(property, out v)) - { - v = this.CreatePriorityValue(property); - this.values.Add(property, v); - } - - this.Log().Debug(string.Format( - "Bound value of {0}.{1} (#{2:x8}) to {3}", - this.GetType().Name, - property.Name, - this.GetHashCode(), - description != null ? description.Description : "[Anonymous]")); - - if (priority == BindingPriority.LocalValue) - { - return v.Replace(source, (int)priority); - } - else - { - return v.Add(source, (int)priority); - } - } - - /// - /// Binds a to an observable. - /// - /// The type of the property. - /// The property. - /// The observable. - /// The priority of the binding. - /// - /// A disposable which can be used to terminate the binding. - /// - public IDisposable Bind( - PerspexProperty property, - IObservable source, - BindingPriority priority = BindingPriority.LocalValue) - { - Contract.Requires(property != null); - - return this.Bind((PerspexProperty)property, (IObservable)source, priority); - } - - /// - /// Initialites a two-way bind between s. - /// - /// The property on this object. - /// The source object. - /// The property on the source object. - /// - /// A disposable which can be used to terminate the binding. - /// - /// - /// The binding is first carried out from to this. Two-way - /// bindings are always at the LocalValue priority. - /// - public void BindTwoWay( - PerspexProperty property, - PerspexObject source, - PerspexProperty sourceProperty) - { - source.GetObservable(sourceProperty).Subscribe(x => this.SetValue(property, x)); - this.GetObservable(property).Subscribe(x => source.SetValue(sourceProperty, x)); - } - - private PriorityValue CreatePriorityValue(PerspexProperty property) - { - PriorityValue result = new PriorityValue(property.Name, property.PropertyType); - - result.Changed.Subscribe(x => - { - object oldValue = (x.Item1 == PerspexProperty.UnsetValue) ? - this.GetDefaultValue(property) : - x.Item1; - object newValue = (x.Item2 == PerspexProperty.UnsetValue) ? - this.GetDefaultValue(property) : - x.Item2; - - if (!object.Equals(oldValue, newValue)) - { - this.RaisePropertyChanged(property, oldValue, newValue); - - this.Log().Debug(string.Format( - "Value of {0}.{1} (#{2:x8}) changed from {3} to {4}", - this.GetType().Name, - property.Name, - this.GetHashCode(), - oldValue, - newValue)); - } - }); - - return result; - } - - /// - /// Gets the default value for a property. - /// - /// The property. - /// The default value. - private object GetDefaultValue(PerspexProperty property) - { - if (property.Inherits && this.inheritanceParent != null) - { - return this.inheritanceParent.GetValue(property); - } - else - { - return property.GetDefaultValue(this.GetType()); - } - } - - /// - /// Called when a property is changed on the current . - /// - /// The event sender. - /// The event args. - /// - /// Checks for changes in an inherited property value. - /// - 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); - } - } - - /// - /// Raises the event. - /// - /// The property that has changed. - /// The old property value. - /// The new property value. - private void RaisePropertyChanged(PerspexProperty property, object oldValue, object newValue) - { - Contract.Requires(property != null); - - if (this.PropertyChanged != null) - { - PerspexPropertyChangedEventArgs e = new PerspexPropertyChangedEventArgs(this, property, oldValue, newValue); - property.NotifyChanged(e); - this.PropertyChanged(this, e); - } - } - } -} diff --git a/Perspex/PerspexProperty.cs b/Perspex/PerspexProperty.cs deleted file mode 100644 index e16ef28d7f..0000000000 --- a/Perspex/PerspexProperty.cs +++ /dev/null @@ -1,336 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Subjects; - using System.Reflection; - using System.Text; - using System.Threading.Tasks; - - /// - /// A perspex property. - /// - /// - /// This class is analogous to DependencyProperty in WPF. - /// - public class PerspexProperty - { - /// - /// Represents an unset property value. - /// - public static readonly object UnsetValue = new Unset(); - - /// - /// The default values for the property, by type. - /// - private Dictionary defaultValues = new Dictionary(); - - /// - /// Observable fired when this property changes on any . - /// - private Subject changed = new Subject(); - - /// - /// Initializes a new instance of the class. - /// - /// The name of the property. - /// The type of the property's value. - /// The type of the class that registers the property. - /// The default value of the property. - /// Whether the property inherits its value. - /// The default binding mode for the property. - public PerspexProperty( - string name, - Type valueType, - Type ownerType, - object defaultValue, - bool inherits, - BindingMode defaultBindingMode) - { - Contract.Requires(name != null); - Contract.Requires(valueType != null); - Contract.Requires(ownerType != null); - - this.Name = name; - this.PropertyType = valueType; - this.OwnerType = ownerType; - this.Inherits = inherits; - this.DefaultBindingMode = defaultBindingMode; - this.defaultValues.Add(ownerType, defaultValue); - } - - /// - /// Gets the name of the property. - /// - public string Name { get; private set; } - - /// - /// Gets the type of the property's value. - /// - public Type PropertyType { get; private set; } - - /// - /// Gets the type of the class that registers the property. - /// - public Type OwnerType { get; private set; } - - /// - /// Gets a value indicating whether the property inherits its value. - /// - public bool Inherits { get; private set; } - - /// - /// Gets the default binding mode for the property. - /// - /// - public BindingMode DefaultBindingMode { get; private set; } - - /// - /// Gets an observable that is fired when this property changes on any - /// instance. - /// - public IObservable Changed - { - get { return this.changed; } - } - - /// - /// Registers a . - /// - /// The type of the class that is registering the property. - /// The type of the property's value. - /// The name of the property. - /// The default value of the property. - /// Whether the property inherits its value. - /// The default binding mode for the property. - /// A - public static PerspexProperty Register( - string name, - TValue defaultValue = default(TValue), - bool inherits = false, - BindingMode defaultBindingMode = BindingMode.OneWay) - where TOwner : PerspexObject - { - Contract.Requires(name != null); - - PerspexProperty result = new PerspexProperty( - name, - typeof(TOwner), - defaultValue, - inherits, - defaultBindingMode); - - PerspexObject.Register(typeof(TOwner), result); - - return result; - } - - /// - /// Registers an attached . - /// - /// The type of the class that is registering the property. - /// The type of the class that the property is to be registered on. - /// The type of the property's value. - /// The name of the property. - /// The default value of the property. - /// Whether the property inherits its value. - /// The default binding mode for the property. - /// A - public static PerspexProperty RegisterAttached( - string name, - TValue defaultValue = default(TValue), - bool inherits = false, - BindingMode defaultBindingMode = BindingMode.OneWay) - where TOwner : PerspexObject - { - Contract.Requires(name != null); - - PerspexProperty result = new PerspexProperty( - name, - typeof(TOwner), - defaultValue, - inherits, - defaultBindingMode); - - PerspexObject.Register(typeof(THost), result); - - return result; - } - - /// - /// Provides access to a property's binding via the - /// indexer. - /// - /// The property. - /// A describing the binding. - public static Binding operator!(PerspexProperty property) - { - return new Binding - { - Priority = BindingPriority.LocalValue, - Property = property, - }; - } - - /// - /// Provides access to a property's template binding via the - /// indexer. - /// - /// The property. - /// A describing the binding. - public static Binding operator ~(PerspexProperty property) - { - return new Binding - { - Priority = BindingPriority.TemplatedParent, - Property = property, - }; - } - - /// - /// Returns a binding accessor that can be passed to 's [] - /// operator to initiate a binding. - /// - /// A . - /// - /// The ! and ~ operators are short forms of this. - /// - public Binding Bind() - { - return new Binding - { - Property = this, - }; - } - - /// - /// Gets the default value for the property on the specified type. - /// - /// The type. - /// The default value. - public object GetDefaultValue(Type type) - { - Contract.Requires(type != null); - - while (type != null) - { - object result; - - if (this.defaultValues.TryGetValue(type, out result)) - { - return result; - } - - type = type.GetTypeInfo().BaseType; - } - - return this.defaultValues[this.OwnerType]; - } - - public bool IsValidValue(object value) - { - if (value == UnsetValue) - { - return true; - } - else if (value == null) - { - return !this.PropertyType.GetTypeInfo().IsValueType || - Nullable.GetUnderlyingType(this.PropertyType) != null; - } - - return this.PropertyType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()); - } - - /// - /// Gets the default value for the property on the specified type. - /// - /// The type. - /// The default value. - public void OverrideDefaultValue(Type type, object defaultValue) - { - Contract.Requires(type != null); - - // TODO: Ensure correct type. - - if (this.defaultValues.ContainsKey(type)) - { - throw new InvalidOperationException("Default value is already set for this property."); - } - - this.defaultValues.Add(type, defaultValue); - } - - public override string ToString() - { - return this.Name; - } - - internal void NotifyChanged(PerspexPropertyChangedEventArgs e) - { - this.changed.OnNext(e); - } - - private class Unset - { - public override string ToString() - { - return "{Unset}"; - } - } - } - - /// - /// A typed perspex property. - /// - public class PerspexProperty : PerspexProperty - { - /// - /// Initializes a new instance of the class. - /// - /// The name of the property. - /// The type of the class that registers the property. - /// The default value of the property. - /// Whether the property inherits its value. - /// The default binding mode for the property. - public PerspexProperty( - string name, - Type ownerType, - TValue defaultValue, - bool inherits, - BindingMode defaultBindingMode) - : base(name, typeof(TValue), ownerType, defaultValue, inherits, defaultBindingMode) - { - Contract.Requires(name != null); - Contract.Requires(ownerType != null); - } - - /// - /// Registers the property on another type. - /// - /// The type of the additional owner. - /// The property. - public PerspexProperty AddOwner() - { - PerspexObject.Register(typeof(TOwner), this); - return this; - } - - /// - /// Gets the default value for the property on the specified type. - /// - /// The type. - /// The default value. - public TValue GetDefaultValue() - { - return (TValue)this.GetDefaultValue(typeof(T)); - } - } -} diff --git a/Perspex/PerspexPropertyChangedEventArgs.cs b/Perspex/PerspexPropertyChangedEventArgs.cs deleted file mode 100644 index 5a48bea354..0000000000 --- a/Perspex/PerspexPropertyChangedEventArgs.cs +++ /dev/null @@ -1,53 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - /// - /// Provides information for a perspex property change. - /// - public class PerspexPropertyChangedEventArgs - { - public PerspexPropertyChangedEventArgs( - PerspexObject sender, - PerspexProperty property, - object oldValue, - object newValue) - { - this.Sender = sender; - this.Property = property; - this.OldValue = oldValue; - this.NewValue = newValue; - } - - /// - /// Gets the that the property changed on. - /// - /// - public PerspexObject Sender { get; private set; } - - /// - /// Gets the property that changed. - /// - public PerspexProperty Property { get; private set; } - - /// - /// Gets the old value of the property. - /// - public object OldValue { get; private set; } - - /// - /// Gets the new value of the property. - /// - public object NewValue { get; private set; } - } -} diff --git a/Perspex/Platform/IBitmapImpl.cs b/Perspex/Platform/IBitmapImpl.cs deleted file mode 100644 index b6ae7a7ff3..0000000000 --- a/Perspex/Platform/IBitmapImpl.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - public interface IBitmapImpl - { - int PixelWidth { get; } - - int PixelHeight { get; } - - void Save(string fileName); - } -} diff --git a/Perspex/Platform/IGeometryImpl.cs b/Perspex/Platform/IGeometryImpl.cs deleted file mode 100644 index 6b1755230b..0000000000 --- a/Perspex/Platform/IGeometryImpl.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using Perspex.Media; - - public interface IGeometryImpl - { - Rect Bounds { get; } - - Rect GetRenderBounds(double strokeThickness); - } -} diff --git a/Perspex/Platform/IPlatformRenderInterface.cs b/Perspex/Platform/IPlatformRenderInterface.cs deleted file mode 100644 index a5bb3be06c..0000000000 --- a/Perspex/Platform/IPlatformRenderInterface.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using System; - using Perspex.Threading; - - public interface IPlatformRenderInterface - { - ITextService TextService { get; } - - IBitmapImpl CreateBitmap(int width, int height); - - IStreamGeometryImpl CreateStreamGeometry(); - - IRenderer CreateRenderer(IntPtr handle, double width, double height); - - IRenderTargetBitmapImpl CreateRenderTargetBitmap(int width, int height); - - IBitmapImpl LoadBitmap(string fileName); - } -} diff --git a/Perspex/Platform/IPlatformThreadingInterface.cs b/Perspex/Platform/IPlatformThreadingInterface.cs deleted file mode 100644 index fa71e33956..0000000000 --- a/Perspex/Platform/IPlatformThreadingInterface.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using System; - using Perspex.Threading; - - public interface IPlatformThreadingInterface - { - Dispatcher GetThreadDispatcher(); - - void KillTimer(object timerHandle); - - object StartTimer(TimeSpan interval, Action internalTick); - } -} diff --git a/Perspex/Platform/IRenderTargetBitmapImpl.cs b/Perspex/Platform/IRenderTargetBitmapImpl.cs deleted file mode 100644 index dc20a78304..0000000000 --- a/Perspex/Platform/IRenderTargetBitmapImpl.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - public interface IRenderTargetBitmapImpl : IBitmapImpl - { - void Render(IVisual visual); - } -} diff --git a/Perspex/Platform/IRenderer.cs b/Perspex/Platform/IRenderer.cs deleted file mode 100644 index e251fe0f6e..0000000000 --- a/Perspex/Platform/IRenderer.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using System; - - public interface IRenderer - { - /// - /// Renders the specified visual. - /// - /// The visual to render. - void Render(IVisual visual); - - /// - /// Resizes the rendered viewport. - /// - /// The new width. - /// The new height. - void Resize(int width, int height); - } -} diff --git a/Perspex/Platform/IStreamGeometryContextImpl.cs b/Perspex/Platform/IStreamGeometryContextImpl.cs deleted file mode 100644 index cb58199f72..0000000000 --- a/Perspex/Platform/IStreamGeometryContextImpl.cs +++ /dev/null @@ -1,19 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using System; - - public interface IStreamGeometryContextImpl : IDisposable - { - void BeginFigure(Point startPoint, bool isFilled); - - void LineTo(Point point); - - void EndFigure(bool isClosed); - } -} diff --git a/Perspex/Platform/IStreamGeometryImpl.cs b/Perspex/Platform/IStreamGeometryImpl.cs deleted file mode 100644 index 0f7065ff22..0000000000 --- a/Perspex/Platform/IStreamGeometryImpl.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - public interface IStreamGeometryImpl : IGeometryImpl - { - IStreamGeometryContextImpl Open(); - } -} diff --git a/Perspex/Platform/ITextService.cs b/Perspex/Platform/ITextService.cs deleted file mode 100644 index d4eadd7b91..0000000000 --- a/Perspex/Platform/ITextService.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using Perspex.Media; - - public interface ITextService - { - int GetCaretIndex(FormattedText text, Point point, Size constraint); - - Point GetCaretPosition(FormattedText text, int caretIndex, Size constraint); - - double[] GetLineHeights(FormattedText text, Size constraint); - - Size Measure(FormattedText text, Size constraint); - } -} diff --git a/Perspex/Point.cs b/Perspex/Point.cs deleted file mode 100644 index 8e000e9d34..0000000000 --- a/Perspex/Point.cs +++ /dev/null @@ -1,77 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System.Globalization; - - /// - /// Defines a point. - /// - public struct Point - { - /// - /// The X position. - /// - private double x; - - /// - /// The Y position. - /// - private double y; - - /// - /// Initializes a new instance of the structure. - /// - /// The X position. - /// The Y position. - public Point(double x, double y) - { - this.x = x; - this.y = y; - } - - /// - /// Gets the X position. - /// - public double X - { - get { return this.x; } - } - - /// - /// Gets the Y position. - /// - public double Y - { - get { return this.y; } - } - - public static Point operator +(Point a, Point b) - { - return new Point(a.x + b.x, a.y + b.y); - } - - public static Point operator -(Point a, Point b) - { - return new Point(a.x - b.x, a.y - b.y); - } - - public static implicit operator Vector(Point p) - { - return new Vector(p.x, p.y); - } - - /// - /// Returns the string representation of the point. - /// - /// The string representation of the point. - public override string ToString() - { - return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", this.x, this.y); - } - } -} diff --git a/Perspex/PriorityValue.cs b/Perspex/PriorityValue.cs deleted file mode 100644 index ffc67cccd6..0000000000 --- a/Perspex/PriorityValue.cs +++ /dev/null @@ -1,405 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Reactive.Disposables; - using System.Reactive.Subjects; - using System.Reflection; - - /// - /// Maintains a list of prioritised bindings together with a current value. - /// - /// - /// Bindings, in the form of s are added to the object using - /// the method. With the observable is passed a priority, where lower values - /// represent higher priorites. The current is selected from the highest - /// priority binding that doesn't return . Where there - /// are multiple bindings registered with the same priority, the most recently added binding - /// has a higher priority. Each time the value changes to a distinct new value, the - /// observable is fired with the old and new values. - /// - public class PriorityValue - { - /// - /// The name of the property. - /// - private string name; - - /// - /// The value type. - /// - private Type valueType; - - /// - /// The currently registered binding entries. - /// - private LinkedList bindings = new LinkedList(); - - /// - /// The changed observable. - /// - private Subject> changed = new Subject>(); - - /// - /// The current value. - /// - private object value; - - /// - /// Initializes a new instance of the class. - /// - /// The name of the property. - /// The value type. - public PriorityValue(string name, Type valueType) - { - this.name = name; - this.valueType = valueType; - this.value = PerspexProperty.UnsetValue; - this.ValuePriority = int.MaxValue; - } - - /// - /// Fired whenever the current changes to a new distinct value. - /// - public IObservable> Changed - { - get { return this.changed; } - } - - /// - /// Gets the current value. - /// - public object Value - { - get { return this.value; } - } - - /// - /// Gets the priority of the binding that is currently active. - /// - public int ValuePriority - { - get; - private set; - } - - /// - /// Checks whether a value is valid for a type. - /// - /// - /// - /// - public static bool IsValidValue(object value, Type propertyType) - { - TypeInfo type = propertyType.GetTypeInfo(); - - if (value == PerspexProperty.UnsetValue) - { - return true; - } - else if (value == null) - { - if (type.IsValueType && - (!type.IsGenericType || !(type.GetGenericTypeDefinition() == typeof(Nullable<>)))) - { - return false; - } - } - else - { - if (!type.IsAssignableFrom(value.GetType().GetTypeInfo())) - { - return false; - } - } - - return true; - } - - /// - /// Adds a new binding. - /// - /// The binding. - /// The binding priority. - /// - /// A disposable that will remove the binding. - /// - public IDisposable Add(IObservable binding, int priority) - { - BindingEntry entry = new BindingEntry(); - LinkedListNode insert = this.bindings.First; - - while (insert != null && insert.Value.Priority < priority) - { - insert = insert.Next; - } - - if (insert == null) - { - this.bindings.AddLast(entry); - } - else - { - this.bindings.AddBefore(insert, entry); - } - - entry.Start(binding, priority, this.EntryChanged, this.EntryCompleted); - - return Disposable.Create(() => - { - this.Remove(entry); - }); - } - - /// - /// Adds a new binding, replacing all those of the same priority. - /// - /// The binding. - /// The binding priority. - /// - /// A disposable that will remove the binding. - /// - public IDisposable Replace(IObservable binding, int priority) - { - BindingEntry entry = new BindingEntry(); - LinkedListNode insert = this.bindings.First; - - while (insert != null && insert.Value.Priority < priority) - { - insert = insert.Next; - } - - while (insert != null && insert.Value.Priority == priority) - { - LinkedListNode next = insert.Next; - insert.Value.Dispose(); - this.bindings.Remove(insert); - insert = next; - } - - if (insert == null) - { - this.bindings.AddLast(entry); - } - else - { - this.bindings.AddBefore(insert, entry); - } - - entry.Start(binding, priority, this.EntryChanged, this.EntryCompleted); - - return Disposable.Create(() => - { - this.Remove(entry); - }); - } - - /// - /// Removes all bindings with the specified priority. - /// - /// The priority. - public void Clear(int priority) - { - LinkedListNode item = this.bindings.First; - bool removed = false; - - while (item != null && item.Value.Priority <= priority) - { - LinkedListNode next = item.Next; - - if (item.Value.Priority == priority) - { - item.Value.Dispose(); - this.bindings.Remove(item); - removed = true; - } - - item = next; - } - - if (removed && priority <= this.ValuePriority) - { - this.UpdateValue(); - } - } - - /// - /// Gets the currently active bindings on this object. - /// - /// An enumerable collection of bindings. - public IEnumerable GetBindings() - { - return this.bindings; - } - - /// - /// Called when a binding's value changes. - /// - /// The changed entry. - private void EntryChanged(BindingEntry changed) - { - if (changed.Priority <= this.ValuePriority) - { - this.UpdateValue(); - } - } - - /// - /// Called when a binding completes. - /// - /// The completed entry. - private void EntryCompleted(BindingEntry entry) - { - this.Remove(entry); - } - - /// - /// Sets the current value and notifies all observers. - /// - /// The new value. - /// The priority of the binding which produced the value. - private void SetValue(object value, int priority) - { - if (!IsValidValue(value, this.valueType)) - { - throw new InvalidOperationException(string.Format( - "Invalid value for Property '{0}': {1} ({2})", - this.name, - value, - value.GetType().FullName)); - } - - object old = this.value; - - this.ValuePriority = priority; - - if (!EqualityComparer.Default.Equals(old, value)) - { - this.value = value; - this.changed.OnNext(Tuple.Create(old, value)); - } - } - - /// - /// Removes the specified binding entry and updates the current value. - /// - /// The binding entry to remove. - private void Remove(BindingEntry entry) - { - entry.Dispose(); - this.bindings.Remove(entry); - this.UpdateValue(); - } - - /// - /// Updates the current value. - /// - private void UpdateValue() - { - foreach (BindingEntry entry in this.bindings) - { - if (entry.Value != PerspexProperty.UnsetValue) - { - this.SetValue(entry.Value, entry.Priority); - return; - } - } - - this.SetValue(PerspexProperty.UnsetValue, int.MaxValue); - } - - /// - /// A registered binding. - /// - public class BindingEntry : IDisposable - { - /// - /// The binding subscription. - /// - private IDisposable subscription; - - /// - /// Gets a description of the binding. - /// - public string Description - { - get; - private set; - } - - /// - /// The priority of the binding. - /// - public int Priority - { - get; - private set; - } - - /// - /// The current value of the binding. - /// - public object Value - { - get; - private set; - } - - /// - /// Starts listening to the specified binding. - /// - /// The binding. - /// The binding priority. - /// Called when the binding changes. - /// Called when the binding completes. - public void Start( - IObservable binding, - int priority, - Action changed, - Action completed) - { - Contract.Requires(binding != null); - Contract.Requires(changed != null); - Contract.Requires(completed != null); - - if (this.subscription != null) - { - throw new Exception("PriorityValue.Entry.Start() called more than once."); - } - - this.Priority = priority; - this.Value = PerspexProperty.UnsetValue; - - if (binding is IObservableDescription) - { - this.Description = ((IObservableDescription)binding).Description; - } - - this.subscription = binding.Subscribe( - value => - { - this.Value = value; - changed(this); - }, - () => completed(this)); - } - - /// - /// Ends the binding subscription. - /// - public void Dispose() - { - if (this.subscription != null) - { - this.subscription.Dispose(); - } - } - } - } -} diff --git a/Perspex/Properties/AssemblyInfo.cs b/Perspex/Properties/AssemblyInfo.cs deleted file mode 100644 index 0dd8327fa8..0000000000 --- a/Perspex/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Perspex")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Perspex")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] - -[assembly: InternalsVisibleTo("Perspex.UnitTests")] \ No newline at end of file diff --git a/Perspex/Rect.cs b/Perspex/Rect.cs deleted file mode 100644 index 88f8abfe6b..0000000000 --- a/Perspex/Rect.cs +++ /dev/null @@ -1,300 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Globalization; - - /// - /// Defines a rectangle. - /// - public struct Rect - { - /// - /// The X position. - /// - private double x; - - /// - /// The Y position. - /// - private double y; - - /// - /// The width. - /// - private double width; - - /// - /// The height. - /// - private double height; - - /// - /// Initializes a new instance of the structure. - /// - /// The X position. - /// The Y position. - /// The width. - /// The height. - public Rect(double x, double y, double width, double height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - /// - /// Initializes a new instance of the structure. - /// - /// The size of the rectangle. - public Rect(Size size) - { - this.x = 0; - this.y = 0; - this.width = size.Width; - this.height = size.Height; - } - - /// - /// Initializes a new instance of the structure. - /// - /// The position of the rectangle. - /// The size of the rectangle. - public Rect(Point position, Size size) - { - this.x = position.X; - this.y = position.Y; - this.width = size.Width; - this.height = size.Height; - } - - /// - /// Initializes a new instance of the structure. - /// - /// The top left position of the rectangle. - /// The bottom right position of the rectangle. - public Rect(Point topLeft, Point bottomRight) - { - this.x = topLeft.X; - this.y = topLeft.Y; - this.width = bottomRight.X - topLeft.X; - this.height = bottomRight.Y - topLeft.Y; - } - - /// - /// Gets the X position. - /// - public double X - { - get { return this.x; } - } - - /// - /// Gets the Y position. - /// - public double Y - { - get { return this.y; } - } - - /// - /// Gets the width. - /// - public double Width - { - get { return this.width; } - } - - /// - /// Gets the height. - /// - public double Height - { - get { return this.height; } - } - - /// - /// Gets the position of the rectangle. - /// - public Point Position - { - get { return new Point(this.x, this.y); } - } - - /// - /// Gets the size of the rectangle. - /// - public Size Size - { - get { return new Size(this.width, this.height); } - } - - /// - /// Gets the right position of the rectangle. - /// - public double Right - { - get { return this.x + this.width; } - } - - /// - /// Gets the bottom position of the rectangle. - /// - public double Bottom - { - get { return this.y + this.height; } - } - - /// - /// Gets the top left point of the rectangle. - /// - public Point TopLeft - { - get { return new Point(this.x, this.y); } - } - - /// - /// Gets the top right point of the rectangle. - /// - public Point TopRight - { - get { return new Point(this.Right, this.y); } - } - - /// - /// Gets the bottom left point of the rectangle. - /// - public Point BottomLeft - { - get { return new Point(this.x, this.Bottom); } - } - - /// - /// Gets the bottom right point of the rectangle. - /// - public Point BottomRight - { - get { return new Point(this.Right, this.Bottom); } - } - - /// - /// Gets a value that indicates whether the rectangle is empty. - /// - public bool IsEmpty - { - get { return this.width == 0 && this.height == 0; } - } - - public static Rect operator *(Rect rect, Vector scale) - { - double centerX = rect.x + rect.width / 2; - double centerY = rect.y + rect.height / 2; - double width = rect.width * scale.X; - double height = rect.height * scale.Y; - return new Rect( - centerX - (width / 2), - centerY - (height / 2), - width, - height); - } - - public static Rect operator /(Rect rect, Vector scale) - { - double centerX = rect.x + rect.width / 2; - double centerY = rect.y + rect.height / 2; - double width = rect.width / scale.X; - double height = rect.height / scale.Y; - return new Rect( - centerX - (width / 2), - centerY - (height / 2), - width, - height); - } - - /// - /// Determines whether a points in in the bounds of the rectangle. - /// - /// The point. - /// true if the point is in the bounds of the rectangle; otherwise false. - public bool Contains(Point p) - { - return p.X >= this.x && p.X < this.x + this.width && - p.Y >= this.y && p.Y < this.y + this.height; - } - - public Rect Center(Rect rect) - { - return new Rect( - this.x + ((this.width - rect.width) / 2), - this.y + ((this.height - rect.height) / 2), - rect.width, - rect.height); - } - - /// - /// Deflates the rectangle. - /// - /// The thickness. - /// The deflated rectangle. - /// The deflated rectangle size cannot be less than 0. - public Rect Deflate(double thickness) - { - return this.Deflate(new Thickness(thickness)); - } - - /// - /// Deflates the rectangle by a . - /// - /// The thickness. - /// The deflated rectangle. - /// The deflated rectangle size cannot be less than 0. - public Rect Deflate(Thickness thickness) - { - return new Rect( - new Point(this.x + thickness.Left, this.y + thickness.Top), - this.Size.Deflate(thickness)); - } - - public Rect Intersect(Rect rect) - { - double x = Math.Max(this.x, rect.x); - double y = Math.Max(this.y, rect.y); - double width = Math.Min(this.Right, rect.Right) - x; - double height = Math.Min(this.Bottom, rect.Bottom) - y; - - if (width < 0 || height < 0) - { - return new Rect( - double.PositiveInfinity, - double.PositiveInfinity, - double.NegativeInfinity, - double.NegativeInfinity); - } - else - { - return new Rect(x, y, width, height); - } - } - - /// - /// Returns the string representation of the rectangle. - /// - /// The string representation of the rectangle. - public override string ToString() - { - return string.Format( - CultureInfo.InvariantCulture, - "{0}, {1}, {2}, {3}", - this.x, - this.y, - this.width, - this.height); - } - } -} diff --git a/Perspex/Rendering/IRenderManager.cs b/Perspex/Rendering/IRenderManager.cs deleted file mode 100644 index f239f7d7e5..0000000000 --- a/Perspex/Rendering/IRenderManager.cs +++ /dev/null @@ -1,18 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Rendering -{ - using System; - using System.Reactive; - - public interface IRenderManager - { - IObservable RenderNeeded { get; } - - void InvalidateRender(IVisual visual); - } -} diff --git a/Perspex/Rendering/IRendered.cs b/Perspex/Rendering/IRendered.cs deleted file mode 100644 index bd6f83198a..0000000000 --- a/Perspex/Rendering/IRendered.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Rendering -{ - public interface IRenderRoot - { - IRenderManager RenderManager { get; } - } -} diff --git a/Perspex/Rendering/RenderManager.cs b/Perspex/Rendering/RenderManager.cs deleted file mode 100644 index a5c0e9448c..0000000000 --- a/Perspex/Rendering/RenderManager.cs +++ /dev/null @@ -1,27 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Rendering -{ - using System; - using System.Reactive; - using System.Reactive.Subjects; - - public class RenderManager : IRenderManager - { - private Subject renderNeeded = new Subject(); - - public IObservable RenderNeeded - { - get { return this.renderNeeded; } - } - - public void InvalidateRender(IVisual visual) - { - this.renderNeeded.OnNext(Unit.Default); - } - } -} diff --git a/Perspex/RoutedEvent.cs b/Perspex/RoutedEvent.cs deleted file mode 100644 index e3e0b9fb27..0000000000 --- a/Perspex/RoutedEvent.cs +++ /dev/null @@ -1,86 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Reflection; - - public enum RoutingStrategy - { - Tunnel, - Bubble, - Direct, - } - - public class RoutedEvent - { - public RoutedEvent( - string name, - RoutingStrategy routingStrategy, - Type eventArgsType, - Type ownerType) - { - Contract.Requires(name != null); - Contract.Requires(eventArgsType != null); - Contract.Requires(ownerType != null); - Contract.Requires(typeof(RoutedEventArgs).GetTypeInfo().IsAssignableFrom(eventArgsType.GetTypeInfo())); - Contract.Requires(typeof(Interactive).GetTypeInfo().IsAssignableFrom(ownerType.GetTypeInfo())); - - this.EventArgsType = eventArgsType; - this.Name = name; - this.OwnerType = ownerType; - this.RoutingStrategy = routingStrategy; - } - - public Type EventArgsType - { - get; - private set; - } - - public string Name - { - get; - private set; - } - - public Type OwnerType - { - get; - private set; - } - - public RoutingStrategy RoutingStrategy - { - get; - private set; - } - - public static RoutedEvent Register( - string name, - RoutingStrategy routingStrategy) - where TOwner : Interactive - where TEventArgs : RoutedEventArgs - { - Contract.Requires(name != null); - - return new RoutedEvent(name, routingStrategy, typeof(TOwner)); - } - } - - public class RoutedEvent : RoutedEvent - where TEventArgs : RoutedEventArgs - { - public RoutedEvent(string name, RoutingStrategy routingStrategy, Type ownerType) - : base(name, routingStrategy, typeof(TEventArgs), ownerType) - { - Contract.Requires(name != null); - Contract.Requires(ownerType != null); - Contract.Requires(typeof(Interactive).GetTypeInfo().IsAssignableFrom(ownerType.GetTypeInfo())); - } - } -} diff --git a/Perspex/RoutedEventArgs.cs b/Perspex/RoutedEventArgs.cs deleted file mode 100644 index acafd65a7e..0000000000 --- a/Perspex/RoutedEventArgs.cs +++ /dev/null @@ -1,36 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - - public class RoutedEventArgs : EventArgs - { - public RoutedEventArgs() - { - } - - public RoutedEventArgs(RoutedEvent routedEvent) - { - this.RoutedEvent = routedEvent; - } - - public RoutedEventArgs(RoutedEvent routedEvent, object source) - { - this.RoutedEvent = routedEvent; - this.Source = source; - } - - public bool Handled { get; set; } - - public object OriginalSource { get; set; } - - public RoutedEvent RoutedEvent { get; set; } - - public object Source { get; set; } - } -} diff --git a/Perspex/Setter.cs b/Perspex/Setter.cs deleted file mode 100644 index b751858de2..0000000000 --- a/Perspex/Setter.cs +++ /dev/null @@ -1,38 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Collections.Generic; - using System.Reactive.Disposables; - using Perspex.Controls; - - public class Setter - { - public Setter() - { - } - - public Setter(PerspexProperty property, object value) - { - this.Property = property; - this.Value = value; - } - - public PerspexProperty Property - { - get; - set; - } - - public object Value - { - get; - set; - } - } -} diff --git a/Perspex/Settings.StyleCop b/Perspex/Settings.StyleCop deleted file mode 100644 index 5bd6cda777..0000000000 --- a/Perspex/Settings.StyleCop +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - - - \ No newline at end of file diff --git a/Perspex/Shapes/Path.cs b/Perspex/Shapes/Path.cs deleted file mode 100644 index 534a7fc753..0000000000 --- a/Perspex/Shapes/Path.cs +++ /dev/null @@ -1,28 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Shapes -{ - using System; - using Perspex.Media; - - public class Path : Shape - { - public static readonly PerspexProperty DataProperty = - PerspexProperty.Register("Data"); - - public Geometry Data - { - get { return this.GetValue(DataProperty); } - set { this.SetValue(DataProperty, value); } - } - - public override Geometry DefiningGeometry - { - get { return this.Data; } - } - } -} diff --git a/Perspex/Shapes/Rectangle.cs b/Perspex/Shapes/Rectangle.cs deleted file mode 100644 index 6f325331fa..0000000000 --- a/Perspex/Shapes/Rectangle.cs +++ /dev/null @@ -1,36 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Shapes -{ - using Perspex.Media; - - public class Rectangle : Shape - { - private Geometry geometry; - - private Size geometrySize; - - public override Geometry DefiningGeometry - { - get - { - if (this.geometry == null || this.geometrySize != this.ActualSize) - { - this.geometry = new RectangleGeometry(new Rect(0, 0, this.ActualSize.Width, this.ActualSize.Height)); - this.geometrySize = this.ActualSize; - } - - return this.geometry; - } - } - - protected override Size MeasureOverride(Size availableSize) - { - return new Size(this.StrokeThickness, this.StrokeThickness); - } - } -} diff --git a/Perspex/Shapes/Shape.cs b/Perspex/Shapes/Shape.cs deleted file mode 100644 index 478e0a061e..0000000000 --- a/Perspex/Shapes/Shape.cs +++ /dev/null @@ -1,139 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Shapes -{ - using System; - using Perspex.Controls; - using Perspex.Media; - - public abstract class Shape : Control - { - public static readonly PerspexProperty FillProperty = - PerspexProperty.Register("Fill"); - - public static readonly PerspexProperty StretchProperty = - PerspexProperty.Register("Stretch"); - - public static readonly PerspexProperty StrokeProperty = - PerspexProperty.Register("Stroke"); - - public static readonly PerspexProperty StrokeThicknessProperty = - PerspexProperty.Register("StrokeThickness"); - - public abstract Geometry DefiningGeometry - { - get; - } - - public Brush Fill - { - get { return this.GetValue(FillProperty); } - set { this.SetValue(FillProperty, value); } - } - - public Geometry RenderedGeometry - { - get { return this.DefiningGeometry; } - } - - public Stretch Stretch - { - get { return this.GetValue(StretchProperty); } - set { this.SetValue(StretchProperty, value); } - } - - public Brush Stroke - { - get { return this.GetValue(StrokeProperty); } - set { this.SetValue(StrokeProperty, value); } - } - - public double StrokeThickness - { - get { return this.GetValue(StrokeThicknessProperty); } - set { this.SetValue(StrokeThicknessProperty, value); } - } - - protected override Size MeasureOverride(Size availableSize) - { - Rect shapeBounds = this.RenderedGeometry.GetRenderBounds(this.StrokeThickness); - double width = this.Width; - double height = this.Height; - double desiredX = availableSize.Width; - double desiredY = availableSize.Height; - double sx = 0.0; - double sy = 0.0; - - if (double.IsInfinity(availableSize.Width)) - { - desiredX = shapeBounds.Right; - } - - if (double.IsInfinity(availableSize.Height)) - { - desiredY = shapeBounds.Bottom; - } - - if (shapeBounds.Width > 0) - { - sx = desiredX / shapeBounds.Right; - } - - if (shapeBounds.Height > 0) - { - sy = desiredY / shapeBounds.Bottom; - } - - if (double.IsInfinity(availableSize.Width)) - { - sx = sy; - } - - if (double.IsInfinity(availableSize.Height)) - { - sy = sx; - } - - switch (this.Stretch) - { - case Stretch.Uniform: - sx = sy = Math.Min(sx, sy); - break; - case Stretch.UniformToFill: - sx = sy = Math.Max(sx, sy); - break; - case Stretch.Fill: - if (double.IsInfinity(availableSize.Width)) - { - sx = 1.0; - } - - if (double.IsInfinity(availableSize.Height)) - { - sy = 1.0; - } - - break; - default: - sx = sy = 1; - break; - } - - double finalX = (width > 0) ? width : shapeBounds.Right * sx; - double finalY = (height > 0) ? height : shapeBounds.Bottom * sy; - return new Size(finalX, finalY); - } - - public override void Render(IDrawingContext context) - { - if (this.RenderedGeometry != null) - { - context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.RenderedGeometry); - } - } - } -} diff --git a/Perspex/Size.cs b/Perspex/Size.cs deleted file mode 100644 index 23e4cab500..0000000000 --- a/Perspex/Size.cs +++ /dev/null @@ -1,164 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex -{ - using System; - using System.Globalization; - - /// - /// Defines a size. - /// - public struct Size - { - /// - /// The width. - /// - private double width; - - /// - /// The height. - /// - private double height; - - /// - /// Initializes a new instance of the structure. - /// - /// The width. - /// The height. - public Size(double width, double height) - { - this.width = width; - this.height = height; - } - - /// - /// Gets the width. - /// - public double Width - { - get { return this.width; } - } - - /// - /// Gets the height. - /// - public double Height - { - get { return this.height; } - } - - /// - /// Checks for equality between two s. - /// - /// The first size. - /// The second size. - /// True if the sizes are equal; otherwise false. - public static bool operator ==(Size left, Size right) - { - return left.width == right.width && left.height == right.height; - } - - /// - /// Checks for unequality between two s. - /// - /// The first size. - /// The second size. - /// True if the sizes are unequal; otherwise false. - public static bool operator !=(Size left, Size right) - { - return !(left == right); - } - - /// - /// Scales a size. - /// - /// The size - /// The scaling factor. - /// The scaled size. - public static Size operator *(Size size, Vector scale) - { - return new Size(size.width * scale.X, size.height * scale.Y); - } - - /// - /// Scales a size. - /// - /// The size - /// The scaling factor. - /// The scaled size. - public static Size operator /(Size size, Vector scale) - { - return new Size(size.width / scale.X, size.height / scale.Y); - } - - /// - /// Constrains the size. - /// - /// The size to constrain to. - /// The constrained size. - public Size Constrain(Size constraint) - { - return new Size( - Math.Min(this.width, constraint.width), - Math.Min(this.height, constraint.height)); - } - - /// - /// Deflates the size by a . - /// - /// The thickness. - /// The deflated size. - /// The deflated size cannot be less than 0. - public Size Deflate(Thickness thickness) - { - return new Size( - Math.Max(0, this.width - thickness.Left - thickness.Right), - Math.Max(0, this.height - thickness.Top - thickness.Bottom)); - } - - /// - /// Inflates the size by a . - /// - /// The thickness. - /// The inflated size. - public Size Inflate(Thickness thickness) - { - return new Size( - this.width + thickness.Left + thickness.Right, - this.height + thickness.Top + thickness.Bottom); - } - - /// - /// Returns a new with the same height and the specified width. - /// - /// The width. - /// The new . - public Size WithWidth(double width) - { - return new Size(width, this.height); - } - - /// - /// Returns a new with the same width and the specified height. - /// - /// The height. - /// The new . - public Size WithHeight(double height) - { - return new Size(this.width, height); - } - - /// - /// Returns the string representation of the size. - /// - /// The string representation of the size - public override string ToString() - { - return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", this.width, this.height); - } - } -} diff --git a/Perspex/Styling/IStyle.cs b/Perspex/Styling/IStyle.cs deleted file mode 100644 index a1ff620cb4..0000000000 --- a/Perspex/Styling/IStyle.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using Perspex.Controls; - - public interface IStyle - { - void Attach(IStyleable control); - } -} diff --git a/Perspex/Styling/IStyleable.cs b/Perspex/Styling/IStyleable.cs deleted file mode 100644 index 11678c726b..0000000000 --- a/Perspex/Styling/IStyleable.cs +++ /dev/null @@ -1,47 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using Perspex.Controls; - - /// - /// Interface for styleable elements. - /// - public interface IStyleable - { - /// - /// Gets the list of classes for the control. - /// - Classes Classes { get; } - - /// - /// Gets the ID of the control. - /// - string Id { get; } - - /// - /// Gets the template parent of this element if the control comes from a template. - /// - ITemplatedControl TemplatedParent { get; } - - /// - /// Binds a to an observable. - /// - /// The type of the property. - /// The property. - /// The observable. - /// The priority of the binding. - /// - /// A disposable which can be used to terminate the binding. - /// - IDisposable Bind( - PerspexProperty property, - IObservable source, - BindingPriority priority = BindingPriority.LocalValue); - } -} diff --git a/Perspex/Styling/IStyled.cs b/Perspex/Styling/IStyled.cs deleted file mode 100644 index 5d48b22b57..0000000000 --- a/Perspex/Styling/IStyled.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using Perspex.Controls; - - public interface IStyled - { - Styles Styles { get; } - } -} diff --git a/Perspex/Styling/IStyler.cs b/Perspex/Styling/IStyler.cs deleted file mode 100644 index cf244d9f3e..0000000000 --- a/Perspex/Styling/IStyler.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - - public interface IStyler - { - void ApplyStyles(IStyleable control); - } -} diff --git a/Perspex/Styling/Selector.cs b/Perspex/Styling/Selector.cs deleted file mode 100644 index 43d5b8da0e..0000000000 --- a/Perspex/Styling/Selector.cs +++ /dev/null @@ -1,112 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - using System.Text; - using Perspex.Controls; - - public class Selector - { - private bool stopTraversal; - - public Selector() - { - this.GetObservable = _ => Observable.Return(true); - this.Priority = BindingPriority.Style; - } - - public Selector(Selector previous, bool stopTraversal = false) - : this() - { - this.Previous = previous; - this.Priority = previous.Priority; - this.InTemplate = previous != null ? previous.InTemplate : false; - this.stopTraversal = stopTraversal; - } - - public Selector(Selector previous, BindingPriority priority) - : this() - { - this.Previous = previous; - this.Priority = priority; - this.InTemplate = previous != null ? previous.InTemplate : false; - } - - public bool InTemplate - { - get; - set; - } - - public Func> GetObservable - { - get; - set; - } - - public Selector Previous - { - get; - private set; - } - - public BindingPriority Priority - { - get; - private set; - } - - public string SelectorString - { - get; - set; - } - - public Selector MovePrevious() - { - return this.stopTraversal ? null : this.Previous; - } - - public StyleActivator GetActivator(IStyleable control) - { - List> inputs = new List>(); - Selector selector = this; - - while (selector != null) - { - if (selector.InTemplate && control.TemplatedParent == null) - { - inputs.Add(Observable.Return(false)); - } - else - { - inputs.Add(selector.GetObservable(control)); - } - - selector = selector.MovePrevious(); - } - - return new StyleActivator(inputs); - } - - public override string ToString() - { - string result = string.Empty; - - if (this.Previous != null) - { - result = this.Previous.ToString(); - } - - return result + this.SelectorString; - } - } -} diff --git a/Perspex/Styling/Selectors.cs b/Perspex/Styling/Selectors.cs deleted file mode 100644 index a7e4e9ba48..0000000000 --- a/Perspex/Styling/Selectors.cs +++ /dev/null @@ -1,108 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using System.Collections.Generic; - using System.Reactive.Linq; - using Perspex.Controls; - - public static class Selectors - { - public static Selector Class(this Selector previous, string name) - { - Contract.Requires(previous != null); - Contract.Requires(name != null); - - return new Selector(previous, BindingPriority.StyleTrigger) - { - GetObservable = control => Observable - .Return(control.Classes.Contains(name)) - .Concat(control.Classes.Changed.Select(e => control.Classes.Contains(name))), - SelectorString = (name[0] == ':') ? name : '.' + name, - }; - } - - public static Selector Descendent(this Selector previous) - { - return new Selector(previous, stopTraversal: true) - { - SelectorString = " ", - GetObservable = control => - { - ILogical c = (ILogical)control; - List> descendentMatches = new List>(); - - while (c != null) - { - c = c.LogicalParent; - - if (c is IStyleable) - { - descendentMatches.Add(previous.GetActivator((IStyleable)c)); - } - } - - return new StyleActivator( - descendentMatches, - ActivatorMode.Or); - }, - }; - } - - public static Selector Id(this Selector previous, string id) - { - Contract.Requires(previous != null); - - return new Selector(previous) - { - GetObservable = control => Observable.Return(control.Id == id), - SelectorString = '#' + id, - }; - } - - public static Selector OfType(this Selector previous) where T : IStyleable - { - Contract.Requires(previous != null); - - return new Selector(previous) - { - GetObservable = control => Observable.Return(control.GetType() == typeof(T)), - SelectorString = typeof(T).Name, - }; - } - - public static Selector OfType(this Selector previous, Type type) - { - Contract.Requires(previous != null); - - return new Selector(previous) - { - GetObservable = control => Observable.Return(control.GetType() == type), - SelectorString = type.Name, - }; - } - - public static Selector Template(this Selector previous) - { - Contract.Requires(previous != null); - - return new Selector(previous, stopTraversal: true) - { - GetObservable = control => - { - IStyleable templatedParent = control.TemplatedParent as IStyleable; - return templatedParent != null ? - previous.GetActivator(templatedParent) : - Observable.Return(true); - }, - InTemplate = true, - SelectorString = " $ ", - }; - } - } -} diff --git a/Perspex/Styling/Style.cs b/Perspex/Styling/Style.cs deleted file mode 100644 index 6c8999f646..0000000000 --- a/Perspex/Styling/Style.cs +++ /dev/null @@ -1,71 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - using System.Reactive.Subjects; - using Perspex.Controls; - - public class Style : IStyle - { - public Style() - { - this.Setters = new List(); - } - - public Style(Func selector) - : this() - { - this.Selector = selector(new Selector()); - } - - public Selector Selector - { - get; - set; - } - - public IEnumerable Setters - { - get; - set; - } - - public void Attach(IStyleable control) - { - string description = "Style " + this.Selector.ToString(); - StyleActivator activator = this.Selector.GetActivator(control); - - if (activator.CurrentValue || !activator.HasCompleted) - { - IObservable observable = activator; - - // If the activator has completed, then we want its value to be true forever. - // Because of this we can't pass the activator directly as it will complete - // immediately and remove the binding. - if (activator.HasCompleted) - { - observable = Observable.Never().StartWith(true); - } - - foreach (Setter setter in this.Setters) - { - StyleBinding binding = new StyleBinding(observable, setter.Value, description); - control.Bind(setter.Property, binding, this.Selector.Priority); - } - } - } - - public override string ToString() - { - return "Style: " + this.Selector.ToString(); - } - } -} diff --git a/Perspex/Styling/StyleActivator.cs b/Perspex/Styling/StyleActivator.cs deleted file mode 100644 index 9bb406392a..0000000000 --- a/Perspex/Styling/StyleActivator.cs +++ /dev/null @@ -1,150 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Disposables; - - public enum ActivatorMode - { - And, - Or, - } - - public class StyleActivator : IObservable, IDisposable - { - private ActivatorMode mode; - - private bool[] values; - - private List subscriptions = new List(); - - private List> observers = new List>(); - - public StyleActivator( - IList> inputs, - ActivatorMode mode = ActivatorMode.And) - { - int i = 0; - - this.mode = mode; - this.values = new bool[inputs.Count]; - - foreach (IObservable input in inputs) - { - int capturedIndex = i; - - IDisposable subscription = input.Subscribe( - x => this.Update(capturedIndex, x), - x => this.Finish(capturedIndex), - () => this.Finish(capturedIndex)); - this.subscriptions.Add(subscription); - ++i; - } - } - - public bool CurrentValue - { - get; - private set; - } - - public bool HasCompleted - { - get; - private set; - } - - public void Dispose() - { - foreach (IObserver observer in this.observers) - { - observer.OnCompleted(); - } - - foreach (IDisposable subscription in this.subscriptions) - { - subscription.Dispose(); - } - } - - public IDisposable Subscribe(IObserver observer) - { - Contract.Requires(observer != null); - - observer.OnNext(this.CurrentValue); - - if (this.HasCompleted) - { - observer.OnCompleted(); - return Disposable.Empty; - } - else - { - this.observers.Add(observer); - return Disposable.Create(() => this.observers.Remove(observer)); - } - } - - private void Update(int index, bool value) - { - this.values[index] = value; - - bool current; - - switch (this.mode) - { - case ActivatorMode.And: - current = this.values.All(x => x); - break; - case ActivatorMode.Or: - current = this.values.Any(x => x); - break; - default: - throw new InvalidOperationException("Invalid Activator mode."); - } - - if (current != this.CurrentValue) - { - this.Push(current); - this.CurrentValue = current; - } - } - - private void Finish(int i) - { - // We can unsubscribe from everything if the completed observable: - // - Is the only subscription. - // - Has finished on 'false' and we're in And mode - // - Has finished on 'true' and we're in Or mode - var value = this.values[i]; - var unsubscribe = - (this.values.Length == 1) || - (this.mode == ActivatorMode.And ? !value : value); - - if (unsubscribe) - { - foreach (IDisposable subscription in this.subscriptions) - { - subscription.Dispose(); - } - - this.HasCompleted = true; - } - } - - private void Push(bool value) - { - foreach (IObserver observer in this.observers) - { - observer.OnNext(value); - } - } - } -} diff --git a/Perspex/Styling/StyleBinding.cs b/Perspex/Styling/StyleBinding.cs deleted file mode 100644 index 622f667017..0000000000 --- a/Perspex/Styling/StyleBinding.cs +++ /dev/null @@ -1,75 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using System.Reactive.Subjects; - - /// - /// Provides an observable for a style. - /// - /// - /// This class takes an activator and a value. The activator is an observable which produces - /// a bool. When the activator produces true, this observable will produce . - /// When the activator produces false it will produce . - /// - internal class StyleBinding : IObservable, IObservableDescription - { - /// - /// The activator. - /// - private IObservable activator; - - /// - /// Initializes a new instance of the class. - /// - /// The activator. - /// The activated value. - /// The binding description. - public StyleBinding( - IObservable activator, - object activatedValue, - string description) - { - this.activator = activator; - this.ActivatedValue = activatedValue; - this.Description = description; - } - - /// - /// Gets a description of the binding. - /// - public string Description - { - get; - private set; - } - - /// - /// Gets the activated value. - /// - public object ActivatedValue - { - get; - private set; - } - - /// - /// Notifies the provider that an observer is to receive notifications. - /// - /// The observer. - /// IDisposable object used to unsubscribe from the observable sequence. - public IDisposable Subscribe(IObserver observer) - { - Contract.Requires(observer != null); - return this.activator.Subscribe( - active => observer.OnNext(active ? this.ActivatedValue : PerspexProperty.UnsetValue), - observer.OnError, - observer.OnCompleted); - } - } -} diff --git a/Perspex/Styling/Styler.cs b/Perspex/Styling/Styler.cs deleted file mode 100644 index 1d1932f486..0000000000 --- a/Perspex/Styling/Styler.cs +++ /dev/null @@ -1,45 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - public class Styler : IStyler - { - public void ApplyStyles(IStyleable control) - { - IVisual visual = control as IVisual; - IStyled styleContainer = visual.GetVisualAncestorOrSelf(); - - if (Application.Current != null) - { - Application.Current.Styles.Attach(control); - } - - this.ApplyStyles(control, styleContainer); - } - - private void ApplyStyles(IStyleable control, IStyled container) - { - if (container != null) - { - IVisual visual = container as IVisual; - - if (visual != null) - { - this.ApplyStyles(control, visual.GetVisualAncestor()); - } - - container.Styles.Attach(control); - } - } - } -} diff --git a/Perspex/Styling/Styles.cs b/Perspex/Styling/Styles.cs deleted file mode 100644 index 96257e4066..0000000000 --- a/Perspex/Styling/Styles.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Styling -{ - using Perspex.Controls; - - public class Styles : PerspexList, IStyle - { - public void Attach(IStyleable control) - { - foreach (IStyle style in this) - { - style.Attach(control); - } - } - } -} diff --git a/Perspex/Themes/Default/ButtonStyle.cs b/Perspex/Themes/Default/ButtonStyle.cs deleted file mode 100644 index 30327a4ad6..0000000000 --- a/Perspex/Themes/Default/ButtonStyle.cs +++ /dev/null @@ -1,78 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Themes.Default -{ - using System.Linq; - using Perspex.Controls; - using Perspex.Media; - using Perspex.Styling; - - public class ButtonStyle : Styles - { - public ButtonStyle() - { - this.AddRange(new[] - { - new Style(x => x.OfType