Esempio n. 1
0
        // Token: 0x06006109 RID: 24841 RVA: 0x001B3754 File Offset: 0x001B1954
        private bool MeasureGeneratedItems(bool asNeededPass, Size constraint, bool horizontal, double maxExtent, ref Size panelDesiredSize, out double overflowExtent)
        {
            ToolBarOverflowPanel toolBarOverflowPanel = this.ToolBarOverflowPanel;
            bool flag   = false;
            bool result = false;
            bool flag2  = false;

            overflowExtent = 0.0;
            UIElementCollection internalChildren = base.InternalChildren;
            int num  = internalChildren.Count;
            int num2 = 0;

            for (int i = 0; i < this._generatedItemsCollection.Count; i++)
            {
                UIElement    uielement    = this._generatedItemsCollection[i];
                OverflowMode overflowMode = ToolBar.GetOverflowMode(uielement);
                bool         flag3        = overflowMode == OverflowMode.AsNeeded;
                if (flag3 == asNeededPass)
                {
                    DependencyObject parent = VisualTreeHelper.GetParent(uielement);
                    if (overflowMode != OverflowMode.Always && !flag)
                    {
                        ToolBar.SetIsOverflowItem(uielement, BooleanBoxes.FalseBox);
                        uielement.Measure(constraint);
                        Size desiredSize = uielement.DesiredSize;
                        if (flag3)
                        {
                            double value;
                            if (horizontal)
                            {
                                value = desiredSize.Width + panelDesiredSize.Width;
                            }
                            else
                            {
                                value = desiredSize.Height + panelDesiredSize.Height;
                            }
                            if (DoubleUtil.GreaterThan(value, maxExtent))
                            {
                                flag = true;
                            }
                        }
                        if (!flag)
                        {
                            if (horizontal)
                            {
                                panelDesiredSize.Width += desiredSize.Width;
                                panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, desiredSize.Height);
                            }
                            else
                            {
                                panelDesiredSize.Width   = Math.Max(panelDesiredSize.Width, desiredSize.Width);
                                panelDesiredSize.Height += desiredSize.Height;
                            }
                            if (parent != this)
                            {
                                if (parent == toolBarOverflowPanel && toolBarOverflowPanel != null)
                                {
                                    toolBarOverflowPanel.Children.Remove(uielement);
                                }
                                if (num2 < num)
                                {
                                    internalChildren.InsertInternal(num2, uielement);
                                }
                                else
                                {
                                    internalChildren.AddInternal(uielement);
                                }
                                num++;
                            }
                            num2++;
                        }
                    }
                    if (overflowMode == OverflowMode.Always || flag)
                    {
                        result = true;
                        if (uielement.MeasureDirty)
                        {
                            ToolBar.SetIsOverflowItem(uielement, BooleanBoxes.FalseBox);
                            uielement.Measure(constraint);
                        }
                        Size desiredSize2 = uielement.DesiredSize;
                        if (horizontal)
                        {
                            overflowExtent         += desiredSize2.Width;
                            panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, desiredSize2.Height);
                        }
                        else
                        {
                            overflowExtent        += desiredSize2.Height;
                            panelDesiredSize.Width = Math.Max(panelDesiredSize.Width, desiredSize2.Width);
                        }
                        ToolBar.SetIsOverflowItem(uielement, BooleanBoxes.TrueBox);
                        if (parent == this)
                        {
                            internalChildren.RemoveNoVerify(uielement);
                            num--;
                            flag2 = true;
                        }
                        else if (parent == null)
                        {
                            flag2 = true;
                        }
                    }
                }
                else if (num2 < num && internalChildren[num2] == uielement)
                {
                    num2++;
                }
            }
            if (flag2 && toolBarOverflowPanel != null)
            {
                toolBarOverflowPanel.InvalidateMeasure();
            }
            return(result);
        }
Esempio n. 2
0
        private bool MeasureGeneratedItems(bool asNeededPass, Size constraint, bool horizontal, double maxExtent, ref Size panelDesiredSize, out double overflowExtent)
        {
            ToolBarOverflowPanel overflowPanel = ToolBarOverflowPanel;
            bool sendToOverflow            = false; // Becomes true when the first AsNeeded does not fit
            bool hasOverflowItems          = false;
            bool overflowNeedsInvalidation = false;

            overflowExtent = 0.0;
            UIElementCollection children = InternalChildren;
            int childrenCount            = children.Count;
            int childrenIndex            = 0;

            for (int i = 0; i < _generatedItemsCollection.Count; i++)
            {
                UIElement    child        = _generatedItemsCollection[i];
                OverflowMode overflowMode = ToolBar.GetOverflowMode(child);
                bool         asNeededMode = overflowMode == OverflowMode.AsNeeded;

                // MeasureGeneratedItems is called twice to do a complete measure.
                // The first pass measures Always and Never items -- items that
                // are guaranteed to be or not to be in the overflow menu.
                // The second pass measures AsNeeded items and determines whether
                // there is enough room for them in the main bar or if they should
                // be placed in the overflow menu.
                // Check here whether the overflow mode matches a mode we should be
                // examining in this pass.
                if (asNeededMode == asNeededPass)
                {
                    DependencyObject visualParent = VisualTreeHelper.GetParent(child);

                    // In non-Always overflow modes, measure for main bar placement.
                    if ((overflowMode != OverflowMode.Always) && !sendToOverflow)
                    {
                        // Children may change their size depending on whether they are in the overflow
                        // menu or not. Ensure that when we measure, we are using the main bar size.
                        // If the item goes to overflow, this property will be updated later in this loop
                        // when it is removed from the visual tree.
                        ToolBar.SetIsOverflowItem(child, BooleanBoxes.FalseBox);
                        child.Measure(constraint);
                        Size childDesiredSize = child.DesiredSize;

                        // If the child is an AsNeeded, check if it fits. If it doesn't then
                        // this child and all subsequent AsNeeded children should be sent
                        // to the overflow menu.
                        if (asNeededMode)
                        {
                            double newExtent;
                            if (horizontal)
                            {
                                newExtent = childDesiredSize.Width + panelDesiredSize.Width;
                            }
                            else
                            {
                                newExtent = childDesiredSize.Height + panelDesiredSize.Height;
                            }
                            if (DoubleUtil.GreaterThan(newExtent, maxExtent))
                            {
                                // It doesn't fit, send to overflow
                                sendToOverflow = true;
                            }
                        }

                        // The child has been validated as belonging in the main bar.
                        // Update the panel desired size dimensions, and ensure the child
                        // is in the main bar's visual tree.
                        if (!sendToOverflow)
                        {
                            if (horizontal)
                            {
                                panelDesiredSize.Width += childDesiredSize.Width;
                                panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, childDesiredSize.Height);
                            }
                            else
                            {
                                panelDesiredSize.Width   = Math.Max(panelDesiredSize.Width, childDesiredSize.Width);
                                panelDesiredSize.Height += childDesiredSize.Height;
                            }

                            if (visualParent != this)
                            {
                                if ((visualParent == overflowPanel) && (overflowPanel != null))
                                {
                                    overflowPanel.Children.Remove(child);
                                }

                                if (childrenIndex < childrenCount)
                                {
                                    children.InsertInternal(childrenIndex, child);
                                }
                                else
                                {
                                    children.AddInternal(child);
                                }
                                childrenCount++;
                            }

                            Debug.Assert(children[childrenIndex] == child, "InternalChildren is out of sync with _generatedItemsCollection.");
                            childrenIndex++;
                        }
                    }

                    // The child should go to the overflow menu
                    if ((overflowMode == OverflowMode.Always) || sendToOverflow)
                    {
                        hasOverflowItems = true;

                        // If a child is in the overflow menu, we don't want to keep measuring.
                        // However, we need to calculate the MaxLength as well as set the desired height
                        // correctly. Thus, we will use the DesiredSize of the child. There is a problem
                        // that can occur if the child changes size while in the overflow menu and
                        // was recently displayed. It will be measure clean, yet its DesiredSize
                        // will not be accurate for the MaxLength calculation.
                        if (child.MeasureDirty)
                        {
                            // Set this temporarily in case the size is different while in the overflow area
                            ToolBar.SetIsOverflowItem(child, BooleanBoxes.FalseBox);
                            child.Measure(constraint);
                        }

                        // Even when in the overflow, we need two pieces of information:
                        // 1. We need to continue to track the maximum size of the non-logical direction
                        //    (i.e. height in horizontal bars). This way, ToolBars with everything in
                        //    the overflow will still have some height.
                        // 2. We want to track how much of the space we saved by placing the child in
                        //    the overflow menu. This is used to calculate MinLength and MaxLength.
                        Size childDesiredSize = child.DesiredSize;
                        if (horizontal)
                        {
                            overflowExtent         += childDesiredSize.Width;
                            panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, childDesiredSize.Height);
                        }
                        else
                        {
                            overflowExtent        += childDesiredSize.Height;
                            panelDesiredSize.Width = Math.Max(panelDesiredSize.Width, childDesiredSize.Width);
                        }

                        // Set the flag to indicate that the child is in the overflow menu
                        ToolBar.SetIsOverflowItem(child, BooleanBoxes.TrueBox);

                        // If the child is in this panel's visual tree, remove it.
                        if (visualParent == this)
                        {
                            Debug.Assert(children[childrenIndex] == child, "InternalChildren is out of sync with _generatedItemsCollection.");
                            children.RemoveNoVerify(child);
                            childrenCount--;
                            overflowNeedsInvalidation = true;
                        }
                        // If the child isnt connected to the visual tree, notify the overflow panel to pick it up.
                        else if (visualParent == null)
                        {
                            overflowNeedsInvalidation = true;
                        }
                    }
                }
                else
                {
                    // We are not measure this child in this pass. Update the index into the
                    // visual children collection.
                    if ((childrenIndex < childrenCount) && (children[childrenIndex] == child))
                    {
                        childrenIndex++;
                    }
                }
            }

            // A child was added to the overflow panel, but since we don't add it
            // to the overflow panel's visual collection until that panel's measure
            // pass, we need to mark it as measure dirty.
            if (overflowNeedsInvalidation && (overflowPanel != null))
            {
                overflowPanel.InvalidateMeasure();
            }

            return(hasOverflowItems);
        }