From 58fb57ce24faa27731f52e2cef0c97961af594e0 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 30 Mar 2010 18:16:10 +0000 Subject: [PATCH] Move NumericUpDown and ZoomScrollViewer to SharpDevelop.Widgets. 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-cef0b8235c61 --- .../AvalonEdit.AddIn/themes/generic.xaml | 4 +- .../Project/Controls/ControlStyles.xaml | 74 --- .../Project/Controls/NumericUpDown.cs | 309 ------------ .../Project/Controls/NumericUpDown.xaml | 149 ------ .../Project/Controls/ZoomControl.cs | 188 +++----- .../Project/DesignSurface.xaml | 2 +- .../Project/DesignSurface.xaml.cs | 2 +- .../Editors/BrushEditor/BrushEditorView.xaml | 3 +- .../Editors/BrushEditor/ColorPicker.xaml | 447 +++++++++--------- .../PropertyGrid/Editors/NumberEditor.xaml | 6 +- .../Project/WpfDesign.Designer.csproj | 12 +- .../Misc/StartPage/Project/StartPage.csproj | 3 +- .../StartPageMessage.xaml | 14 +- .../UsageDataCollector.AddIn.csproj | 5 + .../IDEOptions/ProjectAndSolutionOptions.xaml | 3 +- .../ICSharpCode.Core.Presentation.csproj | 21 - .../themes/generic.xaml | 39 -- .../Project}/CollapsiblePanel.cs | 2 +- .../Project/Configuration/AssemblyInfo.cs | 10 + .../Project}/DragListener.cs | 2 +- .../ICSharpCode.SharpDevelop.Widgets.csproj | 34 ++ .../Project}/Images/ZoomIn.png | Bin .../Project}/Images/ZoomOut.png | Bin .../Project}/NumericUpDown.cs | 2 +- .../Project}/NumericUpDown.xaml | 2 +- .../Project}/ZoomButtons.cs | 2 +- .../Project}/ZoomScrollViewer.cs | 33 +- .../Project}/ZoomScrollViewer.xaml | 4 +- .../Project/themes/generic.xaml | 43 ++ 29 files changed, 433 insertions(+), 982 deletions(-) delete mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NumericUpDown.cs delete mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NumericUpDown.xaml rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/CollapsiblePanel.cs (99%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/DragListener.cs (98%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/Images/ZoomIn.png (100%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/Images/ZoomOut.png (100%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/NumericUpDown.cs (99%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/NumericUpDown.xaml (98%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/ZoomButtons.cs (97%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/ZoomScrollViewer.cs (78%) rename src/Main/{ICSharpCode.Core.Presentation => ICSharpCode.SharpDevelop.Widgets/Project}/ZoomScrollViewer.xaml (94%) create mode 100644 src/Main/ICSharpCode.SharpDevelop.Widgets/Project/themes/generic.xaml diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/themes/generic.xaml b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/themes/generic.xaml index 4a0721a5fe..6721aaa770 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/themes/generic.xaml +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/themes/generic.xaml @@ -1,14 +1,14 @@  - - - - - - - - - diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs index f6187ed91c..d3891f2745 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs @@ -6,202 +6,122 @@ // 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.IO; using System.Reflection; using System.Resources; +using System.Windows; +using System.Windows.Input; + +using ICSharpCode.SharpDevelop.Widgets; namespace ICSharpCode.WpfDesign.Designer.Controls { - public class ZoomControl : ContentControl + public class ZoomControl : ZoomScrollViewer { static ZoomControl() { - DefaultStyleKeyProperty.OverrideMetadata(typeof(ZoomControl), - new FrameworkPropertyMetadata(typeof(ZoomControl))); - - PanToolCursor = new Cursor(GetStream("Images/PanToolCursor.cur")); - PanToolCursorMouseDown = new Cursor(GetStream("Images/PanToolCursorMouseDown.cur")); + PanToolCursor = GetCursor("Images/PanToolCursor.cur"); + PanToolCursorMouseDown = GetCursor("Images/PanToolCursorMouseDown.cur"); } - - static Stream GetStream(string path) + + static Cursor GetCursor(string path) { var a = Assembly.GetExecutingAssembly(); var m = new ResourceManager(a.GetName().Name + ".g", a); - var s = m.GetStream(path.ToLower()); - return s; + using (Stream s = m.GetStream(path.ToLowerInvariant())) { + return new Cursor(s); + } } static Cursor PanToolCursor; static Cursor PanToolCursorMouseDown; - public const double ZoomFactor = 1.1; - public const double Minimum = 0.1; - public const double Maximum = 10; - + double startHorizontalOffset; double startVericalOffset; - - internal ScrollViewer ScrollViewer; - FrameworkElement container; - ScaleTransform transform; Point startPoint; bool isMouseDown; bool pan; - public static readonly DependencyProperty ZoomProperty = - DependencyProperty.Register("Zoom", typeof(double), typeof(ZoomControl), - new PropertyMetadata(1.0, null, CoerceZoom)); - - public double Zoom - { - get { return (double)GetValue(ZoomProperty); } - set { SetValue(ZoomProperty, value); } - } - - static object CoerceZoom(DependencyObject d, object baseValue) - { - var zoom = (double)baseValue; - return Math.Max(Minimum, Math.Min(Maximum, zoom)); - } - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - ScrollViewer = (ScrollViewer)Template.FindName("scrollViewer", this); - container = (FrameworkElement)Template.FindName("container", this); - transform = new ScaleTransform(); - container.LayoutTransform = transform; - - var uxPlus = (ButtonBase)Template.FindName("uxPlus", this); - var uxMinus = (ButtonBase)Template.FindName("uxMinus", this); - var uxReset = (ButtonBase)Template.FindName("uxReset", this); - - uxPlus.Click += delegate { ZoomIn(); }; - uxMinus.Click += delegate { ZoomOut(); }; - uxReset.Click += delegate { Reset(); }; - } - - protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) - { - base.OnPropertyChanged(e); - if (e.Property == ZoomProperty) - { - transform.ScaleX = Zoom; - transform.ScaleY = Zoom; - CenterViewport((double)e.OldValue); - } - } - protected override void OnKeyDown(KeyEventArgs e) { - if (!pan && e.Key == Key.Space) - { - Cursor = PanToolCursor; + if (!pan && e.Key == Key.Space) { pan = true; + Mouse.UpdateCursor(); } + base.OnKeyDown(e); } protected override void OnKeyUp(KeyEventArgs e) { - if (e.Key == Key.Space) - { - ClearValue(CursorProperty); + if (e.Key == Key.Space) { pan = false; + Mouse.UpdateCursor(); } + base.OnKeyUp(e); } protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { - if (pan) - { - Cursor = PanToolCursorMouseDown; - Mouse.Capture(this); // will call move - isMouseDown = true; - startPoint = e.GetPosition(this); - PanStart(); + if (pan && !e.Handled) { + if (Mouse.Capture(this)) { + isMouseDown = true; + e.Handled = true; + startPoint = e.GetPosition(this); + PanStart(); + Mouse.UpdateCursor(); + } } + base.OnPreviewMouseDown(e); } protected override void OnPreviewMouseMove(MouseEventArgs e) { - if (isMouseDown && pan) - { + if (isMouseDown) { var endPoint = e.GetPosition(this); PanContinue(endPoint - startPoint); } + base.OnPreviewMouseMove(e); } protected override void OnPreviewMouseUp(MouseButtonEventArgs e) { - if (isMouseDown) - { - Cursor = PanToolCursor; + if (isMouseDown) { isMouseDown = false; - Mouse.Capture(null); + ReleaseMouseCapture(); + Mouse.UpdateCursor(); } + base.OnPreviewMouseUp(e); } - - protected override void OnMouseEnter(MouseEventArgs e) - { - Focus(); - } - - public void Fit() - { - Zoom = Math.Min( - ScrollViewer.ActualWidth / container.ActualWidth, - ScrollViewer.ActualHeight / container.ActualHeight); - } - - public void ZoomIn() - { - Zoom *= ZoomFactor; - } - - public void ZoomOut() + + protected override void OnLostMouseCapture(MouseEventArgs e) { - Zoom /= ZoomFactor; + if (isMouseDown) { + isMouseDown = false; + ReleaseMouseCapture(); + Mouse.UpdateCursor(); + } + base.OnLostMouseCapture(e); } - - public void Reset() + + protected override void OnQueryCursor(QueryCursorEventArgs e) { - Zoom = 1; - ScrollViewer.ScrollToHorizontalOffset(0); - ScrollViewer.ScrollToVerticalOffset(0); + base.OnQueryCursor(e); + if (!e.Handled && (pan || isMouseDown)) { + e.Handled = true; + e.Cursor = isMouseDown ? PanToolCursorMouseDown : PanToolCursor; + } } - + void PanStart() { - startHorizontalOffset = ScrollViewer.HorizontalOffset; - startVericalOffset = ScrollViewer.VerticalOffset; + startHorizontalOffset = this.HorizontalOffset; + startVericalOffset = this.VerticalOffset; } void PanContinue(Vector delta) { - ScrollViewer.ScrollToHorizontalOffset(startHorizontalOffset - delta.X); - ScrollViewer.ScrollToVerticalOffset(startVericalOffset - delta.Y); - } - - void CenterViewport(double oldZoom) - { - var k = Zoom / oldZoom; - var add = (k * ScrollViewer.ViewportWidth - ScrollViewer.ViewportWidth) / 2; - ScrollViewer.ScrollToHorizontalOffset(k * ScrollViewer.HorizontalOffset + add); - add = (k * ScrollViewer.ViewportHeight - ScrollViewer.ViewportHeight) / 2; - ScrollViewer.ScrollToVerticalOffset(k * ScrollViewer.VerticalOffset + add); + this.ScrollToHorizontalOffset(startHorizontalOffset - delta.X / this.CurrentZoom); + this.ScrollToVerticalOffset(startVericalOffset - delta.Y / this.CurrentZoom); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml index c00011da22..0e5779abb0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml @@ -5,7 +5,7 @@ xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" DataContext="{x:Null}" Background="#888"> - + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs index 681c14fa16..3d164e670d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs @@ -63,7 +63,7 @@ namespace ICSharpCode.WpfDesign.Designer protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { - if (e.OriginalSource == uxZoom.ScrollViewer) { + if (e.OriginalSource == uxZoom) { UnselectAll(); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml index 8286f1060a..2d89ae00a2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml @@ -6,6 +6,7 @@ xmlns:BrushEditor="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor" xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters" xmlns:PropertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid" + xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" Width="395"> @@ -51,7 +52,7 @@ Margin="5"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml index 3d201d21e4..2568a09dee 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml @@ -1,9 +1,9 @@ - - + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 7823c3e45e..2ed0a3b620 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -92,9 +92,6 @@ GridUnitSelector.xaml Code - - NumericUpDown.xaml - @@ -217,6 +214,11 @@ + + {8035765F-D51F-4A0C-A746-2FD100E19419} + ICSharpCode.SharpDevelop.Widgets + False + {88DA149F-21B2-48AB-82C4-28FB6BDFD783} WpfDesign.XamlDom @@ -233,10 +235,6 @@ Designer - - MSBuild:Compile - Designer - Designer diff --git a/src/AddIns/Misc/StartPage/Project/StartPage.csproj b/src/AddIns/Misc/StartPage/Project/StartPage.csproj index 07e2d7c750..582dbc9107 100644 --- a/src/AddIns/Misc/StartPage/Project/StartPage.csproj +++ b/src/AddIns/Misc/StartPage/Project/StartPage.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU diff --git a/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/StartPageMessage.xaml b/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/StartPageMessage.xaml index 6cf5a6f01c..22c946121d 100644 --- a/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/StartPageMessage.xaml +++ b/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/StartPageMessage.xaml @@ -1,8 +1,8 @@  + x:Class="ICSharpCode.UsageDataCollector.StartPageMessage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:local="clr-namespace:ICSharpCode.UsageDataCollector" xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"> - - - + - - + - + ICSharpCode.Core.Presentation False + + {8035765F-D51F-4A0C-A746-2FD100E19419} + ICSharpCode.SharpDevelop.Widgets + False + {6B1CFE35-DA17-4DEB-9C6E-227E5E251DA0} UsageDataCollector diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/ProjectAndSolutionOptions.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/ProjectAndSolutionOptions.xaml index 3abc057693..6105f6ec08 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/ProjectAndSolutionOptions.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/ProjectAndSolutionOptions.xaml @@ -1,6 +1,7 @@  - + - - - NumericUpDown.xaml - - @@ -103,30 +98,14 @@ - - ZoomScrollViewer.xaml - - - ZoomScrollViewer.xaml - Code - - {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} ICSharpCode.Core False - - MSBuild:Compile - Designer - - - - - \ No newline at end of file diff --git a/src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml b/src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml index 5e2997b9ac..b4262f4fe3 100644 --- a/src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml +++ b/src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml @@ -2,11 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ICSharpCode.Core.Presentation" > - - - - - - - - + \ No newline at end of file