Browse Source
Remove WPF designer's copy of NumericUpDown and ZoomControl and use SD.Widgets instead. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5659 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
29 changed files with 433 additions and 982 deletions
@ -1,309 +0,0 @@
@@ -1,309 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Ivan Shumilin"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Media.Imaging; |
||||
using System.Windows.Navigation; |
||||
using System.Windows.Shapes; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Globalization; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
public class NumericUpDown : Control |
||||
{ |
||||
static NumericUpDown() |
||||
{ |
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(typeof(NumericUpDown))); |
||||
} |
||||
|
||||
TextBox textBox; |
||||
DragRepeatButton upButton; |
||||
DragRepeatButton downButton; |
||||
|
||||
public static readonly DependencyProperty DecimalPlacesProperty = |
||||
DependencyProperty.Register("DecimalPlaces", typeof(int), typeof(NumericUpDown)); |
||||
|
||||
public int DecimalPlaces { |
||||
get { return (int)GetValue(DecimalPlacesProperty); } |
||||
set { SetValue(DecimalPlacesProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty MinimumProperty = |
||||
DependencyProperty.Register("Minimum", typeof(double), typeof(NumericUpDown)); |
||||
|
||||
public double Minimum { |
||||
get { return (double)GetValue(MinimumProperty); } |
||||
set { SetValue(MinimumProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty MaximumProperty = |
||||
DependencyProperty.Register("Maximum", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(100.0)); |
||||
|
||||
public double Maximum { |
||||
get { return (double)GetValue(MaximumProperty); } |
||||
set { SetValue(MaximumProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty ValueProperty = |
||||
DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); |
||||
|
||||
public double Value { |
||||
get { return (double)GetValue(ValueProperty); } |
||||
set { SetValue(ValueProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty SmallChangeProperty = |
||||
DependencyProperty.Register("SmallChange", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(1.0)); |
||||
|
||||
public double SmallChange { |
||||
get { return (double)GetValue(SmallChangeProperty); } |
||||
set { SetValue(SmallChangeProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty LargeChangeProperty = |
||||
DependencyProperty.Register("LargeChange", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(10.0)); |
||||
|
||||
public double LargeChange { |
||||
get { return (double)GetValue(LargeChangeProperty); } |
||||
set { SetValue(LargeChangeProperty, value); } |
||||
} |
||||
|
||||
bool IsDragging { |
||||
get { |
||||
return upButton.IsDragging; |
||||
} |
||||
set { |
||||
upButton.IsDragging = value; downButton.IsDragging = value; |
||||
} |
||||
} |
||||
|
||||
public override void OnApplyTemplate() |
||||
{ |
||||
base.OnApplyTemplate(); |
||||
|
||||
upButton = (DragRepeatButton)Template.FindName("PART_UpButton", this); |
||||
downButton = (DragRepeatButton)Template.FindName("PART_DownButton", this); |
||||
textBox = (TextBox)Template.FindName("PART_TextBox", this); |
||||
|
||||
upButton.Click += new RoutedEventHandler(upButton_Click); |
||||
downButton.Click += new RoutedEventHandler(downButton_Click); |
||||
|
||||
var upDrag = new DragListener(upButton); |
||||
var downDrag = new DragListener(downButton); |
||||
|
||||
upDrag.Started += drag_Started; |
||||
upDrag.Changed += drag_Changed; |
||||
upDrag.Completed += drag_Completed; |
||||
|
||||
downDrag.Started += drag_Started; |
||||
downDrag.Changed += drag_Changed; |
||||
downDrag.Completed += drag_Completed; |
||||
|
||||
Print(); |
||||
} |
||||
|
||||
void drag_Started(DragListener drag) |
||||
{ |
||||
OnDragStarted(); |
||||
} |
||||
|
||||
void drag_Changed(DragListener drag) |
||||
{ |
||||
IsDragging = true; |
||||
MoveValue(-drag.DeltaDelta.Y * SmallChange); |
||||
} |
||||
|
||||
void drag_Completed(DragListener drag) |
||||
{ |
||||
IsDragging = false; |
||||
OnDragCompleted(); |
||||
} |
||||
|
||||
void downButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
if (!IsDragging) SmallDown(); |
||||
} |
||||
|
||||
void upButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
if (!IsDragging) SmallUp(); |
||||
} |
||||
|
||||
protected virtual void OnDragStarted() |
||||
{ |
||||
} |
||||
|
||||
protected virtual void OnDragCompleted() |
||||
{ |
||||
} |
||||
|
||||
public void SmallUp() |
||||
{ |
||||
MoveValue(SmallChange); |
||||
} |
||||
|
||||
public void SmallDown() |
||||
{ |
||||
MoveValue(-SmallChange); |
||||
} |
||||
|
||||
public void LargeUp() |
||||
{ |
||||
MoveValue(LargeChange); |
||||
} |
||||
|
||||
public void LargeDown() |
||||
{ |
||||
MoveValue(-LargeChange); |
||||
} |
||||
|
||||
void MoveValue(double delta) |
||||
{ |
||||
double result; |
||||
if (double.IsNaN(Value) || double.IsInfinity(Value)) { |
||||
SetValue(delta); |
||||
} |
||||
else if (double.TryParse(textBox.Text, out result)) { |
||||
SetValue(result + delta); |
||||
} |
||||
else { |
||||
SetValue(Value + delta); |
||||
} |
||||
} |
||||
|
||||
void Print() |
||||
{ |
||||
if (textBox != null) { |
||||
textBox.Text = Value.ToString("F" + DecimalPlaces); |
||||
textBox.CaretIndex = int.MaxValue; |
||||
} |
||||
} |
||||
|
||||
//wpf bug?: Value = -1 updates bindings without coercing, workaround
|
||||
//update: not derived from RangeBase - no problem
|
||||
void SetValue(double newValue) |
||||
{ |
||||
newValue = CoerceValue(newValue); |
||||
if (Value != newValue) { |
||||
Value = newValue; |
||||
} |
||||
} |
||||
|
||||
double CoerceValue(double newValue) |
||||
{ |
||||
return Math.Max(Minimum, Math.Min(newValue, Maximum)); |
||||
} |
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e) |
||||
{ |
||||
base.OnPreviewKeyDown(e); |
||||
if (e.Key == Key.Enter) { |
||||
double result; |
||||
if (double.TryParse(textBox.Text, out result)) { |
||||
SetValue(result); |
||||
} |
||||
else { |
||||
Print(); |
||||
} |
||||
textBox.SelectAll(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.Up) { |
||||
SmallUp(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.Down) { |
||||
SmallDown(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.PageUp) { |
||||
LargeUp(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.PageDown) { |
||||
LargeDown(); |
||||
e.Handled = true; |
||||
} |
||||
//else if (e.Key == Key.Home) {
|
||||
// Maximize();
|
||||
// e.Handled = true;
|
||||
//}
|
||||
//else if (e.Key == Key.End) {
|
||||
// Minimize();
|
||||
// e.Handled = true;
|
||||
//}
|
||||
} |
||||
|
||||
//protected override void OnMouseWheel(MouseWheelEventArgs e)
|
||||
//{
|
||||
// if (e.Delta > 0)
|
||||
// {
|
||||
// if (Keyboard.IsKeyDown(Key.LeftShift))
|
||||
// {
|
||||
// LargeUp();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SmallUp();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (Keyboard.IsKeyDown(Key.LeftShift))
|
||||
// {
|
||||
// LargeDown();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SmallDown();
|
||||
// }
|
||||
// }
|
||||
// e.Handled = true;
|
||||
//}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
base.OnPropertyChanged(e); |
||||
|
||||
if (e.Property == ValueProperty) { |
||||
Value = CoerceValue((double)e.NewValue); |
||||
Print(); |
||||
} |
||||
else if (e.Property == SmallChangeProperty && |
||||
ReadLocalValue(LargeChangeProperty) == DependencyProperty.UnsetValue) { |
||||
LargeChange = SmallChange * 10; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class DragRepeatButton : RepeatButton |
||||
{ |
||||
public static readonly DependencyProperty IsDraggingProperty = |
||||
DependencyProperty.Register("IsDragging", typeof(bool), typeof(DragRepeatButton)); |
||||
|
||||
public bool IsDragging { |
||||
get { return (bool)GetValue(IsDraggingProperty); } |
||||
set { SetValue(IsDraggingProperty, value); } |
||||
} |
||||
} |
||||
} |
@ -1,149 +0,0 @@
@@ -1,149 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" |
||||
xmlns:BrushEditor="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor"> |
||||
|
||||
<!--<Brush x:Key="ButtonNormal">#C3D3FD</Brush> |
||||
<Brush x:Key="ButtonHover">#D7ECFC</Brush> |
||||
<Brush x:Key="ButtonPressed">#92AAF0</Brush> |
||||
<Brush x:Key="BorderBrush">#FF7F9DB9</Brush> |
||||
<Brush x:Key="ArrowBrush">#4D6185</Brush> |
||||
<Brush x:Key="ArrowsBorderBrush">#B4C8F6</Brush>--> |
||||
|
||||
<Brush x:Key="ButtonNormal">#DADFEA</Brush> |
||||
<Brush x:Key="ButtonHover">#E6EBEF</Brush> |
||||
<Brush x:Key="ButtonPressed">#B6BDD3</Brush> |
||||
<Brush x:Key="BorderBrush">#7F9DB9</Brush> |
||||
<Brush x:Key="ArrowBrush">Black</Brush> |
||||
<Brush x:Key="ArrowsBorderBrush">#B6BDD3</Brush> |
||||
|
||||
<Style x:Key="UpButton" |
||||
TargetType="RepeatButton"> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:DragRepeatButton}"> |
||||
<Border x:Name="bg" |
||||
Background="{StaticResource ButtonNormal}" |
||||
CornerRadius="2 2 0 0"> |
||||
<Path Fill="{StaticResource ArrowBrush}" |
||||
Data="M 0 3 L 3.5 0 L 7 3" |
||||
HorizontalAlignment="Center" |
||||
VerticalAlignment="Center" /> |
||||
</Border> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonHover}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsMouseCaptured" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsDragging" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style x:Key="DownButton" |
||||
TargetType="RepeatButton"> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:DragRepeatButton}"> |
||||
<Border x:Name="bg" |
||||
Background="{StaticResource ButtonNormal}" |
||||
CornerRadius="0 0 2 2"> |
||||
<Path Fill="{StaticResource ArrowBrush}" |
||||
Data="M 0 0 L 3.5 3 L 7 0" |
||||
HorizontalAlignment="Center" |
||||
VerticalAlignment="Center" /> |
||||
</Border> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonHover}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsMouseCaptured" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsDragging" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:NumericUpDown}"> |
||||
<Setter Property="Background" |
||||
Value="White" /> |
||||
<Setter Property="BorderThickness" |
||||
Value="1" /> |
||||
<Setter Property="BorderBrush" |
||||
Value="{StaticResource BorderBrush}" /> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:NumericUpDown}"> |
||||
<Border Background="{TemplateBinding Background}" |
||||
BorderBrush="{TemplateBinding BorderBrush}" |
||||
BorderThickness="{TemplateBinding BorderThickness}" |
||||
Padding="1"> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition /> |
||||
<RowDefinition /> |
||||
</Grid.RowDefinitions> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition /> |
||||
<ColumnDefinition Width="15" /> |
||||
</Grid.ColumnDefinitions> |
||||
<TextBox x:Name="PART_TextBox" |
||||
BorderThickness="0" |
||||
Background="{x:Null}" |
||||
Foreground="{TemplateBinding Foreground}" |
||||
Grid.RowSpan="2" /> |
||||
<Controls:DragRepeatButton x:Name="PART_UpButton" |
||||
Style="{StaticResource UpButton}" |
||||
Grid.Column="1" /> |
||||
<Controls:DragRepeatButton x:Name="PART_DownButton" |
||||
Style="{StaticResource DownButton}" |
||||
Grid.Column="1" |
||||
Grid.Row="1" /> |
||||
<Border Grid.Column="1" |
||||
Grid.RowSpan="2" |
||||
BorderBrush="{StaticResource ArrowsBorderBrush}" |
||||
BorderThickness="1" |
||||
CornerRadius="2" /> |
||||
</Grid> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
</ResourceDictionary> |
@ -1,9 +1,9 @@
@@ -1,9 +1,9 @@
|
||||
<Controls:NumericUpDown x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.NumberEditor" |
||||
<widgets:NumericUpDown x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.NumberEditor" |
||||
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" |
||||
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" |
||||
xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters" |
||||
BorderThickness="0" |
||||
Background="{x:Null}" |
||||
Value="{Binding Value, Converter={x:Static Converters:DummyConverter.Instance}}"> |
||||
</Controls:NumericUpDown> |
||||
</widgets:NumericUpDown> |
||||
|
Before Width: | Height: | Size: 635 B After Width: | Height: | Size: 635 B |
Before Width: | Height: | Size: 647 B After Width: | Height: | Size: 647 B |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:Controls="clr-namespace:ICSharpCode.Core.Presentation"> |
||||
xmlns:Controls="clr-namespace:ICSharpCode.SharpDevelop.Widgets"> |
||||
|
||||
<Brush x:Key="ButtonNormal">#DADFEA</Brush> |
||||
<Brush x:Key="ButtonHover">#E6EBEF</Brush> |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Widgets" |
||||
> |
||||
<ResourceDictionary.MergedDictionaries> |
||||
<ResourceDictionary Source="/ICSharpCode.SharpDevelop.Widgets;component/NumericUpDown.xaml" /> |
||||
<ResourceDictionary Source="/ICSharpCode.SharpDevelop.Widgets;component/ZoomScrollViewer.xaml" /> |
||||
</ResourceDictionary.MergedDictionaries> |
||||
|
||||
<!-- Template for CollapsiblePanel --> |
||||
<Style TargetType="{x:Type local:CollapsiblePanel}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="local:CollapsiblePanel"> |
||||
<ControlTemplate.Resources> |
||||
<local:CollapsiblePanelProgressToVisibilityConverter x:Key="visibilityConverter"/> |
||||
</ControlTemplate.Resources> |
||||
<Border |
||||
BorderThickness="{TemplateBinding Border.BorderThickness}" |
||||
BorderBrush="{TemplateBinding Border.BorderBrush}" |
||||
Background="{TemplateBinding Panel.Background}" |
||||
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" |
||||
Name="PART_Border" |
||||
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AnimationProgress, Converter={StaticResource visibilityConverter}}" |
||||
> |
||||
<Border.LayoutTransform> |
||||
<ScaleTransform ScaleX="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AnimationProgressX}" |
||||
ScaleY="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AnimationProgressY}"/> |
||||
</Border.LayoutTransform> |
||||
<ContentPresenter |
||||
Margin="{TemplateBinding Control.Padding}" |
||||
Content="{TemplateBinding ContentControl.Content}" |
||||
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" |
||||
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" |
||||
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" |
||||
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" |
||||
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</ResourceDictionary> |
Loading…
Reference in new issue