示例#1
0
        /// <summary>
        /// Change the RibbonSize for every IRibbonControl inside this group.
        /// </summary>
        private void ChangeControlSizes()
        {
            int  level     = ReductionLevel;
            int  maxLevels = GetMaxLevel();
            bool minimized = level >= maxLevels;

            IsMinimized = minimized;
            if (minimized)
            {
                level = 0;
            }

            for (int i = 0; i < Controls.Count; i++)
            {
                UIElement      e       = Controls[i];
                IRibbonGallery gallery = e as IRibbonGallery;
                if (gallery != null)
                {
                    int columns = GetGalleryColumns(e, level, maxLevels);
                    gallery.Columns     = columns;
                    gallery.IsCollapsed = columns == 0;
                    gallery.SetDropDownColumns(GetGalleryColumns(e, 0, maxLevels));
                }
                else
                {
                    if (e is IRibbonControl)
                    {
                        RibbonSize size = GetControlSize(e, level, i);
                        RibbonBar.SetSize(e, size);
                    }
                }
            }
            InvalidateMeasure();
            UpdateLayout();
        }
示例#2
0
 protected virtual void OnButtonClickEvent(object sender, RoutedEventArgs e)
 {
     if (IsDropDownPressed)
     {
         if (e.OriginalSource == this)
         {
             return;
         }
         DependencyObject dep = e.OriginalSource as DependencyObject;
         if (!(e.OriginalSource is RibbonButton) && !(e.OriginalSource is RibbonDropDownButton))
         {
             if (dep != null && !RibbonOption.GetCloseDropDownOnClick(dep))
             {
                 return;
             }
         }
         else
         {
             if (dep != null && !RibbonBar.GetAffectsDropDown(dep))
             {
                 return;
             }
         }
         if (IsAncestorType(e.OriginalSource, typeof(RibbonComboBox)))
         {
             return;
         }
         IsDropDownPressed = false;
     }
 }
示例#3
0
 private bool CanControlBeSmall(UIElement e)
 {
     if ((e is IRibbonControl) && !(e is IRibbonLargeControl))
     {
         RibbonSize min = RibbonBar.GetMinSize(e);
         return(min < RibbonSize.Large);
     }
     return(e.DesiredSize.Height <= InternalGroupPanel.MaxSmallHeight);
 }
示例#4
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            IRibbonButton b = element as IRibbonButton;

            if (b != null)
            {
                RibbonBar.SetSize(element, RibbonSize.Small);
            }
        }
示例#5
0
        private Size ArrangeOrMeasure(bool arrange)
        {
            double left     = 0;
            int    rowIndex = 0;
            int    maxRows  = 3;

            List <UIElement> rowElements = new List <UIElement>(maxRows);

            foreach (UIElement e in Children)
            {
                if (e.Visibility != Visibility.Visible)
                {
                    continue;
                }
                IRibbonControl ribbonControl = e as IRibbonControl;
                Size           dsize         = e.DesiredSize;
                if (dsize.Height > smallHeight)
                {
                    if (rowIndex > 0)
                    {
                        left    += ArrangeRow(rowElements, left, arrange);
                        rowIndex = 0;
                    }
                    if (arrange)
                    {
                        Size   size = e.DesiredSize;
                        double h    = Math.Max(smallHeight, size.Height);
                        e.Arrange(new Rect(left, 0, size.Width, h));
                    }
                    left += e.DesiredSize.Width;
                }
                else
                {
                    RibbonSize size = RibbonBar.GetSize(e);
                    if (size != RibbonSize.Minimized)
                    {
                        rowElements.Add(e);
                        if (++rowIndex == maxRows)
                        {
                            left    += ArrangeRow(rowElements, left, arrange);
                            rowIndex = 0;
                        }
                    }
                }
            }
            left += ArrangeRow(rowElements, left, arrange);

            left = Math.Max(32, left);
            return(new Size(left, smallHeight * 3));
        }
示例#6
0
        //Gets the maximum possible ReductionLevel that would change any of the controls.
        private int GetMaxLevel()
        {
            int max = 1;

            foreach (UIElement e in Controls)
            {
                if (e is IRibbonControl)
                {
                    RibbonSizeCollection reduction = RibbonBar.GetReduction(e);
                    int m = reduction != null ? reduction.Count : 3;
                    max = Math.Max(max, m);
                }
                if (e is IRibbonGallery)
                {
                    RibbonGalleryColumns columns = RibbonGallery.GetReductionColumns(e);
                    int m = columns != null ? columns.Count : 3;
                    max = Math.Max(max, m);
                }
            }
            return(max);
        }
示例#7
0
        /// <summary>
        /// Ensure the position of the tooltip to be exactly below the <see cref="T:RibbonBar"/> if available, otherwise use default positioning.
        /// </summary>
        private CustomPopupPlacement[] PopupPlacement(Size popupSize, Size targetSize, Point offset)
        {
            RibbonBar ribbon = GetRibbonBar();
            double    y      = ActualHeight;
            double    x      = 0.0d;

            if (ribbon != null)
            {
                FrameworkElement owner = this.PlacementTarget as FrameworkElement;
                if (!(owner is RibbonApplicationMenu))
                {
                    if (owner.IsDescendantOf(ribbon))
                    {
                        Point p = ribbon.TranslatePoint(new Point(), owner);
                        y = ribbon.ActualHeight + p.Y;
                    }
                    else
                    {
                        Popup            popup = ribbon.Popup;
                        FrameworkElement child = popup.Child as FrameworkElement;
                        if (child != null)
                        {
                            Point p = child.TranslatePoint(new Point(), owner);
                            y = child.ActualHeight + p.Y;
                        }
                    }
                }
                else
                {
                    y = owner.ActualHeight + 4.0d;
                    x = 0d;
                }
            }

            CustomPopupPlacement placement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.Vertical);

            return(new CustomPopupPlacement[] { placement });
        }
示例#8
0
        protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint)
        {
            itemsHost.Children.Clear();
            if (overflowHost != null)
            {
                overflowHost.Children.Clear();
            }
            CreateMenuItems();
            foreach (UIElement e in GetToolbarItems())
            {
                RibbonBar.SetSize(e, RibbonSize.Small);
                itemsHost.Children.Add(e);
            }
            HasOverflowItems = false;
            Size maxSize = base.MeasureOverride(new Size(double.PositiveInfinity, constraint.Height));

            while (maxSize.Width > constraint.Width)
            {
                int n = itemsHost.Children.Count;
                if (n == 0)
                {
                    break;
                }
                UIElement e = itemsHost.Children[n - 1];
                InvalidateAncestorMeasure(e);
                itemsHost.Children.RemoveAt(n - 1);
                if (overflowHost != null)
                {
                    overflowHost.Children.Insert(0, e);
                    HasOverflowItems = true;
                }
                maxSize = base.MeasureOverride(new Size(double.PositiveInfinity, constraint.Height));
            }
            Size size = base.MeasureOverride(constraint);

            return(size);
        }
示例#9
0
        /// <summary>
        /// Gets the RibbonSize for a control for a specific level.
        /// </summary>
        /// <param name="control">The control for which to retreive a RibbonSize.</param>
        /// <param name="level">The reduction Level (0=large, 2=medium,3=small,4=minimized,...).</param>
        /// <param name="index">The index of the control in the group.</param>
        /// <returns>The RibbonSize for the control.</returns>
        RibbonSize GetControlSize(DependencyObject control, int level, int index)
        {
            RibbonSizeCollection reductions = RibbonBar.GetReduction(control);

            if (reductions != null && reductions.Count > 0)
            {
                level = Math.Max(0, Math.Min(level, reductions.Count - 1));
                return(reductions[level]);
            }
            RibbonSize size;

            switch (level)
            {
            case 0: size = GetDefaultSizeForLevel0(index); break;

            case 1: size = GetDefaultSizeForLevel1(index); break;

            case 2: size = GetDefaultSizeForLevel2(index); break;

            default: size = RibbonSize.Minimized; break;
            }

            RibbonSize min = RibbonBar.GetMinSize(control);
            RibbonSize max = RibbonBar.GetMaxSize(control);

            if (size < min)
            {
                size = min;
            }
            if (size > max)
            {
                size = max;
            }

            return(size);
        }
示例#10
0
        private static void alignGroupsLeft(object sender, ExecutedRoutedEventArgs e)
        {
            RibbonBar bar = (RibbonBar)sender;

            bar.AlignGroupsLeft();
        }
示例#11
0
        private static void collapseRibbonBar(object sender, ExecutedRoutedEventArgs e)
        {
            RibbonBar bar = (RibbonBar)sender;

            bar.IsExpanded = false;
        }
示例#12
0
        private static void IsQAPlacementBottomEnabled(object sender, CanExecuteRoutedEventArgs e)
        {
            RibbonBar bar = (RibbonBar)sender;

            e.CanExecute = bar.ToolbarPlacement == QAPlacement.Top;
        }
示例#13
0
        private static void QAPlacementBottom(object sender, ExecutedRoutedEventArgs e)
        {
            RibbonBar bar = (RibbonBar)sender;

            bar.ToolbarPlacement = QAPlacement.Bottom;
        }