Пример #1
0
        public static Size Measure(Size availableSize, Orientation orientation, IEnumerable uiElements, bool remeasureElements, out Rect[] elementBounds, SplitterPanel splitterPanel)
        {
            double           num1   = 0.0;
            double           num2   = 0.0;
            double           num3   = 0.0;
            double           num4   = 0.0;
            double           val2   = 0.0;
            double           val1_1 = 0.0;
            double           val1_2 = 0.0;
            List <UIElement> list1  = new List <UIElement>();

            foreach (UIElement uiElement in uiElements)
            {
                list1.Add(uiElement);
            }
            foreach (UIElement element in list1)
            {
                if (remeasureElements)
                {
                    element.Measure(availableSize);
                }
                if (orientation == Orientation.Horizontal)
                {
                    val1_2 += element.DesiredSize.Height;
                    val1_1  = Math.Max(val1_1, element.DesiredSize.Width);
                }
                else
                {
                    val1_1 += element.DesiredSize.Width;
                    val1_2  = Math.Max(val1_2, element.DesiredSize.Height);
                }
                SplitterLength splitterLength = SplitterPanel.GetSplitterLength(element);
                double         minimumLength  = SplitterPanel.GetMinimumLength(element);
                if (splitterLength.IsStretch)
                {
                    num1 += splitterLength.Value;
                    num4 += minimumLength;
                }
                else if (splitterLength.IsFixed)
                {
                    val2 += splitterLength.Value;
                }
                else
                {
                    num2 += splitterLength.Value;
                    num3 += minimumLength;
                }
                SplitterPanel.SetIsMinimumReached(element, false);
            }
            double num5   = num4 + num3 + val2;
            double width  = ExtensionMethods.IsNonreal(availableSize.Width) ? val1_1 : availableSize.Width;
            double height = ExtensionMethods.IsNonreal(availableSize.Height) ? val1_2 : availableSize.Height;
            double val1_3 = orientation == Orientation.Horizontal ? width : height;
            double num6   = val2 == 0.0 ? 0.0 : Math.Min(val1_3, val2);
            double num7   = num2 == 0.0 ? 0.0 : Math.Max(0.0, val1_3 - num1 - val2);
            double num8   = num7 == 0.0 ? val1_3 - num6 : val1_3 - num7 - num6;

            if (num5 <= val1_3)
            {
                if (num7 < num3)
                {
                    num7 = num3;
                    num8 = val1_3 - num7 - num6;
                }
                foreach (UIElement element in list1)
                {
                    SplitterLength splitterLength = SplitterPanel.GetSplitterLength(element);
                    double         minimumLength  = SplitterPanel.GetMinimumLength(element);
                    if (splitterLength.IsFill)
                    {
                        if ((num2 == 0.0 ? 0.0 : splitterLength.Value / num2 * num7) < minimumLength)
                        {
                            SplitterPanel.SetIsMinimumReached(element, true);
                            num7 -= minimumLength;
                            num2 -= splitterLength.Value;
                        }
                    }
                    else if (splitterLength.IsStretch && (num1 == 0.0 ? 0.0 : splitterLength.Value / num1 * num8) < minimumLength)
                    {
                        SplitterPanel.SetIsMinimumReached(element, true);
                        num8 -= minimumLength;
                        num1 -= splitterLength.Value;
                    }
                }
            }
            Size        availableSize1 = new Size(width, height);
            List <Rect> list2          = new List <Rect>();
            Rect        rect           = new Rect(0.0, 0.0, width, height);
            bool        flag           = false;

            if (splitterPanel != null && splitterPanel.SnapsToDevicePixels)
            {
                PresentationSource presentationSource = PresentationSource.FromVisual((Visual)splitterPanel);
                if (presentationSource != null)
                {
                    Visual rootVisual = presentationSource.RootVisual;
                    if (rootVisual != null)
                    {
                        Transform transform = splitterPanel.TransformToAncestor(rootVisual) as Transform;
                        if (transform != null && transform.Value.HasInverse)
                        {
                            flag = true;
                        }
                    }
                }
            }
            double num9 = num6;

            foreach (UIElement element in list1)
            {
                SplitterLength splitterLength = SplitterPanel.GetSplitterLength(element);
                double         num10;
                if (!SplitterPanel.GetIsMinimumReached(element))
                {
                    if (splitterLength.IsFill)
                    {
                        num10 = num2 == 0.0 ? 0.0 : splitterLength.Value / num2 * num7;
                    }
                    else if (splitterLength.IsFixed)
                    {
                        num10 = splitterLength.Value;
                        if (num10 > num9)
                        {
                            num10 = num9;
                        }
                        num9 -= num10;
                    }
                    else
                    {
                        num10 = num1 == 0.0 ? 0.0 : splitterLength.Value / num1 * num8;
                    }
                }
                else
                {
                    num10 = SplitterPanel.GetMinimumLength(element);
                }
                if (flag)
                {
                    Point point1 = splitterPanel.Orientation != Orientation.Horizontal ? new Point(0.0, num10) : new Point(num10, 0.0);
                    Point point2 = splitterPanel.PointFromScreen(splitterPanel.PointToScreen(point1));
                    num10 = splitterPanel.Orientation != Orientation.Horizontal ? point2.Y : point2.X;
                }
                if (num10 < 0.0)
                {
                    num10 = 0.0;
                }
                if (remeasureElements)
                {
                    SplitterPanel.SetActualSplitterLength(element, num10);
                }
                if (orientation == Orientation.Horizontal)
                {
                    availableSize1.Width = num10;
                    list2.Add(new Rect(rect.Left, rect.Top, num10, rect.Height));
                    rect.X += num10;
                    if (remeasureElements)
                    {
                        element.Measure(availableSize1);
                    }
                }
                else
                {
                    availableSize1.Height = num10;
                    list2.Add(new Rect(rect.Left, rect.Top, rect.Width, num10));
                    rect.Y += num10;
                    if (remeasureElements)
                    {
                        element.Measure(availableSize1);
                    }
                }
            }
            elementBounds = list2.ToArray();
            return(new Size(width, height));
        }
Пример #2
0
 public static void RaiseEvent(this EventHandler eventHandler, object source)
 {
     ExtensionMethods.RaiseEvent(eventHandler, source, EventArgs.Empty);
 }
Пример #3
0
 public static TAncestorType FindAncestor <TAncestorType>(this Visual obj) where TAncestorType : Visual
 {
     return(ExtensionMethods.FindAncestor <TAncestorType, DependencyObject>((DependencyObject)obj, new Func <DependencyObject, DependencyObject>(ExtensionMethods.GetVisualOrLogicalParent)));
 }
Пример #4
0
 public static DependencyObject FindCommonAncestor(this DependencyObject obj1, DependencyObject obj2)
 {
     return(ExtensionMethods.FindCommonAncestor <DependencyObject>(obj1, obj2, new Func <DependencyObject, DependencyObject>(ExtensionMethods.GetVisualOrLogicalParent)));
 }