示例#1
0
        /// <summary>
        /// Standard method that is executed when the template 'skin' is applied
        /// (by the WPF framework) on the look-less control.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.mPART_TopRSThumb         = this.GetTemplateChild("PART_TopRSThumb") as ResizeThumb;
            this.mPART_LeftRSThumb        = this.GetTemplateChild("PART_LeftRSThumb") as ResizeThumb;
            this.mPART_RightRSThumb       = this.GetTemplateChild("PART_RightRSThumb") as ResizeThumb;
            this.mPART_BottomRSThumb      = this.GetTemplateChild("PART_BottomRSThumb") as ResizeThumb;
            this.mPART_TopLeftRSThumb     = this.GetTemplateChild("PART_TopLeftRSThumb") as ResizeThumb;
            this.mPART_TopRightRSThumb    = this.GetTemplateChild("PART_TopRightRSThumb") as ResizeThumb;
            this.mPART_BottomLeftRSThumb  = this.GetTemplateChild("PART_BottomLeftRSThumb") as ResizeThumb;
            this.mPART_BottomRightRSThumb = this.GetTemplateChild("PART_BottomRightRSThumb") as ResizeThumb;

            if (this.mDragDeltaAction_DelegateFunction != null)
            {
                this.mPART_TopRSThumb.DragDeltaEvent += this.mDragDeltaAction_DelegateFunction;

                this.mPART_TopRSThumb.DragDeltaEvent         += this.mDragDeltaAction_DelegateFunction;
                this.mPART_LeftRSThumb.DragDeltaEvent        += this.mDragDeltaAction_DelegateFunction;
                this.mPART_RightRSThumb.DragDeltaEvent       += this.mDragDeltaAction_DelegateFunction;
                this.mPART_BottomRSThumb.DragDeltaEvent      += this.mDragDeltaAction_DelegateFunction;
                this.mPART_TopLeftRSThumb.DragDeltaEvent     += this.mDragDeltaAction_DelegateFunction;
                this.mPART_TopRightRSThumb.DragDeltaEvent    += this.mDragDeltaAction_DelegateFunction;
                this.mPART_BottomLeftRSThumb.DragDeltaEvent  += this.mDragDeltaAction_DelegateFunction;
                this.mPART_BottomRightRSThumb.DragDeltaEvent += this.mDragDeltaAction_DelegateFunction;
            }
        }
示例#2
0
        /// <summary>
        /// 改变大小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            if (!(sender is ResizeThumb))
            {
                return;
            }
            ResizeThumb tb = (sender as ResizeThumb);

            Resize_DragDelta(tb, e.HorizontalChange, e.VerticalChange);
        }
示例#3
0
 internal protected void UpdateResizeThumbPoints()
 {
     resizePoints[0] = new ResizeThumb(ResizeThumbPosition.TopLeft, this.innerX, this.innerY);
     resizePoints[1] = new ResizeThumb(ResizeThumbPosition.Top, this.innerX + this.halfWidth, this.innerY);
     resizePoints[2] = new ResizeThumb(ResizeThumbPosition.TopRight, this.Right, this.innerY);
     resizePoints[3] = new ResizeThumb(ResizeThumbPosition.Left, this.innerX, this.innerY + this.halfHeight);
     resizePoints[4] = new ResizeThumb(ResizeThumbPosition.Right, this.Right, this.innerY + this.halfHeight);
     resizePoints[5] = new ResizeThumb(ResizeThumbPosition.BottomLeft, this.innerX, this.Bottom);
     resizePoints[6] = new ResizeThumb(ResizeThumbPosition.Bottom, this.innerX + this.halfWidth, this.Bottom);
     resizePoints[7] = new ResizeThumb(ResizeThumbPosition.BottomRight, this.Right, this.Bottom);
 }
        DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
        {
            DesignerThumb designerThumb = new ResizeThumb(cursor == Cursors.SizeNS, cursor == Cursors.SizeWE);

            designerThumb.Cursor    = cursor;
            designerThumb.Alignment = alignment;
            AdornerPanel.SetPlacement(designerThumb, Place(ref designerThumb, alignment));
            adornerPanel.Children.Add(designerThumb);

            DragListener drag = new DragListener(designerThumb);

            drag.Started   += drag_Started;
            drag.Changed   += drag_Changed;
            drag.Completed += drag_Completed;
            return(designerThumb);
        }
示例#5
0
        /// <summary>
        /// Places resize thumbs at their respective positions
        /// and streches out thumbs which are at the center of outline to extend resizability across the whole outline
        /// </summary>
        /// <param name="resizeThumb"></param>
        /// <param name="alignment"></param>
        /// <returns></returns>
        private RelativePlacement Place(ref ResizeThumb resizeThumb, PlacementAlignment alignment)
        {
            RelativePlacement placement = new RelativePlacement(alignment.Horizontal, alignment.Vertical);

            if (alignment.Horizontal == HorizontalAlignment.Center)
            {
                placement.WidthRelativeToContentWidth = 1;
                placement.HeightOffset = 6;
                resizeThumb.Opacity    = 0;
                return(placement);
            }
            if (alignment.Vertical == VerticalAlignment.Center)
            {
                placement.HeightRelativeToContentHeight = 1;
                placement.WidthOffset = 6;
                resizeThumb.Opacity   = 0;
                return(placement);
            }

            placement.WidthOffset  = 6;
            placement.HeightOffset = 6;
            return(placement);
        }
 public static void Run(CommandManager cmgr, DragDeltaEventArgs m_drage, DesignerCanvas dc,
                        DesignerContainer items, ResizeThumb rt)
 {
     cmgr.Run <CommandResizeThumb>(m_drage, dc, items, rt);
 }
        public override bool Run(CommandManager mgr, params object[] param)
        {
            if (param.Length > 3)
            {
                m_drage = param[0] as DragDeltaEventArgs;
                m_dc    = param[1] as DesignerCanvas;
                m_di    = param[2] as DesignerContainer;
                m_rt    = param[3] as ResizeThumb;
                // m_drage = param[3] as DragDeltaEventArgs;
                if (m_di != null && m_dc != null && m_di.IsSelected)
                {
                    double scale = 1;

                    var selectedDesignerContainers = m_dc.SelectionService.SelectedDesignerContainer.OfType <DesignerContainer>();

                    var designerContainers = selectedDesignerContainers as IList <DesignerContainer> ??
                                             selectedDesignerContainers.ToList();
                    if (m_rt != null)
                    {
                        double minDeltaHorizontal;
                        double minDeltaVertical;
                        double minLeft;
                        double minTop;
                        m_rt.CalculateDragLimits(designerContainers, out minLeft, out minTop,
                                                 out minDeltaHorizontal, out minDeltaVertical);

                        var rect = GetBoundingRectangle(designerContainers);


                        var bd      = m_dc.Parent as Viewbox;
                        var maxLeft = double.IsNaN(rect.Left)
                            ? m_dc.Width - rect.Width
                            : m_dc.Width - rect.Left - rect.Width;
                        var maxTop = double.IsNaN(rect.Top)
                            ? m_dc.Height - rect.Height
                            : m_dc.Height - rect.Top - rect.Height;

                        foreach (var item in designerContainers)
                        {
                            if (m_width == null)
                            {
                                m_width = new List <double>();
                            }
                            m_width.Add(item.Width);
                            if (m_height == null)
                            {
                                m_height = new List <double>();
                            }
                            m_height.Add(item.Height);
                            if (m_des == null)
                            {
                                m_des = new List <DesignerContainer>();
                            }
                            m_des.Add(item);

                            var disabledH = DesignerContainer.GetDisabledHeight(m_di);
                            var disabledW = DesignerContainer.GetDisabledWidth(m_di);
                            if (item != null && item.ParentID == Guid.Empty)
                            {
                                //if (isUniform)
                                //{
                                //    UniformScale(Item, scale);
                                //    break;
                                //}

                                double dragDeltaVertical;
                                switch (m_rt.VerticalAlignment)
                                {
                                case VerticalAlignment.Bottom:
                                    if (disabledH)
                                    {
                                        break;
                                    }
                                    var bottom = Canvas.GetTop(item);
                                    if (m_pointy == null)
                                    {
                                        m_pointy = new List <double>();
                                    }
                                    m_pointy.Add(bottom);
                                    if (m_drage != null)
                                    {
                                        if (m_drage.VerticalChange > maxTop)
                                        {
                                            dragDeltaVertical = 0;
                                            scale             = 1;
                                        }
                                    }
                                    else
                                    {
                                        dragDeltaVertical = Math.Min(m_drage != null ? -m_drage.VerticalChange : 0,
                                                                     minDeltaVertical);
                                        scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight;
                                    }
                                    if (flag)
                                    {
                                        m_rt.UniformScale(item, scale, m_drage);
                                    }
                                    else
                                    {
                                        DragBottom(scale, item, m_dc.SelectionService);
                                    }
                                    break;

                                case VerticalAlignment.Top:
                                    if (disabledH)
                                    {
                                        break;
                                    }
                                    var top = Canvas.GetTop(item);
                                    if (m_pointy == null)
                                    {
                                        m_pointy = new List <double>();
                                    }
                                    m_pointy.Add(top);

                                    dragDeltaVertical =
                                        Math.Min(Math.Max(-minTop, m_drage != null ? m_drage.VerticalChange : 0),
                                                 minDeltaVertical);

                                    scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight;

                                    if (flag)
                                    {
                                        m_rt.UniformScale(item, scale, m_drage);
                                    }
                                    else
                                    {
                                        DragTop(scale, item, m_dc.SelectionService);
                                    }
                                    break;

                                default:
                                    break;
                                }

                                double dragDeltaHorizontal;
                                switch (m_rt.HorizontalAlignment)
                                {
                                case HorizontalAlignment.Left:
                                    if (disabledW)
                                    {
                                        break;
                                    }
                                    var left = Canvas.GetLeft(item);
                                    if (m_left == null)
                                    {
                                        m_left = new List <double>();
                                    }
                                    m_left.Add(left);
                                    dragDeltaHorizontal =
                                        Math.Min(
                                            Math.Max(-minLeft, m_drage != null ? m_drage.HorizontalChange : 0),
                                            minDeltaHorizontal);
                                    scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth;
                                    if (!flag)
                                    {
                                        DragLeft(scale, item, m_dc.SelectionService);
                                    }
                                    break;

                                case HorizontalAlignment.Right:
                                    if (disabledW)
                                    {
                                        break;
                                    }
                                    var left1 = Canvas.GetLeft(item);
                                    if (m_left == null)
                                    {
                                        m_left = new List <double>();
                                    }
                                    m_left.Add(left1);
                                    if (m_drage != null)
                                    {
                                        if (m_drage.HorizontalChange > maxLeft)
                                        {
                                            dragDeltaHorizontal = 0;
                                            scale = 1;
                                        }
                                        else
                                        {
                                            dragDeltaHorizontal =
                                                Math.Min(m_drage != null ? -m_drage.HorizontalChange : 0,
                                                         minDeltaHorizontal);
                                            scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth;
                                        }
                                    }
                                    if (!flag)
                                    {
                                        DragRight(scale, item, m_dc.SelectionService);
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                    if (m_drage != null)
                    {
                        m_drage.Handled = true;
                    }
                }
                return(true);
            }
            return(false);
        }
示例#8
0
        protected void Resize_DragDelta(ResizeThumb resizeThumb, double horizontalChange, double verticalChange)
        {
            if (IsReadOnly)
            {
                return;
            }

            FlowContent dv = ControlsCommon.FindParentControl <FlowContent>(this);

            if (dv == null)
            {
                return;
            }
            this.BResizing = true; //设置为Resizing
            if (!dv.BCtrl)         //不是Ctrl
            {
                if (Math.Abs(horizontalChange) > 0.0001)
                {
                    horizontalChange = horizontalChange - (horizontalChange % 5);
                }
                if (Math.Abs(verticalChange) > 0.0001)
                {
                    verticalChange = verticalChange - (verticalChange % 5);
                }
            }

            Point newPosition = new Point(Position.X, Position.Y);

            double addWidth  = 0;
            double addHeight = 0;

            const double alignSpan = 10;

            double hSpan = alignSpan; //水平增大缩小间隔 - 停靠
            double vSpan = alignSpan; //垂直增大缩小间隔 - 停靠

            int iAutoResize = 0;      //自动大小方向 0 :无;1:水平;2:垂直

            #region Resize

            switch (resizeThumb.EmDragDirection)
            {
            case EmDragDirection.TopLeft:     //左上

                #region 左上

                newPosition.X = Position.X + horizontalChange;
                newPosition.Y = Position.Y + verticalChange;

                if (newPosition.X <= 0)
                {
                    newPosition.X = 0;
                }
                else
                {
                    addWidth = horizontalChange * (-1);
                }
                if (newPosition.Y <= 0)
                {
                    newPosition.Y = 0;
                }
                else
                {
                    addHeight = verticalChange * (-1);
                }

                #region 停靠 - 左上

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 左边停靠

                    span = Math.Abs(newPosition.X - thumb.Position.X);

                    if (span <= hSpan)     //左边
                    {
                        hSpan         = span;
                        newPosition.X = thumb.Position.X;
                        addWidth      = this.Position.X - thumb.Position.X;

                        iAutoResize = 1;
                    }

                    #endregion

                    #region 等宽

                    span = Math.Abs(this.Width + addWidth - thumb.Width);

                    if (span <= hSpan)     //宽
                    {
                        hSpan         = span;
                        addWidth      = thumb.Width - this.Width;
                        newPosition.X = this.Position.X - addWidth;
                        iAutoResize   = 1;
                    }

                    #endregion

                    #region 顶部停靠

                    span = Math.Abs(newPosition.Y - thumb.Position.Y);

                    if (span <= vSpan)     //顶部
                    {
                        vSpan         = span;
                        newPosition.Y = thumb.Position.Y;
                        addHeight     = this.Position.Y - thumb.Position.Y;
                        iAutoResize   = 2;
                    }

                    #endregion

                    #region 等高

                    span = Math.Abs(this.Height + addHeight - thumb.Height);

                    if (span <= vSpan)     //高
                    {
                        vSpan         = span;
                        addHeight     = thumb.Height - this.Height;
                        newPosition.Y = this.Position.Y - addHeight;
                        iAutoResize   = 2;
                    }

                    #endregion
                }

                #endregion

                #region 格式拖动

                if (BelongCanvas.bResizeFormat) //格式化
                {
                    if (iAutoResize == 1)       //按照水平
                    {
                        addHeight     = addWidth * this.Height / this.Width;
                        newPosition.Y = this.Position.Y - addHeight;
                    }
                    //else if (iAutoResize == 2)
                    //{

                    //}
                    else
                    {
                        addWidth      = addHeight * this.Width / this.Height;
                        newPosition.X = this.Position.X - addWidth;
                    }
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.TopCenter:     //中上

                #region 中上

                newPosition.Y = Position.Y + verticalChange;

                if (newPosition.Y <= 0)
                {
                    newPosition.Y = 0;
                }
                else
                {
                    addHeight = verticalChange * (-1);
                }

                #region 停靠 - 上

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 顶部停靠

                    span = Math.Abs(newPosition.Y - thumb.Position.Y);

                    if (span <= vSpan)     //顶部
                    {
                        vSpan         = span;
                        newPosition.Y = thumb.Position.Y;
                        addHeight     = this.Position.Y - thumb.Position.Y;
                    }

                    #endregion

                    #region 等高

                    span = Math.Abs(this.Height + addHeight - thumb.Height);

                    if (span <= vSpan)     //高
                    {
                        vSpan         = span;
                        addHeight     = thumb.Height - this.Height;
                        newPosition.Y = this.Position.Y - addHeight;
                    }

                    #endregion
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.TopRight:     //右上

                #region 右上

                newPosition.Y = Position.Y + verticalChange;
                addWidth      = horizontalChange;

                if (newPosition.Y <= 0)
                {
                    newPosition.Y = 0;
                }
                else
                {
                    addHeight = verticalChange * (-1);
                }
                if (newPosition.Y > dv.ActualHeight - this.ActualHeight)
                {
                    newPosition.Y = dv.ActualHeight - this.ActualHeight;
                }

                #region 停靠 - 右上

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 右边停靠

                    span = Math.Abs(newPosition.X + this.Width + addWidth - (thumb.Position.X + thumb.Width));

                    if (span <= hSpan)     //右边
                    {
                        hSpan    = span;
                        addWidth = thumb.Position.X + thumb.Width - (newPosition.X + this.Width);

                        iAutoResize = 1;
                    }

                    #endregion

                    #region 等宽

                    span = Math.Abs(this.Width + addWidth - thumb.Width);

                    if (span <= hSpan)     //宽
                    {
                        hSpan       = span;
                        addWidth    = thumb.Width - this.Width;
                        iAutoResize = 1;
                    }

                    #endregion

                    #region 顶部停靠

                    span = Math.Abs(newPosition.Y - thumb.Position.Y);

                    if (span <= vSpan)     //顶部
                    {
                        vSpan         = span;
                        newPosition.Y = thumb.Position.Y;
                        addHeight     = this.Position.Y - thumb.Position.Y;
                        iAutoResize   = 2;
                    }

                    #endregion

                    #region 等高

                    span = Math.Abs(this.Height + addHeight - thumb.Height);

                    if (span <= vSpan)     //高
                    {
                        vSpan         = span;
                        addHeight     = thumb.Height - this.Height;
                        newPosition.Y = this.Position.Y - addHeight;
                        iAutoResize   = 2;
                    }

                    #endregion
                }

                #endregion

                #region 格式拖动

                if (BelongCanvas.bResizeFormat) //格式化
                {
                    if (iAutoResize == 1)       //按照水平
                    {
                        addHeight     = addWidth * this.Height / this.Width;
                        newPosition.Y = this.Position.Y - addHeight;
                    }
                    //else if (iAutoResize == 2)
                    //{

                    //}
                    else
                    {
                        addWidth = addHeight * this.Width / this.Height;
                    }
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.MiddleLeft:     //中左

                #region 中左

                newPosition.X = Position.X + horizontalChange;
                addWidth      = horizontalChange * (-1);

                if (newPosition.Y <= 0)
                {
                    newPosition.Y = 0;
                }

                #region 停靠 左

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 左边停靠

                    span = Math.Abs(newPosition.X - thumb.Position.X);

                    if (span <= hSpan)     //左边
                    {
                        hSpan         = span;
                        newPosition.X = thumb.Position.X;
                        addWidth      = this.Position.X - thumb.Position.X;
                    }

                    #endregion

                    #region 等宽

                    span = Math.Abs(this.Width + addWidth - thumb.Width);

                    if (span <= hSpan)     //宽
                    {
                        hSpan         = span;
                        addWidth      = thumb.Width - this.Width;
                        newPosition.X = this.Position.X - addWidth;
                    }

                    #endregion
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.MiddleRight:     //中右

                #region 中右

                addWidth = horizontalChange;

                #region 停靠 右

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 右边停靠

                    span = Math.Abs(newPosition.X + this.Width + addWidth - (thumb.Position.X + thumb.Width));

                    if (span <= hSpan)     //右边
                    {
                        hSpan    = span;
                        addWidth = thumb.Position.X + thumb.Width - (newPosition.X + this.Width);
                    }

                    #endregion

                    #region 等宽

                    span = Math.Abs(this.Width + addWidth - thumb.Width);

                    if (span <= hSpan)     //宽
                    {
                        hSpan    = span;
                        addWidth = thumb.Width - this.Width;
                    }

                    #endregion
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.BottomLeft:     //下左

                #region  左

                newPosition.X = Position.X + horizontalChange;
                addWidth      = horizontalChange * (-1);

                addHeight = verticalChange;

                if (newPosition.X <= 0)
                {
                    newPosition.X = 0;
                }

                #region 停靠 下左

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 左边停靠

                    span = Math.Abs(newPosition.X - thumb.Position.X);

                    if (span <= hSpan)     //左边
                    {
                        hSpan         = span;
                        newPosition.X = thumb.Position.X;
                        addWidth      = this.Position.X - thumb.Position.X;
                        iAutoResize   = 1;
                    }

                    #endregion

                    #region 等宽

                    span = Math.Abs(this.Width + addWidth - thumb.Width);

                    if (span <= hSpan)     //宽
                    {
                        hSpan         = span;
                        addWidth      = thumb.Width - this.Width;
                        newPosition.X = this.Position.X - addWidth;
                        iAutoResize   = 1;
                    }

                    #endregion

                    #region 底部停靠

                    span = Math.Abs(newPosition.Y + this.Height + addHeight - (thumb.Position.Y + thumb.Height));

                    if (span <= vSpan)     //底部
                    {
                        vSpan       = span;
                        addHeight   = thumb.Position.Y + thumb.Height - (newPosition.Y + this.Height);
                        iAutoResize = 2;
                    }

                    #endregion

                    #region 等高

                    span = Math.Abs(this.Height + addHeight - thumb.Height);

                    if (span <= vSpan)     //高
                    {
                        vSpan       = span;
                        addHeight   = thumb.Height - this.Height;
                        iAutoResize = 2;
                    }

                    #endregion
                }

                #endregion

                #region 格式拖动

                if (BelongCanvas.bResizeFormat) //格式化
                {
                    if (iAutoResize == 1)       //按照水平
                    {
                        addHeight     = addWidth * this.Height / this.Width;
                        newPosition.X = this.Position.X - addWidth;
                    }
                    //else if (iAutoResize == 2)
                    //{

                    //}
                    else
                    {
                        addWidth = addHeight * this.Width / this.Height;
                    }
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.BottomCenter:     //下中

                #region  中

                addHeight = verticalChange;

                #region 停靠 下中

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 底部停靠

                    span = Math.Abs(newPosition.Y + this.Height + addHeight - (thumb.Position.Y + thumb.Height));

                    if (span <= vSpan)     //底部
                    {
                        vSpan     = span;
                        addHeight = thumb.Position.Y + thumb.Height - (newPosition.Y + this.Height);
                    }

                    #endregion

                    #region 等高

                    span = Math.Abs(this.Height + addHeight - thumb.Height);

                    if (span <= vSpan)     //高
                    {
                        vSpan     = span;
                        addHeight = thumb.Height - this.Height;
                    }

                    #endregion
                }

                #endregion

                #endregion

                break;

            case EmDragDirection.BottomRight:     //下右

                #region  右

                addWidth  = horizontalChange;
                addHeight = verticalChange;

                #region 停靠 下右

                foreach (DragThumb thumb in dv.DragThumbs)
                {
                    if (thumb.Equals(this))
                    {
                        continue;
                    }

                    double span = 0;

                    #region 右边停靠

                    span = Math.Abs(newPosition.X + this.Width + addWidth - (thumb.Position.X + thumb.Width));

                    if (span <= hSpan)     //右边
                    {
                        hSpan       = span;
                        addWidth    = thumb.Position.X + thumb.Width - (newPosition.X + this.Width);
                        iAutoResize = 1;
                    }

                    #endregion

                    #region 等宽

                    span = Math.Abs(this.Width + addWidth - thumb.Width);

                    if (span <= hSpan)     //宽
                    {
                        hSpan       = span;
                        addWidth    = thumb.Width - this.Width;
                        iAutoResize = 1;
                    }

                    #endregion

                    #region 底部停靠

                    span = Math.Abs(newPosition.Y + this.Height + addHeight - (thumb.Position.Y + thumb.Height));

                    if (span <= vSpan)     //底部
                    {
                        vSpan       = span;
                        addHeight   = thumb.Position.Y + thumb.Height - (newPosition.Y + this.Height);
                        iAutoResize = 2;
                    }

                    #endregion


                    #region 等高

                    span = Math.Abs(this.Height + addHeight - thumb.Height);

                    if (span <= vSpan)     //高
                    {
                        vSpan       = span;
                        addHeight   = thumb.Height - this.Height;
                        iAutoResize = 2;
                    }

                    #endregion
                }

                #endregion

                #region 格式拖动

                if (BelongCanvas.bResizeFormat) //格式化
                {
                    if (iAutoResize == 1)       //按照水平
                    {
                        addHeight = addWidth * this.Height / this.Width;
                    }
                    //else if (iAutoResize == 2)
                    //{

                    //}
                    else
                    {
                        addWidth = addHeight * this.Width / this.Height;
                    }
                }

                #endregion

                #endregion

                break;
            }

            #endregion

            #region 限制最小宽度、高度

            if (this.Width + addWidth <= MinWidth)
            {
                addWidth = MinWidth - this.Width;
            }

            if (this.Height + addHeight <= MinHeight)
            {
                addHeight = MinHeight - this.Height;
            }

            #endregion

            this.Width  += addWidth;
            this.Height += addHeight;

            #region 控制区域


            if (newPosition.X <= 0)
            {
                newPosition.X = 0;
            }
            if (newPosition.Y <= 0)
            {
                newPosition.Y = 0;
            }

            if (newPosition.X > dv.ActualWidth)
            {
                newPosition.X = dv.ActualWidth;
            }

            if (newPosition.Y > dv.ActualHeight)
            {
                newPosition.Y = dv.ActualHeight;
            }

            #endregion

            Position = newPosition; //设置位置

            #region 绘制 对齐和 等宽高线

            dv.ReDrawAlignLines(this,
                                (resizeThumb.EmDragDirection == EmDragDirection.TopLeft ||
                                 resizeThumb.EmDragDirection == EmDragDirection.TopRight ||
                                 resizeThumb.EmDragDirection == EmDragDirection.TopCenter),
                                (resizeThumb.EmDragDirection == EmDragDirection.BottomLeft ||
                                 resizeThumb.EmDragDirection == EmDragDirection.BottomRight ||
                                 resizeThumb.EmDragDirection == EmDragDirection.BottomCenter),
                                false,
                                (resizeThumb.EmDragDirection == EmDragDirection.TopLeft ||
                                 resizeThumb.EmDragDirection == EmDragDirection.BottomLeft ||
                                 resizeThumb.EmDragDirection == EmDragDirection.MiddleLeft),
                                (resizeThumb.EmDragDirection == EmDragDirection.TopRight ||
                                 resizeThumb.EmDragDirection == EmDragDirection.BottomRight ||
                                 resizeThumb.EmDragDirection == EmDragDirection.MiddleRight),
                                false
                                );

            dv.ReDrawWidthHeightLines(this,
                                      (resizeThumb.EmDragDirection == EmDragDirection.TopLeft ||
                                       resizeThumb.EmDragDirection == EmDragDirection.TopRight ||
                                       resizeThumb.EmDragDirection == EmDragDirection.BottomLeft ||
                                       resizeThumb.EmDragDirection == EmDragDirection.BottomRight ||

                                       resizeThumb.EmDragDirection == EmDragDirection.MiddleLeft ||
                                       resizeThumb.EmDragDirection == EmDragDirection.MiddleRight),

                                      (resizeThumb.EmDragDirection == EmDragDirection.TopLeft ||
                                       resizeThumb.EmDragDirection == EmDragDirection.TopRight ||
                                       resizeThumb.EmDragDirection == EmDragDirection.BottomLeft ||
                                       resizeThumb.EmDragDirection == EmDragDirection.BottomRight ||

                                       resizeThumb.EmDragDirection == EmDragDirection.TopCenter ||
                                       resizeThumb.EmDragDirection == EmDragDirection.BottomCenter)
                                      );

            #endregion

            if (BelongCanvas != null)
            {
                BelongCanvas.bSaved = false;
            }
        }
        public DragResizeRotateManipulator(IDocumentView view, FrameworkElement el)
            : base(view, el)
        {
            rotateTopLeft     = new RotateThumb(view, el);
            rotateBottomLeft  = new RotateThumb(view, el);
            rotateTopRight    = new RotateThumb(view, el);
            rotateBottomRight = new RotateThumb(view, el);
            resizeTopLeft     = new ResizeThumb(view, el);
            resizeBottomLeft  = new ResizeThumb(view, el);
            resizeTopRight    = new ResizeThumb(view, el);
            resizeBottomRight = new ResizeThumb(view, el);
            resizeLeft        = new ResizeThumb(view, el);
            resizeRight       = new ResizeThumb(view, el);
            resizeTop         = new ResizeThumb(view, el);
            resizeBottom      = new ResizeThumb(view, el);



            dragControl.VerticalAlignment   = VerticalAlignment.Stretch;
            dragControl.HorizontalAlignment = HorizontalAlignment.Stretch;
            dragControl.StrokeThickness     = 1;
            dragControl.Stroke = System.Windows.Media.Brushes.Black;
            dragControl.Cursor = Cursors.SizeAll;
            visualChildren.Add(dragControl);


            rotateTopLeft.VerticalAlignment   = VerticalAlignment.Top;
            rotateTopLeft.HorizontalAlignment = HorizontalAlignment.Left;
            visualChildren.Add(rotateTopLeft);


            rotateBottomLeft.VerticalAlignment   = VerticalAlignment.Bottom;
            rotateBottomLeft.HorizontalAlignment = HorizontalAlignment.Left;
            visualChildren.Add(rotateBottomLeft);


            rotateTopRight.VerticalAlignment   = VerticalAlignment.Top;
            rotateTopRight.HorizontalAlignment = HorizontalAlignment.Right;
            visualChildren.Add(rotateTopRight);


            rotateBottomRight.VerticalAlignment   = VerticalAlignment.Bottom;
            rotateBottomRight.HorizontalAlignment = HorizontalAlignment.Right;
            visualChildren.Add(rotateBottomRight);

            resizeTopLeft.Cursor              = Cursors.SizeNWSE;
            resizeTopLeft.VerticalAlignment   = VerticalAlignment.Top;
            resizeTopLeft.HorizontalAlignment = HorizontalAlignment.Left;
            visualChildren.Add(resizeTopLeft);

            resizeBottomLeft.Cursor              = Cursors.SizeNESW;
            resizeBottomLeft.VerticalAlignment   = VerticalAlignment.Bottom;
            resizeBottomLeft.HorizontalAlignment = HorizontalAlignment.Left;
            visualChildren.Add(resizeBottomLeft);

            resizeTopRight.Cursor              = Cursors.SizeNESW;
            resizeTopRight.VerticalAlignment   = VerticalAlignment.Top;
            resizeTopRight.HorizontalAlignment = HorizontalAlignment.Right;
            visualChildren.Add(resizeTopRight);

            resizeBottomRight.Cursor              = Cursors.SizeNWSE;
            resizeBottomRight.VerticalAlignment   = VerticalAlignment.Bottom;
            resizeBottomRight.HorizontalAlignment = HorizontalAlignment.Right;
            visualChildren.Add(resizeBottomRight);

            resizeLeft.Cursor = Cursors.SizeWE;
            resizeLeft.HorizontalAlignment = HorizontalAlignment.Left;
            resizeLeft.VerticalAlignment   = VerticalAlignment.Center;
            visualChildren.Add(resizeLeft);

            resizeRight.Cursor = Cursors.SizeWE;
            resizeRight.HorizontalAlignment = HorizontalAlignment.Right;
            resizeRight.VerticalAlignment   = VerticalAlignment.Center;
            visualChildren.Add(resizeRight);

            resizeTop.Cursor = Cursors.SizeNS;
            resizeTop.HorizontalAlignment = HorizontalAlignment.Center;
            resizeTop.VerticalAlignment   = VerticalAlignment.Top;
            visualChildren.Add(resizeTop);

            resizeBottom.Cursor = Cursors.SizeNS;
            resizeBottom.HorizontalAlignment = HorizontalAlignment.Center;
            resizeBottom.VerticalAlignment   = VerticalAlignment.Bottom;
            visualChildren.Add(resizeBottom);
        }