// In In RibbonMode only e first gallery if exist is accessible. protected override List <AutomationPeer> GetChildrenCore() { InRibbonGallery irg = (InRibbonGallery)Owner; if (irg.IsInInRibbonMode) { List <AutomationPeer> children = new List <AutomationPeer>(); RibbonGallery firstGallery = irg.FirstGallery; if (firstGallery != null) { AutomationPeer galleryPeer = UIElementAutomationPeer.CreatePeerForElement(firstGallery); if (galleryPeer != null) { children.Add(galleryPeer); } } RepeatButton scrollUpButton = irg.ScrollUpButton; if (scrollUpButton != null) { AutomationPeer scrollUpButtonPeer = UIElementAutomationPeer.CreatePeerForElement(scrollUpButton); if (scrollUpButtonPeer != null) { children.Add(scrollUpButtonPeer); } } RepeatButton scrollDownButton = irg.ScrollDownButton; if (scrollDownButton != null) { AutomationPeer scrollDownButtonPeer = UIElementAutomationPeer.CreatePeerForElement(scrollDownButton); if (scrollDownButtonPeer != null) { children.Add(scrollDownButtonPeer); } } ToggleButton partToggleButton = irg.PartToggleButton; if (partToggleButton != null) { AutomationPeer partToggleButtonPeer = UIElementAutomationPeer.CreatePeerForElement(partToggleButton); if (partToggleButtonPeer != null) { children.Add(partToggleButtonPeer); } } return(children); } return(base.GetChildrenCore()); }
private static bool CoerceCanLineUpDown(InRibbonGallery irg, bool lineUp) { if (irg.FirstGallery != null) { RibbonGalleryCategoriesPanel categoriesPanel = irg.FirstGallery.ItemsHostSite as RibbonGalleryCategoriesPanel; if (categoriesPanel != null) { return(lineUp ? categoriesPanel.InRibbonModeCanLineUp() : categoriesPanel.InRibbonModeCanLineDown()); } } return(true); }
internal void RemoveFirstGallery(InRibbonGallery irg) { for (int i = 0; i < InternalChildren.Count; i++) { if (InternalChildren[i].Equals(irg.FirstGallery)) { Debug.Assert(_firstRibbonGalleryReInsertIndex == -1); RemoveInternalChildRange(i, 1); _firstRibbonGalleryReInsertIndex = i; break; } } }
public void Opening_DropDown_Should_Not_Throw_When_GalleryPanel_Has_No_Width() { var control = new InRibbonGallery { Width = 10, Height = 30 }; using (new TestRibbonWindow(control)) { Assert.That(() => control.IsDropDownOpen = true, Throws.Nothing); } }
internal void ReInsertFirstGallery(InRibbonGallery irg) { RibbonGallery firstGallery = irg.FirstGallery; if (firstGallery != null && _firstRibbonGalleryReInsertIndex >= 0) { Debug.Assert(_firstRibbonGalleryReInsertIndex <= InternalChildren.Count); InsertInternalChild(_firstRibbonGalleryReInsertIndex, firstGallery); _firstRibbonGalleryReInsertIndex = -1; } }
private static object CoerceIsCollapsed(DependencyObject d, object baseValue) { InRibbonGallery irg = (InRibbonGallery)d; if (DependencyPropertyHelper.GetValueSource(irg, IsCollapsedProperty).BaseValueSource != BaseValueSource.Local) { RibbonControlSizeDefinition csd = irg.ControlSizeDefinition; if (csd != null) { return(csd.IsCollapsed); } } return(baseValue); }
// 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); }
private UIElement CreateGallery(object parameter, ToolbarElement element) { var gallery = element.Element as IToolbarGalleryFactory; if (gallery == null) { return(null); } var result = new InRibbonGallery { Header = element.Text }; gallery.Create(result, parameter); return(result); }
// When IsDropDownOpen changes the InRibbonGallery would be able to acheive IN Ribbon mode and hence visual // properties needs to be coerced. private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) { InRibbonGallery irg = (InRibbonGallery)d; irg.PrivateManageRibbonGalleryVisualParent(); if ((bool)args.NewValue == false && irg.FilterHasChanged) { irg.FilterHasChanged = false; irg.InvalidateMeasure(); } if ((bool)args.NewValue == false && irg.FirstGallery != null) { irg.FirstGallery.ChangeHighlight(null, null, false); } }
public void Create(InRibbonGallery gallery, object parameter) { gallery.Header = "Views"; gallery.Icon = new Icon("Resources/32x32/Plus.png").GetSource(); gallery.LargeIcon = new Icon("Resources/32x32/Plus.png").GetSource(); gallery.SelectionChanged += delegate(object sender, SelectionChangedEventArgs args) { var button = args.AddedItems.OfType <SkinButton>().FirstOrDefault(); if (button == null) { return; } SetSkin(parameter, button); }; LoadViewGallery(gallery); }
public void Create(InRibbonGallery gallery, [CanBeNull] object parameter) { Assert.ArgumentNotNull(gallery, nameof(gallery)); var context = parameter as LayoutDesignerContext; if (context == null) { return; } var layoutDesigner = context.LayoutDesigner; gallery.Header = "Renderings"; gallery.Icon = new Icon("Resources/32x32/Plus.png").GetSource(); gallery.LargeIcon = new Icon("Resources/32x32/Plus.png").GetSource(); LoadRenderingGallery(layoutDesigner, gallery); }
private void LoadViewGallery(InRibbonGallery gallery) { var renderings = new List <SkinButton>(); foreach (var item in SkinManager.Types) { var button = new SkinButton { Label = item.Key, Tag = item.Key }; renderings.Add(button); } renderings = renderings.OrderBy(i => i.Label).ToList(); gallery.ItemsSource = renderings; }
private void LoadRenderingGallery([NotNull] LayoutDesigner layoutDesigner, [NotNull] InRibbonGallery gallery) { Debug.ArgumentNotNull(layoutDesigner, nameof(layoutDesigner)); Debug.ArgumentNotNull(gallery, nameof(gallery)); Site.RequestCompleted completed = delegate(string response) { var root = response.ToXElement(); if (root == null) { return; } var items = root.Elements().Select(element => ItemHeader.Parse(layoutDesigner.DatabaseUri, element)).Where(e => MatchesSpeakCoreVersion(e, layoutDesigner)).ToList(); var renderings = new List <RenderingButton>(); foreach (var item in items.OrderBy(i => i.ParentName).ThenBy(i => i.Name)) { var button = new RenderingButton { Label = item.Name, Icon = item.Icon, Tag = item, ToolTip = ToolTipBuilder.BuildToolTip(item) }; button.PreviewMouseUp += (sender, args) => { AddRenderingFromRibbon(layoutDesigner, sender, button); }; renderings.Add(button); } renderings = renderings.OrderBy(i => i.Label).ToList(); gallery.ItemsSource = renderings; }; layoutDesigner.DatabaseUri.Site.Execute("Layouts.GetRenderings", completed, layoutDesigner.DatabaseUri.DatabaseName.ToString()); }
// Updates Width and other layout properties in the Visual tree from RibbonControl to InRibbonGallery wherever needed // when attains In Ribbon mode. private static void OnControlSizeDefinitionChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) { InRibbonGallery me = (InRibbonGallery)d; me.CoerceValue(IsCollapsedProperty); if (me.IsInInRibbonMode) { if (me._ribbonControl == null) { me._ribbonControl = TreeHelper.FindAncestor(me, delegate(DependencyObject element) { RibbonControl rc = (element as RibbonControl); if (rc != null) { return(me == rc.ContentChild); } return(false); }) as RibbonControl; } } me.UpdateInRibbonGalleryModeProperties(); }
/// <summary> /// Creates a new instance. /// </summary> public RibbonInRibbonGalleryAutomationPeer(InRibbonGallery owner) : base(owner) { this.owner = owner; }
/// <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 }
public void Opening_And_Closing_DropDown_Should_Not_Change_Size_For_Dynamic_Item_Width() { var ribbonGroupsContainer = new RibbonGroupsContainer { Height = RibbonTabControl.DefaultContentHeight, ReduceOrder = "(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup),(MyGroup)" }; var groupBox = new RibbonGroupBox { Name = "MyGroup", BorderBrush = Brushes.Red }; ribbonGroupsContainer.Children.Add(groupBox); var firstInRibbonGallery = new InRibbonGallery { MinItemsInRow = 1, MaxItemsInRow = 5, ItemHeight = 18, GroupBy = "Group", ResizeMode = ContextMenuResizeMode.Both, ItemsSource = this.sampleDataItemsForDynamicWidth }; groupBox.Items.Add(firstInRibbonGallery); var secondInRibbonGallery = new InRibbonGallery { MinItemsInRow = 1, MaxItemsInRow = 5, ItemHeight = 18, GroupBy = "Group", ResizeMode = ContextMenuResizeMode.Both, ItemsSource = this.sampleDataItemsForDynamicWidth }; groupBox.Items.Add(secondInRibbonGallery); using (new TestRibbonWindow(ribbonGroupsContainer)) { UIHelper.DoEvents(); ribbonGroupsContainer.Width = 620; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); for (var i = 0; i < 5; i++) { UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); // open and close first { firstInRibbonGallery.IsDropDownOpen = true; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(0)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); firstInRibbonGallery.IsDropDownOpen = false; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); } // open and close second { secondInRibbonGallery.IsDropDownOpen = true; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(0)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); secondInRibbonGallery.IsDropDownOpen = false; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); } ++ribbonGroupsContainer.Width; } UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(247)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(3)); Assert.That(groupBox.ActualWidth, Is.EqualTo(512)); ribbonGroupsContainer.Width = 670; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(323)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(323)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(4)); Assert.That(groupBox.ActualWidth, Is.EqualTo(664)); ribbonGroupsContainer.Width = 900; UIHelper.DoEvents(); Assert.That(firstInRibbonGallery.ActualWidth, Is.EqualTo(399)); Assert.That(secondInRibbonGallery.ActualWidth, Is.EqualTo(399)); Assert.That(firstInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(5)); Assert.That(secondInRibbonGallery.CurrentGalleryPanelState.GalleryPanel.MaxItemsInRow, Is.EqualTo(5)); Assert.That(groupBox.ActualWidth, Is.EqualTo(816)); } }
/// <summary> /// Initialize Automation Peer for InRibbonGallery /// </summary> public InRibbonGalleryAutomationPeer(InRibbonGallery owner) : base(owner) { }
/// <summary> /// Creates a new instance. /// </summary> public RibbonInRibbonGalleryAutomationPeer([NotNull] InRibbonGallery owner) : base(owner) { }
private static object CoerceCanLineDown(DependencyObject d, object baseValue) { InRibbonGallery irg = (InRibbonGallery)d; return(CoerceCanLineUpDown(irg, false)); }
// When IsCollapsed changes the InRibbonGallery would be able to acheive IN Ribbon mode and hence visual // properties needs to be coerced. private static void OnIsCollapsedChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) { InRibbonGallery irg = (InRibbonGallery)d; irg.PrivateManageRibbonGalleryVisualParent(); }