/// <summary>TODO</summary>
        /// <param name="e"></param>
        protected virtual void OnMouseHWheel(MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (!AutoScroll)
            {
                return;
            }

            _wheelHPos += e.Delta;
            while (_wheelHPos > MouseWheelStep)
            {
                ScrollHorizontal(MouseWheelStep);
                _wheelHPos -= MouseWheelStep;
            }
            while (_wheelHPos < -MouseWheelStep)
            {
                ScrollHorizontal(-MouseWheelStep);
                _wheelHPos += MouseWheelStep;
            }

            if (MouseHWheel != null)
            {
                MouseHWheel.Raise(this, e);
            }
        }
示例#2
0
        protected void FireMouseHWheel(MouseButtons buttons, int clicks, int x, int y, int delta)
        {
            MouseEventArgs args = new MouseEventArgs(buttons,
                                                     clicks, x, y, delta);

            OnMouseHWheel(args);
            //let everybody else have a crack at it
            MouseHWheel?.Invoke(this, args);
        }
示例#3
0
            private IntPtr AllMBHookProc(int code, IntPtr wParam, IntPtr lParam)
            {
                tagMSLLHOOKSTRUCT param = new tagMSLLHOOKSTRUCT();

                param = (tagMSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(tagMSLLHOOKSTRUCT));
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.LBUTTONDOWN)
                {
                    MouseDown?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.RBUTTONDOWN)
                {
                    MouseDown?.Invoke(this, new MouseEventArgs(MouseButtons.Right, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.MBUTTONDOWN)
                {
                    MouseDown?.Invoke(this, new MouseEventArgs(MouseButtons.Middle, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.XBUTTONDOWN)
                {
                    MouseDown?.Invoke(this, new MouseEventArgs((param.mouseData & 0x10000) != 0 ? MouseButtons.XButton1 : MouseButtons.XButton2, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.LBUTTONUP)
                {
                    MouseUp?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.RBUTTONUP)
                {
                    MouseUp?.Invoke(this, new MouseEventArgs(MouseButtons.Right, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.MBUTTONUP)
                {
                    MouseUp?.Invoke(this, new MouseEventArgs(MouseButtons.Middle, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.XBUTTONUP)
                {
                    MouseUp?.Invoke(this, new MouseEventArgs(param.mouseData == 1 ? MouseButtons.XButton1 : MouseButtons.XButton2, 0, param.x, param.y, 0));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.MOUSEWHEEL)
                {
                    MouseWheel?.Invoke(this, new MouseEventArgs(MouseButtons.None, 0, param.x, param.y, (int)(param.mouseData)));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.MOUSEHWHEEL)
                {
                    MouseHWheel?.Invoke(this, new MouseEventArgs(MouseButtons.None, 0, param.x, param.y, (int)(param.mouseData)));
                }
                if (code >= 0 && wParam == (IntPtr)WinAPI.Message.WindowsMessage.MOUSEMOVE)
                {
                    MouseMove?.Invoke(this, new MouseEventArgs(MouseButtons.None, 0, param.x, param.y, (int)(param.mouseData)));
                }
                return(WinAPI.Hook.CallNextHookEx(_mbHHook, code, wParam, lParam));
            }
示例#4
0
        private int _wheelHPos = 0;   //!< <summary>Unapplied horizontal scroll.</summary>

        /// <summary>Scrolls horizontally and raises the MouseHWheel event</summary>
        /// <param name="e"></param>
        protected virtual void OnMouseHWheel(MouseWheelEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (CanContentScroll)
            {
                ScrollToHorizontalOffset(HorizontalOffset + e.Delta);

                if (MouseHWheel != null)
                {
                    MouseHWheel?.Invoke(this, e);
                }
            }
        }
        /// <summary>Raise a <see cref="MouseHWheel"/> event.</summary>
        /// <param name="e">A <see cref="MouseEventArgs"/> that contains the event data. </param>
        protected virtual void OnMouseHWheel(MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (!AutoScroll)
            {
                return;
            }

            this.RollHorizontal(e.Delta);
            MouseHWheel?.Invoke(this, e);

            if (e is HandledMouseEventArgs eh)
            {
                eh.Handled = true;
            }
        }
示例#6
0
        internal override IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var data = (MSLLHOOKSTRUCT)PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));

            var ea = new LowLevelMouseProcEventArgs(data);

            LowLevelMouseProc?.Invoke((WPARAM)wParam, ea);

            switch ((WPARAM)wParam)
            {
            case WPARAM.WM_MOUSEMOVE:
                MouseMove?.Invoke(ea);
                break;

            case WPARAM.WM_LBUTTONDOWN:
                LButtonDown?.Invoke(ea);
                break;

            case WPARAM.WM_LBUTTONUP:
                LButtonUp?.Invoke(ea);
                break;

            case WPARAM.WM_RBUTTONDOWN:
                RButtonDown?.Invoke(ea);
                break;

            case WPARAM.WM_RBUTTONUP:
                RButtonUp?.Invoke(ea);
                break;

            case WPARAM.WM_MOUSEWHEEL:
                MouseWheel?.Invoke(ea);
                break;

            case WPARAM.WM_MOUSEHWHEEL:
                MouseHWheel?.Invoke(ea);
                break;
            }

            return(base.Callback(nCode, wParam, lParam));
        }
示例#7
0
        /// <summary>
        /// The internal hook callback.
        /// </summary>
        private IntPtr HookCallback(
            int nCode, IntPtr wParam, IntPtr lParam)
        {
            int           nmsg = wParam.ToInt32();
            WindowMessage msg  = (WindowMessage)nmsg;

            if (nCode >= 0 &&
                (nmsg >= (int)WindowMessage.WM_MOUSEFIRST && nmsg <= (int)WindowMessage.WM_MOUSEWHEEL))
            {
                try
                {
                    int  vkCode = Marshal.ReadInt32(lParam);
                    Keys key    = (Keys)vkCode;

                    if (!NativeMethods.GetCursorPos(out NativeMethods.POINT pt))
                    {
                        throw new Win32Exception();
                    }

                    MouseHookEventArgs eventArgs = new MouseHookEventArgs(new Point(pt.X, pt.Y));

                    switch (msg)
                    {
                    case WindowMessage.WM_MOUSEMOVE:
                        MouseMove?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_LBUTTONDOWN:
                        LButtonDown?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_LBUTTONUP:
                        LButtonUp?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_LBUTTONDBLCLK:
                        LButtonDblClick?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_RBUTTONDOWN:
                        RButtonDown?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_RBUTTONUP:
                        RButtonUp?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_RBUTTONDBLCLK:
                        RButtonDblClick?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_MBUTTONDOWN:
                        MButtonDown?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_MBUTTONUP:
                        MButtonUp?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_MBUTTONDBLCLK:
                        MButtonDblClick?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_XBUTTONDOWN:
                        XButtonDown?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_XBUTTONUP:
                        XButtonUp?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_XBUTTONDBLCLK:
                        XButtonDblClick?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_MOUSEWHEEL:
                        MouseVWheel?.Invoke(this, eventArgs);
                        break;

                    case WindowMessage.WM_MOUSEHWHEEL:
                        MouseHWheel?.Invoke(this, eventArgs);
                        break;
                    }

                    // If Handled is set to true,
                    // return 1 and stop the keyboard event
                    // from propagating to other applications.
                    if (eventArgs.Handled)
                    {
                        return((IntPtr)1);
                    }
                }
                catch (Exception e)
                {
                    System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
                    {
                        System.Windows.MessageBox.Show(e.ToString(), "Application Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    });
                }
            }
            return(NativeMethods.CallNextHookEx(_nativeHookId, nCode, wParam, lParam));
        }
示例#8
0
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Delta       = BitConverter.ToInt16(e.Bytes, 20),
            };

            Debug.WriteLine($"Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Delta: {eventArgs.Delta}");

            MessageReceived?.Invoke(this, eventArgs);

            switch (GetMessageCode(eventArgs.MessageCode))
            {
            case MouseMessageCode.MouseMove:
                MouseMove?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDown:
                LeftButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonUp:
                LeftButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDblClk:
                LeftButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDown:
                RightButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonUp:
                RightButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDblClk:
                RightButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDown:
                MiddleButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonUp:
                MiddleButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDblClk:
                MiddleButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseWheel:
                MouseWheel?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDown:
                XButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonUp:
                XButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDblClk:
                XButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseHWheel:
                MouseHWheel?.Invoke(this, eventArgs);
                break;

            default:
                break;
            }

            if (_messageHandlers.ContainsKey(eventArgs.MessageCode))
            {
                _messageHandlers[eventArgs.MessageCode]?.Invoke(this, eventArgs);
            }
        }
示例#9
0
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var modifiers = BitConverter.ToUInt16(e.Bytes, 24);
            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Modifiers   = modifiers,
                Shift       = (modifiers & 0b100) > 0,
                Control     = (modifiers & 0b10) > 0,
                Alt         = (modifiers & 0b1) > 0,
            };

            var messageCode = GetMessageCode(eventArgs.MessageCode);

            if (messageCode == MouseMessageCode.MouseWheel)
            {
                eventArgs.Delta = BitConverter.ToInt16(e.Bytes, 20);
            }
            else if (messageCode == MouseMessageCode.NCXButtonDown ||
                     messageCode == MouseMessageCode.NCXButtonUp ||
                     messageCode == MouseMessageCode.NCXButtonDblClk ||
                     messageCode == MouseMessageCode.XButtonDown ||
                     messageCode == MouseMessageCode.XButtonUp ||
                     messageCode == MouseMessageCode.XButtonDblClk)
            {
                eventArgs.XButtons = BitConverter.ToInt16(e.Bytes, 20);
            }

            Debug.Write($"Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Modifiers: {eventArgs.Modifiers:x}; ");
            Debug.WriteLine($"Delta: {eventArgs.Delta}; XButtons: {eventArgs.XButtons}");

            MessageReceived?.Invoke(this, eventArgs);

            switch (messageCode)
            {
            case MouseMessageCode.MouseMove:
                MouseMove?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDown:
                LeftButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonUp:
                LeftButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDblClk:
                LeftButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDown:
                RightButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonUp:
                RightButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDblClk:
                RightButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDown:
                MiddleButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonUp:
                MiddleButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDblClk:
                MiddleButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseWheel:
                MouseWheel?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDown:
                XButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonUp:
                XButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDblClk:
                XButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseHWheel:
                MouseHWheel?.Invoke(this, eventArgs);
                break;

            default:
                break;
            }

            if (_messageHandlers.ContainsKey(eventArgs.MessageCode))
            {
                _messageHandlers[eventArgs.MessageCode]?.Invoke(this, eventArgs);
            }
        }
示例#10
0
 private void OnMouseHWheel(MouseHookEventArgs e)
 {
     MouseHWheel?.Invoke(this, e);
     OnMouseEvent(e);
 }
示例#11
0
 /// <summary>
 /// Invoked by <see cref="HookMouseHWheel(int)"/>
 /// </summary>
 protected virtual void OnMouseHWheel(int delta)
 {
     MouseHWheel?.Invoke(this, new MouseTiltEventArgs(delta));
 }
示例#12
0
 protected virtual void OnMouseHWheel(EventArgs e) //TODO: MouseEventArgs kellene
 {
     UpdateDocumentOffset();
     Invalidate(); //TODO: SetDisplayRectLocation() kellene
     MouseHWheel?.Invoke(this, e);
 }
示例#13
0
 protected virtual void OnMouseHWheel(int delta)
 {
     MouseHWheel?.Invoke(this, new MouseTiltEventArgs(delta));
     ScrollToHorizontalOffset(HorizontalOffset + delta * 0.5);
 }
示例#14
0
文件: Canvas.cs 项目: koenmd/nERD
 private void OnMouseHWheel(EventArgs e)
 {
     UpdateDocumentOffset();
     Invalidate();
     MouseHWheel?.Invoke(this, e);
 }