86 files changed
+1249
-311
No files matched your search
@@ -246,7 +246,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
for (int i = 0; i < itemsCount; i++)
|
||||
for (var i = 0; i < itemsCount; i++)
|
||||
{
|
||||
var row = (DataGridRow)generator.ContainerFromIndex(i);
|
||||
if (row != null)
|
||||
@@ -257,7 +257,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < itemsCount; i++)
|
||||
for (var i = 0; i < itemsCount; i++)
|
||||
{
|
||||
var row = (DataGridRow)generator.ContainerFromIndex(i);
|
||||
if (row != null)
|
||||
|
||||
@@ -333,7 +333,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
|
||||
var list = new List<bool>();
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
list.Add(false);
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace HandyControl.Controls
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
guids[i] = (Guid)ExternDllHelper.PtrToStructure((IntPtr)((long)buffer + size * i), typeof(Guid));
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ namespace HandyControl.Controls
|
||||
|
||||
public static readonly DependencyProperty DotCountProperty = DependencyProperty.Register(
|
||||
"DotCount", typeof(int), typeof(LoadingBase),
|
||||
new FrameworkPropertyMetadata(5, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
new FrameworkPropertyMetadata(ValueBoxes.Int5Box, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public static readonly DependencyProperty DotIntervalProperty = DependencyProperty.Register(
|
||||
"DotInterval", typeof(double), typeof(LoadingBase),
|
||||
new FrameworkPropertyMetadata(10.0, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
new FrameworkPropertyMetadata(ValueBoxes.Double10Box, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public static readonly DependencyProperty DotBorderBrushProperty = DependencyProperty.Register(
|
||||
"DotBorderBrush", typeof(Brush), typeof(LoadingBase),
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace HandyControl.Controls
|
||||
StretchProperty.AddOwner(typeof(AnimationPath), new FrameworkPropertyMetadata(Stretch.Uniform,
|
||||
OnPropertiesChanged));
|
||||
|
||||
StrokeThicknessProperty.AddOwner(typeof(AnimationPath), new FrameworkPropertyMetadata(1.0,
|
||||
StrokeThicknessProperty.AddOwner(typeof(AnimationPath), new FrameworkPropertyMetadata(ValueBoxes.Double1Box,
|
||||
OnPropertiesChanged));
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace HandyControl.Controls
|
||||
/// 最大页数
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty MaxPageCountProperty = DependencyProperty.Register(
|
||||
"MaxPageCount", typeof(int), typeof(Pagination), new PropertyMetadata(1, (o, args) =>
|
||||
"MaxPageCount", typeof(int), typeof(Pagination), new PropertyMetadata(ValueBoxes.Int1Box, (o, args) =>
|
||||
{
|
||||
if (o is Pagination pagination && args.NewValue is int value)
|
||||
{
|
||||
@@ -156,7 +156,7 @@ namespace HandyControl.Controls
|
||||
/// 当前页
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty PageIndexProperty = DependencyProperty.Register(
|
||||
"PageIndex", typeof(int), typeof(Pagination), new PropertyMetadata(1, (o, args) =>
|
||||
"PageIndex", typeof(int), typeof(Pagination), new PropertyMetadata(ValueBoxes.Int1Box, (o, args) =>
|
||||
{
|
||||
if (o is Pagination pagination && args.NewValue is int value)
|
||||
{
|
||||
@@ -312,7 +312,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
|
||||
var sub = PageIndex;
|
||||
for (int i = 0; i < MaxPageInterval - 1; i++)
|
||||
for (var i = 0; i < MaxPageInterval - 1; i++)
|
||||
{
|
||||
if (--sub > 1)
|
||||
{
|
||||
@@ -324,7 +324,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
}
|
||||
var add = PageIndex;
|
||||
for (int i = 0; i < MaxPageInterval - 1; i++)
|
||||
for (var i = 0; i < MaxPageInterval - 1; i++)
|
||||
{
|
||||
if (++add < MaxPageCount)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace HandyControl.Controls
|
||||
base.OnVisualChildrenChanged(visualAdded, visualRemoved);
|
||||
|
||||
var count = Items.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var item = (RadioButton)Items[i];
|
||||
item.Style = ItemStyleSelector?.SelectStyle(item, this);
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Tools.Converter;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class RelativePanel : Panel
|
||||
{
|
||||
public static readonly DependencyProperty AboveProperty = DependencyProperty.RegisterAttached(
|
||||
"Above", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAbove(DependencyObject element, DependencyObject value) => element.SetValue(AboveProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAbove(DependencyObject element) => (DependencyObject)element.GetValue(AboveProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignBottomWithProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignBottomWith", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAlignBottomWith(DependencyObject element, DependencyObject value) => element.SetValue(AlignBottomWithProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAlignBottomWith(DependencyObject element) => (DependencyObject)element.GetValue(AlignBottomWithProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignBottomWithPanelProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignBottomWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(default(bool)));
|
||||
|
||||
public static void SetAlignBottomWithPanel(DependencyObject element, bool value) => element.SetValue(AlignBottomWithPanelProperty, value);
|
||||
|
||||
public static bool GetAlignBottomWithPanel(DependencyObject element) => (bool)element.GetValue(AlignBottomWithPanelProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignHorizontalCenterWithProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignHorizontalCenterWith", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAlignHorizontalCenterWith(DependencyObject element, DependencyObject value) => element.SetValue(AlignHorizontalCenterWithProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAlignHorizontalCenterWith(DependencyObject element) => (DependencyObject)element.GetValue(AlignHorizontalCenterWithProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignHorizontalCenterWithPanelProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignHorizontalCenterWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(default(bool)));
|
||||
|
||||
public static void SetAlignHorizontalCenterWithPanel(DependencyObject element, bool value) => element.SetValue(AlignHorizontalCenterWithPanelProperty, value);
|
||||
|
||||
public static bool GetAlignHorizontalCenterWithPanel(DependencyObject element) => (bool)element.GetValue(AlignHorizontalCenterWithPanelProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignLeftWithProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignLeftWith", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAlignLeftWith(DependencyObject element, DependencyObject value) => element.SetValue(AlignLeftWithProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAlignLeftWith(DependencyObject element) => (DependencyObject)element.GetValue(AlignLeftWithProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignLeftWithPanelProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignLeftWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(default(bool)));
|
||||
|
||||
public static void SetAlignLeftWithPanel(DependencyObject element, bool value) => element.SetValue(AlignLeftWithPanelProperty, value);
|
||||
|
||||
public static bool GetAlignLeftWithPanel(DependencyObject element) => (bool)element.GetValue(AlignLeftWithPanelProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignRightWithProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignRightWith", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAlignRightWith(DependencyObject element, DependencyObject value) => element.SetValue(AlignRightWithProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAlignRightWith(DependencyObject element) => (DependencyObject)element.GetValue(AlignRightWithProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignRightWithPanelProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignRightWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(default(bool)));
|
||||
|
||||
public static void SetAlignRightWithPanel(DependencyObject element, bool value) => element.SetValue(AlignRightWithPanelProperty, value);
|
||||
|
||||
public static bool GetAlignRightWithPanel(DependencyObject element) => (bool)element.GetValue(AlignRightWithPanelProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignTopWithProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignTopWith", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAlignTopWith(DependencyObject element, DependencyObject value) => element.SetValue(AlignTopWithProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAlignTopWith(DependencyObject element) => (DependencyObject)element.GetValue(AlignTopWithProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignTopWithPanelProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignTopWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(default(bool)));
|
||||
|
||||
public static void SetAlignTopWithPanel(DependencyObject element, bool value) => element.SetValue(AlignTopWithPanelProperty, value);
|
||||
|
||||
public static bool GetAlignTopWithPanel(DependencyObject element) => (bool)element.GetValue(AlignTopWithPanelProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignVerticalCenterWithProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignVerticalCenterWith", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetAlignVerticalCenterWith(DependencyObject element, DependencyObject value) => element.SetValue(AlignVerticalCenterWithProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetAlignVerticalCenterWith(DependencyObject element) => (DependencyObject)element.GetValue(AlignVerticalCenterWithProperty);
|
||||
|
||||
public static readonly DependencyProperty AlignVerticalCenterWithPanelProperty = DependencyProperty.RegisterAttached(
|
||||
"AlignVerticalCenterWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(default(bool)));
|
||||
|
||||
public static void SetAlignVerticalCenterWithPanel(DependencyObject element, bool value) => element.SetValue(AlignVerticalCenterWithPanelProperty, value);
|
||||
|
||||
public static bool GetAlignVerticalCenterWithPanel(DependencyObject element) => (bool)element.GetValue(AlignVerticalCenterWithPanelProperty);
|
||||
|
||||
public static readonly DependencyProperty BelowProperty = DependencyProperty.RegisterAttached(
|
||||
"Below", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetBelow(DependencyObject element, DependencyObject value) => element.SetValue(BelowProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetBelow(DependencyObject element) => (DependencyObject)element.GetValue(BelowProperty);
|
||||
|
||||
public static readonly DependencyProperty LeftOfProperty = DependencyProperty.RegisterAttached(
|
||||
"LeftOf", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetLeftOf(DependencyObject element, DependencyObject value) => element.SetValue(LeftOfProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetLeftOf(DependencyObject element) => (DependencyObject)element.GetValue(LeftOfProperty);
|
||||
|
||||
public static readonly DependencyProperty RightOfProperty = DependencyProperty.RegisterAttached(
|
||||
"RightOf", typeof(DependencyObject), typeof(RelativePanel), new PropertyMetadata(default(DependencyObject)));
|
||||
|
||||
public static void SetRightOf(DependencyObject element, DependencyObject value) => element.SetValue(RightOfProperty, value);
|
||||
|
||||
[TypeConverter(typeof(NameReferenceConverter))]
|
||||
public static DependencyObject GetRightOf(DependencyObject element) => (DependencyObject)element.GetValue(RightOfProperty);
|
||||
}
|
||||
}
|
||||
@@ -353,7 +353,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
if (_visualChildren == null) return 0;
|
||||
|
||||
for (int i = 0; i < _visualChildren.Length; i++)
|
||||
for (var i = 0; i < _visualChildren.Length; i++)
|
||||
{
|
||||
if (_visualChildren[i] == null) return i;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace HandyControl.Controls
|
||||
var count = Items.Count;
|
||||
if (count <= 0) return;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
if (ItemContainerGenerator.ContainerFromIndex(i) is StepBarItem stepBarItem)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ namespace HandyControl.Controls
|
||||
|
||||
if (StepIndex < count)
|
||||
{
|
||||
for (int i = 0; i < StepIndex; i++)
|
||||
for (var i = 0; i < StepIndex; i++)
|
||||
{
|
||||
if (ItemContainerGenerator.ContainerFromIndex(i) is StepBarItem stepBarItem)
|
||||
{
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace HandyControl.Controls
|
||||
private void CreateItemsSource(ItemsControl selector, int count)
|
||||
{
|
||||
var list = new List<string>();
|
||||
for (int i = 0; i < count; i++)
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
list.Add(i.ToString("#00"));
|
||||
}
|
||||
|
||||
@@ -340,7 +340,10 @@ namespace HandyControl.Controls
|
||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(info.IconBrushKey);
|
||||
}
|
||||
|
||||
messageBox.Style = info.Style;
|
||||
if (info.Style != null)
|
||||
{
|
||||
messageBox.Style = info.Style;
|
||||
}
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
#else
|
||||
@@ -356,7 +359,10 @@ namespace HandyControl.Controls
|
||||
messageBox.ImageBrush = ResourceHelper.GetResource<Brush>(info.IconBrushKey);
|
||||
}
|
||||
|
||||
messageBox.Style = info.Style;
|
||||
if (info.Style != null)
|
||||
{
|
||||
messageBox.Style = info.Style;
|
||||
}
|
||||
SystemSounds.Asterisk.Play();
|
||||
messageBox.ShowDialog();
|
||||
});
|
||||
|
||||
@@ -9,7 +9,6 @@ using HandyControl.Tools.Extension;
|
||||
using Microsoft.Windows.Shell;
|
||||
#else
|
||||
using System.Windows.Shell;
|
||||
|
||||
#endif
|
||||
|
||||
namespace HandyControl.Controls
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Windows.Input;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal class KeyboardHookEventArgs : EventArgs
|
||||
public class KeyboardHookEventArgs : EventArgs
|
||||
{
|
||||
public bool IsSystemKey { get; }
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
namespace HandyControl_Shared.Data.Enum
|
||||
{
|
||||
public enum RelativeStatus
|
||||
{
|
||||
LeftOf,
|
||||
|
||||
Above,
|
||||
|
||||
RightOf,
|
||||
|
||||
Below,
|
||||
|
||||
AlignLeftWith,
|
||||
|
||||
AlignTopWith,
|
||||
|
||||
AlignRightWith,
|
||||
|
||||
AlignBottomWith,
|
||||
|
||||
AlignHorizontalCenterWith,
|
||||
|
||||
AlignVerticalCenterWith,
|
||||
|
||||
AlignLeftWithPanel,
|
||||
|
||||
AlignTopWithPanel,
|
||||
|
||||
AlignRightWithPanel,
|
||||
|
||||
AlignBottomWithPanel,
|
||||
|
||||
AlignHorizontalCenterWithPanel,
|
||||
|
||||
AlignVerticalCenterWithPanel
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace HandyControl.Data
|
||||
//
|
||||
var values = frameDelayItem.Value;
|
||||
_frameDelay = new int[FrameCount];
|
||||
for (int i = 0; i < FrameCount; ++i)
|
||||
for (var i = 0; i < FrameCount; ++i)
|
||||
{
|
||||
_frameDelay[i] = values[i * 4] + 256 * values[i * 4 + 1] + 256 * 256 * values[i * 4 + 2] + 256 * 256 * 256 * values[i * 4 + 3];
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace HandyControl.Expression.Drawing
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = list.Count - 1; i >= count; i--)
|
||||
for (var i = list.Count - 1; i >= count; i--)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ namespace HandyControl.Expression.Drawing
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = list.Count; i < count; i++)
|
||||
for (var i = list.Count; i < count; i++)
|
||||
{
|
||||
list.Add((factory == null) ? default(T) : factory());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Expression.Drawing;
|
||||
using HandyControl.Expression.Media;
|
||||
|
||||
@@ -16,7 +17,7 @@ namespace HandyControl.Expression.Shapes
|
||||
StretchProperty.OverrideMetadata(typeof(PrimitiveShape),
|
||||
new DrawingPropertyMetadata(Stretch.Fill, DrawingPropertyMetadataOptions.AffectsRender));
|
||||
StrokeThicknessProperty.OverrideMetadata(typeof(PrimitiveShape),
|
||||
new DrawingPropertyMetadata(1.0, DrawingPropertyMetadataOptions.AffectsRender));
|
||||
new DrawingPropertyMetadata(ValueBoxes.Double1Box, DrawingPropertyMetadataOptions.AffectsRender));
|
||||
}
|
||||
|
||||
protected sealed override Geometry DefiningGeometry =>
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\InfoElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PanelElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PasswordBoxAttach.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\RelativePanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\RelativeStatus.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\NameReferenceConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\FrameworkElementExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\StringExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\GlobalShortcut.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\StatusSwitchElement.cs" />
|
||||
@@ -273,6 +272,10 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\WNDCLASS.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\WpfSafeHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\MouseDragElementBehaviorEx.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\IPool!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SimplePool!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SynchronizedPool!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Queue\Deque!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularJudgment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularPatterns.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\RadioGroupItemStyleSelector.cs" />
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Border.xaml"/>
|
||||
<ResourceDictionary Source="Base/ToggleButtonBaseStyle.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@@ -101,6 +102,124 @@
|
||||
<!--开关-->
|
||||
<Style x:Key="ToggleButtonSwitch" BasedOn="{StaticResource ToggleButtonSwitchBaseStyle}" TargetType="ToggleButton"/>
|
||||
|
||||
<!--翻转-->
|
||||
<Style x:Key="ToggleButtonFlip" BasedOn="{StaticResource BaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Height" Value="30"/>
|
||||
<Setter Property="Width" Value="30"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<ControlTemplate.Resources>
|
||||
<Storyboard x:Key="StoryboardChecked">
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="CheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="UnCheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="CheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="UnCheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
<Storyboard x:Key="StoryboardUnChecked">
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="CheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="UnCheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="CheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="UnCheckedElement">
|
||||
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1">
|
||||
<EasingDoubleKeyFrame.EasingFunction>
|
||||
<PowerEase EasingMode="EaseOut"/>
|
||||
</EasingDoubleKeyFrame.EasingFunction>
|
||||
</EasingDoubleKeyFrame>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</ControlTemplate.Resources>
|
||||
<Viewbox>
|
||||
<controls:SimplePanel Height="28" Width="28">
|
||||
<Border Name="UnCheckedElement" Style="{StaticResource BorderClip}" RenderTransformOrigin="0.5,0.5" SnapsToDevicePixels="true" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
|
||||
<Border.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleX="1"/>
|
||||
</TransformGroup>
|
||||
</Border.RenderTransform>
|
||||
<ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Border>
|
||||
<Border Name="CheckedElement" Style="{StaticResource BorderClip}" RenderTransformOrigin="0.5,0.5" SnapsToDevicePixels="true" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
|
||||
<Border.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleX="0"/>
|
||||
</TransformGroup>
|
||||
</Border.RenderTransform>
|
||||
<ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{Binding Path=(controls:StatusSwitchElement.CheckedElement),RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
</Border>
|
||||
</controls:SimplePanel>
|
||||
</Viewbox>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Opacity" Value=".9"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Opacity" Value=".6"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="true">
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard Storyboard="{StaticResource StoryboardChecked}"/>
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<BeginStoryboard Storyboard="{StaticResource StoryboardUnChecked}"/>
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" Value="0.4"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!--自定义-->
|
||||
<Style x:Key="ToggleButtonCustom" BasedOn="{StaticResource BaseStyle}" TargetType="ToggleButton">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace HandyControl.Tools.Extension
|
||||
{
|
||||
public static class FrameworkElementExtension
|
||||
{
|
||||
|
||||
public static double GetValidWidth(this FrameworkElement element)
|
||||
{
|
||||
if (!double.IsNaN(element.Width))
|
||||
{
|
||||
if (element.Width > 0)
|
||||
{
|
||||
return element.Width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (element.ActualWidth > 0)
|
||||
{
|
||||
return element.ActualWidth;
|
||||
}
|
||||
|
||||
if (element.DesiredSize.Width > 0)
|
||||
{
|
||||
return element.DesiredSize.Width;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double GetValidHeight(this FrameworkElement element)
|
||||
{
|
||||
if (!double.IsNaN(element.Height))
|
||||
{
|
||||
if (element.Height > 0)
|
||||
{
|
||||
return element.Height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (element.ActualHeight > 0)
|
||||
{
|
||||
return element.ActualHeight;
|
||||
}
|
||||
|
||||
if (element.DesiredSize.Height > 0)
|
||||
{
|
||||
return element.DesiredSize.Height;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace HandyControl.Tools
|
||||
try
|
||||
{
|
||||
// Find the corresponding reference and remove it
|
||||
for (int i = 0; i < ImageInfoList.Count; i++)
|
||||
for (var i = 0; i < ImageInfoList.Count; i++)
|
||||
{
|
||||
var imageInfo = ImageInfoList[i];
|
||||
|
||||
|
||||
@@ -27,23 +27,23 @@ namespace HandyControl.Tools
|
||||
}
|
||||
|
||||
var index = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
for (int j = 0; j < 5; j++, index++)
|
||||
for (var j = 0; j < 5; j++, index++)
|
||||
{
|
||||
AddRec(i, j, renderData[index] == 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < 5; j++, index++)
|
||||
for (var j = 0; j < 5; j++, index++)
|
||||
{
|
||||
AddRec(2, j, renderData[index] == 0);
|
||||
}
|
||||
|
||||
index -= 10;
|
||||
for (int i = 3; i < 5; i++)
|
||||
for (var i = 3; i < 5; i++)
|
||||
{
|
||||
for (int j = 0; j < 5; j++, index++)
|
||||
for (var j = 0; j < 5; j++, index++)
|
||||
{
|
||||
AddRec(i, j, renderData[index] == 0);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ namespace HandyControl.Tools
|
||||
private int[] GetRenderData(string hashcode)
|
||||
{
|
||||
var arr = new int[RenderDataMaxLength];
|
||||
for (int i = 0; i < RenderDataMaxLength; i++)
|
||||
for (var i = 0; i < RenderDataMaxLength; i++)
|
||||
{
|
||||
var c = hashcode[i];
|
||||
var v = (int) c;
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace HandyControl.Tools
|
||||
var arr = new int[count];
|
||||
var div = num / count;
|
||||
var rest = num % count;
|
||||
for (int i = 0; i < count; i++)
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
arr[i] = div;
|
||||
}
|
||||
for (int i = 0; i < rest; i++)
|
||||
for (var i = 0; i < rest; i++)
|
||||
{
|
||||
arr[i] += 1;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace HandyControl.Tools
|
||||
|
||||
var isBitmapIconDecoder = frames[0].Decoder is IconBitmapDecoder;
|
||||
|
||||
for (int i = 0; i < frames.Count && bestScore != 0; ++i)
|
||||
for (var i = 0; i < frames.Count && bestScore != 0; ++i)
|
||||
{
|
||||
var currentIconBitDepth = isBitmapIconDecoder ? frames[i].Thumbnail.Format.BitsPerPixel : frames[i].Format.BitsPerPixel;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace HandyControl.Tools
|
||||
return t;
|
||||
}
|
||||
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(d, i);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
internal class KeyboardHook
|
||||
public class KeyboardHook
|
||||
{
|
||||
public static event EventHandler<KeyboardHookEventArgs> KeyDown;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
public interface IPool<T>
|
||||
{
|
||||
T Acquire();
|
||||
|
||||
bool Release(T instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//adapted from https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/util/Pools.java
|
||||
|
||||
using System;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
public class SimplePool<T> : IPool<T>
|
||||
{
|
||||
private readonly object[] _pool;
|
||||
|
||||
private int _poolSize;
|
||||
|
||||
public SimplePool(int maxPoolSize)
|
||||
{
|
||||
if (maxPoolSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("The max pool size must be > 0");
|
||||
}
|
||||
_pool = new object[maxPoolSize];
|
||||
}
|
||||
|
||||
public virtual T Acquire()
|
||||
{
|
||||
if (_poolSize > 0)
|
||||
{
|
||||
var lastPooledIndex = _poolSize - 1;
|
||||
var instance = (T)_pool[lastPooledIndex];
|
||||
_pool[lastPooledIndex] = null;
|
||||
_poolSize--;
|
||||
return instance;
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public virtual bool Release(T instance)
|
||||
{
|
||||
if (IsInPool(instance))
|
||||
{
|
||||
throw new Exception("Already in the pool!");
|
||||
}
|
||||
|
||||
if (_poolSize < _pool.Length)
|
||||
{
|
||||
_pool[_poolSize] = instance;
|
||||
_poolSize++;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsInPool(T instance)
|
||||
{
|
||||
for (var i = 0; i < _poolSize; i++)
|
||||
{
|
||||
if (Equals(_pool[i], instance))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
public class SynchronizedPool<T> : SimplePool<T>
|
||||
{
|
||||
private readonly object _lockObj = new object();
|
||||
|
||||
public SynchronizedPool(int maxPoolSize) : base(maxPoolSize)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override T Acquire()
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
return base.Acquire();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Release(T element)
|
||||
{
|
||||
lock (_lockObj) {
|
||||
return base.Release(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
// adapted from https://www.c-sharpcorner.com/uploadfile/b942f9/implementing-a-double-ended-queue-or-deque-in-c-sharp/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
[Serializable]
|
||||
public class Deque<T> : IEnumerable<T>, ICollection
|
||||
{
|
||||
[NonSerialized]
|
||||
private object _syncRoot;
|
||||
|
||||
private List<T> _front;
|
||||
|
||||
private List<T> _back;
|
||||
|
||||
private int _frontDeleted;
|
||||
|
||||
private int _backDeleted;
|
||||
|
||||
public int Capacity => _front.Capacity + _back.Capacity;
|
||||
|
||||
public int Count => _front.Count + _back.Count - _frontDeleted - _backDeleted;
|
||||
|
||||
public bool IsEmpty => Count == 0;
|
||||
|
||||
public IEnumerable<T> Reversed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_back.Count - _backDeleted > 0)
|
||||
{
|
||||
for (var i = _back.Count - 1; i >= _backDeleted; i--) yield return _back[i];
|
||||
}
|
||||
|
||||
if (_front.Count - _frontDeleted > 0)
|
||||
{
|
||||
for (var i = _frontDeleted; i < _front.Count; i++) yield return _front[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Deque()
|
||||
{
|
||||
_front = new List<T>();
|
||||
_back = new List<T>();
|
||||
}
|
||||
|
||||
public Deque(int capacity)
|
||||
{
|
||||
if (capacity < 0) throw new ArgumentException("Capacity cannot be negative");
|
||||
var temp = capacity / 2;
|
||||
var temp2 = capacity - temp;
|
||||
_front = new List<T>(temp);
|
||||
_back = new List<T>(temp2);
|
||||
}
|
||||
|
||||
public Deque(IEnumerable<T> backCollection) : this(backCollection, null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Deque(IEnumerable<T> backCollection, IEnumerable<T> frontCollection)
|
||||
{
|
||||
if (backCollection == null && frontCollection == null) throw new ArgumentException("Collections cannot both be null");
|
||||
_front = new List<T>();
|
||||
_back = new List<T>();
|
||||
|
||||
if (backCollection != null)
|
||||
{
|
||||
foreach (var item in backCollection) _back.Add(item);
|
||||
}
|
||||
|
||||
if (frontCollection != null)
|
||||
{
|
||||
foreach (var item in frontCollection) _front.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddFirst(T item)
|
||||
{
|
||||
if (_frontDeleted > 0 && _front.Count == _front.Capacity)
|
||||
{
|
||||
_front.RemoveRange(0, _frontDeleted);
|
||||
_frontDeleted = 0;
|
||||
}
|
||||
|
||||
_front.Add(item);
|
||||
}
|
||||
|
||||
public void AddLast(T item)
|
||||
{
|
||||
if (_backDeleted > 0 && _back.Count == _back.Capacity)
|
||||
{
|
||||
_back.RemoveRange(0, _backDeleted);
|
||||
_backDeleted = 0;
|
||||
}
|
||||
|
||||
_back.Add(item);
|
||||
}
|
||||
|
||||
public void AddRangeFirst(IEnumerable<T> range)
|
||||
{
|
||||
if (range == null) return;
|
||||
|
||||
foreach (var item in range) AddFirst(item);
|
||||
}
|
||||
|
||||
public void AddRangeLast(IEnumerable<T> range)
|
||||
{
|
||||
if (range == null) return;
|
||||
|
||||
foreach (var item in range) AddLast(item);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_front.Clear();
|
||||
_back.Clear();
|
||||
_frontDeleted = 0;
|
||||
_backDeleted = 0;
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
for (var i = _frontDeleted; i < _front.Count; i++)
|
||||
{
|
||||
if (Equals(_front[i], item)) return true;
|
||||
}
|
||||
|
||||
for (var i = _backDeleted; i < _back.Count; i++)
|
||||
{
|
||||
if (Equals(_back[i], item)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int index)
|
||||
{
|
||||
if (array == null) throw new ArgumentNullException("Array cannot be null");
|
||||
if (index < 0) throw new ArgumentOutOfRangeException("Index cannot be negative");
|
||||
if (array.Length < index + Count) throw new ArgumentException("Index is invalid");
|
||||
var i = index;
|
||||
|
||||
foreach (var item in this)
|
||||
{
|
||||
array[i++] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
if (_front.Count - _frontDeleted > 0)
|
||||
{
|
||||
for (var i = _front.Count - 1; i >= _frontDeleted; i--) yield return _front[i];
|
||||
}
|
||||
|
||||
if (_back.Count - _backDeleted > 0)
|
||||
{
|
||||
for (var i = _backDeleted; i < _back.Count; i++) yield return _back[i];
|
||||
}
|
||||
}
|
||||
|
||||
public T PeekFirst()
|
||||
{
|
||||
if (_front.Count > _frontDeleted)
|
||||
{
|
||||
return _front[_front.Count - 1];
|
||||
}
|
||||
|
||||
if (_back.Count > _backDeleted)
|
||||
{
|
||||
return _back[_backDeleted];
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Can't peek at empty Deque");
|
||||
}
|
||||
|
||||
public T PeekLast()
|
||||
{
|
||||
if (_back.Count > _backDeleted)
|
||||
{
|
||||
return _back[_back.Count - 1];
|
||||
}
|
||||
|
||||
if (_front.Count > _frontDeleted)
|
||||
{
|
||||
return _front[_frontDeleted];
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Can't peek at empty Deque");
|
||||
}
|
||||
|
||||
public T PopFirst()
|
||||
{
|
||||
T result;
|
||||
|
||||
if (_front.Count > _frontDeleted)
|
||||
{
|
||||
result = _front[_front.Count - 1];
|
||||
_front.RemoveAt(_front.Count - 1);
|
||||
}
|
||||
else if (_back.Count > _backDeleted)
|
||||
{
|
||||
result = _back[_backDeleted];
|
||||
_backDeleted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Can't pop empty Deque");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public T PopLast()
|
||||
{
|
||||
T result;
|
||||
|
||||
if (_back.Count > _backDeleted)
|
||||
{
|
||||
result = _back[_back.Count - 1];
|
||||
_back.RemoveAt(_back.Count - 1);
|
||||
}
|
||||
else if (_front.Count > _frontDeleted)
|
||||
{
|
||||
result = _front[_frontDeleted];
|
||||
_frontDeleted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Can't pop empty Deque");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Reverse()
|
||||
{
|
||||
var temp = _front;
|
||||
_front = _back;
|
||||
_back = temp;
|
||||
var temp2 = _frontDeleted;
|
||||
_frontDeleted = _backDeleted;
|
||||
_backDeleted = temp2;
|
||||
}
|
||||
|
||||
public T[] ToArray()
|
||||
{
|
||||
if (Count == 0) return new T[0];
|
||||
var result = new T[Count];
|
||||
CopyTo(result, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void TrimExcess()
|
||||
{
|
||||
if (_frontDeleted > 0)
|
||||
{
|
||||
_front.RemoveRange(0, _frontDeleted);
|
||||
_frontDeleted = 0;
|
||||
}
|
||||
|
||||
if (_backDeleted > 0)
|
||||
{
|
||||
_back.RemoveRange(0, _backDeleted);
|
||||
_backDeleted = 0;
|
||||
}
|
||||
|
||||
_front.TrimExcess();
|
||||
_back.TrimExcess();
|
||||
}
|
||||
|
||||
public bool TryPeekFirst(out T item)
|
||||
{
|
||||
if (!IsEmpty)
|
||||
{
|
||||
item = PeekFirst();
|
||||
return true;
|
||||
}
|
||||
|
||||
item = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryPeekLast(out T item)
|
||||
{
|
||||
if (!IsEmpty)
|
||||
{
|
||||
item = PeekLast();
|
||||
return true;
|
||||
}
|
||||
|
||||
item = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryPopFirst(out T item)
|
||||
{
|
||||
if (!IsEmpty)
|
||||
{
|
||||
item = PopFirst();
|
||||
return true;
|
||||
}
|
||||
|
||||
item = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryPopLast(out T item)
|
||||
{
|
||||
if (!IsEmpty)
|
||||
{
|
||||
item = PopLast();
|
||||
return true;
|
||||
}
|
||||
|
||||
item = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICollection.IsSynchronized => false;
|
||||
|
||||
object ICollection.SyncRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_syncRoot == null)
|
||||
{
|
||||
Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
|
||||
}
|
||||
return _syncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection.CopyTo(Array array, int index) => CopyTo((T[])array, index);
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user