예제 #1
0
        // Returns true if processing should continue (base.SendEvent should be called), false if not
        protected bool PreprocessMouseDown(NSEvent e)
        {
            bool   hitTestCalled = false;
            NSView hitTestView   = null;

            if (ToolStripManager.activeToolStrips.Count != 0)
            {
                hitTestCalled = true;
                hitTestView   = (ContentView.Superview ?? ContentView).HitTest(e.LocationInWindow);
                if (hitTestView != null && !ToolStripManager.IsChildOfActiveToolStrip(hitTestView.Handle))
                {
                    ToolStripManager.FireAppClicked();
                }
            }

            if (e.Type == NSEventType.LeftMouseDown)
            {
                var topLevelParent = IntPtr.Zero;                 // FIXME
                if (!hitTestCalled)
                {
                    hitTestView = (ContentView.Superview ?? ContentView).HitTest(e.LocationInWindow);
                }
                var hitTestHandle = hitTestView?.Handle ?? IntPtr.Zero;
                mouseActivate = (MouseActivate)driver.SendMessage(ContentView.Handle, Msg.WM_MOUSEACTIVATE, topLevelParent, hitTestHandle).ToInt32();
                if (mouseActivate == MouseActivate.MA_NOACTIVATEANDEAT)                // || mouseActivate == MouseActivate.MA_ACTIVATEANDEAT)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        public override void SendEvent(NSEvent theEvent)
        {
            lastEventType = theEvent.Type;
            var monoContentView = (MonoContentView)ContentView;

            switch (theEvent.Type)
            {
            case NSEventType.LeftMouseDown:
            case NSEventType.RightMouseDown:
            case NSEventType.OtherMouseDown:
            case NSEventType.BeginGesture:
                hitTestHandle = (IntPtr)(ContentView.Superview ?? ContentView).HitTest(theEvent.LocationInWindow)?.Handle;
                // Make sure any popup menus are closed when clicking on embedded NSView.
                if (null == Control.FromHandle(hitTestHandle))
                {
                    ToolStripManager.FireAppClicked();
                }
                break;

            case NSEventType.KeyUp:
            case NSEventType.KeyDown:
                // Emulation of ToolStrip's modal filter
                if (Application.KeyboardCapture is ToolStripDropDown)
                {
                    var monoView = (FirstResponder as NSView)?.ClosestParentOfType <MonoView>();
                    if (monoView != null)
                    {
                        if (theEvent.Type == NSEventType.KeyDown)
                        {
                            monoView.eventResponder.KeyDown(theEvent);
                        }
                        else
                        {
                            monoView.eventResponder.KeyUp(theEvent);
                        }
                        return;
                    }
                }
                break;
            }

            if (theEvent.Type == NSEventType.LeftMouseDown)
            {
                var topLevelParent = IntPtr.Zero;                       // FIXME
                mouseActivate = (MouseActivate)driver.SendMessage(ContentView.Handle, Msg.WM_MOUSEACTIVATE, topLevelParent, hitTestHandle).ToInt32();
                if (mouseActivate == MouseActivate.MA_NOACTIVATEANDEAT) // || mouseActivate == MouseActivate.MA_ACTIVATEANDEAT)
                {
                    return;
                }
            }

            base.SendEvent(theEvent);
        }
예제 #3
0
        // Returns true if processing should continue (base.SendEvent should be called), false if not
        protected virtual bool PreprocessMouseDown(NSEvent e)
        {
            bool   hitTestCalled = false;
            NSView hitTestView   = null;

            if (ToolStripManager.activeToolStrips.Count != 0)
            {
                hitTestCalled = true;
                hitTestView   = (ContentView.Superview ?? ContentView).HitTest(e.LocationInWindow);
                if (hitTestView != null && !ToolStripManager.IsChildOfActiveToolStrip(hitTestView.Handle))
                {
                    ToolStripManager.FireAppClicked();
                }
            }

            if (!hitTestCalled)
            {
                hitTestView = (ContentView.Superview ?? ContentView).HitTest(e.LocationInWindow);
            }
            var hitTestHandle        = hitTestView?.Handle ?? IntPtr.Zero;
            var hitTestControl       = Control.FromChildHandle(hitTestHandle);
            var hitTestControlHandle = hitTestControl?.Handle ?? IntPtr.Zero;

            if (e.Type == NSEventType.LeftMouseDown)
            {
                var topLevelParent = IntPtr.Zero;                       // FIXME
                mouseActivate = (MouseActivate)driver.SendMessage(ContentView.Handle, Msg.WM_MOUSEACTIVATE, topLevelParent, hitTestControlHandle).ToInt32();
                if (mouseActivate == MouseActivate.MA_NOACTIVATEANDEAT) // || mouseActivate == MouseActivate.MA_ACTIVATEANDEAT)
                {
                    return(true);
                }
            }

            if (hitTestControlHandle == IntPtr.Zero)
            {
                OnNcMouseDown(e);
            }
            else
            {
                if (!hitTestView.IsSwfControl())
                {
                    var p = driver.NativeToMonoScreen(this.ConvertPointToScreenSafe(e.LocationInWindow));
                    driver.SendParentNotify(hitTestControlHandle, Msg.WM_LBUTTONDOWN, p.X, p.Y);
                }
            }

            return(false);
        }
예제 #4
0
        public override void SendEvent(NSEvent theEvent)
        {
            DebugUtility.WriteInfoIfChanged(theEvent);

            lastEventType = theEvent.Type;
            currentEvent  = theEvent;

            switch (theEvent.Type)
            {
            case NSEventType.LeftMouseDown:
            case NSEventType.RightMouseDown:
            case NSEventType.OtherMouseDown:
            case NSEventType.BeginGesture:
                hitTestHandle = (ContentView.Superview ?? ContentView).HitTest(theEvent.LocationInWindow)?.Handle ?? IntPtr.Zero;
                if (!ToolStripManager.IsChildOfActiveToolStrip(hitTestHandle))
                {
                    ToolStripManager.FireAppClicked();
                }
                break;

            case NSEventType.KeyUp:
            case NSEventType.KeyDown:
                // Emulation of ToolStrip's modal filter
                if (Application.KeyboardCapture is ToolStripDropDown capture)
                {
                    var resp = FirstResponder;
                    var h    = resp?.Handle ?? IntPtr.Zero;
                    if (h != IntPtr.Zero)
                    {
                        if (!ToolStripManager.IsChildOfActiveToolStrip(h))
                        {
                            resp = capture.Handle.AsNSObject <NSResponder>();
                        }
                    }

                    if (resp != null)
                    {
                        if (theEvent.Type == NSEventType.KeyDown)
                        {
                            resp.KeyDown(theEvent);
                        }
                        else
                        {
                            resp.KeyUp(theEvent);
                        }
                        return;
                    }
                }

                // Deliver key messages also to SWF controls that are wrappers of native controls.
                // This gives them a the chance to handle special keys
                if (!(FirstResponder is MonoView) && !(FirstResponder is WindowsEventResponder))
                {
                    var control = Control.FromChildHandle(FirstResponder.Handle);
                    if (control != null && control.Handle.ToNSObject() is NSView obj)
                    {
                        theEvent.ToKeyMsg(out Msg msg, out IntPtr wParam, out IntPtr lParam);
                        if (IntPtr.Zero != driver.SendMessage(control.Handle, msg, wParam, lParam))
                        {
                            return;
                        }
                    }
                }

                break;
            }

            if (theEvent.Type == NSEventType.LeftMouseDown)
            {
                var topLevelParent = IntPtr.Zero;                       // FIXME
                mouseActivate = (MouseActivate)driver.SendMessage(ContentView.Handle, Msg.WM_MOUSEACTIVATE, topLevelParent, hitTestHandle).ToInt32();
                if (mouseActivate == MouseActivate.MA_NOACTIVATEANDEAT) // || mouseActivate == MouseActivate.MA_ACTIVATEANDEAT)
                {
                    return;
                }
            }

            base.SendEvent(theEvent);
            currentEvent = null;
        }