/// <summary>
        /// Called whenever RibbonTabHeaders are measured
        /// Sums up DesiredSize.Width of each RibbonTabHeader belonging to a ContextualTabGroup and stores it as ContextualTabGroup.TabsDesiredWidth.
        /// </summary>
        private void NotifyDesiredWidthChanged()
        {
            // Invalidate ContextualTabHeadersPanel
            RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;

            if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null)
            {
                foreach (RibbonContextualTabGroup tabGroup in groupHeaderItemsControl.InternalItemsHost.Children)
                {
                    tabGroup.TabsDesiredWidth          = 0.0;
                    tabGroup.DesiredExtraPaddingPerTab = 0.0;
                }
            }

            foreach (UIElement element in InternalChildren)
            {
                RibbonTabHeader tabHeader = element as RibbonTabHeader;
                if (tabHeader != null && tabHeader.IsVisible && tabHeader.IsContextualTab)
                {
                    RibbonContextualTabGroup tabGroup = tabHeader.ContextualTabGroup;
                    if (tabGroup != null)
                    {
                        double previousTabCount = 0;
                        if (!DoubleUtil.IsZero(tabGroup.DesiredExtraPaddingPerTab))
                        {
                            previousTabCount = (tabGroup.IdealDesiredWidth - tabGroup.TabsDesiredWidth) / tabGroup.DesiredExtraPaddingPerTab;
                        }
                        tabGroup.TabsDesiredWidth += tabHeader.DesiredSize.Width;
                        // compute new average
                        tabGroup.DesiredExtraPaddingPerTab = (tabGroup.IdealDesiredWidth - tabGroup.TabsDesiredWidth) / (previousTabCount + 1);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     This method is invoked when the IsItemsHost property changes.
        /// </summary>
        /// <param name="oldIsItemsHost">The old value of the IsItemsHost property.</param>
        /// <param name="newIsItemsHost">The new value of the IsItemsHost property.</param>
        protected override void OnIsItemsHostChanged(bool oldIsItemsHost, bool newIsItemsHost)
        {
            base.OnIsItemsHostChanged(oldIsItemsHost, newIsItemsHost);

            if (newIsItemsHost)
            {
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = ParentItemsControl;
                if (groupHeaderItemsControl != null)
                {
                    IItemContainerGenerator generator = groupHeaderItemsControl.ItemContainerGenerator as IItemContainerGenerator;
                    if (generator != null && generator.GetItemContainerGeneratorForPanel(this) == generator)
                    {
                        groupHeaderItemsControl.InternalItemsHost = this;
                    }
                }
            }
            else
            {
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = ParentItemsControl;
                if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost == this)
                {
                    groupHeaderItemsControl.InternalItemsHost = null;
                }
            }
        }
Пример #3
0
        /// <summary>
        ///     Arranges contextual tab headers
        /// </summary>
        private void ArrangeContextualTabHeaders(Size arrangeSize,
                                                 Ribbon ribbon,
                                                 Dictionary <object, List <RibbonTabHeaderAndIndex> > contextualTabHeaders,
                                                 ref int displayIndex,
                                                 ref double childX)
        {
            if (ribbon != null)
            {
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = ribbon.ContextualTabGroupItemsControl;
                if (groupHeaderItemsControl != null)
                {
                    if (groupHeaderItemsControl.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                    {
                        int groupHeaderCount = groupHeaderItemsControl.Items.Count;
                        for (int i = 0; i < groupHeaderCount; i++)
                        {
                            RibbonContextualTabGroup groupHeader = groupHeaderItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as RibbonContextualTabGroup;
                            if (groupHeader != null)
                            {
                                object contextualTabGroupHeader = groupHeader.Header;
                                if (contextualTabGroupHeader != null && contextualTabHeaders.ContainsKey(contextualTabGroupHeader))
                                {
                                    foreach (RibbonTabHeaderAndIndex headerAndIndex in contextualTabHeaders[contextualTabGroupHeader])
                                    {
                                        RibbonTabHeader child = headerAndIndex.RibbonTabHeader;
                                        Debug.Assert(child != null);
                                        child.InvalidateVisual();
                                        child.Arrange(new Rect(childX - HorizontalOffset, arrangeSize.Height - child.DesiredSize.Height, child.DesiredSize.Width, child.DesiredSize.Height));
                                        childX += child.DesiredSize.Width;

                                        ribbon.TabDisplayIndexToIndexMap[displayIndex]         = headerAndIndex.Index;
                                        ribbon.TabIndexToDisplayIndexMap[headerAndIndex.Index] = displayIndex;
                                        displayIndex++;
                                    }

                                    contextualTabHeaders.Remove(contextualTabGroupHeader);
                                }
                            }
                        }

                        RibbonContextualTabGroupsPanel contextualTabGroupsPanel = groupHeaderItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel;
                        if (contextualTabGroupsPanel != null)
                        {
                            contextualTabGroupsPanel.WaitingForMeasure = false;
                        }
                    }
                    else
                    {
                        // Tell the ContextualTabGroupsPanel that we are waiting on its Measure.
                        RibbonContextualTabGroupsPanel contextualTabGroupsPanel = groupHeaderItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel;
                        if (contextualTabGroupsPanel != null)
                        {
                            contextualTabGroupsPanel.WaitingForMeasure = true;
                        }
                    }
                }
            }
        }
        private void UpdateWindowStateVisuals()
        {
            if (WindowState == WindowState.Maximized)
            {
                double borderWidth = 3;

                try
                {
                    ribbon.FindChild <FrameworkElement>("QatTopHost").Margin     = new Thickness(0, borderWidth, 0, -borderWidth);
                    ribbon.FindChild <FrameworkElement>("PART_TitleHost").Margin = new Thickness(0, borderWidth + 3, 0, -(borderWidth + 3));

                    RibbonContextualTabGroupItemsControl rctgic = ribbon.FindChild <RibbonContextualTabGroupItemsControl>("PART_ContextualTabGroupItemsControl");
                    rctgic.Margin = new Thickness(0, 1, 0, -2);
                    foreach (RibbonContextualTabGroup each in rctgic.InternalItemsHost.Children)
                    {
                        each.Height = 53;
                    }
                }
                catch { }

                maximizeRestoreButton.Content = FindResource("RestoreButtonKey");
                maximizeRestoreButton.ToolTip = "Restore Down";

                outerGrid.Margin        = new Thickness(SystemParameters.BorderWidth + 2, SystemParameters.BorderWidth + 1, SystemParameters.BorderWidth + 2, SystemParameters.BorderWidth + 2);
                windowBorder.Visibility = Visibility.Collapsed;
                minimizeButton.Margin   = new Thickness(0, -2, 0, 2);

                WindowChrome chrome = WindowChrome.GetWindowChrome(this);
                chrome.ResizeBorderThickness = new Thickness(0);
            }
            else if (WindowState == WindowState.Normal)
            {
                try
                {
                    ribbon.FindChild <FrameworkElement>("QatTopHost").Margin     = new Thickness(0, 3, 0, -3);
                    ribbon.FindChild <FrameworkElement>("PART_TitleHost").Margin = new Thickness(0, 7, 0, -7);

                    RibbonContextualTabGroupItemsControl rctgic = ribbon.FindChild <RibbonContextualTabGroupItemsControl>("PART_ContextualTabGroupItemsControl");
                    rctgic.Margin = new Thickness(0, 0, 0, -2);
                    foreach (RibbonContextualTabGroup each in rctgic.InternalItemsHost.Children)
                    {
                        each.Height = 54;
                    }
                }
                catch { }

                maximizeRestoreButton.Content = FindResource("MaximizeButtonKey");
                maximizeRestoreButton.ToolTip = "Maximize";
                outerGrid.Margin        = new Thickness(0);
                windowBorder.Visibility = Visibility.Visible;
                minimizeButton.Margin   = new Thickness(0);

                WindowChrome chrome = WindowChrome.GetWindowChrome(this);
                chrome.ResizeBorderThickness = new Thickness(1);
            }
        }
        private static object CoerceVisibility(DependencyObject d, object baseValue)
        {
            RibbonContextualTabGroupItemsControl headerItemsControl = (RibbonContextualTabGroupItemsControl)d;

            if (headerItemsControl.ForceCollapse)
            {
                return(Visibility.Collapsed);
            }
            return(baseValue);
        }
        private static object CoerceItemContainerStyle(DependencyObject d, object baseValue)
        {
            RibbonContextualTabGroupItemsControl me = (RibbonContextualTabGroupItemsControl)d;

            return(PropertyHelper.GetCoercedTransferPropertyValue(
                       me,
                       baseValue,
                       ItemContainerStyleProperty,
                       me.Ribbon,
                       Ribbon.ContextualTabGroupStyleProperty));
        }
Пример #7
0
        /// <summary>
        ///     Arrange
        /// </summary>
        protected override Size ArrangeOverride(Size finalSize)
        {
            // Note: The logic below assumes that the TabHeaders belonging to inactive
            // ContextualTabGroups have their IsVisible set to false.

            UIElementCollection children = InternalChildren;
            int    childCount            = children.Count;
            double childX = 0.0;
            Dictionary <object, List <RibbonTabHeaderAndIndex> > contextualTabHeaders = new Dictionary <object, List <RibbonTabHeaderAndIndex> >();
            Ribbon ribbon = Ribbon;

            if (ribbon != null)
            {
                ribbon.TabDisplayIndexToIndexMap.Clear();
                ribbon.TabIndexToDisplayIndexMap.Clear();
            }
            int displayIndex = 0;

            ArrangeRegularTabHeaders(finalSize,
                                     ribbon,
                                     contextualTabHeaders,
                                     ref displayIndex,
                                     ref childX);

            ArrangeContextualTabHeaders(finalSize,
                                        ribbon,
                                        contextualTabHeaders,
                                        ref displayIndex,
                                        ref childX);


            // this arrange happens after the RibbonTitlePanel arrange
            // so we need to update the RibbonContextualTabGroup positions whenever RibbonTabHeaders move around
            if (Ribbon != null)
            {
                // Invalidate TitlePanel
                if (Ribbon.RibbonTitlePanel != null)
                {
                    Ribbon.RibbonTitlePanel.InvalidateMeasure();
                    Ribbon.RibbonTitlePanel.InvalidateArrange();
                }

                // Invalidate ContextualTabHeadersPanel
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;
                if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null)
                {
                    groupHeaderItemsControl.InternalItemsHost.InvalidateArrange();
                }
            }

            InvalidateVisual();

            return(finalSize);
        }
        /// <summary>
        ///     Measure
        /// </summary>
        protected override Size MeasureOverride(Size availableSize)
        {
            // Note: The logic below assumes that the TabHeaders belonging to inactive
            // ContextualTabGroups have their IsVisible set to false.

            //_separatorOpacity = 0.0;
            Size desiredSize = new Size();

            UIElementCollection children = InternalChildren;

            if (children.Count == 0)
            {
                return(desiredSize);
            }

            Size   childConstraint  = new Size(double.PositiveInfinity, availableSize.Height);
            int    countRegularTabs = 0;
            double totalDefaultPaddingAllTabHeaders     = 0;
            double totalDefaultPaddingRegularTabHeaders = 0;
            double totalDesiredWidthRegularTabHeaders   = 0;
            bool   showRegularTabHeaderToolTips         = false;
            bool   showContextualTabHeaderToolTips      = false;
            int    countVisibleTabs = 0;

            // Measure all TabHeaders to fit their content
            // desiredSize should hold the total size required to fit all TabHeaders
            desiredSize = InitialMeasure(childConstraint,
                                         out totalDefaultPaddingAllTabHeaders,
                                         out totalDefaultPaddingRegularTabHeaders,
                                         out totalDesiredWidthRegularTabHeaders,
                                         out countRegularTabs,
                                         out countVisibleTabs);

            int countContextualTabs = countVisibleTabs - countRegularTabs;

            SpaceAvailable = 0.0;
            double overflowWidth = desiredSize.Width - availableSize.Width;             // Total overflow width

            if (DoubleUtil.GreaterThan(overflowWidth, 0))
            {
                // Calculate max tab width if tab clipping is necessary
                double totalClipWidthRegularTabHeaders    = 0;                               // How much pixels we need to clip regular tabs
                double totalClipWidthContextualTabHeaders = 0;                               // How much pixels we need to clip contextual tabs

                if (DoubleUtil.GreaterThan(overflowWidth, totalDefaultPaddingAllTabHeaders)) // Clipping is necessary - all tabs padding will we 0
                {
                    showRegularTabHeaderToolTips    = true;
                    totalClipWidthRegularTabHeaders = overflowWidth - totalDefaultPaddingAllTabHeaders;                     // Try to use the whole totalClipAmount in the regular tabs
                }

                double maxRegularTabHeaderWidth = CalculateMaxTabHeaderWidth(totalClipWidthRegularTabHeaders, false);
                if (DoubleUtil.AreClose(maxRegularTabHeaderWidth, _tabHeaderMinWidth))                 // Regular tabs are clipped to the min size -  need to clip contextual tabs
                {
                    showContextualTabHeaderToolTips = true;
                    double totalClipAmount = overflowWidth - totalDefaultPaddingAllTabHeaders;
                    double usedClipAmount  = totalDesiredWidthRegularTabHeaders - totalDefaultPaddingRegularTabHeaders - (_tabHeaderMinWidth * countRegularTabs);
                    totalClipWidthContextualTabHeaders = totalClipAmount - usedClipAmount;                     // Remaining clipping amount
                }

                double maxContextualTabHeaderWidth      = CalculateMaxTabHeaderWidth(totalClipWidthContextualTabHeaders, true);
                double reducePaddingRegularTabHeader    = 0;
                double reducePaddingContextualTabHeader = 0;

                if (DoubleUtil.GreaterThanOrClose(totalDefaultPaddingRegularTabHeaders, overflowWidth))
                {
                    reducePaddingRegularTabHeader = (0.5 * overflowWidth) / countRegularTabs;
                    //_separatorOpacity = Math.Max(0.0, reducePaddingRegularTabHeader * 0.2);
                }
                else
                {
                    //_separatorOpacity = 1.0;
                    reducePaddingRegularTabHeader = double.PositiveInfinity;
                    // If countContextualTabs==0 then reducePaddingContextualTab will become Infinity
                    reducePaddingContextualTabHeader = (0.5 * (overflowWidth - totalDefaultPaddingRegularTabHeaders)) / (countVisibleTabs - countRegularTabs);
                }

                desiredSize = FinalMeasure(childConstraint,
                                           reducePaddingContextualTabHeader,
                                           reducePaddingRegularTabHeader,
                                           maxContextualTabHeaderWidth,
                                           maxRegularTabHeaderWidth);
            }
            else if (countContextualTabs > 0)
            {
                // After assigning DefaultPadding, we are left with extra space.
                // If contextual tabs need that extra space, assign them more padding.
                NotifyDesiredWidthChanged();
                double spaceAvailable            = availableSize.Width - desiredSize.Width;
                double availableExtraWidthPerTab = CalculateMaxPadding(spaceAvailable);

                foreach (UIElement child in InternalChildren)
                {
                    RibbonTabHeader ribbonTabHeader = child as RibbonTabHeader;
                    if (ribbonTabHeader != null && ribbonTabHeader.IsVisible && ribbonTabHeader.IsContextualTab)
                    {
                        RibbonContextualTabGroup ctg = ribbonTabHeader.ContextualTabGroup;
                        if (ctg != null && DoubleUtil.GreaterThan(ctg.DesiredExtraPaddingPerTab, 0.0))
                        {
                            double desiredExtraPaddingPerTab = ctg.DesiredExtraPaddingPerTab;
                            double availableExtraWidth       = Math.Min(desiredExtraPaddingPerTab, availableExtraWidthPerTab);

                            Thickness newPadding = ribbonTabHeader.Padding;
                            newPadding.Left        += availableExtraWidth * 0.5;
                            newPadding.Right       += availableExtraWidth * 0.5;
                            ribbonTabHeader.Padding = newPadding;

                            // Remeasure with added padding
                            desiredSize.Width -= ribbonTabHeader.DesiredSize.Width;
                            ribbonTabHeader.Measure(new Size(Double.MaxValue, childConstraint.Height));
                            desiredSize.Width += ribbonTabHeader.DesiredSize.Width;
                        }
                    }
                }
            }

            // If the difference between desiredWidth and constraintWidth is less
            // than 1e-10 then assume that both are same. This avoids unnecessary
            // inequalities in extent and viewport resulting in spontaneous
            // flickering of scroll button.
            if (Math.Abs(desiredSize.Width - availableSize.Width) < _desiredWidthEpsilon)
            {
                desiredSize.Width = availableSize.Width;
            }

            SpaceAvailable = availableSize.Width - desiredSize.Width;
            // Update ContextualTabGroup.TabsDesiredWidth
            NotifyDesiredWidthChanged();

            // Update whether tooltips should be shown.
            UpdateToolTips(showRegularTabHeaderToolTips, showContextualTabHeaderToolTips);

            VerifyScrollData(availableSize.Width, desiredSize.Width);


            // Invalidate ContextualTabHeadersPanel
            if (Ribbon != null)
            {
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;
                if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null)
                {
                    groupHeaderItemsControl.InternalItemsHost.InvalidateMeasure();
                }
            }

            return(desiredSize);
        }
Пример #9
0
        /// <summary>
        ///   Measures the children of the RibbonTitlePanel.
        /// </summary>
        /// <param name="constraint">The space available for layout.</param>
        /// <returns>Returns the RibbonTitlePanel's desired size as determined by measurement of its children.</returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            Size desiredSize = new Size();
            int  count       = Children.Count;

            if (count == 0)
            {
                return(desiredSize);
            }

            double startContextualTabX = availableSize.Width;
            double endContextualTabX   = 0.0;

            RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;

            if (groupHeaderItemsControl != null && groupHeaderItemsControl.Visibility == Visibility.Visible)
            {
                // A dummy measure to ensure containers are generated.
                // We need to know FirstContextualTabHeader and LastContextualTabHeader
                if (groupHeaderItemsControl.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
                {
                    groupHeaderItemsControl.Measure(availableSize);
                }

                // Calculate start and end positions
                RibbonContextualTabGroup firstContextualTab = groupHeaderItemsControl.FirstContextualTabHeader;
                if (firstContextualTab != null)
                {
                    startContextualTabX = Math.Min(CalculateContextualTabGroupStartX(firstContextualTab), availableSize.Width);
                }

                RibbonContextualTabGroup lastContextualTab = groupHeaderItemsControl.LastContextualTabHeader;
                if (lastContextualTab != null)
                {
                    endContextualTabX = Math.Min(CalculateContextualTabGroupEndX(lastContextualTab), availableSize.Width);
                }

                groupHeaderItemsControl.Measure(new Size(Math.Max(endContextualTabX - startContextualTabX, 0), availableSize.Height));
                desiredSize.Width += groupHeaderItemsControl.DesiredSize.Width;
                desiredSize.Height = Math.Max(desiredSize.Height, groupHeaderItemsControl.DesiredSize.Height);
            }

            FrameworkElement qat       = Ribbon.QatTopHost as FrameworkElement;
            FrameworkElement titleHost = Ribbon.TitleHost as FrameworkElement;

            if (qat != null && titleHost != null)
            {
                double availableToQat = 0.0, availableToTitle;
                double leftSpace, rightSpace;

                // If ribbon is not collapsed and QAT is on top
                if (qat.Visibility == Visibility.Visible)
                {
                    rightSpace = availableSize.Width - endContextualTabX;
                    // 1) if there is no room on the right for Title
                    // 2) or when there are no contextual tabs (i.e. endContextualTabX==0), then rightSpace=entire width
                    //  want to ensure MinWidth for title if possible
                    if ((DoubleUtil.LessThan(rightSpace, titleHost.MinWidth) ||
                         DoubleUtil.GreaterThan(startContextualTabX, endContextualTabX)) &&
                        DoubleUtil.GreaterThan(startContextualTabX, titleHost.MinWidth))
                    {
                        // Leave titleHost.MinWidth at the left of ContextualTabGroupItemsControl for TitleHost
                        availableToQat = startContextualTabX - titleHost.MinWidth;
                    }
                    else
                    {
                        // Give QAT space from 0 to start of ContextualTabGroupItemsControl
                        availableToQat = startContextualTabX;
                    }
                    // The size computed could be negative because of invalid
                    // transforms due to invalid arrange. Assume that the space
                    // available is 0 in such cases and assume that validation of
                    // transforms at a later point of time will fix the situation.
                    availableToQat = Math.Max(availableToQat, 0);

                    // Measure QAT
                    qat.Measure(new Size(availableToQat, availableSize.Height));
                    availableToQat = qat.DesiredSize.Width;

                    desiredSize.Width += availableToQat;
                    desiredSize.Height = Math.Max(desiredSize.Height, qat.DesiredSize.Height);
                }

                // Measure TitleHost.
                // We try to give it titleHost.MinWidth, but it may get less than that when QAT has already reached qat.MinWidth
                endContextualTabX = Math.Max(endContextualTabX, availableToQat);
                rightSpace        = availableSize.Width - endContextualTabX;
                leftSpace         = startContextualTabX - availableToQat;

                // first measure to title's full size and see if it can fit entirely to the left
                titleHost.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                if (DoubleUtil.LessThanOrClose(titleHost.DesiredSize.Width, leftSpace))
                {
                    availableToTitle = leftSpace;
                }
                else
                {
                    // title takes best of right or left
                    availableToTitle = Math.Max(leftSpace, rightSpace);
                }
                // The size computed could be negative because of invalid
                // transforms due to invalid arrange. Assume that the space
                // available is 0 in such cases and assume that validation of
                // transforms at a later point of time will fix the situation.
                availableToTitle = Math.Max(availableToTitle, 0);

                titleHost.Measure(new Size(availableToTitle, availableSize.Height));
                desiredSize.Width += titleHost.DesiredSize.Width;
                desiredSize.Height = Math.Max(desiredSize.Height, titleHost.DesiredSize.Height);
            }

            desiredSize.Width = Math.Min(desiredSize.Width, availableSize.Width);             // Prevent clipping
            return(desiredSize);
        }
Пример #10
0
        /// <summary>
        ///   Arranges the children of the RibbonTitlePanel.
        /// </summary>
        /// <param name="arrangeSize">The arranged size of the TitlePanel.</param>
        /// <returns>The size at which the TitlePanel was arranged.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            double x = 0.0;
            double width;
            double height;

            double startContextualTabX = 0;
            double endContextualTabX   = 0;

            // Arrange ContextualTabHeaders
            RibbonContextualTabGroupItemsControl tabGroups = Ribbon.ContextualTabGroupItemsControl;

            if (tabGroups != null && tabGroups.Visibility == Visibility.Visible)
            {
                RibbonContextualTabGroup firstContextualTab = tabGroups.FirstContextualTabHeader;
                if (firstContextualTab != null)
                {
                    startContextualTabX = Math.Min(CalculateContextualTabGroupStartX(firstContextualTab), finalSize.Width);
                }

                endContextualTabX = Math.Min(startContextualTabX + tabGroups.DesiredSize.Width, finalSize.Width);
                tabGroups.Arrange(new Rect(startContextualTabX, finalSize.Height - tabGroups.DesiredSize.Height, tabGroups.DesiredSize.Width, tabGroups.DesiredSize.Height));
            }

            // Arrange QuickAccessToolbar
            double    qatDesiredWidth = 0.0;
            UIElement qat             = Ribbon.QatTopHost;

            if (qat != null)
            {
                qatDesiredWidth = qat.DesiredSize.Width;
                qat.Arrange(new Rect(0, 0.0, qatDesiredWidth, qat.DesiredSize.Height));
            }

            endContextualTabX = Math.Max(endContextualTabX, qatDesiredWidth);

            // Arrange the title
            UIElement titleHost = Ribbon.TitleHost;

            if (titleHost != null)
            {
                x      = 0.0;
                width  = titleHost.DesiredSize.Width;
                height = titleHost.DesiredSize.Height;
                double leftSpace = startContextualTabX - qatDesiredWidth;

                // If title can fit entirely to the left, then arrange on the left
                // i.e. between QAT and CTGHeaders
                if (DoubleUtil.LessThanOrClose(width, leftSpace))
                {
                    x = qatDesiredWidth;
                }
                else
                {
                    // Arrange to the right of CTGHeaders.
                    x = endContextualTabX;
                }

                titleHost.Arrange(new Rect(x, 0.0, width, height));
            }

            return(finalSize);
        }
Пример #11
0
 public RibbonContextualTabGroupItemsControlAutomationPeer(RibbonContextualTabGroupItemsControl owner)
     : base(owner)
 {
 }
        private void TitleHack()
        {
            if (ribbonTitlePanel == null)
            {
                ribbonTitlePanel = ribbon.FindChild <RibbonTitlePanel>("PART_TitlePanel");
            }

            if (ribbonQatTopHost == null)
            {
                ribbonQatTopHost = ribbon.FindChild <FrameworkElement>("QatTopHost");
            }

            if (ribbonTitleHost == null)
            {
                ribbonTitleHost = ribbon.FindChild <FrameworkElement>("PART_TitleHost");
            }

            if (ribbonContextualTabGroup == null)
            {
                ribbonContextualTabGroup = ribbon.FindChild <RibbonContextualTabGroupItemsControl>("PART_ContextualTabGroupItemsControl");
            }

            double qatTopHostLeft = ribbonQatTopHost.TransformToAncestor(ribbonTitlePanel).Transform(new Point(0, 0)).X;
            double tabGroupLeft   = ribbonContextualTabGroup.TransformToAncestor(ribbonTitlePanel).Transform(new Point(0, 0)).X;

            double width = ribbonTitlePanel.ActualWidth;

            bool areContextualTabGroupsVisible = false;

            foreach (RibbonContextualTabGroup group in ribbonContextualTabGroup.Items)
            {
                if (group.Visibility == Visibility.Visible)
                {
                    areContextualTabGroupsVisible = true;
                    break;
                }
            }

            if (ribbonTitlePanel.ActualWidth - (tabGroupLeft + ribbonContextualTabGroup.ActualWidth) >= tabGroupLeft)
            {
                // Title is positioned on right of ContextualTabGroups.

                if (areContextualTabGroupsVisible && ribbonContextualTabGroup.Visibility == Visibility.Visible)
                {
                    width -= ribbonContextualTabGroup.ActualWidth;
                    width -= tabGroupLeft - qatTopHostLeft;
                }
                else
                {
                    width -= ribbonQatTopHost.ActualWidth;
                }
            }
            else
            {
                // Title is positioned on left on ContextualTabGroups.

                if (areContextualTabGroupsVisible && ribbonContextualTabGroup.Visibility == Visibility.Visible)
                {
                    width = tabGroupLeft - qatTopHostLeft;
                }
                else
                {
                    width -= ribbonQatTopHost.ActualWidth;
                }
            }

            ribbonTitleHost.Width = width > 0 ? width : Double.NaN;
        }