A Static class declaring attached dependency properties needed for ribbon controls.
Exemplo n.º 1
0
        private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonContextMenu contextMenu = (RibbonContextMenu)d;

            if (!(bool)(e.NewValue))
            {
                if (!contextMenu._ignoreDismissPopupsOnNextClose)
                {
                    UIElement dismissPopupSource = contextMenu.GetDismissPopupSource();
                    if (CanRaiseDismissPopups(dismissPopupSource))
                    {
                        // Raise DismissPopup on owner if can raise and if
                        // was not asked to ignore.
                        dismissPopupSource.RaiseEvent(new RibbonDismissPopupEventArgs(RibbonDismissPopupMode.Always));
                        ((Ribbon)(RibbonControlService.GetRibbon(dismissPopupSource))).RestoreFocusOnContextMenuClose();
                    }
                }
                else
                {
                    contextMenu.RestoreFocusToRibbon();
                    contextMenu._ignoreDismissPopupsOnNextClose = false;
                }
            }
            else
            {
                contextMenu._ignoreDismissPopupsOnNextClose = false;
            }
        }
Exemplo n.º 2
0
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                DependencyObject d = value as DependencyObject;

                if (d != null)
                {
                    Ribbon ribbon = RibbonControlService.GetRibbon(d);
                    if (ribbon != null &&
                        !ribbon.ShowQuickAccessToolBarOnTop)
                    {
                        if (_mode == ConverterMode.Header)
                        {
                            return(ShowQATAboveText);
                        }
                        else
                        {
                            return(RibbonCommands.ShowQuickAccessToolBarAboveRibbonCommand);
                        }
                    }
                }

                if (_mode == ConverterMode.Header)
                {
                    return(ShowQATBelowText);
                }
                else
                {
                    return(RibbonCommands.ShowQuickAccessToolBarBelowRibbonCommand);
                }
            }
Exemplo n.º 3
0
        internal static RibbonContextMenu ChooseContextMenu(DependencyObject owner)
        {
            if (owner is Ribbon)
            {
                return(GetDefaultRibbonClientAreaContextMenu());
            }
            else if (RibbonControlService.GetCanAddToQuickAccessToolBarDirectly(owner))
            {
                if (owner is RibbonGallery)
                {
                    return(GetGalleryContextMenu());
                }
                else
                {
                    if (RibbonControlService.GetIsInQuickAccessToolBar(owner))
                    {
                        return(GetQATControlContextMenu());
                    }
                    else
                    {
                        return(GetRibbonControlContextMenu());
                    }
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Tries to restore focus to the first focusable element across
        ///     the ancestor chain of ContextMenuOriginalSource. Should
        ///     be called only when Ribbon is supposed to retain the focus.
        /// </summary>
        private void RestoreFocusToRibbon()
        {
            DependencyObject current = GetDismissPopupSource();

            if (current == null)
            {
                return;
            }
            Ribbon ribbon = RibbonControlService.GetRibbon(current);

            if (ribbon == null)
            {
                return;
            }
            while (current != null)
            {
                UIElement uie = current as UIElement;
                if (uie != null && uie.Focusable)
                {
                    uie.Dispatcher.BeginInvoke(
                        (Action) delegate()
                    {
                        if (!ribbon.IsKeyboardFocusWithin)
                        {
                            uie.Focus();
                        }
                    },
                        DispatcherPriority.Input,
                        null);
                    break;
                }
                current = TreeHelper.GetParent(current);
            }
        }
Exemplo n.º 5
0
        private static object CoerceDefaultControlSizeDefinition(DependencyObject d, object baseValue)
        {
            if (baseValue == null)
            {
                RibbonControlGroup controlGroup = (RibbonControlGroup)d;
                RibbonImageSize    imageSize    = RibbonImageSize.Collapsed;
                bool isLabelVisible             = false;
                int  itemCount  = controlGroup.Items.Count;
                bool childFound = false;

                // Get the largest ControlSizeDefinition variant for all
                // the child controls and construct a union ControlSizeDefinition.
                for (int i = 0; i < itemCount; i++)
                {
                    RibbonControl ribbonControl = controlGroup.ItemContainerGenerator.ContainerFromIndex(i) as RibbonControl;
                    if (ribbonControl != null && ribbonControl.Visibility != Visibility.Collapsed)
                    {
                        UIElement contentChild = ribbonControl.ContentChild;
                        if (contentChild != null && contentChild.Visibility != Visibility.Collapsed)
                        {
                            RibbonControlSizeDefinition currentLargeCsd = RibbonControlService.GetDefaultControlSizeDefinition(contentChild);
                            if (currentLargeCsd == null)
                            {
                                contentChild.CoerceValue(RibbonControlService.DefaultControlSizeDefinitionProperty);
                                currentLargeCsd = RibbonControlService.GetDefaultControlSizeDefinition(contentChild);
                            }

                            if (currentLargeCsd != null)
                            {
                                childFound = true;
                                if (imageSize == RibbonImageSize.Collapsed)
                                {
                                    imageSize = currentLargeCsd.ImageSize;
                                }
                                else if (currentLargeCsd.ImageSize == RibbonImageSize.Large)
                                {
                                    imageSize = RibbonImageSize.Large;
                                }

                                isLabelVisible |= currentLargeCsd.IsLabelVisible;

                                if (isLabelVisible && imageSize == RibbonImageSize.Large)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (childFound)
                {
                    return(RibbonControlSizeDefinition.GetFrozenControlSizeDefinition(imageSize, isLabelVisible));
                }
            }
            return(baseValue);
        }
Exemplo n.º 6
0
 private static object CoerceControlSizeDefinition(DependencyObject d, object baseValue)
 {
     if (baseValue == null)
     {
         RibbonControlSizeDefinition defaultControlSizeDefinition = RibbonControlService.GetDefaultControlSizeDefinition(d);
         if (defaultControlSizeDefinition == null)
         {
             d.CoerceValue(DefaultControlSizeDefinitionProperty);
             defaultControlSizeDefinition = RibbonControlService.GetDefaultControlSizeDefinition(d);
         }
         return(defaultControlSizeDefinition);
     }
     return(baseValue);
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Property changed callback for tooltip PlacementTarget property.
        /// </summary>
        private static void OnPlacementTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonToolTip ribbonToolTip = (RibbonToolTip)d;
            UIElement     target        = e.NewValue as UIElement;

            if (target == null)
            {
                ribbonToolTip.Ribbon = null;
            }
            else
            {
                ribbonToolTip.Ribbon = RibbonControlService.GetRibbon(target);
            }
        }
Exemplo n.º 8
0
        private static void UpdateDefaultControlSizeDefinition(DependencyObject d)
        {
            d.CoerceValue(DefaultControlSizeDefinitionProperty);

            // If the element belongs to a ControlGroup, then
            // coerce DefaultControlSizeDefinition for the ControlGroup too.
            if (RibbonControlService.GetIsInControlGroup(d))
            {
                RibbonControlGroup controlGroup = TreeHelper.FindVisualAncestor <RibbonControlGroup>(d);
                if (controlGroup != null)
                {
                    controlGroup.CoerceValue(DefaultControlSizeDefinitionProperty);
                }
            }
        }
Exemplo n.º 9
0
        // Determine whether the QAT contains an element with the given QAT ID.
        internal bool ContainsId(object targetID)
        {
            foreach (object o in this.Items)
            {
                DependencyObject dependencyObject = o as DependencyObject;
                if (dependencyObject != null)
                {
                    object currentID = RibbonControlService.GetQuickAccessToolBarId(dependencyObject);
                    if (object.Equals(currentID, targetID))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 10
0
 private void TransferPseudoInheritedProperties()
 {
     if (_templateRoot != null)
     {
         // Ribbon is an inherited property. In non-MVVM scenarios where
         // controls are directly added under RibbonGroup in XAML, RibbonGroup
         // is the logical parent of those controls and they get the value
         // of RibbonParent set from their logical parent. When a RibbonGroup
         // get collapsed and its template changes, due to a bug in framework
         // the inheritance value of those controls is lost during visual tree
         // change and never again gets updated. The workaround is to set the
         // local value on those controls from RibbonContentPresenter which
         // would be their visual parent. This works because Ribbon property is
         // readonly.
         RibbonControlService.SetRibbon(_templateRoot, RibbonControlService.GetRibbon(this));
         RibbonHelper.TransferPseudoInheritedProperties(this, _templateRoot);
     }
 }
Exemplo n.º 11
0
        private static object CoerceDefaultControlSizeDefinition(DependencyObject d, object baseValue)
        {
            if (baseValue == null)
            {
                RibbonImageSize imageSize = RibbonImageSize.Collapsed;
                if (RibbonControlService.GetLargeImageSource(d) != null)
                {
                    imageSize = RibbonImageSize.Large;
                }
                else if (RibbonControlService.GetSmallImageSource(d) != null)
                {
                    imageSize = RibbonImageSize.Small;
                }
                bool isLabelVisible = !string.IsNullOrEmpty(RibbonControlService.GetLabel(d));

                return(RibbonControlSizeDefinition.GetFrozenControlSizeDefinition(imageSize, isLabelVisible));
            }
            return(baseValue);
        }
Exemplo n.º 12
0
        private static bool CanRaiseDismissPopups(UIElement dismissPopupSource)
        {
            // Contextmenu raises DismissPopup event on the source only
            // if it is in a popup and is in a Ribbon.
            if (dismissPopupSource == null ||
                RibbonControlService.GetRibbon(dismissPopupSource) == null)
            {
                return(false);
            }

            Popup ancestorPopup = TreeHelper.FindAncestor(dismissPopupSource, delegate(DependencyObject element) { return(element is Popup); }) as Popup;

            if (ancestorPopup == null ||
                !ancestorPopup.IsOpen)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        ///     Helper method which scrolls item at given index into view.
        ///     Can be used as a dispatcher operation.
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private object ScrollContainerIntoView(object arg)
        {
            int index = (int)arg;
            FrameworkElement element = ItemContainerGenerator.ContainerFromIndex(index) as FrameworkElement;

            if (element != null)
            {
                element.BringIntoView();

                // If there is a margin on TabHeader on the end, BringIntoView call
                // may not scroll to the end. Explicitly scroll to end in such cases.
                IScrollInfo scrollInfo = InternalItemsHost as IScrollInfo;
                if (scrollInfo != null)
                {
                    ScrollViewer scrollViewer = scrollInfo.ScrollOwner;
                    if (scrollViewer != null)
                    {
                        Ribbon ribbon = RibbonControlService.GetRibbon(this);
                        if (ribbon != null)
                        {
                            int displayIndex = ribbon.GetTabDisplayIndexForIndex(index);
                            if (displayIndex == 0)
                            {
                                // If this tab header is the first tab header displayed
                                // then scroll to the left end.
                                scrollViewer.ScrollToLeftEnd();
                            }
                            else if (ribbon.GetTabIndexForDisplayIndex(displayIndex + 1) < 0)
                            {
                                // If this tab header is the last tab header displayed
                                // then scroll to the right end.
                                scrollViewer.ScrollToRightEnd();
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 14
0
        private UIElement GetDismissPopupSource()
        {
            UIElement placementTarget = PlacementTarget;

            if (placementTarget == null)
            {
                return(null);
            }
            Ribbon ribbon = RibbonControlService.GetRibbon(placementTarget);

            if (ribbon == null)
            {
                return(null);
            }
            // The original source for corresponding ContextMenuOpening will
            // be the original source for DismissPopup event.
            UIElement returnValue = ribbon.ContextMenuOriginalSource;

            if (returnValue == null)
            {
                returnValue = placementTarget;
            }
            return(returnValue);
        }