/// <summary> /// If the application developer has specified a GroupSizeReductionOrder, this /// takes the next group in that order and tells it to reduce to its next size. /// If no GroupSizeReductionOrder was specified, or if we need to collapse RibbonGroups /// beyond what was specified by the developer, we reduce groups from right-to-left, /// step by step in cyclical order. /// </summary> /// <returns> /// Returns true if a group was located and resized successfully, false otherwise. /// </returns> internal bool DecreaseNextGroupSize() { bool resizeSuccessful = false; if (GroupSizeReductionOrder != null) { while (_groupReduceOrderLocation < GroupSizeReductionOrder.Count - 1 && !resizeSuccessful) { // Find the group who's next to be reduced. RibbonGroup targetGroup = FindRibbonGroupWithName(GroupSizeReductionOrder[++_groupReduceOrderLocation]); if (targetGroup == null) { resizeSuccessful = false; } else { resizeSuccessful = targetGroup.DecreaseGroupSize(); } _groupReductionResizeStatus.Add(resizeSuccessful); } } if (!resizeSuccessful) { // Either no GroupSizeReductionOrder was specified, or we've run out of predefined orderings. // In this case we should begin reducing groups in size right-to-left, step by step, in cyclical // order. resizeSuccessful = DefaultCyclicalReduceGroup(); } return(resizeSuccessful); }
/// <summary> /// From right-to-left, finds the next group who can be reduced in size. If the leftmost /// group is encountered reduction will continue in a cyclical fashion back at the rightmost /// RibbonGroup. /// </summary> /// <returns>True if a group was successfully located and reduced in size, false otherwise.</returns> private bool DefaultCyclicalReduceGroup() { bool resizeSuccessful = false; if (_groupAutoResizeIndex == null) { _groupAutoResizeIndex = Items.Count - 1; } bool resizesRemain = true; while (resizesRemain && !resizeSuccessful) { int numAttempts = 0; do { numAttempts++; RibbonGroup group = ItemContainerGenerator.ContainerFromIndex((_groupAutoResizeIndex--).Value) as RibbonGroup; if (group != null) { resizeSuccessful = group.DecreaseGroupSize(); } if (resizeSuccessful == true) { _automaticResizeOrder.Add(_groupAutoResizeIndex.Value + 1); } // If we have underflowed our Groups collection, start again at the end. This // is what makes our group reduction cyclical. if (_groupAutoResizeIndex.Value < 0) { _groupAutoResizeIndex = Items.Count - 1; break; } } while (resizeSuccessful == false); // If we failed to resize during this pass, and we attempted to resize for every // group, then there are no reamining groups to resize. if (numAttempts == Items.Count) { resizesRemain = false; } } return(resizeSuccessful); }