// 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); }
public void OnInitializeLayout() { IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; if (iContainsStarLayoutManager.StarLayoutManager != null && !iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass) { TreeHelper.InvalidateMeasureForVisualAncestorPath(this, RibbonHelper.IsISupportStarLayout); } }
private void OnRibbonGroupItemsPanelUnloaded(object sender, RoutedEventArgs e) { IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; if (iContainsStarLayoutManager.StarLayoutManager != null) { iContainsStarLayoutManager.StarLayoutManager.UnregisterStarLayoutProvider(this); iContainsStarLayoutManager.StarLayoutManager = null; } }
public void OnInitializeLayout() { IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; if (iContainsStarLayoutManager.StarLayoutManager != null) { TreeHelper.InvalidateMeasureForVisualAncestorPath(this, RibbonHelper.IsISupportStarLayout); ((RibbonGallery)TargetElement).InvalidateMeasureOnAllCategoriesPanel(); } }
/// <summary> /// In normal(Star) pass this panel behaves like a StackPanel but during Auto(non Star) pass /// It returns minimum Width and Height required to represent the children. /// </summary> /// <param name="availableSize"></param> /// <returns></returns> protected override Size MeasureOverride(Size availableSize) { RibbonHelper.InitializeStarLayoutManager(this); IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; bool isStarLayoutPass = (iContainsStarLayoutManager.StarLayoutManager == null ? true : iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass); if (isStarLayoutPass) { return(RealMeasureOverride(availableSize)); } else { return(AutoPassMeasureOverride()); } }
protected override Size MeasureOverride(Size availableSize) { Size desiredSize = new Size(); IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; RibbonHelper.InitializeStarLayoutManager(this); bool isStarLayoutPass = (iContainsStarLayoutManager.StarLayoutManager == null ? false : iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass); if (!isStarLayoutPass) { desiredSize = NonStarPassMeasure(availableSize); } else { desiredSize = StarMeasurePass(availableSize); } return(desiredSize); }
// It just determines if any ancestor supports StarLayout and is not in StarLayoutPass mode. private bool IsAutoLayoutPass() { RibbonGallery gallery = Gallery; if (gallery != null) { RibbonGalleryCategoriesPanel categoriesPanel = gallery.ItemsHostSite as RibbonGalleryCategoriesPanel; if (categoriesPanel != null) { IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)categoriesPanel; if (iContainsStarLayoutManager.StarLayoutManager != null) { return(!iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass); } } } return(false); }
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); }
/// <summary> /// In normal(Star) pass this panel behaves like a StackPanel but during Auto(non Star) pass /// It returns minimum Width and Height required to represent the children. There is another /// mode wherein it provides laying out mechanism for InRibbonGallery in INRibbon mode. /// </summary> /// <param name="availableSize"></param> /// <returns></returns> protected override Size MeasureOverride(Size availableSize) { RibbonGallery gallery = this.Gallery; #if IN_RIBBON_GALLERY InRibbonGallery parentInRibbonGallery = gallery != null ? gallery.ParentInRibbonGallery : null; bool isInInRibbonMode = parentInRibbonGallery != null ? parentInRibbonGallery.IsInInRibbonMode : false; // For an InRibbonGallery rendering with IsDropDownOpen==true, we force gallery.ItemsPresenter's // MinWidth to be at least the value of IRG.ContentPresenter.ActualWidth. This way, the IRG's popup // totally eclipses the IRG, which is required by the Office Fluent UI guidelines. if (gallery != null && gallery.ItemsPresenter != null && parentInRibbonGallery != null) { if (isInInRibbonMode && _irgIsConstrainingWidth) { gallery.ItemsPresenter.MinWidth = _originalGalleryItemsPresenterMinWidth; _irgIsConstrainingWidth = false; } else if (parentInRibbonGallery.IsDropDownOpen && !_irgIsConstrainingWidth) { _originalGalleryItemsPresenterMinWidth = gallery.ItemsPresenter.MinWidth; double minWidthFromParent = parentInRibbonGallery.CalculateGalleryItemsPresenterMinWidth(); gallery.ItemsPresenter.MinWidth = Math.Max(minWidthFromParent, _originalGalleryItemsPresenterMinWidth); _irgIsConstrainingWidth = true; } } if (!isInInRibbonMode) { #endif RibbonHelper.InitializeStarLayoutManager(this); #if IN_RIBBON_GALLERY } #endif IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; bool isStarLayoutPass = (iContainsStarLayoutManager.StarLayoutManager == null ? true : iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass); #if IN_RIBBON_GALLERY if (isInInRibbonMode) { PreComputeMaxRibbonGalleryItemWidthAndHeight(); return(InRibbonGalleryModeMeasureOverride(availableSize)); } else { #endif if (isStarLayoutPass) { return(RealMeasureOverride(availableSize)); } else { return(AutoPassMeasureOverride()); } #if IN_RIBBON_GALLERY } #endif }