From 51c6465ec812248f6752ec15ad3f3e27f9e7d22b Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Jul 2013 18:44:03 +0200 Subject: [PATCH] Keep Quick Operation menu Size when zoomed... So thats it is also usable when zoomed out very wide... --- .../Project/Controls/QuickOperationMenu.cs | 227 ++++++++++-------- 1 file changed, 125 insertions(+), 102 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs index 6a06abc89f..686c4e646a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs @@ -6,6 +6,11 @@ using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Media; +using ICSharpCode.WpfDesign.Designer.Converters; +using System.Globalization; +using System.Windows.Data; + namespace ICSharpCode.WpfDesign.Designer.Controls { @@ -13,106 +18,124 @@ namespace ICSharpCode.WpfDesign.Designer.Controls /// A Small icon which shows up a menu containing common properties /// public class QuickOperationMenu : Control - { - static QuickOperationMenu() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof (QuickOperationMenu), new FrameworkPropertyMetadata(typeof (QuickOperationMenu))); - } - - private MenuItem _mainHeader; - - /// - /// Contains Default values in the Sub menu for example "HorizontalAlignment" has "HorizontalAlignment.Stretch" as it's value. - /// - private readonly Dictionary _defaults = new Dictionary(); - - /// - /// Is the main header menu which brings up all the menus. - /// - public MenuItem MainHeader { - get { return _mainHeader; } - } - - /// - /// Add a submenu with checkable values. - /// - /// The parent menu under which to add. - /// All the values of an enum to be showed in the menu - /// The default value out of all the enums. - /// The presently set value out of the enums - public void AddSubMenuCheckable(MenuItem parent, Array enumValues, string defaultValue, string setValue) - { - foreach (var enumValue in enumValues) { - var menuItem = new MenuItem {Header = enumValue.ToString(), IsCheckable = true}; - parent.Items.Add(menuItem); - if (enumValue.ToString() == defaultValue) - _defaults.Add(parent, menuItem); - if (enumValue.ToString() == setValue) - menuItem.IsChecked = true; - } - } - - /// - /// Add a menu in the main header. - /// - /// The menu to add. - public void AddSubMenuInTheHeader(MenuItem menuItem) - { - if (_mainHeader != null) - _mainHeader.Items.Add(menuItem); - } - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - var mainHeader = Template.FindName("MainHeader", this) as MenuItem; - if (mainHeader != null) { - _mainHeader = mainHeader; - } - } - - /// - /// Checks a menu item and making it exclusive. If the check was toggled then the default menu item is selected. - /// - /// The parent item of the sub menu - /// The Item clicked on - /// Returns the Default value if the checkable menu item is toggled or otherwise the new checked menu item. - public string UncheckChildrenAndSelectClicked(MenuItem parent, MenuItem clickedOn) - { - MenuItem defaultMenuItem; - _defaults.TryGetValue(parent, out defaultMenuItem); - if (IsAnyItemChecked(parent)) { - foreach (var item in parent.Items) { - var menuItem = item as MenuItem; - if (menuItem != null) menuItem.IsChecked = false; - } - clickedOn.IsChecked = true; - return (string) clickedOn.Header; - } else { - if (defaultMenuItem != null) { - defaultMenuItem.IsChecked = true; - return (string) defaultMenuItem.Header; - } - } - return null; - } - - /// - /// Checks in the sub-menu whether aby items has been checked or not - /// - /// - /// - private bool IsAnyItemChecked(MenuItem parent) - { - bool check = false; - if (parent.HasItems) { - foreach (var item in parent.Items) { - var menuItem = item as MenuItem; - if (menuItem != null && menuItem.IsChecked) - check = true; - } - } - return check; - } - } + { + static QuickOperationMenu() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof (QuickOperationMenu), new FrameworkPropertyMetadata(typeof (QuickOperationMenu))); + } + + public QuickOperationMenu() + { + scaleTransform = new ScaleTransform(1.0, 1.0); + this.LayoutTransform = scaleTransform; + } + + private ScaleTransform scaleTransform; + + private MenuItem _mainHeader; + + /// + /// Contains Default values in the Sub menu for example "HorizontalAlignment" has "HorizontalAlignment.Stretch" as it's value. + /// + private readonly Dictionary _defaults = new Dictionary(); + + /// + /// Is the main header menu which brings up all the menus. + /// + public MenuItem MainHeader { + get { return _mainHeader; } + } + + /// + /// Add a submenu with checkable values. + /// + /// The parent menu under which to add. + /// All the values of an enum to be showed in the menu + /// The default value out of all the enums. + /// The presently set value out of the enums + public void AddSubMenuCheckable(MenuItem parent, Array enumValues, string defaultValue, string setValue) + { + foreach (var enumValue in enumValues) { + var menuItem = new MenuItem {Header = enumValue.ToString(), IsCheckable = true}; + parent.Items.Add(menuItem); + if (enumValue.ToString() == defaultValue) + _defaults.Add(parent, menuItem); + if (enumValue.ToString() == setValue) + menuItem.IsChecked = true; + } + } + + /// + /// Add a menu in the main header. + /// + /// The menu to add. + public void AddSubMenuInTheHeader(MenuItem menuItem) + { + if (_mainHeader != null) + _mainHeader.Items.Add(menuItem); + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + var mainHeader = Template.FindName("MainHeader", this) as MenuItem; + if (mainHeader != null) { + _mainHeader = mainHeader; + } + + var surface = this.TryFindParent(); + if (surface != null && surface.ZoomControl != null) + { + var bnd = new Binding("CurrentZoom") { Source = surface.ZoomControl }; + bnd.Converter = InvertedZoomConverter.Instance; + + BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleXProperty, bnd); + BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleYProperty, bnd); + } + } + + /// + /// Checks a menu item and making it exclusive. If the check was toggled then the default menu item is selected. + /// + /// The parent item of the sub menu + /// The Item clicked on + /// Returns the Default value if the checkable menu item is toggled or otherwise the new checked menu item. + public string UncheckChildrenAndSelectClicked(MenuItem parent, MenuItem clickedOn) + { + MenuItem defaultMenuItem; + _defaults.TryGetValue(parent, out defaultMenuItem); + if (IsAnyItemChecked(parent)) { + foreach (var item in parent.Items) { + var menuItem = item as MenuItem; + if (menuItem != null) menuItem.IsChecked = false; + } + clickedOn.IsChecked = true; + return (string) clickedOn.Header; + } else { + if (defaultMenuItem != null) { + defaultMenuItem.IsChecked = true; + return (string) defaultMenuItem.Header; + } + } + return null; + } + + /// + /// Checks in the sub-menu whether aby items has been checked or not + /// + /// + /// + private bool IsAnyItemChecked(MenuItem parent) + { + bool check = false; + if (parent.HasItems) { + foreach (var item in parent.Items) { + var menuItem = item as MenuItem; + if (menuItem != null && menuItem.IsChecked) + check = true; + } + } + return check; + } + } }