Example #1
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code 
        /// or internal processes call System.Windows.FrameworkElement.ApplyTemplate().
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Clear cache
            cachedMeasures.Clear();

            if (LauncherButton != null) LauncherButton.Click -= OnDialogLauncherButtonClick;
            LauncherButton = GetTemplateChild("PART_DialogLauncherButton") as Button;
            if (LauncherButton != null)
            {
                LauncherButton.Click += OnDialogLauncherButtonClick;
                if (LauncherKeys != null)
                    KeyTip.SetKeys(LauncherButton, LauncherKeys);
            }

            popup = GetTemplateChild("PART_Popup") as Popup;
            if (popup != null)
            {
                Binding binding = new Binding("IsOpen");
                binding.Mode = BindingMode.TwoWay;
                binding.Source = this;
                popup.SetBinding(Popup.IsOpenProperty, binding);
            }

            downGrid = GetTemplateChild("PART_DownGrid") as Grid;
            upPanel = GetTemplateChild("PART_UpPanel") as Panel;
            parentPanel = GetTemplateChild("PART_ParentPanel") as Panel;
        }
Example #2
0
        void Show()
        {
            // Check whether the window is still active
            // (it prevent keytips showing during Alt-Tab'ing)
            if (!window.IsActive)
            {
                RestoreFocuses();
                return;
            }

            activeAdornerChain             = new KeyTipAdorner(ribbon, ribbon, null);
            activeAdornerChain.Terminated += OnAdornerChainTerminated;

            // Special behavior for backstage
            Backstage backstage = ribbon.Menu as Backstage;

            if (backstage != null && backstage.IsOpen)
            {
                string keys = KeyTip.GetKeys(backstage);
                if (!String.IsNullOrEmpty(keys))
                {
                    activeAdornerChain.Forward(KeyTip.GetKeys(backstage), false);
                }
                else
                {
                    activeAdornerChain.Attach();
                }
            }
            else
            {
                activeAdornerChain.Attach();
            }
        }
Example #3
0
        // Find key tips on the given element
        private void FindKeyTips(FrameworkElement element, bool hide)
        {
            var children = GetVisibleChildren(element);

            foreach (var child in children)
            {
                var groupBox = child as RibbonGroupBox;

                var keys = KeyTip.GetKeys(child);
                if (keys != null)
                {
                    if (groupBox != null)
                    {
                        this.GenerateAndAddGroupBoxKeyTipInformation(hide, keys, child, groupBox);
                    }
                    else
                    {
                        this.GenerateAndAddRegularKeyTipInformations(keys, child, hide);

                        // Do not search deeper in the tree
                        continue;
                    }
                }

                var innerHide = hide || groupBox?.State == RibbonGroupBoxState.Collapsed;
                this.FindKeyTips(child, innerHide);
            }
        }
Example #4
0
        private void Show()
        {
            // Check whether the window is still active
            // (it prevent keytips showing during Alt-Tab'ing)
            if (!this.window.IsActive)
            {
                this.RestoreFocuses();
                return;
            }

            this.currentUserInput = string.Empty;

            this.activeAdornerChain             = new KeyTipAdorner(this.ribbon, this.ribbon, null);
            this.activeAdornerChain.Terminated += this.OnAdornerChainTerminated;

            // Special behavior for backstage
            var backstage = this.ribbon.Menu as Backstage;

            if (backstage != null && backstage.IsOpen)
            {
                var keys = KeyTip.GetKeys(backstage);
                if (!String.IsNullOrEmpty(keys))
                {
                    this.activeAdornerChain.Forward(KeyTip.GetKeys(backstage), false);
                }
                else
                {
                    this.activeAdornerChain.Attach();
                }
            }
            else
            {
                this.activeAdornerChain.Attach();
            }
        }
Example #5
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code
        /// or internal processes call System.Windows.FrameworkElement.ApplyTemplate().
        /// </summary>
        public override void OnApplyTemplate()
        {
            this.UnSubscribeEvents();

            // Clear cache
            cachedMeasures.Clear();

            LauncherButton = GetTemplateChild("PART_DialogLauncherButton") as Button;

            if (LauncherButton != null)
            {
                if (LauncherKeys != null)
                {
                    KeyTip.SetKeys(LauncherButton, LauncherKeys);
                }
            }

            popup = GetTemplateChild("PART_Popup") as Popup;

            downGrid    = GetTemplateChild("PART_DownGrid") as Grid;
            upPanel     = GetTemplateChild("PART_UpPanel") as Panel;
            parentPanel = GetTemplateChild("PART_ParentPanel") as Panel;

            snappedImage = GetTemplateChild("PART_SnappedImage") as Image;

            this.SubscribeEvents();
        }
Example #6
0
 static void OnDialogLauncherButtonKeyTipKeysChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     RibbonGroupBox ribbonGroupBox = (RibbonGroupBox)d;
     if (ribbonGroupBox.LauncherButton != null)
     {
         KeyTip.SetKeys(ribbonGroupBox.LauncherButton, (string)e.NewValue);
     }
 }
Example #7
0
        private void DirectlyForwardToSpecialControl(DependencyObject specialControl)
        {
            var keys = KeyTip.GetKeys(specialControl);

            if (string.IsNullOrEmpty(keys) == false)
            {
                this.activeAdornerChain.Forward(keys, false);
            }
            else
            {
                this.activeAdornerChain.Attach();
            }
        }
        // Updates keys for keytip access
        void UpdateKeyTips()
        {
            for (int i = 0; i < Math.Min(9, Items.Count); i++)
            {
                // 1, 2, 3, ... , 9
                KeyTip.SetKeys(Items[i], (i + 1).ToString(CultureInfo.InvariantCulture));
            }
            for (int i = 9; i < Math.Min(18, Items.Count); i++)
            {
                // 09, 08, 07, ... , 01
                KeyTip.SetKeys(Items[i], "0" + (18 - i).ToString(CultureInfo.InvariantCulture));
            }
            char startChar = 'A';

            for (int i = 18; i < Math.Min(9 + 9 + 26, Items.Count); i++)
            {
                // 0A, 0B, 0C, ... , 0Z
                KeyTip.SetKeys(Items[i], "0" + startChar++);
            }
        }
Example #9
0
        // Updates keys for keytip access
        private static void DefaultUpdateKeyTips(QuickAccessToolBar quickAccessToolBar)
        {
            for (var i = 0; i < Math.Min(9, quickAccessToolBar.Items.Count); i++)
            {
                // 1, 2, 3, ... , 9
                KeyTip.SetKeys(quickAccessToolBar.Items[i], (i + 1).ToString(CultureInfo.InvariantCulture));
            }

            for (var i = 9; i < Math.Min(18, quickAccessToolBar.Items.Count); i++)
            {
                // 09, 08, 07, ... , 01
                KeyTip.SetKeys(quickAccessToolBar.Items[i], "0" + (18 - i).ToString(CultureInfo.InvariantCulture));
            }

            var startChar = 'A';

            for (var i = 18; i < Math.Min(9 + 9 + 26, quickAccessToolBar.Items.Count); i++)
            {
                // 0A, 0B, 0C, ... , 0Z
                KeyTip.SetKeys(quickAccessToolBar.Items[i], "0" + startChar++);
            }
        }
Example #10
0
        private void UpdateKeyTipPositions()
        {
            this.Log("UpdateKeyTipPositions");

            if (this.keyTips.Count == 0)
            {
                return;
            }

            double[] rows     = null;
            var      groupBox = GetGroupBox(this.oneOfAssociatedElements);

            if (groupBox != null)
            {
                var panel = groupBox.GetPanel();
                if (panel != null)
                {
                    var height = groupBox.GetLayoutRoot().DesiredSize.Height;
                    rows = new[]
                    {
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, 0), this.AdornedElement).Y,
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height / 2.0), this.AdornedElement).Y,
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height), this.AdornedElement).Y,
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, height + 1), this.AdornedElement).Y
                    };
                }
            }

            for (var i = 0; i < this.keyTips.Count; i++)
            {
                // Skip invisible keytips
                if (this.keyTips[i].Visibility != Visibility.Visible)
                {
                    continue;
                }

                // Update KeyTip Visibility
                var associatedElementIsVisible    = this.associatedElements[i].IsVisible;
                var associatedElementInVisualTree = VisualTreeHelper.GetParent(this.associatedElements[i]) != null;
                this.keyTips[i].Visibility = associatedElementIsVisible && associatedElementInVisualTree ? Visibility.Visible : Visibility.Collapsed;

                if (!KeyTip.GetAutoPlacement(this.associatedElements[i]))
                {
                    #region Custom Placement

                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].RenderSize;

                    double x = 0, y = 0;
                    var    margin = KeyTip.GetMargin(this.associatedElements[i]);

                    switch (KeyTip.GetHorizontalAlignment(this.associatedElements[i]))
                    {
                    case HorizontalAlignment.Left:
                        x = margin.Left;
                        break;

                    case HorizontalAlignment.Right:
                        x = elementSize.Width - keyTipSize.Width - margin.Right;
                        break;

                    case HorizontalAlignment.Center:
                    case HorizontalAlignment.Stretch:
                        x = elementSize.Width / 2.0 - keyTipSize.Width / 2.0 + margin.Left;
                        break;
                    }

                    switch (KeyTip.GetVerticalAlignment(this.associatedElements[i]))
                    {
                    case VerticalAlignment.Top:
                        y = margin.Top;
                        break;

                    case VerticalAlignment.Bottom:
                        y = elementSize.Height - keyTipSize.Height - margin.Bottom;
                        break;

                    case VerticalAlignment.Center:
                    case VerticalAlignment.Stretch:
                        y = elementSize.Height / 2.0 - keyTipSize.Height / 2.0 + margin.Top;
                        break;
                    }

                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point(x, y), this.AdornedElement);

                    #endregion
                }
                else if (((FrameworkElement)this.associatedElements[i]).Name == "PART_DialogLauncherButton")
                {
                    // Dialog Launcher Button Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].RenderSize;
                    if (rows == null)
                    {
                        continue;
                    }

                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point(
                                                                                            elementSize.Width / 2.0 - keyTipSize.Width / 2.0,
                                                                                            0), this.AdornedElement);
                    this.keyTipPositions[i].Y = rows[3];
                }
                else if ((this.associatedElements[i] is InRibbonGallery && !((InRibbonGallery)this.associatedElements[i]).IsCollapsed))
                {
                    // InRibbonGallery Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].RenderSize;
                    if (rows == null)
                    {
                        continue;
                    }

                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point(
                                                                                            elementSize.Width - keyTipSize.Width / 2.0,
                                                                                            0), this.AdornedElement);
                    this.keyTipPositions[i].Y = rows[2] - keyTipSize.Height / 2;
                }
                else if ((this.associatedElements[i] is RibbonTabItem) || (this.associatedElements[i] is Backstage))
                {
                    // Ribbon Tab Item Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].RenderSize;
                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point(
                                                                                            elementSize.Width / 2.0 - keyTipSize.Width / 2.0,
                                                                                            elementSize.Height - keyTipSize.Height / 2.0), this.AdornedElement);
                }
                else if (this.associatedElements[i] is RibbonGroupBox)
                {
                    // Ribbon Group Box Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].DesiredSize;
                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point(
                                                                                            elementSize.Width / 2.0 - keyTipSize.Width / 2.0,
                                                                                            elementSize.Height + 1), this.AdornedElement);
                }
                else if (IsWithinQuickAccessToolbar(this.associatedElements[i]))
                {
                    var translatedPoint = this.associatedElements[i].TranslatePoint(new Point(this.associatedElements[i].DesiredSize.Width / 2.0 - this.keyTips[i].DesiredSize.Width / 2.0, this.associatedElements[i].DesiredSize.Height - this.keyTips[i].DesiredSize.Height / 2.0), this.AdornedElement);
                    this.keyTipPositions[i] = translatedPoint;
                }
                else if (this.associatedElements[i] is MenuItem)
                {
                    // MenuItem Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].DesiredSize;
                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(
                        new Point(
                            elementSize.Height / 2.0 + 2,
                            elementSize.Height / 2.0 + 2), this.AdornedElement);
                }
                else if (this.associatedElements[i] is BackstageTabItem)
                {
                    // BackstageButton Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].DesiredSize;
                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(
                        new Point(
                            5,
                            elementSize.Height / 2.0 - keyTipSize.Height), this.AdornedElement);
                }
                else if (((FrameworkElement)this.associatedElements[i]).Parent is BackstageTabControl)
                {
                    // Backstage Items Exclusive Placement
                    var keyTipSize  = this.keyTips[i].DesiredSize;
                    var elementSize = this.associatedElements[i].DesiredSize;
                    this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(
                        new Point(
                            20,
                            elementSize.Height / 2.0 - keyTipSize.Height), this.AdornedElement);
                }
                else
                {
                    if ((RibbonProperties.GetSize(this.associatedElements[i]) != RibbonControlSize.Large) ||
                        (this.associatedElements[i] is Spinner) ||
                        (this.associatedElements[i] is ComboBox) ||
                        (this.associatedElements[i] is TextBox) ||
                        (this.associatedElements[i] is CheckBox))
                    {
                        var withinRibbonToolbar = IsWithinRibbonToolbarInTwoLine(this.associatedElements[i]);
                        var translatedPoint     = this.associatedElements[i].TranslatePoint(new Point(this.keyTips[i].DesiredSize.Width / 2.0, this.keyTips[i].DesiredSize.Height / 2.0), this.AdornedElement);

                        // Snapping to rows if it present
                        if (rows != null)
                        {
                            var index       = 0;
                            var mindistance = Math.Abs(rows[0] - translatedPoint.Y);
                            for (var j = 1; j < rows.Length; j++)
                            {
                                if (withinRibbonToolbar && j == 1)
                                {
                                    continue;
                                }

                                var distance = Math.Abs(rows[j] - translatedPoint.Y);
                                if (distance < mindistance)
                                {
                                    mindistance = distance;
                                    index       = j;
                                }
                            }

                            translatedPoint.Y = rows[index] - this.keyTips[i].DesiredSize.Height / 2.0;
                        }

                        this.keyTipPositions[i] = translatedPoint;
                    }
                    else
                    {
                        var translatedPoint = this.associatedElements[i].TranslatePoint(new Point(this.associatedElements[i].DesiredSize.Width / 2.0 - this.keyTips[i].DesiredSize.Width / 2.0, this.associatedElements[i].DesiredSize.Height - 8), this.AdornedElement);
                        if (rows != null)
                        {
                            translatedPoint.Y = rows[2] - this.keyTips[i].DesiredSize.Height / 2.0;
                        }

                        this.keyTipPositions[i] = translatedPoint;
                    }
                }
            }
        }
Example #11
0
        // Find key tips on the given element
        private void FindKeyTips(UIElement element, bool hide)
        {
            this.Log("FindKeyTips");

            var children = LogicalTreeHelper.GetChildren(element);

            foreach (var item in children)
            {
                var child = item as UIElement;

                if (child == null ||
                    child.Visibility != Visibility.Visible)
                {
                    continue;
                }

                var groupBox = child as RibbonGroupBox;

                var keys = KeyTip.GetKeys(child);
                if (keys != null)
                {
                    // Gotcha!
                    var keyTip = new KeyTip
                    {
                        Content    = keys,
                        Visibility = hide
                            ? Visibility.Collapsed
                            : Visibility.Visible
                    };

                    // Add to list & visual
                    // children collections
                    this.keyTips.Add(keyTip);
                    this.AddVisualChild(keyTip);
                    this.associatedElements.Add(child);

                    if (groupBox != null)
                    {
                        if (groupBox.State == RibbonGroupBoxState.Collapsed)
                        {
                            keyTip.Visibility = Visibility.Visible;
                            this.FindKeyTips(child, true);
                            continue;
                        }
                        else
                        {
                            keyTip.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        // Bind IsEnabled property
                        var binding = new Binding("IsEnabled")
                        {
                            Source = child,
                            Mode   = BindingMode.OneWay
                        };
                        keyTip.SetBinding(IsEnabledProperty, binding);
                        continue;
                    }
                }

                if (groupBox != null &&
                    groupBox.State == RibbonGroupBoxState.Collapsed)
                {
                    this.FindKeyTips(child, true);
                }
                else
                {
                    this.FindKeyTips(child, hide);
                }
            }
        }
Example #12
0
        // Find key tips on the given element
        private void FindKeyTips(UIElement element, bool hide)
        {
            this.Log("FindKeyTips");

            IEnumerable children = LogicalTreeHelper.GetChildren(element);
            foreach (object item in children)
            {
                UIElement child = item as UIElement;
                RibbonGroupBox groupBox = (child as RibbonGroupBox);
                if (child != null)
                {
                    string keys = KeyTip.GetKeys(child);
                    if (keys != null)
                    {
                        // Gotcha!
                        KeyTip keyTip = new KeyTip
                                        {
                                            Content = keys,
                                            Visibility = hide
                                                ? Visibility.Collapsed
                                                : Visibility.Visible
                                        };

                        // Add to list & visual 
                        // children collections
                        keyTips.Add(keyTip);
                        base.AddVisualChild(keyTip);
                        associatedElements.Add(child);

                        if (groupBox != null)
                        {
                            if (groupBox.State == RibbonGroupBoxState.Collapsed)
                            {
                                keyTip.Visibility = Visibility.Visible;
                                FindKeyTips(child, true);
                                continue;
                            }
                            else keyTip.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            // Bind IsEnabled property
                            Binding binding = new Binding("IsEnabled")
                                              {
                                                  Source = child,
                                                  Mode = BindingMode.OneWay
                                              };
                            keyTip.SetBinding(UIElement.IsEnabledProperty, binding);
                            continue;
                        }
                    }

                    if ((groupBox != null) &&
                        (groupBox.State == RibbonGroupBoxState.Collapsed))
                    {
                        FindKeyTips(child, true);
                    }
                    else
                    {
                        FindKeyTips(child, hide);
                    }
                }
            }
        }
Example #13
0
        private void UpdateKeyTipPositions()
        {
            this.LogDebug("UpdateKeyTipPositions");

            if (this.keyTipInformations.Count == 0)
            {
                return;
            }

            double[] rows     = null;
            var      groupBox = this.oneOfAssociatedElements as RibbonGroupBox ?? UIHelper.GetParent <RibbonGroupBox>(this.oneOfAssociatedElements);
            var      panel    = groupBox?.GetPanel();

            if (panel != null)
            {
                var height = groupBox.GetLayoutRoot().DesiredSize.Height;
                rows = new[]
                {
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, 0), this.AdornedElement).Y,
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height / 2.0), this.AdornedElement).Y,
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height), this.AdornedElement).Y,
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, height + 1), this.AdornedElement).Y
                };
            }

            foreach (var keyTipInformation in this.keyTipInformations)
            {
                // Skip invisible keytips
                if (keyTipInformation.Visibility != Visibility.Visible)
                {
                    continue;
                }

                // Update KeyTip Visibility
                var visualTargetIsVisible    = keyTipInformation.VisualTarget.IsVisible;
                var visualTargetInVisualTree = VisualTreeHelper.GetParent(keyTipInformation.VisualTarget) != null;
                keyTipInformation.Visibility = visualTargetIsVisible && visualTargetInVisualTree ? Visibility.Visible : Visibility.Collapsed;

                keyTipInformation.KeyTip.Margin = KeyTip.GetMargin(keyTipInformation.AssociatedElement);

                if (IsWithinQuickAccessToolbar(keyTipInformation.AssociatedElement))
                {
                    var x = (keyTipInformation.VisualTarget.DesiredSize.Width / 2.0) - (keyTipInformation.KeyTip.DesiredSize.Width / 2.0);
                    var y = keyTipInformation.VisualTarget.DesiredSize.Height - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0);

                    if (KeyTip.GetAutoPlacement(keyTipInformation.AssociatedElement) == false)
                    {
                        switch (KeyTip.GetHorizontalAlignment(keyTipInformation.AssociatedElement))
                        {
                        case HorizontalAlignment.Left:
                            x = 0;
                            break;

                        case HorizontalAlignment.Right:
                            x = keyTipInformation.VisualTarget.DesiredSize.Width - keyTipInformation.KeyTip.DesiredSize.Width;
                            break;
                        }
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(x, y), this.AdornedElement);
                }
                else if (keyTipInformation.AssociatedElement.Name == "PART_DialogLauncherButton")
                {
                    // Dialog Launcher Button Exclusive Placement
                    var keyTipSize  = keyTipInformation.KeyTip.DesiredSize;
                    var elementSize = keyTipInformation.VisualTarget.RenderSize;
                    if (rows == null)
                    {
                        continue;
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(
                                                                                                   (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0),
                                                                                                   0), this.AdornedElement);
                    keyTipInformation.Position = new Point(keyTipInformation.Position.X, rows[3]);
                }
                else if (KeyTip.GetAutoPlacement(keyTipInformation.AssociatedElement) == false)
                {
                    var keyTipSize = keyTipInformation.KeyTip.DesiredSize;

                    var elementSize = keyTipInformation.VisualTarget.RenderSize;

                    double x = 0, y = 0;

                    switch (KeyTip.GetHorizontalAlignment(keyTipInformation.AssociatedElement))
                    {
                    case HorizontalAlignment.Left:
                        break;

                    case HorizontalAlignment.Right:
                        x = elementSize.Width - keyTipSize.Width;
                        break;

                    case HorizontalAlignment.Center:
                    case HorizontalAlignment.Stretch:
                        x = (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0);
                        break;
                    }

                    switch (KeyTip.GetVerticalAlignment(keyTipInformation.AssociatedElement))
                    {
                    case VerticalAlignment.Top:
                        break;

                    case VerticalAlignment.Bottom:
                        y = elementSize.Height - keyTipSize.Height;
                        break;

                    case VerticalAlignment.Center:
                    case VerticalAlignment.Stretch:
                        y = (elementSize.Height / 2.0) - (keyTipSize.Height / 2.0);
                        break;
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(x, y), this.AdornedElement);
                }
                else if (keyTipInformation.AssociatedElement is InRibbonGallery && !((InRibbonGallery)keyTipInformation.AssociatedElement).IsCollapsed)
                {
                    // InRibbonGallery Exclusive Placement
                    var keyTipSize  = keyTipInformation.KeyTip.DesiredSize;
                    var elementSize = keyTipInformation.VisualTarget.RenderSize;
                    if (rows == null)
                    {
                        continue;
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(
                                                                                                   elementSize.Width - (keyTipSize.Width / 2.0),
                                                                                                   0), this.AdornedElement);
                    keyTipInformation.Position = new Point(keyTipInformation.Position.X, rows[2] - (keyTipSize.Height / 2));
                }
                else if (keyTipInformation.AssociatedElement is RibbonTabItem || keyTipInformation.AssociatedElement is Backstage)
                {
                    // Ribbon Tab Item Exclusive Placement
                    var keyTipSize  = keyTipInformation.KeyTip.DesiredSize;
                    var elementSize = keyTipInformation.VisualTarget.RenderSize;
                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(
                                                                                                   (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0),
                                                                                                   elementSize.Height - (keyTipSize.Height / 2.0)), this.AdornedElement);
                }
                else if (keyTipInformation.AssociatedElement is MenuItem)
                {
                    // MenuItem Exclusive Placement
                    var elementSize = keyTipInformation.VisualTarget.DesiredSize;
                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(
                        new Point(
                            (elementSize.Height / 3.0) + 2,
                            (elementSize.Height / 4.0) + 2), this.AdornedElement);
                }
                else if (keyTipInformation.AssociatedElement.Parent is BackstageTabControl)
                {
                    // Backstage Items Exclusive Placement
                    var keyTipSize       = keyTipInformation.KeyTip.DesiredSize;
                    var elementSize      = keyTipInformation.VisualTarget.DesiredSize;
                    var parent           = (UIElement)keyTipInformation.VisualTarget.Parent;
                    var positionInParent = keyTipInformation.VisualTarget.TranslatePoint(default(Point), parent);
                    keyTipInformation.Position = parent.TranslatePoint(
                        new Point(
                            5,
                            positionInParent.Y + ((elementSize.Height / 2.0) - keyTipSize.Height)), this.AdornedElement);
                }
                else
                {
                    if (RibbonProperties.GetSize(keyTipInformation.AssociatedElement) != RibbonControlSize.Large ||
                        IsTextBoxShapedControl(keyTipInformation.AssociatedElement))
                    {
                        var withinRibbonToolbar = IsWithinRibbonToolbarInTwoLine(keyTipInformation.VisualTarget);
                        var x               = keyTipInformation.KeyTip.DesiredSize.Width / 2.0;
                        var y               = keyTipInformation.KeyTip.DesiredSize.Height / 2.0;
                        var point           = new Point(x, y);
                        var translatedPoint = keyTipInformation.VisualTarget.TranslatePoint(point, this.AdornedElement);

                        // Snapping to rows if it present
                        if (rows != null)
                        {
                            var index       = 0;
                            var mindistance = Math.Abs(rows[0] - translatedPoint.Y);
                            for (var j = 1; j < rows.Length; j++)
                            {
                                if (withinRibbonToolbar &&
                                    j == 1)
                                {
                                    continue;
                                }

                                var distance = Math.Abs(rows[j] - translatedPoint.Y);
                                if (distance < mindistance)
                                {
                                    mindistance = distance;
                                    index       = j;
                                }
                            }

                            translatedPoint.Y = rows[index] - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0);
                        }

                        keyTipInformation.Position = translatedPoint;
                    }
                    else
                    {
                        var x               = (keyTipInformation.VisualTarget.DesiredSize.Width / 2.0) - (keyTipInformation.KeyTip.DesiredSize.Width / 2.0);
                        var y               = keyTipInformation.VisualTarget.DesiredSize.Height - 8;
                        var point           = new Point(x, y);
                        var translatedPoint = keyTipInformation.VisualTarget.TranslatePoint(point, this.AdornedElement);

                        if (rows != null)
                        {
                            translatedPoint.Y = rows[2] - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0);
                        }

                        keyTipInformation.Position = translatedPoint;
                    }
                }
            }
        }
        // Find key tips on the given element
        private void FindKeyTips(UIElement element, bool hide)
        {
            this.Log("FindKeyTips");

            var children = GetVisibleChildren(element);

            foreach (var child in children)
            {
                var groupBox = child as RibbonGroupBox;

                var keys = KeyTip.GetKeys(child);
                if (keys != null)
                {
                    // Gotcha!
                    var keyTip = new KeyTip
                    {
                        Content = keys,
                        Visibility = hide
                            ? Visibility.Collapsed
                            : Visibility.Visible
                    };

                    // Add to list & visual 
                    // children collections
                    this.keyTips.Add(keyTip);
                    this.AddVisualChild(keyTip);
                    this.associatedElements.Add(child);

                    if (groupBox != null)
                    {
                        if (groupBox.State == RibbonGroupBoxState.Collapsed)
                        {
                            keyTip.Visibility = Visibility.Visible;
                            this.FindKeyTips(child, true);
                            continue;
                        }
                        else
                        {
                            keyTip.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        // Bind IsEnabled property
                        var binding = new Binding("IsEnabled")
                        {
                            Source = child,
                            Mode = BindingMode.OneWay
                        };
                        keyTip.SetBinding(IsEnabledProperty, binding);
                        continue;
                    }
                }

                if (groupBox != null &&
                    groupBox.State == RibbonGroupBoxState.Collapsed)
                {
                    this.FindKeyTips(child, true);
                }
                else
                {
                    this.FindKeyTips(child, hide);
                }
            }
        }
Example #15
0
        private void UpdateKeyTipPositions()
        {
            this.LogDebug("UpdateKeyTipPositions");

            if (this.keyTipInformations.Count == 0)
            {
                return;
            }

            double[] rows     = null;
            var      groupBox = this.oneOfAssociatedElements as RibbonGroupBox ?? UIHelper.GetParent <RibbonGroupBox>(this.oneOfAssociatedElements);
            var      panel    = groupBox?.GetPanel();

            if (panel != null)
            {
                var height = groupBox.GetLayoutRoot().DesiredSize.Height;
                rows = new[]
                {
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, 0), this.AdornedElement).Y,
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height / 2.0), this.AdornedElement).Y,
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height), this.AdornedElement).Y,
                    groupBox.GetLayoutRoot().TranslatePoint(new Point(0, height + 1), this.AdornedElement).Y
                };
            }

            foreach (var keyTipInformation in this.keyTipInformations)
            {
                // Skip invisible keytips
                if (keyTipInformation.Visibility != Visibility.Visible)
                {
                    continue;
                }

                // Update KeyTip Visibility
                var visualTargetIsVisible    = keyTipInformation.VisualTarget.IsVisible;
                var visualTargetInVisualTree = VisualTreeHelper.GetParent(keyTipInformation.VisualTarget) != null;
                keyTipInformation.Visibility = visualTargetIsVisible && visualTargetInVisualTree ? Visibility.Visible : Visibility.Collapsed;

                keyTipInformation.KeyTip.Margin = KeyTip.GetMargin(keyTipInformation.AssociatedElement);

                if (IsWithinQuickAccessToolbar(keyTipInformation.AssociatedElement))
                {
                    var x = (keyTipInformation.VisualTarget.DesiredSize.Width / 2.0) - (keyTipInformation.KeyTip.DesiredSize.Width / 2.0);
                    var y = keyTipInformation.VisualTarget.DesiredSize.Height - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0);

                    if (KeyTip.GetAutoPlacement(keyTipInformation.AssociatedElement) == false)
                    {
                        switch (KeyTip.GetHorizontalAlignment(keyTipInformation.AssociatedElement))
                        {
                        case HorizontalAlignment.Left:
                            x = 0;
                            break;

                        case HorizontalAlignment.Right:
                            x = keyTipInformation.VisualTarget.DesiredSize.Width - keyTipInformation.KeyTip.DesiredSize.Width;
                            break;
                        }
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(x, y), this.AdornedElement);
                }
                else if (keyTipInformation.AssociatedElement.Name == "PART_DialogLauncherButton")
                {
                    // Dialog Launcher Button Exclusive Placement
                    var keyTipSize  = keyTipInformation.KeyTip.DesiredSize;
                    var elementSize = keyTipInformation.VisualTarget.RenderSize;
                    if (rows is null)
                    {
                        continue;
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(
                                                                                                   (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0),
                                                                                                   0), this.AdornedElement);
                    keyTipInformation.Position = new Point(keyTipInformation.Position.X, rows[3]);
                }
                else if (KeyTip.GetAutoPlacement(keyTipInformation.AssociatedElement) == false)
                {
                    var keyTipSize = keyTipInformation.KeyTip.DesiredSize;

                    var elementSize = keyTipInformation.VisualTarget.RenderSize;

                    double x = 0, y = 0;

                    switch (KeyTip.GetHorizontalAlignment(keyTipInformation.AssociatedElement))
                    {
                    case HorizontalAlignment.Left:
                        break;

                    case HorizontalAlignment.Right:
                        x = elementSize.Width - keyTipSize.Width;
                        break;

                    case HorizontalAlignment.Center:
                    case HorizontalAlignment.Stretch:
                        x = (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0);
                        break;
                    }

                    switch (KeyTip.GetVerticalAlignment(keyTipInformation.AssociatedElement))
                    {
                    case VerticalAlignment.Top:
                        break;

                    case VerticalAlignment.Bottom:
                        y = elementSize.Height - keyTipSize.Height;
                        break;

                    case VerticalAlignment.Center:
                    case VerticalAlignment.Stretch:
                        y = (elementSize.Height / 2.0) - (keyTipSize.Height / 2.0);
                        break;
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(x, y), this.AdornedElement);
                }
                else if (keyTipInformation.AssociatedElement is InRibbonGallery gallery &&
                         gallery.IsCollapsed == false)
                {
                    // InRibbonGallery Exclusive Placement
                    var keyTipSize  = keyTipInformation.KeyTip.DesiredSize;
                    var elementSize = keyTipInformation.VisualTarget.RenderSize;
                    if (rows is null)
                    {
                        continue;
                    }

                    keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(
                                                                                                   elementSize.Width - (keyTipSize.Width / 2.0),
                                                                                                   0), this.AdornedElement);
                    keyTipInformation.Position = new Point(keyTipInformation.Position.X, rows[2] - (keyTipSize.Height / 2));
                }
Example #16
0
        // Find key tips on the given element
        private void FindKeyTips(UIElement element, bool hide)
        {
            this.Log("FindKeyTips");

            IEnumerable children = LogicalTreeHelper.GetChildren(element);

            foreach (object item in children)
            {
                UIElement      child    = item as UIElement;
                RibbonGroupBox groupBox = (child as RibbonGroupBox);
                if (child != null)
                {
                    string keys = KeyTip.GetKeys(child);
                    if (keys != null)
                    {
                        // Gotcha!
                        KeyTip keyTip = new KeyTip
                        {
                            Content    = keys,
                            Visibility = hide
                                                ? Visibility.Collapsed
                                                : Visibility.Visible
                        };

                        // Add to list & visual
                        // children collections
                        keyTips.Add(keyTip);
                        base.AddVisualChild(keyTip);
                        associatedElements.Add(child);

                        if (groupBox != null)
                        {
                            if (groupBox.State == RibbonGroupBoxState.Collapsed)
                            {
                                keyTip.Visibility = Visibility.Visible;
                                FindKeyTips(child, true);
                                continue;
                            }
                            else
                            {
                                keyTip.Visibility = Visibility.Collapsed;
                            }
                        }
                        else
                        {
                            // Bind IsEnabled property
                            Binding binding = new Binding("IsEnabled")
                            {
                                Source = child,
                                Mode   = BindingMode.OneWay
                            };
                            keyTip.SetBinding(UIElement.IsEnabledProperty, binding);
                            continue;
                        }
                    }

                    if ((groupBox != null) &&
                        (groupBox.State == RibbonGroupBoxState.Collapsed))
                    {
                        FindKeyTips(child, true);
                    }
                    else
                    {
                        FindKeyTips(child, hide);
                    }
                }
            }
        }