Exemplo n.º 1
0
        // It just determines if any ancestor supports StarLayout and is not in StarLayoutPass mode.
        private bool IsAutoLayoutPass(double sumOfHeight, int childrenCount)
        {
            RibbonGalleryCategory category = (RibbonGalleryCategory)ItemsControl.GetItemsOwner(this);

            if (category != null)
            {
                // Adding virtual count of items and cumulative height to RGC for the purpose of calcualting
                // avg height as scrolling delta in RibbonGalleryCategoriesPanel.
                category.averageItemHeightInfo.count            = childrenCount;
                category.averageItemHeightInfo.cumulativeHeight = sumOfHeight;
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    RibbonGalleryCategoriesPanel categoriesPanel = (RibbonGalleryCategoriesPanel)gallery.ItemsHostSite;
                    if (categoriesPanel != null)
                    {
                        IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)categoriesPanel;
                        if (iContainsStarLayoutManager.StarLayoutManager != null)
                        {
                            return(!iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        // PreComputing MaxItemHeight and MaxItemWidth as the Measure algorithms of parent panels of Items will need it already
        // If it is in InRibbonGalleryMode.
        private void PreComputeMaxRibbonGalleryItemWidthAndHeight()
        {
            UIElementCollection children = InternalChildren;
            Size   childConstraint       = new Size(double.PositiveInfinity, double.PositiveInfinity);
            double maxItemHeight         = 0;
            int    childrenCount         = children.Count;
            double maxColumnWidth        = 0;

            for (int i = 0; i < childrenCount; i++)
            {
                RibbonGalleryCategory   child     = children[i] as RibbonGalleryCategory;
                RibbonGalleryItemsPanel itemPanel = child.ItemsHostSite as RibbonGalleryItemsPanel;
                if (itemPanel != null)
                {
                    int itemPanelChildrenCount = itemPanel.Children.Count;
                    for (int j = 0; j < itemPanelChildrenCount; j++)
                    {
                        RibbonGalleryItem item = (RibbonGalleryItem)itemPanel.Children[j];
                        item.Measure(childConstraint);
                        Size itemSize = item.DesiredSize;
                        maxColumnWidth = Math.Max(maxColumnWidth, itemSize.Width);
                        maxItemHeight  = Math.Max(maxItemHeight, itemSize.Height);
                    }
                }
            }

            RibbonGallery gallery = this.Gallery;

            if (gallery != null)
            {
                gallery.MaxItemHeight  = maxItemHeight;
                gallery.MaxColumnWidth = maxColumnWidth;
            }
        }
        /// <summary>
        /// call wrapper.BringIntoView
        /// </summary>
        void IScrollItemProvider.ScrollIntoView()
        {
            RibbonGalleryCategory category = GetWrapper() as RibbonGalleryCategory;

            if (category != null)
            {
                category.BringIntoView();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// call wrapper.BringIntoView
        /// </summary>
        void IScrollItemProvider.ScrollIntoView()
        {
            RibbonGalleryCategory category = GetOwningRibbonGalleryCategory();

            if (category != null)
            {
                category.BringIntoView();
            }
        }
        // Minimum number of Col must be shown is determined by this method
        private int GetMinColumnCount()
        {
            RibbonGalleryCategory category = Category;

            if (category != null)
            {
                return((int)category.MinColumnCount);
            }
            return(1);
        }
Exemplo n.º 6
0
        private static object CoerceItemContainerStyle(DependencyObject d, object baseValue)
        {
            RibbonGalleryCategory category = (RibbonGalleryCategory)d;

            return(PropertyHelper.GetCoercedTransferPropertyValue(category,
                                                                  baseValue,
                                                                  ItemsControl.ItemContainerStyleProperty,
                                                                  category.RibbonGallery,
                                                                  RibbonGallery.GalleryItemStyleProperty));
        }
Exemplo n.º 7
0
        // Minimum number of Col must be shown is determined by this method
        private int GetMinColumnCount()
        {
            RibbonGalleryCategory category = (RibbonGalleryCategory)ItemsControl.GetItemsOwner(this);

            if (category != null)
            {
                return((int)category.MinColumnCount);
            }
            return(1);
        }
        // Maximum number of Col must be shown is determined by this method
        private int GetMaxColumnCount()
        {
            RibbonGalleryCategory category = Category;

            if (category != null)
            {
                return((int)category.MaxColumnCount);
            }

            return(int.MaxValue);
        }
Exemplo n.º 9
0
        // Coerce MinColumnCount to retrieve the value defined on parent Gallery if it's not set here locally.
        private static object CoerceMinColumnCount(DependencyObject d, object baseValue)
        {
            RibbonGalleryCategory me = (RibbonGalleryCategory)d;

            return(PropertyHelper.GetCoercedTransferPropertyValue(
                       me,
                       baseValue,
                       MinColumnCountProperty,
                       me.RibbonGallery,
                       RibbonGallery.MinColumnCountProperty));
        }
Exemplo n.º 10
0
 static public RibbonGalleryItem CmbPick(RibbonGalleryCategory cat, string tag)
 {
     if (tag == null)
         return null;
     for (int i = 0; i < cat.Items.Count; i++)
     {
         RibbonGalleryItem item = (cat.Items[i] as RibbonGalleryItem);
         if (item.Tag != null && item.Tag.ToString().Equals(tag))
             return item;
     }
     return null;
 }
        private void AddScrollDeltaInfo(double sumOfHeight, int childrenCount)
        {
            RibbonGalleryCategory category = Category;

            if (category != null)
            {
                // Adding virtual count of items and cumulative height to RGC for the purpose of calcualting
                // avg height as scrolling delta in RibbonGalleryCategoriesPanel.
                category.averageItemHeightInfo.Count            = childrenCount;
                category.averageItemHeightInfo.CumulativeHeight = sumOfHeight;
            }
        }
Exemplo n.º 12
0
        internal RibbonGalleryItem GetOwningRibbonGalleryItem()
        {
            RibbonGalleryItem          owningRibbonGalleryItem    = null;
            ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer;

            if (itemsControlAutomationPeer != null)
            {
                RibbonGalleryCategory containingCategory = (RibbonGalleryCategory)(itemsControlAutomationPeer.Owner);
                if (containingCategory != null)
                {
                    owningRibbonGalleryItem = (RibbonGalleryItem)containingCategory.ItemContainerGenerator.ContainerFromItem(Item);
                }
            }
            return(owningRibbonGalleryItem);
        }
Exemplo n.º 13
0
        // InRibbonGalleryMode where the gallery is shown within Ribbon via InRibbonGallery and Arrange
        // becomes responsibility of InRibbonGalleryModeArrangeOverride.
        private Size InRibbonGalleryModeArrangeOverride(Size finalSize)
        {
            UIElementCollection children = this.Children;
            Rect rcChild = new Rect(finalSize);

            //
            // Seed scroll offset into rcChild.
            //
            if (IsScrolling)
            {
                rcChild.X = -1.0 * _scrollData._offset.X;
                rcChild.Y = -1.0 * _scrollData._offset.Y;
            }

            // Arrange and Position Children. over each other as the items being arranged in child
            // in a way to respect the offset of where previous category children are ending.
            // It's merged wrapping.
            for (int i = 0, count = children.Count; i < count; ++i)
            {
                RibbonGalleryCategory child = children[i] as RibbonGalleryCategory;

                if (child == null ||
                    child.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                rcChild.Width = Math.Max(finalSize.Width, child.DesiredSize.Width);
                child.Arrange(rcChild);
            }

            // Refresh the IsEnabled state of the InRibbonGallery's LineUp & LineDown buttons.
            RibbonGallery gallery = Gallery;

            if (gallery != null)
            {
                InRibbonGallery irg = gallery.ParentInRibbonGallery;
                if (irg != null &&
                    irg.IsInInRibbonMode)
                {
                    irg.CoerceValue(InRibbonGallery.CanLineUpProperty);
                    irg.CoerceValue(InRibbonGallery.CanLineDownProperty);
                }
            }

            return(DesiredSize);
        }
Exemplo n.º 14
0
        // Coerces the various visual's properties when InRibbonGallery attains in-Ribbon mode.
        private void CoerceVisibilityPropertiesOnRibbonGallery()
        {
            if (_firstGallery != null)
            {
                _firstGallery.CoerceValue(RibbonGallery.CanUserFilterProperty);
                _firstGallery.CoerceValue(ScrollViewer.VerticalScrollBarVisibilityProperty);

                for (int i = 0; i < _firstGallery.Items.Count; i++)
                {
                    RibbonGalleryCategory category = _firstGallery.ItemContainerGenerator.ContainerFromIndex(i) as RibbonGalleryCategory;
                    if (category != null)
                    {
                        category.CoerceValue(RibbonGalleryCategory.HeaderVisibilityProperty);
                    }
                }
            }
        }
Exemplo n.º 15
0
        // Gets the MaxColumnWidth if the shared scope is Gallery (gallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope)
        // then MaxColumnWidth is used which is defined on Gallery to lay out all Items as Uniform width columns in scope of Gallery
        // otherwise they layout as Uniform width column within the scope of current Category only.
        private double GetMaxColumnWidth()
        {
            RibbonGalleryCategory category = (RibbonGalleryCategory)ItemsControl.GetItemsOwner(this);

            if (category != null)
            {
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    if (gallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope)
                    {
                        return(gallery.MaxColumnWidth);
                    }
                }
            }
            return(_maxColumnWidth);
        }
Exemplo n.º 16
0
        // Coerce Max   ColumnCount to retrieve the value defined on parent Gallery if it's not set here locally.
        private static object CoerceMaxColumnCount(DependencyObject d, object baseValue)
        {
            RibbonGalleryCategory me = (RibbonGalleryCategory)d;
            int maxColumnCount       = (int)PropertyHelper.GetCoercedTransferPropertyValue(
                me,
                baseValue,
                MaxColumnCountProperty,
                me.RibbonGallery,
                RibbonGallery.MaxColumnCountProperty);

            if (maxColumnCount < (int)me.MinColumnCount)
            {
                return((int)me.MinColumnCount);
            }

            return(maxColumnCount);
        }
Exemplo n.º 17
0
        private static void OnIsHighlightedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonGalleryItem galleryItem = (RibbonGalleryItem)d;
            bool isHighlighted            = (bool)e.NewValue;

            RibbonGalleryCategory category = galleryItem.RibbonGalleryCategory;

            if (category != null)
            {
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    // Give the RibbonGallery a reference to this container and its data
                    object item = category.ItemContainerGenerator.ItemFromContainer(galleryItem);
                    gallery.ChangeHighlight(item, galleryItem, isHighlighted);
                }
            }
        }
Exemplo n.º 18
0
        private static void OnNotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonGalleryCategory galleryCategory = (RibbonGalleryCategory)d;

            galleryCategory.NotifyPropertyChanged(e);

            // This is for the layout related properties MinColumnCount/MaxColumnCount IsSharedColumnScope
            // and MaxColumnWidth on RibbonGallery/RibbonGalleryCategory. This calls InvalidateMeasure
            // for all the categories' ItemsPanel and they must use changed values.
            if (e.Property == MinColumnCountProperty || e.Property == MaxColumnCountProperty || e.Property == IsSharedColumnSizeScopeProperty || e.Property == ColumnsStretchToFillProperty)
            {
                RibbonGallery gallery = galleryCategory.RibbonGallery;
                if (gallery != null)
                {
                    gallery.InvalidateMeasureOnAllCategoriesPanel();
                }
            }
        }
Exemplo n.º 19
0
        // Sets the ArrangeWidth on Gallery if the shared scope is Gallery (gallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope)
        private void SetArrangeWidth(double value)
        {
            _arrangeWidth = value;

            RibbonGalleryCategory category = (RibbonGalleryCategory)ItemsControl.GetItemsOwner(this);

            if (category != null)
            {
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    if (gallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope)
                    {
                        gallery.ArrangeWidth        = value;
                        gallery.IsArrangeWidthValid = true;
                    }
                }
            }
        }
Exemplo n.º 20
0
        ///
        override public object GetPattern(PatternInterface patternInterface)
        {
            if (patternInterface == PatternInterface.ScrollItem)
            {
                return(this);
            }

            // Simply use GetWrapperPeer when available while integrating in PresentationFramework.dll
            RibbonGalleryCategory owningCategory = GetOwningRibbonGalleryCategory();

            if (owningCategory != null)
            {
                RibbonGalleryCategoryAutomationPeer owningPeer = (RibbonGalleryCategoryAutomationPeer)UIElementAutomationPeer.CreatePeerForElement(owningCategory);
                if (owningPeer != null)
                {
                    return(owningPeer.GetPattern(patternInterface));
                }
            }

            return(null);
        }
Exemplo n.º 21
0
 ///
 public RibbonGalleryCategoryAutomationPeer(RibbonGalleryCategory owner)
     : base(owner)
 {
 }
        // InRibbonGalleryMode where the gallery is shown within Ribbon via InRibbonGallery and Measure becomes responsibility
        // of InRibbonGalleryModeMeasureOverride.
        private Size InRibbonGalleryModeMeasureOverride(Size availableSize)
        {
            UIElementCollection children = InternalChildren;
            Size   panelSize             = new Size();
            Size   childConstraint       = new Size(double.PositiveInfinity, double.PositiveInfinity);
            double maxItemHeight         = 0;
            double maxColumnWidth        = 0;
            double sumItemHeight         = 0;
            int    columnCount           = 0;
            int    childrenCount         = children.Count;
            int    minColumnCount        = GetMinColumnCount();
            int    maxColumnCount        = GetMaxColumnCount();

            Debug.Assert(maxColumnCount >= minColumnCount);

            // Determine the maximum column width so that all items
            // can be hosted in equispaced columns. row height is auto
            // and depends on the maximum height of the items in that row
            for (int i = 0; i < childrenCount; i++)
            {
                UIElement child = children[i] as UIElement;

                // It has been already measure once directly in RibbonCategoriesPanel and hence will get short circuit already.
                // The call still needed as to Measure in case if the Parent panel is being changed from
                // RibbonGalleryCatgoriesPanel to something else.
                child.Measure(childConstraint);

                Size childSize = child.DesiredSize;
                maxColumnWidth = Math.Max(maxColumnWidth, childSize.Width);
                maxItemHeight  = Math.Max(maxItemHeight, childSize.Height);
                sumItemHeight += childSize.Height;
            }

            // It has been already calculated once directly in RibbonCategoriesPanel and hence will get short circuit already.
            // The call still needs to be made in case if the Parent panel is being changed from RibbonGalleryCatgoriesPanel
            // to something else.
            SetMaxColumnWidthAndHeight(maxColumnWidth, maxItemHeight);

            // Gets the final MaxColumnWidth for this panel.
            maxColumnWidth = GetMaxColumnWidth();
            maxItemHeight  = GetMaxItemHeight();

            AddScrollDeltaInfo(sumItemHeight, childrenCount);

            if (!double.IsInfinity(availableSize.Width) && maxColumnWidth != 0)
            {
                columnCount = (int)(availableSize.Width / maxColumnWidth);
            }
            else
            {
                columnCount = childrenCount;
            }

            // Initialize Width and Height, specially in case of height it's more off leaving the empty space in panel where Items in other categories
            // are to be rendered.
            panelSize.Width = columnCount * maxColumnWidth;

            RibbonGalleryCategory category = Category;

            if (category != null)
            {
                panelSize.Height = category.RowOffset * maxItemHeight;

                if (columnCount != 0)
                {
                    // There could be space left in the last row of the previous category to render some of the items in this category.
                    Debug.Assert(category.ColumnOffset < columnCount);
                    int spotsLeftInPreviousRow = category.ColumnOffset == 0 ? 0 : columnCount - category.ColumnOffset;

                    if (childrenCount > spotsLeftInPreviousRow)
                    {
                        int remainingChildren = childrenCount - spotsLeftInPreviousRow;
                        category.ColumnEndOffSet = remainingChildren % columnCount;

                        category.RowCount = remainingChildren / columnCount;  // Initialize RowCount as the number of full rows.

                        // Increment RowCount if we filled the previous row.
                        if (spotsLeftInPreviousRow > 0)
                        {
                            category.RowCount++;
                        }

                        // Increment RowCount if we started a new row.
                        if (category.ColumnEndOffSet > 0)
                        {
                            category.RowCount++;
                        }
                    }
                    else
                    {
                        // All children can fit in the previous row.

                        category.ColumnEndOffSet = (category.ColumnOffset + childrenCount) % columnCount;
                        category.RowCount        = 1;
                    }
                }
                else
                {
                    category.ColumnEndOffSet = 0;
                    category.RowCount        = 0;
                }

                panelSize.Height += category.RowCount * maxItemHeight;
            }

            return(panelSize);
        }
        private Size InRibbonGalleryModeArrangeOverride(Size finalSize)
        {
            // Get final coumn count by finalsizw.width , MaxColumnWidth
            // Iterate through children one row at a time.
            // Arrange the first row at offset 0 and the next
            // row just below that and so on. Besure to arrange
            // the children within each row uniformly based on
            // the MaxColumnWidth that was computed during the
            // Measure pass.

            UIElementCollection children = InternalChildren;
            double rowStartHeight        = 0;
            double rowStartWidth         = 0;
            int    finalColumnCount      = 0;
            int    childrenCount         = children.Count;
            double maxColumnWidth        = GetMaxColumnWidth();
            double maxItemHeight         = GetMaxItemHeight();

            //Calculate the available column count based on final space
            //keeping the same column width.
            if (maxColumnWidth == 0.0)
            {
                return(finalSize);
            }

            if (!double.IsInfinity(finalSize.Width) && maxColumnWidth != 0)
            {
                finalColumnCount = (int)(finalSize.Width / maxColumnWidth);
            }
            else
            {
                finalColumnCount = childrenCount;
            }

            if (finalColumnCount == 0)
            {
                return(finalSize);
            }

            RibbonGalleryCategory category = Category;

            // Calculate the starting offsets in pixels from actual Row and Coulmn offsets.
            if (category != null)
            {
                rowStartHeight = category.RowOffset * maxItemHeight;
                rowStartWidth  = category.ColumnOffset * maxColumnWidth;
            }

            for (int i = 0; i < childrenCount; i++)
            {
                children[i].Arrange(new Rect(rowStartWidth, rowStartHeight, maxColumnWidth, maxItemHeight));
                rowStartWidth += maxColumnWidth;
                if ((i + category.ColumnOffset + 1) % finalColumnCount == 0)
                {
                    rowStartHeight += maxItemHeight;
                    rowStartWidth   = 0;
                }
            }

            return(finalSize);
        }
Exemplo n.º 24
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            // Get final coumn count by finalsizw.width , MaxColumnWidth
            // Iterate through children one row at a time.
            // Arrange the first row at offset 0 and the next
            // row just below that and so on. Besure to arrange
            // the children within each row uniformly based on
            // the MaxColumnWidth that was computed during the
            // Measure pass.

            UIElementCollection children           = InternalChildren;
            double                rowStartHeight   = 0;
            double                rowStartWidth    = 0;
            double                maxRowHeight     = 0.0;
            int                   finalColumnCount = 0;
            int                   rowStartIndex    = 0;
            int                   childrenCount    = children.Count;
            int                   minColumnCount   = GetMinColumnCount();
            int                   maxColumnCount   = GetMaxColumnCount();
            RibbonGallery         parentGallery    = RibbonGallery;
            RibbonGalleryCategory category         = Category;
            double                arrangeWidth     = 0.0;

            if (parentGallery != null && category != null)
            {
                if (parentGallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope && parentGallery.ColumnsStretchToFill)
                {
                    // If sharedScope is Gallery, fetch global ArrangeWidth
                    arrangeWidth = GetArrangeWidth();
                }
                else if (category.IsSharedColumnSizeScope && category.ColumnsStretchToFill)
                {
                    // SharedScope is Category, use local arrangeWidth.
                    arrangeWidth = _arrangeWidth;
                }
                else
                {
                    // ColumnStretchToFill is false.
                    arrangeWidth = GetMaxColumnWidth();
                }
            }

            //Calculate the available column count based on final space
            //keeping the same column width.
            if (arrangeWidth == 0.0)
            {
                return(finalSize);
            }

            finalColumnCount = Math.Max(minColumnCount, Math.Min((int)(finalSize.Width / arrangeWidth), maxColumnCount));

            for (int i = 0; i < childrenCount; i++)
            {
                maxRowHeight = Math.Max(maxRowHeight, children[i].DesiredSize.Height);
                if ((i + 1) % finalColumnCount == 0 || i == childrenCount - 1)
                {
                    //Arrange the row
                    for (int j = rowStartIndex; j <= i; j++)
                    {
                        children[j].Arrange(new Rect(rowStartWidth, rowStartHeight, arrangeWidth, maxRowHeight));
                        rowStartWidth += arrangeWidth;
                    }
                    rowStartHeight += maxRowHeight;
                    maxRowHeight    = 0;
                    rowStartIndex   = i + 1;
                    rowStartWidth   = 0;
                }
            }

            return(finalSize);
        }
Exemplo n.º 25
0
        // InRibbonGalleryMode where the gallery is shown within Ribbon via InRibbonGallery and Measure becomes responsibility
        // of InRibbonGalleryModeMeasureOverride.
        private Size InRibbonGalleryModeMeasureOverride(Size availableSize)
        {
            Size desiredSize     = new Size();
            Size childConstraint = availableSize;

            childConstraint.Height = Double.PositiveInfinity;
            UIElementCollection children       = InternalChildren;
            int    childrenCount               = children.Count;
            int    galleryItemCount            = 0;
            double galleryItemCumulativeHeight = 0.0;
            double maxChildWidth               = 0.0;
            double maxChildHeight              = 0.0;
            int    rowOffset = 0;
            int    colOffset = 0;

            // Measure the child and also sets start and end offsets of the categories to be used their ItemsPanel
            // (RibbonGalleryItemsPanel) in their Measure and Arrange algorithms when in InRibbonMode.
            for (int i = 0; i < childrenCount; i++)
            {
                RibbonGalleryCategory child = children[i] as RibbonGalleryCategory;

                if (child == null ||
                    child.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                child.RowOffset    = rowOffset;
                child.ColumnOffset = colOffset;
                child.Measure(childConstraint);
                Size childSize = child.DesiredSize;
                maxChildWidth                = Math.Max(maxChildWidth, childSize.Width);
                maxChildHeight               = Math.Max(maxChildHeight, childSize.Height);
                galleryItemCount            += child.averageItemHeightInfo.Count;
                galleryItemCumulativeHeight += child.averageItemHeightInfo.CumulativeHeight;

                int childFullRows = Math.Max(0, child.RowCount - 1);
                if (child.RowCount > 0 && child.ColumnEndOffSet == 0)
                {
                    childFullRows++;
                }

                rowOffset += childFullRows;
                colOffset  = child.ColumnEndOffSet;
            }

            if (galleryItemCount == 0 || galleryItemCumulativeHeight == 0.0)
            {
                internalScrollDelta = 16.0;
            }
            else
            {
                internalScrollDelta = galleryItemCumulativeHeight / galleryItemCount;
            }
            desiredSize.Width  = maxChildWidth;
            desiredSize.Height = maxChildHeight;

            if (IsScrolling)
            {
                UpdateScrollingData(availableSize, desiredSize);
            }

            return(desiredSize);
        }
Exemplo n.º 26
0
        protected override Size MeasureOverride(Size availableSize)
        {
            // Iterate through all of the children. For each row first measure # of children
            // to infinity and gather their Max of DesiredWidths. Also, calculate the
            // columnCount. Then space permitting measure as many more
            // children that will fit into that row till columnCount is acheived and get
            // MaxHeight for that Row. Cumulative height of such Rows gives you DesiredHeight
            // for Panel.
            // Return desired size for this Panel as the
            // new Size(ColumnCount * MaxColumnWidth, cumulative RowHeights).

            UIElementCollection children  = InternalChildren;
            Size          panelSize       = new Size();
            Size          childConstraint = new Size(double.PositiveInfinity, double.PositiveInfinity);
            double        maxRowHeight    = 0;
            double        maxItemHeight   = 0;
            double        sumItemHeight   = 0;
            int           columnCount     = 0;
            int           childrenCount   = children.Count;
            RibbonGallery parentGallery   = RibbonGallery;
            double        maxColumnWidth  = (parentGallery != null && parentGallery.IsMaxColumnWidthValid) ? GetMaxColumnWidth() : 0.0;
            int           minColumnCount  = GetMinColumnCount();
            int           maxColumnCount  = GetMaxColumnCount();

            Debug.Assert(maxColumnCount >= minColumnCount);

            // Determine the maximum column width so that all items
            // can be hosted in equispaced columns. row height is auto
            // and depends on the maximum height of the items in that row
            for (int i = 0; i < childrenCount; i++)
            {
                UIElement child = children[i] as UIElement;
                child.Measure(childConstraint);
                Size childSize = child.DesiredSize;
                maxColumnWidth = Math.Max(maxColumnWidth, childSize.Width);
                maxItemHeight  = Math.Max(maxItemHeight, childSize.Height);
                sumItemHeight += childSize.Height;
            }

            // if none of the children has substantial width, panelsize would be equivalent to zero.
            if (maxColumnWidth == 0.0)
            {
                return(panelSize);
            }

            // Updates the MaxColumnWidth of this Category as well as the of the parent Gallery if suffices all conditions.
            SetMaxColumnWidth(maxColumnWidth);

            // Gets the final MaxColumnWidth for this panel.
            maxColumnWidth = GetMaxColumnWidth();

            if (!IsAutoLayoutPass(sumItemHeight, childrenCount))
            {
                if (!double.IsInfinity(availableSize.Width))
                {
                    columnCount = Math.Min(Math.Max(minColumnCount, Math.Min((int)(availableSize.Width / maxColumnWidth), childrenCount)), maxColumnCount);

                    RibbonGalleryCategory category = Category;
                    if (parentGallery != null && category != null)
                    {
                        if (parentGallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope && parentGallery.ColumnsStretchToFill)
                        {
                            // Since Gallery is a SharedColumnScope, store ArrangeWidth to be shared by the entire Gallery
                            double arrangeWidth = GetArrangeWidth();
                            if (!parentGallery.IsArrangeWidthValid)
                            {
                                // Calculate ArrangeWidth such that columnCount no. of columns occupy all of availableSize.Width
                                columnCount  = Math.Min(Math.Max(minColumnCount, Math.Min((int)(availableSize.Width / maxColumnWidth), childrenCount)), maxColumnCount);
                                arrangeWidth = Math.Max(availableSize.Width / columnCount, maxColumnWidth);
                                SetArrangeWidth(arrangeWidth);
                            }
                            else
                            {
                                // Once a valid arrangeWidth has been computed, we use arrangeWidth to determine number of columns.
                                columnCount = Math.Min(Math.Max(minColumnCount, Math.Min((int)(availableSize.Width / arrangeWidth), childrenCount)), maxColumnCount);
                            }
                        }
                        else if (category.IsSharedColumnSizeScope && category.ColumnsStretchToFill)
                        {
                            // Since category is a sharedColumnScope.
                            // Calculate and store _arrangeWidth locally for just this category
                            if (!_isArrangeWidthValid)
                            {
                                columnCount          = Math.Min(Math.Max(minColumnCount, Math.Min((int)(availableSize.Width / maxColumnWidth), childrenCount)), maxColumnCount);
                                _arrangeWidth        = Math.Max(availableSize.Width / columnCount, maxColumnWidth);
                                _isArrangeWidthValid = true;
                            }
                            else
                            {
                                // Once a valid arrangeWidth has been computed, we use arrangeWidth to determine number of columns.
                                columnCount = Math.Min(Math.Max(minColumnCount, Math.Min((int)(availableSize.Width / _arrangeWidth), childrenCount)), maxColumnCount);
                            }
                        }
                    }
                }
                else
                {
                    columnCount = Math.Max(minColumnCount, Math.Min(childrenCount, maxColumnCount));
                }

                // Finds row Items once ColumnWidth is determined to fetch MaxHeight of a particular row.
                // Also adds these height to acheive cumulative height which is desired height of the panel.
                for (int i = 0; i < childrenCount; i++)
                {
                    UIElement child     = children[i] as UIElement;
                    Size      childSize = child.DesiredSize;
                    maxRowHeight = Math.Max(maxRowHeight, childSize.Height);
                    if ((i + 1) % columnCount == 0 || i == childrenCount - 1)
                    {
                        panelSize.Height += maxRowHeight;

                        // Save the maxRowHeight so it can be used for PageDown operations
                        _maxRowHeight = maxRowHeight;

                        maxRowHeight = 0;
                    }
                }
            }
            else
            {
                columnCount      = minColumnCount;
                panelSize.Height = maxItemHeight;
            }

            panelSize.Width = columnCount * maxColumnWidth;
            return(panelSize);
        }
Exemplo n.º 27
0
        private void UpdateRendererList()
        {
            var list = from value in Plugin.Manager.PluginManager.PluginRendererList
                       orderby value.Group.Name ascending
                       group value by value.Group;

            foreach (var group in list)
            {
                RibbonGroup rgGroup = new RibbonGroup();
                rgGroup.Header           = group.Key.Name;
                rgGroup.SmallImageSource = group.Key.Image.Source;
                rgGroup.Tag = group.Key;

                rtRenderer.Items.Add(rgGroup);


                /* Effects */
                IEnumerator <IRenderer> renderers = group.GetEnumerator();
                while (renderers.MoveNext())
                {
                    if (renderers.Current.DefaultCount > 0)
                    {
                        RibbonMenuButton btn = new RibbonMenuButton();
                        btn.Label            = renderers.Current.Name;
                        btn.SmallImageSource = renderers.Current.Icon.Source;

                        btn.ToolTipTitle             = renderers.Current.Name;
                        btn.ToolTipImageSource       = BitmapFrame.Create(new Uri("pack://application:,,, /Effect FX;component/Resources/Info.ico"));
                        btn.ToolTipDescription       = renderers.Current.Description;
                        btn.ToolTipFooterTitle       = renderers.Current.Group.Name;
                        btn.ToolTipFooterImageSource = renderers.Current.Group.Image.Source;
                        btn.ToolTipFooterDescription = renderers.Current.Group.Description;

                        btn.Tag = renderers.Current;

                        RibbonGallery gallery = new RibbonGallery();
                        gallery.MaxHeight = 500;
                        gallery.Command   = (ICommand)Resources["cmdImageNull"];
                        RibbonGalleryCategory cat = new RibbonGalleryCategory();
                        gallery.Items.Add(cat);

                        for (int i = 0; i < renderers.Current.DefaultCount; i++)
                        {
                            RibbonGalleryItem item  = new RibbonGalleryItem();
                            Image             image = new Image();
                            image.Width               = 230;
                            image.Height              = 124;
                            image.Stretch             = Stretch.UniformToFill;
                            image.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                            image.Source              = BitmapFrame.Create(new Uri("pack://application:,,, /Effect FX;component/Resources/preview.png"));
                            image.Source              = renderers.Current.GenerateImage(image.Source as BitmapSource, i);
                            image.Tag = new KeyValuePair <int, IRenderer>(i, renderers.Current);
                            previewImageList.Add(image);
                            item.Content = image;
                            cat.Items.Add(item);

                            int finalIndex = i;
                            image.MouseDown += (s, e) =>
                            {
                                //Console.WriteLine("OK: " + finalIndex);
                                manager.AddAction((btn.Tag as IRenderer).Name, imgPicture.Source as BitmapFrame);
                                imgPicture.Source = (btn.Tag as IRenderer).GenerateImage(
                                    imgPicture.Source as BitmapFrame, finalIndex);
                                UpdatePreviewImages();

                                gallery.SelectedItem = null;
                            };
                        }

                        btn.Items.Add(gallery);
                        rgGroup.Items.Add(btn);
                    }
                    else
                    {
                        RibbonButton btn = new RibbonButton();
                        btn.Label            = renderers.Current.Name;
                        btn.SmallImageSource = renderers.Current.Icon.Source;

                        btn.ToolTipTitle             = renderers.Current.Name;
                        btn.ToolTipImageSource       = BitmapFrame.Create(new Uri("pack://application:,,, /Effect FX;component/Resources/Info.ico"));
                        btn.ToolTipDescription       = renderers.Current.Description;
                        btn.ToolTipFooterTitle       = renderers.Current.Group.Name;
                        btn.ToolTipFooterImageSource = renderers.Current.Group.Image.Source;
                        btn.ToolTipFooterDescription = renderers.Current.Group.Description;

                        btn.Tag = renderers.Current;

                        rgGroup.Items.Add(btn);
                    }
                } //while
            }     //for
        }
Exemplo n.º 28
0
        private Size AutoPassMeasureOverride()
        {
            Size desiredSize     = new Size();
            Size childConstraint = new Size(double.PositiveInfinity, double.PositiveInfinity);
            IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this;

            // This is Auto(non Star) pass
            UIElementCollection children = InternalChildren;
            int    childrenCount, endCountForUpdate = children.Count;
            int    galleryItemCount            = 0;
            double galleryItemCumulativeHeight = 0.0;
            double maxChildWidth  = 0.0;
            double maxChildHeight = 0.0;
            double maxColumnWidth = 0.0;

            // Since we support SharedColumnSizes across different categories, we need
            // to repeatedly measure them until their MaxColumnWidth has been synchronized.
            // The inner loop iterates over all of those categories that need an update.
            // Of course in the beginning all of them do. During that pass we detect if the
            // MaxColumnWidth has increased such that a previously measured category needs
            // an update. If so we make another pass over those categories once more. We
            // repeat this strategy until none of the categories need an update.

            while (endCountForUpdate > 0)
            {
                childrenCount     = endCountForUpdate;
                endCountForUpdate = 0;
                for (int i = 0; i < childrenCount; i++)
                {
                    UIElement child = children[i] as UIElement;
                    child.Measure(childConstraint);
                    Size childSize = child.DesiredSize;
                    maxChildWidth  = Math.Max(maxChildWidth, childSize.Width);
                    maxChildHeight = Math.Max(maxChildHeight, childSize.Height);

                    RibbonGalleryCategory category = child as RibbonGalleryCategory;
                    if (category != null)
                    {
                        galleryItemCount            += category.averageItemHeightInfo.Count;
                        galleryItemCumulativeHeight += category.averageItemHeightInfo.CumulativeHeight;

                        // If the category is a ColumnSizeScope in itself it does not need
                        // to be synchronized with the gallery's scope and hence can be ignored.

                        if (!category.IsSharedColumnSizeScope && DoubleUtil.GreaterThan(category.MaxColumnWidth, maxColumnWidth))
                        {
                            maxColumnWidth    = category.MaxColumnWidth;
                            endCountForUpdate = i;
                        }
                    }
                }
            }

            if (galleryItemCount == 0 || galleryItemCumulativeHeight == 0.0)
            {
                internalScrollDelta = 16.0;
            }
            else
            {
                internalScrollDelta = galleryItemCumulativeHeight / galleryItemCount;
            }

            desiredSize.Width  = maxChildWidth;
            desiredSize.Height = maxChildHeight;

            return(desiredSize);
        }