コード例 #1
0
ファイル: ToolBarTray.cs プロジェクト: ash2005/z
        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;
                }
            }
        }
コード例 #2
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;
                }
            }
        }