Пример #1
0
        }// void DrawDragRect()

        /// <summary>
        /// 判断指定拖拽点是否可用
        /// </summary>
        /// <param name="point">拖拽点样式</param>
        /// <returns>是否可用</returns>
        private bool DragRectEnable(DragPointStyle point)
        {
            switch (point)
            {
            case  DragPointStyle.Move:
                return(bolCanMove);

            case  DragPointStyle.LeftTop:
                return(bolCanMove && bolCanResize);

            case DragPointStyle.TopCenter:
                return(bolCanMove && bolCanResize);

            case DragPointStyle.TopRight:
                return(bolCanMove && bolCanResize);

            case  DragPointStyle.RightCenter:
                return(bolCanResize);

            case DragPointStyle.RightBottom:
                return(bolCanResize);

            case DragPointStyle.BottomCenter:
                return(bolCanResize);

            case DragPointStyle.LeftBottom:
                return(bolCanMove && bolCanResize);

            case DragPointStyle.LeftCenter:
                return(bolCanMove && bolCanResize);

            default:
                return(false);
            }
        }        //bool DragRectEnable()
Пример #2
0
 /// <summary>
 /// 处理文档用户界面事件
 /// </summary>
 /// <param name="args">事件参数</param>
 public override void HandleDocumentEvent(DocumentEventArgs args)
 {
     if (args.Style == DocumentEventStyles.MouseDown)
     {
         if (this.Enabled)
         {
             if (this.OwnerDocument.EditorControl != null)
             {
                 if (this.OwnerDocument.EditorControl.MouseDragScroll)
                 {
                     return;
                 }
             }
             DragPointStyle hit = this.GetDragHit(args.X, args.Y);
             if (this.ShowDragRect)
             {
                 if (hit >= 0)
                 {
                     DragBounds(hit);
                     args.CancelBubble = true;
                     if (this.OwnerDocument.EditorControl != null)
                     {
                         this.OwnerDocument.EditorControl.UpdateTextCaret();
                     }
                     return;
                 }
             }
             //if (this.AbsBounds.Contains(args.X, args.Y))
             {
                 this.OwnerDocument.CurrentContentElement.SetSelection(this.ViewIndex, 1);
                 args.CancelBubble = true;
             }
         }
     }
     else if (args.Style == DocumentEventStyles.MouseMove)
     {
         if (this.Enabled)
         {
             if (this.ShowDragRect)
             {
                 DragRectangle  dr  = this.CreateDragRectangle();
                 DragPointStyle hit = dr.DragHit(args.X, args.Y);
                 if (hit >= 0)
                 {
                     args.Cursor = DragRectangle.GetMouseCursor(hit);
                     base.HandleDocumentEvent(args);
                     return;
                 }
             }
             args.Cursor = System.Windows.Forms.Cursors.Arrow;
         }
     }
     else
     {
         base.HandleDocumentEvent(args);
     }
 }
Пример #3
0
 /// <summary>
 /// 移动矩形
 /// </summary>
 /// <param name="dx">横向移动量</param>
 /// <param name="dy">纵向移动量</param>
 /// <param name="DragStyle">移动方式</param>
 /// <param name="SourceRect">原始矩形</param>
 /// <returns>移动后的矩形</returns>
 public static System.Drawing.Rectangle CalcuteDragRectangle(
     int dx,
     int dy,
     DragPointStyle DragStyle,
     System.Drawing.Rectangle SourceRect)
 {
     // 中间
     if (DragStyle == DragPointStyle.Move)
     {
         SourceRect.Offset(dx, dy);
     }
     // 左边
     if (DragStyle == DragPointStyle.LeftTop ||
         DragStyle == DragPointStyle.LeftCenter ||
         DragStyle == DragPointStyle.LeftBottom)
     {
         SourceRect.Offset(dx, 0);
         SourceRect.Width = SourceRect.Width - dx;
     }
     // 顶边
     if (DragStyle == DragPointStyle.LeftTop ||
         DragStyle == DragPointStyle.TopCenter ||
         DragStyle == DragPointStyle.TopRight)
     {
         SourceRect.Offset(0, dy);
         SourceRect.Height = SourceRect.Height - dy;
     }
     // 右边
     if (DragStyle == DragPointStyle.TopRight ||
         DragStyle == DragPointStyle.RightCenter ||
         DragStyle == DragPointStyle.RightBottom)
     {
         SourceRect.Width = SourceRect.Width + dx;
     }
     // 底边
     if (DragStyle == DragPointStyle.RightBottom ||
         DragStyle == DragPointStyle.BottomCenter ||
         DragStyle == DragPointStyle.LeftBottom)
     {
         SourceRect.Height = SourceRect.Height + dy;
     }
     return(SourceRect);
 }
Пример #4
0
        private bool DragBounds(DragPointStyle hit)
        {
            MouseCapturer cap = new MouseCapturer(this.OwnerDocument.EditorControl);

            cap.Tag             = hit;
            cap.ReversibleShape = ReversibleShapeStyle.Custom;
            cap.Draw           += new CaptureMouseMoveEventHandler(cap_Draw);
            DomDocumentContentElement ce = this.DocumentContentElement;

            if (cap.CaptureMouseMove())
            {
                if (LastDragBounds.Width > 0 && LastDragBounds.Height > 0)
                {
                    if (LastDragBounds.Width != this.Width ||
                        LastDragBounds.Height != this.Height)
                    {
                        System.Drawing.SizeF OldSize = new System.Drawing.SizeF(
                            this.Width,
                            this.Height);
                        this.InvalidateView();
                        this.EditorSize = new SizeF(LastDragBounds.Width, LastDragBounds.Height);
                        this.InvalidateView();
                        ce.SetSelection(this.ViewIndex, 1);
                        if (this.OwnerDocument.BeginLogUndo())
                        {
                            this.OwnerDocument.UndoList.AddProperty(
                                XTextUndoStyles.EditorSize,
                                OldSize,
                                new System.Drawing.SizeF(this.Width, this.Height),
                                this);
                            this.OwnerDocument.EndLogUndo();
                        }
                        this.ContentElement.RefreshPrivateContent(
                            this.ContentElement.PrivateContent.IndexOf(this));
                        //ce.RefreshPrivateContent(ce.Content.IndexOf(this));
                        this.OwnerDocument.Modified = true;
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #5
0
        private void cap_Draw(object sender, CaptureMouseMoveEventArgs e)
        {
            DragPointStyle hit = (DragPointStyle)e.Sender.Tag;

            System.Drawing.Rectangle rect  = Rectangle.Ceiling(this.AbsBounds);
            System.Drawing.Point     p1    = e.StartPosition;
            System.Drawing.Point     p2    = e.CurrentPosition;
            SimpleRectangleTransform trans = this.OwnerDocument.EditorControl.GetTransformItemByDescPoint(rect.Left, rect.Top);

            if (trans != null)
            {
                p1   = trans.TransformPoint(p1);
                p2   = trans.TransformPoint(p2);
                rect = DragRectangle.CalcuteDragRectangle(
                    (int)(p2.X - p1.X),
                    (int)(p2.Y - p1.Y),
                    hit,
                    Rectangle.Ceiling(this.AbsBounds));
                if (rect.Width > (int)this.OwnerDocument.Width)
                {
                    rect.Width = (int)this.OwnerDocument.Width;
                }
                if (this.WidthHeightRate > 0.1)
                {
                    rect.Height = (int)(rect.Width / this.WidthHeightRate);
                }
                LastDragBounds = rect;
                rect           = trans.UnTransformRectangle(rect);
                using (ReversibleDrawer drawer =
                           ReversibleDrawer.FromHwnd(this.OwnerDocument.EditorControl.Handle))
                {
                    drawer.PenStyle = PenStyle.PS_DOT;
                    drawer.PenColor = System.Drawing.Color.Red;
                    drawer.DrawRectangle(rect);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 计算拖拉矩形上的鼠标光标位置
        /// </summary>
        /// <remarks>
        /// 鼠标设置如下
        /// 西北-东南          南北                东北-西南
        ///	   ■               ■                  ■
        ///     ┌────────────────┐
        ///     │0            1                 2│
        ///     │                                │
        ///     │                                │
        ///     │                                │
        ///     │                                │
        ///   ■│7 西-南                        3│■ 西-南
        ///     │                                │
        ///     │                                │
        ///     │                                │
        ///     │                                │
        ///     │6             5               4 │
        ///     └────────────────┘
        ///   ■                ■                 ■
        /// 东北-西南          南北                   西北-东南
        /// </remarks>
        /// <param name="point">拖拽矩形的序号,从0至7</param>
        /// <returns>鼠标光标对象,若序号小于0或大于7则返回空引用</returns>
        public static System.Windows.Forms.Cursor GetMouseCursor(DragPointStyle point)
        {
            switch (point)
            {
            case DragPointStyle.Move:
                return(System.Windows.Forms.Cursors.Arrow);

            case DragPointStyle.LeftTop:
                return(System.Windows.Forms.Cursors.SizeNWSE);

            case  DragPointStyle.TopCenter:
                return(System.Windows.Forms.Cursors.SizeNS);

            case DragPointStyle.TopRight:
                return(System.Windows.Forms.Cursors.SizeNESW);

            case DragPointStyle.RightCenter:
                return(System.Windows.Forms.Cursors.SizeWE);

            case DragPointStyle.RightBottom:
                return(System.Windows.Forms.Cursors.SizeNWSE);

            case  DragPointStyle.BottomCenter:
                return(System.Windows.Forms.Cursors.SizeNS);

            case DragPointStyle.LeftBottom:
                return(System.Windows.Forms.Cursors.SizeNESW);

            case DragPointStyle.LeftCenter:
                return(System.Windows.Forms.Cursors.SizeWE);

            default:
                return(System.Windows.Forms.Cursors.Default);
            }
            //return null;
        }