コード例 #1
0
            void DesignerPanel_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                IUISelectionService selectionServ = this.DesignedControl.Site.GetService(typeof(IUISelectionService)) as IUISelectionService;

                if (selectionServ == null)
                {
                    return;
                }

                selectionServ.SetCursor(e.X, e.Y);
                if (_mouseDown)
                {
                    if (_firstMove)
                    {
                        selectionServ.MouseDragBegin(this.DesignerPanel, e.X, e.Y);
                        _firstMove = false;
                    }
                    else
                    {
                        selectionServ.MouseDragMove(e.X, e.Y);
                    }
                }
                else if (selectionServ.SelectionInProgress)
                {
                    selectionServ.MouseDragMove(e.X, e.Y);
                }
            }
コード例 #2
0
        protected override void OnMouseDragBegin(int x, int y)
        {
            // do not call base here because the behaviour is specific for the ControlDesgner (does IUISelectionService.DragBegin)
            //

            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                // once ControlDesigner.MouseDragBegin is fired this will start getting dragover events.
                //
                Point         location = new Point(x, y);
                IDesignerHost host     = GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (base.MouseButtonDown == MouseButtons.Middle && host != null && host.RootComponent != this.Control)
                {
                    location = this.Control.Parent.PointToClient(this.Control.PointToScreen(new Point(x, y)));
                    // I have to do this, because I get DragOver events fired for the control I am actually dragging
                    //
                    this.Control.AllowDrop = false;
                    selectionServ.DragBegin();
                }
                else
                {
                    selectionServ.MouseDragBegin(this.Control, location.X, location.Y);
                }
            }
        }
コード例 #3
0
            void DesignerPanel_Paint(object sender, PaintEventArgs e)
            {
                IUISelectionService selectionServ = this.DesignedControl.Site.GetService(typeof(IUISelectionService)) as IUISelectionService;

                if (selectionServ != null)
                {
                    selectionServ.PaintAdornments(this.DesignerPanel, e.Graphics);
                }
            }
コード例 #4
0
        protected virtual void OnMouseDragBegin(int x, int y)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null && ((this.SelectionRules & SelectionRules.Moveable) == SelectionRules.Moveable))
            {
                // once this is fired the parent control (parentcontroldesigner) will start getting dragover events.
                //
                selectionServ.DragBegin();
            }
        }
コード例 #5
0
        internal override void OnMouseMove(int x, int y)
        {
            IUISelectionService uiSelection = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (uiSelection != null)
            {
                uiSelection.SetCursor(x, y);
            }

            base.OnMouseMove(x, y);
        }
コード例 #6
0
        protected override void OnMouseDragEnd(bool cancel)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                if (selectionServ.SelectionInProgress || selectionServ.ResizeInProgress)
                {
                    selectionServ.MouseDragEnd(cancel);
                }
            }
        }
コード例 #7
0
        protected override void OnDragDrop(DragEventArgs e)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                // once this is fired the parent control (parentcontroldesigner) will start getting dragover events.
                //
                Point location = this.SnapPointToGrid(this.Control.PointToClient(new Point(e.X, e.Y)));
                selectionServ.DragDrop(false, this.Control, location.X, location.Y);
            }
        }
コード例 #8
0
    private void InitializeSelectionService ()
    {
        IUISelectionService guiSelectionService = this.GetService (typeof (IUISelectionService)) as IUISelectionService;
        if (guiSelectionService == null)
        {
            IServiceContainer serviceContainer = this.GetService (typeof (IServiceContainer)) as IServiceContainer;
            serviceContainer.AddService (typeof (IUISelectionService), (IUISelectionService) new UISelectionService (serviceContainer));
        }

        ISelectionService selectionService = this.GetService (typeof (ISelectionService)) as ISelectionService;
        selectionService.SetSelectedComponents (new IComponent[] { this.Component });
    }
コード例 #9
0
        protected override void OnDragOver(DragEventArgs e)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                // once ControlDesigner.MouseDragBegin is fired this will start getting dragover events.
                //
                Point location = this.SnapPointToGrid(this.Control.PointToClient(new Point(e.X, e.Y)));
                selectionServ.DragOver(this.Control, location.X, location.Y);
            }
            e.Effect = DragDropEffects.Move;
        }
コード例 #10
0
 void DesignerPanel_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     IUISelectionService selectionServ = this.DesignedControl.Site.GetService (typeof (IUISelectionService)) as IUISelectionService;
     if (_mouseDown)
     {
         if (selectionServ != null)
             selectionServ.MouseDragEnd (false);
         _mouseDown = false;
     }
     else if (selectionServ.SelectionInProgress)
     {
         selectionServ.MouseDragEnd (false);
     }
 }
コード例 #11
0
        protected override void OnMouseDragMove(int x, int y)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                Point location = new Point(x, y);
                if (!selectionServ.SelectionInProgress)
                {
                    location = this.SnapPointToGrid(new Point(x, y));
                }

                selectionServ.MouseDragMove(location.X, location.Y);
            }
        }
コード例 #12
0
        // Draws the design-time grid if DrawGrid == true
        //
        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);

            bool drawGrid;
            Size gridSize;

            // in case WM_PAINT is received before the IDesignerFilter is invoked to add
            // those properties.
            try
            {
                drawGrid = (bool)GetValue(this.Component, "DrawGrid");
            }
            catch
            {
                drawGrid = this.DrawGrid;
            }
            try
            {
                gridSize = (Size)GetValue(this.Component, "GridSize");
            }
            catch
            {
                gridSize = this.GridSize;
            }

            if (drawGrid)
            {
                GraphicsState state = pe.Graphics.Save();
                pe.Graphics.TranslateTransform(this.Control.ClientRectangle.X,
                                               this.Control.ClientRectangle.Y);
                ControlPaint.DrawGrid(pe.Graphics, this.Control.ClientRectangle, gridSize, this.Control.BackColor);
                pe.Graphics.Restore(state);
            }

            IUISelectionService selection = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selection != null)
            {
                selection.PaintAdornments(this.Control, pe.Graphics);
            }
        }
コード例 #13
0
        internal virtual void OnMouseDown(int x, int y)
        {
            _mouseDown          = true;
            _mouseDownFirstMove = true;
            IUISelectionService uiSelection = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (uiSelection != null && uiSelection.AdornmentsHitTest(this.Control, x, y))
            {
                // 1) prevent primary selection from being changed at this point.
                // 2) delegate behaviour in the future to the IUISelectionService
            }
            else
            {
                ISelectionService selectionService = this.GetService(typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SetSelectedComponents(new IComponent[] { this.Component });
                }
            }
        }
コード例 #14
0
        protected override void OnMouseDragEnd(bool cancel)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                // If there is a Toolbox component seleted then create it instead of finishing the selection
                IToolboxService toolBoxService = this.GetService(typeof(IToolboxService)) as IToolboxService;
                if (!cancel && toolBoxService != null && toolBoxService.GetSelectedToolboxItem() != null)
                {
                    if (selectionServ.SelectionInProgress)
                    {
                        bool hasSize = selectionServ.SelectionBounds.Width > 0 &&
                                       selectionServ.SelectionBounds.Height > 0;
                        CreateToolCore(toolBoxService.GetSelectedToolboxItem(),
                                       selectionServ.SelectionBounds.X,
                                       selectionServ.SelectionBounds.Y,
                                       selectionServ.SelectionBounds.Width,
                                       selectionServ.SelectionBounds.Height,
                                       true, hasSize);
                        toolBoxService.SelectedToolboxItemUsed();
                        cancel = true;
                    }
                    else if (!selectionServ.SelectionInProgress &&
                             !selectionServ.ResizeInProgress && !selectionServ.DragDropInProgress)
                    {
                        CreateTool(toolBoxService.GetSelectedToolboxItem(), _mouseDownPoint);
                        toolBoxService.SelectedToolboxItemUsed();
                        cancel = true;
                    }
                }

                if (selectionServ.SelectionInProgress || selectionServ.ResizeInProgress)
                {
                    selectionServ.MouseDragEnd(cancel);
                }
            }
        }
コード例 #15
0
        internal virtual void OnMouseUp()
        {
            IUISelectionService uiSelection = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (_mouseDown)
            {
                this.OnMouseDragEnd(false);
                if (uiSelection != null && (uiSelection.SelectionInProgress || uiSelection.ResizeInProgress))
                {
                    uiSelection.MouseDragEnd(false);
                }
                _mouseDown = false;
            }
            else
            {
                if (uiSelection != null && (uiSelection.SelectionInProgress || uiSelection.ResizeInProgress))
                {
                    // If the mouse up happens over the a control which is not defacto participating in
                    // the selection or resizing in progress, then inform the IUISelectionService of that event
                    //
                    uiSelection.MouseDragEnd(false);
                }
            }
        }
コード例 #16
0
        // Keep in mind that messages are recieved for the child controls if routed
        //
        protected virtual void WndProc(ref Message m)
        {
            // Filter out kb input
            //
            if ((Native.Msg)m.Msg >= Native.Msg.WM_KEYFIRST && (Native.Msg)m.Msg <= Native.Msg.WM_KEYLAST)
            {
                return;
            }

            // Mouse messages should be routed the control, if GetHitTest (virtual) returns true.
            //
            if (IsMouseMessage((Native.Msg)m.Msg) &&
                this.GetHitTest(new Point(Native.LoWord((int)m.LParam), Native.HiWord(((int)m.LParam)))))
            {
                this.DefWndProc(ref m);
                return;
            }

            switch ((Native.Msg)m.Msg)
            {
            case Native.Msg.WM_CREATE:
                this.DefWndProc(ref m);
                if (m.HWnd == this.Control.Handle)
                {
                    OnCreateHandle();
                }
                break;

            case Native.Msg.WM_CONTEXTMENU:
                OnContextMenu(Native.LoWord((int)m.LParam), Native.HiWord((int)m.LParam));
                break;

            case Native.Msg.WM_SETCURSOR:
                if (this.GetHitTest(new Point(Native.LoWord((int)m.LParam), Native.HiWord((int)m.LParam))))
                {
                    this.DefWndProc(ref m);
                }
                else
                {
                    OnSetCursor();
                }
                break;

            case Native.Msg.WM_SETFOCUS:
                this.DefWndProc(ref m);
                break;

            case Native.Msg.WM_PAINT:
                // Wait for control's WM_PAINT to complete first.
                //
                this.DefWndProc(ref m);

                Graphics       gfx  = Graphics.FromHwnd(m.HWnd);
                PaintEventArgs args = new PaintEventArgs(gfx, this.Control.Bounds);
                OnPaintAdornments(args);
                gfx.Dispose();
                args.Dispose();
                break;

            case Native.Msg.WM_NCRBUTTONDOWN:
            case Native.Msg.WM_NCLBUTTONDOWN:
            case Native.Msg.WM_NCMBUTTONDOWN:
            case Native.Msg.WM_NCLBUTTONDBLCLK:
            case Native.Msg.WM_NCRBUTTONDBLCLK:
                break;

            case Native.Msg.WM_LBUTTONDBLCLK:
            case Native.Msg.WM_RBUTTONDBLCLK:
            case Native.Msg.WM_MBUTTONDBLCLK:
                if ((Native.Msg)m.Msg == Native.Msg.WM_LBUTTONDBLCLK)
                {
                    _mouseButtonDown = MouseButtons.Left;
                }
                else if ((Native.Msg)m.Msg == Native.Msg.WM_RBUTTONDBLCLK)
                {
                    _mouseButtonDown = MouseButtons.Right;
                }
                else if ((Native.Msg)m.Msg == Native.Msg.WM_MBUTTONDBLCLK)
                {
                    _mouseButtonDown = MouseButtons.Middle;
                }
                OnMouseDoubleClick();
                this.BaseWndProc(ref m);
                break;

            case Native.Msg.WM_MOUSEHOVER:
                OnMouseHover();
                break;

            case Native.Msg.WM_LBUTTONDOWN:
            case Native.Msg.WM_RBUTTONDOWN:
            case Native.Msg.WM_MBUTTONDOWN:
                _mouseMoveAfterMouseDown = true;
                if ((Native.Msg)m.Msg == Native.Msg.WM_LBUTTONDOWN)
                {
                    _mouseButtonDown = MouseButtons.Left;
                }
                else if ((Native.Msg)m.Msg == Native.Msg.WM_RBUTTONDOWN)
                {
                    _mouseButtonDown = MouseButtons.Right;
                }
                else if ((Native.Msg)m.Msg == Native.Msg.WM_MBUTTONDOWN)
                {
                    _mouseButtonDown = MouseButtons.Middle;
                }

                if (_firstMouseMoveInClient)
                {
                    OnMouseEnter();
                    _firstMouseMoveInClient = false;
                }
                this.OnMouseDown(Native.LoWord((int)m.LParam), Native.HiWord((int)m.LParam));
                this.BaseWndProc(ref m);
                break;

            case Native.Msg.WM_MOUSELEAVE:
                _firstMouseMoveInClient = false;
                OnMouseLeave();
                this.BaseWndProc(ref m);
                break;

            // The WM_CANCELMODE message is sent to cancel certain modes, such as mouse capture.
            // For example, the system sends this message to the active window when a dialog box
            // or message box is displayed. Certain functions also send this message explicitly to
            // the specified window regardless of whether it is the active window. For example,
            // the EnableWindow function sends this message when disabling the specified window.
            //
            case Native.Msg.WM_CANCELMODE:
                OnMouseDragEnd(true);
                this.DefWndProc(ref m);
                break;

            case Native.Msg.WM_LBUTTONUP:
            case Native.Msg.WM_RBUTTONUP:
            case Native.Msg.WM_NCLBUTTONUP:
            case Native.Msg.WM_NCRBUTTONUP:
            case Native.Msg.WM_MBUTTONUP:
            case Native.Msg.WM_NCMBUTTONUP:
                _mouseMoveAfterMouseDown = false;                         // just in case
                this.OnMouseUp();
                this.BaseWndProc(ref m);
                break;

            // // MWF Specific msg! - must reach control
            // //
            // case Native.Msg.WM_MOUSE_ENTER:
            //  _firstMouseMoveInClient = false; // just so that nothing will get fired in WM_MOUSEMOVE
            //  OnMouseEnter ();
            //  this.DefWndProc (ref m);
            //  break;

            // FIXME: The first MOUSEMOVE after WM_MOUSEDOWN should be ingored
            //
            case Native.Msg.WM_MOUSEMOVE:
                if (_mouseMoveAfterMouseDown)                           // mousemove is send after each mousedown so ignore that
                {
                    _mouseMoveAfterMouseDown = false;
                    this.BaseWndProc(ref m);
                    return;
                }
                // If selection is in progress pass the mouse move msg to the primary selection.
                // If resizing is in progress pass to the parent of the primary selection (remmember that the selection
                // frame is not a control and is drawn in the parent of the primary selection).
                //
                // Required in order for those 2 operations to continue when the mouse is moving over a control covering
                // the one where the action takes place.
                //
                IUISelectionService uiSelectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;
                ISelectionService   selectionServ   = this.GetService(typeof(ISelectionService)) as ISelectionService;
                IDesignerHost       host            = this.GetService(typeof(IDesignerHost)) as IDesignerHost;


                if (uiSelectionServ != null && selectionServ != null && host != null)
                {
                    Control primarySelection = selectionServ.PrimarySelection as Control;
                    Point   location         = new Point(Native.LoWord((int)m.LParam), Native.HiWord((int)m.LParam));

                    if (uiSelectionServ.SelectionInProgress &&
                        this.Component != host.RootComponent &&
                        this.Component != selectionServ.PrimarySelection)
                    {
                        location = primarySelection.PointToClient(this.Control.PointToScreen(location));
                        Native.SendMessage(primarySelection.Handle, (Native.Msg)m.Msg, m.WParam, Native.LParam(location.X, location.Y));
                    }
                    else if (uiSelectionServ.ResizeInProgress &&
                             // this.Component != host.RootComponent &&
                             this.Control.Parent == ((Control)selectionServ.PrimarySelection).Parent)
                    {
                        location = this.Control.Parent.PointToClient(this.Control.PointToScreen(location));
                        Native.SendMessage(this.Control.Parent.Handle, (Native.Msg)m.Msg, m.WParam, Native.LParam(location.X, location.Y));
                    }
                    else
                    {
                        this.OnMouseMove(location.X, location.Y);
                    }
                }
                else
                {
                    this.OnMouseMove(Native.LoWord((int)m.LParam), Native.HiWord((int)m.LParam));
                }
                this.BaseWndProc(ref m);
                break;

            default:
                // Pass everything else to the control and return
                //
                this.DefWndProc(ref m);
                break;
            }
        }