Exemplo n.º 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()
        {
            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();
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
        static void OnDialogLauncherButtonKeyTipKeysChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonGroupBox ribbonGroupBox = (RibbonGroupBox)d;

            if (ribbonGroupBox.LauncherButton != null)
            {
                KeyTip.SetKeys(ribbonGroupBox.LauncherButton, (string)e.NewValue);
            }
        }
Exemplo n.º 4
0
        // Updates keys for keytip access
        private void UpdateKeyTips()
        {
            for (var i = 0; i < Math.Min(9, Items.Count); i++)
            {
                // 1, 2, 3, ... , 9
                KeyTip.SetKeys(Items[i], (i + 1).ToString(CultureInfo.InvariantCulture));
            }

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

            var startChar = 'A';

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

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

            double[] rows     = null;
            var      groupBox = GetGroupBox(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), AdornedElement).Y,
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height / 2.0), AdornedElement).Y,
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height), AdornedElement).Y,
                        groupBox.GetLayoutRoot().TranslatePoint(new Point(0, height + 1), AdornedElement).Y
                    };
                }
            }

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

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

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

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

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

                    switch (KeyTip.GetHorizontalAlignment(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(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;
                    }

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

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

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

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

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

                        keyTipPositions[i] = translatedPoint;
                    }
                }
            }
        }
Exemplo n.º 6
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);
                    }
                }
            }
        }