Exemple #1
0
        protected override bool GetHitTest(Point point)
        {
            if (base.GetHitTest(point))
            {
                return(true);
            }

            // Check if the user has clicked on the scroll bars and forward the message to
            // the ScrollableControl. (Don't filter out the scrolling.). Keep in mind that scrollbars
            // will be shown only if ScrollableControl.AutoScroll = true
            //
            if (this.Control is ScrollableControl && ((ScrollableControl)Control).AutoScroll)
            {
                int hitTestResult = (int)Native.SendMessage(this.Control.Handle,
                                                            Native.Msg.WM_NCHITTEST,
                                                            IntPtr.Zero,
                                                            (IntPtr)Native.LParam(point.X, point.Y));
                if (hitTestResult == HTHSCROLL || hitTestResult == HTVSCROLL)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
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;
            }
        }