Esempio n. 1
0
        private static void OnIsOverflowOpenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            // If the drop down is closed due to
            // an action of context menu or if the
            // ContextMenu for a parent
            // was opened by right clicking this
            // instance then ContextMenuClosed
            // event is never raised.
            // Hence reset the flag.
            qat.InContextMenu = false;

            UIElement popupChild = qat._overflowPopup.TryGetChild();

            RibbonHelper.HandleIsDropDownChanged(
                qat,
                delegate() { return(qat.IsOverflowOpen); },
                popupChild,
                popupChild);

            if ((bool)(e.NewValue))
            {
                qat.RetainFocusOnEscape = RibbonHelper.IsKeyboardMostRecentInputDevice();
            }

            // Raise UI Automation Events
            RibbonQuickAccessToolBarAutomationPeer peer = UIElementAutomationPeer.FromElement(qat) as RibbonQuickAccessToolBarAutomationPeer;

            if (peer != null)
            {
                peer.RaiseExpandCollapseAutomationEvent(!(bool)e.OldValue, !(bool)e.NewValue);
            }
        }
Esempio n. 2
0
        public static void CheckQATButton(RibbonQuickAccessToolBar qatBar, object id, bool?isChecked)
        {
            DependencyObject obj = GetQATButton(qatBar, id);

            if (obj != null)
            {
                (obj as ToggleButton).IsChecked = isChecked;
            }
        }
Esempio n. 3
0
        private static object OnCoerceIsOverflowOpen(DependencyObject d, object baseValue)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)d;

            if (!qat.HasOverflowItems)
            {
                return(false);
            }
            return(baseValue);
        }
Esempio n. 4
0
        public static DependencyObject GetQATButton(RibbonQuickAccessToolBar qatBar, object id)
        {
            foreach (DependencyObject each in qatBar.Items)
            {
                if (RibbonControlService.GetQuickAccessToolBarId(each) == id)
                {
                    return(each);
                }
            }

            return(null);
        }
Esempio n. 5
0
        private void SaveQatItems(RibbonQuickAccessToolBar qat)
        {
            if (qat != null)
            {
                QatItemCollection qatItems       = new QatItemCollection();
                QatItemCollection remainingItems = new QatItemCollection();

                if (qat.Items.Count > 0)
                {
                    for (int qatIndex = 0; qatIndex < qat.Items.Count; qatIndex++)
                    {
                        object instance      = qat.Items[qatIndex];
                        bool   isSplitHeader = false;

                        if (instance is ICommandSource)
                        {
                            ICommandSource element = (ICommandSource)instance;

                            if (element.Command != null)
                            {
                                isSplitHeader = instance is RibbonSplitMenuItem || instance is RibbonSplitButton;
                                instance      = element.Command;
                            }
                        }

                        QatItem qatItem = new QatItem(instance, isSplitHeader);
                        qatItems.Add(qatItem);
                        remainingItems.Add(qatItem);
                    }

                    for (int tabIndex = 0; tabIndex < _ribbon.Items.Count && remainingItems.Count > 0; tabIndex++)
                    {
                        RibbonTab tab = _ribbon.Items[tabIndex] as RibbonTab;
                        SaveQatItemsAmongChildren(remainingItems, tab, tabIndex);
                    }
                }

                if (!Directory.Exists(Static.LocalAppData))
                {
                    Directory.CreateDirectory(Static.LocalAppData);
                }

                XmlWriter xmlWriter = XmlWriter.Create(_qatFileName);
                XamlWriter.Save(qatItems, xmlWriter);
                xmlWriter.Close();
            }
        }
        protected override Size MeasureOverride(Size availableSize)
        {
            Size panelDesiredSize = new Size();

            for (int i = 0; i < Children.Count; i++)
            {
                UIElement child = Children[i];
                Debug.Assert(child != null, "child not expected to be null");
                Debug.Assert(RibbonQuickAccessToolBar.GetIsOverflowItem(child) == true, "child expected to have IsOverflowItem == true");

                Size infinity = new Size(Double.PositiveInfinity, availableSize.Height);
                child.Measure(infinity);
                panelDesiredSize.Width += child.DesiredSize.Width;
                panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, child.DesiredSize.Height);
            }

            return(panelDesiredSize);
        }
        private void ValidateMeasure()
        {
            // validation code

            if (QAT.HasOverflowItems)
            {
                Debug.Assert(GeneratedChildren.Count > InternalChildren.Count);
                int numItemsExpectedInOverflowPanel = GeneratedChildren.Count - InternalChildren.Count;
                Debug.Assert(QAT.OverflowPanel.Children.Count == numItemsExpectedInOverflowPanel);
            }

            // MainPanel
            for (int j = 0; j < InternalChildren.Count; j++)
            {
                Debug.Assert(object.ReferenceEquals(InternalChildren[j], GeneratedChildren[j]));
                UIElement currentChild = InternalChildren[j];
                Debug.Assert(currentChild != null);
                Debug.Assert(RibbonQuickAccessToolBar.GetIsOverflowItem(currentChild) == false);
                Debug.Assert(this.Children.Contains(currentChild) == true);
                Debug.Assert(QAT.OverflowPanel.Children.Contains(currentChild) == false);
                Debug.Assert(currentChild.IsVisible == this.IsVisible);
                Debug.Assert(currentChild.DesiredSize.Width > 0.0);
            }

            // OverflowPanel
            for (int k = InternalChildren.Count; k < GeneratedChildren.Count; k++)
            {
                int overflowPanelIndex = k - InternalChildren.Count;
                Debug.Assert(object.ReferenceEquals(QAT.OverflowPanel.Children[overflowPanelIndex], GeneratedChildren[k]));
                UIElement currentChild = GeneratedChildren[k];
                Debug.Assert(currentChild != null);
                Debug.Assert(RibbonQuickAccessToolBar.GetIsOverflowItem(currentChild) == true);
                Debug.Assert(this.Children.Contains(currentChild) == false);
                Debug.Assert(QAT.OverflowPanel.Children.Contains(currentChild) == true);
            }
        }
        private void SaveQatItems(RibbonQuickAccessToolBar qat)
        {
            if (qat != null)
            {
                VM.QatItemCollection qatItems = new VM.QatItemCollection();
                VM.QatItemCollection remainingItems = new VM.QatItemCollection();

                if (qat.Items.Count > 0)
                {
                    for (int qatIndex = 0; qatIndex < qat.Items.Count; qatIndex++)
                    {
                        object instance = qat.Items[qatIndex];
                        bool isSplitHeader = false;

                        if (instance is FrameworkElement)
                        {
                            FrameworkElement element = (FrameworkElement)instance;
                            instance = ((FrameworkElement)instance).DataContext;

                            isSplitHeader =
                                (instance is VM.SplitMenuItemData && element is ButtonBase) ||
                                (instance is VM.SplitButtonData && element is ButtonBase);
                        }

                        VM.QatItem qatItem = new VM.QatItem(instance, isSplitHeader);
                        qatItems.Add(qatItem);
                        remainingItems.Add(qatItem);
                    }

                    VM.RibbonData ribbonData = VM.ViewModelData.RibbonData;
                    for (int tabIndex = 0; tabIndex < ribbonData.TabDataCollection.Count && remainingItems.Count > 0; tabIndex++)
                    {
                        for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
                        {
                            VM.QatItem qatItem = remainingItems[qatIndex];
                            qatItem.TabIndex = tabIndex;
                        }

                        VM.TabData tabData = ribbonData.TabDataCollection[tabIndex];
                        for (int groupIndex = 0; groupIndex < tabData.GroupDataCollection.Count && remainingItems.Count > 0; groupIndex++)
                        {
                            VM.GroupData groupData = tabData.GroupDataCollection[groupIndex];
                            for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
                            {
                                VM.QatItem qatItem = remainingItems[qatIndex];
                                qatItem.GroupIndex = groupIndex;

                                if (qatItem.Instance == groupData)
                                {
                                    remainingItems.Remove(qatItem);
                                    qatIndex--;
                                }
                            }

                            for (int controlIndex = 0; controlIndex < groupData.ControlDataCollection.Count && remainingItems.Count > 0; controlIndex++)
                            {
                                for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
                                {
                                    VM.QatItem qatItem = remainingItems[qatIndex];
                                    qatItem.ControlIndices.Add(controlIndex);
                                }

                                VM.ControlData controlData = groupData.ControlDataCollection[controlIndex];
                                bool matched = SaveQatControlData(remainingItems, controlData);
                                if (!matched)
                                {
                                    for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
                                    {
                                        VM.QatItem qatItem = remainingItems[qatIndex];
                                        qatItem.ControlIndices.Clear();
                                    }
                                }
                            }
                        }
                    }
                }

                XmlWriter xmlWriter = XmlWriter.Create(_qatFileName);
                XamlWriter.Save(qatItems, xmlWriter);
                xmlWriter.Close();
            }
        }
        private void LoadQatItems(RibbonQuickAccessToolBar qat)
        {
            if (qat != null)
            {
                if (File.Exists(_qatFileName))
                {
                    XmlReader xmlReader = XmlReader.Create(_qatFileName);
                    VM.QatItemCollection qatItems = (VM.QatItemCollection)XamlReader.Load(xmlReader);
                    xmlReader.Close();
                    if (qatItems != null)
                    {
                        int remainingItemsCount = qatItems.Count;
                        VM.QatItemCollection tabMatchedItems = new VM.QatItemCollection();
                        VM.QatItemCollection groupMatchedItems = new VM.QatItemCollection();

                        if (qatItems.Count > 0)
                        {
                            VM.RibbonData ribbonData = VM.ViewModelData.RibbonData;
                            for (int tabIndex = 0; tabIndex < ribbonData.TabDataCollection.Count && remainingItemsCount > 0; tabIndex++)
                            {
                                tabMatchedItems.Clear();
                                for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                                {
                                    VM.QatItem qatItem = qatItems[qatIndex];
                                    if (qatItem.TabIndex == tabIndex)
                                    {
                                        tabMatchedItems.Add(qatItem);
                                    }
                                }

                                VM.TabData tabData = ribbonData.TabDataCollection[tabIndex];
                                for (int groupIndex = 0; groupIndex < tabData.GroupDataCollection.Count && tabMatchedItems.Count > 0 && remainingItemsCount > 0; groupIndex++)
                                {
                                    VM.GroupData groupData = tabData.GroupDataCollection[groupIndex];

                                    groupMatchedItems.Clear();
                                    for (int qatIndex = 0; qatIndex < tabMatchedItems.Count; qatIndex++)
                                    {
                                        VM.QatItem qatItem = tabMatchedItems[qatIndex];
                                        if (qatItem.GroupIndex == groupIndex)
                                        {
                                            if (qatItem.ControlIndices.Count == 0)
                                            {
                                                qatItem.Instance = groupData;
                                                remainingItemsCount--;
                                            }
                                            else
                                            {
                                                groupMatchedItems.Add(qatItem);
                                            }
                                        }
                                    }

                                    for (int controlIndex = 0; controlIndex < groupData.ControlDataCollection.Count && groupMatchedItems.Count > 0 && remainingItemsCount > 0; controlIndex++)
                                    {
                                        VM.ControlData controlData = groupData.ControlDataCollection[controlIndex];
                                        LoadQatControlData(groupMatchedItems, 0, controlIndex, controlData, ref remainingItemsCount);
                                    }
                                }
                            }

                            for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                            {
                                VM.QatItem qatItem = qatItems[qatIndex];
                                Control control = MapQatDataToControl(qatItem);
                                if (control != null)
                                {
                                    qat.Items.Add(control);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private static void OnHasOverflowItemsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            qat.CoerceValue(RibbonQuickAccessToolBar.IsOverflowOpenProperty);
        }
Esempio n. 11
0
        private void LoadQatItems(RibbonQuickAccessToolBar qat)
        {
            Dispatcher.CurrentDispatcher.BeginInvoke(() =>
            {
                try
                {
                    if (qat != null)
                    {
                        if (File.Exists(_qatFileName))
                        {
                            XmlReader xmlReader        = XmlReader.Create(_qatFileName);
                            QatItemCollection qatItems = (QatItemCollection)XamlReader.Load(xmlReader);
                            xmlReader.Close();

                            if (qatItems != null)
                            {
                                int remainingItemsCount        = qatItems.Count;
                                QatItemCollection matchedItems = new QatItemCollection();

                                if (qatItems.Count > 0)
                                {
                                    for (int tabIndex = 0; tabIndex < _ribbon.Items.Count && remainingItemsCount > 0; tabIndex++)
                                    {
                                        matchedItems.Clear();

                                        for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                                        {
                                            QatItem qatItem = qatItems[qatIndex];

                                            if (qatItem.ControlIndices[0] == tabIndex)
                                            {
                                                matchedItems.Add(qatItem);
                                            }
                                        }

                                        RibbonTab tab = _ribbon.Items[tabIndex] as RibbonTab;

                                        if (tab != null)
                                        {
                                            LoadQatItemsAmongChildren(matchedItems, 0, tabIndex, tab, ref remainingItemsCount);
                                        }
                                    }

                                    for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                                    {
                                        QatItem qatItem = qatItems[qatIndex];
                                        Control control = qatItem.Instance as Control;

                                        if (control != null)
                                        {
                                            if (RibbonCommands.AddToQuickAccessToolBarCommand.CanExecute(null, control))
                                            {
                                                RibbonCommands.AddToQuickAccessToolBarCommand.Execute(null, control);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch { }
            });
        }
Esempio n. 12
0
        private static void OnClickThroughThunk(object sender, MouseButtonEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            qat.OnClickThrough(e);
        }
Esempio n. 13
0
        private static void OnLostMouseCaptureThunk(object sender, MouseEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            qat.OnLostMouseCaptureThunk(e);
        }
 public RibbonQuickAccessToolBarAutomationPeer(RibbonQuickAccessToolBar owner)
     : base(owner)
 {
 }
Esempio n. 15
0
 public RibbonQuickAccessToolBarAutomationPeer(RibbonQuickAccessToolBar owner)
     : base(owner)
 {
 }
Esempio n. 16
0
        private static void OnDismissPopupThunk(object sender, RibbonDismissPopupEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            qat.OnDismissPopup(e);
        }
        // Basic algorithm:
        // For each child in GeneratedChildren...
        //   If we are not sending items to overflow...
        //     If the child is already in InternalChildren at the current index, do nothing.  Otherwise...
        //       If the child is in overlow panel at position 0, remove it and set IsOverflowItem = false.
        //       Insert the child into InternalChildren at the current index.
        //       Measure the child...
        //         If the child fits, increment the panel's desired width by the child's width.
        //         Otherwise...
        //           Set sendToOverflow flag to start sending items to overflow.
        //           Remove child and any other items beyond it from InternalChildren.
        //   If we are sending items to overflow...
        //     If child is not already in the overflow panel at overflowIndex, insert it.
        //     Increment overflowIndex.
        // Set HasOverflowItems appropriately & invalidate the overflow panel's measure if necessary.
        protected override Size MeasureOverride(Size availableSize)
        {
            Size   panelDesiredSize            = new Size();
            double maxExtent                   = availableSize.Width;
            bool   sendToOverflow              = false;
            UIElementCollection children       = InternalChildren;
            List <UIElement>    generatedItems = GeneratedChildren;
            int overflowIndex                  = 0;
            RibbonQuickAccessToolBarOverflowPanel overflowPanel = QAT == null ? null : QAT.OverflowPanel;

            for (int i = 0; i < generatedItems.Count; i++)
            {
                UIElement generatedChild = generatedItems[i];
                Debug.Assert(generatedChild != null);

                if (!sendToOverflow)
                {
                    if (i >= children.Count ||
                        !object.ReferenceEquals(children[i], generatedChild))
                    {
                        if (overflowPanel != null &&
                            overflowPanel.Children.Count > 0 &&
                            object.ReferenceEquals(overflowPanel.Children[0], generatedChild))
                        {
                            overflowPanel.Children.RemoveAt(0);
                            RibbonQuickAccessToolBar.SetIsOverflowItem(generatedChild, false);
                        }

                        base.InsertInternalChild(i, generatedChild);
                    }

                    Size infinity = new Size(Double.PositiveInfinity, availableSize.Height);
                    generatedChild.Measure(infinity);
                    Size childDesiredSize = generatedChild.DesiredSize;

                    double newExtent = panelDesiredSize.Width + childDesiredSize.Width;

                    if (DoubleUtil.GreaterThan(newExtent, maxExtent))
                    {
                        // It doesn't fit, send to overflow
                        sendToOverflow = true;
                        base.RemoveInternalChildRange(i, children.Count - i);
                    }
                    else
                    {
                        panelDesiredSize.Width  = newExtent;
                        panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, childDesiredSize.Height);
                    }
                }

                if (sendToOverflow)
                {
                    Debug.Assert(overflowPanel.Children.Count >= overflowIndex, "overflowIndex should never get above overflowPanel.Children.Count");

                    if (overflowPanel != null &&
                        overflowPanel.Children.Count == overflowIndex ||
                        !object.ReferenceEquals(overflowPanel.Children[overflowIndex], generatedChild))
                    {
                        overflowPanel.Children.Insert(overflowIndex, generatedChild);
                    }

                    RibbonQuickAccessToolBar.SetIsOverflowItem(generatedChild, true);
                    overflowIndex++;
                }
            }

            // If necessary, set HasOverflowItems and invalidate the overflow panel's measure.
            if (QAT != null)
            {
                if (QAT.HasOverflowItems != sendToOverflow)
                {
                    QAT.HasOverflowItems = sendToOverflow;

                    // HasOverflowItems has changed, but the Grid that holds OverflowButtonHost does not automatically remeasure since it is already in its measure pass.
                    // Therefore, we must dispatch a call to remeasure that Grid after this current pass has completed.
                    Dispatcher.BeginInvoke((Action) delegate()
                    {
                        UIElement parent = VisualTreeHelper.GetParent(this) as UIElement;
                        if (parent != null)
                        {
                            parent.InvalidateMeasure();
                        }
                    },
                                           DispatcherPriority.Normal,
                                           null);
                }

                if (sendToOverflow &&
                    QAT.OverflowPanel != null)
                {
                    QAT.OverflowPanel.InvalidateMeasure();
                }
            }

#if DEBUG
            ValidateMeasure();
#endif

            return(panelDesiredSize);
        }
        private void SaveQatItems(RibbonQuickAccessToolBar qat)
        {
            if (qat != null)
            {
                QatItemCollection qatItems = new QatItemCollection();
                QatItemCollection remainingItems = new QatItemCollection();

                if (qat.Items.Count > 0)
                {
                    for (int qatIndex = 0; qatIndex < qat.Items.Count; qatIndex++)
                    {
                        object instance = qat.Items[qatIndex];
                        bool isSplitHeader = false;

                        if (instance is FrameworkElement)
                        {
                            FrameworkElement element = (FrameworkElement)instance;

                            if (((FrameworkElement)instance).DataContext != null)
                            {
                                instance = ((FrameworkElement)instance).DataContext;
                                isSplitHeader =
                                    (instance is SplitMenuItemData && element is ButtonBase) ||
                                    (instance is SplitButtonData && element is ButtonBase);
                            }
                        }

                        QatItem qatItem = new QatItem(instance, isSplitHeader);
                        qatItems.Add(qatItem);
                        remainingItems.Add(qatItem);
                    }

                    for (int tabIndex = 0; tabIndex < ribbon.Items.Count && remainingItems.Count > 0; tabIndex++)
                    {
                        RibbonTab tab = ribbon.Items[tabIndex] as RibbonTab;
                        SaveQatItemsAmongChildren(remainingItems, tab, tabIndex);
                    }
                }

                XmlWriter xmlWriter = XmlWriter.Create(_qatFileName);
                XamlWriter.Save(qatItems, xmlWriter);
                xmlWriter.Close();
            }
        }
        private void LoadQatItems(RibbonQuickAccessToolBar qat)
        {
            if (qat != null)
            {
                if (File.Exists(_qatFileName))
                {
                    XmlReader xmlReader = XmlReader.Create(_qatFileName);
                    QatItemCollection qatItems = (QatItemCollection)XamlReader.Load(xmlReader);
                    xmlReader.Close();
                    if (qatItems != null)
                    {
                        int remainingItemsCount = qatItems.Count;
                        QatItemCollection matchedItems = new QatItemCollection();

                        if (qatItems.Count > 0)
                        {
                            for (int tabIndex = 0; tabIndex < ribbon.Items.Count && remainingItemsCount > 0; tabIndex++)
                            {
                                matchedItems.Clear();
                                for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                                {
                                    QatItem qatItem = qatItems[qatIndex];
                                    if (qatItem.ControlIndices[0] == tabIndex)
                                    {
                                        matchedItems.Add(qatItem);
                                    }
                                }

                                RibbonTab tab = ribbon.Items[tabIndex] as RibbonTab;
                                if (tab != null)
                                {
                                    LoadQatItemsAmongChildren(matchedItems, 0, tabIndex, tab, ref remainingItemsCount);
                                }
                            }

                            for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                            {
                                QatItem qatItem = qatItems[qatIndex];
                                Control control = qatItem.Instance as Control;
                                if (control != null)
                                {
                                    if (RibbonCommands.AddToQuickAccessToolBarCommand.CanExecute(null, control))
                                    {
                                        RibbonCommands.AddToQuickAccessToolBarCommand.Execute(null, control);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 20
0
 public KeyTipAutoGenerationElements(RibbonQuickAccessToolBar quickAccessToolBar)
 {
     QuickAccessToolBar = quickAccessToolBar;
 }
Esempio n. 21
0
        private static void OnContextMenuClosingThunk(object sender, ContextMenuEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            qat.OnContextMenuClosingInternal();
        }
Esempio n. 22
0
        private static void OnMouseDownThunk(object sender, MouseButtonEventArgs e)
        {
            RibbonQuickAccessToolBar qat = (RibbonQuickAccessToolBar)sender;

            qat.OnAnyMouseDown();
        }