From a833a5e883682263d4537c09d0b0179a756968e1 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 4 Dec 2014 19:55:49 +0100 Subject: [PATCH] Stylecop fixes. Also added solution-wide stylecop settings. --- Perspex.Application/Application.cs | 14 +- .../Properties/AssemblyInfo.cs | 10 +- Perspex.Base/Settings.StyleCop | 1 + Perspex.Controls/Border.cs | 4 +- Perspex.Controls/Control.cs | 6 +- Perspex.Controls/Controls.cs | 4 +- Perspex.Controls/DataTemplate.cs | 12 +- Perspex.Controls/Grid.cs | 8 +- Perspex.Controls/GridSplitter.cs | 6 +- Perspex.Controls/Image.cs | 48 ++--- Perspex.Controls/ItemsControl.cs | 20 +- Perspex.Controls/ItemsPanelTemplate.cs | 12 +- Perspex.Controls/ListBoxItem.cs | 2 +- Perspex.Controls/Panel.cs | 6 +- Perspex.Controls/Presenters/ItemsPresenter.cs | 6 +- .../Presenters/ScrollContentPresenter.cs | 10 +- .../Primitives/HeaderedContentControl.cs | 2 +- Perspex.Controls/Primitives/ScrollBar.cs | 4 +- Perspex.Controls/Primitives/TabStrip.cs | 2 +- Perspex.Controls/Primitives/Thumb.cs | 2 +- Perspex.Controls/Primitives/ToggleButton.cs | 2 +- Perspex.Controls/Primitives/Track.cs | 15 +- Perspex.Controls/Properties/AssemblyInfo.cs | 10 +- Perspex.Controls/ScrollViewer.cs | 20 +- Perspex.Controls/Shapes/Shape.cs | 16 +- Perspex.Controls/TabControl.cs | 2 +- Perspex.Controls/TabItem.cs | 4 +- Perspex.Controls/TextBlock.cs | 2 +- Perspex.Controls/TextBoxView.cs | 16 +- Perspex.Controls/TreeDataTemplate.cs | 26 ++- Perspex.Controls/TreeView.cs | 6 +- Perspex.Controls/TreeViewItem.cs | 6 +- Perspex.Controls/Window.cs | 8 +- .../Properties/AssemblyInfo.cs | 10 +- Settings.StyleCop | 184 ++++++++++++++++++ .../Perspex.Win32/Input/WindowsMouseDevice.cs | 5 +- .../Perspex.Win32/Interop/UnmanagedMethods.cs | 26 +-- .../Perspex.Win32/Properties/AssemblyInfo.cs | 8 +- Windows/Perspex.Win32/Win32Platform.cs | 2 +- Windows/Perspex.Win32/WindowImpl.cs | 1 + 40 files changed, 386 insertions(+), 162 deletions(-) create mode 100644 Perspex.Base/Settings.StyleCop create mode 100644 Settings.StyleCop diff --git a/Perspex.Application/Application.cs b/Perspex.Application/Application.cs index 8247149225e..f6dafd82111 100644 --- a/Perspex.Application/Application.cs +++ b/Perspex.Application/Application.cs @@ -76,6 +76,13 @@ public Styles Styles private set; } + public void Run(ICloseable closable) + { + var source = new CancellationTokenSource(); + closable.Closed += (s, e) => source.Cancel(); + Dispatcher.UIThread.MainLoop(source.Token); + } + protected virtual void RegisterServices() { Locator.CurrentMutable.Register(() => this, typeof(IGlobalDataTemplates)); @@ -84,12 +91,5 @@ protected virtual void RegisterServices() Locator.CurrentMutable.Register(() => this.InputManager, typeof(IInputManager)); Locator.CurrentMutable.Register(() => this.styler, typeof(IStyler)); } - - public void Run(ICloseable closable) - { - var source = new CancellationTokenSource(); - closable.Closed += (s, e) => source.Cancel(); - Dispatcher.UIThread.MainLoop(source.Token); - } } } diff --git a/Perspex.Application/Properties/AssemblyInfo.cs b/Perspex.Application/Properties/AssemblyInfo.cs index c9fa9ecdd7f..04c5a6c9a21 100644 --- a/Perspex.Application/Properties/AssemblyInfo.cs +++ b/Perspex.Application/Properties/AssemblyInfo.cs @@ -1,7 +1,11 @@ -using System.Resources; +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using System.Resources; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/Perspex.Base/Settings.StyleCop b/Perspex.Base/Settings.StyleCop new file mode 100644 index 00000000000..bb05f99bc1a --- /dev/null +++ b/Perspex.Base/Settings.StyleCop @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Perspex.Controls/Border.cs b/Perspex.Controls/Border.cs index bd0be84e28c..c702d09ff55 100644 --- a/Perspex.Controls/Border.cs +++ b/Perspex.Controls/Border.cs @@ -15,8 +15,8 @@ public class Border : Decorator { static Border() { - AffectsRender(BackgroundProperty); - AffectsRender(BorderBrushProperty); + Control.AffectsRender(Border.BackgroundProperty); + Control.AffectsRender(Border.BorderBrushProperty); } public override void Render(IDrawingContext context) diff --git a/Perspex.Controls/Control.cs b/Perspex.Controls/Control.cs index a19185d98d5..581aaa2da22 100644 --- a/Perspex.Controls/Control.cs +++ b/Perspex.Controls/Control.cs @@ -43,9 +43,9 @@ public class Control : InputElement, IStyleable, IStyleHost static Control() { - AffectsMeasure(IsVisibleProperty); - PseudoClass(IsPointerOverProperty, ":pointerover"); - PseudoClass(IsFocusedProperty, ":focus"); + Control.AffectsMeasure(Control.IsVisibleProperty); + PseudoClass(Control.IsPointerOverProperty, ":pointerover"); + PseudoClass(Control.IsFocusedProperty, ":focus"); } public Brush Background diff --git a/Perspex.Controls/Controls.cs b/Perspex.Controls/Controls.cs index 3e0667cc174..5214e59ade3 100644 --- a/Perspex.Controls/Controls.cs +++ b/Perspex.Controls/Controls.cs @@ -4,10 +4,10 @@ // // ----------------------------------------------------------------------- -using System.Collections.Generic; - namespace Perspex.Controls { + using System.Collections.Generic; + public class Controls : PerspexList { public Controls() diff --git a/Perspex.Controls/DataTemplate.cs b/Perspex.Controls/DataTemplate.cs index 9f9de2b4772..6d238a7f9ba 100644 --- a/Perspex.Controls/DataTemplate.cs +++ b/Perspex.Controls/DataTemplate.cs @@ -33,25 +33,25 @@ public DataTemplate(Func match, Func build) this.Build = build; } + public Func Match { get; private set; } + + public Func Build { get; private set; } + 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)) + : base(typeof(T), DataTemplate.Cast(build)) { } public DataTemplate(Func match, Func build) - : base(CastMatch(match), Cast(build)) + : base(CastMatch(match), DataTemplate.Cast(build)) { } diff --git a/Perspex.Controls/Grid.cs b/Perspex.Controls/Grid.cs index 613ce9fcf5a..7b422847586 100644 --- a/Perspex.Controls/Grid.cs +++ b/Perspex.Controls/Grid.cs @@ -605,10 +605,10 @@ private void AssignSize( // 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; + 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; + count += type == GridUnitType.Star ? (matrix[i, i].Stars) : 1; } } @@ -620,7 +620,7 @@ private void AssignSize( for (int i = start; i <= end; i++) { - double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize; + double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize; if (!(matrix[i, i].Type == type && segmentSize < matrix[i, i].Max)) { @@ -628,7 +628,7 @@ private void AssignSize( } double newsize = segmentSize; - newsize += contribution * (type == GridUnitType.Star ? (matrix[i, i].Stars) : 1); + newsize += contribution * (type == GridUnitType.Star ? (matrix[i, i].Stars) : 1); newsize = Math.Min(newsize, matrix[i, i].Max); assigned |= newsize > segmentSize; size -= newsize - segmentSize; diff --git a/Perspex.Controls/GridSplitter.cs b/Perspex.Controls/GridSplitter.cs index 93d62c346f2..99e713d6d9c 100644 --- a/Perspex.Controls/GridSplitter.cs +++ b/Perspex.Controls/GridSplitter.cs @@ -18,10 +18,10 @@ protected override void OnDragDelta(VectorEventArgs e) { int col = this.GetValue(Grid.ColumnProperty); - if (grid != null && col > 0) + if (this.grid != null && col > 0) { - grid.ColumnDefinitions[col - 1].Width = new GridLength( - grid.ColumnDefinitions[col - 1].ActualWidth + e.Vector.X, + this.grid.ColumnDefinitions[col - 1].Width = new GridLength( + this.grid.ColumnDefinitions[col - 1].ActualWidth + e.Vector.X, GridUnitType.Pixel); } } diff --git a/Perspex.Controls/Image.cs b/Perspex.Controls/Image.cs index cb594b33405..051e47cf1f8 100644 --- a/Perspex.Controls/Image.cs +++ b/Perspex.Controls/Image.cs @@ -56,30 +56,6 @@ public override void Render(IDrawingContext drawingContext) } } - 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; @@ -111,5 +87,29 @@ protected override Size ArrangeOverride(Size finalSize) { return finalSize; } + + 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); + } } } diff --git a/Perspex.Controls/ItemsControl.cs b/Perspex.Controls/ItemsControl.cs index 730dc534154..4f053ab0233 100644 --- a/Perspex.Controls/ItemsControl.cs +++ b/Perspex.Controls/ItemsControl.cs @@ -15,15 +15,15 @@ namespace Perspex.Controls 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 static readonly ItemsPanelTemplate DefaultPanel = + new ItemsPanelTemplate(() => new StackPanel { Orientation = Orientation.Vertical }); + private ItemContainerGenerator itemContainerGenerator; public ItemsControl() @@ -44,11 +44,6 @@ public ItemContainerGenerator ItemContainerGenerator } } - protected virtual ItemContainerGenerator CreateItemContainerGenerator() - { - return new ItemContainerGenerator(this); - } - public IEnumerable Items { get { return this.GetValue(ItemsProperty); } @@ -61,13 +56,18 @@ public ItemsPanelTemplate ItemsPanel set { this.SetValue(ItemsPanelProperty, value); } } + protected virtual ItemContainerGenerator CreateItemContainerGenerator() + { + return new ItemContainerGenerator(this); + } + private void ItemsChanged(Tuple value) { INotifyPropertyChanged inpc = value.Item1 as INotifyPropertyChanged; if (inpc != null) { - inpc.PropertyChanged -= ItemsPropertyChanged; + inpc.PropertyChanged -= this.ItemsPropertyChanged; } if (value.Item2 == null || !value.Item2.OfType().Any()) @@ -83,7 +83,7 @@ private void ItemsChanged(Tuple value) if (inpc != null) { - inpc.PropertyChanged += ItemsPropertyChanged; + inpc.PropertyChanged += this.ItemsPropertyChanged; } } diff --git a/Perspex.Controls/ItemsPanelTemplate.cs b/Perspex.Controls/ItemsPanelTemplate.cs index 1e2375c5b02..491b7e0fe11 100644 --- a/Perspex.Controls/ItemsPanelTemplate.cs +++ b/Perspex.Controls/ItemsPanelTemplate.cs @@ -1,11 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// ----------------------------------------------------------------------- +// +// Copyright 2013 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- namespace Perspex.Controls { + using System; + public class ItemsPanelTemplate { public ItemsPanelTemplate(Func build) diff --git a/Perspex.Controls/ListBoxItem.cs b/Perspex.Controls/ListBoxItem.cs index 327cff78878..ce9cdacb5d7 100644 --- a/Perspex.Controls/ListBoxItem.cs +++ b/Perspex.Controls/ListBoxItem.cs @@ -13,7 +13,7 @@ public class ListBoxItem : ContentControl, ISelectable static ListBoxItem() { - PseudoClass(IsSelectedProperty, ":selected"); + Control.PseudoClass(IsSelectedProperty, ":selected"); } public bool IsSelected diff --git a/Perspex.Controls/Panel.cs b/Perspex.Controls/Panel.cs index 417a0d2b45d..147831e3bf1 100644 --- a/Perspex.Controls/Panel.cs +++ b/Perspex.Controls/Panel.cs @@ -24,7 +24,7 @@ public Controls Children if (this.children == null) { this.children = new Controls(); - this.children.CollectionChanged += ChildrenChanged; + this.children.CollectionChanged += this.ChildrenChanged; } return this.children; @@ -38,7 +38,7 @@ public Controls Children { if (this.children != null) { - this.children.CollectionChanged -= ChildrenChanged; + this.children.CollectionChanged -= this.ChildrenChanged; } this.children = value; @@ -46,7 +46,7 @@ public Controls Children if (this.children != null) { - this.children.CollectionChanged += ChildrenChanged; + this.children.CollectionChanged += this.ChildrenChanged; this.AddVisualChildren(value); this.InvalidateMeasure(); } diff --git a/Perspex.Controls/Presenters/ItemsPresenter.cs b/Perspex.Controls/Presenters/ItemsPresenter.cs index 4ed3c5850b9..622e3b9e9d0 100644 --- a/Perspex.Controls/Presenters/ItemsPresenter.cs +++ b/Perspex.Controls/Presenters/ItemsPresenter.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- @@ -51,8 +51,8 @@ protected override sealed void ApplyTemplate() protected override Size MeasureOverride(Size availableSize) { - panel.Measure(availableSize); - return panel.DesiredSize.Value; + this.panel.Measure(availableSize); + return this.panel.DesiredSize.Value; } protected override Size ArrangeOverride(Size finalSize) diff --git a/Perspex.Controls/Presenters/ScrollContentPresenter.cs b/Perspex.Controls/Presenters/ScrollContentPresenter.cs index ae3b89199c5..a33f4af7a87 100644 --- a/Perspex.Controls/Presenters/ScrollContentPresenter.cs +++ b/Perspex.Controls/Presenters/ScrollContentPresenter.cs @@ -9,20 +9,20 @@ namespace Perspex.Controls.Presenters using System.Linq; using Perspex.Layout; - public class ScrollContentPresenter : ContentPresenter + public class ScrollContentPresenter : ContentPresenter { - public static PerspexProperty ExtentProperty = + public static readonly PerspexProperty ExtentProperty = ScrollViewer.ExtentProperty.AddOwner(); - public static PerspexProperty OffsetProperty = + public static readonly PerspexProperty OffsetProperty = ScrollViewer.OffsetProperty.AddOwner(); - public static PerspexProperty ViewportProperty = + public static readonly PerspexProperty ViewportProperty = ScrollViewer.ViewportProperty.AddOwner(); public ScrollContentPresenter() { - AffectsRender(OffsetProperty); + Control.AffectsRender(OffsetProperty); } public Size Extent diff --git a/Perspex.Controls/Primitives/HeaderedContentControl.cs b/Perspex.Controls/Primitives/HeaderedContentControl.cs index 674f1f80644..31686a31aa5 100644 --- a/Perspex.Controls/Primitives/HeaderedContentControl.cs +++ b/Perspex.Controls/Primitives/HeaderedContentControl.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- diff --git a/Perspex.Controls/Primitives/ScrollBar.cs b/Perspex.Controls/Primitives/ScrollBar.cs index 2cc44fccc11..6c075a80573 100644 --- a/Perspex.Controls/Primitives/ScrollBar.cs +++ b/Perspex.Controls/Primitives/ScrollBar.cs @@ -28,8 +28,8 @@ public class ScrollBar : TemplatedControl static ScrollBar() { - PseudoClass(OrientationProperty, x => x == Orientation.Horizontal, ":horizontal"); - PseudoClass(OrientationProperty, x => x == Orientation.Vertical, ":vertical"); + Control.PseudoClass(OrientationProperty, x => x == Orientation.Horizontal, ":horizontal"); + Control.PseudoClass(OrientationProperty, x => x == Orientation.Vertical, ":vertical"); } public double Minimum diff --git a/Perspex.Controls/Primitives/TabStrip.cs b/Perspex.Controls/Primitives/TabStrip.cs index 0f6cc6a2f95..03d3709a759 100644 --- a/Perspex.Controls/Primitives/TabStrip.cs +++ b/Perspex.Controls/Primitives/TabStrip.cs @@ -37,7 +37,7 @@ protected override ItemContainerGenerator CreateItemContainerGenerator() result = new TypedItemContainerGenerator(this); } - result.StateChanged += ItemsContainerGeneratorStateChanged; + result.StateChanged += this.ItemsContainerGeneratorStateChanged; return result; } diff --git a/Perspex.Controls/Primitives/Thumb.cs b/Perspex.Controls/Primitives/Thumb.cs index 5c9adfcb26f..65b583a91d4 100644 --- a/Perspex.Controls/Primitives/Thumb.cs +++ b/Perspex.Controls/Primitives/Thumb.cs @@ -21,7 +21,7 @@ public class Thumb : TemplatedControl public static readonly RoutedEvent DragCompletedEvent = RoutedEvent.Register("DragCompleted", RoutingStrategy.Bubble); - Point? lastPoint; + private Point? lastPoint; public Thumb() { diff --git a/Perspex.Controls/Primitives/ToggleButton.cs b/Perspex.Controls/Primitives/ToggleButton.cs index 4c8a1c44633..101127be712 100644 --- a/Perspex.Controls/Primitives/ToggleButton.cs +++ b/Perspex.Controls/Primitives/ToggleButton.cs @@ -15,7 +15,7 @@ public class ToggleButton : Button static ToggleButton() { - PseudoClass(IsCheckedProperty, ":checked"); + Control.PseudoClass(IsCheckedProperty, ":checked"); } public ToggleButton() diff --git a/Perspex.Controls/Primitives/Track.cs b/Perspex.Controls/Primitives/Track.cs index 6a441284842..2e26608b285 100644 --- a/Perspex.Controls/Primitives/Track.cs +++ b/Perspex.Controls/Primitives/Track.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- @@ -30,6 +30,14 @@ public class Track : Control public static readonly PerspexProperty ThumbProperty = PerspexProperty.Register("Thumb"); + static Track() + { + Control.AffectsArrange(MinimumProperty); + Control.AffectsArrange(MaximumProperty); + Control.AffectsArrange(ValueProperty); + Control.AffectsMeasure(OrientationProperty); + } + public Track() { this.GetObservableWithHistory(ThumbProperty).Subscribe(val => @@ -47,11 +55,6 @@ public Track() this.AddVisualChild(val.Item2); } }); - - AffectsArrange(MinimumProperty); - AffectsArrange(MaximumProperty); - AffectsArrange(ValueProperty); - AffectsMeasure(OrientationProperty); } public double Minimum diff --git a/Perspex.Controls/Properties/AssemblyInfo.cs b/Perspex.Controls/Properties/AssemblyInfo.cs index e5f678d5a70..f39537fd7ad 100644 --- a/Perspex.Controls/Properties/AssemblyInfo.cs +++ b/Perspex.Controls/Properties/AssemblyInfo.cs @@ -1,7 +1,11 @@ -using System.Resources; +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using System.Resources; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/Perspex.Controls/ScrollViewer.cs b/Perspex.Controls/ScrollViewer.cs index 3dd5058e35a..5a384e2d879 100644 --- a/Perspex.Controls/ScrollViewer.cs +++ b/Perspex.Controls/ScrollViewer.cs @@ -1,24 +1,24 @@ // ----------------------------------------------------------------------- -// +// // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- -using System.Reactive.Linq; -using Perspex.Controls.Presenters; -using Perspex.Controls.Primitives; - namespace Perspex.Controls { + using System.Reactive.Linq; + using Perspex.Controls.Presenters; + using Perspex.Controls.Primitives; + public class ScrollViewer : ContentControl { - public static PerspexProperty ExtentProperty = + public static readonly PerspexProperty ExtentProperty = PerspexProperty.Register("Extent"); - public static PerspexProperty OffsetProperty = + public static readonly PerspexProperty OffsetProperty = PerspexProperty.Register("Offset"); - public static PerspexProperty ViewportProperty = + public static readonly PerspexProperty ViewportProperty = PerspexProperty.Register("Viewport"); private ScrollContentPresenter presenter; @@ -61,7 +61,7 @@ protected override void OnTemplateApplied() .Select(x => new { Extent = x[0], Viewport = x[1] }); this.horizontalScrollBar.Bind( - IsVisibleProperty, + Visual.IsVisibleProperty, extentAndViewport.Select(x => x.Extent.Width > x.Viewport.Width)); this.horizontalScrollBar.Bind( @@ -73,7 +73,7 @@ protected override void OnTemplateApplied() extentAndViewport.Select(x => (x.Viewport.Width / x.Extent.Width) * (x.Extent.Width - x.Viewport.Width))); this.verticalScrollBar.Bind( - IsVisibleProperty, + Visual.IsVisibleProperty, extentAndViewport.Select(x => x.Extent.Height > x.Viewport.Height)); this.verticalScrollBar.Bind( diff --git a/Perspex.Controls/Shapes/Shape.cs b/Perspex.Controls/Shapes/Shape.cs index 690164bdbd2..09c37facc02 100644 --- a/Perspex.Controls/Shapes/Shape.cs +++ b/Perspex.Controls/Shapes/Shape.cs @@ -58,6 +58,14 @@ public double StrokeThickness set { this.SetValue(StrokeThicknessProperty, value); } } + public override void Render(IDrawingContext context) + { + if (this.RenderedGeometry != null) + { + context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.RenderedGeometry); + } + } + protected override Size MeasureOverride(Size availableSize) { Rect shapeBounds = this.RenderedGeometry.GetRenderBounds(this.StrokeThickness); @@ -127,13 +135,5 @@ protected override Size MeasureOverride(Size availableSize) 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.Controls/TabControl.cs b/Perspex.Controls/TabControl.cs index 86e5d61790e..5e71dd7b7f1 100644 --- a/Perspex.Controls/TabControl.cs +++ b/Perspex.Controls/TabControl.cs @@ -37,7 +37,7 @@ protected override ItemContainerGenerator CreateItemContainerGenerator() protected override void OnTemplateApplied() { this.tabStrip = this.GetTemplateControls().OfType().FirstOrDefault(); - this.BindTwoWay(SelectedItemProperty, this.tabStrip, SelectedItemProperty); + this.BindTwoWay(TabControl.SelectedItemProperty, this.tabStrip, TabControl.SelectedItemProperty); } } } diff --git a/Perspex.Controls/TabItem.cs b/Perspex.Controls/TabItem.cs index 3f2fca5757b..94828fbdb5f 100644 --- a/Perspex.Controls/TabItem.cs +++ b/Perspex.Controls/TabItem.cs @@ -15,8 +15,8 @@ public class TabItem : HeaderedContentControl, ISelectable static TabItem() { - AffectsRender(IsSelectedProperty); - PseudoClass(IsSelectedProperty, ":selected"); + Control.AffectsRender(IsSelectedProperty); + Control.PseudoClass(IsSelectedProperty, ":selected"); } public bool IsSelected diff --git a/Perspex.Controls/TextBlock.cs b/Perspex.Controls/TextBlock.cs index e77cf218169..96175e0e7d8 100644 --- a/Perspex.Controls/TextBlock.cs +++ b/Perspex.Controls/TextBlock.cs @@ -27,7 +27,7 @@ public class TextBlock : Control static TextBlock() { - AffectsMeasure(TextProperty); + Control.AffectsMeasure(TextProperty); } public string Text diff --git a/Perspex.Controls/TextBoxView.cs b/Perspex.Controls/TextBoxView.cs index 2a3a4439399..389ac544139 100644 --- a/Perspex.Controls/TextBoxView.cs +++ b/Perspex.Controls/TextBoxView.cs @@ -61,14 +61,6 @@ public void InvalidateText() 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); @@ -95,6 +87,14 @@ public override void Render(IDrawingContext context) } } + internal void CaretMoved() + { + this.caretBlink = true; + this.caretTimer.Stop(); + this.caretTimer.Start(); + this.InvalidateVisual(); + } + protected override Size MeasureOverride(Size constraint) { if (!string.IsNullOrEmpty(this.parent.Text)) diff --git a/Perspex.Controls/TreeDataTemplate.cs b/Perspex.Controls/TreeDataTemplate.cs index 5a78fea93f8..b72af87c2b9 100644 --- a/Perspex.Controls/TreeDataTemplate.cs +++ b/Perspex.Controls/TreeDataTemplate.cs @@ -22,7 +22,7 @@ public TreeDataTemplate( Type type, Func build, Func itemsSelector) - : this(o => IsInstance(o, type), build, itemsSelector) + : this(o => DataTemplate.IsInstance(o, type), build, itemsSelector) { } @@ -31,7 +31,7 @@ public TreeDataTemplate( Func build, Func itemsSelector, Func isExpanded) - : this(o => IsInstance(o, type), build, itemsSelector, isExpanded) + : this(o => DataTemplate.IsInstance(o, type), build, itemsSelector, isExpanded) { } @@ -65,7 +65,10 @@ public class TreeDataTemplate : TreeDataTemplate public TreeDataTemplate( Func build, Func itemsSelector) - : base(typeof(T), Cast(build), Cast(itemsSelector)) + : base( + typeof(T), + TreeDataTemplate.Cast(build), + TreeDataTemplate.Cast(itemsSelector)) { } @@ -73,7 +76,11 @@ public TreeDataTemplate( Func build, Func itemsSelector, Func isExpanded) - : base(typeof(T), Cast(build), Cast(itemsSelector), Cast(isExpanded)) + : base( + typeof(T), + TreeDataTemplate.Cast(build), + TreeDataTemplate.Cast(itemsSelector), + TreeDataTemplate.Cast(isExpanded)) { } @@ -81,7 +88,10 @@ public TreeDataTemplate( Func match, Func build, Func itemsSelector) - : base(CastMatch(match), Cast(build), Cast(itemsSelector)) + : base( + TreeDataTemplate.CastMatch(match), + TreeDataTemplate.Cast(build), + TreeDataTemplate.Cast(itemsSelector)) { } @@ -90,7 +100,11 @@ public TreeDataTemplate( Func build, Func itemsSelector, Func isExpanded) - : base(CastMatch(match), Cast(build), Cast(itemsSelector), Cast(isExpanded)) + : base( + TreeDataTemplate.CastMatch(match), + TreeDataTemplate.Cast(build), + TreeDataTemplate.Cast(itemsSelector), + TreeDataTemplate.Cast(isExpanded)) { } diff --git a/Perspex.Controls/TreeView.cs b/Perspex.Controls/TreeView.cs index 85f0e6573e5..c3a92901307 100644 --- a/Perspex.Controls/TreeView.cs +++ b/Perspex.Controls/TreeView.cs @@ -36,6 +36,7 @@ protected override void MoveSelection(FocusNavigationDirection direction) { this.SelectedItem = list[index - 1]; } + break; } @@ -48,6 +49,7 @@ protected override void MoveSelection(FocusNavigationDirection direction) { this.SelectedItem = list[index + 1]; } + break; } @@ -68,14 +70,14 @@ protected override void MoveSelection(FocusNavigationDirection direction) } } - List Flatten() + private List Flatten() { var result = new List(); this.Flatten(this.Items, result); return result; } - void Flatten(IEnumerable items, List result) + private void Flatten(IEnumerable items, List result) { if (items != null) { diff --git a/Perspex.Controls/TreeViewItem.cs b/Perspex.Controls/TreeViewItem.cs index 8b24db205c3..c0c028818fd 100644 --- a/Perspex.Controls/TreeViewItem.cs +++ b/Perspex.Controls/TreeViewItem.cs @@ -19,16 +19,16 @@ public class TreeViewItem : HeaderedItemsControl, ISelectable public static readonly PerspexProperty IsSelectedProperty = ListBoxItem.IsSelectedProperty.AddOwner(); - TreeView treeView; + private TreeView treeView; static TreeViewItem() { - PseudoClass(IsSelectedProperty, ":selected"); + Control.PseudoClass(IsSelectedProperty, ":selected"); } public TreeViewItem() { - AffectsRender(IsSelectedProperty); + Control.AffectsRender(IsSelectedProperty); } public bool IsExpanded diff --git a/Perspex.Controls/Window.cs b/Perspex.Controls/Window.cs index c3f070068f0..f4f5843bb41 100644 --- a/Perspex.Controls/Window.cs +++ b/Perspex.Controls/Window.cs @@ -34,10 +34,6 @@ public class Window : ContentControl, ILayoutRoot, IRenderRoot, ICloseable, IFoc private IInputManager inputManager; - public event EventHandler Activated; - - public event EventHandler Closed; - static Window() { BackgroundProperty.OverrideDefaultValue(typeof(Window), Brushes.White); @@ -85,6 +81,10 @@ public Window() styler.ApplyStyles(this); } + public event EventHandler Activated; + + public event EventHandler Closed; + public Size ClientSize { get { return this.GetValue(ClientSizeProperty); } diff --git a/Perspex.Themes.Default/Properties/AssemblyInfo.cs b/Perspex.Themes.Default/Properties/AssemblyInfo.cs index 0b148c3602a..83df8747d14 100644 --- a/Perspex.Themes.Default/Properties/AssemblyInfo.cs +++ b/Perspex.Themes.Default/Properties/AssemblyInfo.cs @@ -1,7 +1,11 @@ -using System.Resources; +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using System.Resources; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/Settings.StyleCop b/Settings.StyleCop new file mode 100644 index 00000000000..5bd6cda7779 --- /dev/null +++ b/Settings.StyleCop @@ -0,0 +1,184 @@ + + + + + + + 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/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs b/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs index abf36d40a36..094d06ed335 100644 --- a/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs +++ b/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- @@ -39,5 +39,4 @@ protected override Point GetClientPosition() return new Point(p.X, p.Y); } } -} - +} \ No newline at end of file diff --git a/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs b/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs index c295080738a..6b37c21e2b6 100644 --- a/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs +++ b/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs @@ -42,18 +42,6 @@ public enum Cursor IDC_HELP = 32651 } - [StructLayout(LayoutKind.Sequential)] - public struct PAINTSTRUCT - { - public IntPtr hdc; - public bool fErase; - public RECT rcPaint; - public bool fRestore; - public bool fIncUpdate; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] - public byte[] rgbReserved; - } - [Flags] public enum SetWindowPosFlags : uint { @@ -469,7 +457,7 @@ public static extern IntPtr CreateWindowEx( IntPtr lpParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern bool SetWindowText(IntPtr hwnd, String lpString); + public static extern bool SetWindowText(IntPtr hwnd, string lpString); public struct MSG { @@ -481,6 +469,18 @@ public struct MSG public POINT pt; } + [StructLayout(LayoutKind.Sequential)] + public struct PAINTSTRUCT + { + public IntPtr hdc; + public bool fErase; + public RECT rcPaint; + public bool fRestore; + public bool fIncUpdate; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] rgbReserved; + } + public struct POINT { public int X; diff --git a/Windows/Perspex.Win32/Properties/AssemblyInfo.cs b/Windows/Perspex.Win32/Properties/AssemblyInfo.cs index 16a3451f98e..bb40ce91d3c 100644 --- a/Windows/Perspex.Win32/Properties/AssemblyInfo.cs +++ b/Windows/Perspex.Win32/Properties/AssemblyInfo.cs @@ -1,4 +1,10 @@ -using System.Reflection; +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/Windows/Perspex.Win32/Win32Platform.cs b/Windows/Perspex.Win32/Win32Platform.cs index 34ea286e19e..99cbaf6ec79 100644 --- a/Windows/Perspex.Win32/Win32Platform.cs +++ b/Windows/Perspex.Win32/Win32Platform.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- diff --git a/Windows/Perspex.Win32/WindowImpl.cs b/Windows/Perspex.Win32/WindowImpl.cs index e850afb3b46..acf5926e39c 100644 --- a/Windows/Perspex.Win32/WindowImpl.cs +++ b/Windows/Perspex.Win32/WindowImpl.cs @@ -202,6 +202,7 @@ private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { this.Resized(new Size((int)lParam & 0xffff, (int)lParam >> 16)); } + return IntPtr.Zero; }