/// <summary>Draws the contents of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Border" />. </summary>
        /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> that defines the object to be drawn.</param>
        // Token: 0x06004266 RID: 16998 RVA: 0x0012FBE0 File Offset: 0x0012DDE0
        protected override void OnRender(DrawingContext dc)
        {
            bool     useLayoutRounding = base.UseLayoutRounding;
            DpiScale dpi = base.GetDpi();

            if (this._useComplexRenderCodePath)
            {
                StreamGeometry borderGeometryCache = this.BorderGeometryCache;
                Brush          brush;
                if (borderGeometryCache != null && (brush = this.BorderBrush) != null)
                {
                    dc.DrawGeometry(brush, null, borderGeometryCache);
                }
                StreamGeometry backgroundGeometryCache = this.BackgroundGeometryCache;
                if (backgroundGeometryCache != null && (brush = this.Background) != null)
                {
                    dc.DrawGeometry(brush, null, backgroundGeometryCache);
                    return;
                }
            }
            else
            {
                Thickness    borderThickness = this.BorderThickness;
                CornerRadius cornerRadius    = this.CornerRadius;
                double       topLeft         = cornerRadius.TopLeft;
                bool         flag            = !DoubleUtil.IsZero(topLeft);
                Brush        borderBrush;
                if (!borderThickness.IsZero && (borderBrush = this.BorderBrush) != null)
                {
                    Pen pen = this.LeftPenCache;
                    if (pen == null)
                    {
                        pen       = new Pen();
                        pen.Brush = borderBrush;
                        if (useLayoutRounding)
                        {
                            pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX);
                        }
                        else
                        {
                            pen.Thickness = borderThickness.Left;
                        }
                        if (borderBrush.IsFrozen)
                        {
                            pen.Freeze();
                        }
                        this.LeftPenCache = pen;
                    }
                    if (borderThickness.IsUniform)
                    {
                        double num       = pen.Thickness * 0.5;
                        Rect   rectangle = new Rect(new Point(num, num), new Point(base.RenderSize.Width - num, base.RenderSize.Height - num));
                        if (flag)
                        {
                            dc.DrawRoundedRectangle(null, pen, rectangle, topLeft, topLeft);
                        }
                        else
                        {
                            dc.DrawRectangle(null, pen, rectangle);
                        }
                    }
                    else
                    {
                        if (DoubleUtil.GreaterThan(borderThickness.Left, 0.0))
                        {
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(num, 0.0), new Point(num, base.RenderSize.Height));
                        }
                        if (DoubleUtil.GreaterThan(borderThickness.Right, 0.0))
                        {
                            pen = this.RightPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX);
                                }
                                else
                                {
                                    pen.Thickness = borderThickness.Right;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }
                                this.RightPenCache = pen;
                            }
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(base.RenderSize.Width - num, 0.0), new Point(base.RenderSize.Width - num, base.RenderSize.Height));
                        }
                        if (DoubleUtil.GreaterThan(borderThickness.Top, 0.0))
                        {
                            pen = this.TopPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = borderThickness.Top;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }
                                this.TopPenCache = pen;
                            }
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(0.0, num), new Point(base.RenderSize.Width, num));
                        }
                        if (DoubleUtil.GreaterThan(borderThickness.Bottom, 0.0))
                        {
                            pen = this.BottomPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = borderThickness.Bottom;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }
                                this.BottomPenCache = pen;
                            }
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(0.0, base.RenderSize.Height - num), new Point(base.RenderSize.Width, base.RenderSize.Height - num));
                        }
                    }
                }
                Brush background = this.Background;
                if (background != null)
                {
                    Point point;
                    Point point2;
                    if (useLayoutRounding)
                    {
                        point = new Point(UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY));
                        if (FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
                        {
                            point2 = new Point(UIElement.RoundLayoutValue(base.RenderSize.Width - borderThickness.Right, dpi.DpiScaleX), UIElement.RoundLayoutValue(base.RenderSize.Height - borderThickness.Bottom, dpi.DpiScaleY));
                        }
                        else
                        {
                            point2 = new Point(base.RenderSize.Width - UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX), base.RenderSize.Height - UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY));
                        }
                    }
                    else
                    {
                        point  = new Point(borderThickness.Left, borderThickness.Top);
                        point2 = new Point(base.RenderSize.Width - borderThickness.Right, base.RenderSize.Height - borderThickness.Bottom);
                    }
                    if (point2.X > point.X && point2.Y > point.Y)
                    {
                        if (flag)
                        {
                            Border.Radii radii    = new Border.Radii(cornerRadius, borderThickness, false);
                            double       topLeft2 = radii.TopLeft;
                            dc.DrawRoundedRectangle(background, null, new Rect(point, point2), topLeft2, topLeft2);
                            return;
                        }
                        dc.DrawRectangle(background, null, new Rect(point, point2));
                    }
                }
            }
        }
        // Token: 0x06004268 RID: 17000 RVA: 0x001301EC File Offset: 0x0012E3EC
        private static bool AreUniformCorners(CornerRadius borderRadii)
        {
            double topLeft = borderRadii.TopLeft;

            return(DoubleUtil.AreClose(topLeft, borderRadii.TopRight) && DoubleUtil.AreClose(topLeft, borderRadii.BottomLeft) && DoubleUtil.AreClose(topLeft, borderRadii.BottomRight));
        }
Beispiel #3
0
        /// <summary>
        ///     This is the method that responds to the KeyDown event.
        /// </summary>
        /// <param name="e">Event Arguments</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool handled = true;
            Key  key     = e.Key;

            switch (key)
            {
            case Key.Divide:
            case Key.Oem2:
                // Ctrl-Fowardslash = Select All
                if (((Keyboard.Modifiers & ModifierKeys.Control) == (ModifierKeys.Control)) && (SelectionMode == SelectionMode.Extended))
                {
                    SelectAll();
                }
                else
                {
                    handled = false;
                }

                break;

            case Key.Oem5:
                // Ctrl-Backslash = Select the item with focus.
                if (((Keyboard.Modifiers & ModifierKeys.Control) == (ModifierKeys.Control)) && (SelectionMode == SelectionMode.Extended))
                {
                    ListBoxItem focusedItemUI = (FocusedInfo != null) ? FocusedInfo.Container as ListBoxItem : null;
                    if (focusedItemUI != null)
                    {
                        MakeSingleSelection(focusedItemUI);
                    }
                }
                else
                {
                    handled = false;
                }

                break;

            case Key.Up:
            case Key.Left:
            case Key.Down:
            case Key.Right:
            {
                KeyboardNavigation.ShowFocusVisual();

                // Depend on logical orientation we decide to move focus or just scroll
                // shouldScroll also detects if we can scroll more in this direction
                bool shouldScroll = ScrollHost != null;
                if (shouldScroll)
                {
                    shouldScroll =
                        ((key == Key.Down && IsLogicalHorizontal && DoubleUtil.GreaterThan(ScrollHost.ScrollableHeight, ScrollHost.VerticalOffset))) ||
                        ((key == Key.Up && IsLogicalHorizontal && DoubleUtil.GreaterThan(ScrollHost.VerticalOffset, 0d))) ||
                        ((key == Key.Right && IsLogicalVertical && DoubleUtil.GreaterThan(ScrollHost.ScrollableWidth, ScrollHost.HorizontalOffset))) ||
                        ((key == Key.Left && IsLogicalVertical && DoubleUtil.GreaterThan(ScrollHost.HorizontalOffset, 0d)));
                }

                if (shouldScroll)
                {
                    ScrollHost.ScrollInDirection(e);
                }
                else
                {
                    if ((ItemsHost != null && ItemsHost.IsKeyboardFocusWithin) || IsKeyboardFocused)
                    {
                        if (!NavigateByLine(KeyboardNavigation.KeyToTraversalDirection(key),
                                            new ItemNavigateArgs(e.Device, Keyboard.Modifiers)))
                        {
                            handled = false;
                        }
                    }
                    else
                    {
                        handled = false;
                    }
                }
            }
            break;

            case Key.Home:
                NavigateToStart(new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            case Key.End:
                NavigateToEnd(new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            case Key.Space:
            case Key.Enter:
            {
                if (e.Key == Key.Enter && (bool)GetValue(KeyboardNavigation.AcceptsReturnProperty) == false)
                {
                    handled = false;
                    break;
                }

                // If the event came from a ListBoxItem that's a child of ours, then look at it.
                ListBoxItem source = e.OriginalSource as ListBoxItem;

                // If ALT is down & Ctrl is up, then we shouldn't handle this. (system menu)
                if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Alt)) == ModifierKeys.Alt)
                {
                    handled = false;
                    break;
                }

                // If the user hits just "space" while text searching, do not handle the event
                // Note: Space cannot be the first character in a string sent to ITS.
                if (IsTextSearchEnabled && Keyboard.Modifiers == ModifierKeys.None)
                {
                    TextSearch instance = TextSearch.EnsureInstance(this);
                    // If TextSearch enabled and Prefix is not empty
                    // then let this SPACE go so ITS can process it.
                    if (instance != null && (instance.GetCurrentPrefix() != String.Empty))
                    {
                        handled = false;
                        break;
                    }
                }

                if (source != null && ItemsControlFromItemContainer(source) == this)
                {
                    switch (SelectionMode)
                    {
                    case SelectionMode.Single:
                        if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                        {
                            MakeToggleSelection(source);
                        }
                        else
                        {
                            MakeSingleSelection(source);
                        }

                        break;

                    case SelectionMode.Multiple:
                        MakeToggleSelection(source);
                        break;

                    case SelectionMode.Extended:
                        if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Control)
                        {
                            // Only CONTROL
                            MakeToggleSelection(source);
                        }
                        else if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Shift)
                        {
                            // Only SHIFT
                            MakeAnchorSelection(source, true /* clearCurrent */);
                        }
                        else if ((Keyboard.Modifiers & ModifierKeys.Shift) == 0)
                        {
                            MakeSingleSelection(source);
                        }
                        else
                        {
                            handled = false;
                        }

                        break;
                    }
                }
                else
                {
                    handled = false;
                }
            }
            break;

            case Key.PageUp:
                NavigateByPage(FocusNavigationDirection.Up, new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            case Key.PageDown:
                NavigateByPage(FocusNavigationDirection.Down, new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            default:
                handled = false;
                break;
            }
            if (handled)
            {
                e.Handled = true;
            }
            else
            {
                base.OnKeyDown(e);
            }
        }
        /// <summary>Arranges the contents of a <see cref="T:System.Windows.Controls.Border" /> element.</summary>
        /// <param name="finalSize">The <see cref="T:System.Windows.Size" /> this element uses to arrange its child element.</param>
        /// <returns>The <see cref="T:System.Windows.Size" /> that represents the arranged size of this <see cref="T:System.Windows.Controls.Border" /> element and its child element.</returns>
        // Token: 0x06004265 RID: 16997 RVA: 0x0012F998 File Offset: 0x0012DB98
        protected override Size ArrangeOverride(Size finalSize)
        {
            Thickness borderThickness = this.BorderThickness;

            if (base.UseLayoutRounding && !FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
            {
                DpiScale dpi = base.GetDpi();
                borderThickness = new Thickness(UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY), UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY));
            }
            Rect      rect  = new Rect(finalSize);
            Rect      rect2 = Border.HelperDeflateRect(rect, borderThickness);
            UIElement child = this.Child;

            if (child != null)
            {
                Rect finalRect = Border.HelperDeflateRect(rect2, this.Padding);
                child.Arrange(finalRect);
            }
            CornerRadius cornerRadius = this.CornerRadius;
            Brush        borderBrush  = this.BorderBrush;
            bool         flag         = Border.AreUniformCorners(cornerRadius);

            this._useComplexRenderCodePath = !flag;
            if (!this._useComplexRenderCodePath && borderBrush != null)
            {
                SolidColorBrush solidColorBrush = borderBrush as SolidColorBrush;
                bool            isUniform       = borderThickness.IsUniform;
                this._useComplexRenderCodePath = (solidColorBrush == null || (solidColorBrush.Color.A < byte.MaxValue && !isUniform) || (!DoubleUtil.IsZero(cornerRadius.TopLeft) && !isUniform));
            }
            if (this._useComplexRenderCodePath)
            {
                Border.Radii   radii          = new Border.Radii(cornerRadius, borderThickness, false);
                StreamGeometry streamGeometry = null;
                if (!DoubleUtil.IsZero(rect2.Width) && !DoubleUtil.IsZero(rect2.Height))
                {
                    streamGeometry = new StreamGeometry();
                    using (StreamGeometryContext streamGeometryContext = streamGeometry.Open())
                    {
                        Border.GenerateGeometry(streamGeometryContext, rect2, radii);
                    }
                    streamGeometry.Freeze();
                    this.BackgroundGeometryCache = streamGeometry;
                }
                else
                {
                    this.BackgroundGeometryCache = null;
                }
                if (!DoubleUtil.IsZero(rect.Width) && !DoubleUtil.IsZero(rect.Height))
                {
                    Border.Radii   radii2          = new Border.Radii(cornerRadius, borderThickness, true);
                    StreamGeometry streamGeometry2 = new StreamGeometry();
                    using (StreamGeometryContext streamGeometryContext2 = streamGeometry2.Open())
                    {
                        Border.GenerateGeometry(streamGeometryContext2, rect, radii2);
                        if (streamGeometry != null)
                        {
                            Border.GenerateGeometry(streamGeometryContext2, rect2, radii);
                        }
                    }
                    streamGeometry2.Freeze();
                    this.BorderGeometryCache = streamGeometry2;
                }
                else
                {
                    this.BorderGeometryCache = null;
                }
            }
            else
            {
                this.BackgroundGeometryCache = null;
                this.BorderGeometryCache     = null;
            }
            return(finalSize);
        }
 private bool CheckIsPointBetween(Rect rect, double pointY)
 {
     // return rect.Top <= pointY <= rect.Bottom
     return(DoubleUtil.LessThanOrClose(rect.Top, pointY) &&
            DoubleUtil.LessThanOrClose(pointY, rect.Bottom));
 }
Beispiel #6
0
        // Token: 0x060058E9 RID: 22761 RVA: 0x00189730 File Offset: 0x00187930
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scrollHost = base.ScrollHost;

            if (scrollHost != null)
            {
                bool flag = base.FlowDirection == FlowDirection.RightToLeft;
                switch (key)
                {
                case Key.Prior:
                    if (DoubleUtil.GreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageUp();
                    }
                    else
                    {
                        scrollHost.PageLeft();
                    }
                    return(true);

                case Key.Next:
                    if (DoubleUtil.GreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageDown();
                    }
                    else
                    {
                        scrollHost.PageRight();
                    }
                    return(true);

                case Key.End:
                    scrollHost.ScrollToBottom();
                    return(true);

                case Key.Home:
                    scrollHost.ScrollToTop();
                    return(true);

                case Key.Left:
                    if (flag)
                    {
                        scrollHost.LineRight();
                    }
                    else
                    {
                        scrollHost.LineLeft();
                    }
                    return(true);

                case Key.Up:
                    scrollHost.LineUp();
                    return(true);

                case Key.Right:
                    if (flag)
                    {
                        scrollHost.LineLeft();
                    }
                    else
                    {
                        scrollHost.LineRight();
                    }
                    return(true);

                case Key.Down:
                    scrollHost.LineDown();
                    return(true);
                }
            }
            return(false);
        }
Beispiel #7
0
            /// <summary>
            /// OnLayoutUpdated handler. Validates that all participating definitions
            /// have updated min size value. Forces another layout update cycle if needed.
            /// </summary>
            private void OnLayoutUpdated(object sender, EventArgs e)
            {
                double sharedMinSize = 0;

                //  accumulate min size of all participating definitions
                for (int i = 0, count = _registry.Count; i < count; ++i)
                {
                    sharedMinSize = Math.Max(sharedMinSize, _registry[i]._minSize);
                }

                bool sharedMinSizeChanged = !DoubleUtil.AreClose(_minSize, sharedMinSize);

                //  compare accumulated min size with min sizes of the individual definitions
                for (int i = 0, count = _registry.Count; i < count; ++i)
                {
                    DefinitionBase definitionBase = _registry[i];

                    // we'll set d.UseSharedMinimum to maintain the invariant:
                    //      d.UseSharedMinimum iff d._minSize < this.MinSize
                    // i.e. iff d is not a "long-pole" definition.
                    //
                    // Measure/Arrange of d's Grid uses d._minSize for long-pole
                    // definitions, and max(d._minSize, shared size) for
                    // short-pole definitions.  This distinction allows us to react
                    // to changes in "long-pole-ness" more efficiently and correctly,
                    // by avoiding remeasures when a long-pole definition changes.
                    bool useSharedMinimum = !DoubleUtil.AreClose(definitionBase._minSize, sharedMinSize);

                    // before doing that, determine whether d's Grid needs to be remeasured.
                    // It's important _not_ to remeasure if the last measure is still
                    // valid, otherwise infinite loops are possible
                    bool measureIsValid;
                    if (!definitionBase.UseSharedMinimum)
                    {
                        // d was a long-pole.  measure is valid iff it's still a long-pole,
                        // since previous measure didn't use shared size.
                        measureIsValid = !useSharedMinimum;
                    }
                    else if (useSharedMinimum)
                    {
                        // d was a short-pole, and still is.  measure is valid
                        // iff the shared size didn't change
                        measureIsValid = !sharedMinSizeChanged;
                    }
                    else
                    {
                        // d was a short-pole, but is now a long-pole.  This can
                        // happen in several ways:
                        //  a. d's minSize increased to or past the old shared size
                        //  b. other long-pole definitions decreased, leaving
                        //      d as the new winner
                        // In the former case, the measure is valid - it used
                        // d's new larger minSize.  In the latter case, the
                        // measure is invalid - it used the old shared size,
                        // which is larger than d's (possibly changed) minSize
                        measureIsValid = (definitionBase.LayoutWasUpdated &&
                                          DoubleUtil.GreaterThanOrClose(definitionBase._minSize, this.MinSize));
                    }

                    if (!measureIsValid)
                    {
                        Grid parentGrid = (Grid)definitionBase.Parent;
                        parentGrid.InvalidateMeasure();
                    }
                    else if (!DoubleUtil.AreClose(sharedMinSize, definitionBase.SizeCache))
                    {
                        //  if measure is valid then also need to check arrange.
                        //  Note: definitionBase.SizeCache is volatile but at this point
                        //  it contains up-to-date final size
                        Grid parentGrid = (Grid)definitionBase.Parent;
                        parentGrid.InvalidateArrange();
                    }

                    // now we can restore the invariant, and clear the layout flag
                    definitionBase.UseSharedMinimum = useSharedMinimum;
                    definitionBase.LayoutWasUpdated = false;
                }

                _minSize = sharedMinSize;

                _layoutUpdatedHost.LayoutUpdated -= _layoutUpdated;
                _layoutUpdatedHost = null;

                _broadcastInvalidation = true;
            }
Beispiel #8
0
        /// <summary>
        ///     Parses a DataGridLength from a string given the CultureInfo.
        /// </summary>
        /// <param name="s">String to parse from.</param>
        /// <param name="cultureInfo">Culture Info.</param>
        /// <returns>Newly created DataGridLength instance.</returns>
        /// <remarks>
        /// Formats:
        /// "[value][unit]"
        ///     [value] is a double
        ///     [unit] is a string in DataGridLength._unitTypes connected to a DataGridLengthUnitType
        /// "[value]"
        ///     As above, but the DataGridLengthUnitType is assumed to be DataGridLengthUnitType.Pixel
        /// "[unit]"
        ///     As above, but the value is assumed to be 1.0
        ///     This is only acceptable for a subset of DataGridLengthUnitType: Auto
        /// </remarks>
        private static DataGridLength ConvertFromString(string s, CultureInfo cultureInfo)
        {
            string goodString = s.Trim().ToLowerInvariant();

            // Check if the string matches any of the descriptive unit types.
            // In these cases, there is no need to parse a value.
            for (int i = 0; i < NumDescriptiveUnits; i++)
            {
                string unitString = _unitStrings[i];
                if (goodString == unitString)
                {
                    return(new DataGridLength(1.0, (DataGridLengthUnitType)i));
                }
            }

            double value = 0.0;
            DataGridLengthUnitType unit = DataGridLengthUnitType.Pixel;
            int    strLen     = goodString.Length;
            int    strLenUnit = 0;
            double unitFactor = 1.0;

            // Check if the string contains a non-descriptive unit at the end.
            int numUnitStrings = _unitStrings.Length;

            for (int i = NumDescriptiveUnits; i < numUnitStrings; i++)
            {
                string unitString = _unitStrings[i];

                // Note: This is NOT a culture specific comparison.
                // This is by design: we want the same unit string table to work across all cultures.
                if (goodString.EndsWith(unitString, StringComparison.Ordinal))
                {
                    strLenUnit = unitString.Length;
                    unit       = (DataGridLengthUnitType)i;
                    break;
                }
            }

            // Couldn't match a standard unit type, try a non-standard unit type.
            if (strLenUnit == 0)
            {
                numUnitStrings = _nonStandardUnitStrings.Length;
                for (int i = 0; i < numUnitStrings; i++)
                {
                    string unitString = _nonStandardUnitStrings[i];

                    // Note: This is NOT a culture specific comparison.
                    // This is by design: we want the same unit string table to work across all cultures.
                    if (goodString.EndsWith(unitString, StringComparison.Ordinal))
                    {
                        strLenUnit = unitString.Length;
                        unitFactor = _pixelUnitFactors[i];
                        break;
                    }
                }
            }

            // Check if there is a numerical value to parse
            if (strLen == strLenUnit)
            {
                // There is no numerical value to parse
                if (unit == DataGridLengthUnitType.Star)
                {
                    // Star's value defaults to 1. Anyone else would be 0.
                    value = 1.0;
                }
            }
            else
            {
                // Parse a numerical value
                Debug.Assert(
                    (unit == DataGridLengthUnitType.Pixel) || DoubleUtil.AreClose(unitFactor, 1.0),
                    "unitFactor should not be other than 1.0 unless the unit type is Pixel.");

                ReadOnlySpan <char> valueString = goodString.AsSpan(0, strLen - strLenUnit);
                value = double.Parse(valueString, provider: cultureInfo) * unitFactor;
            }

            return(new DataGridLength(value, unit));
        }
Beispiel #9
0
        /// <summary>
        /// <see cref="DependencyProperty.ValidateValueCallback"/>
        /// </summary>
        /// <remarks>
        /// This method needs to be internal to be accessable from derived classes.
        /// </remarks>
        internal static bool IsUserMinSizePropertyValueValid(object value)
        {
            double v = (double)value;

            return(!DoubleUtil.IsNaN(v) && v >= 0.0d && !Double.IsPositiveInfinity(v));
        }
Beispiel #10
0
        /// <summary>
        /// <see cref="DependencyProperty.ValidateValueCallback"/>
        /// </summary>
        /// <remarks>
        /// This method needs to be internal to be accessable from derived classes.
        /// </remarks>
        internal static bool IsUserMaxSizePropertyValueValid(object value)
        {
            double v = (double)value;

            return(!DoubleUtil.IsNaN(v) && v >= 0.0d);
        }
Beispiel #11
0
        private void ProcessThumbDragDelta(DragDeltaEventArgs e)
        {
            // Process thumb event only if Thumb styled parent is a ToolBar under the TollBarTray
            Thumb thumb = e.OriginalSource as Thumb;

            if (thumb != null)
            {
                ToolBar toolBar = thumb.TemplatedParent as ToolBar;
                if (toolBar != null && toolBar.Parent == this)
                {
                    // _bandsDirty would be true at this time only when a Measure gets
                    // skipped between two mouse moves. Ideally that should not happen
                    // but VS has proved that it can. Hence making the code more robust.
                    // Uncomment the line below if the measure skip issue ever gets fixed.
                    // Debug.Assert(!_bandsDirty, "Bands should not be dirty at this point");
                    if (_bandsDirty)
                    {
                        GenerateBands();
                    }

                    bool   fHorizontal = (Orientation == Orientation.Horizontal);
                    int    currentBand = toolBar.Band;
                    Point  pointRelativeToToolBarTray = Mouse.PrimaryDevice.GetPosition((IInputElement)this);
                    Point  pointRelativeToToolBar     = TransformPointToToolBar(toolBar, pointRelativeToToolBarTray);
                    int    hittestBand = GetBandFromOffset(fHorizontal ? pointRelativeToToolBarTray.Y : pointRelativeToToolBarTray.X);
                    double newPosition;
                    double thumbChange = fHorizontal ? e.HorizontalChange : e.VerticalChange;
                    double toolBarPosition;
                    if (fHorizontal)
                    {
                        toolBarPosition = pointRelativeToToolBarTray.X - pointRelativeToToolBar.X;
                    }
                    else
                    {
                        toolBarPosition = pointRelativeToToolBarTray.Y - pointRelativeToToolBar.Y;
                    }
                    newPosition = toolBarPosition + thumbChange; // New toolBar position

                    // Move within the band
                    if (hittestBand == currentBand)
                    {
                        List <ToolBar> band         = _bands[currentBand].Band;
                        int            toolBarIndex = toolBar.BandIndex;

                        // Move ToolBar within the band
                        if (DoubleUtil.LessThan(thumbChange, 0)) // Move left/up
                        {
                            double toolBarsTotalMinimum = ToolBarsTotalMinimum(band, 0, toolBarIndex - 1);
                            // Check if minimized toolbars will fit in the range
                            if (DoubleUtil.LessThanOrClose(toolBarsTotalMinimum, newPosition))
                            {
                                ShrinkToolBars(band, 0, toolBarIndex - 1, -thumbChange);
                            }
                            else if (toolBarIndex > 0) // Swap toolbars
                            {
                                ToolBar prevToolBar = band[toolBarIndex - 1];
                                Point   pointRelativeToPreviousToolBar = TransformPointToToolBar(prevToolBar, pointRelativeToToolBarTray);
                                // if pointer in on the left side of previous toolbar
                                if (DoubleUtil.LessThan((fHorizontal ? pointRelativeToPreviousToolBar.X : pointRelativeToPreviousToolBar.Y), 0))
                                {
                                    prevToolBar.BandIndex = toolBarIndex;
                                    band[toolBarIndex]    = prevToolBar;

                                    toolBar.BandIndex      = toolBarIndex - 1;
                                    band[toolBarIndex - 1] = toolBar;

                                    if (toolBarIndex + 1 == band.Count) // If toolBar was the last item in the band
                                    {
                                        prevToolBar.ClearValue(fHorizontal ? WidthProperty : HeightProperty);
                                    }
                                }
                                else
                                { // Move to the left/up and shring the other toolbars
                                    if (fHorizontal)
                                    {
                                        if (DoubleUtil.LessThan(toolBarsTotalMinimum, pointRelativeToToolBarTray.X - pointRelativeToToolBar.X))
                                        {
                                            ShrinkToolBars(band, 0, toolBarIndex - 1, pointRelativeToToolBarTray.X - pointRelativeToToolBar.X - toolBarsTotalMinimum);
                                        }
                                    }
                                    else
                                    {
                                        if (DoubleUtil.LessThan(toolBarsTotalMinimum, pointRelativeToToolBarTray.Y - pointRelativeToToolBar.Y))
                                        {
                                            ShrinkToolBars(band, 0, toolBarIndex - 1, pointRelativeToToolBarTray.Y - pointRelativeToToolBar.Y - toolBarsTotalMinimum);
                                        }
                                    }
                                }
                            }
                        }
                        else // Move right/down
                        {
                            double toolBarsTotalMaximum = ToolBarsTotalMaximum(band, 0, toolBarIndex - 1);

                            if (DoubleUtil.GreaterThan(toolBarsTotalMaximum, newPosition))
                            {
                                ExpandToolBars(band, 0, toolBarIndex - 1, thumbChange);
                            }
                            else
                            {
                                if (toolBarIndex < band.Count - 1) // Swap toolbars
                                {
                                    ToolBar nextToolBar = band[toolBarIndex + 1];
                                    Point   pointRelativeToNextToolBar = TransformPointToToolBar(nextToolBar, pointRelativeToToolBarTray);
                                    // if pointer in on the right side of next toolbar
                                    if (DoubleUtil.GreaterThanOrClose((fHorizontal ? pointRelativeToNextToolBar.X : pointRelativeToNextToolBar.Y), 0))
                                    {
                                        nextToolBar.BandIndex = toolBarIndex;
                                        band[toolBarIndex]    = nextToolBar;

                                        toolBar.BandIndex      = toolBarIndex + 1;
                                        band[toolBarIndex + 1] = toolBar;
                                        if (toolBarIndex + 2 == band.Count) // If toolBar becomes the last item in the band
                                        {
                                            toolBar.ClearValue(fHorizontal ? WidthProperty : HeightProperty);
                                        }
                                    }
                                    else
                                    {
                                        ExpandToolBars(band, 0, toolBarIndex - 1, thumbChange);
                                    }
                                }
                                else
                                {
                                    ExpandToolBars(band, 0, toolBarIndex - 1, thumbChange);
                                }
                            }
                        }
                    }
                    else // Move ToolBar to another band
                    {
                        _bandsDirty  = true;
                        toolBar.Band = hittestBand;
                        toolBar.ClearValue(fHorizontal ? WidthProperty : HeightProperty);

                        // move to another existing band
                        if (hittestBand >= 0 && hittestBand < _bands.Count)
                        {
                            MoveToolBar(toolBar, hittestBand, newPosition);
                        }

                        List <ToolBar> oldBand = _bands[currentBand].Band;
                        // currentBand should restore sizes to Auto
                        for (int i = 0; i < oldBand.Count; i++)
                        {
                            ToolBar currentToolBar = oldBand[i];
                            currentToolBar.ClearValue(fHorizontal ? WidthProperty : HeightProperty);
                        }
                    }

                    e.Handled = true;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Updates DesiredSize of the ToolBarTray. Called by parent UIElement.
        /// This is the first pass of layout.
        /// MeasureOverride distributes all ToolBars in bands depend on Band and BandIndex properties.
        /// All ToolBars with the same Band are places in one band. After that they are sorted by BandIndex.
        /// </summary>
        /// <param name="constraint">Constraint size is an "upper limit" that ToolBarTray should not exceed.</param>
        /// <returns>ToolBarTray' desired size.</returns>
        protected override Size MeasureOverride(Size constraint)
        {
            GenerateBands();

            Size toolBarTrayDesiredSize = new Size();
            int  bandIndex;
            int  toolBarIndex;
            bool fHorizontal     = (Orientation == Orientation.Horizontal);
            Size childConstraint = new Size(Double.PositiveInfinity, Double.PositiveInfinity);

            for (bandIndex = 0; bandIndex < _bands.Count; bandIndex++)
            {
                // Calculate the available size before we measure the children.
                // remainingLength is the constraint minus sum of all minimum sizes
                double         remainingLength = fHorizontal ? constraint.Width : constraint.Height;
                List <ToolBar> band            = _bands[bandIndex].Band;
                double         bandThickness   = 0d;
                double         bandLength      = 0d;
                for (toolBarIndex = 0; toolBarIndex < band.Count; toolBarIndex++)
                {
                    ToolBar toolBar = band[toolBarIndex];
                    remainingLength -= toolBar.MinLength;
                    if (DoubleUtil.LessThan(remainingLength, 0))
                    {
                        remainingLength = 0;
                        break;
                    }
                }

                // Measure all children passing the remainingLength as a constraint
                for (toolBarIndex = 0; toolBarIndex < band.Count; toolBarIndex++)
                {
                    ToolBar toolBar = band[toolBarIndex];
                    remainingLength += toolBar.MinLength;
                    if (fHorizontal)
                    {
                        childConstraint.Width = remainingLength;
                    }
                    else
                    {
                        childConstraint.Height = remainingLength;
                    }
                    toolBar.Measure(childConstraint);
                    bandThickness    = Math.Max(bandThickness, fHorizontal ? toolBar.DesiredSize.Height : toolBar.DesiredSize.Width);
                    bandLength      += fHorizontal ? toolBar.DesiredSize.Width : toolBar.DesiredSize.Height;
                    remainingLength -= fHorizontal ? toolBar.DesiredSize.Width : toolBar.DesiredSize.Height;
                    if (DoubleUtil.LessThan(remainingLength, 0))
                    {
                        remainingLength = 0;
                    }
                }

                // Store band thickness in the BandInfo property
                _bands[bandIndex].Thickness = bandThickness;

                if (fHorizontal)
                {
                    toolBarTrayDesiredSize.Height += bandThickness;
                    toolBarTrayDesiredSize.Width   = Math.Max(toolBarTrayDesiredSize.Width, bandLength);
                }
                else
                {
                    toolBarTrayDesiredSize.Width += bandThickness;
                    toolBarTrayDesiredSize.Height = Math.Max(toolBarTrayDesiredSize.Height, bandLength);
                }
            }

            return(toolBarTrayDesiredSize);
        }
Beispiel #13
0
        // Token: 0x06005698 RID: 22168 RVA: 0x0017F0C4 File Offset: 0x0017D2C4
        internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)
        {
            Size size = default(Size);
            UIElementCollection internalChildren = measureElement.InternalChildren;
            Size   availableSize = constraint;
            bool   flag          = measureElement.Orientation == Orientation.Horizontal;
            int    num           = -1;
            int    i;
            double num2;

            if (flag)
            {
                availableSize.Width = double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanVerticallyScroll)
                {
                    availableSize.Height = double.PositiveInfinity;
                }
                i    = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.X, internalChildren.Count) : 0);
                num2 = constraint.Width;
            }
            else
            {
                availableSize.Height = double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll)
                {
                    availableSize.Width = double.PositiveInfinity;
                }
                i    = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.Y, internalChildren.Count) : 0);
                num2 = constraint.Height;
            }
            int j     = 0;
            int count = internalChildren.Count;

            while (j < count)
            {
                UIElement uielement = internalChildren[j];
                if (uielement != null)
                {
                    uielement.Measure(availableSize);
                    Size   desiredSize = uielement.DesiredSize;
                    double num3;
                    if (flag)
                    {
                        size.Width += desiredSize.Width;
                        size.Height = Math.Max(size.Height, desiredSize.Height);
                        num3        = desiredSize.Width;
                    }
                    else
                    {
                        size.Width   = Math.Max(size.Width, desiredSize.Width);
                        size.Height += desiredSize.Height;
                        num3         = desiredSize.Height;
                    }
                    if (measureElement.IsScrolling && num == -1 && j >= i)
                    {
                        num2 -= num3;
                        if (DoubleUtil.LessThanOrClose(num2, 0.0))
                        {
                            num = j;
                        }
                    }
                }
                j++;
            }
            if (measureElement.IsScrolling)
            {
                Size   viewport = constraint;
                Size   extent   = size;
                Vector offset   = scrollData.Offset;
                if (num == -1)
                {
                    num = internalChildren.Count - 1;
                }
                while (i > 0)
                {
                    double num4 = num2;
                    if (flag)
                    {
                        num4 -= internalChildren[i - 1].DesiredSize.Width;
                    }
                    else
                    {
                        num4 -= internalChildren[i - 1].DesiredSize.Height;
                    }
                    if (DoubleUtil.LessThan(num4, 0.0))
                    {
                        break;
                    }
                    i--;
                    num2 = num4;
                }
                int count2 = internalChildren.Count;
                int num5   = num - i;
                if (num5 == 0 || DoubleUtil.GreaterThanOrClose(num2, 0.0))
                {
                    num5++;
                }
                if (flag)
                {
                    scrollData.SetPhysicalViewport(viewport.Width);
                    viewport.Width = (double)num5;
                    extent.Width   = (double)count2;
                    offset.X       = (double)i;
                    offset.Y       = Math.Max(0.0, Math.Min(offset.Y, extent.Height - viewport.Height));
                }
                else
                {
                    scrollData.SetPhysicalViewport(viewport.Height);
                    viewport.Height = (double)num5;
                    extent.Height   = (double)count2;
                    offset.Y        = (double)i;
                    offset.X        = Math.Max(0.0, Math.Min(offset.X, extent.Width - viewport.Width));
                }
                size.Width  = Math.Min(size.Width, constraint.Width);
                size.Height = Math.Min(size.Height, constraint.Height);
                StackPanel.VerifyScrollingData(measureElement, scrollData, viewport, extent, offset);
            }
            return(size);
        }
        // Token: 0x0600426A RID: 17002 RVA: 0x001302AC File Offset: 0x0012E4AC
        private static void GenerateGeometry(StreamGeometryContext ctx, Rect rect, Border.Radii radii)
        {
            Point point  = new Point(radii.LeftTop, 0.0);
            Point point2 = new Point(rect.Width - radii.RightTop, 0.0);
            Point point3 = new Point(rect.Width, radii.TopRight);
            Point point4 = new Point(rect.Width, rect.Height - radii.BottomRight);
            Point point5 = new Point(rect.Width - radii.RightBottom, rect.Height);
            Point point6 = new Point(radii.LeftBottom, rect.Height);
            Point point7 = new Point(0.0, rect.Height - radii.BottomLeft);
            Point point8 = new Point(0.0, radii.TopLeft);

            if (point.X > point2.X)
            {
                double x = radii.LeftTop / (radii.LeftTop + radii.RightTop) * rect.Width;
                point.X  = x;
                point2.X = x;
            }
            if (point3.Y > point4.Y)
            {
                double y = radii.TopRight / (radii.TopRight + radii.BottomRight) * rect.Height;
                point3.Y = y;
                point4.Y = y;
            }
            if (point5.X < point6.X)
            {
                double x2 = radii.LeftBottom / (radii.LeftBottom + radii.RightBottom) * rect.Width;
                point5.X = x2;
                point6.X = x2;
            }
            if (point7.Y < point8.Y)
            {
                double y2 = radii.TopLeft / (radii.TopLeft + radii.BottomLeft) * rect.Height;
                point7.Y = y2;
                point8.Y = y2;
            }
            Vector vector = new Vector(rect.TopLeft.X, rect.TopLeft.Y);

            point  += vector;
            point2 += vector;
            point3 += vector;
            point4 += vector;
            point5 += vector;
            point6 += vector;
            point7 += vector;
            point8 += vector;
            ctx.BeginFigure(point, true, true);
            ctx.LineTo(point2, true, false);
            double num  = rect.TopRight.X - point2.X;
            double num2 = point3.Y - rect.TopRight.Y;

            if (!DoubleUtil.IsZero(num) || !DoubleUtil.IsZero(num2))
            {
                ctx.ArcTo(point3, new Size(num, num2), 0.0, false, SweepDirection.Clockwise, true, false);
            }
            ctx.LineTo(point4, true, false);
            num  = rect.BottomRight.X - point5.X;
            num2 = rect.BottomRight.Y - point4.Y;
            if (!DoubleUtil.IsZero(num) || !DoubleUtil.IsZero(num2))
            {
                ctx.ArcTo(point5, new Size(num, num2), 0.0, false, SweepDirection.Clockwise, true, false);
            }
            ctx.LineTo(point6, true, false);
            num  = point6.X - rect.BottomLeft.X;
            num2 = rect.BottomLeft.Y - point7.Y;
            if (!DoubleUtil.IsZero(num) || !DoubleUtil.IsZero(num2))
            {
                ctx.ArcTo(point7, new Size(num, num2), 0.0, false, SweepDirection.Clockwise, true, false);
            }
            ctx.LineTo(point8, true, false);
            num  = point.X - rect.TopLeft.X;
            num2 = point8.Y - rect.TopLeft.Y;
            if (!DoubleUtil.IsZero(num) || !DoubleUtil.IsZero(num2))
            {
                ctx.ArcTo(point, new Size(num, num2), 0.0, false, SweepDirection.Clockwise, true, false);
            }
        }
Beispiel #15
0
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scroller = ScrollHost;

            if (scroller != null)
            {
                bool invert = (FlowDirection == FlowDirection.RightToLeft);
                switch (key)
                {
                case Key.Up:
                    scroller.LineUp();
                    return(true);

                case Key.Down:
                    scroller.LineDown();
                    return(true);

                case Key.Left:
                    if (invert)
                    {
                        scroller.LineRight();
                    }
                    else
                    {
                        scroller.LineLeft();
                    }
                    return(true);

                case Key.Right:
                    if (invert)
                    {
                        scroller.LineLeft();
                    }
                    else
                    {
                        scroller.LineRight();
                    }
                    return(true);

                case Key.Home:
                    scroller.ScrollToTop();
                    return(true);

                case Key.End:
                    scroller.ScrollToBottom();
                    return(true);

                case Key.PageUp:
                    //if vertically scrollable - go vertical, otherwise horizontal
                    if (DoubleUtil.GreaterThan(scroller.ExtentHeight, scroller.ViewportHeight))
                    {
                        scroller.PageUp();
                    }
                    else
                    {
                        scroller.PageLeft();
                    }
                    return(true);

                case Key.PageDown:
                    //if vertically scrollable - go vertical, otherwise horizontal
                    if (DoubleUtil.GreaterThan(scroller.ExtentHeight, scroller.ViewportHeight))
                    {
                        scroller.PageDown();
                    }
                    else
                    {
                        scroller.PageRight();
                    }
                    return(true);
                }
            }

            return(false);
        }
Beispiel #16
0
        /// <summary>
        /// This is a helper function that computes scale factors depending on a target size and a content size
        /// </summary>
        /// <param name="availableSize">Size into which the content is being fitted.</param>
        /// <param name="contentSize">Size of the content, measured natively (unconstrained).</param>
        /// <param name="stretch">Value of the Stretch property on the element.</param>
        /// <param name="stretchDirection">Value of the StretchDirection property on the element.</param>
        internal static Size ComputeScaleFactor(Size availableSize,
                                                Size contentSize,
                                                Stretch stretch,
                                                StretchDirection stretchDirection)
        {
            // Compute scaling factors to use for axes
            double scaleX = 1.0;
            double scaleY = 1.0;

            bool isConstrainedWidth  = !Double.IsPositiveInfinity(availableSize.Width);
            bool isConstrainedHeight = !Double.IsPositiveInfinity(availableSize.Height);

            if ((stretch == Stretch.Uniform || stretch == Stretch.UniformToFill || stretch == Stretch.Fill) &&
                (isConstrainedWidth || isConstrainedHeight))
            {
                // Compute scaling factors for both axes
                scaleX = (DoubleUtil.IsZero(contentSize.Width)) ? 0.0 : availableSize.Width / contentSize.Width;
                scaleY = (DoubleUtil.IsZero(contentSize.Height)) ? 0.0 : availableSize.Height / contentSize.Height;

                if (!isConstrainedWidth)
                {
                    scaleX = scaleY;
                }
                else if (!isConstrainedHeight)
                {
                    scaleY = scaleX;
                }
                else
                {
                    // If not preserving aspect ratio, then just apply transform to fit
                    switch (stretch)
                    {
                    case Stretch.Uniform:           //Find minimum scale that we use for both axes
                        double minscale = scaleX < scaleY ? scaleX : scaleY;
                        scaleX = scaleY = minscale;
                        break;

                    case Stretch.UniformToFill:     //Find maximum scale that we use for both axes
                        double maxscale = scaleX > scaleY ? scaleX : scaleY;
                        scaleX = scaleY = maxscale;
                        break;

                    case Stretch.Fill:              //We already computed the fill scale factors above, so just use them
                        break;
                    }
                }

                //Apply stretch direction by bounding scales.
                //In the uniform case, scaleX=scaleY, so this sort of clamping will maintain aspect ratio
                //In the uniform fill case, we have the same result too.
                //In the fill case, note that we change aspect ratio, but that is okay
                switch (stretchDirection)
                {
                case StretchDirection.UpOnly:
                    if (scaleX < 1.0)
                    {
                        scaleX = 1.0;
                    }
                    if (scaleY < 1.0)
                    {
                        scaleY = 1.0;
                    }
                    break;

                case StretchDirection.DownOnly:
                    if (scaleX > 1.0)
                    {
                        scaleX = 1.0;
                    }
                    if (scaleY > 1.0)
                    {
                        scaleY = 1.0;
                    }
                    break;

                case StretchDirection.Both:
                    break;

                default:
                    break;
                }
            }
            //Return this as a size now
            return(new Size(scaleX, scaleY));
        }
Beispiel #17
0
        // Token: 0x06005B4A RID: 23370 RVA: 0x0019BBC4 File Offset: 0x00199DC4
        private static bool IsWidthHeightValid(object value)
        {
            double num = (double)value;

            return(DoubleUtil.IsNaN(num) || (num >= 0.0 && !double.IsPositiveInfinity(num)));
        }
        //-------------------------------------------------------------------
        //
        //  Public Methods
        //
        //-------------------------------------------------------------------

        #region Public Methods


        #endregion

        //-------------------------------------------------------------------
        //
        //  Public Properties + Dependency Properties's
        //
        //-------------------------------------------------------------------

        #region Public Properties

        private static bool IsWidthHeightValid(object value)
        {
            double v = (double)value;

            return((DoubleUtil.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)));
        }
Beispiel #19
0
        // Token: 0x06005859 RID: 22617 RVA: 0x00187528 File Offset: 0x00185728
        private void ProcessThumbDragDelta(DragDeltaEventArgs e)
        {
            Thumb thumb = e.OriginalSource as Thumb;

            if (thumb != null)
            {
                ToolBar toolBar = thumb.TemplatedParent as ToolBar;
                if (toolBar != null && toolBar.Parent == this)
                {
                    if (this._bandsDirty)
                    {
                        this.GenerateBands();
                    }
                    bool   flag           = this.Orientation == Orientation.Horizontal;
                    int    band           = toolBar.Band;
                    Point  position       = Mouse.PrimaryDevice.GetPosition(this);
                    Point  point          = this.TransformPointToToolBar(toolBar, position);
                    int    bandFromOffset = this.GetBandFromOffset(flag ? position.Y : position.X);
                    double num            = flag ? e.HorizontalChange : e.VerticalChange;
                    double num2;
                    if (flag)
                    {
                        num2 = position.X - point.X;
                    }
                    else
                    {
                        num2 = position.Y - point.Y;
                    }
                    double num3 = num2 + num;
                    if (bandFromOffset == band)
                    {
                        List <ToolBar> band2     = this._bands[band].Band;
                        int            bandIndex = toolBar.BandIndex;
                        if (DoubleUtil.LessThan(num, 0.0))
                        {
                            double num4 = this.ToolBarsTotalMinimum(band2, 0, bandIndex - 1);
                            if (DoubleUtil.LessThanOrClose(num4, num3))
                            {
                                this.ShrinkToolBars(band2, 0, bandIndex - 1, -num);
                            }
                            else if (bandIndex > 0)
                            {
                                ToolBar toolBar2 = band2[bandIndex - 1];
                                Point   point2   = this.TransformPointToToolBar(toolBar2, position);
                                if (DoubleUtil.LessThan(flag ? point2.X : point2.Y, 0.0))
                                {
                                    toolBar2.BandIndex   = bandIndex;
                                    band2[bandIndex]     = toolBar2;
                                    toolBar.BandIndex    = bandIndex - 1;
                                    band2[bandIndex - 1] = toolBar;
                                    if (bandIndex + 1 == band2.Count)
                                    {
                                        toolBar2.ClearValue(flag ? FrameworkElement.WidthProperty : FrameworkElement.HeightProperty);
                                    }
                                }
                                else if (flag)
                                {
                                    if (DoubleUtil.LessThan(num4, position.X - point.X))
                                    {
                                        this.ShrinkToolBars(band2, 0, bandIndex - 1, position.X - point.X - num4);
                                    }
                                }
                                else if (DoubleUtil.LessThan(num4, position.Y - point.Y))
                                {
                                    this.ShrinkToolBars(band2, 0, bandIndex - 1, position.Y - point.Y - num4);
                                }
                            }
                        }
                        else
                        {
                            double value = this.ToolBarsTotalMaximum(band2, 0, bandIndex - 1);
                            if (DoubleUtil.GreaterThan(value, num3))
                            {
                                this.ExpandToolBars(band2, 0, bandIndex - 1, num);
                            }
                            else if (bandIndex < band2.Count - 1)
                            {
                                ToolBar toolBar3 = band2[bandIndex + 1];
                                Point   point3   = this.TransformPointToToolBar(toolBar3, position);
                                if (DoubleUtil.GreaterThanOrClose(flag ? point3.X : point3.Y, 0.0))
                                {
                                    toolBar3.BandIndex   = bandIndex;
                                    band2[bandIndex]     = toolBar3;
                                    toolBar.BandIndex    = bandIndex + 1;
                                    band2[bandIndex + 1] = toolBar;
                                    if (bandIndex + 2 == band2.Count)
                                    {
                                        toolBar.ClearValue(flag ? FrameworkElement.WidthProperty : FrameworkElement.HeightProperty);
                                    }
                                }
                                else
                                {
                                    this.ExpandToolBars(band2, 0, bandIndex - 1, num);
                                }
                            }
                            else
                            {
                                this.ExpandToolBars(band2, 0, bandIndex - 1, num);
                            }
                        }
                    }
                    else
                    {
                        this._bandsDirty = true;
                        toolBar.Band     = bandFromOffset;
                        toolBar.ClearValue(flag ? FrameworkElement.WidthProperty : FrameworkElement.HeightProperty);
                        if (bandFromOffset >= 0 && bandFromOffset < this._bands.Count)
                        {
                            this.MoveToolBar(toolBar, bandFromOffset, num3);
                        }
                        List <ToolBar> band3 = this._bands[band].Band;
                        for (int i = 0; i < band3.Count; i++)
                        {
                            ToolBar toolBar4 = band3[i];
                            toolBar4.ClearValue(flag ? FrameworkElement.WidthProperty : FrameworkElement.HeightProperty);
                        }
                    }
                    e.Handled = true;
                }
            }
        }